2 * ulpi.c - DesignWare USB3 Controller's ULPI PHY interface
4 * Copyright (C) 2015 Intel Corporation
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 ulpi_ops *ops, u8 addr)
40 struct dwc3 *dwc = dev_get_drvdata(ops->dev);
44 reg = DWC3_GUSB2PHYACC_NEWREGREQ | DWC3_ULPI_ADDR(addr);
45 dwc3_writel(dwc->regs, DWC3_GUSB2PHYACC(0), reg);
47 ret = dwc3_ulpi_busyloop(dwc);
51 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYACC(0));
53 return DWC3_GUSB2PHYACC_DATA(reg);
56 static int dwc3_ulpi_write(struct ulpi_ops *ops, u8 addr, u8 val)
58 struct dwc3 *dwc = dev_get_drvdata(ops->dev);
61 reg = DWC3_GUSB2PHYACC_NEWREGREQ | DWC3_ULPI_ADDR(addr);
62 reg |= DWC3_GUSB2PHYACC_WRITE | val;
63 dwc3_writel(dwc->regs, DWC3_GUSB2PHYACC(0), reg);
65 return dwc3_ulpi_busyloop(dwc);
68 static struct ulpi_ops dwc3_ulpi_ops = {
69 .read = dwc3_ulpi_read,
70 .write = dwc3_ulpi_write,
73 int dwc3_ulpi_init(struct dwc3 *dwc)
75 /* Register the interface */
76 dwc->ulpi = ulpi_register_interface(dwc->dev, &dwc3_ulpi_ops);
77 if (IS_ERR(dwc->ulpi)) {
78 dev_err(dwc->dev, "failed to register ULPI interface");
79 return PTR_ERR(dwc->ulpi);
85 void dwc3_ulpi_exit(struct dwc3 *dwc)
88 ulpi_unregister_interface(dwc->ulpi);