blob: 0db281b970ef6913694c778868a5428d59c08156 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mugunthan V N1a547132016-04-12 16:01:19 +05302/*
3 * Provides code common for host and device side USB.
4 *
5 * (C) Copyright 2016
6 * Texas Instruments Incorporated, <www.ti.com>
Mugunthan V N1a547132016-04-12 16:01:19 +05307 */
8
9#include <common.h>
Kever Yang1b807052020-03-04 08:59:50 +080010#include <dm.h>
Mugunthan V N1a547132016-04-12 16:01:19 +053011#include <linux/usb/otg.h>
Mugunthan V N58d8fbe2018-05-18 13:15:05 +020012#include <linux/usb/ch9.h>
Mugunthan V N1a547132016-04-12 16:01:19 +053013
14DECLARE_GLOBAL_DATA_PTR;
15
16static const char *const usb_dr_modes[] = {
17 [USB_DR_MODE_UNKNOWN] = "",
18 [USB_DR_MODE_HOST] = "host",
19 [USB_DR_MODE_PERIPHERAL] = "peripheral",
20 [USB_DR_MODE_OTG] = "otg",
21};
22
Kever Yang1b807052020-03-04 08:59:50 +080023enum usb_dr_mode usb_get_dr_mode(ofnode node)
Mugunthan V N1a547132016-04-12 16:01:19 +053024{
Mugunthan V N1a547132016-04-12 16:01:19 +053025 const char *dr_mode;
26 int i;
27
Kever Yang1b807052020-03-04 08:59:50 +080028 dr_mode = ofnode_read_string(node, "dr_mode");
Mugunthan V N1a547132016-04-12 16:01:19 +053029 if (!dr_mode) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090030 pr_err("usb dr_mode not found\n");
Mugunthan V N1a547132016-04-12 16:01:19 +053031 return USB_DR_MODE_UNKNOWN;
32 }
33
34 for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
35 if (!strcmp(dr_mode, usb_dr_modes[i]))
36 return i;
37
38 return USB_DR_MODE_UNKNOWN;
39}
Mugunthan V N58d8fbe2018-05-18 13:15:05 +020040
41static const char *const speed_names[] = {
42 [USB_SPEED_UNKNOWN] = "UNKNOWN",
43 [USB_SPEED_LOW] = "low-speed",
44 [USB_SPEED_FULL] = "full-speed",
45 [USB_SPEED_HIGH] = "high-speed",
46 [USB_SPEED_WIRELESS] = "wireless",
47 [USB_SPEED_SUPER] = "super-speed",
48};
49
Kever Yang1b807052020-03-04 08:59:50 +080050enum usb_device_speed usb_get_maximum_speed(ofnode node)
Mugunthan V N58d8fbe2018-05-18 13:15:05 +020051{
Mugunthan V N58d8fbe2018-05-18 13:15:05 +020052 const char *max_speed;
53 int i;
54
Kever Yang1b807052020-03-04 08:59:50 +080055 max_speed = ofnode_read_string(node, "maximum-speed");
Mugunthan V N58d8fbe2018-05-18 13:15:05 +020056 if (!max_speed) {
57 pr_err("usb maximum-speed not found\n");
58 return USB_SPEED_UNKNOWN;
59 }
60
61 for (i = 0; i < ARRAY_SIZE(speed_names); i++)
62 if (!strcmp(max_speed, speed_names[i]))
63 return i;
64
65 return USB_SPEED_UNKNOWN;
66}