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