pcm990-baseboard.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. /*
  2. * arch/arm/mach-pxa/pcm990-baseboard.c
  3. * Support for the Phytec phyCORE-PXA270 Development Platform (PCM-990).
  4. *
  5. * Refer
  6. * http://www.phytec.com/products/rdk/ARM-XScale/phyCORE-XScale-PXA270.html
  7. * for additional hardware info
  8. *
  9. * Author: Juergen Kilb
  10. * Created: April 05, 2005
  11. * Copyright: Phytec Messtechnik GmbH
  12. * e-Mail: armlinux@phytec.de
  13. *
  14. * based on Intel Mainstone Board
  15. *
  16. * Copyright 2007 Juergen Beisert @ Pengutronix (j.beisert@pengutronix.de)
  17. *
  18. * This program is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License version 2 as
  20. * published by the Free Software Foundation.
  21. */
  22. #include <linux/irq.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/i2c.h>
  25. #include <linux/pwm_backlight.h>
  26. #include <media/soc_camera.h>
  27. #include <asm/gpio.h>
  28. #include <plat/i2c.h>
  29. #include <mach/camera.h>
  30. #include <asm/mach/map.h>
  31. #include <mach/pxa27x.h>
  32. #include <mach/audio.h>
  33. #include <mach/mmc.h>
  34. #include <mach/ohci.h>
  35. #include <mach/pcm990_baseboard.h>
  36. #include <mach/pxafb.h>
  37. #include "devices.h"
  38. #include "generic.h"
  39. static unsigned long pcm990_pin_config[] __initdata = {
  40. /* MMC */
  41. GPIO32_MMC_CLK,
  42. GPIO112_MMC_CMD,
  43. GPIO92_MMC_DAT_0,
  44. GPIO109_MMC_DAT_1,
  45. GPIO110_MMC_DAT_2,
  46. GPIO111_MMC_DAT_3,
  47. /* USB */
  48. GPIO88_USBH1_PWR,
  49. GPIO89_USBH1_PEN,
  50. /* PWM0 */
  51. GPIO16_PWM0_OUT,
  52. /* I2C */
  53. GPIO117_I2C_SCL,
  54. GPIO118_I2C_SDA,
  55. };
  56. /*
  57. * pcm990_lcd_power - control power supply to the LCD
  58. * @on: 0 = switch off, 1 = switch on
  59. *
  60. * Called by the pxafb driver
  61. */
  62. #ifndef CONFIG_PCM990_DISPLAY_NONE
  63. static void pcm990_lcd_power(int on, struct fb_var_screeninfo *var)
  64. {
  65. if (on) {
  66. /* enable LCD-Latches
  67. * power on LCD
  68. */
  69. __PCM990_CTRL_REG(PCM990_CTRL_PHYS + PCM990_CTRL_REG3) =
  70. PCM990_CTRL_LCDPWR + PCM990_CTRL_LCDON;
  71. } else {
  72. /* disable LCD-Latches
  73. * power off LCD
  74. */
  75. __PCM990_CTRL_REG(PCM990_CTRL_PHYS + PCM990_CTRL_REG3) = 0x00;
  76. }
  77. }
  78. #endif
  79. #if defined(CONFIG_PCM990_DISPLAY_SHARP)
  80. static struct pxafb_mode_info fb_info_sharp_lq084v1dg21 = {
  81. .pixclock = 28000,
  82. .xres = 640,
  83. .yres = 480,
  84. .bpp = 16,
  85. .hsync_len = 20,
  86. .left_margin = 103,
  87. .right_margin = 47,
  88. .vsync_len = 6,
  89. .upper_margin = 28,
  90. .lower_margin = 5,
  91. .sync = 0,
  92. .cmap_greyscale = 0,
  93. };
  94. static struct pxafb_mach_info pcm990_fbinfo __initdata = {
  95. .modes = &fb_info_sharp_lq084v1dg21,
  96. .num_modes = 1,
  97. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  98. .pxafb_lcd_power = pcm990_lcd_power,
  99. };
  100. #elif defined(CONFIG_PCM990_DISPLAY_NEC)
  101. struct pxafb_mode_info fb_info_nec_nl6448bc20_18d = {
  102. .pixclock = 39720,
  103. .xres = 640,
  104. .yres = 480,
  105. .bpp = 16,
  106. .hsync_len = 32,
  107. .left_margin = 16,
  108. .right_margin = 48,
  109. .vsync_len = 2,
  110. .upper_margin = 12,
  111. .lower_margin = 17,
  112. .sync = 0,
  113. .cmap_greyscale = 0,
  114. };
  115. static struct pxafb_mach_info pcm990_fbinfo __initdata = {
  116. .modes = &fb_info_nec_nl6448bc20_18d,
  117. .num_modes = 1,
  118. .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
  119. .pxafb_lcd_power = pcm990_lcd_power,
  120. };
  121. #endif
  122. static struct platform_pwm_backlight_data pcm990_backlight_data = {
  123. .pwm_id = 0,
  124. .max_brightness = 1023,
  125. .dft_brightness = 1023,
  126. .pwm_period_ns = 78770,
  127. };
  128. static struct platform_device pcm990_backlight_device = {
  129. .name = "pwm-backlight",
  130. .dev = {
  131. .parent = &pxa27x_device_pwm0.dev,
  132. .platform_data = &pcm990_backlight_data,
  133. },
  134. };
  135. /*
  136. * The PCM-990 development baseboard uses PCM-027's hardware in the
  137. * following way:
  138. *
  139. * - LCD support is in use
  140. * - GPIO16 is output for back light on/off with PWM
  141. * - GPIO58 ... GPIO73 are outputs for display data
  142. * - GPIO74 is output output for LCDFCLK
  143. * - GPIO75 is output for LCDLCLK
  144. * - GPIO76 is output for LCDPCLK
  145. * - GPIO77 is output for LCDBIAS
  146. * - MMC support is in use
  147. * - GPIO32 is output for MMCCLK
  148. * - GPIO92 is MMDAT0
  149. * - GPIO109 is MMDAT1
  150. * - GPIO110 is MMCS0
  151. * - GPIO111 is MMCS1
  152. * - GPIO112 is MMCMD
  153. * - IDE/CF card is in use
  154. * - GPIO48 is output /POE
  155. * - GPIO49 is output /PWE
  156. * - GPIO50 is output /PIOR
  157. * - GPIO51 is output /PIOW
  158. * - GPIO54 is output /PCE2
  159. * - GPIO55 is output /PREG
  160. * - GPIO56 is input /PWAIT
  161. * - GPIO57 is output /PIOS16
  162. * - GPIO79 is output PSKTSEL
  163. * - GPIO85 is output /PCE1
  164. * - FFUART is in use
  165. * - GPIO34 is input FFRXD
  166. * - GPIO35 is input FFCTS
  167. * - GPIO36 is input FFDCD
  168. * - GPIO37 is input FFDSR
  169. * - GPIO38 is input FFRI
  170. * - GPIO39 is output FFTXD
  171. * - GPIO40 is output FFDTR
  172. * - GPIO41 is output FFRTS
  173. * - BTUART is in use
  174. * - GPIO42 is input BTRXD
  175. * - GPIO43 is output BTTXD
  176. * - GPIO44 is input BTCTS
  177. * - GPIO45 is output BTRTS
  178. * - IRUART is in use
  179. * - GPIO46 is input STDRXD
  180. * - GPIO47 is output STDTXD
  181. * - AC97 is in use*)
  182. * - GPIO28 is input AC97CLK
  183. * - GPIO29 is input AC97DatIn
  184. * - GPIO30 is output AC97DatO
  185. * - GPIO31 is output AC97SYNC
  186. * - GPIO113 is output AC97_RESET
  187. * - SSP is in use
  188. * - GPIO23 is output SSPSCLK
  189. * - GPIO24 is output chip select to Max7301
  190. * - GPIO25 is output SSPTXD
  191. * - GPIO26 is input SSPRXD
  192. * - GPIO27 is input for Max7301 IRQ
  193. * - GPIO53 is input SSPSYSCLK
  194. * - SSP3 is in use
  195. * - GPIO81 is output SSPTXD3
  196. * - GPIO82 is input SSPRXD3
  197. * - GPIO83 is output SSPSFRM
  198. * - GPIO84 is output SSPCLK3
  199. *
  200. * Otherwise claimed GPIOs:
  201. * GPIO1 -> IRQ from user switch
  202. * GPIO9 -> IRQ from power management
  203. * GPIO10 -> IRQ from WML9712 AC97 controller
  204. * GPIO11 -> IRQ from IDE controller
  205. * GPIO12 -> IRQ from CF controller
  206. * GPIO13 -> IRQ from CF controller
  207. * GPIO14 -> GPIO free
  208. * GPIO15 -> /CS1 selects baseboard's Control CPLD (U7, 16 bit wide data path)
  209. * GPIO19 -> GPIO free
  210. * GPIO20 -> /SDCS2
  211. * GPIO21 -> /CS3 PC card socket select
  212. * GPIO33 -> /CS5 network controller select
  213. * GPIO78 -> /CS2 (16 bit wide data path)
  214. * GPIO80 -> /CS4 (16 bit wide data path)
  215. * GPIO86 -> GPIO free
  216. * GPIO87 -> GPIO free
  217. * GPIO90 -> LED0 on CPU module
  218. * GPIO91 -> LED1 on CPI module
  219. * GPIO117 -> SCL
  220. * GPIO118 -> SDA
  221. */
  222. static unsigned long pcm990_irq_enabled;
  223. static void pcm990_mask_ack_irq(unsigned int irq)
  224. {
  225. int pcm990_irq = (irq - PCM027_IRQ(0));
  226. PCM990_INTMSKENA = (pcm990_irq_enabled &= ~(1 << pcm990_irq));
  227. }
  228. static void pcm990_unmask_irq(unsigned int irq)
  229. {
  230. int pcm990_irq = (irq - PCM027_IRQ(0));
  231. /* the irq can be acknowledged only if deasserted, so it's done here */
  232. PCM990_INTSETCLR |= 1 << pcm990_irq;
  233. PCM990_INTMSKENA = (pcm990_irq_enabled |= (1 << pcm990_irq));
  234. }
  235. static struct irq_chip pcm990_irq_chip = {
  236. .mask_ack = pcm990_mask_ack_irq,
  237. .unmask = pcm990_unmask_irq,
  238. };
  239. static void pcm990_irq_handler(unsigned int irq, struct irq_desc *desc)
  240. {
  241. unsigned long pending = (~PCM990_INTSETCLR) & pcm990_irq_enabled;
  242. do {
  243. desc->chip->ack(irq); /* clear our parent IRQ */
  244. if (likely(pending)) {
  245. irq = PCM027_IRQ(0) + __ffs(pending);
  246. generic_handle_irq(irq);
  247. }
  248. pending = (~PCM990_INTSETCLR) & pcm990_irq_enabled;
  249. } while (pending);
  250. }
  251. static void __init pcm990_init_irq(void)
  252. {
  253. int irq;
  254. /* setup extra PCM990 irqs */
  255. for (irq = PCM027_IRQ(0); irq <= PCM027_IRQ(3); irq++) {
  256. set_irq_chip(irq, &pcm990_irq_chip);
  257. set_irq_handler(irq, handle_level_irq);
  258. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  259. }
  260. PCM990_INTMSKENA = 0x00; /* disable all Interrupts */
  261. PCM990_INTSETCLR = 0xFF;
  262. set_irq_chained_handler(PCM990_CTRL_INT_IRQ, pcm990_irq_handler);
  263. set_irq_type(PCM990_CTRL_INT_IRQ, PCM990_CTRL_INT_IRQ_EDGE);
  264. }
  265. static int pcm990_mci_init(struct device *dev, irq_handler_t mci_detect_int,
  266. void *data)
  267. {
  268. int err;
  269. err = request_irq(PCM027_MMCDET_IRQ, mci_detect_int, IRQF_DISABLED,
  270. "MMC card detect", data);
  271. if (err)
  272. printk(KERN_ERR "pcm990_mci_init: MMC/SD: can't request MMC "
  273. "card detect IRQ\n");
  274. return err;
  275. }
  276. static void pcm990_mci_setpower(struct device *dev, unsigned int vdd)
  277. {
  278. struct pxamci_platform_data *p_d = dev->platform_data;
  279. if ((1 << vdd) & p_d->ocr_mask)
  280. __PCM990_CTRL_REG(PCM990_CTRL_PHYS + PCM990_CTRL_REG5) =
  281. PCM990_CTRL_MMC2PWR;
  282. else
  283. __PCM990_CTRL_REG(PCM990_CTRL_PHYS + PCM990_CTRL_REG5) =
  284. ~PCM990_CTRL_MMC2PWR;
  285. }
  286. static void pcm990_mci_exit(struct device *dev, void *data)
  287. {
  288. free_irq(PCM027_MMCDET_IRQ, data);
  289. }
  290. #define MSECS_PER_JIFFY (1000/HZ)
  291. static struct pxamci_platform_data pcm990_mci_platform_data = {
  292. .detect_delay = 250 / MSECS_PER_JIFFY,
  293. .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
  294. .init = pcm990_mci_init,
  295. .setpower = pcm990_mci_setpower,
  296. .exit = pcm990_mci_exit,
  297. .gpio_card_detect = -1,
  298. .gpio_card_ro = -1,
  299. .gpio_power = -1,
  300. };
  301. static struct pxaohci_platform_data pcm990_ohci_platform_data = {
  302. .port_mode = PMM_PERPORT_MODE,
  303. .flags = ENABLE_PORT1 | POWER_CONTROL_LOW | POWER_SENSE_LOW,
  304. .power_on_delay = 10,
  305. };
  306. /*
  307. * PXA27x Camera specific stuff
  308. */
  309. #if defined(CONFIG_VIDEO_PXA27x) || defined(CONFIG_VIDEO_PXA27x_MODULE)
  310. static unsigned long pcm990_camera_pin_config[] = {
  311. /* CIF */
  312. GPIO98_CIF_DD_0,
  313. GPIO105_CIF_DD_1,
  314. GPIO104_CIF_DD_2,
  315. GPIO103_CIF_DD_3,
  316. GPIO95_CIF_DD_4,
  317. GPIO94_CIF_DD_5,
  318. GPIO93_CIF_DD_6,
  319. GPIO108_CIF_DD_7,
  320. GPIO107_CIF_DD_8,
  321. GPIO106_CIF_DD_9,
  322. GPIO42_CIF_MCLK,
  323. GPIO45_CIF_PCLK,
  324. GPIO43_CIF_FV,
  325. GPIO44_CIF_LV,
  326. };
  327. /*
  328. * CICR4: PCLK_EN: Pixel clock is supplied by the sensor
  329. * MCLK_EN: Master clock is generated by PXA
  330. * PCP: Data sampled on the falling edge of pixel clock
  331. */
  332. struct pxacamera_platform_data pcm990_pxacamera_platform_data = {
  333. .flags = PXA_CAMERA_MASTER | PXA_CAMERA_DATAWIDTH_8 | PXA_CAMERA_DATAWIDTH_10 |
  334. PXA_CAMERA_PCLK_EN | PXA_CAMERA_MCLK_EN/* | PXA_CAMERA_PCP*/,
  335. .mclk_10khz = 1000,
  336. };
  337. #include <linux/i2c/pca953x.h>
  338. static struct pca953x_platform_data pca9536_data = {
  339. .gpio_base = NR_BUILTIN_GPIO,
  340. };
  341. static int gpio_bus_switch = -EINVAL;
  342. static int pcm990_camera_set_bus_param(struct soc_camera_link *link,
  343. unsigned long flags)
  344. {
  345. if (gpio_bus_switch < 0) {
  346. if (flags == SOCAM_DATAWIDTH_10)
  347. return 0;
  348. else
  349. return -EINVAL;
  350. }
  351. if (flags & SOCAM_DATAWIDTH_8)
  352. gpio_set_value(gpio_bus_switch, 1);
  353. else
  354. gpio_set_value(gpio_bus_switch, 0);
  355. return 0;
  356. }
  357. static unsigned long pcm990_camera_query_bus_param(struct soc_camera_link *link)
  358. {
  359. int ret;
  360. if (gpio_bus_switch < 0) {
  361. ret = gpio_request(NR_BUILTIN_GPIO, "camera");
  362. if (!ret) {
  363. gpio_bus_switch = NR_BUILTIN_GPIO;
  364. gpio_direction_output(gpio_bus_switch, 0);
  365. }
  366. }
  367. if (gpio_bus_switch >= 0)
  368. return SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_10;
  369. else
  370. return SOCAM_DATAWIDTH_10;
  371. }
  372. static void pcm990_camera_free_bus(struct soc_camera_link *link)
  373. {
  374. if (gpio_bus_switch < 0)
  375. return;
  376. gpio_free(gpio_bus_switch);
  377. gpio_bus_switch = -EINVAL;
  378. }
  379. /* Board I2C devices. */
  380. static struct i2c_board_info __initdata pcm990_i2c_devices[] = {
  381. {
  382. /* Must initialize before the camera(s) */
  383. I2C_BOARD_INFO("pca9536", 0x41),
  384. .platform_data = &pca9536_data,
  385. },
  386. };
  387. static struct i2c_board_info pcm990_camera_i2c[] = {
  388. {
  389. I2C_BOARD_INFO("mt9v022", 0x48),
  390. }, {
  391. I2C_BOARD_INFO("mt9m001", 0x5d),
  392. },
  393. };
  394. static struct soc_camera_link iclink[] = {
  395. {
  396. .bus_id = 0, /* Must match with the camera ID */
  397. .board_info = &pcm990_camera_i2c[0],
  398. .i2c_adapter_id = 0,
  399. .query_bus_param = pcm990_camera_query_bus_param,
  400. .set_bus_param = pcm990_camera_set_bus_param,
  401. .free_bus = pcm990_camera_free_bus,
  402. .module_name = "mt9v022",
  403. }, {
  404. .bus_id = 0, /* Must match with the camera ID */
  405. .board_info = &pcm990_camera_i2c[1],
  406. .i2c_adapter_id = 0,
  407. .query_bus_param = pcm990_camera_query_bus_param,
  408. .set_bus_param = pcm990_camera_set_bus_param,
  409. .free_bus = pcm990_camera_free_bus,
  410. .module_name = "mt9m001",
  411. },
  412. };
  413. static struct platform_device pcm990_camera[] = {
  414. {
  415. .name = "soc-camera-pdrv",
  416. .id = 0,
  417. .dev = {
  418. .platform_data = &iclink[0],
  419. },
  420. }, {
  421. .name = "soc-camera-pdrv",
  422. .id = 1,
  423. .dev = {
  424. .platform_data = &iclink[1],
  425. },
  426. },
  427. };
  428. #endif /* CONFIG_VIDEO_PXA27x ||CONFIG_VIDEO_PXA27x_MODULE */
  429. /*
  430. * enable generic access to the base board control CPLDs U6 and U7
  431. */
  432. static struct map_desc pcm990_io_desc[] __initdata = {
  433. {
  434. .virtual = PCM990_CTRL_BASE,
  435. .pfn = __phys_to_pfn(PCM990_CTRL_PHYS),
  436. .length = PCM990_CTRL_SIZE,
  437. .type = MT_DEVICE /* CPLD */
  438. }, {
  439. .virtual = PCM990_CF_PLD_BASE,
  440. .pfn = __phys_to_pfn(PCM990_CF_PLD_PHYS),
  441. .length = PCM990_CF_PLD_SIZE,
  442. .type = MT_DEVICE /* CPLD */
  443. }
  444. };
  445. /*
  446. * system init for baseboard usage. Will be called by pcm027 init.
  447. *
  448. * Add platform devices present on this baseboard and init
  449. * them from CPU side as far as required to use them later on
  450. */
  451. void __init pcm990_baseboard_init(void)
  452. {
  453. pxa2xx_mfp_config(ARRAY_AND_SIZE(pcm990_pin_config));
  454. /* register CPLD access */
  455. iotable_init(ARRAY_AND_SIZE(pcm990_io_desc));
  456. /* register CPLD's IRQ controller */
  457. pcm990_init_irq();
  458. #ifndef CONFIG_PCM990_DISPLAY_NONE
  459. set_pxa_fb_info(&pcm990_fbinfo);
  460. #endif
  461. platform_device_register(&pcm990_backlight_device);
  462. /* MMC */
  463. pxa_set_mci_info(&pcm990_mci_platform_data);
  464. /* USB host */
  465. pxa_set_ohci_info(&pcm990_ohci_platform_data);
  466. pxa_set_i2c_info(NULL);
  467. pxa_set_ac97_info(NULL);
  468. #if defined(CONFIG_VIDEO_PXA27x) || defined(CONFIG_VIDEO_PXA27x_MODULE)
  469. pxa2xx_mfp_config(ARRAY_AND_SIZE(pcm990_camera_pin_config));
  470. pxa_set_camera_info(&pcm990_pxacamera_platform_data);
  471. i2c_register_board_info(0, ARRAY_AND_SIZE(pcm990_i2c_devices));
  472. platform_device_register(&pcm990_camera[0]);
  473. platform_device_register(&pcm990_camera[1]);
  474. #endif
  475. printk(KERN_INFO "PCM-990 Evaluation baseboard initialized\n");
  476. }