1 /* 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> 11 #include <linux/libfdt.h> 12 #include <linux/usb/otg.h> 13 #include <linux/usb/ch9.h> 14 15 DECLARE_GLOBAL_DATA_PTR; 16 17 static const char *const usb_dr_modes[] = { 18 [USB_DR_MODE_UNKNOWN] = "", 19 [USB_DR_MODE_HOST] = "host", 20 [USB_DR_MODE_PERIPHERAL] = "peripheral", 21 [USB_DR_MODE_OTG] = "otg", 22 }; 23 24 enum usb_dr_mode usb_get_dr_mode(int node) 25 { 26 const void *fdt = gd->fdt_blob; 27 const char *dr_mode; 28 int i; 29 30 dr_mode = fdt_getprop(fdt, node, "dr_mode", NULL); 31 if (!dr_mode) { 32 pr_err("usb dr_mode not found\n"); 33 return USB_DR_MODE_UNKNOWN; 34 } 35 36 for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++) 37 if (!strcmp(dr_mode, usb_dr_modes[i])) 38 return i; 39 40 return USB_DR_MODE_UNKNOWN; 41 } 42 43 static const char *const speed_names[] = { 44 [USB_SPEED_UNKNOWN] = "UNKNOWN", 45 [USB_SPEED_LOW] = "low-speed", 46 [USB_SPEED_FULL] = "full-speed", 47 [USB_SPEED_HIGH] = "high-speed", 48 [USB_SPEED_WIRELESS] = "wireless", 49 [USB_SPEED_SUPER] = "super-speed", 50 }; 51 52 enum usb_device_speed usb_get_maximum_speed(int node) 53 { 54 const void *fdt = gd->fdt_blob; 55 const char *max_speed; 56 int i; 57 58 max_speed = fdt_getprop(fdt, node, "maximum-speed", NULL); 59 if (!max_speed) { 60 pr_err("usb maximum-speed not found\n"); 61 return USB_SPEED_UNKNOWN; 62 } 63 64 for (i = 0; i < ARRAY_SIZE(speed_names); i++) 65 if (!strcmp(max_speed, speed_names[i])) 66 return i; 67 68 return USB_SPEED_UNKNOWN; 69 } 70