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
,
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
,
141 static struct gpio visstrim_m10_version_gpios
[] = {
142 { EXPBOARD_BIT0
, GPIOF_IN
, "exp-version-0" },
143 { EXPBOARD_BIT1
, GPIOF_IN
, "exp-version-1" },
144 { EXPBOARD_BIT2
, GPIOF_IN
, "exp-version-2" },
145 { MOTHERBOARD_BIT0
, GPIOF_IN
, "mother-version-0" },
146 { MOTHERBOARD_BIT1
, GPIOF_IN
, "mother-version-1" },
147 { MOTHERBOARD_BIT2
, GPIOF_IN
, "mother-version-2" },
151 static int visstrim_camera_power(struct device
*dev
, int on
)
153 gpio_set_value(TVP5150_PWDN
, on
);
158 static int visstrim_camera_reset(struct device
*dev
)
160 gpio_set_value(TVP5150_RSTN
, 0);
162 gpio_set_value(TVP5150_RSTN
, 1);
167 static struct i2c_board_info visstrim_i2c_camera
= {
168 I2C_BOARD_INFO("tvp5150", 0x5d),
171 static struct soc_camera_link iclink_tvp5150
= {
173 .board_info
= &visstrim_i2c_camera
,
175 .power
= visstrim_camera_power
,
176 .reset
= visstrim_camera_reset
,
179 static struct mx2_camera_platform_data visstrim_camera
= {
180 .flags
= MX2_CAMERA_CCIR
| MX2_CAMERA_CCIR_INTERLACE
|
181 MX2_CAMERA_PCLK_SAMPLE_RISING
,
185 static phys_addr_t mx2_camera_base __initdata
;
186 #define MX2_CAMERA_BUF_SIZE SZ_8M
188 static void __init
visstrim_camera_init(void)
190 struct platform_device
*pdev
;
193 /* Initialize tvp5150 gpios */
194 mxc_gpio_mode(TVP5150_RSTN
| GPIO_GPIO
| GPIO_OUT
);
195 mxc_gpio_mode(TVP5150_PWDN
| GPIO_GPIO
| GPIO_OUT
);
196 gpio_set_value(TVP5150_RSTN
, 1);
197 gpio_set_value(TVP5150_PWDN
, 0);
200 gpio_set_value(TVP5150_PWDN
, 1);
202 gpio_set_value(TVP5150_RSTN
, 0);
204 gpio_set_value(TVP5150_RSTN
, 1);
207 pdev
= imx27_add_mx2_camera(&visstrim_camera
);
211 dma
= dma_declare_coherent_memory(&pdev
->dev
,
212 mx2_camera_base
, mx2_camera_base
,
214 DMA_MEMORY_MAP
| DMA_MEMORY_EXCLUSIVE
);
215 if (!(dma
& DMA_MEMORY_MAP
))
219 static void __init
visstrim_reserve(void)
221 /* reserve 4 MiB for mx2-camera */
222 mx2_camera_base
= memblock_alloc(MX2_CAMERA_BUF_SIZE
,
223 MX2_CAMERA_BUF_SIZE
);
224 memblock_free(mx2_camera_base
, MX2_CAMERA_BUF_SIZE
);
225 memblock_remove(mx2_camera_base
, MX2_CAMERA_BUF_SIZE
);
228 /* GPIOs used as events for applications */
229 static struct gpio_keys_button visstrim_gpio_keys
[] = {
233 .gpio
= (GPIO_PORTC
+ 15),
234 .desc
= "Default config",
241 .gpio
= (GPIO_PORTF
+ 14),
249 .gpio
= (GPIO_PORTF
+ 13),
256 static const struct gpio_keys_platform_data
257 visstrim_gpio_keys_platform_data __initconst
= {
258 .buttons
= visstrim_gpio_keys
,
259 .nbuttons
= ARRAY_SIZE(visstrim_gpio_keys
),
263 static const struct gpio_led visstrim_m10_leds
[] __initconst
= {
265 .name
= "visstrim:ld0",
266 .default_trigger
= "nand-disk",
267 .gpio
= (GPIO_PORTC
+ 29),
270 .name
= "visstrim:ld1",
271 .default_trigger
= "nand-disk",
272 .gpio
= (GPIO_PORTC
+ 24),
275 .name
= "visstrim:ld2",
276 .default_trigger
= "nand-disk",
277 .gpio
= (GPIO_PORTC
+ 28),
280 .name
= "visstrim:ld3",
281 .default_trigger
= "nand-disk",
282 .gpio
= (GPIO_PORTC
+ 25),
286 static const struct gpio_led_platform_data visstrim_m10_led_data __initconst
= {
287 .leds
= visstrim_m10_leds
,
288 .num_leds
= ARRAY_SIZE(visstrim_m10_leds
),
291 /* Visstrim_SM10 has a microSD slot connected to sdhc1 */
292 static int visstrim_m10_sdhc1_init(struct device
*dev
,
293 irq_handler_t detect_irq
, void *data
)
297 ret
= request_irq(SDHC1_IRQ
, detect_irq
, IRQF_TRIGGER_FALLING
,
302 static void visstrim_m10_sdhc1_exit(struct device
*dev
, void *data
)
304 free_irq(SDHC1_IRQ
, data
);
307 static const struct imxmmc_platform_data visstrim_m10_sdhc_pdata __initconst
= {
308 .init
= visstrim_m10_sdhc1_init
,
309 .exit
= visstrim_m10_sdhc1_exit
,
312 /* Visstrim_SM10 NOR flash */
313 static struct physmap_flash_data visstrim_m10_flash_data
= {
317 static struct resource visstrim_m10_flash_resource
= {
319 .end
= 0xc0000000 + SZ_64M
- 1,
320 .flags
= IORESOURCE_MEM
,
323 static struct platform_device visstrim_m10_nor_mtd_device
= {
324 .name
= "physmap-flash",
327 .platform_data
= &visstrim_m10_flash_data
,
330 .resource
= &visstrim_m10_flash_resource
,
333 static struct platform_device
*platform_devices
[] __initdata
= {
334 &visstrim_m10_nor_mtd_device
,
337 /* Visstrim_M10 uses UART0 as console */
338 static const struct imxuart_platform_data uart_pdata __initconst
= {
339 .flags
= IMXUART_HAVE_RTSCTS
,
343 static const struct imxi2c_platform_data visstrim_m10_i2c_data __initconst
= {
347 static struct pca953x_platform_data visstrim_m10_pca9555_pdata
= {
348 .gpio_base
= 240, /* After MX27 internal GPIOs */
352 static struct aic32x4_pdata visstrim_m10_aic32x4_pdata
= {
353 .power_cfg
= AIC32X4_PWR_MICBIAS_2075_LDOIN
|
354 AIC32X4_PWR_AVDD_DVDD_WEAK_DISABLE
|
355 AIC32X4_PWR_AIC32X4_LDO_ENABLE
|
356 AIC32X4_PWR_CMMODE_LDOIN_RANGE_18_36
|
357 AIC32X4_PWR_CMMODE_HP_LDOIN_POWERED
,
358 .micpga_routing
= AIC32X4_MICPGA_ROUTE_LMIC_IN2R_10K
|
359 AIC32X4_MICPGA_ROUTE_RMIC_IN1L_10K
,
363 static struct i2c_board_info visstrim_m10_i2c_devices
[] = {
365 I2C_BOARD_INFO("pca9555", 0x20),
366 .platform_data
= &visstrim_m10_pca9555_pdata
,
369 I2C_BOARD_INFO("tlv320aic32x4", 0x18),
370 .platform_data
= &visstrim_m10_aic32x4_pdata
,
373 I2C_BOARD_INFO("m41t00", 0x68),
378 static int otg_phy_init(struct platform_device
*pdev
)
380 gpio_set_value(OTG_PHY_CS_GPIO
, 0);
384 return mx27_initialize_usb_hw(pdev
->id
, MXC_EHCI_POWER_PINS_ENABLED
);
387 static const struct mxc_usbh_platform_data
388 visstrim_m10_usbotg_pdata __initconst
= {
389 .init
= otg_phy_init
,
390 .portsc
= MXC_EHCI_MODE_ULPI
| MXC_EHCI_UTMI_8BIT
,
394 static const struct imx_ssi_platform_data visstrim_m10_ssi_pdata __initconst
= {
395 .flags
= IMX_SSI_DMA
| IMX_SSI_SYN
,
398 static void __init
visstrim_m10_revision(void)
404 ret
= gpio_request_array(visstrim_m10_version_gpios
,
405 ARRAY_SIZE(visstrim_m10_version_gpios
));
407 pr_err("Failed to request version gpios");
411 /* Get expansion board version (negative logic) */
412 exp_version
|= !gpio_get_value(EXPBOARD_BIT2
) << 2;
413 exp_version
|= !gpio_get_value(EXPBOARD_BIT1
) << 1;
414 exp_version
|= !gpio_get_value(EXPBOARD_BIT0
);
416 /* Get mother board version (negative logic) */
417 mo_version
|= !gpio_get_value(MOTHERBOARD_BIT2
) << 2;
418 mo_version
|= !gpio_get_value(MOTHERBOARD_BIT1
) << 1;
419 mo_version
|= !gpio_get_value(MOTHERBOARD_BIT0
);
421 system_rev
= 0x27000;
422 system_rev
|= (mo_version
<< 4);
423 system_rev
|= exp_version
;
426 static void __init
visstrim_m10_board_init(void)
431 visstrim_m10_revision();
433 ret
= mxc_gpio_setup_multiple_pins(visstrim_m10_pins
,
434 ARRAY_SIZE(visstrim_m10_pins
), "VISSTRIM_M10");
436 pr_err("Failed to setup pins (%d)\n", ret
);
438 imx27_add_imx_ssi(0, &visstrim_m10_ssi_pdata
);
439 imx27_add_imx_uart0(&uart_pdata
);
441 imx27_add_imx_i2c(0, &visstrim_m10_i2c_data
);
442 imx27_add_imx_i2c(1, &visstrim_m10_i2c_data
);
443 i2c_register_board_info(0, visstrim_m10_i2c_devices
,
444 ARRAY_SIZE(visstrim_m10_i2c_devices
));
446 imx27_add_mxc_mmc(0, &visstrim_m10_sdhc_pdata
);
447 imx27_add_mxc_ehci_otg(&visstrim_m10_usbotg_pdata
);
449 imx_add_gpio_keys(&visstrim_gpio_keys_platform_data
);
450 platform_add_devices(platform_devices
, ARRAY_SIZE(platform_devices
));
451 imx_add_platform_device("mx27vis", 0, NULL
, 0, NULL
, 0);
452 platform_device_register_resndata(NULL
, "soc-camera-pdrv", 0, NULL
, 0,
453 &iclink_tvp5150
, sizeof(iclink_tvp5150
));
454 gpio_led_register_device(0, &visstrim_m10_led_data
);
455 visstrim_camera_init();
458 static void __init
visstrim_m10_timer_init(void)
460 mx27_clocks_init((unsigned long)25000000);
463 static struct sys_timer visstrim_m10_timer
= {
464 .init
= visstrim_m10_timer_init
,
467 MACHINE_START(IMX27_VISSTRIM_M10
, "Vista Silicon Visstrim_M10")
468 .atag_offset
= 0x100,
469 .reserve
= visstrim_reserve
,
470 .map_io
= mx27_map_io
,
471 .init_early
= imx27_init_early
,
472 .init_irq
= mx27_init_irq
,
473 .handle_irq
= imx27_handle_irq
,
474 .timer
= &visstrim_m10_timer
,
475 .init_machine
= visstrim_m10_board_init
,
476 .restart
= mxc_restart
,