pcm990-baseboard.c 14 KB

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