Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Álvaro Fernández Rojas | b3c963a | 2018-02-04 11:18:24 +0100 | [diff] [blame] | 2 | /* |
Álvaro Fernández Rojas | 23617a3 | 2018-03-22 19:39:40 +0100 | [diff] [blame] | 3 | * Copyright (C) 2018 Álvaro Fernández Rojas <noltari@gmail.com> |
Álvaro Fernández Rojas | b3c963a | 2018-02-04 11:18:24 +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 | b3c963a | 2018-02-04 11:18:24 +0100 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <clk.h> |
| 12 | #include <dm.h> |
| 13 | #include <generic-phy.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 14 | #include <malloc.h> |
Álvaro Fernández Rojas | b3c963a | 2018-02-04 11:18:24 +0100 | [diff] [blame] | 15 | #include <reset.h> |
| 16 | #include <asm/io.h> |
| 17 | #include <dm/device.h> |
| 18 | |
| 19 | #define USBH_SETUP_PORT1_EN BIT(0) |
| 20 | |
| 21 | struct bcm6348_usbh_priv { |
| 22 | void __iomem *regs; |
| 23 | }; |
| 24 | |
| 25 | static int bcm6348_usbh_init(struct phy *phy) |
| 26 | { |
| 27 | struct bcm6348_usbh_priv *priv = dev_get_priv(phy->dev); |
| 28 | |
| 29 | writel_be(USBH_SETUP_PORT1_EN, priv->regs); |
| 30 | |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | static struct phy_ops bcm6348_usbh_ops = { |
| 35 | .init = bcm6348_usbh_init, |
| 36 | }; |
| 37 | |
| 38 | static const struct udevice_id bcm6348_usbh_ids[] = { |
| 39 | { .compatible = "brcm,bcm6348-usbh" }, |
| 40 | { /* sentinel */ } |
| 41 | }; |
| 42 | |
| 43 | static int bcm6348_usbh_probe(struct udevice *dev) |
| 44 | { |
| 45 | struct bcm6348_usbh_priv *priv = dev_get_priv(dev); |
| 46 | struct reset_ctl rst_ctl; |
| 47 | struct clk clk; |
Álvaro Fernández Rojas | b3c963a | 2018-02-04 11:18:24 +0100 | [diff] [blame] | 48 | int ret; |
| 49 | |
Álvaro Fernández Rojas | 23617a3 | 2018-03-22 19:39:40 +0100 | [diff] [blame] | 50 | priv->regs = dev_remap_addr(dev); |
| 51 | if (!priv->regs) |
Álvaro Fernández Rojas | b3c963a | 2018-02-04 11:18:24 +0100 | [diff] [blame] | 52 | return -EINVAL; |
| 53 | |
Álvaro Fernández Rojas | b3c963a | 2018-02-04 11:18:24 +0100 | [diff] [blame] | 54 | /* enable usbh clock */ |
| 55 | ret = clk_get_by_name(dev, "usbh", &clk); |
| 56 | if (ret < 0) |
| 57 | return ret; |
| 58 | |
| 59 | ret = clk_enable(&clk); |
| 60 | if (ret < 0) |
| 61 | return ret; |
| 62 | |
| 63 | ret = clk_free(&clk); |
| 64 | if (ret < 0) |
| 65 | return ret; |
| 66 | |
| 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(bcm6348_usbh) = { |
| 84 | .name = "bcm6348-usbh", |
| 85 | .id = UCLASS_PHY, |
| 86 | .of_match = bcm6348_usbh_ids, |
| 87 | .ops = &bcm6348_usbh_ops, |
| 88 | .priv_auto_alloc_size = sizeof(struct bcm6348_usbh_priv), |
| 89 | .probe = bcm6348_usbh_probe, |
| 90 | }; |