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