Roman Byshko | 8d15400 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 Roman Byshko |
| 3 | * |
| 4 | * Roman Byshko <rbyshko@gmail.com> |
| 5 | * |
| 6 | * Based on code from |
| 7 | * Allwinner Technology Co., Ltd. <www.allwinnertech.com> |
| 8 | * |
| 9 | * SPDX-License-Identifier: GPL-2.0+ |
| 10 | */ |
| 11 | |
Hans de Goede | 0eccec4 | 2015-01-07 15:08:43 +0100 | [diff] [blame] | 12 | #include <asm/arch/usbc.h> |
Roman Byshko | 8d15400 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 13 | #include <common.h> |
| 14 | #include "ehci.h" |
| 15 | |
Roman Byshko | 8d15400 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 16 | int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr, |
| 17 | struct ehci_hcor **hcor) |
| 18 | { |
Hans de Goede | 44fd591 | 2014-10-31 17:04:52 +0100 | [diff] [blame] | 19 | int err; |
Roman Byshko | 8d15400 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 20 | |
Hans de Goede | 0eccec4 | 2015-01-07 15:08:43 +0100 | [diff] [blame] | 21 | err = sunxi_usbc_request_resources(index + 1); |
| 22 | if (err) |
| 23 | return err; |
Hans de Goede | 115200c | 2014-11-07 16:09:00 +0100 | [diff] [blame] | 24 | |
Hans de Goede | 0eccec4 | 2015-01-07 15:08:43 +0100 | [diff] [blame] | 25 | sunxi_usbc_enable(index + 1); |
| 26 | sunxi_usbc_vbus_enable(index + 1); |
Roman Byshko | 8d15400 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 27 | |
Hans de Goede | 0eccec4 | 2015-01-07 15:08:43 +0100 | [diff] [blame] | 28 | *hccr = sunxi_usbc_get_io_base(index + 1); |
Roman Byshko | 8d15400 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 29 | |
| 30 | *hcor = (struct ehci_hcor *)((uint32_t) *hccr |
| 31 | + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); |
| 32 | |
| 33 | debug("sunxi-ehci: init hccr %x and hcor %x hc_length %d\n", |
| 34 | (uint32_t)*hccr, (uint32_t)*hcor, |
| 35 | (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); |
| 36 | |
Roman Byshko | 8d15400 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | int ehci_hcd_stop(int index) |
| 41 | { |
Hans de Goede | 0eccec4 | 2015-01-07 15:08:43 +0100 | [diff] [blame] | 42 | sunxi_usbc_vbus_disable(index + 1); |
| 43 | sunxi_usbc_disable(index + 1); |
Roman Byshko | 8d15400 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 44 | |
Hans de Goede | 0eccec4 | 2015-01-07 15:08:43 +0100 | [diff] [blame] | 45 | return sunxi_usbc_free_resources(index + 1); |
Roman Byshko | 8d15400 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 46 | } |