Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: common: add API to update usb otg capabilities by device tree

Check property of usb hardware to update otg version and disable SRP, HNP
and ADP if its disable flag is present.

Reviewed-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Li Jun <jun.li@freescale.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>

authored by

Li Jun and committed by
Felipe Balbi
929412d9 b5513ded

+63
+56
drivers/usb/common/common.c
··· 154 154 return false; 155 155 } 156 156 EXPORT_SYMBOL_GPL(of_usb_host_tpl_support); 157 + 158 + /** 159 + * of_usb_update_otg_caps - to update usb otg capabilities according to 160 + * the passed properties in DT. 161 + * @np: Pointer to the given device_node 162 + * @otg_caps: Pointer to the target usb_otg_caps to be set 163 + * 164 + * The function updates the otg capabilities 165 + */ 166 + int of_usb_update_otg_caps(struct device_node *np, 167 + struct usb_otg_caps *otg_caps) 168 + { 169 + u32 otg_rev; 170 + 171 + if (!otg_caps) 172 + return -EINVAL; 173 + 174 + if (!of_property_read_u32(np, "otg-rev", &otg_rev)) { 175 + switch (otg_rev) { 176 + case 0x0100: 177 + case 0x0120: 178 + case 0x0130: 179 + case 0x0200: 180 + /* Choose the lesser one if it's already been set */ 181 + if (otg_caps->otg_rev) 182 + otg_caps->otg_rev = min_t(u16, otg_rev, 183 + otg_caps->otg_rev); 184 + else 185 + otg_caps->otg_rev = otg_rev; 186 + break; 187 + default: 188 + pr_err("%s: unsupported otg-rev: 0x%x\n", 189 + np->full_name, otg_rev); 190 + return -EINVAL; 191 + } 192 + } else { 193 + /* 194 + * otg-rev is mandatory for otg properties, if not passed 195 + * we set it to be 0 and assume it's a legacy otg device. 196 + * Non-dt platform can set it afterwards. 197 + */ 198 + otg_caps->otg_rev = 0; 199 + } 200 + 201 + if (of_find_property(np, "hnp-disable", NULL)) 202 + otg_caps->hnp_support = false; 203 + if (of_find_property(np, "srp-disable", NULL)) 204 + otg_caps->srp_support = false; 205 + if (of_find_property(np, "adp-disable", NULL) || 206 + (otg_caps->otg_rev < 0x0200)) 207 + otg_caps->adp_support = false; 208 + 209 + return 0; 210 + } 211 + EXPORT_SYMBOL_GPL(of_usb_update_otg_caps); 212 + 157 213 #endif 158 214 159 215 MODULE_LICENSE("GPL");
+7
include/linux/usb/of.h
··· 15 15 enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np); 16 16 enum usb_device_speed of_usb_get_maximum_speed(struct device_node *np); 17 17 bool of_usb_host_tpl_support(struct device_node *np); 18 + int of_usb_update_otg_caps(struct device_node *np, 19 + struct usb_otg_caps *otg_caps); 18 20 #else 19 21 static inline enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np) 20 22 { ··· 31 29 static inline bool of_usb_host_tpl_support(struct device_node *np) 32 30 { 33 31 return false; 32 + } 33 + static inline int of_usb_update_otg_caps(struct device_node *np, 34 + struct usb_otg_caps *otg_caps) 35 + { 36 + return 0; 34 37 } 35 38 #endif 36 39