tosa.c 11 KB

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