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