Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Bin Meng | d79593b | 2015-02-04 16:26:13 +0800 | [diff] [blame] | 8 | #include <mmc.h> |
Bin Meng | 7e96d31 | 2015-03-11 11:25:56 +0800 | [diff] [blame] | 9 | #include <netdev.h> |
| 10 | #include <phy.h> |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 11 | #include <asm/io.h> |
Bin Meng | ef9e9f9 | 2015-05-25 22:35:06 +0800 | [diff] [blame] | 12 | #include <asm/irq.h> |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 13 | #include <asm/pci.h> |
| 14 | #include <asm/post.h> |
| 15 | #include <asm/processor.h> |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 16 | #include <asm/arch/device.h> |
| 17 | #include <asm/arch/msg_port.h> |
| 18 | #include <asm/arch/quark.h> |
| 19 | |
Bin Meng | d79593b | 2015-02-04 16:26:13 +0800 | [diff] [blame] | 20 | static struct pci_device_id mmc_supported[] = { |
| 21 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_SDIO }, |
| 22 | }; |
| 23 | |
Bin Meng | ba6faff | 2015-02-04 16:26:12 +0800 | [diff] [blame] | 24 | /* |
| 25 | * TODO: |
| 26 | * |
| 27 | * This whole routine should be removed until we fully convert the ICH SPI |
| 28 | * driver to DM and make use of DT to pass the bios control register offset |
| 29 | */ |
| 30 | static void unprotect_spi_flash(void) |
| 31 | { |
| 32 | u32 bc; |
| 33 | |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame^] | 34 | qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, 0xd8, &bc); |
Bin Meng | ba6faff | 2015-02-04 16:26:12 +0800 | [diff] [blame] | 35 | bc |= 0x1; /* unprotect the flash */ |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame^] | 36 | qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, 0xd8, bc); |
Bin Meng | ba6faff | 2015-02-04 16:26:12 +0800 | [diff] [blame] | 37 | } |
| 38 | |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 39 | static void quark_setup_bars(void) |
| 40 | { |
| 41 | /* GPIO - D31:F0:R44h */ |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame^] | 42 | qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GBA, |
| 43 | CONFIG_GPIO_BASE | IO_BAR_EN); |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 44 | |
| 45 | /* ACPI PM1 Block - D31:F0:R48h */ |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame^] | 46 | qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_PM1BLK, |
| 47 | CONFIG_ACPI_PM1_BASE | IO_BAR_EN); |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 48 | |
| 49 | /* GPE0 - D31:F0:R4Ch */ |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame^] | 50 | qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GPE0BLK, |
| 51 | CONFIG_ACPI_GPE0_BASE | IO_BAR_EN); |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 52 | |
| 53 | /* WDT - D31:F0:R84h */ |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame^] | 54 | qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_WDTBA, |
| 55 | CONFIG_WDT_BASE | IO_BAR_EN); |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 56 | |
| 57 | /* RCBA - D31:F0:RF0h */ |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame^] | 58 | qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, |
| 59 | CONFIG_RCBA_BASE | MEM_BAR_EN); |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 60 | |
| 61 | /* ACPI P Block - Msg Port 04:R70h */ |
| 62 | msg_port_write(MSG_PORT_RMU, PBLK_BA, |
| 63 | CONFIG_ACPI_PBLK_BASE | IO_BAR_EN); |
| 64 | |
| 65 | /* SPI DMA - Msg Port 04:R7Ah */ |
| 66 | msg_port_write(MSG_PORT_RMU, SPI_DMA_BA, |
| 67 | CONFIG_SPI_DMA_BASE | IO_BAR_EN); |
| 68 | |
| 69 | /* PCIe ECAM */ |
| 70 | msg_port_write(MSG_PORT_MEM_ARBITER, AEC_CTRL, |
| 71 | CONFIG_PCIE_ECAM_BASE | MEM_BAR_EN); |
| 72 | msg_port_write(MSG_PORT_HOST_BRIDGE, HEC_REG, |
| 73 | CONFIG_PCIE_ECAM_BASE | MEM_BAR_EN); |
| 74 | } |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 75 | |
Bin Meng | 6db1448 | 2015-04-27 14:16:02 +0800 | [diff] [blame] | 76 | static void quark_enable_legacy_seg(void) |
| 77 | { |
| 78 | u32 hmisc2; |
| 79 | |
| 80 | hmisc2 = msg_port_read(MSG_PORT_HOST_BRIDGE, HMISC2); |
| 81 | hmisc2 |= (HMISC2_SEGE | HMISC2_SEGF | HMISC2_SEGAB); |
| 82 | msg_port_write(MSG_PORT_HOST_BRIDGE, HMISC2, hmisc2); |
| 83 | } |
| 84 | |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 85 | int arch_cpu_init(void) |
| 86 | { |
| 87 | struct pci_controller *hose; |
| 88 | int ret; |
| 89 | |
| 90 | post_code(POST_CPU_INIT); |
| 91 | #ifdef CONFIG_SYS_X86_TSC_TIMER |
| 92 | timer_set_base(rdtsc()); |
| 93 | #endif |
| 94 | |
| 95 | ret = x86_cpu_init_f(); |
| 96 | if (ret) |
| 97 | return ret; |
| 98 | |
| 99 | ret = pci_early_init_hose(&hose); |
| 100 | if (ret) |
| 101 | return ret; |
| 102 | |
Bin Meng | 3446986 | 2015-02-04 16:26:09 +0800 | [diff] [blame] | 103 | /* |
| 104 | * Quark SoC has some non-standard BARs (excluding PCI standard BARs) |
| 105 | * which need be initialized with suggested values |
| 106 | */ |
| 107 | quark_setup_bars(); |
| 108 | |
Bin Meng | 6db1448 | 2015-04-27 14:16:02 +0800 | [diff] [blame] | 109 | /* Turn on legacy segments (A/B/E/F) decode to system RAM */ |
| 110 | quark_enable_legacy_seg(); |
| 111 | |
Bin Meng | ba6faff | 2015-02-04 16:26:12 +0800 | [diff] [blame] | 112 | unprotect_spi_flash(); |
| 113 | |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | int print_cpuinfo(void) |
| 118 | { |
| 119 | post_code(POST_CPU_INFO); |
| 120 | return default_print_cpuinfo(); |
| 121 | } |
| 122 | |
| 123 | void reset_cpu(ulong addr) |
| 124 | { |
| 125 | /* cold reset */ |
Simon Glass | d0963d4 | 2015-04-28 20:11:31 -0600 | [diff] [blame] | 126 | x86_full_reset(); |
Bin Meng | 81da5a8 | 2015-02-02 22:35:27 +0800 | [diff] [blame] | 127 | } |
Bin Meng | d79593b | 2015-02-04 16:26:13 +0800 | [diff] [blame] | 128 | |
| 129 | int cpu_mmc_init(bd_t *bis) |
| 130 | { |
| 131 | return pci_mmc_init("Quark SDHCI", mmc_supported, |
| 132 | ARRAY_SIZE(mmc_supported)); |
| 133 | } |
Bin Meng | 7e96d31 | 2015-03-11 11:25:56 +0800 | [diff] [blame] | 134 | |
| 135 | int cpu_eth_init(bd_t *bis) |
| 136 | { |
| 137 | u32 base; |
| 138 | int ret0, ret1; |
| 139 | |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame^] | 140 | qrk_pci_read_config_dword(QUARK_EMAC0, PCI_BASE_ADDRESS_0, &base); |
Bin Meng | 7e96d31 | 2015-03-11 11:25:56 +0800 | [diff] [blame] | 141 | ret0 = designware_initialize(base, PHY_INTERFACE_MODE_RMII); |
| 142 | |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame^] | 143 | qrk_pci_read_config_dword(QUARK_EMAC1, PCI_BASE_ADDRESS_0, &base); |
Bin Meng | 7e96d31 | 2015-03-11 11:25:56 +0800 | [diff] [blame] | 144 | ret1 = designware_initialize(base, PHY_INTERFACE_MODE_RMII); |
| 145 | |
| 146 | if (ret0 < 0 && ret1 < 0) |
| 147 | return -1; |
| 148 | else |
| 149 | return 0; |
| 150 | } |
Bin Meng | ef9e9f9 | 2015-05-25 22:35:06 +0800 | [diff] [blame] | 151 | |
| 152 | void cpu_irq_init(void) |
| 153 | { |
| 154 | struct quark_rcba *rcba; |
| 155 | u32 base; |
| 156 | |
Bin Meng | 9cdcfd7 | 2015-09-03 05:37:24 -0700 | [diff] [blame^] | 157 | qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base); |
Bin Meng | ef9e9f9 | 2015-05-25 22:35:06 +0800 | [diff] [blame] | 158 | base &= ~MEM_BAR_EN; |
| 159 | rcba = (struct quark_rcba *)base; |
| 160 | |
| 161 | /* |
| 162 | * Route Quark PCI device interrupt pin to PIRQ |
| 163 | * |
| 164 | * Route device#23's INTA/B/C/D to PIRQA/B/C/D |
| 165 | * Route device#20,21's INTA/B/C/D to PIRQE/F/G/H |
| 166 | */ |
| 167 | writew(PIRQC, &rcba->rmu_ir); |
| 168 | writew(PIRQA | (PIRQB << 4) | (PIRQC << 8) | (PIRQD << 12), |
| 169 | &rcba->d23_ir); |
| 170 | writew(PIRQD, &rcba->core_ir); |
| 171 | writew(PIRQE | (PIRQF << 4) | (PIRQG << 8) | (PIRQH << 12), |
| 172 | &rcba->d20d21_ir); |
| 173 | } |
| 174 | |
| 175 | int arch_misc_init(void) |
| 176 | { |
Simon Glass | af1c2d68 | 2015-08-10 07:05:08 -0600 | [diff] [blame] | 177 | return pirq_init(); |
Bin Meng | ef9e9f9 | 2015-05-25 22:35:06 +0800 | [diff] [blame] | 178 | } |