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