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