1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * mach-imx27_visstrim_m10.c
5 * Copyright 2010 Javier Martin <javier.martin@vista-silicon.com>
7 * Based on mach-pcm038.c, mach-pca100.c, mach-mx27ads.c and others.
10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 #include <linux/platform_device.h>
13 #include <linux/mtd/physmap.h>
14 #include <linux/i2c.h>
15 #include <linux/platform_data/pca953x.h>
16 #include <linux/input.h>
17 #include <linux/gpio.h>
18 #include <linux/delay.h>
19 #include <linux/dma-mapping.h>
20 #include <linux/leds.h>
21 #include <linux/platform_data/asoc-mx27vis.h>
22 #include <media/soc_camera.h>
23 #include <sound/tlv320aic32x4.h>
24 #include <asm/mach-types.h>
25 #include <asm/mach/arch.h>
26 #include <asm/mach/time.h>
27 #include <asm/system_info.h>
28 #include <asm/memblock.h>
31 #include "devices-imx27.h"
34 #include "iomux-mx27.h"
36 #define TVP5150_RSTN (GPIO_PORTC + 18)
37 #define TVP5150_PWDN (GPIO_PORTC + 19)
38 #define OTG_PHY_CS_GPIO (GPIO_PORTF + 17)
39 #define SDHC1_IRQ_GPIO IMX_GPIO_NR(2, 25)
41 #define VERSION_MASK 0x7
42 #define MOTHERBOARD_SHIFT 4
43 #define EXPBOARD_SHIFT 0
45 #define MOTHERBOARD_BIT2 (GPIO_PORTD + 31)
46 #define MOTHERBOARD_BIT1 (GPIO_PORTD + 30)
47 #define MOTHERBOARD_BIT0 (GPIO_PORTD + 29)
49 #define EXPBOARD_BIT2 (GPIO_PORTD + 25)
50 #define EXPBOARD_BIT1 (GPIO_PORTD + 27)
51 #define EXPBOARD_BIT0 (GPIO_PORTD + 28)
53 #define AMP_GAIN_0 (GPIO_PORTF + 9)
54 #define AMP_GAIN_1 (GPIO_PORTF + 8)
55 #define AMP_MUTE_SDL (GPIO_PORTE + 5)
56 #define AMP_MUTE_SDR (GPIO_PORTF + 7)
58 static const int visstrim_m10_pins
[] __initconst
= {
101 OTG_PHY_CS_GPIO
| GPIO_GPIO
| GPIO_OUT
,
103 PC11_PF_USBOTG_DATA1
,
104 PC10_PF_USBOTG_DATA2
,
105 PC13_PF_USBOTG_DATA3
,
106 PC12_PF_USBOTG_DATA4
,
109 PE25_PF_USBOTG_DATA7
,
117 TVP5150_RSTN
| GPIO_GPIO
| GPIO_OUT
,
118 TVP5150_PWDN
| GPIO_GPIO
| GPIO_OUT
,
131 /* mother board version */
132 MOTHERBOARD_BIT2
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
133 MOTHERBOARD_BIT1
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
134 MOTHERBOARD_BIT0
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
135 /* expansion board version */
136 EXPBOARD_BIT2
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
137 EXPBOARD_BIT1
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
138 EXPBOARD_BIT0
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
139 /* Audio AMP control */
140 AMP_GAIN_0
| GPIO_GPIO
| GPIO_OUT
,
141 AMP_GAIN_1
| GPIO_GPIO
| GPIO_OUT
,
142 AMP_MUTE_SDL
| GPIO_GPIO
| GPIO_OUT
,
143 AMP_MUTE_SDR
| GPIO_GPIO
| GPIO_OUT
,
146 static struct gpio visstrim_m10_version_gpios
[] = {
147 { EXPBOARD_BIT0
, GPIOF_IN
, "exp-version-0" },
148 { EXPBOARD_BIT1
, GPIOF_IN
, "exp-version-1" },
149 { EXPBOARD_BIT2
, GPIOF_IN
, "exp-version-2" },
150 { MOTHERBOARD_BIT0
, GPIOF_IN
, "mother-version-0" },
151 { MOTHERBOARD_BIT1
, GPIOF_IN
, "mother-version-1" },
152 { MOTHERBOARD_BIT2
, GPIOF_IN
, "mother-version-2" },
155 static const struct gpio visstrim_m10_gpios
[] __initconst
= {
157 .gpio
= TVP5150_RSTN
,
158 .flags
= GPIOF_DIR_OUT
| GPIOF_INIT_HIGH
,
159 .label
= "tvp5150_rstn",
162 .gpio
= TVP5150_PWDN
,
163 .flags
= GPIOF_DIR_OUT
| GPIOF_INIT_LOW
,
164 .label
= "tvp5150_pwdn",
167 .gpio
= OTG_PHY_CS_GPIO
,
168 .flags
= GPIOF_DIR_OUT
| GPIOF_INIT_LOW
,
169 .label
= "usbotg_cs",
173 .flags
= GPIOF_DIR_OUT
,
174 .label
= "amp-gain-0",
178 .flags
= GPIOF_DIR_OUT
,
179 .label
= "amp-gain-1",
182 .gpio
= AMP_MUTE_SDL
,
183 .flags
= GPIOF_DIR_OUT
,
184 .label
= "amp-mute-sdl",
187 .gpio
= AMP_MUTE_SDR
,
188 .flags
= GPIOF_DIR_OUT
,
189 .label
= "amp-mute-sdr",
194 static int visstrim_camera_power(struct device
*dev
, int on
)
196 gpio_set_value(TVP5150_PWDN
, on
);
201 static int visstrim_camera_reset(struct device
*dev
)
203 gpio_set_value(TVP5150_RSTN
, 0);
205 gpio_set_value(TVP5150_RSTN
, 1);
210 static struct i2c_board_info visstrim_i2c_camera
= {
211 I2C_BOARD_INFO("tvp5150", 0x5d),
214 static struct soc_camera_link iclink_tvp5150
= {
216 .board_info
= &visstrim_i2c_camera
,
218 .power
= visstrim_camera_power
,
219 .reset
= visstrim_camera_reset
,
222 static struct mx2_camera_platform_data visstrim_camera
= {
223 .flags
= MX2_CAMERA_CCIR
| MX2_CAMERA_CCIR_INTERLACE
|
224 MX2_CAMERA_PCLK_SAMPLE_RISING
,
228 static phys_addr_t mx2_camera_base __initdata
;
229 #define MX2_CAMERA_BUF_SIZE SZ_8M
231 static void __init
visstrim_analog_camera_init(void)
233 struct platform_device
*pdev
;
235 gpio_set_value(TVP5150_PWDN
, 1);
237 gpio_set_value(TVP5150_RSTN
, 0);
239 gpio_set_value(TVP5150_RSTN
, 1);
242 pdev
= imx27_add_mx2_camera(&visstrim_camera
);
246 dma_declare_coherent_memory(&pdev
->dev
, mx2_camera_base
,
247 mx2_camera_base
, MX2_CAMERA_BUF_SIZE
);
250 static void __init
visstrim_reserve(void)
252 /* reserve 4 MiB for mx2-camera */
253 mx2_camera_base
= arm_memblock_steal(3 * MX2_CAMERA_BUF_SIZE
,
254 MX2_CAMERA_BUF_SIZE
);
257 /* GPIOs used as events for applications */
258 static struct gpio_keys_button visstrim_gpio_keys
[] = {
262 .gpio
= (GPIO_PORTC
+ 15),
263 .desc
= "Default config",
270 .gpio
= (GPIO_PORTF
+ 14),
278 .gpio
= (GPIO_PORTF
+ 13),
285 static const struct gpio_keys_platform_data
286 visstrim_gpio_keys_platform_data __initconst
= {
287 .buttons
= visstrim_gpio_keys
,
288 .nbuttons
= ARRAY_SIZE(visstrim_gpio_keys
),
292 static const struct gpio_led visstrim_m10_leds
[] __initconst
= {
294 .name
= "visstrim:ld0",
295 .default_trigger
= "nand-disk",
296 .gpio
= (GPIO_PORTC
+ 29),
299 .name
= "visstrim:ld1",
300 .default_trigger
= "nand-disk",
301 .gpio
= (GPIO_PORTC
+ 24),
304 .name
= "visstrim:ld2",
305 .default_trigger
= "nand-disk",
306 .gpio
= (GPIO_PORTC
+ 28),
309 .name
= "visstrim:ld3",
310 .default_trigger
= "nand-disk",
311 .gpio
= (GPIO_PORTC
+ 25),
315 static const struct gpio_led_platform_data visstrim_m10_led_data __initconst
= {
316 .leds
= visstrim_m10_leds
,
317 .num_leds
= ARRAY_SIZE(visstrim_m10_leds
),
320 /* Visstrim_SM10 has a microSD slot connected to sdhc1 */
321 static int visstrim_m10_sdhc1_init(struct device
*dev
,
322 irq_handler_t detect_irq
, void *data
)
326 ret
= request_irq(gpio_to_irq(SDHC1_IRQ_GPIO
), detect_irq
,
327 IRQF_TRIGGER_FALLING
, "mmc-detect", data
);
331 static void visstrim_m10_sdhc1_exit(struct device
*dev
, void *data
)
333 free_irq(gpio_to_irq(SDHC1_IRQ_GPIO
), data
);
336 static const struct imxmmc_platform_data visstrim_m10_sdhc_pdata __initconst
= {
337 .init
= visstrim_m10_sdhc1_init
,
338 .exit
= visstrim_m10_sdhc1_exit
,
341 /* Visstrim_SM10 NOR flash */
342 static struct physmap_flash_data visstrim_m10_flash_data
= {
346 static struct resource visstrim_m10_flash_resource
= {
348 .end
= 0xc0000000 + SZ_64M
- 1,
349 .flags
= IORESOURCE_MEM
,
352 static struct platform_device visstrim_m10_nor_mtd_device
= {
353 .name
= "physmap-flash",
356 .platform_data
= &visstrim_m10_flash_data
,
359 .resource
= &visstrim_m10_flash_resource
,
362 static struct platform_device
*platform_devices
[] __initdata
= {
363 &visstrim_m10_nor_mtd_device
,
366 /* Visstrim_M10 uses UART0 as console */
367 static const struct imxuart_platform_data uart_pdata __initconst
= {
368 .flags
= IMXUART_HAVE_RTSCTS
,
372 static const struct imxi2c_platform_data visstrim_m10_i2c_data __initconst
= {
376 static struct pca953x_platform_data visstrim_m10_pca9555_pdata
= {
377 .gpio_base
= 240, /* After MX27 internal GPIOs */
381 static struct aic32x4_pdata visstrim_m10_aic32x4_pdata
= {
382 .power_cfg
= AIC32X4_PWR_MICBIAS_2075_LDOIN
|
383 AIC32X4_PWR_AVDD_DVDD_WEAK_DISABLE
|
384 AIC32X4_PWR_AIC32X4_LDO_ENABLE
|
385 AIC32X4_PWR_CMMODE_LDOIN_RANGE_18_36
|
386 AIC32X4_PWR_CMMODE_HP_LDOIN_POWERED
,
387 .micpga_routing
= AIC32X4_MICPGA_ROUTE_LMIC_IN2R_10K
|
388 AIC32X4_MICPGA_ROUTE_RMIC_IN1L_10K
,
392 static struct i2c_board_info visstrim_m10_i2c_devices
[] = {
394 I2C_BOARD_INFO("pca9555", 0x20),
395 .platform_data
= &visstrim_m10_pca9555_pdata
,
398 I2C_BOARD_INFO("tlv320aic32x4", 0x18),
399 .platform_data
= &visstrim_m10_aic32x4_pdata
,
402 I2C_BOARD_INFO("m41t00", 0x68),
407 static int otg_phy_init(struct platform_device
*pdev
)
409 return mx27_initialize_usb_hw(pdev
->id
, MXC_EHCI_POWER_PINS_ENABLED
);
412 static const struct mxc_usbh_platform_data
413 visstrim_m10_usbotg_pdata __initconst
= {
414 .init
= otg_phy_init
,
415 .portsc
= MXC_EHCI_MODE_ULPI
| MXC_EHCI_UTMI_8BIT
,
419 static const struct imx_ssi_platform_data visstrim_m10_ssi_pdata __initconst
= {
420 .flags
= IMX_SSI_DMA
| IMX_SSI_SYN
,
425 static void __init
visstrim_coda_init(void)
427 struct platform_device
*pdev
;
429 pdev
= imx27_add_coda();
430 dma_declare_coherent_memory(&pdev
->dev
,
431 mx2_camera_base
+ MX2_CAMERA_BUF_SIZE
,
432 mx2_camera_base
+ MX2_CAMERA_BUF_SIZE
,
433 MX2_CAMERA_BUF_SIZE
);
436 /* DMA deinterlace */
437 static struct platform_device visstrim_deinterlace
= {
438 .name
= "m2m-deinterlace",
442 static void __init
visstrim_deinterlace_init(void)
445 struct platform_device
*pdev
= &visstrim_deinterlace
;
447 ret
= platform_device_register(pdev
);
449 dma_declare_coherent_memory(&pdev
->dev
,
450 mx2_camera_base
+ 2 * MX2_CAMERA_BUF_SIZE
,
451 mx2_camera_base
+ 2 * MX2_CAMERA_BUF_SIZE
,
452 MX2_CAMERA_BUF_SIZE
);
455 /* Emma-PrP for format conversion */
456 static void __init
visstrim_emmaprp_init(void)
458 struct platform_device
*pdev
;
461 pdev
= imx27_add_mx2_emmaprp();
466 * Use the same memory area as the analog camera since both
467 * devices are, by nature, exclusive.
469 ret
= dma_declare_coherent_memory(&pdev
->dev
,
470 mx2_camera_base
, mx2_camera_base
,
471 MX2_CAMERA_BUF_SIZE
);
473 pr_err("Failed to declare memory for emmaprp\n");
477 static const struct snd_mx27vis_platform_data snd_mx27vis_pdata __initconst
= {
478 .amp_gain0_gpio
= AMP_GAIN_0
,
479 .amp_gain1_gpio
= AMP_GAIN_1
,
480 .amp_mutel_gpio
= AMP_MUTE_SDL
,
481 .amp_muter_gpio
= AMP_MUTE_SDR
,
484 static void __init
visstrim_m10_revision(void)
490 ret
= gpio_request_array(visstrim_m10_version_gpios
,
491 ARRAY_SIZE(visstrim_m10_version_gpios
));
493 pr_err("Failed to request version gpios");
497 /* Get expansion board version (negative logic) */
498 exp_version
|= !gpio_get_value(EXPBOARD_BIT2
) << 2;
499 exp_version
|= !gpio_get_value(EXPBOARD_BIT1
) << 1;
500 exp_version
|= !gpio_get_value(EXPBOARD_BIT0
);
502 /* Get mother board version (negative logic) */
503 mo_version
|= !gpio_get_value(MOTHERBOARD_BIT2
) << 2;
504 mo_version
|= !gpio_get_value(MOTHERBOARD_BIT1
) << 1;
505 mo_version
|= !gpio_get_value(MOTHERBOARD_BIT0
);
507 system_rev
= 0x27000;
508 system_rev
|= (mo_version
<< MOTHERBOARD_SHIFT
);
509 system_rev
|= (exp_version
<< EXPBOARD_SHIFT
);
512 static void __init
visstrim_m10_board_init(void)
517 visstrim_m10_revision();
519 ret
= mxc_gpio_setup_multiple_pins(visstrim_m10_pins
,
520 ARRAY_SIZE(visstrim_m10_pins
), "VISSTRIM_M10");
522 pr_err("Failed to setup pins (%d)\n", ret
);
524 imx27_add_imx_ssi(0, &visstrim_m10_ssi_pdata
);
525 imx27_add_imx_uart0(&uart_pdata
);
527 imx27_add_imx_i2c(0, &visstrim_m10_i2c_data
);
528 imx27_add_imx_i2c(1, &visstrim_m10_i2c_data
);
529 i2c_register_board_info(0, visstrim_m10_i2c_devices
,
530 ARRAY_SIZE(visstrim_m10_i2c_devices
));
532 imx27_add_mxc_mmc(0, &visstrim_m10_sdhc_pdata
);
533 imx27_add_mxc_ehci_otg(&visstrim_m10_usbotg_pdata
);
536 platform_add_devices(platform_devices
, ARRAY_SIZE(platform_devices
));
539 static void __init
visstrim_m10_late_init(void)
543 ret
= gpio_request_array(visstrim_m10_gpios
,
544 ARRAY_SIZE(visstrim_m10_gpios
));
546 pr_err("Failed to request gpios (%d)\n", ret
);
548 imx_add_gpio_keys(&visstrim_gpio_keys_platform_data
);
550 imx_add_platform_device("mx27vis", 0, NULL
, 0, &snd_mx27vis_pdata
,
551 sizeof(snd_mx27vis_pdata
));
552 platform_device_register_resndata(NULL
, "soc-camera-pdrv", 0, NULL
, 0,
553 &iclink_tvp5150
, sizeof(iclink_tvp5150
));
555 gpio_led_register_device(0, &visstrim_m10_led_data
);
557 /* Use mother board version to decide what video devices we shall use */
558 mo_version
= (system_rev
>> MOTHERBOARD_SHIFT
) & VERSION_MASK
;
559 if (mo_version
& 0x1) {
560 visstrim_emmaprp_init();
563 * Despite not being used, tvp5150 must be
564 * powered on to avoid I2C problems. To minimize
565 * power consupmtion keep reset enabled.
567 gpio_set_value(TVP5150_PWDN
, 1);
569 gpio_set_value(TVP5150_RSTN
, 0);
571 visstrim_deinterlace_init();
572 visstrim_analog_camera_init();
575 visstrim_coda_init();
578 static void __init
visstrim_m10_timer_init(void)
580 mx27_clocks_init((unsigned long)25000000);
583 MACHINE_START(IMX27_VISSTRIM_M10
, "Vista Silicon Visstrim_M10")
584 .atag_offset
= 0x100,
585 .reserve
= visstrim_reserve
,
586 .map_io
= mx27_map_io
,
587 .init_early
= imx27_init_early
,
588 .init_irq
= mx27_init_irq
,
589 .init_time
= visstrim_m10_timer_init
,
590 .init_machine
= visstrim_m10_board_init
,
591 .init_late
= visstrim_m10_late_init
,
592 .restart
= mxc_restart
,