xref: /openbmc/qemu/include/hw/ssi/pnv_spi_regs.h (revision b4cb930e)
129318db1SChalapathi V /*
229318db1SChalapathi V  * QEMU PowerPC SPI model
329318db1SChalapathi V  *
429318db1SChalapathi V  * Copyright (c) 2024, IBM Corporation.
529318db1SChalapathi V  *
629318db1SChalapathi V  * SPDX-License-Identifier: GPL-2.0-or-later
729318db1SChalapathi V  */
829318db1SChalapathi V 
929318db1SChalapathi V #ifndef PNV_SPI_CONTROLLER_REGS_H
1029318db1SChalapathi V #define PNV_SPI_CONTROLLER_REGS_H
1129318db1SChalapathi V 
1229318db1SChalapathi V /*
1329318db1SChalapathi V  * Macros from target/ppc/cpu.h
1429318db1SChalapathi V  * These macros are copied from ppc target specific file target/ppc/cpu.h
1529318db1SChalapathi V  * as target/ppc/cpu.h cannot be included here.
1629318db1SChalapathi V  */
1729318db1SChalapathi V #define PPC_BIT(bit)            (0x8000000000000000ULL >> (bit))
1829318db1SChalapathi V #define PPC_BIT8(bit)           (0x80 >> (bit))
1929318db1SChalapathi V #define PPC_BITMASK(bs, be)     ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs))
2029318db1SChalapathi V #define PPC_BITMASK8(bs, be)    ((PPC_BIT8(bs) - PPC_BIT8(be)) | PPC_BIT8(bs))
2129318db1SChalapathi V #define MASK_TO_LSH(m)          (__builtin_ffsll(m) - 1)
2229318db1SChalapathi V #define GETFIELD(m, v)          (((v) & (m)) >> MASK_TO_LSH(m))
2329318db1SChalapathi V #define SETFIELD(m, v, val) \
2429318db1SChalapathi V         (((v) & ~(m)) | ((((typeof(v))(val)) << MASK_TO_LSH(m)) & (m)))
2529318db1SChalapathi V 
2629318db1SChalapathi V /* Error Register */
2729318db1SChalapathi V #define ERROR_REG               0x00
2829318db1SChalapathi V 
2929318db1SChalapathi V /* counter_config_reg */
3029318db1SChalapathi V #define SPI_CTR_CFG_REG         0x01
31*b4cb930eSChalapathi V #define SPI_CTR_CFG_N1          PPC_BITMASK(0, 7)
32*b4cb930eSChalapathi V #define SPI_CTR_CFG_N2          PPC_BITMASK(8, 15)
33*b4cb930eSChalapathi V #define SPI_CTR_CFG_CMP1        PPC_BITMASK(24, 31)
34*b4cb930eSChalapathi V #define SPI_CTR_CFG_CMP2        PPC_BITMASK(32, 39)
35*b4cb930eSChalapathi V #define SPI_CTR_CFG_N1_CTRL_B1  PPC_BIT(49)
36*b4cb930eSChalapathi V #define SPI_CTR_CFG_N1_CTRL_B2  PPC_BIT(50)
37*b4cb930eSChalapathi V #define SPI_CTR_CFG_N1_CTRL_B3  PPC_BIT(51)
38*b4cb930eSChalapathi V #define SPI_CTR_CFG_N2_CTRL_B0  PPC_BIT(52)
39*b4cb930eSChalapathi V #define SPI_CTR_CFG_N2_CTRL_B1  PPC_BIT(53)
40*b4cb930eSChalapathi V #define SPI_CTR_CFG_N2_CTRL_B2  PPC_BIT(54)
41*b4cb930eSChalapathi V #define SPI_CTR_CFG_N2_CTRL_B3  PPC_BIT(55)
4229318db1SChalapathi V 
4329318db1SChalapathi V /* config_reg */
4429318db1SChalapathi V #define CONFIG_REG1             0x02
4529318db1SChalapathi V 
4629318db1SChalapathi V /* clock_config_reset_control_ecc_enable_reg */
4729318db1SChalapathi V #define SPI_CLK_CFG_REG         0x03
4829318db1SChalapathi V #define SPI_CLK_CFG_HARD_RST    0x0084000000000000;
4929318db1SChalapathi V #define SPI_CLK_CFG_RST_CTRL    PPC_BITMASK(24, 27)
50*b4cb930eSChalapathi V #define SPI_CLK_CFG_ECC_EN      PPC_BIT(28)
51*b4cb930eSChalapathi V #define SPI_CLK_CFG_ECC_CTRL    PPC_BITMASK(29, 30)
5229318db1SChalapathi V 
5329318db1SChalapathi V /* memory_mapping_reg */
5429318db1SChalapathi V #define SPI_MM_REG              0x04
55*b4cb930eSChalapathi V #define SPI_MM_RDR_MATCH_VAL    PPC_BITMASK(32, 47)
56*b4cb930eSChalapathi V #define SPI_MM_RDR_MATCH_MASK   PPC_BITMASK(48, 63)
5729318db1SChalapathi V 
5829318db1SChalapathi V /* transmit_data_reg */
5929318db1SChalapathi V #define SPI_XMIT_DATA_REG       0x05
6029318db1SChalapathi V 
6129318db1SChalapathi V /* receive_data_reg */
6229318db1SChalapathi V #define SPI_RCV_DATA_REG        0x06
6329318db1SChalapathi V 
6429318db1SChalapathi V /* sequencer_operation_reg */
6529318db1SChalapathi V #define SPI_SEQ_OP_REG          0x07
6629318db1SChalapathi V 
6729318db1SChalapathi V /* status_reg */
6829318db1SChalapathi V #define SPI_STS_REG             0x08
6929318db1SChalapathi V #define SPI_STS_RDR_FULL        PPC_BIT(0)
7029318db1SChalapathi V #define SPI_STS_RDR_OVERRUN     PPC_BIT(1)
7129318db1SChalapathi V #define SPI_STS_RDR_UNDERRUN    PPC_BIT(2)
7229318db1SChalapathi V #define SPI_STS_TDR_FULL        PPC_BIT(4)
7329318db1SChalapathi V #define SPI_STS_TDR_OVERRUN     PPC_BIT(5)
7429318db1SChalapathi V #define SPI_STS_TDR_UNDERRUN    PPC_BIT(6)
7529318db1SChalapathi V #define SPI_STS_SEQ_FSM         PPC_BITMASK(8, 15)
7629318db1SChalapathi V #define SPI_STS_SHIFTER_FSM     PPC_BITMASK(16, 27)
7729318db1SChalapathi V #define SPI_STS_SEQ_INDEX       PPC_BITMASK(28, 31)
78*b4cb930eSChalapathi V #define SPI_STS_GEN_STATUS_B3   PPC_BIT(35)
7929318db1SChalapathi V #define SPI_STS_RDR             PPC_BITMASK(1, 3)
8029318db1SChalapathi V #define SPI_STS_TDR             PPC_BITMASK(5, 7)
8129318db1SChalapathi V 
82*b4cb930eSChalapathi V /*
83*b4cb930eSChalapathi V  * Shifter states
84*b4cb930eSChalapathi V  *
85*b4cb930eSChalapathi V  * These are the same values defined for the Shifter FSM field of the
86*b4cb930eSChalapathi V  * status register.  It's a 12 bit field so we will represent it as three
87*b4cb930eSChalapathi V  * nibbles in the constants.
88*b4cb930eSChalapathi V  *
89*b4cb930eSChalapathi V  * These are shifter_fsm values
90*b4cb930eSChalapathi V  *
91*b4cb930eSChalapathi V  * Status reg bits 16-27 -> field bits 0-11
92*b4cb930eSChalapathi V  * bits 0,1,2,5 unused/reserved
93*b4cb930eSChalapathi V  * bit 4 crc shift in (unused)
94*b4cb930eSChalapathi V  * bit 8 crc shift out (unused)
95*b4cb930eSChalapathi V  */
96*b4cb930eSChalapathi V 
97*b4cb930eSChalapathi V #define FSM_DONE                        0x100   /* bit 3 */
98*b4cb930eSChalapathi V #define FSM_SHIFT_N2                    0x020   /* bit 6 */
99*b4cb930eSChalapathi V #define FSM_WAIT                        0x010   /* bit 7 */
100*b4cb930eSChalapathi V #define FSM_SHIFT_N1                    0x004   /* bit 9 */
101*b4cb930eSChalapathi V #define FSM_START                       0x002   /* bit 10 */
102*b4cb930eSChalapathi V #define FSM_IDLE                        0x001   /* bit 11 */
103*b4cb930eSChalapathi V 
104*b4cb930eSChalapathi V /*
105*b4cb930eSChalapathi V  * Sequencer states
106*b4cb930eSChalapathi V  *
107*b4cb930eSChalapathi V  * These are sequencer_fsm values
108*b4cb930eSChalapathi V  *
109*b4cb930eSChalapathi V  * Status reg bits 8-15 -> field bits 0-7
110*b4cb930eSChalapathi V  * bits 0-3 unused/reserved
111*b4cb930eSChalapathi V  *
112*b4cb930eSChalapathi V  */
113*b4cb930eSChalapathi V #define SEQ_STATE_INDEX_INCREMENT       0x08    /* bit 4 */
114*b4cb930eSChalapathi V #define SEQ_STATE_EXECUTE               0x04    /* bit 5 */
115*b4cb930eSChalapathi V #define SEQ_STATE_DECODE                0x02    /* bit 6 */
116*b4cb930eSChalapathi V #define SEQ_STATE_IDLE                  0x01    /* bit 7 */
117*b4cb930eSChalapathi V 
118*b4cb930eSChalapathi V /*
119*b4cb930eSChalapathi V  * These are the supported sequencer operations.
120*b4cb930eSChalapathi V  * Only the upper nibble is significant because for many operations
121*b4cb930eSChalapathi V  * the lower nibble is a variable specific to the operation.
122*b4cb930eSChalapathi V  */
123*b4cb930eSChalapathi V #define SEQ_OP_STOP                     0x00
124*b4cb930eSChalapathi V #define SEQ_OP_SELECT_SLAVE             0x10
125*b4cb930eSChalapathi V #define SEQ_OP_SHIFT_N1                 0x30
126*b4cb930eSChalapathi V #define SEQ_OP_SHIFT_N2                 0x40
127*b4cb930eSChalapathi V #define SEQ_OP_BRANCH_IFNEQ_RDR         0x60
128*b4cb930eSChalapathi V #define SEQ_OP_TRANSFER_TDR             0xC0
129*b4cb930eSChalapathi V #define SEQ_OP_BRANCH_IFNEQ_INC_1       0xE0
130*b4cb930eSChalapathi V #define SEQ_OP_BRANCH_IFNEQ_INC_2       0xF0
131*b4cb930eSChalapathi V #define NUM_SEQ_OPS                     8
132*b4cb930eSChalapathi V 
13329318db1SChalapathi V #endif
134