sync hh.org
[hh.org.git] / drivers / soc / tsc2200_keys.c
blob44dc6f2c97144ec0dfe67c6ee8f79415433a8eac
1 /*
2 * LED interface for Himalaya, the HTC PocketPC.
4 * License: GPL
6 * Author: Luke Kenneth Casson Leighton, Copyright(C) 2004
8 * Copyright(C) 2004, Luke Kenneth Casson Leighton.
10 * History:
12 * 2004-02-19 Luke Kenneth Casson Leighton created.
16 #include <linux/init.h>
19 #include <linux/platform_device.h>
20 #include <linux/module.h>
21 #include <linux/delay.h>
22 #include <linux/platform_device.h>
23 #include <linux/input.h>
24 #include <linux/soc/asic3_base.h>
25 #include <linux/irq.h>
27 #include <asm/hardware/ipaq-asic3.h>
28 #include <asm/hardware/ipaq-ops.h>
29 #include <asm/hardware.h>
30 #include <asm/arch/pxa-regs.h>
31 #include <asm/mach-types.h>
32 #include <asm/arch/ipaq.h>
33 #include <asm/arch/htcblueangel-gpio.h>
34 #include <asm/arch/htcblueangel-asic.h>
36 #include <linux/soc/tsc2200.h>
38 #ifdef DEBUG
39 #define dprintk(x...) printk(x)
40 #else
41 #define dprintk(x...)
42 #endif
44 #define KP_POLL_TIME 30 /* milliseconds */
46 static void
47 blueangel_kp_check_keys( struct tsc2200_buttons_data *devdata, int new)
49 struct tsc2200_buttons_platform_info *platform_info = devdata->platform_info;
51 int i, pressed, xor;
52 struct tsc2200_key *k;
54 xor = new ^ devdata->keydata;
55 for (i = 0 ; i < platform_info->num_keys ; i++) {
56 k = &platform_info->keys[i];
57 if ((xor & (1 << k->key_index)))
59 pressed = new & (1 << k->key_index);
60 input_report_key(devdata->input_dev, k->keycode, pressed);
61 input_sync(devdata->input_dev);
63 if (pressed)
64 printk("%s pressed\n", k->name);
65 else
66 printk("%s released\n", k->name);
70 devdata->keydata = new;
73 static void
74 blueangel_kp_getkey( struct tsc2200_buttons_data *devdata )
76 struct tsc2200_buttons_platform_info *platform_info = devdata->platform_info;
78 int status, keys;
80 // tsc2200_lock( devdata->tsc2200_dev );
81 status = tsc2200_read( devdata->tsc2200_dev, TSC2200_CTRLREG_KEY);
83 if (status & 0x8000) {
84 keys = tsc2200_read( devdata->tsc2200_dev, TSC2200_DATAREG_KPDATA );
85 } else {
86 keys = 0;
89 // tsc2200_unlock( devdata->tsc2200_dev );
91 blueangel_kp_check_keys(devdata, keys);
93 if (keys) {
94 mod_timer (&devdata->timer, jiffies + (KP_POLL_TIME * HZ) / 1000);
95 } else {
96 enable_irq(platform_info->irq);
99 return;
102 static void
103 tsc2200_buttons_timer(void *data)
105 struct tsc2200_buttons_data *devdata = data;
107 printk("t");
108 blueangel_kp_getkey(devdata);
111 static irqreturn_t tsc2200_buttons_irq(int irq, void *data, struct pt_regs *regs)
113 struct tsc2200_buttons_data *devdata = data;
114 struct tsc2200_buttons_platform_info *platform_info = devdata->platform_info;
116 printk("i");
118 disable_irq( platform_info->irq );
120 blueangel_kp_getkey(devdata);
122 return IRQ_HANDLED;
125 static int tsc2200_buttons_probe (struct device *dev )
127 struct tsc2200_buttons_data *devdata = dev->platform_data;
128 struct tsc2200_buttons_platform_info *platform_info = devdata->platform_info;
130 int i;
131 struct tsc2200_key *k;
133 printk("%x", platform_info->num_keys);
134 dprintk("%s\n", __FUNCTION__);
136 // Allocate input device
137 devdata->input_dev = input_allocate_device();
138 //init_input_dev(devdata->input_dev);
139 set_bit(EV_KEY, devdata->input_dev->evbit);
141 //devdata->input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
143 for (i = 0 ; i < platform_info->num_keys ; i++) {
144 k = &platform_info->keys[i];
145 set_bit(k->keycode, devdata->input_dev->keybit);
148 devdata->input_dev->name = "tsc2200-keys";
149 input_register_device(devdata->input_dev);
151 // tsc2200_write(devdata->tsc2200_dev,
152 // TSC2200_CTRLREG_ADC,
153 // TSC2200_CTRLREG_ADC_AD3 |
154 // TSC2200_CTRLREG_ADC_AD1 |
155 // TSC2200_CTRLREG_ADC_AD0 |
156 // TSC2200_CTRLREG_ADC_RES (TSC2200_CTRLREG_ADC_RES_12BIT) |
157 // TSC2200_CTRLREG_ADC_AVG (TSC2200_CTRLREG_ADC_16AVG) |
158 // TSC2200_CTRLREG_ADC_CL (TSC2200_CTRLREG_ADC_CL_4MHZ_10BIT) |
159 // TSC2200_CTRLREG_ADC_PV (TSC2200_CTRLREG_ADC_PV_1mS) );
161 // Wait for keypress interrupt from the tsc2200
162 request_irq( platform_info->irq, tsc2200_buttons_irq, SA_SAMPLE_RANDOM, "tsc2200-keys", devdata);
163 enable_irq( platform_info->irq );
164 set_irq_type( platform_info->irq, IRQT_FALLING);
166 // Initialize timer for buttons
167 init_timer(&devdata->timer);
168 devdata->timer.function = tsc2200_buttons_timer;
169 devdata->timer.data = devdata;
171 return 0;
174 static int tsc2200_buttons_suspend( struct device *dev, pm_message_t state) {
175 struct tsc2200_buttons_data *devdata = dev->platform_data;
176 struct tsc2200_buttons_platform_info *platform_info = devdata->platform_info;
178 disable_irq(platform_info->irq);
180 return 0;
183 static int tsc2200_buttons_resume ( struct device *dev ) {
184 struct tsc2200_buttons_data *devdata = dev->platform_data;
185 struct tsc2200_buttons_platform_info *platform_info = devdata->platform_info;
187 enable_irq(platform_info->irq);
189 return 0;
192 static int tsc2200_buttons_remove (struct device *dev)
194 struct tsc2200_buttons_data *devdata = dev->platform_data;
195 struct tsc2200_buttons_platform_info *platform_info = devdata->platform_info;
197 dprintk("%s\n", __FUNCTION__);
198 input_unregister_device(devdata->input_dev);
200 disable_irq( platform_info->irq );
201 free_irq( platform_info->irq, NULL);
203 del_timer_sync (&devdata->timer);
204 return 0;
207 static struct platform_driver tsc2200_buttons = {
208 .driver = {
209 .name = "tsc2200-keys",
210 .probe = tsc2200_buttons_probe,
211 .remove = tsc2200_buttons_remove,
212 .suspend = tsc2200_buttons_suspend,
213 .resume = tsc2200_buttons_resume,
217 static int tsc2200_buttons_init(void) {
218 printk("Registering tsc2200 buttons driver\n");
219 return platform_driver_register(&tsc2200_buttons);
222 static void tsc2200_buttons_exit(void) {
223 printk("Deregistering tsc2200 buttons driver\n");
224 platform_driver_unregister(&tsc2200_buttons);
228 module_init (tsc2200_buttons_init);
229 module_exit (tsc2200_buttons_exit);
231 MODULE_LICENSE("GPL");