From nobody Wed Feb 11 02:33:35 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88C76342CA7 for ; Tue, 10 Feb 2026 13:51:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770731477; cv=none; b=DO+veSjIKHgoGmjKc6bXjzTHU619Wa0RSFi/p11tU8Lsv6+wIR6Dn5tfm2LwQQwiQnSXT39cFleQpof0r/uKzXUlDsV2nKWcWWbqMnkoP3YcDKhUsaHMtZ+SmkBNRFDSs6lncAbYQCmPKqu6Gj+w8+9lIS86XzItFUMZCD94AEM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770731477; c=relaxed/simple; bh=7dbgM/fiez4ysPFBLTptUiSY/MFna2Qw7TSTnE50WCg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oYDB1uU58HHfhhq4FajyRTQnG+gF0LuszQZtSCTy1qDQfasJ/Pf7g44pUyadbXexbqEq6GIV9j2uZpNk5hFOTym2pOt5hYk7rHESjacZbrFNe0nN1HmvMABKbhSi3vxQ3xllRNwFJU5zW0oXA60hJyuX4if0XCYiqEaZJjhWDWI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1vpo93-0005dK-HX; Tue, 10 Feb 2026 14:51:13 +0100 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac] helo=dude04) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vpo92-0005d6-0M; Tue, 10 Feb 2026 14:51:12 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vpo92-00000008VNq-3OEz; Tue, 10 Feb 2026 14:51:12 +0100 From: Oleksij Rempel To: Jonathan Cameron , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, Andy Shevchenko , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , David Jander Subject: [PATCH v6 05/12] iio: dac: ds4424: use device match data for chip info Date: Tue, 10 Feb 2026 14:51:03 +0100 Message-ID: <20260210135110.2027073-6-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260210135110.2027073-1-o.rempel@pengutronix.de> References: <20260210135110.2027073-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Refactor the driver to use device match data instead of checking ID enums in a switch statement. Define a `ds4424_chip_info` structure to hold variant-specific attributes (currently just the channel count) and attach it directly to the I2C and OF device ID tables. This simplifies the probe function and makes it easier to add support for new variants like DS4402/DS4404. Signed-off-by: Oleksij Rempel --- changes v6: - assign predictable name to indio_dev->name. changes v5: - drop client->name change changes v4: - New patch --- drivers/iio/dac/ds4424.c | 47 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/drivers/iio/dac/ds4424.c b/drivers/iio/dac/ds4424.c index 3385f39521d9..c9d3110eac28 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -34,9 +34,19 @@ .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW), \ } =20 -enum ds4424_device_ids { - ID_DS4422, - ID_DS4424, +struct ds4424_chip_info { + const char *name; + u8 num_channels; +}; + +static const struct ds4424_chip_info ds4422_info =3D { + .name =3D "ds4422", + .num_channels =3D DS4422_MAX_DAC_CHANNELS, +}; + +static const struct ds4424_chip_info ds4424_info =3D { + .name =3D "ds4424", + .num_channels =3D DS4424_MAX_DAC_CHANNELS, }; =20 struct ds4424_data { @@ -204,11 +214,15 @@ static const struct iio_info ds4424_iio_info =3D { =20 static int ds4424_probe(struct i2c_client *client) { - const struct i2c_device_id *id =3D i2c_client_get_device_id(client); + const struct ds4424_chip_info *chip_info; struct ds4424_data *data; struct iio_dev *indio_dev; int ret; =20 + chip_info =3D i2c_get_match_data(client); + if (!chip_info) + return -ENODEV; + indio_dev =3D devm_iio_device_alloc(&client->dev, sizeof(*data)); if (!indio_dev) return -ENOMEM; @@ -216,7 +230,7 @@ static int ds4424_probe(struct i2c_client *client) data =3D iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); data->client =3D client; - indio_dev->name =3D id->name; + indio_dev->name =3D chip_info->name; =20 data->vcc_reg =3D devm_regulator_get(&client->dev, "vcc"); if (IS_ERR(data->vcc_reg)) @@ -236,20 +250,7 @@ static int ds4424_probe(struct i2c_client *client) if (ret < 0) goto fail; =20 - switch (id->driver_data) { - case ID_DS4422: - indio_dev->num_channels =3D DS4422_MAX_DAC_CHANNELS; - break; - case ID_DS4424: - indio_dev->num_channels =3D DS4424_MAX_DAC_CHANNELS; - break; - default: - dev_err(&client->dev, - "ds4424: Invalid chip id.\n"); - ret =3D -ENXIO; - goto fail; - } - + indio_dev->num_channels =3D chip_info->num_channels; indio_dev->channels =3D ds4424_channels; indio_dev->modes =3D INDIO_DIRECT_MODE; indio_dev->info =3D &ds4424_iio_info; @@ -278,16 +279,16 @@ static void ds4424_remove(struct i2c_client *client) } =20 static const struct i2c_device_id ds4424_id[] =3D { - { "ds4422", ID_DS4422 }, - { "ds4424", ID_DS4424 }, + { "ds4422", (kernel_ulong_t)&ds4422_info }, + { "ds4424", (kernel_ulong_t)&ds4424_info }, { } }; =20 MODULE_DEVICE_TABLE(i2c, ds4424_id); =20 static const struct of_device_id ds4424_of_match[] =3D { - { .compatible =3D "maxim,ds4422" }, - { .compatible =3D "maxim,ds4424" }, + { .compatible =3D "maxim,ds4422", .data =3D &ds4422_info }, + { .compatible =3D "maxim,ds4424", .data =3D &ds4424_info }, { } }; =20 --=20 2.47.3