1/* SPDX-License-Identifier: GPL-2.0-or-later
2 *
3 * DMI based code to deal with broken DSDTs on X86 tablets which ship with
4 * Android as (part of) the factory image. The factory kernels shipped on these
5 * devices typically have a bunch of things hardcoded, rather than specified
6 * in their DSDT.
7 *
8 * Copyright (C) 2021-2023 Hans de Goede <hdegoede@redhat.com>
9 */
10#ifndef __PDX86_X86_ANDROID_TABLETS_H
11#define __PDX86_X86_ANDROID_TABLETS_H
12
13#include <linux/gpio_keys.h>
14#include <linux/i2c.h>
15#include <linux/irqdomain_defs.h>
16
17struct gpio_desc;
18struct gpiod_lookup_table;
19struct platform_device_info;
20struct software_node;
21
22/*
23 * Helpers to get Linux IRQ numbers given a description of the IRQ source
24 * (either IOAPIC index, or GPIO chip name + pin-number).
25 */
26enum x86_acpi_irq_type {
27	X86_ACPI_IRQ_TYPE_NONE,
28	X86_ACPI_IRQ_TYPE_APIC,
29	X86_ACPI_IRQ_TYPE_GPIOINT,
30	X86_ACPI_IRQ_TYPE_PMIC,
31};
32
33struct x86_acpi_irq_data {
34	char *chip;   /* GPIO chip label (GPIOINT) or PMIC ACPI path (PMIC) */
35	enum x86_acpi_irq_type type;
36	enum irq_domain_bus_token domain;
37	int index;
38	int trigger;  /* ACPI_EDGE_SENSITIVE / ACPI_LEVEL_SENSITIVE */
39	int polarity; /* ACPI_ACTIVE_HIGH / ACPI_ACTIVE_LOW / ACPI_ACTIVE_BOTH */
40};
41
42/* Structs to describe devices to instantiate */
43struct x86_i2c_client_info {
44	struct i2c_board_info board_info;
45	char *adapter_path;
46	struct x86_acpi_irq_data irq_data;
47};
48
49struct x86_serdev_info {
50	const char *ctrl_hid;
51	const char *ctrl_uid;
52	const char *ctrl_devname;
53	/*
54	 * ATM the serdev core only supports of or ACPI matching; and sofar all
55	 * Android x86 tablets DSDTs have usable serdev nodes, but sometimes
56	 * under the wrong controller. So we just tie the existing serdev ACPI
57	 * node to the right controller.
58	 */
59	const char *serdev_hid;
60};
61
62struct x86_gpio_button {
63	struct gpio_keys_button button;
64	const char *chip;
65	int pin;
66};
67
68struct x86_dev_info {
69	char *invalid_aei_gpiochip;
70	const char * const *modules;
71	const struct software_node *bat_swnode;
72	struct gpiod_lookup_table * const *gpiod_lookup_tables;
73	const struct x86_i2c_client_info *i2c_client_info;
74	const struct platform_device_info *pdev_info;
75	const struct x86_serdev_info *serdev_info;
76	const struct x86_gpio_button *gpio_button;
77	int i2c_client_count;
78	int pdev_count;
79	int serdev_count;
80	int gpio_button_count;
81	int (*init)(void);
82	void (*exit)(void);
83};
84
85int x86_android_tablet_get_gpiod(const char *label, int pin, struct gpio_desc **desc);
86int x86_acpi_irq_helper_get(const struct x86_acpi_irq_data *data);
87
88/*
89 * Extern declarations of x86_dev_info structs so there can be a single
90 * MODULE_DEVICE_TABLE(dmi, ...), while splitting the board descriptions.
91 */
92extern const struct x86_dev_info acer_b1_750_info;
93extern const struct x86_dev_info advantech_mica_071_info;
94extern const struct x86_dev_info asus_me176c_info;
95extern const struct x86_dev_info asus_tf103c_info;
96extern const struct x86_dev_info chuwi_hi8_info;
97extern const struct x86_dev_info cyberbook_t116_info;
98extern const struct x86_dev_info czc_p10t;
99extern const struct x86_dev_info lenovo_yogabook_x90_info;
100extern const struct x86_dev_info lenovo_yogabook_x91_info;
101extern const struct x86_dev_info lenovo_yoga_tab2_830_1050_info;
102extern const struct x86_dev_info lenovo_yt3_info;
103extern const struct x86_dev_info medion_lifetab_s10346_info;
104extern const struct x86_dev_info nextbook_ares8_info;
105extern const struct x86_dev_info nextbook_ares8a_info;
106extern const struct x86_dev_info peaq_c1010_info;
107extern const struct x86_dev_info whitelabel_tm800a550l_info;
108extern const struct x86_dev_info xiaomi_mipad2_info;
109extern const struct dmi_system_id x86_android_tablet_ids[];
110
111#endif
112