1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2011 Jana Rapava <fermata7@gmail.com>
4 * Copyright (C) 2011 CompuLab, Ltd. <www.compulab.co.il>
6 * Authors: Jana Rapava <fermata7@gmail.com>
7 * Igor Grinberg <grinberg@compulab.co.il>
10 * linux/drivers/usb/otg/ulpi_viewport.c
12 * Original Copyright follow:
13 * Copyright (C) 2011 Google, Inc.
20 /* ULPI viewport control bits */
21 #define ULPI_SS (1 << 27)
22 #define ULPI_RWCTRL (1 << 29)
23 #define ULPI_RWRUN (1 << 30)
24 #define ULPI_WU (1 << 31)
27 * Wait for the ULPI request to complete
29 * @ulpi_viewport - the address of the viewport
30 * @mask - expected value to wait for
32 * returns 0 on mask match, ULPI_ERROR on time out.
34 static int ulpi_wait(struct ulpi_viewport *ulpi_vp, u32 mask)
36 int timeout = CONFIG_USB_ULPI_TIMEOUT;
38 /* Wait for the bits in mask to become zero. */
40 if ((readl(ulpi_vp->viewport_addr) & mask) == 0)
50 * Wake the ULPI PHY up for communication
52 * returns 0 on success.
54 static int ulpi_wakeup(struct ulpi_viewport *ulpi_vp)
58 if (readl(ulpi_vp->viewport_addr) & ULPI_SS)
59 return 0; /* already awake */
61 writel(ULPI_WU, ulpi_vp->viewport_addr);
63 err = ulpi_wait(ulpi_vp, ULPI_WU);
65 printf("ULPI wakeup timed out\n");
71 * Issue a ULPI read/write request
73 * @value - the ULPI request
75 static int ulpi_request(struct ulpi_viewport *ulpi_vp, u32 value)
79 err = ulpi_wakeup(ulpi_vp);
83 writel(value, ulpi_vp->viewport_addr);
85 err = ulpi_wait(ulpi_vp, ULPI_RWRUN);
87 printf("ULPI request timed out\n");
92 int ulpi_write(struct ulpi_viewport *ulpi_vp, u8 *reg, u32 value)
94 u32 addr = (uintptr_t)reg & 0xFF;
95 u32 val = ULPI_RWRUN | ULPI_RWCTRL | addr << 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 | ((uintptr_t)reg & 0xFF) << 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;