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