blob: ca807efe634fc78191eba24f3357df08f7c89261 [file] [log] [blame]
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014 Vladimir Serbinenko
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2, or (at your
9 * option) any later version, of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +010015 */
16
17#include <types.h>
18#include <console/console.h>
19#include <arch/acpi.h>
20#include <arch/acpigen.h>
21#include <device/device.h>
22#include <device/pnp.h>
23#include <string.h>
24#include "lenovo.h"
25#include "drivers/i2c/at24rf08c/lenovo.h"
26
27static const char tablet_numbers[][5] = {
28 /* X60t. */
29 "6363", "6364", "6365", "6366",
30 "6367", "6368", "7762", "7763",
31 "7764", "7767", "7768", "7769",
Alex Davidbb03aaa2015-05-14 20:09:18 -040032 /* X200t. */
33 "7448", "7449", "7450", "7453",
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +010034 /* X201t. */
35 "0053", "0831", "2985", "3093",
36 "3113", "3144", "3239", "4184",
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +010037 "2263", "2266",
38};
39
40int
41drivers_lenovo_is_wacom_present(void)
42{
43 const char *pn;
44 int i;
45 static int result = -1;
Elyes HAOUAS372917d2018-05-02 22:00:38 +020046 struct device *superio;
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +010047 u8 sioid;
48
49 if (result != -1)
50 return result;
51
52 if (IS_ENABLED(CONFIG_DIGITIZER_PRESENT)) {
53 printk (BIOS_INFO, "Digitizer state forced as present\n");
54 return (result = 1);
55 }
56
57 if (IS_ENABLED(CONFIG_DIGITIZER_ABSENT)) {
58 printk (BIOS_INFO, "Digitizer state forced as absent\n");
59 return (result = 0);
60 }
61
62 superio = dev_find_slot_pnp (0x164e, 3);
63 if (!superio) {
64 printk (BIOS_INFO, "No Super I/O, skipping wacom\n");
65 return (result = 0);
66 }
67
68 /* Probe ID. */
69 sioid = pnp_read_config(superio, 0x20);
70 if (sioid == 0xff) {
71 printk (BIOS_INFO, "Super I/O probe failed, skipping wacom\n");
72 return (result = 0);
73 }
74
75 pn = lenovo_mainboard_partnumber();
76 if (!pn)
77 return (result = 0);
78 printk (BIOS_DEBUG, "Lenovo P/N is %s\n", pn);
79 for (i = 0; i < ARRAY_SIZE (tablet_numbers); i++)
80 if (memcmp (tablet_numbers[i], pn, 4) == 0) {
81 printk (BIOS_DEBUG, "Lenovo P/N %s is a tablet\n", pn);
82 return (result = 1);
83 }
84 printk (BIOS_DEBUG, "Lenovo P/N %s is not a tablet\n", pn);
85 return (result = 0);
86}
87
88void
89drivers_lenovo_serial_ports_ssdt_generate(const char *scope,
90 int have_dock_serial)
91{
Vladimir Serbinenkobcb3abe2014-11-04 21:17:30 +010092 acpigen_write_scope(scope);
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +010093
94 if (drivers_lenovo_is_wacom_present()) {
Vladimir Serbinenko663be6e2014-11-05 21:29:45 +010095 acpigen_write_device("DTR");
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +010096
Vladimir Serbinenkobcb3abe2014-11-04 21:17:30 +010097 acpigen_write_name("_HID");
98 acpigen_emit_eisaid("WACF004");
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +010099
Vladimir Serbinenkobcb3abe2014-11-04 21:17:30 +0100100 acpigen_write_name("_CRS");
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +0100101
Vladimir Serbinenko9acc1e82014-11-09 03:37:28 +0100102 acpigen_write_resourcetemplate_header();
103 acpigen_write_io16(0x200, 0x200, 1, 8, 1);
104 acpigen_write_irq((1 << 5));
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +0100105
Vladimir Serbinenko9acc1e82014-11-09 03:37:28 +0100106 acpigen_write_resourcetemplate_footer();
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +0100107
Patrick Rudolphb1181c32017-08-13 11:04:04 +0200108 acpigen_write_STA(0xf);
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +0100109
Vladimir Serbinenkobcb3abe2014-11-04 21:17:30 +0100110 acpigen_pop_len();
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +0100111 }
112
113 if (have_dock_serial) {
Vladimir Serbinenko663be6e2014-11-05 21:29:45 +0100114 acpigen_write_device("COMA");
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +0100115
Vladimir Serbinenkobcb3abe2014-11-04 21:17:30 +0100116 acpigen_write_name("_HID");
117 acpigen_emit_eisaid("PNP0501");
118 acpigen_write_name("_UID");
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +0100119 /* Byte */
Vladimir Serbinenkobcb3abe2014-11-04 21:17:30 +0100120 acpigen_write_byte(0x2);
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +0100121
Vladimir Serbinenkobcb3abe2014-11-04 21:17:30 +0100122 acpigen_write_name("_CRS");
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +0100123
Vladimir Serbinenko9acc1e82014-11-09 03:37:28 +0100124 acpigen_write_resourcetemplate_header();
125 acpigen_write_io16(0x3f8, 0x3f8, 1, 8, 1);
126 acpigen_write_irq(1 << 4);
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +0100127
Vladimir Serbinenko9acc1e82014-11-09 03:37:28 +0100128 acpigen_write_resourcetemplate_footer();
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +0100129
Patrick Rudolphb1181c32017-08-13 11:04:04 +0200130 acpigen_write_STA(0xf);
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +0100131
Vladimir Serbinenkobcb3abe2014-11-04 21:17:30 +0100132 acpigen_pop_len();
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +0100133 }
134
Vladimir Serbinenkobcb3abe2014-11-04 21:17:30 +0100135 acpigen_pop_len();
Vladimir Serbinenkof2b3cd62014-02-15 17:00:46 +0100136}