xref: /openbmc/qemu/include/hw/ssi/bcm2835_spi.h (revision 4f2fdb10b5f78ba95300648fce74c42d3e4511c7)
1*28004fb7SRayhan Faizel /*
2*28004fb7SRayhan Faizel  * BCM2835 SPI Master Controller
3*28004fb7SRayhan Faizel  *
4*28004fb7SRayhan Faizel  * Copyright (c) 2024 Rayhan Faizel <rayhan.faizel@gmail.com>
5*28004fb7SRayhan Faizel  *
6*28004fb7SRayhan Faizel  * Permission is hereby granted, free of charge, to any person obtaining a copy
7*28004fb7SRayhan Faizel  * of this software and associated documentation files (the "Software"), to deal
8*28004fb7SRayhan Faizel  * in the Software without restriction, including without limitation the rights
9*28004fb7SRayhan Faizel  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10*28004fb7SRayhan Faizel  * copies of the Software, and to permit persons to whom the Software is
11*28004fb7SRayhan Faizel  * furnished to do so, subject to the following conditions:
12*28004fb7SRayhan Faizel  *
13*28004fb7SRayhan Faizel  * The above copyright notice and this permission notice shall be included in
14*28004fb7SRayhan Faizel  * all copies or substantial portions of the Software.
15*28004fb7SRayhan Faizel  *
16*28004fb7SRayhan Faizel  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17*28004fb7SRayhan Faizel  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*28004fb7SRayhan Faizel  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19*28004fb7SRayhan Faizel  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20*28004fb7SRayhan Faizel  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21*28004fb7SRayhan Faizel  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22*28004fb7SRayhan Faizel  * THE SOFTWARE.
23*28004fb7SRayhan Faizel  */
24*28004fb7SRayhan Faizel 
25*28004fb7SRayhan Faizel #include "hw/sysbus.h"
26*28004fb7SRayhan Faizel #include "hw/ssi/ssi.h"
27*28004fb7SRayhan Faizel #include "qom/object.h"
28*28004fb7SRayhan Faizel #include "qemu/fifo8.h"
29*28004fb7SRayhan Faizel 
30*28004fb7SRayhan Faizel #define TYPE_BCM2835_SPI "bcm2835-spi"
31*28004fb7SRayhan Faizel OBJECT_DECLARE_SIMPLE_TYPE(BCM2835SPIState, BCM2835_SPI)
32*28004fb7SRayhan Faizel 
33*28004fb7SRayhan Faizel /*
34*28004fb7SRayhan Faizel  * Though BCM2835 documentation says FIFOs have a capacity of 16,
35*28004fb7SRayhan Faizel  * FIFOs are actually 16 words in size or effectively 64 bytes when operating
36*28004fb7SRayhan Faizel  * in non DMA mode.
37*28004fb7SRayhan Faizel  */
38*28004fb7SRayhan Faizel #define FIFO_SIZE               64
39*28004fb7SRayhan Faizel #define FIFO_SIZE_3_4           48
40*28004fb7SRayhan Faizel 
41*28004fb7SRayhan Faizel #define RO_MASK                 0x1f0000
42*28004fb7SRayhan Faizel 
43*28004fb7SRayhan Faizel #define BCM2835_SPI_CS          0x00
44*28004fb7SRayhan Faizel #define BCM2835_SPI_FIFO        0x04
45*28004fb7SRayhan Faizel #define BCM2835_SPI_CLK         0x08
46*28004fb7SRayhan Faizel #define BCM2835_SPI_DLEN        0x0c
47*28004fb7SRayhan Faizel #define BCM2835_SPI_LTOH        0x10
48*28004fb7SRayhan Faizel #define BCM2835_SPI_DC          0x14
49*28004fb7SRayhan Faizel 
50*28004fb7SRayhan Faizel #define BCM2835_SPI_CS_RXF      BIT(20)
51*28004fb7SRayhan Faizel #define BCM2835_SPI_CS_RXR      BIT(19)
52*28004fb7SRayhan Faizel #define BCM2835_SPI_CS_TXD      BIT(18)
53*28004fb7SRayhan Faizel #define BCM2835_SPI_CS_RXD      BIT(17)
54*28004fb7SRayhan Faizel #define BCM2835_SPI_CS_DONE     BIT(16)
55*28004fb7SRayhan Faizel #define BCM2835_SPI_CS_LEN      BIT(13)
56*28004fb7SRayhan Faizel #define BCM2835_SPI_CS_REN      BIT(12)
57*28004fb7SRayhan Faizel #define BCM2835_SPI_CS_INTR     BIT(10)
58*28004fb7SRayhan Faizel #define BCM2835_SPI_CS_INTD     BIT(9)
59*28004fb7SRayhan Faizel #define BCM2835_SPI_CS_DMAEN    BIT(8)
60*28004fb7SRayhan Faizel #define BCM2835_SPI_CS_TA       BIT(7)
61*28004fb7SRayhan Faizel #define BCM2835_SPI_CLEAR_RX    BIT(5)
62*28004fb7SRayhan Faizel #define BCM2835_SPI_CLEAR_TX    BIT(4)
63*28004fb7SRayhan Faizel 
64*28004fb7SRayhan Faizel struct BCM2835SPIState {
65*28004fb7SRayhan Faizel     /* <private> */
66*28004fb7SRayhan Faizel     SysBusDevice parent_obj;
67*28004fb7SRayhan Faizel 
68*28004fb7SRayhan Faizel     /* <public> */
69*28004fb7SRayhan Faizel     SSIBus *bus;
70*28004fb7SRayhan Faizel     MemoryRegion iomem;
71*28004fb7SRayhan Faizel     qemu_irq irq;
72*28004fb7SRayhan Faizel 
73*28004fb7SRayhan Faizel     uint32_t cs;
74*28004fb7SRayhan Faizel     uint32_t clk;
75*28004fb7SRayhan Faizel     uint32_t dlen;
76*28004fb7SRayhan Faizel     uint32_t ltoh;
77*28004fb7SRayhan Faizel     uint32_t dc;
78*28004fb7SRayhan Faizel 
79*28004fb7SRayhan Faizel     Fifo8 tx_fifo;
80*28004fb7SRayhan Faizel     Fifo8 rx_fifo;
81*28004fb7SRayhan Faizel };
82