Support for TSC/ADC MFD driver
Subsystems (4)
v5 cover Support for TSC/ADC MFD driver
This patch set adds a MFD core driver which registers touchscreen and ADC as its client drivers.
The existing touchscreen has been modified to work as a MFD client driver and a new ADC driver has been added in the IIO subsystem.
There are 8 analog input lines, which can be used as:
1. 8 general purpose ADC channels
2. 4 wire TS, with 4 general purpose ADC channels
3. 5 wire TS, with 3 general purpose ADC channels
This patch set has been tested on AM335x EVM.
These set of patches apply to linux-nxt branch and are based
on top of Touchscreen patch set submitted viz.
Subject: [PATCH 0/4] input: TSC: ti_tscadc: TI Touchscreen driver updates [1]
[1] http://www.spinics.net/lists/linux-input/msg22107.html
Changes in v2:
Dropped one patch send in the last version after receiving internal comments. I have merged the changes into existing patches.
Also added a new patch to support suspend/resume feature. Fixed review comments by Matthias Kaehlcke.
Changes in v3:
Addressed review comments by Jonathan Cameron. Improved ADC driver with more readable labels, spaces and comments.
Changes in v4:
Renamed the drivers from ti_xxx to ti_am335x_xxx. For consistency with other drivers renamed idev to indio_dev in IIO ADC driver.
Replaced suspend/resume callbacks with dev_pm_ops.
Changes in v5:
Merged suspend/resume part of code (present as separate patch) into the respective driver.
Patil, Rachna (4):
input: TSC: ti_tscadc: Rename the existing touchscreen driver
MFD: ti_tscadc: Add support for TI's TSC/ADC MFDevice
input: TSC: ti_tsc: Convert TSC into a MFDevice
IIO : ADC: tiadc: Add support of TI's ADC driver
drivers/iio/adc/Kconfig | 7 +
drivers/iio/adc/Makefile | 1 +
drivers/iio/adc/ti_am335x_adc.c | 260 ++++++++++
drivers/input/touchscreen/Kconfig | 6 +-
drivers/input/touchscreen/Makefile | 2 +-
drivers/input/touchscreen/ti_am335x_tsc.c | 398 +++++++++++++++
drivers/input/touchscreen/ti_tscadc.c | 522 --------------------
drivers/mfd/Kconfig | 11 +
drivers/mfd/Makefile | 1 +
drivers/mfd/ti_am335x_tscadc.c | 277 +++++++++++
.../linux/input/{ti_tscadc.h => ti_am335x_tsc.h} | 4 +-
include/linux/mfd/ti_am335x_tscadc.h | 152 ++++++
include/linux/platform_data/ti_am335x_adc.h | 14 +
13 files changed, 1127 insertions(+), 528 deletions(-)
create mode 100644 drivers/iio/adc/ti_am335x_adc.c
create mode 100644 drivers/input/touchscreen/ti_am335x_tsc.c
delete mode 100644 drivers/input/touchscreen/ti_tscadc.c
create mode 100644 drivers/mfd/ti_am335x_tscadc.c
rename include/linux/input/{ti_tscadc.h => ti_am335x_tsc.h} (88%)
create mode 100644 include/linux/mfd/ti_am335x_tscadc.h
create mode 100644 include/linux/platform_data/ti_am335x_adc.hPATCH v5 1/4 input: TSC: ti_tscadc: Rename the existing touchscreen driver
Make way for addition of MFD driver.
The existing touchsreen driver is a MFD client. For better readability we rename the file to indicate its functionality as only touchscreen.
---
Changes in v2:
Missed changing the name of touchscreen header file in the previous version.
Adding the same.
Changes in v3:
no changes.
Changes in v4:
no changes.
Changes in v5:
updated the struct and function names to match that of file name for better readability.
drivers/input/touchscreen/Kconfig | 4 +-
drivers/input/touchscreen/Makefile | 2 +-
.../touchscreen/{ti_tscadc.c => ti_am335x_tsc.c} | 96 ++++++++++----------
.../linux/input/{ti_tscadc.h => ti_am335x_tsc.h} | 4 +-
4 files changed, 53 insertions(+), 53 deletions(-)
rename drivers/input/touchscreen/{ti_tscadc.c => ti_am335x_tsc.c} (83%)
rename include/linux/input/{ti_tscadc.h => ti_am335x_tsc.h} (88%)drivers/input/touchscreen/Kconfig +2 -2
@@ -529,7 +529,7 @@ config TOUCHSCREEN_TOUCHWIN To compile this driver as a module, choose M here: the module will be called touchwin. -config TOUCHSCREEN_TI_TSCADC +config TOUCHSCREEN_TI_AM335X_TSC tristate "TI Touchscreen Interface" depends on ARCH_OMAP2PLUS help
@@ -539,7 +539,7 @@ config TOUCHSCREEN_TI_TSCADC If unsure, say N. To compile this driver as a module, choose M here: the - module will be called ti_tscadc. + module will be called ti_am335x_tsc. config TOUCHSCREEN_ATMEL_TSADCC tristate "Atmel Touchscreen Interface"
drivers/input/touchscreen/Makefile +1 -1
@@ -52,7 +52,7 @@ obj-$(CONFIG_TOUCHSCREEN_PIXCIR) += pixcir_i2c_ts.o obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o obj-$(CONFIG_TOUCHSCREEN_ST1232) += st1232.o obj-$(CONFIG_TOUCHSCREEN_STMPE) += stmpe-ts.o -obj-$(CONFIG_TOUCHSCREEN_TI_TSCADC) += ti_tscadc.o +obj-$(CONFIG_TOUCHSCREEN_TI_AM335X_TSC) += ti_am335x_tsc.o obj-$(CONFIG_TOUCHSCREEN_TNETV107X) += tnetv107x-ts.o obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
drivers/input/touchscreen/ti_am335x_tsc.c renamed from drivers/input/touchscreen/ti_tscadc.c +48 -48
257 lines not on this page · raw message
include/linux/input/ti_am335x_tsc.h renamed from include/linux/input/ti_tscadc.h +2 -2
@@ -1,5 +1,5 @@ -#ifndef __LINUX_TI_TSCADC_H -#define __LINUX_TI_TSCADC_H +#ifndef __LINUX_TI_AM335X_TSC_H +#define __LINUX_TI_AM335X_TSC_H/** * struct tsc_data Touchscreen wire configuration
Signature · 1 line
1.7.0.4
PATCH v5 2/4 MFD: ti_tscadc: Add support for TI's TSC/ADC MFDevice
In reply to Patil, RachnaAdd the mfd core driver which supports touchscreen and ADC.
With this patch we are only adding infrastructure to support the MFD clients.
---
Changes in v2:
Merged "[PATCH 5/5] MFD: ti_tscadc: Add check on number of i/p channels", patch submitted in previous version into this file.
Changes in v3:
No changes
Changes in v4:
No changes
Changes in v5:
Make use of devm_xxx and regmap MMIO API's.
drivers/mfd/Kconfig | 11 ++ drivers/mfd/Makefile | 1 + drivers/mfd/ti_am335x_tscadc.c | 250 ++++++++++++++++++++++++++++++++++ include/linux/mfd/ti_am335x_tscadc.h | 137 +++++++++++++++++++ 4 files changed, 399 insertions(+), 0 deletions(-) create mode 100644 drivers/mfd/ti_am335x_tscadc.c create mode 100644 include/linux/mfd/ti_am335x_tscadc.h
drivers/mfd/Kconfig +11 -0
@@ -94,6 +94,17 @@ config MFD_TI_SSP To compile this driver as a module, choose M here: the module will be called ti-ssp. +config MFD_TI_AM335X_TSCADC + tristate "TI ADC / Touch Screen chip support" + select MFD_CORE + select REGMAP + select REGMAP_MMIO + help + If you say yes here you get support for Texas Instruments series + of Touch Screen /ADC chips. + To compile this driver as a module, choose M here: the + module will be called ti_am335x_tscadc. + config HTC_EGPIO bool "HTC EGPIO support" depends on GENERIC_HARDIRQS && GPIOLIB && ARM
drivers/mfd/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_HTC_I2CPLD) += htc-i2cpld.o obj-$(CONFIG_MFD_DAVINCI_VOICECODEC) += davinci_voicecodec.o obj-$(CONFIG_MFD_DM355EVM_MSP) += dm355evm_msp.o obj-$(CONFIG_MFD_TI_SSP) += ti-ssp.o +obj-$(CONFIG_MFD_TI_AM335X_TSCADC) += ti_am335x_tscadc.o obj-$(CONFIG_MFD_STA2X11) += sta2x11-mfd.o obj-$(CONFIG_MFD_STMPE) += stmpe.o
drivers/mfd/ti_am335x_tscadc.c new file +250 -0
250 lines not on this page · raw message
include/linux/mfd/ti_am335x_tscadc.h new file +137 -0
137 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH v5 3/4 input: TSC: ti_tsc: Convert TSC into a MFDevice
In reply to Patil, RachnaThis patch converts touchscreen into a MFD client. All the register definitions, clock initialization, etc has been moved to MFD core driver.
---
Changes in v2:
No changes
Changes in v3:
No changes
Changes in v4:
No changes
Changes in v5:
No changes
drivers/input/touchscreen/Kconfig | 2 +- drivers/input/touchscreen/ti_am335x_tsc.c | 318 +++++++++-------------------- drivers/mfd/ti_am335x_tscadc.c | 11 + include/linux/mfd/ti_am335x_tscadc.h | 10 +- 4 files changed, 118 insertions(+), 223 deletions(-)
drivers/input/touchscreen/Kconfig +1 -1
@@ -531,7 +531,7 @@ config TOUCHSCREEN_TOUCHWIN config TOUCHSCREEN_TI_AM335X_TSC tristate "TI Touchscreen Interface" - depends on ARCH_OMAP2PLUS + depends on MFD_TI_AM335X_TSCADC help Say Y here if you have 4/5/8 wire touchscreen controller to be connected to the ADC controller on your TI AM335x SoC.
drivers/input/touchscreen/ti_am335x_tsc.c +97 -221
445 lines not on this page · raw message
drivers/mfd/ti_am335x_tscadc.c +11 -0
@@ -24,6 +24,7 @@#include <linux/pm_runtime.h> #include <linux/mfd/ti_am335x_tscadc.h> +#include <linux/input/ti_am335x_tsc.h> static unsigned int tscadc_readl (struct ti_tscadc_dev *tsadc,unsigned int reg) {
@@ -62,15 +63,19 @@ static int __devinit ti_tscadc_probe(struct platform_device *pdev)struct resource *res;struct clk *clk;struct mfd_tscadc_board *pdata = pdev->dev.platform_data; +struct mfd_cell *cell;int irq;int err, ctrl;int clk_value, clock_rate; +int tsc_wires;if (!pdata) {dev_err (&pdev->dev,"Could not find platform data\n" );return -EINVAL ; } + tsc_wires = pdata->tsc_init->wires; + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!res) {dev_err (&pdev->dev,"no memory resource defined.\n" );
@@ -161,6 +166,12 @@ static int __devinit ti_tscadc_probe(struct platform_device *pdev) ctrl |=CNTRLREG_TSCSSENB ;tscadc_writel (tscadc,REG_CTRL , ctrl); +/* TSC Cell */ + cell = &tscadc->cells[TSC_CELL ]; + cell->name ="tsc" ; + cell->platform_data = tscadc; + cell->pdata_size =sizeof (*tscadc); + err =mfd_add_devices (&pdev->dev, pdev->id, tscadc->cells,TSCADC_CELLS ,NULL ,0 ,NULL );if (err <0 )
include/linux/mfd/ti_am335x_tscadc.h +9 -1
@@ -47,6 +47,7 @@#define STEPENB_MASK (0x1FFFF << 0)#define STEPENB (val) ((val) << 0)#define STPENB_STEPENB STEPENB(0x1FFFF) +#define STPENB_STEPENB_TC STEPENB(0x1FFF)/* IRQ enable */ #define IRQENB_HW_PEN BIT(0)
@@ -120,7 +121,11 @@#define ADC_CLK 3000000#define MAX_CLK_DIV 7 -#define TSCADC_CELLS 0 +#define TSCADC_CELLS 1 + +enum tscadc_cells { +TSC_CELL , +};struct mfd_tscadc_board {struct tsc_data *tsc_init;
@@ -132,6 +137,9 @@ struct ti_tscadc_dev {void __iomem *tscadc_base;int irq;struct mfd_cell cells[TSCADC_CELLS ]; + +/* tsc device */ + struct titsc *tsc; };#endif
Signature · 1 line
1.7.0.4
PATCH v5 4/4 IIO : ADC: tiadc: Add support of TI's ADC driver
In reply to Patil, RachnaThis patch adds support for TI's ADC driver.
This is a multifunctional device.
Analog input lines are provided on which
voltage measurements can be carried out.
You can have upto 8 input lines.
---
Changes in v2:
Addressed review comments from Matthias Kaehlcke
Changes in v3:
Addressed review comments from Jonathan Cameron. Added comments, new line appropriately.
Changes in v4:
Removed extra comments and variables. rename idev to indio_dev throughout the driver. Renamed structs for better readability.
Changes in v5:
No changes
drivers/iio/adc/Kconfig | 7 +
drivers/iio/adc/Makefile | 1 + drivers/iio/adc/ti_am335x_adc.c | 260 +++++++++++++++++++++++++++ drivers/mfd/ti_am335x_tscadc.c | 18 ++- include/linux/mfd/ti_am335x_tscadc.h | 9 +- include/linux/platform_data/ti_am335x_adc.h | 14 ++ 6 files changed, 307 insertions(+), 2 deletions(-) create mode 100644 drivers/iio/adc/ti_am335x_adc.c create mode 100644 include/linux/platform_data/ti_am335x_adc.h
drivers/iio/adc/Kconfig +7 -0
@@ -22,4 +22,11 @@ config AT91_ADC help Say yes here to build support for Atmel AT91 ADC. +config TI_AM335X_ADC + tristate "TI's ADC driver" + depends on MFD_TI_AM335X_TSCADC + help + Say yes here to build support for Texas Instruments ADC + driver which is also a MFD client. + endmenu
drivers/iio/adc/Makefile +1 -0
@@ -4,3 +4,4 @@ obj-$(CONFIG_AD7266) += ad7266.o obj-$(CONFIG_AT91_ADC) += at91_adc.o +obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
drivers/iio/adc/ti_am335x_adc.c new file +260 -0
260 lines not on this page · raw message
drivers/mfd/ti_am335x_tscadc.c +17 -1
@@ -25,6 +25,7 @@#include <linux/mfd/ti_am335x_tscadc.h> #include <linux/input/ti_am335x_tsc.h> +#include <linux/platform_data/ti_am335x_adc.h> static unsigned int tscadc_readl (struct ti_tscadc_dev *tsadc,unsigned int reg) {
@@ -67,14 +68,23 @@ static int __devinit ti_tscadc_probe(struct platform_device *pdev)int irq;int err, ctrl;int clk_value, clock_rate; -int tsc_wires; +int tsc_wires, adc_channels =0 , total_channels;if (!pdata) {dev_err (&pdev->dev,"Could not find platform data\n" );return -EINVAL ; } +if (pdata->adc_init) + adc_channels = pdata->adc_init->adc_channels; + tsc_wires = pdata->tsc_init->wires; + total_channels = tsc_wires + adc_channels; + +if (total_channels >8 ) { +dev_err (&pdev->dev,"Number of i/p channels more than 8\n" ); +return -EINVAL ; + } res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!res) {
@@ -172,6 +182,12 @@ static int __devinit ti_tscadc_probe(struct platform_device *pdev) cell->platform_data = tscadc; cell->pdata_size =sizeof (*tscadc); +/* ADC Cell */ + cell = &tscadc->cells[ADC_CELL ]; + cell->name ="tiadc" ; + cell->platform_data = tscadc; + cell->pdata_size =sizeof (*tscadc); + err =mfd_add_devices (&pdev->dev, pdev->id, tscadc->cells,TSCADC_CELLS ,NULL ,0 ,NULL );if (err <0 )
include/linux/mfd/ti_am335x_tscadc.h +8 -1
@@ -120,15 +120,19 @@#define ADC_CLK 3000000#define MAX_CLK_DIV 7 +#define TOTAL_STEPS 16 +#define TOTAL_CHANNELS 8 -#define TSCADC_CELLS 1 +#define TSCADC_CELLS 2enum tscadc_cells {TSC_CELL , +ADC_CELL , };struct mfd_tscadc_board {struct tsc_data *tsc_init; +struct adc_data *adc_init; };struct ti_tscadc_dev {
@@ -140,6 +144,9 @@ struct ti_tscadc_dev {/* tsc device */ struct titsc *tsc; + +/* adc device */ + struct adc_device *adc; };#endif
include/linux/platform_data/ti_am335x_adc.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef __LINUX_TI_AM335X_ADC_H +#define __LINUX_TI_AM335X_ADC_H + +/** +* struct adc_data ADC Input information +* @adc_channels: Number of analog inputs +* available for ADC. +*/ + +struct adc_data { +unsigned int adc_channels; +}; + +#endif
Signature · 1 line
1.7.0.4
Jonathan Cameron
maintainerRe: [PATCH v5 4/4] IIO : ADC: tiadc: Add support of TI's ADC driver
Quoted 8 lines · Rachna
This patch adds support for TI's ADC driver.
This is a multifunctional device.
Analog input lines are provided on which
voltage measurements can be carried out.
You can have upto 8 input lines.Signed-off-by Patil, Rachna <[email protected]>Acked-by Jonathan Cameron <[email protected]>
I'll take this patch as soon as I know the mfd part has been accepted (just in case any interfaces change!)
Quoted 423 lines
---
Changes in v2:
Addressed review comments from Matthias KaehlckeChanges in v3:
Addressed review comments from Jonathan Cameron. Added comments, new line appropriately.Changes in v4:
Removed extra comments and variables. rename idev toindio_devthroughout the driver. Renamed structs for better readability.Changes in v5:
No changes
drivers/iio/adc/Kconfig| 7 +drivers/iio/adc/Makefile | 1 + drivers/iio/adc/ti_am335x_adc.c | 260 +++++++++++++++++++++++++++ drivers/mfd/ti_am335x_tscadc.c | 18 ++- include/linux/mfd/ti_am335x_tscadc.h | 9 +- include/linux/platform_data/ti_am335x_adc.h | 14 ++ 6 files changed, 307 insertions(+), 2 deletions(-) create mode 100644 drivers/iio/adc/ti_am335x_adc.c create mode 100644 include/linux/platform_data/ti_am335x_adc.hdrivers/iio/adc/Kconfig +7
-0@@ -22,4 +22,11 @@ config AT91_ADC help Say yes here to build support for Atmel AT91 ADC. +config TI_AM335X_ADC + tristate "TI's ADC driver" + depends on MFD_TI_AM335X_TSCADC + help + Say yes here to build support for Texas Instruments ADC + driver which is also a MFD client. + endmenudrivers/iio/adc/Makefile +1
-0@@ -4,3 +4,4 @@ obj-$(CONFIG_AD7266) += ad7266.o obj-$(CONFIG_AT91_ADC) += at91_adc.o +obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.odrivers/iio/adc/ti_am335x_adc.c new file +260
-0@@ -0,0 +1,260 @@ +/* +* TI ADC MFD driver +* +* Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/ +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation version 2. +* +* This program is distributed "as is" WITHOUT ANY WARRANTY of any +* kind, whether express or implied; without even the implied warranty +* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/err.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/interrupt.h> +#include <linux/platform_device.h> +#include <linux/io.h> +#include <linux/iio/iio.h> + +#include <linux/mfd/ti_am335x_tscadc.h> +#include <linux/platform_data/ti_am335x_adc.h> + +struct tiadc_device { +struct ti_tscadc_dev *mfd_tscadc; +int channels; +}; + +static unsigned int tiadc_readl (struct tiadc_device *adc,unsigned int reg) +{ +return readl (adc->mfd_tscadc->tscadc_base + reg); +} + +static void tiadc_writel (struct tiadc_device *adc,unsigned int reg, +unsigned int val) +{ +writel (val, adc->mfd_tscadc->tscadc_base + reg); +} + +static void tiadc_step_config (struct tiadc_device *adc_dev) +{ +unsigned int stepconfig; +int i, channels =0 , steps; + +/* +* There are 16 configurable steps and 8 analog input +* lines available which are shared between Touchscreen and ADC. +* +* Steps backwards i.e. from 16 towards 0 are used by ADC +* depending on number of input lines needed. +* Channel would represent which analog input +* needs to be given to ADC to digitalize data. +*/ + + steps =TOTAL_STEPS - adc_dev->channels; + channels =TOTAL_CHANNELS - adc_dev->channels; + + stepconfig =STEPCONFIG_AVG_16 |STEPCONFIG_FIFO1 ; + +for (i = (steps +1 ); i <=TOTAL_STEPS ; i++) { +tiadc_writel (adc_dev,REG_STEPCONFIG (i), + stepconfig |STEPCONFIG_INP (channels)); +tiadc_writel (adc_dev,REG_STEPDELAY (i), +STEPCONFIG_OPENDLY ); + channels++; + } +tiadc_writel (adc_dev,REG_SE ,STPENB_STEPENB ); +} + +static int tiadc_channel_init (struct iio_dev *indio_dev,int channels) +{ +struct iio_chan_spec *chan_array; +int i; + + indio_dev->num_channels = channels; + chan_array =kcalloc (indio_dev->num_channels, +sizeof (struct iio_chan_spec ),GFP_KERNEL ); + +if (chan_array ==NULL ) +return -ENOMEM ; + +for (i =0 ; i < (indio_dev->num_channels); i++) { +struct iio_chan_spec *chan = chan_array + i; + chan->type =IIO_VOLTAGE ; + chan->indexed =1 ; + chan->channel = i; + chan->info_mask =IIO_CHAN_INFO_RAW_SEPARATE_BIT ; + } + + indio_dev->channels = chan_array; + +return indio_dev->num_channels; +} + +static void tiadc_channels_remove (struct iio_dev *indio_dev) +{ +kfree (indio_dev->channels); +} + +static int tiadc_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan, +int *val,int *val2,long mask) +{ +struct tiadc_device *adc_dev =iio_priv (indio_dev); +int i; +unsigned int fifo1count, readx1; + +/* +* When the sub-system is first enabled, +* the sequencer will always start with the +* lowest step (1) and continue until step (16). +* For ex: If we have enabled 4 ADC channels and +* currently use only 1 out of them, the +* sequencer still configures all the 4 steps, +* leading to 3 unwanted data. +* Hence we need to flush out this data. +*/ + + fifo1count =tiadc_readl (adc_dev,REG_FIFO1CNT ); +for (i =0 ; i < fifo1count; i++) { + readx1 =tiadc_readl (adc_dev,REG_FIFO1 ); +if (i == chan->channel) + *val = readx1 &0xfff ; + } +tiadc_writel (adc_dev,REG_SE ,STPENB_STEPENB ); + +return IIO_VAL_INT ; +} + +static const struct iio_info tiadc_info = { + .read_raw = &tiadc_read_raw, +}; + +static int __devinit tiadc_probe (struct platform_device *pdev) +{ +struct iio_dev *indio_dev; +struct tiadc_device *adc_dev; +struct ti_tscadc_dev *tscadc_dev = pdev->dev.platform_data; +struct mfd_tscadc_board *pdata; +int err; + + pdata = tscadc_dev->dev->platform_data; +if (!pdata || !pdata->adc_init) { +dev_err (&pdev->dev,"Could not find platform data\n" ); +return -EINVAL ; + } + + indio_dev =iio_device_alloc (sizeof (struct tiadc_device )); +if (indio_dev ==NULL ) { +dev_err (&pdev->dev,"failed to allocate iio device\n" ); + err = -ENOMEM ; + goto err_ret; + } + adc_dev =iio_priv (indio_dev); + + adc_dev->mfd_tscadc = tscadc_dev; + adc_dev->channels = pdata->adc_init->adc_channels; + + indio_dev->dev.parent = &pdev->dev; + indio_dev->name =dev_name (&pdev->dev); + indio_dev->modes =INDIO_DIRECT_MODE ; + indio_dev->info = &tiadc_info; + +tiadc_step_config (adc_dev); + + err =tiadc_channel_init (indio_dev, adc_dev->channels); +if (err <0 ) + goto err_free_device; + + err =iio_device_register (indio_dev); +if (err) + goto err_free_channels; + +platform_set_drvdata (pdev, indio_dev); + +return 0 ; + +err_free_channels: +tiadc_channels_remove (indio_dev); +err_free_device: +iio_device_free (indio_dev); +err_ret: +return err; +} + +static int __devexit tiadc_remove(struct platform_device *pdev) +{ +struct iio_dev *indio_dev =platform_get_drvdata (pdev); + +iio_device_unregister (indio_dev); +tiadc_channels_remove (indio_dev); + +iio_device_free (indio_dev); + +return 0 ; +} + +#ifdef CONFIG_PM +static int tiadc_suspend (struct device *dev) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct tiadc_device *adc_dev =iio_priv (indio_dev); +struct ti_tscadc_dev *tscadc_dev = dev->platform_data; +unsigned int idle; + +if (!device_may_wakeup (tscadc_dev->dev)) { + idle =tiadc_readl (adc_dev,REG_CTRL ); + idle &= ~(CNTRLREG_TSCSSENB ); +tiadc_writel (adc_dev,REG_CTRL , (idle | +CNTRLREG_POWERDOWN )); + } + +return 0 ; +} + +static int tiadc_resume (struct device *dev) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct tiadc_device *adc_dev =iio_priv (indio_dev); +unsigned int restore; + +/* Make sure ADC is powered up */ + restore =tiadc_readl (adc_dev,REG_CTRL ); + restore &= ~(CNTRLREG_POWERDOWN ); +tiadc_writel (adc_dev,REG_CTRL , restore); + +tiadc_step_config (adc_dev); + +return 0 ; +} + +static const struct dev_pm_ops tiadc_pm_ops = { + .suspend = tiadc_suspend, + .resume = tiadc_resume, +}; +#define TIADC_PM_OPS (&tiadc_pm_ops) +#else +#define TIADC_PM_OPS NULL +#endif + +static struct platform_driver tiadc_driver = { + .driver = { + .name ="tiadc" , + .owner =THIS_MODULE , + .pm =TIADC_PM_OPS , + }, + .probe = tiadc_probe, + .remove =__devexit_p (tiadc_remove), +}; + +module_platform_driver (tiadc_driver); + +MODULE_DESCRIPTION ("TI ADC controller driver" ); +MODULE_AUTHOR ("Rachna Patil <[email protected]>" ); +MODULE_LICENSE ("GPL" );drivers/mfd/ti_am335x_tscadc.c +17
-1@@ -25,6 +25,7 @@#include <linux/mfd/ti_am335x_tscadc.h> #include <linux/input/ti_am335x_tsc.h> +#include <linux/platform_data/ti_am335x_adc.h> static unsigned int tscadc_readl (struct ti_tscadc_dev *tsadc,unsigned int reg) {@@ -67,14 +68,23 @@ static int __devinit ti_tscadc_probe(struct platform_device *pdev)int irq;int err, ctrl;int clk_value, clock_rate; -int tsc_wires; +int tsc_wires, adc_channels =0 , total_channels;if (!pdata) {dev_err (&pdev->dev,"Could not find platform data\n" );return -EINVAL ; } +if (pdata->adc_init) + adc_channels = pdata->adc_init->adc_channels; + tsc_wires = pdata->tsc_init->wires; + total_channels = tsc_wires + adc_channels; + +if (total_channels >8 ) { +dev_err (&pdev->dev,"Number of i/p channels more than 8\n" ); +return -EINVAL ; + } res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!res) {@@ -172,6 +182,12 @@ static int __devinit ti_tscadc_probe(struct platform_device *pdev) cell->platform_data = tscadc; cell->pdata_size =sizeof (*tscadc); +/* ADC Cell */ + cell = &tscadc->cells[ADC_CELL ]; + cell->name ="tiadc" ; + cell->platform_data = tscadc; + cell->pdata_size =sizeof (*tscadc); + err =mfd_add_devices (&pdev->dev, pdev->id, tscadc->cells,TSCADC_CELLS ,NULL ,0 ,NULL );if (err <0 )include/linux/mfd/ti_am335x_tscadc.h +8
-1@@ -120,15 +120,19 @@#define ADC_CLK 3000000#define MAX_CLK_DIV 7 +#define TOTAL_STEPS 16 +#define TOTAL_CHANNELS 8 -#define TSCADC_CELLS 1 +#define TSCADC_CELLS 2enum tscadc_cells {TSC_CELL , +ADC_CELL , };struct mfd_tscadc_board {struct tsc_data *tsc_init; +struct adc_data *adc_init; };struct ti_tscadc_dev {@@ -140,6 +144,9 @@ struct ti_tscadc_dev {/* tsc device */ struct titsc *tsc; + +/* adc device */ + struct adc_device *adc; };#endif include/linux/platform_data/ti_am335x_adc.h new file +14
-0@@ -0,0 +1,14 @@ +#ifndef __LINUX_TI_AM335X_ADC_H +#define __LINUX_TI_AM335X_ADC_H + +/** +* struct adc_data ADC Input information +* @adc_channels: Number of analog inputs +* available for ADC. +*/ + +struct adc_data { +unsigned int adc_channels; +}; + +#endif