tosa.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. /*
  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. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/major.h>
  18. #include <linux/fs.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/mmc/host.h>
  21. #include <linux/pm.h>
  22. #include <linux/delay.h>
  23. #include <linux/gpio_keys.h>
  24. #include <linux/input.h>
  25. #include <linux/gpio.h>
  26. #include <asm/setup.h>
  27. #include <asm/mach-types.h>
  28. #include <asm/arch/pxa2xx-regs.h>
  29. #include <asm/arch/mfp-pxa25x.h>
  30. #include <asm/arch/irda.h>
  31. #include <asm/arch/i2c.h>
  32. #include <asm/arch/mmc.h>
  33. #include <asm/arch/udc.h>
  34. #include <asm/mach/arch.h>
  35. #include <asm/arch/tosa.h>
  36. #include <asm/hardware/scoop.h>
  37. #include <asm/mach/sharpsl_param.h>
  38. #include "generic.h"
  39. #include "devices.h"
  40. static unsigned long tosa_pin_config[] = {
  41. GPIO78_nCS_2, /* Scoop */
  42. GPIO80_nCS_4, /* tg6393xb */
  43. GPIO33_nCS_5, /* Scoop */
  44. // GPIO76 CARD_VCC_ON1
  45. GPIO19_GPIO, /* Reset out */
  46. GPIO1_RST | WAKEUP_ON_EDGE_FALL,
  47. GPIO0_GPIO | WAKEUP_ON_EDGE_FALL, /* WAKE_UP */
  48. GPIO2_GPIO | WAKEUP_ON_EDGE_BOTH, /* AC_IN */
  49. GPIO3_GPIO | WAKEUP_ON_EDGE_FALL, /* RECORD */
  50. GPIO4_GPIO | WAKEUP_ON_EDGE_FALL, /* SYNC */
  51. GPIO20_GPIO, /* EAR_IN */
  52. GPIO22_GPIO, /* On */
  53. GPIO5_GPIO, /* USB_IN */
  54. GPIO32_GPIO, /* Pen IRQ */
  55. GPIO7_GPIO, /* Jacket Detect */
  56. GPIO14_GPIO, /* BAT0_CRG */
  57. GPIO12_GPIO, /* BAT1_CRG */
  58. GPIO17_GPIO, /* BAT0_LOW */
  59. GPIO84_GPIO, /* BAT1_LOW */
  60. GPIO38_GPIO, /* BAT_LOCK */
  61. GPIO11_3_6MHz,
  62. GPIO15_GPIO, /* TC6393XB IRQ */
  63. GPIO18_RDY,
  64. GPIO27_GPIO, /* LCD Sync */
  65. /* MMC */
  66. GPIO6_MMC_CLK,
  67. GPIO8_MMC_CS0,
  68. GPIO9_GPIO, /* Detect */
  69. GPIO10_GPIO, /* nSD_INT */
  70. /* CF */
  71. GPIO13_GPIO, /* CD_IRQ */
  72. GPIO21_GPIO, /* Main Slot IRQ */
  73. GPIO36_GPIO, /* Jacket Slot IRQ */
  74. GPIO48_nPOE,
  75. GPIO49_nPWE,
  76. GPIO50_nPIOR,
  77. GPIO51_nPIOW,
  78. GPIO52_nPCE_1,
  79. GPIO53_nPCE_2,
  80. GPIO54_nPSKTSEL,
  81. GPIO55_nPREG,
  82. GPIO56_nPWAIT,
  83. GPIO57_nIOIS16,
  84. /* AC97 */
  85. GPIO31_AC97_SYNC,
  86. GPIO30_AC97_SDATA_OUT,
  87. GPIO28_AC97_BITCLK,
  88. GPIO29_AC97_SDATA_IN_0,
  89. // GPIO79 nAUD_IRQ
  90. /* FFUART */
  91. GPIO34_FFUART_RXD,
  92. GPIO35_FFUART_CTS,
  93. GPIO37_FFUART_DSR,
  94. GPIO39_FFUART_TXD,
  95. GPIO40_FFUART_DTR,
  96. GPIO41_FFUART_RTS,
  97. /* BTUART */
  98. GPIO42_BTUART_RXD,
  99. GPIO43_BTUART_TXD,
  100. GPIO44_BTUART_CTS,
  101. GPIO45_BTUART_RTS,
  102. /* Keybd */
  103. GPIO58_GPIO | MFP_LPM_DRIVE_LOW,
  104. GPIO59_GPIO | MFP_LPM_DRIVE_LOW,
  105. GPIO60_GPIO | MFP_LPM_DRIVE_LOW,
  106. GPIO61_GPIO | MFP_LPM_DRIVE_LOW,
  107. GPIO62_GPIO | MFP_LPM_DRIVE_LOW,
  108. GPIO63_GPIO | MFP_LPM_DRIVE_LOW,
  109. GPIO64_GPIO | MFP_LPM_DRIVE_LOW,
  110. GPIO65_GPIO | MFP_LPM_DRIVE_LOW,
  111. GPIO66_GPIO | MFP_LPM_DRIVE_LOW,
  112. GPIO67_GPIO | MFP_LPM_DRIVE_LOW,
  113. GPIO68_GPIO | MFP_LPM_DRIVE_LOW,
  114. GPIO69_GPIO | MFP_LPM_DRIVE_LOW,
  115. GPIO70_GPIO | MFP_LPM_DRIVE_LOW,
  116. GPIO71_GPIO | MFP_LPM_DRIVE_LOW,
  117. GPIO72_GPIO | MFP_LPM_DRIVE_LOW,
  118. GPIO73_GPIO | MFP_LPM_DRIVE_LOW,
  119. GPIO74_GPIO | MFP_LPM_DRIVE_LOW,
  120. GPIO75_GPIO | MFP_LPM_DRIVE_LOW,
  121. /* SPI */
  122. GPIO81_SSP2_CLK_OUT,
  123. GPIO82_SSP2_FRM_OUT,
  124. GPIO83_SSP2_TXD,
  125. };
  126. static unsigned long tosa_pin_irda_off[] = {
  127. GPIO46_STUART_RXD,
  128. GPIO47_GPIO | MFP_LPM_DRIVE_LOW,
  129. };
  130. static unsigned long tosa_pin_irda_on[] = {
  131. GPIO46_STUART_RXD,
  132. GPIO47_STUART_TXD,
  133. };
  134. /*
  135. * SCOOP Device
  136. */
  137. static struct resource tosa_scoop_resources[] = {
  138. [0] = {
  139. .start = TOSA_CF_PHYS,
  140. .end = TOSA_CF_PHYS + 0xfff,
  141. .flags = IORESOURCE_MEM,
  142. },
  143. };
  144. static struct scoop_config tosa_scoop_setup = {
  145. .io_dir = TOSA_SCOOP_IO_DIR,
  146. .gpio_base = TOSA_SCOOP_GPIO_BASE,
  147. };
  148. static struct platform_device tosascoop_device = {
  149. .name = "sharp-scoop",
  150. .id = 0,
  151. .dev = {
  152. .platform_data = &tosa_scoop_setup,
  153. },
  154. .num_resources = ARRAY_SIZE(tosa_scoop_resources),
  155. .resource = tosa_scoop_resources,
  156. };
  157. /*
  158. * SCOOP Device Jacket
  159. */
  160. static struct resource tosa_scoop_jc_resources[] = {
  161. [0] = {
  162. .start = TOSA_SCOOP_PHYS + 0x40,
  163. .end = TOSA_SCOOP_PHYS + 0xfff,
  164. .flags = IORESOURCE_MEM,
  165. },
  166. };
  167. static struct scoop_config tosa_scoop_jc_setup = {
  168. .io_dir = TOSA_SCOOP_JC_IO_DIR,
  169. .gpio_base = TOSA_SCOOP_JC_GPIO_BASE,
  170. };
  171. static struct platform_device tosascoop_jc_device = {
  172. .name = "sharp-scoop",
  173. .id = 1,
  174. .dev = {
  175. .platform_data = &tosa_scoop_jc_setup,
  176. .parent = &tosascoop_device.dev,
  177. },
  178. .num_resources = ARRAY_SIZE(tosa_scoop_jc_resources),
  179. .resource = tosa_scoop_jc_resources,
  180. };
  181. /*
  182. * PCMCIA
  183. */
  184. static struct scoop_pcmcia_dev tosa_pcmcia_scoop[] = {
  185. {
  186. .dev = &tosascoop_device.dev,
  187. .irq = TOSA_IRQ_GPIO_CF_IRQ,
  188. .cd_irq = TOSA_IRQ_GPIO_CF_CD,
  189. .cd_irq_str = "PCMCIA0 CD",
  190. },{
  191. .dev = &tosascoop_jc_device.dev,
  192. .irq = TOSA_IRQ_GPIO_JC_CF_IRQ,
  193. .cd_irq = -1,
  194. },
  195. };
  196. static struct scoop_pcmcia_config tosa_pcmcia_config = {
  197. .devs = &tosa_pcmcia_scoop[0],
  198. .num_devs = 2,
  199. };
  200. /*
  201. * USB Device Controller
  202. */
  203. static struct pxa2xx_udc_mach_info udc_info __initdata = {
  204. .gpio_pullup = TOSA_GPIO_USB_PULLUP,
  205. .gpio_vbus = TOSA_GPIO_USB_IN,
  206. .gpio_vbus_inverted = 1,
  207. };
  208. /*
  209. * MMC/SD Device
  210. */
  211. static struct pxamci_platform_data tosa_mci_platform_data;
  212. static int tosa_mci_init(struct device *dev, irq_handler_t tosa_detect_int, void *data)
  213. {
  214. int err;
  215. tosa_mci_platform_data.detect_delay = msecs_to_jiffies(250);
  216. err = gpio_request(TOSA_GPIO_nSD_DETECT, "MMC/SD card detect");
  217. if (err) {
  218. printk(KERN_ERR "tosa_mci_init: can't request nSD_DETECT gpio\n");
  219. goto err_gpio_detect;
  220. }
  221. err = gpio_direction_input(TOSA_GPIO_nSD_DETECT);
  222. if (err)
  223. goto err_gpio_detect_dir;
  224. err = request_irq(TOSA_IRQ_GPIO_nSD_DETECT, tosa_detect_int,
  225. IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
  226. "MMC/SD card detect", data);
  227. if (err) {
  228. printk(KERN_ERR "tosa_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
  229. goto err_irq;
  230. }
  231. err = gpio_request(TOSA_GPIO_SD_WP, "SD Write Protect");
  232. if (err) {
  233. printk(KERN_ERR "tosa_mci_init: can't request SD_WP gpio\n");
  234. goto err_gpio_wp;
  235. }
  236. err = gpio_direction_input(TOSA_GPIO_SD_WP);
  237. if (err)
  238. goto err_gpio_wp_dir;
  239. err = gpio_request(TOSA_GPIO_PWR_ON, "SD Power");
  240. if (err) {
  241. printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
  242. goto err_gpio_pwr;
  243. }
  244. err = gpio_direction_output(TOSA_GPIO_PWR_ON, 0);
  245. if (err)
  246. goto err_gpio_pwr_dir;
  247. err = gpio_request(TOSA_GPIO_nSD_INT, "SD Int");
  248. if (err) {
  249. printk(KERN_ERR "tosa_mci_init: can't request SD_PWR gpio\n");
  250. goto err_gpio_int;
  251. }
  252. err = gpio_direction_input(TOSA_GPIO_nSD_INT);
  253. if (err)
  254. goto err_gpio_int_dir;
  255. return 0;
  256. err_gpio_int_dir:
  257. gpio_free(TOSA_GPIO_nSD_INT);
  258. err_gpio_int:
  259. err_gpio_pwr_dir:
  260. gpio_free(TOSA_GPIO_PWR_ON);
  261. err_gpio_pwr:
  262. err_gpio_wp_dir:
  263. gpio_free(TOSA_GPIO_SD_WP);
  264. err_gpio_wp:
  265. free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data);
  266. err_irq:
  267. err_gpio_detect_dir:
  268. gpio_free(TOSA_GPIO_nSD_DETECT);
  269. err_gpio_detect:
  270. return err;
  271. }
  272. static void tosa_mci_setpower(struct device *dev, unsigned int vdd)
  273. {
  274. struct pxamci_platform_data* p_d = dev->platform_data;
  275. if (( 1 << vdd) & p_d->ocr_mask) {
  276. gpio_set_value(TOSA_GPIO_PWR_ON, 1);
  277. } else {
  278. gpio_set_value(TOSA_GPIO_PWR_ON, 0);
  279. }
  280. }
  281. static int tosa_mci_get_ro(struct device *dev)
  282. {
  283. return gpio_get_value(TOSA_GPIO_SD_WP);
  284. }
  285. static void tosa_mci_exit(struct device *dev, void *data)
  286. {
  287. gpio_free(TOSA_GPIO_nSD_INT);
  288. gpio_free(TOSA_GPIO_PWR_ON);
  289. gpio_free(TOSA_GPIO_SD_WP);
  290. free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data);
  291. gpio_free(TOSA_GPIO_nSD_DETECT);
  292. }
  293. static struct pxamci_platform_data tosa_mci_platform_data = {
  294. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  295. .init = tosa_mci_init,
  296. .get_ro = tosa_mci_get_ro,
  297. .setpower = tosa_mci_setpower,
  298. .exit = tosa_mci_exit,
  299. };
  300. /*
  301. * Irda
  302. */
  303. static void tosa_irda_transceiver_mode(struct device *dev, int mode)
  304. {
  305. if (mode & IR_OFF) {
  306. gpio_set_value(TOSA_GPIO_IR_POWERDWN, 0);
  307. pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_off));
  308. gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
  309. } else {
  310. pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_on));
  311. gpio_set_value(TOSA_GPIO_IR_POWERDWN, 1);
  312. }
  313. }
  314. static int tosa_irda_startup(struct device *dev)
  315. {
  316. int ret;
  317. ret = gpio_request(TOSA_GPIO_IRDA_TX, "IrDA TX");
  318. if (ret)
  319. goto err_tx;
  320. ret = gpio_direction_output(TOSA_GPIO_IRDA_TX, 0);
  321. if (ret)
  322. goto err_tx_dir;
  323. ret = gpio_request(TOSA_GPIO_IR_POWERDWN, "IrDA powerdown");
  324. if (ret)
  325. goto err_pwr;
  326. ret = gpio_direction_output(TOSA_GPIO_IR_POWERDWN, 0);
  327. if (ret)
  328. goto err_pwr_dir;
  329. tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
  330. return 0;
  331. err_pwr_dir:
  332. gpio_free(TOSA_GPIO_IR_POWERDWN);
  333. err_pwr:
  334. err_tx_dir:
  335. gpio_free(TOSA_GPIO_IRDA_TX);
  336. err_tx:
  337. return ret;
  338. }
  339. static void tosa_irda_shutdown(struct device *dev)
  340. {
  341. tosa_irda_transceiver_mode(dev, IR_SIRMODE | IR_OFF);
  342. gpio_free(TOSA_GPIO_IR_POWERDWN);
  343. gpio_free(TOSA_GPIO_IRDA_TX);
  344. }
  345. static struct pxaficp_platform_data tosa_ficp_platform_data = {
  346. .transceiver_cap = IR_SIRMODE | IR_OFF,
  347. .transceiver_mode = tosa_irda_transceiver_mode,
  348. .startup = tosa_irda_startup,
  349. .shutdown = tosa_irda_shutdown,
  350. };
  351. /*
  352. * Tosa Keyboard
  353. */
  354. static struct platform_device tosakbd_device = {
  355. .name = "tosa-keyboard",
  356. .id = -1,
  357. };
  358. static struct gpio_keys_button tosa_gpio_keys[] = {
  359. /*
  360. * Two following keys are directly tied to "ON" button of tosa. Why?
  361. * The first one can be used as a wakeup source, the second can't;
  362. * also the first one is OR of ac_powered and on_button.
  363. */
  364. {
  365. .type = EV_PWR,
  366. .code = KEY_RESERVED,
  367. .gpio = TOSA_GPIO_POWERON,
  368. .desc = "Poweron",
  369. .wakeup = 1,
  370. .active_low = 1,
  371. },
  372. {
  373. .type = EV_PWR,
  374. .code = KEY_SUSPEND,
  375. .gpio = TOSA_GPIO_ON_KEY,
  376. .desc = "On key",
  377. /*
  378. * can't be used as wakeup
  379. * .wakeup = 1,
  380. */
  381. .active_low = 1,
  382. },
  383. {
  384. .type = EV_KEY,
  385. .code = TOSA_KEY_RECORD,
  386. .gpio = TOSA_GPIO_RECORD_BTN,
  387. .desc = "Record Button",
  388. .wakeup = 1,
  389. .active_low = 1,
  390. },
  391. {
  392. .type = EV_KEY,
  393. .code = TOSA_KEY_SYNC,
  394. .gpio = TOSA_GPIO_SYNC,
  395. .desc = "Sync Button",
  396. .wakeup = 1,
  397. .active_low = 1,
  398. },
  399. };
  400. static struct gpio_keys_platform_data tosa_gpio_keys_platform_data = {
  401. .buttons = tosa_gpio_keys,
  402. .nbuttons = ARRAY_SIZE(tosa_gpio_keys),
  403. };
  404. static struct platform_device tosa_gpio_keys_device = {
  405. .name = "gpio-keys",
  406. .id = -1,
  407. .dev = {
  408. .platform_data = &tosa_gpio_keys_platform_data,
  409. },
  410. };
  411. /*
  412. * Tosa LEDs
  413. */
  414. static struct gpio_led tosa_gpio_leds[] = {
  415. {
  416. .name = "tosa:amber:charge",
  417. .default_trigger = "main-battery-charging",
  418. .gpio = TOSA_GPIO_CHRG_ERR_LED,
  419. },
  420. {
  421. .name = "tosa:green:mail",
  422. .default_trigger = "nand-disk",
  423. .gpio = TOSA_GPIO_NOTE_LED,
  424. },
  425. {
  426. .name = "tosa:dual:wlan",
  427. .default_trigger = "none",
  428. .gpio = TOSA_GPIO_WLAN_LED,
  429. },
  430. {
  431. .name = "tosa:blue:bluetooth",
  432. .default_trigger = "none",
  433. .gpio = TOSA_GPIO_BT_LED,
  434. },
  435. };
  436. static struct gpio_led_platform_data tosa_gpio_leds_platform_data = {
  437. .leds = tosa_gpio_leds,
  438. .num_leds = ARRAY_SIZE(tosa_gpio_leds),
  439. };
  440. static struct platform_device tosaled_device = {
  441. .name = "leds-gpio",
  442. .id = -1,
  443. .dev = {
  444. .platform_data = &tosa_gpio_leds_platform_data,
  445. },
  446. };
  447. static struct platform_device *devices[] __initdata = {
  448. &tosascoop_device,
  449. &tosascoop_jc_device,
  450. &tosakbd_device,
  451. &tosa_gpio_keys_device,
  452. &tosaled_device,
  453. };
  454. static void tosa_poweroff(void)
  455. {
  456. arm_machine_restart('g');
  457. }
  458. static void tosa_restart(char mode)
  459. {
  460. /* Bootloader magic for a reboot */
  461. if((MSC0 & 0xffff0000) == 0x7ff00000)
  462. MSC0 = (MSC0 & 0xffff) | 0x7ee00000;
  463. tosa_poweroff();
  464. }
  465. static void __init tosa_init(void)
  466. {
  467. pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_config));
  468. pxa2xx_mfp_config(ARRAY_AND_SIZE(tosa_pin_irda_off));
  469. gpio_set_wake(MFP_PIN_GPIO1, 1);
  470. /* We can't pass to gpio-keys since it will drop the Reset altfunc */
  471. init_gpio_reset(TOSA_GPIO_ON_RESET);
  472. pm_power_off = tosa_poweroff;
  473. arm_pm_restart = tosa_restart;
  474. PCFR |= PCFR_OPDE;
  475. /* enable batt_fault */
  476. PMCR = 0x01;
  477. pxa_set_mci_info(&tosa_mci_platform_data);
  478. pxa_set_udc_info(&udc_info);
  479. pxa_set_ficp_info(&tosa_ficp_platform_data);
  480. pxa_set_i2c_info(NULL);
  481. platform_scoop_config = &tosa_pcmcia_config;
  482. platform_add_devices(devices, ARRAY_SIZE(devices));
  483. }
  484. static void __init fixup_tosa(struct machine_desc *desc,
  485. struct tag *tags, char **cmdline, struct meminfo *mi)
  486. {
  487. sharpsl_save_param();
  488. mi->nr_banks=1;
  489. mi->bank[0].start = 0xa0000000;
  490. mi->bank[0].node = 0;
  491. mi->bank[0].size = (64*1024*1024);
  492. }
  493. MACHINE_START(TOSA, "SHARP Tosa")
  494. .phys_io = 0x40000000,
  495. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  496. .fixup = fixup_tosa,
  497. .map_io = pxa_map_io,
  498. .init_irq = pxa25x_init_irq,
  499. .init_machine = tosa_init,
  500. .timer = &pxa_timer,
  501. MACHINE_END