blob: a8d24609bfc0d9970595ba79de3c0458432f448d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Álvaro Fernández Rojas54a1fb62018-02-04 11:19:11 +01002/*
Álvaro Fernández Rojasb7de4cb2018-03-22 19:39:41 +01003 * Copyright (C) 2018 Álvaro Fernández Rojas <noltari@gmail.com>
Álvaro Fernández Rojas54a1fb62018-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 Rojas54a1fb62018-02-04 11:19:11 +01008 */
9
Álvaro Fernández Rojas54a1fb62018-02-04 11:19:11 +010010#include <dm.h>
11#include <generic-phy.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -070013#include <malloc.h>
Álvaro Fernández Rojas54a1fb62018-02-04 11:19:11 +010014#include <reset.h>
15#include <asm/io.h>
16#include <dm/device.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060017#include <linux/bitops.h>
Álvaro Fernández Rojas54a1fb62018-02-04 11:19:11 +010018
19/* USBH Swap Control register */
20#define USBH_SWAP_REG 0x00
21#define USBH_SWAP_OHCI_DATA BIT(0)
22#define USBH_SWAP_OHCI_ENDIAN BIT(1)
23#define USBH_SWAP_EHCI_DATA BIT(3)
24#define USBH_SWAP_EHCI_ENDIAN BIT(4)
25
26/* USBH Test register */
27#define USBH_TEST_REG 0x24
28#define USBH_TEST_PORT_CTL 0x1c0020
29
30struct bcm6358_usbh_priv {
31 void __iomem *regs;
32};
33
34static int bcm6358_usbh_init(struct phy *phy)
35{
36 struct bcm6358_usbh_priv *priv = dev_get_priv(phy->dev);
37
38 /* configure to work in native cpu endian */
39 clrsetbits_be32(priv->regs + USBH_SWAP_REG,
40 USBH_SWAP_EHCI_ENDIAN | USBH_SWAP_OHCI_ENDIAN,
41 USBH_SWAP_EHCI_DATA | USBH_SWAP_OHCI_DATA);
42
43 /* test port control */
44 writel_be(USBH_TEST_PORT_CTL, priv->regs + USBH_TEST_REG);
45
46 return 0;
47}
48
49static struct phy_ops bcm6358_usbh_ops = {
50 .init = bcm6358_usbh_init,
51};
52
53static const struct udevice_id bcm6358_usbh_ids[] = {
54 { .compatible = "brcm,bcm6358-usbh" },
55 { /* sentinel */ }
56};
57
58static int bcm6358_usbh_probe(struct udevice *dev)
59{
60 struct bcm6358_usbh_priv *priv = dev_get_priv(dev);
61 struct reset_ctl rst_ctl;
Álvaro Fernández Rojas54a1fb62018-02-04 11:19:11 +010062 int ret;
63
Álvaro Fernández Rojasb7de4cb2018-03-22 19:39:41 +010064 priv->regs = dev_remap_addr(dev);
65 if (!priv->regs)
Álvaro Fernández Rojas54a1fb62018-02-04 11:19:11 +010066 return -EINVAL;
67
Álvaro Fernández Rojas54a1fb62018-02-04 11:19:11 +010068 /* perform reset */
69 ret = reset_get_by_index(dev, 0, &rst_ctl);
70 if (ret < 0)
71 return ret;
72
73 ret = reset_deassert(&rst_ctl);
74 if (ret < 0)
75 return ret;
76
77 ret = reset_free(&rst_ctl);
78 if (ret < 0)
79 return ret;
80
81 return 0;
82}
83
84U_BOOT_DRIVER(bcm6358_usbh) = {
85 .name = "bcm6358-usbh",
86 .id = UCLASS_PHY,
87 .of_match = bcm6358_usbh_ids,
88 .ops = &bcm6358_usbh_ops,
Simon Glass8a2b47f2020-12-03 16:55:17 -070089 .priv_auto = sizeof(struct bcm6358_usbh_priv),
Álvaro Fernández Rojas54a1fb62018-02-04 11:19:11 +010090 .probe = bcm6358_usbh_probe,
91};