in vt8237r_enable(), write function enables only to ISA bridge config space
[coreboot.git] / src / southbridge / via / vt8237r / vt8237r.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
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; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 #include <console/console.h>
21 #include <device/device.h>
22 #include <device/pci.h>
23 #include <device/pci_ids.h>
24 #include "vt8237r.h"
25 #include "chip.h"
26
27 /*
28  * Datasheet: http://www.via.com.tw/en/downloads/datasheets/chipsets/
29  *              VT8237R_SouthBridge_Revision2.06_Lead-Free.zip
30  */
31
32 #if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 7
33 void writeback(struct device *dev, u16 where, u8 what)
34 {
35         u8 regval;
36
37         pci_write_config8(dev, where, what);
38         regval = pci_read_config8(dev, where);
39
40         if (regval != what) {
41                 print_debug("Writeback to ");
42                 print_debug_hex8(where);
43                 print_debug(" failed ");
44                 print_debug_hex8(regval);
45                 print_debug("\n");
46         }
47 }
48 #else
49 void writeback(struct device *dev, u16 where, u8 what)
50 {
51         pci_write_config8(dev, where, what);
52 }
53 #endif
54
55 void dump_south(device_t dev)
56 {
57         int i, j;
58
59         for (i = 0; i < 256; i += 16) {
60                 printk(BIOS_DEBUG, "%02x: ", i);
61                 for (j = 0; j < 16; j++)
62                         printk(BIOS_DEBUG, "%02x ", pci_read_config8(dev, i + j));
63                 printk(BIOS_DEBUG, "\n");
64         }
65 }
66
67 static void vt8237r_enable(struct device *dev)
68 {
69         u16 vid, did;
70         struct southbridge_via_vt8237r_config *sb =
71             (struct southbridge_via_vt8237r_config *)dev->chip_info;
72
73         if (dev->path.type == DEVICE_PATH_PCI) {
74                 vid = pci_read_config16(dev, PCI_VENDOR_ID);
75                 did = pci_read_config16(dev, PCI_DEVICE_ID);
76                 if (vid == PCI_VENDOR_ID_VIA &&
77                         (did == PCI_DEVICE_ID_VIA_VT8237R_LPC ||
78                          did == PCI_DEVICE_ID_VIA_VT8237A_LPC ||
79                          did == PCI_DEVICE_ID_VIA_VT8237S_LPC)) {
80                         pci_write_config8(dev, 0x50, sb->fn_ctrl_lo);
81                         pci_write_config8(dev, 0x51, sb->fn_ctrl_hi);
82                 }
83         }
84
85         /* TODO: If SATA is disabled, move IDE to fn0 to conform PCI specs. */
86 }
87
88 struct chip_operations southbridge_via_vt8237r_ops = {
89         CHIP_NAME("VIA VT8237R Southbridge")
90         .enable_dev = vt8237r_enable,
91 };