blob: 1297fdb6a7112eb70e90643318e266002d7fad0c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Roman Byshko637fbb62014-07-27 19:32:44 +02002/*
Hans de Goede86979092015-04-27 14:54:47 +02003 * Sunxi ehci glue
Roman Byshko637fbb62014-07-27 19:32:44 +02004 *
Hans de Goede86979092015-04-27 14:54:47 +02005 * Copyright (C) 2015 Hans de Goede <hdegoede@redhat.com>
6 * Copyright (C) 2014 Roman Byshko <rbyshko@gmail.com>
Roman Byshko637fbb62014-07-27 19:32:44 +02007 *
8 * Based on code from
9 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
Roman Byshko637fbb62014-07-27 19:32:44 +020010 */
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>
Hans de Goede26a90052015-04-27 15:05:10 +020014#include <asm/arch/usb_phy.h>
Hans de Goede7e5aabd2015-04-27 11:44:22 +020015#include <asm/io.h>
Hans de Goede4dba1082015-05-10 14:10:26 +020016#include <dm.h>
Roman Byshko637fbb62014-07-27 19:32:44 +020017#include "ehci.h"
18
Hans de Goede8b6ab7d2016-03-21 14:44:35 +010019#ifdef CONFIG_SUNXI_GEN_SUN4I
20#define BASE_DIST 0x8000
21#define AHB_CLK_DIST 2
22#else
23#define BASE_DIST 0x1000
24#define AHB_CLK_DIST 1
25#endif
26
Hans de Goede4dba1082015-05-10 14:10:26 +020027struct ehci_sunxi_priv {
28 struct ehci_ctrl ehci;
29 int ahb_gate_mask; /* Mask of ahb_gate0 clk gate bits for this hcd */
30 int phy_index; /* Index of the usb-phy attached to this hcd */
31};
32
33static int ehci_usb_probe(struct udevice *dev)
Roman Byshko637fbb62014-07-27 19:32:44 +020034{
Hans de Goede7e5aabd2015-04-27 11:44:22 +020035 struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
Hans de Goede4dba1082015-05-10 14:10:26 +020036 struct usb_platdata *plat = dev_get_platdata(dev);
37 struct ehci_sunxi_priv *priv = dev_get_priv(dev);
Simon Glassba1dea42017-05-17 17:18:05 -060038 struct ehci_hccr *hccr = (struct ehci_hccr *)devfdt_get_addr(dev);
Hans de Goede4dba1082015-05-10 14:10:26 +020039 struct ehci_hcor *hcor;
Hans de Goede52b5e5a2016-04-09 15:00:52 +020040 int extra_ahb_gate_mask = 0;
Hans de Goede4dba1082015-05-10 14:10:26 +020041
42 /*
43 * This should go away once we've moved to the driver model for
44 * clocks resp. phys.
45 */
Jelle van der Waaa1f5d112016-02-09 23:59:33 +010046 priv->ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0;
Andre Przywara5fb97432017-02-16 01:20:27 +000047#if defined(CONFIG_MACH_SUNXI_H3_H5) || defined(CONFIG_MACH_SUN50I)
Hans de Goede52b5e5a2016-04-09 15:00:52 +020048 extra_ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_OHCI0;
Jelle van der Waaa1f5d112016-02-09 23:59:33 +010049#endif
Amit Singh Tomarbd732d02016-10-21 02:24:30 +010050 priv->phy_index = ((uintptr_t)hccr - SUNXI_USB1_BASE) / BASE_DIST;
Hans de Goede8b6ab7d2016-03-21 14:44:35 +010051 priv->ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
Hans de Goede52b5e5a2016-04-09 15:00:52 +020052 extra_ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST;
Hans de Goede8b6ab7d2016-03-21 14:44:35 +010053 priv->phy_index++; /* Non otg phys start at 1 */
Hans de Goedeaf4273b2014-11-07 16:09:00 +010054
Hans de Goede52b5e5a2016-04-09 15:00:52 +020055 setbits_le32(&ccm->ahb_gate0,
56 priv->ahb_gate_mask | extra_ahb_gate_mask);
Hans de Goede7e5aabd2015-04-27 11:44:22 +020057#ifdef CONFIG_SUNXI_GEN_SUN6I
Hans de Goede52b5e5a2016-04-09 15:00:52 +020058 setbits_le32(&ccm->ahb_reset0_cfg,
59 priv->ahb_gate_mask | extra_ahb_gate_mask);
Hans de Goede7e5aabd2015-04-27 11:44:22 +020060#endif
61
Hans de Goede4dba1082015-05-10 14:10:26 +020062 sunxi_usb_phy_init(priv->phy_index);
63 sunxi_usb_phy_power_on(priv->phy_index);
Roman Byshko637fbb62014-07-27 19:32:44 +020064
Amit Singh Tomarbd732d02016-10-21 02:24:30 +010065 hcor = (struct ehci_hcor *)((uintptr_t)hccr +
Hans de Goede4dba1082015-05-10 14:10:26 +020066 HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
Roman Byshko637fbb62014-07-27 19:32:44 +020067
Hans de Goede4dba1082015-05-10 14:10:26 +020068 return ehci_register(dev, hccr, hcor, NULL, 0, plat->init_type);
Roman Byshko637fbb62014-07-27 19:32:44 +020069}
70
Hans de Goede4dba1082015-05-10 14:10:26 +020071static int ehci_usb_remove(struct udevice *dev)
Roman Byshko637fbb62014-07-27 19:32:44 +020072{
Hans de Goede7e5aabd2015-04-27 11:44:22 +020073 struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
Hans de Goede4dba1082015-05-10 14:10:26 +020074 struct ehci_sunxi_priv *priv = dev_get_priv(dev);
75 int ret;
76
77 ret = ehci_deregister(dev);
78 if (ret)
79 return ret;
Hans de Goede7e5aabd2015-04-27 11:44:22 +020080
Hans de Goede4dba1082015-05-10 14:10:26 +020081 sunxi_usb_phy_exit(priv->phy_index);
Hans de Goedeea7851d2014-10-31 17:04:52 +010082
Hans de Goede7e5aabd2015-04-27 11:44:22 +020083#ifdef CONFIG_SUNXI_GEN_SUN6I
Hans de Goede4dba1082015-05-10 14:10:26 +020084 clrbits_le32(&ccm->ahb_reset0_cfg, priv->ahb_gate_mask);
Hans de Goede7e5aabd2015-04-27 11:44:22 +020085#endif
Hans de Goede4dba1082015-05-10 14:10:26 +020086 clrbits_le32(&ccm->ahb_gate0, priv->ahb_gate_mask);
Hans de Goede7e5aabd2015-04-27 11:44:22 +020087
Hans de Goede1168e092015-04-27 16:50:04 +020088 return 0;
Roman Byshko637fbb62014-07-27 19:32:44 +020089}
Hans de Goede4dba1082015-05-10 14:10:26 +020090
91static const struct udevice_id ehci_usb_ids[] = {
92 { .compatible = "allwinner,sun4i-a10-ehci", },
93 { .compatible = "allwinner,sun5i-a13-ehci", },
94 { .compatible = "allwinner,sun6i-a31-ehci", },
95 { .compatible = "allwinner,sun7i-a20-ehci", },
96 { .compatible = "allwinner,sun8i-a23-ehci", },
Chen-Yu Tsaid0f38132016-03-30 00:26:53 +080097 { .compatible = "allwinner,sun8i-a83t-ehci", },
Jelle van der Waaa1f5d112016-02-09 23:59:33 +010098 { .compatible = "allwinner,sun8i-h3-ehci", },
Hans de Goede4dba1082015-05-10 14:10:26 +020099 { .compatible = "allwinner,sun9i-a80-ehci", },
Amit Singh Tomarbd732d02016-10-21 02:24:30 +0100100 { .compatible = "allwinner,sun50i-a64-ehci", },
Hans de Goede4dba1082015-05-10 14:10:26 +0200101 { }
102};
103
Marek Vasutad693ce2015-11-30 18:15:33 +0100104U_BOOT_DRIVER(ehci_sunxi) = {
Hans de Goede4dba1082015-05-10 14:10:26 +0200105 .name = "ehci_sunxi",
106 .id = UCLASS_USB,
107 .of_match = ehci_usb_ids,
108 .probe = ehci_usb_probe,
109 .remove = ehci_usb_remove,
110 .ops = &ehci_usb_ops,
111 .platdata_auto_alloc_size = sizeof(struct usb_platdata),
112 .priv_auto_alloc_size = sizeof(struct ehci_sunxi_priv),
113 .flags = DM_FLAG_ALLOC_PRIV_DMA,
114};