Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 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. |
Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 20 | */ |
| 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 Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 31 | uint8_t SiS_SiS1183_init[68][3]={ |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 32 | {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 Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 46 | {0x57, 0x00, 0x14}, |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 47 | {0x67, 0x00, 0x28}, |
| 48 | {0x81, 0x00, 0xB3}, |
| 49 | {0x82, 0x00, 0x72}, |
| 50 | {0x83, 0x00, 0x40}, |
| 51 | {0x85, 0x00, 0xB3}, |
| 52 | {0x86, 0x00, 0x72}, |
Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 53 | {0x87, 0x00, 0x40}, |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 54 | {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 Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 66 | {0x97, 0x00, 0x08}, |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 67 | {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 Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 74 | {0xA3, 0x00, 0x15}, |
| 75 | |
| 76 | |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 77 | {0xD8, 0xFE, 0x01}, // Com reset |
Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 78 | {0xC8, 0xFE, 0x01}, |
| 79 | {0xE8, 0xFE, 0x01}, |
| 80 | {0xF8, 0xFE, 0x01}, |
| 81 | |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 82 | {0xD8, 0xFE, 0x00}, // Com reset |
Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 83 | {0xC8, 0xFE, 0x00}, |
| 84 | {0xE8, 0xFE, 0x00}, |
| 85 | {0xF8, 0xFE, 0x00}, |
| 86 | |
| 87 | |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 88 | {0xC4, 0xFF, 0xFF}, // Clear status |
Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 89 | {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 Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 96 | {0xE4, 0xFF, 0xFF}, // Clear status |
Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 97 | {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 Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 108 | static void sata_init(struct device *dev) |
| 109 | { |
Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 110 | struct southbridge_sis_sis966_config *conf; |
| 111 | |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 112 | |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 113 | |
Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 114 | conf = dev->chip_info; |
Stefan Reinauer | 5ab52dd | 2015-01-05 13:01:01 -0800 | [diff] [blame] | 115 | printk(BIOS_DEBUG, "SATA_INIT:---------->\n"); |
Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 116 | |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 117 | //-------------- enable IDE (SiS1183) ------------------------- |
| 118 | { |
| 119 | uint8_t temp8; |
| 120 | int i=0; |
Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 121 | while(SiS_SiS1183_init[i][0] != 0) |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 122 | { |
| 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 Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 128 | }; |
| 129 | } |
Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 130 | //----------------------------------------------------------- |
Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 131 | |
| 132 | { |
| 133 | uint32_t i,j; |
| 134 | uint32_t temp32; |
| 135 | |
| 136 | for (i=0;i<10;i++){ |
| 137 | temp32=0; |
| 138 | temp32= pci_read_config32(dev, 0xC0); |
| 139 | for ( j=0;j<0xFFFF;j++); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 140 | printk(BIOS_DEBUG, "status= %x\n",temp32); |
Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 141 | if (((temp32&0xF) == 0x3) || ((temp32&0xF) == 0x0)) break; |
| 142 | } |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 143 | |
Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 146 | #if DEBUG_SATA |
Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 147 | { |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 148 | int i; |
| 149 | |
Stefan Reinauer | 5ab52dd | 2015-01-05 13:01:01 -0800 | [diff] [blame] | 150 | printk(BIOS_DEBUG, "****** SATA PCI config ******"); |
| 151 | printk(BIOS_DEBUG, "\n 03020100 07060504 0B0A0908 0F0E0D0C"); |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 152 | |
| 153 | for(i=0;i<0xff;i+=4){ |
Stefan Reinauer | 5ab52dd | 2015-01-05 13:01:01 -0800 | [diff] [blame] | 154 | if((i%16)==0) |
| 155 | printk(BIOS_DEBUG, "\n%02x: ", i); |
| 156 | printk(BIOS_DEBUG, "%08x ", pci_read_config32(dev,i)); |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 157 | } |
Stefan Reinauer | 5ab52dd | 2015-01-05 13:01:01 -0800 | [diff] [blame] | 158 | printk(BIOS_DEBUG, "\n"); |
Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 159 | } |
| 160 | #endif |
Morgan Tsai | 218c265 | 2007-11-02 16:09:58 +0000 | [diff] [blame] | 161 | |
Stefan Reinauer | 5ab52dd | 2015-01-05 13:01:01 -0800 | [diff] [blame] | 162 | printk(BIOS_DEBUG, "SATA_INIT:<----------\n"); |
Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 163 | |
| 164 | } |
| 165 | |
| 166 | static 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 | } |
| 171 | static struct pci_operations lops_pci = { |
| 172 | .set_subsystem = lpci_set_subsystem, |
| 173 | }; |
| 174 | |
| 175 | static 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 Reinauer | 83b52e7 | 2007-10-30 02:17:49 +0000 | [diff] [blame] | 185 | static const struct pci_driver sata0_driver __pci_driver = { |
Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 186 | .ops = &sata_ops, |
| 187 | .vendor = PCI_VENDOR_ID_SIS, |
Morgan Tsai | 31e805d | 2007-11-14 01:34:02 +0000 | [diff] [blame] | 188 | .device = PCI_DEVICE_ID_SIS_SIS966_SATA, |
Morgan Tsai | 1602dd5 | 2007-10-29 21:00:14 +0000 | [diff] [blame] | 189 | }; |