corgi.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /*
  2. * Support for Sharp SL-C7xx PDAs
  3. * Models: SL-C700 (Corgi), SL-C750 (Shepherd), SL-C760 (Husky)
  4. *
  5. * Copyright (c) 2004-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/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/backlight.h>
  23. #include <video/w100fb.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/pxa2xx-gpio.h>
  36. #include <asm/arch/irda.h>
  37. #include <asm/arch/mmc.h>
  38. #include <asm/arch/udc.h>
  39. #include <asm/arch/corgi.h>
  40. #include <asm/arch/sharpsl.h>
  41. #include <asm/mach/sharpsl_param.h>
  42. #include <asm/hardware/scoop.h>
  43. #include "generic.h"
  44. #include "devices.h"
  45. #include "sharpsl.h"
  46. /*
  47. * Corgi SCOOP Device
  48. */
  49. static struct resource corgi_scoop_resources[] = {
  50. [0] = {
  51. .start = 0x10800000,
  52. .end = 0x10800fff,
  53. .flags = IORESOURCE_MEM,
  54. },
  55. };
  56. static struct scoop_config corgi_scoop_setup = {
  57. .io_dir = CORGI_SCOOP_IO_DIR,
  58. .io_out = CORGI_SCOOP_IO_OUT,
  59. };
  60. struct platform_device corgiscoop_device = {
  61. .name = "sharp-scoop",
  62. .id = -1,
  63. .dev = {
  64. .platform_data = &corgi_scoop_setup,
  65. },
  66. .num_resources = ARRAY_SIZE(corgi_scoop_resources),
  67. .resource = corgi_scoop_resources,
  68. };
  69. static void corgi_pcmcia_init(void)
  70. {
  71. /* Setup default state of GPIO outputs
  72. before we enable them as outputs. */
  73. GPSR(GPIO48_nPOE) = GPIO_bit(GPIO48_nPOE) |
  74. GPIO_bit(GPIO49_nPWE) | GPIO_bit(GPIO50_nPIOR) |
  75. GPIO_bit(GPIO51_nPIOW) | GPIO_bit(GPIO52_nPCE_1) |
  76. GPIO_bit(GPIO53_nPCE_2);
  77. pxa_gpio_mode(GPIO48_nPOE_MD);
  78. pxa_gpio_mode(GPIO49_nPWE_MD);
  79. pxa_gpio_mode(GPIO50_nPIOR_MD);
  80. pxa_gpio_mode(GPIO51_nPIOW_MD);
  81. pxa_gpio_mode(GPIO55_nPREG_MD);
  82. pxa_gpio_mode(GPIO56_nPWAIT_MD);
  83. pxa_gpio_mode(GPIO57_nIOIS16_MD);
  84. pxa_gpio_mode(GPIO52_nPCE_1_MD);
  85. pxa_gpio_mode(GPIO53_nPCE_2_MD);
  86. pxa_gpio_mode(GPIO54_pSKTSEL_MD);
  87. }
  88. static struct scoop_pcmcia_dev corgi_pcmcia_scoop[] = {
  89. {
  90. .dev = &corgiscoop_device.dev,
  91. .irq = CORGI_IRQ_GPIO_CF_IRQ,
  92. .cd_irq = CORGI_IRQ_GPIO_CF_CD,
  93. .cd_irq_str = "PCMCIA0 CD",
  94. },
  95. };
  96. static struct scoop_pcmcia_config corgi_pcmcia_config = {
  97. .devs = &corgi_pcmcia_scoop[0],
  98. .num_devs = 1,
  99. .pcmcia_init = corgi_pcmcia_init,
  100. };
  101. EXPORT_SYMBOL(corgiscoop_device);
  102. /*
  103. * Corgi SSP Device
  104. *
  105. * Set the parent as the scoop device because a lot of SSP devices
  106. * also use scoop functions and this makes the power up/down order
  107. * work correctly.
  108. */
  109. struct platform_device corgissp_device = {
  110. .name = "corgi-ssp",
  111. .dev = {
  112. .parent = &corgiscoop_device.dev,
  113. },
  114. .id = -1,
  115. };
  116. struct corgissp_machinfo corgi_ssp_machinfo = {
  117. .port = 1,
  118. .cs_lcdcon = CORGI_GPIO_LCDCON_CS,
  119. .cs_ads7846 = CORGI_GPIO_ADS7846_CS,
  120. .cs_max1111 = CORGI_GPIO_MAX1111_CS,
  121. .clk_lcdcon = 76,
  122. .clk_ads7846 = 2,
  123. .clk_max1111 = 8,
  124. };
  125. /*
  126. * LCD/Framebuffer
  127. */
  128. static void w100_lcdtg_suspend(struct w100fb_par *par)
  129. {
  130. corgi_lcdtg_suspend();
  131. }
  132. static void w100_lcdtg_init(struct w100fb_par *par)
  133. {
  134. corgi_lcdtg_hw_init(par->xres);
  135. }
  136. static struct w100_tg_info corgi_lcdtg_info = {
  137. .change = w100_lcdtg_init,
  138. .suspend = w100_lcdtg_suspend,
  139. .resume = w100_lcdtg_init,
  140. };
  141. static struct w100_mem_info corgi_fb_mem = {
  142. .ext_cntl = 0x00040003,
  143. .sdram_mode_reg = 0x00650021,
  144. .ext_timing_cntl = 0x10002a4a,
  145. .io_cntl = 0x7ff87012,
  146. .size = 0x1fffff,
  147. };
  148. static struct w100_gen_regs corgi_fb_regs = {
  149. .lcd_format = 0x00000003,
  150. .lcdd_cntl1 = 0x01CC0000,
  151. .lcdd_cntl2 = 0x0003FFFF,
  152. .genlcd_cntl1 = 0x00FFFF0D,
  153. .genlcd_cntl2 = 0x003F3003,
  154. .genlcd_cntl3 = 0x000102aa,
  155. };
  156. static struct w100_gpio_regs corgi_fb_gpio = {
  157. .init_data1 = 0x000000bf,
  158. .init_data2 = 0x00000000,
  159. .gpio_dir1 = 0x00000000,
  160. .gpio_oe1 = 0x03c0feff,
  161. .gpio_dir2 = 0x00000000,
  162. .gpio_oe2 = 0x00000000,
  163. };
  164. static struct w100_mode corgi_fb_modes[] = {
  165. {
  166. .xres = 480,
  167. .yres = 640,
  168. .left_margin = 0x56,
  169. .right_margin = 0x55,
  170. .upper_margin = 0x03,
  171. .lower_margin = 0x00,
  172. .crtc_ss = 0x82360056,
  173. .crtc_ls = 0xA0280000,
  174. .crtc_gs = 0x80280028,
  175. .crtc_vpos_gs = 0x02830002,
  176. .crtc_rev = 0x00400008,
  177. .crtc_dclk = 0xA0000000,
  178. .crtc_gclk = 0x8015010F,
  179. .crtc_goe = 0x80100110,
  180. .crtc_ps1_active = 0x41060010,
  181. .pll_freq = 75,
  182. .fast_pll_freq = 100,
  183. .sysclk_src = CLK_SRC_PLL,
  184. .sysclk_divider = 0,
  185. .pixclk_src = CLK_SRC_PLL,
  186. .pixclk_divider = 2,
  187. .pixclk_divider_rotated = 6,
  188. },{
  189. .xres = 240,
  190. .yres = 320,
  191. .left_margin = 0x27,
  192. .right_margin = 0x2e,
  193. .upper_margin = 0x01,
  194. .lower_margin = 0x00,
  195. .crtc_ss = 0x81170027,
  196. .crtc_ls = 0xA0140000,
  197. .crtc_gs = 0xC0140014,
  198. .crtc_vpos_gs = 0x00010141,
  199. .crtc_rev = 0x00400008,
  200. .crtc_dclk = 0xA0000000,
  201. .crtc_gclk = 0x8015010F,
  202. .crtc_goe = 0x80100110,
  203. .crtc_ps1_active = 0x41060010,
  204. .pll_freq = 0,
  205. .fast_pll_freq = 0,
  206. .sysclk_src = CLK_SRC_XTAL,
  207. .sysclk_divider = 0,
  208. .pixclk_src = CLK_SRC_XTAL,
  209. .pixclk_divider = 1,
  210. .pixclk_divider_rotated = 1,
  211. },
  212. };
  213. static struct w100fb_mach_info corgi_fb_info = {
  214. .tg = &corgi_lcdtg_info,
  215. .init_mode = INIT_MODE_ROTATED,
  216. .mem = &corgi_fb_mem,
  217. .regs = &corgi_fb_regs,
  218. .modelist = &corgi_fb_modes[0],
  219. .num_modes = 2,
  220. .gpio = &corgi_fb_gpio,
  221. .xtal_freq = 12500000,
  222. .xtal_dbl = 0,
  223. };
  224. static struct resource corgi_fb_resources[] = {
  225. [0] = {
  226. .start = 0x08000000,
  227. .end = 0x08ffffff,
  228. .flags = IORESOURCE_MEM,
  229. },
  230. };
  231. static struct platform_device corgifb_device = {
  232. .name = "w100fb",
  233. .id = -1,
  234. .num_resources = ARRAY_SIZE(corgi_fb_resources),
  235. .resource = corgi_fb_resources,
  236. .dev = {
  237. .platform_data = &corgi_fb_info,
  238. .parent = &corgissp_device.dev,
  239. },
  240. };
  241. /*
  242. * Corgi Backlight Device
  243. */
  244. static void corgi_bl_kick_battery(void)
  245. {
  246. void (*kick_batt)(void);
  247. kick_batt = symbol_get(sharpsl_battery_kick);
  248. if (kick_batt) {
  249. kick_batt();
  250. symbol_put(sharpsl_battery_kick);
  251. }
  252. }
  253. static void corgi_bl_set_intensity(int intensity)
  254. {
  255. if (intensity > 0x10)
  256. intensity += 0x10;
  257. /* Bits 0-4 are accessed via the SSP interface */
  258. corgi_ssp_blduty_set(intensity & 0x1f);
  259. /* Bit 5 is via SCOOP */
  260. if (intensity & 0x0020)
  261. set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_BACKLIGHT_CONT);
  262. else
  263. reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_BACKLIGHT_CONT);
  264. }
  265. static struct generic_bl_info corgi_bl_machinfo = {
  266. .name = "corgi-bl",
  267. .max_intensity = 0x2f,
  268. .default_intensity = 0x1f,
  269. .limit_mask = 0x0b,
  270. .set_bl_intensity = corgi_bl_set_intensity,
  271. .kick_battery = corgi_bl_kick_battery,
  272. };
  273. static struct platform_device corgibl_device = {
  274. .name = "generic-bl",
  275. .dev = {
  276. .parent = &corgifb_device.dev,
  277. .platform_data = &corgi_bl_machinfo,
  278. },
  279. .id = -1,
  280. };
  281. /*
  282. * Corgi Keyboard Device
  283. */
  284. static struct platform_device corgikbd_device = {
  285. .name = "corgi-keyboard",
  286. .id = -1,
  287. };
  288. /*
  289. * Corgi LEDs
  290. */
  291. static struct platform_device corgiled_device = {
  292. .name = "corgi-led",
  293. .id = -1,
  294. };
  295. /*
  296. * Corgi Touch Screen Device
  297. */
  298. static unsigned long (*get_hsync_invperiod)(struct device *dev);
  299. static void inline sharpsl_wait_sync(int gpio)
  300. {
  301. while((GPLR(gpio) & GPIO_bit(gpio)) == 0);
  302. while((GPLR(gpio) & GPIO_bit(gpio)) != 0);
  303. }
  304. static unsigned long corgi_get_hsync_invperiod(void)
  305. {
  306. if (!get_hsync_invperiod)
  307. get_hsync_invperiod = symbol_get(w100fb_get_hsynclen);
  308. if (!get_hsync_invperiod)
  309. return 0;
  310. return get_hsync_invperiod(&corgifb_device.dev);
  311. }
  312. static void corgi_put_hsync(void)
  313. {
  314. if (get_hsync_invperiod)
  315. symbol_put(w100fb_get_hsynclen);
  316. get_hsync_invperiod = NULL;
  317. }
  318. static void corgi_wait_hsync(void)
  319. {
  320. sharpsl_wait_sync(CORGI_GPIO_HSYNC);
  321. }
  322. static struct resource corgits_resources[] = {
  323. [0] = {
  324. .start = CORGI_IRQ_GPIO_TP_INT,
  325. .end = CORGI_IRQ_GPIO_TP_INT,
  326. .flags = IORESOURCE_IRQ,
  327. },
  328. };
  329. static struct corgits_machinfo corgi_ts_machinfo = {
  330. .get_hsync_invperiod = corgi_get_hsync_invperiod,
  331. .put_hsync = corgi_put_hsync,
  332. .wait_hsync = corgi_wait_hsync,
  333. };
  334. static struct platform_device corgits_device = {
  335. .name = "corgi-ts",
  336. .dev = {
  337. .parent = &corgissp_device.dev,
  338. .platform_data = &corgi_ts_machinfo,
  339. },
  340. .id = -1,
  341. .num_resources = ARRAY_SIZE(corgits_resources),
  342. .resource = corgits_resources,
  343. };
  344. /*
  345. * MMC/SD Device
  346. *
  347. * The card detect interrupt isn't debounced so we delay it by 250ms
  348. * to give the card a chance to fully insert/eject.
  349. */
  350. static struct pxamci_platform_data corgi_mci_platform_data;
  351. static int corgi_mci_init(struct device *dev, irq_handler_t corgi_detect_int, void *data)
  352. {
  353. int err;
  354. /* setup GPIO for PXA25x MMC controller */
  355. pxa_gpio_mode(GPIO6_MMCCLK_MD);
  356. pxa_gpio_mode(GPIO8_MMCCS0_MD);
  357. pxa_gpio_mode(CORGI_GPIO_nSD_DETECT | GPIO_IN);
  358. pxa_gpio_mode(CORGI_GPIO_SD_PWR | GPIO_OUT);
  359. corgi_mci_platform_data.detect_delay = msecs_to_jiffies(250);
  360. err = request_irq(CORGI_IRQ_GPIO_nSD_DETECT, corgi_detect_int,
  361. IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
  362. "MMC card detect", data);
  363. if (err)
  364. printk(KERN_ERR "corgi_mci_init: MMC/SD: can't request MMC card detect IRQ\n");
  365. return err;
  366. }
  367. static void corgi_mci_setpower(struct device *dev, unsigned int vdd)
  368. {
  369. struct pxamci_platform_data* p_d = dev->platform_data;
  370. if (( 1 << vdd) & p_d->ocr_mask)
  371. GPSR1 = GPIO_bit(CORGI_GPIO_SD_PWR);
  372. else
  373. GPCR1 = GPIO_bit(CORGI_GPIO_SD_PWR);
  374. }
  375. static int corgi_mci_get_ro(struct device *dev)
  376. {
  377. return GPLR(CORGI_GPIO_nSD_WP) & GPIO_bit(CORGI_GPIO_nSD_WP);
  378. }
  379. static void corgi_mci_exit(struct device *dev, void *data)
  380. {
  381. free_irq(CORGI_IRQ_GPIO_nSD_DETECT, data);
  382. }
  383. static struct pxamci_platform_data corgi_mci_platform_data = {
  384. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  385. .init = corgi_mci_init,
  386. .get_ro = corgi_mci_get_ro,
  387. .setpower = corgi_mci_setpower,
  388. .exit = corgi_mci_exit,
  389. };
  390. /*
  391. * Irda
  392. */
  393. static void corgi_irda_transceiver_mode(struct device *dev, int mode)
  394. {
  395. if (mode & IR_OFF)
  396. GPSR(CORGI_GPIO_IR_ON) = GPIO_bit(CORGI_GPIO_IR_ON);
  397. else
  398. GPCR(CORGI_GPIO_IR_ON) = GPIO_bit(CORGI_GPIO_IR_ON);
  399. }
  400. static struct pxaficp_platform_data corgi_ficp_platform_data = {
  401. .transceiver_cap = IR_SIRMODE | IR_OFF,
  402. .transceiver_mode = corgi_irda_transceiver_mode,
  403. };
  404. /*
  405. * USB Device Controller
  406. */
  407. static struct pxa2xx_udc_mach_info udc_info __initdata = {
  408. /* no connect GPIO; corgi can't tell connection status */
  409. .gpio_pullup = CORGI_GPIO_USB_PULLUP,
  410. };
  411. static struct platform_device *devices[] __initdata = {
  412. &corgiscoop_device,
  413. &corgissp_device,
  414. &corgifb_device,
  415. &corgikbd_device,
  416. &corgibl_device,
  417. &corgits_device,
  418. &corgiled_device,
  419. };
  420. static void corgi_poweroff(void)
  421. {
  422. RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR;
  423. if (!machine_is_corgi())
  424. /* Green LED off tells the bootloader to halt */
  425. reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_LED_GREEN);
  426. arm_machine_restart('h');
  427. }
  428. static void corgi_restart(char mode)
  429. {
  430. RCSR = RCSR_HWR | RCSR_WDR | RCSR_SMR | RCSR_GPR;
  431. if (!machine_is_corgi())
  432. /* Green LED on tells the bootloader to reboot */
  433. set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_LED_GREEN);
  434. arm_machine_restart('h');
  435. }
  436. static void __init corgi_init(void)
  437. {
  438. pm_power_off = corgi_poweroff;
  439. arm_pm_restart = corgi_restart;
  440. /* setup sleep mode values */
  441. PWER = 0x00000002;
  442. PFER = 0x00000000;
  443. PRER = 0x00000002;
  444. PGSR0 = 0x0158C000;
  445. PGSR1 = 0x00FF0080;
  446. PGSR2 = 0x0001C004;
  447. /* Stop 3.6MHz and drive HIGH to PCMCIA and CS */
  448. PCFR |= PCFR_OPDE;
  449. corgi_ssp_set_machinfo(&corgi_ssp_machinfo);
  450. pxa_gpio_mode(CORGI_GPIO_IR_ON | GPIO_OUT);
  451. pxa_gpio_mode(CORGI_GPIO_HSYNC | GPIO_IN);
  452. pxa_set_udc_info(&udc_info);
  453. pxa_set_mci_info(&corgi_mci_platform_data);
  454. pxa_set_ficp_info(&corgi_ficp_platform_data);
  455. platform_scoop_config = &corgi_pcmcia_config;
  456. platform_add_devices(devices, ARRAY_SIZE(devices));
  457. }
  458. static void __init fixup_corgi(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. if (machine_is_corgi())
  466. mi->bank[0].size = (32*1024*1024);
  467. else
  468. mi->bank[0].size = (64*1024*1024);
  469. }
  470. #ifdef CONFIG_MACH_CORGI
  471. MACHINE_START(CORGI, "SHARP Corgi")
  472. .phys_io = 0x40000000,
  473. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  474. .fixup = fixup_corgi,
  475. .map_io = pxa_map_io,
  476. .init_irq = pxa25x_init_irq,
  477. .init_machine = corgi_init,
  478. .timer = &pxa_timer,
  479. MACHINE_END
  480. #endif
  481. #ifdef CONFIG_MACH_SHEPHERD
  482. MACHINE_START(SHEPHERD, "SHARP Shepherd")
  483. .phys_io = 0x40000000,
  484. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  485. .fixup = fixup_corgi,
  486. .map_io = pxa_map_io,
  487. .init_irq = pxa25x_init_irq,
  488. .init_machine = corgi_init,
  489. .timer = &pxa_timer,
  490. MACHINE_END
  491. #endif
  492. #ifdef CONFIG_MACH_HUSKY
  493. MACHINE_START(HUSKY, "SHARP Husky")
  494. .phys_io = 0x40000000,
  495. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  496. .fixup = fixup_corgi,
  497. .map_io = pxa_map_io,
  498. .init_irq = pxa25x_init_irq,
  499. .init_machine = corgi_init,
  500. .timer = &pxa_timer,
  501. MACHINE_END
  502. #endif