]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/genesi/mx51_efikamx/efikamx-usb.c
Merge branch 'master' of git://git.denx.de/u-boot-video
[karo-tx-uboot.git] / board / genesi / mx51_efikamx / efikamx-usb.c
1 /*
2  * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
3  *
4  * (C) Copyright 2009 Freescale Semiconductor, Inc.
5  *
6  * See file CREDITS for list of people who contributed to this
7  * project.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of
12  * the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22  * MA 02111-1307 USA
23  */
24
25 #include <common.h>
26 #include <usb.h>
27 #include <asm/io.h>
28 #include <asm/arch/imx-regs.h>
29 #include <asm/arch/iomux-mx51.h>
30 #include <asm/gpio.h>
31 #include <usb/ehci-fsl.h>
32 #include <usb/ulpi.h>
33 #include <errno.h>
34
35 #include "../../../drivers/usb/host/ehci.h"
36
37 /*
38  * Configure the USB H1 and USB H2 IOMUX
39  */
40 void setup_iomux_usb(void)
41 {
42         static const iomux_v3_cfg_t usb_h1_pads[] = {
43                 MX51_PAD_USBH1_CLK__USBH1_CLK,
44                 MX51_PAD_USBH1_DIR__USBH1_DIR,
45                 MX51_PAD_USBH1_STP__USBH1_STP,
46                 MX51_PAD_USBH1_NXT__USBH1_NXT,
47                 MX51_PAD_USBH1_DATA0__USBH1_DATA0,
48                 MX51_PAD_USBH1_DATA1__USBH1_DATA1,
49                 MX51_PAD_USBH1_DATA2__USBH1_DATA2,
50                 MX51_PAD_USBH1_DATA3__USBH1_DATA3,
51                 MX51_PAD_USBH1_DATA4__USBH1_DATA4,
52                 MX51_PAD_USBH1_DATA5__USBH1_DATA5,
53                 MX51_PAD_USBH1_DATA6__USBH1_DATA6,
54                 MX51_PAD_USBH1_DATA7__USBH1_DATA7,
55         };
56
57         static const iomux_v3_cfg_t usb_pads[] = {
58                 MX51_PAD_EIM_D27__GPIO2_9, /* USB PHY reset */
59                 MX51_PAD_GPIO1_5__GPIO1_5, /* USB HUB reset */
60                 NEW_PAD_CTRL(MX51_PAD_EIM_A22__GPIO2_16, 0), /* WIFI /EN */
61                 NEW_PAD_CTRL(MX51_PAD_EIM_A16__GPIO2_10, 0), /* WIFI RESET */
62                 NEW_PAD_CTRL(MX51_PAD_EIM_A17__GPIO2_11, 0), /* BT /EN */
63         };
64
65         imx_iomux_v3_setup_multiple_pads(usb_h1_pads, ARRAY_SIZE(usb_h1_pads));
66
67         if (machine_is_efikasb()) {
68                 static const iomux_v3_cfg_t usb_h2_pads[] = {
69                         MX51_PAD_EIM_A24__USBH2_CLK,
70                         MX51_PAD_EIM_A25__USBH2_DIR,
71                         MX51_PAD_EIM_A26__USBH2_STP,
72                         MX51_PAD_EIM_A27__USBH2_NXT,
73                         MX51_PAD_EIM_D16__USBH2_DATA0,
74                         MX51_PAD_EIM_D17__USBH2_DATA1,
75                         MX51_PAD_EIM_D18__USBH2_DATA2,
76                         MX51_PAD_EIM_D19__USBH2_DATA3,
77                         MX51_PAD_EIM_D20__USBH2_DATA4,
78                         MX51_PAD_EIM_D21__USBH2_DATA5,
79                         MX51_PAD_EIM_D22__USBH2_DATA6,
80                         MX51_PAD_EIM_D23__USBH2_DATA7,
81                 };
82
83                 imx_iomux_v3_setup_multiple_pads(usb_h2_pads,
84                                                  ARRAY_SIZE(usb_h2_pads));
85         }
86
87         imx_iomux_v3_setup_multiple_pads(usb_pads, ARRAY_SIZE(usb_pads));
88 }
89
90 /*
91  * Enable devices connected to USB BUSes
92  */
93 static void efika_usb_enable_devices(void)
94 {
95         /* Enable Bluetooth */
96         gpio_direction_output(IMX_GPIO_NR(2, 11), 0);
97         udelay(10000);
98         gpio_set_value(IMX_GPIO_NR(2, 11), 1);
99
100         /* Enable WiFi */
101         gpio_direction_output(IMX_GPIO_NR(2, 16), 1);
102         udelay(10000);
103
104         /* Reset the WiFi chip */
105         gpio_direction_output(IMX_GPIO_NR(2, 10), 0);
106         udelay(10000);
107         gpio_set_value(IMX_GPIO_NR(2, 10), 1);
108 }
109
110 /*
111  * Reset USB HUB (or HUBs on EfikaSB)
112  */
113 static void efika_usb_hub_reset(void)
114 {
115         /* HUB reset */
116         gpio_direction_output(IMX_GPIO_NR(1, 5), 1);
117         udelay(1000);
118         gpio_set_value(IMX_GPIO_NR(1, 5), 0);
119         udelay(1000);
120         gpio_set_value(IMX_GPIO_NR(1, 5), 1);
121 }
122
123 /*
124  * Reset USB PHY (or PHYs on EfikaSB)
125  */
126 static void efika_usb_phy_reset(void)
127 {
128         /* SMSC 3317 PHY reset */
129         gpio_direction_output(IMX_GPIO_NR(2, 9), 0);
130         udelay(1000);
131         gpio_set_value(IMX_GPIO_NR(2, 9), 1);
132 }
133
134 static void efika_ehci_init(struct usb_ehci *ehci, uint32_t stp_gpio,
135                                 iomux_v3_cfg_t stp_pad_gpio,
136                                 iomux_v3_cfg_t stp_pad_usb)
137 {
138         int ret;
139         struct ulpi_regs *ulpi = (struct ulpi_regs *)0;
140         struct ulpi_viewport ulpi_vp;
141
142         imx_iomux_v3_setup_pad(stp_pad_gpio);
143         gpio_direction_output(stp_gpio, 0);
144         udelay(1000);
145         gpio_set_value(stp_gpio, 1);
146         udelay(1000);
147
148         imx_iomux_v3_setup_pad(stp_pad_usb);
149         udelay(10000);
150
151         ulpi_vp.viewport_addr = (u32)&ehci->ulpi_viewpoint;
152         ulpi_vp.port_num = 0;
153
154         ret = ulpi_init(&ulpi_vp);
155         if (ret) {
156                 printf("Efika USB ULPI initialization failed\n");
157                 return;
158         }
159
160         /* ULPI set flags */
161         ulpi_write(&ulpi_vp, &ulpi->otg_ctrl,
162                         ULPI_OTG_DP_PULLDOWN | ULPI_OTG_DM_PULLDOWN |
163                         ULPI_OTG_EXTVBUSIND);
164         ulpi_write(&ulpi_vp, &ulpi->function_ctrl,
165                         ULPI_FC_FULL_SPEED | ULPI_FC_OPMODE_NORMAL |
166                         ULPI_FC_SUSPENDM);
167         ulpi_write(&ulpi_vp, &ulpi->iface_ctrl, 0);
168
169         /* Set VBus */
170         ulpi_write(&ulpi_vp, &ulpi->otg_ctrl_set,
171                         ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT);
172
173         /*
174          * Set VBusChrg
175          *
176          * NOTE: This violates USB specification, but otherwise, USB on Efika
177          * doesn't work.
178          */
179         ulpi_write(&ulpi_vp, &ulpi->otg_ctrl_set, ULPI_OTG_CHRGVBUS);
180 }
181
182 int board_ehci_hcd_init(int port)
183 {
184         /* Init iMX51 EHCI */
185         efika_usb_phy_reset();
186         efika_usb_hub_reset();
187         efika_usb_enable_devices();
188
189         return 0;
190 }
191
192 void ehci_powerup_fixup(uint32_t *status_reg, uint32_t *reg)
193 {
194         uint32_t port = OTG_BASE_ADDR + (0x200 * CONFIG_MXC_USB_PORT);
195         struct usb_ehci *ehci = (struct usb_ehci *)port;
196         struct ulpi_regs *ulpi = (struct ulpi_regs *)0;
197         struct ulpi_viewport ulpi_vp;
198
199         ulpi_vp.viewport_addr = (u32)&ehci->ulpi_viewpoint;
200         ulpi_vp.port_num = 0;
201
202         ulpi_write(&ulpi_vp, &ulpi->otg_ctrl_set, ULPI_OTG_CHRGVBUS);
203
204         mdelay(50);
205
206         /* terminate the reset */
207         *reg = ehci_readl(status_reg);
208         *reg |= EHCI_PS_PE;
209 }
210
211 void board_ehci_hcd_postinit(struct usb_ehci *ehci, int port)
212 {
213         uint32_t tmp;
214
215         if (port == 0) {
216                 /* Adjust UTMI PHY frequency to 24MHz */
217                 tmp = readl(OTG_BASE_ADDR + 0x80c);
218                 tmp = (tmp & ~0x3) | 0x01;
219                 writel(tmp, OTG_BASE_ADDR + 0x80c);
220         } else if (port == 1) {
221                 efika_ehci_init(ehci, IMX_GPIO_NR(1, 27),
222                                 MX51_PAD_USBH1_STP__GPIO1_27,
223                                 MX51_PAD_USBH1_STP__USBH1_STP);
224         } else if ((port == 2) && machine_is_efikasb()) {
225                 efika_ehci_init(ehci, IMX_GPIO_NR(2, 20),
226                                 MX51_PAD_EIM_A26__GPIO2_20,
227                                 MX51_PAD_EIM_A26__USBH2_STP);
228         }
229
230         if (port)
231                 mdelay(10);
232 }
233
234 /*
235  * Ethernet on the Smarttop is on the USB bus. Rather than give an error about
236  * "CPU Net Initialization Failed", just pass this test since no other settings
237  * are required. Smartbook doesn't have built-in Ethernet but we will let it
238  * pass anyway considering someone may have plugged in a USB stick and all
239  * they need to do is run "usb start".
240  */
241 int board_eth_init(bd_t *bis)
242 {
243         return 0;
244 }