From patchwork Tue Oct 18 00:42:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 9380953 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2E0E160487 for ; Tue, 18 Oct 2016 00:45:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AE4228CF5 for ; Tue, 18 Oct 2016 00:45:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E36828CFD; Tue, 18 Oct 2016 00:45:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8C31128CF5 for ; Tue, 18 Oct 2016 00:45:15 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bwIVf-0003Qi-8T; Tue, 18 Oct 2016 00:44:03 +0000 Received: from mail-pf0-x230.google.com ([2607:f8b0:400e:c00::230]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bwIUw-0003GO-GL for linux-arm-kernel@lists.infradead.org; Tue, 18 Oct 2016 00:43:20 +0000 Received: by mail-pf0-x230.google.com with SMTP id 128so85669097pfz.0 for ; Mon, 17 Oct 2016 17:42:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XbVUxAVZUko2x9a0MN/JImf3rn3S3HrjhPQWUSwZaBk=; b=dGOW90LGoMpOaUfBixLG0Mx5AqxJma4CBFbQFzxvk9ag1vay983rtl4ZiqwKUeucBZ rS8LwiV5Uue4vc67kSQKl7j6wWk4c9wlmg8xoj52Xc0qPne+kppVKa8gAPmPynX8GNM0 X6Sh869aBg9rEvScKDSTAddzaVCONGrVPrlCE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XbVUxAVZUko2x9a0MN/JImf3rn3S3HrjhPQWUSwZaBk=; b=Ks5Nhx4lLl50biRIB9XcJFLYmet4kGIqrWO3IvpQ32qaRABZ6U4bi4AjI673IhAXcs x/5z1OIXSTILNZAfEIb01ji1K6jVdHTsUoUmuYTPBXPED9DADx7VTCnhwJVnGwjleBBH 1adJWOcbp57Hw5ga6GyCWrvimdQJy9kedb88+x/0wduJPrcxOtsH6dzv1ihjVcQ3xOLZ iWSspnoeRu7O6neah1wCOm1lpCDVgeghLxN/VbhqGIxV6yvOrJPL0idtUve3r8+sGigs 2DtLN+fA9B3ifmp1GaH4gIf42hssxtv/qzxyRPjbFxAPa6ahfhUrQLlPbvMyvumu1c29 q9Rw== X-Gm-Message-State: AA6/9RlD8P2jmIw7NE14CQulssNolpWHwn68zAzSGoGOzstOJ1oMauw3OWRipbUJpF9yIp/4 X-Received: by 10.98.220.141 with SMTP id c13mr324507pfl.63.1476751376708; Mon, 17 Oct 2016 17:42:56 -0700 (PDT) Received: from localhost.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id j63sm50692446pfj.70.2016.10.17.17.42.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Oct 2016 17:42:55 -0700 (PDT) From: Stephen Boyd To: Sebastian Reichel Subject: [PATCH v5 2/2] power: qcom_smbb: Add otg regulator for control of vbus Date: Mon, 17 Oct 2016 17:42:51 -0700 Message-Id: <20161018004251.28733-3-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.10.0.297.gf6727b0 In-Reply-To: <20161018004251.28733-1-stephen.boyd@linaro.org> References: <20161018004251.28733-1-stephen.boyd@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161017_174318_636464_D374AA8A X-CRM114-Status: GOOD ( 16.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, Tim Bird , linux-kernel@vger.kernel.org, Bjorn Andersson , Mark Brown , Andy Gross , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: "Bird, Tim" Add a regulator to control the OTG chargepath switch. This is used by USB code to control VBUS direction - out for host mode on the OTG port, and in for charging mode. Signed-off-by: Tim Bird Acked-by: Bjorn Andersson Reviewed-by: Andy Gross [stephen.boyd@linaro.org: Fix supply name, constify ops, drop machine.h and of_regulator.h includes] Signed-off-by: Stephen Boyd --- drivers/power/supply/qcom_smbb.c | 70 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/drivers/power/supply/qcom_smbb.c b/drivers/power/supply/qcom_smbb.c index b5896ba2a602..5bdde6108c12 100644 --- a/drivers/power/supply/qcom_smbb.c +++ b/drivers/power/supply/qcom_smbb.c @@ -35,6 +35,7 @@ #include #include #include +#include #define SMBB_CHG_VMAX 0x040 #define SMBB_CHG_VSAFE 0x041 @@ -72,6 +73,8 @@ #define BTC_CTRL_HOT_EXT_N BIT(0) #define SMBB_USB_IMAX 0x344 +#define SMBB_USB_OTG_CTL 0x348 +#define OTG_CTL_EN BIT(0) #define SMBB_USB_ENUM_TIMER_STOP 0x34e #define ENUM_TIMER_STOP BIT(0) #define SMBB_USB_SEC_ACCESS 0x3d0 @@ -125,6 +128,9 @@ struct smbb_charger { struct power_supply *dc_psy; struct power_supply *bat_psy; struct regmap *regmap; + + struct regulator_desc otg_rdesc; + struct regulator_dev *otg_reg; }; static const unsigned int smbb_usb_extcon_cable[] = { @@ -787,12 +793,56 @@ static const struct power_supply_desc dc_psy_desc = { .property_is_writeable = smbb_charger_writable_property, }; +static int smbb_chg_otg_enable(struct regulator_dev *rdev) +{ + struct smbb_charger *chg = rdev_get_drvdata(rdev); + int rc; + + rc = regmap_update_bits(chg->regmap, chg->addr + SMBB_USB_OTG_CTL, + OTG_CTL_EN, OTG_CTL_EN); + if (rc) + dev_err(chg->dev, "failed to update OTG_CTL\n"); + return rc; +} + +static int smbb_chg_otg_disable(struct regulator_dev *rdev) +{ + struct smbb_charger *chg = rdev_get_drvdata(rdev); + int rc; + + rc = regmap_update_bits(chg->regmap, chg->addr + SMBB_USB_OTG_CTL, + OTG_CTL_EN, 0); + if (rc) + dev_err(chg->dev, "failed to update OTG_CTL\n"); + return rc; +} + +static int smbb_chg_otg_is_enabled(struct regulator_dev *rdev) +{ + struct smbb_charger *chg = rdev_get_drvdata(rdev); + unsigned int value = 0; + int rc; + + rc = regmap_read(chg->regmap, chg->addr + SMBB_USB_OTG_CTL, &value); + if (rc) + dev_err(chg->dev, "failed to read OTG_CTL\n"); + + return !!(value & OTG_CTL_EN); +} + +static const struct regulator_ops smbb_chg_otg_ops = { + .enable = smbb_chg_otg_enable, + .disable = smbb_chg_otg_disable, + .is_enabled = smbb_chg_otg_is_enabled, +}; + static int smbb_charger_probe(struct platform_device *pdev) { struct power_supply_config bat_cfg = {}; struct power_supply_config usb_cfg = {}; struct power_supply_config dc_cfg = {}; struct smbb_charger *chg; + struct regulator_config config = { }; int rc, i; chg = devm_kzalloc(&pdev->dev, sizeof(*chg), GFP_KERNEL); @@ -905,6 +955,26 @@ static int smbb_charger_probe(struct platform_device *pdev) } } + /* + * otg regulator is used to control VBUS voltage direction + * when USB switches between host and gadget mode + */ + chg->otg_rdesc.id = -1; + chg->otg_rdesc.name = "otg-vbus"; + chg->otg_rdesc.ops = &smbb_chg_otg_ops; + chg->otg_rdesc.owner = THIS_MODULE; + chg->otg_rdesc.type = REGULATOR_VOLTAGE; + chg->otg_rdesc.supply_name = "usb-otg-in"; + chg->otg_rdesc.of_match = "otg-vbus"; + + config.dev = &pdev->dev; + config.driver_data = chg; + + chg->otg_reg = devm_regulator_register(&pdev->dev, &chg->otg_rdesc, + &config); + if (IS_ERR(chg->otg_reg)) + return PTR_ERR(chg->otg_reg); + chg->jeita_ext_temp = of_property_read_bool(pdev->dev.of_node, "qcom,jeita-extended-temp-range");