sync hh.org
[hh.org.git] / drivers / soc / tsc2200.c
blobfa396d23c7c60ae79ca4897ea0589afcf2a23394
1 /*
2 * TI TSC2200 Common Code
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 */
10 #include <asm/mach-types.h>
11 #include <asm/arch/hardware.h>
12 #include <asm/arch/pxa-regs.h>
14 #include <linux/interrupt.h>
15 #include <linux/device.h>
16 #include <linux/delay.h>
17 #include <linux/soc/tsc2200.h>
18 #include <linux/platform_device.h>
20 unsigned short tsc2200_read(struct device *dev, unsigned short reg)
23 struct tsc2200_data *devdata = dev_get_drvdata(dev);
25 reg |= TSC2200_REG_READ;
27 return devdata->platform->send(reg, 0);
29 EXPORT_SYMBOL(tsc2200_read);
31 void tsc2200_write(struct device *dev, unsigned short reg, unsigned short value)
33 struct tsc2200_data *devdata = dev_get_drvdata(dev);
35 // int reg=value;
36 devdata->platform->send(reg, value);
37 return;
39 EXPORT_SYMBOL(tsc2200_write);
41 unsigned short tsc2200_dav(struct device *dev)
43 return ( tsc2200_read(dev, TSC2200_CTRLREG_CONFIG) & TSC2200_CTRLREG_CONFIG_DAV ) ? 0 : 1;
45 EXPORT_SYMBOL(tsc2200_dav);
47 void tsc2200_lock( struct device *dev )
49 unsigned long flags=0;
50 struct tsc2200_data *devdata = dev_get_drvdata(dev);
51 spin_lock_irqsave(&devdata->lock, flags);
53 EXPORT_SYMBOL(tsc2200_lock);
55 void tsc2200_unlock( struct device *dev )
57 unsigned long flags=0;
58 struct tsc2200_data *devdata = dev_get_drvdata(dev);
59 spin_unlock_irqrestore(&devdata->lock, flags);
61 EXPORT_SYMBOL(tsc2200_unlock);
63 void tsc2200_stop(struct device *dev ) {
64 printk("TSC2200_ADC: %d\n", tsc2200_read( dev, TSC2200_CTRLREG_ADC ) );
65 tsc2200_write( dev, TSC2200_CTRLREG_ADC, 0);
66 printk("TSC2200_ADC: %d\n", tsc2200_read( dev, TSC2200_CTRLREG_ADC ) );
68 EXPORT_SYMBOL( tsc2200_stop );
70 void tsc2200_reset( struct device *dev )
72 unsigned long flags;
73 struct tsc2200_data *devdata = dev_get_drvdata(dev);
75 spin_lock_irqsave(&devdata->lock, flags);
77 tsc2200_write(dev, TSC2200_CTRLREG_RESET, 0xBBFF);
79 printk("%s: %X.\n", __FUNCTION__, tsc2200_read(dev, TSC2200_CTRLREG_ADC));
80 msleep(100);
81 printk("%s: %X.\n", __FUNCTION__, tsc2200_read(dev, TSC2200_CTRLREG_ADC));
83 tsc2200_write(dev, TSC2200_CTRLREG_REF, 0x1F);
84 tsc2200_write(dev, TSC2200_CTRLREG_CONFIG, 0xA);
86 spin_unlock_irqrestore(&devdata->lock, flags);
89 static int tsc2200_suspend(struct device *dev, pm_message_t state)
91 struct tsc2200_data *devdata = dev_get_drvdata(dev);
92 if (devdata->platform->exit) {
93 devdata->platform->exit();
95 return 0;
98 static int tsc2200_resume(struct device *dev)
100 struct tsc2200_data *devdata = dev_get_drvdata(dev);
101 if (devdata->platform->init) {
102 devdata->platform->init();
104 // tsc2200_reset( dev );
105 return 0;
108 static void tsc2200_register_button_driver ( struct device *dev ) {
110 struct tsc2200_data *devdata = dev_get_drvdata(dev);
111 struct tsc2200_platform_info *platform_info = devdata->platform;
113 struct platform_device *sdev = kzalloc (sizeof (*sdev), GFP_KERNEL);
114 struct tsc2200_buttons_data *buttons_devdata = kzalloc (sizeof (*buttons_devdata), GFP_KERNEL);
117 // Prepare some platform info for the tsc2200 buttons
118 sdev->name = "tsc2200-keys";
119 sdev->dev.platform_data = buttons_devdata;
121 buttons_devdata->tsc2200_dev = dev;
122 buttons_devdata->platform_info = platform_info->buttons_info;
124 platform_device_register( sdev );
126 devdata->buttons_dev = sdev;
130 static void tsc2200_unregister_button_driver (struct device *dev ) {
131 struct tsc2200_data *devdata = dev_get_drvdata(dev);
132 //struct tsc2200_platform_info *platform_info = devdata->platform;
134 kfree (devdata->buttons_dev->dev.platform_data);
135 kfree (devdata->buttons_dev);
139 static void tsc2200_register_ts_driver ( struct device *dev ) {
141 struct tsc2200_data *devdata = dev_get_drvdata(dev);
142 struct tsc2200_platform_info *platform_info = devdata->platform;
144 struct platform_device *sdev = kzalloc (sizeof (*sdev), GFP_KERNEL);
145 struct tsc2200_ts_data *ts_devdata = kzalloc (sizeof (*ts_devdata), GFP_KERNEL);
148 // Prepare some platform info for the tsc2200 buttons
149 sdev->name = "tsc2200-ts";
150 sdev->dev.platform_data = ts_devdata;
152 ts_devdata->tsc2200_dev = dev;
153 ts_devdata->platform_info = platform_info->touchscreen_info;
155 platform_device_register( sdev );
157 devdata->ts_dev = sdev;
161 static void tsc2200_unregister_ts_driver (struct device *dev ) {
162 struct tsc2200_data *devdata = dev_get_drvdata(dev);
163 //struct tsc2200_platform_info *platform_info = devdata->platform;
165 kfree (devdata->ts_dev->dev.platform_data);
166 kfree (devdata->ts_dev);
170 static int __init tsc2200_probe(struct device *dev)
172 struct tsc2200_data *devdata;
174 if (!(devdata = kcalloc(1, sizeof(struct tsc2200_data), GFP_KERNEL)))
175 return -ENOMEM;
177 dev_set_drvdata(dev, devdata);
178 spin_lock_init(&devdata->lock);
179 devdata->platform = dev->platform_data;
181 if (devdata->platform->init) {
182 devdata->platform->init();
185 udelay(300);
186 // tsc2200_reset( dev );
187 udelay(300);
189 printk("%s: SPI: cr0 %08x cr1 %08x sr: %08x it: %08x to: %08x ps: %08x\n",
190 __FUNCTION__,
191 SSCR0_P2, SSCR1_P2, SSSR_P2, SSITR_P2, SSTO_P2, SSPSP_P2);
193 // Are there keys on this device?
194 if (devdata->platform->buttons_info) {
195 tsc2200_register_button_driver( dev );
198 // Is there a touchscreen on this device?
199 if (devdata->platform->touchscreen_info) {
200 tsc2200_register_ts_driver( dev );
204 return 0;
208 static int __exit tsc2200_remove(struct device *dev)
210 struct tsc2200_data *devdata = dev_get_drvdata(dev);
212 // Are there keys on this device?
213 if (devdata->platform->buttons_info) {
214 tsc2200_unregister_button_driver( dev );
217 // Is there a touchscreen on this device?
218 if (devdata->platform->touchscreen_info) {
219 tsc2200_unregister_ts_driver( dev );
222 kfree(devdata);
223 return 0;
226 static struct platform_driver tsc2200_driver = {
227 .driver = {
228 .name = "tsc2200",
229 .bus = &platform_bus_type,
230 .probe = tsc2200_probe,
231 .remove = __exit_p(tsc2200_remove),
232 .suspend = tsc2200_suspend,
233 .resume = tsc2200_resume,
237 static int __init tsc2200_init(void)
239 return platform_driver_register(&tsc2200_driver);
242 static void __exit tsc2200_exit(void)
244 platform_driver_unregister(&tsc2200_driver);
247 module_init(tsc2200_init);
248 module_exit(tsc2200_exit);
250 MODULE_LICENSE("GPL");