tosa.c 11 KB

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