usb: dwc2: Add support for dual-role
Subsystems (2)
v7 cover usb: dwc2: Add support for dual-role
From: Dinh Nguyen <[email protected]>
Hello,
This is version 7 of the patch series that combines the dwc2 gadget and host driver into a single dual role driver. Here are the main differences from V6:
- patch 1/8: Addressed Felipe's comment on which variables should not be just limited to gadget(phy, uphy, regulator_bulk_data_supplies, irq, clk, debug_root, debug_file, and debug_fifo).
- patch 2/8: Move conversion to use dev_pm_ops API to separate patch.
- patch 3/8: Convert to use dev_pm_ops API
- patch 4/8: Rebased to s3c_hsotg_core_init is now s3c_hsotg_core_init_disconnected(), followed by s3c_hsotg_core_connect().
- patch 5/8: Use IRQF_SHARED to have s3c_hsotg_irq handle gadget interrupts. Had to remove paulz's Acked-by for this patch, as it is not quite the same patch when his ack was given.
- patch 6/8: Assign clk=NULL if a clock is not provided.
- patch 7/8: Moved ahead of Kconfig/Makefile patch to avoid a build error when patch 8 is applied to dual-role.
- patch 8/8: none
For v7, the series is rebased on top of Felipe Balbi's tree on -next branch. I thought this might be appropriate as there are dwc2 patches already on this branch.
As usual, tested on SOCFPGA(host, gadget, and dual-role) and on Rpi-B (host mode only).
I have pushed this series to a git repo to make it more convenient for people to test/review.
git://git.rocketboards.org/linux-socfpga-next.git dwc2_dual_role_v7
Thanks,
Dinh Nguyen (8):
usb: dwc2: Update the gadget driver to use common dwc2_hsotg structure
usb: dwc2: Move gadget probe function into platform code
usb: dwc2: convert to use dev_pm_ops API
usb: dwc2: Initialize the USB core for peripheral mode
usb: dwc2: Update common interrupt handler to call gadget interrupt
handler
usb: dwc2: gadget: Do not fail probe if there isn't a clock node
usb: dwc2: move usb_disabled() call to host driver only
usb: dwc2: Update Kconfig to support dual-role
drivers/usb/dwc2/Kconfig | 66 ++++++----- drivers/usb/dwc2/Makefile | 32 ++--- drivers/usb/dwc2/core.c | 10 -- drivers/usb/dwc2/core.h | 192 ++++++++++++++++++------------ drivers/usb/dwc2/core_intr.c | 8 +- drivers/usb/dwc2/gadget.c | 274 ++++++++++++++----------------------------- drivers/usb/dwc2/hcd.c | 6 +- drivers/usb/dwc2/hcd.h | 10 -- drivers/usb/dwc2/pci.c | 7 ++ drivers/usb/dwc2/platform.c | 42 ++++++- 10 files changed, 317 insertions(+), 330 deletions(-)
Signature · 1 line
2.0.3
PATCH v7 1/8 usb: dwc2: Update the gadget driver to use common dwc2_hsotg structure
From: Dinh Nguyen <[email protected]>
Adds the gadget data structure and appropriate data structure pointers to the common dwc2_hsotg data structure. To keep the driver data dereference code looking clean, the gadget variable declares are only available for peripheral and dual-role mode. This is needed so that the dwc2_hsotg data structure can be used by the hcd and gadget drivers.
Updates gadget.c to use the dwc2_hsotg data structure and gadget pointers that have been moved into the common dwc2_hsotg structure.
---
v7: Addressed comments from Felipe Balbi on which variables should not be just
limited to gadget(phy, uphy, regulator_bulk_data_supplies, irq, clk, debug_root, debug_file, and debug_fifo).
v6: None
v5: Keep the changes to mininum and maintain hcd and gadget driver to build
and work separately. Use IS_ENABLED() instead of #if defined
v3: Updated with paulz's suggestion to avoid double pointers.
v2: Left the function parameter name as 'hsotg' and just changed its type.
--- drivers/usb/dwc2/core.h | 155 ++++++++++++++++++++++++---------------------- drivers/usb/dwc2/gadget.c | 146 +++++++++++++++++++++---------------------- 2 files changed, 153 insertions(+), 148 deletions(-)
drivers/usb/dwc2/core.h +80 -75
@@ -84,7 +84,7 @@ static const char * const s3c_hsotg_supply_names[] = {*/ #define EP0_MPS_LIMIT 64 -struct s3c_hsotg ; +struct dwc2_hsotg ;struct s3c_hsotg_req ;/**
@@ -130,7 +130,7 @@ struct s3c_hsotg_req;struct s3c_hsotg_ep {struct usb_ep ep;struct list_head queue; -struct s3c_hsotg *parent; +struct dwc2_hsotg *parent;struct s3c_hsotg_req *req;struct dentry *debugfs;
@@ -155,67 +155,6 @@ struct s3c_hsotg_ep { };/** -* struct s3c_hsotg - driver state. -* @dev: The parent device supplied to the probe function -* @driver: USB gadget driver -* @phy: The otg phy transceiver structure for phy control. -* @uphy: The otg phy transceiver structure for old USB phy control. -* @plat: The platform specific configuration data. This can be removed once -* all SoCs support usb transceiver. -* @regs: The memory area mapped for accessing registers. -* @irq: The IRQ number we are using -* @supplies: Definition of USB power supplies -* @phyif: PHY interface width -* @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos. -* @num_of_eps: Number of available EPs (excluding EP0) -* @debug_root: root directrory for debugfs. -* @debug_file: main status file for debugfs. -* @debug_fifo: FIFO status file for debugfs. -* @ep0_reply: Request used for ep0 reply. -* @ep0_buff: Buffer for EP0 reply data, if needed. -* @ctrl_buff: Buffer for EP0 control requests. -* @ctrl_req: Request for EP0 control packets. -* @setup: NAK management for EP0 SETUP -* @last_rst: Time of last reset -* @eps: The endpoints being supplied to the gadget framework -*/ -struct s3c_hsotg { -struct device *dev; -struct usb_gadget_driver *driver; -struct phy *phy; -struct usb_phy *uphy; -struct s3c_hsotg_plat *plat; - -spinlock_t lock; - -void __iomem *regs; -int irq; -struct clk *clk; - -struct regulator_bulk_data supplies[ARRAY_SIZE (s3c_hsotg_supply_names)]; - -u32 phyif; -int fifo_mem; -unsigned int dedicated_fifos:1 ; -unsigned char num_of_eps; -u32 fifo_map; - -struct dentry *debug_root; -struct dentry *debug_file; -struct dentry *debug_fifo; - -struct usb_request *ep0_reply; -struct usb_request *ctrl_req; -u8 ep0_buff[8 ]; -u8 ctrl_buff[8 ]; - -struct usb_gadget gadget; -unsigned int setup; -unsigned long last_rst; -struct s3c_hsotg_ep *eps; -}; - -/** * struct s3c_hsotg_req - data transfer request * @req: The USB gadget request * @queue: The list of requests for the endpoint this is queued for.
@@ -229,6 +168,7 @@ struct s3c_hsotg_req {unsigned char mapped; }; +#if IS_ENABLED (CONFIG_USB_DWC2_PERIPHERAL ) ||IS_ENABLED (CONFIG_USB_DWC2_DUAL_ROLE )#define call_gadget (_hs, _entry) \ do { \ if ((_hs)->gadget.speed != USB_SPEED_UNKNOWN && \
@@ -238,6 +178,9 @@ do { \ spin_lock(&_hs->lock); \ } \ } while (0) +#else +#define call_gadget (_hs, _entry) do {} while (0) +#endif struct dwc2_hsotg ;struct dwc2_host_chan ;
@@ -495,11 +438,13 @@ struct dwc2_hw_params {* struct dwc2_hsotg - Holds the state of the driver, including the non-periodic * and periodic schedules * +* These are common for both host and peripheral modes: +* * @dev: The struct device pointer * @regs: Pointer to controller regs -* @core_params: Parameters that define how the core should be configured * @hw_params: Parameters that were autodetected from the * hardware registers +* @core_params: Parameters that define how the core should be configured * @op_state: The operational State, during transitions (a_host=> * a_peripheral and b_device=>b_host) this may not match * the core, but allows the software to determine
@@ -508,6 +453,8 @@ struct dwc2_hw_params {* - USB_DR_MODE_PERIPHERAL * - USB_DR_MODE_HOST * - USB_DR_MODE_OTG +* @lock: Spinlock that protects all the driver data structures +* @priv: Stores a pointer to the struct usb_hcd * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth * transfer are in process of being queued * @srp_success: Stores status of SRP request in the case of a FS PHY
@@ -517,6 +464,9 @@ struct dwc2_hw_params {* interrupt * @wkp_timer: Timer object for handling Wakeup Detected interrupt * @lx_state: Lx state of connected device +* +* These are for host mode: +* * @flags: Flags for handling root port state changes * @non_periodic_sched_inactive: Inactive QHs in the non-periodic schedule. * Transfers associated with these QHs are not currently
@@ -585,11 +535,31 @@ struct dwc2_hw_params {* @status_buf_dma: DMA address for status_buf * @start_work: Delayed work for handling host A-cable connection * @reset_work: Delayed work for handling a port reset -* @lock: Spinlock that protects all the driver data structures -* @priv: Stores a pointer to the struct usb_hcd * @otg_port: OTG port number * @frame_list: Frame list * @frame_list_dma: Frame list DMA address +* +* These are for peripheral mode: +* +* @driver: USB gadget driver +* @phy: The otg phy transceiver structure for phy control. +* @uphy: The otg phy transceiver structure for old USB phy control. +* @plat: The platform specific configuration data. This can be removed once +* all SoCs support usb transceiver. +* @supplies: Definition of USB power supplies +* @phyif: PHY interface width +* @dedicated_fifos: Set if the hardware has dedicated IN-EP fifos. +* @num_of_eps: Number of available EPs (excluding EP0) +* @debug_root: Root directrory for debugfs. +* @debug_file: Main status file for debugfs. +* @debug_fifo: FIFO status file for debugfs. +* @ep0_reply: Request used for ep0 reply. +* @ep0_buff: Buffer for EP0 reply data, if needed. +* @ctrl_buff: Buffer for EP0 control requests. +* @ctrl_req: Request for EP0 control packets. +* @setup: NAK management for EP0 SETUP +* @last_rst: Time of last reset +* @eps: The endpoints being supplied to the gadget framework */ struct dwc2_hsotg {struct device *dev;
@@ -601,6 +571,15 @@ struct dwc2_hsotg {enum usb_otg_state op_state;enum usb_dr_mode dr_mode; +struct phy *phy; +struct usb_phy *uphy; +struct regulator_bulk_data supplies[ARRAY_SIZE (s3c_hsotg_supply_names)]; + +spinlock_t lock; +void *priv; +int irq; +struct clk *clk; + unsigned int queuing_high_bandwidth:1; unsigned int srp_success:1;
@@ -609,6 +588,18 @@ struct dwc2_hsotg {struct timer_list wkp_timer;enum dwc2_lx_state lx_state; +struct dentry *debug_root; +struct dentry *debug_file; +struct dentry *debug_fifo; + +/* DWC OTG HW Release versions */ +#define DWC2_CORE_REV_2_71a 0x4f54271a +#define DWC2_CORE_REV_2_90a 0x4f54290a +#define DWC2_CORE_REV_2_92a 0x4f54292a +#define DWC2_CORE_REV_2_94a 0x4f54294a +#define DWC2_CORE_REV_3_00a 0x4f54300a + +#if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) union dwc2_hcd_internal_flags { u32 d32; struct {
@@ -655,19 +646,10 @@ struct dwc2_hsotg {struct delayed_work start_work;struct delayed_work reset_work; -spinlock_t lock; -void *priv;u8 otg_port;u32 *frame_list;dma_addr_t frame_list_dma; -/* DWC OTG HW Release versions */ -#define DWC2_CORE_REV_2_71a 0x4f54271a -#define DWC2_CORE_REV_2_90a 0x4f54290a -#define DWC2_CORE_REV_2_92a 0x4f54292a -#define DWC2_CORE_REV_2_94a 0x4f54294a -#define DWC2_CORE_REV_3_00a 0x4f54300a -#ifdef DEBUG u32 frrem_samples;u64 frrem_accum;
@@ -686,6 +668,29 @@ struct dwc2_hsotg {u32 hfnum_other_samples_b;u64 hfnum_other_frrem_accum_b;#endif +#endif /* CONFIG_USB_DWC2_HOST || CONFIG_USB_DWC2_DUAL_ROLE */ + +#if IS_ENABLED (CONFIG_USB_DWC2_PERIPHERAL ) ||IS_ENABLED (CONFIG_USB_DWC2_DUAL_ROLE ) +/* Gadget structures */ +struct usb_gadget_driver *driver; +struct s3c_hsotg_plat *plat; + +u32 phyif; +int fifo_mem; + unsigned int dedicated_fifos:1; +unsigned char num_of_eps; +u32 fifo_map; + +struct usb_request *ep0_reply; +struct usb_request *ctrl_req; +u8 ep0_buff[8 ]; +u8 ctrl_buff[8 ]; + +struct usb_gadget gadget; +unsigned int setup; +unsigned long last_rst; +struct s3c_hsotg_ep *eps; +#endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */ };/* Reasons for halting a host channel */
drivers/usb/dwc2/gadget.c +73 -73
577 lines not on this page · raw message
Signature · 1 line
2.0.3
Re: [PATCHv7 1/8] usb: dwc2: Update the gadget driver to use common dwc2_hsotg structure
Hi Dinh:
Quoted 11 lines · On 2014/11/12 1:13, [email protected] wrote:
From: Dinh Nguyen <[email protected]>
Adds the gadget data structure and appropriate data structure pointers to the common
dwc2_hsotgdata structure. To keep the driver data dereference code looking clean, the gadget variable declares are only available for peripheral and dual-role mode. This is needed so that thedwc2_hsotgdata structure can be used by the hcd and gadget drivers.Updates
gadget.cto use thedwc2_hsotgdata structure and gadget pointers that have been moved into the commondwc2_hsotgstructure.
Quoted 6 lines
Signed-off-by Dinh Nguyen <[email protected]>Signed-off-by Paul Zimmerman <[email protected]>---
v7: Addressed comments from Felipe Balbi on which variables should not be just
limited togadget(phy, uphy, regulator_bulk_data_supplies, irq, clk, debug_root, debug_file, and debug_fifo).
I hope your dual-roal patches could bring the intializtion code of hsotg->clk and hsotg->phy out from dwc2_gadget_init() into dwc2_driver_probe() like intializtion of irq and regs base address. Because the host-only platforms may also need clk gating when enter suspend for power saving.
Quoted 6 lines
v6: None
v5: Keep the changes to mininum and maintain hcd and gadget driver to build
and work separately. UseIS_ENABLED()instead of #if defined
v3: Updated with paulz's suggestion to avoid double pointers.
v2: Left the function parameter name as 'hsotg' and just changed its type.
Signature · 2 lines
-------- Roy Li @ Rockchip
PATCH v7 2/8 usb: dwc2: Move gadget probe function into platform code
In reply to [email protected]From: Dinh Nguyen <[email protected]>
This patch will aggregate the probing of gadget/hcd driver into platform.c. The gadget probe funtion is converted into gadget_init that is now only responsible for gadget only initialization. All the gadget resources are now handled by platform.c
Since the host workqueue will not get initialized if the driver is configured for peripheral mode only. Thus we need to check for wq_otg before calling queue_work().
Also, we move spin_lock_init to common location for both host and gadget that is either in platform.c or pci.c.
We also move suspend/resume code to common platform code.
Lastly, move the "samsung,s3c6400-hsotg" binding into dwc2_of_match_table.
---
v7: Move the conversion to use pm_ops to a separate patch
v6: None
v5: Reworked by squashing the following commits into this one:
* [PATCHv4 02/12] usb: dwc2: move "samsung,s3c6400-hsotg" into common platform
* [PATCHv4 03/12] usb: dwc2: Update the gadget driver to use common dwc2_hsotg structure
* [PATCHv4 09/12] usb: dwc2: initialize the spin_lock for both host and gadget
* [PATCHv4 10/12] usb: dwc2: Add suspend/resume for gadget
* [PATCHv4 11/12] usb: dwc2: check that the host work queue is valid Also use IS_ENABLED instead of #if defined
--- drivers/usb/dwc2/core.h | 33 +++++++++++++++ drivers/usb/dwc2/core_intr.c | 8 ++-- drivers/usb/dwc2/gadget.c | 99 ++++++++++---------------------------------- drivers/usb/dwc2/hcd.c | 1 - drivers/usb/dwc2/hcd.h | 10 ----- drivers/usb/dwc2/pci.c | 1 + drivers/usb/dwc2/platform.c | 28 +++++++++++++ 7 files changed, 88 insertions(+), 92 deletions(-)
drivers/usb/dwc2/core.h +33 -0
@@ -960,4 +960,37 @@ extern void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg);*/ extern u16 dwc2_get_otg_version (struct dwc2_hsotg *hsotg); +/* Gadget defines */ +#if IS_ENABLED (CONFIG_USB_DWC2_PERIPHERAL ) ||IS_ENABLED (CONFIG_USB_DWC2_DUAL_ROLE ) +extern int s3c_hsotg_remove (struct dwc2_hsotg *hsotg); +extern int s3c_hsotg_suspend (struct dwc2_hsotg *dwc2); +extern int s3c_hsotg_resume (struct dwc2_hsotg *dwc2); +extern int dwc2_gadget_init (struct dwc2_hsotg *hsotg,int irq); +#else +static inline int s3c_hsotg_remove (struct dwc2_hsotg *dwc2) +{return 0 ; } +static inline int s3c_hsotg_suspend (struct dwc2_hsotg *dwc2) +{return 0 ; } +static inline int s3c_hsotg_resume (struct dwc2_hsotg *dwc2) +{return 0 ; } +static inline int dwc2_gadget_init (struct dwc2_hsotg *hsotg,int irq) +{return 0 ; } +#endif + +#if IS_ENABLED (CONFIG_USB_DWC2_HOST ) ||IS_ENABLED (CONFIG_USB_DWC2_DUAL_ROLE ) +extern int dwc2_hcd_get_frame_number (struct dwc2_hsotg *hsotg); +extern void dwc2_hcd_disconnect (struct dwc2_hsotg *hsotg); +extern void dwc2_hcd_start (struct dwc2_hsotg *hsotg); +#else +static inline void dwc2_set_all_params (struct dwc2_core_params *params,int value) {} +static inline int dwc2_hcd_get_frame_number (struct dwc2_hsotg *hsotg) +{return 0 ; } +static inline void dwc2_hcd_disconnect (struct dwc2_hsotg *hsotg) {} +static inline void dwc2_hcd_start (struct dwc2_hsotg *hsotg) {} +static inline void dwc2_hcd_remove (struct dwc2_hsotg *hsotg) {} +static inline int dwc2_hcd_init (struct dwc2_hsotg *hsotg,int irq, +const struct dwc2_core_params *params) +{return 0 ; } +#endif +#endif /* __DWC2_CORE_H__ */
drivers/usb/dwc2/core_intr.c +5 -3
@@ -287,9 +287,11 @@ static void dwc2_handle_conn_id_status_change_intr(struct dwc2_hsotg *hsotg)* Release lock before scheduling workq as it holds spinlock during * scheduling. */ -spin_unlock (&hsotg->lock); -queue_work (hsotg->wq_otg, &hsotg->wf_otg); -spin_lock (&hsotg->lock); +if (hsotg->wq_otg) { +spin_unlock (&hsotg->lock); +queue_work (hsotg->wq_otg, &hsotg->wf_otg); +spin_lock (&hsotg->lock); + }/* Clear interrupt */ writel (GINTSTS_CONIDSTSCHNG , hsotg->regs +GINTSTS );
drivers/usb/dwc2/gadget.c +21 -78
188 lines not on this page · raw message
drivers/usb/dwc2/hcd.c +0 -1
@@ -2839,7 +2839,6 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq, hcd->has_tt =1 ; -spin_lock_init (&hsotg->lock); ((struct wrapper_priv_data *) &hcd->hcd_priv)->hsotg = hsotg; hsotg->priv = hcd;
drivers/usb/dwc2/hcd.h +0 -10
@@ -668,9 +668,6 @@ extern irqreturn_t dwc2_handle_hcd_intr(struct dwc2_hsotg *hsotg);*/ extern void dwc2_hcd_stop (struct dwc2_hsotg *hsotg); -extern void dwc2_hcd_start (struct dwc2_hsotg *hsotg); -extern void dwc2_hcd_disconnect (struct dwc2_hsotg *hsotg); -/** * dwc2_hcd_is_b_host() - Returns 1 if core currently is acting as B host, * and 0 otherwise
@@ -680,13 +677,6 @@ extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg);extern int dwc2_hcd_is_b_host (struct dwc2_hsotg *hsotg);/** -* dwc2_hcd_get_frame_number() - Returns current frame number -* -* @hsotg: The DWC2 HCD -*/ -extern int dwc2_hcd_get_frame_number (struct dwc2_hsotg *hsotg); - -/** * dwc2_hcd_dump_state() - Dumps hsotg state * * @hsotg: The DWC2 HCD
drivers/usb/dwc2/pci.c +1 -0
@@ -141,6 +141,7 @@ static int dwc2_driver_probe(struct pci_dev *dev,pci_set_master (dev); +spin_lock_init (&hsotg->lock); retval =dwc2_hcd_init (hsotg, dev->irq, &dwc2_module_params);if (retval) {pci_disable_device (dev);
drivers/usb/dwc2/platform.c +28 -0
@@ -121,6 +121,7 @@ static int dwc2_driver_remove(struct platform_device *dev)struct dwc2_hsotg *hsotg =platform_get_drvdata (dev);dwc2_hcd_remove (hsotg); +s3c_hsotg_remove (hsotg);return 0 ; }
@@ -129,6 +130,7 @@ static const struct of_device_id dwc2_of_match_table[] = { { .compatible = "brcm,bcm2835-usb", .data = ¶ms_bcm2835 }, { .compatible = "rockchip,rk3066-usb", .data = ¶ms_rk3066 }, { .compatible = "snps,dwc2", .data = NULL }, + { .compatible = "samsung,s3c6400-hsotg", .data = NULL}, {}, };MODULE_DEVICE_TABLE (of, dwc2_of_match_table);
@@ -204,6 +206,10 @@ static int dwc2_driver_probe(struct platform_device *dev) hsotg->dr_mode =of_usb_get_dr_mode (dev->dev.of_node); +spin_lock_init (&hsotg->lock); + retval =dwc2_gadget_init (hsotg, irq); +if (retval) +return retval; retval =dwc2_hcd_init (hsotg, irq, params);if (retval)return retval;
@@ -213,6 +219,26 @@ static int dwc2_driver_probe(struct platform_device *dev)return retval; } +static int dwc2_suspend (struct platform_device *dev,pm_message_t state) +{ +struct dwc2_hsotg *dwc2 =platform_get_drvdata (dev); +int ret =0 ; + +if (dwc2_is_device_mode (dwc2)) + ret =s3c_hsotg_suspend (dwc2); +return ret; +} + +static int dwc2_resume (struct platform_device *dev) +{ +struct dwc2_hsotg *dwc2 =platform_get_drvdata (dev); +int ret =0 ; + +if (dwc2_is_device_mode (dwc2)) + ret =s3c_hsotg_resume (dwc2); +return ret; +} +static struct platform_driver dwc2_platform_driver = { .driver = { .name = dwc2_driver_name,
@@ -220,6 +246,8 @@ static struct platform_driver dwc2_platform_driver = { }, .probe = dwc2_driver_probe, .remove = dwc2_driver_remove, + .suspend = dwc2_suspend, + .resume = dwc2_resume, };module_platform_driver (dwc2_platform_driver);
Signature · 1 line
2.0.3
PATCH v7 3/8 usb: dwc2: convert to use dev_pm_ops API
In reply to [email protected]From: Dinh Nguyen <[email protected]>
Update suspend/resume to use dev_pm_ops API.
--- drivers/usb/dwc2/platform.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/usb/dwc2/platform.c +9 -6
@@ -219,9 +219,9 @@ static int dwc2_driver_probe(struct platform_device *dev)return retval; } -static int dwc2_suspend (struct platform_device *dev,pm_message_t state) +static int dwc2_suspend (struct device *dev) { -struct dwc2_hsotg *dwc2 =platform_get_drvdata (dev); +struct dwc2_hsotg *dwc2 =dev_get_drvdata (dev);int ret =0 ;if (dwc2_is_device_mode (dwc2))
@@ -229,9 +229,9 @@ static int dwc2_suspend(struct platform_device *dev, pm_message_t state)return ret; } -static int dwc2_resume (struct platform_device *dev) +static int dwc2_resume (struct device *dev) { -struct dwc2_hsotg *dwc2 =platform_get_drvdata (dev); +struct dwc2_hsotg *dwc2 =dev_get_drvdata (dev);int ret =0 ;if (dwc2_is_device_mode (dwc2))
@@ -239,15 +239,18 @@ static int dwc2_resume(struct platform_device *dev)return ret; } +static const struct dev_pm_ops dwc2_dev_pm_ops = { +SET_SYSTEM_SLEEP_PM_OPS (dwc2_suspend, dwc2_resume) +}; +static struct platform_driver dwc2_platform_driver = { .driver = { .name = dwc2_driver_name, .of_match_table = dwc2_of_match_table, + .pm = &dwc2_dev_pm_ops, }, .probe = dwc2_driver_probe, .remove = dwc2_driver_remove, - .suspend = dwc2_suspend, - .resume = dwc2_resume, };module_platform_driver (dwc2_platform_driver);
Signature · 1 line
2.0.3
RE: [PATCHv7 3/8] usb: dwc2: convert to use dev_pm_ops API
Quoted 51 lines
From: [email protected] [mailto:[email protected]]
Sent: Tuesday, November 11, 2014 9:14 AMFrom: Dinh Nguyen <[email protected]>
Update suspend/resume to use
dev_pm_opsAPI.Signed-off-by Dinh Nguyen <[email protected]>--- drivers/usb/dwc2/platform.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)drivers/usb/dwc2/platform.c +8
-4@@ -219,9 +219,9 @@ static int dwc2_driver_probe(struct platform_device *dev)return retval; } -static int dwc2_suspend (struct platform_device *dev,pm_message_t state) +static int dwc2_suspend (struct device *dev) { -struct dwc2_hsotg *dwc2 =platform_get_drvdata (dev); +struct dwc2_hsotg *dwc2 =dev_get_drvdata (dev);int ret =0 ;if (dwc2_is_device_mode (dwc2))@@ -229,9 +229,9 @@ static int dwc2_suspend(struct platform_device *dev, pm_message_t state)return ret; } -static int dwc2_resume (struct platform_device *dev) +static int dwc2_resume (struct device *dev) { -struct dwc2_hsotg *dwc2 =platform_get_drvdata (dev); +struct dwc2_hsotg *dwc2 =dev_get_drvdata (dev);int ret =0 ;if (dwc2_is_device_mode (dwc2))@@ -239,15 +239,18 @@ static int dwc2_resume(struct platform_device *dev)return ret; } +static const struct dev_pm_ops dwc2_dev_pm_ops = { +SET_SYSTEM_SLEEP_PM_OPS (dwc2_suspend, dwc2_resume) +}; +static struct platform_driver dwc2_platform_driver = { .driver = { .name = dwc2_driver_name,
drivers/usb/dwc2/platform.c static int dwc2_resume(struct platform_device *dev) · line 256
Quoted 10 lines
drivers/usb/dwc2/platform.c +1
-2.of_match_table = dwc2_of_match_table, + .pm = &dwc2_dev_pm_ops, }, .probe = dwc2_driver_probe, .remove = dwc2_driver_remove, - .suspend = dwc2_suspend, - .resume = dwc2_resume, };module_platform_driver (dwc2_platform_driver);
PATCH v7 4/8 usb: dwc2: Initialize the USB core for peripheral mode
In reply to [email protected]From: Dinh Nguyen <[email protected]>
Initialize the USB driver to peripheral mode when a B-Device connector is attached.
---
v7: s3c_hsotg_core_init became s3c_hsotg_core_init_disconnected
v5: move the export of s3c_hsotg_core_init into this patch
--- drivers/usb/dwc2/core.h | 4 ++++ drivers/usb/dwc2/gadget.c | 4 ++-- drivers/usb/dwc2/hcd.c | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-)
drivers/usb/dwc2/core.h +4 -0
@@ -966,6 +966,8 @@ extern int s3c_hsotg_remove(struct dwc2_hsotg *hsotg);extern int s3c_hsotg_suspend (struct dwc2_hsotg *dwc2);extern int s3c_hsotg_resume (struct dwc2_hsotg *dwc2);extern int dwc2_gadget_init (struct dwc2_hsotg *hsotg,int irq); +extern void s3c_hsotg_core_init_disconnected (struct dwc2_hsotg *dwc2); +extern void s3c_hsotg_core_connect (struct dwc2_hsotg *hsotg);#else static inline int s3c_hsotg_remove (struct dwc2_hsotg *dwc2) {return 0 ; }
@@ -975,6 +977,8 @@ static inline int s3c_hsotg_resume(struct dwc2_hsotg *dwc2) {return 0 ; }static inline int dwc2_gadget_init (struct dwc2_hsotg *hsotg,int irq) {return 0 ; } +static inline void s3c_hsotg_core_init_disconnected (struct dwc2_hsotg *dwc2) {} +static inline void s3c_hsotg_core_connect (struct dwc2_hsotg *hsotg) {}#endif #if IS_ENABLED (CONFIG_USB_DWC2_HOST ) ||IS_ENABLED (CONFIG_USB_DWC2_DUAL_ROLE )
drivers/usb/dwc2/gadget.c +2 -2
@@ -2125,7 +2125,7 @@ static int s3c_hsotg_corereset(struct dwc2_hsotg *hsotg)* * Issue a soft reset to the core, and await the core finishing it. */ -static void s3c_hsotg_core_init_disconnected (struct dwc2_hsotg *hsotg) +void s3c_hsotg_core_init_disconnected (struct dwc2_hsotg *hsotg) {s3c_hsotg_corereset (hsotg);
@@ -2257,7 +2257,7 @@ static void s3c_hsotg_core_disconnect(struct dwc2_hsotg *hsotg)__orr32 (hsotg->regs +DCTL ,DCTL_SFTDISCON ); } -static void s3c_hsotg_core_connect (struct dwc2_hsotg *hsotg) +void s3c_hsotg_core_connect (struct dwc2_hsotg *hsotg) {/* remove the soft-disconnect and let's go */ __bic32 (hsotg->regs +DCTL ,DCTL_SFTDISCON );
drivers/usb/dwc2/hcd.c +2 -0
@@ -1371,6 +1371,8 @@ static void dwc2_conn_id_status_change(struct work_struct *work) hsotg->op_state =OTG_STATE_B_PERIPHERAL ;dwc2_core_init (hsotg, false,-1 );dwc2_enable_global_interrupts (hsotg); +s3c_hsotg_core_init_disconnected (hsotg); +s3c_hsotg_core_connect (hsotg); }else {/* A-Device connector (Host Mode) */ dev_dbg (hsotg->dev,"connId A\n" );
Signature · 1 line
2.0.3
PATCH v7 5/8 usb: dwc2: Update common interrupt handler to call gadget interrupt handler
In reply to [email protected]From: Dinh Nguyen <[email protected]>
Make dwc2_handle_common_intr call the gadget interrupt function when operating in peripheral mode. Remove the spinlock functions in s3c_hsotg_irq as dwc2_handle_common_intr() already has the spinlocks.
Move the registeration of the IRQ to common code for platform and PCI.
Remove duplicate interrupt conditions that was in gadget, as those are handled by dwc2 common interrupt handler.
---
v7: Use IRQF_SHARED
v5: remove individual devm_request_irq from gadget and hcd, and place a
single devm_request_irq in platform and pci.
v2: Keep interrupt handler for host and peripheral modes separate
--- drivers/usb/dwc2/core.c | 10 ---------- drivers/usb/dwc2/gadget.c | 46 +++------------------------------------------ drivers/usb/dwc2/pci.c | 6 ++++++ drivers/usb/dwc2/platform.c | 8 ++++++++ 4 files changed, 17 insertions(+), 53 deletions(-)
drivers/usb/dwc2/core.c +0 -10
@@ -458,16 +458,6 @@ int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq)/* Clear the SRP success bit for FS-I2c */ hsotg->srp_success =0 ; -if (irq >=0 ) { -dev_dbg (hsotg->dev,"registering common handler for irq%d\n" , - irq); - retval =devm_request_irq (hsotg->dev, irq, - dwc2_handle_common_intr,IRQF_SHARED , -dev_name (hsotg->dev), hsotg); -if (retval) -return retval; - } -/* Enable common interrupts */ dwc2_enable_common_interrupts (hsotg);
drivers/usb/dwc2/gadget.c +3 -43
75 lines not on this page · raw message
drivers/usb/dwc2/pci.c +6 -0
@@ -141,6 +141,12 @@ static int dwc2_driver_probe(struct pci_dev *dev,pci_set_master (dev); + retval =devm_request_irq (hsotg->dev, dev->irq, + dwc2_handle_common_intr,IRQF_SHARED , +dev_name (hsotg->dev), hsotg); +if (retval) +return retval; +spin_lock_init (&hsotg->lock); retval =dwc2_hcd_init (hsotg, dev->irq, &dwc2_module_params);if (retval) {
drivers/usb/dwc2/platform.c +8 -0
@@ -196,6 +196,14 @@ static int dwc2_driver_probe(struct platform_device *dev)return irq; } +dev_dbg (hsotg->dev,"registering common handler for irq%d\n" , + irq); + retval =devm_request_irq (hsotg->dev, irq, + dwc2_handle_common_intr,IRQF_SHARED , +dev_name (hsotg->dev), hsotg); +if (retval) +return retval; + res =platform_get_resource (dev,IORESOURCE_MEM ,0 ); hsotg->regs =devm_ioremap_resource (&dev->dev, res);if (IS_ERR (hsotg->regs))
Signature · 1 line
2.0.3
RE: [PATCHv7 5/8] usb: dwc2: Update common interrupt handler to call gadget interrupt handler
Quoted 59 lines
From: [email protected] [mailto:[email protected]]
Sent: Tuesday, November 11, 2014 9:14 AMFrom: Dinh Nguyen <[email protected]>
Make
dwc2_handle_common_intrcall the gadget interrupt function when operating in peripheral mode. Remove the spinlock functions ins3c_hsotg_irqasdwc2_handle_common_intr()already has the spinlocks.Move the registeration of the IRQ to common code for platform and PCI.
Remove duplicate interrupt conditions that was in gadget, as those are handled by dwc2 common interrupt handler.
Signed-off-by Dinh Nguyen <[email protected]>---
v7: UseIRQF_SHARED
v5: remove individualdevm_request_irqfrom gadget and hcd, and place a
singledevm_request_irqin platform and pci.
v2: Keep interrupt handler for host and peripheral modes separate--- drivers/usb/dwc2/core.c | 10 ---------- drivers/usb/dwc2/gadget.c | 46 +++------------------------------------------ drivers/usb/dwc2/pci.c | 6 ++++++ drivers/usb/dwc2/platform.c | 8 ++++++++ 4 files changed, 17 insertions(+), 53 deletions(-)drivers/usb/dwc2/core.c +0
-10@@ -458,16 +458,6 @@ int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq)/* Clear the SRP success bit for FS-I2c */ hsotg->srp_success =0 ; -if (irq >=0 ) { -dev_dbg (hsotg->dev,"registering common handler for irq%d\n" , - irq); - retval =devm_request_irq (hsotg->dev, irq, - dwc2_handle_common_intr,IRQF_SHARED , -dev_name (hsotg->dev), hsotg); -if (retval) -return retval; - } -/* Enable common interrupts */ dwc2_enable_common_interrupts (hsotg);drivers/usb/dwc2/gadget.c +0
-3@@ -2285,33 +2285,12 @@ irq_retry: gintsts &= gintmsk; -if (gintsts &GINTSTS_OTGINT ) { -u32 otgint =readl (hsotg->regs +GOTGINT ); -
drivers/usb/dwc2/gadget.c irq_retry: · line 2300
Quoted 10 lines
drivers/usb/dwc2/gadget.c +0
-10-dev_info (hsotg->dev,"OTGInt: %08x\n" , otgint); - -writel (otgint, hsotg->regs +GOTGINT ); - } - -if (gintsts &GINTSTS_SESSREQINT ) { -dev_dbg (hsotg->dev,"%s: SessReqInt\n" , __func__); -writel (GINTSTS_SESSREQINT , hsotg->regs +GINTSTS ); - } -
This hunk will clash with the patch that Marek has just submitted, which uses the SESSREQINT in the gadget. But I guess you two and Felipe can resolve that :)
Quoted 87 lines
drivers/usb/dwc2/gadget.c +3
-30if (gintsts &GINTSTS_ENUMDONE ) {writel (GINTSTS_ENUMDONE , hsotg->regs +GINTSTS );s3c_hsotg_irq_enumdone (hsotg); } -if (gintsts &GINTSTS_CONIDSTSCHNG ) { -dev_dbg (hsotg->dev,"ConIDStsChg (DSTS=0x%08x, GOTCTL=%08x)\n" , -readl (hsotg->regs +DSTS ), -readl (hsotg->regs +GOTGCTL )); - -writel (GINTSTS_CONIDSTSCHNG , hsotg->regs +GINTSTS ); - } -if (gintsts & (GINTSTS_OEPINT |GINTSTS_IEPINT )) {u32 daint =readl (hsotg->regs +DAINT );u32 daintmsk =readl (hsotg->regs +DAINTMSK );@@ -2392,25 +2371,6 @@ irq_retry:s3c_hsotg_handle_rx (hsotg); } -if (gintsts &GINTSTS_MODEMIS ) { -dev_warn (hsotg->dev,"warning, mode mismatch triggered\n" ); -writel (GINTSTS_MODEMIS , hsotg->regs +GINTSTS ); - } - -if (gintsts &GINTSTS_USBSUSP ) { -dev_info (hsotg->dev,"GINTSTS_USBSusp\n" ); -writel (GINTSTS_USBSUSP , hsotg->regs +GINTSTS ); - -call_gadget (hsotg, suspend); - } - -if (gintsts &GINTSTS_WKUPINT ) { -dev_info (hsotg->dev,"GINTSTS_WkUpIn\n" ); -writel (GINTSTS_WKUPINT , hsotg->regs +GINTSTS ); - -call_gadget (hsotg, resume); - } -if (gintsts &GINTSTS_ERLYSUSP ) {dev_dbg (hsotg->dev,"GINTSTS_ErlySusp\n" );writel (GINTSTS_ERLYSUSP , hsotg->regs +GINTSTS );@@ -3510,14 +3470,14 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)s3c_hsotg_hw_cfg (hsotg);s3c_hsotg_init (hsotg); - ret =devm_request_irq (dev, irq, s3c_hsotg_irq,0 , -dev_name (dev), hsotg); + ret =devm_request_irq (hsotg->dev, irq, s3c_hsotg_irq,IRQF_SHARED , +dev_name (hsotg->dev), hsotg);if (ret <0 ) {s3c_hsotg_phy_disable (hsotg);clk_disable_unprepare (hsotg->clk);regulator_bulk_disable (ARRAY_SIZE (hsotg->supplies), hsotg->supplies); -dev_err (dev,"cannot claim IRQ\n" ); +dev_err (dev,"cannot claim IRQ for gadget\n" ); goto err_clk; }drivers/usb/dwc2/pci.c +6
-0@@ -141,6 +141,12 @@ static int dwc2_driver_probe(struct pci_dev *dev,pci_set_master (dev); + retval =devm_request_irq (hsotg->dev, dev->irq, + dwc2_handle_common_intr,IRQF_SHARED , +dev_name (hsotg->dev), hsotg); +if (retval) +return retval; +spin_lock_init (&hsotg->lock); retval =dwc2_hcd_init (hsotg, dev->irq, &dwc2_module_params);if (retval) {drivers/usb/dwc2/platform.c +1
-0@@ -196,6 +196,14 @@ static int dwc2_driver_probe(struct platform_device *dev)return irq; } + dev_dbg(hsotg->dev, "registering common handler for irq%d\n",
drivers/usb/dwc2/platform.c static int dwc2_driver_probe(struct platform_device *dev) · line 209
Quoted 10 lines
drivers/usb/dwc2/platform.c +7
-0+ irq); + retval =devm_request_irq (hsotg->dev, irq, + dwc2_handle_common_intr,IRQF_SHARED , +dev_name (hsotg->dev), hsotg); +if (retval) +return retval; + res =platform_get_resource (dev,IORESOURCE_MEM ,0 ); hsotg->regs =devm_ioremap_resource (&dev->dev, res);if (IS_ERR (hsotg->regs))
PATCH v7 6/8 usb: dwc2: gadget: Do not fail probe if there isn't a clock node
In reply to [email protected]From: Dinh Nguyen <[email protected]>
Since the dwc2 hcd driver is currently not looking for a clock node during init, we should not completely fail if there isn't a clock provided. By assigning clk = NULL, this allows the driver, when configured for dual-role mode, to be able to continue loading the host portion of the driver when a clock node is not specified.
---
v7: Reworked to use clk=NULL and remove the need to is IS_ERR(clk)
v6: none
v5: reworked to not access gadget functions from the hcd.
--- drivers/usb/dwc2/gadget.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/dwc2/gadget.c +1 -0
@@ -3431,6 +3431,7 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq) hsotg->clk =devm_clk_get (dev,"otg" );if (IS_ERR (hsotg->clk)) { + hsotg->clk =NULL ;dev_err (dev,"cannot get otg clock\n" );return PTR_ERR (hsotg->clk); }
Signature · 1 line
2.0.3
RE: [PATCHv7 6/8] usb: dwc2: gadget: Do not fail probe if there isn't a clock node
Quoted 25 lines
From: [email protected] [mailto:[email protected]]
Sent: Tuesday, November 11, 2014 9:14 AMFrom: Dinh Nguyen <[email protected]>
Since the dwc2 hcd driver is currently not looking for a clock node during init, we should not completely fail if there isn't a clock provided. By assigning clk = NULL, this allows the driver, when configured for dual-role mode, to be able to continue loading the host portion of the driver when a clock node is not specified.
Signed-off-by Dinh Nguyen <[email protected]>---
v7: Reworked to use clk=NULL and remove the need to isIS_ERR(clk)
v6: none
v5: reworked to not access gadget functions from the hcd.--- drivers/usb/dwc2/gadget.c | 1 + 1 file changed, 1 insertion(+)drivers/usb/dwc2/gadget.c +0
-0
drivers/usb/dwc2/gadget.c int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq) · line 3437
Quoted 7 lines
drivers/usb/dwc2/gadget.c +1
-0@@ -3431,6 +3431,7 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq) hsotg->clk =devm_clk_get (dev,"otg" );if (IS_ERR (hsotg->clk)) { + hsotg->clk =NULL ;dev_err (dev,"cannot get otg clock\n" );return PTR_ERR (hsotg->clk); }
Whoops, you just broke the return value, since you NULL out hsotg->clk and then call PTR_ERR() on it.
Signature · 1 line
Paul
Re: [PATCHv7 6/8] usb: dwc2: gadget: Do not fail probe if there isn't a clock node
Quoted 26 lines · Paul Zimmerman
Quoted 26 lines
From: [email protected] [mailto:[email protected]]
Sent: Tuesday, November 11, 2014 9:14 AMFrom: Dinh Nguyen <[email protected]>
Since the dwc2 hcd driver is currently not looking for a clock node during init, we should not completely fail if there isn't a clock provided. By assigning clk = NULL, this allows the driver, when configured for dual-role mode, to be able to continue loading the host portion of the driver when a clock node is not specified.
Signed-off-by Dinh Nguyen <[email protected]>---
v7: Reworked to use clk=NULL and remove the need to isIS_ERR(clk)
v6: none
v5: reworked to not access gadget functions from the hcd.--- drivers/usb/dwc2/gadget.c | 1 + 1 file changed, 1 insertion(+)drivers/usb/dwc2/gadget.c +0
-0@@ -3431,6 +3431,7 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
Quoted 9 lines
drivers/usb/dwc2/gadget.c int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq) · line 3437
Quoted 6 lines
drivers/usb/dwc2/gadget.c +1
-0hsotg->clk =devm_clk_get (dev,"otg" );if (IS_ERR (hsotg->clk)) { + hsotg->clk =NULL ;dev_err (dev,"cannot get otg clock\n" );return PTR_ERR (hsotg->clk); }Whoops, you just broke the return value, since you NULL out
hsotg->clkand then callPTR_ERR()on it.
yeah, the idea was to remove the early return too :-)
Signature · 1 line
balbi
PATCH v7 7/8 usb: dwc2: move usb_disabled() call to host driver only
In reply to [email protected]From: Dinh Nguyen <[email protected]>
Since platform.c will get built for both Host and Gadget, if we leave the usb_disabled() call in platform.c, it results in the following build error when (!USB && USB_GADGET) condition is met.
ERROR: "usb_disabled" [drivers/usb/dwc2/dwc2_platform.ko] undefined!
Since usb_disabled() is mostly used to disable USB host functionality, move the call the host portion for the DWC2 driver.
--- drivers/usb/dwc2/hcd.c | 3 +++ drivers/usb/dwc2/platform.c | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/usb/dwc2/hcd.c +3 -0
@@ -2780,6 +2780,9 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,int i, num_channels;int retval; +if (usb_disabled ()) +return -ENODEV ; +dev_dbg (hsotg->dev,"DWC OTG HCD INIT\n" );/* Detect config values from hardware */
drivers/usb/dwc2/platform.c +0 -3
@@ -157,9 +157,6 @@ static int dwc2_driver_probe(struct platform_device *dev)int retval;int irq; -if (usb_disabled ()) -return -ENODEV ; - match =of_match_device (dwc2_of_match_table, &dev->dev);if (match && match->data) { params = match->data;
Signature · 1 line
2.0.3
RE: [PATCHv7 7/8] usb: dwc2: move usb_disabled() call to host driver only
Quoted 39 lines
From: [email protected] [mailto:[email protected]]
Sent: Tuesday, November 11, 2014 9:14 AMFrom: Dinh Nguyen <[email protected]>
Since
platform.cwill get built for both Host and Gadget, if we leave theusb_disabled()call inplatform.c, it results in the following build error when (!USB &&USB_GADGET) condition is met.ERROR: "
usb_disabled" [drivers/usb/dwc2/dwc2_platform.ko] undefined!Since
usb_disabled()is mostly used to disable USB host functionality, move the call the host portion for the DWC2 driver.Signed-off-by Dinh Nguyen <[email protected]>--- drivers/usb/dwc2/hcd.c | 3 +++ drivers/usb/dwc2/platform.c | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-)drivers/usb/dwc2/hcd.c +3
-0@@ -2780,6 +2780,9 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,int i, num_channels;int retval; +if (usb_disabled ()) +return -ENODEV ; +dev_dbg (hsotg->dev,"DWC OTG HCD INIT\n" );/* Detect config values from hardware */ drivers/usb/dwc2/platform.c +0
-0
drivers/usb/dwc2/platform.c static int dwc2_driver_probe(struct platform_device *dev) · line 162
Quoted 9 lines
drivers/usb/dwc2/platform.c +0
-3@@ -157,9 +157,6 @@ static int dwc2_driver_probe(struct platform_device *dev)int retval;int irq; -if (usb_disabled ()) -return -ENODEV ; - match =of_match_device (dwc2_of_match_table, &dev->dev);if (match && match->data) { params = match->data;
This patch also fixes a minor buglet, in that we were missing the usb_disabled() check in pci.c.
PATCH v7 8/8 usb: dwc2: Update Kconfig to support dual-role
In reply to [email protected]From: Dinh Nguyen <[email protected]>
Update DWC2 kconfig and makefile to support dual-role mode. The platform file will always get compiled for the case where the controller is directly connected to the CPU. So for loadable modules, dwc2.ko is built for host, peripheral, and dual-role mode. The PCI bus interface will be called dwc2_pci.ko and the platform interface module will be called dwc2_platform.ko.
---
v7: None
v6: Correct notes for USB_DWC2_DUAL_ROLE and USB_DWC2_PERIPHERAL
Remove extra default for USB_DWC2_PLATFORM and make it a condition for building dwc2_platform.ko. In addition USB_DWC2_PLATFORM and USB_DWC2_PCI are now tristate.
v5: dwc2.ko for all modes along with dwc2_platform.ko and dwc2_pci.ko will
get built for kernel modules.
v3: Add USB_GADGET=y and USB_GADGET=USB_DWC2 for peripheral and dual-role
config options.
v2: Remove reference to dwc2_gadget
--- drivers/usb/dwc2/Kconfig | 66 ++++++++++++++++++++++++++++------------------- drivers/usb/dwc2/Makefile | 32 +++++++++++------------ 2 files changed, 55 insertions(+), 43 deletions(-)
drivers/usb/dwc2/Kconfig +39 -27
@@ -1,5 +1,5 @@ config USB_DWC2 - bool "DesignWare USB2 DRD Core Support" + tristate "DesignWare USB2 DRD Core Support" depends on USB || USB_GADGET help Say Y here if your system has a Dual Role Hi-Speed USB
@@ -10,49 +10,61 @@ config USB_DWC2 bus interface module (if you have a PCI bus system) will be called dwc2_pci.ko, and the platform interface module (for controllers directly connected to the CPU) will be called - dwc2_platform.ko. For gadget mode, there will be a single - module called dwc2_gadget.ko. - - NOTE: The s3c-hsotg driver is now renamed to dwc2_gadget. The - host and gadget drivers are still currently separate drivers. - There are plans to merge the dwc2_gadget driver with the dwc2 - host driver in the near future to create a dual-role driver. + dwc2_platform.ko. For all modes(host, gadget and dual-role), there + will be an additional module named dwc2.ko. if USB_DWC2 +choice + bool "DWC2 Mode Selection" + default USB_DWC2_DUAL_ROLE if (USB && USB_GADGET) + default USB_DWC2_HOST if (USB && !USB_GADGET) + default USB_DWC2_PERIPHERAL if (!USB && USB_GADGET) + config USB_DWC2_HOST - tristate "Host only mode" + bool "Host only mode" depends on USB help The Designware USB2.0 high-speed host controller - integrated into many SoCs. + integrated into many SoCs. Select this option if you want the + driver to operate in Host-only mode. -config USB_DWC2_PLATFORM - bool "DWC2 Platform" - depends on USB_DWC2_HOST - default USB_DWC2_HOST +comment "Gadget/Dual-role mode requires USB Gadget support to be enabled" + +config USB_DWC2_PERIPHERAL + bool "Gadget only mode" + depends on USB_GADGET=y || USB_GADGET=USB_DWC2 + help + The Designware USB2.0 high-speed gadget controller + integrated into many SoCs. Select this option if you want the + driver to operate in Peripheral-only mode. This option requires + USB_GADGET to be enabled. + +config USB_DWC2_DUAL_ROLE + bool "Dual Role mode" + depends on (USB=y || USB=USB_DWC2) && (USB_GADGET=y || USB_GADGET=USB_DWC2) help - The Designware USB2.0 platform interface module for - controllers directly connected to the CPU. This is only - used for host mode. + Select this option if you want the driver to work in a dual-role + mode. In this mode both host and gadget features are enabled, and + the role will be determined by the cable that gets plugged-in. This + option requires USB_GADGET to be enabled. +endchoice + +config USB_DWC2_PLATFORM + tristate "DWC2 Platform" + default USB_DWC2_HOST || USB_DWC2_PERIPHERAL + help + The Designware USB2.0 platform interface module for + controllers directly connected to the CPU. config USB_DWC2_PCI - bool "DWC2 PCI" + tristate "DWC2 PCI" depends on USB_DWC2_HOST && PCI default USB_DWC2_HOST help The Designware USB2.0 PCI interface module for controllers connected to a PCI bus. This is only used for host mode. -comment "Gadget mode requires USB Gadget support to be enabled" - -config USB_DWC2_PERIPHERAL - tristate "Gadget only mode" - depends on USB_GADGET - help - The Designware USB2.0 high-speed gadget controller - integrated into many SoCs. - config USB_DWC2_DEBUG bool "Enable Debugging Messages" help
drivers/usb/dwc2/Makefile +16 -16
@@ -1,28 +1,28 @@ ccflags-$(CONFIG_USB_DWC2_DEBUG) += -DDEBUG ccflags-$(CONFIG_USB_DWC2_VERBOSE) += -DVERBOSE_DEBUG -obj-$(CONFIG_USB_DWC2_HOST) += dwc2.o +obj-$(CONFIG_USB_DWC2) += dwc2.o dwc2-y := core.o core_intr.o -dwc2-y += hcd.o hcd_intr.o -dwc2-y += hcd_queue.o hcd_ddma.o + +ifneq ($(filter y,$(CONFIG_USB_DWC2_HOST) $(CONFIG_USB_DWC2_DUAL_ROLE)),) + dwc2-y += hcd.o hcd_intr.o + dwc2-y += hcd_queue.o hcd_ddma.o +endif + +ifneq ($(filter y,$(CONFIG_USB_DWC2_PERIPHERAL) $(CONFIG_USB_DWC2_DUAL_ROLE)),) + dwc2-y += gadget.o +endif # NOTE: The previous s3c-hsotg peripheral mode only driver has been moved to # this location and renamed gadget.c. When building for dynamically linked -# modules, dwc2_gadget.ko will get built for peripheral mode. For host mode, -# the core module will be dwc2.ko, the PCI bus interface module will called -# dwc2_pci.ko and the platform interface module will be called dwc2_platform.ko. -# At present the host and gadget driver will be separate drivers, but there -# are plans in the near future to create a dual-role driver. +# modules, dwc2.ko will get built for host mode, peripheral mode, and dual-role +# mode. The PCI bus interface module will called dwc2_pci.ko and the platform +# interface module will be called dwc2_platform.ko. ifneq ($(CONFIG_USB_DWC2_PCI),) - obj-$(CONFIG_USB_DWC2_HOST) += dwc2_pci.o + obj-$(CONFIG_USB_DWC2) += dwc2_pci.o dwc2_pci-y := pci.o endif -ifneq ($(CONFIG_USB_DWC2_PLATFORM),) - obj-$(CONFIG_USB_DWC2_HOST) += dwc2_platform.o - dwc2_platform-y := platform.o -endif - -obj-$(CONFIG_USB_DWC2_PERIPHERAL) += dwc2_gadget.o -dwc2_gadget-y := gadget.o +obj-$(CONFIG_USB_DWC2_PLATFORM) += dwc2_platform.o +dwc2_platform-y := platform.o
Signature · 1 line
2.0.3