From nobody Mon Feb 9 02:03:12 2026 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 9D68FC83F3F for ; Sun, 3 Sep 2023 11:56:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236900AbjICL4D (ORCPT ); Sun, 3 Sep 2023 07:56:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230293AbjICL4C (ORCPT ); Sun, 3 Sep 2023 07:56:02 -0400 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6614F124; Sun, 3 Sep 2023 04:55:58 -0700 (PDT) X-IronPort-AV: E=Sophos;i="6.02,224,1688396400"; d="scan'208";a="174843004" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 03 Sep 2023 20:55:58 +0900 Received: from localhost.localdomain (unknown [10.226.92.30]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 566E141C2D8A; Sun, 3 Sep 2023 20:55:55 +0900 (JST) From: Biju Das To: Jonathan Cameron Cc: Biju Das , Lars-Peter Clausen , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Marek Vasut , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Biju Das Subject: [PATCH v3 1/4] iio: dac: mcp4725: Replace variable 'id' from struct mcp4725_data Date: Sun, 3 Sep 2023 12:55:45 +0100 Message-Id: <20230903115548.59306-2-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230903115548.59306-1-biju.das.jz@bp.renesas.com> References: <20230903115548.59306-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Replace the variable 'id' from struct mcp4725_data with local variable chip_id in probe() as the id variable is not used elsewhere in the driver. Signed-off-by: Biju Das --- v2->v3: * No change. v1->v2: * Update commit description with reason for change. --- drivers/iio/dac/mcp4725.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/iio/dac/mcp4725.c b/drivers/iio/dac/mcp4725.c index f4a3124d29f2..33a61f65bc25 100644 --- a/drivers/iio/dac/mcp4725.c +++ b/drivers/iio/dac/mcp4725.c @@ -32,7 +32,6 @@ =20 struct mcp4725_data { struct i2c_client *client; - int id; unsigned ref_mode; bool vref_buffered; u16 dac_value; @@ -387,6 +386,7 @@ static int mcp4725_probe(struct i2c_client *client) struct mcp4725_data *data; struct iio_dev *indio_dev; struct mcp4725_platform_data *pdata, pdata_dt; + int chip_id; u8 inbuf[4]; u8 pd; u8 ref; @@ -399,9 +399,9 @@ static int mcp4725_probe(struct i2c_client *client) i2c_set_clientdata(client, indio_dev); data->client =3D client; if (dev_fwnode(&client->dev)) - data->id =3D (uintptr_t)device_get_match_data(&client->dev); + chip_id =3D (uintptr_t)device_get_match_data(&client->dev); else - data->id =3D id->driver_data; + chip_id =3D id->driver_data; pdata =3D dev_get_platdata(&client->dev); =20 if (!pdata) { @@ -414,7 +414,7 @@ static int mcp4725_probe(struct i2c_client *client) pdata =3D &pdata_dt; } =20 - if (data->id =3D=3D MCP4725 && pdata->use_vref) { + if (chip_id =3D=3D MCP4725 && pdata->use_vref) { dev_err(&client->dev, "external reference is unavailable on MCP4725"); return -EINVAL; @@ -455,12 +455,12 @@ static int mcp4725_probe(struct i2c_client *client) =20 indio_dev->name =3D id->name; indio_dev->info =3D &mcp4725_info; - indio_dev->channels =3D &mcp472x_channel[id->driver_data]; + indio_dev->channels =3D &mcp472x_channel[chip_id]; indio_dev->num_channels =3D 1; indio_dev->modes =3D INDIO_DIRECT_MODE; =20 /* read current DAC value and settings */ - err =3D i2c_master_recv(client, inbuf, data->id =3D=3D MCP4725 ? 3 : 4); + err =3D i2c_master_recv(client, inbuf, chip_id =3D=3D MCP4725 ? 3 : 4); =20 if (err < 0) { dev_err(&client->dev, "failed to read DAC value"); @@ -470,10 +470,10 @@ static int mcp4725_probe(struct i2c_client *client) data->powerdown =3D pd > 0; data->powerdown_mode =3D pd ? pd - 1 : 2; /* largest resistor to gnd */ data->dac_value =3D (inbuf[1] << 4) | (inbuf[2] >> 4); - if (data->id =3D=3D MCP4726) + if (chip_id =3D=3D MCP4726) ref =3D (inbuf[3] >> 3) & 0x3; =20 - if (data->id =3D=3D MCP4726 && ref !=3D data->ref_mode) { + if (chip_id =3D=3D MCP4726 && ref !=3D data->ref_mode) { dev_info(&client->dev, "voltage reference mode differs (conf: %u, eeprom: %u), setting %u", data->ref_mode, ref, data->ref_mode); --=20 2.25.1 From nobody Mon Feb 9 02:03:12 2026 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 DB9ECC83F3F for ; Sun, 3 Sep 2023 11:56:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236914AbjICL4H (ORCPT ); Sun, 3 Sep 2023 07:56:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236895AbjICL4F (ORCPT ); Sun, 3 Sep 2023 07:56:05 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3B43213D; Sun, 3 Sep 2023 04:56:02 -0700 (PDT) X-IronPort-AV: E=Sophos;i="6.02,224,1688396400"; d="scan'208";a="178550475" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 03 Sep 2023 20:56:01 +0900 Received: from localhost.localdomain (unknown [10.226.92.30]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id B3CC541C2D99; Sun, 3 Sep 2023 20:55:58 +0900 (JST) From: Biju Das To: Jonathan Cameron Cc: Biju Das , Lars-Peter Clausen , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Marek Vasut , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Biju Das Subject: [PATCH v3 2/4] iio: dac: mcp4725: Use i2c_get_match_data() Date: Sun, 3 Sep 2023 12:55:46 +0100 Message-Id: <20230903115548.59306-3-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230903115548.59306-1-biju.das.jz@bp.renesas.com> References: <20230903115548.59306-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add struct mcp4725_chip_info with chan_spec and chip_id variable. After this simplify probe() by replacing device_get_match_data() and id lookup for retrieving match data by i2c_get_match_data() by converting enum->pointer for data in the match table. Signed-off-by: Biju Das --- v2->v3: * Added struct mcp4725_chip_info with chan_spec and chip_id variable and used that as OF/ID table match data. v2: * New patch --- drivers/iio/dac/mcp4725.c | 40 +++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/drivers/iio/dac/mcp4725.c b/drivers/iio/dac/mcp4725.c index 33a61f65bc25..fe8981ec7923 100644 --- a/drivers/iio/dac/mcp4725.c +++ b/drivers/iio/dac/mcp4725.c @@ -30,6 +30,11 @@ #define MCP472X_REF_VREF_UNBUFFERED 0x02 #define MCP472X_REF_VREF_BUFFERED 0x03 =20 +struct mcp4725_chip_info { + const struct iio_chan_spec *chan_spec; + unsigned int chip_id; +}; + struct mcp4725_data { struct i2c_client *client; unsigned ref_mode; @@ -383,10 +388,10 @@ static int mcp4725_probe_dt(struct device *dev, static int mcp4725_probe(struct i2c_client *client) { const struct i2c_device_id *id =3D i2c_client_get_device_id(client); + const struct mcp4725_chip_info *info; struct mcp4725_data *data; struct iio_dev *indio_dev; struct mcp4725_platform_data *pdata, pdata_dt; - int chip_id; u8 inbuf[4]; u8 pd; u8 ref; @@ -398,10 +403,7 @@ static int mcp4725_probe(struct i2c_client *client) data =3D iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); data->client =3D client; - if (dev_fwnode(&client->dev)) - chip_id =3D (uintptr_t)device_get_match_data(&client->dev); - else - chip_id =3D id->driver_data; + info =3D i2c_get_match_data(client); pdata =3D dev_get_platdata(&client->dev); =20 if (!pdata) { @@ -414,7 +416,7 @@ static int mcp4725_probe(struct i2c_client *client) pdata =3D &pdata_dt; } =20 - if (chip_id =3D=3D MCP4725 && pdata->use_vref) { + if (info->chip_id =3D=3D MCP4725 && pdata->use_vref) { dev_err(&client->dev, "external reference is unavailable on MCP4725"); return -EINVAL; @@ -455,12 +457,12 @@ static int mcp4725_probe(struct i2c_client *client) =20 indio_dev->name =3D id->name; indio_dev->info =3D &mcp4725_info; - indio_dev->channels =3D &mcp472x_channel[chip_id]; + indio_dev->channels =3D info->chan_spec; indio_dev->num_channels =3D 1; indio_dev->modes =3D INDIO_DIRECT_MODE; =20 /* read current DAC value and settings */ - err =3D i2c_master_recv(client, inbuf, chip_id =3D=3D MCP4725 ? 3 : 4); + err =3D i2c_master_recv(client, inbuf, info->chip_id =3D=3D MCP4725 ? 3 := 4); =20 if (err < 0) { dev_err(&client->dev, "failed to read DAC value"); @@ -470,10 +472,10 @@ static int mcp4725_probe(struct i2c_client *client) data->powerdown =3D pd > 0; data->powerdown_mode =3D pd ? pd - 1 : 2; /* largest resistor to gnd */ data->dac_value =3D (inbuf[1] << 4) | (inbuf[2] >> 4); - if (chip_id =3D=3D MCP4726) + if (info->chip_id =3D=3D MCP4726) ref =3D (inbuf[3] >> 3) & 0x3; =20 - if (chip_id =3D=3D MCP4726 && ref !=3D data->ref_mode) { + if (info->chip_id =3D=3D MCP4726 && ref !=3D data->ref_mode) { dev_info(&client->dev, "voltage reference mode differs (conf: %u, eeprom: %u), setting %u", data->ref_mode, ref, data->ref_mode); @@ -510,9 +512,19 @@ static void mcp4725_remove(struct i2c_client *client) regulator_disable(data->vdd_reg); } =20 +static const struct mcp4725_chip_info mcp4725 =3D { + .chan_spec =3D &mcp472x_channel[MCP4725], + .chip_id =3D MCP4725, +}; + +static const struct mcp4725_chip_info mcp4726 =3D { + .chan_spec =3D &mcp472x_channel[MCP4726], + .chip_id =3D MCP4726, +}; + static const struct i2c_device_id mcp4725_id[] =3D { - { "mcp4725", MCP4725 }, - { "mcp4726", MCP4726 }, + { "mcp4725", (kernel_ulong_t)&mcp4725 }, + { "mcp4726", (kernel_ulong_t)&mcp4726 }, { } }; MODULE_DEVICE_TABLE(i2c, mcp4725_id); @@ -520,11 +532,11 @@ MODULE_DEVICE_TABLE(i2c, mcp4725_id); static const struct of_device_id mcp4725_of_match[] =3D { { .compatible =3D "microchip,mcp4725", - .data =3D (void *)MCP4725 + .data =3D &mcp4725 }, { .compatible =3D "microchip,mcp4726", - .data =3D (void *)MCP4726 + .data =3D &mcp4726 }, { } }; --=20 2.25.1 From nobody Mon Feb 9 02:03:12 2026 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 854A5C83F3F for ; Sun, 3 Sep 2023 11:56:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236933AbjICL4N (ORCPT ); Sun, 3 Sep 2023 07:56:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236941AbjICL4L (ORCPT ); Sun, 3 Sep 2023 07:56:11 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 23138131; Sun, 3 Sep 2023 04:56:05 -0700 (PDT) X-IronPort-AV: E=Sophos;i="6.02,224,1688396400"; d="scan'208";a="178550481" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 03 Sep 2023 20:56:04 +0900 Received: from localhost.localdomain (unknown [10.226.92.30]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 149AE41C3085; Sun, 3 Sep 2023 20:56:01 +0900 (JST) From: Biju Das To: Jonathan Cameron Cc: Biju Das , Lars-Peter Clausen , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Marek Vasut , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Biju Das Subject: [PATCH v3 3/4] iio: dac: mcp4725: Add use_ext_ref_voltage to struct mcp4725_chip_info Date: Sun, 3 Sep 2023 12:55:47 +0100 Message-Id: <20230903115548.59306-4-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230903115548.59306-1-biju.das.jz@bp.renesas.com> References: <20230903115548.59306-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The MCP4725 has external voltage reference compared MCP4725 which has reference embeedded in eeprom. Add use_ext_ref_voltage variable to struct mcp4725_chip_info to handle this difference. Signed-off-by: Biju Das --- v3: * New patch --- drivers/iio/dac/mcp4725.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/iio/dac/mcp4725.c b/drivers/iio/dac/mcp4725.c index fe8981ec7923..9cbea6f223e4 100644 --- a/drivers/iio/dac/mcp4725.c +++ b/drivers/iio/dac/mcp4725.c @@ -33,6 +33,7 @@ struct mcp4725_chip_info { const struct iio_chan_spec *chan_spec; unsigned int chip_id; + bool use_ext_ref_voltage; }; =20 struct mcp4725_data { @@ -416,7 +417,7 @@ static int mcp4725_probe(struct i2c_client *client) pdata =3D &pdata_dt; } =20 - if (info->chip_id =3D=3D MCP4725 && pdata->use_vref) { + if (info->use_ext_ref_voltage && pdata->use_vref) { dev_err(&client->dev, "external reference is unavailable on MCP4725"); return -EINVAL; @@ -472,10 +473,10 @@ static int mcp4725_probe(struct i2c_client *client) data->powerdown =3D pd > 0; data->powerdown_mode =3D pd ? pd - 1 : 2; /* largest resistor to gnd */ data->dac_value =3D (inbuf[1] << 4) | (inbuf[2] >> 4); - if (info->chip_id =3D=3D MCP4726) + if (!info->use_ext_ref_voltage) ref =3D (inbuf[3] >> 3) & 0x3; =20 - if (info->chip_id =3D=3D MCP4726 && ref !=3D data->ref_mode) { + if (!info->use_ext_ref_voltage && ref !=3D data->ref_mode) { dev_info(&client->dev, "voltage reference mode differs (conf: %u, eeprom: %u), setting %u", data->ref_mode, ref, data->ref_mode); @@ -515,6 +516,7 @@ static void mcp4725_remove(struct i2c_client *client) static const struct mcp4725_chip_info mcp4725 =3D { .chan_spec =3D &mcp472x_channel[MCP4725], .chip_id =3D MCP4725, + .use_ext_ref_voltage =3D true, }; =20 static const struct mcp4725_chip_info mcp4726 =3D { --=20 2.25.1 From nobody Mon Feb 9 02:03:12 2026 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 726E4C83F2D for ; Sun, 3 Sep 2023 11:56:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236949AbjICL4T (ORCPT ); Sun, 3 Sep 2023 07:56:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230102AbjICL4S (ORCPT ); Sun, 3 Sep 2023 07:56:18 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 902EFE5D; Sun, 3 Sep 2023 04:56:08 -0700 (PDT) X-IronPort-AV: E=Sophos;i="6.02,224,1688396400"; d="scan'208";a="178550485" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 03 Sep 2023 20:56:08 +0900 Received: from localhost.localdomain (unknown [10.226.92.30]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 7053F41C2D99; Sun, 3 Sep 2023 20:56:05 +0900 (JST) From: Biju Das To: Jonathan Cameron Cc: Biju Das , Lars-Peter Clausen , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Marek Vasut , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Biju Das Subject: [PATCH v3 4/4] iio: dac: mcp4725: Add dac_reg_offset to struct mcp4725_chip_info Date: Sun, 3 Sep 2023 12:55:48 +0100 Message-Id: <20230903115548.59306-5-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230903115548.59306-1-biju.das.jz@bp.renesas.com> References: <20230903115548.59306-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The MCP4725 has a register offset '3' for reading DAC value compared to '4' for MCP4726. Add dac_reg_offset variable to struct mcp4725_chip_info to handle this difference. Drop chip_id from struct mcp4725_chip_info as it is unused. Signed-off-by: Biju Das --- v3: * New patch. --- drivers/iio/dac/mcp4725.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/iio/dac/mcp4725.c b/drivers/iio/dac/mcp4725.c index 9cbea6f223e4..25bb1c0490af 100644 --- a/drivers/iio/dac/mcp4725.c +++ b/drivers/iio/dac/mcp4725.c @@ -32,7 +32,7 @@ =20 struct mcp4725_chip_info { const struct iio_chan_spec *chan_spec; - unsigned int chip_id; + u8 dac_reg_offset; bool use_ext_ref_voltage; }; =20 @@ -463,7 +463,7 @@ static int mcp4725_probe(struct i2c_client *client) indio_dev->modes =3D INDIO_DIRECT_MODE; =20 /* read current DAC value and settings */ - err =3D i2c_master_recv(client, inbuf, info->chip_id =3D=3D MCP4725 ? 3 := 4); + err =3D i2c_master_recv(client, inbuf, info->dac_reg_offset); =20 if (err < 0) { dev_err(&client->dev, "failed to read DAC value"); @@ -515,13 +515,13 @@ static void mcp4725_remove(struct i2c_client *client) =20 static const struct mcp4725_chip_info mcp4725 =3D { .chan_spec =3D &mcp472x_channel[MCP4725], - .chip_id =3D MCP4725, + .dac_reg_offset =3D 3, .use_ext_ref_voltage =3D true, }; =20 static const struct mcp4725_chip_info mcp4726 =3D { .chan_spec =3D &mcp472x_channel[MCP4726], - .chip_id =3D MCP4726, + .dac_reg_offset =3D 4, }; =20 static const struct i2c_device_id mcp4725_id[] =3D { --=20 2.25.1