From nobody Tue Feb 10 09:24:26 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 B287C3148B4 for ; Tue, 3 Feb 2026 09:34:37 +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=1770111283; cv=none; b=Ix01QBvxEQUzODh/2hMUcaz6tTSq0bx1/V24iIS3StNiklKPEQn2Uj1os992YQgJT498A7ysZBSKaI+z0XG0fUTqZwP7Ag9BxCUjwX/QIsNhpIVpcfFMDrh7MAqY+k+i8kFviTjIHxh9QMc0aXEApE9RRvPx9jxb0XBplwoi6E8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770111283; c=relaxed/simple; bh=zwBYqkLNtbhXVbgrsrQaASQJCt7kvW7S2MFFwDgGVuw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bZJ35jG4hseZhCoXVsWLqMlDySTIdhnjcUJ1TeO85Ylc7VN9tpV9mX+lAmkDtGLgGqgoFis3hzRDNLee8olbj5VtnwFBRrGe0Y+xRdZqKfgBG2kUqfYbP6queAzyMLvHq6dmhihMUIq4d19DxEMTvupPCEGwxm0cDIgBzXkgbzA= 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 1vnCnr-0003lc-Q9; Tue, 03 Feb 2026 10:34:35 +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 1vnCnr-003slV-36; Tue, 03 Feb 2026 10:34:35 +0100 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1vnCnr-0000000Ah9c-0icp; Tue, 03 Feb 2026 10:34:35 +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 v4 06/13] iio: dac: ds4424: use device match data for chip info Date: Tue, 3 Feb 2026 10:34:26 +0100 Message-ID: <20260203093434.2548978-7-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260203093434.2548978-1-o.rempel@pengutronix.de> References: <20260203093434.2548978-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. Use `client->name` instead of `id->name` to decouple the probe function from the legacy `i2c_device_id` structure. This simplifies the probe function and makes it easier to add support for new variants like DS4402/DS4404. Signed-off-by: Oleksij Rempel --- changes v4: - New patch --- drivers/iio/dac/ds4424.c | 44 +++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/drivers/iio/dac/ds4424.c b/drivers/iio/dac/ds4424.c index 3385f39521d9..5709d8a39d7b 100644 --- a/drivers/iio/dac/ds4424.c +++ b/drivers/iio/dac/ds4424.c @@ -34,9 +34,16 @@ .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW), \ } =20 -enum ds4424_device_ids { - ID_DS4422, - ID_DS4424, +struct ds4424_chip_info { + u8 num_channels; +}; + +static const struct ds4424_chip_info ds4422_info =3D { + .num_channels =3D DS4422_MAX_DAC_CHANNELS, +}; + +static const struct ds4424_chip_info ds4424_info =3D { + .num_channels =3D DS4424_MAX_DAC_CHANNELS, }; =20 struct ds4424_data { @@ -204,11 +211,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 +227,6 @@ 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; =20 data->vcc_reg =3D devm_regulator_get(&client->dev, "vcc"); if (IS_ERR(data->vcc_reg)) @@ -236,20 +246,8 @@ 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->name =3D client->name; + 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 +276,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