[ARM] pxa/poodle: use SPI based ads7846 touch screen driver
[safe/jmp/linux-2.6] / arch / arm / mach-pxa / poodle.c
1 /*
2  * linux/arch/arm/mach-pxa/poodle.c
3  *
4  *  Support for the SHARP Poodle Board.
5  *
6  * Based on:
7  *  linux/arch/arm/mach-pxa/lubbock.c Author:   Nicolas Pitre
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License version 2 as
11  *  published by the Free Software Foundation.
12  *
13  * Change Log
14  *  12-Dec-2002 Sharp Corporation for Poodle
15  *  John Lenz <lenz@cs.wisc.edu> updates to 2.6
16  */
17 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <linux/platform_device.h>
20 #include <linux/fb.h>
21 #include <linux/pm.h>
22 #include <linux/delay.h>
23 #include <linux/gpio.h>
24 #include <linux/spi/spi.h>
25 #include <linux/spi/ads7846.h>
26
27 #include <mach/hardware.h>
28 #include <asm/mach-types.h>
29 #include <asm/irq.h>
30 #include <asm/setup.h>
31 #include <asm/system.h>
32
33 #include <asm/mach/arch.h>
34 #include <asm/mach/map.h>
35 #include <asm/mach/irq.h>
36
37 #include <mach/pxa-regs.h>
38 #include <mach/pxa2xx-regs.h>
39 #include <mach/mfp-pxa25x.h>
40 #include <mach/mmc.h>
41 #include <mach/udc.h>
42 #include <mach/i2c.h>
43 #include <mach/irda.h>
44 #include <mach/poodle.h>
45 #include <mach/pxafb.h>
46 #include <mach/sharpsl.h>
47 #include <mach/ssp.h>
48 #include <mach/pxa2xx_spi.h>
49
50 #include <asm/hardware/scoop.h>
51 #include <asm/hardware/locomo.h>
52 #include <asm/mach/sharpsl_param.h>
53
54 #include "generic.h"
55 #include "devices.h"
56 #include "sharpsl.h"
57
58 static unsigned long poodle_pin_config[] __initdata = {
59         /* I/O */
60         GPIO79_nCS_3,
61         GPIO80_nCS_4,
62         GPIO18_RDY,
63
64         /* Clock */
65         GPIO12_32KHz,
66
67         /* SSP1 */
68         GPIO23_SSP1_SCLK,
69         GPIO25_SSP1_TXD,
70         GPIO26_SSP1_RXD,
71         GPIO24_GPIO,    /* POODLE_GPIO_TP_CS - SFRM as chip select */
72
73         /* I2S */
74         GPIO28_I2S_BITCLK_OUT,
75         GPIO29_I2S_SDATA_IN,
76         GPIO30_I2S_SDATA_OUT,
77         GPIO31_I2S_SYNC,
78         GPIO32_I2S_SYSCLK,
79
80         /* Infra-Red */
81         GPIO47_FICP_TXD,
82         GPIO46_FICP_RXD,
83
84         /* FFUART */
85         GPIO40_FFUART_DTR,
86         GPIO41_FFUART_RTS,
87         GPIO39_FFUART_TXD,
88         GPIO37_FFUART_DSR,
89         GPIO34_FFUART_RXD,
90         GPIO35_FFUART_CTS,
91
92         /* LCD */
93         GPIO58_LCD_LDD_0,
94         GPIO59_LCD_LDD_1,
95         GPIO60_LCD_LDD_2,
96         GPIO61_LCD_LDD_3,
97         GPIO62_LCD_LDD_4,
98         GPIO63_LCD_LDD_5,
99         GPIO64_LCD_LDD_6,
100         GPIO65_LCD_LDD_7,
101         GPIO66_LCD_LDD_8,
102         GPIO67_LCD_LDD_9,
103         GPIO68_LCD_LDD_10,
104         GPIO69_LCD_LDD_11,
105         GPIO70_LCD_LDD_12,
106         GPIO71_LCD_LDD_13,
107         GPIO72_LCD_LDD_14,
108         GPIO73_LCD_LDD_15,
109         GPIO74_LCD_FCLK,
110         GPIO75_LCD_LCLK,
111         GPIO76_LCD_PCLK,
112         GPIO77_LCD_ACBIAS,
113
114         /* PC Card */
115         GPIO48_nPOE,
116         GPIO49_nPWE,
117         GPIO50_nPIOR,
118         GPIO51_nPIOW,
119         GPIO52_nPCE_1,
120         GPIO53_nPCE_2,
121         GPIO54_nPSKTSEL,
122         GPIO55_nPREG,
123         GPIO56_nPWAIT,
124         GPIO57_nIOIS16,
125
126         /* MMC */
127         GPIO6_MMC_CLK,
128         GPIO8_MMC_CS0,
129
130         /* GPIO */
131         GPIO9_GPIO,     /* POODLE_GPIO_nSD_DETECT */
132         GPIO7_GPIO,     /* POODLE_GPIO_nSD_WP */
133         GPIO3_GPIO,     /* POODLE_GPIO_SD_PWR */
134         GPIO33_GPIO,    /* POODLE_GPIO_SD_PWR1 */
135
136         GPIO20_GPIO,    /* POODLE_GPIO_USB_PULLUP */
137         GPIO22_GPIO,    /* POODLE_GPIO_IR_ON */
138 };
139
140 static struct resource poodle_scoop_resources[] = {
141         [0] = {
142                 .start          = 0x10800000,
143                 .end            = 0x10800fff,
144                 .flags          = IORESOURCE_MEM,
145         },
146 };
147
148 static struct scoop_config poodle_scoop_setup = {
149         .io_dir         = POODLE_SCOOP_IO_DIR,
150         .io_out         = POODLE_SCOOP_IO_OUT,
151 };
152
153 struct platform_device poodle_scoop_device = {
154         .name           = "sharp-scoop",
155         .id             = -1,
156         .dev            = {
157                 .platform_data  = &poodle_scoop_setup,
158         },
159         .num_resources  = ARRAY_SIZE(poodle_scoop_resources),
160         .resource       = poodle_scoop_resources,
161 };
162
163 static struct scoop_pcmcia_dev poodle_pcmcia_scoop[] = {
164 {
165         .dev        = &poodle_scoop_device.dev,
166         .irq        = POODLE_IRQ_GPIO_CF_IRQ,
167         .cd_irq     = POODLE_IRQ_GPIO_CF_CD,
168         .cd_irq_str = "PCMCIA0 CD",
169 },
170 };
171
172 static struct scoop_pcmcia_config poodle_pcmcia_config = {
173         .devs         = &poodle_pcmcia_scoop[0],
174         .num_devs     = 1,
175 };
176
177 EXPORT_SYMBOL(poodle_scoop_device);
178
179
180 /* LoCoMo device */
181 static struct resource locomo_resources[] = {
182         [0] = {
183                 .start          = 0x10000000,
184                 .end            = 0x10001fff,
185                 .flags          = IORESOURCE_MEM,
186         },
187         [1] = {
188                 .start          = IRQ_GPIO(10),
189                 .end            = IRQ_GPIO(10),
190                 .flags          = IORESOURCE_IRQ,
191         },
192 };
193
194 struct platform_device poodle_locomo_device = {
195         .name           = "locomo",
196         .id             = 0,
197         .num_resources  = ARRAY_SIZE(locomo_resources),
198         .resource       = locomo_resources,
199 };
200
201 EXPORT_SYMBOL(poodle_locomo_device);
202
203 #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
204 static struct pxa2xx_spi_master poodle_spi_info = {
205         .num_chipselect = 1,
206 };
207
208 static struct ads7846_platform_data poodle_ads7846_info = {
209         .model                  = 7846,
210         .vref_delay_usecs       = 100,
211         .x_plate_ohms           = 419,
212         .y_plate_ohms           = 486,
213         .gpio_pendown           = POODLE_GPIO_TP_INT,
214 };
215
216 static void ads7846_cs(u32 command)
217 {
218         gpio_set_value(POODLE_GPIO_TP_CS, !(command == PXA2XX_CS_ASSERT));
219 }
220
221 static struct pxa2xx_spi_chip poodle_ads7846_chip = {
222         .cs_control             = ads7846_cs,
223 };
224
225 static struct spi_board_info poodle_spi_devices[] = {
226         {
227                 .modalias       = "ads7846",
228                 .max_speed_hz   = 10000,
229                 .bus_num        = 1,
230                 .platform_data  = &poodle_ads7846_info,
231                 .controller_data= &poodle_ads7846_chip,
232                 .irq            = gpio_to_irq(POODLE_GPIO_TP_INT),
233         },
234 };
235
236 static void __init poodle_init_spi(void)
237 {
238         int err;
239
240         err = gpio_request(POODLE_GPIO_TP_CS, "ADS7846_CS");
241         if (err)
242                 return;
243
244         gpio_direction_output(POODLE_GPIO_TP_CS, 1);
245
246         pxa2xx_set_spi_info(1, &poodle_spi_info);
247         spi_register_board_info(ARRAY_AND_SIZE(poodle_spi_devices));
248 }
249 #else
250 static inline void poodle_init_spi(void) {}
251 #endif
252
253 /*
254  * MMC/SD Device
255  *
256  * The card detect interrupt isn't debounced so we delay it by 250ms
257  * to give the card a chance to fully insert/eject.
258  */
259 static struct pxamci_platform_data poodle_mci_platform_data;
260
261 static int poodle_mci_init(struct device *dev, irq_handler_t poodle_detect_int, void *data)
262 {
263         int err;
264
265         err = gpio_request(POODLE_GPIO_nSD_DETECT, "nSD_DETECT");
266         if (err)
267                 goto err_out;
268
269         err = gpio_request(POODLE_GPIO_nSD_WP, "nSD_WP");
270         if (err)
271                 goto err_free_1;
272
273         err = gpio_request(POODLE_GPIO_SD_PWR, "SD_PWR");
274         if (err)
275                 goto err_free_2;
276
277         err = gpio_request(POODLE_GPIO_SD_PWR1, "SD_PWR1");
278         if (err)
279                 goto err_free_3;
280
281         gpio_direction_input(POODLE_GPIO_nSD_DETECT);
282         gpio_direction_input(POODLE_GPIO_nSD_WP);
283
284         gpio_direction_output(POODLE_GPIO_SD_PWR, 0);
285         gpio_direction_output(POODLE_GPIO_SD_PWR1, 0);
286
287         poodle_mci_platform_data.detect_delay = msecs_to_jiffies(250);
288
289         err = request_irq(POODLE_IRQ_GPIO_nSD_DETECT, poodle_detect_int,
290                           IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
291                           "MMC card detect", data);
292         if (err) {
293                 pr_err("%s: MMC/SD: can't request MMC card detect IRQ\n",
294                                 __func__);
295                 goto err_free_4;
296         }
297
298         return 0;
299
300 err_free_4:
301         gpio_free(POODLE_GPIO_SD_PWR1);
302 err_free_3:
303         gpio_free(POODLE_GPIO_SD_PWR);
304 err_free_2:
305         gpio_free(POODLE_GPIO_nSD_WP);
306 err_free_1:
307         gpio_free(POODLE_GPIO_nSD_DETECT);
308 err_out:
309         return err;
310 }
311
312 static void poodle_mci_setpower(struct device *dev, unsigned int vdd)
313 {
314         struct pxamci_platform_data* p_d = dev->platform_data;
315
316         if ((1 << vdd) & p_d->ocr_mask) {
317                 gpio_set_value(POODLE_GPIO_SD_PWR, 1);
318                 mdelay(2);
319                 gpio_set_value(POODLE_GPIO_SD_PWR1, 1);
320         } else {
321                 gpio_set_value(POODLE_GPIO_SD_PWR1, 0);
322                 gpio_set_value(POODLE_GPIO_SD_PWR, 0);
323         }
324 }
325
326 static int poodle_mci_get_ro(struct device *dev)
327 {
328         return !!gpio_get_value(POODLE_GPIO_nSD_WP);
329         return GPLR(POODLE_GPIO_nSD_WP) & GPIO_bit(POODLE_GPIO_nSD_WP);
330 }
331
332
333 static void poodle_mci_exit(struct device *dev, void *data)
334 {
335         free_irq(POODLE_IRQ_GPIO_nSD_DETECT, data);
336         gpio_free(POODLE_GPIO_SD_PWR1);
337         gpio_free(POODLE_GPIO_SD_PWR);
338         gpio_free(POODLE_GPIO_nSD_WP);
339         gpio_free(POODLE_GPIO_nSD_DETECT);
340 }
341
342 static struct pxamci_platform_data poodle_mci_platform_data = {
343         .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
344         .init           = poodle_mci_init,
345         .get_ro         = poodle_mci_get_ro,
346         .setpower       = poodle_mci_setpower,
347         .exit           = poodle_mci_exit,
348 };
349
350
351 /*
352  * Irda
353  */
354 static void poodle_irda_transceiver_mode(struct device *dev, int mode)
355 {
356         gpio_set_value(POODLE_GPIO_IR_ON, mode & IR_OFF);
357         pxa2xx_transceiver_mode(dev, mode);
358 }
359
360 static int poodle_irda_startup(struct device *dev)
361 {
362         int err;
363
364         err = gpio_request(POODLE_GPIO_IR_ON, "IR_ON");
365         if (err)
366                 return err;
367
368         gpio_direction_output(POODLE_GPIO_IR_ON, 1);
369         return 0;
370 }
371
372 static void poodle_irda_shutdown(struct device *dev)
373 {
374         gpio_free(POODLE_GPIO_IR_ON);
375 }
376
377 static struct pxaficp_platform_data poodle_ficp_platform_data = {
378         .transceiver_cap        = IR_SIRMODE | IR_OFF,
379         .transceiver_mode       = poodle_irda_transceiver_mode,
380         .startup                = poodle_irda_startup,
381         .shutdown               = poodle_irda_shutdown,
382 };
383
384
385 /*
386  * USB Device Controller
387  */
388 static struct pxa2xx_udc_mach_info udc_info __initdata = {
389         /* no connect GPIO; poodle can't tell connection status */
390         .gpio_pullup    = POODLE_GPIO_USB_PULLUP,
391 };
392
393
394 /* PXAFB device */
395 static struct pxafb_mode_info poodle_fb_mode = {
396         .pixclock       = 144700,
397         .xres           = 320,
398         .yres           = 240,
399         .bpp            = 16,
400         .hsync_len      = 7,
401         .left_margin    = 11,
402         .right_margin   = 30,
403         .vsync_len      = 2,
404         .upper_margin   = 2,
405         .lower_margin   = 0,
406         .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
407 };
408
409 static struct pxafb_mach_info poodle_fb_info = {
410         .modes          = &poodle_fb_mode,
411         .num_modes      = 1,
412         .lcd_conn       = LCD_COLOR_TFT_16BPP,
413 };
414
415 static struct platform_device *devices[] __initdata = {
416         &poodle_locomo_device,
417         &poodle_scoop_device,
418 };
419
420 static void poodle_poweroff(void)
421 {
422         arm_machine_restart('h');
423 }
424
425 static void poodle_restart(char mode)
426 {
427         arm_machine_restart('h');
428 }
429
430 static void __init poodle_init(void)
431 {
432         int ret = 0;
433
434         pm_power_off = poodle_poweroff;
435         arm_pm_restart = poodle_restart;
436
437         PCFR |= PCFR_OPDE;
438
439         pxa2xx_mfp_config(ARRAY_AND_SIZE(poodle_pin_config));
440
441         platform_scoop_config = &poodle_pcmcia_config;
442
443         ret = platform_add_devices(devices, ARRAY_SIZE(devices));
444         if (ret)
445                 pr_warning("poodle: Unable to register LoCoMo device\n");
446
447         set_pxa_fb_parent(&poodle_locomo_device.dev);
448         set_pxa_fb_info(&poodle_fb_info);
449         pxa_set_udc_info(&udc_info);
450         pxa_set_mci_info(&poodle_mci_platform_data);
451         pxa_set_ficp_info(&poodle_ficp_platform_data);
452         pxa_set_i2c_info(NULL);
453         poodle_init_spi();
454 }
455
456 static void __init fixup_poodle(struct machine_desc *desc,
457                 struct tag *tags, char **cmdline, struct meminfo *mi)
458 {
459         sharpsl_save_param();
460         mi->nr_banks=1;
461         mi->bank[0].start = 0xa0000000;
462         mi->bank[0].node = 0;
463         mi->bank[0].size = (32*1024*1024);
464 }
465
466 MACHINE_START(POODLE, "SHARP Poodle")
467         .phys_io        = 0x40000000,
468         .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
469         .fixup          = fixup_poodle,
470         .map_io         = pxa_map_io,
471         .init_irq       = pxa25x_init_irq,
472         .timer          = &pxa_timer,
473         .init_machine   = poodle_init,
474 MACHINE_END