corgi.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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 <linux/spi/spi.h>
  25. #include <linux/spi/ads7846.h>
  26. #include <linux/spi/corgi_lcd.h>
  27. #include <video/w100fb.h>
  28. #include <asm/setup.h>
  29. #include <asm/memory.h>
  30. #include <asm/mach-types.h>
  31. #include <mach/hardware.h>
  32. #include <asm/irq.h>
  33. #include <asm/io.h>
  34. #include <asm/system.h>
  35. #include <asm/mach/arch.h>
  36. #include <asm/mach/map.h>
  37. #include <asm/mach/irq.h>
  38. #include <mach/pxa-regs.h>
  39. #include <mach/pxa2xx-regs.h>
  40. #include <mach/mfp-pxa25x.h>
  41. #include <mach/i2c.h>
  42. #include <mach/irda.h>
  43. #include <mach/mmc.h>
  44. #include <mach/udc.h>
  45. #include <mach/pxa2xx_spi.h>
  46. #include <mach/corgi.h>
  47. #include <mach/sharpsl.h>
  48. #include <asm/mach/sharpsl_param.h>
  49. #include <asm/hardware/scoop.h>
  50. #include "generic.h"
  51. #include "devices.h"
  52. #include "sharpsl.h"
  53. static unsigned long corgi_pin_config[] __initdata = {
  54. /* Static Memory I/O */
  55. GPIO78_nCS_2, /* w100fb */
  56. GPIO80_nCS_4, /* scoop */
  57. /* SSP1 */
  58. GPIO23_SSP1_SCLK,
  59. GPIO25_SSP1_TXD,
  60. GPIO26_SSP1_RXD,
  61. GPIO24_GPIO, /* CORGI_GPIO_ADS7846_CS - SFRM as chip select */
  62. /* I2S */
  63. GPIO28_I2S_BITCLK_OUT,
  64. GPIO29_I2S_SDATA_IN,
  65. GPIO30_I2S_SDATA_OUT,
  66. GPIO31_I2S_SYNC,
  67. GPIO32_I2S_SYSCLK,
  68. /* Infra-Red */
  69. GPIO47_FICP_TXD,
  70. GPIO46_FICP_RXD,
  71. /* FFUART */
  72. GPIO40_FFUART_DTR,
  73. GPIO41_FFUART_RTS,
  74. GPIO39_FFUART_TXD,
  75. GPIO37_FFUART_DSR,
  76. GPIO34_FFUART_RXD,
  77. GPIO35_FFUART_CTS,
  78. /* PC Card */
  79. GPIO48_nPOE,
  80. GPIO49_nPWE,
  81. GPIO50_nPIOR,
  82. GPIO51_nPIOW,
  83. GPIO52_nPCE_1,
  84. GPIO53_nPCE_2,
  85. GPIO54_nPSKTSEL,
  86. GPIO55_nPREG,
  87. GPIO56_nPWAIT,
  88. GPIO57_nIOIS16,
  89. /* MMC */
  90. GPIO6_MMC_CLK,
  91. GPIO8_MMC_CS0,
  92. /* GPIO */
  93. GPIO9_GPIO, /* CORGI_GPIO_nSD_DETECT */
  94. GPIO7_GPIO, /* CORGI_GPIO_nSD_WP */
  95. GPIO33_GPIO, /* CORGI_GPIO_SD_PWR */
  96. GPIO22_GPIO, /* CORGI_GPIO_IR_ON */
  97. GPIO44_GPIO, /* CORGI_GPIO_HSYNC */
  98. GPIO1_GPIO | WAKEUP_ON_EDGE_RISE,
  99. };
  100. /*
  101. * Corgi SCOOP Device
  102. */
  103. static struct resource corgi_scoop_resources[] = {
  104. [0] = {
  105. .start = 0x10800000,
  106. .end = 0x10800fff,
  107. .flags = IORESOURCE_MEM,
  108. },
  109. };
  110. static struct scoop_config corgi_scoop_setup = {
  111. .io_dir = CORGI_SCOOP_IO_DIR,
  112. .io_out = CORGI_SCOOP_IO_OUT,
  113. };
  114. struct platform_device corgiscoop_device = {
  115. .name = "sharp-scoop",
  116. .id = -1,
  117. .dev = {
  118. .platform_data = &corgi_scoop_setup,
  119. },
  120. .num_resources = ARRAY_SIZE(corgi_scoop_resources),
  121. .resource = corgi_scoop_resources,
  122. };
  123. static struct scoop_pcmcia_dev corgi_pcmcia_scoop[] = {
  124. {
  125. .dev = &corgiscoop_device.dev,
  126. .irq = CORGI_IRQ_GPIO_CF_IRQ,
  127. .cd_irq = CORGI_IRQ_GPIO_CF_CD,
  128. .cd_irq_str = "PCMCIA0 CD",
  129. },
  130. };
  131. static struct scoop_pcmcia_config corgi_pcmcia_config = {
  132. .devs = &corgi_pcmcia_scoop[0],
  133. .num_devs = 1,
  134. };
  135. EXPORT_SYMBOL(corgiscoop_device);
  136. static struct w100_mem_info corgi_fb_mem = {
  137. .ext_cntl = 0x00040003,
  138. .sdram_mode_reg = 0x00650021,
  139. .ext_timing_cntl = 0x10002a4a,
  140. .io_cntl = 0x7ff87012,
  141. .size = 0x1fffff,
  142. };
  143. static struct w100_gen_regs corgi_fb_regs = {
  144. .lcd_format = 0x00000003,
  145. .lcdd_cntl1 = 0x01CC0000,
  146. .lcdd_cntl2 = 0x0003FFFF,
  147. .genlcd_cntl1 = 0x00FFFF0D,
  148. .genlcd_cntl2 = 0x003F3003,
  149. .genlcd_cntl3 = 0x000102aa,
  150. };
  151. static struct w100_gpio_regs corgi_fb_gpio = {
  152. .init_data1 = 0x000000bf,
  153. .init_data2 = 0x00000000,
  154. .gpio_dir1 = 0x00000000,
  155. .gpio_oe1 = 0x03c0feff,
  156. .gpio_dir2 = 0x00000000,
  157. .gpio_oe2 = 0x00000000,
  158. };
  159. static struct w100_mode corgi_fb_modes[] = {
  160. {
  161. .xres = 480,
  162. .yres = 640,
  163. .left_margin = 0x56,
  164. .right_margin = 0x55,
  165. .upper_margin = 0x03,
  166. .lower_margin = 0x00,
  167. .crtc_ss = 0x82360056,
  168. .crtc_ls = 0xA0280000,
  169. .crtc_gs = 0x80280028,
  170. .crtc_vpos_gs = 0x02830002,
  171. .crtc_rev = 0x00400008,
  172. .crtc_dclk = 0xA0000000,
  173. .crtc_gclk = 0x8015010F,
  174. .crtc_goe = 0x80100110,
  175. .crtc_ps1_active = 0x41060010,
  176. .pll_freq = 75,
  177. .fast_pll_freq = 100,
  178. .sysclk_src = CLK_SRC_PLL,
  179. .sysclk_divider = 0,
  180. .pixclk_src = CLK_SRC_PLL,
  181. .pixclk_divider = 2,
  182. .pixclk_divider_rotated = 6,
  183. },{
  184. .xres = 240,
  185. .yres = 320,
  186. .left_margin = 0x27,
  187. .right_margin = 0x2e,
  188. .upper_margin = 0x01,
  189. .lower_margin = 0x00,
  190. .crtc_ss = 0x81170027,
  191. .crtc_ls = 0xA0140000,
  192. .crtc_gs = 0xC0140014,
  193. .crtc_vpos_gs = 0x00010141,
  194. .crtc_rev = 0x00400008,
  195. .crtc_dclk = 0xA0000000,
  196. .crtc_gclk = 0x8015010F,
  197. .crtc_goe = 0x80100110,
  198. .crtc_ps1_active = 0x41060010,
  199. .pll_freq = 0,
  200. .fast_pll_freq = 0,
  201. .sysclk_src = CLK_SRC_XTAL,
  202. .sysclk_divider = 0,
  203. .pixclk_src = CLK_SRC_XTAL,
  204. .pixclk_divider = 1,
  205. .pixclk_divider_rotated = 1,
  206. },
  207. };
  208. static struct w100fb_mach_info corgi_fb_info = {
  209. .init_mode = INIT_MODE_ROTATED,
  210. .mem = &corgi_fb_mem,
  211. .regs = &corgi_fb_regs,
  212. .modelist = &corgi_fb_modes[0],
  213. .num_modes = 2,
  214. .gpio = &corgi_fb_gpio,
  215. .xtal_freq = 12500000,
  216. .xtal_dbl = 0,
  217. };
  218. static struct resource corgi_fb_resources[] = {
  219. [0] = {
  220. .start = 0x08000000,
  221. .end = 0x08ffffff,
  222. .flags = IORESOURCE_MEM,
  223. },
  224. };
  225. static struct platform_device corgifb_device = {
  226. .name = "w100fb",
  227. .id = -1,
  228. .num_resources = ARRAY_SIZE(corgi_fb_resources),
  229. .resource = corgi_fb_resources,
  230. .dev = {
  231. .platform_data = &corgi_fb_info,
  232. },
  233. };
  234. /*
  235. * Corgi Keyboard Device
  236. */
  237. static struct platform_device corgikbd_device = {
  238. .name = "corgi-keyboard",
  239. .id = -1,
  240. };
  241. /*
  242. * Corgi LEDs
  243. */
  244. static struct platform_device corgiled_device = {
  245. .name = "corgi-led",
  246. .id = -1,
  247. };
  248. /*
  249. * MMC/SD Device
  250. *
  251. * The card detect interrupt isn't debounced so we delay it by 250ms
  252. * to give the card a chance to fully insert/eject.
  253. */
  254. static struct pxamci_platform_data corgi_mci_platform_data;
  255. static int corgi_mci_init(struct device *dev, irq_handler_t corgi_detect_int, void *data)
  256. {
  257. int err;
  258. err = gpio_request(CORGI_GPIO_nSD_DETECT, "nSD_DETECT");
  259. if (err)
  260. goto err_out;
  261. err = gpio_request(CORGI_GPIO_nSD_WP, "nSD_WP");
  262. if (err)
  263. goto err_free_1;
  264. err = gpio_request(CORGI_GPIO_SD_PWR, "SD_PWR");
  265. if (err)
  266. goto err_free_2;
  267. gpio_direction_input(CORGI_GPIO_nSD_DETECT);
  268. gpio_direction_input(CORGI_GPIO_nSD_WP);
  269. gpio_direction_output(CORGI_GPIO_SD_PWR, 0);
  270. corgi_mci_platform_data.detect_delay = msecs_to_jiffies(250);
  271. err = request_irq(CORGI_IRQ_GPIO_nSD_DETECT, corgi_detect_int,
  272. IRQF_DISABLED | IRQF_TRIGGER_RISING |
  273. IRQF_TRIGGER_FALLING,
  274. "MMC card detect", data);
  275. if (err) {
  276. pr_err("%s: MMC/SD: can't request MMC card detect IRQ\n",
  277. __func__);
  278. goto err_free_3;
  279. }
  280. return 0;
  281. err_free_3:
  282. gpio_free(CORGI_GPIO_SD_PWR);
  283. err_free_2:
  284. gpio_free(CORGI_GPIO_nSD_WP);
  285. err_free_1:
  286. gpio_free(CORGI_GPIO_nSD_DETECT);
  287. err_out:
  288. return err;
  289. }
  290. static void corgi_mci_setpower(struct device *dev, unsigned int vdd)
  291. {
  292. struct pxamci_platform_data* p_d = dev->platform_data;
  293. gpio_set_value(CORGI_GPIO_SD_PWR, ((1 << vdd) & p_d->ocr_mask));
  294. }
  295. static int corgi_mci_get_ro(struct device *dev)
  296. {
  297. return gpio_get_value(CORGI_GPIO_nSD_WP);
  298. }
  299. static void corgi_mci_exit(struct device *dev, void *data)
  300. {
  301. free_irq(CORGI_IRQ_GPIO_nSD_DETECT, data);
  302. gpio_free(CORGI_GPIO_SD_PWR);
  303. gpio_free(CORGI_GPIO_nSD_WP);
  304. gpio_free(CORGI_GPIO_nSD_DETECT);
  305. }
  306. static struct pxamci_platform_data corgi_mci_platform_data = {
  307. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  308. .init = corgi_mci_init,
  309. .get_ro = corgi_mci_get_ro,
  310. .setpower = corgi_mci_setpower,
  311. .exit = corgi_mci_exit,
  312. };
  313. /*
  314. * Irda
  315. */
  316. static void corgi_irda_transceiver_mode(struct device *dev, int mode)
  317. {
  318. gpio_set_value(CORGI_GPIO_IR_ON, mode & IR_OFF);
  319. pxa2xx_transceiver_mode(dev, mode);
  320. }
  321. static int corgi_irda_startup(struct device *dev)
  322. {
  323. int err;
  324. err = gpio_request(CORGI_GPIO_IR_ON, "IR_ON");
  325. if (err)
  326. return err;
  327. gpio_direction_output(CORGI_GPIO_IR_ON, 1);
  328. return 0;
  329. }
  330. static void corgi_irda_shutdown(struct device *dev)
  331. {
  332. gpio_free(CORGI_GPIO_IR_ON);
  333. }
  334. static struct pxaficp_platform_data corgi_ficp_platform_data = {
  335. .transceiver_cap = IR_SIRMODE | IR_OFF,
  336. .transceiver_mode = corgi_irda_transceiver_mode,
  337. .startup = corgi_irda_startup,
  338. .shutdown = corgi_irda_shutdown,
  339. };
  340. /*
  341. * USB Device Controller
  342. */
  343. static struct pxa2xx_udc_mach_info udc_info __initdata = {
  344. /* no connect GPIO; corgi can't tell connection status */
  345. .gpio_pullup = CORGI_GPIO_USB_PULLUP,
  346. };
  347. #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MASTER)
  348. static struct pxa2xx_spi_master corgi_spi_info = {
  349. .num_chipselect = 3,
  350. };
  351. static struct ads7846_platform_data corgi_ads7846_info = {
  352. .model = 7846,
  353. .vref_delay_usecs = 100,
  354. .x_plate_ohms = 419,
  355. .y_plate_ohms = 486,
  356. .gpio_pendown = CORGI_GPIO_TP_INT,
  357. };
  358. static void corgi_ads7846_cs(u32 command)
  359. {
  360. gpio_set_value(CORGI_GPIO_ADS7846_CS, !(command == PXA2XX_CS_ASSERT));
  361. }
  362. static struct pxa2xx_spi_chip corgi_ads7846_chip = {
  363. .cs_control = corgi_ads7846_cs,
  364. };
  365. static void corgi_notify_intensity(int intensity)
  366. {
  367. /* Bit 5 is via SCOOP */
  368. if (intensity & 0x0020)
  369. set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_BACKLIGHT_CONT);
  370. else
  371. reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_BACKLIGHT_CONT);
  372. }
  373. static void corgi_bl_kick_battery(void)
  374. {
  375. void (*kick_batt)(void);
  376. kick_batt = symbol_get(sharpsl_battery_kick);
  377. if (kick_batt) {
  378. kick_batt();
  379. symbol_put(sharpsl_battery_kick);
  380. }
  381. }
  382. static struct corgi_lcd_platform_data corgi_lcdcon_info = {
  383. .init_mode = CORGI_LCD_MODE_VGA,
  384. .max_intensity = 0x2f,
  385. .default_intensity = 0x1f,
  386. .limit_mask = 0x0b,
  387. .notify = corgi_notify_intensity,
  388. .kick_battery = corgi_bl_kick_battery,
  389. };
  390. static void corgi_lcdcon_cs(u32 command)
  391. {
  392. gpio_set_value(CORGI_GPIO_LCDCON_CS, !(command == PXA2XX_CS_ASSERT));
  393. }
  394. static struct pxa2xx_spi_chip corgi_lcdcon_chip = {
  395. .cs_control = corgi_lcdcon_cs,
  396. };
  397. static void corgi_max1111_cs(u32 command)
  398. {
  399. gpio_set_value(CORGI_GPIO_MAX1111_CS, !(command == PXA2XX_CS_ASSERT));
  400. }
  401. static struct pxa2xx_spi_chip corgi_max1111_chip = {
  402. .cs_control = corgi_max1111_cs,
  403. };
  404. static struct spi_board_info corgi_spi_devices[] = {
  405. {
  406. .modalias = "ads7846",
  407. .max_speed_hz = 1200000,
  408. .bus_num = 1,
  409. .chip_select = 0,
  410. .platform_data = &corgi_ads7846_info,
  411. .controller_data= &corgi_ads7846_chip,
  412. .irq = gpio_to_irq(CORGI_GPIO_TP_INT),
  413. }, {
  414. .modalias = "corgi-lcd",
  415. .max_speed_hz = 50000,
  416. .bus_num = 1,
  417. .chip_select = 1,
  418. .platform_data = &corgi_lcdcon_info,
  419. .controller_data= &corgi_lcdcon_chip,
  420. }, {
  421. .modalias = "max1111",
  422. .max_speed_hz = 450000,
  423. .bus_num = 1,
  424. .chip_select = 2,
  425. .controller_data= &corgi_max1111_chip,
  426. },
  427. };
  428. static void __init corgi_init_spi(void)
  429. {
  430. int err;
  431. err = gpio_request(CORGI_GPIO_ADS7846_CS, "ADS7846_CS");
  432. if (err)
  433. return;
  434. err = gpio_request(CORGI_GPIO_LCDCON_CS, "LCDCON_CS");
  435. if (err)
  436. goto err_free_1;
  437. err = gpio_request(CORGI_GPIO_MAX1111_CS, "MAX1111_CS");
  438. if (err)
  439. goto err_free_2;
  440. gpio_direction_output(CORGI_GPIO_ADS7846_CS, 1);
  441. gpio_direction_output(CORGI_GPIO_LCDCON_CS, 1);
  442. gpio_direction_output(CORGI_GPIO_MAX1111_CS, 1);
  443. pxa2xx_set_spi_info(1, &corgi_spi_info);
  444. spi_register_board_info(ARRAY_AND_SIZE(corgi_spi_devices));
  445. return;
  446. err_free_2:
  447. gpio_free(CORGI_GPIO_LCDCON_CS);
  448. err_free_1:
  449. gpio_free(CORGI_GPIO_ADS7846_CS);
  450. }
  451. #else
  452. static inline void corgi_init_spi(void) {}
  453. #endif
  454. static struct platform_device *devices[] __initdata = {
  455. &corgiscoop_device,
  456. &corgifb_device,
  457. &corgikbd_device,
  458. &corgiled_device,
  459. };
  460. static void corgi_poweroff(void)
  461. {
  462. if (!machine_is_corgi())
  463. /* Green LED off tells the bootloader to halt */
  464. reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_LED_GREEN);
  465. arm_machine_restart('h');
  466. }
  467. static void corgi_restart(char mode)
  468. {
  469. if (!machine_is_corgi())
  470. /* Green LED on tells the bootloader to reboot */
  471. set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_LED_GREEN);
  472. arm_machine_restart('h');
  473. }
  474. static void __init corgi_init(void)
  475. {
  476. pm_power_off = corgi_poweroff;
  477. arm_pm_restart = corgi_restart;
  478. /* Stop 3.6MHz and drive HIGH to PCMCIA and CS */
  479. PCFR |= PCFR_OPDE;
  480. pxa2xx_mfp_config(ARRAY_AND_SIZE(corgi_pin_config));
  481. corgi_init_spi();
  482. pxa_set_udc_info(&udc_info);
  483. pxa_set_mci_info(&corgi_mci_platform_data);
  484. pxa_set_ficp_info(&corgi_ficp_platform_data);
  485. pxa_set_i2c_info(NULL);
  486. platform_scoop_config = &corgi_pcmcia_config;
  487. platform_add_devices(devices, ARRAY_SIZE(devices));
  488. }
  489. static void __init fixup_corgi(struct machine_desc *desc,
  490. struct tag *tags, char **cmdline, struct meminfo *mi)
  491. {
  492. sharpsl_save_param();
  493. mi->nr_banks=1;
  494. mi->bank[0].start = 0xa0000000;
  495. mi->bank[0].node = 0;
  496. if (machine_is_corgi())
  497. mi->bank[0].size = (32*1024*1024);
  498. else
  499. mi->bank[0].size = (64*1024*1024);
  500. }
  501. #ifdef CONFIG_MACH_CORGI
  502. MACHINE_START(CORGI, "SHARP Corgi")
  503. .phys_io = 0x40000000,
  504. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  505. .fixup = fixup_corgi,
  506. .map_io = pxa_map_io,
  507. .init_irq = pxa25x_init_irq,
  508. .init_machine = corgi_init,
  509. .timer = &pxa_timer,
  510. MACHINE_END
  511. #endif
  512. #ifdef CONFIG_MACH_SHEPHERD
  513. MACHINE_START(SHEPHERD, "SHARP Shepherd")
  514. .phys_io = 0x40000000,
  515. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  516. .fixup = fixup_corgi,
  517. .map_io = pxa_map_io,
  518. .init_irq = pxa25x_init_irq,
  519. .init_machine = corgi_init,
  520. .timer = &pxa_timer,
  521. MACHINE_END
  522. #endif
  523. #ifdef CONFIG_MACH_HUSKY
  524. MACHINE_START(HUSKY, "SHARP Husky")
  525. .phys_io = 0x40000000,
  526. .io_pg_offst = (io_p2v(0x40000000) >> 18) & 0xfffc,
  527. .fixup = fixup_corgi,
  528. .map_io = pxa_map_io,
  529. .init_irq = pxa25x_init_irq,
  530. .init_machine = corgi_init,
  531. .timer = &pxa_timer,
  532. MACHINE_END
  533. #endif