upload tizen1.0 source
[kernel/linux-2.6.36.git] / drivers / input / touchscreen / s5pc210_ts_sysfs.c
1 /*
2  * Touch Sensor Interface driver
3  */
4 #include <linux/kernel.h>
5 #include <linux/types.h>
6 #include <linux/module.h>
7 #include <linux/device.h>
8 #include <linux/platform_device.h>
9 #include <linux/delay.h>
10 #include <linux/irq.h>
11 #include <linux/interrupt.h>
12 #include <linux/sysfs.h>
13
14 #include "s5pc210_ts_gpio_i2c.h"
15 #include "s5pc210_ts.h"
16
17 /* function prototype define */
18 int s5pv310_ts_sysfs_create (struct platform_device *pdev);
19 void s5pv310_ts_sysfs_remove (struct platform_device *pdev);
20
21 /*  sysfs function prototype define */
22 /*  screen hold control (on -> hold, off -> normal mode) */
23 static ssize_t show_hold_state (struct device *dev, struct device_attribute *attr, char *buf);
24 static ssize_t set_hold_state (struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
25 static DEVICE_ATTR(hold_state, S_IRWXUGO, show_hold_state, set_hold_state);
26
27 /* touch sampling rate control (5, 10, 20 : unit msec) */
28 static ssize_t show_sampling_rate (struct device *dev, struct device_attribute *attr, char *buf);
29 static ssize_t set_sampling_rate (struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
30 static DEVICE_ATTR(sampling_rate, S_IRWXUGO, show_sampling_rate, set_sampling_rate);
31
32 /* touch threshold control (range 0 - 10) : default 3 */
33 #define THRESHOLD_MAX   10
34
35 static  ssize_t show_threshold_x                (struct device *dev, struct device_attribute *attr, char *buf);
36 static  ssize_t set_threshold_x                 (struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
37 static  DEVICE_ATTR(threshold_x, S_IRWXUGO, show_threshold_x, set_threshold_x);
38
39 static  ssize_t show_threshold_y                (struct device *dev, struct device_attribute *attr, char *buf);
40 static  ssize_t set_threshold_y                 (struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
41 static  DEVICE_ATTR(threshold_y, S_IRWXUGO, show_threshold_y, set_threshold_y);
42
43 /* touch calibration */
44 #if defined(CONFIG_TOUCHSCREEN_S5PV310_MT)
45 static ssize_t set_ts_cal(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
46 static DEVICE_ATTR(ts_cal, S_IWUGO, NULL, set_ts_cal);
47 #endif
48 static struct attribute *s5pv310_ts_sysfs_entries[] = {
49         &dev_attr_hold_state.attr,
50         &dev_attr_sampling_rate.attr,
51         &dev_attr_threshold_x.attr,
52         &dev_attr_threshold_y.attr,
53 #if defined(CONFIG_TOUCHSCREEN_S5PV310_MT)
54         &dev_attr_ts_cal.attr,
55 #endif
56         NULL
57 };
58
59 static struct attribute_group s5pv310_ts_attr_group = {
60         .name   = NULL,
61         .attrs  = s5pv310_ts_sysfs_entries,
62 };
63 static  ssize_t show_hold_state (struct device *dev, struct device_attribute *attr, char *buf)
64 {
65         if(s5pv310_ts.hold_status)
66                 return  sprintf(buf, "on\n");
67         else
68                 return  sprintf(buf, "off\n");
69 }
70 static ssize_t set_hold_state (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
71 {
72         unsigned long flags;
73         unsigned char wdata;
74
75         local_irq_save(flags);
76
77         if(!strcmp(buf, "on\n"))
78                 s5pv310_ts.hold_status = 1;
79         else {
80 #if defined(CONFIG_TOUCHSCREEN_S5PV310_MT)
81                 /* INT_mode : disable interrupt, low-active, finger moving */
82                 wdata = 0x01;
83                 s5pv310_ts_write(MODULE_INTMODE, &wdata, 1);
84                 mdelay(10);
85                 /* INT_mode : enable interrupt, low-active, finger moving */
86                 wdata = 0x09;
87                 s5pv310_ts_write(MODULE_INTMODE, &wdata, 1);
88                 mdelay(10);
89 #endif
90                 s5pv310_ts.hold_status = 0;
91         }
92
93         local_irq_restore(flags);
94
95         return count;
96 }
97 static ssize_t show_sampling_rate (struct device *dev, struct device_attribute *attr, char *buf)
98 {
99         switch(s5pv310_ts.sampling_rate) {
100         default :
101                 s5pv310_ts.sampling_rate = 0;
102         case    0:
103                 return  sprintf(buf, "10 msec\n");
104         case    1:
105                 return  sprintf(buf, "20 msec\n");
106         case    2:
107                 return  sprintf(buf, "50 msec\n");
108         }
109 }
110
111 static ssize_t set_sampling_rate(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
112 {
113         unsigned long   flags;
114         unsigned int    val;
115
116         if(!(sscanf(buf, "%u\n", &val)))
117                 return -EINVAL;
118
119         local_irq_save(flags);
120         if(val > 20)
121                 s5pv310_ts.sampling_rate = 2;
122         else if(val > 10)
123                 s5pv310_ts.sampling_rate = 1;
124         else
125                 s5pv310_ts.sampling_rate = 0;
126
127         local_irq_restore(flags);
128
129         return count;
130 }
131 static ssize_t show_threshold_x(struct device *dev, struct device_attribute *attr, char *buf)
132 {
133         if(s5pv310_ts.threshold_x > THRESHOLD_MAX)
134                 s5pv310_ts.threshold_x = THRESHOLD_MAX;
135
136         return  sprintf(buf, "%d\n", s5pv310_ts.threshold_x);
137 }
138
139 static ssize_t set_threshold_x(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
140 {
141         unsigned long   flags;
142         unsigned int    val;
143
144         if(!(sscanf(buf, "%u\n", &val)))        return  -EINVAL;
145
146         local_irq_save(flags);
147
148         if(val < 0)
149                 val *= (-1);
150
151         if(val > THRESHOLD_MAX)
152                 val = THRESHOLD_MAX;
153
154         s5pv310_ts.threshold_x = val;
155
156         local_irq_restore(flags);
157
158         return count;
159 }
160 static ssize_t show_threshold_y(struct device *dev, struct device_attribute *attr, char *buf)
161 {
162         if(s5pv310_ts.threshold_y > THRESHOLD_MAX)
163                 s5pv310_ts.threshold_y = THRESHOLD_MAX;
164
165         return  sprintf(buf, "%d\n", s5pv310_ts.threshold_y);
166 }
167 static ssize_t set_threshold_y(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
168 {
169         unsigned long flags;
170         unsigned int val;
171
172         if(!(sscanf(buf, "%u\n", &val)))
173                 return  -EINVAL;
174
175         local_irq_save(flags);
176
177         if(val < 0)
178                 val *= (-1);
179
180         if(val > THRESHOLD_MAX)
181                 val = THRESHOLD_MAX;
182
183         s5pv310_ts.threshold_y = val;
184
185         local_irq_restore(flags);
186
187         return count;
188 }
189
190 #if defined(CONFIG_TOUCHSCREEN_S5PV310_MT)
191 static ssize_t set_ts_cal (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
192 {
193
194         unsigned char wdata;
195         unsigned long flags;
196
197         local_irq_save(flags);
198
199         /* INT_mode : disable interrupt */
200         wdata = 0x00;
201         s5pv310_ts_write(MODULE_INTMODE, &wdata, 1);
202
203         /* touch calibration */
204
205         wdata =0x03;
206         s5pv310_ts_write(MODULE_CALIBRATION, &wdata, 1);        /* set mode */
207
208         mdelay(500);
209
210         /* INT_mode : enable interrupt, low-active, periodically*/
211
212         wdata = 0x09;
213         s5pv310_ts_write(MODULE_INTMODE, &wdata, 1);
214
215         local_irq_restore(flags);
216
217         return count;
218 }
219
220 #endif
221
222 int s5pv310_ts_sysfs_create (struct platform_device *pdev)
223 {
224         /* variable init */
225
226         s5pv310_ts.hold_status = 0;
227
228         s5pv310_ts.sampling_rate        = 0;    /* 5 msec sampling */
229         s5pv310_ts.threshold_x  = TS_X_THRESHOLD;       /* x data threshold (0~10) */
230         s5pv310_ts.threshold_y  = TS_Y_THRESHOLD;       /* y data threshold (0~10) */
231
232         return  sysfs_create_group(&pdev->dev.kobj, &s5pv310_ts_attr_group);
233 }
234 void s5pv310_ts_sysfs_remove (struct platform_device *pdev)
235 {
236         sysfs_remove_group(&pdev->dev.kobj, &s5pv310_ts_attr_group);
237 }