The ARRAY_SIZE macro is convenient, yet mostly unused. Switch lots of
[coreboot.git] / src / mainboard / gigabyte / m57sli / fanctl.c
1 #include <arch/io.h>
2 #include <stdlib.h>
3
4 static void write_index(uint16_t port_base, uint8_t reg, uint8_t value)
5 {
6         outb(reg, port_base);
7         outb(value, port_base + 1);
8 }
9
10 static const struct {
11         uint8_t index, value;
12 } sequence[]= {
13         /* Make sure we can monitor, and enable SMI# interrupt output */
14         { 0x00, 0x13},
15         /* Disable fan interrupt status bits for SMI# */
16         { 0x04, 0x37},
17         /* Disable VIN interrupt status bits for SMI# */
18         { 0x05, 0xff},
19         /* Disable fan interrupt status bits for IRQ */
20         { 0x07, 0x37},
21         /* Disable VIN interrupt status bits for IRQ */
22         { 0x08, 0xff},
23         /* Disable external sensor interrupt */
24         { 0x09, 0x87},
25         /* Enable 16 bit counter divisors */
26         { 0x0c, 0x07},
27         /* Set FAN_CTL control register (0x14) polarity to high, and
28            activate fans 1, 2 and 3. */
29         { 0x14, 0xd7},
30         /* set the correct sensor types 1,2 thermistor; 3 diode */
31         { 0x51, 0x1c},
32         /* set the 'zero' voltage for diode type sensor 3 */
33         { 0x5c, 0x80},
34 //      { 0x56, 0xe5},
35 //      { 0x57, 0xe5},
36         { 0x59, 0xec},
37         { 0x5c, 0x00},
38         /* fan1 (controlled by temp3) control parameters */
39         /* fan off limit */
40         { 0x60, 0xff},
41         /* fan start limit */
42         { 0x61, 0x14},
43         /* ???? */
44 //      { 0x62, 0x00},
45         /* start PWM */
46         { 0x63, 0x27},
47         /* smooth and slope PWM */
48         { 0x64, 0x90},
49         /* direct-down and interval */
50         { 0x65, 0x03},
51         /* temperature limit of fan stop for fan3 (automatic) */
52         { 0x70, 0xff},
53         /* temperature limit of fan start for fan3 (automatic) */
54         { 0x71, 0x14},
55         /* Set PWM start & slope for fan3 */
56         { 0x73, 0x20},
57         /* Initialize PWM automatic mode slope values for fan3 */
58         { 0x74, 0x90},
59         /* set smartguardian temperature interval for fan3 */
60         { 0x75, 0x03},
61         /* fan1 auto controlled by temp3 */
62         { 0x15, 0x82},
63         /* fan2 auto controlled by temp3 */
64         { 0x16, 0x82},
65         /* fan3 auto controlled by temp3 */
66         { 0x17, 0x82},
67         /* all fans enable, fan1 ctl smart */
68         { 0x13, 0x77}
69 };
70
71 /*
72  * Called from superio.c
73  */
74 void init_ec(uint16_t base)
75 {
76         int i;
77         for (i=0; i<ARRAY_SIZE(sequence); i++) {
78                 write_index(base, sequence[i].index, sequence[i].value);
79         }
80 }