2 * Copyright (C) 2011 Jana Rapava <fermata7@gmail.com>
3 * Copyright (C) 2011 CompuLab, Ltd. <www.compulab.co.il>
5 * Authors: Jana Rapava <fermata7@gmail.com>
6 * Igor Grinberg <grinberg@compulab.co.il>
9 * linux/drivers/usb/otg/ulpi_viewport.c
11 * Original Copyright follow:
12 * Copyright (C) 2011 Google, Inc.
14 * SPDX-License-Identifier: GPL-2.0
21 /* ULPI viewport control bits */
22 #define ULPI_SS (1 << 27)
23 #define ULPI_RWCTRL (1 << 29)
24 #define ULPI_RWRUN (1 << 30)
25 #define ULPI_WU (1 << 31)
28 * Wait for the ULPI request to complete
30 * @ulpi_viewport - the address of the viewport
31 * @mask - expected value to wait for
33 * returns 0 on mask match, ULPI_ERROR on time out.
35 static int ulpi_wait(struct ulpi_viewport *ulpi_vp, u32 mask)
37 int timeout = CONFIG_USB_ULPI_TIMEOUT;
39 /* Wait for the bits in mask to become zero. */
41 if ((readl(ulpi_vp->viewport_addr) & mask) == 0)
51 * Wake the ULPI PHY up for communication
53 * returns 0 on success.
55 static int ulpi_wakeup(struct ulpi_viewport *ulpi_vp)
59 if (readl(ulpi_vp->viewport_addr) & ULPI_SS)
60 return 0; /* already awake */
62 writel(ULPI_WU, ulpi_vp->viewport_addr);
64 err = ulpi_wait(ulpi_vp, ULPI_WU);
66 printf("ULPI wakeup timed out\n");
72 * Issue a ULPI read/write request
74 * @value - the ULPI request
76 static int ulpi_request(struct ulpi_viewport *ulpi_vp, u32 value)
80 err = ulpi_wakeup(ulpi_vp);
84 writel(value, ulpi_vp->viewport_addr);
86 err = ulpi_wait(ulpi_vp, ULPI_RWRUN);
88 printf("ULPI request timed out\n");
93 int ulpi_write(struct ulpi_viewport *ulpi_vp, u8 *reg, u32 value)
95 u32 val = ULPI_RWRUN | ULPI_RWCTRL | ((u32)reg << 16) | (value & 0xff);
97 val |= (ulpi_vp->port_num & 0x7) << 24;
98 return ulpi_request(ulpi_vp, val);
101 u32 ulpi_read(struct ulpi_viewport *ulpi_vp, u8 *reg)
104 u32 val = ULPI_RWRUN | ((u32)reg << 16);
106 val |= (ulpi_vp->port_num & 0x7) << 24;
107 err = ulpi_request(ulpi_vp, val);
111 return (readl(ulpi_vp->viewport_addr) >> 8) & 0xff;