blob: 6f0c3eb154ee40ce57d6a4cf10613043060d87ca [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
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Govindraj.Rc5e57072012-02-06 03:55:32 +000011#include <asm/io.h>
Simon Glassdbd79542020-05-10 11:40:11 -060012#include <linux/delay.h>
Govindraj.Rc5e57072012-02-06 03:55:32 +000013#include <usb/ulpi.h>
14
Michael Trimarchidf477ac2013-06-10 18:18:04 +020015#define OMAP_ULPI_WR_OPSEL (2 << 22)
16#define OMAP_ULPI_RD_OPSEL (3 << 22)
17#define OMAP_ULPI_START (1 << 31)
Govindraj.Rc5e57072012-02-06 03:55:32 +000018
19/*
Michael Trimarchidf477ac2013-06-10 18:18:04 +020020 * Wait for having ulpi in done state
Govindraj.Rc5e57072012-02-06 03:55:32 +000021 */
22static int ulpi_wait(struct ulpi_viewport *ulpi_vp, u32 mask)
23{
Tom Rini364d0022023-01-10 11:19:45 -050024 int timeout = CFG_USB_ULPI_TIMEOUT;
Govindraj.Rc5e57072012-02-06 03:55:32 +000025
26 while (--timeout) {
Michael Trimarchidf477ac2013-06-10 18:18:04 +020027 if (!(readl(ulpi_vp->viewport_addr) & mask))
Govindraj.Rc5e57072012-02-06 03:55:32 +000028 return 0;
29
30 udelay(1);
31 }
32
33 return ULPI_ERROR;
34}
35
36/*
Govindraj.Rc5e57072012-02-06 03:55:32 +000037 * Issue a ULPI read/write request
38 */
39static int ulpi_request(struct ulpi_viewport *ulpi_vp, u32 value)
40{
41 int err;
42
Govindraj.Rc5e57072012-02-06 03:55:32 +000043 writel(value, ulpi_vp->viewport_addr);
44
Michael Trimarchidf477ac2013-06-10 18:18:04 +020045 err = ulpi_wait(ulpi_vp, OMAP_ULPI_START);
Govindraj.Rc5e57072012-02-06 03:55:32 +000046 if (err)
47 debug("ULPI request timed out\n");
48
49 return err;
50}
51
52int ulpi_write(struct ulpi_viewport *ulpi_vp, u8 *reg, u32 value)
53{
Michael Trimarchidf477ac2013-06-10 18:18:04 +020054 u32 val = OMAP_ULPI_START | (((ulpi_vp->port_num + 1) & 0xf) << 24) |
Govindraj.Rc5e57072012-02-06 03:55:32 +000055 OMAP_ULPI_WR_OPSEL | ((u32)reg << 16) | (value & 0xff);
56
57 return ulpi_request(ulpi_vp, val);
58}
59
60u32 ulpi_read(struct ulpi_viewport *ulpi_vp, u8 *reg)
61{
62 int err;
Michael Trimarchidf477ac2013-06-10 18:18:04 +020063 u32 val = OMAP_ULPI_START | (((ulpi_vp->port_num + 1) & 0xf) << 24) |
64 OMAP_ULPI_RD_OPSEL | ((u32)reg << 16);
Govindraj.Rc5e57072012-02-06 03:55:32 +000065
66 err = ulpi_request(ulpi_vp, val);
67 if (err)
68 return err;
69
70 return readl(ulpi_vp->viewport_addr) & 0xff;
71}