Skip to contentSkip to conversation

iio: potentiometer: tpl0102: add hi-z enable/disable support

PATCH In review Matt Ranostay 2 participants 2 messages Mar 14, 2016 – Mar 20, 2016 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: potentiometer: tpl0102: add hi-z enable/disable support

---
 drivers/iio/potentiometer/tpl0102.c | 43 ++++++++++++++++++++++++++-----------
 1 file changed, 31 insertions(+), 12 deletions(-)
drivers/iio/potentiometer/tpl0102.c +31 -12
index 313124b..1413419c 100644
@@ -12,8 +12,6 @@
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
- *
- * TODO: enable/disable hi-z output control
  */
 
 #include <linux/module.h>
@@ -39,7 +37,7 @@ static const struct tpl0102_cfg tpl0102_cfg[] = {
 	[CAT5140_503] = { .wipers = 1, .max_pos = 256, .kohms = 50, },
 	[CAT5140_104] = { .wipers = 1, .max_pos = 256, .kohms = 100, },
 	/* ti parts */
-	[TPL0102_104] = { .wipers = 2, .max_pos = 256, .kohms = 100 },
+	[TPL0102_104] = { .wipers = 3, .max_pos = 256, .kohms = 100 },
 	[TPL0401_103] = { .wipers = 1, .max_pos = 128, .kohms = 10, },
 };
 
@@ -65,6 +63,15 @@ static const struct regmap_config tpl0102_regmap_config = {
 static const struct iio_chan_spec tpl0102_channels[] = {
 	TPL0102_CHANNEL(0),
 	TPL0102_CHANNEL(1),
+	/* hi-z enable/disable */
+	{
+		.type = IIO_RESISTANCE,
+		.output = 1,
+		.address = 0x10,
+		.channel = BIT(6),
+		.info_mask_separate = BIT(IIO_CHAN_INFO_ENABLE),
+		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
+	}
 };
 
 static int tpl0102_read_raw(struct iio_dev *indio_dev,
@@ -72,13 +79,20 @@ static int tpl0102_read_raw(struct iio_dev *indio_dev,
 			    int *val, int *val2, long mask)
 {
 	struct tpl0102_data *data = iio_priv(indio_dev);
+	int ret;
 
 	switch (mask) {
-	case IIO_CHAN_INFO_RAW: {
-		int ret = regmap_read(data->regmap, chan->channel, val);
+	case IIO_CHAN_INFO_ENABLE:
+		ret = regmap_read(data->regmap, chan->address, val);
+
+		if (!ret)
+			*val = !!(*val & chan->channel);
+
+		return ret ? ret : IIO_VAL_INT;
+	case IIO_CHAN_INFO_RAW:
+		ret = regmap_read(data->regmap, chan->channel, val);
 
 		return ret ? ret : IIO_VAL_INT;
-	}
 	case IIO_CHAN_INFO_SCALE:
 		*val = 1000 * tpl0102_cfg[data->devid].kohms;
 		*val2 = tpl0102_cfg[data->devid].max_pos;
@@ -94,13 +108,18 @@ static int tpl0102_write_raw(struct iio_dev *indio_dev,
 {
 	struct tpl0102_data *data = iio_priv(indio_dev);
 
-	if (mask != IIO_CHAN_INFO_RAW)
-		return -EINVAL;
-
-	if (val >= tpl0102_cfg[data->devid].max_pos || val < 0)
-		return -EINVAL;
+	switch (mask) {
+	case IIO_CHAN_INFO_ENABLE:
+		return regmap_update_bits(data->regmap, chan->address,
+					  chan->channel,
+					  !!val ? chan->channel : 0);
+	case IIO_CHAN_INFO_RAW:
+		if (val >= tpl0102_cfg[data->devid].max_pos || val < 0)
+			return -EINVAL;
+		return regmap_write(data->regmap, chan->channel, val);
+	}
 
-	return regmap_write(data->regmap, chan->channel, val);
+	return -EINVAL;
 }
 
 static const struct iio_info tpl0102_info = {
Signature · 1 line
2.7.0
maintainer
#1 lore raw
Quoted 1 line · Matt Ranostay

I've been ignoring this a few days as it looked fiddly :)

Quoted 29 lines
---
 drivers/iio/potentiometer/tpl0102.c | 43 ++++++++++++++++++++++++++-----------
 1 file changed, 31 insertions(+), 12 deletions(-)
drivers/iio/potentiometer/tpl0102.c +1 -3
index 313124b..1413419c 100644
@@ -12,8 +12,6 @@
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
- *
- * TODO: enable/disable hi-z output control
  */
 
 #include <linux/module.h>
@@ -39,7 +37,7 @@ static const struct tpl0102_cfg tpl0102_cfg[] = {
 	[CAT5140_503] = { .wipers = 1, .max_pos = 256, .kohms = 50, },
 	[CAT5140_104] = { .wipers = 1, .max_pos = 256, .kohms = 100, },
 	/* ti parts */
-	[TPL0102_104] = { .wipers = 2, .max_pos = 256, .kohms = 100 },
+	[TPL0102_104] = { .wipers = 3, .max_pos = 256, .kohms = 100 },
 	[TPL0401_103] = { .wipers = 1, .max_pos = 128, .kohms = 10, },
 };
 
@@ -65,6 +63,15 @@ static const struct regmap_config tpl0102_regmap_config = {
 static const struct iio_chan_spec tpl0102_channels[] = {
 	TPL0102_CHANNEL(0),

drivers/iio/potentiometer/tpl0102.c static const struct regmap_config tpl0102_regmap_config = { · line 74

Quoted 10 lines
drivers/iio/potentiometer/tpl0102.c +9 -0
 	TPL0102_CHANNEL(1),
+	/* hi-z enable/disable */
+	{
+		.type = IIO_RESISTANCE,
+		.output = 1,
+		.address = 0x10,
+		.channel = BIT(6),
+		.info_mask_separate = BIT(IIO_CHAN_INFO_ENABLE),
+		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
+	}

I'm confused as to what this actually is... What is the result on the output value of doing this and does it apply to all other channels? As far as I can tell this cuts off the upper voltage by opening a switch. Upshot is that you end up with just resistance between the output and the low voltage rather than a potentiometer. So it becomes an rheostat between the wiper output and the other end...

That's not remotely clear from the interface you have here unfortunately.

Mind you I'm open to ideas on how to support this!

Quoted 53 lines
drivers/iio/potentiometer/tpl0102.c +21 -9
 };
 
 static int tpl0102_read_raw(struct iio_dev *indio_dev,
@@ -72,13 +79,20 @@ static int tpl0102_read_raw(struct iio_dev *indio_dev,
 			    int *val, int *val2, long mask)
 {
 	struct tpl0102_data *data = iio_priv(indio_dev);
+	int ret;
 
 	switch (mask) {
-	case IIO_CHAN_INFO_RAW: {
-		int ret = regmap_read(data->regmap, chan->channel, val);
+	case IIO_CHAN_INFO_ENABLE:
+		ret = regmap_read(data->regmap, chan->address, val);
+
+		if (!ret)
+			*val = !!(*val & chan->channel);
+
+		return ret ? ret : IIO_VAL_INT;
+	case IIO_CHAN_INFO_RAW:
+		ret = regmap_read(data->regmap, chan->channel, val);
 
 		return ret ? ret : IIO_VAL_INT;
-	}
 	case IIO_CHAN_INFO_SCALE:
 		*val = 1000 * tpl0102_cfg[data->devid].kohms;
 		*val2 = tpl0102_cfg[data->devid].max_pos;
@@ -94,13 +108,18 @@ static int tpl0102_write_raw(struct iio_dev *indio_dev,
 {
 	struct tpl0102_data *data = iio_priv(indio_dev);
 
-	if (mask != IIO_CHAN_INFO_RAW)
-		return -EINVAL;
-
-	if (val >= tpl0102_cfg[data->devid].max_pos || val < 0)
-		return -EINVAL;
+	switch (mask) {
+	case IIO_CHAN_INFO_ENABLE:
+		return regmap_update_bits(data->regmap, chan->address,
+					  chan->channel,
+					  !!val ? chan->channel : 0);
+	case IIO_CHAN_INFO_RAW:
+		if (val >= tpl0102_cfg[data->devid].max_pos || val < 0)
+			return -EINVAL;
+		return regmap_write(data->regmap, chan->channel, val);
+	}
 
-	return regmap_write(data->regmap, chan->channel, val);
+	return -EINVAL;
 }
 
 static const struct iio_info tpl0102_info = {