tosa.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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/irda.h>
  33. #include <asm/arch/mmc.h>
  34. #include <asm/arch/udc.h>
  35. #include <asm/mach/arch.h>
  36. #include <asm/mach/map.h>
  37. #include <asm/mach/irq.h>
  38. #include <asm/arch/tosa.h>
  39. #include <asm/hardware/scoop.h>
  40. #include <asm/mach/sharpsl_param.h>
  41. #include "generic.h"
  42. #include "devices.h"
  43. /*
  44. * SCOOP Device
  45. */
  46. static struct resource tosa_scoop_resources[] = {
  47. [0] = {
  48. .start = TOSA_CF_PHYS,
  49. .end = TOSA_CF_PHYS + 0xfff,
  50. .flags = IORESOURCE_MEM,
  51. },
  52. };
  53. static struct scoop_config tosa_scoop_setup = {
  54. .io_dir = TOSA_SCOOP_IO_DIR,
  55. .io_out = TOSA_SCOOP_IO_OUT,
  56. };
  57. struct platform_device tosascoop_device = {
  58. .name = "sharp-scoop",
  59. .id = 0,
  60. .dev = {
  61. .platform_data = &tosa_scoop_setup,
  62. },
  63. .num_resources = ARRAY_SIZE(tosa_scoop_resources),
  64. .resource = tosa_scoop_resources,
  65. };
  66. /*
  67. * SCOOP Device Jacket
  68. */
  69. static struct resource tosa_scoop_jc_resources[] = {
  70. [0] = {
  71. .start = TOSA_SCOOP_PHYS + 0x40,
  72. .end = TOSA_SCOOP_PHYS + 0xfff,
  73. .flags = IORESOURCE_MEM,
  74. },
  75. };
  76. static struct scoop_config tosa_scoop_jc_setup = {
  77. .io_dir = TOSA_SCOOP_JC_IO_DIR,
  78. .io_out = TOSA_SCOOP_JC_IO_OUT,
  79. };
  80. struct platform_device tosascoop_jc_device = {
  81. .name = "sharp-scoop",
  82. .id = 1,
  83. .dev = {
  84. .platform_data = &tosa_scoop_jc_setup,
  85. .parent = &tosascoop_device.dev,
  86. },
  87. .num_resources = ARRAY_SIZE(tosa_scoop_jc_resources),
  88. .resource = tosa_scoop_jc_resources,
  89. };
  90. /*
  91. * PCMCIA
  92. */
  93. static struct scoop_pcmcia_dev tosa_pcmcia_scoop[] = {
  94. {
  95. .dev = &tosascoop_device.dev,
  96. .irq = TOSA_IRQ_GPIO_CF_IRQ,
  97. .cd_irq = TOSA_IRQ_GPIO_CF_CD,
  98. .cd_irq_str = "PCMCIA0 CD",
  99. },{
  100. .dev = &tosascoop_jc_device.dev,
  101. .irq = TOSA_IRQ_GPIO_JC_CF_IRQ,
  102. .cd_irq = -1,
  103. },
  104. };
  105. static void tosa_pcmcia_init(void)
  106. {
  107. /* Setup default state of GPIO outputs
  108. before we enable them as outputs. */
  109. GPSR(GPIO48_nPOE) = GPIO_bit(GPIO48_nPOE) |
  110. GPIO_bit(GPIO49_nPWE) | GPIO_bit(GPIO50_nPIOR) |
  111. GPIO_bit(GPIO51_nPIOW) | GPIO_bit(GPIO52_nPCE_1) |
  112. GPIO_bit(GPIO53_nPCE_2);
  113. pxa_gpio_mode(GPIO48_nPOE_MD);
  114. pxa_gpio_mode(GPIO49_nPWE_MD);
  115. pxa_gpio_mode(GPIO50_nPIOR_MD);
  116. pxa_gpio_mode(GPIO51_nPIOW_MD);
  117. pxa_gpio_mode(GPIO55_nPREG_MD);
  118. pxa_gpio_mode(GPIO56_nPWAIT_MD);
  119. pxa_gpio_mode(GPIO57_nIOIS16_MD);
  120. pxa_gpio_mode(GPIO52_nPCE_1_MD);
  121. pxa_gpio_mode(GPIO53_nPCE_2_MD);
  122. pxa_gpio_mode(GPIO54_pSKTSEL_MD);
  123. }
  124. static struct scoop_pcmcia_config tosa_pcmcia_config = {
  125. .devs = &tosa_pcmcia_scoop[0],
  126. .num_devs = 2,
  127. .pcmcia_init = tosa_pcmcia_init,
  128. };
  129. /*
  130. * USB Device Controller
  131. */
  132. static void tosa_udc_command(int cmd)
  133. {
  134. switch(cmd) {
  135. case PXA2XX_UDC_CMD_CONNECT:
  136. set_scoop_gpio(&tosascoop_jc_device.dev,TOSA_SCOOP_JC_USB_PULLUP);
  137. break;
  138. case PXA2XX_UDC_CMD_DISCONNECT:
  139. reset_scoop_gpio(&tosascoop_jc_device.dev,TOSA_SCOOP_JC_USB_PULLUP);
  140. break;
  141. }
  142. }
  143. static int tosa_udc_is_connected(void)
  144. {
  145. return ((GPLR(TOSA_GPIO_USB_IN) & GPIO_bit(TOSA_GPIO_USB_IN)) == 0);
  146. }
  147. static struct pxa2xx_udc_mach_info udc_info __initdata = {
  148. .udc_command = tosa_udc_command,
  149. .udc_is_connected = tosa_udc_is_connected,
  150. };
  151. /*
  152. * MMC/SD Device
  153. */
  154. static struct pxamci_platform_data tosa_mci_platform_data;
  155. static int tosa_mci_init(struct device *dev, irq_handler_t tosa_detect_int, void *data)
  156. {
  157. int err;
  158. /* setup GPIO for PXA25x MMC controller */
  159. pxa_gpio_mode(GPIO6_MMCCLK_MD);
  160. pxa_gpio_mode(GPIO8_MMCCS0_MD);
  161. pxa_gpio_mode(TOSA_GPIO_nSD_DETECT | GPIO_IN);
  162. tosa_mci_platform_data.detect_delay = msecs_to_jiffies(250);
  163. err = request_irq(TOSA_IRQ_GPIO_nSD_DETECT, tosa_detect_int, IRQF_DISABLED,
  164. "MMC/SD card detect", data);
  165. if (err) {
  166. printk(KERN_ERR "tosa_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
  167. return -1;
  168. }
  169. set_irq_type(TOSA_IRQ_GPIO_nSD_DETECT, IRQT_BOTHEDGE);
  170. return 0;
  171. }
  172. static void tosa_mci_setpower(struct device *dev, unsigned int vdd)
  173. {
  174. struct pxamci_platform_data* p_d = dev->platform_data;
  175. if (( 1 << vdd) & p_d->ocr_mask) {
  176. set_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_PWR_ON);
  177. } else {
  178. reset_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_PWR_ON);
  179. }
  180. }
  181. static int tosa_mci_get_ro(struct device *dev)
  182. {
  183. return (read_scoop_reg(&tosascoop_device.dev, SCOOP_GPWR)&TOSA_SCOOP_SD_WP);
  184. }
  185. static void tosa_mci_exit(struct device *dev, void *data)
  186. {
  187. free_irq(TOSA_IRQ_GPIO_nSD_DETECT, data);
  188. }
  189. static struct pxamci_platform_data tosa_mci_platform_data = {
  190. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  191. .init = tosa_mci_init,
  192. .get_ro = tosa_mci_get_ro,
  193. .setpower = tosa_mci_setpower,
  194. .exit = tosa_mci_exit,
  195. };
  196. /*
  197. * Irda
  198. */
  199. static void tosa_irda_transceiver_mode(struct device *dev, int mode)
  200. {
  201. if (mode & IR_OFF) {
  202. reset_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_IR_POWERDWN);
  203. pxa_gpio_mode(GPIO47_STTXD|GPIO_DFLT_LOW);
  204. pxa_gpio_mode(GPIO47_STTXD|GPIO_OUT);
  205. } else {
  206. pxa_gpio_mode(GPIO47_STTXD_MD);
  207. set_scoop_gpio(&tosascoop_device.dev,TOSA_SCOOP_IR_POWERDWN);
  208. }
  209. }
  210. static struct pxaficp_platform_data tosa_ficp_platform_data = {
  211. .transceiver_cap = IR_SIRMODE | IR_OFF,
  212. .transceiver_mode = tosa_irda_transceiver_mode,
  213. };
  214. /*
  215. * Tosa Keyboard
  216. */
  217. static struct platform_device tosakbd_device = {
  218. .name = "tosa-keyboard",
  219. .id = -1,
  220. };
  221. static struct gpio_keys_button tosa_gpio_keys[] = {
  222. {
  223. .type = EV_PWR,
  224. .code = KEY_SUSPEND,
  225. .gpio = TOSA_GPIO_ON_KEY,
  226. .desc = "On key",
  227. .wakeup = 1,
  228. .active_low = 1,
  229. },
  230. {
  231. .type = EV_KEY,
  232. .code = TOSA_KEY_RECORD,
  233. .gpio = TOSA_GPIO_RECORD_BTN,
  234. .desc = "Record Button",
  235. .wakeup = 1,
  236. .active_low = 1,
  237. },
  238. {
  239. .type = EV_KEY,
  240. .code = TOSA_KEY_SYNC,
  241. .gpio = TOSA_GPIO_SYNC,
  242. .desc = "Sync Button",
  243. .wakeup = 1,
  244. .active_low = 1,
  245. },
  246. };
  247. static struct gpio_keys_platform_data tosa_gpio_keys_platform_data = {
  248. .buttons = tosa_gpio_keys,
  249. .nbuttons = ARRAY_SIZE(tosa_gpio_keys),
  250. };
  251. static struct platform_device tosa_gpio_keys_device = {
  252. .name = "gpio-keys",
  253. .id = -1,
  254. .dev = {
  255. .platform_data = &tosa_gpio_keys_platform_data,
  256. },
  257. };
  258. /*
  259. * Tosa LEDs
  260. */
  261. static struct platform_device tosaled_device = {
  262. .name = "tosa-led",
  263. .id = -1,
  264. };
  265. static struct platform_device *devices[] __initdata = {
  266. &tosascoop_device,
  267. &tosascoop_jc_device,
  268. &tosakbd_device,
  269. &tosa_gpio_keys_device,
  270. &tosaled_device,
  271. };
  272. static void tosa_poweroff(void)
  273. {
  274. RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR;
  275. pxa_gpio_mode(TOSA_GPIO_ON_RESET | GPIO_OUT);
  276. GPSR(TOSA_GPIO_ON_RESET) = GPIO_bit(TOSA_GPIO_ON_RESET);
  277. mdelay(1000);
  278. arm_machine_restart('h');
  279. }
  280. static void tosa_restart(char mode)
  281. {
  282. /* Bootloader magic for a reboot */
  283. if((MSC0 & 0xffff0000) == 0x7ff00000)
  284. MSC0 = (MSC0 & 0xffff) | 0x7ee00000;
  285. tosa_poweroff();
  286. }
  287. static void __init tosa_init(void)
  288. {
  289. pm_power_off = tosa_poweroff;
  290. arm_pm_restart = tosa_restart;
  291. pxa_gpio_mode(TOSA_GPIO_ON_RESET | GPIO_IN);
  292. pxa_gpio_mode(TOSA_GPIO_TC6393_INT | GPIO_IN);
  293. pxa_gpio_mode(TOSA_GPIO_USB_IN | GPIO_IN);
  294. /* setup sleep mode values */
  295. PWER = 0x00000002;
  296. PFER = 0x00000000;
  297. PRER = 0x00000002;
  298. PGSR0 = 0x00000000;
  299. PGSR1 = 0x00FF0002;
  300. PGSR2 = 0x00014000;
  301. PCFR |= PCFR_OPDE;
  302. /* enable batt_fault */
  303. PMCR = 0x01;
  304. pxa_set_mci_info(&tosa_mci_platform_data);
  305. pxa_set_udc_info(&udc_info);
  306. pxa_set_ficp_info(&tosa_ficp_platform_data);
  307. platform_scoop_config = &tosa_pcmcia_config;
  308. platform_add_devices(devices, ARRAY_SIZE(devices));
  309. }
  310. static void __init fixup_tosa(struct machine_desc *desc,
  311. struct tag *tags, char **cmdline, struct meminfo *mi)
  312. {
  313. sharpsl_save_param();
  314. mi->nr_banks=1;
  315. mi->bank[0].start = 0xa0000000;
  316. mi->bank[0].node = 0;
  317. mi->bank[0].size = (64*1024*1024);
  318. }
  319. MACHINE_START(TOSA, "SHARP Tosa")
  320. .phys_io = 0x40000000,
  321. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  322. .fixup = fixup_tosa,
  323. .map_io = pxa_map_io,
  324. .init_irq = pxa25x_init_irq,
  325. .init_machine = tosa_init,
  326. .timer = &pxa_timer,
  327. MACHINE_END