spitz.c 14 KB

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