tosa.c 9.3 KB

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