]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iio: pressure: dlhl60d: Use separate structures rather than an array for chip info
authorDavid Lechner <dlechner@baylibre.com>
Sat, 28 Jun 2025 18:15:10 +0000 (13:15 -0500)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 13 Jul 2025 14:36:24 +0000 (15:36 +0100)
Change the dlhl60d driver to use individual chip info structures instead
of an array. This reduces the verbosity of the code. Also, the data is
now const as it should have been in the first place.

Signed-off-by: David Lechner <dlechner@baylibre.com>
Link: https://patch.msgid.link/20250628-iio-const-data-24-v2-1-1c90073d1323@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/pressure/dlhl60d.c

index 48afe5c94000b44eb324d7631f3c0db8e3d0079e..6a13cf2eaf50187d4cbd94cd93b1d14ad4de8b26 100644 (file)
 /* DLH  timings */
 #define DLH_SINGLE_DUT_MS   5
 
-enum dhl_ids {
-       dlhl60d,
-       dlhl60g,
-};
-
 struct dlh_info {
+       const char *name;   /* chip name */
        u8 osdig;           /* digital offset factor */
        unsigned int fss;   /* full scale span (inch H2O) */
 };
 
 struct dlh_state {
        struct i2c_client *client;
-       struct dlh_info info;
+       const struct dlh_info *info;
        bool use_interrupt;
        struct completion completion;
        u8 rx_buf[DLH_NUM_READ_BYTES];
 };
 
-static struct dlh_info dlh_info_tbl[] = {
-       [dlhl60d] = {
-               .osdig = 2,
-               .fss = 120,
-       },
-       [dlhl60g] = {
-               .osdig = 10,
-               .fss = 60,
-       },
+static const struct dlh_info dlhl60d_info = {
+       .name = "dlhl60d",
+       .osdig = 2,
+       .fss = 120,
 };
 
+static const struct dlh_info dlhl60g_info = {
+       .name = "dlhl60g",
+       .osdig = 10,
+       .fss = 60,
+};
 
 static int dlh_cmd_start_single(struct dlh_state *st)
 {
@@ -170,7 +166,7 @@ static int dlh_read_raw(struct iio_dev *indio_dev,
        case IIO_CHAN_INFO_SCALE:
                switch (channel->type) {
                case IIO_PRESSURE:
-                       tmp = div_s64(125LL * st->info.fss * 24909 * 100,
+                       tmp = div_s64(125LL * st->info->fss * 24909 * 100,
                                1 << DLH_NUM_PR_BITS);
                        tmp = div_s64_rem(tmp, 1000000000LL, &rem);
                        *value = tmp;
@@ -188,8 +184,8 @@ static int dlh_read_raw(struct iio_dev *indio_dev,
        case IIO_CHAN_INFO_OFFSET:
                switch (channel->type) {
                case IIO_PRESSURE:
-                       *value = -125 * st->info.fss * 24909;
-                       *value2 = 100 * st->info.osdig * 100000;
+                       *value = -125 * st->info->fss * 24909;
+                       *value2 = 100 * st->info->osdig * 100000;
                        return IIO_VAL_FRACTIONAL;
 
                case IIO_TEMP:
@@ -281,7 +277,6 @@ static irqreturn_t dlh_interrupt(int irq, void *private)
 
 static int dlh_probe(struct i2c_client *client)
 {
-       const struct i2c_device_id *id = i2c_client_get_device_id(client);
        struct dlh_state *st;
        struct iio_dev *indio_dev;
        int ret;
@@ -302,11 +297,11 @@ static int dlh_probe(struct i2c_client *client)
        i2c_set_clientdata(client, indio_dev);
 
        st = iio_priv(indio_dev);
-       st->info = dlh_info_tbl[id->driver_data];
+       st->info = i2c_get_match_data(client);
        st->client = client;
        st->use_interrupt = false;
 
-       indio_dev->name = id->name;
+       indio_dev->name = st->info->name;
        indio_dev->info = &dlh_info;
        indio_dev->modes = INDIO_DIRECT_MODE;
        indio_dev->channels =  dlh_channels;
@@ -316,7 +311,7 @@ static int dlh_probe(struct i2c_client *client)
                ret = devm_request_threaded_irq(&client->dev, client->irq,
                        dlh_interrupt, NULL,
                        IRQF_TRIGGER_RISING | IRQF_ONESHOT,
-                       id->name, indio_dev);
+                       st->info->name, indio_dev);
                if (ret) {
                        dev_err(&client->dev, "failed to allocate threaded irq");
                        return ret;
@@ -341,15 +336,15 @@ static int dlh_probe(struct i2c_client *client)
 }
 
 static const struct of_device_id dlh_of_match[] = {
-       { .compatible = "asc,dlhl60d" },
-       { .compatible = "asc,dlhl60g" },
+       { .compatible = "asc,dlhl60d", .data = &dlhl60d_info },
+       { .compatible = "asc,dlhl60g", .data = &dlhl60g_info },
        { }
 };
 MODULE_DEVICE_TABLE(of, dlh_of_match);
 
 static const struct i2c_device_id dlh_id[] = {
-       { "dlhl60d",    dlhl60d },
-       { "dlhl60g",    dlhl60g },
+       { "dlhl60d", (kernel_ulong_t)&dlhl60d_info },
+       { "dlhl60g", (kernel_ulong_t)&dlhl60g_info },
        { }
 };
 MODULE_DEVICE_TABLE(i2c, dlh_id);