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: amplifiers: ad8366: add device tree support

Drop the enum ID, split chip info table into per-device structs and add
of_match_table. Additionally, add 'name' field into the chip info struct,
dropping the usage of spi_get_device_id().

Signed-off-by: Rodrigo Alencar <rodrigo.alencar@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Rodrigo Alencar and committed by
Jonathan Cameron
d5e02d0d 314b184b

+59 -48
+59 -48
drivers/iio/amplifiers/ad8366.c
··· 29 29 30 30 #include <linux/iio/iio.h> 31 31 32 - enum ad8366_type { 33 - ID_AD8366, 34 - ID_ADA4961, 35 - ID_ADL5240, 36 - ID_HMC792, 37 - ID_HMC1119, 38 - }; 39 - 40 32 struct ad8366_info { 33 + const char *name; 41 34 int gain_min; 42 35 int gain_max; 43 36 int gain_step; ··· 61 68 return sizeof(__be16); 62 69 } 63 70 64 - static const struct ad8366_info ad8366_infos[] = { 65 - [ID_AD8366] = { 66 - .gain_min = 4500, 67 - .gain_max = 20500, 68 - .gain_step = 253, 69 - .num_channels = 2, 70 - .pack_code = ad8366_pack_code, 71 - }, 72 - [ID_ADA4961] = { 73 - .gain_min = -6000, 74 - .gain_max = 15000, 75 - .gain_step = -1000, 76 - .num_channels = 1, 77 - }, 78 - [ID_ADL5240] = { 79 - .gain_min = -11500, 80 - .gain_max = 20000, 81 - .gain_step = 500, 82 - .num_channels = 1, 83 - }, 84 - [ID_HMC792] = { 85 - .gain_min = -15750, 86 - .gain_max = 0, 87 - .gain_step = 250, 88 - .num_channels = 1, 89 - }, 90 - [ID_HMC1119] = { 91 - .gain_min = -31750, 92 - .gain_max = 0, 93 - .gain_step = -250, 94 - .num_channels = 1, 95 - }, 71 + static const struct ad8366_info ad8366_chip_info = { 72 + .name = "ad8366", 73 + .gain_min = 4500, 74 + .gain_max = 20500, 75 + .gain_step = 253, 76 + .num_channels = 2, 77 + .pack_code = ad8366_pack_code, 78 + }; 79 + 80 + static const struct ad8366_info ada4961_chip_info = { 81 + .name = "ada4961", 82 + .gain_min = -6000, 83 + .gain_max = 15000, 84 + .gain_step = -1000, 85 + .num_channels = 1, 86 + }; 87 + 88 + static const struct ad8366_info adl5240_chip_info = { 89 + .name = "adl5240", 90 + .gain_min = -11500, 91 + .gain_max = 20000, 92 + .gain_step = 500, 93 + .num_channels = 1, 94 + }; 95 + 96 + static const struct ad8366_info hmc792_chip_info = { 97 + .name = "hmc792a", 98 + .gain_min = -15750, 99 + .gain_max = 0, 100 + .gain_step = 250, 101 + .num_channels = 1, 102 + }; 103 + 104 + static const struct ad8366_info hmc1119_chip_info = { 105 + .name = "hmc1119", 106 + .gain_min = -31750, 107 + .gain_max = 0, 108 + .gain_step = -250, 109 + .num_channels = 1, 96 110 }; 97 111 98 112 static int ad8366_write_code(struct ad8366_state *st) ··· 237 237 return dev_err_probe(dev, ret, "Failed to get regulator\n"); 238 238 239 239 st->spi = spi; 240 - st->info = &ad8366_infos[spi_get_device_id(spi)->driver_data]; 240 + st->info = spi_get_device_match_data(spi); 241 241 242 242 rstc = devm_reset_control_get_optional_exclusive_deasserted(dev, NULL); 243 243 if (IS_ERR(rstc)) 244 244 return dev_err_probe(dev, PTR_ERR(rstc), 245 245 "Failed to get reset controller\n"); 246 246 247 - indio_dev->name = spi_get_device_id(spi)->name; 247 + indio_dev->name = st->info->name; 248 248 indio_dev->info = &ad8366_info; 249 249 indio_dev->modes = INDIO_DIRECT_MODE; 250 250 indio_dev->channels = ad8366_channels; ··· 258 258 } 259 259 260 260 static const struct spi_device_id ad8366_id[] = { 261 - {"ad8366", ID_AD8366}, 262 - {"ada4961", ID_ADA4961}, 263 - {"adl5240", ID_ADL5240}, 264 - {"hmc792a", ID_HMC792}, 265 - {"hmc1119", ID_HMC1119}, 261 + { "ad8366", (kernel_ulong_t)&ad8366_chip_info }, 262 + { "ada4961", (kernel_ulong_t)&ada4961_chip_info }, 263 + { "adl5240", (kernel_ulong_t)&adl5240_chip_info }, 264 + { "hmc792a", (kernel_ulong_t)&hmc792_chip_info }, 265 + { "hmc1119", (kernel_ulong_t)&hmc1119_chip_info }, 266 266 { } 267 267 }; 268 268 MODULE_DEVICE_TABLE(spi, ad8366_id); 269 269 270 + static const struct of_device_id ad8366_of_match[] = { 271 + { .compatible = "adi,ad8366", .data = &ad8366_chip_info }, 272 + { .compatible = "adi,ada4961", .data = &ada4961_chip_info }, 273 + { .compatible = "adi,adl5240", .data = &adl5240_chip_info }, 274 + { .compatible = "adi,hmc792a", .data = &hmc792_chip_info }, 275 + { .compatible = "adi,hmc1119", .data = &hmc1119_chip_info }, 276 + { } 277 + }; 278 + MODULE_DEVICE_TABLE(of, ad8366_of_match); 279 + 270 280 static struct spi_driver ad8366_driver = { 271 281 .driver = { 272 - .name = KBUILD_MODNAME, 282 + .name = KBUILD_MODNAME, 283 + .of_match_table = ad8366_of_match, 273 284 }, 274 285 .probe = ad8366_probe, 275 286 .id_table = ad8366_id,