blob: ffb37b634a31a494e55c4128b31a5170356b157b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Álvaro Fernández Rojasb3c963a2018-02-04 11:18:24 +01002/*
Álvaro Fernández Rojas23617a32018-03-22 19:39:40 +01003 * Copyright (C) 2018 Álvaro Fernández Rojas <noltari@gmail.com>
Álvaro Fernández Rojasb3c963a2018-02-04 11:18:24 +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 Rojasb3c963a2018-02-04 11:18:24 +01008 */
9
Álvaro Fernández Rojasb3c963a2018-02-04 11:18:24 +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 Rojasb3c963a2018-02-04 11:18:24 +010015#include <reset.h>
16#include <asm/io.h>
17#include <dm/device.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060018#include <linux/bitops.h>
Álvaro Fernández Rojasb3c963a2018-02-04 11:18:24 +010019
20#define USBH_SETUP_PORT1_EN BIT(0)
21
22struct bcm6348_usbh_priv {
23 void __iomem *regs;
24};
25
26static int bcm6348_usbh_init(struct phy *phy)
27{
28 struct bcm6348_usbh_priv *priv = dev_get_priv(phy->dev);
29
30 writel_be(USBH_SETUP_PORT1_EN, priv->regs);
31
32 return 0;
33}
34
35static struct phy_ops bcm6348_usbh_ops = {
36 .init = bcm6348_usbh_init,
37};
38
39static const struct udevice_id bcm6348_usbh_ids[] = {
40 { .compatible = "brcm,bcm6348-usbh" },
41 { /* sentinel */ }
42};
43
44static int bcm6348_usbh_probe(struct udevice *dev)
45{
46 struct bcm6348_usbh_priv *priv = dev_get_priv(dev);
47 struct reset_ctl rst_ctl;
48 struct clk clk;
Álvaro Fernández Rojasb3c963a2018-02-04 11:18:24 +010049 int ret;
50
Álvaro Fernández Rojas23617a32018-03-22 19:39:40 +010051 priv->regs = dev_remap_addr(dev);
52 if (!priv->regs)
Álvaro Fernández Rojasb3c963a2018-02-04 11:18:24 +010053 return -EINVAL;
54
Álvaro Fernández Rojasb3c963a2018-02-04 11:18:24 +010055 /* enable usbh clock */
56 ret = clk_get_by_name(dev, "usbh", &clk);
57 if (ret < 0)
58 return ret;
59
60 ret = clk_enable(&clk);
61 if (ret < 0)
62 return ret;
63
Álvaro Fernández Rojasb3c963a2018-02-04 11:18:24 +010064 /* perform reset */
65 ret = reset_get_by_index(dev, 0, &rst_ctl);
66 if (ret < 0)
67 return ret;
68
69 ret = reset_deassert(&rst_ctl);
70 if (ret < 0)
71 return ret;
72
73 ret = reset_free(&rst_ctl);
74 if (ret < 0)
75 return ret;
76
77 return 0;
78}
79
80U_BOOT_DRIVER(bcm6348_usbh) = {
81 .name = "bcm6348-usbh",
82 .id = UCLASS_PHY,
83 .of_match = bcm6348_usbh_ids,
84 .ops = &bcm6348_usbh_ops,
Simon Glass8a2b47f2020-12-03 16:55:17 -070085 .priv_auto = sizeof(struct bcm6348_usbh_priv),
Álvaro Fernández Rojasb3c963a2018-02-04 11:18:24 +010086 .probe = bcm6348_usbh_probe,
87};