1c0c62d92SMugunthan V N /* 2c0c62d92SMugunthan V N * Provides code common for host and device side USB. 3c0c62d92SMugunthan V N * 4c0c62d92SMugunthan V N * (C) Copyright 2016 5c0c62d92SMugunthan V N * Texas Instruments Incorporated, <www.ti.com> 6c0c62d92SMugunthan V N * 7c0c62d92SMugunthan V N * SPDX-License-Identifier: GPL-2.0+ 8c0c62d92SMugunthan V N */ 9c0c62d92SMugunthan V N 10c0c62d92SMugunthan V N #include <common.h> 110e00a84cSMasahiro Yamada #include <linux/libfdt.h> 12c0c62d92SMugunthan V N #include <linux/usb/otg.h> 13*81cd8855SMugunthan V N #include <linux/usb/ch9.h> 14c0c62d92SMugunthan V N 15c0c62d92SMugunthan V N DECLARE_GLOBAL_DATA_PTR; 16c0c62d92SMugunthan V N 17c0c62d92SMugunthan V N static const char *const usb_dr_modes[] = { 18c0c62d92SMugunthan V N [USB_DR_MODE_UNKNOWN] = "", 19c0c62d92SMugunthan V N [USB_DR_MODE_HOST] = "host", 20c0c62d92SMugunthan V N [USB_DR_MODE_PERIPHERAL] = "peripheral", 21c0c62d92SMugunthan V N [USB_DR_MODE_OTG] = "otg", 22c0c62d92SMugunthan V N }; 23c0c62d92SMugunthan V N 24c0c62d92SMugunthan V N enum usb_dr_mode usb_get_dr_mode(int node) 25c0c62d92SMugunthan V N { 26c0c62d92SMugunthan V N const void *fdt = gd->fdt_blob; 27c0c62d92SMugunthan V N const char *dr_mode; 28c0c62d92SMugunthan V N int i; 29c0c62d92SMugunthan V N 30c0c62d92SMugunthan V N dr_mode = fdt_getprop(fdt, node, "dr_mode", NULL); 31c0c62d92SMugunthan V N if (!dr_mode) { 3290aa625cSMasahiro Yamada pr_err("usb dr_mode not found\n"); 33c0c62d92SMugunthan V N return USB_DR_MODE_UNKNOWN; 34c0c62d92SMugunthan V N } 35c0c62d92SMugunthan V N 36c0c62d92SMugunthan V N for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++) 37c0c62d92SMugunthan V N if (!strcmp(dr_mode, usb_dr_modes[i])) 38c0c62d92SMugunthan V N return i; 39c0c62d92SMugunthan V N 40c0c62d92SMugunthan V N return USB_DR_MODE_UNKNOWN; 41c0c62d92SMugunthan V N } 42*81cd8855SMugunthan V N 43*81cd8855SMugunthan V N static const char *const speed_names[] = { 44*81cd8855SMugunthan V N [USB_SPEED_UNKNOWN] = "UNKNOWN", 45*81cd8855SMugunthan V N [USB_SPEED_LOW] = "low-speed", 46*81cd8855SMugunthan V N [USB_SPEED_FULL] = "full-speed", 47*81cd8855SMugunthan V N [USB_SPEED_HIGH] = "high-speed", 48*81cd8855SMugunthan V N [USB_SPEED_WIRELESS] = "wireless", 49*81cd8855SMugunthan V N [USB_SPEED_SUPER] = "super-speed", 50*81cd8855SMugunthan V N }; 51*81cd8855SMugunthan V N 52*81cd8855SMugunthan V N enum usb_device_speed usb_get_maximum_speed(int node) 53*81cd8855SMugunthan V N { 54*81cd8855SMugunthan V N const void *fdt = gd->fdt_blob; 55*81cd8855SMugunthan V N const char *max_speed; 56*81cd8855SMugunthan V N int i; 57*81cd8855SMugunthan V N 58*81cd8855SMugunthan V N max_speed = fdt_getprop(fdt, node, "maximum-speed", NULL); 59*81cd8855SMugunthan V N if (!max_speed) { 60*81cd8855SMugunthan V N pr_err("usb maximum-speed not found\n"); 61*81cd8855SMugunthan V N return USB_SPEED_UNKNOWN; 62*81cd8855SMugunthan V N } 63*81cd8855SMugunthan V N 64*81cd8855SMugunthan V N for (i = 0; i < ARRAY_SIZE(speed_names); i++) 65*81cd8855SMugunthan V N if (!strcmp(max_speed, speed_names[i])) 66*81cd8855SMugunthan V N return i; 67*81cd8855SMugunthan V N 68*81cd8855SMugunthan V N return USB_SPEED_UNKNOWN; 69*81cd8855SMugunthan V N } 70