corgi.c 13 KB

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