blob: 72c359e6ee2d2c4308e0de5c73ae02d2ee8395f5 [file] [log] [blame]
Angel Pons0612b272020-04-05 15:46:56 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Barnali Sarkar89331cd2017-02-16 17:22:37 +05302
3#ifndef SOC_INTEL_COMMON_BLOCK_FAST_SPI_DEF_H
4#define SOC_INTEL_COMMON_BLOCK_FAST_SPI_DEF_H
5
Michał Żygowskic72a65d2024-02-16 19:54:39 +01006/* From JEDEC SFDP JESD216F.02 */
7#define SFDP_HDR_SIG 0x00 /* 1st DWORD of SFDP header */
8#define SFDP_PARAM_DENSITY 0x04 /* 2nd DWORD of SFDP params */
9#define SFDP_SIGNATURE 0x50444653 /* Valid sig in 1st DWORD of SFDP header */
10
Barnali Sarkar89331cd2017-02-16 17:22:37 +053011/* PCI configuration registers */
Tim Chu6e0c78b2022-12-08 09:02:34 +000012#define SPI_BIOS_DECODE_EN 0xd8
13#define SPI_BIOS_DECODE_LOCK BIT(31)
Barnali Sarkar89331cd2017-02-16 17:22:37 +053014
Angel Pons122cc8c2021-02-15 17:18:55 +010015#define SPI_BIOS_CONTROL 0xdc
Barnali Sarkar89331cd2017-02-16 17:22:37 +053016
Srinidhi N Kaushik60949082020-11-25 01:58:34 -080017/* Extended Bios Support Registers */
18#define SPI_CFG_BAR1 0xe0 /* SPI BAR1 MMIO */
19
Barnali Sarkar89331cd2017-02-16 17:22:37 +053020/* Bit definitions for BIOS_CONTROL */
Angel Pons122cc8c2021-02-15 17:18:55 +010021#define SPI_BIOS_CONTROL_WPD (1 << 0)
22#define SPI_BIOS_CONTROL_LOCK_ENABLE (1 << 1)
23#define SPI_BIOS_CONTROL_CACHE_DISABLE (1 << 2)
24#define SPI_BIOS_CONTROL_PREFETCH_ENABLE (1 << 3)
25#define SPI_BIOS_CONTROL_EISS (1 << 5)
26#define SPI_BIOS_CONTROL_BILD (1 << 7)
Angel Pons967753f2021-02-15 17:44:09 +010027#define SPI_BIOS_CONTROL_SYNC_SS (1 << 8)
Angel Pons122cc8c2021-02-15 17:18:55 +010028#define SPI_BIOS_CONTROL_EXT_BIOS_ENABLE (1 << 27)
29#define SPI_BIOS_CONTROL_EXT_BIOS_LOCK_ENABLE (1 << 28)
30#define SPI_BIOS_CONTROL_EXT_BIOS_LIMIT(x) ((x) & ~(0xfff))
Barnali Sarkar89331cd2017-02-16 17:22:37 +053031
32/* Register offsets from the MMIO region base (PCI_BASE_ADDRESS_0) */
33
34#define SPIBAR_BFPREG 0x00
35#define SPIBAR_HSFSTS_CTL 0x04
36#define SPIBAR_FADDR 0x08
Barnali Sarkar4f6e3412017-08-17 11:49:27 +053037#define SPIBAR_DLOCK 0x0c
Barnali Sarkar89331cd2017-02-16 17:22:37 +053038#define SPIBAR_FDATA(n) (0x10 + ((n) & 0xf) * 4)
39#define SPIBAR_FPR_BASE 0x84
Angel Pons122cc8c2021-02-15 17:18:55 +010040#define SPIBAR_FPR(n) (0x84 + (4 * (n)))
41#define SPIBAR_PREOP 0xa4
42#define SPIBAR_OPTYPE 0xa6
43#define SPIBAR_OPMENU_LOWER 0xa8
44#define SPIBAR_OPMENU_UPPER 0xac
45#define SPIBAR_FDOC 0xb4
46#define SPIBAR_FDOD 0xb8
Jonathan Zhangb64fdcc2023-01-26 15:02:43 -080047#define SPIBAR_SFDP0_VSCC0 0xc4
Barnali Sarkar89331cd2017-02-16 17:22:37 +053048#define SPIBAR_PTINX 0xcc
49#define SPIBAR_PTDATA 0xd0
50
51/* Bit definitions for BFPREG (0x00) register */
Angel Pons122cc8c2021-02-15 17:18:55 +010052#define SPIBAR_BFPREG_PRB_MASK 0x7fff
53#define SPIBAR_BFPREG_PRL_SHIFT 16
Barnali Sarkar89331cd2017-02-16 17:22:37 +053054#define SPIBAR_BFPREG_PRL_MASK (0x7fff << SPIBAR_BFPREG_PRL_SHIFT)
55#define SPIBAR_BFPREG_SBRS (1 << 31)
56
57/* Bit definitions for HSFSTS_CTL (0x04) register */
Angel Pons122cc8c2021-02-15 17:18:55 +010058#define SPIBAR_HSFSTS_FDBC_MASK (0x3f << 24)
Barnali Sarkar89331cd2017-02-16 17:22:37 +053059#define SPIBAR_HSFSTS_FDBC(n) (((n) << 24) & SPIBAR_HSFSTS_FDBC_MASK)
60#define SPIBAR_HSFSTS_WET (1 << 21)
61#define SPIBAR_HSFSTS_FCYCLE_MASK (0xf << 17)
Angel Pons122cc8c2021-02-15 17:18:55 +010062#define SPIBAR_HSFSTS_FCYCLE(cyc) (((cyc) << 17) & SPIBAR_HSFSTS_FCYCLE_MASK)
63
Barnali Sarkar89331cd2017-02-16 17:22:37 +053064/* Supported flash cycle types */
65#define SPIBAR_HSFSTS_CYCLE_READ SPIBAR_HSFSTS_FCYCLE(0)
66#define SPIBAR_HSFSTS_CYCLE_WRITE SPIBAR_HSFSTS_FCYCLE(2)
67#define SPIBAR_HSFSTS_CYCLE_4K_ERASE SPIBAR_HSFSTS_FCYCLE(3)
68#define SPIBAR_HSFSTS_CYCLE_64K_ERASE SPIBAR_HSFSTS_FCYCLE(4)
69#define SPIBAR_HSFSTS_CYCLE_RD_STATUS SPIBAR_HSFSTS_FCYCLE(8)
70
71#define SPIBAR_HSFSTS_FGO (1 << 16)
72#define SPIBAR_HSFSTS_FLOCKDN (1 << 15)
73#define SPIBAR_HSFSTS_FDV (1 << 14)
74#define SPIBAR_HSFSTS_FDOPSS (1 << 13)
Marc Jones051bf5d2021-03-30 12:16:09 -060075#define SPIBAR_HSFSTS_PRR34_LOCKDN (1 << 12)
Barnali Sarkar8e513192017-07-19 16:09:56 +053076#define SPIBAR_HSFSTS_WRSDIS (1 << 11)
Barnali Sarkar89331cd2017-02-16 17:22:37 +053077#define SPIBAR_HSFSTS_SAF_CE (1 << 8)
78#define SPIBAR_HSFSTS_SAF_ACTIVE (1 << 7)
79#define SPIBAR_HSFSTS_SAF_LE (1 << 6)
80#define SPIBAR_HSFSTS_SCIP (1 << 5)
81#define SPIBAR_HSFSTS_SAF_DLE (1 << 4)
82#define SPIBAR_HSFSTS_SAF_ERROR (1 << 3)
83#define SPIBAR_HSFSTS_AEL (1 << 2)
84#define SPIBAR_HSFSTS_FCERR (1 << 1)
85#define SPIBAR_HSFSTS_FDONE (1 << 0)
Subrata Banikfa2854d2022-04-22 13:31:05 +053086#define SPIBAR_HSFSTS_W1C_BITS 0x1ff
Barnali Sarkar89331cd2017-02-16 17:22:37 +053087
Barnali Sarkar89331cd2017-02-16 17:22:37 +053088/* Bit definitions for FADDR (0x08) register */
Angel Pons122cc8c2021-02-15 17:18:55 +010089#define SPIBAR_FADDR_MASK 0x7ffffff
Barnali Sarkar89331cd2017-02-16 17:22:37 +053090
Angel Pons122cc8c2021-02-15 17:18:55 +010091/* Bit definitions for DLOCK (0x0c) register */
Barnali Sarkar4f6e3412017-08-17 11:49:27 +053092#define SPIBAR_DLOCK_PR0LOCKDN (1 << 8)
93#define SPIBAR_DLOCK_PR1LOCKDN (1 << 9)
94#define SPIBAR_DLOCK_PR2LOCKDN (1 << 10)
95#define SPIBAR_DLOCK_PR3LOCKDN (1 << 11)
96#define SPIBAR_DLOCK_PR4LOCKDN (1 << 12)
97
Barnali Sarkar89331cd2017-02-16 17:22:37 +053098/* Maximum bytes of data that can fit in FDATAn (0x10) registers */
99#define SPIBAR_FDATA_FIFO_SIZE 0x40
100
Angel Pons122cc8c2021-02-15 17:18:55 +0100101/* Bit definitions for FDOC (0xb4) register */
Barnali Sarkar89331cd2017-02-16 17:22:37 +0530102#define SPIBAR_FDOC_COMPONENT (1 << 12)
103#define SPIBAR_FDOC_FDSI_1 (1 << 2)
104
105/* Flash Descriptor Component Section - Component 0 Density Bit Settings */
Angel Pons122cc8c2021-02-15 17:18:55 +0100106#define FLCOMP_C0DEN_MASK 0xf
Barnali Sarkar89331cd2017-02-16 17:22:37 +0530107#define FLCOMP_C0DEN_8MB 4
108#define FLCOMP_C0DEN_16MB 5
109#define FLCOMP_C0DEN_32MB 6
110
111/* Bit definitions for FPRn (0x84 + (4 * n)) registers */
112#define SPIBAR_FPR_WPE (1 << 31) /* Flash Write protected */
113#define SPIBAR_FPR_MAX 5
114
Angel Pons122cc8c2021-02-15 17:18:55 +0100115/* Programmable values for OPMENU_LOWER(0xa8) & OPMENU_UPPER(0xac) register */
Elyes HAOUAS05498a22018-05-28 16:26:43 +0200116#define SPI_OPMENU_0 0x01 /* WRSR: Write Status Register */
117#define SPI_OPTYPE_0 0x01 /* Write, no address */
118#define SPI_OPMENU_1 0x02 /* BYPR: Byte Program */
119#define SPI_OPTYPE_1 0x03 /* Write, address required */
120#define SPI_OPMENU_2 0x03 /* READ: Read Data */
121#define SPI_OPTYPE_2 0x02 /* Read, address required */
122#define SPI_OPMENU_3 0x05 /* RDSR: Read Status Register */
123#define SPI_OPTYPE_3 0x00 /* Read, no address */
124#define SPI_OPMENU_4 0x20 /* SE20: Sector Erase 0x20 */
125#define SPI_OPTYPE_4 0x03 /* Write, address required */
126#define SPI_OPMENU_5 0x9f /* RDID: Read ID */
127#define SPI_OPTYPE_5 0x00 /* Read, no address */
128#define SPI_OPMENU_6 0xd8 /* BED8: Block Erase 0xd8 */
129#define SPI_OPTYPE_6 0x03 /* Write, address required */
130#define SPI_OPMENU_7 0x0b /* FAST: Fast Read */
Barnali Sarkar89331cd2017-02-16 17:22:37 +0530131#define SPI_OPTYPE_7 0x02 /* Read, address required */
132#define SPI_OPMENU_UPPER ((SPI_OPMENU_7 << 24) | (SPI_OPMENU_6 << 16) | \
133 (SPI_OPMENU_5 << 8) | SPI_OPMENU_4)
134#define SPI_OPMENU_LOWER ((SPI_OPMENU_3 << 24) | (SPI_OPMENU_2 << 16) | \
135 (SPI_OPMENU_1 << 8) | SPI_OPMENU_0)
136#define SPI_OPTYPE ((SPI_OPTYPE_7 << 14) | (SPI_OPTYPE_6 << 12) | \
137 (SPI_OPTYPE_5 << 10) | (SPI_OPTYPE_4 << 8) | \
138 (SPI_OPTYPE_3 << 6) | (SPI_OPTYPE_2 << 4) | \
139 (SPI_OPTYPE_1 << 2) | (SPI_OPTYPE_0))
140#define SPI_OPPREFIX ((0x50 << 8) | 0x06) /* EWSR and WREN */
141
Subrata Banikd6431652022-04-13 20:30:53 +0530142/*
Jonathan Zhangb64fdcc2023-01-26 15:02:43 -0800143 * Spi Flash Vendor Specific Component Capabilities
144 * for Component 0 (0xc4) register
145 */
146#define SPIBAR_SFDP0_VSCC0_VCL (1 << 30)
147
148/*
Subrata Banikd6431652022-04-13 20:30:53 +0530149 * Register Offset of BIOS Vendor Specific Component Capabilities (VSCC)
150 * for Component 0 Register
151 */
152#define SPIBAR_SFDP0_VSCC0 0xc4
153#define SPIBAR_VSCC0_VCL (1 << 30)
154
Angel Pons122cc8c2021-02-15 17:18:55 +0100155/* Bit definitions for PTINX (0xcc) register */
Barnali Sarkar89331cd2017-02-16 17:22:37 +0530156#define SPIBAR_PTINX_COMP_0 (0 << 14)
157#define SPIBAR_PTINX_COMP_1 (1 << 14)
158#define SPIBAR_PTINX_HORD_SFDP (0 << 12)
159#define SPIBAR_PTINX_HORD_PARAM (1 << 12)
160#define SPIBAR_PTINX_HORD_JEDEC (2 << 12)
Barnali Sarkar89331cd2017-02-16 17:22:37 +0530161
162/* Register Offsets of BIOS Flash Program Registers */
Subrata Banike0b74232022-04-13 19:41:43 +0530163#define SPIBAR_RESET_LOCK 0xf0
164#define SPIBAR_RESET_CTRL 0xf4
165#define SPIBAR_RESET_DATA 0xf8
Barnali Sarkar89331cd2017-02-16 17:22:37 +0530166
167/* Programmable values of Bit0 (SSL) of Set STRAP MSG LOCK (0xF0) Register */
168#define SPIBAR_RESET_LOCK_DISABLE 0 /* Set_Strap Lock(SSL) Bit 0 = 0 */
169#define SPIBAR_RESET_LOCK_ENABLE 1 /* Set_Strap Lock(SSL) Bit 0 = 1 */
170
171/* Programmable values of Bit0(SSMS) of Set STRAP MSG Control (0xF4) Register*/
172#define SPIBAR_RESET_CTRL_SSMC 1 /* Set_Strap Mux Select(SSMS) Bit=1*/
173
Angel Pons122cc8c2021-02-15 17:18:55 +0100174#define SPIBAR_HWSEQ_XFER_TIMEOUT_MS 5000
Barnali Sarkar89331cd2017-02-16 17:22:37 +0530175
176void *fast_spi_get_bar(void);
177
178#endif /* SOC_INTEL_COMMON_BLOCK_FAST_SPI_DEF_H */