Merge tag 'ti-v2020.07-rc2' of https://gitlab.denx.de/u-boot/custodians/u-boot-ti
[platform/kernel/u-boot.git] / drivers / phy / bcm6348-usbh-phy.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2018 Álvaro Fernández Rojas <noltari@gmail.com>
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>
8  */
9
10 #include <common.h>
11 #include <clk.h>
12 #include <dm.h>
13 #include <generic-phy.h>
14 #include <malloc.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
21 struct bcm6348_usbh_priv {
22         void __iomem *regs;
23 };
24
25 static 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
34 static struct phy_ops bcm6348_usbh_ops = {
35         .init = bcm6348_usbh_init,
36 };
37
38 static const struct udevice_id bcm6348_usbh_ids[] = {
39         { .compatible = "brcm,bcm6348-usbh" },
40         { /* sentinel */ }
41 };
42
43 static 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         int ret;
49
50         priv->regs = dev_remap_addr(dev);
51         if (!priv->regs)
52                 return -EINVAL;
53
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
83 U_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 };