summaryrefslogtreecommitdiffstats
path: root/recipes-kernel/linux/linux-ti33x-psp-3.2/0012-tscadc-Trigger-through-sysfs.patch
blob: 398c951e579507b764732952852068a51c2504ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
From 5b0c06b556db15cac8d14eb7e74307521481e185 Mon Sep 17 00:00:00 2001
From: Joel A Fernandes <joelagnel@ti.com>
Date: Mon, 28 Nov 2011 20:55:25 -0600
Subject: [PATCH 12/21] tscadc: Trigger through sysfs

Signed-off-by: Joel A Fernandes <joelagnel@ti.com>

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 0b91bdc..a74d9ba 100644
--- a/drivers/input/touchscreen/ti_tscadc.c
+++ b/drivers/input/touchscreen/ti_tscadc.c
@@ -26,6 +26,17 @@
 #include <linux/io.h>
 #include <linux/input/ti_tscadc.h>
 #include <linux/delay.h>
+#include <linux/device.h>
+
+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 */
@@ -144,12 +155,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);
@@ -199,7 +210,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);
 
@@ -207,7 +218,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;
 }
 
@@ -461,6 +472,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;
@@ -472,6 +511,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");
@@ -604,7 +655,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 <linux/device.h>
 
 #define TI_TSCADC_TSCMODE 0
 #define TI_TSCADC_GENMODE 1
-- 
1.7.7.4