~mmach/netext73/lm-sensors

« back to all changes in this revision

Viewing changes to prog/dump/superio.c

  • Committer: mmach
  • Date: 2020-02-05 20:28:34 UTC
  • Revision ID: netbit73@gmail.com-20200205202834-zc3sla47j9e700w5
3.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    superio: Handle special I/O operations needed by most Super-I/O chips
 
3
   
 
4
    Copyright (C) 2005-2008  Jean Delvare <jdelvare@suse.de>
 
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 <sys/io.h>
 
23
#include <stdlib.h>
 
24
#include "superio.h"
 
25
 
 
26
int superio_parse_key(unsigned char *key, const char *s)
 
27
{
 
28
        char *end;
 
29
        int tmp;
 
30
        key[0] = 0;
 
31
        
 
32
        while (*s != '\0') {
 
33
                tmp = strtol(s, &end, 0);
 
34
                if ((*end != '\0' && *end != ',')
 
35
                 || (tmp < 0x00 || tmp > 0xff))
 
36
                        return -1;
 
37
 
 
38
                /* Byte is valid, store it */
 
39
                key[++key[0]] = tmp;
 
40
 
 
41
                /* Last byte? */
 
42
                if (key[0] == SUPERIO_MAX_KEY
 
43
                 || *end == '\0')
 
44
                        return 0;
 
45
 
 
46
                /* Skip comma */
 
47
                s = end + 1;
 
48
        }
 
49
        
 
50
        /* Unexpected end of string */
 
51
        return -1;
 
52
}
 
53
 
 
54
void superio_write_key(int addrreg, unsigned char *key)
 
55
{
 
56
        int i;
 
57
 
 
58
        for (i = 1; i <= key[0]; i++)
 
59
                outb(key[i], addrreg);
 
60
}
 
61
 
 
62
void superio_reset(int addrreg, int datareg)
 
63
{
 
64
        /* Some chips (SMSC, Winbond) want this */
 
65
        outb(0xaa, addrreg);
 
66
 
 
67
        /* Return to "Wait For Key" state (PNP-ISA spec) */
 
68
        outb(0x02, addrreg);
 
69
        outb(0x02, datareg);
 
70
}