blob: 3bb9c0814c14030e5baf5163c767b99319378aad [file] [log] [blame]
Jean-Jacques Hiblot4b127832018-12-04 11:12:59 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
Nishanth Menona94a4072023-11-01 15:56:03 -05003 * Copyright (C) 2017 Texas Instruments Incorporated - https://www.ti.com/
Jean-Jacques Hiblot4b127832018-12-04 11:12:59 +01004 * Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
5 */
6
7#include <common.h>
8#include <dm.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06009#include <log.h>
Jean-Jacques Hiblot4b127832018-12-04 11:12:59 +010010#include <dm/device.h>
11#include <generic-phy.h>
12#include <asm/io.h>
Jean-Jacques Hiblot2bbc1bb2019-09-11 11:33:56 +020013#include <asm/arch/psc_defs.h>
Simon Glasscd93d622020-05-10 11:40:13 -060014#include <linux/bitops.h>
Simon Glassc05ed002020-05-10 11:40:11 -060015#include <linux/delay.h>
Simon Glass1e94b462023-09-14 18:21:46 -060016#include <linux/printk.h>
Jean-Jacques Hiblot4b127832018-12-04 11:12:59 +010017
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
29struct keystone_usb_phy {
Jean-Jacques Hiblot2bbc1bb2019-09-11 11:33:56 +020030 u32 psc_domain;
Jean-Jacques Hiblot4b127832018-12-04 11:12:59 +010031 void __iomem *reg;
32};
33
34static int keystone_usb_init(struct phy *phy)
35{
36 u32 val;
Jean-Jacques Hiblot2bbc1bb2019-09-11 11:33:56 +020037 int rc;
Jean-Jacques Hiblot4b127832018-12-04 11:12:59 +010038 struct udevice *dev = phy->dev;
39 struct keystone_usb_phy *keystone = dev_get_priv(dev);
40
Jean-Jacques Hiblot2bbc1bb2019-09-11 11:33:56 +020041 /* 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 Hiblot4b127832018-12-04 11:12:59 +010049 /*
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
62static 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
75static 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
88static int keystone_usb_exit(struct phy *phy)
89{
Jean-Jacques Hiblot2bbc1bb2019-09-11 11:33:56 +020090 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 Hiblot4b127832018-12-04 11:12:59 +010096 return 0;
97}
98
99static int keystone_usb_phy_probe(struct udevice *dev)
100{
Jean-Jacques Hiblot2bbc1bb2019-09-11 11:33:56 +0200101 int rc;
Jean-Jacques Hiblot4b127832018-12-04 11:12:59 +0100102 struct keystone_usb_phy *keystone = dev_get_priv(dev);
103
Jean-Jacques Hiblot2bbc1bb2019-09-11 11:33:56 +0200104 rc = dev_read_u32(dev, "psc-domain", &keystone->psc_domain);
105 if (rc)
106 return rc;
107
Jean-Jacques Hiblot4b127832018-12-04 11:12:59 +0100108 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
116static const struct udevice_id keystone_usb_phy_ids[] = {
117 { .compatible = "ti,keystone-usbphy" },
118 { }
119};
120
121static 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
128U_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 Glass41575d82020-12-03 16:55:17 -0700134 .priv_auto = sizeof(struct keystone_usb_phy),
Jean-Jacques Hiblot4b127832018-12-04 11:12:59 +0100135};