blob: 5300b7e3a4c780d15080880de746a978480cb735 [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.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
Paul Menzela46a7122013-02-23 18:37:27 +010023 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Morgan Tsai1602dd52007-10-29 21:00:14 +000024 */
25
26#include <console/console.h>
27#include <device/device.h>
28#include <device/pci.h>
29#include <device/pci_ids.h>
30#include <device/pci_ops.h>
31#include <arch/io.h>
32#include "sis966.h"
Uwe Hermannb9c224e2010-12-16 19:57:54 +000033#include "chip.h"
Morgan Tsai1602dd52007-10-29 21:00:14 +000034
35uint8_t SiS_SiS5513_init[49][3]={
Morgan Tsai218c2652007-11-02 16:09:58 +000036{0x04, 0xFF, 0x05},
37{0x0D, 0xFF, 0x80},
38{0x2C, 0xFF, 0x39},
39{0x2D, 0xFF, 0x10},
40{0x2E, 0xFF, 0x13},
41{0x2F, 0xFF, 0x55},
42{0x50, 0xFF, 0xA2},
43{0x51, 0xFF, 0x21},
44{0x53, 0xFF, 0x21},
45{0x54, 0xFF, 0x2A},
46{0x55, 0xFF, 0x96},
47{0x52, 0xFF, 0xA2},
48{0x56, 0xFF, 0x81},
49{0x57, 0xFF, 0xC0},
50{0x60, 0xFF, 0xFB},
51{0x61, 0xFF, 0xAA},
52{0x62, 0xFF, 0xFB},
53{0x63, 0xFF, 0xAA},
54{0x81, 0xFF, 0xB3},
55{0x82, 0xFF, 0x72},
56{0x83, 0xFF, 0x40},
57{0x85, 0xFF, 0xB3},
58{0x86, 0xFF, 0x72},
59{0x87, 0xFF, 0x40},
60{0x94, 0xFF, 0xC0},
61{0x95, 0xFF, 0x08},
62{0x96, 0xFF, 0xC0},
63{0x97, 0xFF, 0x08},
64{0x98, 0xFF, 0xCC},
65{0x99, 0xFF, 0x04},
66{0x9A, 0xFF, 0x0C},
67{0x9B, 0xFF, 0x14},
68{0xA0, 0xFF, 0x11},
69{0x57, 0xFF, 0xD0},
Morgan Tsai1602dd52007-10-29 21:00:14 +000070
Morgan Tsai218c2652007-11-02 16:09:58 +000071{0xD8, 0xFE, 0x01}, // Com reset
72{0xC8, 0xFE, 0x01},
73{0xC4, 0xFF, 0xFF}, // Clear status
Morgan Tsai1602dd52007-10-29 21:00:14 +000074{0xC5, 0xFF, 0xFF},
75{0xC6, 0xFF, 0xFF},
76{0xC7, 0xFF, 0xFF},
77{0xD4, 0xFF, 0xFF},
78{0xD5, 0xFF, 0xFF},
79{0xD6, 0xFF, 0xFF},
80{0xD7, 0xFF, 0xFF},
81
Morgan Tsai218c2652007-11-02 16:09:58 +000082
83{0x2C, 0xFF, 0x39}, // set subsystem ID
84{0x2D, 0xFF, 0x10},
85{0x2E, 0xFF, 0x13},
Morgan Tsai1602dd52007-10-29 21:00:14 +000086{0x2F, 0xFF, 0x55},
87
88
89{0x00, 0x00, 0x00} //End of table
90};
91
92static void ide_init(struct device *dev)
93{
94 struct southbridge_sis_sis966_config *conf;
95 /* Enable ide devices so the linux ide driver will work */
96 uint32_t dword;
97 uint16_t word;
98 uint8_t byte;
99 conf = dev->chip_info;
Morgan Tsai1602dd52007-10-29 21:00:14 +0000100
Morgan Tsai218c2652007-11-02 16:09:58 +0000101
102
Stefan Reinauer5ab52dd2015-01-05 13:01:01 -0800103printk(BIOS_DEBUG, "IDE_INIT:---------->\n");
Morgan Tsai1602dd52007-10-29 21:00:14 +0000104
105
106//-------------- enable IDE (SiS5513) -------------------------
107{
Morgan Tsai218c2652007-11-02 16:09:58 +0000108 uint8_t temp8;
109 int i=0;
Morgan Tsai1602dd52007-10-29 21:00:14 +0000110 while(SiS_SiS5513_init[i][0] != 0)
Morgan Tsai218c2652007-11-02 16:09:58 +0000111 {
112 temp8 = pci_read_config8(dev, SiS_SiS5513_init[i][0]);
113 temp8 &= SiS_SiS5513_init[i][1];
114 temp8 |= SiS_SiS5513_init[i][2];
115 pci_write_config8(dev, SiS_SiS5513_init[i][0], temp8);
116 i++;
Morgan Tsai1602dd52007-10-29 21:00:14 +0000117 };
118}
119//-----------------------------------------------------------
120
121 word = pci_read_config16(dev, 0x50);
122 /* Ensure prefetch is disabled */
123 word &= ~((1 << 15) | (1 << 13));
124 if (conf->ide1_enable) {
125 /* Enable secondary ide interface */
126 word |= (1<<0);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000127 printk(BIOS_DEBUG, "IDE1 \t");
Morgan Tsai1602dd52007-10-29 21:00:14 +0000128 }
129 if (conf->ide0_enable) {
130 /* Enable primary ide interface */
131 word |= (1<<1);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000132 printk(BIOS_DEBUG, "IDE0\n");
Morgan Tsai1602dd52007-10-29 21:00:14 +0000133 }
134
135 word |= (1<<12);
136 word |= (1<<14);
137
138 pci_write_config16(dev, 0x50, word);
139
140
141 byte = 0x20 ; // Latency: 64-->32
142 pci_write_config8(dev, 0xd, byte);
143
144 dword = pci_read_config32(dev, 0xf8);
145 dword |= 12;
146 pci_write_config32(dev, 0xf8, dword);
Morgan Tsai1602dd52007-10-29 21:00:14 +0000147
Morgan Tsai218c2652007-11-02 16:09:58 +0000148#if DEBUG_IDE
149{
150 int i;
151
Stefan Reinauer5ab52dd2015-01-05 13:01:01 -0800152 printk(BIOS_DEBUG, "****** IDE PCI config ******");
153 printk(BIOS_DEBUG, "\n 03020100 07060504 0B0A0908 0F0E0D0C");
Morgan Tsai218c2652007-11-02 16:09:58 +0000154
155 for(i=0;i<0xff;i+=4){
Stefan Reinauer5ab52dd2015-01-05 13:01:01 -0800156 if((i%16)==0)
157 printk(BIOS_DEBUG, "\n%02x: ", i);
158 printk(BIOS_DEBUG, "%08x ", pci_read_config32(dev,i));
Morgan Tsai218c2652007-11-02 16:09:58 +0000159 }
Stefan Reinauer5ab52dd2015-01-05 13:01:01 -0800160 printk(BIOS_DEBUG, "\n");
Morgan Tsai218c2652007-11-02 16:09:58 +0000161}
162#endif
Stefan Reinauer5ab52dd2015-01-05 13:01:01 -0800163printk(BIOS_DEBUG, "IDE_INIT:<----------\n");
Morgan Tsai1602dd52007-10-29 21:00:14 +0000164}
165
166static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
167{
168 pci_write_config32(dev, 0x40,
169 ((device & 0xffff) << 16) | (vendor & 0xffff));
170}
171static struct pci_operations lops_pci = {
172 .set_subsystem = lpci_set_subsystem,
173};
174
175static struct device_operations ide_ops = {
176 .read_resources = pci_dev_read_resources,
177 .set_resources = pci_dev_set_resources,
178 .enable_resources = pci_dev_enable_resources,
179 .init = ide_init,
180 .scan_bus = 0,
181// .enable = sis966_enable,
182 .ops_pci = &lops_pci,
183};
184
Stefan Reinauer83b52e72007-10-30 02:17:49 +0000185static const struct pci_driver ide_driver __pci_driver = {
Morgan Tsai1602dd52007-10-29 21:00:14 +0000186 .ops = &ide_ops,
187 .vendor = PCI_VENDOR_ID_SIS,
188 .device = PCI_DEVICE_ID_SIS_SIS966_IDE,
189};