Merge branch 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jlbec...
[pandora-kernel.git] / arch / arm / mach-mx5 / board-mx51_babbage.c
1 /*
2  * Copyright 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved.
3  * Copyright (C) 2009-2010 Amit Kucheria <amit.kucheria@canonical.com>
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/fsl_devices.h>
20 #include <linux/fec.h>
21 #include <linux/gpio_keys.h>
22 #include <linux/input.h>
23 #include <linux/spi/flash.h>
24 #include <linux/spi/spi.h>
25
26 #include <mach/common.h>
27 #include <mach/hardware.h>
28 #include <mach/iomux-mx51.h>
29 #include <mach/mxc_ehci.h>
30
31 #include <asm/irq.h>
32 #include <asm/setup.h>
33 #include <asm/mach-types.h>
34 #include <asm/mach/arch.h>
35 #include <asm/mach/time.h>
36
37 #include "devices-imx51.h"
38 #include "devices.h"
39 #include "cpu_op-mx51.h"
40
41 #define BABBAGE_USB_HUB_RESET   IMX_GPIO_NR(1, 7)
42 #define BABBAGE_USBH1_STP       IMX_GPIO_NR(1, 27)
43 #define BABBAGE_PHY_RESET       IMX_GPIO_NR(2, 5)
44 #define BABBAGE_FEC_PHY_RESET   IMX_GPIO_NR(2, 14)
45 #define BABBAGE_POWER_KEY       IMX_GPIO_NR(2, 21)
46 #define BABBAGE_ECSPI1_CS0      IMX_GPIO_NR(4, 24)
47 #define BABBAGE_ECSPI1_CS1      IMX_GPIO_NR(4, 25)
48
49 /* USB_CTRL_1 */
50 #define MX51_USB_CTRL_1_OFFSET                  0x10
51 #define MX51_USB_CTRL_UH1_EXT_CLK_EN            (1 << 25)
52
53 #define MX51_USB_PLLDIV_12_MHZ          0x00
54 #define MX51_USB_PLL_DIV_19_2_MHZ       0x01
55 #define MX51_USB_PLL_DIV_24_MHZ 0x02
56
57 static struct gpio_keys_button babbage_buttons[] = {
58         {
59                 .gpio           = BABBAGE_POWER_KEY,
60                 .code           = BTN_0,
61                 .desc           = "PWR",
62                 .active_low     = 1,
63                 .wakeup         = 1,
64         },
65 };
66
67 static const struct gpio_keys_platform_data imx_button_data __initconst = {
68         .buttons        = babbage_buttons,
69         .nbuttons       = ARRAY_SIZE(babbage_buttons),
70 };
71
72 static iomux_v3_cfg_t mx51babbage_pads[] = {
73         /* UART1 */
74         MX51_PAD_UART1_RXD__UART1_RXD,
75         MX51_PAD_UART1_TXD__UART1_TXD,
76         MX51_PAD_UART1_RTS__UART1_RTS,
77         MX51_PAD_UART1_CTS__UART1_CTS,
78
79         /* UART2 */
80         MX51_PAD_UART2_RXD__UART2_RXD,
81         MX51_PAD_UART2_TXD__UART2_TXD,
82
83         /* UART3 */
84         MX51_PAD_EIM_D25__UART3_RXD,
85         MX51_PAD_EIM_D26__UART3_TXD,
86         MX51_PAD_EIM_D27__UART3_RTS,
87         MX51_PAD_EIM_D24__UART3_CTS,
88
89         /* I2C1 */
90         MX51_PAD_EIM_D16__I2C1_SDA,
91         MX51_PAD_EIM_D19__I2C1_SCL,
92
93         /* I2C2 */
94         MX51_PAD_KEY_COL4__I2C2_SCL,
95         MX51_PAD_KEY_COL5__I2C2_SDA,
96
97         /* HSI2C */
98         MX51_PAD_I2C1_CLK__I2C1_CLK,
99         MX51_PAD_I2C1_DAT__I2C1_DAT,
100
101         /* USB HOST1 */
102         MX51_PAD_USBH1_CLK__USBH1_CLK,
103         MX51_PAD_USBH1_DIR__USBH1_DIR,
104         MX51_PAD_USBH1_NXT__USBH1_NXT,
105         MX51_PAD_USBH1_DATA0__USBH1_DATA0,
106         MX51_PAD_USBH1_DATA1__USBH1_DATA1,
107         MX51_PAD_USBH1_DATA2__USBH1_DATA2,
108         MX51_PAD_USBH1_DATA3__USBH1_DATA3,
109         MX51_PAD_USBH1_DATA4__USBH1_DATA4,
110         MX51_PAD_USBH1_DATA5__USBH1_DATA5,
111         MX51_PAD_USBH1_DATA6__USBH1_DATA6,
112         MX51_PAD_USBH1_DATA7__USBH1_DATA7,
113
114         /* USB HUB reset line*/
115         MX51_PAD_GPIO1_7__GPIO1_7,
116
117         /* FEC */
118         MX51_PAD_EIM_EB2__FEC_MDIO,
119         MX51_PAD_EIM_EB3__FEC_RDATA1,
120         MX51_PAD_EIM_CS2__FEC_RDATA2,
121         MX51_PAD_EIM_CS3__FEC_RDATA3,
122         MX51_PAD_EIM_CS4__FEC_RX_ER,
123         MX51_PAD_EIM_CS5__FEC_CRS,
124         MX51_PAD_NANDF_RB2__FEC_COL,
125         MX51_PAD_NANDF_RB3__FEC_RX_CLK,
126         MX51_PAD_NANDF_D9__FEC_RDATA0,
127         MX51_PAD_NANDF_D8__FEC_TDATA0,
128         MX51_PAD_NANDF_CS2__FEC_TX_ER,
129         MX51_PAD_NANDF_CS3__FEC_MDC,
130         MX51_PAD_NANDF_CS4__FEC_TDATA1,
131         MX51_PAD_NANDF_CS5__FEC_TDATA2,
132         MX51_PAD_NANDF_CS6__FEC_TDATA3,
133         MX51_PAD_NANDF_CS7__FEC_TX_EN,
134         MX51_PAD_NANDF_RDY_INT__FEC_TX_CLK,
135
136         /* FEC PHY reset line */
137         MX51_PAD_EIM_A20__GPIO2_14,
138
139         /* SD 1 */
140         MX51_PAD_SD1_CMD__SD1_CMD,
141         MX51_PAD_SD1_CLK__SD1_CLK,
142         MX51_PAD_SD1_DATA0__SD1_DATA0,
143         MX51_PAD_SD1_DATA1__SD1_DATA1,
144         MX51_PAD_SD1_DATA2__SD1_DATA2,
145         MX51_PAD_SD1_DATA3__SD1_DATA3,
146
147         /* SD 2 */
148         MX51_PAD_SD2_CMD__SD2_CMD,
149         MX51_PAD_SD2_CLK__SD2_CLK,
150         MX51_PAD_SD2_DATA0__SD2_DATA0,
151         MX51_PAD_SD2_DATA1__SD2_DATA1,
152         MX51_PAD_SD2_DATA2__SD2_DATA2,
153         MX51_PAD_SD2_DATA3__SD2_DATA3,
154
155         /* eCSPI1 */
156         MX51_PAD_CSPI1_MISO__ECSPI1_MISO,
157         MX51_PAD_CSPI1_MOSI__ECSPI1_MOSI,
158         MX51_PAD_CSPI1_SCLK__ECSPI1_SCLK,
159         MX51_PAD_CSPI1_SS0__GPIO4_24,
160         MX51_PAD_CSPI1_SS1__GPIO4_25,
161 };
162
163 /* Serial ports */
164 #if defined(CONFIG_SERIAL_IMX) || defined(CONFIG_SERIAL_IMX_MODULE)
165 static const struct imxuart_platform_data uart_pdata __initconst = {
166         .flags = IMXUART_HAVE_RTSCTS,
167 };
168
169 static inline void mxc_init_imx_uart(void)
170 {
171         imx51_add_imx_uart(0, &uart_pdata);
172         imx51_add_imx_uart(1, &uart_pdata);
173         imx51_add_imx_uart(2, &uart_pdata);
174 }
175 #else /* !SERIAL_IMX */
176 static inline void mxc_init_imx_uart(void)
177 {
178 }
179 #endif /* SERIAL_IMX */
180
181 static const struct imxi2c_platform_data babbage_i2c_data __initconst = {
182         .bitrate = 100000,
183 };
184
185 static struct imxi2c_platform_data babbage_hsi2c_data = {
186         .bitrate = 400000,
187 };
188
189 static int gpio_usbh1_active(void)
190 {
191         iomux_v3_cfg_t usbh1stp_gpio = MX51_PAD_USBH1_STP__GPIO1_27;
192         iomux_v3_cfg_t phyreset_gpio = MX51_PAD_EIM_D21__GPIO2_5;
193         int ret;
194
195         /* Set USBH1_STP to GPIO and toggle it */
196         mxc_iomux_v3_setup_pad(usbh1stp_gpio);
197         ret = gpio_request(BABBAGE_USBH1_STP, "usbh1_stp");
198
199         if (ret) {
200                 pr_debug("failed to get MX51_PAD_USBH1_STP__GPIO_1_27: %d\n", ret);
201                 return ret;
202         }
203         gpio_direction_output(BABBAGE_USBH1_STP, 0);
204         gpio_set_value(BABBAGE_USBH1_STP, 1);
205         msleep(100);
206         gpio_free(BABBAGE_USBH1_STP);
207
208         /* De-assert USB PHY RESETB */
209         mxc_iomux_v3_setup_pad(phyreset_gpio);
210         ret = gpio_request(BABBAGE_PHY_RESET, "phy_reset");
211
212         if (ret) {
213                 pr_debug("failed to get MX51_PAD_EIM_D21__GPIO_2_5: %d\n", ret);
214                 return ret;
215         }
216         gpio_direction_output(BABBAGE_PHY_RESET, 1);
217         return 0;
218 }
219
220 static inline void babbage_usbhub_reset(void)
221 {
222         int ret;
223
224         /* Bring USB hub out of reset */
225         ret = gpio_request(BABBAGE_USB_HUB_RESET, "GPIO1_7");
226         if (ret) {
227                 printk(KERN_ERR"failed to get GPIO_USB_HUB_RESET: %d\n", ret);
228                 return;
229         }
230         gpio_direction_output(BABBAGE_USB_HUB_RESET, 0);
231
232         /* USB HUB RESET - De-assert USB HUB RESET_N */
233         msleep(1);
234         gpio_set_value(BABBAGE_USB_HUB_RESET, 0);
235         msleep(1);
236         gpio_set_value(BABBAGE_USB_HUB_RESET, 1);
237 }
238
239 static inline void babbage_fec_reset(void)
240 {
241         int ret;
242
243         /* reset FEC PHY */
244         ret = gpio_request(BABBAGE_FEC_PHY_RESET, "fec-phy-reset");
245         if (ret) {
246                 printk(KERN_ERR"failed to get GPIO_FEC_PHY_RESET: %d\n", ret);
247                 return;
248         }
249         gpio_direction_output(BABBAGE_FEC_PHY_RESET, 0);
250         gpio_set_value(BABBAGE_FEC_PHY_RESET, 0);
251         msleep(1);
252         gpio_set_value(BABBAGE_FEC_PHY_RESET, 1);
253 }
254
255 /* This function is board specific as the bit mask for the plldiv will also
256 be different for other Freescale SoCs, thus a common bitmask is not
257 possible and cannot get place in /plat-mxc/ehci.c.*/
258 static int initialize_otg_port(struct platform_device *pdev)
259 {
260         u32 v;
261         void __iomem *usb_base;
262         void __iomem *usbother_base;
263
264         usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K);
265         if (!usb_base)
266                 return -ENOMEM;
267         usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
268
269         /* Set the PHY clock to 19.2MHz */
270         v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
271         v &= ~MX5_USB_UTMI_PHYCTRL1_PLLDIV_MASK;
272         v |= MX51_USB_PLL_DIV_19_2_MHZ;
273         __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
274         iounmap(usb_base);
275         return 0;
276 }
277
278 static int initialize_usbh1_port(struct platform_device *pdev)
279 {
280         u32 v;
281         void __iomem *usb_base;
282         void __iomem *usbother_base;
283
284         usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K);
285         if (!usb_base)
286                 return -ENOMEM;
287         usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
288
289         /* The clock for the USBH1 ULPI port will come externally from the PHY. */
290         v = __raw_readl(usbother_base + MX51_USB_CTRL_1_OFFSET);
291         __raw_writel(v | MX51_USB_CTRL_UH1_EXT_CLK_EN, usbother_base + MX51_USB_CTRL_1_OFFSET);
292         iounmap(usb_base);
293         return 0;
294 }
295
296 static struct mxc_usbh_platform_data dr_utmi_config = {
297         .init           = initialize_otg_port,
298         .portsc = MXC_EHCI_UTMI_16BIT,
299         .flags  = MXC_EHCI_INTERNAL_PHY,
300 };
301
302 static struct fsl_usb2_platform_data usb_pdata = {
303         .operating_mode = FSL_USB2_DR_DEVICE,
304         .phy_mode       = FSL_USB2_PHY_UTMI_WIDE,
305 };
306
307 static struct mxc_usbh_platform_data usbh1_config = {
308         .init           = initialize_usbh1_port,
309         .portsc = MXC_EHCI_MODE_ULPI,
310         .flags  = (MXC_EHCI_POWER_PINS_ENABLED | MXC_EHCI_ITC_NO_THRESHOLD),
311 };
312
313 static int otg_mode_host;
314
315 static int __init babbage_otg_mode(char *options)
316 {
317         if (!strcmp(options, "host"))
318                 otg_mode_host = 1;
319         else if (!strcmp(options, "device"))
320                 otg_mode_host = 0;
321         else
322                 pr_info("otg_mode neither \"host\" nor \"device\". "
323                         "Defaulting to device\n");
324         return 0;
325 }
326 __setup("otg_mode=", babbage_otg_mode);
327
328 static struct spi_board_info mx51_babbage_spi_board_info[] __initdata = {
329         {
330                 .modalias = "mtd_dataflash",
331                 .max_speed_hz = 25000000,
332                 .bus_num = 0,
333                 .chip_select = 1,
334                 .mode = SPI_MODE_0,
335                 .platform_data = NULL,
336         },
337 };
338
339 static int mx51_babbage_spi_cs[] = {
340         BABBAGE_ECSPI1_CS0,
341         BABBAGE_ECSPI1_CS1,
342 };
343
344 static const struct spi_imx_master mx51_babbage_spi_pdata __initconst = {
345         .chipselect     = mx51_babbage_spi_cs,
346         .num_chipselect = ARRAY_SIZE(mx51_babbage_spi_cs),
347 };
348
349 /*
350  * Board specific initialization.
351  */
352 static void __init mxc_board_init(void)
353 {
354         iomux_v3_cfg_t usbh1stp = MX51_PAD_USBH1_STP__USBH1_STP;
355         iomux_v3_cfg_t power_key = _MX51_PAD_EIM_A27__GPIO2_21 |
356                 MUX_PAD_CTRL(PAD_CTL_SRE_FAST | PAD_CTL_DSE_HIGH | PAD_CTL_PUS_100K_UP);
357
358 #if defined(CONFIG_CPU_FREQ_IMX)
359         get_cpu_op = mx51_get_cpu_op;
360 #endif
361         mxc_iomux_v3_setup_multiple_pads(mx51babbage_pads,
362                                         ARRAY_SIZE(mx51babbage_pads));
363         mxc_init_imx_uart();
364         babbage_fec_reset();
365         imx51_add_fec(NULL);
366
367         /* Set the PAD settings for the pwr key. */
368         mxc_iomux_v3_setup_pad(power_key);
369         imx51_add_gpio_keys(&imx_button_data);
370
371         imx51_add_imx_i2c(0, &babbage_i2c_data);
372         imx51_add_imx_i2c(1, &babbage_i2c_data);
373         mxc_register_device(&mxc_hsi2c_device, &babbage_hsi2c_data);
374
375         if (otg_mode_host)
376                 mxc_register_device(&mxc_usbdr_host_device, &dr_utmi_config);
377         else {
378                 initialize_otg_port(NULL);
379                 mxc_register_device(&mxc_usbdr_udc_device, &usb_pdata);
380         }
381
382         gpio_usbh1_active();
383         mxc_register_device(&mxc_usbh1_device, &usbh1_config);
384         /* setback USBH1_STP to be function */
385         mxc_iomux_v3_setup_pad(usbh1stp);
386         babbage_usbhub_reset();
387
388         imx51_add_sdhci_esdhc_imx(0, NULL);
389         imx51_add_sdhci_esdhc_imx(1, NULL);
390
391         spi_register_board_info(mx51_babbage_spi_board_info,
392                 ARRAY_SIZE(mx51_babbage_spi_board_info));
393         imx51_add_ecspi(0, &mx51_babbage_spi_pdata);
394         imx51_add_imx2_wdt(0, NULL);
395 }
396
397 static void __init mx51_babbage_timer_init(void)
398 {
399         mx51_clocks_init(32768, 24000000, 22579200, 0);
400 }
401
402 static struct sys_timer mxc_timer = {
403         .init   = mx51_babbage_timer_init,
404 };
405
406 MACHINE_START(MX51_BABBAGE, "Freescale MX51 Babbage Board")
407         /* Maintainer: Amit Kucheria <amit.kucheria@canonical.com> */
408         .boot_params = MX51_PHYS_OFFSET + 0x100,
409         .map_io = mx51_map_io,
410         .init_irq = mx51_init_irq,
411         .init_machine = mxc_board_init,
412         .timer = &mxc_timer,
413 MACHINE_END