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: 9199105 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 77C12607D3 for ; Sun, 26 Jun 2016 05:54:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 689AF28530 for ; Sun, 26 Jun 2016 05:54:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CD6E2852D; Sun, 26 Jun 2016 05:54:57 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 117F228525 for ; Sun, 26 Jun 2016 05:54:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751914AbcFZFym (ORCPT ); Sun, 26 Jun 2016 01:54:42 -0400 Received: from mail-pf0-f182.google.com ([209.85.192.182]:36007 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751905AbcFZFyl (ORCPT ); Sun, 26 Jun 2016 01:54:41 -0400 Received: by mail-pf0-f182.google.com with SMTP id t190so51513559pfb.3 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=g7GfsWtDU1EIaUvUK1sfoRloVyWoOdUxIe45gsvERCSLLmi72Kax9rhp14QcodToYh 8tqXrF3HxMNXpWyXyimE7fHSBmh14trsY/aQd7+5GCoVFycd+Lj2edIGRDYFDdjOMiNn tS/i3Fnz5jg21P4Y1YP9E4Ik7/s0dtV1243MYECgoHZIt4E8ktDVkrseT1LCpIgnCg2x Z00AUZ3pdzQuOZ7ijG8MXuZ7A/qezWhOHWvoIBgHIPygDwxCMSjOz85AE+1RR011xp9b GCHcdHLdOfGJtwIH/+g0y3IdsaKxCs7AKCEANKodtug+Nv3WLu5YuiZWgNmz/Qg4HE4K vszw== X-Gm-Message-State: ALyK8tLdmFjgX+8k0mg4qfdS6BfOIWvKbBYUP3/OJqFrFQMfe1WptAq/auBVA1PfnJCYSS2h 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 Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, Bjorn Andersson , Chanwoo Choi 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 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.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;