usb: common and dwc3: converting to unified device property
Subsystems (8)
cover usb: common and dwc3: converting to unified device property
Hi,
While converting dwc3 to the unified device property interface, I noticed that there is really nothing preventing of_usb_get_dr_mode and of_usb_get_maximum_speed from being converted as well. Hope that's OK.
The only special case was dwc3-st.c, where the dr_mode is requested before the platform device has been populated. I changed it so that the dr_mode property is requested after the platform device is populated in a separate patch.
Heikki Krogerus (5):
usb: common: of_usb_get_maximum_speed to usb_get_maximum_speed
usb: dwc3: st: prepare the driver for generic usb_get_dr_mode function
usb: common: of_usb_get_dr_mode to usb_get_dr_mode
usb: dwc3: core: convert to unified device property interface
usb: dwc3: pci: passing forward the ACPI companion
drivers/usb/chipidea/core.c | 4 +-- drivers/usb/common/common.c | 59 +++++++++++++++-------------------------- drivers/usb/dwc2/platform.c | 2 +- drivers/usb/dwc3/core.c | 50 +++++++++++++++++----------------- drivers/usb/dwc3/dwc3-pci.c | 1 + drivers/usb/dwc3/dwc3-st.c | 12 +++++++-- drivers/usb/musb/musb_dsps.c | 2 +- drivers/usb/musb/sunxi.c | 2 +- drivers/usb/phy/phy-msm-usb.c | 2 +- drivers/usb/phy/phy-tegra-usb.c | 2 +- include/linux/usb/ch9.h | 11 +++++++- include/linux/usb/of.h | 12 --------- include/linux/usb/otg.h | 9 +++++++ 13 files changed, 84 insertions(+), 84 deletions(-)
Signature · 1 line
2.5.0
PATCH 1/5 usb: common: of_usb_get_maximum_speed to usb_get_maximum_speed
By using the unified device property interface, the function can be made available for all platforms and not just the ones using DT.
--- drivers/usb/chipidea/core.c | 2 +- drivers/usb/common/common.c | 44 ++++++++++++++++++-------------------------- drivers/usb/dwc3/core.c | 3 ++- include/linux/usb/ch9.h | 11 ++++++++++- include/linux/usb/of.h | 6 ------ 5 files changed, 31 insertions(+), 35 deletions(-)
drivers/usb/chipidea/core.c +1 -1
@@ -648,7 +648,7 @@ static int ci_get_platdata(struct device *dev,return ret; } -if (of_usb_get_maximum_speed (dev->of_node) ==USB_SPEED_FULL ) +if (usb_get_maximum_speed (dev) ==USB_SPEED_FULL ) platdata->flags |=CI_HDRC_FORCE_FULLSPEED ; platdata->itc_setting =1 ;
drivers/usb/common/common.c +18 -26
56 lines not on this page · raw message
drivers/usb/dwc3/core.c +2 -1
@@ -842,8 +842,9 @@ static int dwc3_probe(struct platform_device *pdev)*/ hird_threshold =12 ; + dwc->maximum_speed =usb_get_maximum_speed (dev); +if (node) { - dwc->maximum_speed =of_usb_get_maximum_speed (node); dwc->has_lpm_erratum =of_property_read_bool (node,"snps,has-lpm-erratum" ); of_property_read_u8(node, "snps,lpm-nyet-threshold",
include/linux/usb/ch9.h +10 -1
@@ -32,9 +32,9 @@#ifndef __LINUX_USB_CH9_H#define __LINUX_USB_CH9_H +#include <linux/device.h> #include <uapi/linux/usb/ch9.h> -/** * usb_speed_string() - Returns human readable-name of the speed. * @speed: The speed to return human-readable name for. If it's not
@@ -43,6 +43,15 @@*/ extern const char *usb_speed_string (enum usb_device_speed speed); +/** +* usb_get_maximum_speed - Get maximum requested speed for a given USB +* controller. +* @dev: Pointer to the given USB controller device +* +* The function gets the maximum speed string from property "maximum-speed", +* and returns the corresponding enum usb_device_speed. +*/ +extern enum usb_device_speed usb_get_maximum_speed (struct device *dev);/** * usb_state_string - Returns human readable name for the state.
include/linux/usb/of.h +0 -6
@@ -13,7 +13,6 @@#if IS_ENABLED (CONFIG_OF )enum usb_dr_mode of_usb_get_dr_mode (struct device_node *np); -enum usb_device_speed of_usb_get_maximum_speed (struct device_node *np);bool of_usb_host_tpl_support (struct device_node *np);int of_usb_update_otg_caps (struct device_node *np,struct usb_otg_caps *otg_caps);
@@ -23,11 +22,6 @@ static inline enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)return USB_DR_MODE_UNKNOWN ; } -static inline enum usb_device_speed -of_usb_get_maximum_speed (struct device_node *np) -{ -return USB_SPEED_UNKNOWN ; -}static inline bool of_usb_host_tpl_support (struct device_node *np) {return false;
Signature · 1 line
2.5.0
Re: [PATCH 1/5] usb: common: of_usb_get_maximum_speed to usb_get_maximum_speed
Quoted 5 lines · Heikki Krogerus
By using the unified device property interface, the function can be made available for all platforms and not just the ones using DT.
Signed-off-by Heikki Krogerus <[email protected]>
this breaks compilation of my current testing/next.
Signature · 1 line
balbi
Re: [PATCH 1/5] usb: common: of_usb_get_maximum_speed to usb_get_maximum_speed
Quoted 8 lines · Felipe Balbi
Quoted 5 lines · Heikki Krogerus
By using the unified device property interface, the function can be made available for all platforms and not just the ones using DT.
Signed-off-by Heikki Krogerus <[email protected]>this breaks compilation of my current testing/next.
OK. I'll rebase these on top of that branch.
Thanks,
Signature · 1 line
heikki
PATCH 2/5 usb: dwc3: st: prepare the driver for generic usb_get_dr_mode function
In reply to Heikki Krogerusof_usb_get_dr_mode will be converted into more generic usb_get_dr_mode function that will take struct device instead of struct device_node as it's parameter.
To make the conversion possible later, waiting for the platform device for dwc3 to be populated before calling of_usb_get_dr_mode.
--- drivers/usb/dwc3/dwc3-st.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/usb/dwc3/dwc3-st.c +10 -2
@@ -195,6 +195,7 @@ static int st_dwc3_probe(struct platform_device *pdev)struct resource *res;struct device *dev = &pdev->dev;struct device_node *node = dev->of_node, *child; +struct platform_device *child_pdev;struct regmap *regmap;int ret;
@@ -253,8 +254,6 @@ static int st_dwc3_probe(struct platform_device *pdev) goto undo_softreset; } - dwc3_data->dr_mode =of_usb_get_dr_mode (child); -/* Allocate and initialize the core */ ret =of_platform_populate (node,NULL ,NULL , dev);if (ret) {
@@ -262,6 +261,15 @@ static int st_dwc3_probe(struct platform_device *pdev) goto undo_softreset; } + child_pdev =of_find_device_by_node (child); +if (!child_pdev) { +dev_err (dev,"failed to find dwc3 core device\n" ); + ret = -ENODEV ; + goto undo_softreset; + } + + dwc3_data->dr_mode =of_usb_get_dr_mode (child_pdev->dev.of_node); +/* * Configure the USB port as device or host according to the static * configuration passed from DT.
Signature · 1 line
2.5.0
PATCH 3/5 usb: common: of_usb_get_dr_mode to usb_get_dr_mode
In reply to Heikki KrogerusBy using the unified device property interface, the function can be made available for all platforms and not just the ones using DT.
--- drivers/usb/chipidea/core.c | 2 +- drivers/usb/common/common.c | 15 ++++----------- drivers/usb/dwc2/platform.c | 2 +- drivers/usb/dwc3/core.c | 2 +- drivers/usb/dwc3/dwc3-st.c | 2 +- drivers/usb/musb/musb_dsps.c | 2 +- drivers/usb/musb/sunxi.c | 2 +- drivers/usb/phy/phy-msm-usb.c | 2 +- drivers/usb/phy/phy-tegra-usb.c | 2 +- include/linux/usb/of.h | 6 ------ include/linux/usb/otg.h | 9 +++++++++ 11 files changed, 21 insertions(+), 25 deletions(-)
drivers/usb/chipidea/core.c +1 -1
@@ -611,7 +611,7 @@ static int ci_get_platdata(struct device *dev, platdata->phy_mode =of_usb_get_phy_mode (dev->of_node);if (!platdata->dr_mode) - platdata->dr_mode =of_usb_get_dr_mode (dev->of_node); + platdata->dr_mode =usb_get_dr_mode (dev);if (platdata->dr_mode ==USB_DR_MODE_UNKNOWN ) platdata->dr_mode =USB_DR_MODE_OTG ;
drivers/usb/common/common.c +4 -11
@@ -99,7 +99,6 @@ const char *usb_state_string(enum usb_device_state state) }EXPORT_SYMBOL_GPL (usb_state_string); -#ifdef CONFIG_OF static const char *const usb_dr_modes[] = { [USB_DR_MODE_UNKNOWN ] ="" , [USB_DR_MODE_HOST ] ="host" ,
@@ -107,19 +106,12 @@ static const char *const usb_dr_modes[] = { [USB_DR_MODE_OTG] = "otg", }; -/** -* of_usb_get_dr_mode - Get dual role mode for given device_node -* @np: Pointer to the given device_node -* -* The function gets phy interface string from property 'dr_mode', -* and returns the correspondig enum usb_dr_mode -*/ -enum usb_dr_mode of_usb_get_dr_mode (struct device_node *np) +enum usb_dr_mode usb_get_dr_mode (struct device *dev) {const char *dr_mode;int err, i; - err =of_property_read_string (np,"dr_mode" , &dr_mode); + err =device_property_read_string (dev,"dr_mode" , &dr_mode);if (err <0 )return USB_DR_MODE_UNKNOWN ;
@@ -129,8 +121,9 @@ enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)return USB_DR_MODE_UNKNOWN ; } -EXPORT_SYMBOL_GPL (of_usb_get_dr_mode); +EXPORT_SYMBOL_GPL (usb_get_dr_mode); +#ifdef CONFIG_OF /** * of_usb_host_tpl_support - to get if Targeted Peripheral List is supported * for given targeted hosts (non-PC hosts)
drivers/usb/dwc2/platform.c +1 -1
@@ -220,7 +220,7 @@ static int dwc2_driver_probe(struct platform_device *dev)dev_dbg (&dev->dev,"mapped PA %08lx to VA %p\n" , (unsigned long )res->start, hsotg->regs); - hsotg->dr_mode =of_usb_get_dr_mode (dev->dev.of_node); + hsotg->dr_mode =usb_get_dr_mode (&dev->dev);/* * Attempt to find a generic PHY, then look for an old style
drivers/usb/dwc3/core.c +1 -1
@@ -843,6 +843,7 @@ static int dwc3_probe(struct platform_device *pdev) hird_threshold =12 ; dwc->maximum_speed =usb_get_maximum_speed (dev); + dwc->dr_mode =usb_get_dr_mode (dev);if (node) { dwc->has_lpm_erratum = of_property_read_bool(node,
@@ -858,7 +859,6 @@ static int dwc3_probe(struct platform_device *pdev) dwc->needs_fifo_resize =of_property_read_bool (node,"tx-fifo-resize" ); - dwc->dr_mode =of_usb_get_dr_mode (node); dwc->disable_scramble_quirk =of_property_read_bool (node,"snps,disable_scramble_quirk" );
drivers/usb/dwc3/dwc3-st.c +1 -1
@@ -268,7 +268,7 @@ static int st_dwc3_probe(struct platform_device *pdev) goto undo_softreset; } - dwc3_data->dr_mode =of_usb_get_dr_mode (child_pdev->dev.of_node); + dwc3_data->dr_mode =usb_get_dr_mode (&child_pdev->dev);/* * Configure the USB port as device or host according to the static
drivers/usb/musb/musb_dsps.c +1 -1
@@ -663,7 +663,7 @@ static int get_musb_port_mode(struct device *dev) {enum usb_dr_mode mode; - mode =of_usb_get_dr_mode (dev->of_node); + mode =usb_get_dr_mode (dev);switch (mode) {case USB_DR_MODE_HOST :return MUSB_PORT_MODE_HOST ;
drivers/usb/musb/sunxi.c +1 -1
@@ -617,7 +617,7 @@ static int sunxi_musb_probe(struct platform_device *pdev)return -ENOMEM ;memset (&pdata,0 ,sizeof (pdata)); -switch (of_usb_get_dr_mode (np)) { +switch (usb_get_dr_mode (&pdev->dev)) {#if definedCONFIG_USB_MUSB_DUAL_ROLE || definedCONFIG_USB_MUSB_HOST case USB_DR_MODE_HOST : pdata.mode =MUSB_PORT_MODE_HOST ;
drivers/usb/phy/phy-msm-usb.c +1 -1
@@ -1529,7 +1529,7 @@ static int msm_otg_read_dt(struct platform_device *pdev, struct msm_otg *motg)if (IS_ERR (motg->phy_rst)) motg->phy_rst =NULL ; - pdata->mode =of_usb_get_dr_mode (node); + pdata->mode =usb_get_dr_mode (&pdev->dev);if (pdata->mode ==USB_DR_MODE_UNKNOWN ) pdata->mode =USB_DR_MODE_OTG ;
drivers/usb/phy/phy-tegra-usb.c +1 -1
@@ -1029,7 +1029,7 @@ static int tegra_usb_phy_probe(struct platform_device *pdev) }if (of_find_property (np,"dr_mode" ,NULL )) - tegra_phy->mode =of_usb_get_dr_mode (np); + tegra_phy->mode =usb_get_dr_mode (&pdev->dev);else tegra_phy->mode =USB_DR_MODE_HOST ;
include/linux/usb/of.h +0 -6
@@ -12,16 +12,10 @@#include <linux/usb/phy.h> #if IS_ENABLED (CONFIG_OF ) -enum usb_dr_mode of_usb_get_dr_mode (struct device_node *np);bool of_usb_host_tpl_support (struct device_node *np);int of_usb_update_otg_caps (struct device_node *np,struct usb_otg_caps *otg_caps);#else -static inline enum usb_dr_mode of_usb_get_dr_mode (struct device_node *np) -{ -return USB_DR_MODE_UNKNOWN ; -} -static inline bool of_usb_host_tpl_support (struct device_node *np) {return false;
include/linux/usb/otg.h +9 -0
@@ -119,4 +119,13 @@ enum usb_dr_mode { USB_DR_MODE_OTG, }; +/** +* usb_get_dr_mode - Get dual role mode for given device +* @dev: Pointer to the given device +* +* The function gets phy interface string from property 'dr_mode', +* and returns the correspondig enum usb_dr_mode +*/ +extern enum usb_dr_mode usb_get_dr_mode (struct device *dev); +#endif /* __LINUX_USB_OTG_H */
Signature · 1 line
2.5.0
PATCH 4/5 usb: dwc3: core: convert to unified device property interface
In reply to Heikki KrogerusNo functional affect on existing platforms, but the driver is now ready to extract the properties also from ACPI tables as well as from DT.
--- drivers/usb/dwc3/core.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-)
drivers/usb/dwc3/core.c +22 -23
@@ -773,7 +773,6 @@ static int dwc3_probe(struct platform_device *pdev) {struct device *dev = &pdev->dev;struct dwc3_platform_data *pdata =dev_get_platdata (dev); -struct device_node *node = dev->of_node;struct resource *res;struct dwc3 *dwc;u8 lpm_nyet_threshold;
@@ -845,49 +844,49 @@ static int dwc3_probe(struct platform_device *pdev) dwc->maximum_speed =usb_get_maximum_speed (dev); dwc->dr_mode =usb_get_dr_mode (dev); -if (node) { - dwc->has_lpm_erratum =of_property_read_bool (node, + dwc->has_lpm_erratum =device_property_read_bool (dev,"snps,has-lpm-erratum" ); -of_property_read_u8 (node,"snps,lpm-nyet-threshold" , +device_property_read_u8 (dev,"snps,lpm-nyet-threshold" , &lpm_nyet_threshold); - dwc->is_utmi_l1_suspend =of_property_read_bool (node, + dwc->is_utmi_l1_suspend =device_property_read_bool (dev,"snps,is-utmi-l1-suspend" ); -of_property_read_u8 (node,"snps,hird-threshold" , +device_property_read_u8 (dev,"snps,hird-threshold" , &hird_threshold); - dwc->usb3_lpm_capable =of_property_read_bool (node, + dwc->usb3_lpm_capable =device_property_read_bool (dev,"snps,usb3_lpm_capable" ); - dwc->needs_fifo_resize =of_property_read_bool (node, + dwc->needs_fifo_resize =device_property_read_bool (dev,"tx-fifo-resize" ); - dwc->disable_scramble_quirk =of_property_read_bool (node, + dwc->disable_scramble_quirk =device_property_read_bool (dev,"snps,disable_scramble_quirk" ); - dwc->u2exit_lfps_quirk =of_property_read_bool (node, + dwc->u2exit_lfps_quirk =device_property_read_bool (dev,"snps,u2exit_lfps_quirk" ); - dwc->u2ss_inp3_quirk =of_property_read_bool (node, + dwc->u2ss_inp3_quirk =device_property_read_bool (dev,"snps,u2ss_inp3_quirk" ); - dwc->req_p1p2p3_quirk =of_property_read_bool (node, + dwc->req_p1p2p3_quirk =device_property_read_bool (dev,"snps,req_p1p2p3_quirk" ); - dwc->del_p1p2p3_quirk =of_property_read_bool (node, + dwc->del_p1p2p3_quirk =device_property_read_bool (dev,"snps,del_p1p2p3_quirk" ); - dwc->del_phy_power_chg_quirk =of_property_read_bool (node, + dwc->del_phy_power_chg_quirk =device_property_read_bool (dev,"snps,del_phy_power_chg_quirk" ); - dwc->lfps_filter_quirk =of_property_read_bool (node, + dwc->lfps_filter_quirk =device_property_read_bool (dev,"snps,lfps_filter_quirk" ); - dwc->rx_detect_poll_quirk =of_property_read_bool (node, + dwc->rx_detect_poll_quirk =device_property_read_bool (dev,"snps,rx_detect_poll_quirk" ); - dwc->dis_u3_susphy_quirk =of_property_read_bool (node, + dwc->dis_u3_susphy_quirk =device_property_read_bool (dev,"snps,dis_u3_susphy_quirk" ); - dwc->dis_u2_susphy_quirk =of_property_read_bool (node, + dwc->dis_u2_susphy_quirk =device_property_read_bool (dev,"snps,dis_u2_susphy_quirk" ); - dwc->tx_de_emphasis_quirk =of_property_read_bool (node, + dwc->tx_de_emphasis_quirk =device_property_read_bool (dev,"snps,tx_de_emphasis_quirk" ); -of_property_read_u8 (node,"snps,tx_de_emphasis" , +device_property_read_u8 (dev,"snps,tx_de_emphasis" , &tx_de_emphasis); -of_property_read_string (node,"snps,hsphy_interface" , - &dwc->hsphy_interface); - }else if (pdata) { +device_property_read_string (dev,"snps,hsphy_interface" , + &dwc->hsphy_interface); + +if (pdata) { dwc->maximum_speed = pdata->maximum_speed; dwc->has_lpm_erratum = pdata->has_lpm_erratum;if (pdata->lpm_nyet_threshold)
Signature · 1 line
2.5.0
PATCH 5/5 usb: dwc3: pci: passing forward the ACPI companion
In reply to Heikki KrogerusSharing the ACPI companion with dwc3 core so it has access to the properties defined for DWC3 in ACPI tables.
--- drivers/usb/dwc3/dwc3-pci.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/dwc3/dwc3-pci.c +1 -0
@@ -154,6 +154,7 @@ static int dwc3_pci_probe(struct pci_dev *pci, goto err; dwc3->dev.parent = dev; +ACPI_COMPANION_SET (&dwc3->dev,ACPI_COMPANION (dev)); ret =platform_device_add (dwc3);if (ret) {
Signature · 1 line
2.5.0
Quoted 6 lines · Heikki Krogerus
Hi,
While converting dwc3 to the unified device property interface, I noticed that there is really nothing preventing
of_usb_get_dr_modeandof_usb_get_maximum_speedfrom being converted as well. Hope that's OK.
Place the reference for usb_get_dr_mode and usb_get_maximum_speed at otg.h and ch9.h may not be good, why not add a common.h which is at include/linux/usb/ too.
Quoted 35 lines
The only special case was
dwc3-st.c, where thedr_modeis requested before the platform device has been populated. I changed it so that thedr_modeproperty is requested after the platform device is populated in a separate patch.Heikki Krogerus (5):
usb: common:of_usb_get_maximum_speedtousb_get_maximum_speed
usb: dwc3: st: prepare the driver for genericusb_get_dr_modefunction
usb: common:of_usb_get_dr_modetousb_get_dr_mode
usb: dwc3: core: convert to unified device property interface
usb: dwc3: pci: passing forward the ACPI companiondrivers/usb/chipidea/core.c | 4 +-- drivers/usb/common/common.c | 59 +++++++++++++++-------------------------- drivers/usb/dwc2/platform.c | 2 +- drivers/usb/dwc3/core.c | 50 +++++++++++++++++----------------- drivers/usb/dwc3/dwc3-pci.c | 1 + drivers/usb/dwc3/dwc3-st.c | 12 +++++++-- drivers/usb/musb/musb_dsps.c | 2 +- drivers/usb/musb/sunxi.c | 2 +- drivers/usb/phy/phy-msm-usb.c | 2 +- drivers/usb/phy/phy-tegra-usb.c | 2 +- include/linux/usb/ch9.h | 11 +++++++- include/linux/usb/of.h | 12 --------- include/linux/usb/otg.h | 9 +++++++ 13 files changed, 84 insertions(+), 84 deletions(-)Signature · 6 lines
2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Best Regards, Peter Chen
Hi Peter,
Quoted 11 lines · Peter Chen
Quoted 6 lines · Heikki Krogerus
Hi,
While converting dwc3 to the unified device property interface, I noticed that there is really nothing preventing
of_usb_get_dr_modeandof_usb_get_maximum_speedfrom being converted as well. Hope that's OK.Place the reference for
usb_get_dr_modeandusb_get_maximum_speedatotg.handch9.hmay not be good, why not add acommon.hwhich is atinclude/linux/usb/too.
Why? I'm not going to introduce new header file for prototypes which depend on constants defined in other header files, unless there is a really good reason. Please note that the prototypes for the existing generic functions in common.c are defined in ch9.h and otg.h.
These functions are _generic_ helpers for dealing with definitions in ch9.h and otg.h, so I don't really see any reason for putting their prototypes anywhere else then into those same headers.
Thanks,
Signature · 1 line
heikki
Quoted 11 lines · Heikki Krogerus
Hi Peter,
Quoted 8 lines · Peter Chen
Quoted 6 lines · Heikki Krogerus
Hi,
While converting dwc3 to the unified device property interface, I noticed that there is really nothing preventing
of_usb_get_dr_modeandof_usb_get_maximum_speedfrom being converted as well. Hope that's OK.
Quoted 8 lines
Quoted 3 lines
Place the reference for
usb_get_dr_modeandusb_get_maximum_speedatotg.handch9.hmay not be good, why not add acommon.hwhich is atinclude/linux/usb/too.Why? I'm not going to introduce new header file for prototypes which depend on constants defined in other header files, unless there is a really good reason. Please note that the prototypes for the existing generic functions in
common.care defined inch9.handotg.h.
Ok, I just had considered host controller driver may also call usb_get_maximum_speed to get platform available speed, so I am wonder if it is suitable to place it at ch9.h.
Quoted 10 lines
These functions are _generic_ helpers for dealing with definitions in
ch9.handotg.h, so I don't really see any reason for putting their prototypes anywhere else then into those same headers.Thanks,
Signature · 1 line
heikki
Signature · 2 lines
Best Regards, Peter Chen