tosa.c 7.6 KB

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