Skip to contentSkip to conversation

i.MX28 LRADC driver

PATCH New Marek Vasut 3 participants 11 messages Aug 3, 2012 – Aug 12, 2012

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover i.MX28 LRADC driver

Introduce the i.MX28 LRADC driver and support tech that comes with it.

Marek Vasut (3):
IIO: Add 4-byte unsigned reads into generic-buffer example
IIO: Add basic MXS LRADC driver
IIO: arm: Add LRADC to i.MX28 dts

 arch/arm/boot/dts/imx28.dtsi                       |    3 +
 drivers/staging/iio/Documentation/generic_buffer.c |   10 +
 drivers/staging/iio/adc/Kconfig                    |   12 +
 drivers/staging/iio/adc/Makefile                   |    1 +
 drivers/staging/iio/adc/mxs-lradc.c                |  591 ++++++++++++++++++++
 5 files changed, 617 insertions(+)
 create mode 100644 drivers/staging/iio/adc/mxs-lradc.c
Cc Jonathan Cameron <[email protected]>
Cc Juergen Beisert <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Wolfgang Denk <[email protected]>
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/3 IIO: Add 4-byte unsigned reads into generic-buffer example

Add unsigned 32bit-wide reads into the generic-buffer.c

Cc Jonathan Cameron <[email protected]>
Cc Juergen Beisert <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 drivers/staging/iio/Documentation/generic_buffer.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/staging/iio/Documentation/generic_buffer.c +10 -0
index 827e92d..40d0eca 100644
@@ -104,6 +104,16 @@ void process_scan(char *data,
 			print2byte(*(uint16_t *)(data + channels[k].location),
 				   &channels[k]);
 			break;
+		case 4:
+			if (!channels[k].is_signed) {
+				uint32_t val = *(uint32_t *)
+					(data + channels[k].location);
+				printf("%05f ", ((float)val +
+						 channels[k].offset)*
+				       channels[k].scale);
+
+			}
+			break;
 		case 8:
 			if (channels[k].is_signed) {
 				int64_t val = *(int64_t *)
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH v2 2/3 IIO: Add basic MXS LRADC driver

In reply to Marek Vasut

This driver is very basic. It supports userland trigger, buffer and raw access to channels. The support for delay channels is missing altogether.

Cc Jonathan Cameron <[email protected]>
Cc Juergen Beisert <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 drivers/staging/iio/adc/Kconfig     |   12 +
 drivers/staging/iio/adc/Makefile    |    1 +
 drivers/staging/iio/adc/mxs-lradc.c |  591 +++++++++++++++++++++++++++++++++++
 3 files changed, 604 insertions(+)
 create mode 100644 drivers/staging/iio/adc/mxs-lradc.c

V2: Use delay channel 0 in case of buffered sampling so the samples are deployed
continuously.
Disallow RAW sampling while buffered mode is enabled to simplify code.

drivers/staging/iio/adc/Kconfig +12 -0
index 67711b7..97ca697 100644
@@ -200,6 +200,18 @@ config LPC32XX_ADC
 	  activate only one via device tree selection.  Provides direct access
 	  via sysfs.
 
+config MXS_LRADC
+	tristate "Freescale i.MX23/i.MX28 LRADC"
+	depends on ARCH_MXS
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+	help
+	  Say yes here to build support for i.MX23/i.MX28 LRADC convertor
+	  built into these chips.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called mxs-lradc.
+
 config SPEAR_ADC
 	tristate "ST SPEAr ADC"
 	depends on PLAT_SPEAR
drivers/staging/iio/adc/Makefile +1 -0
index 14e98b6..ecac9a0 100644
@@ -38,4 +38,5 @@ obj-$(CONFIG_ADT7310) += adt7310.o
 obj-$(CONFIG_ADT7410) += adt7410.o
 obj-$(CONFIG_AD7280) += ad7280a.o
 obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o
+obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
 obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
drivers/staging/iio/adc/mxs-lradc.c new file +591 -0

591 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#3 lore raw

PATCH v2 2/3 IIO: Add basic MXS LRADC driver

Quoted 2 lines · Marek Vasut
drivers/staging/iio/adc/mxs-lradc.c new file +0 -0

<snip>

drivers/staging/iio/adc/mxs-lradc.c line 38

Quoted 3 lines
drivers/staging/iio/adc/mxs-lradc.c new file +3 -0
+#include <mach/mxs.h>
+#include <mach/common.h>
+

Why do you need these two mach headers?

Signature · 2 lines
Regards,
Shawn
#4 lore raw

PATCH v2 2/3 IIO: Add basic MXS LRADC driver

Dear Shawn Guo,

Quoted 11 lines · Marek Vasut
Quoted 2 lines
drivers/staging/iio/adc/mxs-lradc.c new file +0 -0

<snip>

drivers/staging/iio/adc/mxs-lradc.c line 38

Quoted 3 lines
drivers/staging/iio/adc/mxs-lradc.c new file +3 -0
+#include <mach/mxs.h>
+#include <mach/common.h>
+

Why do you need these two mach headers?

Might be just some remnant ... any further comments please?

Best regards,
Marek Vasut

#5 lore raw

PATCH v2 2/3 IIO: Add basic MXS LRADC driver

In reply to Marek Vasut
Quoted 3 lines · Marek Vasut

This driver is very basic. It supports userland trigger, buffer and raw access to channels. The support for delay channels is missing altogether.

Looks mostly good to me. Some comments inline.

I think you need to provide a documentation for the devicetree binding, even though it's a rather simple binding.

Quoted 22 lines
Cc Jonathan Cameron <[email protected]>
Cc Juergen Beisert <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 drivers/staging/iio/adc/Kconfig     |   12 +
 drivers/staging/iio/adc/Makefile    |    1 +
 drivers/staging/iio/adc/mxs-lradc.c |  591 +++++++++++++++++++++++++++++++++++
 3 files changed, 604 insertions(+)
 create mode 100644 drivers/staging/iio/adc/mxs-lradc.c

V2: Use delay channel 0 in case of buffered sampling so the samples are deployed
continuously.
Disallow RAW sampling while buffered mode is enabled to simplify code.

drivers/staging/iio/adc/Kconfig +0 -0
index 67711b7..97ca697 100644

[...]

drivers/staging/iio/adc/Kconfig

Quoted 8 lines

+ */

drivers/staging/iio/adc/Kconfig +6 -0
+static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
+			const struct iio_chan_spec *chan,
+			int *val, int *val2, long m)
+{
[...]
+
+	init_completion(&lradc->completion);

This should rather be INIT_COMPLETION. init_completion should only called once in probe, since it will reinitialize the spinlock which opens up race conditions.

drivers/staging/iio/adc/Kconfig

Quoted 5 lines

[...]

drivers/staging/iio/adc/Kconfig +4 -0
+
+	/* Wait for completion on the channel, 1 second max. */
+	ret = wait_for_completion_killable_timeout(&lradc->completion,
+						msecs_to_jiffies(1000));

msecs_to_jiffies(1000) = HZ, but I guess both is OK.

Quoted 2 lines

[...]
+}

[...]

Quoted 6 lines
drivers/staging/iio/adc/Kconfig +5 -0
+
+static int __devinit mxs_lradc_probe(struct platform_device *pdev)
+{
[...]
+
+	/* Grab all IRQ sources */

drivers/staging/iio/adc/Kconfig

Quoted 10 lines
drivers/staging/iio/adc/Kconfig +10 -0
+	for (i = 0; i < 13; i++) {
+		lradc->irq[i] = platform_get_irq(pdev, i);
+		if (lradc->irq[i] < 0) {
+			ret = -EINVAL;
+			goto err_addr;
+		}
+
+		ret = devm_request_irq(dev, lradc->irq[i],
+					mxs_lradc_handle_irq, 0,
+					mxs_lradc_irq_name[i], iio);

devm_request_irq is a bit dangerous as long we do not have a devm_iio_device_alloc. The IRQ will only be freed after the memory for the IIO device has been freed, which means there is a slight window where the IRQ could fire although the memory has already been freed.

drivers/staging/iio/adc/Kconfig

Quoted 5 lines
drivers/staging/iio/adc/Kconfig +5 -0
+		if (ret)
+			goto err_addr;
+	}
+
+	dev_set_drvdata(&pdev->dev, iio);

platform_set_drvdata

Quoted 4 lines
drivers/staging/iio/adc/Kconfig +4 -0
+
+	init_completion(&lradc->completion);
+	mutex_init(&lradc->lock);
+

[...]

#6 lore raw

PATCH v2 2/3 IIO: Add basic MXS LRADC driver

Dear Lars-Peter Clausen,

Quoted 9 lines · Marek Vasut
Quoted 3 lines

This driver is very basic. It supports userland trigger, buffer and raw access to channels. The support for delay channels is missing altogether.

Looks mostly good to me. Some comments inline.

I think you need to provide a documentation for the devicetree binding, even though it's a rather simple binding.

Definitelly, will add it.

Quoted 41 lines
Quoted 25 lines
Cc Jonathan Cameron <[email protected]>
Cc Juergen Beisert <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Wolfgang Denk <[email protected]>

---

 drivers/staging/iio/adc/Kconfig     |   12 +
 drivers/staging/iio/adc/Makefile    |    1 +
 drivers/staging/iio/adc/mxs-lradc.c |  591
 +++++++++++++++++++++++++++++++++++ 3 files changed, 604 insertions(+)
 create mode 100644 drivers/staging/iio/adc/mxs-lradc.c

V2: Use delay channel 0 in case of buffered sampling so the samples are deployed

continuously.
Disallow RAW sampling while buffered mode is enabled to simplify code.

(quoted diff) +0 -0

b/drivers/staging/iio/adc/Kconfig index 67711b7..97ca697 100644

drivers/staging/iio/adc/Kconfig +0 -0

[...]

drivers/staging/iio/adc/Kconfig

Quoted 8 lines

+ */

drivers/staging/iio/adc/Kconfig +6 -0
+static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
+			const struct iio_chan_spec *chan,
+			int *val, int *val2, long m)
+{
[...]
+
+	init_completion(&lradc->completion);

This should rather be INIT_COMPLETION. init_completion should only called once in probe, since it will reinitialize the spinlock which opens up race conditions.

Quoted 7 lines

drivers/staging/iio/adc/Kconfig

Quoted 5 lines

[...]

drivers/staging/iio/adc/Kconfig +4 -0
+
+	/* Wait for completion on the channel, 1 second max. */
+	ret = wait_for_completion_killable_timeout(&lradc->completion,
+						msecs_to_jiffies(1000));

msecs_to_jiffies(1000) = HZ, but I guess both is OK.

Even on NOHZ kernel?

Quoted 18 lines
Quoted 2 lines

[...]
+}

[...]

Quoted 13 lines
drivers/staging/iio/adc/Kconfig +12 -0
+
+static int __devinit mxs_lradc_probe(struct platform_device *pdev)
+{
[...]
+
+	/* Grab all IRQ sources */
+	for (i = 0; i < 13; i++) {
+		lradc->irq[i] = platform_get_irq(pdev, i);
+		if (lradc->irq[i] < 0) {
+			ret = -EINVAL;
+			goto err_addr;
+		}
+
Quoted 8 lines

drivers/staging/iio/adc/Kconfig

Quoted 3 lines
drivers/staging/iio/adc/Kconfig +3 -0
+		ret = devm_request_irq(dev, lradc->irq[i],
+					mxs_lradc_handle_irq, 0,
+					mxs_lradc_irq_name[i], iio);

devm_request_irq is a bit dangerous as long we do not have a devm_iio_device_alloc. The IRQ will only be freed after the memory for the IIO device has been freed, which means there is a slight window where the IRQ could fire although the memory has already been freed.

The IRQ is disabled, see mxs_lradc_hw_stop(), so it should be all right.

Quoted 14 lines

drivers/staging/iio/adc/Kconfig

Quoted 5 lines
drivers/staging/iio/adc/Kconfig +5 -0
+		if (ret)
+			goto err_addr;
+	}
+
+	dev_set_drvdata(&pdev->dev, iio);

platform_set_drvdata

Quoted 4 lines
drivers/staging/iio/adc/Kconfig +4 -0
+
+	init_completion(&lradc->completion);
+	mutex_init(&lradc->lock);
+

[...]

#7 lore raw

PATCH v2 2/3 IIO: Add basic MXS LRADC driver

Quoted 63 lines · Marek Vasut

Dear Lars-Peter Clausen,

Quoted 9 lines · Marek Vasut
Quoted 3 lines

This driver is very basic. It supports userland trigger, buffer and raw access to channels. The support for delay channels is missing altogether.

Looks mostly good to me. Some comments inline.

I think you need to provide a documentation for the devicetree binding, even though it's a rather simple binding.

Definitelly, will add it.

Quoted 41 lines
Quoted 25 lines
Cc Jonathan Cameron <[email protected]>
Cc Juergen Beisert <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Wolfgang Denk <[email protected]>

---

 drivers/staging/iio/adc/Kconfig     |   12 +
 drivers/staging/iio/adc/Makefile    |    1 +
 drivers/staging/iio/adc/mxs-lradc.c |  591
 +++++++++++++++++++++++++++++++++++ 3 files changed, 604 insertions(+)
 create mode 100644 drivers/staging/iio/adc/mxs-lradc.c

V2: Use delay channel 0 in case of buffered sampling so the samples are deployed

continuously.
Disallow RAW sampling while buffered mode is enabled to simplify code.

(quoted diff) +0 -0

b/drivers/staging/iio/adc/Kconfig index 67711b7..97ca697 100644

drivers/staging/iio/adc/Kconfig +0 -0

[...]

drivers/staging/iio/adc/Kconfig

Quoted 8 lines

+ */

drivers/staging/iio/adc/Kconfig +6 -0
+static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
+			const struct iio_chan_spec *chan,
+			int *val, int *val2, long m)
+{
[...]
+
+	init_completion(&lradc->completion);

This should rather be INIT_COMPLETION. init_completion should only called once in probe, since it will reinitialize the spinlock which opens up race conditions.

Quoted 7 lines

drivers/staging/iio/adc/Kconfig

Quoted 5 lines

[...]

drivers/staging/iio/adc/Kconfig +4 -0
+
+	/* Wait for completion on the channel, 1 second max. */
+	ret = wait_for_completion_killable_timeout(&lradc->completion,
+						msecs_to_jiffies(1000));

msecs_to_jiffies(1000) = HZ, but I guess both is OK.

Quoted 1 line

Even on NOHZ kernel?

Yes HZ is always the number of jiffies per second.

Quoted 28 lines
Quoted 19 lines
Quoted 3 lines

[...]
+}

[...]

Quoted 13 lines
drivers/staging/iio/adc/Kconfig +12 -0
+
+static int __devinit mxs_lradc_probe(struct platform_device *pdev)
+{
[...]
+
+	/* Grab all IRQ sources */
+	for (i = 0; i < 13; i++) {
+		lradc->irq[i] = platform_get_irq(pdev, i);
+		if (lradc->irq[i] < 0) {
+			ret = -EINVAL;
+			goto err_addr;
+		}
+
Quoted 8 lines

drivers/staging/iio/adc/Kconfig

Quoted 3 lines
drivers/staging/iio/adc/Kconfig +3 -0
+		ret = devm_request_irq(dev, lradc->irq[i],
+					mxs_lradc_handle_irq, 0,
+					mxs_lradc_irq_name[i], iio);

devm_request_irq is a bit dangerous as long we do not have a devm_iio_device_alloc. The IRQ will only be freed after the memory for the IIO device has been freed, which means there is a slight window where the IRQ could fire although the memory has already been freed.

Quoted 1 line

The IRQ is disabled, see mxs_lradc_hw_stop(), so it should be all right.

Ok.

#8 lore raw

PATCH 3/3 IIO: arm: Add LRADC to i.MX28 dts

In reply to Marek Vasut
Cc Jonathan Cameron <[email protected]>
Cc Juergen Beisert <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 arch/arm/boot/dts/imx28.dtsi |    3 +++
 1 file changed, 3 insertions(+)
arch/arm/boot/dts/imx28.dtsi +3 -0
index 4a0f12c..91752d2 100644
@@ -677,7 +677,10 @@
 			};
 
 			lradc at 80050000 {
+				compatible = "fsl,imx28-lradc";
 				reg = <0x80050000 2000>;
+				interrupts = <10 14 15 16 17 18 19
+						20 21 22 23 24 25>;
 				status = "disabled";
 			};
 
Signature · 1 line
1.7.10.4
#9 lore raw

PATCH 3/3 IIO: arm: Add LRADC to i.MX28 dts

Quoted 15 lines · Marek Vasut
Cc Jonathan Cameron <[email protected]>
Cc Juergen Beisert <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Shawn Guo <[email protected]>
Cc Wolfgang Denk <[email protected]>
---
 arch/arm/boot/dts/imx28.dtsi |    3 +++
 1 file changed, 3 insertions(+)
arch/arm/boot/dts/imx28.dtsi +0 -0
index 4a0f12c..91752d2 100644

arch/arm/boot/dts/imx28.dtsi line 683

Quoted 7 lines
arch/arm/boot/dts/imx28.dtsi +3 -0
@@ -677,7 +677,10 @@
 			};
 
 			lradc at 80050000 {
+				compatible = "fsl,imx28-lradc";
 				reg = <0x80050000 2000>;
+				interrupts = <10 14 15 16 17 18 19
+						20 21 22 23 24 25>;

Is there a binding doc for this?

Regards,
Shawn

Quoted 6 lines
arch/arm/boot/dts/imx28.dtsi +0 -0
 				status = "disabled";
 			};
 
Signature · 1 line
1.7.10.4
#10 lore raw

cover i.MX28 LRADC driver

In reply to Marek Vasut

Dear Marek Vasut,

Quoted 6 lines

Introduce the i.MX28 LRADC driver and support tech that comes with it.

Marek Vasut (3):
IIO: Add 4-byte unsigned reads into generic-buffer example
IIO: Add basic MXS LRADC driver
IIO: arm: Add LRADC to i.MX28 dts

What about 1/3 btw? Can that be applied ?

Quoted 8 lines
 arch/arm/boot/dts/imx28.dtsi                       |    3 +
 drivers/staging/iio/Documentation/generic_buffer.c |   10 +
 drivers/staging/iio/adc/Kconfig                    |   12 +
 drivers/staging/iio/adc/Makefile                   |    1 +
 drivers/staging/iio/adc/mxs-lradc.c                |  591
++++++++++++++++++++ 5 files changed, 617 insertions(+)
 create mode 100644 drivers/staging/iio/adc/mxs-lradc.c
Quoted 4 lines
Cc Jonathan Cameron <[email protected]>
Cc Juergen Beisert <[email protected]>
Cc Lars-Peter Clausen <[email protected]>
Cc Wolfgang Denk <[email protected]>

Best regards,
Marek Vasut