Roman Byshko | 8d15400 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 1 | /* |
Hans de Goede | 7b79865 | 2015-04-27 14:54:47 +0200 | [diff] [blame^] | 2 | * Sunxi ehci glue |
Roman Byshko | 8d15400 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 3 | * |
Hans de Goede | 7b79865 | 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 | 8d15400 | 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 | 8d15400 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 13 | #include <common.h> |
Hans de Goede | 375de01 | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 14 | #include <asm/arch/clock.h> |
| 15 | #include <asm/arch/usbc.h> |
| 16 | #include <asm/io.h> |
Roman Byshko | 8d15400 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 17 | #include "ehci.h" |
| 18 | |
Roman Byshko | 8d15400 | 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 | 375de01 | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 22 | struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
| 23 | int ahb_gate_offset, err; |
Roman Byshko | 8d15400 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 24 | |
Hans de Goede | 7b79865 | 2015-04-27 14:54:47 +0200 | [diff] [blame^] | 25 | err = sunxi_usb_phy_probe(index + 1); |
Hans de Goede | 0eccec4 | 2015-01-07 15:08:43 +0100 | [diff] [blame] | 26 | if (err) |
| 27 | return err; |
Hans de Goede | 115200c | 2014-11-07 16:09:00 +0100 | [diff] [blame] | 28 | |
Hans de Goede | 375de01 | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 29 | ahb_gate_offset = index ? AHB_GATE_OFFSET_USB_EHCI1 : |
| 30 | AHB_GATE_OFFSET_USB_EHCI0; |
| 31 | setbits_le32(&ccm->ahb_gate0, 1 << ahb_gate_offset); |
| 32 | #ifdef CONFIG_SUNXI_GEN_SUN6I |
| 33 | setbits_le32(&ccm->ahb_reset0_cfg, 1 << ahb_gate_offset); |
| 34 | #endif |
| 35 | |
Hans de Goede | 7b79865 | 2015-04-27 14:54:47 +0200 | [diff] [blame^] | 36 | sunxi_usb_phy_init(index + 1); |
| 37 | sunxi_usb_phy_power_on(index + 1); |
Roman Byshko | 8d15400 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 38 | |
Hans de Goede | a781c97 | 2015-04-27 14:36:23 +0200 | [diff] [blame] | 39 | if (index == 0) |
| 40 | *hccr = (void *)SUNXI_USB1_BASE; |
| 41 | else |
| 42 | *hccr = (void *)SUNXI_USB2_BASE; |
Roman Byshko | 8d15400 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 43 | |
| 44 | *hcor = (struct ehci_hcor *)((uint32_t) *hccr |
| 45 | + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); |
| 46 | |
| 47 | debug("sunxi-ehci: init hccr %x and hcor %x hc_length %d\n", |
| 48 | (uint32_t)*hccr, (uint32_t)*hcor, |
| 49 | (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); |
| 50 | |
Roman Byshko | 8d15400 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | int ehci_hcd_stop(int index) |
| 55 | { |
Hans de Goede | 375de01 | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 56 | struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
| 57 | int ahb_gate_offset; |
| 58 | |
Hans de Goede | 7b79865 | 2015-04-27 14:54:47 +0200 | [diff] [blame^] | 59 | sunxi_usb_phy_power_off(index + 1); |
| 60 | sunxi_usb_phy_exit(index + 1); |
Roman Byshko | 8d15400 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 61 | |
Hans de Goede | 375de01 | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 62 | ahb_gate_offset = index ? AHB_GATE_OFFSET_USB_EHCI1 : |
| 63 | AHB_GATE_OFFSET_USB_EHCI0; |
| 64 | #ifdef CONFIG_SUNXI_GEN_SUN6I |
| 65 | clrbits_le32(&ccm->ahb_reset0_cfg, 1 << ahb_gate_offset); |
| 66 | #endif |
| 67 | clrbits_le32(&ccm->ahb_gate0, 1 << ahb_gate_offset); |
| 68 | |
Hans de Goede | 7b79865 | 2015-04-27 14:54:47 +0200 | [diff] [blame^] | 69 | return sunxi_usb_phy_remove(index + 1); |
Roman Byshko | 8d15400 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 70 | } |