spitz.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. /*
  2. * Support for Sharp SL-Cxx00 Series of PDAs
  3. * Models: SL-C3000 (Spitz), SL-C1000 (Akita) and SL-C3100 (Borzoi)
  4. *
  5. * Copyright (c) 2005 Richard Purdie
  6. *
  7. * Based on Sharp's 2.4 kernel patches/lubbock.c
  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/delay.h>
  18. #include <linux/major.h>
  19. #include <linux/fs.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/mmc/host.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/io.h>
  28. #include <asm/mach/arch.h>
  29. #include <asm/mach/map.h>
  30. #include <asm/mach/irq.h>
  31. #include <asm/arch/pxa-regs.h>
  32. #include <asm/arch/irq.h>
  33. #include <asm/arch/irda.h>
  34. #include <asm/arch/mmc.h>
  35. #include <asm/arch/udc.h>
  36. #include <asm/arch/pxafb.h>
  37. #include <asm/arch/akita.h>
  38. #include <asm/arch/spitz.h>
  39. #include <asm/arch/sharpsl.h>
  40. #include <asm/mach/sharpsl_param.h>
  41. #include <asm/hardware/scoop.h>
  42. #include "generic.h"
  43. #include "sharpsl.h"
  44. /*
  45. * Spitz SCOOP Device #1
  46. */
  47. static struct resource spitz_scoop_resources[] = {
  48. [0] = {
  49. .start = 0x10800000,
  50. .end = 0x10800fff,
  51. .flags = IORESOURCE_MEM,
  52. },
  53. };
  54. static struct scoop_config spitz_scoop_setup = {
  55. .io_dir = SPITZ_SCP_IO_DIR,
  56. .io_out = SPITZ_SCP_IO_OUT,
  57. .suspend_clr = SPITZ_SCP_SUS_CLR,
  58. .suspend_set = SPITZ_SCP_SUS_SET,
  59. };
  60. struct platform_device spitzscoop_device = {
  61. .name = "sharp-scoop",
  62. .id = 0,
  63. .dev = {
  64. .platform_data = &spitz_scoop_setup,
  65. },
  66. .num_resources = ARRAY_SIZE(spitz_scoop_resources),
  67. .resource = spitz_scoop_resources,
  68. };
  69. /*
  70. * Spitz SCOOP Device #2
  71. */
  72. static struct resource spitz_scoop2_resources[] = {
  73. [0] = {
  74. .start = 0x08800040,
  75. .end = 0x08800fff,
  76. .flags = IORESOURCE_MEM,
  77. },
  78. };
  79. static struct scoop_config spitz_scoop2_setup = {
  80. .io_dir = SPITZ_SCP2_IO_DIR,
  81. .io_out = SPITZ_SCP2_IO_OUT,
  82. .suspend_clr = SPITZ_SCP2_SUS_CLR,
  83. .suspend_set = SPITZ_SCP2_SUS_SET,
  84. };
  85. struct platform_device spitzscoop2_device = {
  86. .name = "sharp-scoop",
  87. .id = 1,
  88. .dev = {
  89. .platform_data = &spitz_scoop2_setup,
  90. },
  91. .num_resources = ARRAY_SIZE(spitz_scoop2_resources),
  92. .resource = spitz_scoop2_resources,
  93. };
  94. #define SPITZ_PWR_SD 0x01
  95. #define SPITZ_PWR_CF 0x02
  96. /* Power control is shared with between one of the CF slots and SD */
  97. static void spitz_card_pwr_ctrl(int device, unsigned short new_cpr)
  98. {
  99. unsigned short cpr = read_scoop_reg(&spitzscoop_device.dev, SCOOP_CPR);
  100. if (new_cpr & 0x0007) {
  101. set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_CF_POWER);
  102. if (!(cpr & 0x0002) && !(cpr & 0x0004))
  103. mdelay(5);
  104. if (device == SPITZ_PWR_CF)
  105. cpr |= 0x0002;
  106. if (device == SPITZ_PWR_SD)
  107. cpr |= 0x0004;
  108. write_scoop_reg(&spitzscoop_device.dev, SCOOP_CPR, cpr | new_cpr);
  109. } else {
  110. if (device == SPITZ_PWR_CF)
  111. cpr &= ~0x0002;
  112. if (device == SPITZ_PWR_SD)
  113. cpr &= ~0x0004;
  114. write_scoop_reg(&spitzscoop_device.dev, SCOOP_CPR, cpr | new_cpr);
  115. if (!(cpr & 0x0002) && !(cpr & 0x0004)) {
  116. mdelay(1);
  117. reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_CF_POWER);
  118. }
  119. }
  120. }
  121. static void spitz_pcmcia_init(void)
  122. {
  123. /* Setup default state of GPIO outputs
  124. before we enable them as outputs. */
  125. GPSR(GPIO48_nPOE) = GPIO_bit(GPIO48_nPOE) |
  126. GPIO_bit(GPIO49_nPWE) | GPIO_bit(GPIO50_nPIOR) |
  127. GPIO_bit(GPIO51_nPIOW) | GPIO_bit(GPIO54_nPCE_2);
  128. GPSR(GPIO85_nPCE_1) = GPIO_bit(GPIO85_nPCE_1);
  129. pxa_gpio_mode(GPIO48_nPOE_MD);
  130. pxa_gpio_mode(GPIO49_nPWE_MD);
  131. pxa_gpio_mode(GPIO50_nPIOR_MD);
  132. pxa_gpio_mode(GPIO51_nPIOW_MD);
  133. pxa_gpio_mode(GPIO55_nPREG_MD);
  134. pxa_gpio_mode(GPIO56_nPWAIT_MD);
  135. pxa_gpio_mode(GPIO57_nIOIS16_MD);
  136. pxa_gpio_mode(GPIO85_nPCE_1_MD);
  137. pxa_gpio_mode(GPIO54_nPCE_2_MD);
  138. pxa_gpio_mode(GPIO104_pSKTSEL_MD);
  139. }
  140. static void spitz_pcmcia_pwr(struct device *scoop, unsigned short cpr, int nr)
  141. {
  142. /* Only need to override behaviour for slot 0 */
  143. if (nr == 0)
  144. spitz_card_pwr_ctrl(SPITZ_PWR_CF, cpr);
  145. else
  146. write_scoop_reg(scoop, SCOOP_CPR, cpr);
  147. }
  148. static struct scoop_pcmcia_dev spitz_pcmcia_scoop[] = {
  149. {
  150. .dev = &spitzscoop_device.dev,
  151. .irq = SPITZ_IRQ_GPIO_CF_IRQ,
  152. .cd_irq = SPITZ_IRQ_GPIO_CF_CD,
  153. .cd_irq_str = "PCMCIA0 CD",
  154. },{
  155. .dev = &spitzscoop2_device.dev,
  156. .irq = SPITZ_IRQ_GPIO_CF2_IRQ,
  157. .cd_irq = -1,
  158. },
  159. };
  160. static struct scoop_pcmcia_config spitz_pcmcia_config = {
  161. .devs = &spitz_pcmcia_scoop[0],
  162. .num_devs = 2,
  163. .pcmcia_init = spitz_pcmcia_init,
  164. .power_ctrl = spitz_pcmcia_pwr,
  165. };
  166. EXPORT_SYMBOL(spitzscoop_device);
  167. EXPORT_SYMBOL(spitzscoop2_device);
  168. /*
  169. * Spitz SSP Device
  170. *
  171. * Set the parent as the scoop device because a lot of SSP devices
  172. * also use scoop functions and this makes the power up/down order
  173. * work correctly.
  174. */
  175. struct platform_device spitzssp_device = {
  176. .name = "corgi-ssp",
  177. .dev = {
  178. .parent = &spitzscoop_device.dev,
  179. },
  180. .id = -1,
  181. };
  182. struct corgissp_machinfo spitz_ssp_machinfo = {
  183. .port = 2,
  184. .cs_lcdcon = SPITZ_GPIO_LCDCON_CS,
  185. .cs_ads7846 = SPITZ_GPIO_ADS7846_CS,
  186. .cs_max1111 = SPITZ_GPIO_MAX1111_CS,
  187. .clk_lcdcon = 520,
  188. .clk_ads7846 = 14,
  189. .clk_max1111 = 56,
  190. };
  191. /*
  192. * Spitz Backlight Device
  193. */
  194. static struct corgibl_machinfo spitz_bl_machinfo = {
  195. .max_intensity = 0x2f,
  196. };
  197. static struct platform_device spitzbl_device = {
  198. .name = "corgi-bl",
  199. .dev = {
  200. .platform_data = &spitz_bl_machinfo,
  201. },
  202. .id = -1,
  203. };
  204. /*
  205. * Spitz Keyboard Device
  206. */
  207. static struct platform_device spitzkbd_device = {
  208. .name = "spitz-keyboard",
  209. .id = -1,
  210. };
  211. /*
  212. * Spitz Touch Screen Device
  213. */
  214. static struct resource spitzts_resources[] = {
  215. [0] = {
  216. .start = SPITZ_IRQ_GPIO_TP_INT,
  217. .end = SPITZ_IRQ_GPIO_TP_INT,
  218. .flags = IORESOURCE_IRQ,
  219. },
  220. };
  221. static struct corgits_machinfo spitz_ts_machinfo = {
  222. .get_hsync_len = spitz_get_hsync_len,
  223. .put_hsync = spitz_put_hsync,
  224. .wait_hsync = spitz_wait_hsync,
  225. };
  226. static struct platform_device spitzts_device = {
  227. .name = "corgi-ts",
  228. .dev = {
  229. .parent = &spitzssp_device.dev,
  230. .platform_data = &spitz_ts_machinfo,
  231. },
  232. .id = -1,
  233. .num_resources = ARRAY_SIZE(spitzts_resources),
  234. .resource = spitzts_resources,
  235. };
  236. /*
  237. * MMC/SD Device
  238. *
  239. * The card detect interrupt isn't debounced so we delay it by 250ms
  240. * to give the card a chance to fully insert/eject.
  241. */
  242. static struct pxamci_platform_data spitz_mci_platform_data;
  243. static int spitz_mci_init(struct device *dev, irqreturn_t (*spitz_detect_int)(int, void *, struct pt_regs *), void *data)
  244. {
  245. int err;
  246. /* setup GPIO for PXA27x MMC controller */
  247. pxa_gpio_mode(GPIO32_MMCCLK_MD);
  248. pxa_gpio_mode(GPIO112_MMCCMD_MD);
  249. pxa_gpio_mode(GPIO92_MMCDAT0_MD);
  250. pxa_gpio_mode(GPIO109_MMCDAT1_MD);
  251. pxa_gpio_mode(GPIO110_MMCDAT2_MD);
  252. pxa_gpio_mode(GPIO111_MMCDAT3_MD);
  253. pxa_gpio_mode(SPITZ_GPIO_nSD_DETECT | GPIO_IN);
  254. pxa_gpio_mode(SPITZ_GPIO_nSD_WP | GPIO_IN);
  255. spitz_mci_platform_data.detect_delay = msecs_to_jiffies(250);
  256. err = request_irq(SPITZ_IRQ_GPIO_nSD_DETECT, spitz_detect_int, SA_INTERRUPT,
  257. "MMC card detect", data);
  258. if (err) {
  259. printk(KERN_ERR "spitz_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
  260. return -1;
  261. }
  262. set_irq_type(SPITZ_IRQ_GPIO_nSD_DETECT, IRQT_BOTHEDGE);
  263. return 0;
  264. }
  265. static void spitz_mci_setpower(struct device *dev, unsigned int vdd)
  266. {
  267. struct pxamci_platform_data* p_d = dev->platform_data;
  268. if (( 1 << vdd) & p_d->ocr_mask)
  269. spitz_card_pwr_ctrl(SPITZ_PWR_SD, 0x0004);
  270. else
  271. spitz_card_pwr_ctrl(SPITZ_PWR_SD, 0x0000);
  272. }
  273. static int spitz_mci_get_ro(struct device *dev)
  274. {
  275. return GPLR(SPITZ_GPIO_nSD_WP) & GPIO_bit(SPITZ_GPIO_nSD_WP);
  276. }
  277. static void spitz_mci_exit(struct device *dev, void *data)
  278. {
  279. free_irq(SPITZ_IRQ_GPIO_nSD_DETECT, data);
  280. }
  281. static struct pxamci_platform_data spitz_mci_platform_data = {
  282. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  283. .init = spitz_mci_init,
  284. .get_ro = spitz_mci_get_ro,
  285. .setpower = spitz_mci_setpower,
  286. .exit = spitz_mci_exit,
  287. };
  288. /*
  289. * Irda
  290. */
  291. static void spitz_irda_transceiver_mode(struct device *dev, int mode)
  292. {
  293. if (mode & IR_OFF)
  294. set_scoop_gpio(&spitzscoop2_device.dev, SPITZ_SCP2_IR_ON);
  295. else
  296. reset_scoop_gpio(&spitzscoop2_device.dev, SPITZ_SCP2_IR_ON);
  297. }
  298. #ifdef CONFIG_MACH_AKITA
  299. static void akita_irda_transceiver_mode(struct device *dev, int mode)
  300. {
  301. if (mode & IR_OFF)
  302. akita_set_ioexp(&akitaioexp_device.dev, AKITA_IOEXP_IR_ON);
  303. else
  304. akita_reset_ioexp(&akitaioexp_device.dev, AKITA_IOEXP_IR_ON);
  305. }
  306. #endif
  307. static struct pxaficp_platform_data spitz_ficp_platform_data = {
  308. .transceiver_cap = IR_SIRMODE | IR_OFF,
  309. .transceiver_mode = spitz_irda_transceiver_mode,
  310. };
  311. /*
  312. * Spitz PXA Framebuffer
  313. */
  314. static struct pxafb_mach_info spitz_pxafb_info __initdata = {
  315. .pixclock = 19231,
  316. .xres = 480,
  317. .yres = 640,
  318. .bpp = 16,
  319. .hsync_len = 40,
  320. .left_margin = 46,
  321. .right_margin = 125,
  322. .vsync_len = 3,
  323. .upper_margin = 1,
  324. .lower_margin = 0,
  325. .sync = 0,
  326. .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act | LCCR0_LDDALT | LCCR0_OUC | LCCR0_CMDIM | LCCR0_RDSTM,
  327. .lccr3 = LCCR3_PixRsEdg | LCCR3_OutEnH,
  328. .pxafb_lcd_power = spitz_lcd_power,
  329. };
  330. static struct platform_device *devices[] __initdata = {
  331. &spitzscoop_device,
  332. &spitzssp_device,
  333. &spitzkbd_device,
  334. &spitzts_device,
  335. &spitzbl_device,
  336. };
  337. static void __init common_init(void)
  338. {
  339. PMCR = 0x00;
  340. /* setup sleep mode values */
  341. PWER = 0x00000002;
  342. PFER = 0x00000000;
  343. PRER = 0x00000002;
  344. PGSR0 = 0x0158C000;
  345. PGSR1 = 0x00FF0080;
  346. PGSR2 = 0x0001C004;
  347. /* Stop 3.6MHz and drive HIGH to PCMCIA and CS */
  348. PCFR |= PCFR_OPDE;
  349. corgi_ssp_set_machinfo(&spitz_ssp_machinfo);
  350. pxa_gpio_mode(SPITZ_GPIO_HSYNC | GPIO_IN);
  351. platform_add_devices(devices, ARRAY_SIZE(devices));
  352. pxa_set_mci_info(&spitz_mci_platform_data);
  353. pxa_set_ficp_info(&spitz_ficp_platform_data);
  354. set_pxa_fb_parent(&spitzssp_device.dev);
  355. set_pxa_fb_info(&spitz_pxafb_info);
  356. }
  357. static void __init spitz_init(void)
  358. {
  359. platform_scoop_config = &spitz_pcmcia_config;
  360. spitz_bl_machinfo.set_bl_intensity = spitz_bl_set_intensity;
  361. common_init();
  362. platform_device_register(&spitzscoop2_device);
  363. }
  364. #ifdef CONFIG_MACH_AKITA
  365. /*
  366. * Akita IO Expander
  367. */
  368. struct platform_device akitaioexp_device = {
  369. .name = "akita-ioexp",
  370. .id = -1,
  371. };
  372. static void __init akita_init(void)
  373. {
  374. spitz_ficp_platform_data.transceiver_mode = akita_irda_transceiver_mode;
  375. /* We just pretend the second element of the array doesn't exist */
  376. spitz_pcmcia_config.num_devs = 1;
  377. platform_scoop_config = &spitz_pcmcia_config;
  378. spitz_bl_machinfo.set_bl_intensity = akita_bl_set_intensity;
  379. platform_device_register(&akitaioexp_device);
  380. spitzscoop_device.dev.parent = &akitaioexp_device.dev;
  381. common_init();
  382. }
  383. #endif
  384. static void __init fixup_spitz(struct machine_desc *desc,
  385. struct tag *tags, char **cmdline, struct meminfo *mi)
  386. {
  387. sharpsl_save_param();
  388. mi->nr_banks = 1;
  389. mi->bank[0].start = 0xa0000000;
  390. mi->bank[0].node = 0;
  391. mi->bank[0].size = (64*1024*1024);
  392. }
  393. #ifdef CONFIG_MACH_SPITZ
  394. MACHINE_START(SPITZ, "SHARP Spitz")
  395. .phys_ram = 0xa0000000,
  396. .phys_io = 0x40000000,
  397. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  398. .fixup = fixup_spitz,
  399. .map_io = pxa_map_io,
  400. .init_irq = pxa_init_irq,
  401. .init_machine = spitz_init,
  402. .timer = &pxa_timer,
  403. MACHINE_END
  404. #endif
  405. #ifdef CONFIG_MACH_BORZOI
  406. MACHINE_START(BORZOI, "SHARP Borzoi")
  407. .phys_ram = 0xa0000000,
  408. .phys_io = 0x40000000,
  409. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  410. .fixup = fixup_spitz,
  411. .map_io = pxa_map_io,
  412. .init_irq = pxa_init_irq,
  413. .init_machine = spitz_init,
  414. .timer = &pxa_timer,
  415. MACHINE_END
  416. #endif
  417. #ifdef CONFIG_MACH_AKITA
  418. MACHINE_START(AKITA, "SHARP Akita")
  419. .phys_ram = 0xa0000000,
  420. .phys_io = 0x40000000,
  421. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  422. .fixup = fixup_spitz,
  423. .map_io = pxa_map_io,
  424. .init_irq = pxa_init_irq,
  425. .init_machine = akita_init,
  426. .timer = &pxa_timer,
  427. MACHINE_END
  428. #endif