From patchwork Sun Jun 26 05:54:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 9199107 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 F0D2A60754 for ; Sun, 26 Jun 2016 05:56:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA6F0284CB for ; Sun, 26 Jun 2016 05:56:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCCB72852D; Sun, 26 Jun 2016 05:56:24 +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 7CB62284CB for ; Sun, 26 Jun 2016 05:56:24 +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 1bH32A-0001ma-D3; Sun, 26 Jun 2016 05:55:06 +0000 Received: from mail-pf0-x229.google.com ([2607:f8b0:400e:c00::229]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bH325-0001Ec-Ch for linux-arm-kernel@lists.infradead.org; Sun, 26 Jun 2016 05:55:02 +0000 Received: by mail-pf0-x229.google.com with SMTP id i123so51525778pfg.0 for ; Sat, 25 Jun 2016 22:54:40 -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; bh=bEOChV6e0MPcg7oKjp8WaPifag+cOxB1zBIfkmYXaCg=; b=HphRLjdaCBemA7B0+D92Jb9VHC96XUchDvFDOr+mCF1AfiTVUuZ5Fd2VKpyWuN+K21 v+DzuX5Q8fbWAebV7/+XXxZJFgmsMItb7Nbxrsmz4EKBtwRgJWhLg7sxA2boypB5y9gS jo9QJ9UR4RVxQ9tHNzw2QroWP36u78X3XFsv0= 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; bh=bEOChV6e0MPcg7oKjp8WaPifag+cOxB1zBIfkmYXaCg=; b=ltH8Fw305LHP2BK4g1YSXInWdxjjDgNT1ALtqGHFM62ZAKDPPMvIWVGyLgtGtmn+k9 UZLcqjVZNb9i9pWe7K0qI40JoliWXo39eGwIYgpmC//rPH5MBAq9JnY4FB6OpxHwhBFV QI+aa9fhnOOuAtkNfcCiZr5sfq4Zlb7oxssjeEFVlshbBkt53PN70Xy/S7NVLA1w+WED gPy/LgW4CdK4RmF29n2UOU36L2MNhbGlUOSfeML2FDkHEYEOauTAgeyUNWb6UbllCMXG z8PRV2slfVDCsXY14+BYhjuA5Euhb/WkU3tNpVXRHp9KSf0HY/7hdsjY4WOC17+LUW4A xsDA== X-Gm-Message-State: ALyK8tJCV1ce8WGRMZusRHeCIq/F7mdR1hMAmKzt3zwuS2QyVLLNi4mpU+adI/kuhmwdqcNa X-Received: by 10.98.152.210 with SMTP id d79mr21735194pfk.2.1466920480292; Sat, 25 Jun 2016 22:54:40 -0700 (PDT) Received: from localhost.localdomain (ip68-101-172-78.sd.sd.cox.net. [68.101.172.78]) by smtp.gmail.com with ESMTPSA id b185sm3231872pfb.55.2016.06.25.22.54.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 25 Jun 2016 22:54:39 -0700 (PDT) From: Stephen Boyd To: Sebastian Reichel , Dmitry Eremin-Solenikov , David Woodhouse Subject: [PATCH] power: qcom_smbb: Make an extcon for usb cable detection Date: Sat, 25 Jun 2016 22:54:37 -0700 Message-Id: <20160626055437.18516-1-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.9.0.rc2.8.ga28705d X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160625_225501_468543_7CDAC2B7 X-CRM114-Status: GOOD ( 14.20 ) 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, linux-kernel@vger.kernel.org, Bjorn Andersson , Chanwoo Choi , 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 On these PMICs the usb cable connection/disconnection is indicated by the usb-valid interrupt being high or low respectively. Let's make an extcon for that, so we can notify usb drivers of the cable state. Cc: Bjorn Andersson Cc: Chanwoo Choi Signed-off-by: Stephen Boyd Reviewed-by: Chanwoo Choi --- drivers/power/qcom_smbb.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/power/qcom_smbb.c b/drivers/power/qcom_smbb.c index 5eb1e9e543e2..b5896ba2a602 100644 --- a/drivers/power/qcom_smbb.c +++ b/drivers/power/qcom_smbb.c @@ -34,6 +34,7 @@ #include #include #include +#include #define SMBB_CHG_VMAX 0x040 #define SMBB_CHG_VSAFE 0x041 @@ -111,6 +112,7 @@ struct smbb_charger { unsigned int revision; unsigned int addr; struct device *dev; + struct extcon_dev *edev; bool dc_disabled; bool jeita_ext_temp; @@ -125,6 +127,11 @@ struct smbb_charger { struct regmap *regmap; }; +static const unsigned int smbb_usb_extcon_cable[] = { + EXTCON_USB, + EXTCON_NONE, +}; + static int smbb_vbat_weak_fn(unsigned int index) { return 2100000 + index * 100000; @@ -371,6 +378,8 @@ static irqreturn_t smbb_usb_valid_handler(int irq, void *_data) struct smbb_charger *chg = _data; smbb_set_line_flag(chg, irq, STATUS_USBIN_VALID); + extcon_set_cable_state_(chg->edev, EXTCON_USB, + chg->status & STATUS_USBIN_VALID); power_supply_changed(chg->usb_psy); return IRQ_HANDLED; @@ -849,6 +858,18 @@ static int smbb_charger_probe(struct platform_device *pdev) return PTR_ERR(chg->usb_psy); } + chg->edev = devm_extcon_dev_allocate(&pdev->dev, smbb_usb_extcon_cable); + if (IS_ERR(chg->edev)) { + dev_err(&pdev->dev, "failed to allocate extcon device\n"); + return -ENOMEM; + } + + rc = devm_extcon_dev_register(&pdev->dev, chg->edev); + if (rc < 0) { + dev_err(&pdev->dev, "failed to register extcon device\n"); + return rc; + } + if (!chg->dc_disabled) { dc_cfg.drv_data = chg; dc_cfg.supplied_to = smbb_bif;