printk_foo -> printk(BIOS_FOO, ...)
[coreboot.git] / src / southbridge / amd / rs690 / rs690.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008 Advanced Micro Devices, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 #include <console/console.h>
21
22 #include <arch/io.h>
23
24 #include <device/device.h>
25 #include <device/pci.h>
26 #include <device/pci_ids.h>
27 #include <device/pci_ops.h>
28 #include <cpu/x86/msr.h>
29 #include <cpu/amd/mtrr.h>
30 #include "rs690.h"
31
32
33 /*****************************************
34 * Compliant with CIM_33's ATINB_MiscClockCtrl
35 *****************************************/
36 void static rs690_config_misc_clk(device_t nb_dev)
37 {
38         u32 reg;
39         u16 word;
40         /* u8 byte; */
41         struct bus pbus; /* fake bus for dev0 fun1 */
42
43         reg = pci_read_config32(nb_dev, 0x4c);
44         reg |= 1 << 0;
45         pci_write_config32(nb_dev, 0x4c, reg);
46
47         word = pci_cf8_conf1.read16(&pbus, 0, 1, 0xf8);
48         word &= 0xf00;
49         pci_cf8_conf1.write16(&pbus, 0, 1, 0xf8, word);
50
51         word = pci_cf8_conf1.read16(&pbus, 0, 1, 0xe8);
52         word &= ~((1 << 12) | (1 << 13) | (1 << 14));
53         word |= 1 << 13;
54         pci_cf8_conf1.write16(&pbus, 0, 1, 0xe8, word);
55
56         reg =  pci_cf8_conf1.read32(&pbus, 0, 1, 0x94);
57         reg &= ~((1 << 16) | (1 << 24) | (1 << 28));
58         pci_cf8_conf1.write32(&pbus, 0, 1, 0x94, reg);
59
60         reg = pci_cf8_conf1.read32(&pbus, 0, 1, 0x8c);
61         reg &= ~((1 << 13) | (1 << 14) | (1 << 24) | (1 << 25));
62         reg |= 1 << 13;
63         pci_cf8_conf1.write32(&pbus, 0, 1, 0x8c, reg);
64
65         reg = pci_cf8_conf1.read32(&pbus, 0, 1, 0xcc);
66         reg |= 1 << 24;
67         pci_cf8_conf1.write32(&pbus, 0, 1, 0xcc, reg);
68
69         reg = nbmc_read_index(nb_dev, 0x7a);
70         reg &= ~0x3f;
71         reg |= 1 << 2;
72         reg &= ~(1 << 6);
73         set_htiu_enable_bits(nb_dev, 0x05, 1 << 11, 1 << 11);
74         nbmc_write_index(nb_dev, 0x7a, reg);
75         /* Powering Down efuse and strap block clocks after boot-up. GFX Mode. */
76         reg = pci_cf8_conf1.read32(&pbus, 0, 1, 0xcc);
77         reg &= ~(1 << 23);
78         reg |= 1 << 24;
79         pci_cf8_conf1.write32(&pbus, 0, 1, 0xcc, reg);
80 #if 0
81         /* Powerdown reference clock to graphics core PLL in northbridge only mode */
82         reg = pci_cf8_conf1.read32(&pbus, 0, 1, 0x8c);
83         reg |= 1 << 21;
84         pci_cf8_conf1.write32(&pbus, 0, 1, 0x8c, reg);
85
86         /* Powering Down efuse and strap block clocks after boot-up. NB Only Mode. */
87         reg = pci_cf8_conf1.read32(&pbus, 0, 1, 0xcc);
88         reg |= (1 << 23) | (1 << 24);
89         pci_cf8_conf1.write32(&pbus, 0, 1, 0xcc, reg);
90
91         /* Powerdown clock to memory controller in northbridge only mode */
92         byte = pci_cf8_conf1.read8(&pbus, 0, 1, 0xe4);
93         byte |= 1 << 0;
94         pci_cf8_conf1.write8(&pbus, 0, 1, 0xe4, reg);
95
96         /* CLKCFG:0xE8 Bit[17] = 0x1     Powerdown clock to IOC GFX block in no external graphics mode */
97         /* TODO: */
98 #endif
99
100         reg = pci_read_config32(nb_dev, 0x4c);
101         reg &= ~(1 << 0);
102         pci_write_config32(nb_dev, 0x4c, reg);
103
104         set_htiu_enable_bits(nb_dev, 0x05, 7 << 8, 7 << 8);
105 }
106
107
108 u32 get_vid_did(device_t dev)
109 {
110         return pci_read_config32(dev, 0);
111 }
112
113 /***********************************************
114 *       0:00.0  NBCFG   :
115 *       0:00.1  CLK     : bit 0 of nb_cfg 0x4c : 0 - disable, default
116 *       0:01.0  P2P Internal:
117 *       0:02.0  P2P     : bit 2 of nbmiscind 0x0c : 0 - enable, default    + 32 * 2
118 *       0:03.0  P2P     : bit 3 of nbmiscind 0x0c : 0 - enable, default    + 32 * 2
119 *       0:04.0  P2P     : bit 4 of nbmiscind 0x0c : 0 - enable, default    + 32 * 2
120 *       0:05.0  P2P     : bit 5 of nbmiscind 0x0c : 0 - enable, default    + 32 * 2
121 *       0:06.0  P2P     : bit 6 of nbmiscind 0x0c : 0 - enable, default    + 32 * 2
122 *       0:07.0  P2P     : bit 7 of nbmiscind 0x0c : 0 - enable, default    + 32 * 2
123 *       0:08.0  NB2SB   : bit 6 of nbmiscind 0x00 : 0 - disable, default   + 32 * 1
124 * case 0 will be called twice, one is by cpu in hypertransport.c line458,
125 * the other is by rs690.
126 ***********************************************/
127 void rs690_enable(device_t dev)
128 {
129         device_t nb_dev = 0, sb_dev = 0;
130         int dev_ind;
131
132         printk(BIOS_INFO, "rs690_enable: dev=%p, VID_DID=0x%x\n", dev, get_vid_did(dev));
133
134         nb_dev = dev_find_slot(0, PCI_DEVFN(0, 0));
135         if (!nb_dev) {
136                 die("rs690_enable: CAN NOT FIND RS690 DEVICE, HALT!\n");
137                 /* NOT REACHED */
138         }
139
140         /* sb_dev (dev 8) is a bridge that links to southbridge. */
141         sb_dev = dev_find_slot(0, PCI_DEVFN(8, 0));
142         if (!sb_dev) {
143                 die("rs690_enable: CAN NOT FIND SB bridge, HALT!\n");
144                 /* NOT REACHED */
145         }
146
147         dev_ind = dev->path.pci.devfn >> 3;
148         switch (dev_ind) {
149         case 0:         /* bus0, dev0, fun0; */
150                 printk(BIOS_INFO, "Bus-0, Dev-0, Fun-0.\n");
151                 enable_pcie_bar3(nb_dev);       /* PCIEMiscInit */
152                 config_gpp_core(nb_dev, sb_dev);
153                 rs690_gpp_sb_init(nb_dev, sb_dev, 8);
154                 /* set SB payload size: 64byte */
155                 set_pcie_enable_bits(nb_dev, 0x10 | PCIE_CORE_INDEX_GPPSB, 3 << 11, 2 << 11);
156
157                 /* Bus0Dev0Fun1Clock control init, we have to do it here, for dev0 Fun1 doesn't have a vendor or device ID */
158                 rs690_config_misc_clk(nb_dev);
159                 break;
160
161         case 1:         /* bus0, dev1 */
162                 printk(BIOS_INFO, "Bus-0, Dev-1, Fun-0.\n");
163                 break;
164         case 2:         /* bus0, dev2,3, two GFX */
165         case 3:
166                 printk(BIOS_INFO, "Bus-0, Dev-2,3, Fun-0. enable=%d\n", dev->enabled);
167                 set_nbmisc_enable_bits(nb_dev, 0x0c, 1 << dev_ind,
168                                        (dev->enabled ? 0 : 1) << dev_ind);
169                 if (dev->enabled)
170                         rs690_gfx_init(nb_dev, dev, dev_ind);
171                 break;
172         case 4:         /* bus0, dev4-7, four GPP */
173         case 5:
174         case 6:
175         case 7:
176                 printk(BIOS_INFO, "Bus-0, Dev-4,5,6,7, Fun-0. enable=%d\n",
177                             dev->enabled);
178                 set_nbmisc_enable_bits(nb_dev, 0x0c, 1 << dev_ind,
179                                        (dev->enabled ? 0 : 1) << dev_ind);
180                 if (dev->enabled)
181                         rs690_gpp_sb_init(nb_dev, dev, dev_ind);
182                 break;
183         case 8:         /* bus0, dev8, SB */
184                 printk(BIOS_INFO, "Bus-0, Dev-8, Fun-0. enable=%d\n", dev->enabled);
185                 set_nbmisc_enable_bits(nb_dev, 0x00, 1 << 6,
186                                        (dev->enabled ? 1 : 0) << 6);
187                 if (dev->enabled)
188                         rs690_gpp_sb_init(nb_dev, dev, dev_ind);
189                 disable_pcie_bar3(nb_dev);
190                 break;
191         default:
192                 printk(BIOS_DEBUG, "unknown dev: %s\n", dev_path(dev));
193         }
194 }
195
196 struct chip_operations southbridge_amd_rs690_ops = {
197         CHIP_NAME("ATI RS690")
198         .enable_dev = rs690_enable,
199 };