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: sca3000: simplify with spi_get_device_match_data()

Refactor each sca3000 variant with it's own chip_info struct, update the
sca3000_probe() to use spi_get_device_match_data().

Suggested-by: David Lechner <dlechner@baylibre.com>
Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Harshit Mogalapalli and committed by
Jonathan Cameron
d6ae9f20 094d5d37

+59 -68
+59 -68
drivers/iio/accel/sca3000.c
··· 171 171 172 172 /** 173 173 * struct sca3000_chip_info - model dependent parameters 174 + * @name: name of the chip 174 175 * @scale: scale * 10^-6 175 176 * @temp_output: some devices have temperature sensors. 176 177 * @measurement_mode_freq: normal mode sampling frequency ··· 194 193 * sca3000 variant. 195 194 **/ 196 195 struct sca3000_chip_info { 196 + const char *name; 197 197 unsigned int scale; 198 198 bool temp_output; 199 199 int measurement_mode_freq; ··· 209 207 int mot_det_mult_y[7]; 210 208 }; 211 209 212 - enum sca3000_variant { 213 - d01, 214 - e02, 215 - e04, 216 - e05, 210 + static const struct sca3000_chip_info sca3000_chip_info_d01 = { 211 + .name = "sca3000_d01", 212 + .scale = 7357, 213 + .temp_output = true, 214 + .measurement_mode_freq = 250, 215 + .measurement_mode_3db_freq = 45, 216 + .option_mode_1 = SCA3000_OP_MODE_BYPASS, 217 + .option_mode_1_freq = 250, 218 + .option_mode_1_3db_freq = 70, 219 + .mot_det_mult_xz = { 50, 100, 200, 350, 650, 1300 }, 220 + .mot_det_mult_y = { 50, 100, 150, 250, 450, 850, 1750 }, 217 221 }; 218 222 219 - /* 220 - * Note where option modes are not defined, the chip simply does not 221 - * support any. 222 - * Other chips in the sca3000 series use i2c and are not included here. 223 - * 224 - * Some of these devices are only listed in the family data sheet and 225 - * do not actually appear to be available. 226 - */ 227 - static const struct sca3000_chip_info sca3000_spi_chip_info_tbl[] = { 228 - [d01] = { 229 - .scale = 7357, 230 - .temp_output = true, 231 - .measurement_mode_freq = 250, 232 - .measurement_mode_3db_freq = 45, 233 - .option_mode_1 = SCA3000_OP_MODE_BYPASS, 234 - .option_mode_1_freq = 250, 235 - .option_mode_1_3db_freq = 70, 236 - .mot_det_mult_xz = {50, 100, 200, 350, 650, 1300}, 237 - .mot_det_mult_y = {50, 100, 150, 250, 450, 850, 1750}, 238 - }, 239 - [e02] = { 240 - .scale = 9810, 241 - .measurement_mode_freq = 125, 242 - .measurement_mode_3db_freq = 40, 243 - .option_mode_1 = SCA3000_OP_MODE_NARROW, 244 - .option_mode_1_freq = 63, 245 - .option_mode_1_3db_freq = 11, 246 - .mot_det_mult_xz = {100, 150, 300, 550, 1050, 2050}, 247 - .mot_det_mult_y = {50, 100, 200, 350, 700, 1350, 2700}, 248 - }, 249 - [e04] = { 250 - .scale = 19620, 251 - .measurement_mode_freq = 100, 252 - .measurement_mode_3db_freq = 38, 253 - .option_mode_1 = SCA3000_OP_MODE_NARROW, 254 - .option_mode_1_freq = 50, 255 - .option_mode_1_3db_freq = 9, 256 - .option_mode_2 = SCA3000_OP_MODE_WIDE, 257 - .option_mode_2_freq = 400, 258 - .option_mode_2_3db_freq = 70, 259 - .mot_det_mult_xz = {200, 300, 600, 1100, 2100, 4100}, 260 - .mot_det_mult_y = {100, 200, 400, 7000, 1400, 2700, 54000}, 261 - }, 262 - [e05] = { 263 - .scale = 61313, 264 - .measurement_mode_freq = 200, 265 - .measurement_mode_3db_freq = 60, 266 - .option_mode_1 = SCA3000_OP_MODE_NARROW, 267 - .option_mode_1_freq = 50, 268 - .option_mode_1_3db_freq = 9, 269 - .option_mode_2 = SCA3000_OP_MODE_WIDE, 270 - .option_mode_2_freq = 400, 271 - .option_mode_2_3db_freq = 75, 272 - .mot_det_mult_xz = {600, 900, 1700, 3200, 6100, 11900}, 273 - .mot_det_mult_y = {300, 600, 1200, 2000, 4100, 7800, 15600}, 274 - }, 223 + static const struct sca3000_chip_info sca3000_chip_info_e02 = { 224 + .name = "sca3000_e02", 225 + .scale = 9810, 226 + .measurement_mode_freq = 125, 227 + .measurement_mode_3db_freq = 40, 228 + .option_mode_1 = SCA3000_OP_MODE_NARROW, 229 + .option_mode_1_freq = 63, 230 + .option_mode_1_3db_freq = 11, 231 + .mot_det_mult_xz = { 100, 150, 300, 550, 1050, 2050 }, 232 + .mot_det_mult_y = { 50, 100, 200, 350, 700, 1350, 2700 }, 233 + }; 234 + 235 + static const struct sca3000_chip_info sca3000_chip_info_e04 = { 236 + .name = "sca3000_e04", 237 + .scale = 19620, 238 + .measurement_mode_freq = 100, 239 + .measurement_mode_3db_freq = 38, 240 + .option_mode_1 = SCA3000_OP_MODE_NARROW, 241 + .option_mode_1_freq = 50, 242 + .option_mode_1_3db_freq = 9, 243 + .option_mode_2 = SCA3000_OP_MODE_WIDE, 244 + .option_mode_2_freq = 400, 245 + .option_mode_2_3db_freq = 70, 246 + .mot_det_mult_xz = { 200, 300, 600, 1100, 2100, 4100 }, 247 + .mot_det_mult_y = { 100, 200, 400, 7000, 1400, 2700, 54000 }, 248 + }; 249 + 250 + static const struct sca3000_chip_info sca3000_chip_info_e05 = { 251 + .name = "sca3000_e05", 252 + .scale = 61313, 253 + .measurement_mode_freq = 200, 254 + .measurement_mode_3db_freq = 60, 255 + .option_mode_1 = SCA3000_OP_MODE_NARROW, 256 + .option_mode_1_freq = 50, 257 + .option_mode_1_3db_freq = 9, 258 + .option_mode_2 = SCA3000_OP_MODE_WIDE, 259 + .option_mode_2_freq = 400, 260 + .option_mode_2_3db_freq = 75, 261 + .mot_det_mult_xz = { 600, 900, 1700, 3200, 6100, 11900 }, 262 + .mot_det_mult_y = { 300, 600, 1200, 2000, 4100, 7800, 15600 }, 275 263 }; 276 264 277 265 static int sca3000_write_reg(struct sca3000_state *st, u8 address, u8 val) ··· 1441 1449 spi_set_drvdata(spi, indio_dev); 1442 1450 st->us = spi; 1443 1451 mutex_init(&st->lock); 1444 - st->info = &sca3000_spi_chip_info_tbl[spi_get_device_id(spi) 1445 - ->driver_data]; 1452 + st->info = spi_get_device_match_data(spi); 1446 1453 1447 - indio_dev->name = spi_get_device_id(spi)->name; 1454 + indio_dev->name = st->info->name; 1448 1455 indio_dev->info = &sca3000_info; 1449 1456 if (st->info->temp_output) { 1450 1457 indio_dev->channels = sca3000_channels_with_temp; ··· 1523 1532 } 1524 1533 1525 1534 static const struct spi_device_id sca3000_id[] = { 1526 - {"sca3000_d01", d01}, 1527 - {"sca3000_e02", e02}, 1528 - {"sca3000_e04", e04}, 1529 - {"sca3000_e05", e05}, 1535 + { "sca3000_d01", (kernel_ulong_t)&sca3000_chip_info_d01 }, 1536 + { "sca3000_e02", (kernel_ulong_t)&sca3000_chip_info_e02 }, 1537 + { "sca3000_e04", (kernel_ulong_t)&sca3000_chip_info_e04 }, 1538 + { "sca3000_e05", (kernel_ulong_t)&sca3000_chip_info_e05 }, 1530 1539 { } 1531 1540 }; 1532 1541 MODULE_DEVICE_TABLE(spi, sca3000_id);