blob: f0fda0290e9032cd4879752d81b69f69197f9031 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Álvaro Fernández Rojas190c36b2018-02-04 11:19:11 +01002/*
Álvaro Fernández Rojas5a1ab872018-03-22 19:39:41 +01003 * Copyright (C) 2018 Álvaro Fernández Rojas <noltari@gmail.com>
Álvaro Fernández Rojas190c36b2018-02-04 11:19:11 +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 Rojas190c36b2018-02-04 11:19:11 +01008 */
9
10#include <common.h>
11#include <dm.h>
12#include <generic-phy.h>
Simon Glass336d4612020-02-03 07:36:16 -070013#include <malloc.h>
Álvaro Fernández Rojas190c36b2018-02-04 11:19:11 +010014#include <reset.h>
15#include <asm/io.h>
16#include <dm/device.h>
17
18/* USBH Swap Control register */
19#define USBH_SWAP_REG 0x00
20#define USBH_SWAP_OHCI_DATA BIT(0)
21#define USBH_SWAP_OHCI_ENDIAN BIT(1)
22#define USBH_SWAP_EHCI_DATA BIT(3)
23#define USBH_SWAP_EHCI_ENDIAN BIT(4)
24
25/* USBH Test register */
26#define USBH_TEST_REG 0x24
27#define USBH_TEST_PORT_CTL 0x1c0020
28
29struct bcm6358_usbh_priv {
30 void __iomem *regs;
31};
32
33static int bcm6358_usbh_init(struct phy *phy)
34{
35 struct bcm6358_usbh_priv *priv = dev_get_priv(phy->dev);
36
37 /* configure to work in native cpu endian */
38 clrsetbits_be32(priv->regs + USBH_SWAP_REG,
39 USBH_SWAP_EHCI_ENDIAN | USBH_SWAP_OHCI_ENDIAN,
40 USBH_SWAP_EHCI_DATA | USBH_SWAP_OHCI_DATA);
41
42 /* test port control */
43 writel_be(USBH_TEST_PORT_CTL, priv->regs + USBH_TEST_REG);
44
45 return 0;
46}
47
48static struct phy_ops bcm6358_usbh_ops = {
49 .init = bcm6358_usbh_init,
50};
51
52static const struct udevice_id bcm6358_usbh_ids[] = {
53 { .compatible = "brcm,bcm6358-usbh" },
54 { /* sentinel */ }
55};
56
57static int bcm6358_usbh_probe(struct udevice *dev)
58{
59 struct bcm6358_usbh_priv *priv = dev_get_priv(dev);
60 struct reset_ctl rst_ctl;
Álvaro Fernández Rojas190c36b2018-02-04 11:19:11 +010061 int ret;
62
Álvaro Fernández Rojas5a1ab872018-03-22 19:39:41 +010063 priv->regs = dev_remap_addr(dev);
64 if (!priv->regs)
Álvaro Fernández Rojas190c36b2018-02-04 11:19:11 +010065 return -EINVAL;
66
Álvaro Fernández Rojas190c36b2018-02-04 11:19:11 +010067 /* 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(bcm6358_usbh) = {
84 .name = "bcm6358-usbh",
85 .id = UCLASS_PHY,
86 .of_match = bcm6358_usbh_ids,
87 .ops = &bcm6358_usbh_ops,
88 .priv_auto_alloc_size = sizeof(struct bcm6358_usbh_priv),
89 .probe = bcm6358_usbh_probe,
90};