1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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/mt9v022.h>
30#include <media/soc_camera.h>
31
32#include <linux/platform_data/camera-pxa.h>
33#include <asm/mach/map.h>
34#include <mach/pxa27x.h>
35#include <mach/audio.h>
36#include <linux/platform_data/mmc-pxamci.h>
37#include <linux/platform_data/usb-ohci-pxa27x.h>
38#include <mach/pcm990_baseboard.h>
39#include <linux/platform_data/video-pxafb.h>
40
41#include "devices.h"
42#include "generic.h"
43
44static unsigned long pcm990_pin_config[] __initdata = {
45
46 GPIO32_MMC_CLK,
47 GPIO112_MMC_CMD,
48 GPIO92_MMC_DAT_0,
49 GPIO109_MMC_DAT_1,
50 GPIO110_MMC_DAT_2,
51 GPIO111_MMC_DAT_3,
52
53 GPIO88_USBH1_PWR,
54 GPIO89_USBH1_PEN,
55
56 GPIO16_PWM0_OUT,
57
58
59 GPIO117_I2C_SCL,
60 GPIO118_I2C_SDA,
61
62
63 GPIO28_AC97_BITCLK,
64 GPIO29_AC97_SDATA_IN_0,
65 GPIO30_AC97_SDATA_OUT,
66 GPIO31_AC97_SYNC,
67};
68
69static void __iomem *pcm990_cpld_base;
70
71static u8 pcm990_cpld_readb(unsigned int reg)
72{
73 return readb(pcm990_cpld_base + reg);
74}
75
76static void pcm990_cpld_writeb(u8 value, unsigned int reg)
77{
78 writeb(value, pcm990_cpld_base + reg);
79}
80
81
82
83
84
85
86
87#ifndef CONFIG_PCM990_DISPLAY_NONE
88static void pcm990_lcd_power(int on, struct fb_var_screeninfo *var)
89{
90 if (on) {
91
92
93
94 pcm990_cpld_writeb(PCM990_CTRL_LCDPWR + PCM990_CTRL_LCDON,
95 PCM990_CTRL_REG3);
96 } else {
97
98
99
100 pcm990_cpld_writeb(0, PCM990_CTRL_REG3);
101 }
102}
103#endif
104
105#if defined(CONFIG_PCM990_DISPLAY_SHARP)
106static struct pxafb_mode_info fb_info_sharp_lq084v1dg21 = {
107 .pixclock = 28000,
108 .xres = 640,
109 .yres = 480,
110 .bpp = 16,
111 .hsync_len = 20,
112 .left_margin = 103,
113 .right_margin = 47,
114 .vsync_len = 6,
115 .upper_margin = 28,
116 .lower_margin = 5,
117 .sync = 0,
118 .cmap_greyscale = 0,
119};
120
121static struct pxafb_mach_info pcm990_fbinfo __initdata = {
122 .modes = &fb_info_sharp_lq084v1dg21,
123 .num_modes = 1,
124 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
125 .pxafb_lcd_power = pcm990_lcd_power,
126};
127#elif defined(CONFIG_PCM990_DISPLAY_NEC)
128struct pxafb_mode_info fb_info_nec_nl6448bc20_18d = {
129 .pixclock = 39720,
130 .xres = 640,
131 .yres = 480,
132 .bpp = 16,
133 .hsync_len = 32,
134 .left_margin = 16,
135 .right_margin = 48,
136 .vsync_len = 2,
137 .upper_margin = 12,
138 .lower_margin = 17,
139 .sync = 0,
140 .cmap_greyscale = 0,
141};
142
143static struct pxafb_mach_info pcm990_fbinfo __initdata = {
144 .modes = &fb_info_nec_nl6448bc20_18d,
145 .num_modes = 1,
146 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
147 .pxafb_lcd_power = pcm990_lcd_power,
148};
149#endif
150
151static struct platform_pwm_backlight_data pcm990_backlight_data = {
152 .pwm_id = 0,
153 .max_brightness = 1023,
154 .dft_brightness = 1023,
155 .pwm_period_ns = 78770,
156 .enable_gpio = -1,
157};
158
159static struct platform_device pcm990_backlight_device = {
160 .name = "pwm-backlight",
161 .dev = {
162 .parent = &pxa27x_device_pwm0.dev,
163 .platform_data = &pcm990_backlight_data,
164 },
165};
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255static unsigned long pcm990_irq_enabled;
256
257static void pcm990_mask_ack_irq(struct irq_data *d)
258{
259 int pcm990_irq = (d->irq - PCM027_IRQ(0));
260
261 pcm990_irq_enabled &= ~(1 << pcm990_irq);
262
263 pcm990_cpld_writeb(pcm990_irq_enabled, PCM990_CTRL_INTMSKENA);
264}
265
266static void pcm990_unmask_irq(struct irq_data *d)
267{
268 int pcm990_irq = (d->irq - PCM027_IRQ(0));
269 u8 val;
270
271
272
273 pcm990_irq_enabled |= (1 << pcm990_irq);
274
275 val = pcm990_cpld_readb(PCM990_CTRL_INTSETCLR);
276 val |= 1 << pcm990_irq;
277 pcm990_cpld_writeb(val, PCM990_CTRL_INTSETCLR);
278
279 pcm990_cpld_writeb(pcm990_irq_enabled, PCM990_CTRL_INTMSKENA);
280}
281
282static struct irq_chip pcm990_irq_chip = {
283 .irq_mask_ack = pcm990_mask_ack_irq,
284 .irq_unmask = pcm990_unmask_irq,
285};
286
287static void pcm990_irq_handler(unsigned int irq, struct irq_desc *desc)
288{
289 unsigned long pending;
290
291 pending = ~pcm990_cpld_readb(PCM990_CTRL_INTSETCLR);
292 pending &= pcm990_irq_enabled;
293
294 do {
295
296 desc->irq_data.chip->irq_ack(&desc->irq_data);
297 if (likely(pending)) {
298 irq = PCM027_IRQ(0) + __ffs(pending);
299 generic_handle_irq(irq);
300 }
301 pending = ~pcm990_cpld_readb(PCM990_CTRL_INTSETCLR);
302 pending &= pcm990_irq_enabled;
303 } while (pending);
304}
305
306static void __init pcm990_init_irq(void)
307{
308 int irq;
309
310
311 for (irq = PCM027_IRQ(0); irq <= PCM027_IRQ(3); irq++) {
312 irq_set_chip_and_handler(irq, &pcm990_irq_chip,
313 handle_level_irq);
314 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
315 }
316
317
318 pcm990_cpld_writeb(0x0, PCM990_CTRL_INTMSKENA);
319 pcm990_cpld_writeb(0xff, PCM990_CTRL_INTSETCLR);
320
321 irq_set_chained_handler(PCM990_CTRL_INT_IRQ, pcm990_irq_handler);
322 irq_set_irq_type(PCM990_CTRL_INT_IRQ, PCM990_CTRL_INT_IRQ_EDGE);
323}
324
325static int pcm990_mci_init(struct device *dev, irq_handler_t mci_detect_int,
326 void *data)
327{
328 int err;
329
330 err = request_irq(PCM027_MMCDET_IRQ, mci_detect_int, 0,
331 "MMC card detect", data);
332 if (err)
333 printk(KERN_ERR "pcm990_mci_init: MMC/SD: can't request MMC "
334 "card detect IRQ\n");
335
336 return err;
337}
338
339static int pcm990_mci_setpower(struct device *dev, unsigned int vdd)
340{
341 struct pxamci_platform_data *p_d = dev->platform_data;
342 u8 val;
343
344 val = pcm990_cpld_readb(PCM990_CTRL_REG5);
345
346 if ((1 << vdd) & p_d->ocr_mask)
347 val |= PCM990_CTRL_MMC2PWR;
348 else
349 val &= ~PCM990_CTRL_MMC2PWR;
350
351 pcm990_cpld_writeb(PCM990_CTRL_MMC2PWR, PCM990_CTRL_REG5);
352 return 0;
353}
354
355static void pcm990_mci_exit(struct device *dev, void *data)
356{
357 free_irq(PCM027_MMCDET_IRQ, data);
358}
359
360#define MSECS_PER_JIFFY (1000/HZ)
361
362static struct pxamci_platform_data pcm990_mci_platform_data = {
363 .detect_delay_ms = 250,
364 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
365 .init = pcm990_mci_init,
366 .setpower = pcm990_mci_setpower,
367 .exit = pcm990_mci_exit,
368 .gpio_card_detect = -1,
369 .gpio_card_ro = -1,
370 .gpio_power = -1,
371};
372
373static struct pxaohci_platform_data pcm990_ohci_platform_data = {
374 .port_mode = PMM_PERPORT_MODE,
375 .flags = ENABLE_PORT1 | POWER_CONTROL_LOW | POWER_SENSE_LOW,
376 .power_on_delay = 10,
377};
378
379
380
381
382#if defined(CONFIG_VIDEO_PXA27x) || defined(CONFIG_VIDEO_PXA27x_MODULE)
383static unsigned long pcm990_camera_pin_config[] = {
384
385 GPIO98_CIF_DD_0,
386 GPIO105_CIF_DD_1,
387 GPIO104_CIF_DD_2,
388 GPIO103_CIF_DD_3,
389 GPIO95_CIF_DD_4,
390 GPIO94_CIF_DD_5,
391 GPIO93_CIF_DD_6,
392 GPIO108_CIF_DD_7,
393 GPIO107_CIF_DD_8,
394 GPIO106_CIF_DD_9,
395 GPIO42_CIF_MCLK,
396 GPIO45_CIF_PCLK,
397 GPIO43_CIF_FV,
398 GPIO44_CIF_LV,
399};
400
401
402
403
404
405
406struct pxacamera_platform_data pcm990_pxacamera_platform_data = {
407 .flags = PXA_CAMERA_MASTER | PXA_CAMERA_DATAWIDTH_8 | PXA_CAMERA_DATAWIDTH_10 |
408 PXA_CAMERA_PCLK_EN | PXA_CAMERA_MCLK_EN,
409 .mclk_10khz = 1000,
410};
411
412#include <linux/platform_data/pca953x.h>
413
414static struct pca953x_platform_data pca9536_data = {
415 .gpio_base = PXA_NR_BUILTIN_GPIO,
416};
417
418static int gpio_bus_switch = -EINVAL;
419
420static int pcm990_camera_set_bus_param(struct soc_camera_link *link,
421 unsigned long flags)
422{
423 if (gpio_bus_switch < 0) {
424 if (flags == SOCAM_DATAWIDTH_10)
425 return 0;
426 else
427 return -EINVAL;
428 }
429
430 if (flags & SOCAM_DATAWIDTH_8)
431 gpio_set_value_cansleep(gpio_bus_switch, 1);
432 else
433 gpio_set_value_cansleep(gpio_bus_switch, 0);
434
435 return 0;
436}
437
438static unsigned long pcm990_camera_query_bus_param(struct soc_camera_link *link)
439{
440 int ret;
441
442 if (gpio_bus_switch < 0) {
443 ret = gpio_request(PXA_NR_BUILTIN_GPIO, "camera");
444 if (!ret) {
445 gpio_bus_switch = PXA_NR_BUILTIN_GPIO;
446 gpio_direction_output(gpio_bus_switch, 0);
447 }
448 }
449
450 if (gpio_bus_switch >= 0)
451 return SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_10;
452 else
453 return SOCAM_DATAWIDTH_10;
454}
455
456static void pcm990_camera_free_bus(struct soc_camera_link *link)
457{
458 if (gpio_bus_switch < 0)
459 return;
460
461 gpio_free(gpio_bus_switch);
462 gpio_bus_switch = -EINVAL;
463}
464
465
466static struct i2c_board_info __initdata pcm990_i2c_devices[] = {
467 {
468
469 I2C_BOARD_INFO("pca9536", 0x41),
470 .platform_data = &pca9536_data,
471 },
472};
473
474static struct mt9v022_platform_data mt9v022_pdata = {
475 .y_skip_top = 1,
476};
477
478static struct i2c_board_info pcm990_camera_i2c[] = {
479 {
480 I2C_BOARD_INFO("mt9v022", 0x48),
481 }, {
482 I2C_BOARD_INFO("mt9m001", 0x5d),
483 },
484};
485
486static struct soc_camera_link iclink[] = {
487 {
488 .bus_id = 0,
489 .board_info = &pcm990_camera_i2c[0],
490 .priv = &mt9v022_pdata,
491 .i2c_adapter_id = 0,
492 .query_bus_param = pcm990_camera_query_bus_param,
493 .set_bus_param = pcm990_camera_set_bus_param,
494 .free_bus = pcm990_camera_free_bus,
495 }, {
496 .bus_id = 0,
497 .board_info = &pcm990_camera_i2c[1],
498 .i2c_adapter_id = 0,
499 .query_bus_param = pcm990_camera_query_bus_param,
500 .set_bus_param = pcm990_camera_set_bus_param,
501 .free_bus = pcm990_camera_free_bus,
502 },
503};
504
505static struct platform_device pcm990_camera[] = {
506 {
507 .name = "soc-camera-pdrv",
508 .id = 0,
509 .dev = {
510 .platform_data = &iclink[0],
511 },
512 }, {
513 .name = "soc-camera-pdrv",
514 .id = 1,
515 .dev = {
516 .platform_data = &iclink[1],
517 },
518 },
519};
520#endif
521
522
523
524
525
526
527
528void __init pcm990_baseboard_init(void)
529{
530 pxa2xx_mfp_config(ARRAY_AND_SIZE(pcm990_pin_config));
531
532 pcm990_cpld_base = ioremap(PCM990_CTRL_PHYS, PCM990_CTRL_SIZE);
533 if (!pcm990_cpld_base) {
534 pr_err("pcm990: failed to ioremap cpld\n");
535 return;
536 }
537
538
539 pcm990_init_irq();
540
541#ifndef CONFIG_PCM990_DISPLAY_NONE
542 pxa_set_fb_info(NULL, &pcm990_fbinfo);
543#endif
544 platform_device_register(&pcm990_backlight_device);
545
546
547 pxa_set_mci_info(&pcm990_mci_platform_data);
548
549
550 pxa_set_ohci_info(&pcm990_ohci_platform_data);
551
552 pxa_set_i2c_info(NULL);
553 pxa_set_ac97_info(NULL);
554
555#if defined(CONFIG_VIDEO_PXA27x) || defined(CONFIG_VIDEO_PXA27x_MODULE)
556 pxa2xx_mfp_config(ARRAY_AND_SIZE(pcm990_camera_pin_config));
557 pxa_set_camera_info(&pcm990_pxacamera_platform_data);
558
559 i2c_register_board_info(0, ARRAY_AND_SIZE(pcm990_i2c_devices));
560
561 platform_device_register(&pcm990_camera[0]);
562 platform_device_register(&pcm990_camera[1]);
563#endif
564
565 printk(KERN_INFO "PCM-990 Evaluation baseboard initialized\n");
566}
567