xref: /linux/drivers/platform/x86/x86-android-tablets/x86-android-tablets.h (revision d2c9a99135da931377240942d44f3dea104cedb8)
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 <hansg@kernel.org>
9  */
10 #ifndef __PDX86_X86_ANDROID_TABLETS_H
11 #define __PDX86_X86_ANDROID_TABLETS_H
12 
13 #include <linux/gpio/consumer.h>
14 #include <linux/i2c.h>
15 #include <linux/irqdomain_defs.h>
16 #include <linux/device-id/dmi.h>
17 #include <linux/spi/spi.h>
18 
19 struct gpio_desc;
20 struct platform_device_info;
21 struct software_node;
22 
23 /*
24  * Helpers to get Linux IRQ numbers given a description of the IRQ source
25  * (either IOAPIC index, or GPIO chip name + pin-number).
26  */
27 enum x86_acpi_irq_type {
28 	X86_ACPI_IRQ_TYPE_NONE,
29 	X86_ACPI_IRQ_TYPE_APIC,
30 	X86_ACPI_IRQ_TYPE_GPIOINT,
31 	X86_ACPI_IRQ_TYPE_PMIC,
32 };
33 
34 enum x86_gpiochip_type {
35 	X86_GPIOCHIP_UNSPECIFIED = 0,
36 	X86_GPIOCHIP_BAYTRAIL,
37 	X86_GPIOCHIP_CHERRYVIEW,
38 };
39 
40 struct x86_acpi_irq_data {
41 	char *chip;   /* GPIO chip label (GPIOINT) or PMIC ACPI path (PMIC) */
42 	enum x86_acpi_irq_type type;
43 	enum irq_domain_bus_token domain;
44 	int index;
45 	int trigger;  /* ACPI_EDGE_SENSITIVE / ACPI_LEVEL_SENSITIVE */
46 	int polarity; /* ACPI_ACTIVE_HIGH / ACPI_ACTIVE_LOW / ACPI_ACTIVE_BOTH */
47 	bool free_gpio; /* Release GPIO after getting IRQ (for TYPE_GPIOINT) */
48 	const char *con_id;
49 };
50 
51 /* Structs to describe devices to instantiate */
52 struct x86_i2c_client_info {
53 	struct i2c_board_info board_info;
54 	char *adapter_path;
55 	struct x86_acpi_irq_data irq_data;
56 };
57 
58 struct x86_spi_dev_info {
59 	struct spi_board_info board_info;
60 	char *ctrl_path;
61 	struct x86_acpi_irq_data irq_data;
62 };
63 
64 struct x86_serdev_info {
65 	union {
66 		struct {
67 			const char *hid;
68 			const char *uid;
69 		} acpi;
70 		struct {
71 			unsigned int devfn;
72 		} pci;
73 	} ctrl;
74 	const char *ctrl_devname;
75 	/*
76 	 * ATM the serdev core only supports of or ACPI matching; and so far all
77 	 * Android x86 tablets DSDTs have usable serdev nodes, but sometimes
78 	 * under the wrong controller. So we just tie the existing serdev ACPI
79 	 * node to the right controller.
80 	 */
81 	const char *serdev_hid;
82 };
83 
84 struct x86_dev_info {
85 	const char * const *modules;
86 	const struct software_node **swnode_group;
87 	const struct x86_i2c_client_info *i2c_client_info;
88 	const struct x86_spi_dev_info *spi_dev_info;
89 	const struct platform_device_info *pdev_info;
90 	const struct x86_serdev_info *serdev_info;
91 	const struct software_node **gpio_button_swnodes;
92 	int i2c_client_count;
93 	int spi_dev_count;
94 	int pdev_count;
95 	int serdev_count;
96 	int (*init)(struct device *dev);
97 	void (*exit)(void);
98 	bool use_pci;
99 	enum x86_gpiochip_type gpiochip_type;
100 };
101 
102 int x86_android_tablet_get_gpiod(const char *chip, int pin, const char *con_id,
103 				 bool active_low, enum gpiod_flags dflags,
104 				 struct gpio_desc **desc);
105 int x86_acpi_irq_helper_get(const struct x86_acpi_irq_data *data);
106 
107 /* Software nodes representing GPIO chips used by various tablets */
108 extern const struct software_node baytrail_gpiochip_nodes[];
109 extern const struct software_node cherryview_gpiochip_nodes[];
110 
111 /*
112  * Extern declarations of x86_dev_info structs so there can be a single
113  * MODULE_DEVICE_TABLE(dmi, ...), while splitting the board descriptions.
114  */
115 extern const struct x86_dev_info acer_a1_840_info;
116 extern const struct x86_dev_info acer_b1_750_info;
117 extern const struct x86_dev_info advantech_mica_071_info;
118 extern const struct x86_dev_info asus_me176c_info;
119 extern const struct x86_dev_info asus_tf103c_info;
120 extern const struct x86_dev_info chuwi_hi8_info;
121 extern const struct x86_dev_info cyberbook_t116_info;
122 extern const struct x86_dev_info czc_p10t;
123 extern const struct x86_dev_info lenovo_yogabook_x90_info;
124 extern const struct x86_dev_info lenovo_yogabook_x91_info;
125 extern const struct x86_dev_info lenovo_yoga_tab2_830_1050_info;
126 extern const struct x86_dev_info lenovo_yoga_tab2_1380_info;
127 extern const struct x86_dev_info lenovo_yt3_info;
128 extern const struct x86_dev_info medion_lifetab_s10346_info;
129 extern const struct x86_dev_info nextbook_ares8_info;
130 extern const struct x86_dev_info nextbook_ares8a_info;
131 extern const struct x86_dev_info peaq_c1010_info;
132 extern const struct x86_dev_info whitelabel_tm800a550l_info;
133 extern const struct x86_dev_info vexia_edu_atla10_5v_info;
134 extern const struct x86_dev_info vexia_edu_atla10_9v_info;
135 extern const struct x86_dev_info xiaomi_mipad2_info;
136 extern const struct dmi_system_id x86_android_tablet_ids[];
137 
138 #endif
139