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

Input: rotary_encoder - move away from platform data structure

Drop support for platform data passed via a C-structure and switch to
device properties instead, which should make the driver compatible with all
platforms: OF, ACPI and static boards. Static boards should use property
sets to communicate device parameters to the driver.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+76 -112
+21 -8
arch/arm/mach-pxa/raumfeld.c
··· 18 18 19 19 #include <linux/init.h> 20 20 #include <linux/kernel.h> 21 + #include <linux/property.h> 21 22 #include <linux/platform_device.h> 22 23 #include <linux/interrupt.h> 23 24 #include <linux/gpio.h> 24 25 #include <linux/gpio/machine.h> 25 26 #include <linux/smsc911x.h> 26 27 #include <linux/input.h> 27 - #include <linux/rotary_encoder.h> 28 28 #include <linux/gpio_keys.h> 29 29 #include <linux/input/eeti_ts.h> 30 30 #include <linux/leds.h> ··· 378 378 }, 379 379 }; 380 380 381 - static struct rotary_encoder_platform_data raumfeld_rotary_encoder_info = { 382 - .steps = 24, 383 - .axis = REL_X, 384 - .relative_axis = 1, 381 + static u32 raumfeld_rotary_encoder_steps = 24; 382 + static u32 raumfeld_rotary_encoder_axis = REL_X; 383 + static u32 raumfeld_rotary_encoder_relative_axis = 1; 384 + 385 + static struct property_entry raumfeld_rotary_properties[] = { 386 + { "rotary-encoder,steps-per-period", 387 + DEV_PROP_U32, 1, &raumfeld_rotary_encoder_steps, }, 388 + { "linux,axis", 389 + DEV_PROP_U32, 1, &raumfeld_rotary_encoder_axis, }, 390 + { "rotary-encoder,relative_axis", 391 + DEV_PROP_U32, 1, &raumfeld_rotary_encoder_relative_axis, }, 392 + { NULL } 393 + }; 394 + 395 + static struct property_set raumfeld_rotary_property_set = { 396 + .properties = raumfeld_rotary_properties, 385 397 }; 386 398 387 399 static struct platform_device rotary_encoder_device = { 388 400 .name = "rotary-encoder", 389 401 .id = 0, 390 - .dev = { 391 - .platform_data = &raumfeld_rotary_encoder_info, 392 - } 393 402 }; 394 403 395 404 /** ··· 1070 1061 pxa3xx_mfp_config(ARRAY_AND_SIZE(raumfeld_controller_pin_config)); 1071 1062 1072 1063 gpiod_add_lookup_table(&raumfeld_rotary_gpios_table); 1064 + device_add_property_set(&rotary_encoder_device.dev, 1065 + &raumfeld_rotary_property_set); 1073 1066 platform_device_register(&rotary_encoder_device); 1074 1067 1075 1068 spi_register_board_info(ARRAY_AND_SIZE(controller_spi_devices)); ··· 1110 1099 platform_device_register(&smc91x_device); 1111 1100 1112 1101 gpiod_add_lookup_table(&raumfeld_rotary_gpios_table); 1102 + device_add_property_set(&rotary_encoder_device.dev, 1103 + &raumfeld_rotary_property_set); 1113 1104 platform_device_register(&rotary_encoder_device); 1114 1105 1115 1106 raumfeld_audio_init();
+55 -91
drivers/input/misc/rotary_encoder.c
··· 21 21 #include <linux/device.h> 22 22 #include <linux/platform_device.h> 23 23 #include <linux/gpio/consumer.h> 24 - #include <linux/rotary_encoder.h> 25 24 #include <linux/slab.h> 26 25 #include <linux/of.h> 27 - #include <linux/of_platform.h> 28 26 #include <linux/pm.h> 27 + #include <linux/property.h> 29 28 30 29 #define DRV_NAME "rotary-encoder" 31 30 32 31 struct rotary_encoder { 33 32 struct input_dev *input; 34 - const struct rotary_encoder_platform_data *pdata; 33 + 35 34 struct mutex access_mutex; 36 35 37 - unsigned int axis; 36 + u32 steps; 37 + u32 axis; 38 + bool relative_axis; 39 + bool rollover; 40 + 38 41 unsigned int pos; 39 42 40 43 struct gpio_desc *gpio_a; ··· 62 59 63 60 static void rotary_encoder_report_event(struct rotary_encoder *encoder) 64 61 { 65 - const struct rotary_encoder_platform_data *pdata = encoder->pdata; 66 - 67 - if (pdata->relative_axis) { 62 + if (encoder->relative_axis) { 68 63 input_report_rel(encoder->input, 69 - pdata->axis, encoder->dir ? -1 : 1); 64 + encoder->axis, encoder->dir ? -1 : 1); 70 65 } else { 71 66 unsigned int pos = encoder->pos; 72 67 73 68 if (encoder->dir) { 74 69 /* turning counter-clockwise */ 75 - if (pdata->rollover) 76 - pos += pdata->steps; 70 + if (encoder->rollover) 71 + pos += encoder->steps; 77 72 if (pos) 78 73 pos--; 79 74 } else { 80 75 /* turning clockwise */ 81 - if (pdata->rollover || pos < pdata->steps) 76 + if (encoder->rollover || pos < encoder->steps) 82 77 pos++; 83 78 } 84 79 85 - if (pdata->rollover) 86 - pos %= pdata->steps; 80 + if (encoder->rollover) 81 + pos %= encoder->steps; 87 82 88 83 encoder->pos = pos; 89 - input_report_abs(encoder->input, pdata->axis, encoder->pos); 84 + input_report_abs(encoder->input, encoder->axis, encoder->pos); 90 85 } 91 86 92 87 input_sync(encoder->input); ··· 205 204 return IRQ_HANDLED; 206 205 } 207 206 208 - #ifdef CONFIG_OF 209 - static const struct of_device_id rotary_encoder_of_match[] = { 210 - { .compatible = "rotary-encoder", }, 211 - { }, 212 - }; 213 - MODULE_DEVICE_TABLE(of, rotary_encoder_of_match); 214 - 215 - static struct rotary_encoder_platform_data *rotary_encoder_parse_dt(struct device *dev) 216 - { 217 - const struct of_device_id *of_id = 218 - of_match_device(rotary_encoder_of_match, dev); 219 - struct device_node *np = dev->of_node; 220 - struct rotary_encoder_platform_data *pdata; 221 - int error; 222 - 223 - if (!of_id || !np) 224 - return NULL; 225 - 226 - pdata = devm_kzalloc(dev, sizeof(struct rotary_encoder_platform_data), 227 - GFP_KERNEL); 228 - if (!pdata) 229 - return ERR_PTR(-ENOMEM); 230 - 231 - of_property_read_u32(np, "rotary-encoder,steps", &pdata->steps); 232 - of_property_read_u32(np, "linux,axis", &pdata->axis); 233 - 234 - pdata->relative_axis = 235 - of_property_read_bool(np, "rotary-encoder,relative-axis"); 236 - pdata->rollover = of_property_read_bool(np, "rotary-encoder,rollover"); 237 - 238 - error = of_property_read_u32(np, "rotary-encoder,steps-per-period", 239 - &pdata->steps_per_period); 240 - if (error) { 241 - /* 242 - * The 'half-period' property has been deprecated, you must use 243 - * 'steps-per-period' and set an appropriate value, but we still 244 - * need to parse it to maintain compatibility. 245 - */ 246 - if (of_property_read_bool(np, "rotary-encoder,half-period")) { 247 - pdata->steps_per_period = 2; 248 - } else { 249 - /* Fallback to one step per period behavior */ 250 - pdata->steps_per_period = 1; 251 - } 252 - } 253 - 254 - pdata->wakeup_source = of_property_read_bool(np, "wakeup-source"); 255 - 256 - return pdata; 257 - } 258 - #else 259 - static inline struct rotary_encoder_platform_data * 260 - rotary_encoder_parse_dt(struct device *dev) 261 - { 262 - return NULL; 263 - } 264 - #endif 265 - 266 207 static int rotary_encoder_probe(struct platform_device *pdev) 267 208 { 268 209 struct device *dev = &pdev->dev; 269 - const struct rotary_encoder_platform_data *pdata = dev_get_platdata(dev); 270 210 struct rotary_encoder *encoder; 271 211 struct input_dev *input; 272 212 irq_handler_t handler; 213 + u32 steps_per_period; 273 214 int err; 274 - 275 - if (!pdata) { 276 - pdata = rotary_encoder_parse_dt(dev); 277 - if (IS_ERR(pdata)) 278 - return PTR_ERR(pdata); 279 - 280 - if (!pdata) { 281 - dev_err(dev, "missing platform data\n"); 282 - return -EINVAL; 283 - } 284 - } 285 215 286 216 encoder = devm_kzalloc(dev, sizeof(struct rotary_encoder), GFP_KERNEL); 287 217 if (!encoder) 288 218 return -ENOMEM; 289 219 290 220 mutex_init(&encoder->access_mutex); 291 - encoder->pdata = pdata; 221 + 222 + device_property_read_u32(dev, "rotary-encoder,steps", &encoder->steps); 223 + 224 + err = device_property_read_u32(dev, "rotary-encoder,steps-per-period", 225 + &steps_per_period); 226 + if (err) { 227 + /* 228 + * The 'half-period' property has been deprecated, you must 229 + * use 'steps-per-period' and set an appropriate value, but 230 + * we still need to parse it to maintain compatibility. If 231 + * neither property is present we fall back to the one step 232 + * per period behavior. 233 + */ 234 + steps_per_period = device_property_read_bool(dev, 235 + "rotary-encoder,half-period") ? 2 : 1; 236 + } 237 + 238 + encoder->rollover = 239 + device_property_read_bool(dev, "rotary-encoder,rollover"); 240 + 241 + device_property_read_u32(dev, "linux,axis", &encoder->axis); 242 + encoder->relative_axis = 243 + device_property_read_bool(dev, "rotary-encoder,relative-axis"); 292 244 293 245 encoder->gpio_a = devm_gpiod_get_index(dev, NULL, 0, GPIOD_IN); 294 246 if (IS_ERR(encoder->gpio_a)) { ··· 271 317 input->id.bustype = BUS_HOST; 272 318 input->dev.parent = dev; 273 319 274 - if (pdata->relative_axis) 275 - input_set_capability(input, EV_REL, pdata->axis); 320 + if (encoder->relative_axis) 321 + input_set_capability(input, EV_REL, encoder->axis); 276 322 else 277 - input_set_abs_params(input, pdata->axis, 0, pdata->steps, 0, 1); 323 + input_set_abs_params(input, 324 + encoder->axis, 0, encoder->steps, 0, 1); 278 325 279 - switch (pdata->steps_per_period) { 326 + switch (steps_per_period) { 280 327 case 4: 281 328 handler = &rotary_encoder_quarter_period_irq; 282 329 encoder->last_stable = rotary_encoder_get_state(encoder); ··· 291 336 break; 292 337 default: 293 338 dev_err(dev, "'%d' is not a valid steps-per-period value\n", 294 - pdata->steps_per_period); 339 + steps_per_period); 295 340 return -EINVAL; 296 341 } 297 342 ··· 319 364 return err; 320 365 } 321 366 322 - device_init_wakeup(&pdev->dev, pdata->wakeup_source); 367 + device_init_wakeup(dev, 368 + device_property_read_bool(dev, "wakeup-source")); 323 369 324 370 platform_set_drvdata(pdev, encoder); 325 371 ··· 353 397 354 398 static SIMPLE_DEV_PM_OPS(rotary_encoder_pm_ops, 355 399 rotary_encoder_suspend, rotary_encoder_resume); 400 + 401 + #ifdef CONFIG_OF 402 + static const struct of_device_id rotary_encoder_of_match[] = { 403 + { .compatible = "rotary-encoder", }, 404 + { }, 405 + }; 406 + MODULE_DEVICE_TABLE(of, rotary_encoder_of_match); 407 + #endif 356 408 357 409 static struct platform_driver rotary_encoder_driver = { 358 410 .probe = rotary_encoder_probe,
-13
include/linux/rotary_encoder.h
··· 1 - #ifndef __ROTARY_ENCODER_H__ 2 - #define __ROTARY_ENCODER_H__ 3 - 4 - struct rotary_encoder_platform_data { 5 - unsigned int steps; 6 - unsigned int axis; 7 - unsigned int steps_per_period; 8 - bool relative_axis; 9 - bool rollover; 10 - bool wakeup_source; 11 - }; 12 - 13 - #endif /* __ROTARY_ENCODER_H__ */