ARM: socfpga: Enable SMP for socfpga
[linux-2.6.git] / drivers / usb / otg / ulpi_viewport.c
blobc5ba7e5423fc5626701aeb029e6c720d90649c18
1 /*
2 * Copyright (C) 2011 Google, Inc.
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
15 #include <linux/kernel.h>
16 #include <linux/usb.h>
17 #include <linux/io.h>
18 #include <linux/usb/otg.h>
19 #include <linux/usb/ulpi.h>
21 #define ULPI_VIEW_WAKEUP (1 << 31)
22 #define ULPI_VIEW_RUN (1 << 30)
23 #define ULPI_VIEW_WRITE (1 << 29)
24 #define ULPI_VIEW_READ (0 << 29)
25 #define ULPI_VIEW_ADDR(x) (((x) & 0xff) << 16)
26 #define ULPI_VIEW_DATA_READ(x) (((x) >> 8) & 0xff)
27 #define ULPI_VIEW_DATA_WRITE(x) ((x) & 0xff)
29 static int ulpi_viewport_wait(void __iomem *view, u32 mask)
31 unsigned long usec = 2000;
33 while (usec--) {
34 if (!(readl(view) & mask))
35 return 0;
37 udelay(1);
40 return -ETIMEDOUT;
43 static int ulpi_viewport_read(struct usb_phy *otg, u32 reg)
45 int ret;
46 void __iomem *view = otg->io_priv;
48 writel(ULPI_VIEW_WAKEUP | ULPI_VIEW_WRITE, view);
49 ret = ulpi_viewport_wait(view, ULPI_VIEW_WAKEUP);
50 if (ret)
51 return ret;
53 writel(ULPI_VIEW_RUN | ULPI_VIEW_READ | ULPI_VIEW_ADDR(reg), view);
54 ret = ulpi_viewport_wait(view, ULPI_VIEW_RUN);
55 if (ret)
56 return ret;
58 return ULPI_VIEW_DATA_READ(readl(view));
61 static int ulpi_viewport_write(struct usb_phy *otg, u32 val, u32 reg)
63 int ret;
64 void __iomem *view = otg->io_priv;
66 writel(ULPI_VIEW_WAKEUP | ULPI_VIEW_WRITE, view);
67 ret = ulpi_viewport_wait(view, ULPI_VIEW_WAKEUP);
68 if (ret)
69 return ret;
71 writel(ULPI_VIEW_RUN | ULPI_VIEW_WRITE | ULPI_VIEW_DATA_WRITE(val) |
72 ULPI_VIEW_ADDR(reg), view);
74 return ulpi_viewport_wait(view, ULPI_VIEW_RUN);
77 struct usb_phy_io_ops ulpi_viewport_access_ops = {
78 .read = ulpi_viewport_read,
79 .write = ulpi_viewport_write,