iio: basic ADC support for Freescale i.MX25
Subsystems (4)
PATCH v2 1/1 iio: basic ADC support for Freescale i.MX25
From: Denis Darwish <[email protected]>
This patch adds basic support for Freescale i.MX25 ADC in the IIO Subsystem.
---
I want to thank Lars-Peter Clausen for a detailed review.
Functionality tested with linux 3.8.0 and linux-next. IIO_BUFFER and IIO_TRIGGER unsupported Changes since v1:
+ end of conversion IRQ support
* cleanup debug info messages, vars etc.
* all definitions put into c file
* iio_chan_spec statically initialized
* get resources in modern way (clk, iomem etc)
arch/arm/mach-imx/clk-imx25.c | 2 +- arch/arm/mach-imx/devices/Kconfig | 4 + arch/arm/mach-imx/devices/Makefile | 1 + arch/arm/mach-imx/devices/devices-common.h | 2 + arch/arm/mach-imx/devices/platform-imx25-adc.c | 27 + arch/arm/mach-imx/mx25.h | 2 + drivers/iio/adc/Kconfig | 7 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/imx25_adc.c | 639 ++++++++++++++++++++++++ 9 files changed, 684 insertions(+), 1 deletions(-) create mode 100644 arch/arm/mach-imx/devices/platform-imx25-adc.c create mode 100644 drivers/iio/adc/imx25_adc.c
arch/arm/mach-imx/clk-imx25.c +1 -1
@@ -274,7 +274,7 @@ int __init mx25_clocks_init(void)clk_register_clkdev (clk[pwm1_ipg],"ipg" ,"mxc_pwm.3" );clk_register_clkdev (clk[per10],"per" ,"mxc_pwm.3" );clk_register_clkdev (clk[kpp_ipg],NULL ,"imx-keypad" ); -clk_register_clkdev (clk[tsc_ipg],NULL ,"mx25-adc" ); +clk_register_clkdev (clk[tsc_ipg],NULL ,"imx25-adc" );clk_register_clkdev (clk[i2c_ipg_per],NULL ,"imx21-i2c.0" );clk_register_clkdev (clk[i2c_ipg_per],NULL ,"imx21-i2c.1" );clk_register_clkdev (clk[i2c_ipg_per],NULL ,"imx21-i2c.2" );
arch/arm/mach-imx/devices/Kconfig +4 -0
@@ -16,6 +16,10 @@ config IMX_HAVE_PLATFORM_GPIO_KEYS config IMX_HAVE_PLATFORM_IMX21_HCD bool +config IMX_HAVE_PLATFORM_IMX25_ADC + bool + default y if SOC_IMX25 + config IMX_HAVE_PLATFORM_IMX27_CODA bool default y if SOC_IMX27
arch/arm/mach-imx/devices/Makefile +1 -0
@@ -6,6 +6,7 @@ obj-$(CONFIG_IMX_HAVE_PLATFORM_FSL_USB2_UDC) += platform-fsl-usb2-udc.o obj-$(CONFIG_IMX_HAVE_PLATFORM_GPIO_KEYS) += platform-gpio_keys.o obj-y += platform-gpio-mxc.o obj-$(CONFIG_IMX_HAVE_PLATFORM_IMX21_HCD) += platform-imx21-hcd.o +obj-$(CONFIG_IMX_HAVE_PLATFORM_IMX25_ADC) += platform-imx25-adc.o obj-$(CONFIG_IMX_HAVE_PLATFORM_IMX27_CODA) += platform-imx27-coda.o obj-$(CONFIG_IMX_HAVE_PLATFORM_IMX2_WDT) += platform-imx2-wdt.o obj-$(CONFIG_IMX_HAVE_PLATFORM_IMXDI_RTC) += platform-imxdi_rtc.o
arch/arm/mach-imx/devices/devices-common.h +2 -0
@@ -344,3 +344,5 @@ struct platform_device *imx_add_imx_dma(char *name, resource_size_t iobase, int irq, int irq_err);struct platform_device *imx_add_imx_sdma (char *name,resource_size_t iobase,int irq,struct sdma_platform_data *pdata); + +struct platform_device *__init imx25_add_adc (void );
arch/arm/mach-imx/devices/platform-imx25-adc.c new file +27 -0
@@ -0,0 +1,27 @@ +/* +* Copyright (C) 2013 Denis Darwish <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License version 2 as published by the +* Free Software Foundation. +*/ +#include "../hardware.h" +#include "devices-common.h" + +struct platform_device *__init imx25_add_adc (void ) +{ +struct resource res[] = { + [0 ] = { + .start =MX25_TSC_BASE_ADDR , + .end =MX25_TSC_BASE_ADDR +SZ_16K -1 , + .flags =IORESOURCE_MEM , + }, + [1 ] = { + .start =MX25_INT_TSC , + .end =MX25_INT_TSC , + .flags =IORESOURCE_IRQ , + }, + }; +return imx_add_platform_device ("imx25-adc" ,-1 , + res,ARRAY_SIZE (res),NULL ,0 ); +}
arch/arm/mach-imx/mx25.h +2 -0
@@ -37,6 +37,7 @@#define MX25_CSPI3_BASE_ADDR 0x50004000#define MX25_CSPI2_BASE_ADDR 0x50010000 +#define MX25_TSC_BASE_ADDR 0x50030000#define MX25_FEC_BASE_ADDR 0x50038000#define MX25_SSI2_BASE_ADDR 0x50014000#define MX25_SSI1_BASE_ADDR 0x50034000
@@ -96,6 +97,7 @@#define MX25_INT_CAN1 (NR_IRQS_LEGACY + 43)#define MX25_INT_CAN2 (NR_IRQS_LEGACY + 44)#define MX25_INT_UART1 (NR_IRQS_LEGACY + 45) +#define MX25_INT_TSC (NR_IRQS_LEGACY + 46)#define MX25_INT_GPIO2 (NR_IRQS_LEGACY + 51)#define MX25_INT_GPIO1 (NR_IRQS_LEGACY + 52)#define MX25_INT_GPT1 (NR_IRQS_LEGACY + 54)
drivers/iio/adc/Kconfig +7 -0
@@ -150,6 +150,13 @@ config TI_AM335X_ADC Say yes here to build support for Texas Instruments ADC driver which is also a MFD client. +config IMX25_ADC + tristate "Freescale IMX25 ADC" + depends on ARCH_MXC + select SYSFS + help + Say yes here to build support for Freescale i.MX25 ADC built into these chips. + config VIPERBOARD_ADC tristate "Viperboard ADC support" depends on MFD_VIPERBOARD && USB
drivers/iio/adc/Makefile +1 -0
@@ -17,3 +17,4 @@ obj-$(CONFIG_MAX1363) += max1363.o obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o +obj-$(CONFIG_IMX25_ADC) += imx25_adc.o
drivers/iio/adc/imx25_adc.c new file +639 -0
639 lines not on this page · raw message
-- 1.7.3.4
Hi,
Looks much better than v1 :) Only a few minor things left
Quoted 17 lines · Denis Darwish
From: Denis Darwish <[email protected]>
This patch adds basic support for Freescale i.MX25 ADC in the IIO Subsystem.
Signed-off-by Denis Darwish <[email protected]>---
I want to thank Lars-Peter Clausen for a detailed review.Functionality tested with linux 3.8.0 and linux-next.
IIO_BUFFERandIIO_TRIGGERunsupported Changes since v1:
+ end of conversion IRQ support
* cleanup debug info messages, vars etc.
* all definitions put into c file
*iio_chan_specstatically initialized
* get resources in modern way (clk, iomem etc)
Quoted 9 lines
arch/arm/mach-imx/clk-imx25.c | 2 +- arch/arm/mach-imx/devices/Kconfig | 4 + arch/arm/mach-imx/devices/Makefile | 1 + arch/arm/mach-imx/devices/devices-common.h | 2 + arch/arm/mach-imx/devices/platform-imx25-adc.c | 27 + arch/arm/mach-imx/mx25.h | 2 + drivers/iio/adc/Kconfig | 7 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/imx25_adc.c | 639 ++++++++++++++++++++++++
This should be split into two patch, the first patch adding the IIO driver, the second one registering the platform device. Also make sure to put the imx maintainers on Cc.
Quoted 9 lines
9 files changed, 684 insertions(+), 1 deletions(-) create mode 100644 arch/arm/mach-imx/devices/platform-imx25-adc.c create mode 100644 drivers/iio/adc/imx25_adc.carch/arm/mach-imx/clk-imx25.c +0
-0@@ -274,7 +274,7 @@ int __init mx25_clocks_init(void)
[...]
Quoted 5 lines
drivers/iio/adc/Kconfig +0
-0
drivers/iio/adc/Kconfig config TI_AM335X_ADC · line 159
Quoted 10 lines
drivers/iio/adc/Kconfig +7
-0@@ -150,6 +150,13 @@ config TI_AM335X_ADC Say yes here to build support for Texas Instruments ADC driver which is also a MFD client. +config IMX25_ADC + tristate "Freescale IMX25 ADC" + depends on ARCH_MXC + select SYSFS + help + Say yes here to build support for Freescale i.MX25 ADC built into these chips. +
Keep the entries sorted alphabetically.
drivers/iio/adc/Makefile obj-$(CONFIG_MAX1363) += max1363.o · line 20
Quoted 12 lines
drivers/iio/adc/Kconfig +0
-0config VIPERBOARD_ADC tristate "Viperboard ADC support" depends on MFD_VIPERBOARD && USBdrivers/iio/adc/Makefile +1
-0@@ -17,3 +17,4 @@ obj-$(CONFIG_MAX1363) += max1363.o obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o +obj-$(CONFIG_IMX25_ADC) += imx25_adc.o
Same here.
Quoted 16 lines
drivers/iio/adc/imx25_adc.c new file +10
-0@@ -0,0 +1,639 @@ +/** +* Copyright (c) 2013 Denis Darwish +* Copyright 2009-2011 Freescale Semiconductor, Inc. +*/ + +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/io.h>
drivers/iio/adc/imx25_adc.c line 20
Quoted 10 lines
drivers/iio/adc/imx25_adc.c new file +10
-0+#include <linux/clk.h> +#include <linux/err.h> +#include <linux/interrupt.h> +#include <linux/completion.h> +#include <linux/regulator/consumer.h> + +#include <linux/iio/iio.h> +#include <linux/iio/sysfs.h> +#include <linux/iio/events.h> +#include <linux/iio/buffer.h>
You don't use buffers or events.
[...]
drivers/iio/adc/imx25_adc.c line 187
Quoted 4 lines
drivers/iio/adc/imx25_adc.c new file +4
-0+#define IMX_ADC_GCQ_ITEM_GCC0 0x0 +#define IMX_ADC_GCQ_ITEM_GCC1 0x1 +#define IMX_ADC_GCQ_ITEM_GCC2 0x2 +#define IMX_ADC_GCQ_ITEM_GCC3 0x3
How about using 'IMX_ADC_GCQ_ITEM_GCC(x) (x)', that would allow you to simplify the code using these defines.
There are a few other places where the register offsets or shifts are linar based on the number, those could be simplified in a similar way.
[...]
drivers/iio/adc/imx25_adc.c line 218
Quoted 9 lines
drivers/iio/adc/imx25_adc.c new file +9
-0+static int adc_clk_enable (struct imx_adc_state *st) +{ +unsigned long reg; +int ret; + + ret =clk_prepare_enable (st->adc_clk); + reg =readl_relaxed (st->reg_base +IMX_ADC_TGCR ); + reg |=IMX_ADC_TGCR_IPG_CLK_EN ; +writel_relaxed (reg, st->reg_base +IMX_ADC_TGCR );
You do this read-modify-write operation quite often it might be worth it adding a small helper function for this.
Quoted 3 lines
drivers/iio/adc/imx25_adc.c new file +3
-0+return ret; +} +
[...]
drivers/iio/adc/imx25_adc.c line 242
Quoted 11 lines
drivers/iio/adc/imx25_adc.c new file +11
-0+void tsc_self_reset (struct imx_adc_state *st) +{ +unsigned long reg; + + reg =readl_relaxed (st->reg_base +IMX_ADC_TGCR ); + reg |=IMX_ADC_TGCR_TSC_RST ; +writel_relaxed (reg, st->reg_base +IMX_ADC_TGCR ); + +while (readl_relaxed (st->reg_base +IMX_ADC_TGCR ) & +IMX_ADC_TGCR_TSC_RST ) +continue ;
Needs a timeout in case for the unlikely event the hardware malfunctions.
Quoted 1 line
+}
[...]
drivers/iio/adc/imx25_adc.c line 351
Quoted 11 lines
drivers/iio/adc/imx25_adc.c new file +11
-0+void imx_adc_read_general (unsigned short *result,struct imx_adc_state *st) +{ +unsigned long reg; + + reg =readl_relaxed (st->reg_base +IMX_ADC_GCQCR ); + reg |=IMX_ADC_CQCR_FQS ; +writel_relaxed (reg, st->reg_base +IMX_ADC_GCQCR ); + +while (!(readl_relaxed (st->reg_base +IMX_ADC_GCQSR ) & +IMX_ADC_CQSR_EOQ )) +continue ;
Needs a timeout
drivers/iio/adc/imx25_adc.c line 363
Quoted 12 lines
drivers/iio/adc/imx25_adc.c new file +12
-0+ reg =readl_relaxed (st->reg_base +IMX_ADC_GCQCR ); + reg &= ~IMX_ADC_CQCR_FQS ; +writel_relaxed (reg, st->reg_base +IMX_ADC_GCQCR ); + reg =readl_relaxed (st->reg_base +IMX_ADC_GCQSR ); + reg |=IMX_ADC_CQSR_EOQ ; +writel_relaxed (reg, st->reg_base +IMX_ADC_GCQSR ); + +while (!(readl_relaxed (st->reg_base +IMX_ADC_GCQSR ) & +IMX_ADC_CQSR_EMPT )) { + *result =readl_relaxed (st->reg_base +IMX_ADC_GCQFIFO ) >> +IMX_ADC_GCQFIFO_ADCOUT_SHIFT ; + }
This one too
drivers/iio/adc/imx25_adc.c line 375
Quoted 12 lines
drivers/iio/adc/imx25_adc.c new file +12
-0+ +} + +static irqreturn_t imx_adc_handle_irq (int irq,void *private) +{ +struct iio_dev *iodev = private; +struct imx_adc_state *st =iio_priv (iodev); +unsigned long reg; + + reg =readl_relaxed (st->reg_base +IMX_ADC_TGSR ); +if (!(reg &IMX_ADC_GCQ_INT )) +return IRQ_HANDLED ;
Well if there is no interrupt you should return IRQ_NONE, [...]
Quoted 5 lines
drivers/iio/adc/imx25_adc.c new file +5
-0+} + +[...] +static int imx_adc_read_raw(struct iio_dev *idev, + struct iio_chan_spec const *chan,
drivers/iio/adc/imx25_adc.c line 432
Quoted 10 lines
drivers/iio/adc/imx25_adc.c new file +10
-0+ int *val, int *val2, long mask) +{ + struct imx_adc_state *st = iio_priv(idev); +int ret; +unsigned long reg; + + +switch (mask) { +case IIO_CHAN_INFO_RAW : + ret =mutex_trylock (&st->lock);
I don't think trylock is necessary. Just use mutex_lock, this will cause concurrent reads to be serialized instead of returning an error.
Quoted 17 lines
drivers/iio/adc/imx25_adc.c new file +17
-0+if (!ret) +return -EBUSY ; + +INIT_COMPLETION (st->completion); + +imx_adc_set_chanel (st, chan->channel); + +/* Enable the IRQ, unmask end-of-queue IRQ */ + reg =readl_relaxed (st->reg_base +IMX_ADC_GCQMR ); + reg &= ~IMX_ADC_GCQMR_EOQ_IRQ_MSK ; +writel_relaxed (reg, st->reg_base +IMX_ADC_GCQMR ); + +/* Start sampling the channel. */ + reg =readl_relaxed (st->reg_base +IMX_ADC_GCQCR ); + reg |=IMX_ADC_CQCR_FQS ; +writel_relaxed (reg, st->reg_base +IMX_ADC_GCQCR ); +
drivers/iio/adc/imx25_adc.c line 459
Quoted 10 lines
drivers/iio/adc/imx25_adc.c new file +10
-0+ ret =wait_for_completion_killable_timeout (&st->completion,HZ ); +if (!ret) + ret = -ETIMEDOUT ; +if (ret >0 ) { +while (!(readl_relaxed (st->reg_base +IMX_ADC_GCQSR ) & +IMX_ADC_CQSR_EMPT )) { + st->value =readl_relaxed (st->reg_base + +IMX_ADC_GCQFIFO ) >> +IMX_ADC_GCQFIFO_ADCOUT_SHIFT ; + }
Needs timeout and the closing bracket has a strange indention.
drivers/iio/adc/imx25_adc.c line 462
Quoted 3 lines
drivers/iio/adc/imx25_adc.c new file +3
-0+ *val = st->value; + ret =IIO_VAL_INT ; + }
if the wait was aborted ret can be less than 0, in which case you should pass the error on to the caller.
[...]
Quoted 2 lines
drivers/iio/adc/imx25_adc.c new file +2
-0+mutex_unlock (&st->lock); +return IIO_VAL_INT ;
[...]
Quoted 2 lines
drivers/iio/adc/imx25_adc.c new file +2
-0+} +
[...]
drivers/iio/adc/imx25_adc.c line 503
Quoted 4 lines
drivers/iio/adc/imx25_adc.c new file +4
-0+static int imx_adc_probe (struct platform_device *pdev) +{ +struct imx_adc_state *st; +struct iio_dev *iodev;
We usually call it indio_dev, it would be nice to use that for consistency as well.
drivers/iio/adc/imx25_adc.c line 507
Quoted 4 lines
drivers/iio/adc/imx25_adc.c new file +4
-0+int ret = -ENODEV ; +struct resource *res; + + iodev =iio_device_alloc (sizeof (struct imx_adc_state ));
sizeof(*st)
Quoted 26 lines
drivers/iio/adc/imx25_adc.c new file +26
-0+if (iodev ==NULL ) { +dev_err (&pdev->dev,"failed allocating iio device\n" ); + ret = -ENOMEM ; + goto error_ret; + } + + st =iio_priv (iodev); + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + st->reg_base =devm_request_and_ioremap (&pdev->dev, res); +if (IS_ERR (st->reg_base)) { + ret =PTR_ERR (st->reg_base); + goto error_free_device; + } + +/* Reset */ +tsc_self_reset (st); + + st->reg =regulator_get (&pdev->dev,"ext-vref" ); +if (!IS_ERR_OR_NULL (st->reg)) { + ret =regulator_enable (st->reg); +if (ret) + goto error_put_reg; + st->vref_mv =regulator_get_voltage (st->reg); + }else { +/* Use internal reference */
drivers/iio/adc/imx25_adc.c line 543
Quoted 10 lines
drivers/iio/adc/imx25_adc.c new file +10
-0+ st->vref_mv =2500 ;/* internal reference = 2.5V */ +tsc_intref_enable (st); + } + + st->irq =platform_get_irq (pdev,0 ); +if (st->irq <0 ) { +dev_err (&pdev->dev,"No IRQ ID is designated\n" ); + ret = -EINVAL ; + goto error_disable_reg; + }
Strange idention.
drivers/iio/adc/imx25_adc.c line 547
Quoted 4 lines
drivers/iio/adc/imx25_adc.c new file +4
-0+ + ret =devm_request_irq (&pdev->dev, st->irq, + imx_adc_handle_irq,0 , + pdev->dev.driver->name, iodev);
This is dangerous and racy you need to make sure to free the IRQ before you free the iio device, otherwise you might run into a use after free condition.
Quoted 23 lines
drivers/iio/adc/imx25_adc.c new file +23
-0+if (ret) + goto error_disable_reg; + + st->adc_clk =devm_clk_get (&pdev->dev,NULL ); +if (IS_ERR (st->adc_clk)) { +dev_err (&pdev->dev,"Failed to get the clock.\n" ); + ret =PTR_ERR (st->adc_clk); + goto error_free_clk; + } + + ret =adc_clk_enable (st); +if (ret) { +dev_err (&pdev->dev, +"Could not prepare or enable the clock.\n" ); + goto error_free_clk; + } + +adc_set_clk (st); + +/* Set power mode */ +adc_set_power_mode (st); + +/* Set queue */
drivers/iio/adc/imx25_adc.c line 580
Quoted 10 lines
drivers/iio/adc/imx25_adc.c new file +10
-0+adc_set_queue (st); + +platform_set_drvdata (pdev, iodev); + + iodev->name =dev_name (&pdev->dev); + iodev->dev.parent = &pdev->dev; + iodev->info = &imx_adc_info; + iodev->modes =INDIO_DIRECT_MODE ; + +
nitpick: No need for these two newlines
Quoted 5 lines
drivers/iio/adc/imx25_adc.c new file +5
-0+ iodev->channels = imx_adc_iio_channels; + iodev->num_channels =ARRAY_SIZE (imx_adc_iio_channels); + +init_completion (&st->completion); +mutex_init (&st->lock);
drivers/iio/adc/imx25_adc.c line 595
Quoted 10 lines
drivers/iio/adc/imx25_adc.c new file +10
-0+ + ret =iio_device_register (iodev); +if (ret <0 ) { +dev_err (&pdev->dev,"Couldn't register the device.\n" ); + goto error_dev; + } + +return 0 ; + +error_dev:
No need for an empty label.
Quoted 14 lines
drivers/iio/adc/imx25_adc.c new file +14
-0+ +error_free_clk: +adc_clk_disable (st); +error_disable_reg: +if (!IS_ERR_OR_NULL (st->reg)) +regulator_disable (st->reg); +error_put_reg: +if (!IS_ERR_OR_NULL (st->reg)) +regulator_put (st->reg); +error_free_device: +iio_device_free (iodev); +error_ret: +return ret; +}
drivers/iio/adc/imx25_adc.c line 619
Quoted 10 lines
drivers/iio/adc/imx25_adc.c new file +10
-0+ +static int imx_adc_remove (struct platform_device *pdev) +{ +struct iio_dev *iodev =platform_get_drvdata (pdev); +struct imx_adc_state *st =iio_priv (iodev); + +iio_device_unregister (iodev); + +adc_clk_disable (st); +clk_put (st->adc_clk);
The clock is device managed, so it will be automatically freed.
You forgot to free the regualtor.
drivers/iio/adc/imx25_adc.c line 624
Quoted 5 lines
drivers/iio/adc/imx25_adc.c new file +5
-0+ +iio_device_free (iodev); + +return 0 ; +}
/
Sascha Hauer
maintainerQuoted 28 lines · Lars-Peter Clausen
Hi,
Looks much better than v1 :) Only a few minor things left
Quoted 22 lines · Denis Darwish
From: Denis Darwish <[email protected]>
This patch adds basic support for Freescale i.MX25 ADC in the IIO Subsystem.
Signed-off-by Denis Darwish <[email protected]>---
I want to thank Lars-Peter Clausen for a detailed review.Functionality tested with linux 3.8.0 and linux-next.
IIO_BUFFERandIIO_TRIGGERunsupported Changes since v1:
+ end of conversion IRQ support
* cleanup debug info messages, vars etc.
* all definitions put into c file
*iio_chan_specstatically initialized
* get resources in modern way (clk, iomem etc)arch/arm/mach-imx/clk-imx25.c | 2 +- arch/arm/mach-imx/devices/Kconfig | 4 + arch/arm/mach-imx/devices/Makefile | 1 + arch/arm/mach-imx/devices/devices-common.h | 2 + arch/arm/mach-imx/devices/platform-imx25-adc.c | 27 +
I don't know Shawns take on this, but I think we are beyond the point where we add new platform devices. New boards should use devicetree which is sufficiently well supported on i.MX25.
Quoted 8 lines
Quoted 4 lines
arch/arm/mach-imx/mx25.h | 2 + drivers/iio/adc/Kconfig | 7 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/imx25_adc.c | 639 ++++++++++++++++++++++++This should be split into two patch, the first patch adding the IIO driver, the second one registering the platform device. Also make sure to put the imx maintainers on Cc.
Yes, at least the ARM Linux kernel Mailing List should be on Cc.
Quoted 6 lines
drivers/iio/adc/imx25_adc.c line 438
Quoted 6 lines
drivers/iio/adc/imx25_adc.c new file +6
-0+if (!ret) +return -EBUSY ; + +INIT_COMPLETION (st->completion); + +imx_adc_set_chanel (st, chan->channel);
Chanel is a fashion and perfume vendor. I think you mean channel.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Quoted 9 lines · Sascha Hauer
Quoted 5 lines
Quoted 5 lines
arch/arm/mach-imx/clk-imx25.c | 2 +- arch/arm/mach-imx/devices/Kconfig | 4 + arch/arm/mach-imx/devices/Makefile | 1 + arch/arm/mach-imx/devices/devices-common.h | 2 + arch/arm/mach-imx/devices/platform-imx25-adc.c | 27 +I don't know Shawns take on this, but I think we are beyond the point where we add new platform devices. New boards should use devicetree which is sufficiently well supported on i.MX25.
I agree that we should stop adding new stuff that will only be used by board files, since we are killing board files with device tree support.
Shawn
Sascha Hauer
maintainerI don't have the original patch to reply on, so some comments here.
Quoted 1 line · Lars-Peter Clausen
Quoted 1 line
+void
tsc_self_reset(struct imx_adc_state *st)
static.
Quoted 13 lines
drivers/iio/adc/imx25_adc.c line 242
Quoted 10 lines
drivers/iio/adc/imx25_adc.c new file +10
-0+{ +unsigned long reg; + + reg =readl_relaxed (st->reg_base +IMX_ADC_TGCR ); + reg |=IMX_ADC_TGCR_TSC_RST ; +writel_relaxed (reg, st->reg_base +IMX_ADC_TGCR ); + +while (readl_relaxed (st->reg_base +IMX_ADC_TGCR ) & +IMX_ADC_TGCR_TSC_RST ) +continue ;Needs a timeout in case for the unlikely event the hardware malfunctions.
Quoted 4 lines
Quoted 1 line
+}
[...]
Quoted 1 line
+void
imx_adc_read_general(unsigned short *result, struct imx_adc_state *st)
ditto. More functions which should be static follow.
Quoted 5 lines
drivers/iio/adc/imx25_adc.c line 526
Quoted 5 lines
drivers/iio/adc/imx25_adc.c new file +5
-0+ +/* Reset */ +tsc_self_reset (st); + + st->reg =regulator_get (&pdev->dev,"ext-vref" );
Use devm_regulator_get
Quoted 1 line
drivers/iio/adc/imx25_adc.c line 527
Quoted 1 line
drivers/iio/adc/imx25_adc.c new file +1
-0+if (!IS_ERR_OR_NULL (st->reg)) {
Don't use IS_ERR_OR_NULL. regulator_get will always return an error pointer, so IS_ERR() is correct here. Also, please use positive logic which is easier to read.
Quoted 5 lines
drivers/iio/adc/imx25_adc.c line 571
Quoted 5 lines
drivers/iio/adc/imx25_adc.c new file +5
-0+/* Set power mode */ +adc_set_power_mode (st); + +/* Set queue */ +adc_set_queue (st);
Remove those comments, they contain no information.
Better even, remove all these functions manipulating this single register and replace it with a simple:
tgcr = IMX_ADC_TGCR_IPG_CLK_EN | IMX_ADC_TGCR_POWER_ON | 31 << IMX_ADC_TGCR_ADCCLKCFG_SHIFT; if (IS_ERR(regulator)) tgcr |= IMX_ADC_TGCR_INTREFEN; writel_relaxed(tgcr, st->reg_base + IMX_ADC_TGCR);
Quoted 3 lines
drivers/iio/adc/imx25_adc.c line 589
Quoted 3 lines
drivers/iio/adc/imx25_adc.c new file +3
-0+ ret =iio_device_register (iodev); +if (ret <0 ) { +dev_err (&pdev->dev,"Couldn't register the device.\n" );
Such messages become much more useful when the error code is printed aswell.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |