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