tosa.c 7.7 KB

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