Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 1 | /* |
Hans de Goede | 8697909 | 2015-04-27 14:54:47 +0200 | [diff] [blame] | 2 | * Sunxi ehci glue |
Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 3 | * |
Hans de Goede | 8697909 | 2015-04-27 14:54:47 +0200 | [diff] [blame] | 4 | * Copyright (C) 2015 Hans de Goede <hdegoede@redhat.com> |
| 5 | * Copyright (C) 2014 Roman Byshko <rbyshko@gmail.com> |
Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 6 | * |
| 7 | * Based on code from |
| 8 | * Allwinner Technology Co., Ltd. <www.allwinnertech.com> |
| 9 | * |
| 10 | * SPDX-License-Identifier: GPL-2.0+ |
| 11 | */ |
| 12 | |
Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 13 | #include <common.h> |
Hans de Goede | 7e5aabd | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 14 | #include <asm/arch/clock.h> |
Hans de Goede | 26a9005 | 2015-04-27 15:05:10 +0200 | [diff] [blame] | 15 | #include <asm/arch/usb_phy.h> |
Hans de Goede | 7e5aabd | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 16 | #include <asm/io.h> |
Hans de Goede | 4dba108 | 2015-05-10 14:10:26 +0200 | [diff] [blame] | 17 | #include <dm.h> |
Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 18 | #include "ehci.h" |
| 19 | |
Hans de Goede | 8b6ab7d | 2016-03-21 14:44:35 +0100 | [diff] [blame] | 20 | #ifdef CONFIG_SUNXI_GEN_SUN4I |
| 21 | #define BASE_DIST 0x8000 |
| 22 | #define AHB_CLK_DIST 2 |
| 23 | #else |
| 24 | #define BASE_DIST 0x1000 |
| 25 | #define AHB_CLK_DIST 1 |
| 26 | #endif |
| 27 | |
Hans de Goede | 4dba108 | 2015-05-10 14:10:26 +0200 | [diff] [blame] | 28 | struct ehci_sunxi_priv { |
| 29 | struct ehci_ctrl ehci; |
| 30 | int ahb_gate_mask; /* Mask of ahb_gate0 clk gate bits for this hcd */ |
| 31 | int phy_index; /* Index of the usb-phy attached to this hcd */ |
| 32 | }; |
| 33 | |
| 34 | static int ehci_usb_probe(struct udevice *dev) |
Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 35 | { |
Hans de Goede | 7e5aabd | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 36 | struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
Hans de Goede | 4dba108 | 2015-05-10 14:10:26 +0200 | [diff] [blame] | 37 | struct usb_platdata *plat = dev_get_platdata(dev); |
| 38 | struct ehci_sunxi_priv *priv = dev_get_priv(dev); |
| 39 | struct ehci_hccr *hccr = (struct ehci_hccr *)dev_get_addr(dev); |
| 40 | struct ehci_hcor *hcor; |
Hans de Goede | 52b5e5a | 2016-04-09 15:00:52 +0200 | [diff] [blame] | 41 | int extra_ahb_gate_mask = 0; |
Hans de Goede | 4dba108 | 2015-05-10 14:10:26 +0200 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * This should go away once we've moved to the driver model for |
| 45 | * clocks resp. phys. |
| 46 | */ |
Jelle van der Waa | a1f5d11 | 2016-02-09 23:59:33 +0100 | [diff] [blame] | 47 | priv->ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_EHCI0; |
Andre Przywara | 5fb9743 | 2017-02-16 01:20:27 +0000 | [diff] [blame] | 48 | #if defined(CONFIG_MACH_SUNXI_H3_H5) || defined(CONFIG_MACH_SUN50I) |
Hans de Goede | 52b5e5a | 2016-04-09 15:00:52 +0200 | [diff] [blame] | 49 | extra_ahb_gate_mask = 1 << AHB_GATE_OFFSET_USB_OHCI0; |
Jelle van der Waa | a1f5d11 | 2016-02-09 23:59:33 +0100 | [diff] [blame] | 50 | #endif |
Amit Singh Tomar | bd732d0 | 2016-10-21 02:24:30 +0100 | [diff] [blame] | 51 | priv->phy_index = ((uintptr_t)hccr - SUNXI_USB1_BASE) / BASE_DIST; |
Hans de Goede | 8b6ab7d | 2016-03-21 14:44:35 +0100 | [diff] [blame] | 52 | priv->ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST; |
Hans de Goede | 52b5e5a | 2016-04-09 15:00:52 +0200 | [diff] [blame] | 53 | extra_ahb_gate_mask <<= priv->phy_index * AHB_CLK_DIST; |
Hans de Goede | 8b6ab7d | 2016-03-21 14:44:35 +0100 | [diff] [blame] | 54 | priv->phy_index++; /* Non otg phys start at 1 */ |
Hans de Goede | af4273b | 2014-11-07 16:09:00 +0100 | [diff] [blame] | 55 | |
Hans de Goede | 52b5e5a | 2016-04-09 15:00:52 +0200 | [diff] [blame] | 56 | setbits_le32(&ccm->ahb_gate0, |
| 57 | priv->ahb_gate_mask | extra_ahb_gate_mask); |
Hans de Goede | 7e5aabd | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 58 | #ifdef CONFIG_SUNXI_GEN_SUN6I |
Hans de Goede | 52b5e5a | 2016-04-09 15:00:52 +0200 | [diff] [blame] | 59 | setbits_le32(&ccm->ahb_reset0_cfg, |
| 60 | priv->ahb_gate_mask | extra_ahb_gate_mask); |
Hans de Goede | 7e5aabd | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 61 | #endif |
| 62 | |
Hans de Goede | 4dba108 | 2015-05-10 14:10:26 +0200 | [diff] [blame] | 63 | sunxi_usb_phy_init(priv->phy_index); |
| 64 | sunxi_usb_phy_power_on(priv->phy_index); |
Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 65 | |
Amit Singh Tomar | bd732d0 | 2016-10-21 02:24:30 +0100 | [diff] [blame] | 66 | hcor = (struct ehci_hcor *)((uintptr_t)hccr + |
Hans de Goede | 4dba108 | 2015-05-10 14:10:26 +0200 | [diff] [blame] | 67 | HC_LENGTH(ehci_readl(&hccr->cr_capbase))); |
Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 68 | |
Hans de Goede | 4dba108 | 2015-05-10 14:10:26 +0200 | [diff] [blame] | 69 | return ehci_register(dev, hccr, hcor, NULL, 0, plat->init_type); |
Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 70 | } |
| 71 | |
Hans de Goede | 4dba108 | 2015-05-10 14:10:26 +0200 | [diff] [blame] | 72 | static int ehci_usb_remove(struct udevice *dev) |
Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 73 | { |
Hans de Goede | 7e5aabd | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 74 | struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
Hans de Goede | 4dba108 | 2015-05-10 14:10:26 +0200 | [diff] [blame] | 75 | struct ehci_sunxi_priv *priv = dev_get_priv(dev); |
| 76 | int ret; |
| 77 | |
| 78 | ret = ehci_deregister(dev); |
| 79 | if (ret) |
| 80 | return ret; |
Hans de Goede | 7e5aabd | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 81 | |
Hans de Goede | 4dba108 | 2015-05-10 14:10:26 +0200 | [diff] [blame] | 82 | sunxi_usb_phy_exit(priv->phy_index); |
Hans de Goede | ea7851d | 2014-10-31 17:04:52 +0100 | [diff] [blame] | 83 | |
Hans de Goede | 7e5aabd | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 84 | #ifdef CONFIG_SUNXI_GEN_SUN6I |
Hans de Goede | 4dba108 | 2015-05-10 14:10:26 +0200 | [diff] [blame] | 85 | clrbits_le32(&ccm->ahb_reset0_cfg, priv->ahb_gate_mask); |
Hans de Goede | 7e5aabd | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 86 | #endif |
Hans de Goede | 4dba108 | 2015-05-10 14:10:26 +0200 | [diff] [blame] | 87 | clrbits_le32(&ccm->ahb_gate0, priv->ahb_gate_mask); |
Hans de Goede | 7e5aabd | 2015-04-27 11:44:22 +0200 | [diff] [blame] | 88 | |
Hans de Goede | 1168e09 | 2015-04-27 16:50:04 +0200 | [diff] [blame] | 89 | return 0; |
Roman Byshko | 637fbb6 | 2014-07-27 19:32:44 +0200 | [diff] [blame] | 90 | } |
Hans de Goede | 4dba108 | 2015-05-10 14:10:26 +0200 | [diff] [blame] | 91 | |
| 92 | static const struct udevice_id ehci_usb_ids[] = { |
| 93 | { .compatible = "allwinner,sun4i-a10-ehci", }, |
| 94 | { .compatible = "allwinner,sun5i-a13-ehci", }, |
| 95 | { .compatible = "allwinner,sun6i-a31-ehci", }, |
| 96 | { .compatible = "allwinner,sun7i-a20-ehci", }, |
| 97 | { .compatible = "allwinner,sun8i-a23-ehci", }, |
Chen-Yu Tsai | d0f3813 | 2016-03-30 00:26:53 +0800 | [diff] [blame] | 98 | { .compatible = "allwinner,sun8i-a83t-ehci", }, |
Jelle van der Waa | a1f5d11 | 2016-02-09 23:59:33 +0100 | [diff] [blame] | 99 | { .compatible = "allwinner,sun8i-h3-ehci", }, |
Hans de Goede | 4dba108 | 2015-05-10 14:10:26 +0200 | [diff] [blame] | 100 | { .compatible = "allwinner,sun9i-a80-ehci", }, |
Amit Singh Tomar | bd732d0 | 2016-10-21 02:24:30 +0100 | [diff] [blame] | 101 | { .compatible = "allwinner,sun50i-a64-ehci", }, |
Hans de Goede | 4dba108 | 2015-05-10 14:10:26 +0200 | [diff] [blame] | 102 | { } |
| 103 | }; |
| 104 | |
Marek Vasut | ad693ce | 2015-11-30 18:15:33 +0100 | [diff] [blame] | 105 | U_BOOT_DRIVER(ehci_sunxi) = { |
Hans de Goede | 4dba108 | 2015-05-10 14:10:26 +0200 | [diff] [blame] | 106 | .name = "ehci_sunxi", |
| 107 | .id = UCLASS_USB, |
| 108 | .of_match = ehci_usb_ids, |
| 109 | .probe = ehci_usb_probe, |
| 110 | .remove = ehci_usb_remove, |
| 111 | .ops = &ehci_usb_ops, |
| 112 | .platdata_auto_alloc_size = sizeof(struct usb_platdata), |
| 113 | .priv_auto_alloc_size = sizeof(struct ehci_sunxi_priv), |
| 114 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 115 | }; |