Linux 5.7.6
[linux/fpc-iii.git] / arch / arm / mach-pxa / pcm990-baseboard.c
blobbf613f88d70b178cca1160e3bf6937e13c03974a
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * arch/arm/mach-pxa/pcm990-baseboard.c
4 * Support for the Phytec phyCORE-PXA270 Development Platform (PCM-990).
6 * Refer
7 * http://www.phytec.com/products/rdk/ARM-XScale/phyCORE-XScale-PXA270.html
8 * for additional hardware info
10 * Author: Juergen Kilb
11 * Created: April 05, 2005
12 * Copyright: Phytec Messtechnik GmbH
13 * e-Mail: armlinux@phytec.de
15 * based on Intel Mainstone Board
17 * Copyright 2007 Juergen Beisert @ Pengutronix (j.beisert@pengutronix.de)
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>
27 #include <media/i2c/mt9v022.h>
28 #include <media/soc_camera.h>
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>
39 #include "devices.h"
40 #include "generic.h"
42 static unsigned long pcm990_pin_config[] __initdata = {
43 /* MMC */
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 /* USB */
51 GPIO88_USBH1_PWR,
52 GPIO89_USBH1_PEN,
53 /* PWM0 */
54 GPIO16_PWM0_OUT,
56 /* I2C */
57 GPIO117_I2C_SCL,
58 GPIO118_I2C_SDA,
60 /* AC97 */
61 GPIO28_AC97_BITCLK,
62 GPIO29_AC97_SDATA_IN_0,
63 GPIO30_AC97_SDATA_OUT,
64 GPIO31_AC97_SYNC,
67 static void __iomem *pcm990_cpld_base;
69 static u8 pcm990_cpld_readb(unsigned int reg)
71 return readb(pcm990_cpld_base + reg);
74 static void pcm990_cpld_writeb(u8 value, unsigned int reg)
76 writeb(value, pcm990_cpld_base + reg);
80 * pcm990_lcd_power - control power supply to the LCD
81 * @on: 0 = switch off, 1 = switch on
83 * Called by the pxafb driver
85 #ifndef CONFIG_PCM990_DISPLAY_NONE
86 static void pcm990_lcd_power(int on, struct fb_var_screeninfo *var)
88 if (on) {
89 /* enable LCD-Latches
90 * power on LCD
92 pcm990_cpld_writeb(PCM990_CTRL_LCDPWR + PCM990_CTRL_LCDON,
93 PCM990_CTRL_REG3);
94 } else {
95 /* disable LCD-Latches
96 * power off LCD
98 pcm990_cpld_writeb(0, PCM990_CTRL_REG3);
101 #endif
103 #if defined(CONFIG_PCM990_DISPLAY_SHARP)
104 static 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,
119 static 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,
125 #elif defined(CONFIG_PCM990_DISPLAY_NEC)
126 struct 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,
141 static 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,
147 #endif
149 static struct pwm_lookup pcm990_pwm_lookup[] = {
150 PWM_LOOKUP("pxa27x-pwm.0", 0, "pwm-backlight.0", NULL, 78770,
151 PWM_POLARITY_NORMAL),
154 static struct platform_pwm_backlight_data pcm990_backlight_data = {
155 .max_brightness = 1023,
156 .dft_brightness = 1023,
159 static struct platform_device pcm990_backlight_device = {
160 .name = "pwm-backlight",
161 .dev = {
162 .parent = &pxa27x_device_pwm0.dev,
163 .platform_data = &pcm990_backlight_data,
168 * The PCM-990 development baseboard uses PCM-027's hardware in the
169 * following way:
171 * - LCD support is in use
172 * - GPIO16 is output for back light on/off with PWM
173 * - GPIO58 ... GPIO73 are outputs for display data
174 * - GPIO74 is output output for LCDFCLK
175 * - GPIO75 is output for LCDLCLK
176 * - GPIO76 is output for LCDPCLK
177 * - GPIO77 is output for LCDBIAS
178 * - MMC support is in use
179 * - GPIO32 is output for MMCCLK
180 * - GPIO92 is MMDAT0
181 * - GPIO109 is MMDAT1
182 * - GPIO110 is MMCS0
183 * - GPIO111 is MMCS1
184 * - GPIO112 is MMCMD
185 * - IDE/CF card is in use
186 * - GPIO48 is output /POE
187 * - GPIO49 is output /PWE
188 * - GPIO50 is output /PIOR
189 * - GPIO51 is output /PIOW
190 * - GPIO54 is output /PCE2
191 * - GPIO55 is output /PREG
192 * - GPIO56 is input /PWAIT
193 * - GPIO57 is output /PIOS16
194 * - GPIO79 is output PSKTSEL
195 * - GPIO85 is output /PCE1
196 * - FFUART is in use
197 * - GPIO34 is input FFRXD
198 * - GPIO35 is input FFCTS
199 * - GPIO36 is input FFDCD
200 * - GPIO37 is input FFDSR
201 * - GPIO38 is input FFRI
202 * - GPIO39 is output FFTXD
203 * - GPIO40 is output FFDTR
204 * - GPIO41 is output FFRTS
205 * - BTUART is in use
206 * - GPIO42 is input BTRXD
207 * - GPIO43 is output BTTXD
208 * - GPIO44 is input BTCTS
209 * - GPIO45 is output BTRTS
210 * - IRUART is in use
211 * - GPIO46 is input STDRXD
212 * - GPIO47 is output STDTXD
213 * - AC97 is in use*)
214 * - GPIO28 is input AC97CLK
215 * - GPIO29 is input AC97DatIn
216 * - GPIO30 is output AC97DatO
217 * - GPIO31 is output AC97SYNC
218 * - GPIO113 is output AC97_RESET
219 * - SSP is in use
220 * - GPIO23 is output SSPSCLK
221 * - GPIO24 is output chip select to Max7301
222 * - GPIO25 is output SSPTXD
223 * - GPIO26 is input SSPRXD
224 * - GPIO27 is input for Max7301 IRQ
225 * - GPIO53 is input SSPSYSCLK
226 * - SSP3 is in use
227 * - GPIO81 is output SSPTXD3
228 * - GPIO82 is input SSPRXD3
229 * - GPIO83 is output SSPSFRM
230 * - GPIO84 is output SSPCLK3
232 * Otherwise claimed GPIOs:
233 * GPIO1 -> IRQ from user switch
234 * GPIO9 -> IRQ from power management
235 * GPIO10 -> IRQ from WML9712 AC97 controller
236 * GPIO11 -> IRQ from IDE controller
237 * GPIO12 -> IRQ from CF controller
238 * GPIO13 -> IRQ from CF controller
239 * GPIO14 -> GPIO free
240 * GPIO15 -> /CS1 selects baseboard's Control CPLD (U7, 16 bit wide data path)
241 * GPIO19 -> GPIO free
242 * GPIO20 -> /SDCS2
243 * GPIO21 -> /CS3 PC card socket select
244 * GPIO33 -> /CS5 network controller select
245 * GPIO78 -> /CS2 (16 bit wide data path)
246 * GPIO80 -> /CS4 (16 bit wide data path)
247 * GPIO86 -> GPIO free
248 * GPIO87 -> GPIO free
249 * GPIO90 -> LED0 on CPU module
250 * GPIO91 -> LED1 on CPI module
251 * GPIO117 -> SCL
252 * GPIO118 -> SDA
255 static unsigned long pcm990_irq_enabled;
257 static void pcm990_mask_ack_irq(struct irq_data *d)
259 int pcm990_irq = (d->irq - PCM027_IRQ(0));
261 pcm990_irq_enabled &= ~(1 << pcm990_irq);
263 pcm990_cpld_writeb(pcm990_irq_enabled, PCM990_CTRL_INTMSKENA);
266 static void pcm990_unmask_irq(struct irq_data *d)
268 int pcm990_irq = (d->irq - PCM027_IRQ(0));
269 u8 val;
271 /* the irq can be acknowledged only if deasserted, so it's done here */
273 pcm990_irq_enabled |= (1 << pcm990_irq);
275 val = pcm990_cpld_readb(PCM990_CTRL_INTSETCLR);
276 val |= 1 << pcm990_irq;
277 pcm990_cpld_writeb(val, PCM990_CTRL_INTSETCLR);
279 pcm990_cpld_writeb(pcm990_irq_enabled, PCM990_CTRL_INTMSKENA);
282 static struct irq_chip pcm990_irq_chip = {
283 .irq_mask_ack = pcm990_mask_ack_irq,
284 .irq_unmask = pcm990_unmask_irq,
287 static void pcm990_irq_handler(struct irq_desc *desc)
289 unsigned int irq;
290 unsigned long pending;
292 pending = ~pcm990_cpld_readb(PCM990_CTRL_INTSETCLR);
293 pending &= pcm990_irq_enabled;
295 do {
296 /* clear our parent IRQ */
297 desc->irq_data.chip->irq_ack(&desc->irq_data);
298 if (likely(pending)) {
299 irq = PCM027_IRQ(0) + __ffs(pending);
300 generic_handle_irq(irq);
302 pending = ~pcm990_cpld_readb(PCM990_CTRL_INTSETCLR);
303 pending &= pcm990_irq_enabled;
304 } while (pending);
307 static void __init pcm990_init_irq(void)
309 int irq;
311 /* setup extra PCM990 irqs */
312 for (irq = PCM027_IRQ(0); irq <= PCM027_IRQ(3); irq++) {
313 irq_set_chip_and_handler(irq, &pcm990_irq_chip,
314 handle_level_irq);
315 irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
318 /* disable all Interrupts */
319 pcm990_cpld_writeb(0x0, PCM990_CTRL_INTMSKENA);
320 pcm990_cpld_writeb(0xff, PCM990_CTRL_INTSETCLR);
322 irq_set_chained_handler(PCM990_CTRL_INT_IRQ, pcm990_irq_handler);
323 irq_set_irq_type(PCM990_CTRL_INT_IRQ, PCM990_CTRL_INT_IRQ_EDGE);
326 static int pcm990_mci_init(struct device *dev, irq_handler_t mci_detect_int,
327 void *data)
329 int err;
331 err = request_irq(PCM027_MMCDET_IRQ, mci_detect_int, 0,
332 "MMC card detect", data);
333 if (err)
334 printk(KERN_ERR "pcm990_mci_init: MMC/SD: can't request MMC "
335 "card detect IRQ\n");
337 return err;
340 static int pcm990_mci_setpower(struct device *dev, unsigned int vdd)
342 struct pxamci_platform_data *p_d = dev->platform_data;
343 u8 val;
345 val = pcm990_cpld_readb(PCM990_CTRL_REG5);
347 if ((1 << vdd) & p_d->ocr_mask)
348 val |= PCM990_CTRL_MMC2PWR;
349 else
350 val &= ~PCM990_CTRL_MMC2PWR;
352 pcm990_cpld_writeb(PCM990_CTRL_MMC2PWR, PCM990_CTRL_REG5);
353 return 0;
356 static void pcm990_mci_exit(struct device *dev, void *data)
358 free_irq(PCM027_MMCDET_IRQ, data);
361 #define MSECS_PER_JIFFY (1000/HZ)
363 static struct pxamci_platform_data pcm990_mci_platform_data = {
364 .detect_delay_ms = 250,
365 .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
366 .init = pcm990_mci_init,
367 .setpower = pcm990_mci_setpower,
368 .exit = pcm990_mci_exit,
371 static struct pxaohci_platform_data pcm990_ohci_platform_data = {
372 .port_mode = PMM_PERPORT_MODE,
373 .flags = ENABLE_PORT1 | POWER_CONTROL_LOW | POWER_SENSE_LOW,
374 .power_on_delay = 10,
378 * PXA27x Camera specific stuff
380 #if defined(CONFIG_VIDEO_PXA27x) || defined(CONFIG_VIDEO_PXA27x_MODULE)
381 static unsigned long pcm990_camera_pin_config[] = {
382 /* CIF */
383 GPIO98_CIF_DD_0,
384 GPIO105_CIF_DD_1,
385 GPIO104_CIF_DD_2,
386 GPIO103_CIF_DD_3,
387 GPIO95_CIF_DD_4,
388 GPIO94_CIF_DD_5,
389 GPIO93_CIF_DD_6,
390 GPIO108_CIF_DD_7,
391 GPIO107_CIF_DD_8,
392 GPIO106_CIF_DD_9,
393 GPIO42_CIF_MCLK,
394 GPIO45_CIF_PCLK,
395 GPIO43_CIF_FV,
396 GPIO44_CIF_LV,
400 * CICR4: PCLK_EN: Pixel clock is supplied by the sensor
401 * MCLK_EN: Master clock is generated by PXA
402 * PCP: Data sampled on the falling edge of pixel clock
404 struct pxacamera_platform_data pcm990_pxacamera_platform_data = {
405 .flags = PXA_CAMERA_MASTER | PXA_CAMERA_DATAWIDTH_8 | PXA_CAMERA_DATAWIDTH_10 |
406 PXA_CAMERA_PCLK_EN | PXA_CAMERA_MCLK_EN/* | PXA_CAMERA_PCP*/,
407 .mclk_10khz = 1000,
410 #include <linux/platform_data/pca953x.h>
412 static struct pca953x_platform_data pca9536_data = {
413 .gpio_base = PXA_NR_BUILTIN_GPIO,
416 static int gpio_bus_switch = -EINVAL;
418 static int pcm990_camera_set_bus_param(struct soc_camera_link *link,
419 unsigned long flags)
421 if (gpio_bus_switch < 0) {
422 if (flags == SOCAM_DATAWIDTH_10)
423 return 0;
424 else
425 return -EINVAL;
428 if (flags & SOCAM_DATAWIDTH_8)
429 gpio_set_value_cansleep(gpio_bus_switch, 1);
430 else
431 gpio_set_value_cansleep(gpio_bus_switch, 0);
433 return 0;
436 static unsigned long pcm990_camera_query_bus_param(struct soc_camera_link *link)
438 int ret;
440 if (gpio_bus_switch < 0) {
441 ret = gpio_request(PXA_NR_BUILTIN_GPIO, "camera");
442 if (!ret) {
443 gpio_bus_switch = PXA_NR_BUILTIN_GPIO;
444 gpio_direction_output(gpio_bus_switch, 0);
448 if (gpio_bus_switch >= 0)
449 return SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_10;
450 else
451 return SOCAM_DATAWIDTH_10;
454 static void pcm990_camera_free_bus(struct soc_camera_link *link)
456 if (gpio_bus_switch < 0)
457 return;
459 gpio_free(gpio_bus_switch);
460 gpio_bus_switch = -EINVAL;
463 /* Board I2C devices. */
464 static struct i2c_board_info __initdata pcm990_i2c_devices[] = {
466 /* Must initialize before the camera(s) */
467 I2C_BOARD_INFO("pca9536", 0x41),
468 .platform_data = &pca9536_data,
472 static struct mt9v022_platform_data mt9v022_pdata = {
473 .y_skip_top = 1,
476 static struct i2c_board_info pcm990_camera_i2c[] = {
478 I2C_BOARD_INFO("mt9v022", 0x48),
479 }, {
480 I2C_BOARD_INFO("mt9m001", 0x5d),
484 static struct soc_camera_link iclink[] = {
486 .bus_id = 0, /* Must match with the camera ID */
487 .board_info = &pcm990_camera_i2c[0],
488 .priv = &mt9v022_pdata,
489 .i2c_adapter_id = 0,
490 .query_bus_param = pcm990_camera_query_bus_param,
491 .set_bus_param = pcm990_camera_set_bus_param,
492 .free_bus = pcm990_camera_free_bus,
493 }, {
494 .bus_id = 0, /* Must match with the camera ID */
495 .board_info = &pcm990_camera_i2c[1],
496 .i2c_adapter_id = 0,
497 .query_bus_param = pcm990_camera_query_bus_param,
498 .set_bus_param = pcm990_camera_set_bus_param,
499 .free_bus = pcm990_camera_free_bus,
503 static struct platform_device pcm990_camera[] = {
505 .name = "soc-camera-pdrv",
506 .id = 0,
507 .dev = {
508 .platform_data = &iclink[0],
510 }, {
511 .name = "soc-camera-pdrv",
512 .id = 1,
513 .dev = {
514 .platform_data = &iclink[1],
518 #endif /* CONFIG_VIDEO_PXA27x ||CONFIG_VIDEO_PXA27x_MODULE */
521 * system init for baseboard usage. Will be called by pcm027 init.
523 * Add platform devices present on this baseboard and init
524 * them from CPU side as far as required to use them later on
526 void __init pcm990_baseboard_init(void)
528 pxa2xx_mfp_config(ARRAY_AND_SIZE(pcm990_pin_config));
530 pcm990_cpld_base = ioremap(PCM990_CTRL_PHYS, PCM990_CTRL_SIZE);
531 if (!pcm990_cpld_base) {
532 pr_err("pcm990: failed to ioremap cpld\n");
533 return;
536 /* register CPLD's IRQ controller */
537 pcm990_init_irq();
539 #ifndef CONFIG_PCM990_DISPLAY_NONE
540 pxa_set_fb_info(NULL, &pcm990_fbinfo);
541 #endif
542 pwm_add_table(pcm990_pwm_lookup, ARRAY_SIZE(pcm990_pwm_lookup));
543 platform_device_register(&pcm990_backlight_device);
545 /* MMC */
546 pxa_set_mci_info(&pcm990_mci_platform_data);
548 /* USB host */
549 pxa_set_ohci_info(&pcm990_ohci_platform_data);
551 pxa_set_i2c_info(NULL);
552 pxa_set_ac97_info(NULL);
554 #if defined(CONFIG_VIDEO_PXA27x) || defined(CONFIG_VIDEO_PXA27x_MODULE)
555 pxa2xx_mfp_config(ARRAY_AND_SIZE(pcm990_camera_pin_config));
556 pxa_set_camera_info(&pcm990_pxacamera_platform_data);
558 i2c_register_board_info(0, ARRAY_AND_SIZE(pcm990_i2c_devices));
560 platform_device_register(&pcm990_camera[0]);
561 platform_device_register(&pcm990_camera[1]);
562 #endif
564 printk(KERN_INFO "PCM-990 Evaluation baseboard initialized\n");