]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/arm/mach-imx/mach-imx27_visstrim_m10.c
ARM i.MX imx21ads: Fix overlapping static i/o mappings
[mirror_ubuntu-bionic-kernel.git] / 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 <mach/common.h>
42 #include <mach/iomux-mx27.h>
43
44 #include "devices-imx27.h"
45
46 #define TVP5150_RSTN (GPIO_PORTC + 18)
47 #define TVP5150_PWDN (GPIO_PORTC + 19)
48 #define OTG_PHY_CS_GPIO (GPIO_PORTF + 17)
49 #define SDHC1_IRQ IRQ_GPIOB(25)
50
51 static const int visstrim_m10_pins[] __initconst = {
52 /* UART1 (console) */
53 PE12_PF_UART1_TXD,
54 PE13_PF_UART1_RXD,
55 PE14_PF_UART1_CTS,
56 PE15_PF_UART1_RTS,
57 /* FEC */
58 PD0_AIN_FEC_TXD0,
59 PD1_AIN_FEC_TXD1,
60 PD2_AIN_FEC_TXD2,
61 PD3_AIN_FEC_TXD3,
62 PD4_AOUT_FEC_RX_ER,
63 PD5_AOUT_FEC_RXD1,
64 PD6_AOUT_FEC_RXD2,
65 PD7_AOUT_FEC_RXD3,
66 PD8_AF_FEC_MDIO,
67 PD9_AIN_FEC_MDC,
68 PD10_AOUT_FEC_CRS,
69 PD11_AOUT_FEC_TX_CLK,
70 PD12_AOUT_FEC_RXD0,
71 PD13_AOUT_FEC_RX_DV,
72 PD14_AOUT_FEC_RX_CLK,
73 PD15_AOUT_FEC_COL,
74 PD16_AIN_FEC_TX_ER,
75 PF23_AIN_FEC_TX_EN,
76 /* SSI1 */
77 PC20_PF_SSI1_FS,
78 PC21_PF_SSI1_RXD,
79 PC22_PF_SSI1_TXD,
80 PC23_PF_SSI1_CLK,
81 /* SDHC1 */
82 PE18_PF_SD1_D0,
83 PE19_PF_SD1_D1,
84 PE20_PF_SD1_D2,
85 PE21_PF_SD1_D3,
86 PE22_PF_SD1_CMD,
87 PE23_PF_SD1_CLK,
88 /* Both I2Cs */
89 PD17_PF_I2C_DATA,
90 PD18_PF_I2C_CLK,
91 PC5_PF_I2C2_SDA,
92 PC6_PF_I2C2_SCL,
93 /* USB OTG */
94 OTG_PHY_CS_GPIO | GPIO_GPIO | GPIO_OUT,
95 PC9_PF_USBOTG_DATA0,
96 PC11_PF_USBOTG_DATA1,
97 PC10_PF_USBOTG_DATA2,
98 PC13_PF_USBOTG_DATA3,
99 PC12_PF_USBOTG_DATA4,
100 PC7_PF_USBOTG_DATA5,
101 PC8_PF_USBOTG_DATA6,
102 PE25_PF_USBOTG_DATA7,
103 PE24_PF_USBOTG_CLK,
104 PE2_PF_USBOTG_DIR,
105 PE0_PF_USBOTG_NXT,
106 PE1_PF_USBOTG_STP,
107 PB23_PF_USB_PWR,
108 PB24_PF_USB_OC,
109 /* CSI */
110 TVP5150_RSTN | GPIO_GPIO | GPIO_OUT,
111 TVP5150_PWDN | GPIO_GPIO | GPIO_OUT,
112 PB10_PF_CSI_D0,
113 PB11_PF_CSI_D1,
114 PB12_PF_CSI_D2,
115 PB13_PF_CSI_D3,
116 PB14_PF_CSI_D4,
117 PB15_PF_CSI_MCLK,
118 PB16_PF_CSI_PIXCLK,
119 PB17_PF_CSI_D5,
120 PB18_PF_CSI_D6,
121 PB19_PF_CSI_D7,
122 PB20_PF_CSI_VSYNC,
123 PB21_PF_CSI_HSYNC,
124 };
125
126 static const struct gpio visstrim_m10_gpios[] __initconst = {
127 {
128 .gpio = TVP5150_RSTN,
129 .flags = GPIOF_DIR_OUT | GPIOF_INIT_HIGH,
130 .label = "tvp5150_rstn",
131 },
132 {
133 .gpio = TVP5150_PWDN,
134 .flags = GPIOF_DIR_OUT | GPIOF_INIT_LOW,
135 .label = "tvp5150_pwdn",
136 },
137 {
138 .gpio = OTG_PHY_CS_GPIO,
139 .flags = GPIOF_DIR_OUT | GPIOF_INIT_LOW,
140 .label = "usbotg_cs",
141 },
142 };
143
144 /* Camera */
145 static int visstrim_camera_power(struct device *dev, int on)
146 {
147 gpio_set_value(TVP5150_PWDN, on);
148
149 return 0;
150 };
151
152 static int visstrim_camera_reset(struct device *dev)
153 {
154 gpio_set_value(TVP5150_RSTN, 0);
155 ndelay(500);
156 gpio_set_value(TVP5150_RSTN, 1);
157
158 return 0;
159 };
160
161 static struct i2c_board_info visstrim_i2c_camera = {
162 I2C_BOARD_INFO("tvp5150", 0x5d),
163 };
164
165 static struct soc_camera_link iclink_tvp5150 = {
166 .bus_id = 0,
167 .board_info = &visstrim_i2c_camera,
168 .i2c_adapter_id = 0,
169 .power = visstrim_camera_power,
170 .reset = visstrim_camera_reset,
171 };
172
173 static struct mx2_camera_platform_data visstrim_camera = {
174 .flags = MX2_CAMERA_CCIR | MX2_CAMERA_CCIR_INTERLACE |
175 MX2_CAMERA_SWAP16 | MX2_CAMERA_PCLK_SAMPLE_RISING,
176 .clk = 100000,
177 };
178
179 static phys_addr_t mx2_camera_base __initdata;
180 #define MX2_CAMERA_BUF_SIZE SZ_8M
181
182 static void __init visstrim_camera_init(void)
183 {
184 struct platform_device *pdev;
185 int dma;
186
187 gpio_set_value(TVP5150_PWDN, 1);
188 ndelay(1);
189 gpio_set_value(TVP5150_RSTN, 0);
190 ndelay(500);
191 gpio_set_value(TVP5150_RSTN, 1);
192 ndelay(200000);
193
194 pdev = imx27_add_mx2_camera(&visstrim_camera);
195 if (IS_ERR(pdev))
196 return;
197
198 dma = dma_declare_coherent_memory(&pdev->dev,
199 mx2_camera_base, mx2_camera_base,
200 MX2_CAMERA_BUF_SIZE,
201 DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE);
202 if (!(dma & DMA_MEMORY_MAP))
203 return;
204 }
205
206 static void __init visstrim_reserve(void)
207 {
208 /* reserve 4 MiB for mx2-camera */
209 mx2_camera_base = memblock_alloc(MX2_CAMERA_BUF_SIZE,
210 MX2_CAMERA_BUF_SIZE);
211 memblock_free(mx2_camera_base, MX2_CAMERA_BUF_SIZE);
212 memblock_remove(mx2_camera_base, MX2_CAMERA_BUF_SIZE);
213 }
214
215 /* GPIOs used as events for applications */
216 static struct gpio_keys_button visstrim_gpio_keys[] = {
217 {
218 .type = EV_KEY,
219 .code = KEY_RESTART,
220 .gpio = (GPIO_PORTC + 15),
221 .desc = "Default config",
222 .active_low = 0,
223 .wakeup = 1,
224 },
225 {
226 .type = EV_KEY,
227 .code = KEY_RECORD,
228 .gpio = (GPIO_PORTF + 14),
229 .desc = "Record",
230 .active_low = 0,
231 .wakeup = 1,
232 },
233 {
234 .type = EV_KEY,
235 .code = KEY_STOP,
236 .gpio = (GPIO_PORTF + 13),
237 .desc = "Stop",
238 .active_low = 0,
239 .wakeup = 1,
240 }
241 };
242
243 static const struct gpio_keys_platform_data
244 visstrim_gpio_keys_platform_data __initconst = {
245 .buttons = visstrim_gpio_keys,
246 .nbuttons = ARRAY_SIZE(visstrim_gpio_keys),
247 };
248
249 /* led */
250 static const struct gpio_led visstrim_m10_leds[] __initconst = {
251 {
252 .name = "visstrim:ld0",
253 .default_trigger = "nand-disk",
254 .gpio = (GPIO_PORTC + 29),
255 },
256 {
257 .name = "visstrim:ld1",
258 .default_trigger = "nand-disk",
259 .gpio = (GPIO_PORTC + 24),
260 },
261 {
262 .name = "visstrim:ld2",
263 .default_trigger = "nand-disk",
264 .gpio = (GPIO_PORTC + 28),
265 },
266 {
267 .name = "visstrim:ld3",
268 .default_trigger = "nand-disk",
269 .gpio = (GPIO_PORTC + 25),
270 },
271 };
272
273 static const struct gpio_led_platform_data visstrim_m10_led_data __initconst = {
274 .leds = visstrim_m10_leds,
275 .num_leds = ARRAY_SIZE(visstrim_m10_leds),
276 };
277
278 /* Visstrim_SM10 has a microSD slot connected to sdhc1 */
279 static int visstrim_m10_sdhc1_init(struct device *dev,
280 irq_handler_t detect_irq, void *data)
281 {
282 int ret;
283
284 ret = request_irq(SDHC1_IRQ, detect_irq, IRQF_TRIGGER_FALLING,
285 "mmc-detect", data);
286 return ret;
287 }
288
289 static void visstrim_m10_sdhc1_exit(struct device *dev, void *data)
290 {
291 free_irq(SDHC1_IRQ, data);
292 }
293
294 static const struct imxmmc_platform_data visstrim_m10_sdhc_pdata __initconst = {
295 .init = visstrim_m10_sdhc1_init,
296 .exit = visstrim_m10_sdhc1_exit,
297 };
298
299 /* Visstrim_SM10 NOR flash */
300 static struct physmap_flash_data visstrim_m10_flash_data = {
301 .width = 2,
302 };
303
304 static struct resource visstrim_m10_flash_resource = {
305 .start = 0xc0000000,
306 .end = 0xc0000000 + SZ_64M - 1,
307 .flags = IORESOURCE_MEM,
308 };
309
310 static struct platform_device visstrim_m10_nor_mtd_device = {
311 .name = "physmap-flash",
312 .id = 0,
313 .dev = {
314 .platform_data = &visstrim_m10_flash_data,
315 },
316 .num_resources = 1,
317 .resource = &visstrim_m10_flash_resource,
318 };
319
320 static struct platform_device *platform_devices[] __initdata = {
321 &visstrim_m10_nor_mtd_device,
322 };
323
324 /* Visstrim_M10 uses UART0 as console */
325 static const struct imxuart_platform_data uart_pdata __initconst = {
326 .flags = IMXUART_HAVE_RTSCTS,
327 };
328
329 /* I2C */
330 static const struct imxi2c_platform_data visstrim_m10_i2c_data __initconst = {
331 .bitrate = 100000,
332 };
333
334 static struct pca953x_platform_data visstrim_m10_pca9555_pdata = {
335 .gpio_base = 240, /* After MX27 internal GPIOs */
336 .invert = 0,
337 };
338
339 static struct aic32x4_pdata visstrim_m10_aic32x4_pdata = {
340 .power_cfg = AIC32X4_PWR_MICBIAS_2075_LDOIN |
341 AIC32X4_PWR_AVDD_DVDD_WEAK_DISABLE |
342 AIC32X4_PWR_AIC32X4_LDO_ENABLE |
343 AIC32X4_PWR_CMMODE_LDOIN_RANGE_18_36 |
344 AIC32X4_PWR_CMMODE_HP_LDOIN_POWERED,
345 .micpga_routing = AIC32X4_MICPGA_ROUTE_LMIC_IN2R_10K |
346 AIC32X4_MICPGA_ROUTE_RMIC_IN1L_10K,
347 .swapdacs = false,
348 };
349
350 static struct i2c_board_info visstrim_m10_i2c_devices[] = {
351 {
352 I2C_BOARD_INFO("pca9555", 0x20),
353 .platform_data = &visstrim_m10_pca9555_pdata,
354 },
355 {
356 I2C_BOARD_INFO("tlv320aic32x4", 0x18),
357 .platform_data = &visstrim_m10_aic32x4_pdata,
358 },
359 {
360 I2C_BOARD_INFO("m41t00", 0x68),
361 }
362 };
363
364 /* USB OTG */
365 static int otg_phy_init(struct platform_device *pdev)
366 {
367 return mx27_initialize_usb_hw(pdev->id, MXC_EHCI_POWER_PINS_ENABLED);
368 }
369
370 static const struct mxc_usbh_platform_data
371 visstrim_m10_usbotg_pdata __initconst = {
372 .init = otg_phy_init,
373 .portsc = MXC_EHCI_MODE_ULPI | MXC_EHCI_UTMI_8BIT,
374 };
375
376 /* SSI */
377 static const struct imx_ssi_platform_data visstrim_m10_ssi_pdata __initconst = {
378 .flags = IMX_SSI_DMA | IMX_SSI_SYN,
379 };
380
381 static void __init visstrim_m10_board_init(void)
382 {
383 int ret;
384
385 imx27_soc_init();
386
387 ret = mxc_gpio_setup_multiple_pins(visstrim_m10_pins,
388 ARRAY_SIZE(visstrim_m10_pins), "VISSTRIM_M10");
389 if (ret)
390 pr_err("Failed to setup pins (%d)\n", ret);
391
392 ret = gpio_request_array(visstrim_m10_gpios,
393 ARRAY_SIZE(visstrim_m10_gpios));
394 if (ret)
395 pr_err("Failed to request gpios (%d)\n", ret);
396
397 imx27_add_imx_ssi(0, &visstrim_m10_ssi_pdata);
398 imx27_add_imx_uart0(&uart_pdata);
399
400 imx27_add_imx_i2c(0, &visstrim_m10_i2c_data);
401 imx27_add_imx_i2c(1, &visstrim_m10_i2c_data);
402 i2c_register_board_info(0, visstrim_m10_i2c_devices,
403 ARRAY_SIZE(visstrim_m10_i2c_devices));
404
405 imx27_add_mxc_mmc(0, &visstrim_m10_sdhc_pdata);
406 imx27_add_mxc_ehci_otg(&visstrim_m10_usbotg_pdata);
407 imx27_add_fec(NULL);
408 imx_add_gpio_keys(&visstrim_gpio_keys_platform_data);
409 platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
410 imx_add_platform_device("mx27vis", 0, NULL, 0, NULL, 0);
411 platform_device_register_resndata(NULL, "soc-camera-pdrv", 0, NULL, 0,
412 &iclink_tvp5150, sizeof(iclink_tvp5150));
413 gpio_led_register_device(0, &visstrim_m10_led_data);
414 visstrim_camera_init();
415 }
416
417 static void __init visstrim_m10_timer_init(void)
418 {
419 mx27_clocks_init((unsigned long)25000000);
420 }
421
422 static struct sys_timer visstrim_m10_timer = {
423 .init = visstrim_m10_timer_init,
424 };
425
426 MACHINE_START(IMX27_VISSTRIM_M10, "Vista Silicon Visstrim_M10")
427 .atag_offset = 0x100,
428 .reserve = visstrim_reserve,
429 .map_io = mx27_map_io,
430 .init_early = imx27_init_early,
431 .init_irq = mx27_init_irq,
432 .handle_irq = imx27_handle_irq,
433 .timer = &visstrim_m10_timer,
434 .init_machine = visstrim_m10_board_init,
435 .restart = mxc_restart,
436 MACHINE_END