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