]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
190c36b9 | 2 | /* |
5a1ab87f | 3 | * Copyright (C) 2018 Álvaro Fernández Rojas <noltari@gmail.com> |
190c36b9 Á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> | |
190c36b9 ÁFR |
8 | */ |
9 | ||
d678a59d | 10 | #include <common.h> |
190c36b9 ÁFR |
11 | #include <dm.h> |
12 | #include <generic-phy.h> | |
f7ae49fc | 13 | #include <log.h> |
336d4615 | 14 | #include <malloc.h> |
190c36b9 ÁFR |
15 | #include <reset.h> |
16 | #include <asm/io.h> | |
17 | #include <dm/device.h> | |
cd93d625 | 18 | #include <linux/bitops.h> |
190c36b9 ÁFR |
19 | |
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 | ||
31 | struct bcm6358_usbh_priv { | |
32 | void __iomem *regs; | |
33 | }; | |
34 | ||
35 | static 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 | ||
50 | static struct phy_ops bcm6358_usbh_ops = { | |
51 | .init = bcm6358_usbh_init, | |
52 | }; | |
53 | ||
54 | static const struct udevice_id bcm6358_usbh_ids[] = { | |
55 | { .compatible = "brcm,bcm6358-usbh" }, | |
56 | { /* sentinel */ } | |
57 | }; | |
58 | ||
59 | static int bcm6358_usbh_probe(struct udevice *dev) | |
60 | { | |
61 | struct bcm6358_usbh_priv *priv = dev_get_priv(dev); | |
62 | struct reset_ctl rst_ctl; | |
190c36b9 ÁFR |
63 | int ret; |
64 | ||
5a1ab87f ÁFR |
65 | priv->regs = dev_remap_addr(dev); |
66 | if (!priv->regs) | |
190c36b9 ÁFR |
67 | return -EINVAL; |
68 | ||
190c36b9 ÁFR |
69 | /* 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 | ||
85 | U_BOOT_DRIVER(bcm6358_usbh) = { | |
86 | .name = "bcm6358-usbh", | |
87 | .id = UCLASS_PHY, | |
88 | .of_match = bcm6358_usbh_ids, | |
89 | .ops = &bcm6358_usbh_ops, | |
41575d8e | 90 | .priv_auto = sizeof(struct bcm6358_usbh_priv), |
190c36b9 ÁFR |
91 | .probe = bcm6358_usbh_probe, |
92 | }; |