blob: ed9f02b375cf57ff8b0704fd3f3dbd10bf786806 [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
10#include <common.h>
11#include <clk.h>
12#include <dm.h>
13#include <generic-phy.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>
18
19#define USBH_SETUP_PORT1_EN BIT(0)
20
21struct bcm6348_usbh_priv {
22 void __iomem *regs;
23};
24
25static int bcm6348_usbh_init(struct phy *phy)
26{
27 struct bcm6348_usbh_priv *priv = dev_get_priv(phy->dev);
28
29 writel_be(USBH_SETUP_PORT1_EN, priv->regs);
30
31 return 0;
32}
33
34static struct phy_ops bcm6348_usbh_ops = {
35 .init = bcm6348_usbh_init,
36};
37
38static const struct udevice_id bcm6348_usbh_ids[] = {
39 { .compatible = "brcm,bcm6348-usbh" },
40 { /* sentinel */ }
41};
42
43static int bcm6348_usbh_probe(struct udevice *dev)
44{
45 struct bcm6348_usbh_priv *priv = dev_get_priv(dev);
46 struct reset_ctl rst_ctl;
47 struct clk clk;
Álvaro Fernández Rojasb3c963a2018-02-04 11:18:24 +010048 int ret;
49
Álvaro Fernández Rojas23617a32018-03-22 19:39:40 +010050 priv->regs = dev_remap_addr(dev);
51 if (!priv->regs)
Álvaro Fernández Rojasb3c963a2018-02-04 11:18:24 +010052 return -EINVAL;
53
Álvaro Fernández Rojasb3c963a2018-02-04 11:18:24 +010054 /* enable usbh clock */
55 ret = clk_get_by_name(dev, "usbh", &clk);
56 if (ret < 0)
57 return ret;
58
59 ret = clk_enable(&clk);
60 if (ret < 0)
61 return ret;
62
63 ret = clk_free(&clk);
64 if (ret < 0)
65 return ret;
66
67 /* perform reset */
68 ret = reset_get_by_index(dev, 0, &rst_ctl);
69 if (ret < 0)
70 return ret;
71
72 ret = reset_deassert(&rst_ctl);
73 if (ret < 0)
74 return ret;
75
76 ret = reset_free(&rst_ctl);
77 if (ret < 0)
78 return ret;
79
80 return 0;
81}
82
83U_BOOT_DRIVER(bcm6348_usbh) = {
84 .name = "bcm6348-usbh",
85 .id = UCLASS_PHY,
86 .of_match = bcm6348_usbh_ids,
87 .ops = &bcm6348_usbh_ops,
88 .priv_auto_alloc_size = sizeof(struct bcm6348_usbh_priv),
89 .probe = bcm6348_usbh_probe,
90};