tosa.c 8.5 KB

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