spitz.c 14 KB

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