blob: bc1e78111592c626f933c162cba3bf0139187d9d [file] [log] [blame]
Yinghai Lu968bbe82005-12-06 23:34:09 +00001/*
Uwe Hermann8af6d552010-10-17 19:13:18 +00002 * This file is part of the coreboot project.
3 *
Timothy Pearsone9162012015-01-23 20:29:46 -06004 * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering
5 *
Uwe Hermann8af6d552010-10-17 19:13:18 +00006 * Copyright (C) 2004 Tyan Computer
7 * Written by Yinghai Lu <yhlu@tyan.com> for Tyan Computer.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Yinghai Lu968bbe82005-12-06 23:34:09 +000017 */
Yinghai Lud4b278c2006-10-04 20:46:15 +000018
Kyösti Mälkki73627682019-03-02 20:16:23 +020019#include <arch/io.h>
Nico Huber718c6fa2018-10-11 22:54:25 +020020#include <southbridge/amd/common/reset.h>
Kyösti Mälkki413e3da2015-02-03 08:05:55 +020021#include "ck804.h"
22
Timothy Pearsone9162012015-01-23 20:29:46 -060023/* Someone messed up and snuck in some K8-specific code */
24static int set_ht_link_buffer_counts_chain(uint8_t ht_c_num, unsigned vendorid, unsigned val) { return 0; /* stub */};
Timothy Pearsone9162012015-01-23 20:29:46 -060025
Uwe Hermann7e2fbd52011-01-04 17:36:55 +000026static int set_ht_link_ck804(u8 ht_c_num)
Yinghai Lu968bbe82005-12-06 23:34:09 +000027{
Myles Watson64caf362008-09-18 16:27:00 +000028 unsigned vendorid = 0x10de;
29 unsigned val = 0x01610169;
30 return set_ht_link_buffer_counts_chain(ht_c_num, vendorid, val);
Yinghai Lu968bbe82005-12-06 23:34:09 +000031}
32
Uwe Hermann7f3d48c2008-10-02 18:19:17 +000033static void setup_ss_table(unsigned index, unsigned where, unsigned control,
34 const unsigned int *register_values, int max)
Yinghai Lu968bbe82005-12-06 23:34:09 +000035{
Myles Watson64caf362008-09-18 16:27:00 +000036 int i;
Yinghai Lu968bbe82005-12-06 23:34:09 +000037 unsigned val;
Uwe Hermann7f3d48c2008-10-02 18:19:17 +000038
Yinghai Lu968bbe82005-12-06 23:34:09 +000039 val = inl(control);
40 val &= 0xfffffffe;
Myles Watson64caf362008-09-18 16:27:00 +000041 outl(val, control);
Yinghai Lu968bbe82005-12-06 23:34:09 +000042
Myles Watson64caf362008-09-18 16:27:00 +000043 outl(0, index);
Yinghai Lu968bbe82005-12-06 23:34:09 +000044
Uwe Hermann7f3d48c2008-10-02 18:19:17 +000045 for (i = 0; i < max; i++) {
Myles Watson64caf362008-09-18 16:27:00 +000046 unsigned long reg;
Myles Watson64caf362008-09-18 16:27:00 +000047 reg = register_values[i];
48 outl(reg, where);
49 }
50 val = inl(control);
51 val |= 1;
52 outl(val, control);
Yinghai Lu968bbe82005-12-06 23:34:09 +000053}
54
55#define ANACTRL_IO_BASE 0x3000
56#define ANACTRL_REG_POS 0x68
57
Yinghai Lu968bbe82005-12-06 23:34:09 +000058#define SYSCTRL_IO_BASE 0x2000
59#define SYSCTRL_REG_POS 0x64
60
61/*
Jonathan Kollaschfae0d6c2010-11-21 22:55:46 +000062 * Values for CONFIG_CK804_PCI_E_X and CONFIG_CK804B_PCI_E_X.
63 * Apparently some sort of lane configuration.
64 *
Uwe Hermann7f3d48c2008-10-02 18:19:17 +000065 * 16 1 1 2 :0
66 * 8 8 2 2 :1
67 * 8 8 4 :2
68 * 8 4 4 4 :3
69 * 16 4 :4
Jonathan Kollaschfae0d6c2010-11-21 22:55:46 +000070 */
Yinghai Lu968bbe82005-12-06 23:34:09 +000071
Kyösti Mälkki43997b72019-01-05 14:34:55 +020072/* There will be implicit offsets applied, the writes below do not
73 * really happen at the PCI_ADDR() this expands to.
74 */
75#define CK804_DEV(d, f, r) PCI_ADDR(0, d, f, r)
76
Uwe Hermann7f3d48c2008-10-02 18:19:17 +000077static void ck804_early_set_port(unsigned ck804_num, unsigned *busn,
78 unsigned *io_base)
Yinghai Lu968bbe82005-12-06 23:34:09 +000079{
Myles Watson64caf362008-09-18 16:27:00 +000080 static const unsigned int ctrl_devport_conf[] = {
Kyösti Mälkki43997b72019-01-05 14:34:55 +020081 CK804_DEV(0x1, 0, ANACTRL_REG_POS), ~(0x0000ff00), ANACTRL_IO_BASE,
82 CK804_DEV(0x1, 0, SYSCTRL_REG_POS), ~(0x0000ff00), SYSCTRL_IO_BASE,
Myles Watson64caf362008-09-18 16:27:00 +000083 };
Yinghai Lu968bbe82005-12-06 23:34:09 +000084
Myles Watson64caf362008-09-18 16:27:00 +000085 int j;
Uwe Hermann7f3d48c2008-10-02 18:19:17 +000086 for (j = 0; j < ck804_num; j++) {
Myles Watson21ee98b2009-10-13 22:53:24 +000087 u32 dev;
Uwe Hermann7e2fbd52011-01-04 17:36:55 +000088 if (busn[j] == 0) /* SB chain */
Myles Watson21ee98b2009-10-13 22:53:24 +000089 dev = PCI_DEV(busn[j], CK804_DEVN_BASE, 0);
90 else
91 dev = PCI_DEV(busn[j], CK804B_DEVN_BASE, 0);
92 setup_resource_map_offset(ctrl_devport_conf,
Uwe Hermann7e2fbd52011-01-04 17:36:55 +000093 ARRAY_SIZE(ctrl_devport_conf), dev, io_base[j]);
Myles Watson64caf362008-09-18 16:27:00 +000094 }
Yinghai Lu968bbe82005-12-06 23:34:09 +000095}
96
Uwe Hermann7f3d48c2008-10-02 18:19:17 +000097static void ck804_early_clear_port(unsigned ck804_num, unsigned *busn,
98 unsigned *io_base)
Yinghai Lu968bbe82005-12-06 23:34:09 +000099{
Myles Watson64caf362008-09-18 16:27:00 +0000100 static const unsigned int ctrl_devport_conf_clear[] = {
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200101 CK804_DEV(0x1, 0, ANACTRL_REG_POS), ~(0x0000ff01), 0,
102 CK804_DEV(0x1, 0, SYSCTRL_REG_POS), ~(0x0000ff01), 0,
Myles Watson64caf362008-09-18 16:27:00 +0000103 };
Yinghai Lu968bbe82005-12-06 23:34:09 +0000104
Myles Watson64caf362008-09-18 16:27:00 +0000105 int j;
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000106 for (j = 0; j < ck804_num; j++) {
Myles Watson21ee98b2009-10-13 22:53:24 +0000107 u32 dev;
Uwe Hermann7e2fbd52011-01-04 17:36:55 +0000108 if (busn[j] == 0) /* SB chain */
Myles Watson21ee98b2009-10-13 22:53:24 +0000109 dev = PCI_DEV(busn[j], CK804_DEVN_BASE, 0);
110 else
111 dev = PCI_DEV(busn[j], CK804B_DEVN_BASE, 0);
112 setup_resource_map_offset(ctrl_devport_conf_clear,
Uwe Hermann7e2fbd52011-01-04 17:36:55 +0000113 ARRAY_SIZE(ctrl_devport_conf_clear), dev, io_base[j]);
Myles Watson64caf362008-09-18 16:27:00 +0000114 }
Yinghai Lu968bbe82005-12-06 23:34:09 +0000115}
116
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000117static void ck804_early_setup(unsigned ck804_num, unsigned *busn,
118 unsigned *io_base)
Yinghai Lu968bbe82005-12-06 23:34:09 +0000119{
Myles Watson64caf362008-09-18 16:27:00 +0000120 static const unsigned int ctrl_conf_master[] = {
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200121 RES_PCI_IO, CK804_DEV(1, 2, 0x8c), 0xffff0000, 0x00009880,
122 RES_PCI_IO, CK804_DEV(1, 2, 0x90), 0xffff000f, 0x000074a0,
123 RES_PCI_IO, CK804_DEV(1, 2, 0xa0), 0xfffff0ff, 0x00000a00,
124 RES_PCI_IO, CK804_DEV(1, 2, 0xac), 0xffffff00, 0x00000000,
Yinghai Lu968bbe82005-12-06 23:34:09 +0000125
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200126 RES_PCI_IO, CK804_DEV(0, 0, 0x48), 0xfffffffd, 0x00000002,
127 RES_PCI_IO, CK804_DEV(0, 0, 0x74), 0xfffff00f, 0x000009d0,
128 RES_PCI_IO, CK804_DEV(0, 0, 0x8c), 0xffff0000, 0x0000007f,
129 RES_PCI_IO, CK804_DEV(0, 0, 0xcc), 0xfffffff8, 0x00000003,
130 RES_PCI_IO, CK804_DEV(0, 0, 0xd0), 0xff000000, 0x00000000,
131 RES_PCI_IO, CK804_DEV(0, 0, 0xd4), 0xff000000, 0x00000000,
132 RES_PCI_IO, CK804_DEV(0, 0, 0xd8), 0xff000000, 0x00000000,
133 RES_PCI_IO, CK804_DEV(0, 0, 0xdc), 0x7f000000, 0x00000000,
Yinghai Lu968bbe82005-12-06 23:34:09 +0000134
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200135 RES_PCI_IO, CK804_DEV(1, 0, 0xf0), 0xfffffffd, 0x00000002,
136 RES_PCI_IO, CK804_DEV(1, 0, 0xf8), 0xffffffcf, 0x00000010,
Yinghai Lu968bbe82005-12-06 23:34:09 +0000137
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200138 RES_PCI_IO, CK804_DEV(9, 0, 0x40), 0xfff8ffff, 0x00030000,
139 RES_PCI_IO, CK804_DEV(9, 0, 0x4c), 0xfe00ffff, 0x00440000,
140 RES_PCI_IO, CK804_DEV(9, 0, 0x74), 0xffffffc0, 0x00000000,
Yinghai Lu968bbe82005-12-06 23:34:09 +0000141
142#ifdef CK804_MB_SETUP
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000143 CK804_MB_SETUP
Yinghai Lu968bbe82005-12-06 23:34:09 +0000144#endif
Yinghai Lu968bbe82005-12-06 23:34:09 +0000145
Kyösti Mälkkid840eb52018-05-24 00:34:15 +0300146#if IS_ENABLED(CONFIG_NORTHBRIDGE_AMD_AMDFAM10)
Jonathan A. Kollaschacba73a2015-07-20 09:51:34 -0500147 /*
148 * Avoid crash (complete with severe memory corruption!) during initial CAR boot
149 * in ck804_early_setup_x() on Fam10h systems by not touching 0x78.
150 * Interestingly once the system is fully booted into Linux this can be set, but
151 * not before! Apparently something isn't initialized but the amount of effort
152 * required to fix this is non-negligible and of unknown real-world benefit
153 */
154#else
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200155 RES_PCI_IO, CK804_DEV(1, 0, 0x78), 0xc0ffffff, 0x19000000,
Timothy Pearsone1cc3ab2015-01-24 13:46:46 -0600156#endif
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200157 RES_PCI_IO, CK804_DEV(1, 0, 0xe0), 0xfffffeff, 0x00000100,
Yinghai Lu968bbe82005-12-06 23:34:09 +0000158
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000159 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x20, 0xe00fffff, 0x11000000,
160 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x24, 0xc3f0ffff, 0x24040000,
161 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x80, 0x8c3f04df, 0x51407120,
162 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x84, 0xffffff8f, 0x00000010,
163 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x94, 0xff00ffff, 0x00c00000,
164 RES_PORT_IO_32, ANACTRL_IO_BASE + 0xcc, 0xf7ffffff, 0x00000000,
Myles Watson64caf362008-09-18 16:27:00 +0000165
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000166 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x74, ~(0xffff), 0x0f008,
167 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x78, ~((0xff) | (0xff << 16)), (0x41 << 16) | (0x32),
168 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x7c, ~(0xff << 16), (0xa0 << 16),
Yinghai Lu968bbe82005-12-06 23:34:09 +0000169
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000170 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x24, 0xfcffff0f, 0x020000b0,
Yinghai Lu968bbe82005-12-06 23:34:09 +0000171
Uwe Hermann7e2fbd52011-01-04 17:36:55 +0000172 /* Activate master port on primary SATA controller. */
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200173 RES_PCI_IO, CK804_DEV(7, 0, 0x50), ~(0x1f000013), 0x15000013,
174 RES_PCI_IO, CK804_DEV(7, 0, 0x64), ~(0x00000001), 0x00000001,
175 RES_PCI_IO, CK804_DEV(7, 0, 0x68), ~(0x02000000), 0x02000000,
176 RES_PCI_IO, CK804_DEV(7, 0, 0x70), ~(0x000f0000), 0x00040000,
177 RES_PCI_IO, CK804_DEV(7, 0, 0xa0), ~(0x000001ff), 0x00000150,
178 RES_PCI_IO, CK804_DEV(7, 0, 0xac), ~(0xffff8f00), 0x02aa8b00,
179 RES_PCI_IO, CK804_DEV(7, 0, 0x7c), ~(0x00000010), 0x00000000,
180 RES_PCI_IO, CK804_DEV(7, 0, 0xc8), ~(0x0fff0fff), 0x000a000a,
181 RES_PCI_IO, CK804_DEV(7, 0, 0xd0), ~(0xf0000000), 0x00000000,
182 RES_PCI_IO, CK804_DEV(7, 0, 0xe0), ~(0xf0000000), 0x00000000,
Myles Watsonb0575d82009-10-14 02:38:24 +0000183
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200184 RES_PCI_IO, CK804_DEV(8, 0, 0x50), ~(0x1f000013), 0x15000013,
185 RES_PCI_IO, CK804_DEV(8, 0, 0x64), ~(0x00000001), 0x00000001,
186 RES_PCI_IO, CK804_DEV(8, 0, 0x68), ~(0x02000000), 0x02000000,
187 RES_PCI_IO, CK804_DEV(8, 0, 0x70), ~(0x000f0000), 0x00040000,
188 RES_PCI_IO, CK804_DEV(8, 0, 0xa0), ~(0x000001ff), 0x00000150,
189 RES_PCI_IO, CK804_DEV(8, 0, 0xac), ~(0xffff8f00), 0x02aa8b00,
190 RES_PCI_IO, CK804_DEV(8, 0, 0x7c), ~(0x00000010), 0x00000000,
191 RES_PCI_IO, CK804_DEV(8, 0, 0xc8), ~(0x0fff0fff), 0x000a000a,
192 RES_PCI_IO, CK804_DEV(8, 0, 0xd0), ~(0xf0000000), 0x00000000,
193 RES_PCI_IO, CK804_DEV(8, 0, 0xe0), ~(0xf0000000), 0x00000000,
Yinghai Lu968bbe82005-12-06 23:34:09 +0000194
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000195 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x04, ~((0x3ff << 0) | (0x3ff << 10)), (0x21 << 0) | (0x22 << 10),
Yinghai Lu968bbe82005-12-06 23:34:09 +0000196
Myles Watsonb0575d82009-10-14 02:38:24 +0000197 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x08, ~(0xfffff), (0x1c << 10) | 0x1b,
Yinghai Lu968bbe82005-12-06 23:34:09 +0000198
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000199 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x80, ~(1 << 3), 0x00000000,
Yinghai Lu968bbe82005-12-06 23:34:09 +0000200
Jonathan Kollaschfae0d6c2010-11-21 22:55:46 +0000201 RES_PORT_IO_32, ANACTRL_IO_BASE + 0xcc, ~((7 << 4) | (1 << 8)), (CONFIG_CK804_PCI_E_X << 4) | (1 << 8),
Yinghai Lu968bbe82005-12-06 23:34:09 +0000202
Uwe Hermann7e2fbd52011-01-04 17:36:55 +0000203 /* SYSCTRL */
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000204 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0 + 8, ~(0xff), ((0 << 4) | (0 << 2) | (0 << 0)),
205 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0 + 9, ~(0xff), ((0 << 4) | (1 << 2) | (1 << 0)),
Martin Roth1858d6a2017-06-24 21:30:42 -0600206#if IS_ENABLED(CONFIG_CK804_USE_NIC)
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200207 RES_PCI_IO, CK804_DEV(0xa, 0, 0xf8), 0xffffffbf, 0x00000040,
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000208 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0 + 19, ~(0xff), ((0 << 4) | (1 << 2) | (0 << 0)),
209 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0 + 3, ~(0xff), ((0 << 4) | (1 << 2) | (0 << 0)),
210 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0 + 3, ~(0xff), ((0 << 4) | (1 << 2) | (1 << 0)),
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200211 RES_PCI_IO, CK804_DEV(1, 0, 0xe4), ~(1 << 23), (1 << 23),
Yinghai Lu968bbe82005-12-06 23:34:09 +0000212#endif
213
Martin Roth1858d6a2017-06-24 21:30:42 -0600214#if IS_ENABLED(CONFIG_CK804_USE_ACI)
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000215 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0 + 0x0d, ~(0xff), ((0 << 4) | (2 << 2) | (0 << 0)),
216 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0 + 0x1a, ~(0xff), ((0 << 4) | (2 << 2) | (0 << 0)),
Yinghai Lu968bbe82005-12-06 23:34:09 +0000217#endif
Timothy Pearson02112bd2015-01-26 02:15:57 -0600218
219#if IS_ENABLED(CONFIG_CK804_PCIE_PME_WAKE)
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200220 RES_PCI_IO, CK804_DEV(1, 0, 0xe4), 0xffffffff, 0x00400000,
Timothy Pearson02112bd2015-01-26 02:15:57 -0600221#else
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200222 RES_PCI_IO, CK804_DEV(1, 0, 0xe4), 0xffbfffff, 0x00000000,
Timothy Pearson02112bd2015-01-26 02:15:57 -0600223#endif
Myles Watson83768312010-07-06 20:36:36 +0000224 };
225
226 static const unsigned int ctrl_conf_multiple[] = {
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000227 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0 + 0, ~(3 << 2), (0 << 2),
Myles Watson64caf362008-09-18 16:27:00 +0000228 };
Yinghai Lu968bbe82005-12-06 23:34:09 +0000229
Myles Watson64caf362008-09-18 16:27:00 +0000230 static const unsigned int ctrl_conf_slave[] = {
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200231 RES_PCI_IO, CK804_DEV(1, 2, 0x8c), 0xffff0000, 0x00009880,
232 RES_PCI_IO, CK804_DEV(1, 2, 0x90), 0xffff000f, 0x000074a0,
233 RES_PCI_IO, CK804_DEV(1, 2, 0xa0), 0xfffff0ff, 0x00000a00,
Yinghai Lu968bbe82005-12-06 23:34:09 +0000234
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200235 RES_PCI_IO, CK804_DEV(0, 0, 0x48), 0xfffffffd, 0x00000002,
236 RES_PCI_IO, CK804_DEV(0, 0, 0x74), 0xfffff00f, 0x000009d0,
237 RES_PCI_IO, CK804_DEV(0, 0, 0x8c), 0xffff0000, 0x0000007f,
238 RES_PCI_IO, CK804_DEV(0, 0, 0xcc), 0xfffffff8, 0x00000003,
239 RES_PCI_IO, CK804_DEV(0, 0, 0xd0), 0xff000000, 0x00000000,
240 RES_PCI_IO, CK804_DEV(0, 0, 0xd4), 0xff000000, 0x00000000,
241 RES_PCI_IO, CK804_DEV(0, 0, 0xd8), 0xff000000, 0x00000000,
242 RES_PCI_IO, CK804_DEV(0, 0, 0xdc), 0x7f000000, 0x00000000,
Yinghai Lu968bbe82005-12-06 23:34:09 +0000243
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200244 RES_PCI_IO, CK804_DEV(1, 0, 0xf0), 0xfffffffd, 0x00000002,
245 RES_PCI_IO, CK804_DEV(1, 0, 0xf8), 0xffffffcf, 0x00000010,
Yinghai Lu968bbe82005-12-06 23:34:09 +0000246
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200247 RES_PCI_IO, CK804_DEV(9, 0, 0x40), 0xfff8ffff, 0x00030000,
248 RES_PCI_IO, CK804_DEV(9, 0, 0x4c), 0xfe00ffff, 0x00440000,
249 RES_PCI_IO, CK804_DEV(9, 0, 0x74), 0xffffffc0, 0x00000000,
Yinghai Lu968bbe82005-12-06 23:34:09 +0000250
Jonathan A. Kollaschacba73a2015-07-20 09:51:34 -0500251 /*
252 * Avoid touching 0x78 for CONFIG_NORTHBRIDGE_AMD_AMDFAM10 for
253 * non-primary chains too???
254 */
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200255 RES_PCI_IO, CK804_DEV(1, 0, 0x78), 0xc0ffffff, 0x20000000,
256 RES_PCI_IO, CK804_DEV(1, 0, 0xe0), 0xfffffeff, 0x00000000,
257 RES_PCI_IO, CK804_DEV(1, 0, 0xe8), 0xffffff00, 0x000000ff,
Yinghai Lu968bbe82005-12-06 23:34:09 +0000258
Myles Watson21ee98b2009-10-13 22:53:24 +0000259 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x20, 0xe00fffff, 0x11000000,
260 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x24, 0xc3f0ffff, 0x24040000,
261 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x80, 0x8c3f04df, 0x51407120,
262 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x84, 0xffffff8f, 0x00000010,
263 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x94, 0xff00ffff, 0x00c00000,
264 RES_PORT_IO_32, ANACTRL_IO_BASE + 0xcc, 0xf7ffffff, 0x00000000,
Yinghai Lu968bbe82005-12-06 23:34:09 +0000265
Myles Watson21ee98b2009-10-13 22:53:24 +0000266 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x24, 0xfcffff0f, 0x020000b0,
Yinghai Lu968bbe82005-12-06 23:34:09 +0000267
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200268 RES_PCI_IO, CK804_DEV(8, 0, 0x50), ~(0x1f000013), 0x15000013,
269 RES_PCI_IO, CK804_DEV(8, 0, 0x64), ~(0x00000001), 0x00000001,
270 RES_PCI_IO, CK804_DEV(8, 0, 0x68), ~(0x02000000), 0x02000000,
271 RES_PCI_IO, CK804_DEV(8, 0, 0x70), ~(0x000f0000), 0x00040000,
272 RES_PCI_IO, CK804_DEV(8, 0, 0xa0), ~(0x000001ff), 0x00000150,
273 RES_PCI_IO, CK804_DEV(8, 0, 0xac), ~(0xffff8f00), 0x02aa8b00,
274 RES_PCI_IO, CK804_DEV(8, 0, 0x7c), ~(0x00000010), 0x00000000,
275 RES_PCI_IO, CK804_DEV(8, 0, 0xc8), ~(0x0fff0fff), 0x000a000a,
276 RES_PCI_IO, CK804_DEV(8, 0, 0xd0), ~(0xf0000000), 0x00000000,
277 RES_PCI_IO, CK804_DEV(8, 0, 0xe0), ~(0xf0000000), 0x00000000,
Yinghai Lu968bbe82005-12-06 23:34:09 +0000278
Myles Watson21ee98b2009-10-13 22:53:24 +0000279 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x04, ~((0x3ff << 0) | (0x3ff << 10)), (0x21 << 0) | (0x22 << 10),
Yinghai Lu968bbe82005-12-06 23:34:09 +0000280
Myles Watsonb0575d82009-10-14 02:38:24 +0000281 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x08, ~(0xfffff), (0x1c << 10) | 0x1b,
Yinghai Lu968bbe82005-12-06 23:34:09 +0000282
Uwe Hermann7e2fbd52011-01-04 17:36:55 +0000283 /* This line doesn't exist in the non-CAR version. */
Myles Watson21ee98b2009-10-13 22:53:24 +0000284 RES_PORT_IO_32, ANACTRL_IO_BASE + 0x80, ~(1 << 3), 0x00000000,
Yinghai Lu968bbe82005-12-06 23:34:09 +0000285
Jonathan Kollaschfae0d6c2010-11-21 22:55:46 +0000286 RES_PORT_IO_32, ANACTRL_IO_BASE + 0xcc, ~((7 << 4) | (1 << 8)), (CONFIG_CK804B_PCI_E_X << 4) | (1 << 8),
Yinghai Lu968bbe82005-12-06 23:34:09 +0000287
Martin Roth1858d6a2017-06-24 21:30:42 -0600288#if IS_ENABLED(CONFIG_CK804_USE_NIC)
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200289 RES_PCI_IO, CK804_DEV(0xa, 0, 0xf8), 0xffffffbf, 0x00000040,
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000290 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0 + 19, ~(0xff), ((0 << 4) | (1 << 2) | (0 << 0)),
291 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0 + 3, ~(0xff), ((0 << 4) | (1 << 2) | (0 << 0)),
292 RES_PORT_IO_8, SYSCTRL_IO_BASE + 0xc0 + 3, ~(0xff), ((0 << 4) | (1 << 2) | (1 << 0)),
Kyösti Mälkki43997b72019-01-05 14:34:55 +0200293 RES_PCI_IO, CK804_DEV(1, 0, 0xe4), ~(1 << 23), (1 << 23),
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000294#endif
Myles Watson64caf362008-09-18 16:27:00 +0000295 };
Yinghai Lu968bbe82005-12-06 23:34:09 +0000296
Myles Watson64caf362008-09-18 16:27:00 +0000297 int j;
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000298 for (j = 0; j < ck804_num; j++) {
299 if (busn[j] == 0) {
300 setup_resource_map_x_offset(ctrl_conf_master,
301 ARRAY_SIZE(ctrl_conf_master),
Myles Watson83768312010-07-06 20:36:36 +0000302 PCI_DEV(0, CK804_DEVN_BASE, 0), io_base[0]);
303 if (ck804_num > 1)
304 setup_resource_map_x_offset(ctrl_conf_multiple,
305 ARRAY_SIZE(ctrl_conf_multiple),
306 PCI_DEV(0, CK804_DEVN_BASE, 0), 0);
307
Myles Watson64caf362008-09-18 16:27:00 +0000308 continue;
309 }
Yinghai Lu968bbe82005-12-06 23:34:09 +0000310
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000311 setup_resource_map_x_offset(ctrl_conf_slave,
Uwe Hermann7e2fbd52011-01-04 17:36:55 +0000312 ARRAY_SIZE(ctrl_conf_slave),
313 PCI_DEV(busn[j], CK804B_DEVN_BASE, 0), io_base[j]);
Myles Watson64caf362008-09-18 16:27:00 +0000314 }
Yinghai Lu968bbe82005-12-06 23:34:09 +0000315
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000316 for (j = 0; j < ck804_num; j++) {
317 /* PCI-E (XSPLL) SS table 0x40, x044, 0x48 */
318 /* SATA (SPPLL) SS table 0xb0, 0xb4, 0xb8 */
319 /* CPU (PPLL) SS table 0xc0, 0xc4, 0xc8 */
320 setup_ss_table(io_base[j] + ANACTRL_IO_BASE + 0x40,
321 io_base[j] + ANACTRL_IO_BASE + 0x44,
322 io_base[j] + ANACTRL_IO_BASE + 0x48,
323 pcie_ss_tbl, 64);
324 setup_ss_table(io_base[j] + ANACTRL_IO_BASE + 0xb0,
325 io_base[j] + ANACTRL_IO_BASE + 0xb4,
326 io_base[j] + ANACTRL_IO_BASE + 0xb8,
327 sata_ss_tbl, 64);
Myles Watsonb0575d82009-10-14 02:38:24 +0000328 setup_ss_table(io_base[j] + ANACTRL_IO_BASE + 0xc0,
329 io_base[j] + ANACTRL_IO_BASE + 0xc4,
330 io_base[j] + ANACTRL_IO_BASE + 0xc8,
331 cpu_ss_tbl, 64);
Myles Watson64caf362008-09-18 16:27:00 +0000332 }
Yinghai Lu968bbe82005-12-06 23:34:09 +0000333}
334
335static int ck804_early_setup_x(void)
336{
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000337 unsigned busn[4], io_base[4];
338 int i, ck804_num = 0;
Yinghai Lu968bbe82005-12-06 23:34:09 +0000339
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000340 for (i = 0; i < 4; i++) {
Uwe Hermann7e2fbd52011-01-04 17:36:55 +0000341 u32 id;
Antonello Dettori10505472016-09-03 10:45:33 +0200342 pci_devfn_t dev;
Uwe Hermann7e2fbd52011-01-04 17:36:55 +0000343 if (i == 0) /* SB chain */
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000344 dev = PCI_DEV(i * 0x40, CK804_DEVN_BASE, 0);
345 else
346 dev = PCI_DEV(i * 0x40, CK804B_DEVN_BASE, 0);
Yinghai Lu968bbe82005-12-06 23:34:09 +0000347 id = pci_read_config32(dev, PCI_VENDOR_ID);
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000348 if (id == 0x005e10de) {
Yinghai Lu968bbe82005-12-06 23:34:09 +0000349 busn[ck804_num] = i * 0x40;
350 io_base[ck804_num] = i * 0x4000;
Myles Watson64caf362008-09-18 16:27:00 +0000351 ck804_num++;
Yinghai Lu968bbe82005-12-06 23:34:09 +0000352 }
353 }
Myles Watson64caf362008-09-18 16:27:00 +0000354
Timothy Pearsoncdc526e2015-10-28 02:58:37 -0500355 printk(BIOS_DEBUG, "ck804_early_set_port(%d, %d, %d)\n", ck804_num, busn[0], io_base[0]);
Yinghai Lu968bbe82005-12-06 23:34:09 +0000356 ck804_early_set_port(ck804_num, busn, io_base);
Timothy Pearsoncdc526e2015-10-28 02:58:37 -0500357 printk(BIOS_DEBUG, "ck804_early_setup(%d, %d, %d)\n", ck804_num, busn[0], io_base[0]);
Yinghai Lu968bbe82005-12-06 23:34:09 +0000358 ck804_early_setup(ck804_num, busn, io_base);
Timothy Pearsoncdc526e2015-10-28 02:58:37 -0500359 printk(BIOS_DEBUG, "ck804_early_clear_port(%d, %d, %d)\n", ck804_num, busn[0], io_base[0]);
Yinghai Lu968bbe82005-12-06 23:34:09 +0000360 ck804_early_clear_port(ck804_num, busn, io_base);
Uwe Hermann7f3d48c2008-10-02 18:19:17 +0000361
Yinghai Lu968bbe82005-12-06 23:34:09 +0000362 return set_ht_link_ck804(4);
363}
Yinghai Lu9a791df2006-04-03 20:38:34 +0000364
Nico Hubere20dd192018-10-07 12:12:27 +0200365void do_board_reset(void)
Yinghai Lu9a791df2006-04-03 20:38:34 +0000366{
Myles Watson64caf362008-09-18 16:27:00 +0000367 set_bios_reset();
Yinghai Lu9a791df2006-04-03 20:38:34 +0000368
Myles Watson64caf362008-09-18 16:27:00 +0000369 /* full reset */
370 outb(0x0a, 0x0cf9);
371 outb(0x0e, 0x0cf9);
Yinghai Lu9a791df2006-04-03 20:38:34 +0000372}
373
Julius Werner01f9aa52017-05-18 16:03:26 -0700374void do_soft_reset(void)
Yinghai Lu9a791df2006-04-03 20:38:34 +0000375{
Myles Watson64caf362008-09-18 16:27:00 +0000376 set_bios_reset();
377
378 /* link reset */
379 outb(0x02, 0x0cf9);
380 outb(0x06, 0x0cf9);
Yinghai Lu9a791df2006-04-03 20:38:34 +0000381}
Timothy Pearson56699942015-10-28 14:41:42 -0500382
383void enable_fid_change_on_sb(unsigned sbbusn, unsigned sbdn)
384{
Elyes HAOUASba28e8d2016-08-31 19:22:16 +0200385 /* The default value for CK804 is good. */
386 /* Set VFSMAF (VID/FID System Management Action Field) to 2. */
Martin Rothbb9722b2016-07-28 16:32:56 -0600387}