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_DIS_BIT (1 << 8) /* OTG Disable Overcurrent Event */
35 #define MXC_H1_OC_DIS_BIT (1 << 5) /* UH1 Disable Overcurrent Event */
38 #define MXC_H2_UCTRL_H2UIE_BIT (1 << 8)
39 #define MXC_H2_UCTRL_H2WIE_BIT (1 << 7)
40 #define MXC_H2_UCTRL_H2PM_BIT (1 << 4)
42 #define MXC_USBCMD_OFFSET 0x140
45 #define MXC_UCMD_ITC_NO_THRESHOLD_MASK (~(0xff << 16)) /* Interrupt Threshold Control */
47 int mx51_initialize_usb_hw(int port
, unsigned int flags
)
50 void __iomem
*usb_base
;
51 void __iomem
*usbotg_base
;
52 void __iomem
*usbother_base
;
55 usb_base
= ioremap(MX51_OTG_BASE_ADDR
, SZ_4K
);
57 printk(KERN_ERR
"%s(): ioremap failed\n", __func__
);
62 case 0: /* OTG port */
63 usbotg_base
= usb_base
+ MXC_OTG_OFFSET
;
65 case 1: /* Host 1 port */
66 usbotg_base
= usb_base
+ MXC_H1_OFFSET
;
68 case 2: /* Host 2 port */
69 usbotg_base
= usb_base
+ MXC_H2_OFFSET
;
72 printk(KERN_ERR
"%s no such port %d\n", __func__
, port
);
76 usbother_base
= usb_base
+ MX5_USBOTHER_REGS_OFFSET
;
80 if (flags
& MXC_EHCI_INTERNAL_PHY
) {
81 v
= __raw_readl(usbother_base
+ MXC_USB_PHY_CTR_FUNC_OFFSET
);
83 if (flags
& MXC_EHCI_POWER_PINS_ENABLED
) {
84 /* OC/USBPWR is not used */
85 v
|= MXC_OTG_PHYCTRL_OC_DIS_BIT
;
87 /* OC/USBPWR is used */
88 v
&= ~MXC_OTG_PHYCTRL_OC_DIS_BIT
;
90 __raw_writel(v
, usbother_base
+ MXC_USB_PHY_CTR_FUNC_OFFSET
);
92 v
= __raw_readl(usbother_base
+ MXC_USBCTRL_OFFSET
);
93 if (flags
& MXC_EHCI_WAKEUP_ENABLED
)
94 v
|= MXC_OTG_UCTRL_OWIE_BIT
;/* OTG wakeup enable */
96 v
&= ~MXC_OTG_UCTRL_OWIE_BIT
;/* OTG wakeup disable */
97 if (flags
& MXC_EHCI_POWER_PINS_ENABLED
)
98 v
|= MXC_OTG_UCTRL_OPM_BIT
;
100 v
&= ~MXC_OTG_UCTRL_OPM_BIT
;
101 __raw_writel(v
, usbother_base
+ MXC_USBCTRL_OFFSET
);
106 v
= __raw_readl(usbother_base
+ MXC_USBCTRL_OFFSET
);
107 if (flags
& MXC_EHCI_WAKEUP_ENABLED
) {
108 /* HOST1 wakeup/ULPI intr enable */
109 v
|= (MXC_H1_UCTRL_H1WIE_BIT
| MXC_H1_UCTRL_H1UIE_BIT
);
111 /* HOST1 wakeup/ULPI intr disable */
112 v
&= ~(MXC_H1_UCTRL_H1WIE_BIT
| MXC_H1_UCTRL_H1UIE_BIT
);
115 if (flags
& MXC_EHCI_POWER_PINS_ENABLED
)
116 v
&= ~MXC_H1_UCTRL_H1PM_BIT
; /* HOST1 power mask used*/
118 v
|= MXC_H1_UCTRL_H1PM_BIT
; /* HOST1 power mask used*/
119 __raw_writel(v
, usbother_base
+ MXC_USBCTRL_OFFSET
);
121 v
= __raw_readl(usbother_base
+ MXC_USB_PHY_CTR_FUNC_OFFSET
);
122 if (flags
& MXC_EHCI_POWER_PINS_ENABLED
)
123 v
&= ~MXC_H1_OC_DIS_BIT
; /* OC is used */
125 v
|= MXC_H1_OC_DIS_BIT
; /* OC is not used */
126 __raw_writel(v
, usbother_base
+ MXC_USB_PHY_CTR_FUNC_OFFSET
);
128 v
= __raw_readl(usbotg_base
+ MXC_USBCMD_OFFSET
);
129 if (flags
& MXC_EHCI_ITC_NO_THRESHOLD
)
130 /* Interrupt Threshold Control:Immediate (no threshold) */
131 v
&= MXC_UCMD_ITC_NO_THRESHOLD_MASK
;
132 __raw_writel(v
, usbotg_base
+ MXC_USBCMD_OFFSET
);
134 case 2: /* Host 2 ULPI */
135 v
= __raw_readl(usbother_base
+ MXC_USBH2CTRL_OFFSET
);
136 if (flags
& MXC_EHCI_WAKEUP_ENABLED
) {
137 /* HOST1 wakeup/ULPI intr enable */
138 v
|= (MXC_H2_UCTRL_H2WIE_BIT
| MXC_H2_UCTRL_H2UIE_BIT
);
140 /* HOST1 wakeup/ULPI intr disable */
141 v
&= ~(MXC_H2_UCTRL_H2WIE_BIT
| MXC_H2_UCTRL_H2UIE_BIT
);
144 if (flags
& MXC_EHCI_POWER_PINS_ENABLED
)
145 v
&= ~MXC_H2_UCTRL_H2PM_BIT
; /* HOST2 power mask used*/
147 v
|= MXC_H2_UCTRL_H2PM_BIT
; /* HOST2 power mask used*/
148 __raw_writel(v
, usbother_base
+ MXC_USBH2CTRL_OFFSET
);