Linux 4.16.11
[linux/fpc-iii.git] / drivers / usb / phy / phy-ulpi-viewport.c
blob7a14e0e3b6350c599155cc496b03b0b6e69a17ca
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2011 Google, Inc.
4 */
6 #include <linux/export.h>
7 #include <linux/kernel.h>
8 #include <linux/usb.h>
9 #include <linux/io.h>
10 #include <linux/usb/otg.h>
11 #include <linux/usb/ulpi.h>
13 #define ULPI_VIEW_WAKEUP (1 << 31)
14 #define ULPI_VIEW_RUN (1 << 30)
15 #define ULPI_VIEW_WRITE (1 << 29)
16 #define ULPI_VIEW_READ (0 << 29)
17 #define ULPI_VIEW_ADDR(x) (((x) & 0xff) << 16)
18 #define ULPI_VIEW_DATA_READ(x) (((x) >> 8) & 0xff)
19 #define ULPI_VIEW_DATA_WRITE(x) ((x) & 0xff)
21 static int ulpi_viewport_wait(void __iomem *view, u32 mask)
23 unsigned long usec = 2000;
25 while (usec--) {
26 if (!(readl(view) & mask))
27 return 0;
29 udelay(1);
32 return -ETIMEDOUT;
35 static int ulpi_viewport_read(struct usb_phy *otg, u32 reg)
37 int ret;
38 void __iomem *view = otg->io_priv;
40 writel(ULPI_VIEW_WAKEUP | ULPI_VIEW_WRITE, view);
41 ret = ulpi_viewport_wait(view, ULPI_VIEW_WAKEUP);
42 if (ret)
43 return ret;
45 writel(ULPI_VIEW_RUN | ULPI_VIEW_READ | ULPI_VIEW_ADDR(reg), view);
46 ret = ulpi_viewport_wait(view, ULPI_VIEW_RUN);
47 if (ret)
48 return ret;
50 return ULPI_VIEW_DATA_READ(readl(view));
53 static int ulpi_viewport_write(struct usb_phy *otg, u32 val, u32 reg)
55 int ret;
56 void __iomem *view = otg->io_priv;
58 writel(ULPI_VIEW_WAKEUP | ULPI_VIEW_WRITE, view);
59 ret = ulpi_viewport_wait(view, ULPI_VIEW_WAKEUP);
60 if (ret)
61 return ret;
63 writel(ULPI_VIEW_RUN | ULPI_VIEW_WRITE | ULPI_VIEW_DATA_WRITE(val) |
64 ULPI_VIEW_ADDR(reg), view);
66 return ulpi_viewport_wait(view, ULPI_VIEW_RUN);
69 struct usb_phy_io_ops ulpi_viewport_access_ops = {
70 .read = ulpi_viewport_read,
71 .write = ulpi_viewport_write,
73 EXPORT_SYMBOL_GPL(ulpi_viewport_access_ops);