From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAF76C43381 for ; Thu, 21 Mar 2019 08:49:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8954F218D4 for ; Thu, 21 Mar 2019 08:49:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553158194; bh=FdY1WoNZvD6ojpCAHyKXepOiKekSlKyKBTq5vKu54ME=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=FMzn7hqRV+H7ntrzOwH5aNxy2TxI6R+M9cqgiEc1J4lCoHerFko7DSenQi80mvj87 I8IxClF//hQxP2RuPlseI05R7w+il9ZFWvjoFWPW4aYSE2wUIUa4LB8OScBq08oeEZ JhEm7sWIL0+JTOMxw8wnlKwAkGbMhTy0RUp1FXzw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728225AbfCUItx (ORCPT ); Thu, 21 Mar 2019 04:49:53 -0400 Received: from mirror2.csie.ntu.edu.tw ([140.112.30.76]:41432 "EHLO wens.csie.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727922AbfCUItE (ORCPT ); Thu, 21 Mar 2019 04:49:04 -0400 Received: by wens.csie.org (Postfix, from userid 1000) id 4049C5FDC4; Thu, 21 Mar 2019 16:48:59 +0800 (CST) From: Chen-Yu Tsai To: Maxime Ripard , Lee Jones , Sebastian Reichel Cc: Chen-Yu Tsai , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Hans de Goede Subject: [PATCH v3 4/9] power: supply: axp20x_usb_power: use polling to detect vbus status change Date: Thu, 21 Mar 2019 16:48:45 +0800 Message-Id: <20190321084850.20769-5-wens@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190321084850.20769-1-wens@kernel.org> References: <20190321084850.20769-1-wens@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chen-Yu Tsai On AXP221 and later AXP PMICs that have the N_VBUSEN pin, when this pin is high, either due to the PMIC driving it high or as an input, the VBUS detection related interrupt mechanisms are disabled. Previously this was worked around in the phy-sun4i-usb driver, which needed to sense VBUS changes and report them to the musb driver in a timely matter. However this workaround was only for the A31 and A33 type USB PHYs. To support newer platforms we would have to enable it for almost all the post-A31 SoCs. However, since this is actually the result of the PMIC's behavior, the workaround would be better if done in the PMIC driver, in this case the VBUS power supply driver. Add the same workqueue-based polling to the VBUS power supply driver. The polling interval is chosen to be the debounce interval from the USB PHY driver, as this short interval is needed in some cases, but the power supply driver would not know when. Signed-off-by: Chen-Yu Tsai --- drivers/power/supply/axp20x_usb_power.c | 53 +++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index e2f353906bb1..ac061bcdc056 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -24,6 +24,7 @@ #include #include #include +#include #define DRVNAME "axp20x-usb-power-supply" @@ -46,6 +47,12 @@ #define AXP20X_VBUS_MON_VBUS_VALID BIT(3) +/* + * Note do not raise the debounce time, we must report Vusb high within + * 100ms otherwise we get Vbus errors in musb. + */ +#define DEBOUNCE_TIME msecs_to_jiffies(50) + struct axp20x_usb_power { struct device_node *np; struct regmap *regmap; @@ -53,6 +60,8 @@ struct axp20x_usb_power { enum axp20x_variants axp20x_id; struct iio_channel *vbus_v; struct iio_channel *vbus_i; + struct delayed_work vbus_detect; + unsigned int old_status; }; static irqreturn_t axp20x_usb_power_irq(int irq, void *devid) @@ -64,6 +73,35 @@ static irqreturn_t axp20x_usb_power_irq(int irq, void *devid) return IRQ_HANDLED; } +static void axp20x_usb_power_poll_vbus(struct work_struct *work) +{ + struct axp20x_usb_power *power = + container_of(work, struct axp20x_usb_power, vbus_detect.work); + unsigned int val; + int ret; + + ret = regmap_read(power->regmap, AXP20X_PWR_INPUT_STATUS, &val); + if (ret) + goto out; + + val &= (AXP20X_PWR_STATUS_VBUS_PRESENT | AXP20X_PWR_STATUS_VBUS_USED); + if (val != power->old_status) + power_supply_changed(power->supply); + + power->old_status = val; + +out: + mod_delayed_work(system_wq, &power->vbus_detect, DEBOUNCE_TIME); +} + +static bool axp20x_usb_vbus_needs_polling(struct axp20x_usb_power *power) +{ + if (power->axp20x_id >= AXP221_ID) + return true; + + return false; +} + static int axp20x_usb_power_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { @@ -362,6 +400,7 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) if (!power) return -ENOMEM; + platform_set_drvdata(pdev, power); power->axp20x_id = (enum axp20x_variants)of_device_get_match_data( &pdev->dev); @@ -420,6 +459,19 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) irq_names[i], ret); } + INIT_DELAYED_WORK(&power->vbus_detect, axp20x_usb_power_poll_vbus); + if (axp20x_usb_vbus_needs_polling(power)) + queue_delayed_work(system_wq, &power->vbus_detect, 0); + + return 0; +} + +static int axp20x_usb_power_remove(struct platform_device *pdev) +{ + struct axp20x_usb_power *power = platform_get_drvdata(pdev); + + cancel_delayed_work_sync(&power->vbus_detect); + return 0; } @@ -439,6 +491,7 @@ MODULE_DEVICE_TABLE(of, axp20x_usb_power_match); static struct platform_driver axp20x_usb_power_driver = { .probe = axp20x_usb_power_probe, + .remove = axp20x_usb_power_remove, .driver = { .name = DRVNAME, .of_match_table = axp20x_usb_power_match, -- 2.20.1 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Chen-Yu Tsai Subject: [PATCH v3 4/9] power: supply: axp20x_usb_power: use polling to detect vbus status change Date: Thu, 21 Mar 2019 16:48:45 +0800 Message-ID: <20190321084850.20769-5-wens@kernel.org> References: <20190321084850.20769-1-wens@kernel.org> Reply-To: wens-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Return-path: Sender: linux-sunxi-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org In-Reply-To: <20190321084850.20769-1-wens-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , To: Maxime Ripard , Lee Jones , Sebastian Reichel Cc: Chen-Yu Tsai , devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, linux-pm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-sunxi-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org, Hans de Goede List-Id: devicetree@vger.kernel.org From: Chen-Yu Tsai On AXP221 and later AXP PMICs that have the N_VBUSEN pin, when this pin is high, either due to the PMIC driving it high or as an input, the VBUS detection related interrupt mechanisms are disabled. Previously this was worked around in the phy-sun4i-usb driver, which needed to sense VBUS changes and report them to the musb driver in a timely matter. However this workaround was only for the A31 and A33 type USB PHYs. To support newer platforms we would have to enable it for almost all the post-A31 SoCs. However, since this is actually the result of the PMIC's behavior, the workaround would be better if done in the PMIC driver, in this case the VBUS power supply driver. Add the same workqueue-based polling to the VBUS power supply driver. The polling interval is chosen to be the debounce interval from the USB PHY driver, as this short interval is needed in some cases, but the power supply driver would not know when. Signed-off-by: Chen-Yu Tsai --- drivers/power/supply/axp20x_usb_power.c | 53 +++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index e2f353906bb1..ac061bcdc056 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -24,6 +24,7 @@ #include #include #include +#include #define DRVNAME "axp20x-usb-power-supply" @@ -46,6 +47,12 @@ #define AXP20X_VBUS_MON_VBUS_VALID BIT(3) +/* + * Note do not raise the debounce time, we must report Vusb high within + * 100ms otherwise we get Vbus errors in musb. + */ +#define DEBOUNCE_TIME msecs_to_jiffies(50) + struct axp20x_usb_power { struct device_node *np; struct regmap *regmap; @@ -53,6 +60,8 @@ struct axp20x_usb_power { enum axp20x_variants axp20x_id; struct iio_channel *vbus_v; struct iio_channel *vbus_i; + struct delayed_work vbus_detect; + unsigned int old_status; }; static irqreturn_t axp20x_usb_power_irq(int irq, void *devid) @@ -64,6 +73,35 @@ static irqreturn_t axp20x_usb_power_irq(int irq, void *devid) return IRQ_HANDLED; } +static void axp20x_usb_power_poll_vbus(struct work_struct *work) +{ + struct axp20x_usb_power *power = + container_of(work, struct axp20x_usb_power, vbus_detect.work); + unsigned int val; + int ret; + + ret = regmap_read(power->regmap, AXP20X_PWR_INPUT_STATUS, &val); + if (ret) + goto out; + + val &= (AXP20X_PWR_STATUS_VBUS_PRESENT | AXP20X_PWR_STATUS_VBUS_USED); + if (val != power->old_status) + power_supply_changed(power->supply); + + power->old_status = val; + +out: + mod_delayed_work(system_wq, &power->vbus_detect, DEBOUNCE_TIME); +} + +static bool axp20x_usb_vbus_needs_polling(struct axp20x_usb_power *power) +{ + if (power->axp20x_id >= AXP221_ID) + return true; + + return false; +} + static int axp20x_usb_power_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { @@ -362,6 +400,7 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) if (!power) return -ENOMEM; + platform_set_drvdata(pdev, power); power->axp20x_id = (enum axp20x_variants)of_device_get_match_data( &pdev->dev); @@ -420,6 +459,19 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) irq_names[i], ret); } + INIT_DELAYED_WORK(&power->vbus_detect, axp20x_usb_power_poll_vbus); + if (axp20x_usb_vbus_needs_polling(power)) + queue_delayed_work(system_wq, &power->vbus_detect, 0); + + return 0; +} + +static int axp20x_usb_power_remove(struct platform_device *pdev) +{ + struct axp20x_usb_power *power = platform_get_drvdata(pdev); + + cancel_delayed_work_sync(&power->vbus_detect); + return 0; } @@ -439,6 +491,7 @@ MODULE_DEVICE_TABLE(of, axp20x_usb_power_match); static struct platform_driver axp20x_usb_power_driver = { .probe = axp20x_usb_power_probe, + .remove = axp20x_usb_power_remove, .driver = { .name = DRVNAME, .of_match_table = axp20x_usb_power_match, -- 2.20.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C08CEC43381 for ; Thu, 21 Mar 2019 08:50:06 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 618C82075E for ; Thu, 21 Mar 2019 08:50:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="C2ELqz3T" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 618C82075E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=J7uF1C5tRYT4lMWLYj386IOHe6gbfPHLn2NsF9xsy6E=; b=C2ELqz3T5JAacM Iex5UcSGLLhUIiygwTvMhAKmNAiT0WrHhPu/e84lIYukfiU5mTNw6cwtLHOvBo1LP2DcRwxta8e5D 3sU1zKRQ3Iy1mL2CQHQ+fZZ6Bwu4Rcd+62FnrteHhjsjHNynvmZPaFL3HvxguoM6Ql/FrmajKis7r tqBjQ41N7u3fZqwsa5mG44CeY2jvdMD8meGPR0HdjNcpPkrvVZ5k4C7/ZBBDVkfyf3L9Hc1G8rfT3 fH1oqUhvks0nCCMOXerFDR4uXjq1TK2UOSpJZHUTBrAIpOHmHG+b/nLq+RBRTOmDYvFbFrQdTGeEI XvSAar6iYRr+BjPW0Xug==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h6tOi-0004fB-5y; Thu, 21 Mar 2019 08:50:00 +0000 Received: from mirror2.csie.ntu.edu.tw ([140.112.30.76] helo=wens.csie.org) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h6tNs-0003dK-CL for linux-arm-kernel@lists.infradead.org; Thu, 21 Mar 2019 08:49:11 +0000 Received: by wens.csie.org (Postfix, from userid 1000) id 4049C5FDC4; Thu, 21 Mar 2019 16:48:59 +0800 (CST) From: Chen-Yu Tsai To: Maxime Ripard , Lee Jones , Sebastian Reichel Subject: [PATCH v3 4/9] power: supply: axp20x_usb_power: use polling to detect vbus status change Date: Thu, 21 Mar 2019 16:48:45 +0800 Message-Id: <20190321084850.20769-5-wens@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190321084850.20769-1-wens@kernel.org> References: <20190321084850.20769-1-wens@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190321_014908_677335_ABFBB884 X-CRM114-Status: GOOD ( 14.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-pm@vger.kernel.org, linux-sunxi@googlegroups.com, linux-kernel@vger.kernel.org, Hans de Goede , Chen-Yu Tsai , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Chen-Yu Tsai On AXP221 and later AXP PMICs that have the N_VBUSEN pin, when this pin is high, either due to the PMIC driving it high or as an input, the VBUS detection related interrupt mechanisms are disabled. Previously this was worked around in the phy-sun4i-usb driver, which needed to sense VBUS changes and report them to the musb driver in a timely matter. However this workaround was only for the A31 and A33 type USB PHYs. To support newer platforms we would have to enable it for almost all the post-A31 SoCs. However, since this is actually the result of the PMIC's behavior, the workaround would be better if done in the PMIC driver, in this case the VBUS power supply driver. Add the same workqueue-based polling to the VBUS power supply driver. The polling interval is chosen to be the debounce interval from the USB PHY driver, as this short interval is needed in some cases, but the power supply driver would not know when. Signed-off-by: Chen-Yu Tsai --- drivers/power/supply/axp20x_usb_power.c | 53 +++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index e2f353906bb1..ac061bcdc056 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -24,6 +24,7 @@ #include #include #include +#include #define DRVNAME "axp20x-usb-power-supply" @@ -46,6 +47,12 @@ #define AXP20X_VBUS_MON_VBUS_VALID BIT(3) +/* + * Note do not raise the debounce time, we must report Vusb high within + * 100ms otherwise we get Vbus errors in musb. + */ +#define DEBOUNCE_TIME msecs_to_jiffies(50) + struct axp20x_usb_power { struct device_node *np; struct regmap *regmap; @@ -53,6 +60,8 @@ struct axp20x_usb_power { enum axp20x_variants axp20x_id; struct iio_channel *vbus_v; struct iio_channel *vbus_i; + struct delayed_work vbus_detect; + unsigned int old_status; }; static irqreturn_t axp20x_usb_power_irq(int irq, void *devid) @@ -64,6 +73,35 @@ static irqreturn_t axp20x_usb_power_irq(int irq, void *devid) return IRQ_HANDLED; } +static void axp20x_usb_power_poll_vbus(struct work_struct *work) +{ + struct axp20x_usb_power *power = + container_of(work, struct axp20x_usb_power, vbus_detect.work); + unsigned int val; + int ret; + + ret = regmap_read(power->regmap, AXP20X_PWR_INPUT_STATUS, &val); + if (ret) + goto out; + + val &= (AXP20X_PWR_STATUS_VBUS_PRESENT | AXP20X_PWR_STATUS_VBUS_USED); + if (val != power->old_status) + power_supply_changed(power->supply); + + power->old_status = val; + +out: + mod_delayed_work(system_wq, &power->vbus_detect, DEBOUNCE_TIME); +} + +static bool axp20x_usb_vbus_needs_polling(struct axp20x_usb_power *power) +{ + if (power->axp20x_id >= AXP221_ID) + return true; + + return false; +} + static int axp20x_usb_power_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { @@ -362,6 +400,7 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) if (!power) return -ENOMEM; + platform_set_drvdata(pdev, power); power->axp20x_id = (enum axp20x_variants)of_device_get_match_data( &pdev->dev); @@ -420,6 +459,19 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) irq_names[i], ret); } + INIT_DELAYED_WORK(&power->vbus_detect, axp20x_usb_power_poll_vbus); + if (axp20x_usb_vbus_needs_polling(power)) + queue_delayed_work(system_wq, &power->vbus_detect, 0); + + return 0; +} + +static int axp20x_usb_power_remove(struct platform_device *pdev) +{ + struct axp20x_usb_power *power = platform_get_drvdata(pdev); + + cancel_delayed_work_sync(&power->vbus_detect); + return 0; } @@ -439,6 +491,7 @@ MODULE_DEVICE_TABLE(of, axp20x_usb_power_match); static struct platform_driver axp20x_usb_power_driver = { .probe = axp20x_usb_power_probe, + .remove = axp20x_usb_power_remove, .driver = { .name = DRVNAME, .of_match_table = axp20x_usb_power_match, -- 2.20.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel