25a65c837174754c1b2bd83da7d65fbb0226e951
[coreboot.git] / src / drivers / i2c / adt7463 / adt7463.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2005 Tyan
5  * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan)
6  * Copyright (C) 2007 Ward Vandewege <ward@gnu.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
21  */
22
23 #include <device/device.h>
24 #include <console/console.h>
25 #include <device/smbus.h>
26 #include "chip.h"
27
28 /**
29  * Do some S2881-specific HWM initialization for the ADT7463 chip.
30  *
31  * Should be factored out so that it can be more general.
32  *
33  * See Analog Devices ADT7463 datasheet, Rev C (2004):
34  * http://www.analog.com/en/prod/0,,766_825_ADT7463,00.html
35  */
36 static void adt7463_init(device_t adt7463)
37 {
38         int result;
39
40         printk(BIOS_DEBUG, "ADT7463 is %s\n", dev_path(adt7463));
41
42         /* Set all fans to 'Fastest Speed Calculated by All 3 Temperature
43          * Channels Controls PWMx'.
44          */
45         result = smbus_write_byte(adt7463, 0x5c, 0xc2);
46         result = smbus_write_byte(adt7463, 0x5d, 0xc2);
47         result = smbus_write_byte(adt7463, 0x5e, 0xc2);
48
49         /* Make sure that our fans never stop when temp. falls below Tmin,
50          * but rather keep going at minimum duty cycle (applies to automatic
51          * fan control mode only).
52          */
53         result = smbus_write_byte(adt7463, 0x62, 0xc0);
54
55         /* Set minimum PWM duty cycle to 25%, rather than the default 50%. */
56         result = smbus_write_byte(adt7463, 0x64, 0x40);
57         result = smbus_write_byte(adt7463, 0x65, 0x40);
58         result = smbus_write_byte(adt7463, 0x66, 0x40);
59
60         /* Set Tmin to 55C, rather than the default 90C. Above this temperature
61          * the fans will start blowing harder as temperature increases
62          * (automatic mode only).
63          */
64         result = smbus_write_byte(adt7463, 0x67, 0x37);
65         result = smbus_write_byte(adt7463, 0x68, 0x37);
66         result = smbus_write_byte(adt7463, 0x69, 0x37);
67
68         /* Set THERM limit to 70C, rather than the default 100C.
69          * The fans will kick in at 100% if the sensors reach this temperature,
70          * (only in automatic mode, but supposedly even when hardware is
71          * locked up). This is a failsafe measure.
72          */
73         result = smbus_write_byte(adt7463, 0x6a, 0x46);
74         result = smbus_write_byte(adt7463, 0x6b, 0x46);
75         result = smbus_write_byte(adt7463, 0x6c, 0x46);
76
77         /* Remote temperature 1 offset (LSB == 0.25C). */
78         result = smbus_write_byte(adt7463, 0x70, 0x02);
79
80         /* Remote temperature 2 offset (LSB == 0.25C). */
81         result = smbus_write_byte(adt7463, 0x72, 0x01);
82
83         /* Set TACH measurements to normal (1/second). */
84         result = smbus_write_byte(adt7463, 0x78, 0xf0);
85
86         printk(BIOS_DEBUG, "ADT7463 properly initialized\n");
87 }
88
89 static void adt7463_noop(device_t dummy)
90 {
91 }
92
93 static struct device_operations adt7463_operations = {
94         .read_resources         = adt7463_noop,
95         .set_resources          = adt7463_noop,
96         .enable_resources       = adt7463_noop,
97         .init                   = adt7463_init,
98 };
99
100 static void enable_dev(struct device *dev)
101 {
102         dev->ops = &adt7463_operations;
103 }
104
105 struct chip_operations drivers_i2c_adt7463_ops = {
106         CHIP_NAME("adt7463")
107         .enable_dev = enable_dev,
108 };