From patchwork Tue Apr 11 11:59:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Breck X-Patchwork-Id: 9675011 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 019CB60382 for ; Tue, 11 Apr 2017 12:00:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F22292711E for ; Tue, 11 Apr 2017 12:00:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E71CA2855D; Tue, 11 Apr 2017 12:00:04 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham 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 4CF9F28516 for ; Tue, 11 Apr 2017 12:00:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752663AbdDKMAD (ORCPT ); Tue, 11 Apr 2017 08:00:03 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:32966 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752134AbdDKMAC (ORCPT ); Tue, 11 Apr 2017 08:00:02 -0400 Received: by mail-pg0-f66.google.com with SMTP id 79so29625887pgf.0 for ; Tue, 11 Apr 2017 05:00:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=urq4XZgqrjKcK2oyKlwTN7UzNnzxm3TksfPPhEq4hK8=; b=NWYJ07zxe96ULT9S40ZSCLh7uh8YGQgKrbgEihe/qMU+ZDY6KiEUkpzpShfsMlZwOx P7/k1eNp/C61ov9V/6Gz5WXPP82mi3wLb6SKZLtQ49XkD1jCzExC+za82u6gNNIN42MI yZ4lGse/FSA+TXBGxiO38DKfIYRWmviWmpuAaFiNH0/ytrxO41XfCjKpMExN/5vfGd2n 0xTn+6/Ruw/zDyh6tEjB8EecmjAt1FtIvakTcnmn6Vh75qMk8VR+bL3Gms3Doxpx73Io Es+sr5DoJ7RIA4mjhHzi1MNuf96R81Qd4z9loFHZiG3cSnys4Ue8PTxJpiZ+hHNx/Hsc ARRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=urq4XZgqrjKcK2oyKlwTN7UzNnzxm3TksfPPhEq4hK8=; b=DcL9nBLaQZ2yMROej92ywFZtdoHaaUpxJYMkWZZ6GMtXkiFX8LQR7C6q102qVZOuM0 eGWPnVXcocnUqyweJTt7i7hr4xFqQqprHR47YCRhvqK8apeviiwTvyPTFTFkPy1ekwH5 UF/MrVF7cPa5UAVYu5Jf/wCmt39Xa/axg4LYCLk7dPZM0WHtHeN3fyi6JT2r28QMgEHO Nt9Yz3VCdZtWlrzVPFGKEhYt+G4Wdbw1ZdszsHCdaAi2l/xs8lRQhZWNbphhRAySyoE6 SEAhA3pYE6QXlHoVvHzwxFhR0gdEB48RSEpPwAZRSee+V8pR6ia2u2jytumwes5cO7VF fXNg== X-Gm-Message-State: AN3rC/6xle7Q3db84V+0u+WjK/BTtpXHgrgKLOf2u8xPhMaRMffkayc2omBqAaePf4C49A== X-Received: by 10.84.196.129 with SMTP id l1mr25245890pld.21.1491912002081; Tue, 11 Apr 2017 05:00:02 -0700 (PDT) Received: from localhost.localdomain (c-73-223-93-234.hsd1.ca.comcast.net. [73.223.93.234]) by smtp.gmail.com with ESMTPSA id d3sm30444736pgc.37.2017.04.11.05.00.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Apr 2017 05:00:01 -0700 (PDT) From: Liam Breck To: Sebastian Reichel , linux-pm@vger.kernel.org Cc: Tony Lindgren , Hans de Goede , Liam Breck Subject: [PATCH v5 2/4] power: bq24190_charger: Clean up extcon code Date: Tue, 11 Apr 2017 04:59:55 -0700 Message-Id: <20170411115957.14253-3-liam@networkimprov.net> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170411115957.14253-1-liam@networkimprov.net> References: <20170411115957.14253-1-liam@networkimprov.net> 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 From: Liam Breck Polishing and fixes for initial extcon patch. Fixes: 4db249b6f3b4 ("power: supply: bq24190_charger: Use extcon to determine ilimit, 5v boost") Cc: Tony Lindgren Cc: Hans de Goede Signed-off-by: Liam Breck --- drivers/power/supply/bq24190_charger.c | 84 +++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c index 64a48b9..69cd344 100644 --- a/drivers/power/supply/bq24190_charger.c +++ b/drivers/power/supply/bq24190_charger.c @@ -38,8 +38,9 @@ #define BQ24190_REG_POC_WDT_RESET_SHIFT 6 #define BQ24190_REG_POC_CHG_CONFIG_MASK (BIT(5) | BIT(4)) #define BQ24190_REG_POC_CHG_CONFIG_SHIFT 4 -#define BQ24190_REG_POC_CHG_CONFIG_CHARGE 1 -#define BQ24190_REG_POC_CHG_CONFIG_OTG 2 +#define BQ24190_REG_POC_CHG_CONFIG_DISABLE 0x0 +#define BQ24190_REG_POC_CHG_CONFIG_CHARGE 0x1 +#define BQ24190_REG_POC_CHG_CONFIG_OTG 0x2 #define BQ24190_REG_POC_SYS_MIN_MASK (BIT(3) | BIT(2) | BIT(1)) #define BQ24190_REG_POC_SYS_MIN_SHIFT 1 #define BQ24190_REG_POC_BOOST_LIM_MASK BIT(0) @@ -173,8 +174,9 @@ struct bq24190_dev_info { */ /* REG00[2:0] (IINLIM) in uAh */ -static const int bq24190_iinlim_values[] = { - 100000, 150000, 500000, 900000, 1200000, 1500000, 2000000, 3000000 }; +static const int bq24190_isc_iinlim_values[] = { + 100000, 150000, 500000, 900000, 1200000, 1500000, 2000000, 3000000 +}; /* REG02[7:2] (ICHG) in uAh */ static const int bq24190_ccc_ichg_values[] = { @@ -1298,16 +1300,18 @@ static void bq24190_extcon_work(struct work_struct *work) { struct bq24190_dev_info *bdi = container_of(work, struct bq24190_dev_info, extcon_work.work); - int ret, iinlim = 0; + int error, iinlim = 0; + u8 v; - ret = pm_runtime_get_sync(bdi->dev); - if (ret < 0) { - dev_err(bdi->dev, "Error getting runtime-pm ref: %d\n", ret); + error = pm_runtime_get_sync(bdi->dev); + if (error < 0) { + dev_warn(bdi->dev, "pm_runtime_get failed: %i\n", error); + pm_runtime_put_noidle(bdi->dev); return; } - if (extcon_get_state(bdi->extcon, EXTCON_CHG_USB_SDP) == 1) - iinlim = 500000; + if (extcon_get_state(bdi->extcon, EXTCON_CHG_USB_SDP) == 1) + iinlim = 500000; else if (extcon_get_state(bdi->extcon, EXTCON_CHG_USB_CDP) == 1 || extcon_get_state(bdi->extcon, EXTCON_CHG_USB_ACA) == 1) iinlim = 1500000; @@ -1315,33 +1319,28 @@ static void bq24190_extcon_work(struct work_struct *work) iinlim = 2000000; if (iinlim) { - ret = bq24190_set_field_val(bdi, BQ24190_REG_ISC, - BQ24190_REG_ISC_IINLIM_MASK, - BQ24190_REG_ISC_IINLIM_SHIFT, - bq24190_iinlim_values, - ARRAY_SIZE(bq24190_iinlim_values), - iinlim); - if (ret) - dev_err(bdi->dev, "Can't set IINLIM: %d\n", ret); + error = bq24190_set_field_val(bdi, BQ24190_REG_ISC, + BQ24190_REG_ISC_IINLIM_MASK, + BQ24190_REG_ISC_IINLIM_SHIFT, + bq24190_isc_iinlim_values, + ARRAY_SIZE(bq24190_isc_iinlim_values), + iinlim); + if (error < 0) + dev_err(bdi->dev, "Can't set IINLIM: %d\n", error); } - /* - * If no charger has been detected and host mode is requested, activate - * the 5V boost converter, otherwise deactivate it. - */ - if (!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST) == 1) { - ret = bq24190_write_mask(bdi, BQ24190_REG_POC, - BQ24190_REG_POC_CHG_CONFIG_MASK, - BQ24190_REG_POC_CHG_CONFIG_SHIFT, - BQ24190_REG_POC_CHG_CONFIG_OTG); - } else { - ret = bq24190_write_mask(bdi, BQ24190_REG_POC, - BQ24190_REG_POC_CHG_CONFIG_MASK, - BQ24190_REG_POC_CHG_CONFIG_SHIFT, - BQ24190_REG_POC_CHG_CONFIG_CHARGE); - } - if (ret) - dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", ret); + /* if no charger found and in USB host mode, set OTG 5V boost, else normal */ + if (!iinlim && extcon_get_state(bdi->extcon, EXTCON_USB_HOST) == 1) + v = BQ24190_REG_POC_CHG_CONFIG_OTG; + else + v = BQ24190_REG_POC_CHG_CONFIG_CHARGE; + + error = bq24190_write_mask(bdi, BQ24190_REG_POC, + BQ24190_REG_POC_CHG_CONFIG_MASK, + BQ24190_REG_POC_CHG_CONFIG_SHIFT, + v); + if (error < 0) + dev_err(bdi->dev, "Can't set CHG_CONFIG: %d\n", error); pm_runtime_mark_last_busy(bdi->dev); pm_runtime_put_autosuspend(bdi->dev); @@ -1432,8 +1431,15 @@ static int bq24190_probe(struct i2c_client *client, } /* - * The extcon-name property is purely an in kernel interface for - * x86/ACPI use, DT platforms should get extcon via phandle. + * Devicetree platforms should get extcon via phandle (not yet supported). + * On ACPI platforms, extcon clients may invoke us with: + * struct property_entry pe[] = + * { PROPERTY_ENTRY_STRING("extcon-name", client_name), ... }; + * struct i2c_board_info bi = + * { .type = "bq24190", .addr = 0x6b, .properties = pe, .irq = irq }; + * struct i2c_adapter ad = { ... }; + * i2c_add_adapter(&ad); + * i2c_new_device(&ad, &bi); */ if (device_property_read_string(dev, "extcon-name", &name) == 0) { bdi->extcon = extcon_get_extcon_dev(name); @@ -1498,8 +1504,10 @@ static int bq24190_probe(struct i2c_client *client, bdi->extcon_nb.notifier_call = bq24190_extcon_event; ret = devm_extcon_register_notifier(dev, bdi->extcon, -1, &bdi->extcon_nb); - if (ret) + if (ret) { + dev_err(dev, "Can't register extcon\n"); goto out5; + } /* Sync initial cable state */ queue_delayed_work(system_wq, &bdi->extcon_work, 0);