2 * QEMU model of the Xilinx Zynq SPI controller
4 * Copyright (c) 2012 Peter A. G. Crosthwaite
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "hw/sysbus.h"
26 #include "sysemu/sysemu.h"
27 #include "hw/ptimer.h"
29 #include "qemu/fifo8.h"
31 #include "qemu/bitops.h"
33 #ifdef XILINX_SPIPS_ERR_DEBUG
34 #define DB_PRINT(...) do { \
35 fprintf(stderr, ": %s: ", __func__); \
36 fprintf(stderr, ## __VA_ARGS__); \
43 #define R_CONFIG (0x00 / 4)
44 #define IFMODE (1 << 31)
45 #define ENDIAN (1 << 26)
46 #define MODEFAIL_GEN_EN (1 << 17)
47 #define MAN_START_COM (1 << 16)
48 #define MAN_START_EN (1 << 15)
49 #define MANUAL_CS (1 << 14)
50 #define CS (0xF << 10)
52 #define PERI_SEL (1 << 9)
53 #define REF_CLK (1 << 8)
54 #define FIFO_WIDTH (3 << 6)
55 #define BAUD_RATE_DIV (7 << 3)
56 #define CLK_PH (1 << 2)
57 #define CLK_POL (1 << 1)
58 #define MODE_SEL (1 << 0)
59 #define R_CONFIG_RSVD (0x7bf40000)
61 /* interrupt mechanism */
62 #define R_INTR_STATUS (0x04 / 4)
63 #define R_INTR_EN (0x08 / 4)
64 #define R_INTR_DIS (0x0C / 4)
65 #define R_INTR_MASK (0x10 / 4)
66 #define IXR_TX_FIFO_UNDERFLOW (1 << 6)
67 #define IXR_RX_FIFO_FULL (1 << 5)
68 #define IXR_RX_FIFO_NOT_EMPTY (1 << 4)
69 #define IXR_TX_FIFO_FULL (1 << 3)
70 #define IXR_TX_FIFO_NOT_FULL (1 << 2)
71 #define IXR_TX_FIFO_MODE_FAIL (1 << 1)
72 #define IXR_RX_FIFO_OVERFLOW (1 << 0)
73 #define IXR_ALL ((IXR_TX_FIFO_UNDERFLOW<<1)-1)
75 #define R_EN (0x14 / 4)
76 #define R_DELAY (0x18 / 4)
77 #define R_TX_DATA (0x1C / 4)
78 #define R_RX_DATA (0x20 / 4)
79 #define R_SLAVE_IDLE_COUNT (0x24 / 4)
80 #define R_TX_THRES (0x28 / 4)
81 #define R_RX_THRES (0x2C / 4)
82 #define R_TXD1 (0x80 / 4)
83 #define R_TXD2 (0x84 / 4)
84 #define R_TXD3 (0x88 / 4)
86 #define R_LQSPI_CFG (0xa0 / 4)
87 #define R_LQSPI_CFG_RESET 0x03A002EB
88 #define LQSPI_CFG_LQ_MODE (1 << 31)
89 #define LQSPI_CFG_TWO_MEM (1 << 30)
90 #define LQSPI_CFG_SEP_BUS (1 << 30)
91 #define LQSPI_CFG_U_PAGE (1 << 28)
92 #define LQSPI_CFG_MODE_EN (1 << 25)
93 #define LQSPI_CFG_MODE_WIDTH 8
94 #define LQSPI_CFG_MODE_SHIFT 16
95 #define LQSPI_CFG_DUMMY_WIDTH 3
96 #define LQSPI_CFG_DUMMY_SHIFT 8
97 #define LQSPI_CFG_INST_CODE 0xFF
99 #define R_LQSPI_STS (0xA4 / 4)
100 #define LQSPI_STS_WR_RECVD (1 << 1)
102 #define R_MOD_ID (0xFC / 4)
104 #define R_MAX (R_MOD_ID+1)
106 /* size of TXRX FIFOs */
110 #define RXFF_A_Q (64 * 4)
111 #define TXFF_A_Q (64 * 4)
113 /* 16MB per linear region */
114 #define LQSPI_ADDRESS_BITS 24
115 /* Bite off 4k chunks at a time */
116 #define LQSPI_CACHE_SIZE 1024
118 #define SNOOP_CHECKING 0xFF
119 #define SNOOP_NONE 0xFE
120 #define SNOOP_STRIPING 0
136 SysBusDevice parent_obj
;
139 MemoryRegion mmlqspi
;
154 uint8_t num_txrx_bytes
;
156 uint32_t regs
[R_MAX
];
160 XilinxSPIPS parent_obj
;
162 uint32_t lqspi_buf
[LQSPI_CACHE_SIZE
];
163 hwaddr lqspi_cached_addr
;
166 typedef struct XilinxSPIPSClass
{
167 SysBusDeviceClass parent_class
;
169 const MemoryRegionOps
*reg_ops
;
171 uint32_t rx_fifo_size
;
172 uint32_t tx_fifo_size
;
175 #define TYPE_XILINX_SPIPS "xlnx.ps7-spi"
176 #define TYPE_XILINX_QSPIPS "xlnx.ps7-qspi"
178 #define XILINX_SPIPS(obj) \
179 OBJECT_CHECK(XilinxSPIPS, (obj), TYPE_XILINX_SPIPS)
180 #define XILINX_SPIPS_CLASS(klass) \
181 OBJECT_CLASS_CHECK(XilinxSPIPSClass, (klass), TYPE_XILINX_SPIPS)
182 #define XILINX_SPIPS_GET_CLASS(obj) \
183 OBJECT_GET_CLASS(XilinxSPIPSClass, (obj), TYPE_XILINX_SPIPS)
185 #define XILINX_QSPIPS(obj) \
186 OBJECT_CHECK(XilinxQSPIPS, (obj), TYPE_XILINX_QSPIPS)
188 static inline int num_effective_busses(XilinxSPIPS
*s
)
190 return (s
->regs
[R_LQSPI_CFG
] & LQSPI_CFG_SEP_BUS
&&
191 s
->regs
[R_LQSPI_CFG
] & LQSPI_CFG_TWO_MEM
) ? s
->num_busses
: 1;
194 static inline bool xilinx_spips_cs_is_set(XilinxSPIPS
*s
, int i
, int field
)
196 return ~field
& (1 << i
) && (s
->regs
[R_CONFIG
] & MANUAL_CS
197 || !fifo8_is_empty(&s
->tx_fifo
));
200 static void xilinx_spips_update_cs_lines(XilinxSPIPS
*s
)
204 int field
= s
->regs
[R_CONFIG
] >> CS_SHIFT
;
206 for (i
= 0; i
< s
->num_cs
; i
++) {
207 for (j
= 0; j
< num_effective_busses(s
); j
++) {
208 int upage
= !!(s
->regs
[R_LQSPI_STS
] & LQSPI_CFG_U_PAGE
);
209 int cs_to_set
= (j
* s
->num_cs
+ i
+ upage
) %
210 (s
->num_cs
* s
->num_busses
);
212 if (xilinx_spips_cs_is_set(s
, i
, field
) && !found
) {
213 DB_PRINT("selecting slave %d\n", i
);
214 qemu_set_irq(s
->cs_lines
[cs_to_set
], 0);
216 DB_PRINT("deselecting slave %d\n", i
);
217 qemu_set_irq(s
->cs_lines
[cs_to_set
], 1);
220 if (xilinx_spips_cs_is_set(s
, i
, field
)) {
225 s
->snoop_state
= SNOOP_CHECKING
;
229 static void xilinx_spips_update_ixr(XilinxSPIPS
*s
)
231 if (s
->regs
[R_LQSPI_CFG
] & LQSPI_CFG_LQ_MODE
) {
234 /* These are set/cleared as they occur */
235 s
->regs
[R_INTR_STATUS
] &= (IXR_TX_FIFO_UNDERFLOW
| IXR_RX_FIFO_OVERFLOW
|
236 IXR_TX_FIFO_MODE_FAIL
);
237 /* these are pure functions of fifo state, set them here */
238 s
->regs
[R_INTR_STATUS
] |=
239 (fifo8_is_full(&s
->rx_fifo
) ? IXR_RX_FIFO_FULL
: 0) |
240 (s
->rx_fifo
.num
>= s
->regs
[R_RX_THRES
] ? IXR_RX_FIFO_NOT_EMPTY
: 0) |
241 (fifo8_is_full(&s
->tx_fifo
) ? IXR_TX_FIFO_FULL
: 0) |
242 (s
->tx_fifo
.num
< s
->regs
[R_TX_THRES
] ? IXR_TX_FIFO_NOT_FULL
: 0);
243 /* drive external interrupt pin */
244 int new_irqline
= !!(s
->regs
[R_INTR_MASK
] & s
->regs
[R_INTR_STATUS
] &
246 if (new_irqline
!= s
->irqline
) {
247 s
->irqline
= new_irqline
;
248 qemu_set_irq(s
->irq
, s
->irqline
);
252 static void xilinx_spips_reset(DeviceState
*d
)
254 XilinxSPIPS
*s
= XILINX_SPIPS(d
);
257 for (i
= 0; i
< R_MAX
; i
++) {
261 fifo8_reset(&s
->rx_fifo
);
262 fifo8_reset(&s
->rx_fifo
);
263 /* non zero resets */
264 s
->regs
[R_CONFIG
] |= MODEFAIL_GEN_EN
;
265 s
->regs
[R_SLAVE_IDLE_COUNT
] = 0xFF;
266 s
->regs
[R_TX_THRES
] = 1;
267 s
->regs
[R_RX_THRES
] = 1;
268 /* FIXME: move magic number definition somewhere sensible */
269 s
->regs
[R_MOD_ID
] = 0x01090106;
270 s
->regs
[R_LQSPI_CFG
] = R_LQSPI_CFG_RESET
;
271 s
->snoop_state
= SNOOP_CHECKING
;
272 xilinx_spips_update_ixr(s
);
273 xilinx_spips_update_cs_lines(s
);
276 /* N way (num) in place bit striper. Lay out row wise bits (LSB to MSB)
277 * column wise (from element 0 to N-1). num is the length of x, and dir
278 * reverses the direction of the transform. Best illustrated by example:
279 * Each digit in the below array is a single bit (num == 3):
281 * {{ 76543210, } ----- stripe (dir == false) -----> {{ FCheb630, }
282 * { hgfedcba, } { GDAfc741, }
283 * { HGFEDCBA, }} <---- upstripe (dir == true) ----- { HEBgda52, }}
286 static inline void stripe8(uint8_t *x
, int num
, bool dir
)
289 memset(r
, 0, sizeof(uint8_t) * num
);
294 for (idx
[0] = 0; idx
[0] < num
; ++idx
[0]) {
295 for (bit
[0] = 0; bit
[0] < 8; ++bit
[0]) {
296 r
[idx
[d
]] |= x
[idx
[!d
]] & 1 << bit
[!d
] ? 1 << bit
[d
] : 0;
297 idx
[1] = (idx
[1] + 1) % num
;
303 memcpy(x
, r
, sizeof(uint8_t) * num
);
306 static void xilinx_spips_flush_txfifo(XilinxSPIPS
*s
)
311 uint8_t tx_rx
[num_effective_busses(s
)];
313 if (fifo8_is_empty(&s
->tx_fifo
)) {
314 if (!(s
->regs
[R_LQSPI_CFG
] & LQSPI_CFG_LQ_MODE
)) {
315 s
->regs
[R_INTR_STATUS
] |= IXR_TX_FIFO_UNDERFLOW
;
317 xilinx_spips_update_ixr(s
);
319 } else if (s
->snoop_state
== SNOOP_STRIPING
) {
320 for (i
= 0; i
< num_effective_busses(s
); ++i
) {
321 tx_rx
[i
] = fifo8_pop(&s
->tx_fifo
);
323 stripe8(tx_rx
, num_effective_busses(s
), false);
325 tx
= fifo8_pop(&s
->tx_fifo
);
326 for (i
= 0; i
< num_effective_busses(s
); ++i
) {
331 for (i
= 0; i
< num_effective_busses(s
); ++i
) {
332 DB_PRINT("tx = %02x\n", tx_rx
[i
]);
333 tx_rx
[i
] = ssi_transfer(s
->spi
[i
], (uint32_t)tx_rx
[i
]);
334 DB_PRINT("rx = %02x\n", tx_rx
[i
]);
337 if (fifo8_is_full(&s
->rx_fifo
)) {
338 s
->regs
[R_INTR_STATUS
] |= IXR_RX_FIFO_OVERFLOW
;
339 DB_PRINT("rx FIFO overflow");
340 } else if (s
->snoop_state
== SNOOP_STRIPING
) {
341 stripe8(tx_rx
, num_effective_busses(s
), true);
342 for (i
= 0; i
< num_effective_busses(s
); ++i
) {
343 fifo8_push(&s
->rx_fifo
, (uint8_t)tx_rx
[i
]);
346 fifo8_push(&s
->rx_fifo
, (uint8_t)tx_rx
[0]);
349 switch (s
->snoop_state
) {
350 case (SNOOP_CHECKING
):
351 switch (tx
) { /* new instruction code */
352 case READ
: /* 3 address bytes, no dummy bytes/cycles */
358 case FAST_READ
: /* 3 address bytes, 1 dummy byte */
361 case DIOR
: /* FIXME: these vary between vendor - set to spansion */
364 case QIOR
: /* 3 address bytes, 2 dummy bytes */
368 s
->snoop_state
= SNOOP_NONE
;
371 case (SNOOP_STRIPING
):
380 static inline void rx_data_bytes(XilinxSPIPS
*s
, uint32_t *value
, int max
)
385 for (i
= 0; i
< max
&& !fifo8_is_empty(&s
->rx_fifo
); ++i
) {
386 uint32_t next
= fifo8_pop(&s
->rx_fifo
) & 0xFF;
387 *value
|= next
<< 8 * (s
->regs
[R_CONFIG
] & ENDIAN
? 3-i
: i
);
391 static uint64_t xilinx_spips_read(void *opaque
, hwaddr addr
,
394 XilinxSPIPS
*s
= opaque
;
401 mask
= ~(R_CONFIG_RSVD
| MAN_START_COM
);
404 ret
= s
->regs
[addr
] & IXR_ALL
;
406 DB_PRINT("addr=" TARGET_FMT_plx
" = %x\n", addr
* 4, ret
);
414 case R_SLAVE_IDLE_COUNT
:
426 rx_data_bytes(s
, &ret
, s
->num_txrx_bytes
);
427 DB_PRINT("addr=" TARGET_FMT_plx
" = %x\n", addr
* 4, ret
);
428 xilinx_spips_update_ixr(s
);
431 DB_PRINT("addr=" TARGET_FMT_plx
" = %x\n", addr
* 4, s
->regs
[addr
] & mask
);
432 return s
->regs
[addr
] & mask
;
436 static inline void tx_data_bytes(XilinxSPIPS
*s
, uint32_t value
, int num
)
439 for (i
= 0; i
< num
&& !fifo8_is_full(&s
->tx_fifo
); ++i
) {
440 if (s
->regs
[R_CONFIG
] & ENDIAN
) {
441 fifo8_push(&s
->tx_fifo
, (uint8_t)(value
>> 24));
444 fifo8_push(&s
->tx_fifo
, (uint8_t)value
);
450 static void xilinx_spips_write(void *opaque
, hwaddr addr
,
451 uint64_t value
, unsigned size
)
454 int man_start_com
= 0;
455 XilinxSPIPS
*s
= opaque
;
457 DB_PRINT("addr=" TARGET_FMT_plx
" = %x\n", addr
, (unsigned)value
);
461 mask
= ~(R_CONFIG_RSVD
| MAN_START_COM
);
462 if (value
& MAN_START_COM
) {
468 s
->regs
[R_INTR_STATUS
] &= ~(mask
& value
);
472 s
->regs
[R_INTR_MASK
] &= ~(mask
& value
);
476 s
->regs
[R_INTR_MASK
] |= mask
& value
;
481 case R_SLAVE_IDLE_COUNT
:
490 tx_data_bytes(s
, (uint32_t)value
, s
->num_txrx_bytes
);
493 tx_data_bytes(s
, (uint32_t)value
, 1);
496 tx_data_bytes(s
, (uint32_t)value
, 2);
499 tx_data_bytes(s
, (uint32_t)value
, 3);
502 s
->regs
[addr
] = (s
->regs
[addr
] & ~mask
) | (value
& mask
);
504 xilinx_spips_update_cs_lines(s
);
505 if ((man_start_com
&& s
->regs
[R_CONFIG
] & MAN_START_EN
) ||
506 (fifo8_is_empty(&s
->tx_fifo
) && s
->regs
[R_CONFIG
] & MAN_START_EN
)) {
507 xilinx_spips_flush_txfifo(s
);
509 xilinx_spips_update_cs_lines(s
);
510 xilinx_spips_update_ixr(s
);
513 static const MemoryRegionOps spips_ops
= {
514 .read
= xilinx_spips_read
,
515 .write
= xilinx_spips_write
,
516 .endianness
= DEVICE_LITTLE_ENDIAN
,
519 static void xilinx_qspips_write(void *opaque
, hwaddr addr
,
520 uint64_t value
, unsigned size
)
522 XilinxQSPIPS
*q
= XILINX_QSPIPS(opaque
);
524 xilinx_spips_write(opaque
, addr
, value
, size
);
527 if (addr
== R_LQSPI_CFG
) {
528 q
->lqspi_cached_addr
= ~0ULL;
532 static const MemoryRegionOps qspips_ops
= {
533 .read
= xilinx_spips_read
,
534 .write
= xilinx_qspips_write
,
535 .endianness
= DEVICE_LITTLE_ENDIAN
,
538 #define LQSPI_CACHE_SIZE 1024
541 lqspi_read(void *opaque
, hwaddr addr
, unsigned int size
)
544 XilinxQSPIPS
*q
= opaque
;
545 XilinxSPIPS
*s
= opaque
;
548 if (addr
>= q
->lqspi_cached_addr
&&
549 addr
<= q
->lqspi_cached_addr
+ LQSPI_CACHE_SIZE
- 4) {
550 ret
= q
->lqspi_buf
[(addr
- q
->lqspi_cached_addr
) >> 2];
551 DB_PRINT("addr: %08x, data: %08x\n", (unsigned)addr
, (unsigned)ret
);
554 int flash_addr
= (addr
/ num_effective_busses(s
));
555 int slave
= flash_addr
>> LQSPI_ADDRESS_BITS
;
557 uint32_t u_page_save
= s
->regs
[R_LQSPI_STS
] & ~LQSPI_CFG_U_PAGE
;
559 s
->regs
[R_LQSPI_STS
] &= ~LQSPI_CFG_U_PAGE
;
560 s
->regs
[R_LQSPI_STS
] |= slave
? LQSPI_CFG_U_PAGE
: 0;
562 DB_PRINT("config reg status: %08x\n", s
->regs
[R_LQSPI_CFG
]);
564 fifo8_reset(&s
->tx_fifo
);
565 fifo8_reset(&s
->rx_fifo
);
568 DB_PRINT("pushing read instruction: %02x\n",
569 (uint8_t)(s
->regs
[R_LQSPI_CFG
] & LQSPI_CFG_INST_CODE
));
570 fifo8_push(&s
->tx_fifo
, s
->regs
[R_LQSPI_CFG
] & LQSPI_CFG_INST_CODE
);
572 DB_PRINT("pushing read address %06x\n", flash_addr
);
573 fifo8_push(&s
->tx_fifo
, (uint8_t)(flash_addr
>> 16));
574 fifo8_push(&s
->tx_fifo
, (uint8_t)(flash_addr
>> 8));
575 fifo8_push(&s
->tx_fifo
, (uint8_t)flash_addr
);
577 if (s
->regs
[R_LQSPI_CFG
] & LQSPI_CFG_MODE_EN
) {
578 fifo8_push(&s
->tx_fifo
, extract32(s
->regs
[R_LQSPI_CFG
],
579 LQSPI_CFG_MODE_SHIFT
,
580 LQSPI_CFG_MODE_WIDTH
));
583 for (i
= 0; i
< (extract32(s
->regs
[R_LQSPI_CFG
], LQSPI_CFG_DUMMY_SHIFT
,
584 LQSPI_CFG_DUMMY_WIDTH
)); ++i
) {
585 DB_PRINT("pushing dummy byte\n");
586 fifo8_push(&s
->tx_fifo
, 0);
588 xilinx_spips_update_cs_lines(s
);
589 xilinx_spips_flush_txfifo(s
);
590 fifo8_reset(&s
->rx_fifo
);
592 DB_PRINT("starting QSPI data read\n");
594 for (i
= 0; i
< LQSPI_CACHE_SIZE
/ 4; ++i
) {
595 tx_data_bytes(s
, 0, 4);
596 xilinx_spips_flush_txfifo(s
);
597 rx_data_bytes(s
, &q
->lqspi_buf
[cache_entry
], 4);
601 s
->regs
[R_LQSPI_STS
] &= ~LQSPI_CFG_U_PAGE
;
602 s
->regs
[R_LQSPI_STS
] |= u_page_save
;
603 xilinx_spips_update_cs_lines(s
);
605 q
->lqspi_cached_addr
= addr
;
606 return lqspi_read(opaque
, addr
, size
);
610 static const MemoryRegionOps lqspi_ops
= {
612 .endianness
= DEVICE_NATIVE_ENDIAN
,
614 .min_access_size
= 4,
619 static void xilinx_spips_realize(DeviceState
*dev
, Error
**errp
)
621 XilinxSPIPS
*s
= XILINX_SPIPS(dev
);
622 SysBusDevice
*sbd
= SYS_BUS_DEVICE(dev
);
623 XilinxSPIPSClass
*xsc
= XILINX_SPIPS_GET_CLASS(s
);
626 DB_PRINT("realized spips\n");
628 s
->spi
= g_new(SSIBus
*, s
->num_busses
);
629 for (i
= 0; i
< s
->num_busses
; ++i
) {
631 snprintf(bus_name
, 16, "spi%d", i
);
632 s
->spi
[i
] = ssi_create_bus(dev
, bus_name
);
635 s
->cs_lines
= g_new0(qemu_irq
, s
->num_cs
* s
->num_busses
);
636 ssi_auto_connect_slaves(DEVICE(s
), s
->cs_lines
, s
->spi
[0]);
637 ssi_auto_connect_slaves(DEVICE(s
), s
->cs_lines
, s
->spi
[1]);
638 sysbus_init_irq(sbd
, &s
->irq
);
639 for (i
= 0; i
< s
->num_cs
* s
->num_busses
; ++i
) {
640 sysbus_init_irq(sbd
, &s
->cs_lines
[i
]);
643 memory_region_init_io(&s
->iomem
, xsc
->reg_ops
, s
, "spi", R_MAX
*4);
644 sysbus_init_mmio(sbd
, &s
->iomem
);
648 fifo8_create(&s
->rx_fifo
, xsc
->rx_fifo_size
);
649 fifo8_create(&s
->tx_fifo
, xsc
->tx_fifo_size
);
652 static void xilinx_qspips_realize(DeviceState
*dev
, Error
**errp
)
654 XilinxSPIPS
*s
= XILINX_SPIPS(dev
);
655 XilinxQSPIPS
*q
= XILINX_QSPIPS(dev
);
656 SysBusDevice
*sbd
= SYS_BUS_DEVICE(dev
);
658 DB_PRINT("realized qspips\n");
662 s
->num_txrx_bytes
= 4;
664 xilinx_spips_realize(dev
, errp
);
665 memory_region_init_io(&s
->mmlqspi
, &lqspi_ops
, s
, "lqspi",
666 (1 << LQSPI_ADDRESS_BITS
) * 2);
667 sysbus_init_mmio(sbd
, &s
->mmlqspi
);
669 q
->lqspi_cached_addr
= ~0ULL;
672 static int xilinx_spips_post_load(void *opaque
, int version_id
)
674 xilinx_spips_update_ixr((XilinxSPIPS
*)opaque
);
675 xilinx_spips_update_cs_lines((XilinxSPIPS
*)opaque
);
679 static const VMStateDescription vmstate_xilinx_spips
= {
680 .name
= "xilinx_spips",
682 .minimum_version_id
= 2,
683 .minimum_version_id_old
= 2,
684 .post_load
= xilinx_spips_post_load
,
685 .fields
= (VMStateField
[]) {
686 VMSTATE_FIFO8(tx_fifo
, XilinxSPIPS
),
687 VMSTATE_FIFO8(rx_fifo
, XilinxSPIPS
),
688 VMSTATE_UINT32_ARRAY(regs
, XilinxSPIPS
, R_MAX
),
689 VMSTATE_UINT8(snoop_state
, XilinxSPIPS
),
690 VMSTATE_END_OF_LIST()
694 static Property xilinx_spips_properties
[] = {
695 DEFINE_PROP_UINT8("num-busses", XilinxSPIPS
, num_busses
, 1),
696 DEFINE_PROP_UINT8("num-ss-bits", XilinxSPIPS
, num_cs
, 4),
697 DEFINE_PROP_UINT8("num-txrx-bytes", XilinxSPIPS
, num_txrx_bytes
, 1),
698 DEFINE_PROP_END_OF_LIST(),
701 static void xilinx_qspips_class_init(ObjectClass
*klass
, void * data
)
703 DeviceClass
*dc
= DEVICE_CLASS(klass
);
704 XilinxSPIPSClass
*xsc
= XILINX_SPIPS_CLASS(klass
);
706 dc
->realize
= xilinx_qspips_realize
;
707 xsc
->reg_ops
= &qspips_ops
;
708 xsc
->rx_fifo_size
= RXFF_A_Q
;
709 xsc
->tx_fifo_size
= TXFF_A_Q
;
712 static void xilinx_spips_class_init(ObjectClass
*klass
, void *data
)
714 DeviceClass
*dc
= DEVICE_CLASS(klass
);
715 XilinxSPIPSClass
*xsc
= XILINX_SPIPS_CLASS(klass
);
717 dc
->realize
= xilinx_spips_realize
;
718 dc
->reset
= xilinx_spips_reset
;
719 dc
->props
= xilinx_spips_properties
;
720 dc
->vmsd
= &vmstate_xilinx_spips
;
722 xsc
->reg_ops
= &spips_ops
;
723 xsc
->rx_fifo_size
= RXFF_A
;
724 xsc
->tx_fifo_size
= TXFF_A
;
727 static const TypeInfo xilinx_spips_info
= {
728 .name
= TYPE_XILINX_SPIPS
,
729 .parent
= TYPE_SYS_BUS_DEVICE
,
730 .instance_size
= sizeof(XilinxSPIPS
),
731 .class_init
= xilinx_spips_class_init
,
732 .class_size
= sizeof(XilinxSPIPSClass
),
735 static const TypeInfo xilinx_qspips_info
= {
736 .name
= TYPE_XILINX_QSPIPS
,
737 .parent
= TYPE_XILINX_SPIPS
,
738 .instance_size
= sizeof(XilinxQSPIPS
),
739 .class_init
= xilinx_qspips_class_init
,
742 static void xilinx_spips_register_types(void)
744 type_register_static(&xilinx_spips_info
);
745 type_register_static(&xilinx_qspips_info
);
748 type_init(xilinx_spips_register_types
)