blob: f3570884883e574df243384475c2fd66b68906ee [file] [log] [blame]
Tony Lindgrenf35ae632008-07-03 12:24:43 +03001 /*
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01002 * arch/arm/plat-omap/usb.c -- platform level USB initialization
3 *
4 * Copyright (C) 2004 Texas Instruments, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#undef DEBUG
22
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010023#include <linux/module.h>
24#include <linux/kernel.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010025#include <linux/init.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010026#include <linux/platform_device.h>
Russell Kingfced80c2008-09-06 12:10:45 +010027#include <linux/io.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010028
Tony Lindgrence491cf2009-10-20 09:40:47 -070029#include <plat/usb.h>
30#include <plat/board.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010031
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010032#ifdef CONFIG_ARCH_OMAP_OTG
33
34void __init
35omap_otg_init(struct omap_usb_config *config)
36{
Tony Lindgrenf35ae632008-07-03 12:24:43 +030037 u32 syscon;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010038 int status;
39 int alt_pingroup = 0;
40
41 /* NOTE: no bus or clock setup (yet?) */
42
Tony Lindgrenf35ae632008-07-03 12:24:43 +030043 syscon = omap_readl(OTG_SYSCON_1) & 0xffff;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010044 if (!(syscon & OTG_RESET_DONE))
45 pr_debug("USB resets not complete?\n");
46
Tony Lindgrenf35ae632008-07-03 12:24:43 +030047 //omap_writew(0, OTG_IRQ_EN);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010048
49 /* pin muxing and transceiver pinouts */
50 if (config->pins[0] > 2) /* alt pingroup 2 */
51 alt_pingroup = 1;
Tony Lindgrenb5e89052010-07-05 16:31:29 +030052 syscon |= config->usb0_init(config->pins[0], is_usb0_device(config));
53 syscon |= config->usb1_init(config->pins[1]);
54 syscon |= config->usb2_init(config->pins[2], alt_pingroup);
Tony Lindgrenf35ae632008-07-03 12:24:43 +030055 pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
56 omap_writel(syscon, OTG_SYSCON_1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010057
58 syscon = config->hmc_mode;
59 syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
60#ifdef CONFIG_USB_OTG
61 if (config->otg)
62 syscon |= OTG_EN;
63#endif
Tony Lindgrenc40fae952006-12-07 13:58:10 -080064 if (cpu_class_is_omap1())
Tony Lindgrenf35ae632008-07-03 12:24:43 +030065 pr_debug("USB_TRANSCEIVER_CTRL = %03x\n",
66 omap_readl(USB_TRANSCEIVER_CTRL));
67 pr_debug("OTG_SYSCON_2 = %08x\n", omap_readl(OTG_SYSCON_2));
68 omap_writel(syscon, OTG_SYSCON_2);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010069
70 printk("USB: hmc %d", config->hmc_mode);
Tony Lindgrenc40fae952006-12-07 13:58:10 -080071 if (!alt_pingroup)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010072 printk(", usb2 alt %d wires", config->pins[2]);
73 else if (config->pins[0])
74 printk(", usb0 %d wires%s", config->pins[0],
75 is_usb0_device(config) ? " (dev)" : "");
76 if (config->pins[1])
77 printk(", usb1 %d wires", config->pins[1]);
78 if (!alt_pingroup && config->pins[2])
79 printk(", usb2 %d wires", config->pins[2]);
80 if (config->otg)
81 printk(", Mini-AB on usb%d", config->otg - 1);
82 printk("\n");
83
Tony Lindgrenc40fae952006-12-07 13:58:10 -080084 if (cpu_class_is_omap1()) {
Tony Lindgrenf35ae632008-07-03 12:24:43 +030085 u16 w;
86
Tony Lindgrenc40fae952006-12-07 13:58:10 -080087 /* leave USB clocks/controllers off until needed */
Tony Lindgrenf35ae632008-07-03 12:24:43 +030088 w = omap_readw(ULPD_SOFT_REQ);
89 w &= ~SOFT_USB_CLK_REQ;
90 omap_writew(w, ULPD_SOFT_REQ);
91
92 w = omap_readw(ULPD_CLOCK_CTRL);
93 w &= ~USB_MCLK_EN;
94 w |= DIS_USB_PVCI_CLK;
95 omap_writew(w, ULPD_CLOCK_CTRL);
Tony Lindgrenc40fae952006-12-07 13:58:10 -080096 }
Tony Lindgrenf35ae632008-07-03 12:24:43 +030097 syscon = omap_readl(OTG_SYSCON_1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010098 syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
99
100#ifdef CONFIG_USB_GADGET_OMAP
101 if (config->otg || config->register_dev) {
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300102 struct platform_device *udc_device = config->udc_device;
103
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100104 syscon &= ~DEV_IDLE_EN;
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300105 udc_device->dev.platform_data = config;
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300106 status = platform_device_register(udc_device);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100107 if (status)
108 pr_debug("can't register UDC device, %d\n", status);
109 }
110#endif
111
112#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
113 if (config->otg || config->register_host) {
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300114 struct platform_device *ohci_device = config->ohci_device;
115
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100116 syscon &= ~HST_IDLE_EN;
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300117 ohci_device->dev.platform_data = config;
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300118 status = platform_device_register(ohci_device);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100119 if (status)
120 pr_debug("can't register OHCI device, %d\n", status);
121 }
122#endif
123
124#ifdef CONFIG_USB_OTG
125 if (config->otg) {
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300126 struct platform_device *otg_device = config->otg_device;
127
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100128 syscon &= ~OTG_IDLE_EN;
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300129 otg_device->dev.platform_data = config;
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300130 status = platform_device_register(otg_device);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100131 if (status)
132 pr_debug("can't register OTG device, %d\n", status);
133 }
134#endif
Tony Lindgrenf35ae632008-07-03 12:24:43 +0300135 pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
136 omap_writel(syscon, OTG_SYSCON_1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100137
138 status = 0;
139}
140
141#else
Tony Lindgrenb5e89052010-07-05 16:31:29 +0300142void omap_otg_init(struct omap_usb_config *config) {}
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100143#endif