blob: 1b01cd4c559f7b2e7b2b6df188b1cb2e391efe50 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Govindraj.Rc5e57072012-02-06 03:55:32 +00002/*
3 * OMAP ulpi viewport support
4 * Based on drivers/usb/ulpi/ulpi-viewport.c
5 *
Nishanth Menoneaa39c62023-11-01 15:56:03 -05006 * Copyright (C) 2011 Texas Instruments Incorporated - https://www.ti.com
Govindraj.Rc5e57072012-02-06 03:55:32 +00007 * Author: Govindraj R <govindraj.raja@ti.com>
Govindraj.Rc5e57072012-02-06 03:55:32 +00008 */
9
10#include <common.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Govindraj.Rc5e57072012-02-06 03:55:32 +000012#include <asm/io.h>
Simon Glassdbd79542020-05-10 11:40:11 -060013#include <linux/delay.h>
Govindraj.Rc5e57072012-02-06 03:55:32 +000014#include <usb/ulpi.h>
15
Michael Trimarchidf477ac2013-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.Rc5e57072012-02-06 03:55:32 +000019
20/*
Michael Trimarchidf477ac2013-06-10 18:18:04 +020021 * Wait for having ulpi in done state
Govindraj.Rc5e57072012-02-06 03:55:32 +000022 */
23static int ulpi_wait(struct ulpi_viewport *ulpi_vp, u32 mask)
24{
Tom Rini364d0022023-01-10 11:19:45 -050025 int timeout = CFG_USB_ULPI_TIMEOUT;
Govindraj.Rc5e57072012-02-06 03:55:32 +000026
27 while (--timeout) {
Michael Trimarchidf477ac2013-06-10 18:18:04 +020028 if (!(readl(ulpi_vp->viewport_addr) & mask))
Govindraj.Rc5e57072012-02-06 03:55:32 +000029 return 0;
30
31 udelay(1);
32 }
33
34 return ULPI_ERROR;
35}
36
37/*
Govindraj.Rc5e57072012-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.Rc5e57072012-02-06 03:55:32 +000044 writel(value, ulpi_vp->viewport_addr);
45
Michael Trimarchidf477ac2013-06-10 18:18:04 +020046 err = ulpi_wait(ulpi_vp, OMAP_ULPI_START);
Govindraj.Rc5e57072012-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 Trimarchidf477ac2013-06-10 18:18:04 +020055 u32 val = OMAP_ULPI_START | (((ulpi_vp->port_num + 1) & 0xf) << 24) |
Govindraj.Rc5e57072012-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 Trimarchidf477ac2013-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.Rc5e57072012-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}