Skip to content

Commit b7b741e

Browse files
zonqueFelipe Balbi
authored andcommitted
usb: musb: add Kconfig options for HOST, GAGDET or DUAL_ROLE modes
This makes building the actual object files optional to the selected mode, which saves users who know which kind of USB mode support they need some binary size. Unimplemented functions are stubbed out with static inline functions. Signed-off-by: Daniel Mack <zonque@gmail.com> Acked-by: Peter Korsgaard <jacmet@sunsite.dk> Signed-off-by: Felipe Balbi <balbi@ti.com>
1 parent 74c2e93 commit b7b741e

4 files changed

Lines changed: 79 additions & 4 deletions

File tree

‎drivers/usb/musb/Kconfig‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,35 @@ config USB_MUSB_HDRC
2727

2828
if USB_MUSB_HDRC
2929

30+
choice
31+
bool "MUSB Mode Selection"
32+
default USB_MUSB_DUAL_ROLE if (USB && USB_GADGET)
33+
default USB_MUSB_HOST if (USB && !USB_GADGET)
34+
default USB_MUSB_GADGET if (!USB && USB_GADGET)
35+
36+
config USB_MUSB_HOST
37+
bool "Host only mode"
38+
depends on USB
39+
help
40+
Select this when you want to use MUSB in host mode only,
41+
thereby the gadget feature will be regressed.
42+
43+
config USB_MUSB_GADGET
44+
bool "Gadget only mode"
45+
depends on USB_GADGET
46+
help
47+
Select this when you want to use MUSB in gadget mode only,
48+
thereby the host feature will be regressed.
49+
50+
config USB_MUSB_DUAL_ROLE
51+
bool "Dual Role mode"
52+
depends on (USB && USB_GADGET)
53+
help
54+
This is the default mode of working of MUSB controller where
55+
both host and gadget features are enabled.
56+
57+
endchoice
58+
3059
choice
3160
prompt "Platform Glue Layer"
3261

‎drivers/usb/musb/Makefile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ obj-$(CONFIG_USB_MUSB_HDRC) += musb_hdrc.o
66

77
musb_hdrc-y := musb_core.o
88

9-
musb_hdrc-y += musb_gadget_ep0.o musb_gadget.o
10-
musb_hdrc-y += musb_virthub.o musb_host.o
9+
musb_hdrc-$(CONFIG_USB_MUSB_HOST)$(CONFIG_USB_MUSB_DUAL_ROLE) += musb_virthub.o musb_host.o
10+
musb_hdrc-$(CONFIG_USB_MUSB_GADGET)$(CONFIG_USB_MUSB_DUAL_ROLE) += musb_gadget_ep0.o musb_gadget.o
1111
musb_hdrc-$(CONFIG_DEBUG_FS) += musb_debugfs.o
1212

1313
# Hardware Glue Layer

‎drivers/usb/musb/musb_gadget.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
#include <linux/list.h>
3939

40+
#if IS_ENABLED(CONFIG_USB_MUSB_GADGET) || IS_ENABLED(CONFIG_USB_MUSB_DUAL_ROLE)
4041
extern irqreturn_t musb_g_ep0_irq(struct musb *);
4142
extern void musb_g_tx(struct musb *, u8);
4243
extern void musb_g_rx(struct musb *, u8);
@@ -48,6 +49,26 @@ extern void musb_g_disconnect(struct musb *);
4849
extern void musb_gadget_cleanup(struct musb *);
4950
extern int musb_gadget_setup(struct musb *);
5051

52+
#else
53+
static inline irqreturn_t musb_g_ep0_irq(struct musb *musb)
54+
{
55+
return 0;
56+
}
57+
58+
static inline void musb_g_tx(struct musb *musb, u8 epnum) {}
59+
static inline void musb_g_rx(struct musb *musb, u8 epnum) {}
60+
static inline void musb_g_reset(struct musb *musb) {}
61+
static inline void musb_g_suspend(struct musb *musb) {}
62+
static inline void musb_g_resume(struct musb *musb) {}
63+
static inline void musb_g_wakeup(struct musb *musb) {}
64+
static inline void musb_g_disconnect(struct musb *musb) {}
65+
static inline void musb_gadget_cleanup(struct musb *musb) {}
66+
static inline int musb_gadget_setup(struct musb *musb)
67+
{
68+
return 0;
69+
}
70+
#endif
71+
5172
enum buffer_map_state {
5273
UN_MAPPED = 0,
5374
PRE_MAPPED,

‎drivers/usb/musb/musb_host.h‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939

4040
#define musb_to_hcd(MUSB) ((MUSB)->hcd)
4141

42-
extern struct musb *hcd_to_musb(struct usb_hcd *);
43-
4442
/* stored in "usb_host_endpoint.hcpriv" for scheduled endpoints */
4543
struct musb_qh {
4644
struct usb_host_endpoint *hep; /* usbcore info */
@@ -78,6 +76,9 @@ static inline struct musb_qh *first_qh(struct list_head *q)
7876
return list_entry(q->next, struct musb_qh, ring);
7977
}
8078

79+
80+
#if IS_ENABLED(CONFIG_USB_MUSB_HOST) || IS_ENABLED(CONFIG_USB_MUSB_DUAL_ROLE)
81+
extern struct musb *hcd_to_musb(struct usb_hcd *);
8182
extern irqreturn_t musb_h_ep0_irq(struct musb *);
8283
extern int musb_host_alloc(struct musb *);
8384
extern void musb_host_tx(struct musb *, u8);
@@ -90,6 +91,30 @@ extern void musb_host_rx(struct musb *, u8);
9091
extern void musb_root_disconnect(struct musb *musb);
9192
extern void musb_host_resume_root_hub(struct musb *musb);
9293
extern void musb_host_poke_root_hub(struct musb *musb);
94+
#else
95+
static inline struct musb *hcd_to_musb(struct usb_hcd *hcd)
96+
{
97+
return NULL;
98+
}
99+
100+
static inline irqreturn_t musb_h_ep0_irq(struct musb *musb)
101+
{
102+
return 0;
103+
}
104+
105+
static inline int musb_host_alloc(struct musb *musb)
106+
{
107+
return 0;
108+
}
109+
110+
static inline void musb_host_free(struct musb *musb) {}
111+
static inline void musb_host_tx(struct musb *musb, u8 epnum) {}
112+
static inline void musb_host_rx(struct musb *musb, u8 epnum) {}
113+
static inline void musb_root_disconnect(struct musb *musb) {}
114+
static inline void musb_host_resume_root_hub(struct musb *musb) {}
115+
static inline void musb_host_poll_rh_status(struct musb *musb) {}
116+
static inline void musb_host_poke_root_hub(struct musb *musb) {}
117+
#endif
93118

94119
struct usb_hcd;
95120

0 commit comments

Comments
 (0)