Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 1 | /* |
Hans de Goede | 8697909 | 2015-04-27 14:54:47 +0200 | [diff] [blame] | 2 | * Sunxi ehci glue |
Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 3 | * |
Hans de Goede | 8697909 | 2015-04-27 14:54:47 +0200 | [diff] [blame] | 4 | * Copyright (C) 2015 Hans de Goede <hdegoede@redhat.com> |
| 5 | * Copyright (C) 2014 Roman Byshko <rbyshko@gmail.com> |
Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 6 | * |
| 7 | * Based on code from |
| 8 | * Allwinner Technology Co., Ltd. <www.allwinnertech.com> |
| 9 | * |
| 10 | * SPDX-License-Identifier: GPL-2.0+ |
| 11 | */ |
| 12 | |
Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 13 | #include <common.h> |
Hans de Goede | 7e5aabd | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 14 | #include <asm/arch/clock.h> |
Hans de Goede | 26a9005 | 2015-04-27 15:05:10 +0200 | [diff] [blame] | 15 | #include <asm/arch/usb_phy.h> |
Hans de Goede | 7e5aabd | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 16 | #include <asm/io.h> |
Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 17 | #include "ehci.h" |
| 18 | |
Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 19 | int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr, |
| 20 | struct ehci_hcor **hcor) |
| 21 | { |
Hans de Goede | 7e5aabd | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 22 | struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
Hans de Goede | 1168e09 | 2015-04-27 16:50:04 +0200 | [diff] [blame] | 23 | int ahb_gate_offset; |
Hans de Goede | af4273b | 2014-11-07 16:09:00 +0100 | [diff] [blame] | 24 | |
Hans de Goede | 7e5aabd | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 25 | ahb_gate_offset = index ? AHB_GATE_OFFSET_USB_EHCI1 : |
| 26 | AHB_GATE_OFFSET_USB_EHCI0; |
| 27 | setbits_le32(&ccm->ahb_gate0, 1 << ahb_gate_offset); |
| 28 | #ifdef CONFIG_SUNXI_GEN_SUN6I |
| 29 | setbits_le32(&ccm->ahb_reset0_cfg, 1 << ahb_gate_offset); |
| 30 | #endif |
| 31 | |
Hans de Goede | 8697909 | 2015-04-27 14:54:47 +0200 | [diff] [blame] | 32 | sunxi_usb_phy_init(index + 1); |
| 33 | sunxi_usb_phy_power_on(index + 1); |
Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 34 | |
Hans de Goede | 1f4e1d1 | 2015-04-27 14:36:23 +0200 | [diff] [blame] | 35 | if (index == 0) |
| 36 | *hccr = (void *)SUNXI_USB1_BASE; |
| 37 | else |
| 38 | *hccr = (void *)SUNXI_USB2_BASE; |
Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 39 | |
| 40 | *hcor = (struct ehci_hcor *)((uint32_t) *hccr |
| 41 | + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); |
| 42 | |
| 43 | debug("sunxi-ehci: init hccr %x and hcor %x hc_length %d\n", |
| 44 | (uint32_t)*hccr, (uint32_t)*hcor, |
| 45 | (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); |
| 46 | |
Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | int ehci_hcd_stop(int index) |
| 51 | { |
Hans de Goede | 7e5aabd | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 52 | struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
| 53 | int ahb_gate_offset; |
| 54 | |
Hans de Goede | 8697909 | 2015-04-27 14:54:47 +0200 | [diff] [blame] | 55 | sunxi_usb_phy_power_off(index + 1); |
| 56 | sunxi_usb_phy_exit(index + 1); |
Hans de Goede | ea7851d | 2014-10-31 17:04:52 +0100 | [diff] [blame] | 57 | |
Hans de Goede | 7e5aabd | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 58 | ahb_gate_offset = index ? AHB_GATE_OFFSET_USB_EHCI1 : |
| 59 | AHB_GATE_OFFSET_USB_EHCI0; |
| 60 | #ifdef CONFIG_SUNXI_GEN_SUN6I |
| 61 | clrbits_le32(&ccm->ahb_reset0_cfg, 1 << ahb_gate_offset); |
| 62 | #endif |
| 63 | clrbits_le32(&ccm->ahb_gate0, 1 << ahb_gate_offset); |
| 64 | |
Hans de Goede | 1168e09 | 2015-04-27 16:50:04 +0200 | [diff] [blame] | 65 | return 0; |
Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 66 | } |