tosa.c 7.1 KB

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