2 * Copyright (C) 2003 Joshua Wise
3 * Copyright (c) 2002,2003 SHARP Corporation
4 * Copyright (C) 2005 Pawel Kolodziejski
6 * Use consistent with the GNU GPL is permitted,
7 * provided that this copyright notice is
8 * preserved in its entirety in all copies and derived works.
10 * HAL code based on h5400_asic_io.c, which is
11 * Copyright (C) 2003 Compaq Computer Corporation.
13 * Author: Joshua Wise <joshua at joshuawise.com>
18 #include <linux/module.h>
19 #include <linux/version.h>
20 #include <linux/init.h>
22 #include <linux/interrupt.h>
23 #include <linux/sched.h>
25 #include <linux/device.h>
26 #include <linux/sysctl.h>
27 #include <linux/proc_fs.h>
28 #include <linux/delay.h>
29 #include <linux/input.h>
30 #include <linux/soc/tsc2200.h>
31 #include <linux/platform_device.h>
33 #include <asm/mach/map.h>
34 #include <asm/mach-types.h>
35 #include <asm/arch/hardware.h>
37 #include <asm/mach/irq.h>
38 #include <asm/arch/pxa-regs.h>
39 #include <asm/hardware/ipaq-asic3.h>
41 #define SAMPLE_TIMEOUT 20 /* sample every 20ms */
43 //extern struct platform_device h4000_asic3;
44 //#define asic3 &h4000_asic3.dev
47 //#define TS_IRQ IRQ_GPIO(TS_IRQ_N)
48 static struct timer_list timer_pen
;
49 static struct input_dev
*idev
;
51 //static spinlock_t ts_lock;
52 static int irq_disable
;
53 static int touch_pressed
;
55 static void report_touchpanel(int x
, int y
, int pressure
)
57 printk("report: x=%04d y=%04d pressure=%04d\n",
63 // input_report_key(idev, BTN_TOUCH, pressure != 0);
64 input_report_abs(idev
, ABS_PRESSURE
, pressure
);
65 input_report_abs(idev
, ABS_X
, x
);
66 input_report_abs(idev
, ABS_Y
, y
);
70 static void ts_check( struct tsc2200_ts_data
*devdata
) {
72 struct tsc2200_ts_platform_info
*platform_info
= devdata
->platform_info
;
74 unsigned short x_pos
, y_pos
, pressure
;
76 int touched
= tsc2200_read(devdata
->tsc2200_dev
, TSC2200_CTRLREG_ADC
) & TSC2200_CTRLREG_ADC_PSM_TSC2200
;
80 tsc2200_write(devdata
->tsc2200_dev
,
82 TSC2200_CTRLREG_ADC_AD1
|
83 TSC2200_CTRLREG_ADC_RES (TSC2200_CTRLREG_ADC_RES_12BIT
) |
84 TSC2200_CTRLREG_ADC_AVG (TSC2200_CTRLREG_ADC_16AVG
) |
85 TSC2200_CTRLREG_ADC_CL (TSC2200_CTRLREG_ADC_CL_4MHZ_10BIT
) |
86 TSC2200_CTRLREG_ADC_PV (TSC2200_CTRLREG_ADC_PV_1mS
) );
90 x_pos
= tsc2200_read(devdata
->tsc2200_dev
, TSC2200_DATAREG_X
);
91 y_pos
= tsc2200_read(devdata
->tsc2200_dev
, TSC2200_DATAREG_Y
);
93 printk("%d\n", tsc2200_read(devdata
->tsc2200_dev
, TSC2200_DATAREG_KPDATA
));
95 // pressure = tsc2200_read(devdata->tsc2200_dev, TSC2200_DATAREG_Z2) -
96 // tsc2200_read(devdata->tsc2200_dev, TSC2200_DATAREG_Z1);
98 report_touchpanel(x_pos
, y_pos
, 1);
100 mod_timer(&timer_pen
, jiffies
+ (SAMPLE_TIMEOUT
* HZ
) / 1000);
102 //tsc2200_stop( devdata->tsc2200_dev );
103 report_touchpanel(0, 0, 0);
104 //printk("touch released irq=%d\n", platform_info->irq);
105 enable_irq(platform_info
->irq
);
106 printk("touch released irq=%d\n", platform_info
->irq
);
111 static irqreturn_t
tsc2200_stylus(int irq
, void* data
, struct pt_regs
*regs
)
113 struct tsc2200_ts_data
*devdata
= data
;
114 struct tsc2200_ts_platform_info
*platform_info
= devdata
->platform_info
;
116 disable_irq( platform_info
->irq
);
117 printk("touch pressed\n");
123 static void tsc2200_ts_timer(unsigned long data
)
125 struct tsc2200_ts_data
*devdata
= (void*) data
;
126 //struct tsc2200_ts_platform_info *platform_info = devdata->platform_info;
131 int tsc2200_ts_probe(struct device
*dev
)
133 struct tsc2200_ts_data
*devdata
= dev
->platform_data
;
134 struct tsc2200_ts_platform_info
*platform_info
= devdata
->platform_info
;
136 printk("tsc2200_ts_probe IRQ: %d\n", platform_info
->irq
);
138 init_timer(&timer_pen
);
139 timer_pen
.function
= tsc2200_ts_timer
;
140 timer_pen
.data
= (unsigned long) devdata
;
142 idev
= input_allocate_device();
147 // idev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
148 set_bit(EV_ABS
, idev
->evbit
);
149 set_bit(ABS_X
, idev
->absbit
);
150 set_bit(ABS_Y
, idev
->absbit
);
151 set_bit(ABS_PRESSURE
, idev
->absbit
);
152 // set_bit(BTN_TOUCH, idev->keybit);
154 input_set_abs_params(idev
, ABS_X
, 0, 5000, 0, 0);
155 input_set_abs_params(idev
, ABS_Y
, 0, 5000, 0, 0);
156 input_set_abs_params(idev
, ABS_PRESSURE
, 0, 1, 0 ,0);
158 idev
->name
= "tsc2200-ts";
159 idev
->phys
= "touchscreen/tsc2200-ts";
164 request_irq(platform_info
->irq
, tsc2200_stylus
, SA_ONESHOT
, "tsc2200-ts", devdata
);
165 set_irq_type(platform_info
->irq
, IRQT_FALLING
);
166 enable_irq(platform_info
->irq
);
168 input_register_device(idev
);
174 static int tsc2200_ts_remove(struct device
*dev
)
176 struct tsc2200_ts_data
*devdata
= dev
->platform_data
;
177 struct tsc2200_ts_platform_info
*platform_info
= devdata
->platform_info
;
179 printk("tsc2200_ts: Removing...\n");
180 del_timer_sync(&timer_pen
);
181 disable_irq(platform_info
->irq
);
182 free_irq(platform_info
->irq
, NULL
);
184 input_unregister_device(idev
);
186 printk("tsc2200_ts: done!\n");
191 static int tsc2200_ts_resume(struct device
*dev
)
196 #define h4000_ts_resume NULL
199 static struct platform_driver tsc2200_ts_driver
= {
201 .name
= "tsc2200-ts",
202 .probe
= tsc2200_ts_probe
,
203 .remove
= tsc2200_ts_remove
,
206 .resume
= tsc2200_ts_resume
,
211 //struct platform_device z = { .name = "h4000_ts", };
213 static int __init
tsc2200_ts_init(void)
215 return platform_driver_register(&tsc2200_ts_driver
);
218 static void __exit
tsc2200_ts_exit(void)
220 platform_driver_unregister(&tsc2200_ts_driver
);
223 module_init(tsc2200_ts_init
)
224 module_exit(tsc2200_ts_exit
)
226 //EXPORT_SYMBOL(h4000_spi_putget);
228 MODULE_AUTHOR("Joshua Wise, Pawel Kolodziejski");
229 MODULE_DESCRIPTION("Touchscreen support for the iPAQ h4xxx");
230 MODULE_LICENSE("GPL");