Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Mugunthan V N | c0c62d9 | 2016-04-12 16:01:19 +0530 | [diff] [blame] | 2 | /* |
| 3 | * Provides code common for host and device side USB. |
| 4 | * |
| 5 | * (C) Copyright 2016 |
| 6 | * Texas Instruments Incorporated, <www.ti.com> |
Mugunthan V N | c0c62d9 | 2016-04-12 16:01:19 +0530 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 10 | #include <linux/libfdt.h> |
Mugunthan V N | c0c62d9 | 2016-04-12 16:01:19 +0530 | [diff] [blame] | 11 | #include <linux/usb/otg.h> |
| 12 | |
| 13 | DECLARE_GLOBAL_DATA_PTR; |
| 14 | |
| 15 | static 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 | |
| 22 | enum 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 Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 30 | pr_err("usb dr_mode not found\n"); |
Mugunthan V N | c0c62d9 | 2016-04-12 16:01:19 +0530 | [diff] [blame] | 31 | 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 | } |