2 * Touch Sensor Interface driver
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>
14 #include "s5pc210_ts_gpio_i2c.h"
15 #include "s5pc210_ts.h"
17 /* function prototype define */
18 int s5pv310_ts_sysfs_create (struct platform_device *pdev);
19 void s5pv310_ts_sysfs_remove (struct platform_device *pdev);
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);
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);
32 /* touch threshold control (range 0 - 10) : default 3 */
33 #define THRESHOLD_MAX 10
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);
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);
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);
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,
59 static struct attribute_group s5pv310_ts_attr_group = {
61 .attrs = s5pv310_ts_sysfs_entries,
63 static ssize_t show_hold_state (struct device *dev, struct device_attribute *attr, char *buf)
65 if(s5pv310_ts.hold_status)
66 return sprintf(buf, "on\n");
68 return sprintf(buf, "off\n");
70 static ssize_t set_hold_state (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
75 local_irq_save(flags);
77 if(!strcmp(buf, "on\n"))
78 s5pv310_ts.hold_status = 1;
80 #if defined(CONFIG_TOUCHSCREEN_S5PV310_MT)
81 /* INT_mode : disable interrupt, low-active, finger moving */
83 s5pv310_ts_write(MODULE_INTMODE, &wdata, 1);
85 /* INT_mode : enable interrupt, low-active, finger moving */
87 s5pv310_ts_write(MODULE_INTMODE, &wdata, 1);
90 s5pv310_ts.hold_status = 0;
93 local_irq_restore(flags);
97 static ssize_t show_sampling_rate (struct device *dev, struct device_attribute *attr, char *buf)
99 switch(s5pv310_ts.sampling_rate) {
101 s5pv310_ts.sampling_rate = 0;
103 return sprintf(buf, "10 msec\n");
105 return sprintf(buf, "20 msec\n");
107 return sprintf(buf, "50 msec\n");
111 static ssize_t set_sampling_rate(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
116 if(!(sscanf(buf, "%u\n", &val)))
119 local_irq_save(flags);
121 s5pv310_ts.sampling_rate = 2;
123 s5pv310_ts.sampling_rate = 1;
125 s5pv310_ts.sampling_rate = 0;
127 local_irq_restore(flags);
131 static ssize_t show_threshold_x(struct device *dev, struct device_attribute *attr, char *buf)
133 if(s5pv310_ts.threshold_x > THRESHOLD_MAX)
134 s5pv310_ts.threshold_x = THRESHOLD_MAX;
136 return sprintf(buf, "%d\n", s5pv310_ts.threshold_x);
139 static ssize_t set_threshold_x(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
144 if(!(sscanf(buf, "%u\n", &val))) return -EINVAL;
146 local_irq_save(flags);
151 if(val > THRESHOLD_MAX)
154 s5pv310_ts.threshold_x = val;
156 local_irq_restore(flags);
160 static ssize_t show_threshold_y(struct device *dev, struct device_attribute *attr, char *buf)
162 if(s5pv310_ts.threshold_y > THRESHOLD_MAX)
163 s5pv310_ts.threshold_y = THRESHOLD_MAX;
165 return sprintf(buf, "%d\n", s5pv310_ts.threshold_y);
167 static ssize_t set_threshold_y(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
172 if(!(sscanf(buf, "%u\n", &val)))
175 local_irq_save(flags);
180 if(val > THRESHOLD_MAX)
183 s5pv310_ts.threshold_y = val;
185 local_irq_restore(flags);
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)
197 local_irq_save(flags);
199 /* INT_mode : disable interrupt */
201 s5pv310_ts_write(MODULE_INTMODE, &wdata, 1);
203 /* touch calibration */
206 s5pv310_ts_write(MODULE_CALIBRATION, &wdata, 1); /* set mode */
210 /* INT_mode : enable interrupt, low-active, periodically*/
213 s5pv310_ts_write(MODULE_INTMODE, &wdata, 1);
215 local_irq_restore(flags);
222 int s5pv310_ts_sysfs_create (struct platform_device *pdev)
226 s5pv310_ts.hold_status = 0;
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) */
232 return sysfs_create_group(&pdev->dev.kobj, &s5pv310_ts_attr_group);
234 void s5pv310_ts_sysfs_remove (struct platform_device *pdev)
236 sysfs_remove_group(&pdev->dev.kobj, &s5pv310_ts_attr_group);