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 <media/soc_camera.h>
36 #include <sound/tlv320aic32x4.h>
37 #include <asm/mach-types.h>
38 #include <asm/mach/arch.h>
39 #include <asm/mach/time.h>
40 #include <asm/system_info.h>
41 #include <asm/memblock.h>
42 #include <mach/common.h>
43 #include <mach/hardware.h>
44 #include <mach/iomux-mx27.h>
46 #include "devices-imx27.h"
48 #define TVP5150_RSTN (GPIO_PORTC + 18)
49 #define TVP5150_PWDN (GPIO_PORTC + 19)
50 #define OTG_PHY_CS_GPIO (GPIO_PORTF + 17)
51 #define SDHC1_IRQ_GPIO IMX_GPIO_NR(2, 25)
53 #define MOTHERBOARD_BIT2 (GPIO_PORTD + 31)
54 #define MOTHERBOARD_BIT1 (GPIO_PORTD + 30)
55 #define MOTHERBOARD_BIT0 (GPIO_PORTD + 29)
57 #define EXPBOARD_BIT2 (GPIO_PORTD + 25)
58 #define EXPBOARD_BIT1 (GPIO_PORTD + 27)
59 #define EXPBOARD_BIT0 (GPIO_PORTD + 28)
61 static const int visstrim_m10_pins[] __initconst = {
104 OTG_PHY_CS_GPIO | GPIO_GPIO | GPIO_OUT,
106 PC11_PF_USBOTG_DATA1,
107 PC10_PF_USBOTG_DATA2,
108 PC13_PF_USBOTG_DATA3,
109 PC12_PF_USBOTG_DATA4,
112 PE25_PF_USBOTG_DATA7,
120 TVP5150_RSTN | GPIO_GPIO | GPIO_OUT,
121 TVP5150_PWDN | GPIO_GPIO | GPIO_OUT,
134 /* mother board version */
135 MOTHERBOARD_BIT2 | GPIO_GPIO | GPIO_IN | GPIO_PUEN,
136 MOTHERBOARD_BIT1 | GPIO_GPIO | GPIO_IN | GPIO_PUEN,
137 MOTHERBOARD_BIT0 | GPIO_GPIO | GPIO_IN | GPIO_PUEN,
138 /* expansion board version */
139 EXPBOARD_BIT2 | GPIO_GPIO | GPIO_IN | GPIO_PUEN,
140 EXPBOARD_BIT1 | GPIO_GPIO | GPIO_IN | GPIO_PUEN,
141 EXPBOARD_BIT0 | GPIO_GPIO | GPIO_IN | GPIO_PUEN,
144 static struct gpio visstrim_m10_version_gpios[] = {
145 { EXPBOARD_BIT0, GPIOF_IN, "exp-version-0" },
146 { EXPBOARD_BIT1, GPIOF_IN, "exp-version-1" },
147 { EXPBOARD_BIT2, GPIOF_IN, "exp-version-2" },
148 { MOTHERBOARD_BIT0, GPIOF_IN, "mother-version-0" },
149 { MOTHERBOARD_BIT1, GPIOF_IN, "mother-version-1" },
150 { MOTHERBOARD_BIT2, GPIOF_IN, "mother-version-2" },
153 static const struct gpio visstrim_m10_gpios[] __initconst = {
155 .gpio = TVP5150_RSTN,
156 .flags = GPIOF_DIR_OUT | GPIOF_INIT_HIGH,
157 .label = "tvp5150_rstn",
160 .gpio = TVP5150_PWDN,
161 .flags = GPIOF_DIR_OUT | GPIOF_INIT_LOW,
162 .label = "tvp5150_pwdn",
165 .gpio = OTG_PHY_CS_GPIO,
166 .flags = GPIOF_DIR_OUT | GPIOF_INIT_LOW,
167 .label = "usbotg_cs",
172 static int visstrim_camera_power(struct device *dev, int on)
174 gpio_set_value(TVP5150_PWDN, on);
179 static int visstrim_camera_reset(struct device *dev)
181 gpio_set_value(TVP5150_RSTN, 0);
183 gpio_set_value(TVP5150_RSTN, 1);
188 static struct i2c_board_info visstrim_i2c_camera = {
189 I2C_BOARD_INFO("tvp5150", 0x5d),
192 static struct soc_camera_link iclink_tvp5150 = {
194 .board_info = &visstrim_i2c_camera,
196 .power = visstrim_camera_power,
197 .reset = visstrim_camera_reset,
200 static struct mx2_camera_platform_data visstrim_camera = {
201 .flags = MX2_CAMERA_CCIR | MX2_CAMERA_CCIR_INTERLACE |
202 MX2_CAMERA_PCLK_SAMPLE_RISING,
206 static phys_addr_t mx2_camera_base __initdata;
207 #define MX2_CAMERA_BUF_SIZE SZ_8M
209 static void __init visstrim_camera_init(void)
211 struct platform_device *pdev;
214 gpio_set_value(TVP5150_PWDN, 1);
216 gpio_set_value(TVP5150_RSTN, 0);
218 gpio_set_value(TVP5150_RSTN, 1);
221 pdev = imx27_add_mx2_camera(&visstrim_camera);
225 dma = dma_declare_coherent_memory(&pdev->dev,
226 mx2_camera_base, mx2_camera_base,
228 DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE);
229 if (!(dma & DMA_MEMORY_MAP))
233 static void __init visstrim_reserve(void)
235 /* reserve 4 MiB for mx2-camera */
236 mx2_camera_base = memblock_steal(MX2_CAMERA_BUF_SIZE,
237 MX2_CAMERA_BUF_SIZE);
240 /* GPIOs used as events for applications */
241 static struct gpio_keys_button visstrim_gpio_keys[] = {
245 .gpio = (GPIO_PORTC + 15),
246 .desc = "Default config",
253 .gpio = (GPIO_PORTF + 14),
261 .gpio = (GPIO_PORTF + 13),
268 static const struct gpio_keys_platform_data
269 visstrim_gpio_keys_platform_data __initconst = {
270 .buttons = visstrim_gpio_keys,
271 .nbuttons = ARRAY_SIZE(visstrim_gpio_keys),
275 static const struct gpio_led visstrim_m10_leds[] __initconst = {
277 .name = "visstrim:ld0",
278 .default_trigger = "nand-disk",
279 .gpio = (GPIO_PORTC + 29),
282 .name = "visstrim:ld1",
283 .default_trigger = "nand-disk",
284 .gpio = (GPIO_PORTC + 24),
287 .name = "visstrim:ld2",
288 .default_trigger = "nand-disk",
289 .gpio = (GPIO_PORTC + 28),
292 .name = "visstrim:ld3",
293 .default_trigger = "nand-disk",
294 .gpio = (GPIO_PORTC + 25),
298 static const struct gpio_led_platform_data visstrim_m10_led_data __initconst = {
299 .leds = visstrim_m10_leds,
300 .num_leds = ARRAY_SIZE(visstrim_m10_leds),
303 /* Visstrim_SM10 has a microSD slot connected to sdhc1 */
304 static int visstrim_m10_sdhc1_init(struct device *dev,
305 irq_handler_t detect_irq, void *data)
309 ret = request_irq(gpio_to_irq(SDHC1_IRQ_GPIO), detect_irq,
310 IRQF_TRIGGER_FALLING, "mmc-detect", data);
314 static void visstrim_m10_sdhc1_exit(struct device *dev, void *data)
316 free_irq(gpio_to_irq(SDHC1_IRQ_GPIO), data);
319 static const struct imxmmc_platform_data visstrim_m10_sdhc_pdata __initconst = {
320 .init = visstrim_m10_sdhc1_init,
321 .exit = visstrim_m10_sdhc1_exit,
324 /* Visstrim_SM10 NOR flash */
325 static struct physmap_flash_data visstrim_m10_flash_data = {
329 static struct resource visstrim_m10_flash_resource = {
331 .end = 0xc0000000 + SZ_64M - 1,
332 .flags = IORESOURCE_MEM,
335 static struct platform_device visstrim_m10_nor_mtd_device = {
336 .name = "physmap-flash",
339 .platform_data = &visstrim_m10_flash_data,
342 .resource = &visstrim_m10_flash_resource,
345 static struct platform_device *platform_devices[] __initdata = {
346 &visstrim_m10_nor_mtd_device,
349 /* Visstrim_M10 uses UART0 as console */
350 static const struct imxuart_platform_data uart_pdata __initconst = {
351 .flags = IMXUART_HAVE_RTSCTS,
355 static const struct imxi2c_platform_data visstrim_m10_i2c_data __initconst = {
359 static struct pca953x_platform_data visstrim_m10_pca9555_pdata = {
360 .gpio_base = 240, /* After MX27 internal GPIOs */
364 static struct aic32x4_pdata visstrim_m10_aic32x4_pdata = {
365 .power_cfg = AIC32X4_PWR_MICBIAS_2075_LDOIN |
366 AIC32X4_PWR_AVDD_DVDD_WEAK_DISABLE |
367 AIC32X4_PWR_AIC32X4_LDO_ENABLE |
368 AIC32X4_PWR_CMMODE_LDOIN_RANGE_18_36 |
369 AIC32X4_PWR_CMMODE_HP_LDOIN_POWERED,
370 .micpga_routing = AIC32X4_MICPGA_ROUTE_LMIC_IN2R_10K |
371 AIC32X4_MICPGA_ROUTE_RMIC_IN1L_10K,
375 static struct i2c_board_info visstrim_m10_i2c_devices[] = {
377 I2C_BOARD_INFO("pca9555", 0x20),
378 .platform_data = &visstrim_m10_pca9555_pdata,
381 I2C_BOARD_INFO("tlv320aic32x4", 0x18),
382 .platform_data = &visstrim_m10_aic32x4_pdata,
385 I2C_BOARD_INFO("m41t00", 0x68),
390 static int otg_phy_init(struct platform_device *pdev)
392 return mx27_initialize_usb_hw(pdev->id, MXC_EHCI_POWER_PINS_ENABLED);
395 static const struct mxc_usbh_platform_data
396 visstrim_m10_usbotg_pdata __initconst = {
397 .init = otg_phy_init,
398 .portsc = MXC_EHCI_MODE_ULPI | MXC_EHCI_UTMI_8BIT,
402 static const struct imx_ssi_platform_data visstrim_m10_ssi_pdata __initconst = {
403 .flags = IMX_SSI_DMA | IMX_SSI_SYN,
406 static void __init visstrim_m10_revision(void)
412 ret = gpio_request_array(visstrim_m10_version_gpios,
413 ARRAY_SIZE(visstrim_m10_version_gpios));
415 pr_err("Failed to request version gpios");
419 /* Get expansion board version (negative logic) */
420 exp_version |= !gpio_get_value(EXPBOARD_BIT2) << 2;
421 exp_version |= !gpio_get_value(EXPBOARD_BIT1) << 1;
422 exp_version |= !gpio_get_value(EXPBOARD_BIT0);
424 /* Get mother board version (negative logic) */
425 mo_version |= !gpio_get_value(MOTHERBOARD_BIT2) << 2;
426 mo_version |= !gpio_get_value(MOTHERBOARD_BIT1) << 1;
427 mo_version |= !gpio_get_value(MOTHERBOARD_BIT0);
429 system_rev = 0x27000;
430 system_rev |= (mo_version << 4);
431 system_rev |= exp_version;
434 static void __init visstrim_m10_board_init(void)
439 visstrim_m10_revision();
441 ret = mxc_gpio_setup_multiple_pins(visstrim_m10_pins,
442 ARRAY_SIZE(visstrim_m10_pins), "VISSTRIM_M10");
444 pr_err("Failed to setup pins (%d)\n", ret);
446 ret = gpio_request_array(visstrim_m10_gpios,
447 ARRAY_SIZE(visstrim_m10_gpios));
449 pr_err("Failed to request gpios (%d)\n", ret);
451 imx27_add_imx_ssi(0, &visstrim_m10_ssi_pdata);
452 imx27_add_imx_uart0(&uart_pdata);
454 imx27_add_imx_i2c(0, &visstrim_m10_i2c_data);
455 imx27_add_imx_i2c(1, &visstrim_m10_i2c_data);
456 i2c_register_board_info(0, visstrim_m10_i2c_devices,
457 ARRAY_SIZE(visstrim_m10_i2c_devices));
459 imx27_add_mxc_mmc(0, &visstrim_m10_sdhc_pdata);
460 imx27_add_mxc_ehci_otg(&visstrim_m10_usbotg_pdata);
462 imx_add_gpio_keys(&visstrim_gpio_keys_platform_data);
463 platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
464 imx_add_platform_device("mx27vis", 0, NULL, 0, NULL, 0);
465 platform_device_register_resndata(NULL, "soc-camera-pdrv", 0, NULL, 0,
466 &iclink_tvp5150, sizeof(iclink_tvp5150));
467 gpio_led_register_device(0, &visstrim_m10_led_data);
468 visstrim_camera_init();
471 static void __init visstrim_m10_timer_init(void)
473 mx27_clocks_init((unsigned long)25000000);
476 static struct sys_timer visstrim_m10_timer = {
477 .init = visstrim_m10_timer_init,
480 MACHINE_START(IMX27_VISSTRIM_M10, "Vista Silicon Visstrim_M10")
481 .atag_offset = 0x100,
482 .reserve = visstrim_reserve,
483 .map_io = mx27_map_io,
484 .init_early = imx27_init_early,
485 .init_irq = mx27_init_irq,
486 .handle_irq = imx27_handle_irq,
487 .timer = &visstrim_m10_timer,
488 .init_machine = visstrim_m10_board_init,
489 .restart = mxc_restart,