sunxi: usb: Move setup of host controller clocks to the host controller drivers
[platform/kernel/u-boot.git] / drivers / usb / host / ehci-sunxi.c
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
12 #include <common.h>
13 #include <asm/arch/clock.h>
14 #include <asm/arch/usbc.h>
15 #include <asm/io.h>
16 #include "ehci.h"
17
18 int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr,
19                 struct ehci_hcor **hcor)
20 {
21         struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
22         int ahb_gate_offset, err;
23
24         err = sunxi_usbc_request_resources(index + 1);
25         if (err)
26                 return err;
27
28         ahb_gate_offset = index ? AHB_GATE_OFFSET_USB_EHCI1 :
29                                   AHB_GATE_OFFSET_USB_EHCI0;
30         setbits_le32(&ccm->ahb_gate0, 1 << ahb_gate_offset);
31 #ifdef CONFIG_SUNXI_GEN_SUN6I
32         setbits_le32(&ccm->ahb_reset0_cfg, 1 << ahb_gate_offset);
33 #endif
34
35         sunxi_usbc_enable(index + 1);
36         sunxi_usbc_vbus_enable(index + 1);
37
38         *hccr = sunxi_usbc_get_io_base(index + 1);
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
47         return 0;
48 }
49
50 int ehci_hcd_stop(int index)
51 {
52         struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
53         int ahb_gate_offset;
54
55         sunxi_usbc_vbus_disable(index + 1);
56         sunxi_usbc_disable(index + 1);
57
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
65         return sunxi_usbc_free_resources(index + 1);
66 }