xref: /openbmc/qemu/include/hw/ssi/pnv_spi.h (revision 7192d7b7fea15f2226a896f02b360bf7cfce1ab1)
1 /*
2  * QEMU PowerPC SPI model
3  *
4  * Copyright (c) 2024, IBM Corporation.
5  *
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  *
8  * This model Supports a connection to a single SPI responder.
9  * Introduced for P10 to provide access to SPI seeproms, TPM, flash device
10  * and an ADC controller.
11  *
12  * All SPI function control is mapped into the SPI register space to enable
13  * full control by firmware.
14  *
15  * SPI Controller has sequencer and shift engine. The SPI shift engine
16  * performs serialization and de-serialization according to the control by
17  * the sequencer and according to the setup defined in the configuration
18  * registers and the SPI sequencer implements the main control logic.
19  */
20 
21 #ifndef PPC_PNV_SPI_H
22 #define PPC_PNV_SPI_H
23 
24 #include "hw/ssi/ssi.h"
25 #include "hw/sysbus.h"
26 #include "qemu/fifo8.h"
27 
28 #define TYPE_PNV_SPI "pnv-spi"
29 OBJECT_DECLARE_SIMPLE_TYPE(PnvSpi, PNV_SPI)
30 
31 #define PNV_SPI_REG_SIZE 8
32 #define PNV_SPI_REGS 7
33 
34 #define TYPE_PNV_SPI_BUS "spi"
35 typedef struct PnvSpi {
36     SysBusDevice parent_obj;
37 
38     SSIBus *ssi_bus;
39     qemu_irq *cs_line;
40     MemoryRegion    xscom_spic_regs;
41     Fifo8 tx_fifo;
42     Fifo8 rx_fifo;
43     /* SPI object number */
44     uint32_t        spic_num;
45     uint32_t        chip_id;
46     uint8_t         transfer_len;
47     uint8_t         responder_select;
48     /* To verify if shift_n1 happens prior to shift_n2 */
49     bool            shift_n1_done;
50     /* Loop counter for branch operation opcode Ex/Fx */
51     uint8_t         loop_counter_1;
52     uint8_t         loop_counter_2;
53     /* N1/N2_bits specifies the size of the N1/N2 segment of a frame in bits.*/
54     uint8_t         N1_bits;
55     uint8_t         N2_bits;
56     /* Number of bytes in a payload for the N1/N2 frame segment.*/
57     uint8_t         N1_bytes;
58     uint8_t         N2_bytes;
59     /* Number of N1/N2 bytes marked for transmit */
60     uint8_t         N1_tx;
61     uint8_t         N2_tx;
62     /* Number of N1/N2 bytes marked for receive */
63     uint8_t         N1_rx;
64     uint8_t         N2_rx;
65 
66     /* SPI registers */
67     uint64_t        regs[PNV_SPI_REGS];
68     uint8_t         seq_op[PNV_SPI_REG_SIZE];
69     uint64_t        status;
70 } PnvSpi;
71 #endif /* PPC_PNV_SPI_H */
72