blob: fe0e43d2703bb5cc640ba0c9ac4fcc0f54bc5533 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Álvaro Fernández Rojas8e948c62018-02-04 21:11:15 +01002/*
Álvaro Fernández Rojas9ca33eb2018-03-22 19:39:43 +01003 * Copyright (C) 2018 Álvaro Fernández Rojas <noltari@gmail.com>
Álvaro Fernández Rojas8e948c62018-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 Rojas8e948c62018-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 Glassf7ae49f2020-05-10 11:40:05 -060014#include <log.h>
Simon Glass336d4612020-02-03 07:36:16 -070015#include <malloc.h>
Álvaro Fernández Rojas8e948c62018-02-04 21:11:15 +010016#include <power-domain.h>
17#include <reset.h>
18#include <asm/io.h>
19#include <dm/device.h>
Simon Glassc05ed002020-05-10 11:40:11 -060020#include <linux/delay.h>
Álvaro Fernández Rojas8e948c62018-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 Rojas8e948c62018-02-04 21:11:15 +010085 int ret;
86
Álvaro Fernández Rojas9ca33eb2018-03-22 19:39:43 +010087 priv->regs = dev_remap_addr(dev);
88 if (!priv->regs)
Álvaro Fernández Rojas8e948c62018-02-04 21:11:15 +010089 return -EINVAL;
90
Álvaro Fernández Rojas8e948c62018-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
100 ret = clk_free(&clk);
101 if (ret < 0)
102 return ret;
103
104 /* enable power domain */
105 ret = power_domain_get(dev, &pwr_dom);
106 if (ret < 0)
107 return ret;
108
109 ret = power_domain_on(&pwr_dom);
110 if (ret < 0)
111 return ret;
112
113 ret = power_domain_free(&pwr_dom);
114 if (ret < 0)
115 return ret;
116
117 /* perform reset */
118 ret = reset_get_by_index(dev, 0, &rst_ctl);
119 if (ret < 0)
120 return ret;
121
122 ret = reset_deassert(&rst_ctl);
123 if (ret < 0)
124 return ret;
125
126 ret = reset_free(&rst_ctl);
127 if (ret < 0)
128 return ret;
129
130 mdelay(100);
131
132 return 0;
133}
134
135U_BOOT_DRIVER(bcm6318_usbh) = {
136 .name = "bcm6318-usbh",
137 .id = UCLASS_PHY,
138 .of_match = bcm6318_usbh_ids,
139 .ops = &bcm6318_usbh_ops,
140 .priv_auto_alloc_size = sizeof(struct bcm6318_usbh_priv),
141 .probe = bcm6318_usbh_probe,
142};