aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLi Jun <jun.li@freescale.com>2015-07-09 03:18:44 -0400
committerFelipe Balbi <balbi@ti.com>2015-07-29 10:59:21 -0400
commit929412d94f2b75fe2a662afa2977bfb6a233c1c3 (patch)
tree308458c63b28530f698017ef2c13159a6fda1cd9
parentb5513dede7c90ba2370ab5eb547568a22991907b (diff)
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>
-rw-r--r--drivers/usb/common/common.c56
-rw-r--r--include/linux/usb/of.h7
2 files changed, 63 insertions, 0 deletions
diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index b530fd403ffb..9e39286a4e5a 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -154,6 +154,62 @@ bool of_usb_host_tpl_support(struct device_node *np)
154 return false; 154 return false;
155} 155}
156EXPORT_SYMBOL_GPL(of_usb_host_tpl_support); 156EXPORT_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 */
166int 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}
211EXPORT_SYMBOL_GPL(of_usb_update_otg_caps);
212
157#endif 213#endif
158 214
159MODULE_LICENSE("GPL"); 215MODULE_LICENSE("GPL");
diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h
index cfe0528cdbb1..8c5a818ec244 100644
--- a/include/linux/usb/of.h
+++ b/include/linux/usb/of.h
@@ -15,6 +15,8 @@
15enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np); 15enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np);
16enum usb_device_speed of_usb_get_maximum_speed(struct device_node *np); 16enum usb_device_speed of_usb_get_maximum_speed(struct device_node *np);
17bool of_usb_host_tpl_support(struct device_node *np); 17bool of_usb_host_tpl_support(struct device_node *np);
18int of_usb_update_otg_caps(struct device_node *np,
19 struct usb_otg_caps *otg_caps);
18#else 20#else
19static inline enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np) 21static inline enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
20{ 22{
@@ -30,6 +32,11 @@ static inline bool of_usb_host_tpl_support(struct device_node *np)
30{ 32{
31 return false; 33 return false;
32} 34}
35static inline int of_usb_update_otg_caps(struct device_node *np,
36 struct usb_otg_caps *otg_caps)
37{
38 return 0;
39}
33#endif 40#endif
34 41
35#if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_USB_SUPPORT) 42#if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_USB_SUPPORT)