linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: potentiometer: tpl0102: add hi-z enable/disable support
@ 2016-03-14  6:34 Matt Ranostay
  2016-03-20 11:33 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Matt Ranostay @ 2016-03-14  6:34 UTC (permalink / raw)
  To: linux-iio; +Cc: jic23, Matt Ranostay

Signed-off-by: Matt Ranostay <mranostay@gmail.com>
---
 drivers/iio/potentiometer/tpl0102.c | 43 ++++++++++++++++++++++++++-----------
 1 file changed, 31 insertions(+), 12 deletions(-)

diff --git a/drivers/iio/potentiometer/tpl0102.c b/drivers/iio/potentiometer/tpl0102.c
index 313124b..1413419c 100644
--- a/drivers/iio/potentiometer/tpl0102.c
+++ b/drivers/iio/potentiometer/tpl0102.c
@@ -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 = {
-- 
2.7.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-03-20 11:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-14  6:34 [PATCH] iio: potentiometer: tpl0102: add hi-z enable/disable support Matt Ranostay
2016-03-20 11:33 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).