예제 #1
0
static ssize_t tsc2005_disable_store(struct device *dev,
				     struct device_attribute *attr,
				     const char *buf, size_t count)
{
	struct tsc2005		*ts = dev_get_drvdata(dev);
	unsigned long res;
	int i;

	if (strict_strtoul(buf, 10, &res) < 0)
		return -EINVAL;
	i = res ? 1 : 0;

	mutex_lock(&ts->mutex);
	if (i == ts->disabled)
		goto out;
	ts->disabled = i;

	if (i)
		tsc2005_disable(ts);
	else
		tsc2005_enable(ts);
out:
	mutex_unlock(&ts->mutex);
	return count;
}
예제 #2
0
static int tsc2005_resume(struct spi_device *spi)
{
	struct tsc2005 *ts = dev_get_drvdata(&spi->dev);

	mutex_lock(&ts->mutex);
	tsc2005_enable(ts);
	mutex_unlock(&ts->mutex);

	return 0;
}
예제 #3
0
static ssize_t tsc2005_ctrl_selftest_show(struct device *dev,
					  struct device_attribute *attr,
					  char *buf)
{
	u16 temp_high_orig, temp_high_test, temp_high;
	unsigned int result = 1;
	struct tsc2005 *ts = dev_get_drvdata(dev);

	if (!ts->set_reset) {
		dev_warn(&ts->spi->dev,
			 "unable to selftest: reset not configured\n");
		result = 0;
		goto out;
	}

	mutex_lock(&ts->mutex);
	tsc2005_disable(ts);

	/* Test ctrl communications via temp high / low registers */
	tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high_orig);

	temp_high_test = (temp_high_orig - 1) & 0x0FFF;

	tsc2005_write(ts, TSC2005_REG_TEMP_HIGH, temp_high_test);

	tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high);

	if (temp_high != temp_high_test) {
		result = 0;
		dev_warn(dev, "selftest failed: %d != %d\n",
			 temp_high, temp_high_test);
	}

	/* HW Reset */
	ts->set_reset(0);
	msleep(1); /* only 10us required */
	ts->set_reset(1);

	tsc2005_enable(ts);

	/* Test that reset really happened */
	tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high);

	if (temp_high != temp_high_orig) {
		result = 0;
		dev_warn(dev, "selftest failed after reset: "
			 "%d != %d\n",
			 temp_high, temp_high_orig);
	}

	mutex_unlock(&ts->mutex);

out:
	return sprintf(buf, "%u\n", result);
}
예제 #4
0
static ssize_t tsc2005_selftest_show(struct device *dev,
				     struct device_attribute *attr,
				     char *buf)
{
	struct tsc2005 *ts = dev_get_drvdata(dev);
	u16 temp_high;
	u16 temp_high_orig;
	u16 temp_high_test;
	unsigned int result;

	if (!ts->set_reset) {
		dev_warn(&ts->spi->dev,
			 "unable to selftest: no reset function\n");
		result = 0;
		goto out;
	}

	mutex_lock(&ts->mutex);

	/*
	 * Test TSC2005 communications via temp high register.
	 */
	tsc2005_disable(ts);
	result = 1;
	tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high_orig);
	temp_high_test = (temp_high_orig - 1) & MAX_12BIT;
	tsc2005_write(ts, TSC2005_REG_TEMP_HIGH, temp_high_test);
	tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high);
	if (temp_high != temp_high_test) {
		dev_warn(dev, "selftest failed: %d != %d\n",
			 temp_high, temp_high_test);
		result = 0;
	}

	/* hardware reset */
	ts->set_reset(0);
	msleep(1); /* only 10us required */
	ts->set_reset(1);
	tsc2005_enable(ts);

	/* test that the reset really happened */
	tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high);
	if (temp_high != temp_high_orig) {
		dev_warn(dev, "selftest failed after reset: %d != %d\n",
			 temp_high, temp_high_orig);
		result = 0;
	}

	mutex_unlock(&ts->mutex);

out:
	return sprintf(buf, "%u\n", result);
}