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