Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp617181pxb; Tue, 1 Feb 2022 07:05:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJyimfIdtvd1VF8uUQ46nqWQKl6RcdO7u8wFtNQq+ESpxIg+4IIyj4PqtRh03v5DQ+NE7hz0 X-Received: by 2002:a17:907:6d96:: with SMTP id sb22mr21136214ejc.25.1643727949462; Tue, 01 Feb 2022 07:05:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643727949; cv=none; d=google.com; s=arc-20160816; b=tyJIc3RMKUyCjCtpczrW9YsrKlDN+/sxX9EnMQR1J3Ag97qBKlkMNYlsZZaJAphfZ+ 3j4bKGugryNJiaoBxkzrQxUwHO8MZXJt5Okdswl+M2gEYEkUsrWG42sRCa/VPS3c3x+O nWZVkTyWId4lniuO4U2SPmcCrro4SPgfIgjNWjFU8MlW1ASOO3dtDHfCli6Aerq/qY9H jIsazqISINiZR4bVkPeIH0Ea/cENXH3C3ZwKcML7tHOhO8X926xQQKRjd57p6Nksru0Q CyIf8hPFeCJ4cFZHblom4IkoogEH7X7tAgTn/ix+RgJWTXaEFTXRXi9RNFKLzsyi64aW AhWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RCI/2xm84dyYISbFEC9/hQrlI+8v3ywGqx6ibk46P7M=; b=PdNUmM/Fh9aDnrGxAQWERuE36l8qg9a7zNhRGcwE83iS8O+V18gQIi9K+VXmbInVr0 2ZcFxdT0F9WqLKJYbKEsIBGEf6s2ay4DtS5jiatRasJyav39UU5wsly/7zPPje63EeFW jb8QhRGo5pv8EONIxJOPXfxBFS69whX6eaJuvPewyU9jCxAdl9qk1aBajY1NvhIA+go/ 00lFPiMofIePRV/bE0l1dAaLZxrcFcbXFilePh3MVa7zLzR+wxL2XXxt/rI4h1/VUvKG 0u7QsXX5HzvfafeWc8al9ELVEfz6K4aWhBARjlkTqIVFctU6jyUUtzeaJBCFdIKX9287 yuSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="W/XS+T2K"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qw41si9785715ejc.443.2022.02.01.07.05.22; Tue, 01 Feb 2022 07:05:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="W/XS+T2K"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356281AbiA3Ur2 (ORCPT + 99 others); Sun, 30 Jan 2022 15:47:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:27446 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356295AbiA3UrS (ORCPT ); Sun, 30 Jan 2022 15:47:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643575637; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RCI/2xm84dyYISbFEC9/hQrlI+8v3ywGqx6ibk46P7M=; b=W/XS+T2KqjuKSfpAarnjPlYKsNiPKfKsRepGHRMJrH4fn6690zDJSW7NSLBQsdNmF2OYxf gD5i5YcQV2WKWe1PjovMDI9kjxaTWKVc6IgqCnDH8vqC2t5nO0cUmb4xIhuFeXr0krciST 6Jcx27nvER4jkqQqKrc3wWUXrKKT/5o= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-630-cxsTHxAuPYisJt_Nb_tmXA-1; Sun, 30 Jan 2022 15:47:13 -0500 X-MC-Unique: cxsTHxAuPYisJt_Nb_tmXA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2A8B718397A7; Sun, 30 Jan 2022 20:47:11 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DF3A61093; Sun, 30 Jan 2022 20:47:05 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , Lee Jones , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , Len Brown , linux-acpi@vger.kernel.org, Yauhen Kharuzhy , Tsuchiya Yuto , Fabio Aiuto , platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, Andy Shevchenko Subject: [PATCH v4 10/20] power: supply: bq25890: Add support for registering the Vbus boost converter as a regulator Date: Sun, 30 Jan 2022 21:45:47 +0100 Message-Id: <20220130204557.15662-11-hdegoede@redhat.com> In-Reply-To: <20220130204557.15662-1-hdegoede@redhat.com> References: <20220130204557.15662-1-hdegoede@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The bq25890_charger code supports enabling/disabling the boost converter based on usb-phy notifications. But the usb-phy framework is not used on all boards/platforms. At support for registering the Vbus boost converter as a standard regulator when there is no usb-phy on the board. Also add support for providing regulator_init_data through platform_data for use on boards where device-tree is not used and the platform code must thus provide the regulator_init_data. Reviewed-by: Andy Shevchenko Signed-off-by: Hans de Goede --- Changes in v2: - When the usb-phy framework is not used, turn off the Vboost regulator on shutdown - Some minor code-tweaks based on Andy's review --- drivers/power/supply/bq25890_charger.c | 80 ++++++++++++++++++++++++++ include/linux/power/bq25890_charger.h | 15 +++++ 2 files changed, 95 insertions(+) create mode 100644 include/linux/power/bq25890_charger.h diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 162bffb02410..637cdd3b6b11 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -8,7 +8,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -876,6 +878,45 @@ static int bq25890_usb_notifier(struct notifier_block *nb, unsigned long val, return NOTIFY_OK; } +#ifdef CONFIG_REGULATOR +static int bq25890_vbus_enable(struct regulator_dev *rdev) +{ + struct bq25890_device *bq = rdev_get_drvdata(rdev); + + return bq25890_set_otg_cfg(bq, 1); +} + +static int bq25890_vbus_disable(struct regulator_dev *rdev) +{ + struct bq25890_device *bq = rdev_get_drvdata(rdev); + + return bq25890_set_otg_cfg(bq, 0); +} + +static int bq25890_vbus_is_enabled(struct regulator_dev *rdev) +{ + struct bq25890_device *bq = rdev_get_drvdata(rdev); + + return bq25890_field_read(bq, F_OTG_CFG); +} + +static const struct regulator_ops bq25890_vbus_ops = { + .enable = bq25890_vbus_enable, + .disable = bq25890_vbus_disable, + .is_enabled = bq25890_vbus_is_enabled, +}; + +static const struct regulator_desc bq25890_vbus_desc = { + .name = "usb_otg_vbus", + .of_match = "usb-otg-vbus", + .type = REGULATOR_VOLTAGE, + .owner = THIS_MODULE, + .ops = &bq25890_vbus_ops, + .fixed_uV = 5000000, + .n_voltages = 1, +}; +#endif + static int bq25890_get_chip_version(struct bq25890_device *bq) { int id, rev; @@ -1075,6 +1116,22 @@ static int bq25890_probe(struct i2c_client *client, bq->usb_nb.notifier_call = bq25890_usb_notifier; usb_register_notifier(bq->usb_phy, &bq->usb_nb); } +#ifdef CONFIG_REGULATOR + else { + struct bq25890_platform_data *pdata = dev_get_platdata(dev); + struct regulator_config cfg = { }; + struct regulator_dev *reg; + + cfg.dev = dev; + cfg.driver_data = bq; + if (pdata) + cfg.init_data = pdata->regulator_init_data; + + reg = devm_regulator_register(dev, &bq25890_vbus_desc, &cfg); + if (IS_ERR(reg)) + return dev_err_probe(dev, PTR_ERR(reg), "registering regulator"); + } +#endif ret = bq25890_power_supply_init(bq); if (ret < 0) { @@ -1113,6 +1170,28 @@ static int bq25890_remove(struct i2c_client *client) return 0; } +static void bq25890_shutdown(struct i2c_client *client) +{ + struct bq25890_device *bq = i2c_get_clientdata(client); + + /* + * TODO this if + return should probably be removed, but that would + * introduce a function change for boards using the usb-phy framework. + * This needs to be tested on such a board before making this change. + */ + if (!IS_ERR_OR_NULL(bq->usb_phy)) + return; + + /* + * Turn off the 5v Boost regulator which outputs Vbus to the device's + * Micro-USB or Type-C USB port. Leaving this on drains power and + * this avoids the PMIC on some device-models seeing this as Vbus + * getting inserted after shutdown, causing the device to immediately + * power-up again. + */ + bq25890_set_otg_cfg(bq, 0); +} + #ifdef CONFIG_PM_SLEEP static int bq25890_suspend(struct device *dev) { @@ -1192,6 +1271,7 @@ static struct i2c_driver bq25890_driver = { }, .probe = bq25890_probe, .remove = bq25890_remove, + .shutdown = bq25890_shutdown, .id_table = bq25890_i2c_ids, }; module_i2c_driver(bq25890_driver); diff --git a/include/linux/power/bq25890_charger.h b/include/linux/power/bq25890_charger.h new file mode 100644 index 000000000000..c706ddb77a08 --- /dev/null +++ b/include/linux/power/bq25890_charger.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Platform data for the TI bq25890 battery charger driver. + */ + +#ifndef _BQ25890_CHARGER_H_ +#define _BQ25890_CHARGER_H_ + +struct regulator_init_data; + +struct bq25890_platform_data { + const struct regulator_init_data *regulator_init_data; +}; + +#endif -- 2.33.1