* [PATCH 01/21] MFD: ti_tscadc: disable TSC control
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
2013-07-17 17:34 ` Greg KH
2013-07-17 17:26 ` [PATCH 02/21] IIO: ADC: ti_adc: Fix 1st sample read Zubair Lutfullah
` (19 subsequent siblings)
20 siblings, 1 reply; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
Register bits when TSC not in use
AFE Pen Ctrl and TouchScreen transistors enabling is not
required when only ADC mode is being used, so check for availability of
TSC driver before accessing control register.
This patch is based on work in the 3.2 tree by TI
Original Author is Patil Rachna
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/mfd/ti_am335x_tscadc.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/drivers/mfd/ti_am335x_tscadc.c b/drivers/mfd/ti_am335x_tscadc.c
index b003a16..d72001c 100644
--- a/drivers/mfd/ti_am335x_tscadc.c
+++ b/drivers/mfd/ti_am335x_tscadc.c
@@ -208,13 +208,14 @@ static int ti_tscadc_probe(struct platform_device *pdev)
/* Set the control register bits */
ctrl = CNTRLREG_STEPCONFIGWRT |
- CNTRLREG_TSCENB |
- CNTRLREG_STEPID |
- CNTRLREG_4WIRE;
+ CNTRLREG_STEPID;
+ if (tsc_wires > 0)
+ ctrl |= CNTRLREG_4WIRE | CNTRLREG_TSCENB;
tscadc_writel(tscadc, REG_CTRL, ctrl);
/* Set register bits for Idle Config Mode */
- tscadc_idle_config(tscadc);
+ if (tsc_wires > 0)
+ tscadc_idle_config(tscadc);
/* Enable the TSC module enable bit */
ctrl = tscadc_readl(tscadc, REG_CTRL);
@@ -294,10 +295,13 @@ static int tscadc_resume(struct device *dev)
pm_runtime_get_sync(dev);
/* context restore */
- ctrl = CNTRLREG_STEPCONFIGWRT | CNTRLREG_TSCENB |
- CNTRLREG_STEPID | CNTRLREG_4WIRE;
+ ctrl = CNTRLREG_STEPCONFIGWRT | CNTRLREG_STEPID;
+ if (tscadc_dev->tsc_cell != -1)
+ ctrl |= CNTRLREG_TSCENB | CNTRLREG_4WIRE;
tscadc_writel(tscadc_dev, REG_CTRL, ctrl);
- tscadc_idle_config(tscadc_dev);
+
+ if (tscadc_dev->tsc_cell != -1)
+ tscadc_idle_config(tscadc_dev);
am335x_tsc_se_update(tscadc_dev);
restore = tscadc_readl(tscadc_dev, REG_CTRL);
tscadc_writel(tscadc_dev, REG_CTRL,
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread* Re: [PATCH 01/21] MFD: ti_tscadc: disable TSC control
2013-07-17 17:26 ` [PATCH 01/21] MFD: ti_tscadc: disable TSC control Zubair Lutfullah
@ 2013-07-17 17:34 ` Greg KH
0 siblings, 0 replies; 27+ messages in thread
From: Greg KH @ 2013-07-17 17:34 UTC (permalink / raw)
To: Zubair Lutfullah; +Cc: jic23, linux-iio, linux-kernel, koen
On Wed, Jul 17, 2013 at 06:26:30PM +0100, Zubair Lutfullah wrote:
> Register bits when TSC not in use
What does this mean?
> AFE Pen Ctrl and TouchScreen transistors enabling is not
>
> required when only ADC mode is being used, so check for availability of
>
> TSC driver before accessing control register.
What's with the extra newlines?
>
> This patch is based on work in the 3.2 tree by TI
> Original Author is Patil Rachna
If you didn't write this, you need to put the "From: " line for the
correct author/email in the patch, as Documentation/SubmittingPatches
describes so that they can get the correct credit.
> Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
What happened to Patil's signed-off-by: line?
Same goes for other patches in this series.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH 02/21] IIO: ADC: ti_adc: Fix 1st sample read
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 01/21] MFD: ti_tscadc: disable TSC control Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 03/21] iio: ti_am335x_adc: Added iio_voltageX_scale Zubair Lutfullah
` (18 subsequent siblings)
20 siblings, 0 replies; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
Previously we tried to read data form ADC even before ADC sequencer
finished sampling. This led to wrong samples.
We now wait on ADC status register idle bit to be set.
This patch is based on work in the 3.2 tree by TI
Original Author is Patil Rachna
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/iio/adc/ti_am335x_adc.c | 30 ++++++++++++++++++++++--------
include/linux/mfd/ti_am335x_tscadc.h | 16 ++++++++++++++++
2 files changed, 38 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index 4427e8e..1f83cf7 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -60,7 +60,6 @@ static void tiadc_step_config(struct tiadc_device *adc_dev)
{
unsigned int stepconfig;
int i, steps;
- u32 step_en;
/*
* There are 16 configurable steps and 8 analog input
@@ -86,8 +85,7 @@ static void tiadc_step_config(struct tiadc_device *adc_dev)
adc_dev->channel_step[i] = steps;
steps++;
}
- step_en = get_adc_step_mask(adc_dev);
- am335x_tsc_se_set(adc_dev->mfd_tscadc, step_en);
+
}
static const char * const chan_name_ain[] = {
@@ -142,10 +140,22 @@ static int tiadc_read_raw(struct iio_dev *indio_dev,
int *val, int *val2, long mask)
{
struct tiadc_device *adc_dev = iio_priv(indio_dev);
- int i;
- unsigned int fifo1count, read;
+ int i, map_val;
+ unsigned int fifo1count, read, stepid;
u32 step = UINT_MAX;
bool found = false;
+ u32 step_en;
+ unsigned long timeout = jiffies + usecs_to_jiffies
+ (IDLE_TIMEOUT * adc_dev->channels);
+ step_en = get_adc_step_mask(adc_dev);
+ am335x_tsc_se_set(adc_dev->mfd_tscadc, step_en);
+
+ /* Wait for ADC sequencer to complete sampling */
+ while (tiadc_readl(adc_dev, REG_ADCFSM) & SEQ_STATUS) {
+ if (time_after(jiffies, timeout))
+ return -EAGAIN;
+ }
+ map_val = chan->channel + TOTAL_CHANNELS;
/*
* When the sub-system is first enabled,
@@ -170,12 +180,16 @@ static int tiadc_read_raw(struct iio_dev *indio_dev,
fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT);
for (i = 0; i < fifo1count; i++) {
read = tiadc_readl(adc_dev, REG_FIFO1);
- if (read >> 16 == step) {
- *val = read & 0xfff;
+ stepid = read & FIFOREAD_CHNLID_MASK;
+ stepid = stepid >> 0x10;
+
+ if (stepid == map_val) {
+ read = read & FIFOREAD_DATA_MASK;
found = true;
+ *val = read;
}
}
- am335x_tsc_se_update(adc_dev->mfd_tscadc);
+
if (found == false)
return -EBUSY;
return IIO_VAL_INT;
diff --git a/include/linux/mfd/ti_am335x_tscadc.h b/include/linux/mfd/ti_am335x_tscadc.h
index 8d73fe2..db1791b 100644
--- a/include/linux/mfd/ti_am335x_tscadc.h
+++ b/include/linux/mfd/ti_am335x_tscadc.h
@@ -113,11 +113,27 @@
#define CNTRLREG_8WIRE CNTRLREG_AFE_CTRL(3)
#define CNTRLREG_TSCENB BIT(7)
+/* FIFO READ Register */
+#define FIFOREAD_DATA_MASK (0xfff << 0)
+#define FIFOREAD_CHNLID_MASK (0xf << 16)
+
+/* Sequencer Status */
+#define SEQ_STATUS BIT(5)
+
#define ADC_CLK 3000000
#define MAX_CLK_DIV 7
#define TOTAL_STEPS 16
#define TOTAL_CHANNELS 8
+/*
+* ADC runs at 3MHz, and it takes
+* 15 cycles to latch one data output.
+* Hence the idle time for ADC to
+* process one sample data would be
+* around 5 micro seconds.
+*/
+#define IDLE_TIMEOUT 5 /* microsec */
+
#define TSCADC_CELLS 2
struct ti_tscadc_dev {
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH 03/21] iio: ti_am335x_adc: Added iio_voltageX_scale
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 01/21] MFD: ti_tscadc: disable TSC control Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 02/21] IIO: ADC: ti_adc: Fix 1st sample read Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
2013-07-17 17:36 ` Greg KH
2013-07-17 17:26 ` [PATCH 04/21] input: ti_tsc: Enable shared IRQ for TSC Zubair Lutfullah
` (17 subsequent siblings)
20 siblings, 1 reply; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
in_voltageX_scale is supposed to give scaled voltages. This was
missing in the driver and has been added.
Current patch is fixed to scale for 1.8V AVDD.
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/iio/adc/ti_am335x_adc.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index 1f83cf7..8a63203 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -26,7 +26,7 @@
#include <linux/of_device.h>
#include <linux/iio/machine.h>
#include <linux/iio/driver.h>
-
+#include <linux/math64.h>
#include <linux/mfd/ti_am335x_tscadc.h>
struct tiadc_device {
@@ -118,7 +118,8 @@ static int tiadc_channel_init(struct iio_dev *indio_dev, int channels)
chan->type = IIO_VOLTAGE;
chan->indexed = 1;
chan->channel = adc_dev->channel_line[i];
- chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW);
+ chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+ BIT(IIO_CHAN_INFO_SCALE);
chan->datasheet_name = chan_name_ain[chan->channel];
chan->scan_type.sign = 'u';
chan->scan_type.realbits = 12;
@@ -190,6 +191,18 @@ static int tiadc_read_raw(struct iio_dev *indio_dev,
}
}
+ switch (mask){
+ case IIO_CHAN_INFO_RAW : /*Do nothing. Above code works fine.*/
+ break;
+ case IIO_CHAN_INFO_SCALE : {
+ /*12 Bit adc. Scale value for 1800mV AVDD. Ideally
+ AVDD should come from DT.*/
+ *val = div_u64( (u64)(*val) * 1800 , 4096);
+ break;
+ }
+ default: break;
+ }
+
if (found == false)
return -EBUSY;
return IIO_VAL_INT;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread* Re: [PATCH 03/21] iio: ti_am335x_adc: Added iio_voltageX_scale
2013-07-17 17:26 ` [PATCH 03/21] iio: ti_am335x_adc: Added iio_voltageX_scale Zubair Lutfullah
@ 2013-07-17 17:36 ` Greg KH
0 siblings, 0 replies; 27+ messages in thread
From: Greg KH @ 2013-07-17 17:36 UTC (permalink / raw)
To: Zubair Lutfullah; +Cc: jic23, linux-iio, linux-kernel, koen
On Wed, Jul 17, 2013 at 06:26:32PM +0100, Zubair Lutfullah wrote:
> in_voltageX_scale is supposed to give scaled voltages. This was
> missing in the driver and has been added.
> Current patch is fixed to scale for 1.8V AVDD.
>
> Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
> ---
> drivers/iio/adc/ti_am335x_adc.c | 17 +++++++++++++++--
> 1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
> index 1f83cf7..8a63203 100644
> --- a/drivers/iio/adc/ti_am335x_adc.c
> +++ b/drivers/iio/adc/ti_am335x_adc.c
> @@ -26,7 +26,7 @@
> #include <linux/of_device.h>
> #include <linux/iio/machine.h>
> #include <linux/iio/driver.h>
> -
> +#include <linux/math64.h>
> #include <linux/mfd/ti_am335x_tscadc.h>
>
> struct tiadc_device {
> @@ -118,7 +118,8 @@ static int tiadc_channel_init(struct iio_dev *indio_dev, int channels)
> chan->type = IIO_VOLTAGE;
> chan->indexed = 1;
> chan->channel = adc_dev->channel_line[i];
> - chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW);
> + chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> + BIT(IIO_CHAN_INFO_SCALE);
> chan->datasheet_name = chan_name_ain[chan->channel];
> chan->scan_type.sign = 'u';
> chan->scan_type.realbits = 12;
> @@ -190,6 +191,18 @@ static int tiadc_read_raw(struct iio_dev *indio_dev,
> }
> }
>
> + switch (mask){
> + case IIO_CHAN_INFO_RAW : /*Do nothing. Above code works fine.*/
What "above code"?
> + break;
Please fix the indentation.
> + case IIO_CHAN_INFO_SCALE : {
> + /*12 Bit adc. Scale value for 1800mV AVDD. Ideally
> + AVDD should come from DT.*/
Did you run this patch through the scripts/codingstyle tool? Please be
generous in your spaces, there's no need to conserve them.
> + *val = div_u64( (u64)(*val) * 1800 , 4096);
> + break;
> + }
> + default: break;
> + }
thanks,
greg k-h
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH 04/21] input: ti_tsc: Enable shared IRQ for TSC
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
` (2 preceding siblings ...)
2013-07-17 17:26 ` [PATCH 03/21] iio: ti_am335x_adc: Added iio_voltageX_scale Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 05/21] iio: input: am335x_adc: Add continuous mode to adc Zubair Lutfullah
` (16 subsequent siblings)
20 siblings, 0 replies; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
Touchscreen and ADC share the same IRQ line from parent
MFD core.
Previously only Touchscreen was interrupt based.
With continuous mode support added in ADC driver, now driver requires
interrupt to process the ADC samples, so enable shared IRQ flag bit for
touchscreen.
This patch is based on work in the 3.2 tree by TI
Original Author is Patil Rachna
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/input/touchscreen/ti_am335x_tsc.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/drivers/input/touchscreen/ti_am335x_tsc.c b/drivers/input/touchscreen/ti_am335x_tsc.c
index 0e9f02a..cf56cae 100644
--- a/drivers/input/touchscreen/ti_am335x_tsc.c
+++ b/drivers/input/touchscreen/ti_am335x_tsc.c
@@ -260,8 +260,16 @@ static irqreturn_t titsc_irq(int irq, void *dev)
unsigned int fsm;
status = titsc_readl(ts_dev, REG_IRQSTATUS);
- if (status & IRQENB_FIFO0THRES) {
-
+
+ /*
+ * ADC and touchscreen share the IRQ line.
+ * FIFO1 threshold interrupt is used by ADC,
+ * hence return from touchscreen IRQ handler if FIFO1
+ * threshold interrupt occurred.
+ */
+ if (status & IRQENB_FIFO1THRES)
+ return IRQ_NONE;
+ else if (status & IRQENB_FIFO0THRES) {
titsc_read_coordinates(ts_dev, &x, &y, &z1, &z2);
if (ts_dev->pen_down && z1 != 0 && z2 != 0) {
@@ -315,7 +323,7 @@ static irqreturn_t titsc_irq(int irq, void *dev)
}
if (irqclr) {
- titsc_writel(ts_dev, REG_IRQSTATUS, irqclr);
+ titsc_writel(ts_dev, REG_IRQSTATUS, (status | irqclr) );
am335x_tsc_se_update(ts_dev->mfd_tscadc);
return IRQ_HANDLED;
}
@@ -389,7 +397,7 @@ static int titsc_probe(struct platform_device *pdev)
}
err = request_irq(ts_dev->irq, titsc_irq,
- 0, pdev->dev.driver->name, ts_dev);
+ IRQF_SHARED, pdev->dev.driver->name, ts_dev);
if (err) {
dev_err(&pdev->dev, "failed to allocate irq.\n");
goto err_free_mem;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH 05/21] iio: input: am335x_adc: Add continuous mode to adc
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
` (3 preceding siblings ...)
2013-07-17 17:26 ` [PATCH 04/21] input: ti_tsc: Enable shared IRQ for TSC Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
2013-07-17 17:38 ` Greg KH
2013-07-18 8:08 ` Felipe Balbi
2013-07-17 17:26 ` [PATCH 06/21] MFD: ti_tscadc: ADC Clock check not required Zubair Lutfullah
` (15 subsequent siblings)
20 siblings, 2 replies; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
Main patch. Adds continuous sampling support for the driver
The IRQs are changed in the TSC drivers as they are shared with
the ADC IRQ lines.
This patch is based on work in the 3.2 tree by TI
Original Author is Patil Rachna
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/iio/adc/ti_am335x_adc.c | 386 ++++++++++++++++++++++++-----
drivers/input/touchscreen/ti_am335x_tsc.c | 9 +-
drivers/mfd/ti_am335x_tscadc.c | 12 +-
include/linux/mfd/ti_am335x_tscadc.h | 12 +
4 files changed, 351 insertions(+), 68 deletions(-)
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index 8a63203..1f6e800 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -29,11 +29,25 @@
#include <linux/math64.h>
#include <linux/mfd/ti_am335x_tscadc.h>
+#include <linux/stat.h>
+
+#include <linux/sched.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/kfifo_buf.h>
+#include <linux/iio/sysfs.h>
+#include <linux/delay.h>
+
struct tiadc_device {
struct ti_tscadc_dev *mfd_tscadc;
int channels;
u8 channel_line[8];
u8 channel_step[8];
+ struct work_struct poll_work;
+ wait_queue_head_t wq_data_avail;
+ int irq;
+ bool is_continuous_mode;
+ u16 *buffer;
};
static unsigned int tiadc_readl(struct tiadc_device *adc, unsigned int reg)
@@ -56,7 +70,7 @@ static u32 get_adc_step_mask(struct tiadc_device *adc_dev)
return step_en;
}
-static void tiadc_step_config(struct tiadc_device *adc_dev)
+static void tiadc_step_config(struct tiadc_device *adc_dev,bool mode)
{
unsigned int stepconfig;
int i, steps;
@@ -72,7 +86,11 @@ static void tiadc_step_config(struct tiadc_device *adc_dev)
*/
steps = TOTAL_STEPS - adc_dev->channels;
- stepconfig = STEPCONFIG_AVG_16 | STEPCONFIG_FIFO1;
+ if (mode == 0)
+ stepconfig = STEPCONFIG_AVG_16 | STEPCONFIG_FIFO1;
+ else
+ stepconfig = STEPCONFIG_AVG_16 | STEPCONFIG_FIFO1
+ | STEPCONFIG_MODE_SWCNT;
for (i = 0; i < adc_dev->channels; i++) {
int chan;
@@ -88,6 +106,226 @@ static void tiadc_step_config(struct tiadc_device *adc_dev)
}
+static ssize_t tiadc_show_mode(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct tiadc_device *adc_dev = iio_priv(indio_dev);
+ unsigned int tmp;
+
+ tmp = tiadc_readl(adc_dev, REG_STEPCONFIG(TOTAL_STEPS));
+ tmp &= STEPCONFIG_MODE(1);
+
+ if (tmp == 0x00)
+ return sprintf(buf, "oneshot\n");
+ else if (tmp == 0x01)
+ return sprintf(buf, "continuous\n");
+ else
+ return sprintf(buf, "Operation mode unknown\n");
+}
+
+static ssize_t tiadc_set_mode(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count)
+{
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct tiadc_device *adc_dev = iio_priv(indio_dev);
+ unsigned config;
+
+ config = tiadc_readl(adc_dev, REG_CTRL);
+ config &= ~(CNTRLREG_TSCSSENB);
+ tiadc_writel(adc_dev, REG_CTRL, config);
+
+ if (!strncmp(buf, "oneshot", 7))
+ adc_dev->is_continuous_mode = false;
+ else if (!strncmp(buf, "continuous", 10))
+ adc_dev->is_continuous_mode = true;
+ else {
+ dev_err(dev, "Operational mode unknown\n");
+ return -EINVAL;
+ }
+
+ tiadc_step_config(adc_dev, adc_dev->is_continuous_mode);
+
+ config = tiadc_readl(adc_dev, REG_CTRL);
+ tiadc_writel(adc_dev, REG_CTRL,
+ (config | CNTRLREG_TSCSSENB));
+ return count;
+}
+
+static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, tiadc_show_mode,
+ tiadc_set_mode, 0);
+
+static struct attribute *tiadc_attributes[] = {
+ &iio_dev_attr_mode.dev_attr.attr,
+ NULL,
+};
+
+static const struct attribute_group tiadc_attribute_group = {
+ .attrs = tiadc_attributes,
+};
+
+static irqreturn_t tiadc_irq(int irq, void *private)
+{
+ struct iio_dev *idev = private;
+ struct tiadc_device *adc_dev = iio_priv(idev);
+ unsigned int status, config;
+
+ status = tiadc_readl(adc_dev, REG_IRQSTATUS);
+ if (status & IRQENB_FIFO1THRES) {
+ tiadc_writel(adc_dev, REG_IRQCLR,
+ IRQENB_FIFO1THRES);
+
+ if (iio_buffer_enabled(idev)) {
+ if (!work_pending(&adc_dev->poll_work))
+ schedule_work(&adc_dev->poll_work);
+ } else {
+ wake_up_interruptible(&adc_dev->wq_data_avail);
+ }
+ tiadc_writel(adc_dev, REG_IRQSTATUS,
+ (status | IRQENB_FIFO1THRES));
+ return IRQ_HANDLED;
+ } else if ((status & IRQENB_FIFO1OVRRUN) ||
+ (status & IRQENB_FIFO1UNDRFLW)) {
+ config = tiadc_readl(adc_dev, REG_CTRL);
+ config &= ~( CNTRLREG_TSCSSENB);
+ tiadc_writel(adc_dev, REG_CTRL, config);
+
+ if (status & IRQENB_FIFO1UNDRFLW)
+ tiadc_writel(adc_dev, REG_IRQSTATUS,
+ (status | IRQENB_FIFO1UNDRFLW));
+ else
+ tiadc_writel(adc_dev, REG_IRQSTATUS,
+ (status | IRQENB_FIFO1OVRRUN));
+
+ tiadc_writel(adc_dev, REG_CTRL,
+ (config | CNTRLREG_TSCSSENB));
+ return IRQ_HANDLED;
+ } else {
+ return IRQ_NONE;
+ }
+}
+
+static void tiadc_poll_handler(struct work_struct *work_s)
+{
+ struct tiadc_device *adc_dev =
+ container_of(work_s, struct tiadc_device, poll_work);
+ struct iio_dev *idev = iio_priv_to_dev(adc_dev);
+ struct iio_buffer *buffer = idev->buffer;
+ unsigned int fifo1count, readx1, status;
+ int i;
+ u32 *iBuf;
+
+ fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT);
+ iBuf = kmalloc((fifo1count + 1) * sizeof(u32), GFP_KERNEL);
+ if (iBuf == NULL)
+ return;
+ /*
+ * Wait for ADC sequencer to settle down.
+ * There could be a scenario where in we
+ * try to read data from ADC before
+ * it is available.
+ */
+ udelay(500);
+
+ for (i = 0; i < fifo1count; i++) {
+ readx1 = tiadc_readl(adc_dev, REG_FIFO1);
+ readx1 &= FIFOREAD_DATA_MASK;
+ iBuf[i] = readx1;
+ }
+
+ buffer->access->store_to(buffer, (u8 *) iBuf);
+ status = tiadc_readl(adc_dev, REG_IRQENABLE);
+ tiadc_writel(adc_dev, REG_IRQENABLE,
+ (status | IRQENB_FIFO1THRES));
+
+ kfree(iBuf);
+}
+
+static int tiadc_buffer_preenable(struct iio_dev *idev)
+{
+ struct iio_buffer *buffer = idev->buffer;
+
+ buffer->access->set_bytes_per_datum(buffer, 16);
+ return 0;
+}
+
+static int tiadc_buffer_postenable(struct iio_dev *idev)
+{
+ struct tiadc_device *adc_dev = iio_priv(idev);
+ struct iio_buffer *buffer = idev->buffer;
+ unsigned int enb, status, fifo1count;
+ int stepnum, i;
+ u8 bit;
+
+ if (!adc_dev->is_continuous_mode) {
+ printk("Data cannot be read continuously in one shot mode\n");
+ return -EINVAL;
+ } else {
+ status = tiadc_readl(adc_dev, REG_IRQENABLE);
+ tiadc_writel(adc_dev, REG_IRQENABLE,
+ (status | IRQENB_FIFO1THRES)|
+ IRQENB_FIFO1OVRRUN |
+ IRQENB_FIFO1UNDRFLW);
+
+ fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT);
+ for (i = 0; i < fifo1count; i++)
+ tiadc_readl(adc_dev, REG_FIFO1);
+
+ tiadc_writel(adc_dev, REG_SE, 0x00);
+ for_each_set_bit(bit, buffer->scan_mask,
+ adc_dev->channels) {
+ struct iio_chan_spec const *chan = idev->channels + bit;
+ /*
+ * There are a total of 16 steps available
+ * that are shared between ADC and touchscreen.
+ * We start configuring from step 16 to 0 incase of
+ * ADC. Hence the relation between input channel
+ * and step for ADC would be as below.
+ */
+ stepnum = chan->channel + 9;
+ enb = tiadc_readl(adc_dev, REG_SE);
+ enb |= (1 << stepnum);
+ tiadc_writel(adc_dev, REG_SE, enb);
+ }
+ return 0;
+ }
+}
+
+static int tiadc_buffer_postdisable(struct iio_dev *idev)
+{
+ struct tiadc_device *adc_dev = iio_priv(idev);
+
+ tiadc_writel(adc_dev, REG_IRQCLR, (IRQENB_FIFO1THRES |
+ IRQENB_FIFO1OVRRUN |
+ IRQENB_FIFO1UNDRFLW));
+ tiadc_writel(adc_dev, REG_SE, STPENB_STEPENB_TC);
+ return 0;
+}
+
+static const struct iio_buffer_setup_ops tiadc_buffer_setup_ops = {
+ .preenable = &tiadc_buffer_preenable,
+ .postenable = &tiadc_buffer_postenable,
+ .postdisable = &tiadc_buffer_postdisable,
+};
+
+static int tiadc_config_sw_ring(struct iio_dev *idev)
+{
+ struct tiadc_device *adc_dev = iio_priv(idev);
+ //int ret;
+
+ idev->buffer = iio_kfifo_allocate(idev);
+ if (!idev->buffer)
+ return(-ENOMEM);
+
+ // idev->buffer->access = &ring_sw_access_funcs;
+ idev->setup_ops = &tiadc_buffer_setup_ops;
+
+ INIT_WORK(&adc_dev->poll_work, &tiadc_poll_handler);
+
+ idev->modes |= INDIO_BUFFER_HARDWARE;
+ return 0;
+}
+
static const char * const chan_name_ain[] = {
"AIN0",
"AIN1",
@@ -121,6 +359,7 @@ static int tiadc_channel_init(struct iio_dev *indio_dev, int channels)
chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE);
chan->datasheet_name = chan_name_ain[chan->channel];
+ chan->scan_index = i;
chan->scan_type.sign = 'u';
chan->scan_type.realbits = 12;
chan->scan_type.storagebits = 32;
@@ -148,68 +387,76 @@ static int tiadc_read_raw(struct iio_dev *indio_dev,
u32 step_en;
unsigned long timeout = jiffies + usecs_to_jiffies
(IDLE_TIMEOUT * adc_dev->channels);
- step_en = get_adc_step_mask(adc_dev);
- am335x_tsc_se_set(adc_dev->mfd_tscadc, step_en);
-
- /* Wait for ADC sequencer to complete sampling */
- while (tiadc_readl(adc_dev, REG_ADCFSM) & SEQ_STATUS) {
- if (time_after(jiffies, timeout))
- return -EAGAIN;
- }
- map_val = chan->channel + TOTAL_CHANNELS;
- /*
- * 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.
- */
-
- for (i = 0; i < ARRAY_SIZE(adc_dev->channel_step); i++) {
- if (chan->channel == adc_dev->channel_line[i]) {
- step = adc_dev->channel_step[i];
- break;
+ if (adc_dev->is_continuous_mode) {
+ printk("One shot mode not enabled\n");
+ return -EINVAL;
+ } else {
+
+ step_en = get_adc_step_mask(adc_dev);
+ am335x_tsc_se_set(adc_dev->mfd_tscadc, step_en);
+
+ /* Wait for ADC sequencer to complete sampling */
+ while (tiadc_readl(adc_dev, REG_ADCFSM) & SEQ_STATUS) {
+ if (time_after(jiffies, timeout))
+ return -EAGAIN;
+ }
+ map_val = chan->channel + TOTAL_CHANNELS;
+
+ /*
+ * 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.
+ */
+
+ for (i = 0; i < ARRAY_SIZE(adc_dev->channel_step); i++) {
+ if (chan->channel == adc_dev->channel_line[i]) {
+ step = adc_dev->channel_step[i];
+ break;
+ }
}
- }
- if (WARN_ON_ONCE(step == UINT_MAX))
- return -EINVAL;
-
- fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT);
- for (i = 0; i < fifo1count; i++) {
- read = tiadc_readl(adc_dev, REG_FIFO1);
- stepid = read & FIFOREAD_CHNLID_MASK;
- stepid = stepid >> 0x10;
-
- if (stepid == map_val) {
- read = read & FIFOREAD_DATA_MASK;
- found = true;
- *val = read;
+ if (WARN_ON_ONCE(step == UINT_MAX))
+ return -EINVAL;
+
+ fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT);
+ for (i = 0; i < fifo1count; i++) {
+ read = tiadc_readl(adc_dev, REG_FIFO1);
+ stepid = read & FIFOREAD_CHNLID_MASK;
+ stepid = stepid >> 0x10;
+
+ if (stepid == map_val) {
+ read = read & FIFOREAD_DATA_MASK;
+ found = true;
+ *val = read;
+ }
}
- }
- switch (mask){
- case IIO_CHAN_INFO_RAW : /*Do nothing. Above code works fine.*/
- break;
- case IIO_CHAN_INFO_SCALE : {
- /*12 Bit adc. Scale value for 1800mV AVDD. Ideally
- AVDD should come from DT.*/
- *val = div_u64( (u64)(*val) * 1800 , 4096);
- break;
+ switch (mask){
+ case IIO_CHAN_INFO_RAW : /*Do nothing. Above code works fine.*/
+ break;
+ case IIO_CHAN_INFO_SCALE : {
+ /*12 Bit adc. Scale value for 1800mV AVDD. Ideally
+ AVDD should come from DT.*/
+ *val = div_u64( (u64)(*val) * 1800 , 4096);
+ break;
+ }
+ default: break;
}
- default: break;
- }
- if (found == false)
- return -EBUSY;
- return IIO_VAL_INT;
+ if (found == false)
+ return -EBUSY;
+ return IIO_VAL_INT;
+ }
}
static const struct iio_info tiadc_info = {
.read_raw = &tiadc_read_raw,
+ .attrs = &tiadc_attribute_group,
};
static int tiadc_probe(struct platform_device *pdev)
@@ -243,17 +490,37 @@ static int tiadc_probe(struct platform_device *pdev)
channels++;
}
adc_dev->channels = channels;
+ adc_dev->irq = adc_dev->mfd_tscadc->irq;
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);
+ /* by default driver comes up with oneshot mode */
+ tiadc_step_config(adc_dev, adc_dev->is_continuous_mode);
+
+ /* program FIFO threshold to value minus 1 */
+ tiadc_writel(adc_dev, REG_FIFO1THR, FIFO1_THRESHOLD);
err = tiadc_channel_init(indio_dev, adc_dev->channels);
if (err < 0)
goto err_free_device;
+ init_waitqueue_head(&adc_dev->wq_data_avail);
+
+ err = request_irq(adc_dev->irq, tiadc_irq, IRQF_SHARED,
+ indio_dev->name, indio_dev);
+ if (err)
+ goto err_free_irq;
+
+ err = tiadc_config_sw_ring(indio_dev);
+ if (err < 0)
+ goto err_unregister;
+
+ err = iio_buffer_register(indio_dev,
+ indio_dev->channels, indio_dev->num_channels);
+ if (err < 0)
+ goto err_unregister;
err = iio_device_register(indio_dev);
if (err)
@@ -263,6 +530,10 @@ static int tiadc_probe(struct platform_device *pdev)
return 0;
+err_unregister:
+
+err_free_irq:
+ free_irq(adc_dev->irq, indio_dev);
err_free_channels:
tiadc_channels_remove(indio_dev);
err_free_device:
@@ -313,13 +584,14 @@ static int tiadc_resume(struct device *dev)
struct tiadc_device *adc_dev = iio_priv(indio_dev);
unsigned int restore;
+ tiadc_writel(adc_dev, REG_FIFO1THR, FIFO1_THRESHOLD);
+ tiadc_step_config(adc_dev, adc_dev->is_continuous_mode);
+
/* 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;
}
diff --git a/drivers/input/touchscreen/ti_am335x_tsc.c b/drivers/input/touchscreen/ti_am335x_tsc.c
index cf56cae..4bf2ee6 100644
--- a/drivers/input/touchscreen/ti_am335x_tsc.c
+++ b/drivers/input/touchscreen/ti_am335x_tsc.c
@@ -263,11 +263,14 @@ static irqreturn_t titsc_irq(int irq, void *dev)
/*
* ADC and touchscreen share the IRQ line.
- * FIFO1 threshold interrupt is used by ADC,
+ * FIFO1 threshold, FIFO1 Overrun and FIFO1 underflow
+ * interrupts are used by ADC,
* hence return from touchscreen IRQ handler if FIFO1
- * threshold interrupt occurred.
+ * related interrupts occurred.
*/
- if (status & IRQENB_FIFO1THRES)
+ if ((status & IRQENB_FIFO1THRES) ||
+ (status & IRQENB_FIFO1OVRRUN) ||
+ (status & IRQENB_FIFO1UNDRFLW))
return IRQ_NONE;
else if (status & IRQENB_FIFO0THRES) {
titsc_read_coordinates(ts_dev, &x, &y, &z1, &z2);
diff --git a/drivers/mfd/ti_am335x_tscadc.c b/drivers/mfd/ti_am335x_tscadc.c
index d72001c..fdbd0d5 100644
--- a/drivers/mfd/ti_am335x_tscadc.c
+++ b/drivers/mfd/ti_am335x_tscadc.c
@@ -282,6 +282,8 @@ static int tscadc_suspend(struct device *dev)
struct ti_tscadc_dev *tscadc_dev = dev_get_drvdata(dev);
tscadc_writel(tscadc_dev, REG_SE, 0x00);
+ tscadc_dev->irqstat = tscadc_readl(tscadc_dev, REG_IRQENABLE);
+ tscadc_dev->ctrl = tscadc_readl(tscadc_dev, REG_CTRL);
pm_runtime_put_sync(dev);
return 0;
@@ -290,22 +292,16 @@ static int tscadc_suspend(struct device *dev)
static int tscadc_resume(struct device *dev)
{
struct ti_tscadc_dev *tscadc_dev = dev_get_drvdata(dev);
- unsigned int restore, ctrl;
pm_runtime_get_sync(dev);
/* context restore */
- ctrl = CNTRLREG_STEPCONFIGWRT | CNTRLREG_STEPID;
- if (tscadc_dev->tsc_cell != -1)
- ctrl |= CNTRLREG_TSCENB | CNTRLREG_4WIRE;
- tscadc_writel(tscadc_dev, REG_CTRL, ctrl);
+ tscadc_writel(tscadc_dev, REG_IRQENABLE, tscadc_dev->irqstat);
if (tscadc_dev->tsc_cell != -1)
tscadc_idle_config(tscadc_dev);
am335x_tsc_se_update(tscadc_dev);
- restore = tscadc_readl(tscadc_dev, REG_CTRL);
- tscadc_writel(tscadc_dev, REG_CTRL,
- (restore | CNTRLREG_TSCSSENB));
+ tscadc_writel(tscadc_dev, REG_CTRL, tscadc_dev->ctrl);
return 0;
}
diff --git a/include/linux/mfd/ti_am335x_tscadc.h b/include/linux/mfd/ti_am335x_tscadc.h
index db1791b..f436918 100644
--- a/include/linux/mfd/ti_am335x_tscadc.h
+++ b/include/linux/mfd/ti_am335x_tscadc.h
@@ -46,17 +46,23 @@
/* Step Enable */
#define STEPENB_MASK (0x1FFFF << 0)
#define STEPENB(val) ((val) << 0)
+#define ENB(val) (1 << (val))
+#define STPENB_STEPENB STEPENB(0x1FFFF)
+#define STPENB_STEPENB_TC STEPENB(0x1FFF)
/* IRQ enable */
#define IRQENB_HW_PEN BIT(0)
#define IRQENB_FIFO0THRES BIT(2)
#define IRQENB_FIFO1THRES BIT(5)
#define IRQENB_PENUP BIT(9)
+#define IRQENB_FIFO1OVRRUN BIT(6)
+#define IRQENB_FIFO1UNDRFLW BIT(7)
/* Step Configuration */
#define STEPCONFIG_MODE_MASK (3 << 0)
#define STEPCONFIG_MODE(val) ((val) << 0)
#define STEPCONFIG_MODE_HWSYNC STEPCONFIG_MODE(2)
+#define STEPCONFIG_MODE_SWCNT STEPCONFIG_MODE(1)
#define STEPCONFIG_AVG_MASK (7 << 2)
#define STEPCONFIG_AVG(val) ((val) << 2)
#define STEPCONFIG_AVG_16 STEPCONFIG_AVG(4)
@@ -124,6 +130,7 @@
#define MAX_CLK_DIV 7
#define TOTAL_STEPS 16
#define TOTAL_CHANNELS 8
+#define FIFO1_THRESHOLD 19
/*
* ADC runs at 3MHz, and it takes
@@ -153,6 +160,11 @@ struct ti_tscadc_dev {
/* adc device */
struct adc_device *adc;
+
+ /* Context save */
+ unsigned int irqstat;
+ unsigned int ctrl;
+
};
static inline struct ti_tscadc_dev *ti_tscadc_dev_get(struct platform_device *p)
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread* Re: [PATCH 05/21] iio: input: am335x_adc: Add continuous mode to adc
2013-07-17 17:26 ` [PATCH 05/21] iio: input: am335x_adc: Add continuous mode to adc Zubair Lutfullah
@ 2013-07-17 17:38 ` Greg KH
[not found] ` <CAExKytyQ23VXMVyRX9OHEQ8HZT5tFhKHSjhaH_-G_O1BVL91-A@mail.gmail.com>
2013-07-18 8:08 ` Felipe Balbi
1 sibling, 1 reply; 27+ messages in thread
From: Greg KH @ 2013-07-17 17:38 UTC (permalink / raw)
To: Zubair Lutfullah; +Cc: jic23, linux-iio, linux-kernel, koen
On Wed, Jul 17, 2013 at 06:26:34PM +0100, Zubair Lutfullah wrote:
> Main patch. Adds continuous sampling support for the driver
What does that mean? Why have this in the changelog at all?
>
> The IRQs are changed in the TSC drivers as they are shared with
> the ADC IRQ lines.
>
> This patch is based on work in the 3.2 tree by TI
> Original Author is Patil Rachna
>
> Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
> ---
> drivers/iio/adc/ti_am335x_adc.c | 386 ++++++++++++++++++++++++-----
> drivers/input/touchscreen/ti_am335x_tsc.c | 9 +-
> drivers/mfd/ti_am335x_tscadc.c | 12 +-
> include/linux/mfd/ti_am335x_tscadc.h | 12 +
> 4 files changed, 351 insertions(+), 68 deletions(-)
>
> diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
> index 8a63203..1f6e800 100644
> --- a/drivers/iio/adc/ti_am335x_adc.c
> +++ b/drivers/iio/adc/ti_am335x_adc.c
> @@ -29,11 +29,25 @@
> #include <linux/math64.h>
> #include <linux/mfd/ti_am335x_tscadc.h>
>
> +#include <linux/stat.h>
> +
> +#include <linux/sched.h>
Why extra newlines?
> +#include <linux/iio/buffer.h>
> +#include <linux/iio/trigger_consumer.h>
> +#include <linux/iio/kfifo_buf.h>
> +#include <linux/iio/sysfs.h>
> +#include <linux/delay.h>
> +
> struct tiadc_device {
> struct ti_tscadc_dev *mfd_tscadc;
> int channels;
> u8 channel_line[8];
> u8 channel_step[8];
> + struct work_struct poll_work;
> + wait_queue_head_t wq_data_avail;
> + int irq;
> + bool is_continuous_mode;
> + u16 *buffer;
Please run all of these patches through checkpatch and fix the issues
that are reported, otherwise there is no way they can be accepted.
I've stopped reviewing this series here...
thanks,
greg k-h
^ permalink raw reply [flat|nested] 27+ messages in thread* Re: [PATCH 05/21] iio: input: am335x_adc: Add continuous mode to adc
2013-07-17 17:26 ` [PATCH 05/21] iio: input: am335x_adc: Add continuous mode to adc Zubair Lutfullah
2013-07-17 17:38 ` Greg KH
@ 2013-07-18 8:08 ` Felipe Balbi
1 sibling, 0 replies; 27+ messages in thread
From: Felipe Balbi @ 2013-07-18 8:08 UTC (permalink / raw)
To: Zubair Lutfullah; +Cc: jic23, linux-iio, gregkh, linux-kernel, koen
[-- Attachment #1: Type: text/plain, Size: 599 bytes --]
Hi,
On Wed, Jul 17, 2013 at 06:26:34PM +0100, Zubair Lutfullah wrote:
> Main patch. Adds continuous sampling support for the driver
>
> The IRQs are changed in the TSC drivers as they are shared with
> the ADC IRQ lines.
>
> This patch is based on work in the 3.2 tree by TI
> Original Author is Patil Rachna
>
> Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
to me this patch looks incorrect. IIO framework provides a generic ring
buffer implementation which could be used for continuous mode. Adding
driver specific attributes isn't very nice IMO.
--
balbi
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH 06/21] MFD: ti_tscadc: ADC Clock check not required
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
` (4 preceding siblings ...)
2013-07-17 17:26 ` [PATCH 05/21] iio: input: am335x_adc: Add continuous mode to adc Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 07/21] iio: TI-am335x-adc: Cleanup Zubair Lutfullah
` (14 subsequent siblings)
20 siblings, 0 replies; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
ADC is ideally expected to work at a frequency of 3MHz.
The present code had a check, which returned error if the frequency
went below the threshold value. But since AM335x supports various
working frequencies, this check is not required.
Now the code just uses the internal ADC clock divider to set the ADC
frequency w.r.t the sys clock.
Signed-off-by: Patil, Rachna <rachna@ti.com>
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/mfd/ti_am335x_tscadc.c | 6 +-----
include/linux/mfd/ti_am335x_tscadc.h | 1 -
2 files changed, 1 insertion(+), 6 deletions(-)
diff --git a/drivers/mfd/ti_am335x_tscadc.c b/drivers/mfd/ti_am335x_tscadc.c
index fdbd0d5..e7314e4 100644
--- a/drivers/mfd/ti_am335x_tscadc.c
+++ b/drivers/mfd/ti_am335x_tscadc.c
@@ -197,11 +197,7 @@ static int ti_tscadc_probe(struct platform_device *pdev)
clock_rate = clk_get_rate(clk);
clk_put(clk);
clk_value = clock_rate / ADC_CLK;
- if (clk_value < MAX_CLK_DIV) {
- dev_err(&pdev->dev, "clock input less than min clock requirement\n");
- err = -EINVAL;
- goto err_disable_clk;
- }
+
/* TSCADC_CLKDIV needs to be configured to the value minus 1 */
clk_value = clk_value - 1;
tscadc_writel(tscadc, REG_CLKDIV, clk_value);
diff --git a/include/linux/mfd/ti_am335x_tscadc.h b/include/linux/mfd/ti_am335x_tscadc.h
index f436918..1516dc8 100644
--- a/include/linux/mfd/ti_am335x_tscadc.h
+++ b/include/linux/mfd/ti_am335x_tscadc.h
@@ -127,7 +127,6 @@
#define SEQ_STATUS BIT(5)
#define ADC_CLK 3000000
-#define MAX_CLK_DIV 7
#define TOTAL_STEPS 16
#define TOTAL_CHANNELS 8
#define FIFO1_THRESHOLD 19
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH 07/21] iio: TI-am335x-adc: Cleanup
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
` (5 preceding siblings ...)
2013-07-17 17:26 ` [PATCH 06/21] MFD: ti_tscadc: ADC Clock check not required Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 08/21] IIO: ti_adc: Handle set to clear IRQENABLE register properly Zubair Lutfullah
` (13 subsequent siblings)
20 siblings, 0 replies; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
Cleaned up the code a bit. Some formatting.
Some error handling paths corrected
This patch is based on work in the 3.2 tree by TI
Original Author is Patil Rachna
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/iio/adc/ti_am335x_adc.c | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index 1f6e800..31665fa 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -311,13 +311,11 @@ static const struct iio_buffer_setup_ops tiadc_buffer_setup_ops = {
static int tiadc_config_sw_ring(struct iio_dev *idev)
{
struct tiadc_device *adc_dev = iio_priv(idev);
- //int ret;
idev->buffer = iio_kfifo_allocate(idev);
if (!idev->buffer)
return(-ENOMEM);
- // idev->buffer->access = &ring_sw_access_funcs;
idev->setup_ops = &tiadc_buffer_setup_ops;
INIT_WORK(&adc_dev->poll_work, &tiadc_poll_handler);
@@ -506,21 +504,22 @@ static int tiadc_probe(struct platform_device *pdev)
err = tiadc_channel_init(indio_dev, adc_dev->channels);
if (err < 0)
goto err_free_device;
- init_waitqueue_head(&adc_dev->wq_data_avail);
- err = request_irq(adc_dev->irq, tiadc_irq, IRQF_SHARED,
- indio_dev->name, indio_dev);
- if (err)
- goto err_free_irq;
+ init_waitqueue_head(&adc_dev->wq_data_avail);
- err = tiadc_config_sw_ring(indio_dev);
- if (err < 0)
- goto err_unregister;
+ err = request_irq(adc_dev->irq, tiadc_irq, IRQF_SHARED,
+ indio_dev->name, indio_dev);
+ if (err)
+ goto err_free_irq;
+
+ err = tiadc_config_sw_ring(indio_dev);
+ if (err < 0)
+ goto err_unregister;
- err = iio_buffer_register(indio_dev,
- indio_dev->channels, indio_dev->num_channels);
- if (err < 0)
- goto err_unregister;
+ err = iio_buffer_register(indio_dev,
+ indio_dev->channels, indio_dev->num_channels);
+ if (err < 0)
+ goto err_unregister;
err = iio_device_register(indio_dev);
if (err)
@@ -531,9 +530,9 @@ static int tiadc_probe(struct platform_device *pdev)
return 0;
err_unregister:
-
+ iio_buffer_unregister(indio_dev);
err_free_irq:
- free_irq(adc_dev->irq, indio_dev);
+ free_irq(adc_dev->irq, indio_dev);
err_free_channels:
tiadc_channels_remove(indio_dev);
err_free_device:
@@ -548,7 +547,9 @@ static int tiadc_remove(struct platform_device *pdev)
struct tiadc_device *adc_dev = iio_priv(indio_dev);
u32 step_en;
+ free_irq(adc_dev->irq, indio_dev);
iio_device_unregister(indio_dev);
+ iio_buffer_unregister(indio_dev);
tiadc_channels_remove(indio_dev);
step_en = get_adc_step_mask(adc_dev);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH 08/21] IIO: ti_adc: Handle set to clear IRQENABLE register properly.
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
` (6 preceding siblings ...)
2013-07-17 17:26 ` [PATCH 07/21] iio: TI-am335x-adc: Cleanup Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 09/21] IIO: ti_adc: Handle set to clear IRQSTATUS " Zubair Lutfullah
` (12 subsequent siblings)
20 siblings, 0 replies; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
The driver is currently mishandling the IRQENABLE register. The driver
should write a 1 for bits it wishes to set, and a zero for bits it does not
wish to change. The read of the current register contents is not
necessary.
Write 0 = No action.
Read 0 = Interrupt disabled (masked).
Read 1 = Interrupt enabled.
Write 1 = Enable interrupt.
The current read/update/write method is currently not causing any
problems, but could cause confusion in the future.
Signed-off-by: Russ Dill <Russ.Dill@ti.com>
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/iio/adc/ti_am335x_adc.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index 31665fa..a86830b 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -211,7 +211,7 @@ static void tiadc_poll_handler(struct work_struct *work_s)
container_of(work_s, struct tiadc_device, poll_work);
struct iio_dev *idev = iio_priv_to_dev(adc_dev);
struct iio_buffer *buffer = idev->buffer;
- unsigned int fifo1count, readx1, status;
+ unsigned int fifo1count, readx1;
int i;
u32 *iBuf;
@@ -234,9 +234,8 @@ static void tiadc_poll_handler(struct work_struct *work_s)
}
buffer->access->store_to(buffer, (u8 *) iBuf);
- status = tiadc_readl(adc_dev, REG_IRQENABLE);
- tiadc_writel(adc_dev, REG_IRQENABLE,
- (status | IRQENB_FIFO1THRES));
+ tiadc_writel(adc_dev, REG_IRQENABLE,
+ IRQENB_FIFO1THRES);
kfree(iBuf);
}
@@ -253,7 +252,7 @@ static int tiadc_buffer_postenable(struct iio_dev *idev)
{
struct tiadc_device *adc_dev = iio_priv(idev);
struct iio_buffer *buffer = idev->buffer;
- unsigned int enb, status, fifo1count;
+ unsigned int enb, fifo1count;
int stepnum, i;
u8 bit;
@@ -261,11 +260,10 @@ static int tiadc_buffer_postenable(struct iio_dev *idev)
printk("Data cannot be read continuously in one shot mode\n");
return -EINVAL;
} else {
- status = tiadc_readl(adc_dev, REG_IRQENABLE);
tiadc_writel(adc_dev, REG_IRQENABLE,
- (status | IRQENB_FIFO1THRES)|
+ (IRQENB_FIFO1THRES |
IRQENB_FIFO1OVRRUN |
- IRQENB_FIFO1UNDRFLW);
+ IRQENB_FIFO1UNDRFLW));
fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT);
for (i = 0; i < fifo1count; i++)
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH 09/21] IIO: ti_adc: Handle set to clear IRQSTATUS register properly
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
` (7 preceding siblings ...)
2013-07-17 17:26 ` [PATCH 08/21] IIO: ti_adc: Handle set to clear IRQENABLE register properly Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 10/21] IIO: ti_adc: Handle overrun before threshold event Zubair Lutfullah
` (11 subsequent siblings)
20 siblings, 0 replies; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
The driver is currently mishandling the IRQSTATUS register by peforming
a read/update/write cycle. The actual functionality of the register is as follows:
Write 0 = No action.
Read 0 = No (enabled) event pending.
Read 1 = Event pending.
Write 1 = Clear (raw) event.
By reading the status and writing it back, the driver is clearing
all pending events, not just the one indicated in the bitmask.
Signed-off-by: Russ Dill <Russ.Dill@ti.com>
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/iio/adc/ti_am335x_adc.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index a86830b..5c95eba 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -182,7 +182,7 @@ static irqreturn_t tiadc_irq(int irq, void *private)
wake_up_interruptible(&adc_dev->wq_data_avail);
}
tiadc_writel(adc_dev, REG_IRQSTATUS,
- (status | IRQENB_FIFO1THRES));
+ IRQENB_FIFO1THRES);
return IRQ_HANDLED;
} else if ((status & IRQENB_FIFO1OVRRUN) ||
(status & IRQENB_FIFO1UNDRFLW)) {
@@ -190,13 +190,10 @@ static irqreturn_t tiadc_irq(int irq, void *private)
config &= ~( CNTRLREG_TSCSSENB);
tiadc_writel(adc_dev, REG_CTRL, config);
- if (status & IRQENB_FIFO1UNDRFLW)
- tiadc_writel(adc_dev, REG_IRQSTATUS,
- (status | IRQENB_FIFO1UNDRFLW));
- else
- tiadc_writel(adc_dev, REG_IRQSTATUS,
- (status | IRQENB_FIFO1OVRRUN));
-
+ tiadc_writel(adc_dev, REG_IRQSTATUS,
+ IRQENB_FIFO1OVRRUN |
+ IRQENB_FIFO1UNDRFLW);
+
tiadc_writel(adc_dev, REG_CTRL,
(config | CNTRLREG_TSCSSENB));
return IRQ_HANDLED;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH 10/21] IIO: ti_adc: Handle overrun before threshold event
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
` (8 preceding siblings ...)
2013-07-17 17:26 ` [PATCH 09/21] IIO: ti_adc: Handle set to clear IRQSTATUS " Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 11/21] iio: ti_adc: Avoid double " Zubair Lutfullah
` (10 subsequent siblings)
20 siblings, 0 replies; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
If an overrun occurs, the threshold event is meaningless, handle
the overrun event first.
Signed-off-by: Russ Dill <Russ.Dill@ti.com>
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/iio/adc/ti_am335x_adc.c | 29 ++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index 5c95eba..e510da7 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -171,7 +171,19 @@ static irqreturn_t tiadc_irq(int irq, void *private)
unsigned int status, config;
status = tiadc_readl(adc_dev, REG_IRQSTATUS);
- if (status & IRQENB_FIFO1THRES) {
+ if (status & IRQENB_FIFO1OVRRUN) {
+ config = tiadc_readl(adc_dev, REG_CTRL);
+ config &= ~(CNTRLREG_TSCSSENB);
+ tiadc_writel(adc_dev, REG_CTRL, config);
+
+ tiadc_writel(adc_dev, REG_IRQSTATUS,
+ IRQENB_FIFO1OVRRUN |
+ IRQENB_FIFO1UNDRFLW);
+
+ tiadc_writel(adc_dev, REG_CTRL,
+ (config | CNTRLREG_TSCSSENB));
+ return IRQ_HANDLED;
+ } else if (status & IRQENB_FIFO1THRES) {
tiadc_writel(adc_dev, REG_IRQCLR,
IRQENB_FIFO1THRES);
@@ -183,20 +195,7 @@ static irqreturn_t tiadc_irq(int irq, void *private)
}
tiadc_writel(adc_dev, REG_IRQSTATUS,
IRQENB_FIFO1THRES);
- return IRQ_HANDLED;
- } else if ((status & IRQENB_FIFO1OVRRUN) ||
- (status & IRQENB_FIFO1UNDRFLW)) {
- config = tiadc_readl(adc_dev, REG_CTRL);
- config &= ~( CNTRLREG_TSCSSENB);
- tiadc_writel(adc_dev, REG_CTRL, config);
-
- tiadc_writel(adc_dev, REG_IRQSTATUS,
- IRQENB_FIFO1OVRRUN |
- IRQENB_FIFO1UNDRFLW);
-
- tiadc_writel(adc_dev, REG_CTRL,
- (config | CNTRLREG_TSCSSENB));
- return IRQ_HANDLED;
+ return IRQ_HANDLED;
} else {
return IRQ_NONE;
}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH 11/21] iio: ti_adc: Avoid double threshold event
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
` (9 preceding siblings ...)
2013-07-17 17:26 ` [PATCH 10/21] IIO: ti_adc: Handle overrun before threshold event Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 12/21] IIO: ti_adc: Also clear threshold event when clearing overrun event Zubair Lutfullah
` (9 subsequent siblings)
20 siblings, 0 replies; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
The threshold event handler is being called before the FIFO has
actually reached the threshold.
The current code receives a FIFO threshold event, masks the interrupt,
clears the event, and schedules a workqueue. The workqueue is run, it
empties the FIFO, and unmasks the interrupt.
In the above sequence, after the event is cleared, it immediately
retriggers since the FIFO remains beyond the threshold. When the IRQ is
unmasked, this triggered event generates another IRQ. However, as the
FIFO has just been emptied, it is likely to not contain enough samples.
The waits to clear the event until the FIFO has actually been emptied,
in the workqueue. The unmasking and masking of the interrupt remains
unchanged.
Signed-off-by: Russ Dill <Russ.Dill@ti.com>
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/iio/adc/ti_am335x_adc.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index e510da7..fcd414d 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -193,8 +193,7 @@ static irqreturn_t tiadc_irq(int irq, void *private)
} else {
wake_up_interruptible(&adc_dev->wq_data_avail);
}
- tiadc_writel(adc_dev, REG_IRQSTATUS,
- IRQENB_FIFO1THRES);
+
return IRQ_HANDLED;
} else {
return IRQ_NONE;
@@ -230,6 +229,8 @@ static void tiadc_poll_handler(struct work_struct *work_s)
}
buffer->access->store_to(buffer, (u8 *) iBuf);
+ tiadc_writel(adc_dev, REG_IRQSTATUS,
+ IRQENB_FIFO1THRES);
tiadc_writel(adc_dev, REG_IRQENABLE,
IRQENB_FIFO1THRES);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH 12/21] IIO: ti_adc: Also clear threshold event when clearing overrun event
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
` (10 preceding siblings ...)
2013-07-17 17:26 ` [PATCH 11/21] iio: ti_adc: Avoid double " Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 13/21] IO: ti_adc: Reset and clear overrun status before capture Zubair Lutfullah
` (8 subsequent siblings)
20 siblings, 0 replies; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
When an overrun occurs, the FIFO is cleared. If a FIFO threshold event
was pending, the data is now gone. Clear the threshold event when
handling an overrun (or underflow).
Signed-off-by: Russ Dill <Russ.Dill@ti.com>
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/iio/adc/ti_am335x_adc.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index fcd414d..1e48799 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -178,7 +178,8 @@ static irqreturn_t tiadc_irq(int irq, void *private)
tiadc_writel(adc_dev, REG_IRQSTATUS,
IRQENB_FIFO1OVRRUN |
- IRQENB_FIFO1UNDRFLW);
+ IRQENB_FIFO1UNDRFLW |
+ IRQENB_FIFO1THRES);
tiadc_writel(adc_dev, REG_CTRL,
(config | CNTRLREG_TSCSSENB));
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH 13/21] IO: ti_adc: Reset and clear overrun status before capture.
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
` (11 preceding siblings ...)
2013-07-17 17:26 ` [PATCH 12/21] IIO: ti_adc: Also clear threshold event when clearing overrun event Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 14/21] IIO: ti_adc: Properly handle out of memory situation Zubair Lutfullah
` (7 subsequent siblings)
20 siblings, 0 replies; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
While not pulling out samples, the FIFO will fill up causing an
overrun event. Before starting up another continuous sample, clear that
event.
Signed-off-by: Russ Dill <Russ.Dill@ti.com>
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/iio/adc/ti_am335x_adc.c | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index 1e48799..eb47385 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -250,22 +250,28 @@ static int tiadc_buffer_postenable(struct iio_dev *idev)
{
struct tiadc_device *adc_dev = iio_priv(idev);
struct iio_buffer *buffer = idev->buffer;
- unsigned int enb, fifo1count;
- int stepnum, i;
+ unsigned int enb, config;
+ int stepnum;
u8 bit;
if (!adc_dev->is_continuous_mode) {
printk("Data cannot be read continuously in one shot mode\n");
return -EINVAL;
} else {
- tiadc_writel(adc_dev, REG_IRQENABLE,
- (IRQENB_FIFO1THRES |
- IRQENB_FIFO1OVRRUN |
- IRQENB_FIFO1UNDRFLW));
- fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT);
- for (i = 0; i < fifo1count; i++)
- tiadc_readl(adc_dev, REG_FIFO1);
+ config = tiadc_readl(adc_dev, REG_CTRL);
+ tiadc_writel(adc_dev, REG_CTRL,
+ config & ~CNTRLREG_TSCSSENB);
+ tiadc_writel(adc_dev, REG_CTRL,
+ config | CNTRLREG_TSCSSENB);
+
+ tiadc_writel(adc_dev, REG_IRQSTATUS,
+ IRQENB_FIFO1THRES |
+ IRQENB_FIFO1OVRRUN |
+ IRQENB_FIFO1UNDRFLW);
+ tiadc_writel(adc_dev, REG_IRQENABLE,
+ IRQENB_FIFO1THRES |
+ IRQENB_FIFO1OVRRUN);
tiadc_writel(adc_dev, REG_SE, 0x00);
for_each_set_bit(bit, buffer->scan_mask,
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH 14/21] IIO: ti_adc: Properly handle out of memory situation.
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
` (12 preceding siblings ...)
2013-07-17 17:26 ` [PATCH 13/21] IO: ti_adc: Reset and clear overrun status before capture Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 15/21] IIO: ti_adc: Print error and handle short FIFO events Zubair Lutfullah
` (6 subsequent siblings)
20 siblings, 0 replies; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
If we fail to allocate a buffer, unmask the interrupt to allow a retry.
The interrupt handler will be re-run, and our workqueue rescheduled.
If we are able to allocate memory next time around, everything will
continue as normal, otherwise, we will eventually get an underrun.
Before this patch, the driver would stop capturing without any
indication of error to the IIO subsystem or the user.
Signed-off-by: Russ Dill <Russ.Dill@ti.com>
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/iio/adc/ti_am335x_adc.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index eb47385..69abde0 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -214,7 +214,7 @@ static void tiadc_poll_handler(struct work_struct *work_s)
fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT);
iBuf = kmalloc((fifo1count + 1) * sizeof(u32), GFP_KERNEL);
if (iBuf == NULL)
- return;
+ goto out;
/*
* Wait for ADC sequencer to settle down.
* There could be a scenario where in we
@@ -230,12 +230,14 @@ static void tiadc_poll_handler(struct work_struct *work_s)
}
buffer->access->store_to(buffer, (u8 *) iBuf);
+ kfree(iBuf);
+
+out:
tiadc_writel(adc_dev, REG_IRQSTATUS,
IRQENB_FIFO1THRES);
tiadc_writel(adc_dev, REG_IRQENABLE,
IRQENB_FIFO1THRES);
-
- kfree(iBuf);
+
}
static int tiadc_buffer_preenable(struct iio_dev *idev)
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH 15/21] IIO: ti_adc: Print error and handle short FIFO events
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
` (13 preceding siblings ...)
2013-07-17 17:26 ` [PATCH 14/21] IIO: ti_adc: Properly handle out of memory situation Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 16/21] IIO: ti_adc: Fix allocation count of FIFO buffer Zubair Lutfullah
` (5 subsequent siblings)
20 siblings, 0 replies; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
In the case that the FIFO threshold handler gets called when the
FIFO has not actually reached the threshold, the driver will pass
uninitialized memory to the IIO subsystem.
In the past, this would occur due to bugs in the driver, those bugs
have been fixed. However, it is still a good idea to close this just
in case additional bugs in hardware or software exist.
Signed-off-by: Russ Dill <Russ.Dill@ti.com>
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/iio/adc/ti_am335x_adc.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index 69abde0..c257169 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -212,6 +212,13 @@ static void tiadc_poll_handler(struct work_struct *work_s)
u32 *iBuf;
fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT);
+ if (fifo1count * sizeof(u32) <
+ buffer->access->get_bytes_per_datum(buffer)) {
+ dev_err(adc_dev->mfd_tscadc->dev, "%s: Short FIFO event\n",
+ __func__);
+ goto out;
+ }
+
iBuf = kmalloc((fifo1count + 1) * sizeof(u32), GFP_KERNEL);
if (iBuf == NULL)
goto out;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH 16/21] IIO: ti_adc: Fix allocation count of FIFO buffer.
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
` (14 preceding siblings ...)
2013-07-17 17:26 ` [PATCH 15/21] IIO: ti_adc: Print error and handle short FIFO events Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 17/21] Revert "IIO: ti_adc: Correct wrong samples received on 1st read in continuous mode" Zubair Lutfullah
` (4 subsequent siblings)
20 siblings, 0 replies; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
Allocating an extra byte is not necessary here. The driver will check
that the allocation is large enough to satisfy the IIO subsystem.
Signed-off-by: Russ Dill <Russ.Dill@ti.com>
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/iio/adc/ti_am335x_adc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index c257169..21294f2 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -219,7 +219,7 @@ static void tiadc_poll_handler(struct work_struct *work_s)
goto out;
}
- iBuf = kmalloc((fifo1count + 1) * sizeof(u32), GFP_KERNEL);
+ iBuf = kmalloc((fifo1count) * sizeof(u32), GFP_KERNEL);
if (iBuf == NULL)
goto out;
/*
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH 17/21] Revert "IIO: ti_adc: Correct wrong samples received on 1st read in continuous mode"
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
` (15 preceding siblings ...)
2013-07-17 17:26 ` [PATCH 16/21] IIO: ti_adc: Fix allocation count of FIFO buffer Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 18/21] IIO: ti_adc: Fix capture operation during resume Zubair Lutfullah
` (3 subsequent siblings)
20 siblings, 0 replies; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
With a proper fix to this code, this is no longer neccessary.
Signed-off-by: Russ Dill <Russ.Dill@ti.com>
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/iio/adc/ti_am335x_adc.c | 8 --------
1 file changed, 8 deletions(-)
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index 21294f2..1f42e0a 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -36,7 +36,6 @@
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/kfifo_buf.h>
#include <linux/iio/sysfs.h>
-#include <linux/delay.h>
struct tiadc_device {
struct ti_tscadc_dev *mfd_tscadc;
@@ -222,13 +221,6 @@ static void tiadc_poll_handler(struct work_struct *work_s)
iBuf = kmalloc((fifo1count) * sizeof(u32), GFP_KERNEL);
if (iBuf == NULL)
goto out;
- /*
- * Wait for ADC sequencer to settle down.
- * There could be a scenario where in we
- * try to read data from ADC before
- * it is available.
- */
- udelay(500);
for (i = 0; i < fifo1count; i++) {
readx1 = tiadc_readl(adc_dev, REG_FIFO1);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH 18/21] IIO: ti_adc: Fix capture operation during resume
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
` (16 preceding siblings ...)
2013-07-17 17:26 ` [PATCH 17/21] Revert "IIO: ti_adc: Correct wrong samples received on 1st read in continuous mode" Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 19/21] iio: ti_amss5x adc Fix check_patch.pl issues Zubair Lutfullah
` (2 subsequent siblings)
20 siblings, 0 replies; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
The ADC needs to go through a proper initialization sequence after
resuming from suspend.
Signed-off-by: Russ Dill <Russ.Dill@ti.com>
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/iio/adc/ti_am335x_adc.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index 1f42e0a..40eec84 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -588,12 +588,16 @@ static int tiadc_resume(struct device *dev)
struct tiadc_device *adc_dev = iio_priv(indio_dev);
unsigned int restore;
+ restore = tiadc_readl(adc_dev, REG_CTRL);
+ restore &= ~(CNTRLREG_TSCSSENB);
+ tiadc_writel(adc_dev, REG_CTRL, restore);
+
tiadc_writel(adc_dev, REG_FIFO1THR, FIFO1_THRESHOLD);
tiadc_step_config(adc_dev, adc_dev->is_continuous_mode);
/* Make sure ADC is powered up */
- restore = tiadc_readl(adc_dev, REG_CTRL);
restore &= ~(CNTRLREG_POWERDOWN);
+ restore |= CNTRLREG_TSCSSENB;
tiadc_writel(adc_dev, REG_CTRL, restore);
return 0;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH 19/21] iio: ti_amss5x adc Fix check_patch.pl issues
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
` (17 preceding siblings ...)
2013-07-17 17:26 ` [PATCH 18/21] IIO: ti_adc: Fix capture operation during resume Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 20/21] input: ti_am335x_tsc.c fix checkpatch.pl issues Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 21/21] mfd: ti_am335x_tscadc.c " Zubair Lutfullah
20 siblings, 0 replies; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
all clear. replaced printk with pr_info..
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/iio/adc/ti_am335x_adc.c | 375 ++++++++++++++++++++-------------------
1 file changed, 188 insertions(+), 187 deletions(-)
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index 40eec84..b1438a7 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -44,9 +44,9 @@ struct tiadc_device {
u8 channel_step[8];
struct work_struct poll_work;
wait_queue_head_t wq_data_avail;
- int irq;
- bool is_continuous_mode;
- u16 *buffer;
+ int irq;
+ bool is_continuous_mode;
+ u16 *buffer;
};
static unsigned int tiadc_readl(struct tiadc_device *adc, unsigned int reg)
@@ -69,7 +69,7 @@ static u32 get_adc_step_mask(struct tiadc_device *adc_dev)
return step_en;
}
-static void tiadc_step_config(struct tiadc_device *adc_dev,bool mode)
+static void tiadc_step_config(struct tiadc_device *adc_dev, bool mode)
{
unsigned int stepconfig;
int i, steps;
@@ -86,10 +86,10 @@ static void tiadc_step_config(struct tiadc_device *adc_dev,bool mode)
steps = TOTAL_STEPS - adc_dev->channels;
if (mode == 0)
- stepconfig = STEPCONFIG_AVG_16 | STEPCONFIG_FIFO1;
+ stepconfig = STEPCONFIG_AVG_16 | STEPCONFIG_FIFO1;
else
- stepconfig = STEPCONFIG_AVG_16 | STEPCONFIG_FIFO1
- | STEPCONFIG_MODE_SWCNT;
+ stepconfig = STEPCONFIG_AVG_16 | STEPCONFIG_FIFO1
+ | STEPCONFIG_MODE_SWCNT;
for (i = 0; i < adc_dev->channels; i++) {
int chan;
@@ -106,225 +106,225 @@ static void tiadc_step_config(struct tiadc_device *adc_dev,bool mode)
}
static ssize_t tiadc_show_mode(struct device *dev,
- struct device_attribute *attr, char *buf)
+ struct device_attribute *attr, char *buf)
{
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct tiadc_device *adc_dev = iio_priv(indio_dev);
- unsigned int tmp;
-
- tmp = tiadc_readl(adc_dev, REG_STEPCONFIG(TOTAL_STEPS));
- tmp &= STEPCONFIG_MODE(1);
-
- if (tmp == 0x00)
- return sprintf(buf, "oneshot\n");
- else if (tmp == 0x01)
- return sprintf(buf, "continuous\n");
- else
- return sprintf(buf, "Operation mode unknown\n");
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct tiadc_device *adc_dev = iio_priv(indio_dev);
+ unsigned int tmp;
+
+ tmp = tiadc_readl(adc_dev, REG_STEPCONFIG(TOTAL_STEPS));
+ tmp &= STEPCONFIG_MODE(1);
+
+ if (tmp == 0x00)
+ return sprintf(buf, "oneshot\n");
+ else if (tmp == 0x01)
+ return sprintf(buf, "continuous\n");
+ else
+ return sprintf(buf, "Operation mode unknown\n");
}
static ssize_t tiadc_set_mode(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
+ struct device_attribute *attr, const char *buf, size_t count)
{
- struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct tiadc_device *adc_dev = iio_priv(indio_dev);
- unsigned config;
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
+ struct tiadc_device *adc_dev = iio_priv(indio_dev);
+ unsigned config;
- config = tiadc_readl(adc_dev, REG_CTRL);
- config &= ~(CNTRLREG_TSCSSENB);
- tiadc_writel(adc_dev, REG_CTRL, config);
+ config = tiadc_readl(adc_dev, REG_CTRL);
+ config &= ~(CNTRLREG_TSCSSENB);
+ tiadc_writel(adc_dev, REG_CTRL, config);
if (!strncmp(buf, "oneshot", 7))
- adc_dev->is_continuous_mode = false;
- else if (!strncmp(buf, "continuous", 10))
- adc_dev->is_continuous_mode = true;
- else {
- dev_err(dev, "Operational mode unknown\n");
- return -EINVAL;
- }
-
+ adc_dev->is_continuous_mode = false;
+ else if (!strncmp(buf, "continuous", 10))
+ adc_dev->is_continuous_mode = true;
+ else {
+ dev_err(dev, "Operational mode unknown\n");
+ return -EINVAL;
+ }
+
tiadc_step_config(adc_dev, adc_dev->is_continuous_mode);
- config = tiadc_readl(adc_dev, REG_CTRL);
- tiadc_writel(adc_dev, REG_CTRL,
- (config | CNTRLREG_TSCSSENB));
- return count;
+ config = tiadc_readl(adc_dev, REG_CTRL);
+ tiadc_writel(adc_dev, REG_CTRL,
+ (config | CNTRLREG_TSCSSENB));
+ return count;
}
static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, tiadc_show_mode,
- tiadc_set_mode, 0);
+ tiadc_set_mode, 0);
static struct attribute *tiadc_attributes[] = {
- &iio_dev_attr_mode.dev_attr.attr,
- NULL,
+ &iio_dev_attr_mode.dev_attr.attr,
+ NULL,
};
static const struct attribute_group tiadc_attribute_group = {
- .attrs = tiadc_attributes,
+ .attrs = tiadc_attributes,
};
static irqreturn_t tiadc_irq(int irq, void *private)
{
- struct iio_dev *idev = private;
- struct tiadc_device *adc_dev = iio_priv(idev);
+ struct iio_dev *idev = private;
+ struct tiadc_device *adc_dev = iio_priv(idev);
unsigned int status, config;
- status = tiadc_readl(adc_dev, REG_IRQSTATUS);
- if (status & IRQENB_FIFO1OVRRUN) {
- config = tiadc_readl(adc_dev, REG_CTRL);
- config &= ~(CNTRLREG_TSCSSENB);
- tiadc_writel(adc_dev, REG_CTRL, config);
-
- tiadc_writel(adc_dev, REG_IRQSTATUS,
- IRQENB_FIFO1OVRRUN |
- IRQENB_FIFO1UNDRFLW |
- IRQENB_FIFO1THRES);
-
- tiadc_writel(adc_dev, REG_CTRL,
- (config | CNTRLREG_TSCSSENB));
+ status = tiadc_readl(adc_dev, REG_IRQSTATUS);
+ if (status & IRQENB_FIFO1OVRRUN) {
+ config = tiadc_readl(adc_dev, REG_CTRL);
+ config &= ~(CNTRLREG_TSCSSENB);
+ tiadc_writel(adc_dev, REG_CTRL, config);
+
+ tiadc_writel(adc_dev, REG_IRQSTATUS,
+ IRQENB_FIFO1OVRRUN |
+ IRQENB_FIFO1UNDRFLW |
+ IRQENB_FIFO1THRES);
+
+ tiadc_writel(adc_dev, REG_CTRL,
+ (config | CNTRLREG_TSCSSENB));
+ return IRQ_HANDLED;
+ } else if (status & IRQENB_FIFO1THRES) {
+ tiadc_writel(adc_dev, REG_IRQCLR,
+ IRQENB_FIFO1THRES);
+
+ if (iio_buffer_enabled(idev)) {
+ if (!work_pending(&adc_dev->poll_work))
+ schedule_work(&adc_dev->poll_work);
+ } else {
+ wake_up_interruptible(&adc_dev->wq_data_avail);
+ }
+
return IRQ_HANDLED;
- } else if (status & IRQENB_FIFO1THRES) {
- tiadc_writel(adc_dev, REG_IRQCLR,
- IRQENB_FIFO1THRES);
-
- if (iio_buffer_enabled(idev)) {
- if (!work_pending(&adc_dev->poll_work))
- schedule_work(&adc_dev->poll_work);
- } else {
- wake_up_interruptible(&adc_dev->wq_data_avail);
- }
-
- return IRQ_HANDLED;
} else {
- return IRQ_NONE;
- }
+ return IRQ_NONE;
+ }
}
static void tiadc_poll_handler(struct work_struct *work_s)
{
- struct tiadc_device *adc_dev =
- container_of(work_s, struct tiadc_device, poll_work);
- struct iio_dev *idev = iio_priv_to_dev(adc_dev);
- struct iio_buffer *buffer = idev->buffer;
- unsigned int fifo1count, readx1;
- int i;
- u32 *iBuf;
-
- fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT);
- if (fifo1count * sizeof(u32) <
- buffer->access->get_bytes_per_datum(buffer)) {
- dev_err(adc_dev->mfd_tscadc->dev, "%s: Short FIFO event\n",
- __func__);
- goto out;
- }
-
- iBuf = kmalloc((fifo1count) * sizeof(u32), GFP_KERNEL);
- if (iBuf == NULL)
- goto out;
-
- for (i = 0; i < fifo1count; i++) {
- readx1 = tiadc_readl(adc_dev, REG_FIFO1);
- readx1 &= FIFOREAD_DATA_MASK;
- iBuf[i] = readx1;
- }
-
- buffer->access->store_to(buffer, (u8 *) iBuf);
- kfree(iBuf);
-
-out:
+ struct tiadc_device *adc_dev =
+ container_of(work_s, struct tiadc_device, poll_work);
+ struct iio_dev *idev = iio_priv_to_dev(adc_dev);
+ struct iio_buffer *buffer = idev->buffer;
+ unsigned int fifo1count, readx1;
+ int i;
+ u32 *inputbuffer;
+
+ fifo1count = tiadc_readl(adc_dev, REG_FIFO1CNT);
+ if (fifo1count * sizeof(u32) <
+ buffer->access->get_bytes_per_datum(buffer)) {
+ dev_err(adc_dev->mfd_tscadc->dev, "%s: Short FIFO event\n",
+ __func__);
+ goto out;
+ }
+
+ inputbuffer = kmalloc((fifo1count) * sizeof(u32), GFP_KERNEL);
+ if (inputbuffer == NULL)
+ goto out;
+
+ for (i = 0; i < fifo1count; i++) {
+ readx1 = tiadc_readl(adc_dev, REG_FIFO1);
+ readx1 &= FIFOREAD_DATA_MASK;
+ inputbuffer[i] = readx1;
+ }
+
+ buffer->access->store_to(buffer, (u8 *) inputbuffer);
+ kfree(inputbuffer);
+
+out:
tiadc_writel(adc_dev, REG_IRQSTATUS,
IRQENB_FIFO1THRES);
- tiadc_writel(adc_dev, REG_IRQENABLE,
+ tiadc_writel(adc_dev, REG_IRQENABLE,
IRQENB_FIFO1THRES);
-
+
}
static int tiadc_buffer_preenable(struct iio_dev *idev)
{
- struct iio_buffer *buffer = idev->buffer;
+ struct iio_buffer *buffer = idev->buffer;
- buffer->access->set_bytes_per_datum(buffer, 16);
- return 0;
+ buffer->access->set_bytes_per_datum(buffer, 16);
+ return 0;
}
static int tiadc_buffer_postenable(struct iio_dev *idev)
{
- struct tiadc_device *adc_dev = iio_priv(idev);
- struct iio_buffer *buffer = idev->buffer;
- unsigned int enb, config;
- int stepnum;
- u8 bit;
-
- if (!adc_dev->is_continuous_mode) {
- printk("Data cannot be read continuously in one shot mode\n");
- return -EINVAL;
- } else {
-
- config = tiadc_readl(adc_dev, REG_CTRL);
- tiadc_writel(adc_dev, REG_CTRL,
- config & ~CNTRLREG_TSCSSENB);
- tiadc_writel(adc_dev, REG_CTRL,
- config | CNTRLREG_TSCSSENB);
-
- tiadc_writel(adc_dev, REG_IRQSTATUS,
- IRQENB_FIFO1THRES |
- IRQENB_FIFO1OVRRUN |
- IRQENB_FIFO1UNDRFLW);
- tiadc_writel(adc_dev, REG_IRQENABLE,
- IRQENB_FIFO1THRES |
- IRQENB_FIFO1OVRRUN);
-
- tiadc_writel(adc_dev, REG_SE, 0x00);
- for_each_set_bit(bit, buffer->scan_mask,
- adc_dev->channels) {
- struct iio_chan_spec const *chan = idev->channels + bit;
- /*
- * There are a total of 16 steps available
- * that are shared between ADC and touchscreen.
- * We start configuring from step 16 to 0 incase of
- * ADC. Hence the relation between input channel
- * and step for ADC would be as below.
- */
- stepnum = chan->channel + 9;
- enb = tiadc_readl(adc_dev, REG_SE);
- enb |= (1 << stepnum);
- tiadc_writel(adc_dev, REG_SE, enb);
- }
- return 0;
- }
+ struct tiadc_device *adc_dev = iio_priv(idev);
+ struct iio_buffer *buffer = idev->buffer;
+ unsigned int enb, config;
+ int stepnum;
+ u8 bit;
+
+ if (!adc_dev->is_continuous_mode) {
+ pr_info("Data cannot be read continuously in one shot mode\n");
+ return -EINVAL;
+ } else {
+
+ config = tiadc_readl(adc_dev, REG_CTRL);
+ tiadc_writel(adc_dev, REG_CTRL,
+ config & ~CNTRLREG_TSCSSENB);
+ tiadc_writel(adc_dev, REG_CTRL,
+ config | CNTRLREG_TSCSSENB);
+
+ tiadc_writel(adc_dev, REG_IRQSTATUS,
+ IRQENB_FIFO1THRES |
+ IRQENB_FIFO1OVRRUN |
+ IRQENB_FIFO1UNDRFLW);
+ tiadc_writel(adc_dev, REG_IRQENABLE,
+ IRQENB_FIFO1THRES |
+ IRQENB_FIFO1OVRRUN);
+
+ tiadc_writel(adc_dev, REG_SE, 0x00);
+ for_each_set_bit(bit, buffer->scan_mask,
+ adc_dev->channels) {
+ struct iio_chan_spec const *chan = idev->channels + bit;
+ /*
+ * There are a total of 16 steps available
+ * that are shared between ADC and touchscreen.
+ * We start configuring from step 16 to 0 incase of
+ * ADC. Hence the relation between input channel
+ * and step for ADC would be as below.
+ */
+ stepnum = chan->channel + 9;
+ enb = tiadc_readl(adc_dev, REG_SE);
+ enb |= (1 << stepnum);
+ tiadc_writel(adc_dev, REG_SE, enb);
+ }
+ return 0;
+ }
}
static int tiadc_buffer_postdisable(struct iio_dev *idev)
{
- struct tiadc_device *adc_dev = iio_priv(idev);
-
+ struct tiadc_device *adc_dev = iio_priv(idev);
+
tiadc_writel(adc_dev, REG_IRQCLR, (IRQENB_FIFO1THRES |
- IRQENB_FIFO1OVRRUN |
- IRQENB_FIFO1UNDRFLW));
- tiadc_writel(adc_dev, REG_SE, STPENB_STEPENB_TC);
- return 0;
+ IRQENB_FIFO1OVRRUN |
+ IRQENB_FIFO1UNDRFLW));
+ tiadc_writel(adc_dev, REG_SE, STPENB_STEPENB_TC);
+ return 0;
}
static const struct iio_buffer_setup_ops tiadc_buffer_setup_ops = {
- .preenable = &tiadc_buffer_preenable,
- .postenable = &tiadc_buffer_postenable,
- .postdisable = &tiadc_buffer_postdisable,
+ .preenable = &tiadc_buffer_preenable,
+ .postenable = &tiadc_buffer_postenable,
+ .postdisable = &tiadc_buffer_postdisable,
};
static int tiadc_config_sw_ring(struct iio_dev *idev)
{
- struct tiadc_device *adc_dev = iio_priv(idev);
+ struct tiadc_device *adc_dev = iio_priv(idev);
- idev->buffer = iio_kfifo_allocate(idev);
- if (!idev->buffer)
- return(-ENOMEM);
+ idev->buffer = iio_kfifo_allocate(idev);
+ if (!idev->buffer)
+ return -ENOMEM;
- idev->setup_ops = &tiadc_buffer_setup_ops;
+ idev->setup_ops = &tiadc_buffer_setup_ops;
- INIT_WORK(&adc_dev->poll_work, &tiadc_poll_handler);
+ INIT_WORK(&adc_dev->poll_work, &tiadc_poll_handler);
- idev->modes |= INDIO_BUFFER_HARDWARE;
- return 0;
+ idev->modes |= INDIO_BUFFER_HARDWARE;
+ return 0;
}
static const char * const chan_name_ain[] = {
@@ -389,14 +389,14 @@ static int tiadc_read_raw(struct iio_dev *indio_dev,
unsigned long timeout = jiffies + usecs_to_jiffies
(IDLE_TIMEOUT * adc_dev->channels);
- if (adc_dev->is_continuous_mode) {
- printk("One shot mode not enabled\n");
- return -EINVAL;
- } else {
+ if (adc_dev->is_continuous_mode) {
+ pr_info("One shot mode not enabled\n");
+ return -EINVAL;
+ } else {
step_en = get_adc_step_mask(adc_dev);
am335x_tsc_se_set(adc_dev->mfd_tscadc, step_en);
-
+
/* Wait for ADC sequencer to complete sampling */
while (tiadc_readl(adc_dev, REG_ADCFSM) & SEQ_STATUS) {
if (time_after(jiffies, timeout))
@@ -437,16 +437,17 @@ static int tiadc_read_raw(struct iio_dev *indio_dev,
}
}
- switch (mask){
- case IIO_CHAN_INFO_RAW : /*Do nothing. Above code works fine.*/
+ switch (mask) {
+ case IIO_CHAN_INFO_RAW: /*Do nothing. Above code works fine.*/
break;
- case IIO_CHAN_INFO_SCALE : {
- /*12 Bit adc. Scale value for 1800mV AVDD. Ideally
- AVDD should come from DT.*/
- *val = div_u64( (u64)(*val) * 1800 , 4096);
+ case IIO_CHAN_INFO_SCALE: {
+ /*12 Bit adc. Scale value for 1800mV AVDD. Ideally
+ AVDD should come from DT.*/
+ *val = div_u64((u64)(*val) * 1800 , 4096);
break;
}
- default: break;
+ default:
+ break;
}
if (found == false)
@@ -518,7 +519,7 @@ static int tiadc_probe(struct platform_device *pdev)
err = tiadc_config_sw_ring(indio_dev);
if (err < 0)
goto err_unregister;
-
+
err = iio_buffer_register(indio_dev,
indio_dev->channels, indio_dev->num_channels);
if (err < 0)
@@ -588,16 +589,16 @@ static int tiadc_resume(struct device *dev)
struct tiadc_device *adc_dev = iio_priv(indio_dev);
unsigned int restore;
- restore = tiadc_readl(adc_dev, REG_CTRL);
- restore &= ~(CNTRLREG_TSCSSENB);
- tiadc_writel(adc_dev, REG_CTRL, restore);
+ restore = tiadc_readl(adc_dev, REG_CTRL);
+ restore &= ~(CNTRLREG_TSCSSENB);
+ tiadc_writel(adc_dev, REG_CTRL, restore);
- tiadc_writel(adc_dev, REG_FIFO1THR, FIFO1_THRESHOLD);
- tiadc_step_config(adc_dev, adc_dev->is_continuous_mode);
+ tiadc_writel(adc_dev, REG_FIFO1THR, FIFO1_THRESHOLD);
+ tiadc_step_config(adc_dev, adc_dev->is_continuous_mode);
/* Make sure ADC is powered up */
restore &= ~(CNTRLREG_POWERDOWN);
- restore |= CNTRLREG_TSCSSENB;
+ restore |= CNTRLREG_TSCSSENB;
tiadc_writel(adc_dev, REG_CTRL, restore);
return 0;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH 20/21] input: ti_am335x_tsc.c fix checkpatch.pl issues
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
` (18 preceding siblings ...)
2013-07-17 17:26 ` [PATCH 19/21] iio: ti_amss5x adc Fix check_patch.pl issues Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
2013-07-17 17:26 ` [PATCH 21/21] mfd: ti_am335x_tscadc.c " Zubair Lutfullah
20 siblings, 0 replies; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
code formatting fixes
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/input/touchscreen/ti_am335x_tsc.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/drivers/input/touchscreen/ti_am335x_tsc.c b/drivers/input/touchscreen/ti_am335x_tsc.c
index 4bf2ee6..ba7abfe 100644
--- a/drivers/input/touchscreen/ti_am335x_tsc.c
+++ b/drivers/input/touchscreen/ti_am335x_tsc.c
@@ -260,19 +260,19 @@ static irqreturn_t titsc_irq(int irq, void *dev)
unsigned int fsm;
status = titsc_readl(ts_dev, REG_IRQSTATUS);
-
- /*
- * ADC and touchscreen share the IRQ line.
- * FIFO1 threshold, FIFO1 Overrun and FIFO1 underflow
- * interrupts are used by ADC,
- * hence return from touchscreen IRQ handler if FIFO1
- * related interrupts occurred.
- */
- if ((status & IRQENB_FIFO1THRES) ||
- (status & IRQENB_FIFO1OVRRUN) ||
- (status & IRQENB_FIFO1UNDRFLW))
- return IRQ_NONE;
- else if (status & IRQENB_FIFO0THRES) {
+
+ /*
+ * ADC and touchscreen share the IRQ line.
+ * FIFO1 threshold, FIFO1 Overrun and FIFO1 underflow
+ * interrupts are used by ADC,
+ * hence return from touchscreen IRQ handler if FIFO1
+ * related interrupts occurred.
+ */
+ if ((status & IRQENB_FIFO1THRES) ||
+ (status & IRQENB_FIFO1OVRRUN) ||
+ (status & IRQENB_FIFO1UNDRFLW))
+ return IRQ_NONE;
+ else if (status & IRQENB_FIFO0THRES) {
titsc_read_coordinates(ts_dev, &x, &y, &z1, &z2);
if (ts_dev->pen_down && z1 != 0 && z2 != 0) {
@@ -326,7 +326,7 @@ static irqreturn_t titsc_irq(int irq, void *dev)
}
if (irqclr) {
- titsc_writel(ts_dev, REG_IRQSTATUS, (status | irqclr) );
+ titsc_writel(ts_dev, REG_IRQSTATUS, (status | irqclr));
am335x_tsc_se_update(ts_dev->mfd_tscadc);
return IRQ_HANDLED;
}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread* [PATCH 21/21] mfd: ti_am335x_tscadc.c fix checkpatch.pl issues
2013-07-17 17:26 [PATCH 00/21] iio: TI-am335x-adc continuous mode Zubair Lutfullah
` (19 preceding siblings ...)
2013-07-17 17:26 ` [PATCH 20/21] input: ti_am335x_tsc.c fix checkpatch.pl issues Zubair Lutfullah
@ 2013-07-17 17:26 ` Zubair Lutfullah
20 siblings, 0 replies; 27+ messages in thread
From: Zubair Lutfullah @ 2013-07-17 17:26 UTC (permalink / raw)
To: jic23; +Cc: linux-iio, gregkh, linux-kernel, koen, zubair.lutfullah
code formatting corrected.
Signed-off-by: Zubair Lutfullah <zubair.lutfullah@gmail.com>
---
drivers/mfd/ti_am335x_tscadc.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/mfd/ti_am335x_tscadc.c b/drivers/mfd/ti_am335x_tscadc.c
index e7314e4..b8d7dfb 100644
--- a/drivers/mfd/ti_am335x_tscadc.c
+++ b/drivers/mfd/ti_am335x_tscadc.c
@@ -278,8 +278,8 @@ static int tscadc_suspend(struct device *dev)
struct ti_tscadc_dev *tscadc_dev = dev_get_drvdata(dev);
tscadc_writel(tscadc_dev, REG_SE, 0x00);
- tscadc_dev->irqstat = tscadc_readl(tscadc_dev, REG_IRQENABLE);
- tscadc_dev->ctrl = tscadc_readl(tscadc_dev, REG_CTRL);
+ tscadc_dev->irqstat = tscadc_readl(tscadc_dev, REG_IRQENABLE);
+ tscadc_dev->ctrl = tscadc_readl(tscadc_dev, REG_CTRL);
pm_runtime_put_sync(dev);
return 0;
@@ -297,7 +297,7 @@ static int tscadc_resume(struct device *dev)
if (tscadc_dev->tsc_cell != -1)
tscadc_idle_config(tscadc_dev);
am335x_tsc_se_update(tscadc_dev);
- tscadc_writel(tscadc_dev, REG_CTRL, tscadc_dev->ctrl);
+ tscadc_writel(tscadc_dev, REG_CTRL, tscadc_dev->ctrl);
return 0;
}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 27+ messages in thread