Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Álvaro Fernández Rojas | 54a1fb6 | 2018-02-04 11:19:11 +0100 | [diff] [blame] | 2 | /* |
Álvaro Fernández Rojas | b7de4cb | 2018-03-22 19:39:41 +0100 | [diff] [blame] | 3 | * Copyright (C) 2018 Álvaro Fernández Rojas <noltari@gmail.com> |
Álvaro Fernández Rojas | 54a1fb6 | 2018-02-04 11:19:11 +0100 | [diff] [blame] | 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> |
Álvaro Fernández Rojas | 54a1fb6 | 2018-02-04 11:19:11 +0100 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <dm.h> |
| 12 | #include <generic-phy.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 13 | #include <malloc.h> |
Álvaro Fernández Rojas | 54a1fb6 | 2018-02-04 11:19:11 +0100 | [diff] [blame] | 14 | #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 | |
| 29 | struct bcm6358_usbh_priv { |
| 30 | void __iomem *regs; |
| 31 | }; |
| 32 | |
| 33 | static 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 | |
| 48 | static struct phy_ops bcm6358_usbh_ops = { |
| 49 | .init = bcm6358_usbh_init, |
| 50 | }; |
| 51 | |
| 52 | static const struct udevice_id bcm6358_usbh_ids[] = { |
| 53 | { .compatible = "brcm,bcm6358-usbh" }, |
| 54 | { /* sentinel */ } |
| 55 | }; |
| 56 | |
| 57 | static 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 Rojas | 54a1fb6 | 2018-02-04 11:19:11 +0100 | [diff] [blame] | 61 | int ret; |
| 62 | |
Álvaro Fernández Rojas | b7de4cb | 2018-03-22 19:39:41 +0100 | [diff] [blame] | 63 | priv->regs = dev_remap_addr(dev); |
| 64 | if (!priv->regs) |
Álvaro Fernández Rojas | 54a1fb6 | 2018-02-04 11:19:11 +0100 | [diff] [blame] | 65 | return -EINVAL; |
| 66 | |
Álvaro Fernández Rojas | 54a1fb6 | 2018-02-04 11:19:11 +0100 | [diff] [blame] | 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(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 | }; |