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