Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Álvaro Fernández Rojas | 66871b7 | 2018-02-04 21:11:15 +0100 | [diff] [blame] | 2 | /* |
Álvaro Fernández Rojas | c7bbeaf | 2018-03-22 19:39:43 +0100 | [diff] [blame] | 3 | * Copyright (C) 2018 Álvaro Fernández Rojas <noltari@gmail.com> |
Álvaro Fernández Rojas | 66871b7 | 2018-02-04 21:11:15 +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 | 66871b7 | 2018-02-04 21:11:15 +0100 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <clk.h> |
| 12 | #include <dm.h> |
| 13 | #include <generic-phy.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 14 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 15 | #include <malloc.h> |
Álvaro Fernández Rojas | 66871b7 | 2018-02-04 21:11:15 +0100 | [diff] [blame] | 16 | #include <power-domain.h> |
| 17 | #include <reset.h> |
| 18 | #include <asm/io.h> |
| 19 | #include <dm/device.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 20 | #include <linux/bitops.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 21 | #include <linux/delay.h> |
Álvaro Fernández Rojas | 66871b7 | 2018-02-04 21:11:15 +0100 | [diff] [blame] | 22 | |
| 23 | /* USBH Setup register */ |
| 24 | #define USBH_SETUP_REG 0x00 |
| 25 | #define USBH_SETUP_IOC BIT(4) |
| 26 | |
| 27 | /* USBH PLL Control register */ |
| 28 | #define USBH_PLL_REG 0x04 |
| 29 | #define USBH_PLL_SUSP_EN BIT(27) |
| 30 | #define USBH_PLL_IDDQ_PWRDN BIT(31) |
| 31 | |
| 32 | /* USBH Swap Control register */ |
| 33 | #define USBH_SWAP_REG 0x0c |
| 34 | #define USBH_SWAP_OHCI_DATA BIT(0) |
| 35 | #define USBH_SWAP_OHCI_ENDIAN BIT(1) |
| 36 | #define USBH_SWAP_EHCI_DATA BIT(3) |
| 37 | #define USBH_SWAP_EHCI_ENDIAN BIT(4) |
| 38 | |
| 39 | /* USBH Sim Control register */ |
| 40 | #define USBH_SIM_REG 0x20 |
| 41 | #define USBH_SIM_LADDR BIT(5) |
| 42 | |
| 43 | struct bcm6318_usbh_priv { |
| 44 | void __iomem *regs; |
| 45 | }; |
| 46 | |
| 47 | static int bcm6318_usbh_init(struct phy *phy) |
| 48 | { |
| 49 | struct bcm6318_usbh_priv *priv = dev_get_priv(phy->dev); |
| 50 | |
| 51 | /* enable pll control susp */ |
| 52 | setbits_be32(priv->regs + USBH_PLL_REG, USBH_PLL_SUSP_EN); |
| 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 | setbits_be32(priv->regs + USBH_SETUP_REG, USBH_SETUP_IOC); |
| 61 | |
| 62 | /* disable pll control pwrdn */ |
| 63 | clrbits_be32(priv->regs + USBH_PLL_REG, USBH_PLL_IDDQ_PWRDN); |
| 64 | |
| 65 | /* sim control config */ |
| 66 | setbits_be32(priv->regs + USBH_SIM_REG, USBH_SIM_LADDR); |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | static struct phy_ops bcm6318_usbh_ops = { |
| 72 | .init = bcm6318_usbh_init, |
| 73 | }; |
| 74 | |
| 75 | static const struct udevice_id bcm6318_usbh_ids[] = { |
| 76 | { .compatible = "brcm,bcm6318-usbh" }, |
| 77 | { /* sentinel */ } |
| 78 | }; |
| 79 | |
| 80 | static int bcm6318_usbh_probe(struct udevice *dev) |
| 81 | { |
| 82 | struct bcm6318_usbh_priv *priv = dev_get_priv(dev); |
| 83 | struct power_domain pwr_dom; |
| 84 | struct reset_ctl rst_ctl; |
| 85 | struct clk clk; |
Álvaro Fernández Rojas | 66871b7 | 2018-02-04 21:11:15 +0100 | [diff] [blame] | 86 | int ret; |
| 87 | |
Álvaro Fernández Rojas | c7bbeaf | 2018-03-22 19:39:43 +0100 | [diff] [blame] | 88 | priv->regs = dev_remap_addr(dev); |
| 89 | if (!priv->regs) |
Álvaro Fernández Rojas | 66871b7 | 2018-02-04 21:11:15 +0100 | [diff] [blame] | 90 | return -EINVAL; |
| 91 | |
Álvaro Fernández Rojas | 66871b7 | 2018-02-04 21:11:15 +0100 | [diff] [blame] | 92 | /* enable usbh clock */ |
| 93 | ret = clk_get_by_name(dev, "usbh", &clk); |
| 94 | if (ret < 0) |
| 95 | return ret; |
| 96 | |
| 97 | ret = clk_enable(&clk); |
| 98 | if (ret < 0) |
| 99 | return ret; |
| 100 | |
Álvaro Fernández Rojas | 66871b7 | 2018-02-04 21:11:15 +0100 | [diff] [blame] | 101 | /* enable power domain */ |
| 102 | ret = power_domain_get(dev, &pwr_dom); |
| 103 | if (ret < 0) |
| 104 | return ret; |
| 105 | |
| 106 | ret = power_domain_on(&pwr_dom); |
| 107 | if (ret < 0) |
| 108 | return ret; |
| 109 | |
| 110 | ret = power_domain_free(&pwr_dom); |
| 111 | if (ret < 0) |
| 112 | return ret; |
| 113 | |
| 114 | /* perform reset */ |
| 115 | ret = reset_get_by_index(dev, 0, &rst_ctl); |
| 116 | if (ret < 0) |
| 117 | return ret; |
| 118 | |
| 119 | ret = reset_deassert(&rst_ctl); |
| 120 | if (ret < 0) |
| 121 | return ret; |
| 122 | |
| 123 | ret = reset_free(&rst_ctl); |
| 124 | if (ret < 0) |
| 125 | return ret; |
| 126 | |
| 127 | mdelay(100); |
| 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | U_BOOT_DRIVER(bcm6318_usbh) = { |
| 133 | .name = "bcm6318-usbh", |
| 134 | .id = UCLASS_PHY, |
| 135 | .of_match = bcm6318_usbh_ids, |
| 136 | .ops = &bcm6318_usbh_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 137 | .priv_auto = sizeof(struct bcm6318_usbh_priv), |
Álvaro Fernández Rojas | 66871b7 | 2018-02-04 21:11:15 +0100 | [diff] [blame] | 138 | .probe = bcm6318_usbh_probe, |
| 139 | }; |