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