From patchwork Sun Aug 20 17:11:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 715317 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03ABDEE49A8 for ; Sun, 20 Aug 2023 17:16:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229854AbjHTRQT (ORCPT ); Sun, 20 Aug 2023 13:16:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229805AbjHTRQM (ORCPT ); Sun, 20 Aug 2023 13:16:12 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2ECB5198C; Sun, 20 Aug 2023 10:11:54 -0700 (PDT) X-IronPort-AV: E=Sophos;i="6.01,188,1684767600"; d="scan'208";a="177097985" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 21 Aug 2023 02:11:53 +0900 Received: from localhost.localdomain (unknown [10.226.92.18]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 1832A40062AF; Mon, 21 Aug 2023 02:11:50 +0900 (JST) From: Biju Das To: Sebastian Reichel Cc: Biju Das , linux-pm@vger.kernel.org, Geert Uytterhoeven , Dmitry Torokhov , Andy Shevchenko , Andi Shyti , linux-renesas-soc@vger.kernel.org Subject: [PATCH 1/2 RESEND] power: supply: sbs-battery: Make similar OF and ID table Date: Sun, 20 Aug 2023 18:11:44 +0100 Message-Id: <20230820171145.82662-2-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230820171145.82662-1-biju.das.jz@bp.renesas.com> References: <20230820171145.82662-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Make similar OF and ID table to extend support for ID match using i2c_match_data()/device_get_match_data() later. Currently it works only for OF match tables as the driver_data is wrong for ID match. Signed-off-by: Biju Das --- drivers/power/supply/sbs-battery.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index cdfc8466d129..50b11b6df1b3 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -1253,9 +1253,9 @@ static SIMPLE_DEV_PM_OPS(sbs_pm_ops, sbs_suspend, NULL); #endif static const struct i2c_device_id sbs_id[] = { - { "bq20z65", 0 }, - { "bq20z75", 0 }, - { "sbs-battery", 1 }, + { "bq20z65", SBS_FLAGS_TI_BQ20ZX5 }, + { "bq20z75", SBS_FLAGS_TI_BQ20ZX5 }, + { "sbs-battery", 0 }, {} }; MODULE_DEVICE_TABLE(i2c, sbs_id); From patchwork Sun Aug 20 17:11:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 715316 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64550EE49AA for ; Sun, 20 Aug 2023 17:16:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229535AbjHTRQU (ORCPT ); Sun, 20 Aug 2023 13:16:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230176AbjHTRQQ (ORCPT ); Sun, 20 Aug 2023 13:16:16 -0400 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 43D841BC0; Sun, 20 Aug 2023 10:11:57 -0700 (PDT) X-IronPort-AV: E=Sophos;i="6.01,188,1684767600"; d="scan'208";a="173400515" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 21 Aug 2023 02:11:56 +0900 Received: from localhost.localdomain (unknown [10.226.92.18]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 2B3C440062AF; Mon, 21 Aug 2023 02:11:53 +0900 (JST) From: Biju Das To: Sebastian Reichel Cc: Biju Das , linux-pm@vger.kernel.org, Geert Uytterhoeven , Dmitry Torokhov , Andy Shevchenko , Andi Shyti , linux-renesas-soc@vger.kernel.org Subject: [PATCH 2/2 RESEND] power: supply: sbs-battery: Convert enum->pointer for data in the match tables Date: Sun, 20 Aug 2023 18:11:45 +0100 Message-Id: <20230820171145.82662-3-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230820171145.82662-1-biju.das.jz@bp.renesas.com> References: <20230820171145.82662-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Convert enum->pointer for data in the match tables, so that device_get_match_data() can do match against OF/ACPI/I2C tables, once i2c bus type match support added to it and it returns NULL for non-match. Therefore it is better to convert enum->pointer for data match and extend match support for both ID and OF tables using i2c_get_match_data() by adding struct sbs_data with flags variable and replacing flags->data in struct sbs_info. Signed-off-by: Biju Das --- drivers/power/supply/sbs-battery.c | 42 ++++++++++++++++++------------ 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index 50b11b6df1b3..06df188c9229 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -201,6 +201,10 @@ static const enum power_supply_property string_properties[] = { #define NR_STRING_BUFFERS ARRAY_SIZE(string_properties) +struct sbs_data { + u32 flags; +}; + struct sbs_info { struct i2c_client *client; struct power_supply *power_supply; @@ -213,7 +217,7 @@ struct sbs_info { u32 poll_retry_count; struct delayed_work work; struct mutex mode_lock; - u32 flags; + const struct sbs_data *data; int technology; char strings[NR_STRING_BUFFERS][I2C_SMBUS_BLOCK_MAX + 1]; }; @@ -579,7 +583,7 @@ static int sbs_get_battery_presence_and_health( struct sbs_info *chip = i2c_get_clientdata(client); int ret; - if (chip->flags & SBS_FLAGS_TI_BQ20ZX5) + if (chip->data->flags & SBS_FLAGS_TI_BQ20ZX5) return sbs_get_ti_battery_presence_and_health(client, psp, val); /* Dummy command; if it succeeds, battery is present. */ @@ -1135,7 +1139,7 @@ static int sbs_probe(struct i2c_client *client) if (!chip) return -ENOMEM; - chip->flags = (u32)(uintptr_t)device_get_match_data(&client->dev); + chip->data = i2c_get_match_data(client); chip->client = client; psy_cfg.of_node = client->dev.of_node; psy_cfg.drv_data = chip; @@ -1233,7 +1237,7 @@ static int sbs_suspend(struct device *dev) if (chip->poll_time > 0) cancel_delayed_work_sync(&chip->work); - if (chip->flags & SBS_FLAGS_TI_BQ20ZX5) { + if (chip->data->flags & SBS_FLAGS_TI_BQ20ZX5) { /* Write to manufacturer access with sleep command. */ ret = sbs_write_word_data(client, sbs_data[REG_MANUFACTURER_DATA].addr, @@ -1252,24 +1256,30 @@ static SIMPLE_DEV_PM_OPS(sbs_pm_ops, sbs_suspend, NULL); #define SBS_PM_OPS NULL #endif +static const struct sbs_data bq20z65 = { + .flags = SBS_FLAGS_TI_BQ20ZX5, +}; + +static const struct sbs_data bq20z75 = { + .flags = SBS_FLAGS_TI_BQ20ZX5, +}; + +static const struct sbs_data sbs_battery = { + .flags = 0, +}; + static const struct i2c_device_id sbs_id[] = { - { "bq20z65", SBS_FLAGS_TI_BQ20ZX5 }, - { "bq20z75", SBS_FLAGS_TI_BQ20ZX5 }, - { "sbs-battery", 0 }, + { "bq20z65", (kernel_ulong_t)&bq20z65 }, + { "bq20z75", (kernel_ulong_t)&bq20z75 }, + { "sbs-battery", (kernel_ulong_t)&sbs_battery }, {} }; MODULE_DEVICE_TABLE(i2c, sbs_id); static const struct of_device_id sbs_dt_ids[] = { - { .compatible = "sbs,sbs-battery" }, - { - .compatible = "ti,bq20z65", - .data = (void *)SBS_FLAGS_TI_BQ20ZX5, - }, - { - .compatible = "ti,bq20z75", - .data = (void *)SBS_FLAGS_TI_BQ20ZX5, - }, + { .compatible = "sbs,sbs-battery", .data = &sbs_battery }, + { .compatible = "ti,bq20z65", .data = &bq20z65 }, + { .compatible = "ti,bq20z75", .data = &bq20z75 }, { } }; MODULE_DEVICE_TABLE(of, sbs_dt_ids);