blob: 34130f8443c4bcab1567a6cfe57fd14710b6c157 [file] [log] [blame]
Roman Byshko637fbb62014-07-27 19:32:44 +02001/*
Hans de Goede86979092015-04-27 14:54:47 +02002 * Sunxi ehci glue
Roman Byshko637fbb62014-07-27 19:32:44 +02003 *
Hans de Goede86979092015-04-27 14:54:47 +02004 * Copyright (C) 2015 Hans de Goede <hdegoede@redhat.com>
5 * Copyright (C) 2014 Roman Byshko <rbyshko@gmail.com>
Roman Byshko637fbb62014-07-27 19:32:44 +02006 *
7 * Based on code from
8 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
9 *
10 * SPDX-License-Identifier: GPL-2.0+
11 */
12
Roman Byshko637fbb62014-07-27 19:32:44 +020013#include <common.h>
Hans de Goede7e5aabd2015-04-27 11:44:22 +020014#include <asm/arch/clock.h>
Hans de Goede26a90052015-04-27 15:05:10 +020015#include <asm/arch/usb_phy.h>
Hans de Goede7e5aabd2015-04-27 11:44:22 +020016#include <asm/io.h>
Hans de Goede4dba1082015-05-10 14:10:26 +020017#include <dm.h>
Roman Byshko637fbb62014-07-27 19:32:44 +020018#include "ehci.h"
19
Hans de Goede4dba1082015-05-10 14:10:26 +020020struct ehci_sunxi_priv {
21 struct ehci_ctrl ehci;
22 int ahb_gate_mask; /* Mask of ahb_gate0 clk gate bits for this hcd */
23 int phy_index; /* Index of the usb-phy attached to this hcd */
24};
25
26static int ehci_usb_probe(struct udevice *dev)
Roman Byshko637fbb62014-07-27 19:32:44 +020027{
Hans de Goede7e5aabd2015-04-27 11:44:22 +020028 struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
Hans de Goede4dba1082015-05-10 14:10:26 +020029 struct usb_platdata *plat = dev_get_platdata(dev);
30 struct ehci_sunxi_priv *priv = dev_get_priv(dev);
31 struct ehci_hccr *hccr = (struct ehci_hccr *)dev_get_addr(dev);
32 struct ehci_hcor *hcor;
33
34 /*
35 * This should go away once we've moved to the driver model for
36 * clocks resp. phys.
37 */
38 if (hccr == (void *)SUNXI_USB1_BASE) {
39 priv->ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0;
40 priv->phy_index = 1;
41 } else {
42 priv->ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI1;
43 priv->phy_index = 2;
44 }
Hans de Goedeaf4273b2014-11-07 16:09:00 +010045
Hans de Goede4dba1082015-05-10 14:10:26 +020046 setbits_le32(&ccm->ahb_gate0, priv->ahb_gate_mask);
Hans de Goede7e5aabd2015-04-27 11:44:22 +020047#ifdef CONFIG_SUNXI_GEN_SUN6I
Hans de Goede4dba1082015-05-10 14:10:26 +020048 setbits_le32(&ccm->ahb_reset0_cfg, priv->ahb_gate_mask);
Hans de Goede7e5aabd2015-04-27 11:44:22 +020049#endif
50
Hans de Goede4dba1082015-05-10 14:10:26 +020051 sunxi_usb_phy_init(priv->phy_index);
52 sunxi_usb_phy_power_on(priv->phy_index);
Roman Byshko637fbb62014-07-27 19:32:44 +020053
Hans de Goede4dba1082015-05-10 14:10:26 +020054 hcor = (struct ehci_hcor *)((uint32_t)hccr +
55 HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
Roman Byshko637fbb62014-07-27 19:32:44 +020056
Hans de Goede4dba1082015-05-10 14:10:26 +020057 return ehci_register(dev, hccr, hcor, NULL, 0, plat->init_type);
Roman Byshko637fbb62014-07-27 19:32:44 +020058}
59
Hans de Goede4dba1082015-05-10 14:10:26 +020060static int ehci_usb_remove(struct udevice *dev)
Roman Byshko637fbb62014-07-27 19:32:44 +020061{
Hans de Goede7e5aabd2015-04-27 11:44:22 +020062 struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
Hans de Goede4dba1082015-05-10 14:10:26 +020063 struct ehci_sunxi_priv *priv = dev_get_priv(dev);
64 int ret;
65
66 ret = ehci_deregister(dev);
67 if (ret)
68 return ret;
Hans de Goede7e5aabd2015-04-27 11:44:22 +020069
Hans de Goede4dba1082015-05-10 14:10:26 +020070 sunxi_usb_phy_power_off(priv->phy_index);
71 sunxi_usb_phy_exit(priv->phy_index);
Hans de Goedeea7851d2014-10-31 17:04:52 +010072
Hans de Goede7e5aabd2015-04-27 11:44:22 +020073#ifdef CONFIG_SUNXI_GEN_SUN6I
Hans de Goede4dba1082015-05-10 14:10:26 +020074 clrbits_le32(&ccm->ahb_reset0_cfg, priv->ahb_gate_mask);
Hans de Goede7e5aabd2015-04-27 11:44:22 +020075#endif
Hans de Goede4dba1082015-05-10 14:10:26 +020076 clrbits_le32(&ccm->ahb_gate0, priv->ahb_gate_mask);
Hans de Goede7e5aabd2015-04-27 11:44:22 +020077
Hans de Goede1168e092015-04-27 16:50:04 +020078 return 0;
Roman Byshko637fbb62014-07-27 19:32:44 +020079}
Hans de Goede4dba1082015-05-10 14:10:26 +020080
81static const struct udevice_id ehci_usb_ids[] = {
82 { .compatible = "allwinner,sun4i-a10-ehci", },
83 { .compatible = "allwinner,sun5i-a13-ehci", },
84 { .compatible = "allwinner,sun6i-a31-ehci", },
85 { .compatible = "allwinner,sun7i-a20-ehci", },
86 { .compatible = "allwinner,sun8i-a23-ehci", },
87 { .compatible = "allwinner,sun9i-a80-ehci", },
88 { }
89};
90
91U_BOOT_DRIVER(usb_ehci) = {
92 .name = "ehci_sunxi",
93 .id = UCLASS_USB,
94 .of_match = ehci_usb_ids,
95 .probe = ehci_usb_probe,
96 .remove = ehci_usb_remove,
97 .ops = &ehci_usb_ops,
98 .platdata_auto_alloc_size = sizeof(struct usb_platdata),
99 .priv_auto_alloc_size = sizeof(struct ehci_sunxi_priv),
100 .flags = DM_FLAG_ALLOC_PRIV_DMA,
101};