printk_foo -> printk(BIOS_FOO, ...)
[coreboot.git] / src / mainboard / tyan / s2881 / mainboard.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  * See Analog Devices ADT7463 datasheet, Rev C (2004):
32  * http://www.analog.com/en/prod/0,,766_825_ADT7463,00.html
33  */
34 static void adt7463_init(device_t dev)
35 {
36         device_t smbus_dev, adt7463;
37         struct device_path path;
38         int result;
39
40         /* Find the SMBus controller (AMD-8111). */
41         smbus_dev = dev_find_device(0x1022, 0x746b, 0);
42         if (!smbus_dev)
43                 die("SMBus controller not found\n");
44         printk(BIOS_DEBUG, "SMBus controller found\n");
45
46         /* Find the ADT7463 device. */
47         path.type = DEVICE_PATH_I2C;
48         path.i2c.device = 0x2d;
49         adt7463 = find_dev_path(smbus_dev->link, &path);
50         if (!adt7463)
51                 die("ADT7463 not found\n");
52         printk(BIOS_DEBUG, "ADT7463 found\n");
53
54         /* Set all fans to 'Fastest Speed Calculated by All 3 Temperature
55          * Channels Controls PWMx'.
56          */
57         result = smbus_write_byte(adt7463, 0x5c, 0xc2);
58         result = smbus_write_byte(adt7463, 0x5d, 0xc2);
59         result = smbus_write_byte(adt7463, 0x5e, 0xc2);
60
61         /* Make sure that our fans never stop when temp. falls below Tmin,
62          * but rather keep going at minimum duty cycle (applies to automatic 
63          * fan control mode only).
64          */
65         result = smbus_write_byte(adt7463, 0x62, 0xc0);
66
67         /* Set minimum PWM duty cycle to 25%, rather than the default 50%. */
68         result = smbus_write_byte(adt7463, 0x64, 0x40);
69         result = smbus_write_byte(adt7463, 0x65, 0x40);
70         result = smbus_write_byte(adt7463, 0x66, 0x40);
71
72         /* Set Tmin to 55C, rather than the default 90C. Above this temperature
73          * the fans will start blowing harder as temperature increases
74          * (automatic mode only).
75          */
76         result = smbus_write_byte(adt7463, 0x67, 0x37);
77         result = smbus_write_byte(adt7463, 0x68, 0x37);
78         result = smbus_write_byte(adt7463, 0x69, 0x37);
79
80         /* Set THERM limit to 70C, rather than the default 100C.
81          * The fans will kick in at 100% if the sensors reach this temperature,
82          * (only in automatic mode, but supposedly even when hardware is
83          * locked up). This is a failsafe measure.
84          */
85         result = smbus_write_byte(adt7463, 0x6a, 0x46);
86         result = smbus_write_byte(adt7463, 0x6b, 0x46);
87         result = smbus_write_byte(adt7463, 0x6c, 0x46);
88
89         /* Remote temperature 1 offset (LSB == 0.25C). */
90         result = smbus_write_byte(adt7463, 0x70, 0x02);
91
92         /* Remote temperature 2 offset (LSB == 0.25C). */
93         result = smbus_write_byte(adt7463, 0x72, 0x01);
94
95         /* Set TACH measurements to normal (1/second). */
96         result = smbus_write_byte(adt7463, 0x78, 0xf0);
97
98         printk(BIOS_DEBUG, "ADT7463 properly initialized\n");
99 }
100
101 static void dummy_noop(device_t dummy)
102 {
103 }
104
105 static struct device_operations dummy_operations = {
106         .read_resources         = dummy_noop,
107         .set_resources          = dummy_noop,
108         .enable_resources       = dummy_noop,
109         .init                   = adt7463_init,
110 };
111
112 static unsigned int scan_root_bus(device_t root, unsigned int max)
113 {
114         struct device_path path;
115         device_t dummy;
116         unsigned link_i;
117
118         max = root_dev_scan_bus(root, max);
119
120         printk(BIOS_DEBUG, "scan_root_bus ok\n");
121
122         /* The following is a little silly. We need a hook into the boot
123          * process *after* the ADT7463 device has been initialized. So we
124          * create this dummy device, and we put the ADT7463 S2881 specific
125          * settings in its init function, which gets called
126          * as the last device to be initialized.
127          */
128
129         link_i = root->links;
130         if (link_i >= MAX_LINKS) {
131                 printk(BIOS_DEBUG, "Reached MAX_LINKS, not configuring ADT7463");
132                 return max;
133         }
134         root->link[link_i].link = link_i;
135         root->link[link_i].dev = root;
136         root->link[link_i].children = 0;
137         root->links++;
138
139         path.type = DEVICE_PATH_PNP;
140         path.pnp.port = 0;
141         path.pnp.device = 0;
142         dummy = alloc_dev(&root->link[link_i], &path);
143         dummy->ops = &dummy_operations;
144
145         return max;
146 }
147
148 static struct device_operations mainboard_operations = {
149         .read_resources         = root_dev_read_resources,
150         .set_resources          = root_dev_set_resources,
151         .enable_resources       = root_dev_enable_resources,
152         .init                   = root_dev_init,
153         .scan_bus               = scan_root_bus,
154 };
155
156 static void enable_dev(struct device *dev)
157 {
158         dev->ops = &mainboard_operations;
159 }
160
161 struct chip_operations mainboard_ops = {
162         CHIP_NAME("Tyan S2881 Mainboard")
163         .enable_dev = enable_dev,
164 };