blob: 308c604abbe85c67aabb16769eb90c3e88fc25b2 [file] [log] [blame]
Morgan Tsai1602dd52007-10-29 21:00:14 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Morgan Tsai1602dd52007-10-29 21:00:14 +00003 *
4 * Copyright (C) 2004 Tyan Computer
5 * Written by Yinghai Lu <yhlu@tyan.com> for Tyan Computer.
6 * Copyright (C) 2006,2007 AMD
7 * Written by Yinghai Lu <yinghai.lu@amd.com> for AMD.
8 * Copyright (C) 2007 Silicon Integrated Systems Corp. (SiS)
9 * Written by Morgan Tsai <my_tsai@sis.com> for SiS.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
Morgan Tsai1602dd52007-10-29 21:00:14 +000020 */
21
22#include <console/console.h>
23
24#include <arch/io.h>
25
26#include <device/device.h>
27#include <device/pci.h>
28#include <device/pci_ids.h>
29#include <device/pci_ops.h>
30#include "sis966.h"
31
32static uint32_t final_reg;
33
34static device_t find_lpc_dev( device_t dev, unsigned devfn)
35{
36
37 device_t lpc_dev;
38
39 lpc_dev = dev_find_slot(dev->bus->secondary, devfn);
40
41 if ( !lpc_dev ) return lpc_dev;
42
43if ((lpc_dev->vendor != PCI_VENDOR_ID_SIS) || (
44 (lpc_dev->device != PCI_DEVICE_ID_SIS_SIS966_LPC)
45 ) ) {
46 uint32_t id;
47 id = pci_read_config32(lpc_dev, PCI_VENDOR_ID);
Morgan Tsai218c2652007-11-02 16:09:58 +000048 if ( (id < (PCI_VENDOR_ID_SIS | (PCI_DEVICE_ID_SIS_SIS966_LPC << 16)))
Morgan Tsai1602dd52007-10-29 21:00:14 +000049 ) {
50 lpc_dev = 0;
51 }
52 }
53
54 return lpc_dev;
55}
56
57void sis966_enable(device_t dev)
58{
59 device_t lpc_dev = 0;
60 device_t sm_dev = 0;
Morgan Tsai218c2652007-11-02 16:09:58 +000061 uint16_t index = 0;
62 uint16_t index2 = 0;
Morgan Tsai1602dd52007-10-29 21:00:14 +000063 uint32_t reg_old, reg;
64 uint8_t byte;
Morgan Tsai218c2652007-11-02 16:09:58 +000065 uint16_t deviceid;
66 uint16_t vendorid;
67 uint16_t devfn;
Morgan Tsai1602dd52007-10-29 21:00:14 +000068
69 struct southbridge_sis_sis966_config *conf;
70 conf = dev->chip_info;
71 int i;
72
Morgan Tsai1602dd52007-10-29 21:00:14 +000073 if(dev->device==0x0000) {
74 vendorid = pci_read_config32(dev, PCI_VENDOR_ID);
75 deviceid = (vendorid>>16) & 0xffff;
76// vendorid &= 0xffff;
77 } else {
78// vendorid = dev->vendor;
79 deviceid = dev->device;
80 }
81
Stefan Reinauer2b34db82009-02-28 20:10:20 +000082 devfn = (dev->path.pci.devfn) & ~7;
Morgan Tsai1602dd52007-10-29 21:00:14 +000083 switch(deviceid) {
Morgan Tsai1602dd52007-10-29 21:00:14 +000084 case PCI_DEVICE_ID_SIS_SIS966_USB:
85 devfn -= (1<<3);
86 index = 8;
87 break;
Morgan Tsai218c2652007-11-02 16:09:58 +000088 case PCI_DEVICE_ID_SIS_SIS966_USB2:
Morgan Tsai1602dd52007-10-29 21:00:14 +000089 devfn -= (1<<3);
90 index = 20;
91 break;
Morgan Tsai31e805d2007-11-14 01:34:02 +000092 case PCI_DEVICE_ID_SIS_SIS966_NIC:
Morgan Tsai1602dd52007-10-29 21:00:14 +000093 devfn -= (7<<3);
94 index = 10;
95 for(i=0;i<2;i++) {
96 lpc_dev = find_lpc_dev(dev, devfn - (i<<3));
97 if(!lpc_dev) continue;
98 index -= i;
99 devfn -= (i<<3);
100 break;
101 }
102 break;
Morgan Tsai31e805d2007-11-14 01:34:02 +0000103 case PCI_DEVICE_ID_SIS_SIS966_HD_AUDIO:
Morgan Tsai1602dd52007-10-29 21:00:14 +0000104 devfn -= (5<<3);
105 index = 11;
106 break;
107 case PCI_DEVICE_ID_SIS_SIS966_IDE:
108 devfn -= (3<<3);
109 index = 14;
110 break;
Morgan Tsai31e805d2007-11-14 01:34:02 +0000111 case PCI_DEVICE_ID_SIS_SIS966_SATA:
Morgan Tsai1602dd52007-10-29 21:00:14 +0000112 devfn -= (4<<3);
113 index = 22;
Stefan Reinauer2b34db82009-02-28 20:10:20 +0000114 i = (dev->path.pci.devfn) & 7;
Morgan Tsai1602dd52007-10-29 21:00:14 +0000115 if(i>0) {
116 index -= (i+3);
117 }
118 break;
Morgan Tsai31e805d2007-11-14 01:34:02 +0000119 case PCI_DEVICE_ID_SIS_SIS966_PCIE:
120 devfn -= (0x9<<3); // to LPC
121 index2 = 9;
Morgan Tsai1602dd52007-10-29 21:00:14 +0000122 break;
123 default:
124 index = 0;
125 }
126
127 if(!lpc_dev)
128 lpc_dev = find_lpc_dev(dev, devfn);
129
130 if ( !lpc_dev ) return;
131
132 if(index2!=0) {
133 sm_dev = dev_find_slot(dev->bus->secondary, devfn + 1);
134 if(!sm_dev) return;
135
136 if ( sm_dev ) {
137 reg_old = reg = pci_read_config32(sm_dev, 0xe4);
138
139 if (!dev->enabled) { //disable it
140 reg |= (1<<index2);
141 }
142
143 if (reg != reg_old) {
144 pci_write_config32(sm_dev, 0xe4, reg);
145 }
146 }
147
148 index2 = 0;
149 return;
150 }
151
152
153 if ( index == 0) { // for LPC
154
155 // expose ioapic base
156 byte = pci_read_config8(lpc_dev, 0x74);
157 byte |= ((1<<1)); // expose the BAR
158 pci_write_config8(dev, 0x74, byte);
159
160 // expose trap base
161 byte = pci_read_config8(lpc_dev, 0xdd);
162 byte |= ((1<<0)|(1<<3)); // expose the BAR and enable write
163 pci_write_config8(dev, 0xdd, byte);
Morgan Tsai1602dd52007-10-29 21:00:14 +0000164 return;
165
166 }
167
168 if( index == 16) {
169 sm_dev = dev_find_slot(dev->bus->secondary, devfn + 1);
170 if(!sm_dev) return;
171
172 final_reg = pci_read_config32(sm_dev, 0xe8);
Morgan Tsai218c2652007-11-02 16:09:58 +0000173 final_reg &= ~0x0057cf00;
Morgan Tsai1602dd52007-10-29 21:00:14 +0000174 pci_write_config32(sm_dev, 0xe8, final_reg); //enable all at first
Morgan Tsai1602dd52007-10-29 21:00:14 +0000175 }
176
177 if (!dev->enabled) {
178 final_reg |= (1 << index);// disable it
Martin Roth226db052014-12-09 13:51:49 -0700179 /*
180 * The reason for using final_reg is that if func 1 is disabled,
181 * then func 2 will become func 1.
182 * Because of this, we need loop through disabling them all at
183 * the same time.
184 */
Morgan Tsai1602dd52007-10-29 21:00:14 +0000185 }
186
187 if(index == 9 ) { //NIC1 is the final, We need update final reg to 0xe8
188 sm_dev = dev_find_slot(dev->bus->secondary, devfn + 1);
189 if(!sm_dev) return;
190 reg_old = pci_read_config32(sm_dev, 0xe8);
191 if (final_reg != reg_old) {
192 pci_write_config32(sm_dev, 0xe8, final_reg);
193 }
194
195 }
Morgan Tsai1602dd52007-10-29 21:00:14 +0000196}
197
198struct chip_operations southbridge_sis_sis966_ops = {
199 CHIP_NAME("SiS SiS966 Southbridge")
200 .enable_dev = sis966_enable,
201};