blob: bfdcfb0d245ebe2406ddffc4ce4cebe300805021 [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
10#include <common.h>
11#include <dm.h>
12#include <generic-phy.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -070014#include <malloc.h>
Álvaro Fernández Rojas54a1fb62018-02-04 11:19:11 +010015#include <reset.h>
16#include <asm/io.h>
17#include <dm/device.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060018#include <linux/bitops.h>
Álvaro Fernández Rojas54a1fb62018-02-04 11:19:11 +010019
20/* USBH Swap Control register */
21#define USBH_SWAP_REG 0x00
22#define USBH_SWAP_OHCI_DATA BIT(0)
23#define USBH_SWAP_OHCI_ENDIAN BIT(1)
24#define USBH_SWAP_EHCI_DATA BIT(3)
25#define USBH_SWAP_EHCI_ENDIAN BIT(4)
26
27/* USBH Test register */
28#define USBH_TEST_REG 0x24
29#define USBH_TEST_PORT_CTL 0x1c0020
30
31struct bcm6358_usbh_priv {
32 void __iomem *regs;
33};
34
35static int bcm6358_usbh_init(struct phy *phy)
36{
37 struct bcm6358_usbh_priv *priv = dev_get_priv(phy->dev);
38
39 /* configure to work in native cpu endian */
40 clrsetbits_be32(priv->regs + USBH_SWAP_REG,
41 USBH_SWAP_EHCI_ENDIAN | USBH_SWAP_OHCI_ENDIAN,
42 USBH_SWAP_EHCI_DATA | USBH_SWAP_OHCI_DATA);
43
44 /* test port control */
45 writel_be(USBH_TEST_PORT_CTL, priv->regs + USBH_TEST_REG);
46
47 return 0;
48}
49
50static struct phy_ops bcm6358_usbh_ops = {
51 .init = bcm6358_usbh_init,
52};
53
54static const struct udevice_id bcm6358_usbh_ids[] = {
55 { .compatible = "brcm,bcm6358-usbh" },
56 { /* sentinel */ }
57};
58
59static int bcm6358_usbh_probe(struct udevice *dev)
60{
61 struct bcm6358_usbh_priv *priv = dev_get_priv(dev);
62 struct reset_ctl rst_ctl;
Álvaro Fernández Rojas54a1fb62018-02-04 11:19:11 +010063 int ret;
64
Álvaro Fernández Rojasb7de4cb2018-03-22 19:39:41 +010065 priv->regs = dev_remap_addr(dev);
66 if (!priv->regs)
Álvaro Fernández Rojas54a1fb62018-02-04 11:19:11 +010067 return -EINVAL;
68
Álvaro Fernández Rojas54a1fb62018-02-04 11:19:11 +010069 /* perform reset */
70 ret = reset_get_by_index(dev, 0, &rst_ctl);
71 if (ret < 0)
72 return ret;
73
74 ret = reset_deassert(&rst_ctl);
75 if (ret < 0)
76 return ret;
77
78 ret = reset_free(&rst_ctl);
79 if (ret < 0)
80 return ret;
81
82 return 0;
83}
84
85U_BOOT_DRIVER(bcm6358_usbh) = {
86 .name = "bcm6358-usbh",
87 .id = UCLASS_PHY,
88 .of_match = bcm6358_usbh_ids,
89 .ops = &bcm6358_usbh_ops,
Simon Glass8a2b47f2020-12-03 16:55:17 -070090 .priv_auto = sizeof(struct bcm6358_usbh_priv),
Álvaro Fernández Rojas54a1fb62018-02-04 11:19:11 +010091 .probe = bcm6358_usbh_probe,
92};