pcm990-baseboard.c 14 KB

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