public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] x86-android-tablets: convert to using GPIO references
@ 2023-05-12  0:18 Dmitry Torokhov
  2023-05-12  0:18 ` [PATCH 1/4] platform/x86: x86-android-tablets: convert Goodix devices to " Dmitry Torokhov
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Dmitry Torokhov @ 2023-05-12  0:18 UTC (permalink / raw)
  To: Hans de Goede; +Cc: Mark Gross, platform-driver-x86, linux-kernel

Hi Hans,

This series came about because now software nodes can be used to
describe GPIOs (via PROPERTY_ENTRY_GPIO() macros) and I would like to
eventually get rid of gpio_keys_platform_data structure.

So while I was doing the conversions from GPIO_LOOKUP() tables for
gpio_keys devices I decided to convert the rest of them as well. Maybe
some time in the future we can drop support for GPIO_LOOKUP() and rely
on device properties exclusively.

This is completely untested.

Thanks.

Dmitry Torokhov (4):
  platform/x86: x86-android-tablets: convert Goodix devices to GPIO references
  platform/x86: x86-android-tablets: convert int3496 devices to GPIO references
  platform/x86: x86-android-tablets: convert wm1502 devices to GPIO references
  platform/x86: x86-android-tablets: convert gpio_keys devices to GPIO references

 drivers/platform/x86/x86-android-tablets.c | 355 ++++++++++++---------
 1 file changed, 201 insertions(+), 154 deletions(-)

-- 
Dmitry


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] platform/x86: x86-android-tablets: convert Goodix devices to GPIO references
  2023-05-12  0:18 [PATCH 0/4] x86-android-tablets: convert to using GPIO references Dmitry Torokhov
@ 2023-05-12  0:18 ` Dmitry Torokhov
  2023-05-12  0:18 ` [PATCH 2/4] platform/x86: x86-android-tablets: convert int3496 " Dmitry Torokhov
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Dmitry Torokhov @ 2023-05-12  0:18 UTC (permalink / raw)
  To: Hans de Goede; +Cc: Mark Gross, platform-driver-x86, linux-kernel

Now that gpiolib supports software nodes to describe GPIOs, switch the
driver away from using GPIO lookup tables for Goodex touchscreens to using
PROPERTY_ENTRY_GPIO() to keep all touchscreen properties together.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/platform/x86/x86-android-tablets.c | 85 +++++++++++-----------
 1 file changed, 44 insertions(+), 41 deletions(-)

diff --git a/drivers/platform/x86/x86-android-tablets.c b/drivers/platform/x86/x86-android-tablets.c
index 111b007656fc..e187fb66b6d7 100644
--- a/drivers/platform/x86/x86-android-tablets.c
+++ b/drivers/platform/x86/x86-android-tablets.c
@@ -17,6 +17,7 @@
 #include <linux/gpio/consumer.h>
 #include <linux/gpio/driver.h>
 #include <linux/gpio/machine.h>
+#include <linux/gpio/property.h>
 #include <linux/i2c.h>
 #include <linux/input.h>
 #include <linux/irq.h>
@@ -184,6 +185,20 @@ struct x86_dev_info {
 	void (*exit)(void);
 };
 
+/* Software nodes representing GPIO chips used by varios devices below */
+static const struct software_node int33fc_gpiochip_nodes[] = {
+	{ .name = "INT33FC:00" },
+	{ .name = "INT33FC:01" },
+	{ .name = "INT33FC:02" },
+};
+
+static const struct software_node *int33fc_gpiochip_node_group[] = {
+	&int33fc_gpiochip_nodes[0],
+	&int33fc_gpiochip_nodes[1],
+	&int33fc_gpiochip_nodes[2],
+	NULL
+};
+
 /* Generic / shared charger / battery settings */
 static const char * const tusb1211_chg_det_psy[] = { "tusb1211-charger-detect" };
 static const char * const bq24190_psy[] = { "bq24190-charger" };
@@ -400,6 +415,18 @@ static const struct software_node asus_me176c_ug3105_node = {
 	.properties = asus_me176c_ug3105_props,
 };
 
+static const struct property_entry asus_me176c_touchscreen_props[] = {
+	PROPERTY_ENTRY_GPIO("reset-gpios",
+			    &int33fc_gpiochip_nodes[0], 60, GPIO_ACTIVE_HIGH),
+	PROPERTY_ENTRY_GPIO("irq-gpios",
+			    &int33fc_gpiochip_nodes[2], 28, GPIO_ACTIVE_HIGH),
+	{ }
+};
+
+static const struct software_node asus_me176c_touchscreen_node = {
+	.properties = asus_me176c_touchscreen_props,
+};
+
 static const struct x86_i2c_client_info asus_me176c_i2c_clients[] __initconst = {
 	{
 		/* bq24297 battery charger */
@@ -455,6 +482,7 @@ static const struct x86_i2c_client_info asus_me176c_i2c_clients[] __initconst =
 			.type = "GDIX1001:00",
 			.addr = 0x14,
 			.dev_name = "goodix_ts",
+			.swnode = &asus_me176c_touchscreen_node,
 		},
 		.adapter_path = "\\_SB_.I2C6",
 		.irq_data = {
@@ -475,18 +503,8 @@ static const struct x86_serdev_info asus_me176c_serdevs[] __initconst = {
 	},
 };
 
-static struct gpiod_lookup_table asus_me176c_goodix_gpios = {
-	.dev_id = "i2c-goodix_ts",
-	.table = {
-		GPIO_LOOKUP("INT33FC:00", 60, "reset", GPIO_ACTIVE_HIGH),
-		GPIO_LOOKUP("INT33FC:02", 28, "irq", GPIO_ACTIVE_HIGH),
-		{ }
-	},
-};
-
 static struct gpiod_lookup_table * const asus_me176c_gpios[] = {
 	&int3496_gpo2_pin22_gpios,
-	&asus_me176c_goodix_gpios,
 	NULL
 };
 
@@ -1181,6 +1199,10 @@ static const struct software_node medion_lifetab_s10346_accel_node = {
 static const struct property_entry medion_lifetab_s10346_touchscreen_props[] = {
 	PROPERTY_ENTRY_BOOL("touchscreen-inverted-x"),
 	PROPERTY_ENTRY_BOOL("touchscreen-swapped-x-y"),
+	PROPERTY_ENTRY_GPIO("reset-gpios",
+			    &int33fc_gpiochip_nodes[1], 26, GPIO_ACTIVE_HIGH),
+	PROPERTY_ENTRY_GPIO("irq-gpios",
+			    &int33fc_gpiochip_nodes[2], 3, GPIO_ACTIVE_HIGH),
 	{ }
 };
 
@@ -1223,24 +1245,9 @@ static const struct x86_i2c_client_info medion_lifetab_s10346_i2c_clients[] __in
 	},
 };
 
-static struct gpiod_lookup_table medion_lifetab_s10346_goodix_gpios = {
-	.dev_id = "i2c-goodix_ts",
-	.table = {
-		GPIO_LOOKUP("INT33FC:01", 26, "reset", GPIO_ACTIVE_HIGH),
-		GPIO_LOOKUP("INT33FC:02", 3, "irq", GPIO_ACTIVE_HIGH),
-		{ }
-	},
-};
-
-static struct gpiod_lookup_table * const medion_lifetab_s10346_gpios[] = {
-	&medion_lifetab_s10346_goodix_gpios,
-	NULL
-};
-
 static const struct x86_dev_info medion_lifetab_s10346_info __initconst = {
 	.i2c_client_info = medion_lifetab_s10346_i2c_clients,
 	.i2c_client_count = ARRAY_SIZE(medion_lifetab_s10346_i2c_clients),
-	.gpiod_lookup_tables = medion_lifetab_s10346_gpios,
 };
 
 /* Nextbook Ares 8 tablets have an Android factory img with everything hardcoded */
@@ -1346,6 +1353,10 @@ static const struct property_entry whitelabel_tm800a550l_goodix_props[] = {
 	PROPERTY_ENTRY_STRING("firmware-name", "gt912-tm800a550l.fw"),
 	PROPERTY_ENTRY_STRING("goodix,config-name", "gt912-tm800a550l.cfg"),
 	PROPERTY_ENTRY_U32("goodix,main-clk", 54),
+	PROPERTY_ENTRY_GPIO("reset-gpios",
+			    &int33fc_gpiochip_nodes[1], 26, GPIO_ACTIVE_HIGH),
+	PROPERTY_ENTRY_GPIO("irq-gpios",
+			    &int33fc_gpiochip_nodes[2], 3, GPIO_ACTIVE_HIGH),
 	{ }
 };
 
@@ -1381,24 +1392,9 @@ static const struct x86_i2c_client_info whitelabel_tm800a550l_i2c_clients[] __in
 	},
 };
 
-static struct gpiod_lookup_table whitelabel_tm800a550l_goodix_gpios = {
-	.dev_id = "i2c-goodix_ts",
-	.table = {
-		GPIO_LOOKUP("INT33FC:01", 26, "reset", GPIO_ACTIVE_HIGH),
-		GPIO_LOOKUP("INT33FC:02", 3, "irq", GPIO_ACTIVE_HIGH),
-		{ }
-	},
-};
-
-static struct gpiod_lookup_table * const whitelabel_tm800a550l_gpios[] = {
-	&whitelabel_tm800a550l_goodix_gpios,
-	NULL
-};
-
 static const struct x86_dev_info whitelabel_tm800a550l_info __initconst = {
 	.i2c_client_info = whitelabel_tm800a550l_i2c_clients,
 	.i2c_client_count = ARRAY_SIZE(whitelabel_tm800a550l_i2c_clients),
-	.gpiod_lookup_tables = whitelabel_tm800a550l_gpios,
 };
 
 /*
@@ -1691,6 +1687,7 @@ static void x86_android_tablet_cleanup(void)
 		gpiod_remove_lookup_table(gpiod_lookup_tables[i]);
 
 	software_node_unregister(bat_swnode);
+	software_node_unregister_node_group(int33fc_gpiochip_node_group);
 }
 
 static __init int x86_android_tablet_init(void)
@@ -1727,11 +1724,17 @@ static __init int x86_android_tablet_init(void)
 	for (i = 0; dev_info->modules && dev_info->modules[i]; i++)
 		request_module(dev_info->modules[i]);
 
+	ret = software_node_register_node_group(int33fc_gpiochip_node_group);
+	if (ret)
+		return ret;
+
 	bat_swnode = dev_info->bat_swnode;
 	if (bat_swnode) {
 		ret = software_node_register(bat_swnode);
-		if (ret)
+		if (ret) {
+			x86_android_tablet_cleanup();
 			return ret;
+		}
 	}
 
 	gpiod_lookup_tables = dev_info->gpiod_lookup_tables;
-- 
2.40.1.606.ga4b1b128d6-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] platform/x86: x86-android-tablets: convert int3496 devices to GPIO references
  2023-05-12  0:18 [PATCH 0/4] x86-android-tablets: convert to using GPIO references Dmitry Torokhov
  2023-05-12  0:18 ` [PATCH 1/4] platform/x86: x86-android-tablets: convert Goodix devices to " Dmitry Torokhov
@ 2023-05-12  0:18 ` Dmitry Torokhov
  2023-05-12  0:18 ` [PATCH 3/4] platform/x86: x86-android-tablets: convert wm1502 " Dmitry Torokhov
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Dmitry Torokhov @ 2023-05-12  0:18 UTC (permalink / raw)
  To: Hans de Goede; +Cc: Mark Gross, platform-driver-x86, linux-kernel

Now that gpiolib supports software nodes to describe GPIOs, switch the
driver away from using GPIO lookup tables for int3496 devices to using
PROPERTY_ENTRY_GPIO().

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/platform/x86/x86-android-tablets.c | 89 +++++++++-------------
 1 file changed, 38 insertions(+), 51 deletions(-)

diff --git a/drivers/platform/x86/x86-android-tablets.c b/drivers/platform/x86/x86-android-tablets.c
index e187fb66b6d7..f7f80237cfa9 100644
--- a/drivers/platform/x86/x86-android-tablets.c
+++ b/drivers/platform/x86/x86-android-tablets.c
@@ -263,23 +263,6 @@ static const char * const bq24190_modules[] __initconst = {
 	NULL
 };
 
-/* Generic pdevs array and gpio-lookups for micro USB ID pin handling */
-static const struct platform_device_info int3496_pdevs[] __initconst = {
-	{
-		/* For micro USB ID pin handling */
-		.name = "intel-int3496",
-		.id = PLATFORM_DEVID_NONE,
-	},
-};
-
-static struct gpiod_lookup_table int3496_gpo2_pin22_gpios = {
-	.dev_id = "intel-int3496",
-	.table = {
-		GPIO_LOOKUP("INT33FC:02", 22, "id", GPIO_ACTIVE_HIGH),
-		{ }
-	},
-};
-
 /*
  * Advantech MICA-071
  * This is a standard Windows tablet, but it has an extra "quick launch" button
@@ -347,6 +330,12 @@ static const struct gpio_keys_platform_data asus_me176c_tf103c_lid_pdata __initc
 	.name = "lid_sw",
 };
 
+static const struct property_entry asus_me176c_tf103c_int3496_props[] = {
+	PROPERTY_ENTRY_GPIO("id-gpios",
+			    &int33fc_gpiochip_nodes[2], 22, GPIO_ACTIVE_HIGH),
+	{ }
+};
+
 static const struct platform_device_info asus_me176c_tf103c_pdevs[] __initconst = {
 	{
 		.name = "gpio-keys",
@@ -358,6 +347,7 @@ static const struct platform_device_info asus_me176c_tf103c_pdevs[] __initconst
 		/* For micro USB ID pin handling */
 		.name = "intel-int3496",
 		.id = PLATFORM_DEVID_NONE,
+		.properties = asus_me176c_tf103c_int3496_props,
 	},
 };
 
@@ -503,11 +493,6 @@ static const struct x86_serdev_info asus_me176c_serdevs[] __initconst = {
 	},
 };
 
-static struct gpiod_lookup_table * const asus_me176c_gpios[] = {
-	&int3496_gpo2_pin22_gpios,
-	NULL
-};
-
 static const struct x86_dev_info asus_me176c_info __initconst = {
 	.i2c_client_info = asus_me176c_i2c_clients,
 	.i2c_client_count = ARRAY_SIZE(asus_me176c_i2c_clients),
@@ -515,7 +500,6 @@ static const struct x86_dev_info asus_me176c_info __initconst = {
 	.pdev_count = ARRAY_SIZE(asus_me176c_tf103c_pdevs),
 	.serdev_info = asus_me176c_serdevs,
 	.serdev_count = ARRAY_SIZE(asus_me176c_serdevs),
-	.gpiod_lookup_tables = asus_me176c_gpios,
 	.bat_swnode = &generic_lipo_hv_4v35_battery_node,
 	.modules = bq24190_modules,
 	.invalid_aei_gpiochip = "INT33FC:02",
@@ -648,17 +632,11 @@ static const struct x86_i2c_client_info asus_tf103c_i2c_clients[] __initconst =
 	},
 };
 
-static struct gpiod_lookup_table * const asus_tf103c_gpios[] = {
-	&int3496_gpo2_pin22_gpios,
-	NULL
-};
-
 static const struct x86_dev_info asus_tf103c_info __initconst = {
 	.i2c_client_info = asus_tf103c_i2c_clients,
 	.i2c_client_count = ARRAY_SIZE(asus_tf103c_i2c_clients),
 	.pdev_info = asus_me176c_tf103c_pdevs,
 	.pdev_count = ARRAY_SIZE(asus_me176c_tf103c_pdevs),
-	.gpiod_lookup_tables = asus_tf103c_gpios,
 	.bat_swnode = &asus_tf103c_battery_node,
 	.modules = bq24190_modules,
 	.invalid_aei_gpiochip = "INT33FC:02",
@@ -877,12 +855,20 @@ static const struct x86_i2c_client_info lenovo_yoga_tab2_830_1050_i2c_clients[]
 	},
 };
 
-static struct gpiod_lookup_table lenovo_yoga_tab2_830_1050_int3496_gpios = {
-	.dev_id = "intel-int3496",
-	.table = {
-		GPIO_LOOKUP("INT33FC:02", 1, "mux", GPIO_ACTIVE_LOW),
-		GPIO_LOOKUP("INT33FC:02", 24, "id", GPIO_ACTIVE_HIGH),
-		{ }
+static const struct property_entry lenovo_yoga_tab2_830_1050_int3496_props[] = {
+	PROPERTY_ENTRY_GPIO("mux-gpios",
+			    &int33fc_gpiochip_nodes[2], 1, GPIO_ACTIVE_LOW),
+	PROPERTY_ENTRY_GPIO("id-gpios",
+			    &int33fc_gpiochip_nodes[2], 24, GPIO_ACTIVE_HIGH),
+	{ }
+};
+
+static const struct platform_device_info lenovo_yoga_tab2_830_1050_pdevs[] __initconst = {
+	{
+		/* For micro USB ID pin handling */
+		.name = "intel-int3496",
+		.id = PLATFORM_DEVID_NONE,
+		.properties = lenovo_yoga_tab2_830_1050_int3496_props,
 	},
 };
 
@@ -900,7 +886,6 @@ static struct gpiod_lookup_table lenovo_yoga_tab2_830_1050_codec_gpios = {
 };
 
 static struct gpiod_lookup_table * const lenovo_yoga_tab2_830_1050_gpios[] = {
-	&lenovo_yoga_tab2_830_1050_int3496_gpios,
 	&lenovo_yoga_tab2_830_1050_codec_gpios,
 	NULL
 };
@@ -911,8 +896,8 @@ static void lenovo_yoga_tab2_830_1050_exit(void);
 static struct x86_dev_info lenovo_yoga_tab2_830_1050_info __initdata = {
 	.i2c_client_info = lenovo_yoga_tab2_830_1050_i2c_clients,
 	/* i2c_client_count gets set by lenovo_yoga_tab2_830_1050_init() */
-	.pdev_info = int3496_pdevs,
-	.pdev_count = ARRAY_SIZE(int3496_pdevs),
+	.pdev_info = lenovo_yoga_tab2_830_1050_pdevs,
+	.pdev_count = ARRAY_SIZE(lenovo_yoga_tab2_830_1050_pdevs),
 	.gpiod_lookup_tables = lenovo_yoga_tab2_830_1050_gpios,
 	.bat_swnode = &generic_lipo_hv_4v35_battery_node,
 	.modules = bq24190_modules,
@@ -1305,26 +1290,28 @@ static const struct x86_i2c_client_info nextbook_ares8_i2c_clients[] __initconst
 	},
 };
 
-static struct gpiod_lookup_table nextbook_ares8_int3496_gpios = {
-	.dev_id = "intel-int3496",
-	.table = {
-		GPIO_LOOKUP("INT33FC:02", 1, "mux", GPIO_ACTIVE_HIGH),
-		GPIO_LOOKUP("INT33FC:02", 18, "id", GPIO_ACTIVE_HIGH),
-		{ }
-	},
+static const struct property_entry nextbook_ares8_int3496_props[] = {
+	PROPERTY_ENTRY_GPIO("mux-gpios",
+			    &int33fc_gpiochip_nodes[2], 1, GPIO_ACTIVE_HIGH),
+	PROPERTY_ENTRY_GPIO("id-gpios",
+			    &int33fc_gpiochip_nodes[2], 18, GPIO_ACTIVE_HIGH),
+	{ }
 };
 
-static struct gpiod_lookup_table * const nextbook_ares8_gpios[] = {
-	&nextbook_ares8_int3496_gpios,
-	NULL
+static const struct platform_device_info nextbook_ares8_pdevs[] __initconst = {
+	{
+		/* For micro USB ID pin handling */
+		.name = "intel-int3496",
+		.id = PLATFORM_DEVID_NONE,
+		.properties = nextbook_ares8_int3496_props,
+	},
 };
 
 static const struct x86_dev_info nextbook_ares8_info __initconst = {
 	.i2c_client_info = nextbook_ares8_i2c_clients,
 	.i2c_client_count = ARRAY_SIZE(nextbook_ares8_i2c_clients),
-	.pdev_info = int3496_pdevs,
-	.pdev_count = ARRAY_SIZE(int3496_pdevs),
-	.gpiod_lookup_tables = nextbook_ares8_gpios,
+	.pdev_info = nextbook_ares8_pdevs,
+	.pdev_count = ARRAY_SIZE(nextbook_ares8_pdevs),
 	.invalid_aei_gpiochip = "INT33FC:02",
 };
 
-- 
2.40.1.606.ga4b1b128d6-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] platform/x86: x86-android-tablets: convert wm1502 devices to GPIO references
  2023-05-12  0:18 [PATCH 0/4] x86-android-tablets: convert to using GPIO references Dmitry Torokhov
  2023-05-12  0:18 ` [PATCH 1/4] platform/x86: x86-android-tablets: convert Goodix devices to " Dmitry Torokhov
  2023-05-12  0:18 ` [PATCH 2/4] platform/x86: x86-android-tablets: convert int3496 " Dmitry Torokhov
@ 2023-05-12  0:18 ` Dmitry Torokhov
  2023-05-12  0:18 ` [PATCH 4/4] platform/x86: x86-android-tablets: convert gpio_keys " Dmitry Torokhov
  2023-05-14 20:21 ` [PATCH 0/4] x86-android-tablets: convert to using " Hans de Goede
  4 siblings, 0 replies; 6+ messages in thread
From: Dmitry Torokhov @ 2023-05-12  0:18 UTC (permalink / raw)
  To: Hans de Goede; +Cc: Mark Gross, platform-driver-x86, linux-kernel

Now that gpiolib supports software nodes to describe GPIOs, switch the
driver away from using GPIO lookup tables for wm1502 devices to using
PROPERTY_ENTRY_GPIO().

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/platform/x86/x86-android-tablets.c | 64 +++++++++++++++++-----
 1 file changed, 50 insertions(+), 14 deletions(-)

diff --git a/drivers/platform/x86/x86-android-tablets.c b/drivers/platform/x86/x86-android-tablets.c
index f7f80237cfa9..02ee793a934e 100644
--- a/drivers/platform/x86/x86-android-tablets.c
+++ b/drivers/platform/x86/x86-android-tablets.c
@@ -874,19 +874,37 @@ static const struct platform_device_info lenovo_yoga_tab2_830_1050_pdevs[] __ini
 
 #define LENOVO_YOGA_TAB2_830_1050_CODEC_NAME "spi-10WM5102:00"
 
-static struct gpiod_lookup_table lenovo_yoga_tab2_830_1050_codec_gpios = {
-	.dev_id = LENOVO_YOGA_TAB2_830_1050_CODEC_NAME,
-	.table = {
-		GPIO_LOOKUP("gpio_crystalcove", 3, "reset", GPIO_ACTIVE_HIGH),
-		GPIO_LOOKUP("INT33FC:01", 23, "wlf,ldoena", GPIO_ACTIVE_HIGH),
-		GPIO_LOOKUP("arizona", 2, "wlf,spkvdd-ena", GPIO_ACTIVE_HIGH),
-		GPIO_LOOKUP("arizona", 4, "wlf,micd-pol", GPIO_ACTIVE_LOW),
-		{ }
-	},
+static const struct software_node lenovo_yoga_tab2_830_1050_crystalcove = {
+	.name = "gpio_crystalcove",
+};
+
+static const struct software_node lenovo_yoga_tab2_830_1050_arizona = {
+	.name = "arizona",
+};
+
+static const struct property_entry lenovo_yoga_tab2_830_1050_wm1502_props[] = {
+	PROPERTY_ENTRY_GPIO("reset-gpios",
+			    &lenovo_yoga_tab2_830_1050_crystalcove,
+			    3, GPIO_ACTIVE_HIGH),
+	PROPERTY_ENTRY_GPIO("wlf,ldoena-gpios",
+			     &int33fc_gpiochip_nodes[1], 23, GPIO_ACTIVE_HIGH),
+	PROPERTY_ENTRY_GPIO("wlf,spkvdd-ena-gpios",
+			    &lenovo_yoga_tab2_830_1050_arizona,
+			    2, GPIO_ACTIVE_HIGH),
+	PROPERTY_ENTRY_GPIO("wlf,micd-pol-gpios",
+			    &lenovo_yoga_tab2_830_1050_arizona,
+			    4, GPIO_ACTIVE_HIGH),
+	{ }
+};
+
+static const struct software_node lenovo_yoga_tab2_830_1050_wm5102 = {
+	.properties = lenovo_yoga_tab2_830_1050_wm1502_props,
 };
 
-static struct gpiod_lookup_table * const lenovo_yoga_tab2_830_1050_gpios[] = {
-	&lenovo_yoga_tab2_830_1050_codec_gpios,
+static const struct software_node *lenovo_yoga_tab2_830_1050_swnodes[] = {
+	&lenovo_yoga_tab2_830_1050_crystalcove,
+	&lenovo_yoga_tab2_830_1050_arizona,
+	&lenovo_yoga_tab2_830_1050_wm5102,
 	NULL
 };
 
@@ -898,7 +916,6 @@ static struct x86_dev_info lenovo_yoga_tab2_830_1050_info __initdata = {
 	/* i2c_client_count gets set by lenovo_yoga_tab2_830_1050_init() */
 	.pdev_info = lenovo_yoga_tab2_830_1050_pdevs,
 	.pdev_count = ARRAY_SIZE(lenovo_yoga_tab2_830_1050_pdevs),
-	.gpiod_lookup_tables = lenovo_yoga_tab2_830_1050_gpios,
 	.bat_swnode = &generic_lipo_hv_4v35_battery_node,
 	.modules = bq24190_modules,
 	.invalid_aei_gpiochip = "INT33FC:02",
@@ -955,6 +972,7 @@ static const struct pinctrl_map lenovo_yoga_tab2_830_1050_codec_pinctrl_map =
 	PIN_MAP_MUX_GROUP(LENOVO_YOGA_TAB2_830_1050_CODEC_NAME, "codec_32khz_clk",
 			  "INT33FC:02", "pmu_clk2_grp", "pmu_clk");
 
+static struct device *lenovo_yoga_tab2_830_1050_codec_dev;
 static struct pinctrl *lenovo_yoga_tab2_830_1050_codec_pinctrl;
 static struct sys_off_handler *lenovo_yoga_tab2_830_1050_sys_off_handler;
 
@@ -981,12 +999,24 @@ static int __init lenovo_yoga_tab2_830_1050_init_codec(void)
 		goto err_unregister_mappings;
 	}
 
-	/* We're done with the codec_dev now */
-	put_device(codec_dev);
+	ret = software_node_register_node_group(lenovo_yoga_tab2_830_1050_swnodes);
+	if (ret) {
+		ret = dev_err_probe(codec_dev, ret, "registering software nodes\n");
+		goto err_unregister_mappings;
+	}
 
+	ret = device_add_software_node(codec_dev, &lenovo_yoga_tab2_830_1050_wm5102);
+	if (ret) {
+		ret = dev_err_probe(codec_dev, ret, "adding software node\n");
+		goto err_unregister_swnodes;
+	}
+
+	lenovo_yoga_tab2_830_1050_codec_dev = codec_dev;
 	lenovo_yoga_tab2_830_1050_codec_pinctrl = pinctrl;
 	return 0;
 
+err_unregister_swnodes:
+	software_node_unregister_node_group(lenovo_yoga_tab2_830_1050_swnodes);
 err_unregister_mappings:
 	pinctrl_unregister_mappings(&lenovo_yoga_tab2_830_1050_codec_pinctrl_map);
 err_put_device:
@@ -1034,6 +1064,12 @@ static void lenovo_yoga_tab2_830_1050_exit(void)
 {
 	unregister_sys_off_handler(lenovo_yoga_tab2_830_1050_sys_off_handler);
 
+	if (lenovo_yoga_tab2_830_1050_codec_dev) {
+		device_remove_software_node(lenovo_yoga_tab2_830_1050_codec_dev);
+		put_device(lenovo_yoga_tab2_830_1050_codec_dev);
+		software_node_unregister_node_group(lenovo_yoga_tab2_830_1050_swnodes);
+	}
+
 	if (lenovo_yoga_tab2_830_1050_codec_pinctrl) {
 		pinctrl_put(lenovo_yoga_tab2_830_1050_codec_pinctrl);
 		pinctrl_unregister_mappings(&lenovo_yoga_tab2_830_1050_codec_pinctrl_map);
-- 
2.40.1.606.ga4b1b128d6-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] platform/x86: x86-android-tablets: convert gpio_keys devices to GPIO references
  2023-05-12  0:18 [PATCH 0/4] x86-android-tablets: convert to using GPIO references Dmitry Torokhov
                   ` (2 preceding siblings ...)
  2023-05-12  0:18 ` [PATCH 3/4] platform/x86: x86-android-tablets: convert wm1502 " Dmitry Torokhov
@ 2023-05-12  0:18 ` Dmitry Torokhov
  2023-05-14 20:21 ` [PATCH 0/4] x86-android-tablets: convert to using " Hans de Goede
  4 siblings, 0 replies; 6+ messages in thread
From: Dmitry Torokhov @ 2023-05-12  0:18 UTC (permalink / raw)
  To: Hans de Goede; +Cc: Mark Gross, platform-driver-x86, linux-kernel

Now that gpiolib supports software nodes to describe GPIOs, switch the
driver away from using GPIO lookup tables for wm1502 devices to using
PROPERTY_ENTRY_GPIO().

With that we can remove support for gpiod_lookup_tables from the driver.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/platform/x86/x86-android-tablets.c | 117 ++++++++++++---------
 1 file changed, 69 insertions(+), 48 deletions(-)

diff --git a/drivers/platform/x86/x86-android-tablets.c b/drivers/platform/x86/x86-android-tablets.c
index 02ee793a934e..878b2b72d214 100644
--- a/drivers/platform/x86/x86-android-tablets.c
+++ b/drivers/platform/x86/x86-android-tablets.c
@@ -16,7 +16,6 @@
 #include <linux/gpio_keys.h>
 #include <linux/gpio/consumer.h>
 #include <linux/gpio/driver.h>
-#include <linux/gpio/machine.h>
 #include <linux/gpio/property.h>
 #include <linux/i2c.h>
 #include <linux/input.h>
@@ -29,6 +28,7 @@
 #include <linux/platform_data/lp855x.h>
 #include <linux/platform_device.h>
 #include <linux/power/bq24190_charger.h>
+#include <linux/property.h>
 #include <linux/reboot.h>
 #include <linux/rmi.h>
 #include <linux/serdev.h>
@@ -174,7 +174,6 @@ struct x86_dev_info {
 	char *invalid_aei_gpiochip;
 	const char * const *modules;
 	const struct software_node *bat_swnode;
-	struct gpiod_lookup_table * const *gpiod_lookup_tables;
 	const struct x86_i2c_client_info *i2c_client_info;
 	const struct platform_device_info *pdev_info;
 	const struct x86_serdev_info *serdev_info;
@@ -269,79 +268,102 @@ static const char * const bq24190_modules[] __initconst = {
  * which is not described in the ACPI tables in anyway.
  * Use the x86-android-tablets infra to create a gpio-button device for this.
  */
-static struct gpio_keys_button advantech_mica_071_button = {
-	.code = KEY_PROG1,
-	/* .gpio gets filled in by advantech_mica_071_init() */
-	.active_low = true,
-	.desc = "prog1_key",
-	.type = EV_KEY,
-	.wakeup = false,
-	.debounce_interval = 50,
-};
-
-static const struct gpio_keys_platform_data advantech_mica_071_button_pdata __initconst = {
-	.buttons = &advantech_mica_071_button,
-	.nbuttons = 1,
+static const struct software_node advantech_mica_071_gpio_keys_node = {
 	.name = "prog1_key",
 };
 
-static const struct platform_device_info advantech_mica_071_pdevs[] __initconst = {
+static const struct property_entry advantech_mica_071_prog1_key_props[] = {
+	PROPERTY_ENTRY_U32("linux,code", KEY_PROG1),
+	PROPERTY_ENTRY_STRING("label", "prog1_key"),
+	PROPERTY_ENTRY_GPIO("gpios",
+			    &int33fc_gpiochip_nodes[0], 2, GPIO_ACTIVE_LOW),
+	PROPERTY_ENTRY_U32("debounce-interval", 50),
+	{ }
+};
+
+static const struct software_node advantech_mica_071_prog1_key_node = {
+	.parent = &advantech_mica_071_gpio_keys_node,
+	.properties = advantech_mica_071_prog1_key_props,
+};
+
+static const struct software_node *advantech_mica_071_swnodes[] = {
+	&advantech_mica_071_gpio_keys_node,
+	&advantech_mica_071_prog1_key_node,
+	NULL
+};
+
+static struct platform_device_info advantech_mica_071_pdevs[] = {
 	{
 		.name = "gpio-keys",
 		.id = PLATFORM_DEVID_AUTO,
-		.data = &advantech_mica_071_button_pdata,
-		.size_data = sizeof(advantech_mica_071_button_pdata),
+		/* .fwnode will be filled by advantech_mica_071_init() */
 	},
 };
 
 static int __init advantech_mica_071_init(void)
 {
-	struct gpio_desc *gpiod;
 	int ret;
 
-	ret = x86_android_tablet_get_gpiod("INT33FC:00", 2, &gpiod);
+	ret = software_node_register_node_group(advantech_mica_071_swnodes);
 	if (ret < 0)
 		return ret;
-	advantech_mica_071_button.gpio = desc_to_gpio(gpiod);
+
+	advantech_mica_071_pdevs[0].fwnode =
+			software_node_fwnode(advantech_mica_071_swnodes[0]);
 
 	return 0;
 }
 
+static void __exit advantech_mica_071_exit(void)
+{
+	software_node_unregister_node_group(advantech_mica_071_swnodes);
+}
+
 static const struct x86_dev_info advantech_mica_071_info __initconst = {
 	.pdev_info = advantech_mica_071_pdevs,
 	.pdev_count = ARRAY_SIZE(advantech_mica_071_pdevs),
 	.init = advantech_mica_071_init,
+	.exit = advantech_mica_071_exit,
 };
 
 /* Asus ME176C and TF103C tablets shared data */
-static struct gpio_keys_button asus_me176c_tf103c_lid = {
-	.code = SW_LID,
-	/* .gpio gets filled in by asus_me176c_tf103c_init() */
-	.active_low = true,
-	.desc = "lid_sw",
-	.type = EV_SW,
-	.wakeup = true,
-	.debounce_interval = 50,
-};
-
-static const struct gpio_keys_platform_data asus_me176c_tf103c_lid_pdata __initconst = {
-	.buttons = &asus_me176c_tf103c_lid,
-	.nbuttons = 1,
+static const struct software_node asus_me176c_tf103c_gpio_keys_node = {
 	.name = "lid_sw",
 };
 
+static const struct property_entry asus_me176c_tf103c_lid_props[] = {
+	PROPERTY_ENTRY_U32("linux,input-type", EV_SW),
+	PROPERTY_ENTRY_U32("linux,code", SW_LID),
+	PROPERTY_ENTRY_STRING("label", "lid_sw"),
+	PROPERTY_ENTRY_GPIO("gpios",
+			    &int33fc_gpiochip_nodes[2], 2, GPIO_ACTIVE_LOW),
+	PROPERTY_ENTRY_U32("debounce-interval", 50),
+	PROPERTY_ENTRY_BOOL("wakeup-source"),
+	{ }
+};
+
+static const struct software_node asus_me176c_tf103c_lid_node = {
+	.parent = &asus_me176c_tf103c_gpio_keys_node,
+	.properties = asus_me176c_tf103c_lid_props,
+};
+
+static const struct software_node *asus_me176c_tf103c_lid_swnodes[] = {
+	&asus_me176c_tf103c_gpio_keys_node,
+	&asus_me176c_tf103c_lid_node,
+	NULL
+};
+
 static const struct property_entry asus_me176c_tf103c_int3496_props[] = {
 	PROPERTY_ENTRY_GPIO("id-gpios",
 			    &int33fc_gpiochip_nodes[2], 22, GPIO_ACTIVE_HIGH),
 	{ }
 };
 
-static const struct platform_device_info asus_me176c_tf103c_pdevs[] __initconst = {
+static struct platform_device_info asus_me176c_tf103c_pdevs[] = {
 	{
 		.name = "gpio-keys",
 		.id = PLATFORM_DEVID_AUTO,
-		.data = &asus_me176c_tf103c_lid_pdata,
-		.size_data = sizeof(asus_me176c_tf103c_lid_pdata),
+		/* .fwnode will be filled by asus_me176c_tf103c_init() */
 	},
 	{
 		/* For micro USB ID pin handling */
@@ -353,17 +375,22 @@ static const struct platform_device_info asus_me176c_tf103c_pdevs[] __initconst
 
 static int __init asus_me176c_tf103c_init(void)
 {
-	struct gpio_desc *gpiod;
 	int ret;
 
-	ret = x86_android_tablet_get_gpiod("INT33FC:02", 12, &gpiod);
+	ret = software_node_register_node_group(asus_me176c_tf103c_lid_swnodes);
 	if (ret < 0)
 		return ret;
-	asus_me176c_tf103c_lid.gpio = desc_to_gpio(gpiod);
+
+	asus_me176c_tf103c_pdevs[0].fwnode =
+			software_node_fwnode(asus_me176c_tf103c_lid_swnodes[0]);
 
 	return 0;
 }
 
+static void __exit asus_me176c_tf103c_exit(void)
+{
+	software_node_unregister_node_group(asus_me176c_tf103c_lid_swnodes);
+}
 
 /* Asus ME176C tablets have an Android factory img with everything hardcoded */
 static const char * const asus_me176c_accel_mount_matrix[] = {
@@ -504,6 +531,7 @@ static const struct x86_dev_info asus_me176c_info __initconst = {
 	.modules = bq24190_modules,
 	.invalid_aei_gpiochip = "INT33FC:02",
 	.init = asus_me176c_tf103c_init,
+	.exit = asus_me176c_tf103c_exit,
 };
 
 /* Asus TF103C tablets have an Android factory img with everything hardcoded */
@@ -641,6 +669,7 @@ static const struct x86_dev_info asus_tf103c_info __initconst = {
 	.modules = bq24190_modules,
 	.invalid_aei_gpiochip = "INT33FC:02",
 	.init = asus_me176c_tf103c_init,
+	.exit = asus_me176c_tf103c_exit,
 };
 
 /*
@@ -1583,7 +1612,6 @@ static int serdev_count;
 static struct i2c_client **i2c_clients;
 static struct platform_device **pdevs;
 static struct serdev_device **serdevs;
-static struct gpiod_lookup_table * const *gpiod_lookup_tables;
 static const struct software_node *bat_swnode;
 static void (*exit_handler)(void);
 
@@ -1706,9 +1734,6 @@ static void x86_android_tablet_cleanup(void)
 	if (exit_handler)
 		exit_handler();
 
-	for (i = 0; gpiod_lookup_tables && gpiod_lookup_tables[i]; i++)
-		gpiod_remove_lookup_table(gpiod_lookup_tables[i]);
-
 	software_node_unregister(bat_swnode);
 	software_node_unregister_node_group(int33fc_gpiochip_node_group);
 }
@@ -1760,10 +1785,6 @@ static __init int x86_android_tablet_init(void)
 		}
 	}
 
-	gpiod_lookup_tables = dev_info->gpiod_lookup_tables;
-	for (i = 0; gpiod_lookup_tables && gpiod_lookup_tables[i]; i++)
-		gpiod_add_lookup_table(gpiod_lookup_tables[i]);
-
 	if (dev_info->init) {
 		ret = dev_info->init();
 		if (ret < 0) {
-- 
2.40.1.606.ga4b1b128d6-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] x86-android-tablets: convert to using GPIO references
  2023-05-12  0:18 [PATCH 0/4] x86-android-tablets: convert to using GPIO references Dmitry Torokhov
                   ` (3 preceding siblings ...)
  2023-05-12  0:18 ` [PATCH 4/4] platform/x86: x86-android-tablets: convert gpio_keys " Dmitry Torokhov
@ 2023-05-14 20:21 ` Hans de Goede
  4 siblings, 0 replies; 6+ messages in thread
From: Hans de Goede @ 2023-05-14 20:21 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Mark Gross, platform-driver-x86, linux-kernel

Hi Dmitry,

On 5/12/23 02:18, Dmitry Torokhov wrote:
> Hi Hans,
> 
> This series came about because now software nodes can be used to
> describe GPIOs (via PROPERTY_ENTRY_GPIO() macros) and I would like to
> eventually get rid of gpio_keys_platform_data structure.
> 
> So while I was doing the conversions from GPIO_LOOKUP() tables for
> gpio_keys devices I decided to convert the rest of them as well. Maybe
> some time in the future we can drop support for GPIO_LOOKUP() and rely
> on device properties exclusively.
> 
> This is completely untested.

Thank you for your work on this. I have hw to test this.

But it seems that you have based this on an older tree,
in 6.4-rc1 the x86-android-tablets code has been split
over multiple files in their own subdir because it was
becoming unyielding.

Can you please rebase this on top of:

https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=for-next

?

Regards,

Hans





> Dmitry Torokhov (4):
>   platform/x86: x86-android-tablets: convert Goodix devices to GPIO references
>   platform/x86: x86-android-tablets: convert int3496 devices to GPIO references
>   platform/x86: x86-android-tablets: convert wm1502 devices to GPIO references
>   platform/x86: x86-android-tablets: convert gpio_keys devices to GPIO references
> 
>  drivers/platform/x86/x86-android-tablets.c | 355 ++++++++++++---------
>  1 file changed, 201 insertions(+), 154 deletions(-)
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-05-14 20:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-12  0:18 [PATCH 0/4] x86-android-tablets: convert to using GPIO references Dmitry Torokhov
2023-05-12  0:18 ` [PATCH 1/4] platform/x86: x86-android-tablets: convert Goodix devices to " Dmitry Torokhov
2023-05-12  0:18 ` [PATCH 2/4] platform/x86: x86-android-tablets: convert int3496 " Dmitry Torokhov
2023-05-12  0:18 ` [PATCH 3/4] platform/x86: x86-android-tablets: convert wm1502 " Dmitry Torokhov
2023-05-12  0:18 ` [PATCH 4/4] platform/x86: x86-android-tablets: convert gpio_keys " Dmitry Torokhov
2023-05-14 20:21 ` [PATCH 0/4] x86-android-tablets: convert to using " Hans de Goede

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox