diff options
| author | Robert Baldyga <r.baldyga@samsung.com> | 2015-09-16 06:10:42 -0400 |
|---|---|---|
| committer | Felipe Balbi <balbi@ti.com> | 2015-09-27 11:54:31 -0400 |
| commit | b0bac2581c1918cc4ab0aca01977ad69f0bc127a (patch) | |
| tree | 924683c079331a43475d1814bebf3f6ade75165c /include/linux/usb | |
| parent | b67f628c84329a9ce82dbff5fde196dc4624e7c2 (diff) | |
usb: gadget: introduce 'enabled' flag in struct usb_ep
This patch introduces 'enabled' flag in struct usb_ep, and modifies
usb_ep_enable() and usb_ep_disable() functions to encapsulate endpoint
enabled/disabled state. It helps to avoid enabling endpoints which are
already enabled, and disabling endpoints which are already disables.
From now USB functions don't have to remember current endpoint
enable/disable state, as this state is now handled automatically which
makes this API less bug-prone.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'include/linux/usb')
| -rw-r--r-- | include/linux/usb/gadget.h | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index 3f299e2b6942..3d583a10b926 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h | |||
| @@ -215,6 +215,7 @@ struct usb_ep { | |||
| 215 | struct list_head ep_list; | 215 | struct list_head ep_list; |
| 216 | struct usb_ep_caps caps; | 216 | struct usb_ep_caps caps; |
| 217 | bool claimed; | 217 | bool claimed; |
| 218 | bool enabled; | ||
| 218 | unsigned maxpacket:16; | 219 | unsigned maxpacket:16; |
| 219 | unsigned maxpacket_limit:16; | 220 | unsigned maxpacket_limit:16; |
| 220 | unsigned max_streams:16; | 221 | unsigned max_streams:16; |
| @@ -264,7 +265,18 @@ static inline void usb_ep_set_maxpacket_limit(struct usb_ep *ep, | |||
| 264 | */ | 265 | */ |
| 265 | static inline int usb_ep_enable(struct usb_ep *ep) | 266 | static inline int usb_ep_enable(struct usb_ep *ep) |
| 266 | { | 267 | { |
| 267 | return ep->ops->enable(ep, ep->desc); | 268 | int ret; |
| 269 | |||
| 270 | if (ep->enabled) | ||
| 271 | return 0; | ||
| 272 | |||
| 273 | ret = ep->ops->enable(ep, ep->desc); | ||
| 274 | if (ret) | ||
| 275 | return ret; | ||
| 276 | |||
| 277 | ep->enabled = true; | ||
| 278 | |||
| 279 | return 0; | ||
| 268 | } | 280 | } |
| 269 | 281 | ||
| 270 | /** | 282 | /** |
| @@ -281,7 +293,18 @@ static inline int usb_ep_enable(struct usb_ep *ep) | |||
| 281 | */ | 293 | */ |
| 282 | static inline int usb_ep_disable(struct usb_ep *ep) | 294 | static inline int usb_ep_disable(struct usb_ep *ep) |
| 283 | { | 295 | { |
| 284 | return ep->ops->disable(ep); | 296 | int ret; |
| 297 | |||
| 298 | if (!ep->enabled) | ||
| 299 | return 0; | ||
| 300 | |||
| 301 | ret = ep->ops->disable(ep); | ||
| 302 | if (ret) | ||
| 303 | return ret; | ||
| 304 | |||
| 305 | ep->enabled = false; | ||
| 306 | |||
| 307 | return 0; | ||
| 285 | } | 308 | } |
| 286 | 309 | ||
| 287 | /** | 310 | /** |
