blob: f31ed2935426feadb44b4f60c9f3b566e8b78a30 [file] [log] [blame]
Morgan Tsai1602dd52007-10-29 21:00:14 +00001/*
2 * This file is part of the LinuxBIOS project.
3 *
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
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
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"
33
34uint8_t SiS_SiS5513_init[49][3]={
Morgan Tsai218c2652007-11-02 16:09:58 +000035{0x04, 0xFF, 0x05},
36{0x0D, 0xFF, 0x80},
37{0x2C, 0xFF, 0x39},
38{0x2D, 0xFF, 0x10},
39{0x2E, 0xFF, 0x13},
40{0x2F, 0xFF, 0x55},
41{0x50, 0xFF, 0xA2},
42{0x51, 0xFF, 0x21},
43{0x53, 0xFF, 0x21},
44{0x54, 0xFF, 0x2A},
45{0x55, 0xFF, 0x96},
46{0x52, 0xFF, 0xA2},
47{0x56, 0xFF, 0x81},
48{0x57, 0xFF, 0xC0},
49{0x60, 0xFF, 0xFB},
50{0x61, 0xFF, 0xAA},
51{0x62, 0xFF, 0xFB},
52{0x63, 0xFF, 0xAA},
53{0x81, 0xFF, 0xB3},
54{0x82, 0xFF, 0x72},
55{0x83, 0xFF, 0x40},
56{0x85, 0xFF, 0xB3},
57{0x86, 0xFF, 0x72},
58{0x87, 0xFF, 0x40},
59{0x94, 0xFF, 0xC0},
60{0x95, 0xFF, 0x08},
61{0x96, 0xFF, 0xC0},
62{0x97, 0xFF, 0x08},
63{0x98, 0xFF, 0xCC},
64{0x99, 0xFF, 0x04},
65{0x9A, 0xFF, 0x0C},
66{0x9B, 0xFF, 0x14},
67{0xA0, 0xFF, 0x11},
68{0x57, 0xFF, 0xD0},
Morgan Tsai1602dd52007-10-29 21:00:14 +000069
Morgan Tsai218c2652007-11-02 16:09:58 +000070{0xD8, 0xFE, 0x01}, // Com reset
71{0xC8, 0xFE, 0x01},
72{0xC4, 0xFF, 0xFF}, // Clear status
Morgan Tsai1602dd52007-10-29 21:00:14 +000073{0xC5, 0xFF, 0xFF},
74{0xC6, 0xFF, 0xFF},
75{0xC7, 0xFF, 0xFF},
76{0xD4, 0xFF, 0xFF},
77{0xD5, 0xFF, 0xFF},
78{0xD6, 0xFF, 0xFF},
79{0xD7, 0xFF, 0xFF},
80
Morgan Tsai218c2652007-11-02 16:09:58 +000081
82{0x2C, 0xFF, 0x39}, // set subsystem ID
83{0x2D, 0xFF, 0x10},
84{0x2E, 0xFF, 0x13},
Morgan Tsai1602dd52007-10-29 21:00:14 +000085{0x2F, 0xFF, 0x55},
86
87
88{0x00, 0x00, 0x00} //End of table
89};
90
91static void ide_init(struct device *dev)
92{
93 struct southbridge_sis_sis966_config *conf;
94 /* Enable ide devices so the linux ide driver will work */
95 uint32_t dword;
96 uint16_t word;
97 uint8_t byte;
98 conf = dev->chip_info;
Morgan Tsai1602dd52007-10-29 21:00:14 +000099
Morgan Tsai218c2652007-11-02 16:09:58 +0000100
101
102print_debug("IDE_INIT:---------->\n");
Morgan Tsai1602dd52007-10-29 21:00:14 +0000103
104
105//-------------- enable IDE (SiS5513) -------------------------
106{
Morgan Tsai218c2652007-11-02 16:09:58 +0000107 uint8_t temp8;
108 int i=0;
Morgan Tsai1602dd52007-10-29 21:00:14 +0000109 while(SiS_SiS5513_init[i][0] != 0)
Morgan Tsai218c2652007-11-02 16:09:58 +0000110 {
111 temp8 = pci_read_config8(dev, SiS_SiS5513_init[i][0]);
112 temp8 &= SiS_SiS5513_init[i][1];
113 temp8 |= SiS_SiS5513_init[i][2];
114 pci_write_config8(dev, SiS_SiS5513_init[i][0], temp8);
115 i++;
Morgan Tsai1602dd52007-10-29 21:00:14 +0000116 };
117}
118//-----------------------------------------------------------
119
120 word = pci_read_config16(dev, 0x50);
121 /* Ensure prefetch is disabled */
122 word &= ~((1 << 15) | (1 << 13));
123 if (conf->ide1_enable) {
124 /* Enable secondary ide interface */
125 word |= (1<<0);
126 printk_debug("IDE1 \t");
127 }
128 if (conf->ide0_enable) {
129 /* Enable primary ide interface */
130 word |= (1<<1);
131 printk_debug("IDE0\n");
132 }
133
134 word |= (1<<12);
135 word |= (1<<14);
136
137 pci_write_config16(dev, 0x50, word);
138
139
140 byte = 0x20 ; // Latency: 64-->32
141 pci_write_config8(dev, 0xd, byte);
142
143 dword = pci_read_config32(dev, 0xf8);
144 dword |= 12;
145 pci_write_config32(dev, 0xf8, dword);
146#if CONFIG_PCI_ROM_RUN == 1
147 pci_dev_init(dev);
148#endif
149
Morgan Tsai218c2652007-11-02 16:09:58 +0000150#if DEBUG_IDE
151{
152 int i;
153
154 print_debug("****** IDE PCI config ******");
155 print_debug("\n 03020100 07060504 0B0A0908 0F0E0D0C");
156
157 for(i=0;i<0xff;i+=4){
158 if((i%16)==0){
159 print_debug("\r\n");
160 print_debug_hex8(i);
161 print_debug(": ");
162 }
163 print_debug_hex32(pci_read_config32(dev,i));
164 print_debug(" ");
165 }
166 print_debug("\r\n");
167}
168#endif
169print_debug("IDE_INIT:<----------\n");
Morgan Tsai1602dd52007-10-29 21:00:14 +0000170}
171
172static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
173{
174 pci_write_config32(dev, 0x40,
175 ((device & 0xffff) << 16) | (vendor & 0xffff));
176}
177static struct pci_operations lops_pci = {
178 .set_subsystem = lpci_set_subsystem,
179};
180
181static struct device_operations ide_ops = {
182 .read_resources = pci_dev_read_resources,
183 .set_resources = pci_dev_set_resources,
184 .enable_resources = pci_dev_enable_resources,
185 .init = ide_init,
186 .scan_bus = 0,
187// .enable = sis966_enable,
188 .ops_pci = &lops_pci,
189};
190
Stefan Reinauer83b52e72007-10-30 02:17:49 +0000191static const struct pci_driver ide_driver __pci_driver = {
Morgan Tsai1602dd52007-10-29 21:00:14 +0000192 .ops = &ide_ops,
193 .vendor = PCI_VENDOR_ID_SIS,
194 .device = PCI_DEVICE_ID_SIS_SIS966_IDE,
195};
196