linux-ti335x-psp: make all patches work with 'git am'
[glsdk/meta-ti-glsdk.git] / recipes-kernel / linux / linux-ti33x-psp-3.1 / adc / 0008-tscadc-Trigger-through-sysfs.patch
1 From 57ce0ce446d8c4626b4ea01005a1173da36f095c Mon Sep 17 00:00:00 2001
2 From: Joel A Fernandes <joelagnel@ti.com>
3 Date: Mon, 28 Nov 2011 20:55:25 -0600
4 Subject: [PATCH 8/9] tscadc: Trigger through sysfs
6 Signed-off-by: Joel A Fernandes <joelagnel@ti.com>
7 ---
8  drivers/input/touchscreen/ti_tscadc.c |   61 ++++++++++++++++++++++++++++++---
9  include/linux/input/ti_tscadc.h       |    1 +
10  2 files changed, 57 insertions(+), 5 deletions(-)
12 diff --git a/drivers/input/touchscreen/ti_tscadc.c b/drivers/input/touchscreen/ti_tscadc.c
13 index 638feb9..0126219 100644
14 --- a/drivers/input/touchscreen/ti_tscadc.c
15 +++ b/drivers/input/touchscreen/ti_tscadc.c
16 @@ -26,6 +26,17 @@
17  #include <linux/io.h>
18  #include <linux/input/ti_tscadc.h>
19  #include <linux/delay.h>
20 +#include <linux/device.h>
21 +
22 +size_t do_adc_sample(struct kobject *, struct attribute *, char *);
23 +static DEVICE_ATTR(ain1, S_IRUGO, do_adc_sample, NULL);
24 +static DEVICE_ATTR(ain2, S_IRUGO, do_adc_sample, NULL);
25 +static DEVICE_ATTR(ain3, S_IRUGO, do_adc_sample, NULL);
26 +static DEVICE_ATTR(ain4, S_IRUGO, do_adc_sample, NULL);
27 +static DEVICE_ATTR(ain5, S_IRUGO, do_adc_sample, NULL);
28 +static DEVICE_ATTR(ain6, S_IRUGO, do_adc_sample, NULL);
29 +static DEVICE_ATTR(ain7, S_IRUGO, do_adc_sample, NULL);
30 +static DEVICE_ATTR(ain8, S_IRUGO, do_adc_sample, NULL);
31  
32  /* Memory mapped registers here have incorrect offsets!
33   * Correct after referring TRM */
34 @@ -144,12 +155,12 @@ static void tsc_adc_step_config(struct tscadc *ts_dev, int channel)
35         stepconfig = TSCADC_STEPCONFIG_MODE_SWONESHOT |
36                 TSCADC_STEPCONFIG_2SAMPLES_AVG |
37                 ((channel-1) << 19);
38 -
39 +       
40         delay = TSCADC_STEPCONFIG_SAMPLEDLY | TSCADC_STEPCONFIG_OPENDLY;
41  
42         tscadc_writel(ts_dev, TSCADC_REG_STEPCONFIG(10), stepconfig);
43         tscadc_writel(ts_dev, TSCADC_REG_STEPDELAY(10), delay);
44 -
45 +       
46         /* Get the ball rolling, this will trigger the FSM to step through
47          * as soon as TSC_ADC_SS is turned on */
48         tscadc_writel(ts_dev, TSCADC_REG_SE, TSCADC_STPENB_STEPENB_GENERAL);
49 @@ -199,7 +210,7 @@ static irqreturn_t tsc_adc_interrupt(int irq, void *dev)
50                 irqclr |= TSCADC_IRQENB_FIFO1THRES;
51         }
52  
53 -       mdelay(500);
54 +       // mdelay(500);
55  
56         tscadc_writel(ts_dev, TSCADC_REG_IRQSTATUS, irqclr);
57  
58 @@ -207,7 +218,7 @@ static irqreturn_t tsc_adc_interrupt(int irq, void *dev)
59         tscadc_writel(ts_dev, TSCADC_REG_IRQEOI, 0x0);
60  
61         /* Turn on Step 1 again */
62 -       tscadc_writel(ts_dev, TSCADC_REG_SE, TSCADC_STPENB_STEPENB_GENERAL);
63 +       // tscadc_writel(ts_dev, TSCADC_REG_SE, TSCADC_STPENB_STEPENB_GENERAL);
64         return IRQ_HANDLED;
65  }
66  
67 @@ -461,6 +472,34 @@ static irqreturn_t tsc_interrupt(int irq, void *dev)
68  * The functions for inserting/removing driver as a module.
69  */
70  
71 +size_t do_adc_sample(struct kobject *kobj, struct attribute *attr, char *buf) {
72 +       struct platform_device *pdev;
73 +       struct device *dev;
74 +       struct tscadc *ts_dev;
75 +       int channel_num;
76 +
77 +       pdev = (struct platform_device *)container_of(kobj, struct device, kobj);
78 +       dev = &pdev->dev;
79 +
80 +       ts_dev = dev_get_drvdata(dev);
81 +
82 +       if(strncmp(attr->name, "ain", 3)) {
83 +               printk("Invalid ain num\n");
84 +               return -EINVAL;
85 +       }
86 +
87 +       channel_num = attr->name[3] - 0x30;
88 +       if(channel_num > 8 || channel_num < 1) {
89 +               printk("Invalid channel_num=%d\n", channel_num);
90 +               return -EINVAL;
91 +       }
92 +
93 +       tsc_adc_step_config(ts_dev, channel_num);
94 +
95 +       memcpy(buf, attr->name, strlen(attr->name)+1);
96 +       return strlen(attr->name);
97 +}
98 +
99  static int __devinit tscadc_probe(struct platform_device *pdev)
100  {
101         struct tscadc                   *ts_dev;
102 @@ -472,6 +511,18 @@ static     int __devinit tscadc_probe(struct platform_device *pdev)
103         struct resource                 *res;
104         struct clk                      *tsc_ick;
105  
106 +       printk("dev addr = %p\n", &pdev->dev);
107 +       printk("pdev addr = %p\n", pdev);
109 +       device_create_file(&pdev->dev, &dev_attr_ain1);
110 +       device_create_file(&pdev->dev, &dev_attr_ain2);
111 +       device_create_file(&pdev->dev, &dev_attr_ain3);
112 +       device_create_file(&pdev->dev, &dev_attr_ain4);
113 +       device_create_file(&pdev->dev, &dev_attr_ain5);
114 +       device_create_file(&pdev->dev, &dev_attr_ain6);
115 +       device_create_file(&pdev->dev, &dev_attr_ain7);
116 +       device_create_file(&pdev->dev, &dev_attr_ain8);
118         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
119         if (!res) {
120                 dev_err(&pdev->dev, "no memory resource defined.\n");
121 @@ -595,7 +646,6 @@ static      int __devinit tscadc_probe(struct platform_device *pdev)
122                         goto err_fail;
123         }
124         else {
125 -               tsc_adc_step_config(ts_dev, 8);
126                 tscadc_writel(ts_dev, TSCADC_REG_FIFO0THR, 0);
127                 irqenable = TSCADC_IRQENB_FIFO0THRES;
128         }
129 @@ -604,6 +654,7 @@ static      int __devinit tscadc_probe(struct platform_device *pdev)
130         ctrl |= TSCADC_CNTRLREG_TSCSSENB;
131         tscadc_writel(ts_dev, TSCADC_REG_CTRL, ctrl);   /* Turn on TSC_ADC */
132  
133 +       dev_set_drvdata(&pdev->dev, ts_dev);
134         return 0;
135  
136  err_fail:
137 diff --git a/include/linux/input/ti_tscadc.h b/include/linux/input/ti_tscadc.h
138 index 850cd4b..fc239c6 100644
139 --- a/include/linux/input/ti_tscadc.h
140 +++ b/include/linux/input/ti_tscadc.h
141 @@ -13,6 +13,7 @@
142   *                     0.
143   * @x_plate_resistance:        X plate resistance.
144   */
145 +#include <linux/device.h>
146  
147  #define TI_TSCADC_TSCMODE 0
148  #define TI_TSCADC_GENMODE 1
149 -- 
150 1.7.2.5