Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp618236pxb; Tue, 1 Feb 2022 07:06:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJxb90en504hquweWo6ShKU7hp1dCbPjx19xMNC//Gz4/N7A1hJCZCgHnnLbMXrwvYdpocbR X-Received: by 2002:a17:907:7faa:: with SMTP id qk42mr5534386ejc.368.1643728002041; Tue, 01 Feb 2022 07:06:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643728002; cv=none; d=google.com; s=arc-20160816; b=j8FZsLaSjk73eAlrL2genHnbFbRDHQGJgfGIV18iSKWKaEGOyJeeJ2LVI33Lkr2cES M4bdTmafddHX74fIEALqgMfrNNlt0VgVeQ3r3GLRr/4urwtyt4sQDHIT/ZKvUxTsJ7jJ bPpg3snb/YP6JRMNP3KUdT/TuXJZnpww2Z2EdubXqIOGHjt2mlbSjlxPfU+xtJR4DSLx fTL6T0WdVQPBlPy6R5bNiiFjrdj6dXgmlFnlI+J2hC5mM8Zlm4e68hkO2NJi/k98GnMM 5XgRjRvEx2EJm39IXRShkNBWQzriSaJQZY0MsawOB8tSCNHzP0GjnpgPCWUJrw8fPRl6 8xNA== 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=U0UDq9ZMy8ORJ9b5R7LyjUT1pKbkDcAyicRI+R3n0Ew=; b=FYs1A6sJ8YlTpmpvF9dZqERshKKLcUXeaDk+OIAmr3BJpNmM1DN3lFueo9KWeVGDUE 3IOM6EGlE6UoksEEVtUjyq6kBRH6MaCDmAkudUlzuxJsLiQyyYSitnfslHw8PT4GQ5wP sSawykfhM7QxXcZRINGsJcrgL1INw5rRCX6hElIVd2cEq+m0Rx7sc4OqyQaFzkTidIpc TXkSa72y2RZtAkH7K+5SL9DapZ9vdwgKvDfcJpZTJUq3FAT5AW6JH9hq05ffK/pgtCLJ VTmZyN7URiKtghZKrOZbyTDWTw8StyaQ1jai3ePvZF75vwqDmbN2paMlsfcjacTeSA0C quZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Xg+Ut6Jo; 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 sh10si9480421ejc.715.2022.02.01.07.06.14; Tue, 01 Feb 2022 07:06:42 -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=Xg+Ut6Jo; 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 S1356194AbiA3Uqg (ORCPT + 99 others); Sun, 30 Jan 2022 15:46:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:46259 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356180AbiA3Uqd (ORCPT ); Sun, 30 Jan 2022 15:46:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643575593; 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=U0UDq9ZMy8ORJ9b5R7LyjUT1pKbkDcAyicRI+R3n0Ew=; b=Xg+Ut6Jo/Uxjgcnh5ZbmUxQTJZGfpasB5Nc9Tp3kTxum7VbnjT4HBMFwqs8RnGLCzbpzlA rf9mFvKdVe1e62kb5YNF39Jh7BY6eqCU8xzMzvtS7mI9cyEUnaLdFXk8uh9CuN1R+bIZrY 4s9xFh8wWcFr7Rgh/uErQPHFJPIPhcY= 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-231-7fIbLxO0OCWOdZr8wArHaA-1; Sun, 30 Jan 2022 15:46:27 -0500 X-MC-Unique: 7fIbLxO0OCWOdZr8wArHaA-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 4EA631006AA3; Sun, 30 Jan 2022 20:46:25 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05AE061093; Sun, 30 Jan 2022 20:46:14 +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 Subject: [PATCH v4 04/20] power: supply: bq25890: Add a bq25890_rw_init_data() helper Date: Sun, 30 Jan 2022 21:45:41 +0100 Message-Id: <20220130204557.15662-5-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 On most x86/ACPI devices there is no devicetree to supply the necessary init-data. Instead the firmware already fully initializes the bq25890 charger at boot. Factor out the current code to write all the init_data from devicetree into a new bq25890_rw_init_data() helper which can both write the data to the charger (the current behavior) as well as read it back from the charger into the init_data struct. This is a preparation patch for adding support for x86/ACPI device's where the init_data must be read back from the bq25890 charger. Signed-off-by: Hans de Goede --- drivers/power/supply/bq25890_charger.c | 62 +++++++++++++++++--------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 7a3269c06b38..eaf0400b632f 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -693,29 +693,52 @@ static int bq25890_chip_reset(struct bq25890_device *bq) return 0; } -static int bq25890_hw_init(struct bq25890_device *bq) +static int bq25890_rw_init_data(struct bq25890_device *bq) { + bool write = true; int ret; int i; const struct { enum bq25890_fields id; - u32 value; + u8 *value; } init_data[] = { - {F_ICHG, bq->init_data.ichg}, - {F_VREG, bq->init_data.vreg}, - {F_ITERM, bq->init_data.iterm}, - {F_IPRECHG, bq->init_data.iprechg}, - {F_SYSVMIN, bq->init_data.sysvmin}, - {F_BOOSTV, bq->init_data.boostv}, - {F_BOOSTI, bq->init_data.boosti}, - {F_BOOSTF, bq->init_data.boostf}, - {F_EN_ILIM, bq->init_data.ilim_en}, - {F_TREG, bq->init_data.treg}, - {F_BATCMP, bq->init_data.rbatcomp}, - {F_VCLAMP, bq->init_data.vclamp}, + {F_ICHG, &bq->init_data.ichg}, + {F_VREG, &bq->init_data.vreg}, + {F_ITERM, &bq->init_data.iterm}, + {F_IPRECHG, &bq->init_data.iprechg}, + {F_SYSVMIN, &bq->init_data.sysvmin}, + {F_BOOSTV, &bq->init_data.boostv}, + {F_BOOSTI, &bq->init_data.boosti}, + {F_BOOSTF, &bq->init_data.boostf}, + {F_EN_ILIM, &bq->init_data.ilim_en}, + {F_TREG, &bq->init_data.treg}, + {F_BATCMP, &bq->init_data.rbatcomp}, + {F_VCLAMP, &bq->init_data.vclamp}, }; + for (i = 0; i < ARRAY_SIZE(init_data); i++) { + if (write) { + ret = bq25890_field_write(bq, init_data[i].id, + *init_data[i].value); + } else { + ret = bq25890_field_read(bq, init_data[i].id); + if (ret >= 0) + *init_data[i].value = ret; + } + if (ret < 0) { + dev_dbg(bq->dev, "Accessing init data failed %d\n", ret); + return ret; + } + } + + return 0; +} + +static int bq25890_hw_init(struct bq25890_device *bq) +{ + int ret; + ret = bq25890_chip_reset(bq); if (ret < 0) { dev_dbg(bq->dev, "Reset failed %d\n", ret); @@ -730,14 +753,9 @@ static int bq25890_hw_init(struct bq25890_device *bq) } /* initialize currents/voltages and other parameters */ - for (i = 0; i < ARRAY_SIZE(init_data); i++) { - ret = bq25890_field_write(bq, init_data[i].id, - init_data[i].value); - if (ret < 0) { - dev_dbg(bq->dev, "Writing init data failed %d\n", ret); - return ret; - } - } + ret = bq25890_rw_init_data(bq); + if (ret) + return ret; ret = bq25890_get_chip_state(bq, &bq->state); if (ret < 0) { -- 2.33.1