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