blob: d715541bd4cb0e4db81bef95d14346a5bd06bffd [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Álvaro Fernández Rojas66871b72018-02-04 21:11:15 +01002/*
Álvaro Fernández Rojasc7bbeaf2018-03-22 19:39:43 +01003 * Copyright (C) 2018 Álvaro Fernández Rojas <noltari@gmail.com>
Álvaro Fernández Rojas66871b72018-02-04 21:11:15 +01004 *
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 Rojas66871b72018-02-04 21:11:15 +01008 */
9
Álvaro Fernández Rojas66871b72018-02-04 21:11:15 +010010#include <clk.h>
11#include <dm.h>
12#include <generic-phy.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -070014#include <malloc.h>
Álvaro Fernández Rojas66871b72018-02-04 21:11:15 +010015#include <power-domain.h>
16#include <reset.h>
17#include <asm/io.h>
18#include <dm/device.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060019#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060020#include <linux/delay.h>
Álvaro Fernández Rojas66871b72018-02-04 21:11:15 +010021
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
42struct bcm6318_usbh_priv {
43 void __iomem *regs;
44};
45
46static 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
70static struct phy_ops bcm6318_usbh_ops = {
71 .init = bcm6318_usbh_init,
72};
73
74static const struct udevice_id bcm6318_usbh_ids[] = {
75 { .compatible = "brcm,bcm6318-usbh" },
76 { /* sentinel */ }
77};
78
79static 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 Rojas66871b72018-02-04 21:11:15 +010085 int ret;
86
Álvaro Fernández Rojasc7bbeaf2018-03-22 19:39:43 +010087 priv->regs = dev_remap_addr(dev);
88 if (!priv->regs)
Álvaro Fernández Rojas66871b72018-02-04 21:11:15 +010089 return -EINVAL;
90
Álvaro Fernández Rojas66871b72018-02-04 21:11:15 +010091 /* 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 Rojas66871b72018-02-04 21:11:15 +0100100 /* 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
131U_BOOT_DRIVER(bcm6318_usbh) = {
132 .name = "bcm6318-usbh",
133 .id = UCLASS_PHY,
134 .of_match = bcm6318_usbh_ids,
135 .ops = &bcm6318_usbh_ops,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700136 .priv_auto = sizeof(struct bcm6318_usbh_priv),
Álvaro Fernández Rojas66871b72018-02-04 21:11:15 +0100137 .probe = bcm6318_usbh_probe,
138};