Received: by 2002:a05:7412:1703:b0:e2:908c:2ebd with SMTP id dm3csp355738rdb; Thu, 24 Aug 2023 08:05:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHWPGoktIbjn3DH/Yh7lwh9eKhJzA5YVkK4srqrzIZwhmytb1LSPN1uWGMlvL/RYBkySlPs X-Received: by 2002:a17:902:d4d0:b0:1be:fe18:3a44 with SMTP id o16-20020a170902d4d000b001befe183a44mr20847669plg.22.1692889525391; Thu, 24 Aug 2023 08:05:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692889525; cv=none; d=google.com; s=arc-20160816; b=C2qKxgoxXIyAVJC1mJ8lWx9ek2VZbozCZ0ChJrO/FAdSAjjSJuHSiDW6RaY+qwQuJX 7sRmVT31NspO/TSJUvd1X9qFU0/6DIjDU+2riuoMF8xXhJeiItgN+1W/sNWXrOsl9cN6 5QBVc8CgQcCAEkbEczS5sTWfnaqMA/23aBUkJooJonnTCNTmIEyhY4O8P8l4odro+DqR 4HXktYmeef2d6leh/GPk0yWzKeVmDOY6wF9n+T/rF6PTXuDrpSUNDmNcZtm7YNvm2p6R PJypmS3Qb0frru8rE1r3YG/Xs+evHJqyOc/OkP2QLgXirj4qp/wgiGyIdB+A/PEezXl7 CmNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from; bh=Q2eOf1mYfMSDypEViX0dCYk1IC6oHrmuukHeAvJ/WXw=; fh=AdkrZQUwtQPUQ+xuacZ41AllCYddoYgTIVzm3nkJypA=; b=0O8afTPEpv/QkPsOC0qQk+YV8EQlqciCCuOQ/iE7I7Tz+CTNESnces2ieazcbUjgdy dy24G5CrLQqVkVwH/JMd2ELV6qkpl+UnAWmoeHteqbRRUtaE1CDBYvSkJmhJ08eWBAu6 0r8JCk2BkIXJj3I6Zer/wujlf4jkv/VmgnPHBmkGf5SWI4s1tAlOdMjR/dSr6g2x81KB Qi94rtXUfgzf6UrLtVBfFZ0rD3g3De8ORZvWbIu5utPZjiuC32b5wtut3WjFPMfGk5Wi 3uOvN3IAnBZVcFzxYISuKB35VzX0nVNS7vVKOKM1OFiF//6rM0DKuA2YWp5tyn/odgKl EYGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a170902e88400b001b9d203659dsi14162410plg.14.2023.08.24.08.04.38; Thu, 24 Aug 2023 08:05:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241262AbjHXMGl (ORCPT + 99 others); Thu, 24 Aug 2023 08:06:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232918AbjHXMGI (ORCPT ); Thu, 24 Aug 2023 08:06:08 -0400 X-Greylist: delayed 880 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 24 Aug 2023 05:06:02 PDT Received: from luna.linkmauve.fr (82-65-109-163.subs.proxad.net [82.65.109.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5513198D; Thu, 24 Aug 2023 05:06:02 -0700 (PDT) Received: by luna.linkmauve.fr (Postfix, from userid 1000) id DC99D8CC50D; Thu, 24 Aug 2023 13:27:57 +0200 (CEST) From: Emmanuel Gil Peyrot Cc: Alexandre Courbot , azkali , CTCaer , Sebastian Reichel , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] power: supply: bq24190_charger: Export current regulator Date: Thu, 24 Aug 2023 13:27:35 +0200 Message-ID: <20230824112741.201353-3-linkmauve@linkmauve.fr> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230824112741.201353-1-linkmauve@linkmauve.fr> References: <20230824112741.201353-1-linkmauve@linkmauve.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,PDS_RDNS_DYNAMIC_FP, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_SORBS_DUL,RDNS_DYNAMIC,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexandre Courbot Signed-off-by: Alexandre Courbot --- drivers/power/supply/bq24190_charger.c | 84 ++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c index a56122b39687..8c026e86aeb3 100644 --- a/drivers/power/supply/bq24190_charger.c +++ b/drivers/power/supply/bq24190_charger.c @@ -530,6 +530,81 @@ static int bq24190_set_otg_vbus(struct bq24190_dev_info *bdi, bool enable) } #ifdef CONFIG_REGULATOR +static int bq24190_set_charging_current(struct regulator_dev *dev, + int min_uA, int max_uA) +{ + struct bq24190_dev_info *bdi = rdev_get_drvdata(dev); + u8 ss_reg; + int in_current_limit; + int ret = 0; + + dev_info(bdi->dev, "Setting charging current %d mA\n", max_uA/1000); + + ret = bq24190_read(bdi, BQ24190_REG_SS, &ss_reg); + if (ret < 0) + goto error; + + if (max_uA == 0 && ss_reg != 0) + return ret; + + if (!(ss_reg & BQ24190_REG_SS_VBUS_STAT_MASK)) + in_current_limit = 500; + else + in_current_limit = max_uA / 1000; + + return 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), + in_current_limit); +error: + dev_err(bdi->dev, "Charger enable failed, err = %d\n", ret); + return ret; +} + +static const struct regulator_ops bq24190_chrg_ops = { + .set_current_limit = bq24190_set_charging_current, +}; + +static const struct regulator_desc bq24190_chrg_desc = { + .name = "charger", + .of_match = "charger", + .type = REGULATOR_CURRENT, + .owner = THIS_MODULE, + .ops = &bq24190_chrg_ops, +}; + +static const struct regulator_init_data bq24190_chrg_init_data = { + .constraints = { + .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_CURRENT, + .min_uA = 0, + .max_uA = 3000000, + }, +}; + +static int bq24190_register_chrg_regulator(struct bq24190_dev_info *bdi) +{ + struct bq24190_platform_data *pdata = bdi->dev->platform_data; + struct regulator_config cfg = { }; + struct regulator_dev *reg; + int ret = 0; + + cfg.dev = bdi->dev; + if (pdata && pdata->regulator_init_data) + cfg.init_data = pdata->regulator_init_data; + else + cfg.init_data = &bq24190_chrg_init_data; + cfg.driver_data = bdi; + reg = devm_regulator_register(bdi->dev, &bq24190_chrg_desc, &cfg); + if (IS_ERR(reg)) { + ret = PTR_ERR(reg); + dev_err(bdi->dev, "Can't register regulator: %d\n", ret); + } + + return ret; +} + static int bq24190_vbus_enable(struct regulator_dev *dev) { return bq24190_set_otg_vbus(rdev_get_drvdata(dev), true); @@ -611,6 +686,11 @@ static int bq24190_register_vbus_regulator(struct bq24190_dev_info *bdi) return ret; } #else +static int bq24190_register_chrg_regulator(struct bq24190_dev_info *bdi) +{ + return 0; +} + static int bq24190_register_vbus_regulator(struct bq24190_dev_info *bdi) { return 0; @@ -1879,6 +1959,10 @@ static int bq24190_probe(struct i2c_client *client) goto out_charger; } + ret = bq24190_register_chrg_regulator(bdi); + if (ret < 0) + goto out_charger; + ret = bq24190_register_vbus_regulator(bdi); if (ret < 0) goto out_charger; -- 2.42.0