blob: 197f4d22b9c7ae24f5c2d60b6d8b3139c4390932 [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 <delay.h>
25#include <device/pci.h>
26#include <device/pci_ids.h>
27#include <device/pci_ops.h>
28#include "sis966.h"
29#include <arch/io.h>
30
Morgan Tsai1602dd52007-10-29 21:00:14 +000031uint8_t SiS_SiS1183_init[68][3]={
Morgan Tsai218c2652007-11-02 16:09:58 +000032{0x04, 0x00, 0x05},
33{0x09, 0x00, 0x05},
34{0x2C, 0x00, 0x39},
35{0x2D, 0x00, 0x10},
36{0x2E, 0x00, 0x83},
37{0x2F, 0x00, 0x11},
38{0x90, 0x00, 0x40},
39{0x91, 0x00, 0x00}, // set mode
40{0x50, 0x00, 0xA2},
41{0x52, 0x00, 0xA2},
42{0x55, 0x00, 0x96},
43{0x52, 0x00, 0xA2},
44{0x55, 0xF7, 0x00},
45{0x56, 0x00, 0xC0},
Morgan Tsai1602dd52007-10-29 21:00:14 +000046{0x57, 0x00, 0x14},
Morgan Tsai218c2652007-11-02 16:09:58 +000047{0x67, 0x00, 0x28},
48{0x81, 0x00, 0xB3},
49{0x82, 0x00, 0x72},
50{0x83, 0x00, 0x40},
51{0x85, 0x00, 0xB3},
52{0x86, 0x00, 0x72},
Morgan Tsai1602dd52007-10-29 21:00:14 +000053{0x87, 0x00, 0x40},
Morgan Tsai218c2652007-11-02 16:09:58 +000054{0x88, 0x00, 0xDE}, // after set mode
55{0x89, 0x00, 0xB3},
56{0x8A, 0x00, 0x72},
57{0x8B, 0x00, 0x40},
58{0x8C, 0x00, 0xDE},
59{0x8D, 0x00, 0xB3},
60{0x8E, 0x00, 0x92},
61{0x8F, 0x00, 0x40},
62{0x93, 0x00, 0x00},
63{0x94, 0x00, 0x80},
64{0x95, 0x00, 0x08},
65{0x96, 0x00, 0x80},
Morgan Tsai1602dd52007-10-29 21:00:14 +000066{0x97, 0x00, 0x08},
Morgan Tsai218c2652007-11-02 16:09:58 +000067{0x9C, 0x00, 0x80},
68{0x9D, 0x00, 0x08},
69{0x9E, 0x00, 0x80},
70{0x9F, 0x00, 0x08},
71{0xA0, 0x00, 0x15},
72{0xA1, 0x00, 0x15},
73{0xA2, 0x00, 0x15},
Morgan Tsai1602dd52007-10-29 21:00:14 +000074{0xA3, 0x00, 0x15},
75
76
Morgan Tsai218c2652007-11-02 16:09:58 +000077{0xD8, 0xFE, 0x01}, // Com reset
Morgan Tsai1602dd52007-10-29 21:00:14 +000078{0xC8, 0xFE, 0x01},
79{0xE8, 0xFE, 0x01},
80{0xF8, 0xFE, 0x01},
81
Morgan Tsai218c2652007-11-02 16:09:58 +000082{0xD8, 0xFE, 0x00}, // Com reset
Morgan Tsai1602dd52007-10-29 21:00:14 +000083{0xC8, 0xFE, 0x00},
84{0xE8, 0xFE, 0x00},
85{0xF8, 0xFE, 0x00},
86
87
Morgan Tsai218c2652007-11-02 16:09:58 +000088{0xC4, 0xFF, 0xFF}, // Clear status
Morgan Tsai1602dd52007-10-29 21:00:14 +000089{0xC5, 0xFF, 0xFF},
90{0xC6, 0xFF, 0xFF},
91{0xC7, 0xFF, 0xFF},
92{0xD4, 0xFF, 0xFF},
93{0xD5, 0xFF, 0xFF},
94{0xD6, 0xFF, 0xFF},
95{0xD7, 0xFF, 0xFF},
Morgan Tsai218c2652007-11-02 16:09:58 +000096{0xE4, 0xFF, 0xFF}, // Clear status
Morgan Tsai1602dd52007-10-29 21:00:14 +000097{0xE5, 0xFF, 0xFF},
98{0xE6, 0xFF, 0xFF},
99{0xE7, 0xFF, 0xFF},
100{0xF4, 0xFF, 0xFF},
101{0xF5, 0xFF, 0xFF},
102{0xF6, 0xFF, 0xFF},
103{0xF7, 0xFF, 0xFF},
104
105{0x00, 0x00, 0x00} //End of table
106};
107
Morgan Tsai1602dd52007-10-29 21:00:14 +0000108static void sata_init(struct device *dev)
109{
Morgan Tsai1602dd52007-10-29 21:00:14 +0000110 struct southbridge_sis_sis966_config *conf;
111
Morgan Tsai218c2652007-11-02 16:09:58 +0000112
Morgan Tsai218c2652007-11-02 16:09:58 +0000113
Morgan Tsai1602dd52007-10-29 21:00:14 +0000114 conf = dev->chip_info;
Stefan Reinauer5ab52dd2015-01-05 13:01:01 -0800115 printk(BIOS_DEBUG, "SATA_INIT:---------->\n");
Morgan Tsai1602dd52007-10-29 21:00:14 +0000116
Morgan Tsai218c2652007-11-02 16:09:58 +0000117//-------------- enable IDE (SiS1183) -------------------------
118{
119 uint8_t temp8;
120 int i=0;
Morgan Tsai1602dd52007-10-29 21:00:14 +0000121 while(SiS_SiS1183_init[i][0] != 0)
Morgan Tsai218c2652007-11-02 16:09:58 +0000122 {
123 temp8 = pci_read_config8(dev, SiS_SiS1183_init[i][0]);
124 temp8 &= SiS_SiS1183_init[i][1];
125 temp8 |= SiS_SiS1183_init[i][2];
126 pci_write_config8(dev, SiS_SiS1183_init[i][0], temp8);
127 i++;
Morgan Tsai1602dd52007-10-29 21:00:14 +0000128 };
129}
Morgan Tsai1602dd52007-10-29 21:00:14 +0000130//-----------------------------------------------------------
Morgan Tsai1602dd52007-10-29 21:00:14 +0000131
132{
133uint32_t i,j;
134uint32_t temp32;
135
136for (i=0;i<10;i++){
137 temp32=0;
138 temp32= pci_read_config32(dev, 0xC0);
139 for ( j=0;j<0xFFFF;j++);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000140 printk(BIOS_DEBUG, "status= %x\n",temp32);
Morgan Tsai1602dd52007-10-29 21:00:14 +0000141 if (((temp32&0xF) == 0x3) || ((temp32&0xF) == 0x0)) break;
142}
Morgan Tsai218c2652007-11-02 16:09:58 +0000143
Morgan Tsai1602dd52007-10-29 21:00:14 +0000144}
145
Morgan Tsai218c2652007-11-02 16:09:58 +0000146#if DEBUG_SATA
Morgan Tsai1602dd52007-10-29 21:00:14 +0000147{
Morgan Tsai218c2652007-11-02 16:09:58 +0000148 int i;
149
Stefan Reinauer5ab52dd2015-01-05 13:01:01 -0800150 printk(BIOS_DEBUG, "****** SATA PCI config ******");
151 printk(BIOS_DEBUG, "\n 03020100 07060504 0B0A0908 0F0E0D0C");
Morgan Tsai218c2652007-11-02 16:09:58 +0000152
153 for(i=0;i<0xff;i+=4){
Stefan Reinauer5ab52dd2015-01-05 13:01:01 -0800154 if((i%16)==0)
155 printk(BIOS_DEBUG, "\n%02x: ", i);
156 printk(BIOS_DEBUG, "%08x ", pci_read_config32(dev,i));
Morgan Tsai218c2652007-11-02 16:09:58 +0000157 }
Stefan Reinauer5ab52dd2015-01-05 13:01:01 -0800158 printk(BIOS_DEBUG, "\n");
Morgan Tsai1602dd52007-10-29 21:00:14 +0000159}
160#endif
Morgan Tsai218c2652007-11-02 16:09:58 +0000161
Stefan Reinauer5ab52dd2015-01-05 13:01:01 -0800162 printk(BIOS_DEBUG, "SATA_INIT:<----------\n");
Morgan Tsai1602dd52007-10-29 21:00:14 +0000163
164}
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 sata_ops = {
176 .read_resources = pci_dev_read_resources,
177 .set_resources = pci_dev_set_resources,
178 .enable_resources = pci_dev_enable_resources,
179// .enable = sis966_enable,
180 .init = sata_init,
181 .scan_bus = 0,
182 .ops_pci = &lops_pci,
183};
184
Stefan Reinauer83b52e72007-10-30 02:17:49 +0000185static const struct pci_driver sata0_driver __pci_driver = {
Morgan Tsai1602dd52007-10-29 21:00:14 +0000186 .ops = &sata_ops,
187 .vendor = PCI_VENDOR_ID_SIS,
Morgan Tsai31e805d2007-11-14 01:34:02 +0000188 .device = PCI_DEVICE_ID_SIS_SIS966_SATA,
Morgan Tsai1602dd52007-10-29 21:00:14 +0000189};