Rudolf Marek | 113c349 | 2011-10-27 20:42:11 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the superiotool project. |
| 3 | * |
| 4 | * Copyright (C) 2011 Rudolf Marek <r.marek@assembler.cz> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 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. |
Rudolf Marek | 113c349 | 2011-10-27 20:42:11 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include "superiotool.h" |
| 18 | |
| 19 | #define DEVICE_ID_REG 0x20 |
| 20 | #define DEVICE_REV_REG 0x21 |
| 21 | |
| 22 | static const struct superio_registers reg_table[] = { |
| 23 | {0xb7, "SB7xx", { |
| 24 | {NOLDN, NULL, |
| 25 | {0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x28,0x29,0x2a, |
| 26 | 0x2b,0x2c,0x2e, 0x2f, EOT}, |
| 27 | {NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,EOT}}, |
| 28 | {0x3, "EC channel 0", |
| 29 | {0x30,0x60,0x61, EOT}, |
| 30 | {NANA,NANA,NANA,EOT}}, |
| 31 | {0x5, "Irda", |
| 32 | {0x30,0x60,0x61,0x70, EOT}, |
| 33 | {NANA,NANA,NANA,NANA,EOT}}, |
| 34 | {0x7, "Keyboard Controller", |
| 35 | {0x30, EOT}, |
| 36 | {NANA,EOT}}, |
| 37 | {0x9, "Mailbox", |
| 38 | {0x30,0x60,0x61, EOT}, |
| 39 | {NANA,NANA,NANA,EOT}}, |
| 40 | {EOT}}}, |
| 41 | {0xb8, "SB8xx", { |
| 42 | {NOLDN, NULL, |
| 43 | {0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x28,0x29,0x2a, |
| 44 | 0x2b,0x2c,0x2e, 0x2f, EOT}, |
| 45 | {NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,NANA,EOT}}, |
| 46 | {0x3, "EC channel 0", |
| 47 | {0x30,0x60,0x61, EOT}, |
| 48 | {NANA,NANA,NANA,EOT}}, |
| 49 | {0x5, "Irda", |
| 50 | {0x30,0x60,0x61,0x70, EOT}, |
| 51 | {NANA,NANA,NANA,NANA,EOT}}, |
| 52 | {0x7, "Keyboard Controller", |
| 53 | {0x30, EOT}, |
| 54 | {NANA,EOT}}, |
| 55 | {0x9, "Mailbox", |
| 56 | {0x30,0x60,0x61, EOT}, |
| 57 | {NANA,NANA,NANA,EOT}}, |
| 58 | {EOT}}}, |
| 59 | {EOT} |
| 60 | }; |
| 61 | |
| 62 | /* same as serverengines */ |
| 63 | static void enter_conf_mode_ec(uint16_t port) |
| 64 | { |
| 65 | OUTB(0x5a, port); |
| 66 | } |
| 67 | |
| 68 | static void exit_conf_mode_ec(uint16_t port) |
| 69 | { |
| 70 | OUTB(0xa5, port); |
| 71 | } |
| 72 | |
| 73 | uint16_t detect_ec(void) |
| 74 | { |
| 75 | uint16_t ec_port; |
| 76 | struct pci_dev *dev; |
| 77 | |
| 78 | dev = pci_dev_find(0x1002, 0x439d); |
| 79 | |
| 80 | if (!dev) { |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | /* is EC disabled ? */ |
| 85 | if (!(pci_read_byte(dev, 0x40) & (1 << 7))) |
| 86 | return 0; |
| 87 | |
| 88 | ec_port = pci_read_word(dev, 0xa4); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 89 | |
Rudolf Marek | 113c349 | 2011-10-27 20:42:11 +0200 | [diff] [blame] | 90 | if (!(ec_port & 0x1)) |
| 91 | return 0; |
| 92 | |
| 93 | ec_port &= ~0x1; |
| 94 | |
| 95 | return ec_port; |
| 96 | } |
| 97 | |
| 98 | void probe_idregs_amd(uint16_t port) |
| 99 | { |
| 100 | uint8_t rev, devid; |
| 101 | |
| 102 | probing_for("AMD EC", "", port); |
| 103 | |
| 104 | if (!(port = detect_ec())) |
| 105 | return; |
| 106 | |
| 107 | enter_conf_mode_ec(port); |
| 108 | |
| 109 | devid = regval(port, DEVICE_ID_REG); |
| 110 | rev = regval(port, DEVICE_REV_REG); |
| 111 | |
| 112 | if (superio_unknown(reg_table, devid)) { |
| 113 | if (verbose) |
| 114 | printf(NOTFOUND "id=0x%02x, rev=0x%02x\n", devid, rev); |
| 115 | exit_conf_mode_ec(port); |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | printf("Found AMD EC %s (id=0x%02x, rev=0x%02x) at 0x%x\n", |
| 120 | get_superio_name(reg_table, devid), devid, rev, port); |
| 121 | chip_found = 1; |
| 122 | |
| 123 | dump_superio("AMD EC", reg_table, port, devid, LDN_SEL); |
| 124 | |
| 125 | exit_conf_mode_ec(port); |
| 126 | } |
| 127 | |
| 128 | void print_amd_chips(void) |
| 129 | { |
| 130 | print_vendor_chips("AMD EC", reg_table); |
| 131 | } |