Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mach-armadillo5x0.c
Go to the documentation of this file.
1 /*
2  * armadillo5x0.c
3  *
4  * Copyright 2009 Alberto Panizzo <[email protected]>
5  * updates in http://alberdroid.blogspot.com/
6  *
7  * Based on Atmark Techno, Inc. armadillo 500 BSP 2008
8  * Based on mx31ads.c and pcm037.c Great Work!
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23  * MA 02110-1301, USA.
24  */
25 
26 #include <linux/types.h>
27 #include <linux/init.h>
28 #include <linux/clk.h>
29 #include <linux/platform_device.h>
30 #include <linux/gpio.h>
31 #include <linux/smsc911x.h>
32 #include <linux/interrupt.h>
33 #include <linux/irq.h>
34 #include <linux/mtd/physmap.h>
35 #include <linux/io.h>
36 #include <linux/input.h>
37 #include <linux/i2c.h>
38 #include <linux/usb/otg.h>
39 #include <linux/usb/ulpi.h>
40 #include <linux/delay.h>
42 #include <linux/regulator/fixed.h>
43 
44 #include <mach/hardware.h>
45 #include <asm/mach-types.h>
46 #include <asm/mach/arch.h>
47 #include <asm/mach/time.h>
48 #include <asm/memory.h>
49 #include <asm/mach/map.h>
50 
51 #include <mach/common.h>
52 #include <mach/iomux-mx3.h>
53 #include <mach/ulpi.h>
54 
55 #include "devices-imx31.h"
56 #include "crmregs-imx3.h"
57 
58 static int armadillo5x0_pins[] = {
59  /* UART1 */
64  /* UART2 */
69  /* LAN9118_IRQ */
71  /* SDHC1 */
78  /* Framebuffer */
101  IOMUX_MODE(MX31_PIN_LCS1, IOMUX_CONFIG_GPIO), /*ADV7125_PSAVE*/
102  /* I2C2 */
105  /* OTG */
118  /* USB host 2 */
131 };
132 
133 /* USB */
134 
135 #define OTG_RESET IOMUX_TO_GPIO(MX31_PIN_STXD4)
136 #define USBH2_RESET IOMUX_TO_GPIO(MX31_PIN_SCK6)
137 #define USBH2_CS IOMUX_TO_GPIO(MX31_PIN_GPIO1_3)
138 
139 #define USB_PAD_CFG (PAD_CTL_DRV_MAX | PAD_CTL_SRE_FAST | PAD_CTL_HYS_CMOS | \
140  PAD_CTL_ODE_CMOS | PAD_CTL_100K_PU)
141 
142 static int usbotg_init(struct platform_device *pdev)
143 {
144  int err;
145 
158 
159  /* Chip already enabled by hardware */
160  /* OTG phy reset*/
161  err = gpio_request(OTG_RESET, "USB-OTG-RESET");
162  if (err) {
163  pr_err("Failed to request the usb otg reset gpio\n");
164  return err;
165  }
166 
167  err = gpio_direction_output(OTG_RESET, 1/*HIGH*/);
168  if (err) {
169  pr_err("Failed to reset the usb otg phy\n");
170  goto otg_free_reset;
171  }
172 
173  gpio_set_value(OTG_RESET, 0/*LOW*/);
174  mdelay(5);
175  gpio_set_value(OTG_RESET, 1/*HIGH*/);
176  mdelay(10);
177 
180 
181 otg_free_reset:
183  return err;
184 }
185 
186 static int usbh2_init(struct platform_device *pdev)
187 {
188  int err;
189 
202 
204 
205 
206  /* Enable the chip */
207  err = gpio_request(USBH2_CS, "USB-H2-CS");
208  if (err) {
209  pr_err("Failed to request the usb host 2 CS gpio\n");
210  return err;
211  }
212 
213  err = gpio_direction_output(USBH2_CS, 0/*Enabled*/);
214  if (err) {
215  pr_err("Failed to drive the usb host 2 CS gpio\n");
216  goto h2_free_cs;
217  }
218 
219  /* H2 phy reset*/
220  err = gpio_request(USBH2_RESET, "USB-H2-RESET");
221  if (err) {
222  pr_err("Failed to request the usb host 2 reset gpio\n");
223  goto h2_free_cs;
224  }
225 
226  err = gpio_direction_output(USBH2_RESET, 1/*HIGH*/);
227  if (err) {
228  pr_err("Failed to reset the usb host 2 phy\n");
229  goto h2_free_reset;
230  }
231 
232  gpio_set_value(USBH2_RESET, 0/*LOW*/);
233  mdelay(5);
234  gpio_set_value(USBH2_RESET, 1/*HIGH*/);
235  mdelay(10);
236 
239 
240 h2_free_reset:
242 h2_free_cs:
244  return err;
245 }
246 
247 static struct mxc_usbh_platform_data usbotg_pdata __initdata = {
248  .init = usbotg_init,
250 };
251 
252 static struct mxc_usbh_platform_data usbh2_pdata __initdata = {
253  .init = usbh2_init,
255 };
256 
257 /* RTC over I2C*/
258 #define ARMADILLO5X0_RTC_GPIO IOMUX_TO_GPIO(MX31_PIN_SRXD4)
259 
260 static struct i2c_board_info armadillo5x0_i2c_rtc = {
261  I2C_BOARD_INFO("s35390a", 0x30),
262 };
263 
264 /* GPIO BUTTONS */
265 static struct gpio_keys_button armadillo5x0_buttons[] = {
266  {
267  .code = KEY_ENTER, /*28*/
268  .gpio = IOMUX_TO_GPIO(MX31_PIN_SCLK0),
269  .active_low = 1,
270  .desc = "menu",
271  .wakeup = 1,
272  }, {
273  .code = KEY_BACK, /*158*/
274  .gpio = IOMUX_TO_GPIO(MX31_PIN_SRST0),
275  .active_low = 1,
276  .desc = "back",
277  .wakeup = 1,
278  }
279 };
280 
281 static const struct gpio_keys_platform_data
282  armadillo5x0_button_data __initconst = {
283  .buttons = armadillo5x0_buttons,
284  .nbuttons = ARRAY_SIZE(armadillo5x0_buttons),
285 };
286 
287 /*
288  * NAND Flash
289  */
290 static const struct mxc_nand_platform_data
291 armadillo5x0_nand_board_info __initconst = {
292  .width = 1,
293  .hw_ecc = 1,
294 };
295 
296 /*
297  * MTD NOR Flash
298  */
299 static struct mtd_partition armadillo5x0_nor_flash_partitions[] = {
300  {
301  .name = "nor.bootloader",
302  .offset = 0x00000000,
303  .size = 4*32*1024,
304  }, {
305  .name = "nor.kernel",
306  .offset = MTDPART_OFS_APPEND,
307  .size = 16*128*1024,
308  }, {
309  .name = "nor.userland",
310  .offset = MTDPART_OFS_APPEND,
311  .size = 110*128*1024,
312  }, {
313  .name = "nor.config",
314  .offset = MTDPART_OFS_APPEND,
315  .size = 1*128*1024,
316  },
317 };
318 
319 static const struct physmap_flash_data
320  armadillo5x0_nor_flash_pdata __initconst = {
321  .width = 2,
322  .parts = armadillo5x0_nor_flash_partitions,
323  .nr_parts = ARRAY_SIZE(armadillo5x0_nor_flash_partitions),
324 };
325 
326 static const struct resource armadillo5x0_nor_flash_resource __initconst = {
327  .flags = IORESOURCE_MEM,
328  .start = MX31_CS0_BASE_ADDR,
329  .end = MX31_CS0_BASE_ADDR + SZ_64M - 1,
330 };
331 
332 /*
333  * FB support
334  */
335 static const struct fb_videomode fb_modedb[] = {
336  { /* 640x480 @ 60 Hz */
337  .name = "CRT-VGA",
338  .refresh = 60,
339  .xres = 640,
340  .yres = 480,
341  .pixclock = 39721,
342  .left_margin = 35,
343  .right_margin = 115,
344  .upper_margin = 43,
345  .lower_margin = 1,
346  .hsync_len = 10,
347  .vsync_len = 1,
348  .sync = FB_SYNC_OE_ACT_HIGH,
349  .vmode = FB_VMODE_NONINTERLACED,
350  .flag = 0,
351  }, {/* 800x600 @ 56 Hz */
352  .name = "CRT-SVGA",
353  .refresh = 56,
354  .xres = 800,
355  .yres = 600,
356  .pixclock = 30000,
357  .left_margin = 30,
358  .right_margin = 108,
359  .upper_margin = 13,
360  .lower_margin = 10,
361  .hsync_len = 10,
362  .vsync_len = 1,
365  .vmode = FB_VMODE_NONINTERLACED,
366  .flag = 0,
367  },
368 };
369 
370 static struct mx3fb_platform_data mx3fb_pdata __initdata = {
371  .name = "CRT-VGA",
372  .mode = fb_modedb,
373  .num_modes = ARRAY_SIZE(fb_modedb),
374 };
375 
376 /*
377  * SDHC 1
378  * MMC support
379  */
380 static int armadillo5x0_sdhc1_get_ro(struct device *dev)
381 {
383 }
384 
385 static int armadillo5x0_sdhc1_init(struct device *dev,
386  irq_handler_t detect_irq, void *data)
387 {
388  int ret;
389  int gpio_det, gpio_wp;
390 
391  gpio_det = IOMUX_TO_GPIO(MX31_PIN_ATA_DMACK);
393 
394  ret = gpio_request(gpio_det, "sdhc-card-detect");
395  if (ret)
396  return ret;
397 
398  gpio_direction_input(gpio_det);
399 
400  ret = gpio_request(gpio_wp, "sdhc-write-protect");
401  if (ret)
402  goto err_gpio_free;
403 
404  gpio_direction_input(gpio_wp);
405 
406  /* When supported the trigger type have to be BOTH */
408  detect_irq,
410  "sdhc-detect", data);
411 
412  if (ret)
413  goto err_gpio_free_2;
414 
415  return 0;
416 
417 err_gpio_free_2:
418  gpio_free(gpio_wp);
419 
420 err_gpio_free:
421  gpio_free(gpio_det);
422 
423  return ret;
424 
425 }
426 
427 static void armadillo5x0_sdhc1_exit(struct device *dev, void *data)
428 {
432 }
433 
434 static const struct imxmmc_platform_data sdhc_pdata __initconst = {
435  .get_ro = armadillo5x0_sdhc1_get_ro,
436  .init = armadillo5x0_sdhc1_init,
437  .exit = armadillo5x0_sdhc1_exit,
438 };
439 
440 /*
441  * SMSC 9118
442  * Network support
443  */
444 static struct resource armadillo5x0_smc911x_resources[] = {
445  {
446  .start = MX31_CS3_BASE_ADDR,
447  .end = MX31_CS3_BASE_ADDR + SZ_32M - 1,
448  .flags = IORESOURCE_MEM,
449  }, {
450  /* irq number is run-time assigned */
452  },
453 };
454 
455 static struct smsc911x_platform_config smsc911x_info = {
456  .flags = SMSC911X_USE_16BIT,
457  .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
458  .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
459 };
460 
461 static struct platform_device armadillo5x0_smc911x_device = {
462  .name = "smsc911x",
463  .id = -1,
464  .num_resources = ARRAY_SIZE(armadillo5x0_smc911x_resources),
465  .resource = armadillo5x0_smc911x_resources,
466  .dev = {
467  .platform_data = &smsc911x_info,
468  },
469 };
470 
471 /* UART device data */
472 static const struct imxuart_platform_data uart_pdata __initconst = {
473  .flags = IMXUART_HAVE_RTSCTS,
474 };
475 
476 static struct platform_device *devices[] __initdata = {
477  &armadillo5x0_smc911x_device,
478 };
479 
480 static struct regulator_consumer_supply dummy_supplies[] = {
481  REGULATOR_SUPPLY("vdd33a", "smsc911x"),
482  REGULATOR_SUPPLY("vddvario", "smsc911x"),
483 };
484 
485 /*
486  * Perform board specific initializations
487  */
488 static void __init armadillo5x0_init(void)
489 {
490  imx31_soc_init();
491 
492  mxc_iomux_setup_multiple_pins(armadillo5x0_pins,
493  ARRAY_SIZE(armadillo5x0_pins), "armadillo5x0");
494 
495  regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies));
496 
497  armadillo5x0_smc911x_resources[1].start =
499  armadillo5x0_smc911x_resources[1].end =
501  platform_add_devices(devices, ARRAY_SIZE(devices));
502  imx_add_gpio_keys(&armadillo5x0_button_data);
504 
505  /* Register UART */
506  imx31_add_imx_uart0(&uart_pdata);
507  imx31_add_imx_uart1(&uart_pdata);
508 
509  /* SMSC9118 IRQ pin */
511 
512  /* Register SDHC */
513  imx31_add_mxc_mmc(0, &sdhc_pdata);
514 
515  /* Register FB */
517  imx31_add_mx3_sdc_fb(&mx3fb_pdata);
518 
519  /* Register NOR Flash */
520  platform_device_register_resndata(NULL, "physmap-flash", -1,
521  &armadillo5x0_nor_flash_resource, 1,
522  &armadillo5x0_nor_flash_pdata,
523  sizeof(armadillo5x0_nor_flash_pdata));
524 
525  /* Register NAND Flash */
526  imx31_add_mxc_nand(&armadillo5x0_nand_board_info);
527 
528  /* set NAND page size to 2k if not configured via boot mode pins */
530  (1 << 30), mx3_ccm_base + MXC_CCM_RCSR);
531 
532  /* RTC */
533  /* Get RTC IRQ and register the chip */
534  if (gpio_request(ARMADILLO5X0_RTC_GPIO, "rtc") == 0) {
536  armadillo5x0_i2c_rtc.irq = gpio_to_irq(ARMADILLO5X0_RTC_GPIO);
537  else
539  }
540  if (armadillo5x0_i2c_rtc.irq == 0)
541  pr_warning("armadillo5x0_init: failed to get RTC IRQ\n");
542  i2c_register_board_info(1, &armadillo5x0_i2c_rtc, 1);
543 
544  /* USB */
545 
546  usbotg_pdata.otg = imx_otg_ulpi_create(ULPI_OTG_DRVVBUS |
548  if (usbotg_pdata.otg)
549  imx31_add_mxc_ehci_otg(&usbotg_pdata);
550  usbh2_pdata.otg = imx_otg_ulpi_create(ULPI_OTG_DRVVBUS |
552  if (usbh2_pdata.otg)
553  imx31_add_mxc_ehci_hs(2, &usbh2_pdata);
554 }
555 
556 static void __init armadillo5x0_timer_init(void)
557 {
558  mx31_clocks_init(26000000);
559 }
560 
561 static struct sys_timer armadillo5x0_timer = {
562  .init = armadillo5x0_timer_init,
563 };
564 
565 MACHINE_START(ARMADILLO5X0, "Armadillo-500")
566  /* Maintainer: Alberto Panizzo */
567  .atag_offset = 0x100,
568  .map_io = mx31_map_io,
569  .init_early = imx31_init_early,
570  .init_irq = mx31_init_irq,
571  .handle_irq = imx31_handle_irq,
572  .timer = &armadillo5x0_timer,
573  .init_machine = armadillo5x0_init,
574  .restart = mxc_restart,