spitz.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  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/irda.h>
  33. #include <asm/arch/mmc.h>
  34. #include <asm/arch/ohci.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. if (!(cpr & 0x0002) && !(cpr & 0x0004)) {
  115. write_scoop_reg(&spitzscoop_device.dev, SCOOP_CPR, 0x0000);
  116. mdelay(1);
  117. reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_CF_POWER);
  118. } else {
  119. write_scoop_reg(&spitzscoop_device.dev, SCOOP_CPR, cpr | new_cpr);
  120. }
  121. }
  122. }
  123. static void spitz_pcmcia_init(void)
  124. {
  125. /* Setup default state of GPIO outputs
  126. before we enable them as outputs. */
  127. GPSR(GPIO48_nPOE) = GPIO_bit(GPIO48_nPOE) |
  128. GPIO_bit(GPIO49_nPWE) | GPIO_bit(GPIO50_nPIOR) |
  129. GPIO_bit(GPIO51_nPIOW) | GPIO_bit(GPIO54_nPCE_2);
  130. GPSR(GPIO85_nPCE_1) = GPIO_bit(GPIO85_nPCE_1);
  131. pxa_gpio_mode(GPIO48_nPOE_MD);
  132. pxa_gpio_mode(GPIO49_nPWE_MD);
  133. pxa_gpio_mode(GPIO50_nPIOR_MD);
  134. pxa_gpio_mode(GPIO51_nPIOW_MD);
  135. pxa_gpio_mode(GPIO55_nPREG_MD);
  136. pxa_gpio_mode(GPIO56_nPWAIT_MD);
  137. pxa_gpio_mode(GPIO57_nIOIS16_MD);
  138. pxa_gpio_mode(GPIO85_nPCE_1_MD);
  139. pxa_gpio_mode(GPIO54_nPCE_2_MD);
  140. pxa_gpio_mode(GPIO104_pSKTSEL_MD);
  141. }
  142. static void spitz_pcmcia_pwr(struct device *scoop, unsigned short cpr, int nr)
  143. {
  144. /* Only need to override behaviour for slot 0 */
  145. if (nr == 0)
  146. spitz_card_pwr_ctrl(SPITZ_PWR_CF, cpr);
  147. else
  148. write_scoop_reg(scoop, SCOOP_CPR, cpr);
  149. }
  150. static struct scoop_pcmcia_dev spitz_pcmcia_scoop[] = {
  151. {
  152. .dev = &spitzscoop_device.dev,
  153. .irq = SPITZ_IRQ_GPIO_CF_IRQ,
  154. .cd_irq = SPITZ_IRQ_GPIO_CF_CD,
  155. .cd_irq_str = "PCMCIA0 CD",
  156. },{
  157. .dev = &spitzscoop2_device.dev,
  158. .irq = SPITZ_IRQ_GPIO_CF2_IRQ,
  159. .cd_irq = -1,
  160. },
  161. };
  162. static struct scoop_pcmcia_config spitz_pcmcia_config = {
  163. .devs = &spitz_pcmcia_scoop[0],
  164. .num_devs = 2,
  165. .pcmcia_init = spitz_pcmcia_init,
  166. .power_ctrl = spitz_pcmcia_pwr,
  167. };
  168. EXPORT_SYMBOL(spitzscoop_device);
  169. EXPORT_SYMBOL(spitzscoop2_device);
  170. /*
  171. * Spitz SSP Device
  172. *
  173. * Set the parent as the scoop device because a lot of SSP devices
  174. * also use scoop functions and this makes the power up/down order
  175. * work correctly.
  176. */
  177. struct platform_device spitzssp_device = {
  178. .name = "corgi-ssp",
  179. .dev = {
  180. .parent = &spitzscoop_device.dev,
  181. },
  182. .id = -1,
  183. };
  184. struct corgissp_machinfo spitz_ssp_machinfo = {
  185. .port = 2,
  186. .cs_lcdcon = SPITZ_GPIO_LCDCON_CS,
  187. .cs_ads7846 = SPITZ_GPIO_ADS7846_CS,
  188. .cs_max1111 = SPITZ_GPIO_MAX1111_CS,
  189. .clk_lcdcon = 520,
  190. .clk_ads7846 = 14,
  191. .clk_max1111 = 56,
  192. };
  193. /*
  194. * Spitz Backlight Device
  195. */
  196. static struct corgibl_machinfo spitz_bl_machinfo = {
  197. .default_intensity = 0x1f,
  198. .limit_mask = 0x0b,
  199. .max_intensity = 0x2f,
  200. };
  201. static struct platform_device spitzbl_device = {
  202. .name = "corgi-bl",
  203. .dev = {
  204. .platform_data = &spitz_bl_machinfo,
  205. },
  206. .id = -1,
  207. };
  208. /*
  209. * Spitz Keyboard Device
  210. */
  211. static struct platform_device spitzkbd_device = {
  212. .name = "spitz-keyboard",
  213. .id = -1,
  214. };
  215. /*
  216. * Spitz LEDs
  217. */
  218. static struct platform_device spitzled_device = {
  219. .name = "spitz-led",
  220. .id = -1,
  221. };
  222. /*
  223. * Spitz Touch Screen Device
  224. */
  225. static struct resource spitzts_resources[] = {
  226. [0] = {
  227. .start = SPITZ_IRQ_GPIO_TP_INT,
  228. .end = SPITZ_IRQ_GPIO_TP_INT,
  229. .flags = IORESOURCE_IRQ,
  230. },
  231. };
  232. static struct corgits_machinfo spitz_ts_machinfo = {
  233. .get_hsync_len = spitz_get_hsync_len,
  234. .put_hsync = spitz_put_hsync,
  235. .wait_hsync = spitz_wait_hsync,
  236. };
  237. static struct platform_device spitzts_device = {
  238. .name = "corgi-ts",
  239. .dev = {
  240. .parent = &spitzssp_device.dev,
  241. .platform_data = &spitz_ts_machinfo,
  242. },
  243. .id = -1,
  244. .num_resources = ARRAY_SIZE(spitzts_resources),
  245. .resource = spitzts_resources,
  246. };
  247. /*
  248. * MMC/SD Device
  249. *
  250. * The card detect interrupt isn't debounced so we delay it by 250ms
  251. * to give the card a chance to fully insert/eject.
  252. */
  253. static struct pxamci_platform_data spitz_mci_platform_data;
  254. static int spitz_mci_init(struct device *dev, irqreturn_t (*spitz_detect_int)(int, void *, struct pt_regs *), void *data)
  255. {
  256. int err;
  257. /* setup GPIO for PXA27x MMC controller */
  258. pxa_gpio_mode(GPIO32_MMCCLK_MD);
  259. pxa_gpio_mode(GPIO112_MMCCMD_MD);
  260. pxa_gpio_mode(GPIO92_MMCDAT0_MD);
  261. pxa_gpio_mode(GPIO109_MMCDAT1_MD);
  262. pxa_gpio_mode(GPIO110_MMCDAT2_MD);
  263. pxa_gpio_mode(GPIO111_MMCDAT3_MD);
  264. pxa_gpio_mode(SPITZ_GPIO_nSD_DETECT | GPIO_IN);
  265. pxa_gpio_mode(SPITZ_GPIO_nSD_WP | GPIO_IN);
  266. spitz_mci_platform_data.detect_delay = msecs_to_jiffies(250);
  267. err = request_irq(SPITZ_IRQ_GPIO_nSD_DETECT, spitz_detect_int,
  268. SA_INTERRUPT | SA_TRIGGER_RISING | SA_TRIGGER_FALLING,
  269. "MMC card detect", data);
  270. if (err) {
  271. printk(KERN_ERR "spitz_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
  272. return -1;
  273. }
  274. return 0;
  275. }
  276. static void spitz_mci_setpower(struct device *dev, unsigned int vdd)
  277. {
  278. struct pxamci_platform_data* p_d = dev->platform_data;
  279. if (( 1 << vdd) & p_d->ocr_mask)
  280. spitz_card_pwr_ctrl(SPITZ_PWR_SD, 0x0004);
  281. else
  282. spitz_card_pwr_ctrl(SPITZ_PWR_SD, 0x0000);
  283. }
  284. static int spitz_mci_get_ro(struct device *dev)
  285. {
  286. return GPLR(SPITZ_GPIO_nSD_WP) & GPIO_bit(SPITZ_GPIO_nSD_WP);
  287. }
  288. static void spitz_mci_exit(struct device *dev, void *data)
  289. {
  290. free_irq(SPITZ_IRQ_GPIO_nSD_DETECT, data);
  291. }
  292. static struct pxamci_platform_data spitz_mci_platform_data = {
  293. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  294. .init = spitz_mci_init,
  295. .get_ro = spitz_mci_get_ro,
  296. .setpower = spitz_mci_setpower,
  297. .exit = spitz_mci_exit,
  298. };
  299. /*
  300. * USB Host (OHCI)
  301. */
  302. static int spitz_ohci_init(struct device *dev)
  303. {
  304. /* Only Port 2 is connected */
  305. pxa_gpio_mode(SPITZ_GPIO_USB_CONNECT | GPIO_IN);
  306. pxa_gpio_mode(SPITZ_GPIO_USB_HOST | GPIO_OUT);
  307. pxa_gpio_mode(SPITZ_GPIO_USB_DEVICE | GPIO_IN);
  308. /* Setup USB Port 2 Output Control Register */
  309. UP2OCR = UP2OCR_HXS | UP2OCR_HXOE | UP2OCR_DPPDE | UP2OCR_DMPDE;
  310. GPSR(SPITZ_GPIO_USB_HOST) = GPIO_bit(SPITZ_GPIO_USB_HOST);
  311. UHCHR = (UHCHR) &
  312. ~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSEP3 | UHCHR_SSE);
  313. UHCRHDA |= UHCRHDA_NOCP;
  314. return 0;
  315. }
  316. static struct pxaohci_platform_data spitz_ohci_platform_data = {
  317. .port_mode = PMM_NPS_MODE,
  318. .init = spitz_ohci_init,
  319. };
  320. /*
  321. * Irda
  322. */
  323. static void spitz_irda_transceiver_mode(struct device *dev, int mode)
  324. {
  325. if (mode & IR_OFF)
  326. set_scoop_gpio(&spitzscoop2_device.dev, SPITZ_SCP2_IR_ON);
  327. else
  328. reset_scoop_gpio(&spitzscoop2_device.dev, SPITZ_SCP2_IR_ON);
  329. }
  330. #ifdef CONFIG_MACH_AKITA
  331. static void akita_irda_transceiver_mode(struct device *dev, int mode)
  332. {
  333. if (mode & IR_OFF)
  334. akita_set_ioexp(&akitaioexp_device.dev, AKITA_IOEXP_IR_ON);
  335. else
  336. akita_reset_ioexp(&akitaioexp_device.dev, AKITA_IOEXP_IR_ON);
  337. }
  338. #endif
  339. static struct pxaficp_platform_data spitz_ficp_platform_data = {
  340. .transceiver_cap = IR_SIRMODE | IR_OFF,
  341. .transceiver_mode = spitz_irda_transceiver_mode,
  342. };
  343. /*
  344. * Spitz PXA Framebuffer
  345. */
  346. static struct pxafb_mach_info spitz_pxafb_info __initdata = {
  347. .pixclock = 19231,
  348. .xres = 480,
  349. .yres = 640,
  350. .bpp = 16,
  351. .hsync_len = 40,
  352. .left_margin = 46,
  353. .right_margin = 125,
  354. .vsync_len = 3,
  355. .upper_margin = 1,
  356. .lower_margin = 0,
  357. .sync = 0,
  358. .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act | LCCR0_LDDALT | LCCR0_OUC | LCCR0_CMDIM | LCCR0_RDSTM,
  359. .lccr3 = LCCR3_PixRsEdg | LCCR3_OutEnH,
  360. .pxafb_lcd_power = spitz_lcd_power,
  361. };
  362. static struct platform_device *devices[] __initdata = {
  363. &spitzscoop_device,
  364. &spitzssp_device,
  365. &spitzkbd_device,
  366. &spitzts_device,
  367. &spitzbl_device,
  368. &spitzled_device,
  369. };
  370. static void __init common_init(void)
  371. {
  372. PMCR = 0x00;
  373. /* setup sleep mode values */
  374. PWER = 0x00000002;
  375. PFER = 0x00000000;
  376. PRER = 0x00000002;
  377. PGSR0 = 0x0158C000;
  378. PGSR1 = 0x00FF0080;
  379. PGSR2 = 0x0001C004;
  380. /* Stop 3.6MHz and drive HIGH to PCMCIA and CS */
  381. PCFR |= PCFR_OPDE;
  382. corgi_ssp_set_machinfo(&spitz_ssp_machinfo);
  383. pxa_gpio_mode(SPITZ_GPIO_HSYNC | GPIO_IN);
  384. platform_add_devices(devices, ARRAY_SIZE(devices));
  385. pxa_set_mci_info(&spitz_mci_platform_data);
  386. pxa_set_ohci_info(&spitz_ohci_platform_data);
  387. pxa_set_ficp_info(&spitz_ficp_platform_data);
  388. set_pxa_fb_parent(&spitzssp_device.dev);
  389. set_pxa_fb_info(&spitz_pxafb_info);
  390. }
  391. static void __init spitz_init(void)
  392. {
  393. platform_scoop_config = &spitz_pcmcia_config;
  394. spitz_bl_machinfo.set_bl_intensity = spitz_bl_set_intensity;
  395. common_init();
  396. platform_device_register(&spitzscoop2_device);
  397. }
  398. #ifdef CONFIG_MACH_AKITA
  399. /*
  400. * Akita IO Expander
  401. */
  402. struct platform_device akitaioexp_device = {
  403. .name = "akita-ioexp",
  404. .id = -1,
  405. };
  406. EXPORT_SYMBOL_GPL(akitaioexp_device);
  407. static void __init akita_init(void)
  408. {
  409. spitz_ficp_platform_data.transceiver_mode = akita_irda_transceiver_mode;
  410. /* We just pretend the second element of the array doesn't exist */
  411. spitz_pcmcia_config.num_devs = 1;
  412. platform_scoop_config = &spitz_pcmcia_config;
  413. spitz_bl_machinfo.set_bl_intensity = akita_bl_set_intensity;
  414. platform_device_register(&akitaioexp_device);
  415. spitzscoop_device.dev.parent = &akitaioexp_device.dev;
  416. common_init();
  417. }
  418. #endif
  419. static void __init fixup_spitz(struct machine_desc *desc,
  420. struct tag *tags, char **cmdline, struct meminfo *mi)
  421. {
  422. sharpsl_save_param();
  423. mi->nr_banks = 1;
  424. mi->bank[0].start = 0xa0000000;
  425. mi->bank[0].node = 0;
  426. mi->bank[0].size = (64*1024*1024);
  427. }
  428. #ifdef CONFIG_MACH_SPITZ
  429. MACHINE_START(SPITZ, "SHARP Spitz")
  430. .phys_io = 0x40000000,
  431. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  432. .fixup = fixup_spitz,
  433. .map_io = pxa_map_io,
  434. .init_irq = pxa_init_irq,
  435. .init_machine = spitz_init,
  436. .timer = &pxa_timer,
  437. MACHINE_END
  438. #endif
  439. #ifdef CONFIG_MACH_BORZOI
  440. MACHINE_START(BORZOI, "SHARP Borzoi")
  441. .phys_io = 0x40000000,
  442. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  443. .fixup = fixup_spitz,
  444. .map_io = pxa_map_io,
  445. .init_irq = pxa_init_irq,
  446. .init_machine = spitz_init,
  447. .timer = &pxa_timer,
  448. MACHINE_END
  449. #endif
  450. #ifdef CONFIG_MACH_AKITA
  451. MACHINE_START(AKITA, "SHARP Akita")
  452. .phys_io = 0x40000000,
  453. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  454. .fixup = fixup_spitz,
  455. .map_io = pxa_map_io,
  456. .init_irq = pxa_init_irq,
  457. .init_machine = akita_init,
  458. .timer = &pxa_timer,
  459. MACHINE_END
  460. #endif