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/i2c/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>
43 #include <mach/hardware.h>
46 #include "devices-imx27.h"
47 #include "iomux-mx27.h"
49 #define TVP5150_RSTN (GPIO_PORTC + 18)
50 #define TVP5150_PWDN (GPIO_PORTC + 19)
51 #define OTG_PHY_CS_GPIO (GPIO_PORTF + 17)
52 #define SDHC1_IRQ_GPIO IMX_GPIO_NR(2, 25)
54 #define MOTHERBOARD_BIT2 (GPIO_PORTD + 31)
55 #define MOTHERBOARD_BIT1 (GPIO_PORTD + 30)
56 #define MOTHERBOARD_BIT0 (GPIO_PORTD + 29)
58 #define EXPBOARD_BIT2 (GPIO_PORTD + 25)
59 #define EXPBOARD_BIT1 (GPIO_PORTD + 27)
60 #define EXPBOARD_BIT0 (GPIO_PORTD + 28)
62 #define AMP_GAIN_0 (GPIO_PORTF + 9)
63 #define AMP_GAIN_1 (GPIO_PORTF + 8)
64 #define AMP_MUTE_SDL (GPIO_PORTE + 5)
65 #define AMP_MUTE_SDR (GPIO_PORTF + 7)
67 static const int visstrim_m10_pins
[] __initconst
= {
110 OTG_PHY_CS_GPIO
| GPIO_GPIO
| GPIO_OUT
,
112 PC11_PF_USBOTG_DATA1
,
113 PC10_PF_USBOTG_DATA2
,
114 PC13_PF_USBOTG_DATA3
,
115 PC12_PF_USBOTG_DATA4
,
118 PE25_PF_USBOTG_DATA7
,
126 TVP5150_RSTN
| GPIO_GPIO
| GPIO_OUT
,
127 TVP5150_PWDN
| GPIO_GPIO
| GPIO_OUT
,
140 /* mother board version */
141 MOTHERBOARD_BIT2
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
142 MOTHERBOARD_BIT1
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
143 MOTHERBOARD_BIT0
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
144 /* expansion board version */
145 EXPBOARD_BIT2
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
146 EXPBOARD_BIT1
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
147 EXPBOARD_BIT0
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
148 /* Audio AMP control */
149 AMP_GAIN_0
| GPIO_GPIO
| GPIO_OUT
,
150 AMP_GAIN_1
| GPIO_GPIO
| GPIO_OUT
,
151 AMP_MUTE_SDL
| GPIO_GPIO
| GPIO_OUT
,
152 AMP_MUTE_SDR
| GPIO_GPIO
| GPIO_OUT
,
155 static struct gpio visstrim_m10_version_gpios
[] = {
156 { EXPBOARD_BIT0
, GPIOF_IN
, "exp-version-0" },
157 { EXPBOARD_BIT1
, GPIOF_IN
, "exp-version-1" },
158 { EXPBOARD_BIT2
, GPIOF_IN
, "exp-version-2" },
159 { MOTHERBOARD_BIT0
, GPIOF_IN
, "mother-version-0" },
160 { MOTHERBOARD_BIT1
, GPIOF_IN
, "mother-version-1" },
161 { MOTHERBOARD_BIT2
, GPIOF_IN
, "mother-version-2" },
164 static const struct gpio visstrim_m10_gpios
[] __initconst
= {
166 .gpio
= TVP5150_RSTN
,
167 .flags
= GPIOF_DIR_OUT
| GPIOF_INIT_HIGH
,
168 .label
= "tvp5150_rstn",
171 .gpio
= TVP5150_PWDN
,
172 .flags
= GPIOF_DIR_OUT
| GPIOF_INIT_LOW
,
173 .label
= "tvp5150_pwdn",
176 .gpio
= OTG_PHY_CS_GPIO
,
177 .flags
= GPIOF_DIR_OUT
| GPIOF_INIT_LOW
,
178 .label
= "usbotg_cs",
182 .flags
= GPIOF_DIR_OUT
,
183 .label
= "amp-gain-0",
187 .flags
= GPIOF_DIR_OUT
,
188 .label
= "amp-gain-1",
191 .gpio
= AMP_MUTE_SDL
,
192 .flags
= GPIOF_DIR_OUT
,
193 .label
= "amp-mute-sdl",
196 .gpio
= AMP_MUTE_SDR
,
197 .flags
= GPIOF_DIR_OUT
,
198 .label
= "amp-mute-sdr",
203 static int visstrim_camera_power(struct device
*dev
, int on
)
205 gpio_set_value(TVP5150_PWDN
, on
);
210 static int visstrim_camera_reset(struct device
*dev
)
212 gpio_set_value(TVP5150_RSTN
, 0);
214 gpio_set_value(TVP5150_RSTN
, 1);
219 static struct i2c_board_info visstrim_i2c_camera
= {
220 I2C_BOARD_INFO("tvp5150", 0x5d),
223 static struct soc_camera_link iclink_tvp5150
= {
225 .board_info
= &visstrim_i2c_camera
,
227 .power
= visstrim_camera_power
,
228 .reset
= visstrim_camera_reset
,
231 static struct mx2_camera_platform_data visstrim_camera
= {
232 .flags
= MX2_CAMERA_CCIR
| MX2_CAMERA_CCIR_INTERLACE
|
233 MX2_CAMERA_PCLK_SAMPLE_RISING
,
237 static phys_addr_t mx2_camera_base __initdata
;
238 #define MX2_CAMERA_BUF_SIZE SZ_8M
240 static void __init
visstrim_camera_init(void)
242 struct platform_device
*pdev
;
245 gpio_set_value(TVP5150_PWDN
, 1);
247 gpio_set_value(TVP5150_RSTN
, 0);
249 gpio_set_value(TVP5150_RSTN
, 1);
252 pdev
= imx27_add_mx2_camera(&visstrim_camera
);
256 dma
= dma_declare_coherent_memory(&pdev
->dev
,
257 mx2_camera_base
, mx2_camera_base
,
259 DMA_MEMORY_MAP
| DMA_MEMORY_EXCLUSIVE
);
260 if (!(dma
& DMA_MEMORY_MAP
))
264 static void __init
visstrim_reserve(void)
266 /* reserve 4 MiB for mx2-camera */
267 mx2_camera_base
= arm_memblock_steal(3 * MX2_CAMERA_BUF_SIZE
,
268 MX2_CAMERA_BUF_SIZE
);
271 /* GPIOs used as events for applications */
272 static struct gpio_keys_button visstrim_gpio_keys
[] = {
276 .gpio
= (GPIO_PORTC
+ 15),
277 .desc
= "Default config",
284 .gpio
= (GPIO_PORTF
+ 14),
292 .gpio
= (GPIO_PORTF
+ 13),
299 static const struct gpio_keys_platform_data
300 visstrim_gpio_keys_platform_data __initconst
= {
301 .buttons
= visstrim_gpio_keys
,
302 .nbuttons
= ARRAY_SIZE(visstrim_gpio_keys
),
306 static const struct gpio_led visstrim_m10_leds
[] __initconst
= {
308 .name
= "visstrim:ld0",
309 .default_trigger
= "nand-disk",
310 .gpio
= (GPIO_PORTC
+ 29),
313 .name
= "visstrim:ld1",
314 .default_trigger
= "nand-disk",
315 .gpio
= (GPIO_PORTC
+ 24),
318 .name
= "visstrim:ld2",
319 .default_trigger
= "nand-disk",
320 .gpio
= (GPIO_PORTC
+ 28),
323 .name
= "visstrim:ld3",
324 .default_trigger
= "nand-disk",
325 .gpio
= (GPIO_PORTC
+ 25),
329 static const struct gpio_led_platform_data visstrim_m10_led_data __initconst
= {
330 .leds
= visstrim_m10_leds
,
331 .num_leds
= ARRAY_SIZE(visstrim_m10_leds
),
334 /* Visstrim_SM10 has a microSD slot connected to sdhc1 */
335 static int visstrim_m10_sdhc1_init(struct device
*dev
,
336 irq_handler_t detect_irq
, void *data
)
340 ret
= request_irq(gpio_to_irq(SDHC1_IRQ_GPIO
), detect_irq
,
341 IRQF_TRIGGER_FALLING
, "mmc-detect", data
);
345 static void visstrim_m10_sdhc1_exit(struct device
*dev
, void *data
)
347 free_irq(gpio_to_irq(SDHC1_IRQ_GPIO
), data
);
350 static const struct imxmmc_platform_data visstrim_m10_sdhc_pdata __initconst
= {
351 .init
= visstrim_m10_sdhc1_init
,
352 .exit
= visstrim_m10_sdhc1_exit
,
355 /* Visstrim_SM10 NOR flash */
356 static struct physmap_flash_data visstrim_m10_flash_data
= {
360 static struct resource visstrim_m10_flash_resource
= {
362 .end
= 0xc0000000 + SZ_64M
- 1,
363 .flags
= IORESOURCE_MEM
,
366 static struct platform_device visstrim_m10_nor_mtd_device
= {
367 .name
= "physmap-flash",
370 .platform_data
= &visstrim_m10_flash_data
,
373 .resource
= &visstrim_m10_flash_resource
,
376 static struct platform_device
*platform_devices
[] __initdata
= {
377 &visstrim_m10_nor_mtd_device
,
380 /* Visstrim_M10 uses UART0 as console */
381 static const struct imxuart_platform_data uart_pdata __initconst
= {
382 .flags
= IMXUART_HAVE_RTSCTS
,
386 static const struct imxi2c_platform_data visstrim_m10_i2c_data __initconst
= {
390 static struct pca953x_platform_data visstrim_m10_pca9555_pdata
= {
391 .gpio_base
= 240, /* After MX27 internal GPIOs */
395 static struct aic32x4_pdata visstrim_m10_aic32x4_pdata
= {
396 .power_cfg
= AIC32X4_PWR_MICBIAS_2075_LDOIN
|
397 AIC32X4_PWR_AVDD_DVDD_WEAK_DISABLE
|
398 AIC32X4_PWR_AIC32X4_LDO_ENABLE
|
399 AIC32X4_PWR_CMMODE_LDOIN_RANGE_18_36
|
400 AIC32X4_PWR_CMMODE_HP_LDOIN_POWERED
,
401 .micpga_routing
= AIC32X4_MICPGA_ROUTE_LMIC_IN2R_10K
|
402 AIC32X4_MICPGA_ROUTE_RMIC_IN1L_10K
,
406 static struct i2c_board_info visstrim_m10_i2c_devices
[] = {
408 I2C_BOARD_INFO("pca9555", 0x20),
409 .platform_data
= &visstrim_m10_pca9555_pdata
,
412 I2C_BOARD_INFO("tlv320aic32x4", 0x18),
413 .platform_data
= &visstrim_m10_aic32x4_pdata
,
416 I2C_BOARD_INFO("m41t00", 0x68),
421 static int otg_phy_init(struct platform_device
*pdev
)
423 return mx27_initialize_usb_hw(pdev
->id
, MXC_EHCI_POWER_PINS_ENABLED
);
426 static const struct mxc_usbh_platform_data
427 visstrim_m10_usbotg_pdata __initconst
= {
428 .init
= otg_phy_init
,
429 .portsc
= MXC_EHCI_MODE_ULPI
| MXC_EHCI_UTMI_8BIT
,
433 static const struct imx_ssi_platform_data visstrim_m10_ssi_pdata __initconst
= {
434 .flags
= IMX_SSI_DMA
| IMX_SSI_SYN
,
439 static void __init
visstrim_coda_init(void)
441 struct platform_device
*pdev
;
444 pdev
= imx27_add_coda();
445 dma
= 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_MAP
| DMA_MEMORY_EXCLUSIVE
);
450 if (!(dma
& DMA_MEMORY_MAP
))
454 /* DMA deinterlace */
455 static struct platform_device visstrim_deinterlace
= {
456 .name
= "m2m-deinterlace",
460 static void __init
visstrim_deinterlace_init(void)
463 struct platform_device
*pdev
= &visstrim_deinterlace
;
466 ret
= platform_device_register(pdev
);
468 dma
= dma_declare_coherent_memory(&pdev
->dev
,
469 mx2_camera_base
+ 2 * MX2_CAMERA_BUF_SIZE
,
470 mx2_camera_base
+ 2 * MX2_CAMERA_BUF_SIZE
,
472 DMA_MEMORY_MAP
| DMA_MEMORY_EXCLUSIVE
);
473 if (!(dma
& DMA_MEMORY_MAP
))
479 static const struct snd_mx27vis_platform_data snd_mx27vis_pdata __initconst
= {
480 .amp_gain0_gpio
= AMP_GAIN_0
,
481 .amp_gain1_gpio
= AMP_GAIN_1
,
482 .amp_mutel_gpio
= AMP_MUTE_SDL
,
483 .amp_muter_gpio
= AMP_MUTE_SDR
,
486 static void __init
visstrim_m10_revision(void)
492 ret
= gpio_request_array(visstrim_m10_version_gpios
,
493 ARRAY_SIZE(visstrim_m10_version_gpios
));
495 pr_err("Failed to request version gpios");
499 /* Get expansion board version (negative logic) */
500 exp_version
|= !gpio_get_value(EXPBOARD_BIT2
) << 2;
501 exp_version
|= !gpio_get_value(EXPBOARD_BIT1
) << 1;
502 exp_version
|= !gpio_get_value(EXPBOARD_BIT0
);
504 /* Get mother board version (negative logic) */
505 mo_version
|= !gpio_get_value(MOTHERBOARD_BIT2
) << 2;
506 mo_version
|= !gpio_get_value(MOTHERBOARD_BIT1
) << 1;
507 mo_version
|= !gpio_get_value(MOTHERBOARD_BIT0
);
509 system_rev
= 0x27000;
510 system_rev
|= (mo_version
<< 4);
511 system_rev
|= exp_version
;
514 static void __init
visstrim_m10_board_init(void)
519 visstrim_m10_revision();
521 ret
= mxc_gpio_setup_multiple_pins(visstrim_m10_pins
,
522 ARRAY_SIZE(visstrim_m10_pins
), "VISSTRIM_M10");
524 pr_err("Failed to setup pins (%d)\n", ret
);
526 ret
= gpio_request_array(visstrim_m10_gpios
,
527 ARRAY_SIZE(visstrim_m10_gpios
));
529 pr_err("Failed to request gpios (%d)\n", ret
);
531 imx27_add_imx_ssi(0, &visstrim_m10_ssi_pdata
);
532 imx27_add_imx_uart0(&uart_pdata
);
534 imx27_add_imx_i2c(0, &visstrim_m10_i2c_data
);
535 imx27_add_imx_i2c(1, &visstrim_m10_i2c_data
);
536 i2c_register_board_info(0, visstrim_m10_i2c_devices
,
537 ARRAY_SIZE(visstrim_m10_i2c_devices
));
539 imx27_add_mxc_mmc(0, &visstrim_m10_sdhc_pdata
);
540 imx27_add_mxc_ehci_otg(&visstrim_m10_usbotg_pdata
);
542 imx_add_gpio_keys(&visstrim_gpio_keys_platform_data
);
543 platform_add_devices(platform_devices
, ARRAY_SIZE(platform_devices
));
544 imx_add_platform_device("mx27vis", 0, NULL
, 0, &snd_mx27vis_pdata
,
545 sizeof(snd_mx27vis_pdata
));
546 platform_device_register_resndata(NULL
, "soc-camera-pdrv", 0, NULL
, 0,
547 &iclink_tvp5150
, sizeof(iclink_tvp5150
));
548 gpio_led_register_device(0, &visstrim_m10_led_data
);
549 visstrim_deinterlace_init();
550 visstrim_camera_init();
551 visstrim_coda_init();
554 static void __init
visstrim_m10_timer_init(void)
556 mx27_clocks_init((unsigned long)25000000);
559 static struct sys_timer visstrim_m10_timer
= {
560 .init
= visstrim_m10_timer_init
,
563 MACHINE_START(IMX27_VISSTRIM_M10
, "Vista Silicon Visstrim_M10")
564 .atag_offset
= 0x100,
565 .reserve
= visstrim_reserve
,
566 .map_io
= mx27_map_io
,
567 .init_early
= imx27_init_early
,
568 .init_irq
= mx27_init_irq
,
569 .handle_irq
= imx27_handle_irq
,
570 .timer
= &visstrim_m10_timer
,
571 .init_machine
= visstrim_m10_board_init
,
572 .restart
= mxc_restart
,