Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Álvaro Fernández Rojas | dbb6baf | 2018-02-04 21:10:13 +0100 | [diff] [blame] | 2 | /* |
Álvaro Fernández Rojas | f02a81a | 2018-03-22 19:39:42 +0100 | [diff] [blame] | 3 | * Copyright (C) 2018 Álvaro Fernández Rojas <noltari@gmail.com> |
Álvaro Fernández Rojas | dbb6baf | 2018-02-04 21:10:13 +0100 | [diff] [blame] | 4 | * |
| 5 | * Derived from linux/arch/mips/bcm63xx/usb-common.c: |
| 6 | * Copyright 2008 Maxime Bizon <mbizon@freebox.fr> |
| 7 | * Copyright 2013 Florian Fainelli <florian@openwrt.org> |
Álvaro Fernández Rojas | dbb6baf | 2018-02-04 21:10:13 +0100 | [diff] [blame] | 8 | */ |
| 9 | |
Álvaro Fernández Rojas | dbb6baf | 2018-02-04 21:10:13 +0100 | [diff] [blame] | 10 | #include <clk.h> |
| 11 | #include <dm.h> |
| 12 | #include <generic-phy.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 14 | #include <malloc.h> |
Álvaro Fernández Rojas | dbb6baf | 2018-02-04 21:10:13 +0100 | [diff] [blame] | 15 | #include <power-domain.h> |
| 16 | #include <reset.h> |
| 17 | #include <asm/io.h> |
| 18 | #include <dm/device.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 19 | #include <linux/bitops.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 20 | #include <linux/delay.h> |
Álvaro Fernández Rojas | dbb6baf | 2018-02-04 21:10:13 +0100 | [diff] [blame] | 21 | |
| 22 | /* USBH PLL Control register */ |
| 23 | #define USBH_PLL_REG 0x18 |
| 24 | #define USBH_PLL_IDDQ_PWRDN BIT(9) |
| 25 | #define USBH_PLL_PWRDN_DELAY BIT(10) |
| 26 | |
| 27 | /* USBH Swap Control register */ |
| 28 | #define USBH_SWAP_REG 0x1c |
| 29 | #define USBH_SWAP_OHCI_DATA BIT(0) |
| 30 | #define USBH_SWAP_OHCI_ENDIAN BIT(1) |
| 31 | #define USBH_SWAP_EHCI_DATA BIT(3) |
| 32 | #define USBH_SWAP_EHCI_ENDIAN BIT(4) |
| 33 | |
| 34 | /* USBH Setup register */ |
| 35 | #define USBH_SETUP_REG 0x28 |
| 36 | #define USBH_SETUP_IOC BIT(4) |
| 37 | #define USBH_SETUP_IPP BIT(5) |
| 38 | |
| 39 | struct bcm6368_usbh_hw { |
| 40 | uint32_t setup_clr; |
| 41 | uint32_t pll_clr; |
| 42 | }; |
| 43 | |
| 44 | struct bcm6368_usbh_priv { |
| 45 | const struct bcm6368_usbh_hw *hw; |
| 46 | void __iomem *regs; |
| 47 | }; |
| 48 | |
| 49 | static int bcm6368_usbh_init(struct phy *phy) |
| 50 | { |
| 51 | struct bcm6368_usbh_priv *priv = dev_get_priv(phy->dev); |
| 52 | const struct bcm6368_usbh_hw *hw = priv->hw; |
| 53 | |
| 54 | /* configure to work in native cpu endian */ |
| 55 | clrsetbits_be32(priv->regs + USBH_SWAP_REG, |
| 56 | USBH_SWAP_EHCI_ENDIAN | USBH_SWAP_OHCI_ENDIAN, |
| 57 | USBH_SWAP_EHCI_DATA | USBH_SWAP_OHCI_DATA); |
| 58 | |
| 59 | /* setup config */ |
| 60 | if (hw->setup_clr) |
| 61 | clrbits_be32(priv->regs + USBH_SETUP_REG, hw->setup_clr); |
| 62 | |
| 63 | setbits_be32(priv->regs + USBH_SETUP_REG, USBH_SETUP_IOC); |
| 64 | |
| 65 | /* enable pll control */ |
| 66 | if (hw->pll_clr) |
| 67 | clrbits_be32(priv->regs + USBH_PLL_REG, hw->pll_clr); |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | static struct phy_ops bcm6368_usbh_ops = { |
| 73 | .init = bcm6368_usbh_init, |
| 74 | }; |
| 75 | |
| 76 | static const struct bcm6368_usbh_hw bcm6328_hw = { |
| 77 | .pll_clr = USBH_PLL_IDDQ_PWRDN | USBH_PLL_PWRDN_DELAY, |
| 78 | .setup_clr = 0, |
| 79 | }; |
| 80 | |
| 81 | static const struct bcm6368_usbh_hw bcm6362_hw = { |
| 82 | .pll_clr = 0, |
| 83 | .setup_clr = 0, |
| 84 | }; |
| 85 | |
| 86 | static const struct bcm6368_usbh_hw bcm6368_hw = { |
| 87 | .pll_clr = 0, |
| 88 | .setup_clr = 0, |
| 89 | }; |
| 90 | |
| 91 | static const struct bcm6368_usbh_hw bcm63268_hw = { |
| 92 | .pll_clr = USBH_PLL_IDDQ_PWRDN | USBH_PLL_PWRDN_DELAY, |
| 93 | .setup_clr = USBH_SETUP_IPP, |
| 94 | }; |
| 95 | |
| 96 | static const struct udevice_id bcm6368_usbh_ids[] = { |
| 97 | { |
| 98 | .compatible = "brcm,bcm6328-usbh", |
| 99 | .data = (ulong)&bcm6328_hw, |
| 100 | }, { |
| 101 | .compatible = "brcm,bcm6362-usbh", |
| 102 | .data = (ulong)&bcm6362_hw, |
| 103 | }, { |
| 104 | .compatible = "brcm,bcm6368-usbh", |
| 105 | .data = (ulong)&bcm6368_hw, |
| 106 | }, { |
| 107 | .compatible = "brcm,bcm63268-usbh", |
| 108 | .data = (ulong)&bcm63268_hw, |
| 109 | }, { /* sentinel */ } |
| 110 | }; |
| 111 | |
| 112 | static int bcm6368_usbh_probe(struct udevice *dev) |
| 113 | { |
| 114 | struct bcm6368_usbh_priv *priv = dev_get_priv(dev); |
| 115 | const struct bcm6368_usbh_hw *hw = |
| 116 | (const struct bcm6368_usbh_hw *)dev_get_driver_data(dev); |
| 117 | #if defined(CONFIG_POWER_DOMAIN) |
| 118 | struct power_domain pwr_dom; |
| 119 | #endif |
| 120 | struct reset_ctl rst_ctl; |
| 121 | struct clk clk; |
Álvaro Fernández Rojas | dbb6baf | 2018-02-04 21:10:13 +0100 | [diff] [blame] | 122 | int ret; |
| 123 | |
Álvaro Fernández Rojas | f02a81a | 2018-03-22 19:39:42 +0100 | [diff] [blame] | 124 | priv->regs = dev_remap_addr(dev); |
| 125 | if (!priv->regs) |
Álvaro Fernández Rojas | dbb6baf | 2018-02-04 21:10:13 +0100 | [diff] [blame] | 126 | return -EINVAL; |
| 127 | |
Álvaro Fernández Rojas | dbb6baf | 2018-02-04 21:10:13 +0100 | [diff] [blame] | 128 | priv->hw = hw; |
| 129 | |
| 130 | /* enable usbh clock */ |
| 131 | ret = clk_get_by_name(dev, "usbh", &clk); |
| 132 | if (ret < 0) |
| 133 | return ret; |
| 134 | |
| 135 | ret = clk_enable(&clk); |
| 136 | if (ret < 0) |
| 137 | return ret; |
| 138 | |
Álvaro Fernández Rojas | dbb6baf | 2018-02-04 21:10:13 +0100 | [diff] [blame] | 139 | #if defined(CONFIG_POWER_DOMAIN) |
| 140 | /* enable power domain */ |
| 141 | ret = power_domain_get(dev, &pwr_dom); |
| 142 | if (ret < 0) |
| 143 | return ret; |
| 144 | |
| 145 | ret = power_domain_on(&pwr_dom); |
| 146 | if (ret < 0) |
| 147 | return ret; |
| 148 | |
| 149 | ret = power_domain_free(&pwr_dom); |
| 150 | if (ret < 0) |
| 151 | return ret; |
| 152 | #endif |
| 153 | |
| 154 | /* perform reset */ |
| 155 | ret = reset_get_by_index(dev, 0, &rst_ctl); |
| 156 | if (ret < 0) |
| 157 | return ret; |
| 158 | |
| 159 | ret = reset_deassert(&rst_ctl); |
| 160 | if (ret < 0) |
| 161 | return ret; |
| 162 | |
| 163 | ret = reset_free(&rst_ctl); |
| 164 | if (ret < 0) |
| 165 | return ret; |
| 166 | |
| 167 | /* enable usb_ref clock */ |
| 168 | ret = clk_get_by_name(dev, "usb_ref", &clk); |
| 169 | if (!ret) { |
| 170 | ret = clk_enable(&clk); |
| 171 | if (ret < 0) |
| 172 | return ret; |
Álvaro Fernández Rojas | dbb6baf | 2018-02-04 21:10:13 +0100 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | mdelay(100); |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | U_BOOT_DRIVER(bcm6368_usbh) = { |
| 181 | .name = "bcm6368-usbh", |
| 182 | .id = UCLASS_PHY, |
| 183 | .of_match = bcm6368_usbh_ids, |
| 184 | .ops = &bcm6368_usbh_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 185 | .priv_auto = sizeof(struct bcm6368_usbh_priv), |
Álvaro Fernández Rojas | dbb6baf | 2018-02-04 21:10:13 +0100 | [diff] [blame] | 186 | .probe = bcm6368_usbh_probe, |
| 187 | }; |