Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mach-mx51_babbage.c
Go to the documentation of this file.
1 /*
2  * Copyright 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved.
3  * Copyright (C) 2009-2010 Amit Kucheria <[email protected]>
4  *
5  * The code contained herein is licensed under the GNU General Public
6  * License. You may obtain a copy of the GNU General Public License
7  * Version 2 or later at the following locations:
8  *
9  * http://www.opensource.org/licenses/gpl-license.html
10  * http://www.gnu.org/copyleft/gpl.html
11  */
12 
13 #include <linux/init.h>
14 #include <linux/platform_device.h>
15 #include <linux/i2c.h>
16 #include <linux/gpio.h>
17 #include <linux/delay.h>
18 #include <linux/io.h>
19 #include <linux/input.h>
20 #include <linux/spi/flash.h>
21 #include <linux/spi/spi.h>
22 
23 #include <mach/common.h>
24 #include <mach/hardware.h>
25 #include <mach/iomux-mx51.h>
26 
27 #include <asm/setup.h>
28 #include <asm/mach-types.h>
29 #include <asm/mach/arch.h>
30 #include <asm/mach/time.h>
31 
32 #include "devices-imx51.h"
33 #include "cpu_op-mx51.h"
34 
35 #define BABBAGE_USB_HUB_RESET IMX_GPIO_NR(1, 7)
36 #define BABBAGE_USBH1_STP IMX_GPIO_NR(1, 27)
37 #define BABBAGE_USB_PHY_RESET IMX_GPIO_NR(2, 5)
38 #define BABBAGE_FEC_PHY_RESET IMX_GPIO_NR(2, 14)
39 #define BABBAGE_POWER_KEY IMX_GPIO_NR(2, 21)
40 #define BABBAGE_ECSPI1_CS0 IMX_GPIO_NR(4, 24)
41 #define BABBAGE_ECSPI1_CS1 IMX_GPIO_NR(4, 25)
42 #define BABBAGE_SD2_CD IMX_GPIO_NR(1, 6)
43 #define BABBAGE_SD2_WP IMX_GPIO_NR(1, 5)
44 
45 /* USB_CTRL_1 */
46 #define MX51_USB_CTRL_1_OFFSET 0x10
47 #define MX51_USB_CTRL_UH1_EXT_CLK_EN (1 << 25)
48 
49 #define MX51_USB_PLLDIV_12_MHZ 0x00
50 #define MX51_USB_PLL_DIV_19_2_MHZ 0x01
51 #define MX51_USB_PLL_DIV_24_MHZ 0x02
52 
53 static struct gpio_keys_button babbage_buttons[] = {
54  {
55  .gpio = BABBAGE_POWER_KEY,
56  .code = BTN_0,
57  .desc = "PWR",
58  .active_low = 1,
59  .wakeup = 1,
60  },
61 };
62 
63 static const struct gpio_keys_platform_data imx_button_data __initconst = {
64  .buttons = babbage_buttons,
65  .nbuttons = ARRAY_SIZE(babbage_buttons),
66 };
67 
68 static iomux_v3_cfg_t mx51babbage_pads[] = {
69  /* UART1 */
74 
75  /* UART2 */
78 
79  /* UART3 */
84 
85  /* I2C1 */
88 
89  /* I2C2 */
92 
93  /* HSI2C */
96 
97  /* USB HOST1 */
109 
110  /* USB HUB reset line*/
112 
113  /* USB PHY reset line */
115 
116  /* FEC */
134 
135  /* FEC PHY reset line */
137 
138  /* SD 1 */
145  /* CD/WP from controller */
148 
149  /* SD 2 */
156  /* CD/WP gpio */
159 
160  /* eCSPI1 */
166 
167  /* Audio */
172 };
173 
174 /* Serial ports */
175 static const struct imxuart_platform_data uart_pdata __initconst = {
176  .flags = IMXUART_HAVE_RTSCTS,
177 };
178 
179 static const struct imxi2c_platform_data babbage_i2c_data __initconst = {
180  .bitrate = 100000,
181 };
182 
183 static const struct imxi2c_platform_data babbage_hsi2c_data __initconst = {
184  .bitrate = 400000,
185 };
186 
187 static struct gpio mx51_babbage_usbh1_gpios[] = {
188  { BABBAGE_USBH1_STP, GPIOF_OUT_INIT_LOW, "usbh1_stp" },
189  { BABBAGE_USB_PHY_RESET, GPIOF_OUT_INIT_LOW, "usbh1_phy_reset" },
190 };
191 
192 static int gpio_usbh1_active(void)
193 {
195  int ret;
196 
197  /* Set USBH1_STP to GPIO and toggle it */
198  mxc_iomux_v3_setup_pad(usbh1stp_gpio);
199  ret = gpio_request_array(mx51_babbage_usbh1_gpios,
200  ARRAY_SIZE(mx51_babbage_usbh1_gpios));
201 
202  if (ret) {
203  pr_debug("failed to get USBH1 pins: %d\n", ret);
204  return ret;
205  }
206 
207  msleep(100);
210  gpio_free_array(mx51_babbage_usbh1_gpios,
211  ARRAY_SIZE(mx51_babbage_usbh1_gpios));
212  return 0;
213 }
214 
215 static inline void babbage_usbhub_reset(void)
216 {
217  int ret;
218 
219  /* Reset USB hub */
221  GPIOF_OUT_INIT_LOW, "GPIO1_7");
222  if (ret) {
223  printk(KERN_ERR"failed to get GPIO_USB_HUB_RESET: %d\n", ret);
224  return;
225  }
226 
227  msleep(2);
228  /* Deassert reset */
230 }
231 
232 static inline void babbage_fec_reset(void)
233 {
234  int ret;
235 
236  /* reset FEC PHY */
238  GPIOF_OUT_INIT_LOW, "fec-phy-reset");
239  if (ret) {
240  printk(KERN_ERR"failed to get GPIO_FEC_PHY_RESET: %d\n", ret);
241  return;
242  }
243  msleep(1);
245 }
246 
247 /* This function is board specific as the bit mask for the plldiv will also
248 be different for other Freescale SoCs, thus a common bitmask is not
249 possible and cannot get place in /plat-mxc/ehci.c.*/
250 static int initialize_otg_port(struct platform_device *pdev)
251 {
252  u32 v;
253  void __iomem *usb_base;
254  void __iomem *usbother_base;
255 
256  usb_base = ioremap(MX51_USB_OTG_BASE_ADDR, SZ_4K);
257  if (!usb_base)
258  return -ENOMEM;
259  usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
260 
261  /* Set the PHY clock to 19.2MHz */
262  v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
265  __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
266  iounmap(usb_base);
267 
268  mdelay(10);
269 
271 }
272 
273 static int initialize_usbh1_port(struct platform_device *pdev)
274 {
275  u32 v;
276  void __iomem *usb_base;
277  void __iomem *usbother_base;
278 
279  usb_base = ioremap(MX51_USB_OTG_BASE_ADDR, SZ_4K);
280  if (!usb_base)
281  return -ENOMEM;
282  usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
283 
284  /* The clock for the USBH1 ULPI port will come externally from the PHY. */
285  v = __raw_readl(usbother_base + MX51_USB_CTRL_1_OFFSET);
287  iounmap(usb_base);
288 
289  mdelay(10);
290 
293 }
294 
295 static const struct mxc_usbh_platform_data dr_utmi_config __initconst = {
296  .init = initialize_otg_port,
297  .portsc = MXC_EHCI_UTMI_16BIT,
298 };
299 
300 static const struct fsl_usb2_platform_data usb_pdata __initconst = {
301  .operating_mode = FSL_USB2_DR_DEVICE,
302  .phy_mode = FSL_USB2_PHY_UTMI_WIDE,
303 };
304 
305 static const struct mxc_usbh_platform_data usbh1_config __initconst = {
306  .init = initialize_usbh1_port,
307  .portsc = MXC_EHCI_MODE_ULPI,
308 };
309 
310 static bool otg_mode_host __initdata;
311 
312 static int __init babbage_otg_mode(char *options)
313 {
314  if (!strcmp(options, "host"))
315  otg_mode_host = true;
316  else if (!strcmp(options, "device"))
317  otg_mode_host = false;
318  else
319  pr_info("otg_mode neither \"host\" nor \"device\". "
320  "Defaulting to device\n");
321  return 1;
322 }
323 __setup("otg_mode=", babbage_otg_mode);
324 
325 static struct spi_board_info mx51_babbage_spi_board_info[] __initdata = {
326  {
327  .modalias = "mtd_dataflash",
328  .max_speed_hz = 25000000,
329  .bus_num = 0,
330  .chip_select = 1,
331  .mode = SPI_MODE_0,
332  .platform_data = NULL,
333  },
334 };
335 
336 static int mx51_babbage_spi_cs[] = {
339 };
340 
341 static const struct spi_imx_master mx51_babbage_spi_pdata __initconst = {
342  .chipselect = mx51_babbage_spi_cs,
343  .num_chipselect = ARRAY_SIZE(mx51_babbage_spi_cs),
344 };
345 
346 static const struct esdhc_platform_data mx51_babbage_sd1_data __initconst = {
347  .cd_type = ESDHC_CD_CONTROLLER,
348  .wp_type = ESDHC_WP_CONTROLLER,
349 };
350 
351 static const struct esdhc_platform_data mx51_babbage_sd2_data __initconst = {
353  .wp_gpio = BABBAGE_SD2_WP,
354  .cd_type = ESDHC_CD_GPIO,
355  .wp_type = ESDHC_WP_GPIO,
356 };
357 
359 {
360  mxc_iomux_v3_setup_multiple_pads(mx51babbage_pads,
361  ARRAY_SIZE(mx51babbage_pads));
362 }
363 
364 /*
365  * Board specific initialization.
366  */
367 static void __init mx51_babbage_init(void)
368 {
372 
373  imx51_soc_init();
374 
375 #if defined(CONFIG_CPU_FREQ_IMX)
377 #endif
379 
380  imx51_add_imx_uart(0, &uart_pdata);
382  imx51_add_imx_uart(2, &uart_pdata);
383 
384  babbage_fec_reset();
386 
387  /* Set the PAD settings for the pwr key. */
388  mxc_iomux_v3_setup_pad(power_key);
389  imx_add_gpio_keys(&imx_button_data);
390 
391  imx51_add_imx_i2c(0, &babbage_i2c_data);
392  imx51_add_imx_i2c(1, &babbage_i2c_data);
393  imx51_add_hsi2c(&babbage_hsi2c_data);
394 
395  if (otg_mode_host)
396  imx51_add_mxc_ehci_otg(&dr_utmi_config);
397  else {
398  initialize_otg_port(NULL);
399  imx51_add_fsl_usb2_udc(&usb_pdata);
400  }
401 
402  gpio_usbh1_active();
403  imx51_add_mxc_ehci_hs(1, &usbh1_config);
404  /* setback USBH1_STP to be function */
405  mxc_iomux_v3_setup_pad(usbh1stp);
406  babbage_usbhub_reset();
407 
408  imx51_add_sdhci_esdhc_imx(0, &mx51_babbage_sd1_data);
409  imx51_add_sdhci_esdhc_imx(1, &mx51_babbage_sd2_data);
410 
411  spi_register_board_info(mx51_babbage_spi_board_info,
412  ARRAY_SIZE(mx51_babbage_spi_board_info));
413  imx51_add_ecspi(0, &mx51_babbage_spi_pdata);
415 }
416 
417 static void __init mx51_babbage_timer_init(void)
418 {
419  mx51_clocks_init(32768, 24000000, 22579200, 0);
420 }
421 
422 static struct sys_timer mx51_babbage_timer = {
423  .init = mx51_babbage_timer_init,
424 };
425 
426 MACHINE_START(MX51_BABBAGE, "Freescale MX51 Babbage Board")
427  /* Maintainer: Amit Kucheria <[email protected]> */
428  .atag_offset = 0x100,
429  .map_io = mx51_map_io,
430  .init_early = imx51_init_early,
431  .init_irq = mx51_init_irq,
432  .handle_irq = imx51_handle_irq,
433  .timer = &mx51_babbage_timer,
434  .init_machine = mx51_babbage_init,
435  .init_late = imx51_init_late,
436  .restart = mxc_restart,