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