Skip to contentSkip to conversation

rotary-encoder: use generic device properties

PATCH In review Dmitry Torokhov 2 participants 6 messages Jan 18, 2016 – Jan 23, 2016

Subsystems (5)
lore
Share & tools
lore

Dmitry Torokhov

author maintainer
#0 lore raw

cover rotary-encoder: use generic device properties

Hi,

This series tries to move the driver away from legacy platform data towards using platform-independent way of retrieving both configuration parameters and GPIOs (device_property_read_* and gpiod APIs).

This is based on top of 2 Timo's patches converting the driver to use devm* API and threaded IRQs. I uploaded all changes into 'rotary-encoder' branch of my tree.

I do not have hard ware so please give it a spin, especially on raumfield as it uses branch new way of passing platform parameters to the driver.

Thanks.

Signature · 1 line
Dmitry
author maintainer
#1 lore raw

PATCH 1/4 Input: rotary_encoder - mark PM methods as __maybe_unused

Instead of guarding PM methods with #ifdef let's mark them as __maybe_unused as it allows for better compile coverage.

---
 drivers/input/misc/rotary_encoder.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/input/misc/rotary_encoder.c +3 -5
index 7828bd1..b9a86ca 100644
@@ -381,8 +381,7 @@ static int rotary_encoder_probe(struct platform_device *pdev)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int rotary_encoder_suspend(struct device *dev)
+static int __maybe_unused rotary_encoder_suspend(struct device *dev)
 {
 	struct rotary_encoder *encoder = dev_get_drvdata(dev);
 
@@ -394,7 +393,7 @@ static int rotary_encoder_suspend(struct device *dev)
 	return 0;
 }
 
-static int rotary_encoder_resume(struct device *dev)
+static int __maybe_unused rotary_encoder_resume(struct device *dev)
 {
 	struct rotary_encoder *encoder = dev_get_drvdata(dev);
 
@@ -405,10 +404,9 @@ static int rotary_encoder_resume(struct device *dev)
 
 	return 0;
 }
-#endif
 
 static SIMPLE_DEV_PM_OPS(rotary_encoder_pm_ops,
-		 rotary_encoder_suspend, rotary_encoder_resume);
+			 rotary_encoder_suspend, rotary_encoder_resume);
 
 static struct platform_driver rotary_encoder_driver = {
 	.probe		= rotary_encoder_probe,
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
author maintainer
#2 lore raw

PATCH 2/4 Input: rotary_encoder - convert to use gpiod API

In reply to Dmitry Torokhov

Instead of using old GPIO API, let's switch to GPIOD API, which automatically handles polarity.

---
 arch/arm/mach-pxa/raumfeld.c        | 21 +++++++++--
 drivers/input/misc/rotary_encoder.c | 73 +++++++++++++++++--------------------
 include/linux/rotary_encoder.h      |  4 --
 3 files changed, 50 insertions(+), 48 deletions(-)
arch/arm/mach-pxa/raumfeld.c +17 -4
index 36571a9..d156f79 100644
@@ -21,6 +21,7 @@
 #include <linux/platform_device.h>
 #include <linux/interrupt.h>
 #include <linux/gpio.h>
+#include <linux/gpio/machine.h>
 #include <linux/smsc911x.h>
 #include <linux/input.h>
 #include <linux/rotary_encoder.h>
@@ -366,14 +367,21 @@ static struct pxaohci_platform_data raumfeld_ohci_info = {
  * Rotary encoder input device
  */
 
+static struct gpiod_lookup_table raumfeld_rotary_gpios_table = {
+	.dev_id = "rotary-encoder",
+	.table = {
+		GPIO_LOOKUP_IDX("gpio-0",
+				GPIO_VOLENC_A, NULL, 0, GPIO_ACTIVE_LOW),
+		GPIO_LOOKUP_IDX("gpio-0",
+				GPIO_VOLENC_B, NULL, 1, GPIO_ACTIVE_HIGH),
+		{ },
+	},
+};
+
 static struct rotary_encoder_platform_data raumfeld_rotary_encoder_info = {
 	.steps		= 24,
 	.axis		= REL_X,
 	.relative_axis	= 1,
-	.gpio_a		= GPIO_VOLENC_A,
-	.gpio_b		= GPIO_VOLENC_B,
-	.inverted_a	= 1,
-	.inverted_b	= 0,
 };
 
 static struct platform_device rotary_encoder_device = {
@@ -1051,7 +1059,10 @@ static void __init raumfeld_controller_init(void)
 	int ret;
 
 	pxa3xx_mfp_config(ARRAY_AND_SIZE(raumfeld_controller_pin_config));
+
+	gpiod_add_lookup_table(&raumfeld_rotary_gpios_table);
 	platform_device_register(&rotary_encoder_device);
+
 	spi_register_board_info(ARRAY_AND_SIZE(controller_spi_devices));
 	i2c_register_board_info(0, &raumfeld_controller_i2c_board_info, 1);
 
@@ -1086,6 +1097,8 @@ static void __init raumfeld_speaker_init(void)
 	i2c_register_board_info(0, &raumfeld_connector_i2c_board_info, 1);
 
 	platform_device_register(&smc91x_device);
+
+	gpiod_add_lookup_table(&raumfeld_rotary_gpios_table);
 	platform_device_register(&rotary_encoder_device);
 
 	raumfeld_audio_init();
drivers/input/misc/rotary_encoder.c +33 -40

143 lines not on this page · raw message

include/linux/rotary_encoder.h +0 -4
index fe3dc64..4536c81 100644
@@ -4,10 +4,6 @@
 struct rotary_encoder_platform_data {
 	unsigned int steps;
 	unsigned int axis;
-	unsigned int gpio_a;
-	unsigned int gpio_b;
-	unsigned int inverted_a;
-	unsigned int inverted_b;
 	unsigned int steps_per_period;
 	bool relative_axis;
 	bool rollover;
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
author maintainer
#3 lore raw

PATCH 3/4 Input: rotary_encoder - use input_set_capability()

In reply to Dmitry Torokhov

Instead of manipulating capability bits directly let's use appropriate helpers. Also there is no need to explicitly set EV_ABS when calling input_set_abs_params().

---
 drivers/input/misc/rotary_encoder.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/input/misc/rotary_encoder.c +4 -8
index e913bfb64..1882e65 100644
@@ -318,14 +318,10 @@ static int rotary_encoder_probe(struct platform_device *pdev)
 	input->id.bustype = BUS_HOST;
 	input->dev.parent = dev;
 
-	if (pdata->relative_axis) {
-		input->evbit[0] = BIT_MASK(EV_REL);
-		input->relbit[0] = BIT_MASK(pdata->axis);
-	} else {
-		input->evbit[0] = BIT_MASK(EV_ABS);
-		input_set_abs_params(encoder->input,
-				     pdata->axis, 0, pdata->steps, 0, 1);
-	}
+	if (pdata->relative_axis)
+		input_set_capability(input, EV_REL, pdata->axis);
+	else
+		input_set_abs_params(input, pdata->axis, 0, pdata->steps, 0, 1);
 
 	switch (pdata->steps_per_period) {
 	case 4:
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
author maintainer
#4 lore raw

PATCH 4/4 Input: rotary_encoder - move away from platform data structure

In reply to Dmitry Torokhov

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.

---
 arch/arm/mach-pxa/raumfeld.c        |  29 +++++--
 drivers/input/misc/rotary_encoder.c | 147 ++++++++++++++----------------------
 include/linux/rotary_encoder.h      |  13 ----
 3 files changed, 76 insertions(+), 113 deletions(-)
 delete mode 100644 include/linux/rotary_encoder.h
arch/arm/mach-pxa/raumfeld.c +21 -8
index d156f79..c559114 100644
@@ -18,13 +18,13 @@
 
 #include <linux/init.h>
 #include <linux/kernel.h>
+#include <linux/property.h>
 #include <linux/platform_device.h>
 #include <linux/interrupt.h>
 #include <linux/gpio.h>
 #include <linux/gpio/machine.h>
 #include <linux/smsc911x.h>
 #include <linux/input.h>
-#include <linux/rotary_encoder.h>
 #include <linux/gpio_keys.h>
 #include <linux/input/eeti_ts.h>
 #include <linux/leds.h>
@@ -378,18 +378,27 @@ static struct gpiod_lookup_table raumfeld_rotary_gpios_table = {
 	},
 };
 
-static struct rotary_encoder_platform_data raumfeld_rotary_encoder_info = {
-	.steps		= 24,
-	.axis		= REL_X,
-	.relative_axis	= 1,
+static u32 raumfeld_rotary_encoder_steps = 24;
+static u32 raumfeld_rotary_encoder_axis = REL_X;
+static u32 raumfeld_rotary_encoder_relative_axis = 1;
+
+static struct property_entry raumfeld_rotary_properties[] = {
+	{ "rotary-encoder,steps-per-period",
+		DEV_PROP_U32, 1, &raumfeld_rotary_encoder_steps, },
+	{ "linux,axis",
+		DEV_PROP_U32, 1, &raumfeld_rotary_encoder_axis, },
+	{ "rotary-encoder,relative_axis", 1, },
+		DEV_PROP_U32, 1, &raumfeld_rotary_encoder_relative_axis, },
+	{ NULL }
+};
+
+static struct property_entry raumfeld_rotary_property_set = {
+	.properties = raumfeld_rotary_properties,
 };
 
 static struct platform_device rotary_encoder_device = {
 	.name		= "rotary-encoder",
 	.id		= 0,
-	.dev		= {
-		.platform_data = &raumfeld_rotary_encoder_info,
-	}
 };
 
 /**
@@ -1061,6 +1070,8 @@ static void __init raumfeld_controller_init(void)
 	pxa3xx_mfp_config(ARRAY_AND_SIZE(raumfeld_controller_pin_config));
 
 	gpiod_add_lookup_table(&raumfeld_rotary_gpios_table);
+	device_add_property_set(&rotary_encoder_device.dev,
+				&raumfeld_rotary_property_set);
 	platform_device_register(&rotary_encoder_device);
 
 	spi_register_board_info(ARRAY_AND_SIZE(controller_spi_devices));
@@ -1099,6 +1110,8 @@ static void __init raumfeld_speaker_init(void)
 	platform_device_register(&smc91x_device);
 
 	gpiod_add_lookup_table(&raumfeld_rotary_gpios_table);
+	device_add_property_set(&rotary_encoder_device.dev,
+				&raumfeld_rotary_property_set);
 	platform_device_register(&rotary_encoder_device);
 
 	raumfeld_audio_init();
drivers/input/misc/rotary_encoder.c +55 -92

229 lines not on this page · raw message

include/linux/rotary_encoder.h deleted +0 -13
deleted file mode 100644
index 4536c81..0000000
@@ -1,13 +0,0 @@
-#ifndef __ROTARY_ENCODER_H__
-#define __ROTARY_ENCODER_H__
-
-struct rotary_encoder_platform_data {
-	unsigned int steps;
-	unsigned int axis;
-	unsigned int steps_per_period;
-	bool relative_axis;
-	bool rollover;
-	bool wakeup_source;
-};
-
-#endif /* __ROTARY_ENCODER_H__ */
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
maintainer
#5 lore raw
In reply to Dmitry Torokhov
Quoted 6 lines · Dmitry Torokhov

Hi,

This series tries to move the driver away from legacy platform data towards using platform-independent way of retrieving both configuration parameters and GPIOs (device_property_read_* and gpiod APIs).

Quoted 6 lines

This is based on top of 2 Timo's patches converting the driver to use devm* API and threaded IRQs. I uploaded all changes into 'rotary-encoder' branch of my tree.

I do not have hard ware so please give it a spin, especially on raumfield as it uses branch new way of passing platform parameters to the driver.

Hi Dmitry,

Quoted 1 line

From the pxa architecture point of view, it looks fine to me.

Daniel, I seem to remember you had this raumfeld hardware, would you have the opportunity to give this serie a try ?

Cheers.

Signature · 1 line
Robert