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 "qemu/osdep.h"
26 #include "hw/sysbus.h"
27 #include "sysemu/sysemu.h"
28 #include "hw/ptimer.h"
30 #include "qemu/fifo8.h"
31 #include "hw/ssi/ssi.h"
32 #include "qemu/bitops.h"
33 #include "hw/ssi/xilinx_spips.h"
35 #ifndef XILINX_SPIPS_ERR_DEBUG
36 #define XILINX_SPIPS_ERR_DEBUG 0
39 #define DB_PRINT_L(level, ...) do { \
40 if (XILINX_SPIPS_ERR_DEBUG > (level)) { \
41 fprintf(stderr, ": %s: ", __func__); \
42 fprintf(stderr, ## __VA_ARGS__); \
47 #define R_CONFIG (0x00 / 4)
48 #define IFMODE (1U << 31)
49 #define ENDIAN (1 << 26)
50 #define MODEFAIL_GEN_EN (1 << 17)
51 #define MAN_START_COM (1 << 16)
52 #define MAN_START_EN (1 << 15)
53 #define MANUAL_CS (1 << 14)
54 #define CS (0xF << 10)
56 #define PERI_SEL (1 << 9)
57 #define REF_CLK (1 << 8)
58 #define FIFO_WIDTH (3 << 6)
59 #define BAUD_RATE_DIV (7 << 3)
60 #define CLK_PH (1 << 2)
61 #define CLK_POL (1 << 1)
62 #define MODE_SEL (1 << 0)
63 #define R_CONFIG_RSVD (0x7bf40000)
65 /* interrupt mechanism */
66 #define R_INTR_STATUS (0x04 / 4)
67 #define R_INTR_EN (0x08 / 4)
68 #define R_INTR_DIS (0x0C / 4)
69 #define R_INTR_MASK (0x10 / 4)
70 #define IXR_TX_FIFO_UNDERFLOW (1 << 6)
71 #define IXR_RX_FIFO_FULL (1 << 5)
72 #define IXR_RX_FIFO_NOT_EMPTY (1 << 4)
73 #define IXR_TX_FIFO_FULL (1 << 3)
74 #define IXR_TX_FIFO_NOT_FULL (1 << 2)
75 #define IXR_TX_FIFO_MODE_FAIL (1 << 1)
76 #define IXR_RX_FIFO_OVERFLOW (1 << 0)
77 #define IXR_ALL ((IXR_TX_FIFO_UNDERFLOW<<1)-1)
79 #define R_EN (0x14 / 4)
80 #define R_DELAY (0x18 / 4)
81 #define R_TX_DATA (0x1C / 4)
82 #define R_RX_DATA (0x20 / 4)
83 #define R_SLAVE_IDLE_COUNT (0x24 / 4)
84 #define R_TX_THRES (0x28 / 4)
85 #define R_RX_THRES (0x2C / 4)
86 #define R_TXD1 (0x80 / 4)
87 #define R_TXD2 (0x84 / 4)
88 #define R_TXD3 (0x88 / 4)
90 #define R_LQSPI_CFG (0xa0 / 4)
91 #define R_LQSPI_CFG_RESET 0x03A002EB
92 #define LQSPI_CFG_LQ_MODE (1U << 31)
93 #define LQSPI_CFG_TWO_MEM (1 << 30)
94 #define LQSPI_CFG_SEP_BUS (1 << 30)
95 #define LQSPI_CFG_U_PAGE (1 << 28)
96 #define LQSPI_CFG_MODE_EN (1 << 25)
97 #define LQSPI_CFG_MODE_WIDTH 8
98 #define LQSPI_CFG_MODE_SHIFT 16
99 #define LQSPI_CFG_DUMMY_WIDTH 3
100 #define LQSPI_CFG_DUMMY_SHIFT 8
101 #define LQSPI_CFG_INST_CODE 0xFF
103 #define R_LQSPI_STS (0xA4 / 4)
104 #define LQSPI_STS_WR_RECVD (1 << 1)
106 #define R_MOD_ID (0xFC / 4)
108 /* size of TXRX FIFOs */
112 #define RXFF_A_Q (64 * 4)
113 #define TXFF_A_Q (64 * 4)
115 /* 16MB per linear region */
116 #define LQSPI_ADDRESS_BITS 24
117 /* Bite off 4k chunks at a time */
118 #define LQSPI_CACHE_SIZE 1024
120 #define SNOOP_CHECKING 0xFF
121 #define SNOOP_NONE 0xFE
122 #define SNOOP_STRIPING 0
138 XilinxSPIPS parent_obj
;
140 uint8_t lqspi_buf
[LQSPI_CACHE_SIZE
];
141 hwaddr lqspi_cached_addr
;
144 typedef struct XilinxSPIPSClass
{
145 SysBusDeviceClass parent_class
;
147 const MemoryRegionOps
*reg_ops
;
149 uint32_t rx_fifo_size
;
150 uint32_t tx_fifo_size
;
153 static inline int num_effective_busses(XilinxSPIPS
*s
)
155 return (s
->regs
[R_LQSPI_CFG
] & LQSPI_CFG_SEP_BUS
&&
156 s
->regs
[R_LQSPI_CFG
] & LQSPI_CFG_TWO_MEM
) ? s
->num_busses
: 1;
159 static inline bool xilinx_spips_cs_is_set(XilinxSPIPS
*s
, int i
, int field
)
161 return ~field
& (1 << i
) && (s
->regs
[R_CONFIG
] & MANUAL_CS
162 || !fifo8_is_empty(&s
->tx_fifo
));
165 static void xilinx_spips_update_cs_lines(XilinxSPIPS
*s
)
169 int field
= s
->regs
[R_CONFIG
] >> CS_SHIFT
;
171 for (i
= 0; i
< s
->num_cs
; i
++) {
172 for (j
= 0; j
< num_effective_busses(s
); j
++) {
173 int upage
= !!(s
->regs
[R_LQSPI_STS
] & LQSPI_CFG_U_PAGE
);
174 int cs_to_set
= (j
* s
->num_cs
+ i
+ upage
) %
175 (s
->num_cs
* s
->num_busses
);
177 if (xilinx_spips_cs_is_set(s
, i
, field
) && !found
) {
178 DB_PRINT_L(0, "selecting slave %d\n", i
);
179 qemu_set_irq(s
->cs_lines
[cs_to_set
], 0);
181 DB_PRINT_L(0, "deselecting slave %d\n", i
);
182 qemu_set_irq(s
->cs_lines
[cs_to_set
], 1);
185 if (xilinx_spips_cs_is_set(s
, i
, field
)) {
190 s
->snoop_state
= SNOOP_CHECKING
;
191 DB_PRINT_L(1, "moving to snoop check state\n");
195 static void xilinx_spips_update_ixr(XilinxSPIPS
*s
)
197 if (s
->regs
[R_LQSPI_CFG
] & LQSPI_CFG_LQ_MODE
) {
200 /* These are set/cleared as they occur */
201 s
->regs
[R_INTR_STATUS
] &= (IXR_TX_FIFO_UNDERFLOW
| IXR_RX_FIFO_OVERFLOW
|
202 IXR_TX_FIFO_MODE_FAIL
);
203 /* these are pure functions of fifo state, set them here */
204 s
->regs
[R_INTR_STATUS
] |=
205 (fifo8_is_full(&s
->rx_fifo
) ? IXR_RX_FIFO_FULL
: 0) |
206 (s
->rx_fifo
.num
>= s
->regs
[R_RX_THRES
] ? IXR_RX_FIFO_NOT_EMPTY
: 0) |
207 (fifo8_is_full(&s
->tx_fifo
) ? IXR_TX_FIFO_FULL
: 0) |
208 (s
->tx_fifo
.num
< s
->regs
[R_TX_THRES
] ? IXR_TX_FIFO_NOT_FULL
: 0);
209 /* drive external interrupt pin */
210 int new_irqline
= !!(s
->regs
[R_INTR_MASK
] & s
->regs
[R_INTR_STATUS
] &
212 if (new_irqline
!= s
->irqline
) {
213 s
->irqline
= new_irqline
;
214 qemu_set_irq(s
->irq
, s
->irqline
);
218 static void xilinx_spips_reset(DeviceState
*d
)
220 XilinxSPIPS
*s
= XILINX_SPIPS(d
);
223 for (i
= 0; i
< XLNX_SPIPS_R_MAX
; i
++) {
227 fifo8_reset(&s
->rx_fifo
);
228 fifo8_reset(&s
->rx_fifo
);
229 /* non zero resets */
230 s
->regs
[R_CONFIG
] |= MODEFAIL_GEN_EN
;
231 s
->regs
[R_SLAVE_IDLE_COUNT
] = 0xFF;
232 s
->regs
[R_TX_THRES
] = 1;
233 s
->regs
[R_RX_THRES
] = 1;
234 /* FIXME: move magic number definition somewhere sensible */
235 s
->regs
[R_MOD_ID
] = 0x01090106;
236 s
->regs
[R_LQSPI_CFG
] = R_LQSPI_CFG_RESET
;
237 s
->snoop_state
= SNOOP_CHECKING
;
238 xilinx_spips_update_ixr(s
);
239 xilinx_spips_update_cs_lines(s
);
242 /* N way (num) in place bit striper. Lay out row wise bits (LSB to MSB)
243 * column wise (from element 0 to N-1). num is the length of x, and dir
244 * reverses the direction of the transform. Best illustrated by example:
245 * Each digit in the below array is a single bit (num == 3):
247 * {{ 76543210, } ----- stripe (dir == false) -----> {{ FCheb630, }
248 * { hgfedcba, } { GDAfc741, }
249 * { HGFEDCBA, }} <---- upstripe (dir == true) ----- { HEBgda52, }}
252 static inline void stripe8(uint8_t *x
, int num
, bool dir
)
255 memset(r
, 0, sizeof(uint8_t) * num
);
260 for (idx
[0] = 0; idx
[0] < num
; ++idx
[0]) {
261 for (bit
[0] = 0; bit
[0] < 8; ++bit
[0]) {
262 r
[idx
[d
]] |= x
[idx
[!d
]] & 1 << bit
[!d
] ? 1 << bit
[d
] : 0;
263 idx
[1] = (idx
[1] + 1) % num
;
269 memcpy(x
, r
, sizeof(uint8_t) * num
);
272 static void xilinx_spips_flush_txfifo(XilinxSPIPS
*s
)
279 uint8_t tx_rx
[num_effective_busses(s
)];
281 if (fifo8_is_empty(&s
->tx_fifo
)) {
282 if (!(s
->regs
[R_LQSPI_CFG
] & LQSPI_CFG_LQ_MODE
)) {
283 s
->regs
[R_INTR_STATUS
] |= IXR_TX_FIFO_UNDERFLOW
;
285 xilinx_spips_update_ixr(s
);
287 } else if (s
->snoop_state
== SNOOP_STRIPING
) {
288 for (i
= 0; i
< num_effective_busses(s
); ++i
) {
289 tx_rx
[i
] = fifo8_pop(&s
->tx_fifo
);
291 stripe8(tx_rx
, num_effective_busses(s
), false);
293 tx
= fifo8_pop(&s
->tx_fifo
);
294 for (i
= 0; i
< num_effective_busses(s
); ++i
) {
299 for (i
= 0; i
< num_effective_busses(s
); ++i
) {
300 DB_PRINT_L(debug_level
, "tx = %02x\n", tx_rx
[i
]);
301 tx_rx
[i
] = ssi_transfer(s
->spi
[i
], (uint32_t)tx_rx
[i
]);
302 DB_PRINT_L(debug_level
, "rx = %02x\n", tx_rx
[i
]);
305 if (fifo8_is_full(&s
->rx_fifo
)) {
306 s
->regs
[R_INTR_STATUS
] |= IXR_RX_FIFO_OVERFLOW
;
307 DB_PRINT_L(0, "rx FIFO overflow");
308 } else if (s
->snoop_state
== SNOOP_STRIPING
) {
309 stripe8(tx_rx
, num_effective_busses(s
), true);
310 for (i
= 0; i
< num_effective_busses(s
); ++i
) {
311 fifo8_push(&s
->rx_fifo
, (uint8_t)tx_rx
[i
]);
314 fifo8_push(&s
->rx_fifo
, (uint8_t)tx_rx
[0]);
317 DB_PRINT_L(debug_level
, "initial snoop state: %x\n",
318 (unsigned)s
->snoop_state
);
319 switch (s
->snoop_state
) {
320 case (SNOOP_CHECKING
):
321 switch (tx
) { /* new instruction code */
322 case READ
: /* 3 address bytes, no dummy bytes/cycles */
328 case FAST_READ
: /* 3 address bytes, 1 dummy byte */
331 case DIOR
: /* FIXME: these vary between vendor - set to spansion */
334 case QIOR
: /* 3 address bytes, 2 dummy bytes */
338 s
->snoop_state
= SNOOP_NONE
;
341 case (SNOOP_STRIPING
):
343 /* Once we hit the boring stuff - squelch debug noise */
345 DB_PRINT_L(0, "squelching debug info ....\n");
352 DB_PRINT_L(debug_level
, "final snoop state: %x\n",
353 (unsigned)s
->snoop_state
);
357 static inline void rx_data_bytes(XilinxSPIPS
*s
, uint8_t *value
, int max
)
361 for (i
= 0; i
< max
&& !fifo8_is_empty(&s
->rx_fifo
); ++i
) {
362 value
[i
] = fifo8_pop(&s
->rx_fifo
);
366 static uint64_t xilinx_spips_read(void *opaque
, hwaddr addr
,
369 XilinxSPIPS
*s
= opaque
;
377 mask
= ~(R_CONFIG_RSVD
| MAN_START_COM
);
380 ret
= s
->regs
[addr
] & IXR_ALL
;
382 DB_PRINT_L(0, "addr=" TARGET_FMT_plx
" = %x\n", addr
* 4, ret
);
390 case R_SLAVE_IDLE_COUNT
:
402 memset(rx_buf
, 0, sizeof(rx_buf
));
403 rx_data_bytes(s
, rx_buf
, s
->num_txrx_bytes
);
404 ret
= s
->regs
[R_CONFIG
] & ENDIAN
? cpu_to_be32(*(uint32_t *)rx_buf
)
405 : cpu_to_le32(*(uint32_t *)rx_buf
);
406 DB_PRINT_L(0, "addr=" TARGET_FMT_plx
" = %x\n", addr
* 4, ret
);
407 xilinx_spips_update_ixr(s
);
410 DB_PRINT_L(0, "addr=" TARGET_FMT_plx
" = %x\n", addr
* 4,
411 s
->regs
[addr
] & mask
);
412 return s
->regs
[addr
] & mask
;
416 static inline void tx_data_bytes(XilinxSPIPS
*s
, uint32_t value
, int num
)
419 for (i
= 0; i
< num
&& !fifo8_is_full(&s
->tx_fifo
); ++i
) {
420 if (s
->regs
[R_CONFIG
] & ENDIAN
) {
421 fifo8_push(&s
->tx_fifo
, (uint8_t)(value
>> 24));
424 fifo8_push(&s
->tx_fifo
, (uint8_t)value
);
430 static void xilinx_spips_write(void *opaque
, hwaddr addr
,
431 uint64_t value
, unsigned size
)
434 int man_start_com
= 0;
435 XilinxSPIPS
*s
= opaque
;
437 DB_PRINT_L(0, "addr=" TARGET_FMT_plx
" = %x\n", addr
, (unsigned)value
);
441 mask
= ~(R_CONFIG_RSVD
| MAN_START_COM
);
442 if (value
& MAN_START_COM
) {
448 s
->regs
[R_INTR_STATUS
] &= ~(mask
& value
);
452 s
->regs
[R_INTR_MASK
] &= ~(mask
& value
);
456 s
->regs
[R_INTR_MASK
] |= mask
& value
;
461 case R_SLAVE_IDLE_COUNT
:
470 tx_data_bytes(s
, (uint32_t)value
, s
->num_txrx_bytes
);
473 tx_data_bytes(s
, (uint32_t)value
, 1);
476 tx_data_bytes(s
, (uint32_t)value
, 2);
479 tx_data_bytes(s
, (uint32_t)value
, 3);
482 s
->regs
[addr
] = (s
->regs
[addr
] & ~mask
) | (value
& mask
);
484 xilinx_spips_update_cs_lines(s
);
485 if ((man_start_com
&& s
->regs
[R_CONFIG
] & MAN_START_EN
) ||
486 (fifo8_is_empty(&s
->tx_fifo
) && s
->regs
[R_CONFIG
] & MAN_START_EN
)) {
487 xilinx_spips_flush_txfifo(s
);
489 xilinx_spips_update_cs_lines(s
);
490 xilinx_spips_update_ixr(s
);
493 static const MemoryRegionOps spips_ops
= {
494 .read
= xilinx_spips_read
,
495 .write
= xilinx_spips_write
,
496 .endianness
= DEVICE_LITTLE_ENDIAN
,
499 static void xilinx_qspips_write(void *opaque
, hwaddr addr
,
500 uint64_t value
, unsigned size
)
502 XilinxQSPIPS
*q
= XILINX_QSPIPS(opaque
);
504 xilinx_spips_write(opaque
, addr
, value
, size
);
507 if (addr
== R_LQSPI_CFG
) {
508 q
->lqspi_cached_addr
= ~0ULL;
512 static const MemoryRegionOps qspips_ops
= {
513 .read
= xilinx_spips_read
,
514 .write
= xilinx_qspips_write
,
515 .endianness
= DEVICE_LITTLE_ENDIAN
,
518 #define LQSPI_CACHE_SIZE 1024
521 lqspi_read(void *opaque
, hwaddr addr
, unsigned int size
)
524 XilinxQSPIPS
*q
= opaque
;
525 XilinxSPIPS
*s
= opaque
;
528 if (addr
>= q
->lqspi_cached_addr
&&
529 addr
<= q
->lqspi_cached_addr
+ LQSPI_CACHE_SIZE
- 4) {
530 uint8_t *retp
= &q
->lqspi_buf
[addr
- q
->lqspi_cached_addr
];
531 ret
= cpu_to_le32(*(uint32_t *)retp
);
532 DB_PRINT_L(1, "addr: %08x, data: %08x\n", (unsigned)addr
,
536 int flash_addr
= (addr
/ num_effective_busses(s
));
537 int slave
= flash_addr
>> LQSPI_ADDRESS_BITS
;
539 uint32_t u_page_save
= s
->regs
[R_LQSPI_STS
] & ~LQSPI_CFG_U_PAGE
;
541 s
->regs
[R_LQSPI_STS
] &= ~LQSPI_CFG_U_PAGE
;
542 s
->regs
[R_LQSPI_STS
] |= slave
? LQSPI_CFG_U_PAGE
: 0;
544 DB_PRINT_L(0, "config reg status: %08x\n", s
->regs
[R_LQSPI_CFG
]);
546 fifo8_reset(&s
->tx_fifo
);
547 fifo8_reset(&s
->rx_fifo
);
550 DB_PRINT_L(0, "pushing read instruction: %02x\n",
551 (unsigned)(uint8_t)(s
->regs
[R_LQSPI_CFG
] &
552 LQSPI_CFG_INST_CODE
));
553 fifo8_push(&s
->tx_fifo
, s
->regs
[R_LQSPI_CFG
] & LQSPI_CFG_INST_CODE
);
555 DB_PRINT_L(0, "pushing read address %06x\n", flash_addr
);
556 fifo8_push(&s
->tx_fifo
, (uint8_t)(flash_addr
>> 16));
557 fifo8_push(&s
->tx_fifo
, (uint8_t)(flash_addr
>> 8));
558 fifo8_push(&s
->tx_fifo
, (uint8_t)flash_addr
);
560 if (s
->regs
[R_LQSPI_CFG
] & LQSPI_CFG_MODE_EN
) {
561 fifo8_push(&s
->tx_fifo
, extract32(s
->regs
[R_LQSPI_CFG
],
562 LQSPI_CFG_MODE_SHIFT
,
563 LQSPI_CFG_MODE_WIDTH
));
566 for (i
= 0; i
< (extract32(s
->regs
[R_LQSPI_CFG
], LQSPI_CFG_DUMMY_SHIFT
,
567 LQSPI_CFG_DUMMY_WIDTH
)); ++i
) {
568 DB_PRINT_L(0, "pushing dummy byte\n");
569 fifo8_push(&s
->tx_fifo
, 0);
571 xilinx_spips_update_cs_lines(s
);
572 xilinx_spips_flush_txfifo(s
);
573 fifo8_reset(&s
->rx_fifo
);
575 DB_PRINT_L(0, "starting QSPI data read\n");
577 while (cache_entry
< LQSPI_CACHE_SIZE
) {
578 for (i
= 0; i
< 64; ++i
) {
579 tx_data_bytes(s
, 0, 1);
581 xilinx_spips_flush_txfifo(s
);
582 for (i
= 0; i
< 64; ++i
) {
583 rx_data_bytes(s
, &q
->lqspi_buf
[cache_entry
++], 1);
587 s
->regs
[R_LQSPI_STS
] &= ~LQSPI_CFG_U_PAGE
;
588 s
->regs
[R_LQSPI_STS
] |= u_page_save
;
589 xilinx_spips_update_cs_lines(s
);
591 q
->lqspi_cached_addr
= flash_addr
* num_effective_busses(s
);
592 return lqspi_read(opaque
, addr
, size
);
596 static const MemoryRegionOps lqspi_ops
= {
598 .endianness
= DEVICE_NATIVE_ENDIAN
,
600 .min_access_size
= 1,
605 static void xilinx_spips_realize(DeviceState
*dev
, Error
**errp
)
607 XilinxSPIPS
*s
= XILINX_SPIPS(dev
);
608 SysBusDevice
*sbd
= SYS_BUS_DEVICE(dev
);
609 XilinxSPIPSClass
*xsc
= XILINX_SPIPS_GET_CLASS(s
);
613 DB_PRINT_L(0, "realized spips\n");
615 s
->spi
= g_new(SSIBus
*, s
->num_busses
);
616 for (i
= 0; i
< s
->num_busses
; ++i
) {
618 snprintf(bus_name
, 16, "spi%d", i
);
619 s
->spi
[i
] = ssi_create_bus(dev
, bus_name
);
622 s
->cs_lines
= g_new0(qemu_irq
, s
->num_cs
* s
->num_busses
);
623 for (i
= 0, cs
= s
->cs_lines
; i
< s
->num_busses
; ++i
, cs
+= s
->num_cs
) {
624 ssi_auto_connect_slaves(DEVICE(s
), cs
, s
->spi
[i
]);
627 sysbus_init_irq(sbd
, &s
->irq
);
628 for (i
= 0; i
< s
->num_cs
* s
->num_busses
; ++i
) {
629 sysbus_init_irq(sbd
, &s
->cs_lines
[i
]);
632 memory_region_init_io(&s
->iomem
, OBJECT(s
), xsc
->reg_ops
, s
,
633 "spi", XLNX_SPIPS_R_MAX
* 4);
634 sysbus_init_mmio(sbd
, &s
->iomem
);
638 fifo8_create(&s
->rx_fifo
, xsc
->rx_fifo_size
);
639 fifo8_create(&s
->tx_fifo
, xsc
->tx_fifo_size
);
642 static void xilinx_qspips_realize(DeviceState
*dev
, Error
**errp
)
644 XilinxSPIPS
*s
= XILINX_SPIPS(dev
);
645 XilinxQSPIPS
*q
= XILINX_QSPIPS(dev
);
646 SysBusDevice
*sbd
= SYS_BUS_DEVICE(dev
);
648 DB_PRINT_L(0, "realized qspips\n");
652 s
->num_txrx_bytes
= 4;
654 xilinx_spips_realize(dev
, errp
);
655 memory_region_init_io(&s
->mmlqspi
, OBJECT(s
), &lqspi_ops
, s
, "lqspi",
656 (1 << LQSPI_ADDRESS_BITS
) * 2);
657 sysbus_init_mmio(sbd
, &s
->mmlqspi
);
659 q
->lqspi_cached_addr
= ~0ULL;
662 static int xilinx_spips_post_load(void *opaque
, int version_id
)
664 xilinx_spips_update_ixr((XilinxSPIPS
*)opaque
);
665 xilinx_spips_update_cs_lines((XilinxSPIPS
*)opaque
);
669 static const VMStateDescription vmstate_xilinx_spips
= {
670 .name
= "xilinx_spips",
672 .minimum_version_id
= 2,
673 .post_load
= xilinx_spips_post_load
,
674 .fields
= (VMStateField
[]) {
675 VMSTATE_FIFO8(tx_fifo
, XilinxSPIPS
),
676 VMSTATE_FIFO8(rx_fifo
, XilinxSPIPS
),
677 VMSTATE_UINT32_ARRAY(regs
, XilinxSPIPS
, XLNX_SPIPS_R_MAX
),
678 VMSTATE_UINT8(snoop_state
, XilinxSPIPS
),
679 VMSTATE_END_OF_LIST()
683 static Property xilinx_spips_properties
[] = {
684 DEFINE_PROP_UINT8("num-busses", XilinxSPIPS
, num_busses
, 1),
685 DEFINE_PROP_UINT8("num-ss-bits", XilinxSPIPS
, num_cs
, 4),
686 DEFINE_PROP_UINT8("num-txrx-bytes", XilinxSPIPS
, num_txrx_bytes
, 1),
687 DEFINE_PROP_END_OF_LIST(),
690 static void xilinx_qspips_class_init(ObjectClass
*klass
, void * data
)
692 DeviceClass
*dc
= DEVICE_CLASS(klass
);
693 XilinxSPIPSClass
*xsc
= XILINX_SPIPS_CLASS(klass
);
695 dc
->realize
= xilinx_qspips_realize
;
696 xsc
->reg_ops
= &qspips_ops
;
697 xsc
->rx_fifo_size
= RXFF_A_Q
;
698 xsc
->tx_fifo_size
= TXFF_A_Q
;
701 static void xilinx_spips_class_init(ObjectClass
*klass
, void *data
)
703 DeviceClass
*dc
= DEVICE_CLASS(klass
);
704 XilinxSPIPSClass
*xsc
= XILINX_SPIPS_CLASS(klass
);
706 dc
->realize
= xilinx_spips_realize
;
707 dc
->reset
= xilinx_spips_reset
;
708 dc
->props
= xilinx_spips_properties
;
709 dc
->vmsd
= &vmstate_xilinx_spips
;
711 xsc
->reg_ops
= &spips_ops
;
712 xsc
->rx_fifo_size
= RXFF_A
;
713 xsc
->tx_fifo_size
= TXFF_A
;
716 static const TypeInfo xilinx_spips_info
= {
717 .name
= TYPE_XILINX_SPIPS
,
718 .parent
= TYPE_SYS_BUS_DEVICE
,
719 .instance_size
= sizeof(XilinxSPIPS
),
720 .class_init
= xilinx_spips_class_init
,
721 .class_size
= sizeof(XilinxSPIPSClass
),
724 static const TypeInfo xilinx_qspips_info
= {
725 .name
= TYPE_XILINX_QSPIPS
,
726 .parent
= TYPE_XILINX_SPIPS
,
727 .instance_size
= sizeof(XilinxQSPIPS
),
728 .class_init
= xilinx_qspips_class_init
,
731 static void xilinx_spips_register_types(void)
733 type_register_static(&xilinx_spips_info
);
734 type_register_static(&xilinx_qspips_info
);
737 type_init(xilinx_spips_register_types
)