blob: 67cdebc0fccf35cea317fe60fd73586d0ed14bb2 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Govindraj.R928c4bd2012-02-06 03:55:32 +00002/*
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.R928c4bd2012-02-06 03:55:32 +00008 */
9
10#include <common.h>
11#include <asm/io.h>
12#include <usb/ulpi.h>
13
Michael Trimarchib0857c42013-06-10 18:18:04 +020014#define OMAP_ULPI_WR_OPSEL (2 << 22)
15#define OMAP_ULPI_RD_OPSEL (3 << 22)
16#define OMAP_ULPI_START (1 << 31)
Govindraj.R928c4bd2012-02-06 03:55:32 +000017
18/*
Michael Trimarchib0857c42013-06-10 18:18:04 +020019 * Wait for having ulpi in done state
Govindraj.R928c4bd2012-02-06 03:55:32 +000020 */
21static int ulpi_wait(struct ulpi_viewport *ulpi_vp, u32 mask)
22{
23 int timeout = CONFIG_USB_ULPI_TIMEOUT;
24
25 while (--timeout) {
Michael Trimarchib0857c42013-06-10 18:18:04 +020026 if (!(readl(ulpi_vp->viewport_addr) & mask))
Govindraj.R928c4bd2012-02-06 03:55:32 +000027 return 0;
28
29 udelay(1);
30 }
31
32 return ULPI_ERROR;
33}
34
35/*
Govindraj.R928c4bd2012-02-06 03:55:32 +000036 * Issue a ULPI read/write request
37 */
38static int ulpi_request(struct ulpi_viewport *ulpi_vp, u32 value)
39{
40 int err;
41
Govindraj.R928c4bd2012-02-06 03:55:32 +000042 writel(value, ulpi_vp->viewport_addr);
43
Michael Trimarchib0857c42013-06-10 18:18:04 +020044 err = ulpi_wait(ulpi_vp, OMAP_ULPI_START);
Govindraj.R928c4bd2012-02-06 03:55:32 +000045 if (err)
46 debug("ULPI request timed out\n");
47
48 return err;
49}
50
51int ulpi_write(struct ulpi_viewport *ulpi_vp, u8 *reg, u32 value)
52{
Michael Trimarchib0857c42013-06-10 18:18:04 +020053 u32 val = OMAP_ULPI_START | (((ulpi_vp->port_num + 1) & 0xf) << 24) |
Govindraj.R928c4bd2012-02-06 03:55:32 +000054 OMAP_ULPI_WR_OPSEL | ((u32)reg << 16) | (value & 0xff);
55
56 return ulpi_request(ulpi_vp, val);
57}
58
59u32 ulpi_read(struct ulpi_viewport *ulpi_vp, u8 *reg)
60{
61 int err;
Michael Trimarchib0857c42013-06-10 18:18:04 +020062 u32 val = OMAP_ULPI_START | (((ulpi_vp->port_num + 1) & 0xf) << 24) |
63 OMAP_ULPI_RD_OPSEL | ((u32)reg << 16);
Govindraj.R928c4bd2012-02-06 03:55:32 +000064
65 err = ulpi_request(ulpi_vp, val);
66 if (err)
67 return err;
68
69 return readl(ulpi_vp->viewport_addr) & 0xff;
70}