Skip to content

Commit a9e340d

Browse files
committed
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 <[email protected]>
1 parent 8631580 commit a9e340d

File tree

3 files changed

+76
-112
lines changed

3 files changed

+76
-112
lines changed

arch/arm/mach-pxa/raumfeld.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818

1919
#include <linux/init.h>
2020
#include <linux/kernel.h>
21+
#include <linux/property.h>
2122
#include <linux/platform_device.h>
2223
#include <linux/interrupt.h>
2324
#include <linux/gpio.h>
2425
#include <linux/gpio/machine.h>
2526
#include <linux/smsc911x.h>
2627
#include <linux/input.h>
27-
#include <linux/rotary_encoder.h>
2828
#include <linux/gpio_keys.h>
2929
#include <linux/input/eeti_ts.h>
3030
#include <linux/leds.h>
@@ -378,18 +378,27 @@ static struct gpiod_lookup_table raumfeld_rotary_gpios_table = {
378378
},
379379
};
380380

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,
385397
};
386398

387399
static struct platform_device rotary_encoder_device = {
388400
.name = "rotary-encoder",
389401
.id = 0,
390-
.dev = {
391-
.platform_data = &raumfeld_rotary_encoder_info,
392-
}
393402
};
394403

395404
/**
@@ -1061,6 +1070,8 @@ static void __init raumfeld_controller_init(void)
10611070
pxa3xx_mfp_config(ARRAY_AND_SIZE(raumfeld_controller_pin_config));
10621071

10631072
gpiod_add_lookup_table(&raumfeld_rotary_gpios_table);
1073+
device_add_property_set(&rotary_encoder_device.dev,
1074+
&raumfeld_rotary_property_set);
10641075
platform_device_register(&rotary_encoder_device);
10651076

10661077
spi_register_board_info(ARRAY_AND_SIZE(controller_spi_devices));
@@ -1099,6 +1110,8 @@ static void __init raumfeld_speaker_init(void)
10991110
platform_device_register(&smc91x_device);
11001111

11011112
gpiod_add_lookup_table(&raumfeld_rotary_gpios_table);
1113+
device_add_property_set(&rotary_encoder_device.dev,
1114+
&raumfeld_rotary_property_set);
11021115
platform_device_register(&rotary_encoder_device);
11031116

11041117
raumfeld_audio_init();

drivers/input/misc/rotary_encoder.c

Lines changed: 55 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,23 @@
2121
#include <linux/device.h>
2222
#include <linux/platform_device.h>
2323
#include <linux/gpio/consumer.h>
24-
#include <linux/rotary_encoder.h>
2524
#include <linux/slab.h>
2625
#include <linux/of.h>
27-
#include <linux/of_platform.h>
2826
#include <linux/pm.h>
27+
#include <linux/property.h>
2928

3029
#define DRV_NAME "rotary-encoder"
3130

3231
struct rotary_encoder {
3332
struct input_dev *input;
34-
const struct rotary_encoder_platform_data *pdata;
33+
3534
struct mutex access_mutex;
3635

37-
unsigned int axis;
36+
u32 steps;
37+
u32 axis;
38+
bool relative_axis;
39+
bool rollover;
40+
3841
unsigned int pos;
3942

4043
struct gpio_desc *gpio_a;
@@ -59,31 +62,29 @@ static int rotary_encoder_get_state(struct rotary_encoder *encoder)
5962

6063
static void rotary_encoder_report_event(struct rotary_encoder *encoder)
6164
{
62-
const struct rotary_encoder_platform_data *pdata = encoder->pdata;
63-
64-
if (pdata->relative_axis) {
65+
if (encoder->relative_axis) {
6566
input_report_rel(encoder->input,
66-
pdata->axis, encoder->dir ? -1 : 1);
67+
encoder->axis, encoder->dir ? -1 : 1);
6768
} else {
6869
unsigned int pos = encoder->pos;
6970

7071
if (encoder->dir) {
7172
/* turning counter-clockwise */
72-
if (pdata->rollover)
73-
pos += pdata->steps;
73+
if (encoder->rollover)
74+
pos += encoder->steps;
7475
if (pos)
7576
pos--;
7677
} else {
7778
/* turning clockwise */
78-
if (pdata->rollover || pos < pdata->steps)
79+
if (encoder->rollover || pos < encoder->steps)
7980
pos++;
8081
}
8182

82-
if (pdata->rollover)
83-
pos %= pdata->steps;
83+
if (encoder->rollover)
84+
pos %= encoder->steps;
8485

8586
encoder->pos = pos;
86-
input_report_abs(encoder->input, pdata->axis, encoder->pos);
87+
input_report_abs(encoder->input, encoder->axis, encoder->pos);
8788
}
8889

8990
input_sync(encoder->input);
@@ -204,90 +205,43 @@ static irqreturn_t rotary_encoder_quarter_period_irq(int irq, void *dev_id)
204205
return IRQ_HANDLED;
205206
}
206207

207-
#ifdef CONFIG_OF
208-
static const struct of_device_id rotary_encoder_of_match[] = {
209-
{ .compatible = "rotary-encoder", },
210-
{ },
211-
};
212-
MODULE_DEVICE_TABLE(of, rotary_encoder_of_match);
213-
214-
static struct rotary_encoder_platform_data *rotary_encoder_parse_dt(struct device *dev)
215-
{
216-
const struct of_device_id *of_id =
217-
of_match_device(rotary_encoder_of_match, dev);
218-
struct device_node *np = dev->of_node;
219-
struct rotary_encoder_platform_data *pdata;
220-
int error;
221-
222-
if (!of_id || !np)
223-
return NULL;
224-
225-
pdata = devm_kzalloc(dev, sizeof(struct rotary_encoder_platform_data),
226-
GFP_KERNEL);
227-
if (!pdata)
228-
return ERR_PTR(-ENOMEM);
229-
230-
of_property_read_u32(np, "rotary-encoder,steps", &pdata->steps);
231-
of_property_read_u32(np, "linux,axis", &pdata->axis);
232-
233-
pdata->relative_axis =
234-
of_property_read_bool(np, "rotary-encoder,relative-axis");
235-
pdata->rollover = of_property_read_bool(np, "rotary-encoder,rollover");
236-
237-
error = of_property_read_u32(np, "rotary-encoder,steps-per-period",
238-
&pdata->steps_per_period);
239-
if (error) {
240-
/*
241-
* The 'half-period' property has been deprecated, you must use
242-
* 'steps-per-period' and set an appropriate value, but we still
243-
* need to parse it to maintain compatibility.
244-
*/
245-
if (of_property_read_bool(np, "rotary-encoder,half-period")) {
246-
pdata->steps_per_period = 2;
247-
} else {
248-
/* Fallback to one step per period behavior */
249-
pdata->steps_per_period = 1;
250-
}
251-
}
252-
253-
pdata->wakeup_source = of_property_read_bool(np, "wakeup-source");
254-
255-
return pdata;
256-
}
257-
#else
258-
static inline struct rotary_encoder_platform_data *
259-
rotary_encoder_parse_dt(struct device *dev)
260-
{
261-
return NULL;
262-
}
263-
#endif
264-
265208
static int rotary_encoder_probe(struct platform_device *pdev)
266209
{
267210
struct device *dev = &pdev->dev;
268-
const struct rotary_encoder_platform_data *pdata = dev_get_platdata(dev);
269211
struct rotary_encoder *encoder;
270212
struct input_dev *input;
271213
irq_handler_t handler;
214+
u32 steps_per_period;
272215
int err;
273216

274-
if (!pdata) {
275-
pdata = rotary_encoder_parse_dt(dev);
276-
if (IS_ERR(pdata))
277-
return PTR_ERR(pdata);
278-
279-
if (!pdata) {
280-
dev_err(dev, "missing platform data\n");
281-
return -EINVAL;
282-
}
283-
}
284-
285217
encoder = devm_kzalloc(dev, sizeof(struct rotary_encoder), GFP_KERNEL);
286218
if (!encoder)
287219
return -ENOMEM;
288220

289221
mutex_init(&encoder->access_mutex);
290-
encoder->pdata = pdata;
222+
223+
device_property_read_u32(dev, "rotary-encoder,steps", &encoder->steps);
224+
225+
err = device_property_read_u32(dev, "rotary-encoder,steps-per-period",
226+
&steps_per_period);
227+
if (err) {
228+
/*
229+
* The 'half-period' property has been deprecated, you must
230+
* use 'steps-per-period' and set an appropriate value, but
231+
* we still need to parse it to maintain compatibility. If
232+
* neither property is present we fall back to the one step
233+
* per period behavior.
234+
*/
235+
steps_per_period = device_property_read_bool(dev,
236+
"rotary-encoder,half-period") ? 2 : 1;
237+
}
238+
239+
encoder->rollover =
240+
device_property_read_bool(dev, "rotary-encoder,rollover");
241+
242+
device_property_read_u32(dev, "linux,axis", &encoder->axis);
243+
encoder->relative_axis =
244+
device_property_read_bool(dev, "rotary-encoder,relative-axis");
291245

292246
encoder->gpio_a = devm_gpiod_get_index(dev, NULL, 0, GPIOD_IN);
293247
if (IS_ERR(encoder->gpio_a)) {
@@ -317,12 +271,13 @@ static int rotary_encoder_probe(struct platform_device *pdev)
317271
input->id.bustype = BUS_HOST;
318272
input->dev.parent = dev;
319273

320-
if (pdata->relative_axis)
321-
input_set_capability(input, EV_REL, pdata->axis);
274+
if (encoder->relative_axis)
275+
input_set_capability(input, EV_REL, encoder->axis);
322276
else
323-
input_set_abs_params(input, pdata->axis, 0, pdata->steps, 0, 1);
277+
input_set_abs_params(input,
278+
encoder->axis, 0, encoder->steps, 0, 1);
324279

325-
switch (pdata->steps_per_period) {
280+
switch (steps_per_period) {
326281
case 4:
327282
handler = &rotary_encoder_quarter_period_irq;
328283
encoder->last_stable = rotary_encoder_get_state(encoder);
@@ -336,7 +291,7 @@ static int rotary_encoder_probe(struct platform_device *pdev)
336291
break;
337292
default:
338293
dev_err(dev, "'%d' is not a valid steps-per-period value\n",
339-
pdata->steps_per_period);
294+
steps_per_period);
340295
return -EINVAL;
341296
}
342297

@@ -364,7 +319,8 @@ static int rotary_encoder_probe(struct platform_device *pdev)
364319
return err;
365320
}
366321

367-
device_init_wakeup(&pdev->dev, pdata->wakeup_source);
322+
device_init_wakeup(dev,
323+
device_property_read_bool(dev, "wakeup-source"));
368324

369325
platform_set_drvdata(pdev, encoder);
370326

@@ -398,6 +354,14 @@ static int __maybe_unused rotary_encoder_resume(struct device *dev)
398354
static SIMPLE_DEV_PM_OPS(rotary_encoder_pm_ops,
399355
rotary_encoder_suspend, rotary_encoder_resume);
400356

357+
#ifdef CONFIG_OF
358+
static const struct of_device_id rotary_encoder_of_match[] = {
359+
{ .compatible = "rotary-encoder", },
360+
{ },
361+
};
362+
MODULE_DEVICE_TABLE(of, rotary_encoder_of_match);
363+
#endif
364+
401365
static struct platform_driver rotary_encoder_driver = {
402366
.probe = rotary_encoder_probe,
403367
.driver = {

include/linux/rotary_encoder.h

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)