]> git.ipfire.org Git - thirdparty/u-boot.git/blame - drivers/phy/bcm6348-usbh-phy.c
dm: core: Create a new header file for 'compat' features
[thirdparty/u-boot.git] / drivers / phy / bcm6348-usbh-phy.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
bcb9b502 2/*
50d16bcf 3 * Copyright (C) 2018 Álvaro Fernández Rojas <noltari@gmail.com>
bcb9b502
ÁFR
4 *
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>
bcb9b502
ÁFR
8 */
9
10#include <common.h>
11#include <clk.h>
12#include <dm.h>
13#include <generic-phy.h>
336d4615 14#include <malloc.h>
bcb9b502
ÁFR
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;
bcb9b502
ÁFR
48 int ret;
49
50d16bcf
ÁFR
50 priv->regs = dev_remap_addr(dev);
51 if (!priv->regs)
bcb9b502
ÁFR
52 return -EINVAL;
53
bcb9b502
ÁFR
54 /* 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};