2 * OMAP ulpi viewport support
3 * Based on drivers/usb/ulpi/ulpi-viewport.c
5 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com
6 * Author: Govindraj R <govindraj.raja@ti.com>
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 of
10 * the License as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #define OMAP_ULPI_WR_OPSEL (3 << 21)
26 #define OMAP_ULPI_ACCESS (1 << 31)
29 * Wait for the ULPI Access to complete
31 static int ulpi_wait(struct ulpi_viewport *ulpi_vp, u32 mask)
33 int timeout = CONFIG_USB_ULPI_TIMEOUT;
36 if ((readl(ulpi_vp->viewport_addr) & mask))
46 * Wake the ULPI PHY up for communication
48 * returns 0 on success.
50 static int ulpi_wakeup(struct ulpi_viewport *ulpi_vp)
54 if (readl(ulpi_vp->viewport_addr) & OMAP_ULPI_ACCESS)
55 return 0; /* already awake */
57 writel(OMAP_ULPI_ACCESS, ulpi_vp->viewport_addr);
59 err = ulpi_wait(ulpi_vp, OMAP_ULPI_ACCESS);
61 debug("ULPI wakeup timed out\n");
67 * Issue a ULPI read/write request
69 static int ulpi_request(struct ulpi_viewport *ulpi_vp, u32 value)
73 err = ulpi_wakeup(ulpi_vp);
77 writel(value, ulpi_vp->viewport_addr);
79 err = ulpi_wait(ulpi_vp, OMAP_ULPI_ACCESS);
81 debug("ULPI request timed out\n");
86 int ulpi_write(struct ulpi_viewport *ulpi_vp, u8 *reg, u32 value)
88 u32 val = ((ulpi_vp->port_num & 0xf) << 24) |
89 OMAP_ULPI_WR_OPSEL | ((u32)reg << 16) | (value & 0xff);
91 return ulpi_request(ulpi_vp, val);
94 u32 ulpi_read(struct ulpi_viewport *ulpi_vp, u8 *reg)
97 u32 val = ((ulpi_vp->port_num & 0xf) << 24) |
98 OMAP_ULPI_WR_OPSEL | ((u32)reg << 16);
100 err = ulpi_request(ulpi_vp, val);
104 return readl(ulpi_vp->viewport_addr) & 0xff;