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/memblock.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.h>
42 #include <mach/common.h>
43 #include <mach/iomux-mx27.h>
45 #include "devices-imx27.h"
47 #define TVP5150_RSTN (GPIO_PORTC + 18)
48 #define TVP5150_PWDN (GPIO_PORTC + 19)
49 #define OTG_PHY_CS_GPIO (GPIO_PORTF + 17)
50 #define SDHC1_IRQ IRQ_GPIOB(25)
52 #define MOTHERBOARD_BIT2 (GPIO_PORTD + 31)
53 #define MOTHERBOARD_BIT1 (GPIO_PORTD + 30)
54 #define MOTHERBOARD_BIT0 (GPIO_PORTD + 29)
56 #define EXPBOARD_BIT2 (GPIO_PORTD + 25)
57 #define EXPBOARD_BIT1 (GPIO_PORTD + 27)
58 #define EXPBOARD_BIT0 (GPIO_PORTD + 28)
60 static const int visstrim_m10_pins
[] __initconst
= {
103 OTG_PHY_CS_GPIO
| GPIO_GPIO
| GPIO_OUT
,
105 PC11_PF_USBOTG_DATA1
,
106 PC10_PF_USBOTG_DATA2
,
107 PC13_PF_USBOTG_DATA3
,
108 PC12_PF_USBOTG_DATA4
,
111 PE25_PF_USBOTG_DATA7
,
119 TVP5150_RSTN
| GPIO_GPIO
| GPIO_OUT
,
120 TVP5150_PWDN
| GPIO_GPIO
| GPIO_OUT
,
133 /* mother board version */
134 MOTHERBOARD_BIT2
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
135 MOTHERBOARD_BIT1
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
136 MOTHERBOARD_BIT0
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
137 /* expansion board version */
138 EXPBOARD_BIT2
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
139 EXPBOARD_BIT1
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
140 EXPBOARD_BIT0
| GPIO_GPIO
| GPIO_IN
| GPIO_PUEN
,
143 static struct gpio visstrim_m10_version_gpios
[] = {
144 { EXPBOARD_BIT0
, GPIOF_IN
, "exp-version-0" },
145 { EXPBOARD_BIT1
, GPIOF_IN
, "exp-version-1" },
146 { EXPBOARD_BIT2
, GPIOF_IN
, "exp-version-2" },
147 { MOTHERBOARD_BIT0
, GPIOF_IN
, "mother-version-0" },
148 { MOTHERBOARD_BIT1
, GPIOF_IN
, "mother-version-1" },
149 { MOTHERBOARD_BIT2
, GPIOF_IN
, "mother-version-2" },
152 static const struct gpio visstrim_m10_gpios
[] __initconst
= {
154 .gpio
= TVP5150_RSTN
,
155 .flags
= GPIOF_DIR_OUT
| GPIOF_INIT_HIGH
,
156 .label
= "tvp5150_rstn",
159 .gpio
= TVP5150_PWDN
,
160 .flags
= GPIOF_DIR_OUT
| GPIOF_INIT_LOW
,
161 .label
= "tvp5150_pwdn",
164 .gpio
= OTG_PHY_CS_GPIO
,
165 .flags
= GPIOF_DIR_OUT
| GPIOF_INIT_LOW
,
166 .label
= "usbotg_cs",
171 static int visstrim_camera_power(struct device
*dev
, int on
)
173 gpio_set_value(TVP5150_PWDN
, on
);
178 static int visstrim_camera_reset(struct device
*dev
)
180 gpio_set_value(TVP5150_RSTN
, 0);
182 gpio_set_value(TVP5150_RSTN
, 1);
187 static struct i2c_board_info visstrim_i2c_camera
= {
188 I2C_BOARD_INFO("tvp5150", 0x5d),
191 static struct soc_camera_link iclink_tvp5150
= {
193 .board_info
= &visstrim_i2c_camera
,
195 .power
= visstrim_camera_power
,
196 .reset
= visstrim_camera_reset
,
199 static struct mx2_camera_platform_data visstrim_camera
= {
200 .flags
= MX2_CAMERA_CCIR
| MX2_CAMERA_CCIR_INTERLACE
|
201 MX2_CAMERA_PCLK_SAMPLE_RISING
,
205 static phys_addr_t mx2_camera_base __initdata
;
206 #define MX2_CAMERA_BUF_SIZE SZ_8M
208 static void __init
visstrim_camera_init(void)
210 struct platform_device
*pdev
;
213 gpio_set_value(TVP5150_PWDN
, 1);
215 gpio_set_value(TVP5150_RSTN
, 0);
217 gpio_set_value(TVP5150_RSTN
, 1);
220 pdev
= imx27_add_mx2_camera(&visstrim_camera
);
224 dma
= dma_declare_coherent_memory(&pdev
->dev
,
225 mx2_camera_base
, mx2_camera_base
,
227 DMA_MEMORY_MAP
| DMA_MEMORY_EXCLUSIVE
);
228 if (!(dma
& DMA_MEMORY_MAP
))
232 static void __init
visstrim_reserve(void)
234 /* reserve 4 MiB for mx2-camera */
235 mx2_camera_base
= memblock_alloc(MX2_CAMERA_BUF_SIZE
,
236 MX2_CAMERA_BUF_SIZE
);
237 memblock_free(mx2_camera_base
, MX2_CAMERA_BUF_SIZE
);
238 memblock_remove(mx2_camera_base
, MX2_CAMERA_BUF_SIZE
);
241 /* GPIOs used as events for applications */
242 static struct gpio_keys_button visstrim_gpio_keys
[] = {
246 .gpio
= (GPIO_PORTC
+ 15),
247 .desc
= "Default config",
254 .gpio
= (GPIO_PORTF
+ 14),
262 .gpio
= (GPIO_PORTF
+ 13),
269 static const struct gpio_keys_platform_data
270 visstrim_gpio_keys_platform_data __initconst
= {
271 .buttons
= visstrim_gpio_keys
,
272 .nbuttons
= ARRAY_SIZE(visstrim_gpio_keys
),
276 static const struct gpio_led visstrim_m10_leds
[] __initconst
= {
278 .name
= "visstrim:ld0",
279 .default_trigger
= "nand-disk",
280 .gpio
= (GPIO_PORTC
+ 29),
283 .name
= "visstrim:ld1",
284 .default_trigger
= "nand-disk",
285 .gpio
= (GPIO_PORTC
+ 24),
288 .name
= "visstrim:ld2",
289 .default_trigger
= "nand-disk",
290 .gpio
= (GPIO_PORTC
+ 28),
293 .name
= "visstrim:ld3",
294 .default_trigger
= "nand-disk",
295 .gpio
= (GPIO_PORTC
+ 25),
299 static const struct gpio_led_platform_data visstrim_m10_led_data __initconst
= {
300 .leds
= visstrim_m10_leds
,
301 .num_leds
= ARRAY_SIZE(visstrim_m10_leds
),
304 /* Visstrim_SM10 has a microSD slot connected to sdhc1 */
305 static int visstrim_m10_sdhc1_init(struct device
*dev
,
306 irq_handler_t detect_irq
, void *data
)
310 ret
= request_irq(SDHC1_IRQ
, detect_irq
, IRQF_TRIGGER_FALLING
,
315 static void visstrim_m10_sdhc1_exit(struct device
*dev
, void *data
)
317 free_irq(SDHC1_IRQ
, data
);
320 static const struct imxmmc_platform_data visstrim_m10_sdhc_pdata __initconst
= {
321 .init
= visstrim_m10_sdhc1_init
,
322 .exit
= visstrim_m10_sdhc1_exit
,
325 /* Visstrim_SM10 NOR flash */
326 static struct physmap_flash_data visstrim_m10_flash_data
= {
330 static struct resource visstrim_m10_flash_resource
= {
332 .end
= 0xc0000000 + SZ_64M
- 1,
333 .flags
= IORESOURCE_MEM
,
336 static struct platform_device visstrim_m10_nor_mtd_device
= {
337 .name
= "physmap-flash",
340 .platform_data
= &visstrim_m10_flash_data
,
343 .resource
= &visstrim_m10_flash_resource
,
346 static struct platform_device
*platform_devices
[] __initdata
= {
347 &visstrim_m10_nor_mtd_device
,
350 /* Visstrim_M10 uses UART0 as console */
351 static const struct imxuart_platform_data uart_pdata __initconst
= {
352 .flags
= IMXUART_HAVE_RTSCTS
,
356 static const struct imxi2c_platform_data visstrim_m10_i2c_data __initconst
= {
360 static struct pca953x_platform_data visstrim_m10_pca9555_pdata
= {
361 .gpio_base
= 240, /* After MX27 internal GPIOs */
365 static struct aic32x4_pdata visstrim_m10_aic32x4_pdata
= {
366 .power_cfg
= AIC32X4_PWR_MICBIAS_2075_LDOIN
|
367 AIC32X4_PWR_AVDD_DVDD_WEAK_DISABLE
|
368 AIC32X4_PWR_AIC32X4_LDO_ENABLE
|
369 AIC32X4_PWR_CMMODE_LDOIN_RANGE_18_36
|
370 AIC32X4_PWR_CMMODE_HP_LDOIN_POWERED
,
371 .micpga_routing
= AIC32X4_MICPGA_ROUTE_LMIC_IN2R_10K
|
372 AIC32X4_MICPGA_ROUTE_RMIC_IN1L_10K
,
376 static struct i2c_board_info visstrim_m10_i2c_devices
[] = {
378 I2C_BOARD_INFO("pca9555", 0x20),
379 .platform_data
= &visstrim_m10_pca9555_pdata
,
382 I2C_BOARD_INFO("tlv320aic32x4", 0x18),
383 .platform_data
= &visstrim_m10_aic32x4_pdata
,
386 I2C_BOARD_INFO("m41t00", 0x68),
391 static int otg_phy_init(struct platform_device
*pdev
)
393 return mx27_initialize_usb_hw(pdev
->id
, MXC_EHCI_POWER_PINS_ENABLED
);
396 static const struct mxc_usbh_platform_data
397 visstrim_m10_usbotg_pdata __initconst
= {
398 .init
= otg_phy_init
,
399 .portsc
= MXC_EHCI_MODE_ULPI
| MXC_EHCI_UTMI_8BIT
,
403 static const struct imx_ssi_platform_data visstrim_m10_ssi_pdata __initconst
= {
404 .flags
= IMX_SSI_DMA
| IMX_SSI_SYN
,
407 static void __init
visstrim_m10_revision(void)
413 ret
= gpio_request_array(visstrim_m10_version_gpios
,
414 ARRAY_SIZE(visstrim_m10_version_gpios
));
416 pr_err("Failed to request version gpios");
420 /* Get expansion board version (negative logic) */
421 exp_version
|= !gpio_get_value(EXPBOARD_BIT2
) << 2;
422 exp_version
|= !gpio_get_value(EXPBOARD_BIT1
) << 1;
423 exp_version
|= !gpio_get_value(EXPBOARD_BIT0
);
425 /* Get mother board version (negative logic) */
426 mo_version
|= !gpio_get_value(MOTHERBOARD_BIT2
) << 2;
427 mo_version
|= !gpio_get_value(MOTHERBOARD_BIT1
) << 1;
428 mo_version
|= !gpio_get_value(MOTHERBOARD_BIT0
);
430 system_rev
= 0x27000;
431 system_rev
|= (mo_version
<< 4);
432 system_rev
|= exp_version
;
435 static void __init
visstrim_m10_board_init(void)
440 visstrim_m10_revision();
442 ret
= mxc_gpio_setup_multiple_pins(visstrim_m10_pins
,
443 ARRAY_SIZE(visstrim_m10_pins
), "VISSTRIM_M10");
445 pr_err("Failed to setup pins (%d)\n", ret
);
447 ret
= gpio_request_array(visstrim_m10_gpios
,
448 ARRAY_SIZE(visstrim_m10_gpios
));
450 pr_err("Failed to request gpios (%d)\n", ret
);
452 imx27_add_imx_ssi(0, &visstrim_m10_ssi_pdata
);
453 imx27_add_imx_uart0(&uart_pdata
);
455 imx27_add_imx_i2c(0, &visstrim_m10_i2c_data
);
456 imx27_add_imx_i2c(1, &visstrim_m10_i2c_data
);
457 i2c_register_board_info(0, visstrim_m10_i2c_devices
,
458 ARRAY_SIZE(visstrim_m10_i2c_devices
));
460 imx27_add_mxc_mmc(0, &visstrim_m10_sdhc_pdata
);
461 imx27_add_mxc_ehci_otg(&visstrim_m10_usbotg_pdata
);
463 imx_add_gpio_keys(&visstrim_gpio_keys_platform_data
);
464 platform_add_devices(platform_devices
, ARRAY_SIZE(platform_devices
));
465 imx_add_platform_device("mx27vis", 0, NULL
, 0, NULL
, 0);
466 platform_device_register_resndata(NULL
, "soc-camera-pdrv", 0, NULL
, 0,
467 &iclink_tvp5150
, sizeof(iclink_tvp5150
));
468 gpio_led_register_device(0, &visstrim_m10_led_data
);
469 visstrim_camera_init();
472 static void __init
visstrim_m10_timer_init(void)
474 mx27_clocks_init((unsigned long)25000000);
477 static struct sys_timer visstrim_m10_timer
= {
478 .init
= visstrim_m10_timer_init
,
481 MACHINE_START(IMX27_VISSTRIM_M10
, "Vista Silicon Visstrim_M10")
482 .atag_offset
= 0x100,
483 .reserve
= visstrim_reserve
,
484 .map_io
= mx27_map_io
,
485 .init_early
= imx27_init_early
,
486 .init_irq
= mx27_init_irq
,
487 .handle_irq
= imx27_handle_irq
,
488 .timer
= &visstrim_m10_timer
,
489 .init_machine
= visstrim_m10_board_init
,
490 .restart
= mxc_restart
,