Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Gabor Juhos | 5a4dcfa | 2013-05-22 03:57:37 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2013 Gabor Juhos <juhosg@openwrt.org> |
Paul Burton | baf37f0 | 2013-11-08 11:18:50 +0000 | [diff] [blame] | 4 | * Copyright (C) 2013 Imagination Technologies |
Gabor Juhos | 5a4dcfa | 2013-05-22 03:57:37 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Paul Burton | ba21a45 | 2015-01-29 10:38:20 +0000 | [diff] [blame] | 8 | #include <ide.h> |
Simon Glass | 2cf431c | 2019-11-14 12:57:47 -0700 | [diff] [blame] | 9 | #include <init.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame^] | 10 | #include <net.h> |
Gabor Juhos | f195749 | 2013-05-22 03:57:44 +0000 | [diff] [blame] | 11 | #include <netdev.h> |
Paul Burton | 81f98bb | 2013-11-08 11:18:57 +0000 | [diff] [blame] | 12 | #include <pci.h> |
Paul Burton | baf37f0 | 2013-11-08 11:18:50 +0000 | [diff] [blame] | 13 | #include <pci_gt64120.h> |
| 14 | #include <pci_msc01.h> |
Paul Burton | 3ced12a | 2013-11-08 11:18:55 +0000 | [diff] [blame] | 15 | #include <rtc.h> |
Gabor Juhos | 5a4dcfa | 2013-05-22 03:57:37 +0000 | [diff] [blame] | 16 | |
Gabor Juhos | feaa606 | 2013-05-22 03:57:42 +0000 | [diff] [blame] | 17 | #include <asm/addrspace.h> |
Gabor Juhos | 0156431 | 2013-05-22 03:57:38 +0000 | [diff] [blame] | 18 | #include <asm/io.h> |
| 19 | #include <asm/malta.h> |
| 20 | |
Paul Burton | a257f62 | 2013-11-08 11:18:49 +0000 | [diff] [blame] | 21 | #include "superio.h" |
| 22 | |
Simon Glass | 088454c | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
Paul Burton | baf37f0 | 2013-11-08 11:18:50 +0000 | [diff] [blame] | 25 | enum core_card { |
| 26 | CORE_UNKNOWN, |
| 27 | CORE_LV, |
| 28 | CORE_FPGA6, |
| 29 | }; |
| 30 | |
| 31 | enum sys_con { |
| 32 | SYSCON_UNKNOWN, |
| 33 | SYSCON_GT64120, |
| 34 | SYSCON_MSC01, |
| 35 | }; |
| 36 | |
Paul Burton | e0ada63 | 2013-11-08 11:18:51 +0000 | [diff] [blame] | 37 | static void malta_lcd_puts(const char *str) |
| 38 | { |
| 39 | int i; |
| 40 | void *reg = (void *)CKSEG1ADDR(MALTA_ASCIIPOS0); |
| 41 | |
| 42 | /* print up to 8 characters of the string */ |
Masahiro Yamada | b414119 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 43 | for (i = 0; i < min((int)strlen(str), 8); i++) { |
Paul Burton | e0ada63 | 2013-11-08 11:18:51 +0000 | [diff] [blame] | 44 | __raw_writel(str[i], reg); |
| 45 | reg += MALTA_ASCIIPOS1 - MALTA_ASCIIPOS0; |
| 46 | } |
| 47 | |
| 48 | /* fill the rest of the display with spaces */ |
| 49 | for (; i < 8; i++) { |
| 50 | __raw_writel(' ', reg); |
| 51 | reg += MALTA_ASCIIPOS1 - MALTA_ASCIIPOS0; |
| 52 | } |
| 53 | } |
| 54 | |
Paul Burton | baf37f0 | 2013-11-08 11:18:50 +0000 | [diff] [blame] | 55 | static enum core_card malta_core_card(void) |
| 56 | { |
| 57 | u32 corid, rev; |
Daniel Schwierzeck | 8061cfc | 2016-01-09 17:32:45 +0100 | [diff] [blame] | 58 | const void *reg = (const void *)CKSEG1ADDR(MALTA_REVISION); |
Paul Burton | baf37f0 | 2013-11-08 11:18:50 +0000 | [diff] [blame] | 59 | |
Daniel Schwierzeck | 8061cfc | 2016-01-09 17:32:45 +0100 | [diff] [blame] | 60 | rev = __raw_readl(reg); |
Paul Burton | baf37f0 | 2013-11-08 11:18:50 +0000 | [diff] [blame] | 61 | corid = (rev & MALTA_REVISION_CORID_MSK) >> MALTA_REVISION_CORID_SHF; |
| 62 | |
| 63 | switch (corid) { |
| 64 | case MALTA_REVISION_CORID_CORE_LV: |
| 65 | return CORE_LV; |
| 66 | |
| 67 | case MALTA_REVISION_CORID_CORE_FPGA6: |
| 68 | return CORE_FPGA6; |
| 69 | |
| 70 | default: |
| 71 | return CORE_UNKNOWN; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | static enum sys_con malta_sys_con(void) |
| 76 | { |
| 77 | switch (malta_core_card()) { |
| 78 | case CORE_LV: |
| 79 | return SYSCON_GT64120; |
| 80 | |
| 81 | case CORE_FPGA6: |
| 82 | return SYSCON_MSC01; |
| 83 | |
| 84 | default: |
| 85 | return SYSCON_UNKNOWN; |
| 86 | } |
| 87 | } |
| 88 | |
Simon Glass | f1683aa | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 89 | int dram_init(void) |
Gabor Juhos | 5a4dcfa | 2013-05-22 03:57:37 +0000 | [diff] [blame] | 90 | { |
Simon Glass | 088454c | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 91 | gd->ram_size = CONFIG_SYS_MEM_SIZE; |
| 92 | |
| 93 | return 0; |
Gabor Juhos | 5a4dcfa | 2013-05-22 03:57:37 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | int checkboard(void) |
| 97 | { |
Paul Burton | baf37f0 | 2013-11-08 11:18:50 +0000 | [diff] [blame] | 98 | enum core_card core; |
| 99 | |
Bin Meng | a187559 | 2016-02-05 19:30:11 -0800 | [diff] [blame] | 100 | malta_lcd_puts("U-Boot"); |
Paul Burton | baf37f0 | 2013-11-08 11:18:50 +0000 | [diff] [blame] | 101 | puts("Board: MIPS Malta"); |
| 102 | |
| 103 | core = malta_core_card(); |
| 104 | switch (core) { |
| 105 | case CORE_LV: |
| 106 | puts(" CoreLV"); |
| 107 | break; |
| 108 | |
| 109 | case CORE_FPGA6: |
| 110 | puts(" CoreFPGA6"); |
| 111 | break; |
| 112 | |
| 113 | default: |
| 114 | puts(" CoreUnknown"); |
| 115 | } |
| 116 | |
| 117 | putc('\n'); |
Gabor Juhos | 5a4dcfa | 2013-05-22 03:57:37 +0000 | [diff] [blame] | 118 | return 0; |
| 119 | } |
Gabor Juhos | 0156431 | 2013-05-22 03:57:38 +0000 | [diff] [blame] | 120 | |
Gabor Juhos | f195749 | 2013-05-22 03:57:44 +0000 | [diff] [blame] | 121 | int board_eth_init(bd_t *bis) |
| 122 | { |
| 123 | return pci_eth_init(bis); |
| 124 | } |
| 125 | |
Gabor Juhos | 0156431 | 2013-05-22 03:57:38 +0000 | [diff] [blame] | 126 | void _machine_restart(void) |
| 127 | { |
| 128 | void __iomem *reset_base; |
| 129 | |
| 130 | reset_base = (void __iomem *)CKSEG1ADDR(MALTA_RESET_BASE); |
| 131 | __raw_writel(GORESET, reset_base); |
Paul Burton | 28c8c3d | 2015-01-29 10:38:21 +0000 | [diff] [blame] | 132 | mdelay(1000); |
Gabor Juhos | 0156431 | 2013-05-22 03:57:38 +0000 | [diff] [blame] | 133 | } |
Gabor Juhos | feaa606 | 2013-05-22 03:57:42 +0000 | [diff] [blame] | 134 | |
Paul Burton | a257f62 | 2013-11-08 11:18:49 +0000 | [diff] [blame] | 135 | int board_early_init_f(void) |
| 136 | { |
Paul Burton | 91ec615 | 2016-01-29 13:54:54 +0000 | [diff] [blame] | 137 | ulong io_base; |
Paul Burton | baf37f0 | 2013-11-08 11:18:50 +0000 | [diff] [blame] | 138 | |
| 139 | /* choose correct PCI I/O base */ |
| 140 | switch (malta_sys_con()) { |
| 141 | case SYSCON_GT64120: |
Paul Burton | 91ec615 | 2016-01-29 13:54:54 +0000 | [diff] [blame] | 142 | io_base = CKSEG1ADDR(MALTA_GT_PCIIO_BASE); |
Paul Burton | baf37f0 | 2013-11-08 11:18:50 +0000 | [diff] [blame] | 143 | break; |
| 144 | |
| 145 | case SYSCON_MSC01: |
Paul Burton | 91ec615 | 2016-01-29 13:54:54 +0000 | [diff] [blame] | 146 | io_base = CKSEG1ADDR(MALTA_MSC01_PCIIO_BASE); |
Paul Burton | baf37f0 | 2013-11-08 11:18:50 +0000 | [diff] [blame] | 147 | break; |
| 148 | |
| 149 | default: |
| 150 | return -1; |
| 151 | } |
| 152 | |
Paul Burton | 91ec615 | 2016-01-29 13:54:54 +0000 | [diff] [blame] | 153 | set_io_port_base(io_base); |
Paul Burton | 19a5ef6 | 2016-01-29 13:54:53 +0000 | [diff] [blame] | 154 | |
Paul Burton | a257f62 | 2013-11-08 11:18:49 +0000 | [diff] [blame] | 155 | /* setup FDC37M817 super I/O controller */ |
Paul Burton | 91ec615 | 2016-01-29 13:54:54 +0000 | [diff] [blame] | 156 | malta_superio_init(); |
Paul Burton | a257f62 | 2013-11-08 11:18:49 +0000 | [diff] [blame] | 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
Paul Burton | 3ced12a | 2013-11-08 11:18:55 +0000 | [diff] [blame] | 161 | int misc_init_r(void) |
| 162 | { |
| 163 | rtc_reset(); |
| 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
Gabor Juhos | feaa606 | 2013-05-22 03:57:42 +0000 | [diff] [blame] | 168 | void pci_init_board(void) |
| 169 | { |
Paul Burton | 81f98bb | 2013-11-08 11:18:57 +0000 | [diff] [blame] | 170 | pci_dev_t bdf; |
Paul Burton | bea12b7 | 2013-11-26 17:45:27 +0000 | [diff] [blame] | 171 | u32 val32; |
| 172 | u8 val8; |
Paul Burton | 81f98bb | 2013-11-08 11:18:57 +0000 | [diff] [blame] | 173 | |
Paul Burton | baf37f0 | 2013-11-08 11:18:50 +0000 | [diff] [blame] | 174 | switch (malta_sys_con()) { |
| 175 | case SYSCON_GT64120: |
Paul Burton | baf37f0 | 2013-11-08 11:18:50 +0000 | [diff] [blame] | 176 | gt64120_pci_init((void *)CKSEG1ADDR(MALTA_GT_BASE), |
| 177 | 0x00000000, 0x00000000, CONFIG_SYS_MEM_SIZE, |
| 178 | 0x10000000, 0x10000000, 128 * 1024 * 1024, |
| 179 | 0x00000000, 0x00000000, 0x20000); |
| 180 | break; |
| 181 | |
| 182 | default: |
| 183 | case SYSCON_MSC01: |
Paul Burton | baf37f0 | 2013-11-08 11:18:50 +0000 | [diff] [blame] | 184 | msc01_pci_init((void *)CKSEG1ADDR(MALTA_MSC01_PCI_BASE), |
| 185 | 0x00000000, 0x00000000, CONFIG_SYS_MEM_SIZE, |
| 186 | MALTA_MSC01_PCIMEM_MAP, |
| 187 | CKSEG1ADDR(MALTA_MSC01_PCIMEM_BASE), |
| 188 | MALTA_MSC01_PCIMEM_SIZE, MALTA_MSC01_PCIIO_MAP, |
| 189 | 0x00000000, MALTA_MSC01_PCIIO_SIZE); |
| 190 | break; |
| 191 | } |
Paul Burton | 81f98bb | 2013-11-08 11:18:57 +0000 | [diff] [blame] | 192 | |
| 193 | bdf = pci_find_device(PCI_VENDOR_ID_INTEL, |
| 194 | PCI_DEVICE_ID_INTEL_82371AB_0, 0); |
| 195 | if (bdf == -1) |
| 196 | panic("Failed to find PIIX4 PCI bridge\n"); |
| 197 | |
| 198 | /* setup PCI interrupt routing */ |
| 199 | pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCA, 10); |
| 200 | pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCB, 10); |
| 201 | pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCC, 11); |
| 202 | pci_write_config_byte(bdf, PCI_CFG_PIIX4_PIRQRCD, 11); |
Paul Burton | bea12b7 | 2013-11-26 17:45:27 +0000 | [diff] [blame] | 203 | |
| 204 | /* mux SERIRQ onto SERIRQ pin */ |
| 205 | pci_read_config_dword(bdf, PCI_CFG_PIIX4_GENCFG, &val32); |
| 206 | val32 |= PCI_CFG_PIIX4_GENCFG_SERIRQ; |
| 207 | pci_write_config_dword(bdf, PCI_CFG_PIIX4_GENCFG, val32); |
| 208 | |
| 209 | /* enable SERIRQ - Linux currently depends upon this */ |
| 210 | pci_read_config_byte(bdf, PCI_CFG_PIIX4_SERIRQC, &val8); |
| 211 | val8 |= PCI_CFG_PIIX4_SERIRQC_EN | PCI_CFG_PIIX4_SERIRQC_CONT; |
| 212 | pci_write_config_byte(bdf, PCI_CFG_PIIX4_SERIRQC, val8); |
Paul Burton | ba21a45 | 2015-01-29 10:38:20 +0000 | [diff] [blame] | 213 | |
| 214 | bdf = pci_find_device(PCI_VENDOR_ID_INTEL, |
| 215 | PCI_DEVICE_ID_INTEL_82371AB, 0); |
| 216 | if (bdf == -1) |
| 217 | panic("Failed to find PIIX4 IDE controller\n"); |
| 218 | |
| 219 | /* enable bus master & IO access */ |
| 220 | val32 |= PCI_COMMAND_MASTER | PCI_COMMAND_IO; |
| 221 | pci_write_config_dword(bdf, PCI_COMMAND, val32); |
| 222 | |
| 223 | /* set latency */ |
| 224 | pci_write_config_byte(bdf, PCI_LATENCY_TIMER, 0x40); |
| 225 | |
| 226 | /* enable IDE/ATA */ |
| 227 | pci_write_config_dword(bdf, PCI_CFG_PIIX4_IDETIM_PRI, |
| 228 | PCI_CFG_PIIX4_IDETIM_IDE); |
| 229 | pci_write_config_dword(bdf, PCI_CFG_PIIX4_IDETIM_SEC, |
| 230 | PCI_CFG_PIIX4_IDETIM_IDE); |
Gabor Juhos | feaa606 | 2013-05-22 03:57:42 +0000 | [diff] [blame] | 231 | } |