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