All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv5 RESEND 0/4] iio: mxs-lradc: add support to optional divider_by_two
@ 2013-12-23 17:48 Alexandre Belloni
  2013-12-23 17:48 ` [PATCHv5 RESEND 1/4] iio: mxs-lradc: add scale attribute to channels Alexandre Belloni
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Alexandre Belloni @ 2013-12-23 17:48 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: lars, Marek Vasut, harald, hector.palacios, linux-iio,
	linux-kernel, Alexandre Belloni

Hello,

This is v5 of the patchset that adds support to the optional divider_by_two
of LRADC channels.

Changes since v4:
 - moved enum mxs_lradc_divbytwo to the third patch
 - added a fourth patch to convert is_divided to a bitmap. I did that in a
   separated patch for review and copyright attribution purposes.

This was tested on a custom i.MX28 platform.

Alexandre Belloni (1):
  iio: mxs-lradc: convert is_divided to a bitmap

Hector Palacios (3):
  iio: mxs-lradc: add scale attribute to channels
  iio: mxs-lradc: add scale_available file to channels
  iio: mxs-lradc: add write_raw function to modify scale

 drivers/staging/iio/adc/mxs-lradc.c | 222 +++++++++++++++++++++++++++++++++++-
 1 file changed, 219 insertions(+), 3 deletions(-)

-- 
1.8.3.2


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

* [PATCHv5 RESEND 1/4] iio: mxs-lradc: add scale attribute to channels
  2013-12-23 17:48 [PATCHv5 RESEND 0/4] iio: mxs-lradc: add support to optional divider_by_two Alexandre Belloni
@ 2013-12-23 17:48 ` Alexandre Belloni
  2014-01-01 14:25   ` Jonathan Cameron
  2013-12-23 17:48 ` [PATCHv5 RESEND 2/4] iio: mxs-lradc: add scale_available file " Alexandre Belloni
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 15+ messages in thread
From: Alexandre Belloni @ 2013-12-23 17:48 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: lars, Marek Vasut, harald, hector.palacios, linux-iio,
	linux-kernel, Alexandre Belloni

From: Hector Palacios <hector.palacios@digi.com>

Some LRADC channels have fixed pre-dividers and all have an optional
divider by two which allows a maximum input voltage of VDDIO - 50mV.

This patch
 - adds the scaling info flag to all channels
 - grabs the max reference voltage per channel
   (where the fixed pre-dividers apply)
 - allows to read the scaling attribute (computed from the Vref)

Signed-off-by: Hector Palacios <hector.palacios@digi.com>.
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Acked-by: Marek Vasut <marex@denx.de>

---
 drivers/staging/iio/adc/mxs-lradc.c | 56 +++++++++++++++++++++++++++++++++++--
 1 file changed, 54 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c
index 5a4499c3d22a..22fef0a408db 100644
--- a/drivers/staging/iio/adc/mxs-lradc.c
+++ b/drivers/staging/iio/adc/mxs-lradc.c
@@ -111,16 +111,59 @@ static const char * const mx28_lradc_irq_names[] = {
 struct mxs_lradc_of_config {
 	const int		irq_count;
 	const char * const	*irq_name;
+	const uint32_t		*vref_mv;
+};
+
+#define VREF_MV_BASE 1850
+
+static const uint32_t mx23_vref_mv[LRADC_MAX_TOTAL_CHANS] = {
+	VREF_MV_BASE,		/* CH0 */
+	VREF_MV_BASE,		/* CH1 */
+	VREF_MV_BASE,		/* CH2 */
+	VREF_MV_BASE,		/* CH3 */
+	VREF_MV_BASE,		/* CH4 */
+	VREF_MV_BASE,		/* CH5 */
+	VREF_MV_BASE * 2,	/* CH6 VDDIO */
+	VREF_MV_BASE * 4,	/* CH7 VBATT */
+	VREF_MV_BASE,		/* CH8 Temp sense 0 */
+	VREF_MV_BASE,		/* CH9 Temp sense 1 */
+	VREF_MV_BASE,		/* CH10 */
+	VREF_MV_BASE,		/* CH11 */
+	VREF_MV_BASE,		/* CH12 USB_DP */
+	VREF_MV_BASE,		/* CH13 USB_DN */
+	VREF_MV_BASE,		/* CH14 VBG */
+	VREF_MV_BASE * 4,	/* CH15 VDD5V */
+};
+
+static const uint32_t mx28_vref_mv[LRADC_MAX_TOTAL_CHANS] = {
+	VREF_MV_BASE,		/* CH0 */
+	VREF_MV_BASE,		/* CH1 */
+	VREF_MV_BASE,		/* CH2 */
+	VREF_MV_BASE,		/* CH3 */
+	VREF_MV_BASE,		/* CH4 */
+	VREF_MV_BASE,		/* CH5 */
+	VREF_MV_BASE,		/* CH6 */
+	VREF_MV_BASE * 4,	/* CH7 VBATT */
+	VREF_MV_BASE,		/* CH8 Temp sense 0 */
+	VREF_MV_BASE,		/* CH9 Temp sense 1 */
+	VREF_MV_BASE * 2,	/* CH10 VDDIO */
+	VREF_MV_BASE,		/* CH11 VTH */
+	VREF_MV_BASE * 2,	/* CH12 VDDA */
+	VREF_MV_BASE,		/* CH13 VDDD */
+	VREF_MV_BASE,		/* CH14 VBG */
+	VREF_MV_BASE * 4,	/* CH15 VDD5V */
 };
 
 static const struct mxs_lradc_of_config mxs_lradc_of_config[] = {
 	[IMX23_LRADC] = {
 		.irq_count	= ARRAY_SIZE(mx23_lradc_irq_names),
 		.irq_name	= mx23_lradc_irq_names,
+		.vref_mv	= mx23_vref_mv,
 	},
 	[IMX28_LRADC] = {
 		.irq_count	= ARRAY_SIZE(mx28_lradc_irq_names),
 		.irq_name	= mx28_lradc_irq_names,
+		.vref_mv	= mx28_vref_mv,
 	},
 };
 
@@ -155,6 +198,8 @@ struct mxs_lradc {
 
 	struct completion	completion;
 
+	const uint32_t		*vref_mv;
+
 	/*
 	 * Touchscreen LRADC channels receives a private slot in the CTRL4
 	 * register, the slot #7. Therefore only 7 slots instead of 8 in the
@@ -836,6 +881,8 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
 			const struct iio_chan_spec *chan,
 			int *val, int *val2, long m)
 {
+	struct mxs_lradc *lradc = iio_priv(iio_dev);
+
 	/* Check for invalid channel */
 	if (chan->channel > LRADC_MAX_TOTAL_CHANS)
 		return -EINVAL;
@@ -857,7 +904,9 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
 			return IIO_VAL_INT_PLUS_MICRO;
 		}
 
-		return -EINVAL;
+		*val = lradc->vref_mv[chan->channel];
+		*val2 = chan->scan_type.realbits;
+		return IIO_VAL_FRACTIONAL_LOG2;
 
 	case IIO_CHAN_INFO_OFFSET:
 		if (chan->type == IIO_TEMP) {
@@ -1189,7 +1238,8 @@ static const struct iio_buffer_setup_ops mxs_lradc_buffer_ops = {
 	.type = (chan_type),					\
 	.indexed = 1,						\
 	.scan_index = (idx),					\
-	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),		\
+	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |		\
+			      BIT(IIO_CHAN_INFO_SCALE),		\
 	.channel = (idx),					\
 	.scan_type = {						\
 		.sign = 'u',					\
@@ -1381,6 +1431,8 @@ static int mxs_lradc_probe(struct platform_device *pdev)
 			return ret;
 	}
 
+	lradc->vref_mv = of_cfg->vref_mv;
+
 	platform_set_drvdata(pdev, iio);
 
 	init_completion(&lradc->completion);
-- 
1.8.3.2


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

* [PATCHv5 RESEND 2/4] iio: mxs-lradc: add scale_available file to channels
  2013-12-23 17:48 [PATCHv5 RESEND 0/4] iio: mxs-lradc: add support to optional divider_by_two Alexandre Belloni
  2013-12-23 17:48 ` [PATCHv5 RESEND 1/4] iio: mxs-lradc: add scale attribute to channels Alexandre Belloni
@ 2013-12-23 17:48 ` Alexandre Belloni
  2014-01-01 14:28   ` Jonathan Cameron
  2013-12-23 17:48 ` [PATCHv5 RESEND 3/4] iio: mxs-lradc: add write_raw function to modify scale Alexandre Belloni
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 15+ messages in thread
From: Alexandre Belloni @ 2013-12-23 17:48 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: lars, Marek Vasut, harald, hector.palacios, linux-iio,
	linux-kernel, Alexandre Belloni

From: Hector Palacios <hector.palacios@digi.com>

Adds in_voltageX_scale_available file for every channel to read
the different available scales.
There are two scales per channel:
 [0] = divider_by_two disabled (default)
 [1] = divider_by_two enabled
The scale is a struct made of integer and nano parts to build
a long decimal number.

Signed-off-by: Hector Palacios <hector.palacios@digi.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Acked-by: Marek Vasut <marex@denx.de>

---
 drivers/staging/iio/adc/mxs-lradc.c | 106 +++++++++++++++++++++++++++++++++++-
 1 file changed, 105 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c
index 22fef0a408db..c63b312e54fd 100644
--- a/drivers/staging/iio/adc/mxs-lradc.c
+++ b/drivers/staging/iio/adc/mxs-lradc.c
@@ -38,6 +38,7 @@
 #include <linux/clk.h>
 
 #include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
 #include <linux/iio/buffer.h>
 #include <linux/iio/trigger.h>
 #include <linux/iio/trigger_consumer.h>
@@ -184,6 +185,11 @@ enum lradc_ts_plate {
 	LRADC_SAMPLE_VALID,
 };
 
+struct mxs_lradc_scale {
+	unsigned int		integer;
+	unsigned int		nano;
+};
+
 struct mxs_lradc {
 	struct device		*dev;
 	void __iomem		*base;
@@ -199,6 +205,7 @@ struct mxs_lradc {
 	struct completion	completion;
 
 	const uint32_t		*vref_mv;
+	struct mxs_lradc_scale	scale_avail[LRADC_MAX_TOTAL_CHANS][2];
 
 	/*
 	 * Touchscreen LRADC channels receives a private slot in the CTRL4
@@ -929,9 +936,84 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
 	return -EINVAL;
 }
 
+static ssize_t mxs_lradc_show_scale_available_ch(struct device *dev,
+		struct device_attribute *attr,
+		char *buf,
+		int ch)
+{
+	struct iio_dev *iio = dev_to_iio_dev(dev);
+	struct mxs_lradc *lradc = iio_priv(iio);
+	int i, len = 0;
+
+	for (i = 0; i < ARRAY_SIZE(lradc->scale_avail[ch]); i++)
+		len += sprintf(buf + len, "%d.%09u ",
+			       lradc->scale_avail[ch][i].integer,
+			       lradc->scale_avail[ch][i].nano);
+
+	len += sprintf(buf + len, "\n");
+
+	return len;
+}
+
+static ssize_t mxs_lradc_show_scale_available(struct device *dev,
+		struct device_attribute *attr,
+		char *buf)
+{
+	struct iio_dev_attr *iio_attr = to_iio_dev_attr(attr);
+
+	return mxs_lradc_show_scale_available_ch(dev, attr, buf,
+						 iio_attr->address);
+}
+
+#define SHOW_SCALE_AVAILABLE_ATTR(ch)					\
+static IIO_DEVICE_ATTR(in_voltage##ch##_scale_available, S_IRUGO,	\
+		       mxs_lradc_show_scale_available, NULL, ch)
+
+SHOW_SCALE_AVAILABLE_ATTR(0);
+SHOW_SCALE_AVAILABLE_ATTR(1);
+SHOW_SCALE_AVAILABLE_ATTR(2);
+SHOW_SCALE_AVAILABLE_ATTR(3);
+SHOW_SCALE_AVAILABLE_ATTR(4);
+SHOW_SCALE_AVAILABLE_ATTR(5);
+SHOW_SCALE_AVAILABLE_ATTR(6);
+SHOW_SCALE_AVAILABLE_ATTR(7);
+SHOW_SCALE_AVAILABLE_ATTR(8);
+SHOW_SCALE_AVAILABLE_ATTR(9);
+SHOW_SCALE_AVAILABLE_ATTR(10);
+SHOW_SCALE_AVAILABLE_ATTR(11);
+SHOW_SCALE_AVAILABLE_ATTR(12);
+SHOW_SCALE_AVAILABLE_ATTR(13);
+SHOW_SCALE_AVAILABLE_ATTR(14);
+SHOW_SCALE_AVAILABLE_ATTR(15);
+
+static struct attribute *mxs_lradc_attributes[] = {
+	&iio_dev_attr_in_voltage0_scale_available.dev_attr.attr,
+	&iio_dev_attr_in_voltage1_scale_available.dev_attr.attr,
+	&iio_dev_attr_in_voltage2_scale_available.dev_attr.attr,
+	&iio_dev_attr_in_voltage3_scale_available.dev_attr.attr,
+	&iio_dev_attr_in_voltage4_scale_available.dev_attr.attr,
+	&iio_dev_attr_in_voltage5_scale_available.dev_attr.attr,
+	&iio_dev_attr_in_voltage6_scale_available.dev_attr.attr,
+	&iio_dev_attr_in_voltage7_scale_available.dev_attr.attr,
+	&iio_dev_attr_in_voltage8_scale_available.dev_attr.attr,
+	&iio_dev_attr_in_voltage9_scale_available.dev_attr.attr,
+	&iio_dev_attr_in_voltage10_scale_available.dev_attr.attr,
+	&iio_dev_attr_in_voltage11_scale_available.dev_attr.attr,
+	&iio_dev_attr_in_voltage12_scale_available.dev_attr.attr,
+	&iio_dev_attr_in_voltage13_scale_available.dev_attr.attr,
+	&iio_dev_attr_in_voltage14_scale_available.dev_attr.attr,
+	&iio_dev_attr_in_voltage15_scale_available.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group mxs_lradc_attribute_group = {
+	.attrs = mxs_lradc_attributes,
+};
+
 static const struct iio_info mxs_lradc_iio_info = {
 	.driver_module		= THIS_MODULE,
 	.read_raw		= mxs_lradc_read_raw,
+	.attrs			= &mxs_lradc_attribute_group,
 };
 
 static int mxs_lradc_ts_open(struct input_dev *dev)
@@ -1241,6 +1323,7 @@ static const struct iio_buffer_setup_ops mxs_lradc_buffer_ops = {
 	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |		\
 			      BIT(IIO_CHAN_INFO_SCALE),		\
 	.channel = (idx),					\
+	.address = (idx),					\
 	.scan_type = {						\
 		.sign = 'u',					\
 		.realbits = LRADC_RESOLUTION,			\
@@ -1386,7 +1469,8 @@ static int mxs_lradc_probe(struct platform_device *pdev)
 	struct iio_dev *iio;
 	struct resource *iores;
 	int ret = 0, touch_ret;
-	int i;
+	int i, s;
+	unsigned int scale_uv;
 
 	/* Allocate the IIO device. */
 	iio = devm_iio_device_alloc(dev, sizeof(*lradc));
@@ -1456,6 +1540,26 @@ static int mxs_lradc_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_trig;
 
+	/* Populate available ADC input ranges */
+	for (i = 0; i < LRADC_MAX_TOTAL_CHANS; i++) {
+		for (s = 0; s < ARRAY_SIZE(lradc->scale_avail[i]); s++) {
+			/*
+			 * [s=0] = optional divider by two disabled (default)
+			 * [s=1] = optional divider by two enabled
+			 *
+			 * The scale is calculated by doing:
+			 *   Vref >> (realbits - s)
+			 * which multiplies by two on the second component
+			 * of the array.
+			 */
+			scale_uv = ((u64)lradc->vref_mv[i] * 100000000) >>
+				   (iio->channels[i].scan_type.realbits - s);
+			lradc->scale_avail[i][s].nano =
+					do_div(scale_uv, 100000000) * 10;
+			lradc->scale_avail[i][s].integer = scale_uv;
+		}
+	}
+
 	/* Configure the hardware. */
 	ret = mxs_lradc_hw_init(lradc);
 	if (ret)
-- 
1.8.3.2


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

* [PATCHv5 RESEND 3/4] iio: mxs-lradc: add write_raw function to modify scale
  2013-12-23 17:48 [PATCHv5 RESEND 0/4] iio: mxs-lradc: add support to optional divider_by_two Alexandre Belloni
  2013-12-23 17:48 ` [PATCHv5 RESEND 1/4] iio: mxs-lradc: add scale attribute to channels Alexandre Belloni
  2013-12-23 17:48 ` [PATCHv5 RESEND 2/4] iio: mxs-lradc: add scale_available file " Alexandre Belloni
@ 2013-12-23 17:48 ` Alexandre Belloni
  2014-01-01 14:29   ` Jonathan Cameron
  2013-12-23 17:48 ` [PATCHv5 RESEND 4/4] iio: mxs-lradc: convert is_divided to a bitmap Alexandre Belloni
  2013-12-23 18:54 ` [PATCHv5 RESEND 0/4] iio: mxs-lradc: add support to optional divider_by_two Marek Vasut
  4 siblings, 1 reply; 15+ messages in thread
From: Alexandre Belloni @ 2013-12-23 17:48 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: lars, Marek Vasut, harald, hector.palacios, linux-iio,
	linux-kernel, Alexandre Belloni

From: Hector Palacios <hector.palacios@digi.com>

Added write_raw function to manipulate the optional divider_by_two
through the scaling attribute out of the available scales.

Signed-off-by: Hector Palacios <hector.palacios@digi.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Acked-by: Marek Vasut <marex@denx.de>

---
 drivers/staging/iio/adc/mxs-lradc.c | 62 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 61 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c
index c63b312e54fd..a58c6aaa94d3 100644
--- a/drivers/staging/iio/adc/mxs-lradc.c
+++ b/drivers/staging/iio/adc/mxs-lradc.c
@@ -185,6 +185,11 @@ enum lradc_ts_plate {
 	LRADC_SAMPLE_VALID,
 };
 
+enum mxs_lradc_divbytwo {
+	MXS_LRADC_DIV_DISABLED = 0,
+	MXS_LRADC_DIV_ENABLED,
+};
+
 struct mxs_lradc_scale {
 	unsigned int		integer;
 	unsigned int		nano;
@@ -206,6 +211,7 @@ struct mxs_lradc {
 
 	const uint32_t		*vref_mv;
 	struct mxs_lradc_scale	scale_avail[LRADC_MAX_TOTAL_CHANS][2];
+	unsigned int		is_divided[LRADC_MAX_TOTAL_CHANS];
 
 	/*
 	 * Touchscreen LRADC channels receives a private slot in the CTRL4
@@ -295,6 +301,7 @@ struct mxs_lradc {
 #define	LRADC_CTRL1_LRADC_IRQ_OFFSET		0
 
 #define	LRADC_CTRL2				0x20
+#define	LRADC_CTRL2_DIVIDE_BY_TWO_OFFSET	24
 #define	LRADC_CTRL2_TEMPSENSE_PWD		(1 << 15)
 
 #define	LRADC_STATUS				0x40
@@ -912,7 +919,8 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
 		}
 
 		*val = lradc->vref_mv[chan->channel];
-		*val2 = chan->scan_type.realbits;
+		*val2 = chan->scan_type.realbits -
+			lradc->is_divided[chan->channel];
 		return IIO_VAL_FRACTIONAL_LOG2;
 
 	case IIO_CHAN_INFO_OFFSET:
@@ -936,6 +944,56 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
 	return -EINVAL;
 }
 
+static int mxs_lradc_write_raw(struct iio_dev *iio_dev,
+			       const struct iio_chan_spec *chan,
+			       int val, int val2, long m)
+{
+	struct mxs_lradc *lradc = iio_priv(iio_dev);
+	struct mxs_lradc_scale *scale_avail =
+			lradc->scale_avail[chan->channel];
+	int ret;
+
+	ret = mutex_trylock(&lradc->lock);
+	if (!ret)
+		return -EBUSY;
+
+	switch (m) {
+	case IIO_CHAN_INFO_SCALE:
+		ret = -EINVAL;
+		if (val == scale_avail[MXS_LRADC_DIV_DISABLED].integer &&
+		    val2 == scale_avail[MXS_LRADC_DIV_DISABLED].nano) {
+			/* divider by two disabled */
+			writel(1 << LRADC_CTRL2_DIVIDE_BY_TWO_OFFSET,
+			       lradc->base + LRADC_CTRL2 + STMP_OFFSET_REG_CLR);
+			lradc->is_divided[chan->channel] = 0;
+			ret = 0;
+		} else if (val == scale_avail[MXS_LRADC_DIV_ENABLED].integer &&
+			   val2 == scale_avail[MXS_LRADC_DIV_ENABLED].nano) {
+			/* divider by two enabled */
+			writel(1 << LRADC_CTRL2_DIVIDE_BY_TWO_OFFSET,
+			       lradc->base + LRADC_CTRL2 + STMP_OFFSET_REG_SET);
+			lradc->is_divided[chan->channel] = 1;
+			ret = 0;
+		}
+
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+	mutex_unlock(&lradc->lock);
+
+	return ret;
+}
+
+static int mxs_lradc_write_raw_get_fmt(struct iio_dev *iio_dev,
+				       const struct iio_chan_spec *chan,
+				       long m)
+{
+	return IIO_VAL_INT_PLUS_NANO;
+}
+
 static ssize_t mxs_lradc_show_scale_available_ch(struct device *dev,
 		struct device_attribute *attr,
 		char *buf,
@@ -1013,6 +1071,8 @@ static const struct attribute_group mxs_lradc_attribute_group = {
 static const struct iio_info mxs_lradc_iio_info = {
 	.driver_module		= THIS_MODULE,
 	.read_raw		= mxs_lradc_read_raw,
+	.write_raw		= mxs_lradc_write_raw,
+	.write_raw_get_fmt	= mxs_lradc_write_raw_get_fmt,
 	.attrs			= &mxs_lradc_attribute_group,
 };
 
-- 
1.8.3.2


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

* [PATCHv5 RESEND 4/4] iio: mxs-lradc: convert is_divided to a bitmap
  2013-12-23 17:48 [PATCHv5 RESEND 0/4] iio: mxs-lradc: add support to optional divider_by_two Alexandre Belloni
                   ` (2 preceding siblings ...)
  2013-12-23 17:48 ` [PATCHv5 RESEND 3/4] iio: mxs-lradc: add write_raw function to modify scale Alexandre Belloni
@ 2013-12-23 17:48 ` Alexandre Belloni
  2014-01-01 14:31   ` Jonathan Cameron
  2013-12-23 18:54 ` [PATCHv5 RESEND 0/4] iio: mxs-lradc: add support to optional divider_by_two Marek Vasut
  4 siblings, 1 reply; 15+ messages in thread
From: Alexandre Belloni @ 2013-12-23 17:48 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: lars, Marek Vasut, harald, hector.palacios, linux-iio,
	linux-kernel, Alexandre Belloni

mxs_lradc.is_divided was an unsigned long array. Convert it to a bitmap to save
some memory.

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
 drivers/staging/iio/adc/mxs-lradc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c
index a58c6aaa94d3..df71669bb60e 100644
--- a/drivers/staging/iio/adc/mxs-lradc.c
+++ b/drivers/staging/iio/adc/mxs-lradc.c
@@ -211,7 +211,7 @@ struct mxs_lradc {
 
 	const uint32_t		*vref_mv;
 	struct mxs_lradc_scale	scale_avail[LRADC_MAX_TOTAL_CHANS][2];
-	unsigned int		is_divided[LRADC_MAX_TOTAL_CHANS];
+	unsigned long		is_divided;
 
 	/*
 	 * Touchscreen LRADC channels receives a private slot in the CTRL4
@@ -920,7 +920,7 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
 
 		*val = lradc->vref_mv[chan->channel];
 		*val2 = chan->scan_type.realbits -
-			lradc->is_divided[chan->channel];
+			test_bit(chan->channel, &lradc->is_divided);
 		return IIO_VAL_FRACTIONAL_LOG2;
 
 	case IIO_CHAN_INFO_OFFSET:
@@ -965,14 +965,14 @@ static int mxs_lradc_write_raw(struct iio_dev *iio_dev,
 			/* divider by two disabled */
 			writel(1 << LRADC_CTRL2_DIVIDE_BY_TWO_OFFSET,
 			       lradc->base + LRADC_CTRL2 + STMP_OFFSET_REG_CLR);
-			lradc->is_divided[chan->channel] = 0;
+			clear_bit(chan->channel, &lradc->is_divided);
 			ret = 0;
 		} else if (val == scale_avail[MXS_LRADC_DIV_ENABLED].integer &&
 			   val2 == scale_avail[MXS_LRADC_DIV_ENABLED].nano) {
 			/* divider by two enabled */
 			writel(1 << LRADC_CTRL2_DIVIDE_BY_TWO_OFFSET,
 			       lradc->base + LRADC_CTRL2 + STMP_OFFSET_REG_SET);
-			lradc->is_divided[chan->channel] = 1;
+			set_bit(chan->channel, &lradc->is_divided);
 			ret = 0;
 		}
 
-- 
1.8.3.2


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

* Re: [PATCHv5 RESEND 0/4] iio: mxs-lradc: add support to optional divider_by_two
  2013-12-23 17:48 [PATCHv5 RESEND 0/4] iio: mxs-lradc: add support to optional divider_by_two Alexandre Belloni
                   ` (3 preceding siblings ...)
  2013-12-23 17:48 ` [PATCHv5 RESEND 4/4] iio: mxs-lradc: convert is_divided to a bitmap Alexandre Belloni
@ 2013-12-23 18:54 ` Marek Vasut
  2013-12-23 19:22   ` Alexandre Belloni
  4 siblings, 1 reply; 15+ messages in thread
From: Marek Vasut @ 2013-12-23 18:54 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Jonathan Cameron, lars, harald, hector.palacios, linux-iio, linux-kernel

On Monday, December 23, 2013 at 06:48:00 PM, Alexandre Belloni wrote:
> Hello,
> 
> This is v5 of the patchset that adds support to the optional divider_by_two
> of LRADC channels.
> 
> Changes since v4:
>  - moved enum mxs_lradc_divbytwo to the third patch
>  - added a fourth patch to convert is_divided to a bitmap. I did that in a
>    separated patch for review and copyright attribution purposes.
> 
> This was tested on a custom i.MX28 platform.
> 
> Alexandre Belloni (1):
>   iio: mxs-lradc: convert is_divided to a bitmap
> 
> Hector Palacios (3):
>   iio: mxs-lradc: add scale attribute to channels
>   iio: mxs-lradc: add scale_available file to channels
>   iio: mxs-lradc: add write_raw function to modify scale
> 
>  drivers/staging/iio/adc/mxs-lradc.c | 222
> +++++++++++++++++++++++++++++++++++- 1 file changed, 219 insertions(+), 3
> deletions(-)

Why is there a resend please ?

Best regards,
Marek Vasut

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

* Re: [PATCHv5 RESEND 0/4] iio: mxs-lradc: add support to optional divider_by_two
  2013-12-23 18:54 ` [PATCHv5 RESEND 0/4] iio: mxs-lradc: add support to optional divider_by_two Marek Vasut
@ 2013-12-23 19:22   ` Alexandre Belloni
  2013-12-24  1:50     ` Marek Vasut
  0 siblings, 1 reply; 15+ messages in thread
From: Alexandre Belloni @ 2013-12-23 19:22 UTC (permalink / raw)
  To: Marek Vasut
  Cc: Jonathan Cameron, lars, harald, hector.palacios, linux-iio, linux-kernel

On 23/12/2013 19:54, Marek Vasut wrote:
> On Monday, December 23, 2013 at 06:48:00 PM, Alexandre Belloni wrote:
>> Hello,
>>
>> This is v5 of the patchset that adds support to the optional divider_by_two
>> of LRADC channels.
>>
>> Changes since v4:
>>  - moved enum mxs_lradc_divbytwo to the third patch
>>  - added a fourth patch to convert is_divided to a bitmap. I did that in a
>>    separated patch for review and copyright attribution purposes.
>>
>> This was tested on a custom i.MX28 platform.
>>
>> Alexandre Belloni (1):
>>   iio: mxs-lradc: convert is_divided to a bitmap
>>
>> Hector Palacios (3):
>>   iio: mxs-lradc: add scale attribute to channels
>>   iio: mxs-lradc: add scale_available file to channels
>>   iio: mxs-lradc: add write_raw function to modify scale
>>
>>  drivers/staging/iio/adc/mxs-lradc.c | 222
>> +++++++++++++++++++++++++++++++++++- 1 file changed, 219 insertions(+), 3
>> deletions(-)
> Why is there a resend please ?

I don't know how but I screwed Jonathan's mail address. As he is the
main maintainer, I though it would be a good idea to get his attention.


>
> Best regards,
> Marek Vasut


-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com


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

* Re: [PATCHv5 RESEND 0/4] iio: mxs-lradc: add support to optional divider_by_two
  2013-12-23 19:22   ` Alexandre Belloni
@ 2013-12-24  1:50     ` Marek Vasut
  0 siblings, 0 replies; 15+ messages in thread
From: Marek Vasut @ 2013-12-24  1:50 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Jonathan Cameron, lars, harald, hector.palacios, linux-iio, linux-kernel

On Monday, December 23, 2013 at 08:22:04 PM, Alexandre Belloni wrote:
> On 23/12/2013 19:54, Marek Vasut wrote:
> > On Monday, December 23, 2013 at 06:48:00 PM, Alexandre Belloni wrote:
> >> Hello,
> >> 
> >> This is v5 of the patchset that adds support to the optional
> >> divider_by_two of LRADC channels.
> >> 
> >> Changes since v4:
> >>  - moved enum mxs_lradc_divbytwo to the third patch
> >>  - added a fourth patch to convert is_divided to a bitmap. I did that in
> >>  a
> >>  
> >>    separated patch for review and copyright attribution purposes.
> >> 
> >> This was tested on a custom i.MX28 platform.
> >> 
> >> Alexandre Belloni (1):
> >>   iio: mxs-lradc: convert is_divided to a bitmap
> >> 
> >> Hector Palacios (3):
> >>   iio: mxs-lradc: add scale attribute to channels
> >>   iio: mxs-lradc: add scale_available file to channels
> >>   iio: mxs-lradc: add write_raw function to modify scale
> >>  
> >>  drivers/staging/iio/adc/mxs-lradc.c | 222
> >> 
> >> +++++++++++++++++++++++++++++++++++- 1 file changed, 219 insertions(+),
> >> 3 deletions(-)
> > 
> > Why is there a resend please ?
> 
> I don't know how but I screwed Jonathan's mail address. As he is the
> main maintainer, I though it would be a good idea to get his attention.

Ah, now I see that ^C there :)

btw. I wish you a Merry Christmas and a happy New Year, guys!

Best regards,
Marek Vasut

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

* Re: [PATCHv5 RESEND 1/4] iio: mxs-lradc: add scale attribute to channels
  2013-12-23 17:48 ` [PATCHv5 RESEND 1/4] iio: mxs-lradc: add scale attribute to channels Alexandre Belloni
@ 2014-01-01 14:25   ` Jonathan Cameron
  0 siblings, 0 replies; 15+ messages in thread
From: Jonathan Cameron @ 2014-01-01 14:25 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: lars, Marek Vasut, harald, hector.palacios, linux-iio, linux-kernel



On 23/12/13 17:48, Alexandre Belloni wrote:
> From: Hector Palacios <hector.palacios@digi.com>
>
> Some LRADC channels have fixed pre-dividers and all have an optional
> divider by two which allows a maximum input voltage of VDDIO - 50mV.
>
> This patch
>   - adds the scaling info flag to all channels
>   - grabs the max reference voltage per channel
>     (where the fixed pre-dividers apply)
>   - allows to read the scaling attribute (computed from the Vref)
>
> Signed-off-by: Hector Palacios <hector.palacios@digi.com>.
> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> Acked-by: Marek Vasut <marex@denx.de>
Applied to the togreg branch of iio.git - initially pushed out as 
testing for the autobuilders to do their magic.

Jonathan
>
> ---
>   drivers/staging/iio/adc/mxs-lradc.c | 56 +++++++++++++++++++++++++++++++++++--
>   1 file changed, 54 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c
> index 5a4499c3d22a..22fef0a408db 100644
> --- a/drivers/staging/iio/adc/mxs-lradc.c
> +++ b/drivers/staging/iio/adc/mxs-lradc.c
> @@ -111,16 +111,59 @@ static const char * const mx28_lradc_irq_names[] = {
>   struct mxs_lradc_of_config {
>   	const int		irq_count;
>   	const char * const	*irq_name;
> +	const uint32_t		*vref_mv;
> +};
> +
> +#define VREF_MV_BASE 1850
> +
> +static const uint32_t mx23_vref_mv[LRADC_MAX_TOTAL_CHANS] = {
> +	VREF_MV_BASE,		/* CH0 */
> +	VREF_MV_BASE,		/* CH1 */
> +	VREF_MV_BASE,		/* CH2 */
> +	VREF_MV_BASE,		/* CH3 */
> +	VREF_MV_BASE,		/* CH4 */
> +	VREF_MV_BASE,		/* CH5 */
> +	VREF_MV_BASE * 2,	/* CH6 VDDIO */
> +	VREF_MV_BASE * 4,	/* CH7 VBATT */
> +	VREF_MV_BASE,		/* CH8 Temp sense 0 */
> +	VREF_MV_BASE,		/* CH9 Temp sense 1 */
> +	VREF_MV_BASE,		/* CH10 */
> +	VREF_MV_BASE,		/* CH11 */
> +	VREF_MV_BASE,		/* CH12 USB_DP */
> +	VREF_MV_BASE,		/* CH13 USB_DN */
> +	VREF_MV_BASE,		/* CH14 VBG */
> +	VREF_MV_BASE * 4,	/* CH15 VDD5V */
> +};
> +
> +static const uint32_t mx28_vref_mv[LRADC_MAX_TOTAL_CHANS] = {
> +	VREF_MV_BASE,		/* CH0 */
> +	VREF_MV_BASE,		/* CH1 */
> +	VREF_MV_BASE,		/* CH2 */
> +	VREF_MV_BASE,		/* CH3 */
> +	VREF_MV_BASE,		/* CH4 */
> +	VREF_MV_BASE,		/* CH5 */
> +	VREF_MV_BASE,		/* CH6 */
> +	VREF_MV_BASE * 4,	/* CH7 VBATT */
> +	VREF_MV_BASE,		/* CH8 Temp sense 0 */
> +	VREF_MV_BASE,		/* CH9 Temp sense 1 */
> +	VREF_MV_BASE * 2,	/* CH10 VDDIO */
> +	VREF_MV_BASE,		/* CH11 VTH */
> +	VREF_MV_BASE * 2,	/* CH12 VDDA */
> +	VREF_MV_BASE,		/* CH13 VDDD */
> +	VREF_MV_BASE,		/* CH14 VBG */
> +	VREF_MV_BASE * 4,	/* CH15 VDD5V */
>   };
>
>   static const struct mxs_lradc_of_config mxs_lradc_of_config[] = {
>   	[IMX23_LRADC] = {
>   		.irq_count	= ARRAY_SIZE(mx23_lradc_irq_names),
>   		.irq_name	= mx23_lradc_irq_names,
> +		.vref_mv	= mx23_vref_mv,
>   	},
>   	[IMX28_LRADC] = {
>   		.irq_count	= ARRAY_SIZE(mx28_lradc_irq_names),
>   		.irq_name	= mx28_lradc_irq_names,
> +		.vref_mv	= mx28_vref_mv,
>   	},
>   };
>
> @@ -155,6 +198,8 @@ struct mxs_lradc {
>
>   	struct completion	completion;
>
> +	const uint32_t		*vref_mv;
> +
>   	/*
>   	 * Touchscreen LRADC channels receives a private slot in the CTRL4
>   	 * register, the slot #7. Therefore only 7 slots instead of 8 in the
> @@ -836,6 +881,8 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
>   			const struct iio_chan_spec *chan,
>   			int *val, int *val2, long m)
>   {
> +	struct mxs_lradc *lradc = iio_priv(iio_dev);
> +
>   	/* Check for invalid channel */
>   	if (chan->channel > LRADC_MAX_TOTAL_CHANS)
>   		return -EINVAL;
> @@ -857,7 +904,9 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
>   			return IIO_VAL_INT_PLUS_MICRO;
>   		}
>
> -		return -EINVAL;
> +		*val = lradc->vref_mv[chan->channel];
> +		*val2 = chan->scan_type.realbits;
> +		return IIO_VAL_FRACTIONAL_LOG2;
>
>   	case IIO_CHAN_INFO_OFFSET:
>   		if (chan->type == IIO_TEMP) {
> @@ -1189,7 +1238,8 @@ static const struct iio_buffer_setup_ops mxs_lradc_buffer_ops = {
>   	.type = (chan_type),					\
>   	.indexed = 1,						\
>   	.scan_index = (idx),					\
> -	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),		\
> +	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |		\
> +			      BIT(IIO_CHAN_INFO_SCALE),		\
>   	.channel = (idx),					\
>   	.scan_type = {						\
>   		.sign = 'u',					\
> @@ -1381,6 +1431,8 @@ static int mxs_lradc_probe(struct platform_device *pdev)
>   			return ret;
>   	}
>
> +	lradc->vref_mv = of_cfg->vref_mv;
> +
>   	platform_set_drvdata(pdev, iio);
>
>   	init_completion(&lradc->completion);
>

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

* Re: [PATCHv5 RESEND 2/4] iio: mxs-lradc: add scale_available file to channels
  2013-12-23 17:48 ` [PATCHv5 RESEND 2/4] iio: mxs-lradc: add scale_available file " Alexandre Belloni
@ 2014-01-01 14:28   ` Jonathan Cameron
  0 siblings, 0 replies; 15+ messages in thread
From: Jonathan Cameron @ 2014-01-01 14:28 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: lars, Marek Vasut, harald, hector.palacios, linux-iio, linux-kernel



On 23/12/13 17:48, Alexandre Belloni wrote:
> From: Hector Palacios <hector.palacios@digi.com>
>
> Adds in_voltageX_scale_available file for every channel to read
> the different available scales.
> There are two scales per channel:
>   [0] = divider_by_two disabled (default)
>   [1] = divider_by_two enabled
> The scale is a struct made of integer and nano parts to build
> a long decimal number.
>
> Signed-off-by: Hector Palacios <hector.palacios@digi.com>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> Acked-by: Marek Vasut <marex@denx.de>
Applied to the togreg branch of iio.git (pushed out as testing for now)

Thanks
>
> ---
>   drivers/staging/iio/adc/mxs-lradc.c | 106 +++++++++++++++++++++++++++++++++++-
>   1 file changed, 105 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c
> index 22fef0a408db..c63b312e54fd 100644
> --- a/drivers/staging/iio/adc/mxs-lradc.c
> +++ b/drivers/staging/iio/adc/mxs-lradc.c
> @@ -38,6 +38,7 @@
>   #include <linux/clk.h>
>
>   #include <linux/iio/iio.h>
> +#include <linux/iio/sysfs.h>
>   #include <linux/iio/buffer.h>
>   #include <linux/iio/trigger.h>
>   #include <linux/iio/trigger_consumer.h>
> @@ -184,6 +185,11 @@ enum lradc_ts_plate {
>   	LRADC_SAMPLE_VALID,
>   };
>
> +struct mxs_lradc_scale {
> +	unsigned int		integer;
> +	unsigned int		nano;
> +};
> +
>   struct mxs_lradc {
>   	struct device		*dev;
>   	void __iomem		*base;
> @@ -199,6 +205,7 @@ struct mxs_lradc {
>   	struct completion	completion;
>
>   	const uint32_t		*vref_mv;
> +	struct mxs_lradc_scale	scale_avail[LRADC_MAX_TOTAL_CHANS][2];
>
>   	/*
>   	 * Touchscreen LRADC channels receives a private slot in the CTRL4
> @@ -929,9 +936,84 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
>   	return -EINVAL;
>   }
>
> +static ssize_t mxs_lradc_show_scale_available_ch(struct device *dev,
> +		struct device_attribute *attr,
> +		char *buf,
> +		int ch)
> +{
> +	struct iio_dev *iio = dev_to_iio_dev(dev);
> +	struct mxs_lradc *lradc = iio_priv(iio);
> +	int i, len = 0;
> +
> +	for (i = 0; i < ARRAY_SIZE(lradc->scale_avail[ch]); i++)
> +		len += sprintf(buf + len, "%d.%09u ",
> +			       lradc->scale_avail[ch][i].integer,
> +			       lradc->scale_avail[ch][i].nano);
> +
> +	len += sprintf(buf + len, "\n");
> +
> +	return len;
> +}
> +
> +static ssize_t mxs_lradc_show_scale_available(struct device *dev,
> +		struct device_attribute *attr,
> +		char *buf)
> +{
> +	struct iio_dev_attr *iio_attr = to_iio_dev_attr(attr);
> +
> +	return mxs_lradc_show_scale_available_ch(dev, attr, buf,
> +						 iio_attr->address);
> +}
> +
> +#define SHOW_SCALE_AVAILABLE_ATTR(ch)					\
> +static IIO_DEVICE_ATTR(in_voltage##ch##_scale_available, S_IRUGO,	\
> +		       mxs_lradc_show_scale_available, NULL, ch)
> +
> +SHOW_SCALE_AVAILABLE_ATTR(0);
> +SHOW_SCALE_AVAILABLE_ATTR(1);
> +SHOW_SCALE_AVAILABLE_ATTR(2);
> +SHOW_SCALE_AVAILABLE_ATTR(3);
> +SHOW_SCALE_AVAILABLE_ATTR(4);
> +SHOW_SCALE_AVAILABLE_ATTR(5);
> +SHOW_SCALE_AVAILABLE_ATTR(6);
> +SHOW_SCALE_AVAILABLE_ATTR(7);
> +SHOW_SCALE_AVAILABLE_ATTR(8);
> +SHOW_SCALE_AVAILABLE_ATTR(9);
> +SHOW_SCALE_AVAILABLE_ATTR(10);
> +SHOW_SCALE_AVAILABLE_ATTR(11);
> +SHOW_SCALE_AVAILABLE_ATTR(12);
> +SHOW_SCALE_AVAILABLE_ATTR(13);
> +SHOW_SCALE_AVAILABLE_ATTR(14);
> +SHOW_SCALE_AVAILABLE_ATTR(15);
> +
> +static struct attribute *mxs_lradc_attributes[] = {
> +	&iio_dev_attr_in_voltage0_scale_available.dev_attr.attr,
> +	&iio_dev_attr_in_voltage1_scale_available.dev_attr.attr,
> +	&iio_dev_attr_in_voltage2_scale_available.dev_attr.attr,
> +	&iio_dev_attr_in_voltage3_scale_available.dev_attr.attr,
> +	&iio_dev_attr_in_voltage4_scale_available.dev_attr.attr,
> +	&iio_dev_attr_in_voltage5_scale_available.dev_attr.attr,
> +	&iio_dev_attr_in_voltage6_scale_available.dev_attr.attr,
> +	&iio_dev_attr_in_voltage7_scale_available.dev_attr.attr,
> +	&iio_dev_attr_in_voltage8_scale_available.dev_attr.attr,
> +	&iio_dev_attr_in_voltage9_scale_available.dev_attr.attr,
> +	&iio_dev_attr_in_voltage10_scale_available.dev_attr.attr,
> +	&iio_dev_attr_in_voltage11_scale_available.dev_attr.attr,
> +	&iio_dev_attr_in_voltage12_scale_available.dev_attr.attr,
> +	&iio_dev_attr_in_voltage13_scale_available.dev_attr.attr,
> +	&iio_dev_attr_in_voltage14_scale_available.dev_attr.attr,
> +	&iio_dev_attr_in_voltage15_scale_available.dev_attr.attr,
> +	NULL
> +};
> +
> +static const struct attribute_group mxs_lradc_attribute_group = {
> +	.attrs = mxs_lradc_attributes,
> +};
> +
>   static const struct iio_info mxs_lradc_iio_info = {
>   	.driver_module		= THIS_MODULE,
>   	.read_raw		= mxs_lradc_read_raw,
> +	.attrs			= &mxs_lradc_attribute_group,
>   };
>
>   static int mxs_lradc_ts_open(struct input_dev *dev)
> @@ -1241,6 +1323,7 @@ static const struct iio_buffer_setup_ops mxs_lradc_buffer_ops = {
>   	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |		\
>   			      BIT(IIO_CHAN_INFO_SCALE),		\
>   	.channel = (idx),					\
> +	.address = (idx),					\
>   	.scan_type = {						\
>   		.sign = 'u',					\
>   		.realbits = LRADC_RESOLUTION,			\
> @@ -1386,7 +1469,8 @@ static int mxs_lradc_probe(struct platform_device *pdev)
>   	struct iio_dev *iio;
>   	struct resource *iores;
>   	int ret = 0, touch_ret;
> -	int i;
> +	int i, s;
> +	unsigned int scale_uv;
>
>   	/* Allocate the IIO device. */
>   	iio = devm_iio_device_alloc(dev, sizeof(*lradc));
> @@ -1456,6 +1540,26 @@ static int mxs_lradc_probe(struct platform_device *pdev)
>   	if (ret)
>   		goto err_trig;
>
> +	/* Populate available ADC input ranges */
> +	for (i = 0; i < LRADC_MAX_TOTAL_CHANS; i++) {
> +		for (s = 0; s < ARRAY_SIZE(lradc->scale_avail[i]); s++) {
> +			/*
> +			 * [s=0] = optional divider by two disabled (default)
> +			 * [s=1] = optional divider by two enabled
> +			 *
> +			 * The scale is calculated by doing:
> +			 *   Vref >> (realbits - s)
> +			 * which multiplies by two on the second component
> +			 * of the array.
> +			 */
> +			scale_uv = ((u64)lradc->vref_mv[i] * 100000000) >>
> +				   (iio->channels[i].scan_type.realbits - s);
> +			lradc->scale_avail[i][s].nano =
> +					do_div(scale_uv, 100000000) * 10;
> +			lradc->scale_avail[i][s].integer = scale_uv;
> +		}
> +	}
> +
>   	/* Configure the hardware. */
>   	ret = mxs_lradc_hw_init(lradc);
>   	if (ret)
>

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

* Re: [PATCHv5 RESEND 3/4] iio: mxs-lradc: add write_raw function to modify scale
  2013-12-23 17:48 ` [PATCHv5 RESEND 3/4] iio: mxs-lradc: add write_raw function to modify scale Alexandre Belloni
@ 2014-01-01 14:29   ` Jonathan Cameron
  0 siblings, 0 replies; 15+ messages in thread
From: Jonathan Cameron @ 2014-01-01 14:29 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: lars, Marek Vasut, harald, hector.palacios, linux-iio, linux-kernel



On 23/12/13 17:48, Alexandre Belloni wrote:
> From: Hector Palacios <hector.palacios@digi.com>
>
> Added write_raw function to manipulate the optional divider_by_two
> through the scaling attribute out of the available scales.
>
> Signed-off-by: Hector Palacios <hector.palacios@digi.com>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> Acked-by: Marek Vasut <marex@denx.de>
Applied to the togreg branch of iio.git

Thanks for your hard work on these!

Jonathan
>
> ---
>   drivers/staging/iio/adc/mxs-lradc.c | 62 ++++++++++++++++++++++++++++++++++++-
>   1 file changed, 61 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c
> index c63b312e54fd..a58c6aaa94d3 100644
> --- a/drivers/staging/iio/adc/mxs-lradc.c
> +++ b/drivers/staging/iio/adc/mxs-lradc.c
> @@ -185,6 +185,11 @@ enum lradc_ts_plate {
>   	LRADC_SAMPLE_VALID,
>   };
>
> +enum mxs_lradc_divbytwo {
> +	MXS_LRADC_DIV_DISABLED = 0,
> +	MXS_LRADC_DIV_ENABLED,
> +};
> +
>   struct mxs_lradc_scale {
>   	unsigned int		integer;
>   	unsigned int		nano;
> @@ -206,6 +211,7 @@ struct mxs_lradc {
>
>   	const uint32_t		*vref_mv;
>   	struct mxs_lradc_scale	scale_avail[LRADC_MAX_TOTAL_CHANS][2];
> +	unsigned int		is_divided[LRADC_MAX_TOTAL_CHANS];
>
>   	/*
>   	 * Touchscreen LRADC channels receives a private slot in the CTRL4
> @@ -295,6 +301,7 @@ struct mxs_lradc {
>   #define	LRADC_CTRL1_LRADC_IRQ_OFFSET		0
>
>   #define	LRADC_CTRL2				0x20
> +#define	LRADC_CTRL2_DIVIDE_BY_TWO_OFFSET	24
>   #define	LRADC_CTRL2_TEMPSENSE_PWD		(1 << 15)
>
>   #define	LRADC_STATUS				0x40
> @@ -912,7 +919,8 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
>   		}
>
>   		*val = lradc->vref_mv[chan->channel];
> -		*val2 = chan->scan_type.realbits;
> +		*val2 = chan->scan_type.realbits -
> +			lradc->is_divided[chan->channel];
>   		return IIO_VAL_FRACTIONAL_LOG2;
>
>   	case IIO_CHAN_INFO_OFFSET:
> @@ -936,6 +944,56 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
>   	return -EINVAL;
>   }
>
> +static int mxs_lradc_write_raw(struct iio_dev *iio_dev,
> +			       const struct iio_chan_spec *chan,
> +			       int val, int val2, long m)
> +{
> +	struct mxs_lradc *lradc = iio_priv(iio_dev);
> +	struct mxs_lradc_scale *scale_avail =
> +			lradc->scale_avail[chan->channel];
> +	int ret;
> +
> +	ret = mutex_trylock(&lradc->lock);
> +	if (!ret)
> +		return -EBUSY;
> +
> +	switch (m) {
> +	case IIO_CHAN_INFO_SCALE:
> +		ret = -EINVAL;
> +		if (val == scale_avail[MXS_LRADC_DIV_DISABLED].integer &&
> +		    val2 == scale_avail[MXS_LRADC_DIV_DISABLED].nano) {
> +			/* divider by two disabled */
> +			writel(1 << LRADC_CTRL2_DIVIDE_BY_TWO_OFFSET,
> +			       lradc->base + LRADC_CTRL2 + STMP_OFFSET_REG_CLR);
> +			lradc->is_divided[chan->channel] = 0;
> +			ret = 0;
> +		} else if (val == scale_avail[MXS_LRADC_DIV_ENABLED].integer &&
> +			   val2 == scale_avail[MXS_LRADC_DIV_ENABLED].nano) {
> +			/* divider by two enabled */
> +			writel(1 << LRADC_CTRL2_DIVIDE_BY_TWO_OFFSET,
> +			       lradc->base + LRADC_CTRL2 + STMP_OFFSET_REG_SET);
> +			lradc->is_divided[chan->channel] = 1;
> +			ret = 0;
> +		}
> +
> +		break;
> +	default:
> +		ret = -EINVAL;
> +		break;
> +	}
> +
> +	mutex_unlock(&lradc->lock);
> +
> +	return ret;
> +}
> +
> +static int mxs_lradc_write_raw_get_fmt(struct iio_dev *iio_dev,
> +				       const struct iio_chan_spec *chan,
> +				       long m)
> +{
> +	return IIO_VAL_INT_PLUS_NANO;
> +}
> +
>   static ssize_t mxs_lradc_show_scale_available_ch(struct device *dev,
>   		struct device_attribute *attr,
>   		char *buf,
> @@ -1013,6 +1071,8 @@ static const struct attribute_group mxs_lradc_attribute_group = {
>   static const struct iio_info mxs_lradc_iio_info = {
>   	.driver_module		= THIS_MODULE,
>   	.read_raw		= mxs_lradc_read_raw,
> +	.write_raw		= mxs_lradc_write_raw,
> +	.write_raw_get_fmt	= mxs_lradc_write_raw_get_fmt,
>   	.attrs			= &mxs_lradc_attribute_group,
>   };
>
>

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

* Re: [PATCHv5 RESEND 4/4] iio: mxs-lradc: convert is_divided to a bitmap
  2013-12-23 17:48 ` [PATCHv5 RESEND 4/4] iio: mxs-lradc: convert is_divided to a bitmap Alexandre Belloni
@ 2014-01-01 14:31   ` Jonathan Cameron
  2014-01-01 19:31     ` Marek Vasut
  0 siblings, 1 reply; 15+ messages in thread
From: Jonathan Cameron @ 2014-01-01 14:31 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: lars, Marek Vasut, harald, hector.palacios, linux-iio, linux-kernel



On 23/12/13 17:48, Alexandre Belloni wrote:
> mxs_lradc.is_divided was an unsigned long array. Convert it to a bitmap to save
> some memory.
>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Hi Alexandre,

I've applied this patch, but would have prefered that you post this one 
in separate series. It is a perfectly valid cleanup, but introducing it
late in a series leads to uneven reviewing.  Anyhow, as it's trivial and
I doubt Marek will mind, I've applied it anyway in a new years burst of
trying to clear the outstanding stuff in my in box ;)

Applied to the togreg branch of iio.git

Thanks,

Jonathan
> ---
>   drivers/staging/iio/adc/mxs-lradc.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c
> index a58c6aaa94d3..df71669bb60e 100644
> --- a/drivers/staging/iio/adc/mxs-lradc.c
> +++ b/drivers/staging/iio/adc/mxs-lradc.c
> @@ -211,7 +211,7 @@ struct mxs_lradc {
>
>   	const uint32_t		*vref_mv;
>   	struct mxs_lradc_scale	scale_avail[LRADC_MAX_TOTAL_CHANS][2];
> -	unsigned int		is_divided[LRADC_MAX_TOTAL_CHANS];
> +	unsigned long		is_divided;
>
>   	/*
>   	 * Touchscreen LRADC channels receives a private slot in the CTRL4
> @@ -920,7 +920,7 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
>
>   		*val = lradc->vref_mv[chan->channel];
>   		*val2 = chan->scan_type.realbits -
> -			lradc->is_divided[chan->channel];
> +			test_bit(chan->channel, &lradc->is_divided);
>   		return IIO_VAL_FRACTIONAL_LOG2;
>
>   	case IIO_CHAN_INFO_OFFSET:
> @@ -965,14 +965,14 @@ static int mxs_lradc_write_raw(struct iio_dev *iio_dev,
>   			/* divider by two disabled */
>   			writel(1 << LRADC_CTRL2_DIVIDE_BY_TWO_OFFSET,
>   			       lradc->base + LRADC_CTRL2 + STMP_OFFSET_REG_CLR);
> -			lradc->is_divided[chan->channel] = 0;
> +			clear_bit(chan->channel, &lradc->is_divided);
>   			ret = 0;
>   		} else if (val == scale_avail[MXS_LRADC_DIV_ENABLED].integer &&
>   			   val2 == scale_avail[MXS_LRADC_DIV_ENABLED].nano) {
>   			/* divider by two enabled */
>   			writel(1 << LRADC_CTRL2_DIVIDE_BY_TWO_OFFSET,
>   			       lradc->base + LRADC_CTRL2 + STMP_OFFSET_REG_SET);
> -			lradc->is_divided[chan->channel] = 1;
> +			set_bit(chan->channel, &lradc->is_divided);
>   			ret = 0;
>   		}
>
>

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

* Re: [PATCHv5 RESEND 4/4] iio: mxs-lradc: convert is_divided to a bitmap
  2014-01-01 14:31   ` Jonathan Cameron
@ 2014-01-01 19:31     ` Marek Vasut
  2014-01-02  8:38       ` Alexandre Belloni
  0 siblings, 1 reply; 15+ messages in thread
From: Marek Vasut @ 2014-01-01 19:31 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Alexandre Belloni, lars, harald, hector.palacios, linux-iio,
	linux-kernel

On Wednesday, January 01, 2014 at 03:31:35 PM, Jonathan Cameron wrote:
> On 23/12/13 17:48, Alexandre Belloni wrote:
> > mxs_lradc.is_divided was an unsigned long array. Convert it to a bitmap
> > to save some memory.
> > 
> > Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> 
> Hi Alexandre,
> 
> I've applied this patch, but would have prefered that you post this one
> in separate series. It is a perfectly valid cleanup, but introducing it
> late in a series leads to uneven reviewing.  Anyhow, as it's trivial and
> I doubt Marek will mind, I've applied it anyway in a new years burst of
> trying to clear the outstanding stuff in my in box ;)
> 
> Applied to the togreg branch of iio.git
> 
> Thanks,

I dont mind, thanks for geting these in. And happy new year to you guys :)

Best regards,
Marek Vasut

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

* Re: [PATCHv5 RESEND 4/4] iio: mxs-lradc: convert is_divided to a bitmap
  2014-01-01 19:31     ` Marek Vasut
@ 2014-01-02  8:38       ` Alexandre Belloni
  2014-01-02  9:40         ` Jonathan Cameron
  0 siblings, 1 reply; 15+ messages in thread
From: Alexandre Belloni @ 2014-01-02  8:38 UTC (permalink / raw)
  To: Marek Vasut, Jonathan Cameron
  Cc: lars, harald, hector.palacios, linux-iio, linux-kernel

On 01/01/2014 20:31, Marek Vasut wrote:
> On Wednesday, January 01, 2014 at 03:31:35 PM, Jonathan Cameron wrote:
>> On 23/12/13 17:48, Alexandre Belloni wrote:
>>> mxs_lradc.is_divided was an unsigned long array. Convert it to a bitmap
>>> to save some memory.
>>>
>>> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
>>
>> Hi Alexandre,
>>
>> I've applied this patch, but would have prefered that you post this one
>> in separate series. It is a perfectly valid cleanup, but introducing it
>> late in a series leads to uneven reviewing.  Anyhow, as it's trivial and
>> I doubt Marek will mind, I've applied it anyway in a new years burst of
>> trying to clear the outstanding stuff in my in box ;)
>>
>> Applied to the togreg branch of iio.git
>>
>> Thanks,
> 
> I dont mind, thanks for geting these in. And happy new year to you guys :)

Thanks Jonathan !

I wish everyone the best for this new year !



-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

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

* Re: [PATCHv5 RESEND 4/4] iio: mxs-lradc: convert is_divided to a bitmap
  2014-01-02  8:38       ` Alexandre Belloni
@ 2014-01-02  9:40         ` Jonathan Cameron
  0 siblings, 0 replies; 15+ messages in thread
From: Jonathan Cameron @ 2014-01-02  9:40 UTC (permalink / raw)
  To: Alexandre Belloni, Marek Vasut
  Cc: lars, harald, hector.palacios, linux-iio, linux-kernel



Alexandre Belloni <alexandre.belloni@free-electrons.com> wrote:
>On 01/01/2014 20:31, Marek Vasut wrote:
>> On Wednesday, January 01, 2014 at 03:31:35 PM, Jonathan Cameron
>wrote:
>>> On 23/12/13 17:48, Alexandre Belloni wrote:
>>>> mxs_lradc.is_divided was an unsigned long array. Convert it to a
>bitmap
>>>> to save some memory.
>>>>
>>>> Signed-off-by: Alexandre Belloni
><alexandre.belloni@free-electrons.com>
>>>
>>> Hi Alexandre,
>>>
>>> I've applied this patch, but would have prefered that you post this
>one
>>> in separate series. It is a perfectly valid cleanup, but introducing
>it
>>> late in a series leads to uneven reviewing.  Anyhow, as it's trivial
>and
>>> I doubt Marek will mind, I've applied it anyway in a new years burst
>of
>>> trying to clear the outstanding stuff in my in box ;)
>>>
>>> Applied to the togreg branch of iio.git
>>>
>>> Thanks,
>> 
>> I dont mind, thanks for geting these in. And happy new year to you
>guys :)
>
>Thanks Jonathan !
You are welcome.  Thanks for persevering.
>
>I wish everyone the best for this new year !
Indeed, happy new year to you too.

-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

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

end of thread, other threads:[~2014-01-02  9:40 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-23 17:48 [PATCHv5 RESEND 0/4] iio: mxs-lradc: add support to optional divider_by_two Alexandre Belloni
2013-12-23 17:48 ` [PATCHv5 RESEND 1/4] iio: mxs-lradc: add scale attribute to channels Alexandre Belloni
2014-01-01 14:25   ` Jonathan Cameron
2013-12-23 17:48 ` [PATCHv5 RESEND 2/4] iio: mxs-lradc: add scale_available file " Alexandre Belloni
2014-01-01 14:28   ` Jonathan Cameron
2013-12-23 17:48 ` [PATCHv5 RESEND 3/4] iio: mxs-lradc: add write_raw function to modify scale Alexandre Belloni
2014-01-01 14:29   ` Jonathan Cameron
2013-12-23 17:48 ` [PATCHv5 RESEND 4/4] iio: mxs-lradc: convert is_divided to a bitmap Alexandre Belloni
2014-01-01 14:31   ` Jonathan Cameron
2014-01-01 19:31     ` Marek Vasut
2014-01-02  8:38       ` Alexandre Belloni
2014-01-02  9:40         ` Jonathan Cameron
2013-12-23 18:54 ` [PATCHv5 RESEND 0/4] iio: mxs-lradc: add support to optional divider_by_two Marek Vasut
2013-12-23 19:22   ` Alexandre Belloni
2013-12-24  1:50     ` Marek Vasut

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.