2 * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
3 * Copyright (C) 2010 Freescale Semiconductor, Inc.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include <linux/platform_device.h>
19 #include <mach/hardware.h>
20 #include <mach/mxc_ehci.h>
22 #define MXC_OTG_OFFSET 0
23 #define MXC_H1_OFFSET 0x200
24 #define MXC_H2_OFFSET 0x400
27 #define MXC_OTG_UCTRL_OWIE_BIT (1 << 27) /* OTG wakeup intr enable */
28 #define MXC_OTG_UCTRL_OPM_BIT (1 << 24) /* OTG power mask */
29 #define MXC_H1_UCTRL_H1UIE_BIT (1 << 12) /* Host1 ULPI interrupt enable */
30 #define MXC_H1_UCTRL_H1WIE_BIT (1 << 11) /* HOST1 wakeup intr enable */
31 #define MXC_H1_UCTRL_H1PM_BIT (1 << 8) /* HOST1 power mask */
33 /* USB_PHY_CTRL_FUNC */
34 #define MXC_OTG_PHYCTRL_OC_POL_BIT (1 << 9) /* OTG Polarity of Overcurrent */
35 #define MXC_OTG_PHYCTRL_OC_DIS_BIT (1 << 8) /* OTG Disable Overcurrent Event */
36 #define MXC_H1_OC_POL_BIT (1 << 6) /* UH1 Polarity of Overcurrent */
37 #define MXC_H1_OC_DIS_BIT (1 << 5) /* UH1 Disable Overcurrent Event */
38 #define MXC_OTG_PHYCTRL_PWR_POL_BIT (1 << 3) /* OTG Power Pin Polarity */
41 #define MXC_H2_UCTRL_H2UIE_BIT (1 << 8)
42 #define MXC_H2_UCTRL_H2WIE_BIT (1 << 7)
43 #define MXC_H2_UCTRL_H2PM_BIT (1 << 4)
45 #define MXC_USBCMD_OFFSET 0x140
48 #define MXC_UCMD_ITC_NO_THRESHOLD_MASK (~(0xff << 16)) /* Interrupt Threshold Control */
50 int mx51_initialize_usb_hw(int port
, unsigned int flags
)
53 void __iomem
*usb_base
;
54 void __iomem
*usbotg_base
;
55 void __iomem
*usbother_base
;
58 usb_base
= ioremap(MX51_USB_OTG_BASE_ADDR
, SZ_4K
);
60 printk(KERN_ERR
"%s(): ioremap failed\n", __func__
);
65 case 0: /* OTG port */
66 usbotg_base
= usb_base
+ MXC_OTG_OFFSET
;
68 case 1: /* Host 1 port */
69 usbotg_base
= usb_base
+ MXC_H1_OFFSET
;
71 case 2: /* Host 2 port */
72 usbotg_base
= usb_base
+ MXC_H2_OFFSET
;
75 printk(KERN_ERR
"%s no such port %d\n", __func__
, port
);
79 usbother_base
= usb_base
+ MX5_USBOTHER_REGS_OFFSET
;
83 if (flags
& MXC_EHCI_INTERNAL_PHY
) {
84 v
= __raw_readl(usbother_base
+ MXC_USB_PHY_CTR_FUNC_OFFSET
);
86 if (flags
& MXC_EHCI_OC_PIN_ACTIVE_LOW
)
87 v
|= MXC_OTG_PHYCTRL_OC_POL_BIT
;
89 v
&= ~MXC_OTG_PHYCTRL_OC_POL_BIT
;
90 if (flags
& MXC_EHCI_POWER_PINS_ENABLED
) {
91 /* OC/USBPWR is used */
92 v
&= ~MXC_OTG_PHYCTRL_OC_DIS_BIT
;
94 /* OC/USBPWR is not used */
95 v
|= MXC_OTG_PHYCTRL_OC_DIS_BIT
;
97 if (flags
& MXC_EHCI_PWR_PIN_ACTIVE_HIGH
)
98 v
|= MXC_OTG_PHYCTRL_PWR_POL_BIT
;
100 v
&= ~MXC_OTG_PHYCTRL_PWR_POL_BIT
;
101 __raw_writel(v
, usbother_base
+ MXC_USB_PHY_CTR_FUNC_OFFSET
);
103 v
= __raw_readl(usbother_base
+ MXC_USBCTRL_OFFSET
);
104 if (flags
& MXC_EHCI_WAKEUP_ENABLED
)
105 v
|= MXC_OTG_UCTRL_OWIE_BIT
;/* OTG wakeup enable */
107 v
&= ~MXC_OTG_UCTRL_OWIE_BIT
;/* OTG wakeup disable */
108 if (flags
& MXC_EHCI_POWER_PINS_ENABLED
)
109 v
&= ~MXC_OTG_UCTRL_OPM_BIT
;
111 v
|= MXC_OTG_UCTRL_OPM_BIT
;
112 __raw_writel(v
, usbother_base
+ MXC_USBCTRL_OFFSET
);
117 v
= __raw_readl(usbother_base
+ MXC_USBCTRL_OFFSET
);
118 if (flags
& MXC_EHCI_WAKEUP_ENABLED
) {
119 /* HOST1 wakeup/ULPI intr enable */
120 v
|= (MXC_H1_UCTRL_H1WIE_BIT
| MXC_H1_UCTRL_H1UIE_BIT
);
122 /* HOST1 wakeup/ULPI intr disable */
123 v
&= ~(MXC_H1_UCTRL_H1WIE_BIT
| MXC_H1_UCTRL_H1UIE_BIT
);
126 if (flags
& MXC_EHCI_POWER_PINS_ENABLED
)
127 v
&= ~MXC_H1_UCTRL_H1PM_BIT
; /* HOST1 power mask unused*/
129 v
|= MXC_H1_UCTRL_H1PM_BIT
; /* HOST1 power mask used*/
130 __raw_writel(v
, usbother_base
+ MXC_USBCTRL_OFFSET
);
132 v
= __raw_readl(usbother_base
+ MXC_USB_PHY_CTR_FUNC_OFFSET
);
133 if (flags
& MXC_EHCI_OC_PIN_ACTIVE_LOW
)
134 v
|= MXC_H1_OC_POL_BIT
;
136 v
&= ~MXC_H1_OC_POL_BIT
;
137 if (flags
& MXC_EHCI_POWER_PINS_ENABLED
)
138 v
&= ~MXC_H1_OC_DIS_BIT
; /* OC is used */
140 v
|= MXC_H1_OC_DIS_BIT
; /* OC is not used */
141 __raw_writel(v
, usbother_base
+ MXC_USB_PHY_CTR_FUNC_OFFSET
);
143 v
= __raw_readl(usbotg_base
+ MXC_USBCMD_OFFSET
);
144 if (flags
& MXC_EHCI_ITC_NO_THRESHOLD
)
145 /* Interrupt Threshold Control:Immediate (no threshold) */
146 v
&= MXC_UCMD_ITC_NO_THRESHOLD_MASK
;
147 __raw_writel(v
, usbotg_base
+ MXC_USBCMD_OFFSET
);
149 case 2: /* Host 2 ULPI */
150 v
= __raw_readl(usbother_base
+ MXC_USBH2CTRL_OFFSET
);
151 if (flags
& MXC_EHCI_WAKEUP_ENABLED
) {
152 /* HOST1 wakeup/ULPI intr enable */
153 v
|= (MXC_H2_UCTRL_H2WIE_BIT
| MXC_H2_UCTRL_H2UIE_BIT
);
155 /* HOST1 wakeup/ULPI intr disable */
156 v
&= ~(MXC_H2_UCTRL_H2WIE_BIT
| MXC_H2_UCTRL_H2UIE_BIT
);
159 if (flags
& MXC_EHCI_POWER_PINS_ENABLED
)
160 v
&= ~MXC_H2_UCTRL_H2PM_BIT
; /* HOST2 power mask unused*/
162 v
|= MXC_H2_UCTRL_H2PM_BIT
; /* HOST2 power mask used*/
163 __raw_writel(v
, usbother_base
+ MXC_USBH2CTRL_OFFSET
);