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: 70854 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp529844qgy; Sat, 25 Jun 2016 22:54:44 -0700 (PDT) X-Received: by 10.66.12.102 with SMTP id x6mr22442518pab.151.1466920484657; Sat, 25 Jun 2016 22:54:44 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3si17767041pfw.92.2016.06.25.22.54.44; Sat, 25 Jun 2016 22:54:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752074AbcFZFym (ORCPT + 30 others); Sun, 26 Jun 2016 01:54:42 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:33749 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751807AbcFZFyk (ORCPT ); Sun, 26 Jun 2016 01:54:40 -0400 Received: by mail-pf0-f177.google.com with SMTP id i123so51525777pfg.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=DjAe3GHuqeoFtOF4vxU550M1JAK3KceferFlTTE+KG+fQDytab/3yLJ3j4oxOs4gpr fR404soWGMo/Xel3HOj74Gt9ZFMVTzTyS2gMc9J6GvOO1uVhXZsHmpXi6EwlYlx0y9Sj miGLPr0XnJMIaVDE0FocbS8toked2ObGV6aaGRiUsYjSzNqj7DYz+XhRaiJ8bgwrdPl2 NgSsiSvoLiopkISRsJbye+WpBm7p2JnNyvmnWw3hiajvmw3C+mtOW6PoihCT2SLP4VDe dhZ8q/WmGJIRYOb7cg5dPuXdEnA6EH+ki9ZQ4QDa/hC78fsvxmqRnS+MeZHvmh7UR/9M 4idA== X-Gm-Message-State: ALyK8tKWOWY742xlOQ9sKs9DonHE9BIxYPwDt7GrhL4gq7uRFF012NXarxABFeREDXGdcwyj 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/power/qcom_smbb.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) -- 2.9.0.rc2.8.ga28705d 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;