blob: 5de20f9d2c17e12302106b7aa8427919c79b76d1 [file] [log] [blame]
Roman Byshko637fbb62014-07-27 19:32:44 +02001/*
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
Roman Byshko637fbb62014-07-27 19:32:44 +020012#include <common.h>
Hans de Goede7e5aabd2015-04-27 11:44:22 +020013#include <asm/arch/clock.h>
14#include <asm/arch/usbc.h>
15#include <asm/io.h>
Roman Byshko637fbb62014-07-27 19:32:44 +020016#include "ehci.h"
17
Roman Byshko637fbb62014-07-27 19:32:44 +020018int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr,
19 struct ehci_hcor **hcor)
20{
Hans de Goede7e5aabd2015-04-27 11:44:22 +020021 struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
22 int ahb_gate_offset, err;
Roman Byshko637fbb62014-07-27 19:32:44 +020023
Hans de Goedea1441982015-01-07 15:08:43 +010024 err = sunxi_usbc_request_resources(index + 1);
25 if (err)
26 return err;
Hans de Goedeaf4273b2014-11-07 16:09:00 +010027
Hans de Goede7e5aabd2015-04-27 11:44:22 +020028 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
Hans de Goedea1441982015-01-07 15:08:43 +010035 sunxi_usbc_enable(index + 1);
36 sunxi_usbc_vbus_enable(index + 1);
Roman Byshko637fbb62014-07-27 19:32:44 +020037
Hans de Goede1f4e1d12015-04-27 14:36:23 +020038 if (index == 0)
39 *hccr = (void *)SUNXI_USB1_BASE;
40 else
41 *hccr = (void *)SUNXI_USB2_BASE;
Roman Byshko637fbb62014-07-27 19:32:44 +020042
43 *hcor = (struct ehci_hcor *)((uint32_t) *hccr
44 + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
45
46 debug("sunxi-ehci: init hccr %x and hcor %x hc_length %d\n",
47 (uint32_t)*hccr, (uint32_t)*hcor,
48 (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
49
Roman Byshko637fbb62014-07-27 19:32:44 +020050 return 0;
51}
52
53int ehci_hcd_stop(int index)
54{
Hans de Goede7e5aabd2015-04-27 11:44:22 +020055 struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
56 int ahb_gate_offset;
57
Hans de Goedea1441982015-01-07 15:08:43 +010058 sunxi_usbc_vbus_disable(index + 1);
59 sunxi_usbc_disable(index + 1);
Hans de Goedeea7851d2014-10-31 17:04:52 +010060
Hans de Goede7e5aabd2015-04-27 11:44:22 +020061 ahb_gate_offset = index ? AHB_GATE_OFFSET_USB_EHCI1 :
62 AHB_GATE_OFFSET_USB_EHCI0;
63#ifdef CONFIG_SUNXI_GEN_SUN6I
64 clrbits_le32(&ccm->ahb_reset0_cfg, 1 << ahb_gate_offset);
65#endif
66 clrbits_le32(&ccm->ahb_gate0, 1 << ahb_gate_offset);
67
Hans de Goedea1441982015-01-07 15:08:43 +010068 return sunxi_usbc_free_resources(index + 1);
Roman Byshko637fbb62014-07-27 19:32:44 +020069}