diff options
author | Ajay Kumar Gupta <ajay.gupta@ti.com> | 2010-01-21 08:33:52 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-03-02 17:54:38 -0500 |
commit | 4f712e010b2da1cc01c178922f2eb5aaeae461b6 (patch) | |
tree | 4341a8c4f1e8184b0a727a9746be74267d20f68f | |
parent | 8af6096caf8b3fb7ee33e636c44a29f373d27df5 (diff) |
usb: musb: Add context save and restore support
Adding support for MUSB register save and restore during system
suspend and resume.
Changes:
- Added musb_save/restore_context() functions
- Added platform specific musb_platform_save/restore_context()
to handle platform specific jobs.
- Maintaining BlackFin compatibility by adding read/write
functions for registers which are not available in BlackFin
Tested system suspend and resume on OMAP3EVM board.
Signed-off-by: Anand Gadiyar <gadiyar@ti.com>
Signed-off-by: Ajay Kumar Gupta <ajay.gupta@ti.com>
Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/usb/musb/musb_core.c | 146 | ||||
-rw-r--r-- | drivers/usb/musb/musb_core.h | 39 | ||||
-rw-r--r-- | drivers/usb/musb/musb_regs.h | 90 | ||||
-rw-r--r-- | drivers/usb/musb/omap2430.c | 16 |
4 files changed, 291 insertions, 0 deletions
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c index 074d380bf883..2c53da771318 100644 --- a/drivers/usb/musb/musb_core.c +++ b/drivers/usb/musb/musb_core.c | |||
@@ -2167,6 +2167,148 @@ static int __exit musb_remove(struct platform_device *pdev) | |||
2167 | 2167 | ||
2168 | #ifdef CONFIG_PM | 2168 | #ifdef CONFIG_PM |
2169 | 2169 | ||
2170 | static struct musb_context_registers musb_context; | ||
2171 | |||
2172 | void musb_save_context(struct musb *musb) | ||
2173 | { | ||
2174 | int i; | ||
2175 | void __iomem *musb_base = musb->mregs; | ||
2176 | |||
2177 | if (is_host_enabled(musb)) { | ||
2178 | musb_context.frame = musb_readw(musb_base, MUSB_FRAME); | ||
2179 | musb_context.testmode = musb_readb(musb_base, MUSB_TESTMODE); | ||
2180 | } | ||
2181 | musb_context.power = musb_readb(musb_base, MUSB_POWER); | ||
2182 | musb_context.intrtxe = musb_readw(musb_base, MUSB_INTRTXE); | ||
2183 | musb_context.intrrxe = musb_readw(musb_base, MUSB_INTRRXE); | ||
2184 | musb_context.intrusbe = musb_readb(musb_base, MUSB_INTRUSBE); | ||
2185 | musb_context.index = musb_readb(musb_base, MUSB_INDEX); | ||
2186 | musb_context.devctl = musb_readb(musb_base, MUSB_DEVCTL); | ||
2187 | |||
2188 | for (i = 0; i < MUSB_C_NUM_EPS; ++i) { | ||
2189 | musb_writeb(musb_base, MUSB_INDEX, i); | ||
2190 | musb_context.index_regs[i].txmaxp = | ||
2191 | musb_readw(musb_base, 0x10 + MUSB_TXMAXP); | ||
2192 | musb_context.index_regs[i].txcsr = | ||
2193 | musb_readw(musb_base, 0x10 + MUSB_TXCSR); | ||
2194 | musb_context.index_regs[i].rxmaxp = | ||
2195 | musb_readw(musb_base, 0x10 + MUSB_RXMAXP); | ||
2196 | musb_context.index_regs[i].rxcsr = | ||
2197 | musb_readw(musb_base, 0x10 + MUSB_RXCSR); | ||
2198 | |||
2199 | if (musb->dyn_fifo) { | ||
2200 | musb_context.index_regs[i].txfifoadd = | ||
2201 | musb_read_txfifoadd(musb_base); | ||
2202 | musb_context.index_regs[i].rxfifoadd = | ||
2203 | musb_read_rxfifoadd(musb_base); | ||
2204 | musb_context.index_regs[i].txfifosz = | ||
2205 | musb_read_txfifosz(musb_base); | ||
2206 | musb_context.index_regs[i].rxfifosz = | ||
2207 | musb_read_rxfifosz(musb_base); | ||
2208 | } | ||
2209 | if (is_host_enabled(musb)) { | ||
2210 | musb_context.index_regs[i].txtype = | ||
2211 | musb_readb(musb_base, 0x10 + MUSB_TXTYPE); | ||
2212 | musb_context.index_regs[i].txinterval = | ||
2213 | musb_readb(musb_base, 0x10 + MUSB_TXINTERVAL); | ||
2214 | musb_context.index_regs[i].rxtype = | ||
2215 | musb_readb(musb_base, 0x10 + MUSB_RXTYPE); | ||
2216 | musb_context.index_regs[i].rxinterval = | ||
2217 | musb_readb(musb_base, 0x10 + MUSB_RXINTERVAL); | ||
2218 | |||
2219 | musb_context.index_regs[i].txfunaddr = | ||
2220 | musb_read_txfunaddr(musb_base, i); | ||
2221 | musb_context.index_regs[i].txhubaddr = | ||
2222 | musb_read_txhubaddr(musb_base, i); | ||
2223 | musb_context.index_regs[i].txhubport = | ||
2224 | musb_read_txhubport(musb_base, i); | ||
2225 | |||
2226 | musb_context.index_regs[i].rxfunaddr = | ||
2227 | musb_read_rxfunaddr(musb_base, i); | ||
2228 | musb_context.index_regs[i].rxhubaddr = | ||
2229 | musb_read_rxhubaddr(musb_base, i); | ||
2230 | musb_context.index_regs[i].rxhubport = | ||
2231 | musb_read_rxhubport(musb_base, i); | ||
2232 | } | ||
2233 | } | ||
2234 | |||
2235 | musb_writeb(musb_base, MUSB_INDEX, musb_context.index); | ||
2236 | |||
2237 | musb_platform_save_context(&musb_context); | ||
2238 | } | ||
2239 | |||
2240 | void musb_restore_context(struct musb *musb) | ||
2241 | { | ||
2242 | int i; | ||
2243 | void __iomem *musb_base = musb->mregs; | ||
2244 | void __iomem *ep_target_regs; | ||
2245 | |||
2246 | musb_platform_restore_context(&musb_context); | ||
2247 | |||
2248 | if (is_host_enabled(musb)) { | ||
2249 | musb_writew(musb_base, MUSB_FRAME, musb_context.frame); | ||
2250 | musb_writeb(musb_base, MUSB_TESTMODE, musb_context.testmode); | ||
2251 | } | ||
2252 | musb_writeb(musb_base, MUSB_POWER, musb_context.power); | ||
2253 | musb_writew(musb_base, MUSB_INTRTXE, musb_context.intrtxe); | ||
2254 | musb_writew(musb_base, MUSB_INTRRXE, musb_context.intrrxe); | ||
2255 | musb_writeb(musb_base, MUSB_INTRUSBE, musb_context.intrusbe); | ||
2256 | musb_writeb(musb_base, MUSB_DEVCTL, musb_context.devctl); | ||
2257 | |||
2258 | for (i = 0; i < MUSB_C_NUM_EPS; ++i) { | ||
2259 | musb_writeb(musb_base, MUSB_INDEX, i); | ||
2260 | musb_writew(musb_base, 0x10 + MUSB_TXMAXP, | ||
2261 | musb_context.index_regs[i].txmaxp); | ||
2262 | musb_writew(musb_base, 0x10 + MUSB_TXCSR, | ||
2263 | musb_context.index_regs[i].txcsr); | ||
2264 | musb_writew(musb_base, 0x10 + MUSB_RXMAXP, | ||
2265 | musb_context.index_regs[i].rxmaxp); | ||
2266 | musb_writew(musb_base, 0x10 + MUSB_RXCSR, | ||
2267 | musb_context.index_regs[i].rxcsr); | ||
2268 | |||
2269 | if (musb->dyn_fifo) { | ||
2270 | musb_write_txfifosz(musb_base, | ||
2271 | musb_context.index_regs[i].txfifosz); | ||
2272 | musb_write_rxfifosz(musb_base, | ||
2273 | musb_context.index_regs[i].rxfifosz); | ||
2274 | musb_write_txfifoadd(musb_base, | ||
2275 | musb_context.index_regs[i].txfifoadd); | ||
2276 | musb_write_rxfifoadd(musb_base, | ||
2277 | musb_context.index_regs[i].rxfifoadd); | ||
2278 | } | ||
2279 | |||
2280 | if (is_host_enabled(musb)) { | ||
2281 | musb_writeb(musb_base, 0x10 + MUSB_TXTYPE, | ||
2282 | musb_context.index_regs[i].txtype); | ||
2283 | musb_writeb(musb_base, 0x10 + MUSB_TXINTERVAL, | ||
2284 | musb_context.index_regs[i].txinterval); | ||
2285 | musb_writeb(musb_base, 0x10 + MUSB_RXTYPE, | ||
2286 | musb_context.index_regs[i].rxtype); | ||
2287 | musb_writeb(musb_base, 0x10 + MUSB_RXINTERVAL, | ||
2288 | |||
2289 | musb_context.index_regs[i].rxinterval); | ||
2290 | musb_write_txfunaddr(musb_base, i, | ||
2291 | musb_context.index_regs[i].txfunaddr); | ||
2292 | musb_write_txhubaddr(musb_base, i, | ||
2293 | musb_context.index_regs[i].txhubaddr); | ||
2294 | musb_write_txhubport(musb_base, i, | ||
2295 | musb_context.index_regs[i].txhubport); | ||
2296 | |||
2297 | ep_target_regs = | ||
2298 | musb_read_target_reg_base(i, musb_base); | ||
2299 | |||
2300 | musb_write_rxfunaddr(ep_target_regs, | ||
2301 | musb_context.index_regs[i].rxfunaddr); | ||
2302 | musb_write_rxhubaddr(ep_target_regs, | ||
2303 | musb_context.index_regs[i].rxhubaddr); | ||
2304 | musb_write_rxhubport(ep_target_regs, | ||
2305 | musb_context.index_regs[i].rxhubport); | ||
2306 | } | ||
2307 | } | ||
2308 | |||
2309 | musb_writeb(musb_base, MUSB_INDEX, musb_context.index); | ||
2310 | } | ||
2311 | |||
2170 | static int musb_suspend(struct device *dev) | 2312 | static int musb_suspend(struct device *dev) |
2171 | { | 2313 | { |
2172 | struct platform_device *pdev = to_platform_device(dev); | 2314 | struct platform_device *pdev = to_platform_device(dev); |
@@ -2188,6 +2330,8 @@ static int musb_suspend(struct device *dev) | |||
2188 | */ | 2330 | */ |
2189 | } | 2331 | } |
2190 | 2332 | ||
2333 | musb_save_context(musb); | ||
2334 | |||
2191 | if (musb->set_clock) | 2335 | if (musb->set_clock) |
2192 | musb->set_clock(musb->clock, 0); | 2336 | musb->set_clock(musb->clock, 0); |
2193 | else | 2337 | else |
@@ -2209,6 +2353,8 @@ static int musb_resume_noirq(struct device *dev) | |||
2209 | else | 2353 | else |
2210 | clk_enable(musb->clock); | 2354 | clk_enable(musb->clock); |
2211 | 2355 | ||
2356 | musb_restore_context(musb); | ||
2357 | |||
2212 | /* for static cmos like DaVinci, register values were preserved | 2358 | /* for static cmos like DaVinci, register values were preserved |
2213 | * unless for some reason the whole soc powered down or the USB | 2359 | * unless for some reason the whole soc powered down or the USB |
2214 | * module got reset through the PSC (vs just being disabled). | 2360 | * module got reset through the PSC (vs just being disabled). |
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h index eaa01140183e..3d66c3e01dbd 100644 --- a/drivers/usb/musb/musb_core.h +++ b/drivers/usb/musb/musb_core.h | |||
@@ -454,6 +454,45 @@ struct musb { | |||
454 | #endif | 454 | #endif |
455 | }; | 455 | }; |
456 | 456 | ||
457 | #ifdef CONFIG_PM | ||
458 | struct musb_csr_regs { | ||
459 | /* FIFO registers */ | ||
460 | u16 txmaxp, txcsr, rxmaxp, rxcsr; | ||
461 | u16 rxfifoadd, txfifoadd; | ||
462 | u8 txtype, txinterval, rxtype, rxinterval; | ||
463 | u8 rxfifosz, txfifosz; | ||
464 | u8 txfunaddr, txhubaddr, txhubport; | ||
465 | u8 rxfunaddr, rxhubaddr, rxhubport; | ||
466 | }; | ||
467 | |||
468 | struct musb_context_registers { | ||
469 | |||
470 | #if defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP2430) | ||
471 | u32 otg_sysconfig, otg_forcestandby; | ||
472 | #endif | ||
473 | u8 power; | ||
474 | u16 intrtxe, intrrxe; | ||
475 | u8 intrusbe; | ||
476 | u16 frame; | ||
477 | u8 index, testmode; | ||
478 | |||
479 | u8 devctl, misc; | ||
480 | |||
481 | struct musb_csr_regs index_regs[MUSB_C_NUM_EPS]; | ||
482 | }; | ||
483 | |||
484 | #if defined(CONFIG_ARCH_OMAP34XX) || defined(CONFIG_ARCH_OMAP2430) | ||
485 | extern void musb_platform_save_context(struct musb_context_registers | ||
486 | *musb_context); | ||
487 | extern void musb_platform_restore_context(struct musb_context_registers | ||
488 | *musb_context); | ||
489 | #else | ||
490 | #define musb_platform_save_context(x) do {} while (0) | ||
491 | #define musb_platform_restore_context(x) do {} while (0) | ||
492 | #endif | ||
493 | |||
494 | #endif | ||
495 | |||
457 | static inline void musb_set_vbus(struct musb *musb, int is_on) | 496 | static inline void musb_set_vbus(struct musb *musb, int is_on) |
458 | { | 497 | { |
459 | musb->board_set_vbus(musb, is_on); | 498 | musb->board_set_vbus(musb, is_on); |
diff --git a/drivers/usb/musb/musb_regs.h b/drivers/usb/musb/musb_regs.h index 9a8621ac5ac2..895fb057e443 100644 --- a/drivers/usb/musb/musb_regs.h +++ b/drivers/usb/musb/musb_regs.h | |||
@@ -326,6 +326,26 @@ static inline void musb_write_rxfifoadd(void __iomem *mbase, u16 c_off) | |||
326 | musb_writew(mbase, MUSB_RXFIFOADD, c_off); | 326 | musb_writew(mbase, MUSB_RXFIFOADD, c_off); |
327 | } | 327 | } |
328 | 328 | ||
329 | static inline u8 musb_read_txfifosz(void __iomem *mbase) | ||
330 | { | ||
331 | return musb_readb(mbase, MUSB_TXFIFOSZ); | ||
332 | } | ||
333 | |||
334 | static inline u16 musb_read_txfifoadd(void __iomem *mbase) | ||
335 | { | ||
336 | return musb_readw(mbase, MUSB_TXFIFOADD); | ||
337 | } | ||
338 | |||
339 | static inline u8 musb_read_rxfifosz(void __iomem *mbase) | ||
340 | { | ||
341 | return musb_readb(mbase, MUSB_RXFIFOSZ); | ||
342 | } | ||
343 | |||
344 | static inline u16 musb_read_rxfifoadd(void __iomem *mbase) | ||
345 | { | ||
346 | return musb_readw(mbase, MUSB_RXFIFOADD); | ||
347 | } | ||
348 | |||
329 | static inline u8 musb_read_configdata(void __iomem *mbase) | 349 | static inline u8 musb_read_configdata(void __iomem *mbase) |
330 | { | 350 | { |
331 | musb_writeb(mbase, MUSB_INDEX, 0); | 351 | musb_writeb(mbase, MUSB_INDEX, 0); |
@@ -381,6 +401,36 @@ static inline void musb_write_txhubport(void __iomem *mbase, u8 epnum, | |||
381 | qh_h_port_reg); | 401 | qh_h_port_reg); |
382 | } | 402 | } |
383 | 403 | ||
404 | static inline u8 musb_read_rxfunaddr(void __iomem *mbase, u8 epnum) | ||
405 | { | ||
406 | return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_RXFUNCADDR)); | ||
407 | } | ||
408 | |||
409 | static inline u8 musb_read_rxhubaddr(void __iomem *mbase, u8 epnum) | ||
410 | { | ||
411 | return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_RXHUBADDR)); | ||
412 | } | ||
413 | |||
414 | static inline u8 musb_read_rxhubport(void __iomem *mbase, u8 epnum) | ||
415 | { | ||
416 | return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_RXHUBPORT)); | ||
417 | } | ||
418 | |||
419 | static inline u8 musb_read_txfunaddr(void __iomem *mbase, u8 epnum) | ||
420 | { | ||
421 | return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXFUNCADDR)); | ||
422 | } | ||
423 | |||
424 | static inline u8 musb_read_txhubaddr(void __iomem *mbase, u8 epnum) | ||
425 | { | ||
426 | return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXHUBADDR)); | ||
427 | } | ||
428 | |||
429 | static inline u8 musb_read_txhubport(void __iomem *mbase, u8 epnum) | ||
430 | { | ||
431 | return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXHUBPORT)); | ||
432 | } | ||
433 | |||
384 | #else /* CONFIG_BLACKFIN */ | 434 | #else /* CONFIG_BLACKFIN */ |
385 | 435 | ||
386 | #define USB_BASE USB_FADDR | 436 | #define USB_BASE USB_FADDR |
@@ -460,6 +510,22 @@ static inline void musb_write_rxfifoadd(void __iomem *mbase, u16 c_off) | |||
460 | { | 510 | { |
461 | } | 511 | } |
462 | 512 | ||
513 | static inline u8 musb_read_txfifosz(void __iomem *mbase) | ||
514 | { | ||
515 | } | ||
516 | |||
517 | static inline u16 musb_read_txfifoadd(void __iomem *mbase) | ||
518 | { | ||
519 | } | ||
520 | |||
521 | static inline u8 musb_read_rxfifosz(void __iomem *mbase) | ||
522 | { | ||
523 | } | ||
524 | |||
525 | static inline u16 musb_read_rxfifoadd(void __iomem *mbase) | ||
526 | { | ||
527 | } | ||
528 | |||
463 | static inline u8 musb_read_configdata(void __iomem *mbase) | 529 | static inline u8 musb_read_configdata(void __iomem *mbase) |
464 | { | 530 | { |
465 | return 0; | 531 | return 0; |
@@ -505,6 +571,30 @@ static inline void musb_write_txhubport(void __iomem *mbase, u8 epnum, | |||
505 | { | 571 | { |
506 | } | 572 | } |
507 | 573 | ||
574 | static inline u8 musb_read_rxfunaddr(void __iomem *mbase, u8 epnum) | ||
575 | { | ||
576 | } | ||
577 | |||
578 | static inline u8 musb_read_rxhubaddr(void __iomem *mbase, u8 epnum) | ||
579 | { | ||
580 | } | ||
581 | |||
582 | static inline u8 musb_read_rxhubport(void __iomem *mbase, u8 epnum) | ||
583 | { | ||
584 | } | ||
585 | |||
586 | static inline u8 musb_read_txfunaddr(void __iomem *mbase, u8 epnum) | ||
587 | { | ||
588 | } | ||
589 | |||
590 | static inline u8 musb_read_txhubaddr(void __iomem *mbase, u8 epnum) | ||
591 | { | ||
592 | } | ||
593 | |||
594 | static inline void musb_read_txhubport(void __iomem *mbase, u8 epnum) | ||
595 | { | ||
596 | } | ||
597 | |||
508 | #endif /* CONFIG_BLACKFIN */ | 598 | #endif /* CONFIG_BLACKFIN */ |
509 | 599 | ||
510 | #endif /* __MUSB_REGS_H__ */ | 600 | #endif /* __MUSB_REGS_H__ */ |
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c index 83beeac5e7bf..15a3f27b5747 100644 --- a/drivers/usb/musb/omap2430.c +++ b/drivers/usb/musb/omap2430.c | |||
@@ -255,6 +255,22 @@ int __init musb_platform_init(struct musb *musb) | |||
255 | return 0; | 255 | return 0; |
256 | } | 256 | } |
257 | 257 | ||
258 | #ifdef CONFIG_PM | ||
259 | void musb_platform_save_context(struct musb_context_registers | ||
260 | *musb_context) | ||
261 | { | ||
262 | musb_context->otg_sysconfig = omap_readl(OTG_SYSCONFIG); | ||
263 | musb_context->otg_forcestandby = omap_readl(OTG_FORCESTDBY); | ||
264 | } | ||
265 | |||
266 | void musb_platform_restore_context(struct musb_context_registers | ||
267 | *musb_context) | ||
268 | { | ||
269 | omap_writel(musb_context->otg_sysconfig, OTG_SYSCONFIG); | ||
270 | omap_writel(musb_context->otg_forcestandby, OTG_FORCESTDBY); | ||
271 | } | ||
272 | #endif | ||
273 | |||
258 | int musb_platform_suspend(struct musb *musb) | 274 | int musb_platform_suspend(struct musb *musb) |
259 | { | 275 | { |
260 | u32 l; | 276 | u32 l; |