blob: 7c9d030a4d8aac2564684c23d51553e5795dea46 [file] [log] [blame]
Ramon Fried019fb8c2018-09-21 13:35:47 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2018 Ramon Fried <ramon.fried@gmail.com>
4 */
5
6#include <common.h>
7#include <dm.h>
8#include <generic-phy.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -06009#include <linux/bitops.h>
Ramon Fried019fb8c2018-09-21 13:35:47 +030010#include <usb/ehci-ci.h>
11#include <usb/ulpi.h>
12#include <asm/io.h>
13
14/* PHY viewport regs */
15#define ULPI_MISC_A_READ 0x96
16#define ULPI_MISC_A_SET 0x97
17#define ULPI_MISC_A_CLEAR 0x98
18#define ULPI_MISC_A_VBUSVLDEXT BIT(0)
19#define ULPI_MISC_A_VBUSVLDEXTSEL BIT(1)
20#define GEN2_SESS_VLD_CTRL_EN BIT(7)
21#define SESS_VLD_CTRL BIT(25)
22
23struct msm_phy_priv {
24 void __iomem *regs;
25 struct usb_ehci *ehci; /* Start of IP core*/
26 struct ulpi_viewport ulpi_vp; /* ULPI Viewport */
27};
28
29static int msm_phy_power_on(struct phy *phy)
30{
31 struct msm_phy_priv *priv = dev_get_priv(phy->dev);
32
33 /* Select and enable external configuration with USB PHY */
34 ulpi_write(&priv->ulpi_vp, (u8 *)ULPI_MISC_A_SET,
35 ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT);
36
37 return 0;
38}
39
40static int msm_phy_power_off(struct phy *phy)
41{
42 struct msm_phy_priv *priv = dev_get_priv(phy->dev);
43
44 /* Disable VBUS mimicing in the controller. */
45 ulpi_write(&priv->ulpi_vp, (u8 *)ULPI_MISC_A_CLEAR,
46 ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT);
47 return 0;
48}
49
50static int msm_phy_reset(struct phy *phy)
51{
52 struct msm_phy_priv *p = dev_get_priv(phy->dev);
53
54 /* select ULPI phy */
55 writel(PORT_PTS_ULPI, &p->ehci->portsc);
56
57 /* Enable sess_vld */
58 setbits_le32(&p->ehci->genconfig2, GEN2_SESS_VLD_CTRL_EN);
59
60 /* Enable external vbus configuration in the LINK */
61 setbits_le32(&p->ehci->usbcmd, SESS_VLD_CTRL);
62
63 /* USB_OTG_HS_AHB_BURST */
64 writel(0x0, &p->ehci->sbuscfg);
65
66 /* USB_OTG_HS_AHB_MODE: HPROT_MODE */
67 /* Bus access related config. */
68 writel(0x08, &p->ehci->sbusmode);
69
70 return 0;
71}
72
73static int msm_phy_probe(struct udevice *dev)
74{
75 struct msm_phy_priv *priv = dev_get_priv(dev);
76
77 priv->regs = dev_remap_addr(dev);
78 if (!priv->regs)
79 return -EINVAL;
80
81 priv->ehci = (struct usb_ehci *)priv->regs;
82 priv->ulpi_vp.port_num = 0;
83
84 /* Warning: this will not work if viewport address is > 64 bit due to
85 * ULPI design.
86 */
87 priv->ulpi_vp.viewport_addr = (phys_addr_t)&priv->ehci->ulpi_viewpoint;
88
89 return 0;
90}
91
92static struct phy_ops msm_phy_ops = {
93 .power_on = msm_phy_power_on,
94 .power_off = msm_phy_power_off,
95 .reset = msm_phy_reset,
96};
97
98static const struct udevice_id msm_phy_ids[] = {
99 { .compatible = "qcom,apq8016-usbphy" },
100 { }
101};
102
103U_BOOT_DRIVER(msm8916_usbphy) = {
104 .name = "msm8916_usbphy",
105 .id = UCLASS_PHY,
106 .of_match = msm_phy_ids,
107 .ops = &msm_phy_ops,
108 .probe = msm_phy_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700109 .priv_auto = sizeof(struct msm_phy_priv),
Ramon Fried019fb8c2018-09-21 13:35:47 +0300110};