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 * This software is licensed under the terms of the GNU General Public
15 * License version 2, as published by the Free Software Foundation, and
16 * may be copied, distributed, and modified under those terms.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
29 /* ULPI viewport control bits */
30 #define ULPI_SS (1 << 27)
31 #define ULPI_RWCTRL (1 << 29)
32 #define ULPI_RWRUN (1 << 30)
33 #define ULPI_WU (1 << 31)
36 * Wait for the ULPI request to complete
38 * @ulpi_viewport - the address of the viewport
39 * @mask - expected value to wait for
41 * returns 0 on mask match, ULPI_ERROR on time out.
43 static int ulpi_wait(struct ulpi_viewport *ulpi_vp, u32 mask)
45 int timeout = CONFIG_USB_ULPI_TIMEOUT;
47 /* Wait for the bits in mask to become zero. */
49 if ((readl(ulpi_vp->viewport_addr) & mask) == 0)
59 * Wake the ULPI PHY up for communication
61 * returns 0 on success.
63 static int ulpi_wakeup(struct ulpi_viewport *ulpi_vp)
67 if (readl(ulpi_vp->viewport_addr) & ULPI_SS)
68 return 0; /* already awake */
70 writel(ULPI_WU, ulpi_vp->viewport_addr);
72 err = ulpi_wait(ulpi_vp, ULPI_WU);
74 printf("ULPI wakeup timed out\n");
80 * Issue a ULPI read/write request
82 * @value - the ULPI request
84 static int ulpi_request(struct ulpi_viewport *ulpi_vp, u32 value)
88 err = ulpi_wakeup(ulpi_vp);
92 writel(value, ulpi_vp->viewport_addr);
94 err = ulpi_wait(ulpi_vp, ULPI_RWRUN);
96 printf("ULPI request timed out\n");
101 int ulpi_write(struct ulpi_viewport *ulpi_vp, u8 *reg, u32 value)
103 u32 val = ULPI_RWRUN | ULPI_RWCTRL | ((u32)reg << 16) | (value & 0xff);
105 val |= (ulpi_vp->port_num & 0x7) << 24;
106 return ulpi_request(ulpi_vp, val);
109 u32 ulpi_read(struct ulpi_viewport *ulpi_vp, u8 *reg)
112 u32 val = ULPI_RWRUN | ((u32)reg << 16);
114 val |= (ulpi_vp->port_num & 0x7) << 24;
115 err = ulpi_request(ulpi_vp, val);
119 return (readl(ulpi_vp->viewport_addr) >> 8) & 0xff;