blob: 2688a707a73e7bf039913b3210af9e92f83e1a40 [file] [log] [blame]
Bin Meng81da5a82015-02-02 22:35:27 +08001/*
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 Mengd79593b2015-02-04 16:26:13 +08008#include <mmc.h>
Bin Meng7e96d312015-03-11 11:25:56 +08009#include <netdev.h>
10#include <phy.h>
Bin Meng81da5a82015-02-02 22:35:27 +080011#include <asm/io.h>
Bin Mengef9e9f92015-05-25 22:35:06 +080012#include <asm/irq.h>
Bin Meng81da5a82015-02-02 22:35:27 +080013#include <asm/pci.h>
14#include <asm/post.h>
15#include <asm/processor.h>
Bin Meng34469862015-02-04 16:26:09 +080016#include <asm/arch/device.h>
17#include <asm/arch/msg_port.h>
18#include <asm/arch/quark.h>
19
Bin Mengd79593b2015-02-04 16:26:13 +080020static struct pci_device_id mmc_supported[] = {
21 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_SDIO },
22};
23
Bin Mengba6faff2015-02-04 16:26:12 +080024/*
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 */
30static void unprotect_spi_flash(void)
31{
32 u32 bc;
33
Bin Meng9cdcfd72015-09-03 05:37:24 -070034 qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, 0xd8, &bc);
Bin Mengba6faff2015-02-04 16:26:12 +080035 bc |= 0x1; /* unprotect the flash */
Bin Meng9cdcfd72015-09-03 05:37:24 -070036 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, 0xd8, bc);
Bin Mengba6faff2015-02-04 16:26:12 +080037}
38
Bin Meng34469862015-02-04 16:26:09 +080039static void quark_setup_bars(void)
40{
41 /* GPIO - D31:F0:R44h */
Bin Meng9cdcfd72015-09-03 05:37:24 -070042 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GBA,
43 CONFIG_GPIO_BASE | IO_BAR_EN);
Bin Meng34469862015-02-04 16:26:09 +080044
45 /* ACPI PM1 Block - D31:F0:R48h */
Bin Meng9cdcfd72015-09-03 05:37:24 -070046 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_PM1BLK,
47 CONFIG_ACPI_PM1_BASE | IO_BAR_EN);
Bin Meng34469862015-02-04 16:26:09 +080048
49 /* GPE0 - D31:F0:R4Ch */
Bin Meng9cdcfd72015-09-03 05:37:24 -070050 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GPE0BLK,
51 CONFIG_ACPI_GPE0_BASE | IO_BAR_EN);
Bin Meng34469862015-02-04 16:26:09 +080052
53 /* WDT - D31:F0:R84h */
Bin Meng9cdcfd72015-09-03 05:37:24 -070054 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_WDTBA,
55 CONFIG_WDT_BASE | IO_BAR_EN);
Bin Meng34469862015-02-04 16:26:09 +080056
57 /* RCBA - D31:F0:RF0h */
Bin Meng9cdcfd72015-09-03 05:37:24 -070058 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA,
59 CONFIG_RCBA_BASE | MEM_BAR_EN);
Bin Meng34469862015-02-04 16:26:09 +080060
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 Meng81da5a82015-02-02 22:35:27 +080075
Bin Meng6db14482015-04-27 14:16:02 +080076static 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 Meng81da5a82015-02-02 22:35:27 +080085int 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 Meng34469862015-02-04 16:26:09 +0800103 /*
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 Meng6db14482015-04-27 14:16:02 +0800109 /* Turn on legacy segments (A/B/E/F) decode to system RAM */
110 quark_enable_legacy_seg();
111
Bin Mengba6faff2015-02-04 16:26:12 +0800112 unprotect_spi_flash();
113
Bin Meng81da5a82015-02-02 22:35:27 +0800114 return 0;
115}
116
117int print_cpuinfo(void)
118{
119 post_code(POST_CPU_INFO);
120 return default_print_cpuinfo();
121}
122
123void reset_cpu(ulong addr)
124{
125 /* cold reset */
Simon Glassd0963d42015-04-28 20:11:31 -0600126 x86_full_reset();
Bin Meng81da5a82015-02-02 22:35:27 +0800127}
Bin Mengd79593b2015-02-04 16:26:13 +0800128
129int cpu_mmc_init(bd_t *bis)
130{
131 return pci_mmc_init("Quark SDHCI", mmc_supported,
132 ARRAY_SIZE(mmc_supported));
133}
Bin Meng7e96d312015-03-11 11:25:56 +0800134
135int cpu_eth_init(bd_t *bis)
136{
137 u32 base;
138 int ret0, ret1;
139
Bin Meng9cdcfd72015-09-03 05:37:24 -0700140 qrk_pci_read_config_dword(QUARK_EMAC0, PCI_BASE_ADDRESS_0, &base);
Bin Meng7e96d312015-03-11 11:25:56 +0800141 ret0 = designware_initialize(base, PHY_INTERFACE_MODE_RMII);
142
Bin Meng9cdcfd72015-09-03 05:37:24 -0700143 qrk_pci_read_config_dword(QUARK_EMAC1, PCI_BASE_ADDRESS_0, &base);
Bin Meng7e96d312015-03-11 11:25:56 +0800144 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 Mengef9e9f92015-05-25 22:35:06 +0800151
152void cpu_irq_init(void)
153{
154 struct quark_rcba *rcba;
155 u32 base;
156
Bin Meng9cdcfd72015-09-03 05:37:24 -0700157 qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base);
Bin Mengef9e9f92015-05-25 22:35:06 +0800158 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
175int arch_misc_init(void)
176{
Simon Glassaf1c2d682015-08-10 07:05:08 -0600177 return pirq_init();
Bin Mengef9e9f92015-05-25 22:35:06 +0800178}