acpi: Add IORT helper functions
[coreboot2.git] / src / drivers / lenovo / wacom.c
blob358c20f13750864b591ecfa4de365c3b5190d75e
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <types.h>
4 #include <console/console.h>
5 #include <acpi/acpigen.h>
6 #include <device/device.h>
7 #include <device/pnp.h>
8 #include <string.h>
9 #include "lenovo.h"
10 #include "drivers/i2c/at24rf08c/lenovo.h"
12 static const char tablet_numbers[][5] = {
13 /* X60t. */
14 "6363", "6364", "6365", "6366",
15 "6367", "6368", "7762", "7763",
16 "7764", "7767", "7768", "7769",
17 /* X200t. */
18 "7448", "7449", "7450", "7453",
19 /* X201t. */
20 "0053", "0831", "2985", "3093",
21 "3113", "3144", "3239", "4184",
22 "2263", "2266",
25 int
26 drivers_lenovo_is_wacom_present(void)
28 const char *pn;
29 int i;
30 static int result = -1;
31 struct device *superio;
32 u8 sioid;
34 if (result != -1)
35 return result;
37 if (CONFIG(DIGITIZER_PRESENT)) {
38 printk(BIOS_INFO, "Digitizer state forced as present\n");
39 return (result = 1);
42 if (CONFIG(DIGITIZER_ABSENT)) {
43 printk(BIOS_INFO, "Digitizer state forced as absent\n");
44 return (result = 0);
47 superio = dev_find_slot_pnp(0x164e, 3);
48 if (!superio) {
49 printk(BIOS_INFO, "No Super I/O, skipping wacom\n");
50 return (result = 0);
53 /* Probe ID. */
54 sioid = pnp_read_config(superio, 0x20);
55 if (sioid == 0xff) {
56 printk(BIOS_INFO, "Super I/O probe failed, skipping wacom\n");
57 return (result = 0);
60 pn = lenovo_mainboard_partnumber();
61 if (!pn)
62 return (result = 0);
63 printk(BIOS_DEBUG, "Lenovo P/N is %s\n", pn);
64 for (i = 0; i < ARRAY_SIZE(tablet_numbers); i++)
65 if (memcmp(tablet_numbers[i], pn, 4) == 0) {
66 printk(BIOS_DEBUG, "Lenovo P/N %s is a tablet\n", pn);
67 return (result = 1);
69 printk(BIOS_DEBUG, "Lenovo P/N %s is not a tablet\n", pn);
70 return (result = 0);
73 void
74 drivers_lenovo_serial_ports_ssdt_generate(const char *scope,
75 int have_dock_serial)
77 acpigen_write_scope(scope);
79 if (drivers_lenovo_is_wacom_present()) {
80 acpigen_write_device("DTR");
82 acpigen_write_name("_HID");
83 acpigen_emit_eisaid("WACF004");
85 acpigen_write_name("_CRS");
87 acpigen_write_resourcetemplate_header();
88 acpigen_write_io16(0x200, 0x200, 1, 8, 1);
89 acpigen_write_irq((1 << 5));
91 acpigen_write_resourcetemplate_footer();
93 acpigen_write_STA(0xf);
95 acpigen_pop_len();
98 if (have_dock_serial) {
99 acpigen_write_device("COMA");
101 acpigen_write_name("_HID");
102 acpigen_emit_eisaid("PNP0501");
103 acpigen_write_name("_UID");
104 /* Byte */
105 acpigen_write_byte(0x2);
107 acpigen_write_name("_CRS");
109 acpigen_write_resourcetemplate_header();
110 acpigen_write_io16(0x3f8, 0x3f8, 1, 8, 1);
111 acpigen_write_irq(1 << 4);
113 acpigen_write_resourcetemplate_footer();
115 acpigen_write_STA(0xf);
117 acpigen_pop_len();
120 acpigen_pop_len();