sync hh.org
[hh.org.git] / arch / arm / mach-pxa / himalaya / himalaya_tsc2200.c
blob1d79fedc9ab8d21649a0c2b00137ce07540e1362
1 #include <linux/device.h>
2 #include <asm/mach-types.h>
3 #include <asm/arch/hardware.h>
4 #include <asm/arch/pxa-regs.h>
5 #include <asm/arch/ssp.h>
6 #include "tsc2200.h"
8 struct ssp_dev tsc2200_nssp_dev;
9 static spinlock_t nssp_lock;
10 static DECLARE_MUTEX( tsc2200_sem );
11 EXPORT_SYMBOL( tsc2200_sem );
13 static int nssp_bus_match(struct device *dev, struct device_driver *drv)
15 printk("%s: %s -> %s\n", __FUNCTION__, dev->bus_id, drv->name);
16 if ( strstr( dev->bus_id, drv->name ) )
17 return 1;
18 return 0;
21 static void nssp_bus_release(struct device *dev)
26 void tsc2200_write(unsigned short reg, unsigned short val)
28 unsigned long flags;
30 spin_lock_irqsave( &nssp_lock, flags );
32 ssp_write_word(&tsc2200_nssp_dev, reg);
33 ssp_write_word(&tsc2200_nssp_dev, val);
34 ssp_read_word(&tsc2200_nssp_dev); // dummy read for reg
35 ssp_read_word(&tsc2200_nssp_dev); // dummy read for val
37 spin_unlock_irqrestore( &nssp_lock, flags );
39 EXPORT_SYMBOL( tsc2200_write );
41 unsigned short tsc2200_read(unsigned short reg)
43 unsigned short result; // initial value is ignored
44 unsigned long flags;
46 reg |= TSC2200_REG_READ;
48 spin_lock_irqsave( &nssp_lock, flags );
50 ssp_write_word(&tsc2200_nssp_dev, reg);
51 ssp_write_word(&tsc2200_nssp_dev, 0);
52 ssp_read_word(&tsc2200_nssp_dev); // dummy read for reg
53 result = ssp_read_word(&tsc2200_nssp_dev);
55 spin_unlock_irqrestore( &nssp_lock, flags );
56 // printk("%s: %X.\n", __FUNCTION__, result);
58 return result;
60 EXPORT_SYMBOL( tsc2200_read );
62 void tsc2200_reset(void)
64 down_interruptible(&tsc2200_sem);
66 tsc2200_write(TSC2200_CTRLREG_RESET, 0xBBFF);
68 printk("%s: %X.\n", __FUNCTION__, tsc2200_read(TSC2200_CTRLREG_ADC));
69 msleep(100);
70 printk("%s: %X.\n", __FUNCTION__, tsc2200_read(TSC2200_CTRLREG_ADC));
72 tsc2200_write(TSC2200_CTRLREG_ADC,
73 TSC2200_CTRLREG_ADC_PSM_TSC2200 |
74 TSC2200_CTRLREG_ADC_STS |
75 TSC2200_CTRLREG_ADC_AD0 |
76 TSC2200_CTRLREG_ADC_RES (TSC2200_CTRLREG_ADC_RES_12BITP) |
77 TSC2200_CTRLREG_ADC_AVG (TSC2200_CTRLREG_ADC_16AVG) |
78 TSC2200_CTRLREG_ADC_CL (TSC2200_CTRLREG_ADC_CL_2MHZ_12BIT) |
79 TSC2200_CTRLREG_ADC_PV (TSC2200_CTRLREG_ADC_PV_500uS) );
80 tsc2200_write(TSC2200_CTRLREG_REF, 0x1F);
81 tsc2200_write(TSC2200_CTRLREG_CONFIG, 0xA);
82 tsc2200_write(TSC2200_CTRLREG_ADC,
83 TSC2200_CTRLREG_ADC_AD0 |
84 TSC2200_CTRLREG_ADC_RES (TSC2200_CTRLREG_ADC_RES_12BIT) |
85 TSC2200_CTRLREG_ADC_AVG (TSC2200_CTRLREG_ADC_16AVG) |
86 TSC2200_CTRLREG_ADC_CL (TSC2200_CTRLREG_ADC_CL_1MHZ_12BIT) |
87 TSC2200_CTRLREG_ADC_PV (TSC2200_CTRLREG_ADC_PV_100mS) );
89 up(&tsc2200_sem);
91 EXPORT_SYMBOL( tsc2200_reset );
93 int tsc2200_dav(void)
95 return ( tsc2200_read(TSC2200_CTRLREG_CONFIG) & TSC2200_CTRLREG_CONFIG_DAV ) ? 0 : 1;
97 EXPORT_SYMBOL( tsc2200_dav );
99 static int tsc2200_probe( struct device *dev )
101 if ( !machine_is_himalaya() ) {
102 printk("%s: unknown iPAQ model %s\n", __FUNCTION__, h3600_generic_name() );
103 return -ENODEV;
106 printk("%s: initializing NSSP.\n", __FUNCTION__);
108 spin_lock_init(&nssp_lock);
110 pxa_gpio_mode(GPIO81_NSSP_CLK_OUT);
111 pxa_gpio_mode(GPIO82_NSSP_FRM_OUT);
112 pxa_gpio_mode(GPIO83_NSSP_TX);
113 pxa_gpio_mode(GPIO84_NSSP_RX);
114 GPSR(GPIO82_NSFRM) = GPIO_bit(GPIO82_NSFRM);
116 ssp_init(&tsc2200_nssp_dev,
118 SSCR0_Motorola | SSCR0_DataSize(0x10),
119 SSCR1_TTE | SSCR1_EBCEI | SSCR1_SPH |
120 SSCR1_TxTresh(1) | SSCR1_RxTresh(1),
122 SSCR0_SerClkDiv(0x14),
123 NULL );
124 ssp_enable(&tsc2200_nssp_dev);
126 printk("%s: initializing the tsc2200.\n", __FUNCTION__);
128 udelay(300);
129 tsc2200_reset();
130 udelay(300);
132 printk("%s: SPI: cr0 %08x cr1 %08x sr: %08x it: %08x to: %08x ps: %08x\n",
133 __FUNCTION__,
134 SSCR0_P2, SSCR1_P2, SSSR_P2, SSITR_P2, SSTO_P2, SSPSP_P2);
136 return 0;
139 static int tsc2200_remove( struct device *dev )
141 printk("%s: closing tsc2200.\n", __FUNCTION__);
143 // nothing to do here
145 printk("%s: closing NSSP.\n", __FUNCTION__);
147 ssp_disable(&tsc2200_nssp_dev);
148 ssp_exit(&tsc2200_nssp_dev);
150 pxa_gpio_mode(GPIO81_NSCLK);
151 pxa_gpio_mode(GPIO82_NSFRM);
152 pxa_gpio_mode(GPIO83_NSTXD);
153 pxa_gpio_mode(GPIO84_NSRXD);
154 GPCR(GPIO82_NSFRM) = GPIO_bit(GPIO82_NSFRM |
155 GPIO82_NSFRM |
156 GPIO83_NSTXD |
157 GPIO84_NSRXD);
159 return 0;
162 struct device nssp_bus = {
163 .bus_id = "nssp_bus",
164 .release = nssp_bus_release,
166 EXPORT_SYMBOL( nssp_bus );
168 struct device_attribute nssp_dev_attrs[] = {
169 /* __ATTR_RO(resource),
170 __ATTR_RO(vendor),
171 __ATTR_RO(device),
172 __ATTR_RO(subsystem_vendor),
173 __ATTR_RO(subsystem_device),
174 __ATTR_RO(class),
175 __ATTR_RO(irq), */
176 __ATTR_NULL,
179 static struct bus_type nssp_bus_type = {
180 .name = "nssp",
181 .match = nssp_bus_match,
182 #if 0
183 #ifdef CONFIG_PM
184 .suspend = pci_device_suspend,
185 .resume = pci_device_resume,
186 #endif
187 #endif
188 .dev_attrs = nssp_dev_attrs,
190 EXPORT_SYMBOL( nssp_bus_type );
192 struct device_driver tsc2200_device_driver = {
193 .name = "tsc2200",
194 .bus = &nssp_bus_type,
195 .probe = tsc2200_probe,
196 .remove = tsc2200_remove,
197 #if 0 // def CONFIG_PM
198 .suspend = tsc2200_suspend,
199 .resume = tsc2200_resume,
200 .shutdown = tsc2200_shutdown,
201 #endif
203 EXPORT_SYMBOL( tsc2200_device_driver );
205 static int __init tsc2200_init(void)
207 printk("Register NSSP bus ... ");
209 if ( device_register(&nssp_bus) )
210 return 1;
211 if ( bus_register(&nssp_bus_type) )
212 return 1;
214 printk(" done.\n");
216 printk("%s: %X/%X.\n", __FUNCTION__, SSCR0_P2, SSCR0_SSE);
218 printk("Register TSC2200 driver ... ");
220 if ( driver_register (&tsc2200_device_driver) )
221 return 1;
223 printk(" done.\n");
225 printk("%s: %X/%X.\n", __FUNCTION__, SSCR0_P2, SSCR0_SSE);
226 return 0;
229 static void __exit tsc2200_exit (void)
231 printk("Unregister TSC2200 driver.\n");
233 driver_unregister (&tsc2200_device_driver);
235 printk("Unregister NSSP bus.\n");
237 bus_unregister(&nssp_bus_type);
238 device_unregister(&nssp_bus);
241 module_init(tsc2200_init)
242 module_exit(tsc2200_exit)
244 MODULE_AUTHOR("Matthias Burghardt");
245 MODULE_DESCRIPTION("TSC2200 driver for Himalaya");