Re: [PATCH v6 101/102] x86: apl: Add FSP support

2019-12-08 Thread Bin Meng
On Sat, Dec 7, 2019 at 12:55 PM Simon Glass  wrote:
>
> The memory and silicon init parts of the FSP need support code to work.
> Add this for Apollo Lake.
>
> Signed-off-by: Simon Glass 
> ---
>
> Changes in v6:
> - Drop mention of devicetree for VTD feature
> - Drop mention of ramstage
> - Fix various coding style problems
> - Make BOOT_FROM_FAST_SPI_FLASH a Kconfig option
> - Use 'No SPI' instead of 'SPI2' as a debug message
>
> Changes in v5:
> - Allocate the FSP-S data instead of using the stack
> - Rename APOLLOLAKE_USB2_PORT_MAX
>
> Changes in v4:
> - Adjust the comment for struct dw_i2c_speed_config
> - Rename arch_fsp_s_preinit() to arch_fsps_preinit()
> - Switch over to use pinctrl for pad init/config
> - Tidy up mixed case in FSP code
> - apollolake -> Apollo Lake
>
> Changes in v3:
> - Add bootstage timing for reading vbt
> - Add fspm_done() hook to handle FSP-S wierdness (it breaks SPI flash)
> - Don't allow BOOT_FROM_FAST_SPI_FLASH with FSP-S
> - Set boot_loader_tolum_size to 0
> - Use the IRQ uclass instead of ITSS
>
> Changes in v2: None
>
>  arch/x86/cpu/apollolake/Makefile |   6 +
>  arch/x86/cpu/apollolake/fsp_m.c  | 210 ++
>  arch/x86/cpu/apollolake/fsp_s.c  | 661 +++
>  3 files changed, 877 insertions(+)
>  create mode 100644 arch/x86/cpu/apollolake/fsp_m.c
>  create mode 100644 arch/x86/cpu/apollolake/fsp_s.c
>

Reviewed-by: Bin Meng 


[PATCH v6 101/102] x86: apl: Add FSP support

2019-12-06 Thread Simon Glass
The memory and silicon init parts of the FSP need support code to work.
Add this for Apollo Lake.

Signed-off-by: Simon Glass 
---

Changes in v6:
- Drop mention of devicetree for VTD feature
- Drop mention of ramstage
- Fix various coding style problems
- Make BOOT_FROM_FAST_SPI_FLASH a Kconfig option
- Use 'No SPI' instead of 'SPI2' as a debug message

Changes in v5:
- Allocate the FSP-S data instead of using the stack
- Rename APOLLOLAKE_USB2_PORT_MAX

Changes in v4:
- Adjust the comment for struct dw_i2c_speed_config
- Rename arch_fsp_s_preinit() to arch_fsps_preinit()
- Switch over to use pinctrl for pad init/config
- Tidy up mixed case in FSP code
- apollolake -> Apollo Lake

Changes in v3:
- Add bootstage timing for reading vbt
- Add fspm_done() hook to handle FSP-S wierdness (it breaks SPI flash)
- Don't allow BOOT_FROM_FAST_SPI_FLASH with FSP-S
- Set boot_loader_tolum_size to 0
- Use the IRQ uclass instead of ITSS

Changes in v2: None

 arch/x86/cpu/apollolake/Makefile |   6 +
 arch/x86/cpu/apollolake/fsp_m.c  | 210 ++
 arch/x86/cpu/apollolake/fsp_s.c  | 661 +++
 3 files changed, 877 insertions(+)
 create mode 100644 arch/x86/cpu/apollolake/fsp_m.c
 create mode 100644 arch/x86/cpu/apollolake/fsp_s.c

diff --git a/arch/x86/cpu/apollolake/Makefile b/arch/x86/cpu/apollolake/Makefile
index dc6df15dab..1760df54d8 100644
--- a/arch/x86/cpu/apollolake/Makefile
+++ b/arch/x86/cpu/apollolake/Makefile
@@ -10,6 +10,12 @@ obj-y += cpu_common.o
 ifndef CONFIG_TPL_BUILD
 obj-y += cpu.o
 obj-y += punit.o
+ifdef CONFIG_SPL_BUILD
+obj-y += fsp_m.o
+endif
+endif
+ifndef CONFIG_SPL_BUILD
+obj-y += fsp_s.o
 endif
 
 obj-y += hostbridge.o
diff --git a/arch/x86/cpu/apollolake/fsp_m.c b/arch/x86/cpu/apollolake/fsp_m.c
new file mode 100644
index 00..5308af8ed4
--- /dev/null
+++ b/arch/x86/cpu/apollolake/fsp_m.c
@@ -0,0 +1,210 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2019 Google LLC
+ * Written by Simon Glass 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * ODT settings:
+ * If ODT PIN to LP4 DRAM is pulled HIGH for ODT_A and HIGH for ODT_B,
+ * choose ODT_A_B_HIGH_HIGH. If ODT PIN to LP4 DRAM is pulled HIGH for ODT_A
+ * and LOW for ODT_B, choose ODT_A_B_HIGH_LOW.
+ *
+ * Note that the enum values correspond to the interpreted UPD fields
+ * within Ch[3:0]_OdtConfig parameters.
+ */
+enum {
+   ODT_A_B_HIGH_LOW= 0 << 1,
+   ODT_A_B_HIGH_HIGH   = 1 << 1,
+   N_WR_24 = 1 << 5,
+};
+
+/*
+ * LPDDR4 helper routines for configuring the memory UPD for LPDDR4 operation.
+ * There are four physical LPDDR4 channels, each 32-bits wide. There are two
+ * logical channels using two physical channels together to form a 64-bit
+ * interface to memory for each logical channel.
+ */
+
+enum {
+   LP4_PHYS_CH0A,
+   LP4_PHYS_CH0B,
+   LP4_PHYS_CH1A,
+   LP4_PHYS_CH1B,
+
+   LP4_NUM_PHYS_CHANNELS,
+};
+
+/*
+ * The DQs within a physical channel can be bit-swizzled within each byte.
+ * Within a channel the bytes can be swapped, but the DQs need to be routed
+ * with the corresponding DQS (strobe).
+ */
+enum {
+   LP4_DQS0,
+   LP4_DQS1,
+   LP4_DQS2,
+   LP4_DQS3,
+
+   LP4_NUM_BYTE_LANES,
+   DQ_BITS_PER_DQS = 8,
+};
+
+/* Provide bit swizzling per DQS and byte swapping within a channel */
+struct lpddr4_chan_swizzle_cfg {
+   u8 dqs[LP4_NUM_BYTE_LANES][DQ_BITS_PER_DQS];
+};
+
+struct lpddr4_swizzle_cfg {
+   struct lpddr4_chan_swizzle_cfg phys[LP4_NUM_PHYS_CHANNELS];
+};
+
+static void setup_sdram(struct fsp_m_config *cfg,
+   const struct lpddr4_swizzle_cfg *swizzle_cfg)
+{
+   const struct lpddr4_chan_swizzle_cfg *sch;
+   /* Number of bytes to copy per DQS */
+   const size_t sz = DQ_BITS_PER_DQS;
+   int chan;
+
+   cfg->memory_down = 1;
+   cfg->scrambler_support = 1;
+   cfg->channel_hash_mask = 0x36;
+   cfg->slice_hash_mask = 9;
+   cfg->interleaved_mode = 2;
+   cfg->channels_slices_enable = 0;
+   cfg->min_ref_rate2x_enable = 0;
+   cfg->dual_rank_support_enable = 1;
+
+   /* LPDDR4 is memory down so no SPD addresses */
+   cfg->dimm0_spd_address = 0;
+   cfg->dimm1_spd_address = 0;
+
+   for (chan = 0; chan < 4; chan++) {
+   struct fsp_ram_channel *ch = >chan[chan];
+
+   ch->rank_enable = 1;
+   ch->device_width = 1;
+   ch->dram_density = 2;
+   ch->option = 3;
+   ch->odt_config = ODT_A_B_HIGH_HIGH;
+   }
+
+   /*
+* CH0_DQB byte lanes in the bit swizzle configuration field are
+* not 1:1. The mapping within the swizzling field is:
+*   indices [0:7]   - byte lane 1 (DQS1) DQ[8:15]
+*   indices [8:15]  - byte lane 0 (DQS0) DQ[0:7]
+*   indices [16:23] - byte lane 3 (DQS3) DQ[24:31]
+*   indices [24:31] -