| 1 |
|
| 2 |
|
| 3 |
#include <types.h> |
| 4 |
#include <console/console.h> |
| 5 |
#include <arch/io.h> |
| 6 |
#include <delay.h> |
| 7 |
|
| 8 |
#include <ec/acpi/ec.h> |
| 9 |
#include "m3885.h" |
| 10 |
|
| 11 |
#define TH0LOW 80 |
| 12 |
#define TH0HIGH 85 |
| 13 |
#define TH0CRIT 120 |
| 14 |
#define TH1LOW 75 |
| 15 |
#define TH1HIGH 80 |
| 16 |
|
| 17 |
static u8 variables[] = { |
| 18 |
|
| 19 |
0x08, 0x48, 0x6C, |
| 20 |
0x0a, 0x01, 0x00, |
| 21 |
0x0c, 0x80, 0x08, |
| 22 |
0x11, 0xff, 0x06, |
| 23 |
0x13, 0xff, 0x00, |
| 24 |
0x14, 0xff, 0x00, |
| 25 |
0x15, 0xff, 0x3f, |
| 26 |
0x16, 0xff, 0x00, |
| 27 |
0x17, 0xff, 0x00, |
| 28 |
0x18, 0xff, 0x0e, |
| 29 |
0x19, 0xff, 0x9f, |
| 30 |
0x1a, 0xff, 0x9f, |
| 31 |
0x1b, 0xff, 0x6a, |
| 32 |
0x1c, 0xff, 0x9f, |
| 33 |
0x1d, 0xff, 0x9f, |
| 34 |
0x1e, 0xff, 0x87, |
| 35 |
0x1f, 0xff, 0x9f, |
| 36 |
0x20, 0xff, 0x9f, |
| 37 |
|
| 38 |
0x21, 0xff, 0x08, |
| 39 |
0x24, 0xff, 0x30, |
| 40 |
|
| 41 |
0x2b, 0xff, 0x00, |
| 42 |
0x2c, 0xff, 0x80, |
| 43 |
0x2d, 0xff, 0x02, |
| 44 |
0x2e, 0xff, 0x00, |
| 45 |
0x2f, 0xff, 0x00, |
| 46 |
}; |
| 47 |
|
| 48 |
static u8 matrix[] = { |
| 49 |
0xc1,0xc0,0xd8,0xdb,0xbf,0x05,0x76,0xbf, |
| 50 |
0xbf,0x80,0x78,0xbf,0xbf,0x07,0x88,0xc2, |
| 51 |
0x03,0x09,0xd9,0x16,0xbf,0x06,0x0e,0x81, |
| 52 |
0xbf,0xbf,0xee,0xbf,0xbf,0x55,0x9a,0x89, |
| 53 |
0x1e,0x15,0x36,0xda,0xe8,0xbf,0x0d,0xbf, |
| 54 |
0xbf,0xbf,0xbf,0xa3,0xbf,0x4e,0x66,0x8b, |
| 55 |
0x1d,0x2e,0xe6,0xe7,0xe5,0x1c,0x58,0xbf, |
| 56 |
0x82,0xbf,0xf0,0xbf,0xbf,0x5b,0x5d,0x8c, |
| 57 |
0x22,0x25,0x2c,0x35,0xe1,0x1a,0x96,0xbf, |
| 58 |
0xbf,0xbf,0xec,0xbf,0xbf,0x54,0xf1,0x8f, |
| 59 |
0x1b,0x2a,0x2b,0x32,0xe9,0x31,0x29,0x61, |
| 60 |
0xbf,0xbf,0x8d,0xbf,0x86,0xc3,0x92,0x93, |
| 61 |
0x21,0x23,0x34,0x33,0x41,0xe0,0xbf,0xbf, |
| 62 |
0xbf,0x85,0xeb,0xbf,0xb6,0xbf,0x91,0xbf, |
| 63 |
0x26,0x24,0x2d,0xe3,0xe2,0xe4,0xbf,0xbf, |
| 64 |
0x87,0xbf,0xea,0xbf,0xbf,0x52,0x90,0x8e, |
| 65 |
}; |
| 66 |
|
| 67 |
static u8 function_ram[] = { |
| 68 |
0x04,0xbd,0x0c,0xbe,0x7e,0x9a,0x8a,0xb6, |
| 69 |
0x92,0x8f,0x93,0x8e,0x81,0x86,0x82,0x87, |
| 70 |
0x8a,0x9a,0x8d,0x7e,0x88,0x84,0x7e,0x78, |
| 71 |
0x77,0x07,0x77,0x98,0x89,0xb2,0x05,0x9b, |
| 72 |
0x78,0x84,0x07,0x88,0x8a,0x7e,0x05,0xa6, |
| 73 |
0x06,0xa7,0x04,0xa8,0x0c,0xa9,0x03,0xaa, |
| 74 |
0x0b,0xc1,0x83,0xc0,0x0a,0xad,0x01,0xae, |
| 75 |
0x09,0xaf,0x78,0xb0,0x07,0xb1,0x1a,0x61, |
| 76 |
0x3b,0x69,0x42,0x72,0x4b,0x7a,0x3c,0x6b, |
| 77 |
0x43,0x73,0x44,0x74,0x3d,0x6c,0x3e,0x75, |
| 78 |
0x46,0x7d,0x3a,0x70,0x49,0x71,0x4a,0x94, |
| 79 |
0x4c,0x79,0x4c,0x7c,0x45,0x7c,0x45,0x79, |
| 80 |
0x4d,0x7b,0x5a,0x95,0x4c,0x7b,0x45,0x7b, |
| 81 |
0x4d,0x79,0x4d,0x7c,0x4e,0x7b,0x54,0x95, |
| 82 |
0x52,0x7c,0x45,0x94,0x4a,0x79,0xb3,0x95, |
| 83 |
0xb4,0x7b,0xb5,0x7c,0x00,0x00,0x55,0x79, |
| 84 |
}; |
| 85 |
|
| 86 |
#define KBD_DATA 0x60 |
| 87 |
#define KBD_SC 0x64 |
| 88 |
|
| 89 |
#define KBD_IBF (1 << 1) |
| 90 |
#define KBD_OBF (1 << 0) |
| 91 |
|
| 92 |
static int send_kbd_command(u8 command) |
| 93 |
{ |
| 94 |
int timeout; |
| 95 |
|
| 96 |
timeout = 0x7ff; |
| 97 |
while ((inb(KBD_SC) & KBD_IBF) && --timeout) { |
| 98 |
udelay(10); |
| 99 |
if ((timeout & 0xff) == 0) |
| 100 |
printk(BIOS_SPEW, "."); |
| 101 |
} |
| 102 |
if (!timeout) { |
| 103 |
printk(BIOS_DEBUG, "Timeout while sending command 0x%02x to EC!\n", |
| 104 |
command); |
| 105 |
} |
| 106 |
|
| 107 |
outb(command, KBD_SC); |
| 108 |
return 0; |
| 109 |
} |
| 110 |
|
| 111 |
static int send_kbd_data(u8 data) |
| 112 |
{ |
| 113 |
int timeout; |
| 114 |
|
| 115 |
timeout = 0x7ff; |
| 116 |
while ((inb(KBD_SC) & KBD_IBF) && --timeout) { |
| 117 |
udelay(10); |
| 118 |
if ((timeout & 0xff) == 0) |
| 119 |
printk(BIOS_SPEW, "."); |
| 120 |
} |
| 121 |
if (!timeout) { |
| 122 |
printk(BIOS_DEBUG, "Timeout while sending data 0x%02x to EC!\n", |
| 123 |
data); |
| 124 |
} |
| 125 |
|
| 126 |
outb(data, KBD_DATA); |
| 127 |
|
| 128 |
return 0; |
| 129 |
} |
| 130 |
|
| 131 |
static u8 recv_kbd_data(void) |
| 132 |
{ |
| 133 |
int timeout; |
| 134 |
u8 data; |
| 135 |
|
| 136 |
timeout = 0x7fff; |
| 137 |
while (--timeout) { |
| 138 |
if (inb(KBD_SC) & KBD_OBF) { |
| 139 |
break; |
| 140 |
} |
| 141 |
udelay(10); |
| 142 |
if ((timeout & 0xff) == 0) |
| 143 |
printk(BIOS_SPEW, "."); |
| 144 |
} |
| 145 |
if (!timeout) { |
| 146 |
printk(BIOS_DEBUG, "\nTimeout while receiving data from EC!\n"); |
| 147 |
} |
| 148 |
|
| 149 |
data = inb(KBD_DATA); |
| 150 |
|
| 151 |
return data; |
| 152 |
} |
| 153 |
|
| 154 |
static u8 m3885_get_variable(u8 index) |
| 155 |
{ |
| 156 |
u8 ret; |
| 157 |
|
| 158 |
send_kbd_command(0xb8); |
| 159 |
send_kbd_data(index); |
| 160 |
send_kbd_command(0xbc); |
| 161 |
send_kbd_command(0xff); |
| 162 |
ret = recv_kbd_data(); |
| 163 |
printk(BIOS_SPEW, "m3885: get variable %02x = %02x\n", index, ret); |
| 164 |
return ret; |
| 165 |
} |
| 166 |
|
| 167 |
static void m3885_set_variable(u8 index, u8 data) |
| 168 |
{ |
| 169 |
printk(BIOS_SPEW, "m3885: set variable %02x = %02x\n", index, data); |
| 170 |
send_kbd_command(0xb8); |
| 171 |
send_kbd_data(index); |
| 172 |
send_kbd_command(0xbd); |
| 173 |
send_kbd_data(data); |
| 174 |
} |
| 175 |
|
| 176 |
static void m3885_set_proc_ram(u8 index, u8 data) |
| 177 |
{ |
| 178 |
printk(BIOS_SPEW, "m3885: set procram %02x = %02x\n", index, data); |
| 179 |
send_kbd_command(0xb8); |
| 180 |
send_kbd_data(index); |
| 181 |
send_kbd_command(0xbb); |
| 182 |
send_kbd_data(data); |
| 183 |
} |
| 184 |
|
| 185 |
static u8 m3885_get_proc_ram(u8 index) |
| 186 |
{ |
| 187 |
u8 ret; |
| 188 |
|
| 189 |
send_kbd_command(0xb8); |
| 190 |
send_kbd_data(index); |
| 191 |
send_kbd_command(0xba); |
| 192 |
ret = recv_kbd_data(); |
| 193 |
printk(BIOS_SPEW, "m3885: get procram %02x = %02x\n", index, ret); |
| 194 |
return ret; |
| 195 |
} |
| 196 |
|
| 197 |
static u8 m3885_read_port(void) |
| 198 |
{ |
| 199 |
u8 reg8; |
| 200 |
|
| 201 |
reg8 = m3885_get_variable(0x0c); |
| 202 |
reg8 &= ~(7 << 4); |
| 203 |
reg8 |= (4 << 4); |
| 204 |
m3885_set_variable(0x0c, reg8); |
| 205 |
|
| 206 |
|
| 207 |
return m3885_get_proc_ram(0xf8); |
| 208 |
} |
| 209 |
|
| 210 |
void m3885_configure_multikey(void) |
| 211 |
{ |
| 212 |
int i; |
| 213 |
u8 reg8; |
| 214 |
u8 kstate5_flags, offs, maxvars; |
| 215 |
|
| 216 |
|
| 217 |
kstate5_flags = m3885_get_variable(0x0c); |
| 218 |
m3885_set_variable(0x0c, kstate5_flags & ~(7 << 4)); |
| 219 |
|
| 220 |
|
| 221 |
for (i = 0; i < ARRAY_SIZE(matrix); i++) { |
| 222 |
m3885_set_proc_ram(i + 0x80, matrix[i]); |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
m3885_set_variable(0x0c, (kstate5_flags & (~(7 << 4))) | (2 << 4)); |
| 228 |
|
| 229 |
|
| 230 |
maxvars = m3885_get_variable(0x00); |
| 231 |
printk(BIOS_DEBUG, "M388x has %d variables in bank 2.\n", maxvars); |
| 232 |
if (maxvars >= 35) { |
| 233 |
offs = m3885_get_variable(0x23); |
| 234 |
if ((offs > 0xc0) || (offs < 0x80)) { |
| 235 |
printk(BIOS_DEBUG, "M388x does not have a valid RAM offset (0x%x)\n", offs); |
| 236 |
} else { |
| 237 |
printk(BIOS_DEBUG, "Writing Fn-Table to M388x RAM offset 0x%x\n", offs); |
| 238 |
for (i = 0; i < ARRAY_SIZE(function_ram); i++) { |
| 239 |
m3885_set_proc_ram(i + offs, function_ram[i]); |
| 240 |
} |
| 241 |
} |
| 242 |
} else { |
| 243 |
printk(BIOS_DEBUG, "Could not load Function-RAM (%d).\n", maxvars); |
| 244 |
} |
| 245 |
|
| 246 |
|
| 247 |
m3885_set_variable(0x0c, kstate5_flags); |
| 248 |
maxvars = m3885_get_variable(0x00); |
| 249 |
printk(BIOS_DEBUG, "M388x has %d variables in original bank.\n", maxvars); |
| 250 |
for (i = 0; i < ARRAY_SIZE(variables); i+=3) { |
| 251 |
if (variables[i + 0] > maxvars) |
| 252 |
continue; |
| 253 |
reg8 = m3885_get_variable(variables[i + 0]); |
| 254 |
reg8 &= ~(variables[i + 1]); |
| 255 |
reg8 |= variables[i + 2]; |
| 256 |
m3885_set_variable(variables[i + 0], reg8); |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
m3885_set_variable(0x0c, (kstate5_flags & ~(7 << 4)) | (1 << 4)); |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
m3885_set_proc_ram(0xff, 0xc1); |
| 267 |
|
| 268 |
|
| 269 |
m3885_set_proc_ram(0x6d, 0x81); |
| 270 |
|
| 271 |
|
| 272 |
m3885_set_proc_ram(0x6c, 0x80); |
| 273 |
|
| 274 |
|
| 275 |
m3885_set_proc_ram(0xf2, 0x02); |
| 276 |
|
| 277 |
|
| 278 |
m3885_set_proc_ram(0xf3, 0x5d); |
| 279 |
|
| 280 |
|
| 281 |
m3885_set_proc_ram(0xf9, 0x0a); |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
if (m3885_read_port() & (1 << 0)) |
| 287 |
reg8 = 0x8a; |
| 288 |
else |
| 289 |
reg8 = 0x9a; |
| 290 |
m3885_set_proc_ram(0xd0, reg8); |
| 291 |
|
| 292 |
|
| 293 |
if (m3885_read_port() & (1 << 2)) |
| 294 |
reg8 = 0x8a; |
| 295 |
else |
| 296 |
reg8 = 0x9a; |
| 297 |
m3885_set_proc_ram(0xd2, reg8); |
| 298 |
|
| 299 |
|
| 300 |
if (m3885_read_port() & (1 << 3)) |
| 301 |
reg8 = 0x8a; |
| 302 |
else |
| 303 |
reg8 = 0x9a; |
| 304 |
m3885_set_proc_ram(0xd3, reg8); |
| 305 |
|
| 306 |
|
| 307 |
m3885_set_proc_ram(0xd1, 0x88); |
| 308 |
m3885_set_proc_ram(0xd6, 0x88); |
| 309 |
m3885_set_proc_ram(0xd7, 0x88); |
| 310 |
|
| 311 |
|
| 312 |
m3885_set_proc_ram(0xd4, 0x98); |
| 313 |
m3885_set_proc_ram(0xd5, 0x98); |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
m3885_set_proc_ram(0xda, 0x80); |
| 318 |
m3885_set_proc_ram(0xdb, 0x80); |
| 319 |
m3885_set_proc_ram(0xdd, 0x80); |
| 320 |
m3885_set_proc_ram(0xde, 0x80); |
| 321 |
m3885_set_proc_ram(0xdf, 0x80); |
| 322 |
|
| 323 |
m3885_set_proc_ram(0xd8, 0x81); |
| 324 |
m3885_set_proc_ram(0xd9, 0x81); |
| 325 |
m3885_set_proc_ram(0xdc, 0x81); |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
m3885_set_variable(0x0c, (kstate5_flags & ~(7 << 4)) | (5 << 4)); |
| 330 |
|
| 331 |
|
| 332 |
m3885_set_proc_ram(0x81, 0x9c); |
| 333 |
m3885_set_proc_ram(0x82, 0x01); |
| 334 |
m3885_set_proc_ram(0x84, TH0LOW); |
| 335 |
m3885_set_proc_ram(0x85, TH0HIGH); |
| 336 |
m3885_set_proc_ram(0x86, 0x81); |
| 337 |
m3885_set_proc_ram(0x87, TH0CRIT); |
| 338 |
|
| 339 |
|
| 340 |
m3885_set_proc_ram(0x89, 0x9c); |
| 341 |
m3885_set_proc_ram(0x8a, 0x01); |
| 342 |
m3885_set_proc_ram(0x8c, TH1LOW); |
| 343 |
m3885_set_proc_ram(0x8d, TH1HIGH); |
| 344 |
m3885_set_proc_ram(0x8e, 0x81); |
| 345 |
|
| 346 |
|
| 347 |
udelay(100 * 1000); |
| 348 |
outb(KBD_SC, 0xca); |
| 349 |
udelay(100 * 1000); |
| 350 |
outb(KBD_DATA, 0x17); |
| 351 |
|
| 352 |
|
| 353 |
udelay(100 * 1000); |
| 354 |
outb(KBD_SC, 0xc5); |
| 355 |
udelay(100 * 1000); |
| 356 |
outb(KBD_DATA, 0x4a); |
| 357 |
} |
| 358 |
|
| 359 |
u8 m3885_gpio(u8 value) |
| 360 |
{ |
| 361 |
|
| 362 |
ec_write(M3885_CMDAT1, value); |
| 363 |
|
| 364 |
|
| 365 |
ec_write(M3885_CMCMD, 0xc5); |
| 366 |
return 0; |
| 367 |
} |