2 * mach-imx27_visstrim_m10.c
4 * Copyright 2010 Javier Martin <javier.martin@vista-silicon.com>
6 * Based on mach-pcm038.c, mach-pca100.c, mach-mx27ads.c and others.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26 #include <linux/platform_device.h>
27 #include <linux/mtd/physmap.h>
28 #include <linux/i2c.h>
29 #include <linux/platform_data/pca953x.h>
30 #include <linux/input.h>
31 #include <linux/gpio.h>
32 #include <linux/delay.h>
33 #include <linux/dma-mapping.h>
34 #include <linux/leds.h>
35 #include <linux/platform_data/asoc-mx27vis.h>
36 #include <media/soc_camera.h>
37 #include <sound/tlv320aic32x4.h>
38 #include <asm/mach-types.h>
39 #include <asm/mach/arch.h>
40 #include <asm/mach/time.h>
41 #include <asm/system_info.h>
42 #include <asm/memblock.h>
45 #include "devices-imx27.h"
48 #include "iomux-mx27.h"
50 #define TVP5150_RSTN (GPIO_PORTC + 18)
51 #define TVP5150_PWDN (GPIO_PORTC + 19)
52 #define OTG_PHY_CS_GPIO (GPIO_PORTF + 17)
53 #define SDHC1_IRQ_GPIO IMX_GPIO_NR(2, 25)
55 #define VERSION_MASK 0x7
56 #define MOTHERBOARD_SHIFT 4
57 #define EXPBOARD_SHIFT 0
59 #define MOTHERBOARD_BIT2 (GPIO_PORTD + 31)
60 #define MOTHERBOARD_BIT1 (GPIO_PORTD + 30)
61 #define MOTHERBOARD_BIT0 (GPIO_PORTD + 29)
63 #define EXPBOARD_BIT2 (GPIO_PORTD + 25)
64 #define EXPBOARD_BIT1 (GPIO_PORTD + 27)
65 #define EXPBOARD_BIT0 (GPIO_PORTD + 28)
67 #define AMP_GAIN_0 (GPIO_PORTF + 9)
68 #define AMP_GAIN_1 (GPIO_PORTF + 8)
69 #define AMP_MUTE_SDL (GPIO_PORTE + 5)
70 #define AMP_MUTE_SDR (GPIO_PORTF + 7)
72 static const int visstrim_m10_pins
[] __initconst
= {
115 OTG_PHY_CS_GPIO
| GPIO_GPIO
| GPIO_OUT
,
117 PC11_PF_USBOTG_DATA1
,
118 PC10_PF_USBOTG_DATA2
,
119 PC13_PF_USBOTG_DATA3
,
120 PC12_PF_USBOTG_DATA4
,
123 PE25_PF_USBOTG_DATA7
,
131 TVP5150_RSTN
| GPIO_GPIO
| GPIO_OUT
,
132 TVP5150_PWDN
| GPIO_GPIO
| GPIO_OUT
,
145 /* mother board version */
146 MOTHERBOARD_BIT2
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
147 MOTHERBOARD_BIT1
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
148 MOTHERBOARD_BIT0
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
149 /* expansion board version */
150 EXPBOARD_BIT2
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
151 EXPBOARD_BIT1
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
152 EXPBOARD_BIT0
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
153 /* Audio AMP control */
154 AMP_GAIN_0
| GPIO_GPIO
| GPIO_OUT
,
155 AMP_GAIN_1
| GPIO_GPIO
| GPIO_OUT
,
156 AMP_MUTE_SDL
| GPIO_GPIO
| GPIO_OUT
,
157 AMP_MUTE_SDR
| GPIO_GPIO
| GPIO_OUT
,
160 static struct gpio visstrim_m10_version_gpios
[] = {
161 { EXPBOARD_BIT0
, GPIOF_IN
, "exp-version-0" },
162 { EXPBOARD_BIT1
, GPIOF_IN
, "exp-version-1" },
163 { EXPBOARD_BIT2
, GPIOF_IN
, "exp-version-2" },
164 { MOTHERBOARD_BIT0
, GPIOF_IN
, "mother-version-0" },
165 { MOTHERBOARD_BIT1
, GPIOF_IN
, "mother-version-1" },
166 { MOTHERBOARD_BIT2
, GPIOF_IN
, "mother-version-2" },
169 static const struct gpio visstrim_m10_gpios
[] __initconst
= {
171 .gpio
= TVP5150_RSTN
,
172 .flags
= GPIOF_DIR_OUT
| GPIOF_INIT_HIGH
,
173 .label
= "tvp5150_rstn",
176 .gpio
= TVP5150_PWDN
,
177 .flags
= GPIOF_DIR_OUT
| GPIOF_INIT_LOW
,
178 .label
= "tvp5150_pwdn",
181 .gpio
= OTG_PHY_CS_GPIO
,
182 .flags
= GPIOF_DIR_OUT
| GPIOF_INIT_LOW
,
183 .label
= "usbotg_cs",
187 .flags
= GPIOF_DIR_OUT
,
188 .label
= "amp-gain-0",
192 .flags
= GPIOF_DIR_OUT
,
193 .label
= "amp-gain-1",
196 .gpio
= AMP_MUTE_SDL
,
197 .flags
= GPIOF_DIR_OUT
,
198 .label
= "amp-mute-sdl",
201 .gpio
= AMP_MUTE_SDR
,
202 .flags
= GPIOF_DIR_OUT
,
203 .label
= "amp-mute-sdr",
208 static int visstrim_camera_power(struct device
*dev
, int on
)
210 gpio_set_value(TVP5150_PWDN
, on
);
215 static int visstrim_camera_reset(struct device
*dev
)
217 gpio_set_value(TVP5150_RSTN
, 0);
219 gpio_set_value(TVP5150_RSTN
, 1);
224 static struct i2c_board_info visstrim_i2c_camera
= {
225 I2C_BOARD_INFO("tvp5150", 0x5d),
228 static struct soc_camera_link iclink_tvp5150
= {
230 .board_info
= &visstrim_i2c_camera
,
232 .power
= visstrim_camera_power
,
233 .reset
= visstrim_camera_reset
,
236 static struct mx2_camera_platform_data visstrim_camera
= {
237 .flags
= MX2_CAMERA_CCIR
| MX2_CAMERA_CCIR_INTERLACE
|
238 MX2_CAMERA_PCLK_SAMPLE_RISING
,
242 static phys_addr_t mx2_camera_base __initdata
;
243 #define MX2_CAMERA_BUF_SIZE SZ_8M
245 static void __init
visstrim_analog_camera_init(void)
247 struct platform_device
*pdev
;
249 gpio_set_value(TVP5150_PWDN
, 1);
251 gpio_set_value(TVP5150_RSTN
, 0);
253 gpio_set_value(TVP5150_RSTN
, 1);
256 pdev
= imx27_add_mx2_camera(&visstrim_camera
);
260 dma_declare_coherent_memory(&pdev
->dev
, mx2_camera_base
,
261 mx2_camera_base
, MX2_CAMERA_BUF_SIZE
,
262 DMA_MEMORY_EXCLUSIVE
);
265 static void __init
visstrim_reserve(void)
267 /* reserve 4 MiB for mx2-camera */
268 mx2_camera_base
= arm_memblock_steal(3 * MX2_CAMERA_BUF_SIZE
,
269 MX2_CAMERA_BUF_SIZE
);
272 /* GPIOs used as events for applications */
273 static struct gpio_keys_button visstrim_gpio_keys
[] = {
277 .gpio
= (GPIO_PORTC
+ 15),
278 .desc
= "Default config",
285 .gpio
= (GPIO_PORTF
+ 14),
293 .gpio
= (GPIO_PORTF
+ 13),
300 static const struct gpio_keys_platform_data
301 visstrim_gpio_keys_platform_data __initconst
= {
302 .buttons
= visstrim_gpio_keys
,
303 .nbuttons
= ARRAY_SIZE(visstrim_gpio_keys
),
307 static const struct gpio_led visstrim_m10_leds
[] __initconst
= {
309 .name
= "visstrim:ld0",
310 .default_trigger
= "nand-disk",
311 .gpio
= (GPIO_PORTC
+ 29),
314 .name
= "visstrim:ld1",
315 .default_trigger
= "nand-disk",
316 .gpio
= (GPIO_PORTC
+ 24),
319 .name
= "visstrim:ld2",
320 .default_trigger
= "nand-disk",
321 .gpio
= (GPIO_PORTC
+ 28),
324 .name
= "visstrim:ld3",
325 .default_trigger
= "nand-disk",
326 .gpio
= (GPIO_PORTC
+ 25),
330 static const struct gpio_led_platform_data visstrim_m10_led_data __initconst
= {
331 .leds
= visstrim_m10_leds
,
332 .num_leds
= ARRAY_SIZE(visstrim_m10_leds
),
335 /* Visstrim_SM10 has a microSD slot connected to sdhc1 */
336 static int visstrim_m10_sdhc1_init(struct device
*dev
,
337 irq_handler_t detect_irq
, void *data
)
341 ret
= request_irq(gpio_to_irq(SDHC1_IRQ_GPIO
), detect_irq
,
342 IRQF_TRIGGER_FALLING
, "mmc-detect", data
);
346 static void visstrim_m10_sdhc1_exit(struct device
*dev
, void *data
)
348 free_irq(gpio_to_irq(SDHC1_IRQ_GPIO
), data
);
351 static const struct imxmmc_platform_data visstrim_m10_sdhc_pdata __initconst
= {
352 .init
= visstrim_m10_sdhc1_init
,
353 .exit
= visstrim_m10_sdhc1_exit
,
356 /* Visstrim_SM10 NOR flash */
357 static struct physmap_flash_data visstrim_m10_flash_data
= {
361 static struct resource visstrim_m10_flash_resource
= {
363 .end
= 0xc0000000 + SZ_64M
- 1,
364 .flags
= IORESOURCE_MEM
,
367 static struct platform_device visstrim_m10_nor_mtd_device
= {
368 .name
= "physmap-flash",
371 .platform_data
= &visstrim_m10_flash_data
,
374 .resource
= &visstrim_m10_flash_resource
,
377 static struct platform_device
*platform_devices
[] __initdata
= {
378 &visstrim_m10_nor_mtd_device
,
381 /* Visstrim_M10 uses UART0 as console */
382 static const struct imxuart_platform_data uart_pdata __initconst
= {
383 .flags
= IMXUART_HAVE_RTSCTS
,
387 static const struct imxi2c_platform_data visstrim_m10_i2c_data __initconst
= {
391 static struct pca953x_platform_data visstrim_m10_pca9555_pdata
= {
392 .gpio_base
= 240, /* After MX27 internal GPIOs */
396 static struct aic32x4_pdata visstrim_m10_aic32x4_pdata
= {
397 .power_cfg
= AIC32X4_PWR_MICBIAS_2075_LDOIN
|
398 AIC32X4_PWR_AVDD_DVDD_WEAK_DISABLE
|
399 AIC32X4_PWR_AIC32X4_LDO_ENABLE
|
400 AIC32X4_PWR_CMMODE_LDOIN_RANGE_18_36
|
401 AIC32X4_PWR_CMMODE_HP_LDOIN_POWERED
,
402 .micpga_routing
= AIC32X4_MICPGA_ROUTE_LMIC_IN2R_10K
|
403 AIC32X4_MICPGA_ROUTE_RMIC_IN1L_10K
,
407 static struct i2c_board_info visstrim_m10_i2c_devices
[] = {
409 I2C_BOARD_INFO("pca9555", 0x20),
410 .platform_data
= &visstrim_m10_pca9555_pdata
,
413 I2C_BOARD_INFO("tlv320aic32x4", 0x18),
414 .platform_data
= &visstrim_m10_aic32x4_pdata
,
417 I2C_BOARD_INFO("m41t00", 0x68),
422 static int otg_phy_init(struct platform_device
*pdev
)
424 return mx27_initialize_usb_hw(pdev
->id
, MXC_EHCI_POWER_PINS_ENABLED
);
427 static const struct mxc_usbh_platform_data
428 visstrim_m10_usbotg_pdata __initconst
= {
429 .init
= otg_phy_init
,
430 .portsc
= MXC_EHCI_MODE_ULPI
| MXC_EHCI_UTMI_8BIT
,
434 static const struct imx_ssi_platform_data visstrim_m10_ssi_pdata __initconst
= {
435 .flags
= IMX_SSI_DMA
| IMX_SSI_SYN
,
440 static void __init
visstrim_coda_init(void)
442 struct platform_device
*pdev
;
444 pdev
= imx27_add_coda();
445 dma_declare_coherent_memory(&pdev
->dev
,
446 mx2_camera_base
+ MX2_CAMERA_BUF_SIZE
,
447 mx2_camera_base
+ MX2_CAMERA_BUF_SIZE
,
449 DMA_MEMORY_EXCLUSIVE
);
452 /* DMA deinterlace */
453 static struct platform_device visstrim_deinterlace
= {
454 .name
= "m2m-deinterlace",
458 static void __init
visstrim_deinterlace_init(void)
461 struct platform_device
*pdev
= &visstrim_deinterlace
;
463 ret
= platform_device_register(pdev
);
465 dma_declare_coherent_memory(&pdev
->dev
,
466 mx2_camera_base
+ 2 * MX2_CAMERA_BUF_SIZE
,
467 mx2_camera_base
+ 2 * MX2_CAMERA_BUF_SIZE
,
469 DMA_MEMORY_EXCLUSIVE
);
472 /* Emma-PrP for format conversion */
473 static void __init
visstrim_emmaprp_init(void)
475 struct platform_device
*pdev
;
478 pdev
= imx27_add_mx2_emmaprp();
483 * Use the same memory area as the analog camera since both
484 * devices are, by nature, exclusive.
486 ret
= dma_declare_coherent_memory(&pdev
->dev
,
487 mx2_camera_base
, mx2_camera_base
,
489 DMA_MEMORY_EXCLUSIVE
);
491 pr_err("Failed to declare memory for emmaprp\n");
495 static const struct snd_mx27vis_platform_data snd_mx27vis_pdata __initconst
= {
496 .amp_gain0_gpio
= AMP_GAIN_0
,
497 .amp_gain1_gpio
= AMP_GAIN_1
,
498 .amp_mutel_gpio
= AMP_MUTE_SDL
,
499 .amp_muter_gpio
= AMP_MUTE_SDR
,
502 static void __init
visstrim_m10_revision(void)
508 ret
= gpio_request_array(visstrim_m10_version_gpios
,
509 ARRAY_SIZE(visstrim_m10_version_gpios
));
511 pr_err("Failed to request version gpios");
515 /* Get expansion board version (negative logic) */
516 exp_version
|= !gpio_get_value(EXPBOARD_BIT2
) << 2;
517 exp_version
|= !gpio_get_value(EXPBOARD_BIT1
) << 1;
518 exp_version
|= !gpio_get_value(EXPBOARD_BIT0
);
520 /* Get mother board version (negative logic) */
521 mo_version
|= !gpio_get_value(MOTHERBOARD_BIT2
) << 2;
522 mo_version
|= !gpio_get_value(MOTHERBOARD_BIT1
) << 1;
523 mo_version
|= !gpio_get_value(MOTHERBOARD_BIT0
);
525 system_rev
= 0x27000;
526 system_rev
|= (mo_version
<< MOTHERBOARD_SHIFT
);
527 system_rev
|= (exp_version
<< EXPBOARD_SHIFT
);
530 static void __init
visstrim_m10_board_init(void)
535 visstrim_m10_revision();
537 ret
= mxc_gpio_setup_multiple_pins(visstrim_m10_pins
,
538 ARRAY_SIZE(visstrim_m10_pins
), "VISSTRIM_M10");
540 pr_err("Failed to setup pins (%d)\n", ret
);
542 imx27_add_imx_ssi(0, &visstrim_m10_ssi_pdata
);
543 imx27_add_imx_uart0(&uart_pdata
);
545 imx27_add_imx_i2c(0, &visstrim_m10_i2c_data
);
546 imx27_add_imx_i2c(1, &visstrim_m10_i2c_data
);
547 i2c_register_board_info(0, visstrim_m10_i2c_devices
,
548 ARRAY_SIZE(visstrim_m10_i2c_devices
));
550 imx27_add_mxc_mmc(0, &visstrim_m10_sdhc_pdata
);
551 imx27_add_mxc_ehci_otg(&visstrim_m10_usbotg_pdata
);
554 platform_add_devices(platform_devices
, ARRAY_SIZE(platform_devices
));
557 static void __init
visstrim_m10_late_init(void)
561 ret
= gpio_request_array(visstrim_m10_gpios
,
562 ARRAY_SIZE(visstrim_m10_gpios
));
564 pr_err("Failed to request gpios (%d)\n", ret
);
566 imx_add_gpio_keys(&visstrim_gpio_keys_platform_data
);
568 imx_add_platform_device("mx27vis", 0, NULL
, 0, &snd_mx27vis_pdata
,
569 sizeof(snd_mx27vis_pdata
));
570 platform_device_register_resndata(NULL
, "soc-camera-pdrv", 0, NULL
, 0,
571 &iclink_tvp5150
, sizeof(iclink_tvp5150
));
573 gpio_led_register_device(0, &visstrim_m10_led_data
);
575 /* Use mother board version to decide what video devices we shall use */
576 mo_version
= (system_rev
>> MOTHERBOARD_SHIFT
) & VERSION_MASK
;
577 if (mo_version
& 0x1) {
578 visstrim_emmaprp_init();
581 * Despite not being used, tvp5150 must be
582 * powered on to avoid I2C problems. To minimize
583 * power consupmtion keep reset enabled.
585 gpio_set_value(TVP5150_PWDN
, 1);
587 gpio_set_value(TVP5150_RSTN
, 0);
589 visstrim_deinterlace_init();
590 visstrim_analog_camera_init();
593 visstrim_coda_init();
596 static void __init
visstrim_m10_timer_init(void)
598 mx27_clocks_init((unsigned long)25000000);
601 MACHINE_START(IMX27_VISSTRIM_M10
, "Vista Silicon Visstrim_M10")
602 .atag_offset
= 0x100,
603 .reserve
= visstrim_reserve
,
604 .map_io
= mx27_map_io
,
605 .init_early
= imx27_init_early
,
606 .init_irq
= mx27_init_irq
,
607 .init_time
= visstrim_m10_timer_init
,
608 .init_machine
= visstrim_m10_board_init
,
609 .init_late
= visstrim_m10_late_init
,
610 .restart
= mxc_restart
,