1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2011 Google, Inc.
6 #include <linux/export.h>
7 #include <linux/kernel.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;
26 if (!(readl(view
) & mask
))
35 static int ulpi_viewport_read(struct usb_phy
*otg
, u32 reg
)
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
);
45 writel(ULPI_VIEW_RUN
| ULPI_VIEW_READ
| ULPI_VIEW_ADDR(reg
), view
);
46 ret
= ulpi_viewport_wait(view
, ULPI_VIEW_RUN
);
50 return ULPI_VIEW_DATA_READ(readl(view
));
53 static int ulpi_viewport_write(struct usb_phy
*otg
, u32 val
, u32 reg
)
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
);
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
);