Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Álvaro Fernández Rojas | 190c36b | 2018-02-04 11:19:11 +0100 | [diff] [blame] | 2 | /* |
Álvaro Fernández Rojas | 5a1ab87 | 2018-03-22 19:39:41 +0100 | [diff] [blame] | 3 | * Copyright (C) 2018 Álvaro Fernández Rojas <noltari@gmail.com> |
Álvaro Fernández Rojas | 190c36b | 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 | 190c36b | 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 | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 14 | #include <malloc.h> |
Álvaro Fernández Rojas | 190c36b | 2018-02-04 11:19:11 +0100 | [diff] [blame] | 15 | #include <reset.h> |
| 16 | #include <asm/io.h> |
| 17 | #include <dm/device.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 18 | #include <linux/bitops.h> |
Álvaro Fernández Rojas | 190c36b | 2018-02-04 11:19:11 +0100 | [diff] [blame] | 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; |
Álvaro Fernández Rojas | 190c36b | 2018-02-04 11:19:11 +0100 | [diff] [blame] | 63 | int ret; |
| 64 | |
Álvaro Fernández Rojas | 5a1ab87 | 2018-03-22 19:39:41 +0100 | [diff] [blame] | 65 | priv->regs = dev_remap_addr(dev); |
| 66 | if (!priv->regs) |
Álvaro Fernández Rojas | 190c36b | 2018-02-04 11:19:11 +0100 | [diff] [blame] | 67 | return -EINVAL; |
| 68 | |
Álvaro Fernández Rojas | 190c36b | 2018-02-04 11:19:11 +0100 | [diff] [blame] | 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, |
| 90 | .priv_auto_alloc_size = sizeof(struct bcm6358_usbh_priv), |
| 91 | .probe = bcm6358_usbh_probe, |
| 92 | }; |