Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 2 | |
| 3 | #include <types.h> |
| 4 | #include <console/console.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 5 | #include <acpi/acpigen.h> |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 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" |
| 11 | |
| 12 | static const char tablet_numbers[][5] = { |
| 13 | /* X60t. */ |
| 14 | "6363", "6364", "6365", "6366", |
| 15 | "6367", "6368", "7762", "7763", |
| 16 | "7764", "7767", "7768", "7769", |
Alex David | bb03aaa | 2015-05-14 20:09:18 -0400 | [diff] [blame] | 17 | /* X200t. */ |
| 18 | "7448", "7449", "7450", "7453", |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 19 | /* X201t. */ |
| 20 | "0053", "0831", "2985", "3093", |
| 21 | "3113", "3144", "3239", "4184", |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 22 | "2263", "2266", |
| 23 | }; |
| 24 | |
| 25 | int |
| 26 | drivers_lenovo_is_wacom_present(void) |
| 27 | { |
| 28 | const char *pn; |
| 29 | int i; |
| 30 | static int result = -1; |
Elyes HAOUAS | 372917d | 2018-05-02 22:00:38 +0200 | [diff] [blame] | 31 | struct device *superio; |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 32 | u8 sioid; |
| 33 | |
| 34 | if (result != -1) |
| 35 | return result; |
| 36 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 37 | if (CONFIG(DIGITIZER_PRESENT)) { |
Elyes Haouas | 3c1a109 | 2023-08-26 16:47:33 +0200 | [diff] [blame] | 38 | printk(BIOS_INFO, "Digitizer state forced as present\n"); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 39 | return (result = 1); |
| 40 | } |
| 41 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 42 | if (CONFIG(DIGITIZER_ABSENT)) { |
Elyes Haouas | 3c1a109 | 2023-08-26 16:47:33 +0200 | [diff] [blame] | 43 | printk(BIOS_INFO, "Digitizer state forced as absent\n"); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 44 | return (result = 0); |
| 45 | } |
| 46 | |
Elyes Haouas | 78d2469 | 2023-09-10 10:41:55 +0200 | [diff] [blame^] | 47 | superio = dev_find_slot_pnp(0x164e, 3); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 48 | if (!superio) { |
Elyes Haouas | 3c1a109 | 2023-08-26 16:47:33 +0200 | [diff] [blame] | 49 | printk(BIOS_INFO, "No Super I/O, skipping wacom\n"); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 50 | return (result = 0); |
| 51 | } |
| 52 | |
| 53 | /* Probe ID. */ |
| 54 | sioid = pnp_read_config(superio, 0x20); |
| 55 | if (sioid == 0xff) { |
Elyes Haouas | 3c1a109 | 2023-08-26 16:47:33 +0200 | [diff] [blame] | 56 | printk(BIOS_INFO, "Super I/O probe failed, skipping wacom\n"); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 57 | return (result = 0); |
| 58 | } |
| 59 | |
| 60 | pn = lenovo_mainboard_partnumber(); |
| 61 | if (!pn) |
| 62 | return (result = 0); |
Elyes Haouas | 78d2469 | 2023-09-10 10:41:55 +0200 | [diff] [blame^] | 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) { |
Elyes Haouas | 3c1a109 | 2023-08-26 16:47:33 +0200 | [diff] [blame] | 66 | printk(BIOS_DEBUG, "Lenovo P/N %s is a tablet\n", pn); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 67 | return (result = 1); |
| 68 | } |
Elyes Haouas | 3c1a109 | 2023-08-26 16:47:33 +0200 | [diff] [blame] | 69 | printk(BIOS_DEBUG, "Lenovo P/N %s is not a tablet\n", pn); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 70 | return (result = 0); |
| 71 | } |
| 72 | |
| 73 | void |
| 74 | drivers_lenovo_serial_ports_ssdt_generate(const char *scope, |
| 75 | int have_dock_serial) |
| 76 | { |
Vladimir Serbinenko | bcb3abe | 2014-11-04 21:17:30 +0100 | [diff] [blame] | 77 | acpigen_write_scope(scope); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 78 | |
| 79 | if (drivers_lenovo_is_wacom_present()) { |
Vladimir Serbinenko | 663be6e | 2014-11-05 21:29:45 +0100 | [diff] [blame] | 80 | acpigen_write_device("DTR"); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 81 | |
Vladimir Serbinenko | bcb3abe | 2014-11-04 21:17:30 +0100 | [diff] [blame] | 82 | acpigen_write_name("_HID"); |
| 83 | acpigen_emit_eisaid("WACF004"); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 84 | |
Vladimir Serbinenko | bcb3abe | 2014-11-04 21:17:30 +0100 | [diff] [blame] | 85 | acpigen_write_name("_CRS"); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 86 | |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 87 | acpigen_write_resourcetemplate_header(); |
| 88 | acpigen_write_io16(0x200, 0x200, 1, 8, 1); |
| 89 | acpigen_write_irq((1 << 5)); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 90 | |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 91 | acpigen_write_resourcetemplate_footer(); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 92 | |
Patrick Rudolph | b1181c3 | 2017-08-13 11:04:04 +0200 | [diff] [blame] | 93 | acpigen_write_STA(0xf); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 94 | |
Vladimir Serbinenko | bcb3abe | 2014-11-04 21:17:30 +0100 | [diff] [blame] | 95 | acpigen_pop_len(); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | if (have_dock_serial) { |
Vladimir Serbinenko | 663be6e | 2014-11-05 21:29:45 +0100 | [diff] [blame] | 99 | acpigen_write_device("COMA"); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 100 | |
Vladimir Serbinenko | bcb3abe | 2014-11-04 21:17:30 +0100 | [diff] [blame] | 101 | acpigen_write_name("_HID"); |
| 102 | acpigen_emit_eisaid("PNP0501"); |
| 103 | acpigen_write_name("_UID"); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 104 | /* Byte */ |
Vladimir Serbinenko | bcb3abe | 2014-11-04 21:17:30 +0100 | [diff] [blame] | 105 | acpigen_write_byte(0x2); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 106 | |
Vladimir Serbinenko | bcb3abe | 2014-11-04 21:17:30 +0100 | [diff] [blame] | 107 | acpigen_write_name("_CRS"); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 108 | |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 109 | acpigen_write_resourcetemplate_header(); |
| 110 | acpigen_write_io16(0x3f8, 0x3f8, 1, 8, 1); |
| 111 | acpigen_write_irq(1 << 4); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 112 | |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 113 | acpigen_write_resourcetemplate_footer(); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 114 | |
Patrick Rudolph | b1181c3 | 2017-08-13 11:04:04 +0200 | [diff] [blame] | 115 | acpigen_write_STA(0xf); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 116 | |
Vladimir Serbinenko | bcb3abe | 2014-11-04 21:17:30 +0100 | [diff] [blame] | 117 | acpigen_pop_len(); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 118 | } |
| 119 | |
Vladimir Serbinenko | bcb3abe | 2014-11-04 21:17:30 +0100 | [diff] [blame] | 120 | acpigen_pop_len(); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 121 | } |