| 1 | /* |
|---|
| 2 | superio: Handle special I/O operations needed by most Super-I/O chips |
|---|
| 3 | |
|---|
| 4 | Copyright (C) 2005 Jean Delvare <khali@linux-fr.org> |
|---|
| 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. |
|---|
| 15 | |
|---|
| 16 | You should have received a copy of the GNU General Public License |
|---|
| 17 | along with this program; if not, write to the Free Software |
|---|
| 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|---|
| 19 | MA 02110-1301 USA. |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | #include <stdlib.h> |
|---|
| 23 | |
|---|
| 24 | #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ >= 0 |
|---|
| 25 | #include <sys/io.h> |
|---|
| 26 | #else |
|---|
| 27 | #include <asm/io.h> |
|---|
| 28 | #endif |
|---|
| 29 | |
|---|
| 30 | #include "superio.h" |
|---|
| 31 | |
|---|
| 32 | int superio_parse_key(unsigned char *key, const char *s) |
|---|
| 33 | { |
|---|
| 34 | char *end; |
|---|
| 35 | int tmp; |
|---|
| 36 | key[0] = 0; |
|---|
| 37 | |
|---|
| 38 | while (*s != '\0') { |
|---|
| 39 | tmp = strtol(s, &end, 0); |
|---|
| 40 | if ((*end != '\0' && *end != ',') |
|---|
| 41 | || (tmp < 0x00 || tmp > 0xff)) |
|---|
| 42 | return -1; |
|---|
| 43 | |
|---|
| 44 | /* Byte is valid, store it */ |
|---|
| 45 | key[++key[0]] = tmp; |
|---|
| 46 | |
|---|
| 47 | /* Last byte? */ |
|---|
| 48 | if (key[0] == SUPERIO_MAX_KEY |
|---|
| 49 | || *end == '\0') |
|---|
| 50 | return 0; |
|---|
| 51 | |
|---|
| 52 | /* Skip comma */ |
|---|
| 53 | s = end + 1; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | /* Unexpected end of string */ |
|---|
| 57 | return -1; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | void superio_write_key(int addrreg, unsigned char *key) |
|---|
| 61 | { |
|---|
| 62 | int i; |
|---|
| 63 | |
|---|
| 64 | for (i = 1; i <= key[0]; i++) |
|---|
| 65 | outb(key[i], addrreg); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | void superio_reset(int addrreg, int datareg) |
|---|
| 69 | { |
|---|
| 70 | /* Some chips (SMSC, Winbond) want this */ |
|---|
| 71 | outb(0xaa, addrreg); |
|---|
| 72 | |
|---|
| 73 | /* Return to "Wait For Key" state (PNP-ISA spec) */ |
|---|
| 74 | outb(0x02, addrreg); |
|---|
| 75 | outb(0x02, datareg); |
|---|
| 76 | } |
|---|