corgi.c 14 KB

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