Jean-Jacques Hiblot | 4b12783 | 2018-12-04 11:12:59 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/ |
| 4 | * Written by Jean-Jacques Hiblot <jjhiblot@ti.com> |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Jean-Jacques Hiblot | 4b12783 | 2018-12-04 11:12:59 +0100 | [diff] [blame] | 10 | #include <dm/device.h> |
| 11 | #include <generic-phy.h> |
| 12 | #include <asm/io.h> |
Jean-Jacques Hiblot | 2bbc1bb | 2019-09-11 11:33:56 +0200 | [diff] [blame] | 13 | #include <asm/arch/psc_defs.h> |
Jean-Jacques Hiblot | 4b12783 | 2018-12-04 11:12:59 +0100 | [diff] [blame] | 14 | |
| 15 | /* USB PHY control register offsets */ |
| 16 | #define USB_PHY_CTL_UTMI 0x0000 |
| 17 | #define USB_PHY_CTL_PIPE 0x0004 |
| 18 | #define USB_PHY_CTL_PARAM_1 0x0008 |
| 19 | #define USB_PHY_CTL_PARAM_2 0x000c |
| 20 | #define USB_PHY_CTL_CLOCK 0x0010 |
| 21 | #define USB_PHY_CTL_PLL 0x0014 |
| 22 | |
| 23 | #define PHY_OTG_VBUSVLDECTSEL BIT(16) |
| 24 | #define PHY_REF_SSP_EN BIT(29) |
| 25 | |
| 26 | struct keystone_usb_phy { |
Jean-Jacques Hiblot | 2bbc1bb | 2019-09-11 11:33:56 +0200 | [diff] [blame] | 27 | u32 psc_domain; |
Jean-Jacques Hiblot | 4b12783 | 2018-12-04 11:12:59 +0100 | [diff] [blame] | 28 | void __iomem *reg; |
| 29 | }; |
| 30 | |
| 31 | static int keystone_usb_init(struct phy *phy) |
| 32 | { |
| 33 | u32 val; |
Jean-Jacques Hiblot | 2bbc1bb | 2019-09-11 11:33:56 +0200 | [diff] [blame] | 34 | int rc; |
Jean-Jacques Hiblot | 4b12783 | 2018-12-04 11:12:59 +0100 | [diff] [blame] | 35 | struct udevice *dev = phy->dev; |
| 36 | struct keystone_usb_phy *keystone = dev_get_priv(dev); |
| 37 | |
Jean-Jacques Hiblot | 2bbc1bb | 2019-09-11 11:33:56 +0200 | [diff] [blame] | 38 | /* Release USB from reset */ |
| 39 | rc = psc_enable_module(keystone->psc_domain); |
| 40 | if (rc) { |
| 41 | debug("Cannot enable USB module"); |
| 42 | return -rc; |
| 43 | } |
| 44 | mdelay(10); |
| 45 | |
Jean-Jacques Hiblot | 4b12783 | 2018-12-04 11:12:59 +0100 | [diff] [blame] | 46 | /* |
| 47 | * VBUSVLDEXTSEL has a default value of 1 in BootCfg but shouldn't. |
| 48 | * It should always be cleared because our USB PHY has an onchip VBUS |
| 49 | * analog comparator. |
| 50 | */ |
| 51 | val = readl(keystone->reg + USB_PHY_CTL_CLOCK); |
| 52 | /* quit selecting the vbusvldextsel by default! */ |
| 53 | val &= ~PHY_OTG_VBUSVLDECTSEL; |
| 54 | writel(val, keystone->reg + USB_PHY_CTL_CLOCK); |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | static int keystone_usb_power_on(struct phy *phy) |
| 60 | { |
| 61 | u32 val; |
| 62 | struct udevice *dev = phy->dev; |
| 63 | struct keystone_usb_phy *keystone = dev_get_priv(dev); |
| 64 | |
| 65 | val = readl(keystone->reg + USB_PHY_CTL_CLOCK); |
| 66 | val |= PHY_REF_SSP_EN; |
| 67 | writel(val, keystone->reg + USB_PHY_CTL_CLOCK); |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | static int keystone_usb_power_off(struct phy *phy) |
| 73 | { |
| 74 | u32 val; |
| 75 | struct udevice *dev = phy->dev; |
| 76 | struct keystone_usb_phy *keystone = dev_get_priv(dev); |
| 77 | |
| 78 | val = readl(keystone->reg + USB_PHY_CTL_CLOCK); |
| 79 | val &= ~PHY_REF_SSP_EN; |
| 80 | writel(val, keystone->reg + USB_PHY_CTL_CLOCK); |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | static int keystone_usb_exit(struct phy *phy) |
| 86 | { |
Jean-Jacques Hiblot | 2bbc1bb | 2019-09-11 11:33:56 +0200 | [diff] [blame] | 87 | struct udevice *dev = phy->dev; |
| 88 | struct keystone_usb_phy *keystone = dev_get_priv(dev); |
| 89 | |
| 90 | if (psc_disable_module(keystone->psc_domain)) |
| 91 | debug("failed to disable USB module!\n"); |
| 92 | |
Jean-Jacques Hiblot | 4b12783 | 2018-12-04 11:12:59 +0100 | [diff] [blame] | 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | static int keystone_usb_phy_probe(struct udevice *dev) |
| 97 | { |
Jean-Jacques Hiblot | 2bbc1bb | 2019-09-11 11:33:56 +0200 | [diff] [blame] | 98 | int rc; |
Jean-Jacques Hiblot | 4b12783 | 2018-12-04 11:12:59 +0100 | [diff] [blame] | 99 | struct keystone_usb_phy *keystone = dev_get_priv(dev); |
| 100 | |
Jean-Jacques Hiblot | 2bbc1bb | 2019-09-11 11:33:56 +0200 | [diff] [blame] | 101 | rc = dev_read_u32(dev, "psc-domain", &keystone->psc_domain); |
| 102 | if (rc) |
| 103 | return rc; |
| 104 | |
Jean-Jacques Hiblot | 4b12783 | 2018-12-04 11:12:59 +0100 | [diff] [blame] | 105 | keystone->reg = dev_remap_addr_index(dev, 0); |
| 106 | if (!keystone->reg) { |
| 107 | pr_err("unable to remap usb phy\n"); |
| 108 | return -EINVAL; |
| 109 | } |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | static const struct udevice_id keystone_usb_phy_ids[] = { |
| 114 | { .compatible = "ti,keystone-usbphy" }, |
| 115 | { } |
| 116 | }; |
| 117 | |
| 118 | static struct phy_ops keystone_usb_phy_ops = { |
| 119 | .init = keystone_usb_init, |
| 120 | .power_on = keystone_usb_power_on, |
| 121 | .power_off = keystone_usb_power_off, |
| 122 | .exit = keystone_usb_exit, |
| 123 | }; |
| 124 | |
| 125 | U_BOOT_DRIVER(keystone_usb_phy) = { |
| 126 | .name = "keystone_usb_phy", |
| 127 | .id = UCLASS_PHY, |
| 128 | .of_match = keystone_usb_phy_ids, |
| 129 | .ops = &keystone_usb_phy_ops, |
| 130 | .probe = keystone_usb_phy_probe, |
| 131 | .priv_auto_alloc_size = sizeof(struct keystone_usb_phy), |
| 132 | }; |