blob: 17a0ab23ff536c563be2cc414e4ca6ef39ea3a7e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mugunthan V Nc0c62d92016-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 Nc0c62d92016-04-12 16:01:19 +05307 */
8
9#include <common.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090010#include <linux/libfdt.h>
Mugunthan V Nc0c62d92016-04-12 16:01:19 +053011#include <linux/usb/otg.h>
12
13DECLARE_GLOBAL_DATA_PTR;
14
15static const char *const usb_dr_modes[] = {
16 [USB_DR_MODE_UNKNOWN] = "",
17 [USB_DR_MODE_HOST] = "host",
18 [USB_DR_MODE_PERIPHERAL] = "peripheral",
19 [USB_DR_MODE_OTG] = "otg",
20};
21
22enum usb_dr_mode usb_get_dr_mode(int node)
23{
24 const void *fdt = gd->fdt_blob;
25 const char *dr_mode;
26 int i;
27
28 dr_mode = fdt_getprop(fdt, node, "dr_mode", NULL);
29 if (!dr_mode) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090030 pr_err("usb dr_mode not found\n");
Mugunthan V Nc0c62d92016-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}