blob: 0ee1df49606db3e33a03c76e0889dc7cc50907d0 [file] [log] [blame]
Dirk Opfer8459c152005-11-06 14:27:52 +00001/*
2 * Support for Sharp SL-C6000x PDAs
3 * Model: (Tosa)
4 *
5 * Copyright (c) 2005 Dirk Opfer
6 *
7 * Based on code written by Sharp/Lineo for 2.4 kernels
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 */
14
15#include <linux/kernel.h>
16#include <linux/init.h>
Dirk Opfer067c9042005-11-21 15:17:06 +000017#include <linux/platform_device.h>
Dirk Opfer8459c152005-11-06 14:27:52 +000018#include <linux/major.h>
19#include <linux/fs.h>
20#include <linux/interrupt.h>
Dmitry Baryshkovbf0116e2008-06-14 11:42:02 +010021#include <linux/delay.h>
22#include <linux/fb.h>
Dirk Opfer8459c152005-11-06 14:27:52 +000023#include <linux/mmc/host.h>
Dmitry Baryshkovbf0116e2008-06-14 11:42:02 +010024#include <linux/mfd/tc6393xb.h>
Dmitry Baryshkov5289fec2008-06-27 10:38:44 +010025#include <linux/mfd/tmio.h>
26#include <linux/mtd/nand.h>
27#include <linux/mtd/partitions.h>
Dmitry Baryshkovf34ee792008-11-25 00:57:27 +030028#include <linux/mtd/physmap.h>
Richard Purdie74617fb2006-06-19 19:57:12 +010029#include <linux/pm.h>
Dmitry Baryshkov93e90122008-01-21 01:04:20 -050030#include <linux/gpio_keys.h>
31#include <linux/input.h>
Dmitry Baryshkovd4e7d092008-04-12 20:16:16 +010032#include <linux/gpio.h>
Dmitry Baryshkov53b14ea2008-06-14 11:43:36 +010033#include <linux/pda_power.h>
Dmitry Baryshkov14b7b402008-09-13 21:06:41 +040034#include <linux/spi/spi.h>
Eric Miaof69a6542010-01-01 15:28:21 +080035#include <linux/input/matrix_keypad.h>
Dirk Opfer8459c152005-11-06 14:27:52 +000036
37#include <asm/setup.h>
Dirk Opfer8459c152005-11-06 14:27:52 +000038#include <asm/mach-types.h>
Eric Miao51c62982009-01-02 23:17:22 +080039
40#include <mach/pxa25x.h>
Russell Kingafd2fc02008-08-07 11:05:25 +010041#include <mach/reset.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010042#include <mach/irda.h>
Eric Miaof0a83702009-04-13 15:03:11 +080043#include <plat/i2c.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010044#include <mach/mmc.h>
45#include <mach/udc.h>
46#include <mach/tosa_bt.h>
Dmitry Baryshkov14b7b402008-09-13 21:06:41 +040047#include <mach/pxa2xx_spi.h>
Mark Brown80748fb2009-04-03 12:45:49 +010048#include <mach/audio.h>
Dirk Opfer8459c152005-11-06 14:27:52 +000049
50#include <asm/mach/arch.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010051#include <mach/tosa.h>
Dirk Opfer8459c152005-11-06 14:27:52 +000052
53#include <asm/hardware/scoop.h>
54#include <asm/mach/sharpsl_param.h>
55
56#include "generic.h"
Dmitry Baryshkov7bdb22c2008-09-10 10:30:37 +010057#include "clock.h"
Russell King46c41e62007-05-15 15:39:36 +010058#include "devices.h"
Dirk Opfer8459c152005-11-06 14:27:52 +000059
Dmitry Baryshkov2cb47342008-04-10 11:00:32 +010060static unsigned long tosa_pin_config[] = {
61 GPIO78_nCS_2, /* Scoop */
62 GPIO80_nCS_4, /* tg6393xb */
63 GPIO33_nCS_5, /* Scoop */
64
65 // GPIO76 CARD_VCC_ON1
66
67 GPIO19_GPIO, /* Reset out */
68 GPIO1_RST | WAKEUP_ON_EDGE_FALL,
69
70 GPIO0_GPIO | WAKEUP_ON_EDGE_FALL, /* WAKE_UP */
71 GPIO2_GPIO | WAKEUP_ON_EDGE_BOTH, /* AC_IN */
72 GPIO3_GPIO | WAKEUP_ON_EDGE_FALL, /* RECORD */
73 GPIO4_GPIO | WAKEUP_ON_EDGE_FALL, /* SYNC */
74 GPIO20_GPIO, /* EAR_IN */
75 GPIO22_GPIO, /* On */
76
77 GPIO5_GPIO, /* USB_IN */
78 GPIO32_GPIO, /* Pen IRQ */
79
80 GPIO7_GPIO, /* Jacket Detect */
81 GPIO14_GPIO, /* BAT0_CRG */
82 GPIO12_GPIO, /* BAT1_CRG */
83 GPIO17_GPIO, /* BAT0_LOW */
84 GPIO84_GPIO, /* BAT1_LOW */
85 GPIO38_GPIO, /* BAT_LOCK */
86
87 GPIO11_3_6MHz,
88 GPIO15_GPIO, /* TC6393XB IRQ */
89 GPIO18_RDY,
90 GPIO27_GPIO, /* LCD Sync */
91
92 /* MMC */
93 GPIO6_MMC_CLK,
94 GPIO8_MMC_CS0,
95 GPIO9_GPIO, /* Detect */
Dmitry Baryshkovc4d5f8d2008-06-09 13:23:50 +010096 GPIO10_GPIO, /* nSD_INT */
Dmitry Baryshkov2cb47342008-04-10 11:00:32 +010097
98 /* CF */
99 GPIO13_GPIO, /* CD_IRQ */
100 GPIO21_GPIO, /* Main Slot IRQ */
101 GPIO36_GPIO, /* Jacket Slot IRQ */
102 GPIO48_nPOE,
103 GPIO49_nPWE,
104 GPIO50_nPIOR,
105 GPIO51_nPIOW,
106 GPIO52_nPCE_1,
107 GPIO53_nPCE_2,
108 GPIO54_nPSKTSEL,
109 GPIO55_nPREG,
110 GPIO56_nPWAIT,
111 GPIO57_nIOIS16,
112
113 /* AC97 */
114 GPIO31_AC97_SYNC,
115 GPIO30_AC97_SDATA_OUT,
116 GPIO28_AC97_BITCLK,
117 GPIO29_AC97_SDATA_IN_0,
118 // GPIO79 nAUD_IRQ
119
120 /* FFUART */
121 GPIO34_FFUART_RXD,
122 GPIO35_FFUART_CTS,
123 GPIO37_FFUART_DSR,
124 GPIO39_FFUART_TXD,
125 GPIO40_FFUART_DTR,
126 GPIO41_FFUART_RTS,
127
128 /* BTUART */
129 GPIO42_BTUART_RXD,
130 GPIO43_BTUART_TXD,
131 GPIO44_BTUART_CTS,
132 GPIO45_BTUART_RTS,
133
Dmitry Baryshkov2cb47342008-04-10 11:00:32 +0100134 /* Keybd */
Eric Miaof69a6542010-01-01 15:28:21 +0800135 GPIO58_GPIO | MFP_LPM_DRIVE_LOW, /* Column 0 */
136 GPIO59_GPIO | MFP_LPM_DRIVE_LOW, /* Column 1 */
137 GPIO60_GPIO | MFP_LPM_DRIVE_LOW, /* Column 2 */
138 GPIO61_GPIO | MFP_LPM_DRIVE_LOW, /* Column 3 */
139 GPIO62_GPIO | MFP_LPM_DRIVE_LOW, /* Column 4 */
140 GPIO63_GPIO | MFP_LPM_DRIVE_LOW, /* Column 5 */
141 GPIO64_GPIO | MFP_LPM_DRIVE_LOW, /* Column 6 */
142 GPIO65_GPIO | MFP_LPM_DRIVE_LOW, /* Column 7 */
143 GPIO66_GPIO | MFP_LPM_DRIVE_LOW, /* Column 8 */
144 GPIO67_GPIO | MFP_LPM_DRIVE_LOW, /* Column 9 */
145 GPIO68_GPIO | MFP_LPM_DRIVE_LOW, /* Column 10 */
146 GPIO69_GPIO | MFP_LPM_DRIVE_LOW, /* Row 0 */
147 GPIO70_GPIO | MFP_LPM_DRIVE_LOW, /* Row 1 */
148 GPIO71_GPIO | MFP_LPM_DRIVE_LOW, /* Row 2 */
149 GPIO72_GPIO | MFP_LPM_DRIVE_LOW, /* Row 3 */
150 GPIO73_GPIO | MFP_LPM_DRIVE_LOW, /* Row 4 */
151 GPIO74_GPIO | MFP_LPM_DRIVE_LOW, /* Row 5 */
152 GPIO75_GPIO | MFP_LPM_DRIVE_LOW, /* Row 6 */
Dmitry Baryshkov2cb47342008-04-10 11:00:32 +0100153
154 /* SPI */
155 GPIO81_SSP2_CLK_OUT,
156 GPIO82_SSP2_FRM_OUT,
157 GPIO83_SSP2_TXD,
Dmitry Baryshkov2cb47342008-04-10 11:00:32 +0100158
Dmitry Baryshkov0fc3ff32008-07-02 13:54:46 +0100159 /* IrDA is managed in other way */
160 GPIO46_GPIO,
161 GPIO47_GPIO,
Dmitry Baryshkovb032fcc2008-06-12 11:42:07 +0100162};
163
Dirk Opfer8459c152005-11-06 14:27:52 +0000164/*
165 * SCOOP Device
166 */
167static struct resource tosa_scoop_resources[] = {
168 [0] = {
169 .start = TOSA_CF_PHYS,
170 .end = TOSA_CF_PHYS + 0xfff,
171 .flags = IORESOURCE_MEM,
172 },
173};
174
175static struct scoop_config tosa_scoop_setup = {
176 .io_dir = TOSA_SCOOP_IO_DIR,
Dmitry Baryshkovd4e7d092008-04-12 20:16:16 +0100177 .gpio_base = TOSA_SCOOP_GPIO_BASE,
Dirk Opfer8459c152005-11-06 14:27:52 +0000178};
179
Dmitry Baryshkovba4eb7e2008-04-19 10:42:25 +0100180static struct platform_device tosascoop_device = {
Dirk Opfer8459c152005-11-06 14:27:52 +0000181 .name = "sharp-scoop",
182 .id = 0,
183 .dev = {
184 .platform_data = &tosa_scoop_setup,
185 },
186 .num_resources = ARRAY_SIZE(tosa_scoop_resources),
187 .resource = tosa_scoop_resources,
188};
189
190
191/*
192 * SCOOP Device Jacket
193 */
194static struct resource tosa_scoop_jc_resources[] = {
195 [0] = {
196 .start = TOSA_SCOOP_PHYS + 0x40,
197 .end = TOSA_SCOOP_PHYS + 0xfff,
198 .flags = IORESOURCE_MEM,
199 },
200};
201
202static struct scoop_config tosa_scoop_jc_setup = {
203 .io_dir = TOSA_SCOOP_JC_IO_DIR,
Dmitry Baryshkovd4e7d092008-04-12 20:16:16 +0100204 .gpio_base = TOSA_SCOOP_JC_GPIO_BASE,
Dirk Opfer8459c152005-11-06 14:27:52 +0000205};
206
Dmitry Baryshkovba4eb7e2008-04-19 10:42:25 +0100207static struct platform_device tosascoop_jc_device = {
Dirk Opfer8459c152005-11-06 14:27:52 +0000208 .name = "sharp-scoop",
209 .id = 1,
210 .dev = {
211 .platform_data = &tosa_scoop_jc_setup,
212 .parent = &tosascoop_device.dev,
213 },
214 .num_resources = ARRAY_SIZE(tosa_scoop_jc_resources),
215 .resource = tosa_scoop_jc_resources,
216};
217
Dirk Opfer4c18ad22005-11-08 19:15:50 +0000218/*
219 * PCMCIA
220 */
Dirk Opfer8459c152005-11-06 14:27:52 +0000221static struct scoop_pcmcia_dev tosa_pcmcia_scoop[] = {
222{
223 .dev = &tosascoop_device.dev,
224 .irq = TOSA_IRQ_GPIO_CF_IRQ,
225 .cd_irq = TOSA_IRQ_GPIO_CF_CD,
226 .cd_irq_str = "PCMCIA0 CD",
227},{
228 .dev = &tosascoop_jc_device.dev,
229 .irq = TOSA_IRQ_GPIO_JC_CF_IRQ,
230 .cd_irq = -1,
231},
232};
233
Dirk Opfer4c18ad22005-11-08 19:15:50 +0000234static struct scoop_pcmcia_config tosa_pcmcia_config = {
235 .devs = &tosa_pcmcia_scoop[0],
236 .num_devs = 2,
Dirk Opfer4c18ad22005-11-08 19:15:50 +0000237};
238
Dirk Opfera93876c2005-11-08 19:15:30 +0000239/*
240 * USB Device Controller
241 */
Dirk Opfera93876c2005-11-08 19:15:30 +0000242static struct pxa2xx_udc_mach_info udc_info __initdata = {
Dmitry Baryshkovd4e7d092008-04-12 20:16:16 +0100243 .gpio_pullup = TOSA_GPIO_USB_PULLUP,
Dmitry Baryshkov487dc922007-12-21 12:18:01 +0300244 .gpio_vbus = TOSA_GPIO_USB_IN,
245 .gpio_vbus_inverted = 1,
Dirk Opfera93876c2005-11-08 19:15:30 +0000246};
247
248/*
249 * MMC/SD Device
250 */
David Howells40220c12006-10-09 12:19:47 +0100251static int tosa_mci_init(struct device *dev, irq_handler_t tosa_detect_int, void *data)
Dirk Opfera93876c2005-11-08 19:15:30 +0000252{
253 int err;
254
Dmitry Baryshkovc4d5f8d2008-06-09 13:23:50 +0100255 err = gpio_request(TOSA_GPIO_nSD_INT, "SD Int");
256 if (err) {
257 printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
258 goto err_gpio_int;
259 }
260 err = gpio_direction_input(TOSA_GPIO_nSD_INT);
261 if (err)
262 goto err_gpio_int_dir;
263
Dmitry Baryshkovd4e7d092008-04-12 20:16:16 +0100264 return 0;
265
Dmitry Baryshkovc4d5f8d2008-06-09 13:23:50 +0100266err_gpio_int_dir:
267 gpio_free(TOSA_GPIO_nSD_INT);
268err_gpio_int:
Russell King2687bd32008-01-23 14:05:58 +0000269 return err;
Dirk Opfera93876c2005-11-08 19:15:30 +0000270}
271
Dirk Opfera93876c2005-11-08 19:15:30 +0000272static void tosa_mci_exit(struct device *dev, void *data)
273{
Dmitry Baryshkovc4d5f8d2008-06-09 13:23:50 +0100274 gpio_free(TOSA_GPIO_nSD_INT);
Dirk Opfera93876c2005-11-08 19:15:30 +0000275}
276
277static struct pxamci_platform_data tosa_mci_platform_data = {
Eric Miaof97cab22010-04-14 07:00:42 +0800278 .detect_delay_ms = 250,
Robert Jarzmik7a648252009-07-06 22:16:42 +0200279 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
280 .init = tosa_mci_init,
281 .exit = tosa_mci_exit,
282 .gpio_card_detect = TOSA_GPIO_nSD_DETECT,
283 .gpio_card_ro = TOSA_GPIO_SD_WP,
284 .gpio_power = TOSA_GPIO_PWR_ON,
Dirk Opfera93876c2005-11-08 19:15:30 +0000285};
286
287/*
288 * Irda
289 */
Dmitry Baryshkovb032fcc2008-06-12 11:42:07 +0100290static void tosa_irda_transceiver_mode(struct device *dev, int mode)
291{
292 if (mode & IR_OFF) {
293 gpio_set_value(TOSA_GPIO_IR_POWERDWN, 0);
Dmitry Baryshkov0fc3ff32008-07-02 13:54:46 +0100294 pxa2xx_transceiver_mode(dev, mode);
Dmitry Baryshkovb032fcc2008-06-12 11:42:07 +0100295 gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
296 } else {
Dmitry Baryshkov0fc3ff32008-07-02 13:54:46 +0100297 pxa2xx_transceiver_mode(dev, mode);
Dmitry Baryshkovb032fcc2008-06-12 11:42:07 +0100298 gpio_set_value(TOSA_GPIO_IR_POWERDWN, 1);
299 }
300}
301
Dmitry Baryshkovd4e7d092008-04-12 20:16:16 +0100302static int tosa_irda_startup(struct device *dev)
303{
304 int ret;
305
Dmitry Baryshkovb032fcc2008-06-12 11:42:07 +0100306 ret = gpio_request(TOSA_GPIO_IRDA_TX, "IrDA TX");
307 if (ret)
308 goto err_tx;
309 ret = gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
310 if (ret)
311 goto err_tx_dir;
312
Dmitry Baryshkovd4e7d092008-04-12 20:16:16 +0100313 ret = gpio_request(TOSA_GPIO_IR_POWERDWN, "IrDA powerdown");
314 if (ret)
Dmitry Baryshkovb032fcc2008-06-12 11:42:07 +0100315 goto err_pwr;
Dmitry Baryshkovd4e7d092008-04-12 20:16:16 +0100316
317 ret = gpio_direction_output(TOSA_GPIO_IR_POWERDWN, 0);
318 if (ret)
Dmitry Baryshkovb032fcc2008-06-12 11:42:07 +0100319 goto err_pwr_dir;
Dmitry Baryshkovd4e7d092008-04-12 20:16:16 +0100320
Dmitry Baryshkovb032fcc2008-06-12 11:42:07 +0100321 tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
322
323 return 0;
324
325err_pwr_dir:
326 gpio_free(TOSA_GPIO_IR_POWERDWN);
327err_pwr:
328err_tx_dir:
329 gpio_free(TOSA_GPIO_IRDA_TX);
330err_tx:
Dmitry Baryshkovd4e7d092008-04-12 20:16:16 +0100331 return ret;
Dmitry Baryshkovb032fcc2008-06-12 11:42:07 +0100332}
Dmitry Baryshkovd4e7d092008-04-12 20:16:16 +0100333
334static void tosa_irda_shutdown(struct device *dev)
335{
Dmitry Baryshkovb032fcc2008-06-12 11:42:07 +0100336 tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
Dmitry Baryshkovd4e7d092008-04-12 20:16:16 +0100337 gpio_free(TOSA_GPIO_IR_POWERDWN);
Dmitry Baryshkovb032fcc2008-06-12 11:42:07 +0100338 gpio_free(TOSA_GPIO_IRDA_TX);
Dirk Opfera93876c2005-11-08 19:15:30 +0000339}
340
341static struct pxaficp_platform_data tosa_ficp_platform_data = {
Marek Vasutc4bd0172009-07-17 12:50:43 +0200342 .gpio_pwdown = -1,
343 .transceiver_cap = IR_SIRMODE | IR_OFF,
344 .transceiver_mode = tosa_irda_transceiver_mode,
345 .startup = tosa_irda_startup,
346 .shutdown = tosa_irda_shutdown,
Dirk Opfera93876c2005-11-08 19:15:30 +0000347};
348
349/*
Dmitry Baryshkov53b14ea2008-06-14 11:43:36 +0100350 * Tosa AC IN
351 */
352static int tosa_power_init(struct device *dev)
353{
354 int ret = gpio_request(TOSA_GPIO_AC_IN, "ac in");
355 if (ret)
356 goto err_gpio_req;
357
358 ret = gpio_direction_input(TOSA_GPIO_AC_IN);
359 if (ret)
360 goto err_gpio_in;
361
362 return 0;
363
364err_gpio_in:
365 gpio_free(TOSA_GPIO_AC_IN);
366err_gpio_req:
367 return ret;
368}
369
370static void tosa_power_exit(struct device *dev)
371{
372 gpio_free(TOSA_GPIO_AC_IN);
373}
374
375static int tosa_power_ac_online(void)
376{
377 return gpio_get_value(TOSA_GPIO_AC_IN) == 0;
378}
379
380static char *tosa_ac_supplied_to[] = {
381 "main-battery",
382 "backup-battery",
383 "jacket-battery",
384};
385
386static struct pda_power_pdata tosa_power_data = {
387 .init = tosa_power_init,
388 .is_ac_online = tosa_power_ac_online,
389 .exit = tosa_power_exit,
390 .supplied_to = tosa_ac_supplied_to,
391 .num_supplicants = ARRAY_SIZE(tosa_ac_supplied_to),
392};
393
394static struct resource tosa_power_resource[] = {
395 {
396 .name = "ac",
397 .start = gpio_to_irq(TOSA_GPIO_AC_IN),
398 .end = gpio_to_irq(TOSA_GPIO_AC_IN),
399 .flags = IORESOURCE_IRQ |
400 IORESOURCE_IRQ_HIGHEDGE |
401 IORESOURCE_IRQ_LOWEDGE,
402 },
403};
404
405static struct platform_device tosa_power_device = {
406 .name = "pda-power",
407 .id = -1,
408 .dev.platform_data = &tosa_power_data,
409 .resource = tosa_power_resource,
410 .num_resources = ARRAY_SIZE(tosa_power_resource),
411};
412
413/*
Dirk Opfera93876c2005-11-08 19:15:30 +0000414 * Tosa Keyboard
415 */
Eric Miaof69a6542010-01-01 15:28:21 +0800416static const uint32_t tosakbd_keymap[] = {
417 KEY(0, 2, KEY_W),
418 KEY(0, 6, KEY_K),
419 KEY(0, 7, KEY_BACKSPACE),
420 KEY(0, 8, KEY_P),
421 KEY(1, 1, KEY_Q),
422 KEY(1, 2, KEY_E),
423 KEY(1, 3, KEY_T),
424 KEY(1, 4, KEY_Y),
425 KEY(1, 6, KEY_O),
426 KEY(1, 7, KEY_I),
427 KEY(1, 8, KEY_COMMA),
428 KEY(2, 1, KEY_A),
429 KEY(2, 2, KEY_D),
430 KEY(2, 3, KEY_G),
431 KEY(2, 4, KEY_U),
432 KEY(2, 6, KEY_L),
433 KEY(2, 7, KEY_ENTER),
434 KEY(2, 8, KEY_DOT),
435 KEY(3, 1, KEY_Z),
436 KEY(3, 2, KEY_C),
437 KEY(3, 3, KEY_V),
438 KEY(3, 4, KEY_J),
439 KEY(3, 5, TOSA_KEY_ADDRESSBOOK),
440 KEY(3, 6, TOSA_KEY_CANCEL),
441 KEY(3, 7, TOSA_KEY_CENTER),
442 KEY(3, 8, TOSA_KEY_OK),
443 KEY(3, 9, KEY_LEFTSHIFT),
444 KEY(4, 1, KEY_S),
445 KEY(4, 2, KEY_R),
446 KEY(4, 3, KEY_B),
447 KEY(4, 4, KEY_N),
448 KEY(4, 5, TOSA_KEY_CALENDAR),
449 KEY(4, 6, TOSA_KEY_HOMEPAGE),
450 KEY(4, 7, KEY_LEFTCTRL),
451 KEY(4, 8, TOSA_KEY_LIGHT),
452 KEY(4, 10, KEY_RIGHTSHIFT),
453 KEY(5, 1, KEY_TAB),
454 KEY(5, 2, KEY_SLASH),
455 KEY(5, 3, KEY_H),
456 KEY(5, 4, KEY_M),
457 KEY(5, 5, TOSA_KEY_MENU),
458 KEY(5, 7, KEY_UP),
459 KEY(5, 11, TOSA_KEY_FN),
460 KEY(6, 1, KEY_X),
461 KEY(6, 2, KEY_F),
462 KEY(6, 3, KEY_SPACE),
463 KEY(6, 4, KEY_APOSTROPHE),
464 KEY(6, 5, TOSA_KEY_MAIL),
465 KEY(6, 6, KEY_LEFT),
466 KEY(6, 7, KEY_DOWN),
467 KEY(6, 8, KEY_RIGHT),
468};
469
470static struct matrix_keymap_data tosakbd_keymap_data = {
471 .keymap = tosakbd_keymap,
472 .keymap_size = ARRAY_SIZE(tosakbd_keymap),
473};
474
475static const int tosakbd_col_gpios[] =
476 { 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68 };
477static const int tosakbd_row_gpios[] =
478 { 69, 70, 71, 72, 73, 74, 75 };
479
480static struct matrix_keypad_platform_data tosakbd_pdata = {
481 .keymap_data = &tosakbd_keymap_data,
482 .row_gpios = tosakbd_row_gpios,
483 .col_gpios = tosakbd_col_gpios,
484 .num_row_gpios = ARRAY_SIZE(tosakbd_row_gpios),
485 .num_col_gpios = ARRAY_SIZE(tosakbd_col_gpios),
486 .col_scan_delay_us = 10,
487 .debounce_ms = 10,
488 .wakeup = 1,
489};
490
Dirk Opfera93876c2005-11-08 19:15:30 +0000491static struct platform_device tosakbd_device = {
Eric Miaof69a6542010-01-01 15:28:21 +0800492 .name = "matrix-keypad",
Dirk Opfera93876c2005-11-08 19:15:30 +0000493 .id = -1,
Eric Miaof69a6542010-01-01 15:28:21 +0800494 .dev = {
495 .platform_data = &tosakbd_pdata,
496 },
Dirk Opfera93876c2005-11-08 19:15:30 +0000497};
Dirk Opfer8459c152005-11-06 14:27:52 +0000498
Dmitry Baryshkov93e90122008-01-21 01:04:20 -0500499static struct gpio_keys_button tosa_gpio_keys[] = {
Dmitry Baryshkov0aa975612008-04-12 20:02:50 +0100500 /*
501 * Two following keys are directly tied to "ON" button of tosa. Why?
502 * The first one can be used as a wakeup source, the second can't;
503 * also the first one is OR of ac_powered and on_button.
504 */
505 {
506 .type = EV_PWR,
507 .code = KEY_RESERVED,
508 .gpio = TOSA_GPIO_POWERON,
509 .desc = "Poweron",
510 .wakeup = 1,
511 .active_low = 1,
512 },
Dmitry Baryshkov93e90122008-01-21 01:04:20 -0500513 {
514 .type = EV_PWR,
515 .code = KEY_SUSPEND,
516 .gpio = TOSA_GPIO_ON_KEY,
517 .desc = "On key",
Dmitry Baryshkov0aa975612008-04-12 20:02:50 +0100518 /*
519 * can't be used as wakeup
520 * .wakeup = 1,
521 */
Dmitry Baryshkov93e90122008-01-21 01:04:20 -0500522 .active_low = 1,
523 },
524 {
525 .type = EV_KEY,
526 .code = TOSA_KEY_RECORD,
527 .gpio = TOSA_GPIO_RECORD_BTN,
528 .desc = "Record Button",
529 .wakeup = 1,
530 .active_low = 1,
531 },
532 {
533 .type = EV_KEY,
534 .code = TOSA_KEY_SYNC,
535 .gpio = TOSA_GPIO_SYNC,
536 .desc = "Sync Button",
537 .wakeup = 1,
538 .active_low = 1,
539 },
Dmitry Baryshkovc33de472008-09-11 01:28:51 +0100540 {
541 .type = EV_SW,
542 .code = SW_HEADPHONE_INSERT,
543 .gpio = TOSA_GPIO_EAR_IN,
544 .desc = "HeadPhone insert",
545 .active_low = 1,
546 .debounce_interval = 300,
547 },
Dmitry Baryshkov93e90122008-01-21 01:04:20 -0500548};
549
550static struct gpio_keys_platform_data tosa_gpio_keys_platform_data = {
551 .buttons = tosa_gpio_keys,
552 .nbuttons = ARRAY_SIZE(tosa_gpio_keys),
553};
554
555static struct platform_device tosa_gpio_keys_device = {
556 .name = "gpio-keys",
557 .id = -1,
558 .dev = {
559 .platform_data = &tosa_gpio_keys_platform_data,
560 },
561};
562
Dirk Opfer6d0cf3e2006-03-31 02:31:12 -0800563/*
564 * Tosa LEDs
565 */
Dmitry Baryshkovba4eb7e2008-04-19 10:42:25 +0100566static struct gpio_led tosa_gpio_leds[] = {
Dmitry Baryshkov311c7362008-04-12 20:17:02 +0100567 {
568 .name = "tosa:amber:charge",
569 .default_trigger = "main-battery-charging",
570 .gpio = TOSA_GPIO_CHRG_ERR_LED,
571 },
572 {
573 .name = "tosa:green:mail",
574 .default_trigger = "nand-disk",
575 .gpio = TOSA_GPIO_NOTE_LED,
576 },
Dmitry Baryshkovc5461062008-04-19 10:42:06 +0100577 {
578 .name = "tosa:dual:wlan",
579 .default_trigger = "none",
580 .gpio = TOSA_GPIO_WLAN_LED,
581 },
582 {
583 .name = "tosa:blue:bluetooth",
Dmitry Baryshkov16b32fd2008-07-05 09:02:48 +0100584 .default_trigger = "tosa-bt",
Dmitry Baryshkovc5461062008-04-19 10:42:06 +0100585 .gpio = TOSA_GPIO_BT_LED,
586 },
Dmitry Baryshkov311c7362008-04-12 20:17:02 +0100587};
588
Dmitry Baryshkovba4eb7e2008-04-19 10:42:25 +0100589static struct gpio_led_platform_data tosa_gpio_leds_platform_data = {
Dmitry Baryshkov311c7362008-04-12 20:17:02 +0100590 .leds = tosa_gpio_leds,
591 .num_leds = ARRAY_SIZE(tosa_gpio_leds),
592};
593
Dirk Opfer6d0cf3e2006-03-31 02:31:12 -0800594static struct platform_device tosaled_device = {
Dmitry Baryshkov311c7362008-04-12 20:17:02 +0100595 .name = "leds-gpio",
596 .id = -1,
597 .dev = {
598 .platform_data = &tosa_gpio_leds_platform_data,
599 },
Dirk Opfer6d0cf3e2006-03-31 02:31:12 -0800600};
601
Dmitry Baryshkovbf0116e2008-06-14 11:42:02 +0100602/*
603 * Toshiba Mobile IO Controller
604 */
605static struct resource tc6393xb_resources[] = {
606 [0] = {
607 .start = TOSA_LCDC_PHYS,
608 .end = TOSA_LCDC_PHYS + 0x3ffffff,
609 .flags = IORESOURCE_MEM,
610 },
611
612 [1] = {
613 .start = TOSA_IRQ_GPIO_TC6393XB_INT,
614 .end = TOSA_IRQ_GPIO_TC6393XB_INT,
615 .flags = IORESOURCE_IRQ,
616 },
617};
618
619
620static int tosa_tc6393xb_enable(struct platform_device *dev)
621{
622 int rc;
623
624 rc = gpio_request(TOSA_GPIO_TC6393XB_REST_IN, "tc6393xb #pclr");
625 if (rc)
626 goto err_req_pclr;
627 rc = gpio_request(TOSA_GPIO_TC6393XB_SUSPEND, "tc6393xb #suspend");
628 if (rc)
629 goto err_req_suspend;
Dmitry Baryshkov14b7b402008-09-13 21:06:41 +0400630 rc = gpio_request(TOSA_GPIO_TC6393XB_L3V_ON, "tc6393xb l3v");
Dmitry Baryshkovbf0116e2008-06-14 11:42:02 +0100631 if (rc)
632 goto err_req_l3v;
633 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_L3V_ON, 0);
634 if (rc)
635 goto err_dir_l3v;
636 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_SUSPEND, 0);
637 if (rc)
638 goto err_dir_suspend;
639 rc = gpio_direction_output(TOSA_GPIO_TC6393XB_REST_IN, 0);
640 if (rc)
641 goto err_dir_pclr;
642
643 mdelay(1);
644
645 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 1);
646
647 mdelay(10);
648
649 gpio_set_value(TOSA_GPIO_TC6393XB_REST_IN, 1);
650 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 1);
651
652 return 0;
653err_dir_pclr:
654err_dir_suspend:
655err_dir_l3v:
656 gpio_free(TOSA_GPIO_TC6393XB_L3V_ON);
657err_req_l3v:
658 gpio_free(TOSA_GPIO_TC6393XB_SUSPEND);
659err_req_suspend:
660 gpio_free(TOSA_GPIO_TC6393XB_REST_IN);
661err_req_pclr:
662 return rc;
663}
664
665static int tosa_tc6393xb_disable(struct platform_device *dev)
666{
667 gpio_free(TOSA_GPIO_TC6393XB_L3V_ON);
668 gpio_free(TOSA_GPIO_TC6393XB_SUSPEND);
669 gpio_free(TOSA_GPIO_TC6393XB_REST_IN);
670
671 return 0;
672}
673
674static int tosa_tc6393xb_resume(struct platform_device *dev)
675{
676 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 1);
677 mdelay(10);
678 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 1);
679 mdelay(10);
680
681 return 0;
682}
683
684static int tosa_tc6393xb_suspend(struct platform_device *dev)
685{
686 gpio_set_value(TOSA_GPIO_TC6393XB_L3V_ON, 0);
687 gpio_set_value(TOSA_GPIO_TC6393XB_SUSPEND, 0);
688 return 0;
689}
690
Dmitry Baryshkov5289fec2008-06-27 10:38:44 +0100691static struct mtd_partition tosa_nand_partition[] = {
692 {
693 .name = "smf",
694 .offset = 0,
695 .size = 7 * 1024 * 1024,
696 },
697 {
698 .name = "root",
699 .offset = MTDPART_OFS_APPEND,
700 .size = 28 * 1024 * 1024,
701 },
702 {
703 .name = "home",
704 .offset = MTDPART_OFS_APPEND,
705 .size = MTDPART_SIZ_FULL,
706 },
707};
708
709static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
710
711static struct nand_bbt_descr tosa_tc6393xb_nand_bbt = {
712 .options = 0,
713 .offs = 4,
714 .len = 2,
715 .pattern = scan_ff_pattern
716};
717
718static struct tmio_nand_data tosa_tc6393xb_nand_config = {
719 .num_partitions = ARRAY_SIZE(tosa_nand_partition),
720 .partition = tosa_nand_partition,
721 .badblock_pattern = &tosa_tc6393xb_nand_bbt,
722};
723
Dmitry Baryshkov1c1b6ff2008-09-24 23:36:23 +0200724static int tosa_tc6393xb_setup(struct platform_device *dev)
725{
726 int rc;
727
728 rc = gpio_request(TOSA_GPIO_CARD_VCC_ON, "CARD_VCC_ON");
729 if (rc)
730 goto err_req;
731
732 rc = gpio_direction_output(TOSA_GPIO_CARD_VCC_ON, 1);
733 if (rc)
734 goto err_dir;
735
736 return rc;
737
738err_dir:
739 gpio_free(TOSA_GPIO_CARD_VCC_ON);
740err_req:
741 return rc;
742}
743
744static void tosa_tc6393xb_teardown(struct platform_device *dev)
745{
746 gpio_free(TOSA_GPIO_CARD_VCC_ON);
747}
748
Dmitry Baryshkovddfb33c2008-11-27 01:25:09 +0300749#ifdef CONFIG_MFD_TC6393XB
Dmitry Baryshkov31c9b282008-10-28 18:40:37 +0300750static struct fb_videomode tosa_tc6393xb_lcd_mode[] = {
751 {
752 .xres = 480,
753 .yres = 640,
754 .pixclock = 0x002cdf00,/* PLL divisor */
755 .left_margin = 0x004c,
756 .right_margin = 0x005b,
757 .upper_margin = 0x0001,
758 .lower_margin = 0x000d,
759 .hsync_len = 0x0002,
760 .vsync_len = 0x0001,
761 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
762 .vmode = FB_VMODE_NONINTERLACED,
763 },{
764 .xres = 240,
765 .yres = 320,
766 .pixclock = 0x00e7f203,/* PLL divisor */
767 .left_margin = 0x0024,
768 .right_margin = 0x002f,
769 .upper_margin = 0x0001,
770 .lower_margin = 0x000d,
771 .hsync_len = 0x0002,
772 .vsync_len = 0x0001,
773 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
774 .vmode = FB_VMODE_NONINTERLACED,
775 }
776};
777
778static struct tmio_fb_data tosa_tc6393xb_fb_config = {
779 .lcd_set_power = tc6393xb_lcd_set_power,
780 .lcd_mode = tc6393xb_lcd_mode,
781 .num_modes = ARRAY_SIZE(tosa_tc6393xb_lcd_mode),
782 .modes = &tosa_tc6393xb_lcd_mode[0],
783 .height = 82,
784 .width = 60,
785};
Dmitry Baryshkovddfb33c2008-11-27 01:25:09 +0300786#endif
Dmitry Baryshkov31c9b282008-10-28 18:40:37 +0300787
Dmitry Baryshkov1c1b6ff2008-09-24 23:36:23 +0200788static struct tc6393xb_platform_data tosa_tc6393xb_data = {
Dmitry Baryshkovbf0116e2008-06-14 11:42:02 +0100789 .scr_pll2cr = 0x0cc1,
790 .scr_gper = 0x3300,
Dmitry Baryshkovbf0116e2008-06-14 11:42:02 +0100791
792 .irq_base = IRQ_BOARD_START,
793 .gpio_base = TOSA_TC6393XB_GPIO_BASE,
Dmitry Baryshkov1c1b6ff2008-09-24 23:36:23 +0200794 .setup = tosa_tc6393xb_setup,
795 .teardown = tosa_tc6393xb_teardown,
Dmitry Baryshkovbf0116e2008-06-14 11:42:02 +0100796
797 .enable = tosa_tc6393xb_enable,
798 .disable = tosa_tc6393xb_disable,
799 .suspend = tosa_tc6393xb_suspend,
800 .resume = tosa_tc6393xb_resume,
Dmitry Baryshkov5289fec2008-06-27 10:38:44 +0100801
802 .nand_data = &tosa_tc6393xb_nand_config,
Dmitry Baryshkovddfb33c2008-11-27 01:25:09 +0300803#ifdef CONFIG_MFD_TC6393XB
Dmitry Baryshkov31c9b282008-10-28 18:40:37 +0300804 .fb_data = &tosa_tc6393xb_fb_config,
Dmitry Baryshkovddfb33c2008-11-27 01:25:09 +0300805#endif
Dmitry Baryshkovf98a0bd2008-09-24 23:46:10 +0200806
807 .resume_restore = 1,
Dmitry Baryshkovbf0116e2008-06-14 11:42:02 +0100808};
809
810
811static struct platform_device tc6393xb_device = {
812 .name = "tc6393xb",
813 .id = -1,
814 .dev = {
Dmitry Baryshkov1c1b6ff2008-09-24 23:36:23 +0200815 .platform_data = &tosa_tc6393xb_data,
Dmitry Baryshkovbf0116e2008-06-14 11:42:02 +0100816 },
817 .num_resources = ARRAY_SIZE(tc6393xb_resources),
818 .resource = tc6393xb_resources,
819};
820
Dmitry Baryshkov16b32fd2008-07-05 09:02:48 +0100821static struct tosa_bt_data tosa_bt_data = {
822 .gpio_pwr = TOSA_GPIO_BT_PWR_EN,
823 .gpio_reset = TOSA_GPIO_BT_RESET,
824};
825
826static struct platform_device tosa_bt_device = {
827 .name = "tosa-bt",
828 .id = -1,
829 .dev.platform_data = &tosa_bt_data,
830};
831
Dmitry Baryshkov14b7b402008-09-13 21:06:41 +0400832static struct pxa2xx_spi_master pxa_ssp_master_info = {
833 .num_chipselect = 1,
834};
835
836static struct spi_board_info spi_board_info[] __initdata = {
837 {
838 .modalias = "tosa-lcd",
839 // .platform_data
840 .max_speed_hz = 28750,
841 .bus_num = 2,
842 .chip_select = 0,
843 .mode = SPI_MODE_0,
844 },
845};
Dmitry Baryshkov16b32fd2008-07-05 09:02:48 +0100846
Dmitry Baryshkovf34ee792008-11-25 00:57:27 +0300847static struct mtd_partition sharpsl_rom_parts[] = {
848 {
849 .name ="Boot PROM Filesystem",
850 .offset = 0x00160000,
851 .size = MTDPART_SIZ_FULL,
852 },
853};
854
855static struct physmap_flash_data sharpsl_rom_data = {
856 .width = 2,
857 .nr_parts = ARRAY_SIZE(sharpsl_rom_parts),
858 .parts = sharpsl_rom_parts,
859};
860
861static struct resource sharpsl_rom_resources[] = {
862 {
863 .start = 0x00000000,
864 .end = 0x007fffff,
865 .flags = IORESOURCE_MEM,
866 },
867};
868
869static struct platform_device sharpsl_rom_device = {
870 .name = "physmap-flash",
871 .id = -1,
872 .resource = sharpsl_rom_resources,
873 .num_resources = ARRAY_SIZE(sharpsl_rom_resources),
874 .dev.platform_data = &sharpsl_rom_data,
875};
876
Dirk Opfer8459c152005-11-06 14:27:52 +0000877static struct platform_device *devices[] __initdata = {
878 &tosascoop_device,
879 &tosascoop_jc_device,
Dmitry Baryshkovbf0116e2008-06-14 11:42:02 +0100880 &tc6393xb_device,
Dmitry Baryshkov53b14ea2008-06-14 11:43:36 +0100881 &tosa_power_device,
Dirk Opfera93876c2005-11-08 19:15:30 +0000882 &tosakbd_device,
Dmitry Baryshkov93e90122008-01-21 01:04:20 -0500883 &tosa_gpio_keys_device,
Dirk Opfer6d0cf3e2006-03-31 02:31:12 -0800884 &tosaled_device,
Dmitry Baryshkov16b32fd2008-07-05 09:02:48 +0100885 &tosa_bt_device,
Dmitry Baryshkovf34ee792008-11-25 00:57:27 +0300886 &sharpsl_rom_device,
Dirk Opfer8459c152005-11-06 14:27:52 +0000887};
888
Richard Purdie74617fb2006-06-19 19:57:12 +0100889static void tosa_poweroff(void)
890{
Russell Kingbe093be2009-03-19 16:20:24 +0000891 arm_machine_restart('g', NULL);
Richard Purdie74617fb2006-06-19 19:57:12 +0100892}
893
Russell Kingbe093be2009-03-19 16:20:24 +0000894static void tosa_restart(char mode, const char *cmd)
Richard Purdie74617fb2006-06-19 19:57:12 +0100895{
896 /* Bootloader magic for a reboot */
897 if((MSC0 & 0xffff0000) == 0x7ff00000)
898 MSC0 = (MSC0 & 0xffff) | 0x7ee00000;
899
900 tosa_poweroff();
901}
902
Dirk Opfer8459c152005-11-06 14:27:52 +0000903static void __init tosa_init(void)
904{
Dmitry Baryshkovbf0116e2008-06-14 11:42:02 +0100905 int dummy;
906
Dmitry Baryshkov2cb47342008-04-10 11:00:32 +0100907 pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_config));
Russell Kingcc155c62009-11-09 13:34:08 +0800908
909 pxa_set_ffuart_info(NULL);
910 pxa_set_btuart_info(NULL);
911 pxa_set_stuart_info(NULL);
912
Dmitry Baryshkov2cb47342008-04-10 11:00:32 +0100913 gpio_set_wake(MFP_PIN_GPIO1, 1);
914 /* We can't pass to gpio-keys since it will drop the Reset altfunc */
915
Daniel Ribeiro216e3b72009-05-05 22:43:18 -0300916 init_gpio_reset(TOSA_GPIO_ON_RESET, 0, 0);
Dmitry Baryshkov86159a92008-05-22 16:21:48 +0100917
Richard Purdie74617fb2006-06-19 19:57:12 +0100918 pm_power_off = tosa_poweroff;
919 arm_pm_restart = tosa_restart;
920
Dirk Opfer8459c152005-11-06 14:27:52 +0000921 PCFR |= PCFR_OPDE;
922
Dirk Opfera93876c2005-11-08 19:15:30 +0000923 /* enable batt_fault */
Dirk Opfer8459c152005-11-06 14:27:52 +0000924 PMCR = 0x01;
925
Dmitry Baryshkovbf0116e2008-06-14 11:42:02 +0100926 dummy = gpiochip_reserve(TOSA_SCOOP_GPIO_BASE, 12);
927 dummy = gpiochip_reserve(TOSA_SCOOP_JC_GPIO_BASE, 12);
928 dummy = gpiochip_reserve(TOSA_TC6393XB_GPIO_BASE, 16);
929
Dirk Opfera93876c2005-11-08 19:15:30 +0000930 pxa_set_mci_info(&tosa_mci_platform_data);
931 pxa_set_udc_info(&udc_info);
932 pxa_set_ficp_info(&tosa_ficp_platform_data);
Dmitry Baryshkov481ea5a2008-04-10 15:43:18 +0100933 pxa_set_i2c_info(NULL);
Mark Brown80748fb2009-04-03 12:45:49 +0100934 pxa_set_ac97_info(NULL);
Dirk Opfer4c18ad22005-11-08 19:15:50 +0000935 platform_scoop_config = &tosa_pcmcia_config;
Dirk Opfer8459c152005-11-06 14:27:52 +0000936
Dmitry Baryshkov14b7b402008-09-13 21:06:41 +0400937 pxa2xx_set_spi_info(2, &pxa_ssp_master_info);
938 spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
939
Dmitry Eremin-Solenikovc68ffdd2009-03-05 18:17:53 +0300940 clk_add_alias("CLK_CK3P6MI", tc6393xb_device.name, "GPIO11_CLK", NULL);
Dmitry Baryshkov7bdb22c2008-09-10 10:30:37 +0100941
Dirk Opfer4c18ad22005-11-08 19:15:50 +0000942 platform_add_devices(devices, ARRAY_SIZE(devices));
Dirk Opfer8459c152005-11-06 14:27:52 +0000943}
944
945static void __init fixup_tosa(struct machine_desc *desc,
946 struct tag *tags, char **cmdline, struct meminfo *mi)
947{
948 sharpsl_save_param();
949 mi->nr_banks=1;
950 mi->bank[0].start = 0xa0000000;
Dirk Opfer8459c152005-11-06 14:27:52 +0000951 mi->bank[0].size = (64*1024*1024);
952}
953
954MACHINE_START(TOSA, "SHARP Tosa")
Dirk Opfer8459c152005-11-06 14:27:52 +0000955 .fixup = fixup_tosa,
956 .map_io = pxa_map_io,
Haojian Zhuang6ac6b812010-08-20 15:23:59 +0800957 .nr_irqs = TOSA_NR_IRQS,
Eric Miaocd491042007-06-22 04:14:09 +0100958 .init_irq = pxa25x_init_irq,
Dirk Opfer8459c152005-11-06 14:27:52 +0000959 .init_machine = tosa_init,
960 .timer = &pxa_timer,
961MACHINE_END