1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Provides code common for host and device side USB. 4 * 5 * (C) Copyright 2016 6 * Texas Instruments Incorporated, <www.ti.com> 7 */ 8 9 #include <common.h> 10 #include <linux/libfdt.h> 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) { 30 pr_err("usb dr_mode not found\n"); 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 } 40