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 | |
Álvaro Fernández Rojas | 54a1fb6 | 2018-02-04 11:19:11 +0100 | [diff] [blame] | 10 | #include <dm.h> |
| 11 | #include <generic-phy.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.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> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 17 | #include <linux/bitops.h> |
Álvaro Fernández Rojas | 54a1fb6 | 2018-02-04 11:19:11 +0100 | [diff] [blame] | 18 | |
| 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 | |
| 30 | struct bcm6358_usbh_priv { |
| 31 | void __iomem *regs; |
| 32 | }; |
| 33 | |
| 34 | static 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 | |
| 49 | static struct phy_ops bcm6358_usbh_ops = { |
| 50 | .init = bcm6358_usbh_init, |
| 51 | }; |
| 52 | |
| 53 | static const struct udevice_id bcm6358_usbh_ids[] = { |
| 54 | { .compatible = "brcm,bcm6358-usbh" }, |
| 55 | { /* sentinel */ } |
| 56 | }; |
| 57 | |
| 58 | static 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 Rojas | 54a1fb6 | 2018-02-04 11:19:11 +0100 | [diff] [blame] | 62 | int ret; |
| 63 | |
Álvaro Fernández Rojas | b7de4cb | 2018-03-22 19:39:41 +0100 | [diff] [blame] | 64 | priv->regs = dev_remap_addr(dev); |
| 65 | if (!priv->regs) |
Álvaro Fernández Rojas | 54a1fb6 | 2018-02-04 11:19:11 +0100 | [diff] [blame] | 66 | return -EINVAL; |
| 67 | |
Álvaro Fernández Rojas | 54a1fb6 | 2018-02-04 11:19:11 +0100 | [diff] [blame] | 68 | /* 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 | |
| 84 | U_BOOT_DRIVER(bcm6358_usbh) = { |
| 85 | .name = "bcm6358-usbh", |
| 86 | .id = UCLASS_PHY, |
| 87 | .of_match = bcm6358_usbh_ids, |
| 88 | .ops = &bcm6358_usbh_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 89 | .priv_auto = sizeof(struct bcm6358_usbh_priv), |
Álvaro Fernández Rojas | 54a1fb6 | 2018-02-04 11:19:11 +0100 | [diff] [blame] | 90 | .probe = bcm6358_usbh_probe, |
| 91 | }; |