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: adc: adc128s052: Simplify matching chip_data

The adc128s052 driver supports a few different ICs. IC specific
configuration data is stored in an array. IC data, residing in a
specific point of the array, is pointed from the SPI device match data.

There is no need to have the chip config data structures in an array
and splitting them out of an array has at least following benefits:

- Chip-specific structures can be named after the chips they support.
This makes referring them a tad cleaner, compared to using a generic
array name with a numerical index.

- Avoid all potential 'out of bounds' errors which can result if the
array is changed.

Split the chip configuration data array to individual structures.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Link: https://patch.msgid.link/943b6f4852ff0944eeaa0366cbe3b5aaf440cf23.1755504346.git.mazziesaccount@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Matti Vaittinen and committed by
Jonathan Cameron
7fe5b83f f1bbfc40

+41 -37
+41 -37
drivers/iio/adc/ti-adc128s052.c
··· 124 124 125 125 static const char * const bd79104_regulators[] = { "iovdd" }; 126 126 127 - static const struct adc128_configuration adc128_config[] = { 128 - { 129 - .channels = adc128s052_channels, 130 - .num_channels = ARRAY_SIZE(adc128s052_channels), 131 - .refname = "vref", 132 - }, { 133 - .channels = adc122s021_channels, 134 - .num_channels = ARRAY_SIZE(adc122s021_channels), 135 - .refname = "vref", 136 - }, { 137 - .channels = adc124s021_channels, 138 - .num_channels = ARRAY_SIZE(adc124s021_channels), 139 - .refname = "vref", 140 - }, { 141 - .channels = adc128s052_channels, 142 - .num_channels = ARRAY_SIZE(adc128s052_channels), 143 - .refname = "vdd", 144 - .other_regulators = &bd79104_regulators, 145 - .num_other_regulators = 1, 146 - }, 127 + static const struct adc128_configuration adc122s_config = { 128 + .channels = adc122s021_channels, 129 + .num_channels = ARRAY_SIZE(adc122s021_channels), 130 + .refname = "vref", 131 + }; 132 + 133 + static const struct adc128_configuration adc124s_config = { 134 + .channels = adc124s021_channels, 135 + .num_channels = ARRAY_SIZE(adc124s021_channels), 136 + .refname = "vref", 137 + }; 138 + 139 + static const struct adc128_configuration adc128s_config = { 140 + .channels = adc128s052_channels, 141 + .num_channels = ARRAY_SIZE(adc128s052_channels), 142 + .refname = "vref", 143 + }; 144 + 145 + static const struct adc128_configuration bd79104_config = { 146 + .channels = adc128s052_channels, 147 + .num_channels = ARRAY_SIZE(adc128s052_channels), 148 + .refname = "vdd", 149 + .other_regulators = &bd79104_regulators, 150 + .num_other_regulators = 1, 147 151 }; 148 152 149 153 static const struct iio_info adc128_info = { ··· 203 199 } 204 200 205 201 static const struct of_device_id adc128_of_match[] = { 206 - { .compatible = "ti,adc128s052", .data = &adc128_config[0] }, 207 - { .compatible = "ti,adc122s021", .data = &adc128_config[1] }, 208 - { .compatible = "ti,adc122s051", .data = &adc128_config[1] }, 209 - { .compatible = "ti,adc122s101", .data = &adc128_config[1] }, 210 - { .compatible = "ti,adc124s021", .data = &adc128_config[2] }, 211 - { .compatible = "ti,adc124s051", .data = &adc128_config[2] }, 212 - { .compatible = "ti,adc124s101", .data = &adc128_config[2] }, 213 - { .compatible = "rohm,bd79104", .data = &adc128_config[3] }, 202 + { .compatible = "ti,adc128s052", .data = &adc128s_config }, 203 + { .compatible = "ti,adc122s021", .data = &adc122s_config }, 204 + { .compatible = "ti,adc122s051", .data = &adc122s_config }, 205 + { .compatible = "ti,adc122s101", .data = &adc122s_config }, 206 + { .compatible = "ti,adc124s021", .data = &adc124s_config }, 207 + { .compatible = "ti,adc124s051", .data = &adc124s_config }, 208 + { .compatible = "ti,adc124s101", .data = &adc124s_config }, 209 + { .compatible = "rohm,bd79104", .data = &bd79104_config }, 214 210 { } 215 211 }; 216 212 MODULE_DEVICE_TABLE(of, adc128_of_match); 217 213 218 214 static const struct spi_device_id adc128_id[] = { 219 - { "adc128s052", (kernel_ulong_t)&adc128_config[0] }, 220 - { "adc122s021", (kernel_ulong_t)&adc128_config[1] }, 221 - { "adc122s051", (kernel_ulong_t)&adc128_config[1] }, 222 - { "adc122s101", (kernel_ulong_t)&adc128_config[1] }, 223 - { "adc124s021", (kernel_ulong_t)&adc128_config[2] }, 224 - { "adc124s051", (kernel_ulong_t)&adc128_config[2] }, 225 - { "adc124s101", (kernel_ulong_t)&adc128_config[2] }, 226 - { "bd79104", (kernel_ulong_t)&adc128_config[3] }, 215 + { "adc128s052", (kernel_ulong_t)&adc128s_config }, 216 + { "adc122s021", (kernel_ulong_t)&adc122s_config }, 217 + { "adc122s051", (kernel_ulong_t)&adc122s_config }, 218 + { "adc122s101", (kernel_ulong_t)&adc122s_config }, 219 + { "adc124s021", (kernel_ulong_t)&adc124s_config }, 220 + { "adc124s051", (kernel_ulong_t)&adc124s_config }, 221 + { "adc124s101", (kernel_ulong_t)&adc124s_config }, 222 + { "bd79104", (kernel_ulong_t)&bd79104_config }, 227 223 { } 228 224 }; 229 225 MODULE_DEVICE_TABLE(spi, adc128_id); 230 226 231 227 static const struct acpi_device_id adc128_acpi_match[] = { 232 - { "AANT1280", (kernel_ulong_t)&adc128_config[2] }, 228 + { "AANT1280", (kernel_ulong_t)&adc124s_config }, 233 229 { } 234 230 }; 235 231 MODULE_DEVICE_TABLE(acpi, adc128_acpi_match);