blob: 69cf11cbf5cb1aecfba0d665514d6154425cd083 [file] [log] [blame]
Mugunthan V N1a547132016-04-12 16:01:19 +05301/*
2 * Provides code common for host and device side USB.
3 *
4 * (C) Copyright 2016
5 * Texas Instruments Incorporated, <www.ti.com>
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10#include <common.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090011#include <linux/libfdt.h>
Mugunthan V N1a547132016-04-12 16:01:19 +053012#include <linux/usb/otg.h>
13
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
23enum usb_dr_mode usb_get_dr_mode(int node)
24{
25 const void *fdt = gd->fdt_blob;
26 const char *dr_mode;
27 int i;
28
29 dr_mode = fdt_getprop(fdt, node, "dr_mode", NULL);
30 if (!dr_mode) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090031 pr_err("usb dr_mode not found\n");
Mugunthan V N1a547132016-04-12 16:01:19 +053032 return USB_DR_MODE_UNKNOWN;
33 }
34
35 for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
36 if (!strcmp(dr_mode, usb_dr_modes[i]))
37 return i;
38
39 return USB_DR_MODE_UNKNOWN;
40}