From 23f1ea4e1324704d36381cf1a2b6d4578c5f3fb4 Mon Sep 17 00:00:00 2001 From: Joel A Fernandes Date: Mon, 28 Nov 2011 20:55:25 -0600 Subject: [PATCH 10/56] tscadc: Trigger through sysfs Signed-off-by: Joel A Fernandes Conflicts: drivers/input/touchscreen/ti_tscadc.c --- drivers/input/touchscreen/ti_tscadc.c | 60 ++++++++++++++++++++++++++++++--- include/linux/input/ti_tscadc.h | 1 + 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/drivers/input/touchscreen/ti_tscadc.c b/drivers/input/touchscreen/ti_tscadc.c index 6083de7..d6aec8c 100644 --- a/drivers/input/touchscreen/ti_tscadc.c +++ b/drivers/input/touchscreen/ti_tscadc.c @@ -26,8 +26,19 @@ #include #include #include +#include #include +size_t do_adc_sample(struct kobject *, struct attribute *, char *); +static DEVICE_ATTR(ain1, S_IRUGO, do_adc_sample, NULL); +static DEVICE_ATTR(ain2, S_IRUGO, do_adc_sample, NULL); +static DEVICE_ATTR(ain3, S_IRUGO, do_adc_sample, NULL); +static DEVICE_ATTR(ain4, S_IRUGO, do_adc_sample, NULL); +static DEVICE_ATTR(ain5, S_IRUGO, do_adc_sample, NULL); +static DEVICE_ATTR(ain6, S_IRUGO, do_adc_sample, NULL); +static DEVICE_ATTR(ain7, S_IRUGO, do_adc_sample, NULL); +static DEVICE_ATTR(ain8, S_IRUGO, do_adc_sample, NULL); + /* Memory mapped registers here have incorrect offsets! * Correct after referring TRM */ #define TSCADC_REG_IRQEOI 0x020 @@ -150,12 +161,12 @@ static void tsc_adc_step_config(struct tscadc *ts_dev, int channel) stepconfig = TSCADC_STEPCONFIG_MODE_SWONESHOT | TSCADC_STEPCONFIG_2SAMPLES_AVG | ((channel-1) << 19); - + delay = TSCADC_STEPCONFIG_SAMPLEDLY | TSCADC_STEPCONFIG_OPENDLY; tscadc_writel(ts_dev, TSCADC_REG_STEPCONFIG(10), stepconfig); tscadc_writel(ts_dev, TSCADC_REG_STEPDELAY(10), delay); - + /* Get the ball rolling, this will trigger the FSM to step through * as soon as TSC_ADC_SS is turned on */ tscadc_writel(ts_dev, TSCADC_REG_SE, TSCADC_STPENB_STEPENB_GENERAL); @@ -205,7 +216,7 @@ static irqreturn_t tsc_adc_interrupt(int irq, void *dev) irqclr |= TSCADC_IRQENB_FIFO1THRES; } - mdelay(500); + // mdelay(500); tscadc_writel(ts_dev, TSCADC_REG_IRQSTATUS, irqclr); @@ -213,7 +224,7 @@ static irqreturn_t tsc_adc_interrupt(int irq, void *dev) tscadc_writel(ts_dev, TSCADC_REG_IRQEOI, 0x0); /* Turn on Step 1 again */ - tscadc_writel(ts_dev, TSCADC_REG_SE, TSCADC_STPENB_STEPENB_GENERAL); + // tscadc_writel(ts_dev, TSCADC_REG_SE, TSCADC_STPENB_STEPENB_GENERAL); return IRQ_HANDLED; } @@ -468,6 +479,34 @@ static irqreturn_t tsc_interrupt(int irq, void *dev) * The functions for inserting/removing driver as a module. */ +size_t do_adc_sample(struct kobject *kobj, struct attribute *attr, char *buf) { + struct platform_device *pdev; + struct device *dev; + struct tscadc *ts_dev; + int channel_num; + + pdev = (struct platform_device *)container_of(kobj, struct device, kobj); + dev = &pdev->dev; + + ts_dev = dev_get_drvdata(dev); + + if(strncmp(attr->name, "ain", 3)) { + printk("Invalid ain num\n"); + return -EINVAL; + } + + channel_num = attr->name[3] - 0x30; + if(channel_num > 8 || channel_num < 1) { + printk("Invalid channel_num=%d\n", channel_num); + return -EINVAL; + } + + tsc_adc_step_config(ts_dev, channel_num); + + memcpy(buf, attr->name, strlen(attr->name)+1); + return strlen(attr->name); +} + static int __devinit tscadc_probe(struct platform_device *pdev) { struct tscadc *ts_dev; @@ -479,6 +518,18 @@ static int __devinit tscadc_probe(struct platform_device *pdev) struct resource *res; struct clk *clk; + printk("dev addr = %p\n", &pdev->dev); + printk("pdev addr = %p\n", pdev); + + device_create_file(&pdev->dev, &dev_attr_ain1); + device_create_file(&pdev->dev, &dev_attr_ain2); + device_create_file(&pdev->dev, &dev_attr_ain3); + device_create_file(&pdev->dev, &dev_attr_ain4); + device_create_file(&pdev->dev, &dev_attr_ain5); + device_create_file(&pdev->dev, &dev_attr_ain6); + device_create_file(&pdev->dev, &dev_attr_ain7); + device_create_file(&pdev->dev, &dev_attr_ain8); + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { dev_err(&pdev->dev, "no memory resource defined.\n"); @@ -606,7 +657,6 @@ static int __devinit tscadc_probe(struct platform_device *pdev) goto err_fail; } else { - tsc_adc_step_config(ts_dev, 8); tscadc_writel(ts_dev, TSCADC_REG_FIFO0THR, 0); irqenable = TSCADC_IRQENB_FIFO0THRES; } diff --git a/include/linux/input/ti_tscadc.h b/include/linux/input/ti_tscadc.h index 850cd4b..fc239c6 100644 --- a/include/linux/input/ti_tscadc.h +++ b/include/linux/input/ti_tscadc.h @@ -13,6 +13,7 @@ * 0. * @x_plate_resistance: X plate resistance. */ +#include #define TI_TSCADC_TSCMODE 0 #define TI_TSCADC_GENMODE 1 -- 1.7.7.6