Skip to content

Commit e2200d3

Browse files
committed
platform/x86: x86-android-tablets: Add gpio_keys support to x86_android_tablet_init()
Add gpio_keys instantation support to x86_android_tablet_init(), to avoid this having to be repeated in various x86_dev_info.init() functions. Signed-off-by: Hans de Goede <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent cc183ad commit e2200d3

File tree

4 files changed

+64
-90
lines changed

4 files changed

+64
-90
lines changed

drivers/platform/x86/x86-android-tablets/asus.c

Lines changed: 16 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
* Copyright (C) 2021-2023 Hans de Goede <[email protected]>
99
*/
1010

11-
#include <linux/gpio_keys.h>
12-
#include <linux/gpio/consumer.h>
1311
#include <linux/gpio/machine.h>
1412
#include <linux/input.h>
1513
#include <linux/platform_device.h>
@@ -26,50 +24,19 @@ static struct gpiod_lookup_table int3496_gpo2_pin22_gpios = {
2624
},
2725
};
2826

29-
static struct gpio_keys_button asus_me176c_tf103c_lid = {
30-
.code = SW_LID,
31-
/* .gpio gets filled in by asus_me176c_tf103c_init() */
32-
.active_low = true,
33-
.desc = "lid_sw",
34-
.type = EV_SW,
35-
.wakeup = true,
36-
.debounce_interval = 50,
37-
};
38-
39-
static const struct gpio_keys_platform_data asus_me176c_tf103c_lid_pdata __initconst = {
40-
.buttons = &asus_me176c_tf103c_lid,
41-
.nbuttons = 1,
42-
.name = "lid_sw",
43-
};
44-
45-
static const struct platform_device_info asus_me176c_tf103c_pdevs[] __initconst = {
46-
{
47-
.name = "gpio-keys",
48-
.id = PLATFORM_DEVID_AUTO,
49-
.data = &asus_me176c_tf103c_lid_pdata,
50-
.size_data = sizeof(asus_me176c_tf103c_lid_pdata),
51-
},
52-
{
53-
/* For micro USB ID pin handling */
54-
.name = "intel-int3496",
55-
.id = PLATFORM_DEVID_NONE,
27+
static struct x86_gpio_button asus_me176c_tf103c_lid = {
28+
.button = {
29+
.code = SW_LID,
30+
.active_low = true,
31+
.desc = "lid_sw",
32+
.type = EV_SW,
33+
.wakeup = true,
34+
.debounce_interval = 50,
5635
},
36+
.chip = "INT33FC:02",
37+
.pin = 12,
5738
};
5839

59-
static int __init asus_me176c_tf103c_init(void)
60-
{
61-
struct gpio_desc *gpiod;
62-
int ret;
63-
64-
ret = x86_android_tablet_get_gpiod("INT33FC:02", 12, &gpiod);
65-
if (ret < 0)
66-
return ret;
67-
asus_me176c_tf103c_lid.gpio = desc_to_gpio(gpiod);
68-
69-
return 0;
70-
}
71-
72-
7340
/* Asus ME176C tablets have an Android factory img with everything hardcoded */
7441
static const char * const asus_me176c_accel_mount_matrix[] = {
7542
"-1", "0", "0",
@@ -203,15 +170,15 @@ static struct gpiod_lookup_table * const asus_me176c_gpios[] = {
203170
const struct x86_dev_info asus_me176c_info __initconst = {
204171
.i2c_client_info = asus_me176c_i2c_clients,
205172
.i2c_client_count = ARRAY_SIZE(asus_me176c_i2c_clients),
206-
.pdev_info = asus_me176c_tf103c_pdevs,
207-
.pdev_count = ARRAY_SIZE(asus_me176c_tf103c_pdevs),
173+
.pdev_info = int3496_pdevs,
174+
.pdev_count = 1,
208175
.serdev_info = asus_me176c_serdevs,
209176
.serdev_count = ARRAY_SIZE(asus_me176c_serdevs),
177+
.gpio_button = &asus_me176c_tf103c_lid,
210178
.gpiod_lookup_tables = asus_me176c_gpios,
211179
.bat_swnode = &generic_lipo_hv_4v35_battery_node,
212180
.modules = bq24190_modules,
213181
.invalid_aei_gpiochip = "INT33FC:02",
214-
.init = asus_me176c_tf103c_init,
215182
};
216183

217184
/* Asus TF103C tablets have an Android factory img with everything hardcoded */
@@ -348,11 +315,11 @@ static struct gpiod_lookup_table * const asus_tf103c_gpios[] = {
348315
const struct x86_dev_info asus_tf103c_info __initconst = {
349316
.i2c_client_info = asus_tf103c_i2c_clients,
350317
.i2c_client_count = ARRAY_SIZE(asus_tf103c_i2c_clients),
351-
.pdev_info = asus_me176c_tf103c_pdevs,
352-
.pdev_count = ARRAY_SIZE(asus_me176c_tf103c_pdevs),
318+
.pdev_info = int3496_pdevs,
319+
.pdev_count = 1,
320+
.gpio_button = &asus_me176c_tf103c_lid,
353321
.gpiod_lookup_tables = asus_tf103c_gpios,
354322
.bat_swnode = &asus_tf103c_battery_node,
355323
.modules = bq24190_modules,
356324
.invalid_aei_gpiochip = "INT33FC:02",
357-
.init = asus_me176c_tf103c_init,
358325
};

drivers/platform/x86/x86-android-tablets/core.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ static __init int x86_android_tablet_init(void)
322322
}
323323
}
324324

325-
pdevs = kcalloc(dev_info->pdev_count, sizeof(*pdevs), GFP_KERNEL);
325+
/* + 1 to make space for (optional) gpio_keys_button pdev */
326+
pdevs = kcalloc(dev_info->pdev_count + 1, sizeof(*pdevs), GFP_KERNEL);
326327
if (!pdevs) {
327328
x86_android_tablet_cleanup();
328329
return -ENOMEM;
@@ -352,6 +353,33 @@ static __init int x86_android_tablet_init(void)
352353
}
353354
}
354355

356+
if (dev_info->gpio_button) {
357+
struct gpio_keys_platform_data pdata = {
358+
.buttons = &dev_info->gpio_button->button,
359+
.nbuttons = 1,
360+
};
361+
struct gpio_desc *gpiod;
362+
363+
/* Get GPIO for the gpio-button */
364+
ret = x86_android_tablet_get_gpiod(dev_info->gpio_button->chip,
365+
dev_info->gpio_button->pin, &gpiod);
366+
if (ret < 0) {
367+
x86_android_tablet_cleanup();
368+
return ret;
369+
}
370+
371+
dev_info->gpio_button->button.gpio = desc_to_gpio(gpiod);
372+
373+
pdevs[pdev_count] = platform_device_register_data(NULL, "gpio-keys",
374+
PLATFORM_DEVID_AUTO,
375+
&pdata, sizeof(pdata));
376+
if (IS_ERR(pdevs[pdev_count])) {
377+
x86_android_tablet_cleanup();
378+
return PTR_ERR(pdevs[pdev_count]);
379+
}
380+
pdev_count++;
381+
}
382+
355383
return 0;
356384
}
357385

drivers/platform/x86/x86-android-tablets/other.c

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
*/
1010

1111
#include <linux/acpi.h>
12-
#include <linux/gpio_keys.h>
13-
#include <linux/gpio/consumer.h>
1412
#include <linux/gpio/machine.h>
1513
#include <linux/input.h>
1614
#include <linux/platform_device.h>
@@ -96,48 +94,21 @@ const struct x86_dev_info acer_b1_750_info __initconst = {
9694
* which is not described in the ACPI tables in anyway.
9795
* Use the x86-android-tablets infra to create a gpio-button device for this.
9896
*/
99-
static struct gpio_keys_button advantech_mica_071_button = {
100-
.code = KEY_PROG1,
101-
/* .gpio gets filled in by advantech_mica_071_init() */
102-
.active_low = true,
103-
.desc = "prog1_key",
104-
.type = EV_KEY,
105-
.wakeup = false,
106-
.debounce_interval = 50,
107-
};
108-
109-
static const struct gpio_keys_platform_data advantech_mica_071_button_pdata __initconst = {
110-
.buttons = &advantech_mica_071_button,
111-
.nbuttons = 1,
112-
.name = "prog1_key",
113-
};
114-
115-
static const struct platform_device_info advantech_mica_071_pdevs[] __initconst = {
116-
{
117-
.name = "gpio-keys",
118-
.id = PLATFORM_DEVID_AUTO,
119-
.data = &advantech_mica_071_button_pdata,
120-
.size_data = sizeof(advantech_mica_071_button_pdata),
97+
static struct x86_gpio_button advantech_mica_071_button = {
98+
.button = {
99+
.code = KEY_PROG1,
100+
.active_low = true,
101+
.desc = "prog1_key",
102+
.type = EV_KEY,
103+
.wakeup = false,
104+
.debounce_interval = 50,
121105
},
106+
.chip = "INT33FC:00",
107+
.pin = 2,
122108
};
123109

124-
static int __init advantech_mica_071_init(void)
125-
{
126-
struct gpio_desc *gpiod;
127-
int ret;
128-
129-
ret = x86_android_tablet_get_gpiod("INT33FC:00", 2, &gpiod);
130-
if (ret < 0)
131-
return ret;
132-
advantech_mica_071_button.gpio = desc_to_gpio(gpiod);
133-
134-
return 0;
135-
}
136-
137110
const struct x86_dev_info advantech_mica_071_info __initconst = {
138-
.pdev_info = advantech_mica_071_pdevs,
139-
.pdev_count = ARRAY_SIZE(advantech_mica_071_pdevs),
140-
.init = advantech_mica_071_init,
111+
.gpio_button = &advantech_mica_071_button,
141112
};
142113

143114
/*

drivers/platform/x86/x86-android-tablets/x86-android-tablets.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#ifndef __PDX86_X86_ANDROID_TABLETS_H
1111
#define __PDX86_X86_ANDROID_TABLETS_H
1212

13+
#include <linux/gpio_keys.h>
1314
#include <linux/i2c.h>
1415
#include <linux/irqdomain_defs.h>
1516

@@ -58,6 +59,12 @@ struct x86_serdev_info {
5859
const char *serdev_hid;
5960
};
6061

62+
struct x86_gpio_button {
63+
struct gpio_keys_button button;
64+
const char *chip;
65+
int pin;
66+
};
67+
6168
struct x86_dev_info {
6269
char *invalid_aei_gpiochip;
6370
const char * const *modules;
@@ -66,6 +73,7 @@ struct x86_dev_info {
6673
const struct x86_i2c_client_info *i2c_client_info;
6774
const struct platform_device_info *pdev_info;
6875
const struct x86_serdev_info *serdev_info;
76+
struct x86_gpio_button *gpio_button;
6977
int i2c_client_count;
7078
int pdev_count;
7179
int serdev_count;

0 commit comments

Comments
 (0)