Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: pressure: dlhl60d: Use separate structures rather than an array for chip info

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>

authored by

David Lechner and committed by
Jonathan Cameron
0f7797f6 50df7043

+21 -26
+21 -26
drivers/iio/pressure/dlhl60d.c
··· 32 32 /* DLH timings */ 33 33 #define DLH_SINGLE_DUT_MS 5 34 34 35 - enum dhl_ids { 36 - dlhl60d, 37 - dlhl60g, 38 - }; 39 - 40 35 struct dlh_info { 36 + const char *name; /* chip name */ 41 37 u8 osdig; /* digital offset factor */ 42 38 unsigned int fss; /* full scale span (inch H2O) */ 43 39 }; 44 40 45 41 struct dlh_state { 46 42 struct i2c_client *client; 47 - struct dlh_info info; 43 + const struct dlh_info *info; 48 44 bool use_interrupt; 49 45 struct completion completion; 50 46 u8 rx_buf[DLH_NUM_READ_BYTES]; 51 47 }; 52 48 53 - static struct dlh_info dlh_info_tbl[] = { 54 - [dlhl60d] = { 55 - .osdig = 2, 56 - .fss = 120, 57 - }, 58 - [dlhl60g] = { 59 - .osdig = 10, 60 - .fss = 60, 61 - }, 49 + static const struct dlh_info dlhl60d_info = { 50 + .name = "dlhl60d", 51 + .osdig = 2, 52 + .fss = 120, 62 53 }; 63 54 55 + static const struct dlh_info dlhl60g_info = { 56 + .name = "dlhl60g", 57 + .osdig = 10, 58 + .fss = 60, 59 + }; 64 60 65 61 static int dlh_cmd_start_single(struct dlh_state *st) 66 62 { ··· 166 170 case IIO_CHAN_INFO_SCALE: 167 171 switch (channel->type) { 168 172 case IIO_PRESSURE: 169 - tmp = div_s64(125LL * st->info.fss * 24909 * 100, 173 + tmp = div_s64(125LL * st->info->fss * 24909 * 100, 170 174 1 << DLH_NUM_PR_BITS); 171 175 tmp = div_s64_rem(tmp, 1000000000LL, &rem); 172 176 *value = tmp; ··· 184 188 case IIO_CHAN_INFO_OFFSET: 185 189 switch (channel->type) { 186 190 case IIO_PRESSURE: 187 - *value = -125 * st->info.fss * 24909; 188 - *value2 = 100 * st->info.osdig * 100000; 191 + *value = -125 * st->info->fss * 24909; 192 + *value2 = 100 * st->info->osdig * 100000; 189 193 return IIO_VAL_FRACTIONAL; 190 194 191 195 case IIO_TEMP: ··· 277 281 278 282 static int dlh_probe(struct i2c_client *client) 279 283 { 280 - const struct i2c_device_id *id = i2c_client_get_device_id(client); 281 284 struct dlh_state *st; 282 285 struct iio_dev *indio_dev; 283 286 int ret; ··· 297 302 i2c_set_clientdata(client, indio_dev); 298 303 299 304 st = iio_priv(indio_dev); 300 - st->info = dlh_info_tbl[id->driver_data]; 305 + st->info = i2c_get_match_data(client); 301 306 st->client = client; 302 307 st->use_interrupt = false; 303 308 304 - indio_dev->name = id->name; 309 + indio_dev->name = st->info->name; 305 310 indio_dev->info = &dlh_info; 306 311 indio_dev->modes = INDIO_DIRECT_MODE; 307 312 indio_dev->channels = dlh_channels; ··· 311 316 ret = devm_request_threaded_irq(&client->dev, client->irq, 312 317 dlh_interrupt, NULL, 313 318 IRQF_TRIGGER_RISING | IRQF_ONESHOT, 314 - id->name, indio_dev); 319 + st->info->name, indio_dev); 315 320 if (ret) { 316 321 dev_err(&client->dev, "failed to allocate threaded irq"); 317 322 return ret; ··· 336 341 } 337 342 338 343 static const struct of_device_id dlh_of_match[] = { 339 - { .compatible = "asc,dlhl60d" }, 340 - { .compatible = "asc,dlhl60g" }, 344 + { .compatible = "asc,dlhl60d", .data = &dlhl60d_info }, 345 + { .compatible = "asc,dlhl60g", .data = &dlhl60g_info }, 341 346 { } 342 347 }; 343 348 MODULE_DEVICE_TABLE(of, dlh_of_match); 344 349 345 350 static const struct i2c_device_id dlh_id[] = { 346 - { "dlhl60d", dlhl60d }, 347 - { "dlhl60g", dlhl60g }, 351 + { "dlhl60d", (kernel_ulong_t)&dlhl60d_info }, 352 + { "dlhl60g", (kernel_ulong_t)&dlhl60g_info }, 348 353 { } 349 354 }; 350 355 MODULE_DEVICE_TABLE(i2c, dlh_id);