blob: 7a14e0e3b6350c599155cc496b03b0b6e69a17ca [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: GPL-2.0
Benoit Gobyee398ba2011-03-09 16:28:54 -08002/*
3 * Copyright (C) 2011 Google, Inc.
Benoit Gobyee398ba2011-03-09 16:28:54 -08004 */
5
Manjunath Goudar9a0e5112013-06-13 11:24:07 -06006#include <linux/export.h>
Benoit Gobyee398ba2011-03-09 16:28:54 -08007#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>
12
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)
20
21static int ulpi_viewport_wait(void __iomem *view, u32 mask)
22{
23 unsigned long usec = 2000;
24
25 while (usec--) {
26 if (!(readl(view) & mask))
27 return 0;
28
29 udelay(1);
Joe Perches2b84f922013-10-08 16:01:37 -070030 }
Benoit Gobyee398ba2011-03-09 16:28:54 -080031
32 return -ETIMEDOUT;
33}
34
Heikki Krogerus86753812012-02-13 13:24:02 +020035static int ulpi_viewport_read(struct usb_phy *otg, u32 reg)
Benoit Gobyee398ba2011-03-09 16:28:54 -080036{
37 int ret;
38 void __iomem *view = otg->io_priv;
39
40 writel(ULPI_VIEW_WAKEUP | ULPI_VIEW_WRITE, view);
41 ret = ulpi_viewport_wait(view, ULPI_VIEW_WAKEUP);
42 if (ret)
43 return ret;
44
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;
49
50 return ULPI_VIEW_DATA_READ(readl(view));
51}
52
Heikki Krogerus86753812012-02-13 13:24:02 +020053static int ulpi_viewport_write(struct usb_phy *otg, u32 val, u32 reg)
Benoit Gobyee398ba2011-03-09 16:28:54 -080054{
55 int ret;
56 void __iomem *view = otg->io_priv;
57
58 writel(ULPI_VIEW_WAKEUP | ULPI_VIEW_WRITE, view);
59 ret = ulpi_viewport_wait(view, ULPI_VIEW_WAKEUP);
60 if (ret)
61 return ret;
62
63 writel(ULPI_VIEW_RUN | ULPI_VIEW_WRITE | ULPI_VIEW_DATA_WRITE(val) |
64 ULPI_VIEW_ADDR(reg), view);
65
66 return ulpi_viewport_wait(view, ULPI_VIEW_RUN);
67}
68
Heikki Krogerus298b0832012-02-13 13:24:13 +020069struct usb_phy_io_ops ulpi_viewport_access_ops = {
Benoit Gobyee398ba2011-03-09 16:28:54 -080070 .read = ulpi_viewport_read,
71 .write = ulpi_viewport_write,
72};
Manjunath Goudar9a0e5112013-06-13 11:24:07 -060073EXPORT_SYMBOL_GPL(ulpi_viewport_access_ops);