Usually usb phy need register one extcon device to get the connection notifications. It will remove some duplicate code if the extcon device is registered using common code instead of each phy driver having its own related extcon APIs. So we add one pointer of extcon device into usb phy structure, and some other helper functions to register extcon.
Suggested-by: NeilBrown neilb@suse.com Signed-off-by: Baolin Wang baolin.wang@linaro.org --- drivers/usb/phy/Kconfig | 17 ++++++++++++++--- drivers/usb/phy/phy.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/phy.h | 6 ++++++ 3 files changed, 64 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig index 61cef75..39fd6e7 100644 --- a/drivers/usb/phy/Kconfig +++ b/drivers/usb/phy/Kconfig @@ -13,6 +13,7 @@ config AB8500_USB tristate "AB8500 USB Transceiver Driver" depends on AB8500_CORE select USB_PHY + select EXTCON help Enable this to support the USB OTG transceiver in AB8500 chip. This transceiver supports high and full speed devices plus, @@ -23,6 +24,7 @@ config FSL_USB2_OTG depends on USB_EHCI_FSL && USB_FSL_USB2 && USB_OTG_FSM && PM depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y' select USB_PHY + select EXTCON help Enable this to support Freescale USB OTG transceiver.
@@ -32,6 +34,7 @@ config ISP1301_OMAP depends on USB depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y' select USB_PHY + select EXTCON help If you say yes here you get support for the Philips ISP1301 USB-On-The-Go transceiver working with the OMAP OTG controller. @@ -55,6 +58,7 @@ config NOP_USB_XCEIV tristate "NOP USB Transceiver Driver" depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, NOP can't be built-in select USB_PHY + select EXTCON help This driver is to be used by all the usb transceiver which are either built-in with usb ip or which are autonomous and doesn't require any @@ -70,6 +74,7 @@ config AM335X_PHY_USB select USB_PHY select AM335X_CONTROL_USB select USB_COMMON + select EXTCON help This driver provides PHY support for that phy which part for the AM335x SoC. @@ -98,6 +103,7 @@ config USB_GPIO_VBUS depends on GPIOLIB || COMPILE_TEST depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y' select USB_PHY + select EXTCON help Provides simple GPIO VBUS sensing for controllers with an internal transceiver via the usb_phy interface, and @@ -116,9 +122,10 @@ config OMAP_OTG
config TAHVO_USB tristate "Tahvo USB transceiver driver" - depends on MFD_RETU && EXTCON + depends on MFD_RETU depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y' select USB_PHY + select EXTCON help Enable this to support USB transceiver on Tahvo. This is used at least on Nokia 770. @@ -135,6 +142,7 @@ config USB_ISP1301 depends on USB || USB_GADGET depends on I2C select USB_PHY + select EXTCON help Say Y here to add support for the NXP ISP1301 USB transceiver driver. This chip is typically used as USB transceiver for USB host, gadget @@ -148,8 +156,8 @@ config USB_MSM_OTG depends on (USB || USB_GADGET) && (ARCH_QCOM || COMPILE_TEST) depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y' depends on RESET_CONTROLLER - depends on EXTCON select USB_PHY + select EXTCON help Enable this to support the USB OTG transceiver on Qualcomm chips. It handles PHY initialization, clock management, and workarounds @@ -162,9 +170,10 @@ config USB_MSM_OTG config USB_QCOM_8X16_PHY tristate "Qualcomm APQ8016/MSM8916 on-chip USB PHY controller support" depends on ARCH_QCOM || COMPILE_TEST - depends on RESET_CONTROLLER && EXTCON + depends on RESET_CONTROLLER select USB_PHY select USB_ULPI_VIEWPORT + select EXTCON help Enable this to support the USB transceiver on Qualcomm 8x16 chipsets. It handles PHY initialization, clock management, power management, @@ -178,6 +187,7 @@ config USB_MV_OTG depends on USB_EHCI_MV && USB_MV_UDC && PM && USB_OTG depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 'y' select USB_PHY + select EXTCON help Say Y here if you want to build Marvell USB OTG transciever driver in kernel (including PXA and MMP series). This driver @@ -190,6 +200,7 @@ config USB_MXS_PHY depends on ARCH_MXC || ARCH_MXS select STMP_DEVICE select USB_PHY + select EXTCON help Enable this to support the Freescale MXS USB PHY.
diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c index 98f75d2..baa8b18 100644 --- a/drivers/usb/phy/phy.c +++ b/drivers/usb/phy/phy.c @@ -100,6 +100,41 @@ static int devm_usb_phy_match(struct device *dev, void *res, void *match_data) return *phy == match_data; }
+static int usb_add_extcon(struct usb_phy *x) +{ + int ret; + + if (of_property_read_bool(x->dev->of_node, "extcon")) { + x->edev = extcon_get_edev_by_phandle(x->dev, 0); + if (IS_ERR(x->edev)) + return PTR_ERR(x->edev); + + if (x->vbus_nb.notifier_call) { + ret = devm_extcon_register_notifier(x->dev, x->edev, + EXTCON_USB, + &x->vbus_nb); + if (ret < 0) { + dev_err(x->dev, + "register VBUS notifier failed\n"); + return ret; + } + } + + if (x->id_nb.notifier_call) { + ret = devm_extcon_register_notifier(x->dev, x->edev, + EXTCON_USB_HOST, + &x->id_nb); + if (ret < 0) { + dev_err(x->dev, + "register ID notifier failed\n"); + return ret; + } + } + } + + return 0; +} + /** * devm_usb_get_phy - find the USB PHY * @dev - device that requests this phy @@ -388,6 +423,10 @@ int usb_add_phy(struct usb_phy *x, enum usb_phy_type type) return -EINVAL; }
+ ret = usb_add_extcon(x); + if (ret) + return ret; + ATOMIC_INIT_NOTIFIER_HEAD(&x->notifier);
spin_lock_irqsave(&phy_lock, flags); @@ -422,12 +461,17 @@ int usb_add_phy_dev(struct usb_phy *x) { struct usb_phy_bind *phy_bind; unsigned long flags; + int ret;
if (!x->dev) { dev_err(x->dev, "no device provided for PHY\n"); return -EINVAL; }
+ ret = usb_add_extcon(x); + if (ret) + return ret; + ATOMIC_INIT_NOTIFIER_HEAD(&x->notifier);
spin_lock_irqsave(&phy_lock, flags); diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h index 31a8068..1b5269e 100644 --- a/include/linux/usb/phy.h +++ b/include/linux/usb/phy.h @@ -9,6 +9,7 @@ #ifndef __LINUX_USB_PHY_H #define __LINUX_USB_PHY_H
+#include <linux/extcon.h> #include <linux/notifier.h> #include <linux/usb.h>
@@ -85,6 +86,11 @@ struct usb_phy { struct usb_phy_io_ops *io_ops; void __iomem *io_priv;
+ /* to support extcon device */ + struct extcon_dev *edev; + struct notifier_block vbus_nb; + struct notifier_block id_nb; + /* for notification of usb_phy_events */ struct atomic_notifier_head notifier;
Since usb phy core has added common code to register or unregister extcon device, then phy-qcom-8x16-usb driver does not need its own code to register/unregister extcon device, then remove them.
Signed-off-by: Baolin Wang baolin.wang@linaro.org --- drivers/usb/phy/phy-qcom-8x16-usb.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-)
diff --git a/drivers/usb/phy/phy-qcom-8x16-usb.c b/drivers/usb/phy/phy-qcom-8x16-usb.c index fdf6863..b6a83a5 100644 --- a/drivers/usb/phy/phy-qcom-8x16-usb.c +++ b/drivers/usb/phy/phy-qcom-8x16-usb.c @@ -69,9 +69,6 @@ struct phy_8x16 {
struct reset_control *phy_reset;
- struct extcon_dev *vbus_edev; - struct notifier_block vbus_notify; - struct gpio_desc *switch_gpio; struct notifier_block reboot_notify; }; @@ -131,7 +128,8 @@ static int phy_8x16_vbus_off(struct phy_8x16 *qphy) static int phy_8x16_vbus_notify(struct notifier_block *nb, unsigned long event, void *ptr) { - struct phy_8x16 *qphy = container_of(nb, struct phy_8x16, vbus_notify); + struct usb_phy *usb_phy = container_of(nb, struct usb_phy, vbus_nb); + struct phy_8x16 *qphy = container_of(usb_phy, struct phy_8x16, phy);
if (event) phy_8x16_vbus_on(qphy); @@ -187,7 +185,7 @@ static int phy_8x16_init(struct usb_phy *phy) val = ULPI_PWR_OTG_COMP_DISABLE; usb_phy_io_write(phy, val, ULPI_SET(ULPI_PWR_CLK_MNG_REG));
- state = extcon_get_state(qphy->vbus_edev, EXTCON_USB); + state = extcon_get_state(qphy->phy.edev, EXTCON_USB); if (state) phy_8x16_vbus_on(qphy); else @@ -289,15 +287,13 @@ static int phy_8x16_probe(struct platform_device *pdev) phy->io_priv = qphy->regs + HSPHY_ULPI_VIEWPORT; phy->io_ops = &ulpi_viewport_access_ops; phy->type = USB_PHY_TYPE_USB2; + phy->vbus_nb.notifier_call = phy_8x16_vbus_notify; + phy->id_nb.notifier_call = NULL;
ret = phy_8x16_read_devicetree(qphy); if (ret < 0) return ret;
- qphy->vbus_edev = extcon_get_edev_by_phandle(phy->dev, 0); - if (IS_ERR(qphy->vbus_edev)) - return PTR_ERR(qphy->vbus_edev); - ret = clk_set_rate(qphy->core_clk, INT_MAX); if (ret < 0) dev_dbg(phy->dev, "Can't boost core clock\n"); @@ -315,12 +311,6 @@ static int phy_8x16_probe(struct platform_device *pdev) if (WARN_ON(ret)) goto off_clks;
- qphy->vbus_notify.notifier_call = phy_8x16_vbus_notify; - ret = devm_extcon_register_notifier(&pdev->dev, qphy->vbus_edev, - EXTCON_USB, &qphy->vbus_notify); - if (ret < 0) - goto off_power; - ret = usb_add_phy_dev(&qphy->phy); if (ret) goto off_power;
Hi Baolin,
[auto build test ERROR on balbi-usb/next] [also build test ERROR on v4.11-rc2 next-20170310] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Baolin-Wang/usb-phy-Introduce-one-e... base: https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next config: i386-randconfig-i1-201712 (attached as .config) compiler: gcc-4.8 (Debian 4.8.4-1) 4.8.4 reproduce: # save the attached .config to linux build tree make ARCH=i386
All errors (new ones prefixed by >>):
drivers/built-in.o: In function `usb_add_extcon':
phy.c:(.text+0x231580): undefined reference to `extcon_get_edev_by_phandle' phy.c:(.text+0x2315d0): undefined reference to `devm_extcon_register_notifier'
phy.c:(.text+0x231629): undefined reference to `devm_extcon_register_notifier'
--- 0-DAY kernel test infrastructure Open Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation
Hi,
On 19 March 2017 at 19:42, kbuild test robot lkp@intel.com wrote:
Hi Baolin,
[auto build test ERROR on balbi-usb/next] [also build test ERROR on v4.11-rc2 next-20170310] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Baolin-Wang/usb-phy-Introduce-one-e... base: https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next config: i386-randconfig-i1-201712 (attached as .config) compiler: gcc-4.8 (Debian 4.8.4-1) 4.8.4 reproduce: # save the attached .config to linux build tree make ARCH=i386
All errors (new ones prefixed by >>):
drivers/built-in.o: In function `usb_add_extcon':
phy.c:(.text+0x231580): undefined reference to `extcon_get_edev_by_phandle' phy.c:(.text+0x2315d0): undefined reference to `devm_extcon_register_notifier'
phy.c:(.text+0x231629): undefined reference to `devm_extcon_register_notifier'
I am not sure how the errors were happened, since we will always select EXTCON if we have selected USB_PHY, moreover we have included the "linux/extcon.h" in phy.h file.
On 03/20, Baolin Wang wrote:
Hi,
On 19 March 2017 at 19:42, kbuild test robot lkp@intel.com wrote:
Hi Baolin,
[auto build test ERROR on balbi-usb/next] [also build test ERROR on v4.11-rc2 next-20170310] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Baolin-Wang/usb-phy-Introduce-one-e... base: https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next config: i386-randconfig-i1-201712 (attached as .config) compiler: gcc-4.8 (Debian 4.8.4-1) 4.8.4 reproduce: # save the attached .config to linux build tree make ARCH=i386
All errors (new ones prefixed by >>):
drivers/built-in.o: In function `usb_add_extcon':
phy.c:(.text+0x231580): undefined reference to `extcon_get_edev_by_phandle' phy.c:(.text+0x2315d0): undefined reference to `devm_extcon_register_notifier'
phy.c:(.text+0x231629): undefined reference to `devm_extcon_register_notifier'
I am not sure how the errors were happened, since we will always select EXTCON if we have selected USB_PHY, moreover we have included
Hmm, this was a random config test and CONFIG_EXTCON was set as 'm', maybe you need to specify the dependency between CONFIG_USB_PHY and CONFIG_EXTCON ?
Thanks, Xiaolong
the "linux/extcon.h" in phy.h file.
-- Baolin.wang Best Regards _______________________________________________ kbuild-all mailing list kbuild-all@lists.01.org https://lists.01.org/mailman/listinfo/kbuild-all
Hi,
On 22 March 2017 at 14:32, Ye Xiaolong xiaolong.ye@intel.com wrote:
On 03/20, Baolin Wang wrote:
Hi,
On 19 March 2017 at 19:42, kbuild test robot lkp@intel.com wrote:
Hi Baolin,
[auto build test ERROR on balbi-usb/next] [also build test ERROR on v4.11-rc2 next-20170310] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Baolin-Wang/usb-phy-Introduce-one-e... base: https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next config: i386-randconfig-i1-201712 (attached as .config) compiler: gcc-4.8 (Debian 4.8.4-1) 4.8.4 reproduce: # save the attached .config to linux build tree make ARCH=i386
All errors (new ones prefixed by >>):
drivers/built-in.o: In function `usb_add_extcon':
phy.c:(.text+0x231580): undefined reference to `extcon_get_edev_by_phandle' phy.c:(.text+0x2315d0): undefined reference to `devm_extcon_register_notifier'
phy.c:(.text+0x231629): undefined reference to `devm_extcon_register_notifier'
I am not sure how the errors were happened, since we will always select EXTCON if we have selected USB_PHY, moreover we have included
Hmm, this was a random config test and CONFIG_EXTCON was set as 'm', maybe you need to specify the dependency between CONFIG_USB_PHY and CONFIG_EXTCON ?
OK, I see. Thanks.
linaro-kernel@lists.linaro.org