summaryrefslogtreecommitdiffstats
path: root/src/mainboard/iwave/iWRainbowG6/romstage.c
blob: 83ae65743058a6b1007bf57b1d35d68ff7f7e53f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/*
 * This file is part of the coreboot project.
 *
 * Copyright (C) 2009-2010 iWave Systems
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include <stdint.h>
#include <string.h>
#include <arch/io.h>
#include <arch/romcc_io.h>
#include <device/pci_def.h>
#include <device/pnp_def.h>
#include <cpu/x86/lapic.h>
#include <cpu/x86/cache.h>
#include <arch/cpu.h>
#include <console/console.h>
#if 0
#include "ram/ramtest.c"
#include "southbridge/intel/sch/early_smbus.c"
#endif

#define RFID_TEST 0

#if RFID_TEST
#define RFID_ADDR 0xA0
#define RFID_SELECT_CARD_COMMAND 0x01
#define SELECT_COMMAND_LENGTH 0x01

#define SMBUS_BASE_ADDRESS 0x400

static u32 sch_SMbase_read(void)
{
	u32 SMBusBase;

	/* SMBus address */
	SMBusBase = pci_read_config32(PCI_DEV(0, 0x1f, 0), 0x40);
	SMBusBase &= 0xFFFF;
	printk(BIOS_DEBUG, "SMBus base = %x\r\n", SMBusBase);
	return SMBusBase;
}

static void sch_SMbase_init(void)
{
	u32 SMBusBase;

	SMBusBase = sch_SMbase_read();
	outb(0x3F, SMBusBase + SMBCLKDIV);
}

static void sch_SMbus_regs(void)
{
	u32 SMBusBase;

	SMBusBase = sch_SMbase_read();
	printk(BIOS_DEBUG, "SMBHSTCNT. =%x\r\n", inb(SMBusBase + SMBHSTCNT));
	printk(BIOS_DEBUG, "SMBHSTSTS. =%x\r\n", inb(SMBusBase + SMBHSTSTS));
	printk(BIOS_DEBUG, "SMBCLKDIV. =%x\r\n", inb(SMBusBase + SMBCLKDIV));

	printk(BIOS_DEBUG, "SMBHSTADD. =%x\r\n", inb(SMBusBase + SMBHSTADD));
	printk(BIOS_DEBUG, "SMBHSTCMD. =%x\r\n", inb(SMBusBase + SMBHSTCMD));
}

void smb_clear(void)
{
	u32 SMBusBase;

	SMBusBase = sch_SMbase_read();
	outb(0x00, SMBusBase + SMBHSTCNT);
	outb(0x07, SMBusBase + SMBHSTSTS);
}

void data_clear(void)
{
	u32 SMBusBase;

	SMBusBase = sch_SMbase_read();
	outb(0x00, SMBusBase + SMBHSTDAT0);
	outb(0x00, SMBusBase + SMBHSTCMD);
	outb(0x00, SMBusBase + SMBHSTDAT1);
	outb(0x00, SMBusBase + SMBHSTDATB);
	outb(0x00, SMBusBase + (SMBHSTDATB + 0x1));
	outb(0x00, SMBusBase + (SMBHSTDATB + 0x2));
	outb(0x00, SMBusBase + (SMBHSTDATB + 0x3));
	outb(0x00, SMBusBase + (SMBHSTDATB + 0x4));
	outb(0x00, SMBusBase + (SMBHSTDATB + 0x5));
	outb(0x00, SMBusBase + (SMBHSTDATB + 0x6));
}

void transaction1(unsigned char dev_addr)
{
	int temp, a;
	u32 SMBusBase;

	SMBusBase = sch_SMbase_read();
	printk(BIOS_DEBUG, "Transaction 1");
	//clear the control and status registers
	smb_clear();
	//clear the data register
	data_clear();
	//program TSA register
	outb(dev_addr, SMBusBase + SMBHSTADD);
	//program command register
	outb(0x04, SMBusBase + SMBHSTCMD);
	//write data register
	outb(0x04, SMBusBase + SMBHSTDAT0);
	outb(0x04, SMBusBase + SMBHSTDATB);

	outb(0x09, SMBusBase + (SMBHSTDATB + 0x1));
	outb(0x11, SMBusBase + (SMBHSTDATB + 0x2));
	outb(0x22, SMBusBase + (SMBHSTDATB + 0x3));

	//set the control register
	outb(0x15, SMBusBase + SMBHSTCNT);
	//check the status register for busy state
	//sch_SMbus_regs ();
	temp = inb(SMBusBase + SMBHSTSTS);
	//printk(BIOS_DEBUG, "SMBus Busy.. status =%x\r\n",temp);
	//printk(BIOS_DEBUG, "SMBHSTSTS. =%x\r\n",inb(SMBusBase+SMBHSTSTS));
	do {
		temp = inb(SMBusBase + SMBHSTSTS);
		printk(BIOS_DEBUG, "SMBus Busy.. status =%x\r\n", temp);
		//sch_SMbus_regs ();
		printk(BIOS_DEBUG, "SMBHSTSTS. =%x\r\n",
		       inb(SMBusBase + SMBHSTSTS));
		if (temp > 0)
			break;
	} while (1);

	switch (temp) {
	case 1:
		printk(BIOS_DEBUG, "SMBus Success");
		break;
	default:
		printk(BIOS_DEBUG, "SMBus error %d", temp);
		break;

	}
	sch_SMbus_regs();
	printk(BIOS_DEBUG, "Command in TRansaction 1=%x\r\n\n",
	       inb(SMBusBase + SMBHSTCMD));
}

void transaction2(unsigned char dev_addr)
{
	int temp, a;
	u32 SMBusBase;

	SMBusBase = sch_SMbase_read();
	printk(BIOS_DEBUG, "Transaction 2");
	//clear the control and status registers
	smb_clear();
	//clear the data register
	data_clear();
	//program TSA register
	outb(dev_addr, SMBusBase + SMBHSTADD);
	//program command register
	outb(0x03, SMBusBase + SMBHSTCMD);
	//write data register
	outb(0x02, SMBusBase + SMBHSTDAT0);
	outb(0x03, SMBusBase + SMBHSTDATB);
	outb(0x09, SMBusBase + (SMBHSTDATB + 0x1));
	outb(0x15, SMBusBase + SMBHSTCNT);
	//check the status register for busy state
	//sch_SMbus_regs ();
	temp = inb(SMBusBase + SMBHSTSTS);
	//printk(BIOS_DEBUG, "SMBus Busy.. status =%x\r\n",temp);
	//printk(BIOS_DEBUG, "SMBHSTSTS. =%x\r\n",inb(SMBusBase+SMBHSTSTS));
	do {
		temp = inb(SMBusBase + SMBHSTSTS);
		printk(BIOS_DEBUG, "SMBus Busy.. status =%x\r\n", temp);
		//sch_SMbus_regs ();
		printk(BIOS_DEBUG, "SMBHSTSTS. =%x\r\n",
		       inb(SMBusBase + SMBHSTSTS));
		if (temp > 0)
			break;
	} while (1);

	switch (temp) {
	case 1:
		printk(BIOS_DEBUG, "SMBus Success");
		break;
	default:
		printk(BIOS_DEBUG, "SMBus error %d", temp);
		break;

	}
	sch_SMbus_regs();

	printk(BIOS_DEBUG, "Command in TRansaction 2=%x\r\n\n",
	       inb(SMBusBase + SMBHSTCMD));
}

void transaction3(unsigned char dev_addr)
{
	int temp, index, length;
	u32 SMBusBase;

	SMBusBase = sch_SMbase_read();
	printk(BIOS_DEBUG, "smb_read_multiple_bytes");
	smb_clear();
	data_clear();
	outb(dev_addr, SMBusBase + SMBHSTADD);
	outb(0x03, SMBusBase + SMBHSTCMD);
	outb(0x11, SMBusBase + SMBHSTCNT);

	//data_clear();
	outb(dev_addr + 1, SMBusBase + SMBHSTADD);

	outb(0x15, SMBusBase + SMBHSTCNT);

	// sch_SMbus_regs ();
	//check the status register for busy state
	//temp=inb(SMBusBase+SMBHSTSTS);
	//printk(BIOS_DEBUG, "SMBus Busy.. status =%x\r\n",temp);
	//sch_SMbus_regs ();
	//printk(BIOS_DEBUG, "SMBHSTSTS. =%x\r\n",inb(SMBusBase+SMBHSTSTS));
	do {
		temp = inb(SMBusBase + SMBHSTSTS);
		printk(BIOS_DEBUG, "SMBHSTSTS. =%x\r\n",
		       inb(SMBusBase + SMBHSTSTS));
		//sch_SMbus_regs ();
		if (temp > 0)
			break;
	} while (1);

	switch (temp) {
	case 1:
		printk(BIOS_DEBUG, "SMBus Success\n");
		break;
	default:
		printk(BIOS_DEBUG, "SMBus error %d", temp);
		break;

	}

	sch_SMbus_regs();
	printk(BIOS_DEBUG, "ADDRESS is.. %x\r\n", inb(SMBusBase + SMBHSTADD));
	length = inb(SMBusBase + SMBHSTDAT0);

	printk(BIOS_DEBUG, "Length is.. %x\r\n", inb(SMBusBase + SMBHSTDAT0));

	printk(BIOS_DEBUG, "Command is... %x\r\n", inb(SMBusBase + SMBHSTDATB));
	printk(BIOS_DEBUG, "Status .. %x\r\n", inb(SMBusBase + SMBHSTDATB + 1));
	for (index = 0; index < length; index++)
		printk(BIOS_DEBUG, "Serial Byte[%x]..%x\r\n", index,
		       inb(SMBusBase + SMBHSTDATB + index));
}

int selectcard(void)
{
	int i;

	printk(BIOS_DEBUG, "%s", "\r\nCase 9....... \n\r");
	// send the length byte and command code through RFID interface

	transaction1(RFID_ADDR);
	transaction2(RFID_ADDR);
	transaction3(RFID_ADDR);
	return (1);
}
#endif

#include "northbridge/intel/sch/early_init.c"
#include "northbridge/intel/sch/raminit.h"
#include "northbridge/intel/sch/raminit.c"

static void sch_enable_lpc(void)
{
	/* Initialize the FWH decode/Enable registers according to platform design */
	pci_write_config32(PCI_DEV(0, 0x1f, 0), 0xD0, 0x00112233);
	pci_write_config32(PCI_DEV(0, 0x1f, 0), 0xD4, 0xC0000000);
	pci_write_config32(PCI_DEV(0, 0x1f, 0), 0x60, 0x808A8B8B);
	pci_write_config32(PCI_DEV(0, 0x1f, 0), 0x64, 0x8F898F89);
}

static void sch_shadow_CMC(void)
{
	u32 reg32;

	/* FIXME: proper dest, proper src, and wbinvd, too */
	memcpy((void *)CMC_SHADOW, (void *)0xfffd0000, 64 * 1024);
	// __asm__ volatile ("wbinvd \n"
	//);
	printk(BIOS_DEBUG, "copy done ");
	memcpy((void *)0x3f5f0000, (void *)0x3faf0000, 64 * 1024);
	printk(BIOS_DEBUG, "copy 2 done ");
	reg32 = cpuid_eax(0x00000001);
	printk(BIOS_INFO, "CPU ID: %d.\n", reg32);

	reg32 = cpuid_eax(0x80000008);
	printk(BIOS_INFO, "Physical Address size: %d.\n", (reg32 & 0xFF));
	printk(BIOS_INFO, "Virtual Address size: %d.\n",
	       ((reg32 & 0xFF00) >> 8));
	sch_port_access_write_ram_cmd(0xB8, 4, 0, 0x3faf0000);
	printk(BIOS_DEBUG, "1 ");
	sch_port_access_write_ram_cmd(0xBA, 4, 0, reg32);
	printk(BIOS_DEBUG, "2 ");
}

static void poulsbo_setup_Stage1Regs(void)
{
	u32 reg32;

	printk(BIOS_DEBUG, "E000/F000 Routing ");
	reg32 = sch_port_access_read(2, 3, 4);
	sch_port_access_write(2, 3, 4, (reg32 | 0x6));
}

static void poulsbo_setup_Stage2Regs(void)
{
	u16 reg16;

	printk(BIOS_DEBUG, "Reserved");
	reg16 = pci_read_config16(PCI_DEV(0, 0x2, 0), 0x62);
	pci_write_config16(PCI_DEV(0, 0x2, 0), 0x62, (reg16 | 0x3));
	/* Slot capabilities */
	pci_write_config32(PCI_DEV(0, 28, 0), 0x54, 0x80500);
	pci_write_config32(PCI_DEV(0, 28, 1), 0x54, 0x100500);
	/* FIXME: CPU ID identification */
	printk(BIOS_DEBUG, " done.\n");
}

void main(unsigned long bist)
{
	int boot_mode = 0;

	if (bist == 0)
		enable_lapic();

	sch_enable_lpc();
	console_init();

	/* Halt if there was a built in self test failure */
	// report_bist_failure(bist);
	// outl (0x00, 0x1088);

	/*
	 * Perform some early chipset initialization required
	 * before RAM initialization can work.
	 */
	sch_early_initialization();
	sdram_initialize(boot_mode);

	sch_shadow_CMC();
	poulsbo_setup_Stage1Regs();
	poulsbo_setup_Stage2Regs();
#if 0
	sch_SMbase_init();

	/* Perform some initialization that must run before stage2. */
#endif

	/*
	 * This should probably go away. Until now it is required
	 * and mainboard specific.
	 */

	/* Chipset Errata! */
	pci_write_config16(PCI_DEV(0, 0x2, 0), GGC, 0x20);
	pci_write_config32(PCI_DEV(0, 0x2, 0), 0xc4, 0x00000002);
	pci_write_config32(PCI_DEV(0, 0x2, 0), 0xe0, 0x00008000);
	pci_write_config32(PCI_DEV(0, 0x2, 0), 0xf0, 0x00000005);
	pci_write_config16(PCI_DEV(0, 0x2, 0), 0xf7, 0x80);
	pci_write_config16(PCI_DEV(0, 0x2, 0), 0x4, 0x7);

#if RFID_TEST
	sch_SMbase_init();
	selectcard();
#endif
}
OpenPOWER on IntegriCloud