Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Markus Klotzbuecher | 9809551 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2006 |
| 4 | * Markus Klotzbuecher, DENX Software Engineering <mk@denx.de> |
Markus Klotzbuecher | 9809551 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 8 | #include <linux/delay.h> |
Markus Klotzbuecher | 9809551 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 9 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 10 | #if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT) |
Marek Vasut | 85cc88a | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 11 | # if defined(CONFIG_CPU_MONAHANS) || defined(CONFIG_CPU_PXA27X) |
Markus Klotzbuecher | d0a3878 | 2006-05-23 13:38:35 +0200 | [diff] [blame] | 12 | |
| 13 | #include <asm/arch/pxa-regs.h> |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 14 | #include <asm/io.h> |
Jean-Christophe PLAGNIOL-VILLARD | bce7b14 | 2007-10-19 10:55:24 +0200 | [diff] [blame] | 15 | #include <usb.h> |
Markus Klotzbuecher | d0a3878 | 2006-05-23 13:38:35 +0200 | [diff] [blame] | 16 | |
Jean-Christophe PLAGNIOL-VILLARD | 733fc37 | 2007-10-19 08:10:15 +0200 | [diff] [blame] | 17 | int usb_cpu_init(void) |
Markus Klotzbuecher | 9809551 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 18 | { |
Rodolfo Giometti | 6659da8 | 2007-03-26 12:03:36 +0200 | [diff] [blame] | 19 | #if defined(CONFIG_CPU_MONAHANS) |
Markus Klotzbuecher | 9809551 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 20 | /* Enable USB host clock. */ |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 21 | writel(readl(CKENA) | CKENA_2_USBHOST | CKENA_20_UDC, CKENA); |
Markus Klotzbuecher | 9809551 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 22 | udelay(100); |
Rodolfo Giometti | 6659da8 | 2007-03-26 12:03:36 +0200 | [diff] [blame] | 23 | #endif |
Marek Vasut | 85cc88a | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 24 | #if defined(CONFIG_CPU_PXA27X) |
Rodolfo Giometti | 6659da8 | 2007-03-26 12:03:36 +0200 | [diff] [blame] | 25 | /* Enable USB host clock. */ |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 26 | writel(readl(CKEN) | CKEN10_USBHOST, CKEN); |
Rodolfo Giometti | 6659da8 | 2007-03-26 12:03:36 +0200 | [diff] [blame] | 27 | #endif |
Markus Klotzbuecher | 9809551 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 28 | |
Markus Klotzbuecher | 4a7847b | 2007-04-03 14:27:08 +0200 | [diff] [blame] | 29 | #if defined(CONFIG_CPU_MONAHANS) |
Markus Klotzbuecher | 9809551 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 30 | /* Configure Port 2 for Host (USB Client Registers) */ |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 31 | writel(0x3000c, UP2OCR); |
Markus Klotzbuecher | 9809551 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 32 | #endif |
| 33 | |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 34 | writel(readl(UHCHR) | UHCHR_FHR, UHCHR); |
Mike Frysinger | 60ce19a | 2012-03-05 13:47:00 +0000 | [diff] [blame] | 35 | mdelay(11); |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 36 | writel(readl(UHCHR) & ~UHCHR_FHR, UHCHR); |
Markus Klotzbuecher | 9809551 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 37 | |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 38 | writel(readl(UHCHR) | UHCHR_FSBIR, UHCHR); |
| 39 | while (readl(UHCHR) & UHCHR_FSBIR) |
Markus Klotzbuecher | 9809551 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 40 | udelay(1); |
| 41 | |
Stefan Herbrechtsmeier | 13d240f | 2011-10-17 17:22:47 +0200 | [diff] [blame] | 42 | #if defined(CONFIG_CPU_MONAHANS) || defined(CONFIG_PXA27X) |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 43 | writel(readl(UHCHR) & ~UHCHR_SSEP0, UHCHR); |
Rodolfo Giometti | 6659da8 | 2007-03-26 12:03:36 +0200 | [diff] [blame] | 44 | #endif |
Marek Vasut | 85cc88a | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 45 | #if defined(CONFIG_CPU_PXA27X) |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 46 | writel(readl(UHCHR) & ~UHCHR_SSEP2, UHCHR); |
Rodolfo Giometti | 6659da8 | 2007-03-26 12:03:36 +0200 | [diff] [blame] | 47 | #endif |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 48 | writel(readl(UHCHR) & ~(UHCHR_SSEP1 | UHCHR_SSE), UHCHR); |
Markus Klotzbuecher | 9809551 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
Jean-Christophe PLAGNIOL-VILLARD | 733fc37 | 2007-10-19 08:10:15 +0200 | [diff] [blame] | 53 | int usb_cpu_stop(void) |
Markus Klotzbuecher | 9809551 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 54 | { |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 55 | writel(readl(UHCHR) | UHCHR_FHR, UHCHR); |
Rodolfo Giometti | dae6b7a | 2007-10-15 11:59:17 +0200 | [diff] [blame] | 56 | udelay(11); |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 57 | writel(readl(UHCHR) & ~UHCHR_FHR, UHCHR); |
Rodolfo Giometti | dae6b7a | 2007-10-15 11:59:17 +0200 | [diff] [blame] | 58 | |
Stefan Herbrechtsmeier | 38f79c6 | 2011-10-17 17:22:46 +0200 | [diff] [blame] | 59 | writel(readl(UHCCOMS) | UHCCOMS_HCR, UHCCOMS); |
Rodolfo Giometti | dae6b7a | 2007-10-15 11:59:17 +0200 | [diff] [blame] | 60 | udelay(10); |
| 61 | |
Stefan Herbrechtsmeier | 13d240f | 2011-10-17 17:22:47 +0200 | [diff] [blame] | 62 | #if defined(CONFIG_CPU_MONAHANS) || defined(CONFIG_PXA27X) |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 63 | writel(readl(UHCHR) | UHCHR_SSEP0, UHCHR); |
Rodolfo Giometti | dae6b7a | 2007-10-15 11:59:17 +0200 | [diff] [blame] | 64 | #endif |
Marek Vasut | 85cc88a | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 65 | #if defined(CONFIG_CPU_PXA27X) |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 66 | writel(readl(UHCHR) | UHCHR_SSEP2, UHCHR); |
Rodolfo Giometti | dae6b7a | 2007-10-15 11:59:17 +0200 | [diff] [blame] | 67 | #endif |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 68 | writel(readl(UHCHR) | UHCHR_SSEP1 | UHCHR_SSE, UHCHR); |
Rodolfo Giometti | 6416a73 | 2007-10-15 11:59:17 +0200 | [diff] [blame] | 69 | |
| 70 | #if defined(CONFIG_CPU_MONAHANS) |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 71 | /* Disable USB host clock. */ |
| 72 | writel(readl(CKENA) & ~(CKENA_2_USBHOST | CKENA_20_UDC), CKENA); |
| 73 | udelay(100); |
Rodolfo Giometti | 6416a73 | 2007-10-15 11:59:17 +0200 | [diff] [blame] | 74 | #endif |
Marek Vasut | 85cc88a | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 75 | #if defined(CONFIG_CPU_PXA27X) |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 76 | /* Disable USB host clock. */ |
| 77 | writel(readl(CKEN) & ~CKEN10_USBHOST, CKEN); |
Rodolfo Giometti | 6416a73 | 2007-10-15 11:59:17 +0200 | [diff] [blame] | 78 | #endif |
Rodolfo Giometti | 6416a73 | 2007-10-15 11:59:17 +0200 | [diff] [blame] | 79 | |
Markus Klotzbuecher | 9809551 | 2006-05-23 10:33:11 +0200 | [diff] [blame] | 80 | return 0; |
| 81 | } |
Markus Klotzbuecher | aa21921 | 2006-05-30 16:56:14 +0200 | [diff] [blame] | 82 | |
Marek Vasut | 2db1e96 | 2010-09-09 09:50:39 +0200 | [diff] [blame] | 83 | int usb_cpu_init_fail(void) |
| 84 | { |
| 85 | return usb_cpu_stop(); |
| 86 | } |
| 87 | |
Marek Vasut | 85cc88a | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 88 | # endif /* defined(CONFIG_CPU_MONAHANS) || defined(CONFIG_CPU_PXA27X) */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 89 | #endif /* defined(CONFIG_USB_OHCI) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT) */ |