blob: 8b930e3fa919bf1a510952724be8da624c664e83 [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>
Simon Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Govindraj.R928c4bd2012-02-06 03:55:32 +000012#include <asm/io.h>
Simon Glassc05ed002020-05-10 11:40:11 -060013#include <linux/delay.h>
Govindraj.R928c4bd2012-02-06 03:55:32 +000014#include <usb/ulpi.h>
15
Michael Trimarchib0857c42013-06-10 18:18:04 +020016#define OMAP_ULPI_WR_OPSEL (2 << 22)
17#define OMAP_ULPI_RD_OPSEL (3 << 22)
18#define OMAP_ULPI_START (1 << 31)
Govindraj.R928c4bd2012-02-06 03:55:32 +000019
20/*
Michael Trimarchib0857c42013-06-10 18:18:04 +020021 * Wait for having ulpi in done state
Govindraj.R928c4bd2012-02-06 03:55:32 +000022 */
23static int ulpi_wait(struct ulpi_viewport *ulpi_vp, u32 mask)
24{
25 int timeout = CONFIG_USB_ULPI_TIMEOUT;
26
27 while (--timeout) {
Michael Trimarchib0857c42013-06-10 18:18:04 +020028 if (!(readl(ulpi_vp->viewport_addr) & mask))
Govindraj.R928c4bd2012-02-06 03:55:32 +000029 return 0;
30
31 udelay(1);
32 }
33
34 return ULPI_ERROR;
35}
36
37/*
Govindraj.R928c4bd2012-02-06 03:55:32 +000038 * Issue a ULPI read/write request
39 */
40static int ulpi_request(struct ulpi_viewport *ulpi_vp, u32 value)
41{
42 int err;
43
Govindraj.R928c4bd2012-02-06 03:55:32 +000044 writel(value, ulpi_vp->viewport_addr);
45
Michael Trimarchib0857c42013-06-10 18:18:04 +020046 err = ulpi_wait(ulpi_vp, OMAP_ULPI_START);
Govindraj.R928c4bd2012-02-06 03:55:32 +000047 if (err)
48 debug("ULPI request timed out\n");
49
50 return err;
51}
52
53int ulpi_write(struct ulpi_viewport *ulpi_vp, u8 *reg, u32 value)
54{
Michael Trimarchib0857c42013-06-10 18:18:04 +020055 u32 val = OMAP_ULPI_START | (((ulpi_vp->port_num + 1) & 0xf) << 24) |
Govindraj.R928c4bd2012-02-06 03:55:32 +000056 OMAP_ULPI_WR_OPSEL | ((u32)reg << 16) | (value & 0xff);
57
58 return ulpi_request(ulpi_vp, val);
59}
60
61u32 ulpi_read(struct ulpi_viewport *ulpi_vp, u8 *reg)
62{
63 int err;
Michael Trimarchib0857c42013-06-10 18:18:04 +020064 u32 val = OMAP_ULPI_START | (((ulpi_vp->port_num + 1) & 0xf) << 24) |
65 OMAP_ULPI_RD_OPSEL | ((u32)reg << 16);
Govindraj.R928c4bd2012-02-06 03:55:32 +000066
67 err = ulpi_request(ulpi_vp, val);
68 if (err)
69 return err;
70
71 return readl(ulpi_vp->viewport_addr) & 0xff;
72}