blob: 62c68e062e9511aff1112b7a69a4013c96efaa87 [file] [log] [blame]
Andrew Wu06510722013-06-21 21:37:05 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 DMP Electronics 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.
Andrew Wu06510722013-06-21 21:37:05 +080014 */
15
16#include <console/console.h>
17#include <arch/io.h>
18#include <stdint.h>
19#include <device/device.h>
20#include <device/pci.h>
21#include <device/pci_ids.h>
22#include <cbmem.h>
23#include <pc80/mc146818rtc.h>
24#include "chip.h"
25#include "northbridge.h"
26
27#define SPI_BASE 0xfc00
28
29static void northbridge_init(device_t dev)
30{
31 printk(BIOS_DEBUG, "Vortex86EX northbridge early init ...\n");
32 // enable F0A/ECA/E8A/E4A/E0A/C4A/C0A shadow read/writable.
33 pci_write_config32(dev, NB_REG_MAR, 0x3ff000f0);
34 // enable C0000h - C3FFFh/C4000h - C7FFF can be in L1 cache selection.
35 pci_write_config32(dev, NB_REG_HOST_CTL, (1 << 18) | (1 << 19));
36 // Set SPI register base.
37 pci_write_config16(dev, NB_REG_SPI_BASE, SPI_BASE | 1);
38}
39
40static struct device_operations northbridge_operations = {
41 .set_resources = pci_dev_set_resources,
42 .enable_resources = pci_dev_enable_resources,
43 .init = northbridge_init
44};
45
Andrew Wu06510722013-06-21 21:37:05 +080046static const struct pci_driver northbridge_driver_6025 __pci_driver = {
47 .ops = &northbridge_operations,
48 .vendor = PCI_VENDOR_ID_RDC,
49 .device = 0x6025, /* EX CPU N/B ID */
50};
51
52/* Set CMOS register 15h/16h/17h/18h for base/extended
53 * memory size. */
54static void set_cmos_memory_size(unsigned long sizek)
55{
56 unsigned long ext_mem_size;
57 u8 ext_mem_size_hb, ext_mem_size_lb;
58 /* calculate memory size between 1M - 65M. */
59 ext_mem_size = sizek - 1024;
60 if (ext_mem_size > 65535)
61 ext_mem_size = 65535;
62 ext_mem_size_hb = (u8) (ext_mem_size >> 8);
63 ext_mem_size_lb = (u8) (ext_mem_size & 0xff);
64 /* Base memory is always 640K. */
65 cmos_write(0x80, 0x15);
66 cmos_write(0x02, 0x16);
67 /* Write extended memory size. */
68 cmos_write(ext_mem_size_lb, 0x17);
69 cmos_write(ext_mem_size_hb, 0x18);
70 /* register 0x30(48) is RTC_BOOT_BYTE for coreboot,
71 * don't touch it. */
72}
73
74static void pci_domain_set_resources(device_t dev)
75{
76 device_t mc_dev;
77 uint32_t pci_tolm;
78
79 printk(BIOS_SPEW, "Entering vortex86ex pci_domain_set_resources.\n");
80
81 pci_tolm = find_pci_tolm(dev->link_list);
82 mc_dev = dev->link_list->children;
83 if (mc_dev) {
84 unsigned long tomk, tolmk;
85 int idx;
86 int ss;
87 /* Get DDRII size setting from northbridge register. */
88 /* SS = 0 for 2MB, 1 for 4MB, 2 for 8MB, 3 for 16MB ... */
89 ss = pci_read_config16(mc_dev, 0x6c);
90 ss = ((ss >> 8) & 0xf);
91 tomk = (2 * 1024) << ss;
92 printk(BIOS_DEBUG, "I would set ram size to %ld Mbytes\n", (tomk >> 10));
93 /* Compute the top of Low memory */
94 tolmk = pci_tolm >> 10;
95 if (tolmk >= tomk)
96 /* The PCI hole does does not overlap the memory.
97 */
98 tolmk = tomk;
99
Kyösti Mälkki42f46512013-06-27 08:20:09 +0300100 set_top_of_ram(tolmk * 1024);
Andrew Wu06510722013-06-21 21:37:05 +0800101
102 /* Report the memory regions */
103 idx = 10;
104 ram_resource(dev, idx++, 0, 640); /* first 640k */
105 ram_resource(dev, idx++, 768, tolmk - 768); /* leave a hole for vga */
106 set_cmos_memory_size(tolmk);
107 }
108 assign_resources(dev->link_list);
109}
110
111static struct device_operations pci_domain_ops = {
112 .read_resources = pci_domain_read_resources,
113 .set_resources = pci_domain_set_resources,
114 .enable_resources = NULL,
115 .init = NULL,
116 .scan_bus = pci_domain_scan_bus,
Kyösti Mälkki33e5df32013-07-03 10:51:34 +0300117 .ops_pci_bus = pci_bus_default_ops,
Andrew Wu06510722013-06-21 21:37:05 +0800118};
119
120static void enable_dev(struct device *dev)
121{
122 printk(BIOS_SPEW, "In vortex86ex enable_dev for device %s.\n", dev_path(dev));
123
124 /* Set the operations if it is a special bus type */
125 if (dev->path.type == DEVICE_PATH_DOMAIN) {
126 dev->ops = &pci_domain_ops;
Andrew Wu06510722013-06-21 21:37:05 +0800127 }
128}
129
130struct chip_operations northbridge_dmp_vortex86ex_ops = {
131 CHIP_NAME("DMP Vortex86EX Northbridge")
132 .enable_dev = enable_dev,
133};