blob: 169ee0ecec024e344c58c78bd9f3672094aead09 [file] [log] [blame]
Álvaro Fernández Rojasb3c963a2018-02-04 11:18:24 +01001/*
2 * Copyright (C) 2018 Álvaro Fernández Rojas <noltari@gmail.com>
3 *
4 * Derived from linux/arch/mips/bcm63xx/usb-common.c:
5 * Copyright 2008 Maxime Bizon <mbizon@freebox.fr>
6 * Copyright 2013 Florian Fainelli <florian@openwrt.org>
7 *
8 * SPDX-License-Identifier: GPL-2.0+
9 */
10
11#include <common.h>
12#include <clk.h>
13#include <dm.h>
14#include <generic-phy.h>
15#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;
48 fdt_addr_t addr;
49 fdt_size_t size;
50 int ret;
51
52 addr = devfdt_get_addr_size_index(dev, 0, &size);
53 if (addr == FDT_ADDR_T_NONE)
54 return -EINVAL;
55
56 priv->regs = ioremap(addr, size);
57
58 /* enable usbh clock */
59 ret = clk_get_by_name(dev, "usbh", &clk);
60 if (ret < 0)
61 return ret;
62
63 ret = clk_enable(&clk);
64 if (ret < 0)
65 return ret;
66
67 ret = clk_free(&clk);
68 if (ret < 0)
69 return ret;
70
71 /* perform reset */
72 ret = reset_get_by_index(dev, 0, &rst_ctl);
73 if (ret < 0)
74 return ret;
75
76 ret = reset_deassert(&rst_ctl);
77 if (ret < 0)
78 return ret;
79
80 ret = reset_free(&rst_ctl);
81 if (ret < 0)
82 return ret;
83
84 return 0;
85}
86
87U_BOOT_DRIVER(bcm6348_usbh) = {
88 .name = "bcm6348-usbh",
89 .id = UCLASS_PHY,
90 .of_match = bcm6348_usbh_ids,
91 .ops = &bcm6348_usbh_ops,
92 .priv_auto_alloc_size = sizeof(struct bcm6348_usbh_priv),
93 .probe = bcm6348_usbh_probe,
94};