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