blob: f3fa07943b5680d510bdeedcc1d06d29aa1d9e53 [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#include <device/device.h>
24#include <device/pci.h>
25#include <device/pci_ids.h>
26#include <device/pci_ops.h>
27#include <arch/io.h>
28#include "sis966.h"
Uwe Hermannb9c224e2010-12-16 19:57:54 +000029#include "chip.h"
Morgan Tsai1602dd52007-10-29 21:00:14 +000030
31uint8_t SiS_SiS5513_init[49][3]={
Morgan Tsai218c2652007-11-02 16:09:58 +000032{0x04, 0xFF, 0x05},
33{0x0D, 0xFF, 0x80},
34{0x2C, 0xFF, 0x39},
35{0x2D, 0xFF, 0x10},
36{0x2E, 0xFF, 0x13},
37{0x2F, 0xFF, 0x55},
38{0x50, 0xFF, 0xA2},
39{0x51, 0xFF, 0x21},
40{0x53, 0xFF, 0x21},
41{0x54, 0xFF, 0x2A},
42{0x55, 0xFF, 0x96},
43{0x52, 0xFF, 0xA2},
44{0x56, 0xFF, 0x81},
45{0x57, 0xFF, 0xC0},
46{0x60, 0xFF, 0xFB},
47{0x61, 0xFF, 0xAA},
48{0x62, 0xFF, 0xFB},
49{0x63, 0xFF, 0xAA},
50{0x81, 0xFF, 0xB3},
51{0x82, 0xFF, 0x72},
52{0x83, 0xFF, 0x40},
53{0x85, 0xFF, 0xB3},
54{0x86, 0xFF, 0x72},
55{0x87, 0xFF, 0x40},
56{0x94, 0xFF, 0xC0},
57{0x95, 0xFF, 0x08},
58{0x96, 0xFF, 0xC0},
59{0x97, 0xFF, 0x08},
60{0x98, 0xFF, 0xCC},
61{0x99, 0xFF, 0x04},
62{0x9A, 0xFF, 0x0C},
63{0x9B, 0xFF, 0x14},
64{0xA0, 0xFF, 0x11},
65{0x57, 0xFF, 0xD0},
Morgan Tsai1602dd52007-10-29 21:00:14 +000066
Morgan Tsai218c2652007-11-02 16:09:58 +000067{0xD8, 0xFE, 0x01}, // Com reset
68{0xC8, 0xFE, 0x01},
69{0xC4, 0xFF, 0xFF}, // Clear status
Morgan Tsai1602dd52007-10-29 21:00:14 +000070{0xC5, 0xFF, 0xFF},
71{0xC6, 0xFF, 0xFF},
72{0xC7, 0xFF, 0xFF},
73{0xD4, 0xFF, 0xFF},
74{0xD5, 0xFF, 0xFF},
75{0xD6, 0xFF, 0xFF},
76{0xD7, 0xFF, 0xFF},
77
Morgan Tsai218c2652007-11-02 16:09:58 +000078
79{0x2C, 0xFF, 0x39}, // set subsystem ID
80{0x2D, 0xFF, 0x10},
81{0x2E, 0xFF, 0x13},
Morgan Tsai1602dd52007-10-29 21:00:14 +000082{0x2F, 0xFF, 0x55},
83
84
85{0x00, 0x00, 0x00} //End of table
86};
87
88static void ide_init(struct device *dev)
89{
90 struct southbridge_sis_sis966_config *conf;
91 /* Enable ide devices so the linux ide driver will work */
92 uint32_t dword;
93 uint16_t word;
94 uint8_t byte;
95 conf = dev->chip_info;
Morgan Tsai1602dd52007-10-29 21:00:14 +000096
Morgan Tsai218c2652007-11-02 16:09:58 +000097
98
Stefan Reinauer5ab52dd2015-01-05 13:01:01 -080099printk(BIOS_DEBUG, "IDE_INIT:---------->\n");
Morgan Tsai1602dd52007-10-29 21:00:14 +0000100
101
102//-------------- enable IDE (SiS5513) -------------------------
103{
Morgan Tsai218c2652007-11-02 16:09:58 +0000104 uint8_t temp8;
105 int i=0;
Morgan Tsai1602dd52007-10-29 21:00:14 +0000106 while(SiS_SiS5513_init[i][0] != 0)
Morgan Tsai218c2652007-11-02 16:09:58 +0000107 {
108 temp8 = pci_read_config8(dev, SiS_SiS5513_init[i][0]);
109 temp8 &= SiS_SiS5513_init[i][1];
110 temp8 |= SiS_SiS5513_init[i][2];
111 pci_write_config8(dev, SiS_SiS5513_init[i][0], temp8);
112 i++;
Morgan Tsai1602dd52007-10-29 21:00:14 +0000113 };
114}
115//-----------------------------------------------------------
116
117 word = pci_read_config16(dev, 0x50);
118 /* Ensure prefetch is disabled */
119 word &= ~((1 << 15) | (1 << 13));
120 if (conf->ide1_enable) {
121 /* Enable secondary ide interface */
122 word |= (1<<0);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000123 printk(BIOS_DEBUG, "IDE1 \t");
Morgan Tsai1602dd52007-10-29 21:00:14 +0000124 }
125 if (conf->ide0_enable) {
126 /* Enable primary ide interface */
127 word |= (1<<1);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000128 printk(BIOS_DEBUG, "IDE0\n");
Morgan Tsai1602dd52007-10-29 21:00:14 +0000129 }
130
131 word |= (1<<12);
132 word |= (1<<14);
133
134 pci_write_config16(dev, 0x50, word);
135
136
137 byte = 0x20 ; // Latency: 64-->32
138 pci_write_config8(dev, 0xd, byte);
139
140 dword = pci_read_config32(dev, 0xf8);
141 dword |= 12;
142 pci_write_config32(dev, 0xf8, dword);
Morgan Tsai1602dd52007-10-29 21:00:14 +0000143
Morgan Tsai218c2652007-11-02 16:09:58 +0000144#if DEBUG_IDE
145{
146 int i;
147
Stefan Reinauer5ab52dd2015-01-05 13:01:01 -0800148 printk(BIOS_DEBUG, "****** IDE PCI config ******");
149 printk(BIOS_DEBUG, "\n 03020100 07060504 0B0A0908 0F0E0D0C");
Morgan Tsai218c2652007-11-02 16:09:58 +0000150
151 for(i=0;i<0xff;i+=4){
Stefan Reinauer5ab52dd2015-01-05 13:01:01 -0800152 if((i%16)==0)
153 printk(BIOS_DEBUG, "\n%02x: ", i);
154 printk(BIOS_DEBUG, "%08x ", pci_read_config32(dev,i));
Morgan Tsai218c2652007-11-02 16:09:58 +0000155 }
Stefan Reinauer5ab52dd2015-01-05 13:01:01 -0800156 printk(BIOS_DEBUG, "\n");
Morgan Tsai218c2652007-11-02 16:09:58 +0000157}
158#endif
Stefan Reinauer5ab52dd2015-01-05 13:01:01 -0800159printk(BIOS_DEBUG, "IDE_INIT:<----------\n");
Morgan Tsai1602dd52007-10-29 21:00:14 +0000160}
161
162static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
163{
164 pci_write_config32(dev, 0x40,
165 ((device & 0xffff) << 16) | (vendor & 0xffff));
166}
167static struct pci_operations lops_pci = {
168 .set_subsystem = lpci_set_subsystem,
169};
170
171static struct device_operations ide_ops = {
172 .read_resources = pci_dev_read_resources,
173 .set_resources = pci_dev_set_resources,
174 .enable_resources = pci_dev_enable_resources,
175 .init = ide_init,
176 .scan_bus = 0,
177// .enable = sis966_enable,
178 .ops_pci = &lops_pci,
179};
180
Stefan Reinauer83b52e72007-10-30 02:17:49 +0000181static const struct pci_driver ide_driver __pci_driver = {
Morgan Tsai1602dd52007-10-29 21:00:14 +0000182 .ops = &ide_ops,
183 .vendor = PCI_VENDOR_ID_SIS,
184 .device = PCI_DEVICE_ID_SIS_SIS966_IDE,
185};