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 | * |
Tom Rini | e237880 | 2016-01-14 22:05:13 -0500 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0 |
Govindraj.R | c5e5707 | 2012-02-06 03:55:32 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <asm/io.h> |
| 13 | #include <usb/ulpi.h> |
| 14 | |
Michael Trimarchi | df477ac | 2013-06-10 18:18:04 +0200 | [diff] [blame] | 15 | #define OMAP_ULPI_WR_OPSEL (2 << 22) |
| 16 | #define OMAP_ULPI_RD_OPSEL (3 << 22) |
| 17 | #define OMAP_ULPI_START (1 << 31) |
Govindraj.R | c5e5707 | 2012-02-06 03:55:32 +0000 | [diff] [blame] | 18 | |
| 19 | /* |
Michael Trimarchi | df477ac | 2013-06-10 18:18:04 +0200 | [diff] [blame] | 20 | * Wait for having ulpi in done state |
Govindraj.R | c5e5707 | 2012-02-06 03:55:32 +0000 | [diff] [blame] | 21 | */ |
| 22 | static int ulpi_wait(struct ulpi_viewport *ulpi_vp, u32 mask) |
| 23 | { |
| 24 | int timeout = CONFIG_USB_ULPI_TIMEOUT; |
| 25 | |
| 26 | while (--timeout) { |
Michael Trimarchi | df477ac | 2013-06-10 18:18:04 +0200 | [diff] [blame] | 27 | if (!(readl(ulpi_vp->viewport_addr) & mask)) |
Govindraj.R | c5e5707 | 2012-02-06 03:55:32 +0000 | [diff] [blame] | 28 | return 0; |
| 29 | |
| 30 | udelay(1); |
| 31 | } |
| 32 | |
| 33 | return ULPI_ERROR; |
| 34 | } |
| 35 | |
| 36 | /* |
Govindraj.R | c5e5707 | 2012-02-06 03:55:32 +0000 | [diff] [blame] | 37 | * Issue a ULPI read/write request |
| 38 | */ |
| 39 | static int ulpi_request(struct ulpi_viewport *ulpi_vp, u32 value) |
| 40 | { |
| 41 | int err; |
| 42 | |
Govindraj.R | c5e5707 | 2012-02-06 03:55:32 +0000 | [diff] [blame] | 43 | writel(value, ulpi_vp->viewport_addr); |
| 44 | |
Michael Trimarchi | df477ac | 2013-06-10 18:18:04 +0200 | [diff] [blame] | 45 | err = ulpi_wait(ulpi_vp, OMAP_ULPI_START); |
Govindraj.R | c5e5707 | 2012-02-06 03:55:32 +0000 | [diff] [blame] | 46 | if (err) |
| 47 | debug("ULPI request timed out\n"); |
| 48 | |
| 49 | return err; |
| 50 | } |
| 51 | |
| 52 | int ulpi_write(struct ulpi_viewport *ulpi_vp, u8 *reg, u32 value) |
| 53 | { |
Michael Trimarchi | df477ac | 2013-06-10 18:18:04 +0200 | [diff] [blame] | 54 | u32 val = OMAP_ULPI_START | (((ulpi_vp->port_num + 1) & 0xf) << 24) | |
Govindraj.R | c5e5707 | 2012-02-06 03:55:32 +0000 | [diff] [blame] | 55 | OMAP_ULPI_WR_OPSEL | ((u32)reg << 16) | (value & 0xff); |
| 56 | |
| 57 | return ulpi_request(ulpi_vp, val); |
| 58 | } |
| 59 | |
| 60 | u32 ulpi_read(struct ulpi_viewport *ulpi_vp, u8 *reg) |
| 61 | { |
| 62 | int err; |
Michael Trimarchi | df477ac | 2013-06-10 18:18:04 +0200 | [diff] [blame] | 63 | u32 val = OMAP_ULPI_START | (((ulpi_vp->port_num + 1) & 0xf) << 24) | |
| 64 | OMAP_ULPI_RD_OPSEL | ((u32)reg << 16); |
Govindraj.R | c5e5707 | 2012-02-06 03:55:32 +0000 | [diff] [blame] | 65 | |
| 66 | err = ulpi_request(ulpi_vp, val); |
| 67 | if (err) |
| 68 | return err; |
| 69 | |
| 70 | return readl(ulpi_vp->viewport_addr) & 0xff; |
| 71 | } |