]> Pileus Git - ~andy/linux/blob - arch/arm/mach-imx/mach-imx27_visstrim_m10.c
Merge branch 'devel'
[~andy/linux] / arch / arm / mach-imx / mach-imx27_visstrim_m10.c
1 /*
2  * mach-imx27_visstrim_m10.c
3  *
4  * Copyright 2010  Javier Martin <javier.martin@vista-silicon.com>
5  *
6  * Based on mach-pcm038.c, mach-pca100.c, mach-mx27ads.c and others.
7  *
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.
12  *
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.
17  *
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,
21  * MA 02110-1301, USA.
22  */
23
24 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25
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_info.h>
42 #include <mach/common.h>
43 #include <mach/iomux-mx27.h>
44
45 #include "devices-imx27.h"
46
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)
51
52 #define MOTHERBOARD_BIT2        (GPIO_PORTD + 31)
53 #define MOTHERBOARD_BIT1        (GPIO_PORTD + 30)
54 #define MOTHERBOARD_BIT0        (GPIO_PORTD + 29)
55
56 #define EXPBOARD_BIT2           (GPIO_PORTD + 25)
57 #define EXPBOARD_BIT1           (GPIO_PORTD + 27)
58 #define EXPBOARD_BIT0           (GPIO_PORTD + 28)
59
60 static const int visstrim_m10_pins[] __initconst = {
61         /* UART1 (console) */
62         PE12_PF_UART1_TXD,
63         PE13_PF_UART1_RXD,
64         PE14_PF_UART1_CTS,
65         PE15_PF_UART1_RTS,
66         /* FEC */
67         PD0_AIN_FEC_TXD0,
68         PD1_AIN_FEC_TXD1,
69         PD2_AIN_FEC_TXD2,
70         PD3_AIN_FEC_TXD3,
71         PD4_AOUT_FEC_RX_ER,
72         PD5_AOUT_FEC_RXD1,
73         PD6_AOUT_FEC_RXD2,
74         PD7_AOUT_FEC_RXD3,
75         PD8_AF_FEC_MDIO,
76         PD9_AIN_FEC_MDC,
77         PD10_AOUT_FEC_CRS,
78         PD11_AOUT_FEC_TX_CLK,
79         PD12_AOUT_FEC_RXD0,
80         PD13_AOUT_FEC_RX_DV,
81         PD14_AOUT_FEC_RX_CLK,
82         PD15_AOUT_FEC_COL,
83         PD16_AIN_FEC_TX_ER,
84         PF23_AIN_FEC_TX_EN,
85         /* SSI1 */
86         PC20_PF_SSI1_FS,
87         PC21_PF_SSI1_RXD,
88         PC22_PF_SSI1_TXD,
89         PC23_PF_SSI1_CLK,
90         /* SDHC1 */
91         PE18_PF_SD1_D0,
92         PE19_PF_SD1_D1,
93         PE20_PF_SD1_D2,
94         PE21_PF_SD1_D3,
95         PE22_PF_SD1_CMD,
96         PE23_PF_SD1_CLK,
97         /* Both I2Cs */
98         PD17_PF_I2C_DATA,
99         PD18_PF_I2C_CLK,
100         PC5_PF_I2C2_SDA,
101         PC6_PF_I2C2_SCL,
102         /* USB OTG */
103         OTG_PHY_CS_GPIO | GPIO_GPIO | GPIO_OUT,
104         PC9_PF_USBOTG_DATA0,
105         PC11_PF_USBOTG_DATA1,
106         PC10_PF_USBOTG_DATA2,
107         PC13_PF_USBOTG_DATA3,
108         PC12_PF_USBOTG_DATA4,
109         PC7_PF_USBOTG_DATA5,
110         PC8_PF_USBOTG_DATA6,
111         PE25_PF_USBOTG_DATA7,
112         PE24_PF_USBOTG_CLK,
113         PE2_PF_USBOTG_DIR,
114         PE0_PF_USBOTG_NXT,
115         PE1_PF_USBOTG_STP,
116         PB23_PF_USB_PWR,
117         PB24_PF_USB_OC,
118         /* CSI */
119         TVP5150_RSTN | GPIO_GPIO | GPIO_OUT,
120         TVP5150_PWDN | GPIO_GPIO | GPIO_OUT,
121         PB10_PF_CSI_D0,
122         PB11_PF_CSI_D1,
123         PB12_PF_CSI_D2,
124         PB13_PF_CSI_D3,
125         PB14_PF_CSI_D4,
126         PB15_PF_CSI_MCLK,
127         PB16_PF_CSI_PIXCLK,
128         PB17_PF_CSI_D5,
129         PB18_PF_CSI_D6,
130         PB19_PF_CSI_D7,
131         PB20_PF_CSI_VSYNC,
132         PB21_PF_CSI_HSYNC,
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,
141 };
142
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" },
150 };
151
152 static const struct gpio visstrim_m10_gpios[] __initconst = {
153         {
154                 .gpio = TVP5150_RSTN,
155                 .flags = GPIOF_DIR_OUT | GPIOF_INIT_HIGH,
156                 .label = "tvp5150_rstn",
157         },
158         {
159                 .gpio = TVP5150_PWDN,
160                 .flags = GPIOF_DIR_OUT | GPIOF_INIT_LOW,
161                 .label = "tvp5150_pwdn",
162         },
163         {
164                 .gpio = OTG_PHY_CS_GPIO,
165                 .flags = GPIOF_DIR_OUT | GPIOF_INIT_LOW,
166                 .label = "usbotg_cs",
167         },
168 };
169
170 /* Camera */
171 static int visstrim_camera_power(struct device *dev, int on)
172 {
173         gpio_set_value(TVP5150_PWDN, on);
174
175         return 0;
176 };
177
178 static int visstrim_camera_reset(struct device *dev)
179 {
180         gpio_set_value(TVP5150_RSTN, 0);
181         ndelay(500);
182         gpio_set_value(TVP5150_RSTN, 1);
183
184         return 0;
185 };
186
187 static struct i2c_board_info visstrim_i2c_camera =  {
188         I2C_BOARD_INFO("tvp5150", 0x5d),
189 };
190
191 static struct soc_camera_link iclink_tvp5150 = {
192         .bus_id         = 0,
193         .board_info     = &visstrim_i2c_camera,
194         .i2c_adapter_id = 0,
195         .power = visstrim_camera_power,
196         .reset = visstrim_camera_reset,
197 };
198
199 static struct mx2_camera_platform_data visstrim_camera = {
200         .flags = MX2_CAMERA_CCIR | MX2_CAMERA_CCIR_INTERLACE |
201                  MX2_CAMERA_PCLK_SAMPLE_RISING,
202         .clk = 100000,
203 };
204
205 static phys_addr_t mx2_camera_base __initdata;
206 #define MX2_CAMERA_BUF_SIZE SZ_8M
207
208 static void __init visstrim_camera_init(void)
209 {
210         struct platform_device *pdev;
211         int dma;
212
213         gpio_set_value(TVP5150_PWDN, 1);
214         ndelay(1);
215         gpio_set_value(TVP5150_RSTN, 0);
216         ndelay(500);
217         gpio_set_value(TVP5150_RSTN, 1);
218         ndelay(200000);
219
220         pdev = imx27_add_mx2_camera(&visstrim_camera);
221         if (IS_ERR(pdev))
222                 return;
223
224         dma = dma_declare_coherent_memory(&pdev->dev,
225                                 mx2_camera_base, mx2_camera_base,
226                                 MX2_CAMERA_BUF_SIZE,
227                                 DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE);
228         if (!(dma & DMA_MEMORY_MAP))
229                 return;
230 }
231
232 static void __init visstrim_reserve(void)
233 {
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);
239 }
240
241 /* GPIOs used as events for applications */
242 static struct gpio_keys_button visstrim_gpio_keys[] = {
243         {
244                 .type   = EV_KEY,
245                 .code   = KEY_RESTART,
246                 .gpio   = (GPIO_PORTC + 15),
247                 .desc   = "Default config",
248                 .active_low = 0,
249                 .wakeup = 1,
250         },
251         {
252                 .type   = EV_KEY,
253                 .code   = KEY_RECORD,
254                 .gpio   = (GPIO_PORTF + 14),
255                 .desc   = "Record",
256                 .active_low = 0,
257                 .wakeup = 1,
258         },
259         {
260                 .type   = EV_KEY,
261                 .code   = KEY_STOP,
262                 .gpio   = (GPIO_PORTF + 13),
263                 .desc   = "Stop",
264                 .active_low = 0,
265                 .wakeup = 1,
266         }
267 };
268
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),
273 };
274
275 /* led */
276 static const struct gpio_led visstrim_m10_leds[] __initconst = {
277         {
278                 .name = "visstrim:ld0",
279                 .default_trigger = "nand-disk",
280                 .gpio = (GPIO_PORTC + 29),
281         },
282         {
283                 .name = "visstrim:ld1",
284                 .default_trigger = "nand-disk",
285                 .gpio = (GPIO_PORTC + 24),
286         },
287         {
288                 .name = "visstrim:ld2",
289                 .default_trigger = "nand-disk",
290                 .gpio = (GPIO_PORTC + 28),
291         },
292         {
293                 .name = "visstrim:ld3",
294                 .default_trigger = "nand-disk",
295                 .gpio = (GPIO_PORTC + 25),
296         },
297 };
298
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),
302 };
303
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)
307 {
308         int ret;
309
310         ret = request_irq(SDHC1_IRQ, detect_irq, IRQF_TRIGGER_FALLING,
311                                 "mmc-detect", data);
312         return ret;
313 }
314
315 static void visstrim_m10_sdhc1_exit(struct device *dev, void *data)
316 {
317         free_irq(SDHC1_IRQ, data);
318 }
319
320 static const struct imxmmc_platform_data visstrim_m10_sdhc_pdata __initconst = {
321         .init = visstrim_m10_sdhc1_init,
322         .exit = visstrim_m10_sdhc1_exit,
323 };
324
325 /* Visstrim_SM10 NOR flash */
326 static struct physmap_flash_data visstrim_m10_flash_data = {
327         .width = 2,
328 };
329
330 static struct resource visstrim_m10_flash_resource = {
331         .start = 0xc0000000,
332         .end = 0xc0000000 + SZ_64M - 1,
333         .flags = IORESOURCE_MEM,
334 };
335
336 static struct platform_device visstrim_m10_nor_mtd_device = {
337         .name = "physmap-flash",
338         .id = 0,
339         .dev = {
340                 .platform_data = &visstrim_m10_flash_data,
341         },
342         .num_resources = 1,
343         .resource = &visstrim_m10_flash_resource,
344 };
345
346 static struct platform_device *platform_devices[] __initdata = {
347         &visstrim_m10_nor_mtd_device,
348 };
349
350 /* Visstrim_M10 uses UART0 as console */
351 static const struct imxuart_platform_data uart_pdata __initconst = {
352         .flags = IMXUART_HAVE_RTSCTS,
353 };
354
355 /* I2C */
356 static const struct imxi2c_platform_data visstrim_m10_i2c_data __initconst = {
357         .bitrate = 100000,
358 };
359
360 static struct pca953x_platform_data visstrim_m10_pca9555_pdata = {
361         .gpio_base = 240, /* After MX27 internal GPIOs */
362         .invert = 0,
363 };
364
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,
373         .swapdacs = false,
374 };
375
376 static struct i2c_board_info visstrim_m10_i2c_devices[] = {
377         {
378                 I2C_BOARD_INFO("pca9555", 0x20),
379                 .platform_data = &visstrim_m10_pca9555_pdata,
380         },
381         {
382                 I2C_BOARD_INFO("tlv320aic32x4", 0x18),
383                 .platform_data = &visstrim_m10_aic32x4_pdata,
384         },
385         {
386                  I2C_BOARD_INFO("m41t00", 0x68),
387         }
388 };
389
390 /* USB OTG */
391 static int otg_phy_init(struct platform_device *pdev)
392 {
393         return mx27_initialize_usb_hw(pdev->id, MXC_EHCI_POWER_PINS_ENABLED);
394 }
395
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,
400 };
401
402 /* SSI */
403 static const struct imx_ssi_platform_data visstrim_m10_ssi_pdata __initconst = {
404         .flags                  = IMX_SSI_DMA | IMX_SSI_SYN,
405 };
406
407 static void __init visstrim_m10_revision(void)
408 {
409         int exp_version = 0;
410         int mo_version = 0;
411         int ret;
412
413         ret = gpio_request_array(visstrim_m10_version_gpios,
414                                  ARRAY_SIZE(visstrim_m10_version_gpios));
415         if (ret) {
416                 pr_err("Failed to request version gpios");
417                 return;
418         }
419
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);
424
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);
429
430         system_rev = 0x27000;
431         system_rev |= (mo_version << 4);
432         system_rev |= exp_version;
433 }
434
435 static void __init visstrim_m10_board_init(void)
436 {
437         int ret;
438
439         imx27_soc_init();
440         visstrim_m10_revision();
441
442         ret = mxc_gpio_setup_multiple_pins(visstrim_m10_pins,
443                         ARRAY_SIZE(visstrim_m10_pins), "VISSTRIM_M10");
444         if (ret)
445                 pr_err("Failed to setup pins (%d)\n", ret);
446
447         ret = gpio_request_array(visstrim_m10_gpios,
448                                 ARRAY_SIZE(visstrim_m10_gpios));
449         if (ret)
450                 pr_err("Failed to request gpios (%d)\n", ret);
451
452         imx27_add_imx_ssi(0, &visstrim_m10_ssi_pdata);
453         imx27_add_imx_uart0(&uart_pdata);
454
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));
459
460         imx27_add_mxc_mmc(0, &visstrim_m10_sdhc_pdata);
461         imx27_add_mxc_ehci_otg(&visstrim_m10_usbotg_pdata);
462         imx27_add_fec(NULL);
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();
470 }
471
472 static void __init visstrim_m10_timer_init(void)
473 {
474         mx27_clocks_init((unsigned long)25000000);
475 }
476
477 static struct sys_timer visstrim_m10_timer = {
478         .init   = visstrim_m10_timer_init,
479 };
480
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,
491 MACHINE_END