Skip to content

Commit 4014ae2

Browse files
committed
platform/x86: x86-android-tablets: Stop using gpiolib private APIs
Refactor x86_android_tablet_get_gpiod() to no longer use gpiolib private functions like gpiochip_find(). As a bonus this allows specifying that the GPIO is active-low, like the /CE (charge enable) pin on the bq25892 charger on the Lenovo Yoga Tablet 3. Reported-by: Bartosz Golaszewski <brgl@bgdev.pl> Closes: https://lore.kernel.org/platform-driver-x86/20230905185309.131295-12-brgl@bgdev.pl/ Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Link: https://lore.kernel.org/r/20230909141816.58358-7-hdegoede@redhat.com
1 parent 8b57d33 commit 4014ae2

5 files changed

Lines changed: 55 additions & 37 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ static const struct x86_i2c_client_info asus_tf103c_i2c_clients[] __initconst =
303303
.index = 28,
304304
.trigger = ACPI_EDGE_SENSITIVE,
305305
.polarity = ACPI_ACTIVE_LOW,
306+
.con_id = "atmel_mxt_ts_irq",
306307
},
307308
},
308309
};

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

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#include <linux/acpi.h>
1414
#include <linux/dmi.h>
15-
#include <linux/gpio/driver.h>
15+
#include <linux/gpio/consumer.h>
1616
#include <linux/gpio/machine.h>
1717
#include <linux/irq.h>
1818
#include <linux/module.h>
@@ -21,35 +21,39 @@
2121
#include <linux/string.h>
2222

2323
#include "x86-android-tablets.h"
24-
/* For gpiochip_get_desc() which is EXPORT_SYMBOL_GPL() */
25-
#include "../../../gpio/gpiolib.h"
26-
#include "../../../gpio/gpiolib-acpi.h"
2724

2825
static struct platform_device *x86_android_tablet_device;
2926

30-
static int gpiochip_find_match_label(struct gpio_chip *gc, void *data)
31-
{
32-
return gc->label && !strcmp(gc->label, data);
33-
}
34-
35-
int x86_android_tablet_get_gpiod(const char *label, int pin, struct gpio_desc **desc)
27+
int x86_android_tablet_get_gpiod(const char *chip, int pin, const char *con_id,
28+
bool active_low, enum gpiod_flags dflags,
29+
struct gpio_desc **desc)
3630
{
31+
struct gpiod_lookup_table *lookup;
3732
struct gpio_desc *gpiod;
38-
struct gpio_chip *chip;
3933

40-
chip = gpiochip_find((void *)label, gpiochip_find_match_label);
41-
if (!chip) {
42-
pr_err("error cannot find GPIO chip %s\n", label);
43-
return -ENODEV;
44-
}
34+
lookup = kzalloc(struct_size(lookup, table, 2), GFP_KERNEL);
35+
if (!lookup)
36+
return -ENOMEM;
37+
38+
lookup->dev_id = KBUILD_MODNAME;
39+
lookup->table[0].key = chip;
40+
lookup->table[0].chip_hwnum = pin;
41+
lookup->table[0].con_id = con_id;
42+
lookup->table[0].flags = active_low ? GPIO_ACTIVE_LOW : GPIO_ACTIVE_HIGH;
43+
44+
gpiod_add_lookup_table(lookup);
45+
gpiod = devm_gpiod_get(&x86_android_tablet_device->dev, con_id, dflags);
46+
gpiod_remove_lookup_table(lookup);
47+
kfree(lookup);
4548

46-
gpiod = gpiochip_get_desc(chip, pin);
4749
if (IS_ERR(gpiod)) {
48-
pr_err("error %ld getting GPIO %s %d\n", PTR_ERR(gpiod), label, pin);
50+
pr_err("error %ld getting GPIO %s %d\n", PTR_ERR(gpiod), chip, pin);
4951
return PTR_ERR(gpiod);
5052
}
5153

52-
*desc = gpiod;
54+
if (desc)
55+
*desc = gpiod;
56+
5357
return 0;
5458
}
5559

@@ -79,7 +83,8 @@ int x86_acpi_irq_helper_get(const struct x86_acpi_irq_data *data)
7983
return irq;
8084
case X86_ACPI_IRQ_TYPE_GPIOINT:
8185
/* Like acpi_dev_gpio_irq_get(), but without parsing ACPI resources */
82-
ret = x86_android_tablet_get_gpiod(data->chip, data->index, &gpiod);
86+
ret = x86_android_tablet_get_gpiod(data->chip, data->index, data->con_id,
87+
false, GPIOD_ASIS, &gpiod);
8388
if (ret)
8489
return ret;
8590

@@ -356,14 +361,18 @@ static __init int x86_android_tablet_probe(struct platform_device *pdev)
356361

357362
for (i = 0; i < dev_info->gpio_button_count; i++) {
358363
ret = x86_android_tablet_get_gpiod(dev_info->gpio_button[i].chip,
359-
dev_info->gpio_button[i].pin, &gpiod);
364+
dev_info->gpio_button[i].pin,
365+
dev_info->gpio_button[i].button.desc,
366+
false, GPIOD_IN, &gpiod);
360367
if (ret < 0) {
361368
x86_android_tablet_remove(pdev);
362369
return ret;
363370
}
364371

365372
buttons[i] = dev_info->gpio_button[i].button;
366373
buttons[i].gpio = desc_to_gpio(gpiod);
374+
/* Release gpiod so that gpio-keys can request it */
375+
devm_gpiod_put(&x86_android_tablet_device->dev, gpiod);
367376
}
368377

369378
pdata.buttons = buttons;

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static const struct x86_i2c_client_info lenovo_yb1_x90_i2c_clients[] __initconst
9595
.index = 56,
9696
.trigger = ACPI_EDGE_SENSITIVE,
9797
.polarity = ACPI_ACTIVE_LOW,
98+
.con_id = "goodix_ts_irq",
9899
},
99100
}, {
100101
/* Wacom Digitizer in keyboard half */
@@ -111,6 +112,7 @@ static const struct x86_i2c_client_info lenovo_yb1_x90_i2c_clients[] __initconst
111112
.index = 49,
112113
.trigger = ACPI_LEVEL_SENSITIVE,
113114
.polarity = ACPI_ACTIVE_LOW,
115+
.con_id = "wacom_irq",
114116
},
115117
}, {
116118
/* LP8557 Backlight controller */
@@ -136,6 +138,7 @@ static const struct x86_i2c_client_info lenovo_yb1_x90_i2c_clients[] __initconst
136138
.index = 77,
137139
.trigger = ACPI_LEVEL_SENSITIVE,
138140
.polarity = ACPI_ACTIVE_LOW,
141+
.con_id = "hideep_ts_irq",
139142
},
140143
},
141144
};
@@ -321,6 +324,7 @@ static struct x86_i2c_client_info lenovo_yoga_tab2_830_1050_i2c_clients[] __init
321324
.index = 2,
322325
.trigger = ACPI_EDGE_SENSITIVE,
323326
.polarity = ACPI_ACTIVE_HIGH,
327+
.con_id = "bq24292i_irq",
324328
},
325329
}, {
326330
/* BQ27541 fuel-gauge */
@@ -431,7 +435,8 @@ static int __init lenovo_yoga_tab2_830_1050_init_touchscreen(void)
431435
int ret;
432436

433437
/* Use PMIC GPIO 10 bootstrap pin to differentiate 830 vs 1050 */
434-
ret = x86_android_tablet_get_gpiod("gpio_crystalcove", 10, &gpiod);
438+
ret = x86_android_tablet_get_gpiod("gpio_crystalcove", 10, "yoga_bootstrap",
439+
false, GPIOD_IN, &gpiod);
435440
if (ret)
436441
return ret;
437442

@@ -615,6 +620,7 @@ static const struct x86_i2c_client_info lenovo_yt3_i2c_clients[] __initconst = {
615620
.index = 5,
616621
.trigger = ACPI_EDGE_SENSITIVE,
617622
.polarity = ACPI_ACTIVE_LOW,
623+
.con_id = "bq25892_0_irq",
618624
},
619625
}, {
620626
/* bq27500 fuel-gauge for the round li-ion cells in the hinge */
@@ -640,6 +646,7 @@ static const struct x86_i2c_client_info lenovo_yt3_i2c_clients[] __initconst = {
640646
.index = 77,
641647
.trigger = ACPI_LEVEL_SENSITIVE,
642648
.polarity = ACPI_ACTIVE_LOW,
649+
.con_id = "hideep_ts_irq",
643650
},
644651
}, {
645652
/* LP8557 Backlight controller */
@@ -655,7 +662,6 @@ static const struct x86_i2c_client_info lenovo_yt3_i2c_clients[] __initconst = {
655662

656663
static int __init lenovo_yt3_init(void)
657664
{
658-
struct gpio_desc *gpiod;
659665
int ret;
660666

661667
/*
@@ -665,31 +671,23 @@ static int __init lenovo_yt3_init(void)
665671
*
666672
* The bq25890_charger driver controls these through I2C, but this only
667673
* works if not overridden by the pins. Set these pins here:
668-
* 1. Set /CE to 0 to allow charging.
674+
* 1. Set /CE to 1 to allow charging.
669675
* 2. Set OTG to 0 disable V5 boost output since the 5V boost output of
670676
* the main "bq25892_1" charger is used when necessary.
671677
*/
672678

673679
/* /CE pin */
674-
ret = x86_android_tablet_get_gpiod("INT33FF:02", 22, &gpiod);
680+
ret = x86_android_tablet_get_gpiod("INT33FF:02", 22, "bq25892_0_ce",
681+
true, GPIOD_OUT_HIGH, NULL);
675682
if (ret < 0)
676683
return ret;
677684

678-
/*
679-
* The gpio_desc returned by x86_android_tablet_get_gpiod() is a "raw"
680-
* gpio_desc, that is there is no way to pass lookup-flags like
681-
* GPIO_ACTIVE_LOW. Set the GPIO to 0 here to enable charging since
682-
* the /CE pin is active-low, but not marked as such in the gpio_desc.
683-
*/
684-
gpiod_set_value(gpiod, 0);
685-
686685
/* OTG pin */
687-
ret = x86_android_tablet_get_gpiod("INT33FF:03", 19, &gpiod);
686+
ret = x86_android_tablet_get_gpiod("INT33FF:03", 19, "bq25892_0_otg",
687+
false, GPIOD_OUT_LOW, NULL);
688688
if (ret < 0)
689689
return ret;
690690

691-
gpiod_set_value(gpiod, 0);
692-
693691
/* Enable the regulators used by the touchscreen */
694692
intel_soc_pmic_exec_mipi_pmic_seq_element(0x6e, 0x9b, 0x02, 0xff);
695693
intel_soc_pmic_exec_mipi_pmic_seq_element(0x6e, 0xa0, 0x02, 0xff);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static const struct x86_i2c_client_info acer_b1_750_i2c_clients[] __initconst =
4747
.index = 3,
4848
.trigger = ACPI_EDGE_SENSITIVE,
4949
.polarity = ACPI_ACTIVE_LOW,
50+
.con_id = "NVT-ts_irq",
5051
},
5152
}, {
5253
/* BMA250E accelerometer */
@@ -62,6 +63,7 @@ static const struct x86_i2c_client_info acer_b1_750_i2c_clients[] __initconst =
6263
.index = 25,
6364
.trigger = ACPI_LEVEL_SENSITIVE,
6465
.polarity = ACPI_ACTIVE_HIGH,
66+
.con_id = "bma250e_irq",
6567
},
6668
},
6769
};
@@ -174,6 +176,7 @@ static const struct x86_i2c_client_info chuwi_hi8_i2c_clients[] __initconst = {
174176
.index = 23,
175177
.trigger = ACPI_LEVEL_SENSITIVE,
176178
.polarity = ACPI_ACTIVE_HIGH,
179+
.con_id = "bma250e_irq",
177180
},
178181
},
179182
};
@@ -312,6 +315,7 @@ static const struct x86_i2c_client_info medion_lifetab_s10346_i2c_clients[] __in
312315
.index = 23,
313316
.trigger = ACPI_EDGE_SENSITIVE,
314317
.polarity = ACPI_ACTIVE_HIGH,
318+
.con_id = "kxtj21009_irq",
315319
},
316320
}, {
317321
/* goodix touchscreen */
@@ -402,6 +406,7 @@ static const struct x86_i2c_client_info nextbook_ares8_i2c_clients[] __initconst
402406
.index = 3,
403407
.trigger = ACPI_EDGE_SENSITIVE,
404408
.polarity = ACPI_ACTIVE_LOW,
409+
.con_id = "ft5416_irq",
405410
},
406411
},
407412
};
@@ -460,6 +465,7 @@ static const struct x86_i2c_client_info nextbook_ares8a_i2c_clients[] __initcons
460465
.index = 17,
461466
.trigger = ACPI_EDGE_SENSITIVE,
462467
.polarity = ACPI_ACTIVE_LOW,
468+
.con_id = "ft5416_irq",
463469
},
464470
},
465471
};

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

Lines changed: 5 additions & 1 deletion
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/consumer.h>
1314
#include <linux/gpio_keys.h>
1415
#include <linux/i2c.h>
1516
#include <linux/irqdomain_defs.h>
@@ -37,6 +38,7 @@ struct x86_acpi_irq_data {
3738
int index;
3839
int trigger; /* ACPI_EDGE_SENSITIVE / ACPI_LEVEL_SENSITIVE */
3940
int polarity; /* ACPI_ACTIVE_HIGH / ACPI_ACTIVE_LOW / ACPI_ACTIVE_BOTH */
41+
const char *con_id;
4042
};
4143

4244
/* Structs to describe devices to instantiate */
@@ -81,7 +83,9 @@ struct x86_dev_info {
8183
void (*exit)(void);
8284
};
8385

84-
int x86_android_tablet_get_gpiod(const char *label, int pin, struct gpio_desc **desc);
86+
int x86_android_tablet_get_gpiod(const char *chip, int pin, const char *con_id,
87+
bool active_low, enum gpiod_flags dflags,
88+
struct gpio_desc **desc);
8589
int x86_acpi_irq_helper_get(const struct x86_acpi_irq_data *data);
8690

8791
/*

0 commit comments

Comments
 (0)