Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 1 | /* |
| 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 Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 15 | */ |
| 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 | |
| 27 | static const char tablet_numbers[][5] = { |
| 28 | /* X60t. */ |
| 29 | "6363", "6364", "6365", "6366", |
| 30 | "6367", "6368", "7762", "7763", |
| 31 | "7764", "7767", "7768", "7769", |
Alex David | bb03aaa | 2015-05-14 20:09:18 -0400 | [diff] [blame] | 32 | /* X200t. */ |
| 33 | "7448", "7449", "7450", "7453", |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 34 | /* X201t. */ |
| 35 | "0053", "0831", "2985", "3093", |
| 36 | "3113", "3144", "3239", "4184", |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 37 | "2263", "2266", |
| 38 | }; |
| 39 | |
| 40 | int |
| 41 | drivers_lenovo_is_wacom_present(void) |
| 42 | { |
| 43 | const char *pn; |
| 44 | int i; |
| 45 | static int result = -1; |
Elyes HAOUAS | 372917d | 2018-05-02 22:00:38 +0200 | [diff] [blame] | 46 | struct device *superio; |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 47 | 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 | |
| 88 | void |
| 89 | drivers_lenovo_serial_ports_ssdt_generate(const char *scope, |
| 90 | int have_dock_serial) |
| 91 | { |
Vladimir Serbinenko | bcb3abe | 2014-11-04 21:17:30 +0100 | [diff] [blame] | 92 | acpigen_write_scope(scope); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 93 | |
| 94 | if (drivers_lenovo_is_wacom_present()) { |
Vladimir Serbinenko | 663be6e | 2014-11-05 21:29:45 +0100 | [diff] [blame] | 95 | acpigen_write_device("DTR"); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 96 | |
Vladimir Serbinenko | bcb3abe | 2014-11-04 21:17:30 +0100 | [diff] [blame] | 97 | acpigen_write_name("_HID"); |
| 98 | acpigen_emit_eisaid("WACF004"); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 99 | |
Vladimir Serbinenko | bcb3abe | 2014-11-04 21:17:30 +0100 | [diff] [blame] | 100 | acpigen_write_name("_CRS"); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 101 | |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 102 | acpigen_write_resourcetemplate_header(); |
| 103 | acpigen_write_io16(0x200, 0x200, 1, 8, 1); |
| 104 | acpigen_write_irq((1 << 5)); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 105 | |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 106 | acpigen_write_resourcetemplate_footer(); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 107 | |
Patrick Rudolph | b1181c3 | 2017-08-13 11:04:04 +0200 | [diff] [blame] | 108 | acpigen_write_STA(0xf); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 109 | |
Vladimir Serbinenko | bcb3abe | 2014-11-04 21:17:30 +0100 | [diff] [blame] | 110 | acpigen_pop_len(); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | if (have_dock_serial) { |
Vladimir Serbinenko | 663be6e | 2014-11-05 21:29:45 +0100 | [diff] [blame] | 114 | acpigen_write_device("COMA"); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 115 | |
Vladimir Serbinenko | bcb3abe | 2014-11-04 21:17:30 +0100 | [diff] [blame] | 116 | acpigen_write_name("_HID"); |
| 117 | acpigen_emit_eisaid("PNP0501"); |
| 118 | acpigen_write_name("_UID"); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 119 | /* Byte */ |
Vladimir Serbinenko | bcb3abe | 2014-11-04 21:17:30 +0100 | [diff] [blame] | 120 | acpigen_write_byte(0x2); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 121 | |
Vladimir Serbinenko | bcb3abe | 2014-11-04 21:17:30 +0100 | [diff] [blame] | 122 | acpigen_write_name("_CRS"); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 123 | |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 124 | acpigen_write_resourcetemplate_header(); |
| 125 | acpigen_write_io16(0x3f8, 0x3f8, 1, 8, 1); |
| 126 | acpigen_write_irq(1 << 4); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 127 | |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 128 | acpigen_write_resourcetemplate_footer(); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 129 | |
Patrick Rudolph | b1181c3 | 2017-08-13 11:04:04 +0200 | [diff] [blame] | 130 | acpigen_write_STA(0xf); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 131 | |
Vladimir Serbinenko | bcb3abe | 2014-11-04 21:17:30 +0100 | [diff] [blame] | 132 | acpigen_pop_len(); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 133 | } |
| 134 | |
Vladimir Serbinenko | bcb3abe | 2014-11-04 21:17:30 +0100 | [diff] [blame] | 135 | acpigen_pop_len(); |
Vladimir Serbinenko | f2b3cd6 | 2014-02-15 17:00:46 +0100 | [diff] [blame] | 136 | } |