2 * USB block power/access management abstraction.
4 * Au1000+: The OHCI block control register is at the far end of the OHCI memory
5 * area. Au1550 has OHCI on different base address. No need to handle
7 * Au1200: one register to control access and clocks to O/EHCI, UDC and OTG
8 * as well as the PHY for EHCI and UDC.
12 #include <linux/init.h>
14 #include <linux/module.h>
15 #include <linux/spinlock.h>
16 #include <linux/syscore_ops.h>
17 #include <asm/mach-au1x00/au1000.h>
19 /* control register offsets */
20 #define AU1000_OHCICFG 0x7fffc
21 #define AU1550_OHCICFG 0x07ffc
22 #define AU1200_USBCFG 0x04
24 /* Au1000 USB block config bits */
25 #define USBHEN_RD (1 << 4) /* OHCI reset-done indicator */
26 #define USBHEN_CE (1 << 3) /* OHCI block clock enable */
27 #define USBHEN_E (1 << 2) /* OHCI block enable */
28 #define USBHEN_C (1 << 1) /* OHCI block coherency bit */
29 #define USBHEN_BE (1 << 0) /* OHCI Big-Endian */
31 /* Au1200 USB config bits */
32 #define USBCFG_PFEN (1 << 31) /* prefetch enable (undoc) */
33 #define USBCFG_RDCOMB (1 << 30) /* read combining (undoc) */
34 #define USBCFG_UNKNOWN (5 << 20) /* unknown, leave this way */
35 #define USBCFG_SSD (1 << 23) /* serial short detect en */
36 #define USBCFG_PPE (1 << 19) /* HS PHY PLL */
37 #define USBCFG_UCE (1 << 18) /* UDC clock enable */
38 #define USBCFG_ECE (1 << 17) /* EHCI clock enable */
39 #define USBCFG_OCE (1 << 16) /* OHCI clock enable */
40 #define USBCFG_FLA(x) (((x) & 0x3f) << 8)
41 #define USBCFG_UCAM (1 << 7) /* coherent access (undoc) */
42 #define USBCFG_GME (1 << 6) /* OTG mem access */
43 #define USBCFG_DBE (1 << 5) /* UDC busmaster enable */
44 #define USBCFG_DME (1 << 4) /* UDC mem enable */
45 #define USBCFG_EBE (1 << 3) /* EHCI busmaster enable */
46 #define USBCFG_EME (1 << 2) /* EHCI mem enable */
47 #define USBCFG_OBE (1 << 1) /* OHCI busmaster enable */
48 #define USBCFG_OME (1 << 0) /* OHCI mem enable */
49 #define USBCFG_INIT_AU1200 (USBCFG_PFEN | USBCFG_RDCOMB | USBCFG_UNKNOWN |\
50 USBCFG_SSD | USBCFG_FLA(0x20) | USBCFG_UCAM | \
51 USBCFG_GME | USBCFG_DBE | USBCFG_DME | \
52 USBCFG_EBE | USBCFG_EME | USBCFG_OBE | \
56 static DEFINE_SPINLOCK(alchemy_usb_lock
);
59 static inline void __au1200_ohci_control(void __iomem
*base
, int enable
)
61 unsigned long r
= __raw_readl(base
+ AU1200_USBCFG
);
63 __raw_writel(r
| USBCFG_OCE
, base
+ AU1200_USBCFG
);
67 __raw_writel(r
& ~USBCFG_OCE
, base
+ AU1200_USBCFG
);
73 static inline void __au1200_ehci_control(void __iomem
*base
, int enable
)
75 unsigned long r
= __raw_readl(base
+ AU1200_USBCFG
);
77 __raw_writel(r
| USBCFG_ECE
| USBCFG_PPE
, base
+ AU1200_USBCFG
);
81 if (!(r
& USBCFG_UCE
)) /* UDC also off? */
82 r
&= ~USBCFG_PPE
; /* yes: disable HS PHY PLL */
83 __raw_writel(r
& ~USBCFG_ECE
, base
+ AU1200_USBCFG
);
89 static inline void __au1200_udc_control(void __iomem
*base
, int enable
)
91 unsigned long r
= __raw_readl(base
+ AU1200_USBCFG
);
93 __raw_writel(r
| USBCFG_UCE
| USBCFG_PPE
, base
+ AU1200_USBCFG
);
96 if (!(r
& USBCFG_ECE
)) /* EHCI also off? */
97 r
&= ~USBCFG_PPE
; /* yes: disable HS PHY PLL */
98 __raw_writel(r
& ~USBCFG_UCE
, base
+ AU1200_USBCFG
);
103 static inline int au1200_coherency_bug(void)
105 #if defined(CONFIG_DMA_COHERENT)
106 /* Au1200 AB USB does not support coherent memory */
107 if (!(read_c0_prid() & 0xff)) {
108 printk(KERN_INFO
"Au1200 USB: this is chip revision AB !!\n");
109 printk(KERN_INFO
"Au1200 USB: update your board or re-configure"
117 static inline int au1200_usb_control(int block
, int enable
)
120 (void __iomem
*)KSEG1ADDR(AU1200_USB_CTL_PHYS_ADDR
);
124 case ALCHEMY_USB_OHCI0
:
125 ret
= au1200_coherency_bug();
128 __au1200_ohci_control(base
, enable
);
130 case ALCHEMY_USB_UDC0
:
131 __au1200_udc_control(base
, enable
);
133 case ALCHEMY_USB_EHCI0
:
134 ret
= au1200_coherency_bug();
137 __au1200_ehci_control(base
, enable
);
147 /* initialize USB block(s) to a known working state */
148 static inline void au1200_usb_init(void)
151 (void __iomem
*)KSEG1ADDR(AU1200_USB_CTL_PHYS_ADDR
);
152 __raw_writel(USBCFG_INIT_AU1200
, base
+ AU1200_USBCFG
);
157 static inline void au1000_usb_init(unsigned long rb
, int reg
)
159 void __iomem
*base
= (void __iomem
*)KSEG1ADDR(rb
+ reg
);
160 unsigned long r
= __raw_readl(base
);
162 #if defined(__BIG_ENDIAN)
167 __raw_writel(r
, base
);
173 static inline void __au1xx0_ohci_control(int enable
, unsigned long rb
, int creg
)
175 void __iomem
*base
= (void __iomem
*)KSEG1ADDR(rb
);
176 unsigned long r
= __raw_readl(base
+ creg
);
179 __raw_writel(r
| USBHEN_CE
, base
+ creg
);
182 __raw_writel(r
| USBHEN_CE
| USBHEN_E
, base
+ creg
);
186 /* wait for reset complete (read reg twice: au1500 erratum) */
187 while (__raw_readl(base
+ creg
),
188 !(__raw_readl(base
+ creg
) & USBHEN_RD
))
191 __raw_writel(r
& ~(USBHEN_CE
| USBHEN_E
), base
+ creg
);
196 static inline int au1000_usb_control(int block
, int enable
, unsigned long rb
,
202 case ALCHEMY_USB_OHCI0
:
203 __au1xx0_ohci_control(enable
, rb
, creg
);
212 * alchemy_usb_control - control Alchemy on-chip USB blocks
213 * @block: USB block to target
214 * @enable: set 1 to enable a block, 0 to disable
216 int alchemy_usb_control(int block
, int enable
)
221 spin_lock_irqsave(&alchemy_usb_lock
, flags
);
222 switch (alchemy_get_cputype()) {
223 case ALCHEMY_CPU_AU1000
:
224 case ALCHEMY_CPU_AU1500
:
225 case ALCHEMY_CPU_AU1100
:
226 ret
= au1000_usb_control(block
, enable
,
227 AU1000_USB_OHCI_PHYS_ADDR
, AU1000_OHCICFG
);
229 case ALCHEMY_CPU_AU1550
:
230 ret
= au1000_usb_control(block
, enable
,
231 AU1550_USB_OHCI_PHYS_ADDR
, AU1550_OHCICFG
);
233 case ALCHEMY_CPU_AU1200
:
234 ret
= au1200_usb_control(block
, enable
);
239 spin_unlock_irqrestore(&alchemy_usb_lock
, flags
);
242 EXPORT_SYMBOL_GPL(alchemy_usb_control
);
245 static unsigned long alchemy_usb_pmdata
[2];
247 static void au1000_usb_pm(unsigned long br
, int creg
, int susp
)
249 void __iomem
*base
= (void __iomem
*)KSEG1ADDR(br
);
252 alchemy_usb_pmdata
[0] = __raw_readl(base
+ creg
);
253 /* There appears to be some undocumented reset register.... */
254 __raw_writel(0, base
+ 0x04);
256 __raw_writel(0, base
+ creg
);
259 __raw_writel(alchemy_usb_pmdata
[0], base
+ creg
);
264 static void au1200_usb_pm(int susp
)
267 (void __iomem
*)KSEG1ADDR(AU1200_USB_OTG_PHYS_ADDR
);
269 /* save OTG_CAP/MUX registers which indicate port routing */
270 /* FIXME: write an OTG driver to do that */
271 alchemy_usb_pmdata
[0] = __raw_readl(base
+ 0x00);
272 alchemy_usb_pmdata
[1] = __raw_readl(base
+ 0x04);
274 /* restore access to all MMIO areas */
277 /* restore OTG_CAP/MUX registers */
278 __raw_writel(alchemy_usb_pmdata
[0], base
+ 0x00);
279 __raw_writel(alchemy_usb_pmdata
[1], base
+ 0x04);
284 static void alchemy_usb_pm(int susp
)
286 switch (alchemy_get_cputype()) {
287 case ALCHEMY_CPU_AU1000
:
288 case ALCHEMY_CPU_AU1500
:
289 case ALCHEMY_CPU_AU1100
:
290 au1000_usb_pm(AU1000_USB_OHCI_PHYS_ADDR
, AU1000_OHCICFG
, susp
);
292 case ALCHEMY_CPU_AU1550
:
293 au1000_usb_pm(AU1550_USB_OHCI_PHYS_ADDR
, AU1550_OHCICFG
, susp
);
295 case ALCHEMY_CPU_AU1200
:
301 static int alchemy_usb_suspend(void)
307 static void alchemy_usb_resume(void)
312 static struct syscore_ops alchemy_usb_pm_ops
= {
313 .suspend
= alchemy_usb_suspend
,
314 .resume
= alchemy_usb_resume
,
317 static int __init
alchemy_usb_init(void)
319 switch (alchemy_get_cputype()) {
320 case ALCHEMY_CPU_AU1000
:
321 case ALCHEMY_CPU_AU1500
:
322 case ALCHEMY_CPU_AU1100
:
323 au1000_usb_init(AU1000_USB_OHCI_PHYS_ADDR
, AU1000_OHCICFG
);
325 case ALCHEMY_CPU_AU1550
:
326 au1000_usb_init(AU1550_USB_OHCI_PHYS_ADDR
, AU1550_OHCICFG
);
328 case ALCHEMY_CPU_AU1200
:
333 register_syscore_ops(&alchemy_usb_pm_ops
);
337 arch_initcall(alchemy_usb_init
);