Govindraj.R | c5e5707 | 2012-02-06 03:55:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * OMAP ulpi viewport support |
| 3 | * Based on drivers/usb/ulpi/ulpi-viewport.c |
| 4 | * |
| 5 | * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com |
| 6 | * Author: Govindraj R <govindraj.raja@ti.com> |
| 7 | * |
| 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. |
| 11 | * |
| 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. |
| 16 | * |
| 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/>. |
| 19 | */ |
| 20 | |
| 21 | #include <common.h> |
| 22 | #include <asm/io.h> |
| 23 | #include <usb/ulpi.h> |
| 24 | |
Michael Trimarchi | df477ac | 2013-06-10 18:18:04 +0200 | [diff] [blame] | 25 | #define OMAP_ULPI_WR_OPSEL (2 << 22) |
| 26 | #define OMAP_ULPI_RD_OPSEL (3 << 22) |
| 27 | #define OMAP_ULPI_START (1 << 31) |
Govindraj.R | c5e5707 | 2012-02-06 03:55:32 +0000 | [diff] [blame] | 28 | |
| 29 | /* |
Michael Trimarchi | df477ac | 2013-06-10 18:18:04 +0200 | [diff] [blame] | 30 | * Wait for having ulpi in done state |
Govindraj.R | c5e5707 | 2012-02-06 03:55:32 +0000 | [diff] [blame] | 31 | */ |
| 32 | static int ulpi_wait(struct ulpi_viewport *ulpi_vp, u32 mask) |
| 33 | { |
| 34 | int timeout = CONFIG_USB_ULPI_TIMEOUT; |
| 35 | |
| 36 | while (--timeout) { |
Michael Trimarchi | df477ac | 2013-06-10 18:18:04 +0200 | [diff] [blame] | 37 | if (!(readl(ulpi_vp->viewport_addr) & mask)) |
Govindraj.R | c5e5707 | 2012-02-06 03:55:32 +0000 | [diff] [blame] | 38 | return 0; |
| 39 | |
| 40 | udelay(1); |
| 41 | } |
| 42 | |
| 43 | return ULPI_ERROR; |
| 44 | } |
| 45 | |
| 46 | /* |
Govindraj.R | c5e5707 | 2012-02-06 03:55:32 +0000 | [diff] [blame] | 47 | * Issue a ULPI read/write request |
| 48 | */ |
| 49 | static int ulpi_request(struct ulpi_viewport *ulpi_vp, u32 value) |
| 50 | { |
| 51 | int err; |
| 52 | |
Govindraj.R | c5e5707 | 2012-02-06 03:55:32 +0000 | [diff] [blame] | 53 | writel(value, ulpi_vp->viewport_addr); |
| 54 | |
Michael Trimarchi | df477ac | 2013-06-10 18:18:04 +0200 | [diff] [blame] | 55 | err = ulpi_wait(ulpi_vp, OMAP_ULPI_START); |
Govindraj.R | c5e5707 | 2012-02-06 03:55:32 +0000 | [diff] [blame] | 56 | if (err) |
| 57 | debug("ULPI request timed out\n"); |
| 58 | |
| 59 | return err; |
| 60 | } |
| 61 | |
| 62 | int ulpi_write(struct ulpi_viewport *ulpi_vp, u8 *reg, u32 value) |
| 63 | { |
Michael Trimarchi | df477ac | 2013-06-10 18:18:04 +0200 | [diff] [blame] | 64 | u32 val = OMAP_ULPI_START | (((ulpi_vp->port_num + 1) & 0xf) << 24) | |
Govindraj.R | c5e5707 | 2012-02-06 03:55:32 +0000 | [diff] [blame] | 65 | OMAP_ULPI_WR_OPSEL | ((u32)reg << 16) | (value & 0xff); |
| 66 | |
| 67 | return ulpi_request(ulpi_vp, val); |
| 68 | } |
| 69 | |
| 70 | u32 ulpi_read(struct ulpi_viewport *ulpi_vp, u8 *reg) |
| 71 | { |
| 72 | int err; |
Michael Trimarchi | df477ac | 2013-06-10 18:18:04 +0200 | [diff] [blame] | 73 | u32 val = OMAP_ULPI_START | (((ulpi_vp->port_num + 1) & 0xf) << 24) | |
| 74 | OMAP_ULPI_RD_OPSEL | ((u32)reg << 16); |
Govindraj.R | c5e5707 | 2012-02-06 03:55:32 +0000 | [diff] [blame] | 75 | |
| 76 | err = ulpi_request(ulpi_vp, val); |
| 77 | if (err) |
| 78 | return err; |
| 79 | |
| 80 | return readl(ulpi_vp->viewport_addr) & 0xff; |
| 81 | } |