2 * ulpi.c - DesignWare USB3 Controller's ULPI PHY interface
4 * Copyright (C) 2015 Intel Corporation
6 * Author: Heikki Krogerus <heikki.krogerus@linux.intel.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/ulpi/regs.h>
18 #define DWC3_ULPI_ADDR(a) \
19 ((a >= ULPI_EXT_VENDOR_SPECIFIC) ? \
20 DWC3_GUSB2PHYACC_ADDR(ULPI_ACCESS_EXTENDED) | \
21 DWC3_GUSB2PHYACC_EXTEND_ADDR(a) : DWC3_GUSB2PHYACC_ADDR(a))
23 static int dwc3_ulpi_busyloop(struct dwc3
*dwc
)
25 unsigned count
= 1000;
29 reg
= dwc3_readl(dwc
->regs
, DWC3_GUSB2PHYACC(0));
30 if (!(reg
& DWC3_GUSB2PHYACC_BUSY
))
38 static int dwc3_ulpi_read(struct device
*dev
, u8 addr
)
40 struct dwc3
*dwc
= dev_get_drvdata(dev
);
44 reg
= dwc3_readl(dwc
->regs
, DWC3_GUSB2PHYCFG(0));
45 if (reg
& DWC3_GUSB2PHYCFG_SUSPHY
) {
46 reg
&= ~DWC3_GUSB2PHYCFG_SUSPHY
;
47 dwc3_writel(dwc
->regs
, DWC3_GUSB2PHYCFG(0), reg
);
50 reg
= DWC3_GUSB2PHYACC_NEWREGREQ
| DWC3_ULPI_ADDR(addr
);
51 dwc3_writel(dwc
->regs
, DWC3_GUSB2PHYACC(0), reg
);
53 ret
= dwc3_ulpi_busyloop(dwc
);
57 reg
= dwc3_readl(dwc
->regs
, DWC3_GUSB2PHYACC(0));
59 return DWC3_GUSB2PHYACC_DATA(reg
);
62 static int dwc3_ulpi_write(struct device
*dev
, u8 addr
, u8 val
)
64 struct dwc3
*dwc
= dev_get_drvdata(dev
);
67 reg
= dwc3_readl(dwc
->regs
, DWC3_GUSB2PHYCFG(0));
68 if (reg
& DWC3_GUSB2PHYCFG_SUSPHY
) {
69 reg
&= ~DWC3_GUSB2PHYCFG_SUSPHY
;
70 dwc3_writel(dwc
->regs
, DWC3_GUSB2PHYCFG(0), reg
);
73 reg
= DWC3_GUSB2PHYACC_NEWREGREQ
| DWC3_ULPI_ADDR(addr
);
74 reg
|= DWC3_GUSB2PHYACC_WRITE
| val
;
75 dwc3_writel(dwc
->regs
, DWC3_GUSB2PHYACC(0), reg
);
77 return dwc3_ulpi_busyloop(dwc
);
80 static const struct ulpi_ops dwc3_ulpi_ops
= {
81 .read
= dwc3_ulpi_read
,
82 .write
= dwc3_ulpi_write
,
85 int dwc3_ulpi_init(struct dwc3
*dwc
)
87 /* Register the interface */
88 dwc
->ulpi
= ulpi_register_interface(dwc
->dev
, &dwc3_ulpi_ops
);
89 if (IS_ERR(dwc
->ulpi
)) {
90 dev_err(dwc
->dev
, "failed to register ULPI interface");
91 return PTR_ERR(dwc
->ulpi
);
97 void dwc3_ulpi_exit(struct dwc3
*dwc
)
100 ulpi_unregister_interface(dwc
->ulpi
);