Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2009 coresystems GmbH |
| 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 of |
| 9 | * 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. |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <types.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <console/console.h> |
| 20 | #include <arch/io.h> |
| 21 | #include <delay.h> |
| 22 | |
Sven Schnelle | 7592e8b | 2011-01-27 11:43:03 +0000 | [diff] [blame] | 23 | #include <ec/acpi/ec.h> |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 24 | #include "m3885.h" |
| 25 | |
| 26 | #define TH0LOW 80 |
| 27 | #define TH0HIGH 85 |
| 28 | #define TH0CRIT 120 |
| 29 | #define TH1LOW 75 |
| 30 | #define TH1HIGH 80 |
| 31 | |
| 32 | static u8 variables[] = { |
| 33 | /* Offs, AND, OR */ |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 34 | 0x08, 0x48, 0x6C, /* Keyboard ScanCode Set & LED Data (kState1) */ |
| 35 | 0x0a, 0x01, 0x00, /* Keyboard Shift flags (kState3) */ |
| 36 | 0x0c, 0x80, 0x08, /* Keyboard State flags (kState5) */ |
| 37 | 0x11, 0xff, 0x06, /* Make/Break Debounce #'s (debounce) */ |
| 38 | 0x13, 0xff, 0x00, /* HotKey1 ScanCode (hotKey1) */ |
| 39 | 0x14, 0xff, 0x00, /* HotKey2 ScanCode (hotKey2) */ |
| 40 | 0x15, 0xff, 0x3f, /* HotKey3 ScanCode (hotKey3) */ |
| 41 | 0x16, 0xff, 0x00, /* HotKey4 ScanCode (hotKey4) */ |
| 42 | 0x17, 0xff, 0x00, /* HotKey5 ScanCode (hotKey5) */ |
| 43 | 0x18, 0xff, 0x0e, /* HotKey6 ScanCode (hotKey6) */ |
| 44 | 0x19, 0xff, 0x9f, /* HotKey1 Task = c5 Command Data (keyTsk1) */ |
| 45 | 0x1a, 0xff, 0x9f, /* HotKey2 Task = c5 Command Data (keyTsk2) */ |
| 46 | 0x1b, 0xff, 0x6a, /* HotKey3 Task = c5 Command Data (keyTsk3) */ |
| 47 | 0x1c, 0xff, 0x9f, /* HotKey4 Task = c5 Command Data (keyTsk4) */ |
| 48 | 0x1d, 0xff, 0x9f, /* HotKey5 Task = c5 Command Data (keyTsk5) */ |
| 49 | 0x1e, 0xff, 0x87, /* FuncKey Task = c5 Command Data (funcTsk) */ |
| 50 | 0x1f, 0xff, 0x9f, /* Delayed Task = c5 Command Data (dlyTsk1) */ |
| 51 | 0x20, 0xff, 0x9f, /* Wake-Up Task = c5 Command Data (wakeTsk) */ |
| 52 | |
| 53 | 0x21, 0xff, 0x08, /* WigglePin Pulse Width * 2.4ms (tmPulse) */ |
| 54 | 0x24, 0xff, 0x30, /* Keyboard State Flags (kState7) */ |
| 55 | |
| 56 | 0x2b, 0xff, 0x00, |
| 57 | 0x2c, 0xff, 0x80, /* Set Fn-Key 8 */ |
| 58 | 0x2d, 0xff, 0x02, /* Set Fn-Key 9 */ |
| 59 | 0x2e, 0xff, 0x00, /* Set Fn-Key 1-8 task (0 = SMI) */ |
| 60 | 0x2f, 0xff, 0x00, /* Set Fn-Key 9-12 task (1 = SCI) */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | static u8 matrix[] = { |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 64 | 0xc1,0xc0,0xd8,0xdb,0xbf,0x05,0x76,0xbf, /* (0x00-0x07) */ |
| 65 | 0xbf,0x80,0x78,0xbf,0xbf,0x07,0x88,0xc2, /* (0x08-0x0f) */ |
| 66 | 0x03,0x09,0xd9,0x16,0xbf,0x06,0x0e,0x81, /* (0x10-0x17) */ |
| 67 | 0xbf,0xbf,0xee,0xbf,0xbf,0x55,0x9a,0x89, /* (0x18-0x1f) */ |
| 68 | 0x1e,0x15,0x36,0xda,0xe8,0xbf,0x0d,0xbf, /* (0x20-0x27) */ |
| 69 | 0xbf,0xbf,0xbf,0xa3,0xbf,0x4e,0x66,0x8b, /* (0x28-0x2f) */ |
| 70 | 0x1d,0x2e,0xe6,0xe7,0xe5,0x1c,0x58,0xbf, /* (0x30-0x37) */ |
| 71 | 0x82,0xbf,0xf0,0xbf,0xbf,0x5b,0x5d,0x8c, /* (0x38-0x3f) */ |
| 72 | 0x22,0x25,0x2c,0x35,0xe1,0x1a,0x96,0xbf, /* (0x40-0x47) */ |
| 73 | 0xbf,0xbf,0xec,0xbf,0xbf,0x54,0xf1,0x8f, /* (0x48-0x4f) */ |
| 74 | 0x1b,0x2a,0x2b,0x32,0xe9,0x31,0x29,0x61, /* (0x50-0x57) */ |
| 75 | 0xbf,0xbf,0x8d,0xbf,0x86,0xc3,0x92,0x93, /* (0x58-0x5f) */ |
| 76 | 0x21,0x23,0x34,0x33,0x41,0xe0,0xbf,0xbf, /* (0x60-0x67) */ |
| 77 | 0xbf,0x85,0xeb,0xbf,0xb6,0xbf,0x91,0xbf, /* (0x68-0x6f) */ |
| 78 | 0x26,0x24,0x2d,0xe3,0xe2,0xe4,0xbf,0xbf, /* (0x70-0x77) */ |
| 79 | 0x87,0xbf,0xea,0xbf,0xbf,0x52,0x90,0x8e, /* (0x78-0x7f) */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | static u8 function_ram[] = { |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 83 | 0x04,0xbd,0x0c,0xbe,0x7e,0x9a,0x8a,0xb6, /* (0xc0-0xc3) */ |
| 84 | 0x92,0x8f,0x93,0x8e,0x81,0x86,0x82,0x87, /* (0xc4-0xc7) */ |
| 85 | 0x8a,0x9a,0x8d,0x7e,0x88,0x84,0x7e,0x78, /* (0xc8-0xcb) */ |
| 86 | 0x77,0x07,0x77,0x98,0x89,0xb2,0x05,0x9b, /* (0xcc-0xcf) */ |
| 87 | 0x78,0x84,0x07,0x88,0x8a,0x7e,0x05,0xa6, /* (0xd0-0xd3) */ |
| 88 | 0x06,0xa7,0x04,0xa8,0x0c,0xa9,0x03,0xaa, /* (0xd4-0xd7) */ |
| 89 | 0x0b,0xc1,0x83,0xc0,0x0a,0xad,0x01,0xae, /* (0xd8-0xdb) */ |
| 90 | 0x09,0xaf,0x78,0xb0,0x07,0xb1,0x1a,0x61, /* (0xdc-0xdf) */ |
| 91 | 0x3b,0x69,0x42,0x72,0x4b,0x7a,0x3c,0x6b, /* (0xe0-0xe3) */ |
| 92 | 0x43,0x73,0x44,0x74,0x3d,0x6c,0x3e,0x75, /* (0xe4-0xe7) */ |
| 93 | 0x46,0x7d,0x3a,0x70,0x49,0x71,0x4a,0x94, /* (0xe8-0xeb) */ |
| 94 | 0x4c,0x79,0x4c,0x7c,0x45,0x7c,0x45,0x79, /* (0xec-0xef) */ |
| 95 | 0x4d,0x7b,0x5a,0x95,0x4c,0x7b,0x45,0x7b, /* (0xf0-0xf3) */ |
| 96 | 0x4d,0x79,0x4d,0x7c,0x4e,0x7b,0x54,0x95, /* (0xf4-0xf7) */ |
| 97 | 0x52,0x7c,0x45,0x94,0x4a,0x79,0xb3,0x95, /* (0xf8-0xfb) */ |
| 98 | 0xb4,0x7b,0xb5,0x7c,0x00,0x00,0x55,0x79, /* (0xfc-0xff) */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | |
| 102 | #define KBD_DATA 0x60 |
| 103 | #define KBD_SC 0x64 |
| 104 | |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 105 | #define KBD_IBF (1 << 1) /* 1: input buffer full (data ready for ec) */ |
| 106 | #define KBD_OBF (1 << 0) /* 1: output buffer full (data ready for host) */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 107 | |
| 108 | static int send_kbd_command(u8 command) |
| 109 | { |
| 110 | int timeout; |
| 111 | |
| 112 | timeout = 0x7ff; |
| 113 | while ((inb(KBD_SC) & KBD_IBF) && --timeout) { |
| 114 | udelay(10); |
| 115 | if ((timeout & 0xff) == 0) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 116 | printk(BIOS_SPEW, "."); |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 117 | } |
| 118 | if (!timeout) { |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 119 | printk(BIOS_DEBUG, "Timeout while sending command 0x%02x to EC!\n", |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 120 | command); |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | outb(command, KBD_SC); |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | static int send_kbd_data(u8 data) |
| 128 | { |
| 129 | int timeout; |
| 130 | |
| 131 | timeout = 0x7ff; |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 132 | while ((inb(KBD_SC) & KBD_IBF) && --timeout) { /* wait for IBF = 0 */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 133 | udelay(10); |
| 134 | if ((timeout & 0xff) == 0) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 135 | printk(BIOS_SPEW, "."); |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 136 | } |
| 137 | if (!timeout) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 138 | printk(BIOS_DEBUG, "Timeout while sending data 0x%02x to EC!\n", |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 139 | data); |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | outb(data, KBD_DATA); |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | |
| 148 | static u8 recv_kbd_data(void) |
| 149 | { |
| 150 | int timeout; |
| 151 | u8 data; |
| 152 | |
| 153 | timeout = 0x7fff; |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 154 | while (--timeout) { /* Wait for OBF = 1 */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 155 | if (inb(KBD_SC) & KBD_OBF) { |
| 156 | break; |
| 157 | } |
| 158 | udelay(10); |
| 159 | if ((timeout & 0xff) == 0) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 160 | printk(BIOS_SPEW, "."); |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 161 | } |
| 162 | if (!timeout) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 163 | printk(BIOS_DEBUG, "\nTimeout while receiving data from EC!\n"); |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | data = inb(KBD_DATA); |
| 167 | |
| 168 | return data; |
| 169 | } |
| 170 | |
| 171 | |
| 172 | static u8 m3885_get_variable(u8 index) |
| 173 | { |
| 174 | u8 ret; |
| 175 | |
| 176 | send_kbd_command(0xb8); |
| 177 | send_kbd_data(index); |
| 178 | send_kbd_command(0xbc); |
| 179 | send_kbd_command(0xff); |
| 180 | ret = recv_kbd_data(); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 181 | printk(BIOS_SPEW, "m3885: get variable %02x = %02x\n", index, ret); |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 182 | return ret; |
| 183 | } |
| 184 | |
| 185 | static void m3885_set_variable(u8 index, u8 data) |
| 186 | { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 187 | printk(BIOS_SPEW, "m3885: set variable %02x = %02x\n", index, data); |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 188 | send_kbd_command(0xb8); |
| 189 | send_kbd_data(index); |
| 190 | send_kbd_command(0xbd); |
| 191 | send_kbd_data(data); |
| 192 | } |
| 193 | |
| 194 | static void m3885_set_proc_ram(u8 index, u8 data) |
| 195 | { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 196 | printk(BIOS_SPEW, "m3885: set procram %02x = %02x\n", index, data); |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 197 | send_kbd_command(0xb8); |
| 198 | send_kbd_data(index); |
| 199 | send_kbd_command(0xbb); |
| 200 | send_kbd_data(data); |
| 201 | } |
| 202 | |
| 203 | static u8 m3885_get_proc_ram(u8 index) |
| 204 | { |
| 205 | u8 ret; |
| 206 | |
| 207 | send_kbd_command(0xb8); |
| 208 | send_kbd_data(index); |
| 209 | send_kbd_command(0xba); |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 210 | ret = recv_kbd_data(); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 211 | printk(BIOS_SPEW, "m3885: get procram %02x = %02x\n", index, ret); |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 212 | return ret; |
| 213 | } |
| 214 | |
| 215 | static u8 m3885_read_port(void) |
| 216 | { |
| 217 | u8 reg8; |
| 218 | |
| 219 | reg8 = m3885_get_variable(0x0c); |
| 220 | reg8 &= ~(7 << 4); |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 221 | reg8 |= (4 << 4); /* bank 4 */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 222 | m3885_set_variable(0x0c, reg8); |
| 223 | |
| 224 | /* P6YSTATE */ |
| 225 | return m3885_get_proc_ram(0xf8); |
| 226 | } |
| 227 | |
| 228 | void m3885_configure_multikey(void) |
| 229 | { |
| 230 | int i; |
| 231 | u8 reg8; |
| 232 | u8 kstate5_flags, offs, maxvars; |
| 233 | |
Elyes HAOUAS | 8ab989e | 2016-07-30 17:46:17 +0200 | [diff] [blame] | 234 | /* RAM bank 0 */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 235 | kstate5_flags = m3885_get_variable(0x0c); |
| 236 | m3885_set_variable(0x0c, kstate5_flags & ~(7 << 4)); |
| 237 | |
| 238 | /* Write Matrix to bank 0 */ |
Elyes HAOUAS | a5aad2e | 2016-09-19 09:47:16 -0600 | [diff] [blame] | 239 | for (i = 0; i < ARRAY_SIZE(matrix); i++) { |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 240 | m3885_set_proc_ram(i + 0x80, matrix[i]); |
| 241 | } |
| 242 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 243 | |
Elyes HAOUAS | 8ab989e | 2016-07-30 17:46:17 +0200 | [diff] [blame] | 244 | /* RAM bank 2 */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 245 | m3885_set_variable(0x0c, (kstate5_flags & (~(7 << 4))) | (2 << 4)); |
| 246 | |
| 247 | /* Get the number of variables */ |
| 248 | maxvars = m3885_get_variable(0x00); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 249 | printk(BIOS_DEBUG, "M388x has %d variables in bank 2.\n", maxvars); |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 250 | if (maxvars >= 35) { |
| 251 | offs = m3885_get_variable(0x23); |
| 252 | if ((offs > 0xc0) || (offs < 0x80)) { |
Elyes HAOUAS | 8ab989e | 2016-07-30 17:46:17 +0200 | [diff] [blame] | 253 | printk(BIOS_DEBUG, "M388x does not have a valid RAM offset (0x%x)\n", offs); |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 254 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 255 | printk(BIOS_DEBUG, "Writing Fn-Table to M388x RAM offset 0x%x\n", offs); |
Elyes HAOUAS | a5aad2e | 2016-09-19 09:47:16 -0600 | [diff] [blame] | 256 | for (i = 0; i < ARRAY_SIZE(function_ram); i++) { |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 257 | m3885_set_proc_ram(i + offs, function_ram[i]); |
| 258 | } |
| 259 | } |
| 260 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 261 | printk(BIOS_DEBUG, "Could not load Function-RAM (%d).\n", maxvars); |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 262 | } |
| 263 | |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 264 | /* restore original bank */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 265 | m3885_set_variable(0x0c, kstate5_flags); |
| 266 | maxvars = m3885_get_variable(0x00); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 267 | printk(BIOS_DEBUG, "M388x has %d variables in original bank.\n", maxvars); |
Elyes HAOUAS | a5aad2e | 2016-09-19 09:47:16 -0600 | [diff] [blame] | 268 | for (i = 0; i < ARRAY_SIZE(variables); i+=3) { |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 269 | if(variables[i + 0] > maxvars) |
| 270 | continue; |
| 271 | reg8 = m3885_get_variable(variables[i + 0]); |
| 272 | reg8 &= ~(variables[i + 1]); |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 273 | reg8 |= variables[i + 2]; |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 274 | m3885_set_variable(variables[i + 0], reg8); |
| 275 | } |
| 276 | |
| 277 | /* OEM Init */ |
| 278 | |
| 279 | /* Set Bank 1 */ |
| 280 | m3885_set_variable(0x0c, (kstate5_flags & ~(7 << 4)) | (1 << 4)); |
| 281 | |
| 282 | /* Set SMI# at P5.1 */ |
| 283 | /* SMI Control -> p5.1 = EXTSMI# */ |
| 284 | m3885_set_proc_ram(0xff, 0xc1); |
| 285 | |
| 286 | /* Set Fn-Key Task 0 -> SMI#/SCI */ |
| 287 | m3885_set_proc_ram(0x6d, 0x81); |
| 288 | |
| 289 | /* Set Fn-Key Task 1 -> SCI */ |
| 290 | m3885_set_proc_ram(0x6c, 0x80); |
| 291 | |
| 292 | /* Number of Thermal Sensors */ |
| 293 | m3885_set_proc_ram(0xf2, 0x02); |
| 294 | |
| 295 | /* Critical Task */ |
| 296 | m3885_set_proc_ram(0xf3, 0x5d); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 297 | |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 298 | /* Thermal Polling Period */ |
| 299 | m3885_set_proc_ram(0xf9, 0x0a); |
| 300 | |
| 301 | /* ReadPort */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 302 | |
| 303 | /* AC PRESN# */ |
| 304 | if (m3885_read_port() & (1 << 0)) |
| 305 | reg8 = 0x8a; |
| 306 | else |
| 307 | reg8 = 0x9a; |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 308 | m3885_set_proc_ram(0xd0, reg8); /* P60SPEC */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 309 | |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 310 | /* SENSE1# */ |
| 311 | if (m3885_read_port() & (1 << 2)) |
| 312 | reg8 = 0x8a; |
| 313 | else |
| 314 | reg8 = 0x9a; |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 315 | m3885_set_proc_ram(0xd2, reg8); /* P62SPEC */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 316 | |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 317 | /* SENSE2# */ |
| 318 | if (m3885_read_port() & (1 << 3)) |
| 319 | reg8 = 0x8a; |
| 320 | else |
| 321 | reg8 = 0x9a; |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 322 | m3885_set_proc_ram(0xd3, reg8); /* P63SPEC */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 323 | |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 324 | /* Low Active Port */ |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 325 | m3885_set_proc_ram(0xd1, 0x88); /* P61SPEC */ |
| 326 | m3885_set_proc_ram(0xd6, 0x88); /* P66SPEC */ |
| 327 | m3885_set_proc_ram(0xd7, 0x88); /* P67SPEC */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 328 | |
| 329 | /* High Active Port */ |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 330 | m3885_set_proc_ram(0xd4, 0x98); /* P64SPEC */ |
| 331 | m3885_set_proc_ram(0xd5, 0x98); /* P65SPEC */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 332 | |
| 333 | /* Set P60TASK-P67TASK */ |
| 334 | /* SCI */ |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 335 | m3885_set_proc_ram(0xda, 0x80); /* P62TASK SENSE1# */ |
| 336 | m3885_set_proc_ram(0xdb, 0x80); /* P63TASK SENSE2# */ |
| 337 | m3885_set_proc_ram(0xdd, 0x80); /* P65TASK PROCHOT */ |
| 338 | m3885_set_proc_ram(0xde, 0x80); /* P65TASK THERMTRIP# */ |
| 339 | m3885_set_proc_ram(0xdf, 0x80); /* P65TASK PME# */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 340 | /* SMI/SCI */ |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 341 | m3885_set_proc_ram(0xd8, 0x81); /* P60TASK, AC_PRESN# */ |
| 342 | m3885_set_proc_ram(0xd9, 0x81); /* P61TASK, LID# */ |
| 343 | m3885_set_proc_ram(0xdc, 0x81); /* P64TASK, FDD/LPT# */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 344 | |
| 345 | /* Thermal */ |
| 346 | /* Bank 5 */ |
| 347 | m3885_set_variable(0x0c, (kstate5_flags & ~(7 << 4)) | (5 << 4)); |
| 348 | |
| 349 | /* Thermal 0: Active cooling, Speed Step Down */ |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 350 | m3885_set_proc_ram(0x81, 0x9c); /* THRM0 */ |
| 351 | m3885_set_proc_ram(0x82, 0x01); /* THRM0 CMD */ |
| 352 | m3885_set_proc_ram(0x84, TH0LOW); /* THRM0 LOW */ |
| 353 | m3885_set_proc_ram(0x85, TH0HIGH); /* THRM0 HIGH */ |
| 354 | m3885_set_proc_ram(0x86, 0x81); /* Set Task SMI#/SCI */ |
| 355 | m3885_set_proc_ram(0x87, TH0CRIT); /* THRM0 CRIT */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 356 | |
| 357 | /* Thermal 1: Passive cooling, Fan On */ |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 358 | m3885_set_proc_ram(0x89, 0x9c); /* THRM1 */ |
| 359 | m3885_set_proc_ram(0x8a, 0x01); /* THRM1 CMD */ |
| 360 | m3885_set_proc_ram(0x8c, TH1LOW); /* THRM1 LOW */ |
| 361 | m3885_set_proc_ram(0x8d, TH1HIGH); /* THRM1 HIGH */ |
| 362 | m3885_set_proc_ram(0x8e, 0x81); /* Set Task SMI#/SCI */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 363 | |
| 364 | /* Switch Task to SMI */ |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 365 | udelay(100 * 1000); /* 100ms */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 366 | outb(KBD_SC, 0xca); |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 367 | udelay(100 * 1000); /* 100ms */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 368 | outb(KBD_DATA, 0x17); |
| 369 | |
| 370 | /* Set P22 to high level, keyboard backlight default off */ |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 371 | udelay(100 * 1000); /* 100ms */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 372 | outb(KBD_SC, 0xc5); |
Elyes HAOUAS | ec16e93 | 2016-10-07 18:22:44 +0200 | [diff] [blame] | 373 | udelay(100 * 1000); /* 100ms */ |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 374 | outb(KBD_DATA, 0x4a); |
| 375 | } |
| 376 | |
| 377 | u8 m3885_gpio(u8 value) |
| 378 | { |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 379 | /* First write data */ |
| 380 | ec_write(M3885_CMDAT1, value); |
| 381 | |
| 382 | /* Issue command: ACCESS GPIO */ |
| 383 | ec_write(M3885_CMCMD, 0xc5); |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 384 | return 0; |
Stefan Reinauer | 838c5a5 | 2010-01-17 14:08:17 +0000 | [diff] [blame] | 385 | } |