root / hw / xilinx_spips.c @ 6a659bbf
History | View | Annotate | Download (17.1 kB)
1 | 94befa45 | Peter A. G. Crosthwaite | /*
|
---|---|---|---|
2 | 94befa45 | Peter A. G. Crosthwaite | * QEMU model of the Xilinx Zynq SPI controller
|
3 | 94befa45 | Peter A. G. Crosthwaite | *
|
4 | 94befa45 | Peter A. G. Crosthwaite | * Copyright (c) 2012 Peter A. G. Crosthwaite
|
5 | 94befa45 | Peter A. G. Crosthwaite | *
|
6 | 94befa45 | Peter A. G. Crosthwaite | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 94befa45 | Peter A. G. Crosthwaite | * of this software and associated documentation files (the "Software"), to deal
|
8 | 94befa45 | Peter A. G. Crosthwaite | * in the Software without restriction, including without limitation the rights
|
9 | 94befa45 | Peter A. G. Crosthwaite | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 94befa45 | Peter A. G. Crosthwaite | * copies of the Software, and to permit persons to whom the Software is
|
11 | 94befa45 | Peter A. G. Crosthwaite | * furnished to do so, subject to the following conditions:
|
12 | 94befa45 | Peter A. G. Crosthwaite | *
|
13 | 94befa45 | Peter A. G. Crosthwaite | * The above copyright notice and this permission notice shall be included in
|
14 | 94befa45 | Peter A. G. Crosthwaite | * all copies or substantial portions of the Software.
|
15 | 94befa45 | Peter A. G. Crosthwaite | *
|
16 | 94befa45 | Peter A. G. Crosthwaite | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 94befa45 | Peter A. G. Crosthwaite | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 94befa45 | Peter A. G. Crosthwaite | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 94befa45 | Peter A. G. Crosthwaite | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 94befa45 | Peter A. G. Crosthwaite | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 94befa45 | Peter A. G. Crosthwaite | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 94befa45 | Peter A. G. Crosthwaite | * THE SOFTWARE.
|
23 | 94befa45 | Peter A. G. Crosthwaite | */
|
24 | 94befa45 | Peter A. G. Crosthwaite | |
25 | 94befa45 | Peter A. G. Crosthwaite | #include "sysbus.h" |
26 | 9c17d615 | Paolo Bonzini | #include "sysemu/sysemu.h" |
27 | 94befa45 | Peter A. G. Crosthwaite | #include "ptimer.h" |
28 | 1de7afc9 | Paolo Bonzini | #include "qemu/log.h" |
29 | 94befa45 | Peter A. G. Crosthwaite | #include "fifo.h" |
30 | 94befa45 | Peter A. G. Crosthwaite | #include "ssi.h" |
31 | 1de7afc9 | Paolo Bonzini | #include "qemu/bitops.h" |
32 | 94befa45 | Peter A. G. Crosthwaite | |
33 | 94befa45 | Peter A. G. Crosthwaite | #ifdef XILINX_SPIPS_ERR_DEBUG
|
34 | 94befa45 | Peter A. G. Crosthwaite | #define DB_PRINT(...) do { \ |
35 | 94befa45 | Peter A. G. Crosthwaite | fprintf(stderr, ": %s: ", __func__); \
|
36 | 94befa45 | Peter A. G. Crosthwaite | fprintf(stderr, ## __VA_ARGS__); \ |
37 | 94befa45 | Peter A. G. Crosthwaite | } while (0); |
38 | 94befa45 | Peter A. G. Crosthwaite | #else
|
39 | 94befa45 | Peter A. G. Crosthwaite | #define DB_PRINT(...)
|
40 | 94befa45 | Peter A. G. Crosthwaite | #endif
|
41 | 94befa45 | Peter A. G. Crosthwaite | |
42 | 94befa45 | Peter A. G. Crosthwaite | /* config register */
|
43 | 94befa45 | Peter A. G. Crosthwaite | #define R_CONFIG (0x00 / 4) |
44 | f1241144 | Peter Crosthwaite | #define IFMODE (1 << 31) |
45 | f1241144 | Peter Crosthwaite | #define ENDIAN (1 << 26) |
46 | 94befa45 | Peter A. G. Crosthwaite | #define MODEFAIL_GEN_EN (1 << 17) |
47 | 94befa45 | Peter A. G. Crosthwaite | #define MAN_START_COM (1 << 16) |
48 | 94befa45 | Peter A. G. Crosthwaite | #define MAN_START_EN (1 << 15) |
49 | 94befa45 | Peter A. G. Crosthwaite | #define MANUAL_CS (1 << 14) |
50 | 94befa45 | Peter A. G. Crosthwaite | #define CS (0xF << 10) |
51 | 94befa45 | Peter A. G. Crosthwaite | #define CS_SHIFT (10) |
52 | 94befa45 | Peter A. G. Crosthwaite | #define PERI_SEL (1 << 9) |
53 | 94befa45 | Peter A. G. Crosthwaite | #define REF_CLK (1 << 8) |
54 | 94befa45 | Peter A. G. Crosthwaite | #define FIFO_WIDTH (3 << 6) |
55 | 94befa45 | Peter A. G. Crosthwaite | #define BAUD_RATE_DIV (7 << 3) |
56 | 94befa45 | Peter A. G. Crosthwaite | #define CLK_PH (1 << 2) |
57 | 94befa45 | Peter A. G. Crosthwaite | #define CLK_POL (1 << 1) |
58 | 94befa45 | Peter A. G. Crosthwaite | #define MODE_SEL (1 << 0) |
59 | 94befa45 | Peter A. G. Crosthwaite | |
60 | 94befa45 | Peter A. G. Crosthwaite | /* interrupt mechanism */
|
61 | 94befa45 | Peter A. G. Crosthwaite | #define R_INTR_STATUS (0x04 / 4) |
62 | 94befa45 | Peter A. G. Crosthwaite | #define R_INTR_EN (0x08 / 4) |
63 | 94befa45 | Peter A. G. Crosthwaite | #define R_INTR_DIS (0x0C / 4) |
64 | 94befa45 | Peter A. G. Crosthwaite | #define R_INTR_MASK (0x10 / 4) |
65 | 94befa45 | Peter A. G. Crosthwaite | #define IXR_TX_FIFO_UNDERFLOW (1 << 6) |
66 | 94befa45 | Peter A. G. Crosthwaite | #define IXR_RX_FIFO_FULL (1 << 5) |
67 | 94befa45 | Peter A. G. Crosthwaite | #define IXR_RX_FIFO_NOT_EMPTY (1 << 4) |
68 | 94befa45 | Peter A. G. Crosthwaite | #define IXR_TX_FIFO_FULL (1 << 3) |
69 | 94befa45 | Peter A. G. Crosthwaite | #define IXR_TX_FIFO_NOT_FULL (1 << 2) |
70 | 94befa45 | Peter A. G. Crosthwaite | #define IXR_TX_FIFO_MODE_FAIL (1 << 1) |
71 | 94befa45 | Peter A. G. Crosthwaite | #define IXR_RX_FIFO_OVERFLOW (1 << 0) |
72 | 94befa45 | Peter A. G. Crosthwaite | #define IXR_ALL ((IXR_TX_FIFO_UNDERFLOW<<1)-1) |
73 | 94befa45 | Peter A. G. Crosthwaite | |
74 | 94befa45 | Peter A. G. Crosthwaite | #define R_EN (0x14 / 4) |
75 | 94befa45 | Peter A. G. Crosthwaite | #define R_DELAY (0x18 / 4) |
76 | 94befa45 | Peter A. G. Crosthwaite | #define R_TX_DATA (0x1C / 4) |
77 | 94befa45 | Peter A. G. Crosthwaite | #define R_RX_DATA (0x20 / 4) |
78 | 94befa45 | Peter A. G. Crosthwaite | #define R_SLAVE_IDLE_COUNT (0x24 / 4) |
79 | 94befa45 | Peter A. G. Crosthwaite | #define R_TX_THRES (0x28 / 4) |
80 | 94befa45 | Peter A. G. Crosthwaite | #define R_RX_THRES (0x2C / 4) |
81 | f1241144 | Peter Crosthwaite | #define R_TXD1 (0x80 / 4) |
82 | f1241144 | Peter Crosthwaite | #define R_TXD2 (0x84 / 4) |
83 | f1241144 | Peter Crosthwaite | #define R_TXD3 (0x88 / 4) |
84 | f1241144 | Peter Crosthwaite | |
85 | f1241144 | Peter Crosthwaite | #define R_LQSPI_CFG (0xa0 / 4) |
86 | f1241144 | Peter Crosthwaite | #define R_LQSPI_CFG_RESET 0x03A002EB |
87 | f1241144 | Peter Crosthwaite | #define LQSPI_CFG_LQ_MODE (1 << 31) |
88 | f1241144 | Peter Crosthwaite | #define LQSPI_CFG_TWO_MEM (1 << 30) |
89 | f1241144 | Peter Crosthwaite | #define LQSPI_CFG_SEP_BUS (1 << 30) |
90 | f1241144 | Peter Crosthwaite | #define LQSPI_CFG_U_PAGE (1 << 28) |
91 | f1241144 | Peter Crosthwaite | #define LQSPI_CFG_MODE_EN (1 << 25) |
92 | f1241144 | Peter Crosthwaite | #define LQSPI_CFG_MODE_WIDTH 8 |
93 | f1241144 | Peter Crosthwaite | #define LQSPI_CFG_MODE_SHIFT 16 |
94 | f1241144 | Peter Crosthwaite | #define LQSPI_CFG_DUMMY_WIDTH 3 |
95 | f1241144 | Peter Crosthwaite | #define LQSPI_CFG_DUMMY_SHIFT 8 |
96 | f1241144 | Peter Crosthwaite | #define LQSPI_CFG_INST_CODE 0xFF |
97 | f1241144 | Peter Crosthwaite | |
98 | f1241144 | Peter Crosthwaite | #define R_LQSPI_STS (0xA4 / 4) |
99 | f1241144 | Peter Crosthwaite | #define LQSPI_STS_WR_RECVD (1 << 1) |
100 | f1241144 | Peter Crosthwaite | |
101 | 94befa45 | Peter A. G. Crosthwaite | #define R_MOD_ID (0xFC / 4) |
102 | 94befa45 | Peter A. G. Crosthwaite | |
103 | 94befa45 | Peter A. G. Crosthwaite | #define R_MAX (R_MOD_ID+1) |
104 | 94befa45 | Peter A. G. Crosthwaite | |
105 | 94befa45 | Peter A. G. Crosthwaite | /* size of TXRX FIFOs */
|
106 | 94befa45 | Peter A. G. Crosthwaite | #define RXFF_A 32 |
107 | 94befa45 | Peter A. G. Crosthwaite | #define TXFF_A 32 |
108 | 94befa45 | Peter A. G. Crosthwaite | |
109 | f1241144 | Peter Crosthwaite | /* 16MB per linear region */
|
110 | f1241144 | Peter Crosthwaite | #define LQSPI_ADDRESS_BITS 24 |
111 | f1241144 | Peter Crosthwaite | /* Bite off 4k chunks at a time */
|
112 | f1241144 | Peter Crosthwaite | #define LQSPI_CACHE_SIZE 1024 |
113 | f1241144 | Peter Crosthwaite | |
114 | f1241144 | Peter Crosthwaite | #define SNOOP_CHECKING 0xFF |
115 | f1241144 | Peter Crosthwaite | #define SNOOP_NONE 0xFE |
116 | f1241144 | Peter Crosthwaite | #define SNOOP_STRIPING 0 |
117 | f1241144 | Peter Crosthwaite | |
118 | 94befa45 | Peter A. G. Crosthwaite | typedef struct { |
119 | 94befa45 | Peter A. G. Crosthwaite | SysBusDevice busdev; |
120 | 94befa45 | Peter A. G. Crosthwaite | MemoryRegion iomem; |
121 | f1241144 | Peter Crosthwaite | MemoryRegion mmlqspi; |
122 | f1241144 | Peter Crosthwaite | |
123 | 94befa45 | Peter A. G. Crosthwaite | qemu_irq irq; |
124 | 94befa45 | Peter A. G. Crosthwaite | int irqline;
|
125 | 94befa45 | Peter A. G. Crosthwaite | |
126 | f1241144 | Peter Crosthwaite | uint8_t num_cs; |
127 | f1241144 | Peter Crosthwaite | uint8_t num_busses; |
128 | f1241144 | Peter Crosthwaite | |
129 | f1241144 | Peter Crosthwaite | uint8_t snoop_state; |
130 | f1241144 | Peter Crosthwaite | qemu_irq *cs_lines; |
131 | f1241144 | Peter Crosthwaite | SSIBus **spi; |
132 | 94befa45 | Peter A. G. Crosthwaite | |
133 | 94befa45 | Peter A. G. Crosthwaite | Fifo8 rx_fifo; |
134 | 94befa45 | Peter A. G. Crosthwaite | Fifo8 tx_fifo; |
135 | 94befa45 | Peter A. G. Crosthwaite | |
136 | f1241144 | Peter Crosthwaite | uint8_t num_txrx_bytes; |
137 | f1241144 | Peter Crosthwaite | |
138 | 94befa45 | Peter A. G. Crosthwaite | uint32_t regs[R_MAX]; |
139 | f1241144 | Peter Crosthwaite | |
140 | f1241144 | Peter Crosthwaite | uint32_t lqspi_buf[LQSPI_CACHE_SIZE]; |
141 | f1241144 | Peter Crosthwaite | hwaddr lqspi_cached_addr; |
142 | 94befa45 | Peter A. G. Crosthwaite | } XilinxSPIPS; |
143 | 94befa45 | Peter A. G. Crosthwaite | |
144 | f1241144 | Peter Crosthwaite | static inline int num_effective_busses(XilinxSPIPS *s) |
145 | f1241144 | Peter Crosthwaite | { |
146 | f1241144 | Peter Crosthwaite | return (s->regs[R_LQSPI_STS] & LQSPI_CFG_SEP_BUS &&
|
147 | f1241144 | Peter Crosthwaite | s->regs[R_LQSPI_STS] & LQSPI_CFG_TWO_MEM) ? s->num_busses : 1;
|
148 | f1241144 | Peter Crosthwaite | } |
149 | f1241144 | Peter Crosthwaite | |
150 | 94befa45 | Peter A. G. Crosthwaite | static void xilinx_spips_update_cs_lines(XilinxSPIPS *s) |
151 | 94befa45 | Peter A. G. Crosthwaite | { |
152 | f1241144 | Peter Crosthwaite | int i, j;
|
153 | 94befa45 | Peter A. G. Crosthwaite | bool found = false; |
154 | 94befa45 | Peter A. G. Crosthwaite | int field = s->regs[R_CONFIG] >> CS_SHIFT;
|
155 | 94befa45 | Peter A. G. Crosthwaite | |
156 | f1241144 | Peter Crosthwaite | for (i = 0; i < s->num_cs; i++) { |
157 | f1241144 | Peter Crosthwaite | for (j = 0; j < num_effective_busses(s); j++) { |
158 | f1241144 | Peter Crosthwaite | int upage = !!(s->regs[R_LQSPI_STS] & LQSPI_CFG_U_PAGE);
|
159 | f1241144 | Peter Crosthwaite | int cs_to_set = (j * s->num_cs + i + upage) %
|
160 | f1241144 | Peter Crosthwaite | (s->num_cs * s->num_busses); |
161 | f1241144 | Peter Crosthwaite | |
162 | f1241144 | Peter Crosthwaite | if (~field & (1 << i) && !found) { |
163 | f1241144 | Peter Crosthwaite | DB_PRINT("selecting slave %d\n", i);
|
164 | f1241144 | Peter Crosthwaite | qemu_set_irq(s->cs_lines[cs_to_set], 0);
|
165 | f1241144 | Peter Crosthwaite | } else {
|
166 | f1241144 | Peter Crosthwaite | qemu_set_irq(s->cs_lines[cs_to_set], 1);
|
167 | f1241144 | Peter Crosthwaite | } |
168 | f1241144 | Peter Crosthwaite | } |
169 | f1241144 | Peter Crosthwaite | if (~field & (1 << i)) { |
170 | 94befa45 | Peter A. G. Crosthwaite | found = true;
|
171 | 94befa45 | Peter A. G. Crosthwaite | } |
172 | f1241144 | Peter Crosthwaite | } |
173 | f1241144 | Peter Crosthwaite | if (!found) {
|
174 | f1241144 | Peter Crosthwaite | s->snoop_state = SNOOP_CHECKING; |
175 | f1241144 | Peter Crosthwaite | } |
176 | 94befa45 | Peter A. G. Crosthwaite | } |
177 | 94befa45 | Peter A. G. Crosthwaite | |
178 | 94befa45 | Peter A. G. Crosthwaite | static void xilinx_spips_update_ixr(XilinxSPIPS *s) |
179 | 94befa45 | Peter A. G. Crosthwaite | { |
180 | 94befa45 | Peter A. G. Crosthwaite | /* These are set/cleared as they occur */
|
181 | 94befa45 | Peter A. G. Crosthwaite | s->regs[R_INTR_STATUS] &= (IXR_TX_FIFO_UNDERFLOW | IXR_RX_FIFO_OVERFLOW | |
182 | 94befa45 | Peter A. G. Crosthwaite | IXR_TX_FIFO_MODE_FAIL); |
183 | 94befa45 | Peter A. G. Crosthwaite | /* these are pure functions of fifo state, set them here */
|
184 | 94befa45 | Peter A. G. Crosthwaite | s->regs[R_INTR_STATUS] |= |
185 | 94befa45 | Peter A. G. Crosthwaite | (fifo8_is_full(&s->rx_fifo) ? IXR_RX_FIFO_FULL : 0) |
|
186 | 94befa45 | Peter A. G. Crosthwaite | (s->rx_fifo.num >= s->regs[R_RX_THRES] ? IXR_RX_FIFO_NOT_EMPTY : 0) |
|
187 | 94befa45 | Peter A. G. Crosthwaite | (fifo8_is_full(&s->tx_fifo) ? IXR_TX_FIFO_FULL : 0) |
|
188 | 94befa45 | Peter A. G. Crosthwaite | (s->tx_fifo.num < s->regs[R_TX_THRES] ? IXR_TX_FIFO_NOT_FULL : 0);
|
189 | 94befa45 | Peter A. G. Crosthwaite | /* drive external interrupt pin */
|
190 | 94befa45 | Peter A. G. Crosthwaite | int new_irqline = !!(s->regs[R_INTR_MASK] & s->regs[R_INTR_STATUS] &
|
191 | 94befa45 | Peter A. G. Crosthwaite | IXR_ALL); |
192 | 94befa45 | Peter A. G. Crosthwaite | if (new_irqline != s->irqline) {
|
193 | 94befa45 | Peter A. G. Crosthwaite | s->irqline = new_irqline; |
194 | 94befa45 | Peter A. G. Crosthwaite | qemu_set_irq(s->irq, s->irqline); |
195 | 94befa45 | Peter A. G. Crosthwaite | } |
196 | 94befa45 | Peter A. G. Crosthwaite | } |
197 | 94befa45 | Peter A. G. Crosthwaite | |
198 | 94befa45 | Peter A. G. Crosthwaite | static void xilinx_spips_reset(DeviceState *d) |
199 | 94befa45 | Peter A. G. Crosthwaite | { |
200 | 94befa45 | Peter A. G. Crosthwaite | XilinxSPIPS *s = DO_UPCAST(XilinxSPIPS, busdev.qdev, d); |
201 | 94befa45 | Peter A. G. Crosthwaite | |
202 | 94befa45 | Peter A. G. Crosthwaite | int i;
|
203 | 94befa45 | Peter A. G. Crosthwaite | for (i = 0; i < R_MAX; i++) { |
204 | 94befa45 | Peter A. G. Crosthwaite | s->regs[i] = 0;
|
205 | 94befa45 | Peter A. G. Crosthwaite | } |
206 | 94befa45 | Peter A. G. Crosthwaite | |
207 | 94befa45 | Peter A. G. Crosthwaite | fifo8_reset(&s->rx_fifo); |
208 | 94befa45 | Peter A. G. Crosthwaite | fifo8_reset(&s->rx_fifo); |
209 | 94befa45 | Peter A. G. Crosthwaite | /* non zero resets */
|
210 | 94befa45 | Peter A. G. Crosthwaite | s->regs[R_CONFIG] |= MODEFAIL_GEN_EN; |
211 | 94befa45 | Peter A. G. Crosthwaite | s->regs[R_SLAVE_IDLE_COUNT] = 0xFF;
|
212 | 94befa45 | Peter A. G. Crosthwaite | s->regs[R_TX_THRES] = 1;
|
213 | 94befa45 | Peter A. G. Crosthwaite | s->regs[R_RX_THRES] = 1;
|
214 | 94befa45 | Peter A. G. Crosthwaite | /* FIXME: move magic number definition somewhere sensible */
|
215 | 94befa45 | Peter A. G. Crosthwaite | s->regs[R_MOD_ID] = 0x01090106;
|
216 | f1241144 | Peter Crosthwaite | s->regs[R_LQSPI_CFG] = R_LQSPI_CFG_RESET; |
217 | f1241144 | Peter Crosthwaite | s->snoop_state = SNOOP_CHECKING; |
218 | 94befa45 | Peter A. G. Crosthwaite | xilinx_spips_update_ixr(s); |
219 | 94befa45 | Peter A. G. Crosthwaite | xilinx_spips_update_cs_lines(s); |
220 | 94befa45 | Peter A. G. Crosthwaite | } |
221 | 94befa45 | Peter A. G. Crosthwaite | |
222 | 94befa45 | Peter A. G. Crosthwaite | static void xilinx_spips_flush_txfifo(XilinxSPIPS *s) |
223 | 94befa45 | Peter A. G. Crosthwaite | { |
224 | 94befa45 | Peter A. G. Crosthwaite | for (;;) {
|
225 | f1241144 | Peter Crosthwaite | int i;
|
226 | f1241144 | Peter Crosthwaite | uint8_t rx; |
227 | f1241144 | Peter Crosthwaite | uint8_t tx = 0;
|
228 | f1241144 | Peter Crosthwaite | |
229 | f1241144 | Peter Crosthwaite | for (i = 0; i < num_effective_busses(s); ++i) { |
230 | f1241144 | Peter Crosthwaite | if (!i || s->snoop_state == SNOOP_STRIPING) {
|
231 | f1241144 | Peter Crosthwaite | if (fifo8_is_empty(&s->tx_fifo)) {
|
232 | f1241144 | Peter Crosthwaite | s->regs[R_INTR_STATUS] |= IXR_TX_FIFO_UNDERFLOW; |
233 | f1241144 | Peter Crosthwaite | xilinx_spips_update_ixr(s); |
234 | f1241144 | Peter Crosthwaite | return;
|
235 | f1241144 | Peter Crosthwaite | } else {
|
236 | f1241144 | Peter Crosthwaite | tx = fifo8_pop(&s->tx_fifo); |
237 | f1241144 | Peter Crosthwaite | } |
238 | f1241144 | Peter Crosthwaite | } |
239 | f1241144 | Peter Crosthwaite | rx = ssi_transfer(s->spi[i], (uint32_t)tx); |
240 | f1241144 | Peter Crosthwaite | DB_PRINT("tx = %02x rx = %02x\n", tx, rx);
|
241 | f1241144 | Peter Crosthwaite | if (!i || s->snoop_state == SNOOP_STRIPING) {
|
242 | f1241144 | Peter Crosthwaite | if (fifo8_is_full(&s->rx_fifo)) {
|
243 | f1241144 | Peter Crosthwaite | s->regs[R_INTR_STATUS] |= IXR_RX_FIFO_OVERFLOW; |
244 | f1241144 | Peter Crosthwaite | DB_PRINT("rx FIFO overflow");
|
245 | f1241144 | Peter Crosthwaite | } else {
|
246 | f1241144 | Peter Crosthwaite | fifo8_push(&s->rx_fifo, (uint8_t)rx); |
247 | f1241144 | Peter Crosthwaite | } |
248 | f1241144 | Peter Crosthwaite | } |
249 | f1241144 | Peter Crosthwaite | } |
250 | 94befa45 | Peter A. G. Crosthwaite | |
251 | f1241144 | Peter Crosthwaite | switch (s->snoop_state) {
|
252 | f1241144 | Peter Crosthwaite | case (SNOOP_CHECKING):
|
253 | f1241144 | Peter Crosthwaite | switch (tx) { /* new instruction code */ |
254 | f1241144 | Peter Crosthwaite | case 0x0b: /* dual/quad output read DOR/QOR */ |
255 | f1241144 | Peter Crosthwaite | case 0x6b: |
256 | f1241144 | Peter Crosthwaite | s->snoop_state = 4;
|
257 | f1241144 | Peter Crosthwaite | break;
|
258 | f1241144 | Peter Crosthwaite | /* FIXME: these vary between vendor - set to spansion */
|
259 | f1241144 | Peter Crosthwaite | case 0xbb: /* high performance dual read DIOR */ |
260 | f1241144 | Peter Crosthwaite | s->snoop_state = 4;
|
261 | f1241144 | Peter Crosthwaite | break;
|
262 | f1241144 | Peter Crosthwaite | case 0xeb: /* high performance quad read QIOR */ |
263 | f1241144 | Peter Crosthwaite | s->snoop_state = 6;
|
264 | f1241144 | Peter Crosthwaite | break;
|
265 | f1241144 | Peter Crosthwaite | default:
|
266 | f1241144 | Peter Crosthwaite | s->snoop_state = SNOOP_NONE; |
267 | f1241144 | Peter Crosthwaite | } |
268 | 94befa45 | Peter A. G. Crosthwaite | break;
|
269 | f1241144 | Peter Crosthwaite | case (SNOOP_STRIPING):
|
270 | f1241144 | Peter Crosthwaite | case (SNOOP_NONE):
|
271 | f1241144 | Peter Crosthwaite | break;
|
272 | f1241144 | Peter Crosthwaite | default:
|
273 | f1241144 | Peter Crosthwaite | s->snoop_state--; |
274 | 94befa45 | Peter A. G. Crosthwaite | } |
275 | f1241144 | Peter Crosthwaite | } |
276 | f1241144 | Peter Crosthwaite | } |
277 | 94befa45 | Peter A. G. Crosthwaite | |
278 | f1241144 | Peter Crosthwaite | static inline void rx_data_bytes(XilinxSPIPS *s, uint32_t *value, int max) |
279 | f1241144 | Peter Crosthwaite | { |
280 | f1241144 | Peter Crosthwaite | int i;
|
281 | f1241144 | Peter Crosthwaite | |
282 | f1241144 | Peter Crosthwaite | *value = 0;
|
283 | f1241144 | Peter Crosthwaite | for (i = 0; i < max && !fifo8_is_empty(&s->rx_fifo); ++i) { |
284 | f1241144 | Peter Crosthwaite | uint32_t next = fifo8_pop(&s->rx_fifo) & 0xFF;
|
285 | f1241144 | Peter Crosthwaite | *value |= next << 8 * (s->regs[R_CONFIG] & ENDIAN ? 3-i : i); |
286 | 94befa45 | Peter A. G. Crosthwaite | } |
287 | 94befa45 | Peter A. G. Crosthwaite | } |
288 | 94befa45 | Peter A. G. Crosthwaite | |
289 | a8170e5e | Avi Kivity | static uint64_t xilinx_spips_read(void *opaque, hwaddr addr, |
290 | 94befa45 | Peter A. G. Crosthwaite | unsigned size)
|
291 | 94befa45 | Peter A. G. Crosthwaite | { |
292 | 94befa45 | Peter A. G. Crosthwaite | XilinxSPIPS *s = opaque; |
293 | 94befa45 | Peter A. G. Crosthwaite | uint32_t mask = ~0;
|
294 | 94befa45 | Peter A. G. Crosthwaite | uint32_t ret; |
295 | 94befa45 | Peter A. G. Crosthwaite | |
296 | 94befa45 | Peter A. G. Crosthwaite | addr >>= 2;
|
297 | 94befa45 | Peter A. G. Crosthwaite | switch (addr) {
|
298 | 94befa45 | Peter A. G. Crosthwaite | case R_CONFIG:
|
299 | 94befa45 | Peter A. G. Crosthwaite | mask = 0x0002FFFF;
|
300 | 94befa45 | Peter A. G. Crosthwaite | break;
|
301 | 94befa45 | Peter A. G. Crosthwaite | case R_INTR_STATUS:
|
302 | 94befa45 | Peter A. G. Crosthwaite | case R_INTR_MASK:
|
303 | 94befa45 | Peter A. G. Crosthwaite | mask = IXR_ALL; |
304 | 94befa45 | Peter A. G. Crosthwaite | break;
|
305 | 94befa45 | Peter A. G. Crosthwaite | case R_EN:
|
306 | 94befa45 | Peter A. G. Crosthwaite | mask = 0x1;
|
307 | 94befa45 | Peter A. G. Crosthwaite | break;
|
308 | 94befa45 | Peter A. G. Crosthwaite | case R_SLAVE_IDLE_COUNT:
|
309 | 94befa45 | Peter A. G. Crosthwaite | mask = 0xFF;
|
310 | 94befa45 | Peter A. G. Crosthwaite | break;
|
311 | 94befa45 | Peter A. G. Crosthwaite | case R_MOD_ID:
|
312 | 94befa45 | Peter A. G. Crosthwaite | mask = 0x01FFFFFF;
|
313 | 94befa45 | Peter A. G. Crosthwaite | break;
|
314 | 94befa45 | Peter A. G. Crosthwaite | case R_INTR_EN:
|
315 | 94befa45 | Peter A. G. Crosthwaite | case R_INTR_DIS:
|
316 | 94befa45 | Peter A. G. Crosthwaite | case R_TX_DATA:
|
317 | 94befa45 | Peter A. G. Crosthwaite | mask = 0;
|
318 | 94befa45 | Peter A. G. Crosthwaite | break;
|
319 | 94befa45 | Peter A. G. Crosthwaite | case R_RX_DATA:
|
320 | f1241144 | Peter Crosthwaite | rx_data_bytes(s, &ret, s->num_txrx_bytes); |
321 | 94befa45 | Peter A. G. Crosthwaite | DB_PRINT("addr=" TARGET_FMT_plx " = %x\n", addr * 4, ret); |
322 | 94befa45 | Peter A. G. Crosthwaite | xilinx_spips_update_ixr(s); |
323 | 94befa45 | Peter A. G. Crosthwaite | return ret;
|
324 | 94befa45 | Peter A. G. Crosthwaite | } |
325 | 94befa45 | Peter A. G. Crosthwaite | DB_PRINT("addr=" TARGET_FMT_plx " = %x\n", addr * 4, s->regs[addr] & mask); |
326 | 94befa45 | Peter A. G. Crosthwaite | return s->regs[addr] & mask;
|
327 | 94befa45 | Peter A. G. Crosthwaite | |
328 | 94befa45 | Peter A. G. Crosthwaite | } |
329 | 94befa45 | Peter A. G. Crosthwaite | |
330 | f1241144 | Peter Crosthwaite | static inline void tx_data_bytes(XilinxSPIPS *s, uint32_t value, int num) |
331 | f1241144 | Peter Crosthwaite | { |
332 | f1241144 | Peter Crosthwaite | int i;
|
333 | f1241144 | Peter Crosthwaite | for (i = 0; i < num && !fifo8_is_full(&s->tx_fifo); ++i) { |
334 | f1241144 | Peter Crosthwaite | if (s->regs[R_CONFIG] & ENDIAN) {
|
335 | f1241144 | Peter Crosthwaite | fifo8_push(&s->tx_fifo, (uint8_t)(value >> 24));
|
336 | f1241144 | Peter Crosthwaite | value <<= 8;
|
337 | f1241144 | Peter Crosthwaite | } else {
|
338 | f1241144 | Peter Crosthwaite | fifo8_push(&s->tx_fifo, (uint8_t)value); |
339 | f1241144 | Peter Crosthwaite | value >>= 8;
|
340 | f1241144 | Peter Crosthwaite | } |
341 | f1241144 | Peter Crosthwaite | } |
342 | f1241144 | Peter Crosthwaite | } |
343 | f1241144 | Peter Crosthwaite | |
344 | a8170e5e | Avi Kivity | static void xilinx_spips_write(void *opaque, hwaddr addr, |
345 | 94befa45 | Peter A. G. Crosthwaite | uint64_t value, unsigned size)
|
346 | 94befa45 | Peter A. G. Crosthwaite | { |
347 | 94befa45 | Peter A. G. Crosthwaite | int mask = ~0; |
348 | 94befa45 | Peter A. G. Crosthwaite | int man_start_com = 0; |
349 | 94befa45 | Peter A. G. Crosthwaite | XilinxSPIPS *s = opaque; |
350 | 94befa45 | Peter A. G. Crosthwaite | |
351 | 94befa45 | Peter A. G. Crosthwaite | DB_PRINT("addr=" TARGET_FMT_plx " = %x\n", addr, (unsigned)value); |
352 | 94befa45 | Peter A. G. Crosthwaite | addr >>= 2;
|
353 | 94befa45 | Peter A. G. Crosthwaite | switch (addr) {
|
354 | 94befa45 | Peter A. G. Crosthwaite | case R_CONFIG:
|
355 | 94befa45 | Peter A. G. Crosthwaite | mask = 0x0002FFFF;
|
356 | 94befa45 | Peter A. G. Crosthwaite | if (value & MAN_START_COM) {
|
357 | 94befa45 | Peter A. G. Crosthwaite | man_start_com = 1;
|
358 | 94befa45 | Peter A. G. Crosthwaite | } |
359 | 94befa45 | Peter A. G. Crosthwaite | break;
|
360 | 94befa45 | Peter A. G. Crosthwaite | case R_INTR_STATUS:
|
361 | 94befa45 | Peter A. G. Crosthwaite | mask = IXR_ALL; |
362 | 94befa45 | Peter A. G. Crosthwaite | s->regs[R_INTR_STATUS] &= ~(mask & value); |
363 | 94befa45 | Peter A. G. Crosthwaite | goto no_reg_update;
|
364 | 94befa45 | Peter A. G. Crosthwaite | case R_INTR_DIS:
|
365 | 94befa45 | Peter A. G. Crosthwaite | mask = IXR_ALL; |
366 | 94befa45 | Peter A. G. Crosthwaite | s->regs[R_INTR_MASK] &= ~(mask & value); |
367 | 94befa45 | Peter A. G. Crosthwaite | goto no_reg_update;
|
368 | 94befa45 | Peter A. G. Crosthwaite | case R_INTR_EN:
|
369 | 94befa45 | Peter A. G. Crosthwaite | mask = IXR_ALL; |
370 | 94befa45 | Peter A. G. Crosthwaite | s->regs[R_INTR_MASK] |= mask & value; |
371 | 94befa45 | Peter A. G. Crosthwaite | goto no_reg_update;
|
372 | 94befa45 | Peter A. G. Crosthwaite | case R_EN:
|
373 | 94befa45 | Peter A. G. Crosthwaite | mask = 0x1;
|
374 | 94befa45 | Peter A. G. Crosthwaite | break;
|
375 | 94befa45 | Peter A. G. Crosthwaite | case R_SLAVE_IDLE_COUNT:
|
376 | 94befa45 | Peter A. G. Crosthwaite | mask = 0xFF;
|
377 | 94befa45 | Peter A. G. Crosthwaite | break;
|
378 | 94befa45 | Peter A. G. Crosthwaite | case R_RX_DATA:
|
379 | 94befa45 | Peter A. G. Crosthwaite | case R_INTR_MASK:
|
380 | 94befa45 | Peter A. G. Crosthwaite | case R_MOD_ID:
|
381 | 94befa45 | Peter A. G. Crosthwaite | mask = 0;
|
382 | 94befa45 | Peter A. G. Crosthwaite | break;
|
383 | 94befa45 | Peter A. G. Crosthwaite | case R_TX_DATA:
|
384 | f1241144 | Peter Crosthwaite | tx_data_bytes(s, (uint32_t)value, s->num_txrx_bytes); |
385 | f1241144 | Peter Crosthwaite | goto no_reg_update;
|
386 | f1241144 | Peter Crosthwaite | case R_TXD1:
|
387 | f1241144 | Peter Crosthwaite | tx_data_bytes(s, (uint32_t)value, 1);
|
388 | f1241144 | Peter Crosthwaite | goto no_reg_update;
|
389 | f1241144 | Peter Crosthwaite | case R_TXD2:
|
390 | f1241144 | Peter Crosthwaite | tx_data_bytes(s, (uint32_t)value, 2);
|
391 | f1241144 | Peter Crosthwaite | goto no_reg_update;
|
392 | f1241144 | Peter Crosthwaite | case R_TXD3:
|
393 | f1241144 | Peter Crosthwaite | tx_data_bytes(s, (uint32_t)value, 3);
|
394 | 94befa45 | Peter A. G. Crosthwaite | goto no_reg_update;
|
395 | 94befa45 | Peter A. G. Crosthwaite | } |
396 | 94befa45 | Peter A. G. Crosthwaite | s->regs[addr] = (s->regs[addr] & ~mask) | (value & mask); |
397 | 94befa45 | Peter A. G. Crosthwaite | no_reg_update:
|
398 | 94befa45 | Peter A. G. Crosthwaite | if (man_start_com) {
|
399 | 94befa45 | Peter A. G. Crosthwaite | xilinx_spips_flush_txfifo(s); |
400 | 94befa45 | Peter A. G. Crosthwaite | } |
401 | 94befa45 | Peter A. G. Crosthwaite | xilinx_spips_update_ixr(s); |
402 | 94befa45 | Peter A. G. Crosthwaite | xilinx_spips_update_cs_lines(s); |
403 | 94befa45 | Peter A. G. Crosthwaite | } |
404 | 94befa45 | Peter A. G. Crosthwaite | |
405 | 94befa45 | Peter A. G. Crosthwaite | static const MemoryRegionOps spips_ops = { |
406 | 94befa45 | Peter A. G. Crosthwaite | .read = xilinx_spips_read, |
407 | 94befa45 | Peter A. G. Crosthwaite | .write = xilinx_spips_write, |
408 | 94befa45 | Peter A. G. Crosthwaite | .endianness = DEVICE_LITTLE_ENDIAN, |
409 | 94befa45 | Peter A. G. Crosthwaite | }; |
410 | 94befa45 | Peter A. G. Crosthwaite | |
411 | f1241144 | Peter Crosthwaite | #define LQSPI_CACHE_SIZE 1024 |
412 | f1241144 | Peter Crosthwaite | |
413 | f1241144 | Peter Crosthwaite | static uint64_t
|
414 | f1241144 | Peter Crosthwaite | lqspi_read(void *opaque, hwaddr addr, unsigned int size) |
415 | f1241144 | Peter Crosthwaite | { |
416 | f1241144 | Peter Crosthwaite | int i;
|
417 | f1241144 | Peter Crosthwaite | XilinxSPIPS *s = opaque; |
418 | f1241144 | Peter Crosthwaite | |
419 | f1241144 | Peter Crosthwaite | if (addr >= s->lqspi_cached_addr &&
|
420 | f1241144 | Peter Crosthwaite | addr <= s->lqspi_cached_addr + LQSPI_CACHE_SIZE - 4) {
|
421 | f1241144 | Peter Crosthwaite | return s->lqspi_buf[(addr - s->lqspi_cached_addr) >> 2]; |
422 | f1241144 | Peter Crosthwaite | } else {
|
423 | f1241144 | Peter Crosthwaite | int flash_addr = (addr / num_effective_busses(s));
|
424 | f1241144 | Peter Crosthwaite | int slave = flash_addr >> LQSPI_ADDRESS_BITS;
|
425 | f1241144 | Peter Crosthwaite | int cache_entry = 0; |
426 | f1241144 | Peter Crosthwaite | |
427 | f1241144 | Peter Crosthwaite | DB_PRINT("config reg status: %08x\n", s->regs[R_LQSPI_CFG]);
|
428 | f1241144 | Peter Crosthwaite | |
429 | f1241144 | Peter Crosthwaite | fifo8_reset(&s->tx_fifo); |
430 | f1241144 | Peter Crosthwaite | fifo8_reset(&s->rx_fifo); |
431 | f1241144 | Peter Crosthwaite | |
432 | f1241144 | Peter Crosthwaite | s->regs[R_CONFIG] &= ~CS; |
433 | f1241144 | Peter Crosthwaite | s->regs[R_CONFIG] |= (~(1 << slave) << CS_SHIFT) & CS;
|
434 | f1241144 | Peter Crosthwaite | xilinx_spips_update_cs_lines(s); |
435 | f1241144 | Peter Crosthwaite | |
436 | f1241144 | Peter Crosthwaite | /* instruction */
|
437 | f1241144 | Peter Crosthwaite | DB_PRINT("pushing read instruction: %02x\n",
|
438 | f1241144 | Peter Crosthwaite | (uint8_t)(s->regs[R_LQSPI_CFG] & LQSPI_CFG_INST_CODE)); |
439 | f1241144 | Peter Crosthwaite | fifo8_push(&s->tx_fifo, s->regs[R_LQSPI_CFG] & LQSPI_CFG_INST_CODE); |
440 | f1241144 | Peter Crosthwaite | /* read address */
|
441 | f1241144 | Peter Crosthwaite | DB_PRINT("pushing read address %06x\n", flash_addr);
|
442 | f1241144 | Peter Crosthwaite | fifo8_push(&s->tx_fifo, (uint8_t)(flash_addr >> 16));
|
443 | f1241144 | Peter Crosthwaite | fifo8_push(&s->tx_fifo, (uint8_t)(flash_addr >> 8));
|
444 | f1241144 | Peter Crosthwaite | fifo8_push(&s->tx_fifo, (uint8_t)flash_addr); |
445 | f1241144 | Peter Crosthwaite | /* mode bits */
|
446 | f1241144 | Peter Crosthwaite | if (s->regs[R_LQSPI_CFG] & LQSPI_CFG_MODE_EN) {
|
447 | f1241144 | Peter Crosthwaite | fifo8_push(&s->tx_fifo, extract32(s->regs[R_LQSPI_CFG], |
448 | f1241144 | Peter Crosthwaite | LQSPI_CFG_MODE_SHIFT, |
449 | f1241144 | Peter Crosthwaite | LQSPI_CFG_MODE_WIDTH)); |
450 | f1241144 | Peter Crosthwaite | } |
451 | f1241144 | Peter Crosthwaite | /* dummy bytes */
|
452 | f1241144 | Peter Crosthwaite | for (i = 0; i < (extract32(s->regs[R_LQSPI_CFG], LQSPI_CFG_DUMMY_SHIFT, |
453 | f1241144 | Peter Crosthwaite | LQSPI_CFG_DUMMY_WIDTH)); ++i) { |
454 | f1241144 | Peter Crosthwaite | DB_PRINT("pushing dummy byte\n");
|
455 | f1241144 | Peter Crosthwaite | fifo8_push(&s->tx_fifo, 0);
|
456 | f1241144 | Peter Crosthwaite | } |
457 | f1241144 | Peter Crosthwaite | xilinx_spips_flush_txfifo(s); |
458 | f1241144 | Peter Crosthwaite | fifo8_reset(&s->rx_fifo); |
459 | f1241144 | Peter Crosthwaite | |
460 | f1241144 | Peter Crosthwaite | DB_PRINT("starting QSPI data read\n");
|
461 | f1241144 | Peter Crosthwaite | |
462 | f1241144 | Peter Crosthwaite | for (i = 0; i < LQSPI_CACHE_SIZE / 4; ++i) { |
463 | f1241144 | Peter Crosthwaite | tx_data_bytes(s, 0, 4); |
464 | f1241144 | Peter Crosthwaite | xilinx_spips_flush_txfifo(s); |
465 | f1241144 | Peter Crosthwaite | rx_data_bytes(s, &s->lqspi_buf[cache_entry], 4);
|
466 | f1241144 | Peter Crosthwaite | cache_entry++; |
467 | f1241144 | Peter Crosthwaite | } |
468 | f1241144 | Peter Crosthwaite | |
469 | f1241144 | Peter Crosthwaite | s->regs[R_CONFIG] |= CS; |
470 | f1241144 | Peter Crosthwaite | xilinx_spips_update_cs_lines(s); |
471 | f1241144 | Peter Crosthwaite | |
472 | f1241144 | Peter Crosthwaite | s->lqspi_cached_addr = addr; |
473 | f1241144 | Peter Crosthwaite | return lqspi_read(opaque, addr, size);
|
474 | f1241144 | Peter Crosthwaite | } |
475 | f1241144 | Peter Crosthwaite | } |
476 | f1241144 | Peter Crosthwaite | |
477 | f1241144 | Peter Crosthwaite | static const MemoryRegionOps lqspi_ops = { |
478 | f1241144 | Peter Crosthwaite | .read = lqspi_read, |
479 | f1241144 | Peter Crosthwaite | .endianness = DEVICE_NATIVE_ENDIAN, |
480 | f1241144 | Peter Crosthwaite | .valid = { |
481 | f1241144 | Peter Crosthwaite | .min_access_size = 4,
|
482 | f1241144 | Peter Crosthwaite | .max_access_size = 4
|
483 | f1241144 | Peter Crosthwaite | } |
484 | f1241144 | Peter Crosthwaite | }; |
485 | f1241144 | Peter Crosthwaite | |
486 | 94befa45 | Peter A. G. Crosthwaite | static int xilinx_spips_init(SysBusDevice *dev) |
487 | 94befa45 | Peter A. G. Crosthwaite | { |
488 | 94befa45 | Peter A. G. Crosthwaite | XilinxSPIPS *s = FROM_SYSBUS(typeof(*s), dev); |
489 | 94befa45 | Peter A. G. Crosthwaite | int i;
|
490 | 94befa45 | Peter A. G. Crosthwaite | |
491 | 94befa45 | Peter A. G. Crosthwaite | DB_PRINT("inited device model\n");
|
492 | 94befa45 | Peter A. G. Crosthwaite | |
493 | f1241144 | Peter Crosthwaite | s->spi = g_new(SSIBus *, s->num_busses); |
494 | f1241144 | Peter Crosthwaite | for (i = 0; i < s->num_busses; ++i) { |
495 | f1241144 | Peter Crosthwaite | char bus_name[16]; |
496 | f1241144 | Peter Crosthwaite | snprintf(bus_name, 16, "spi%d", i); |
497 | f1241144 | Peter Crosthwaite | s->spi[i] = ssi_create_bus(&dev->qdev, bus_name); |
498 | f1241144 | Peter Crosthwaite | } |
499 | b4ae3cfa | Peter Crosthwaite | |
500 | f1241144 | Peter Crosthwaite | s->cs_lines = g_new(qemu_irq, s->num_cs * s->num_busses); |
501 | f1241144 | Peter Crosthwaite | ssi_auto_connect_slaves(DEVICE(s), s->cs_lines, s->spi[0]);
|
502 | f1241144 | Peter Crosthwaite | ssi_auto_connect_slaves(DEVICE(s), s->cs_lines, s->spi[1]);
|
503 | 94befa45 | Peter A. G. Crosthwaite | sysbus_init_irq(dev, &s->irq); |
504 | f1241144 | Peter Crosthwaite | for (i = 0; i < s->num_cs * s->num_busses; ++i) { |
505 | 94befa45 | Peter A. G. Crosthwaite | sysbus_init_irq(dev, &s->cs_lines[i]); |
506 | 94befa45 | Peter A. G. Crosthwaite | } |
507 | 94befa45 | Peter A. G. Crosthwaite | |
508 | 94befa45 | Peter A. G. Crosthwaite | memory_region_init_io(&s->iomem, &spips_ops, s, "spi", R_MAX*4); |
509 | 94befa45 | Peter A. G. Crosthwaite | sysbus_init_mmio(dev, &s->iomem); |
510 | 94befa45 | Peter A. G. Crosthwaite | |
511 | f1241144 | Peter Crosthwaite | memory_region_init_io(&s->mmlqspi, &lqspi_ops, s, "lqspi",
|
512 | f1241144 | Peter Crosthwaite | (1 << LQSPI_ADDRESS_BITS) * 2); |
513 | f1241144 | Peter Crosthwaite | sysbus_init_mmio(dev, &s->mmlqspi); |
514 | f1241144 | Peter Crosthwaite | |
515 | 94befa45 | Peter A. G. Crosthwaite | s->irqline = -1;
|
516 | f1241144 | Peter Crosthwaite | s->lqspi_cached_addr = ~0ULL;
|
517 | 94befa45 | Peter A. G. Crosthwaite | |
518 | 94befa45 | Peter A. G. Crosthwaite | fifo8_create(&s->rx_fifo, RXFF_A); |
519 | 94befa45 | Peter A. G. Crosthwaite | fifo8_create(&s->tx_fifo, TXFF_A); |
520 | 94befa45 | Peter A. G. Crosthwaite | |
521 | 94befa45 | Peter A. G. Crosthwaite | return 0; |
522 | 94befa45 | Peter A. G. Crosthwaite | } |
523 | 94befa45 | Peter A. G. Crosthwaite | |
524 | 94befa45 | Peter A. G. Crosthwaite | static int xilinx_spips_post_load(void *opaque, int version_id) |
525 | 94befa45 | Peter A. G. Crosthwaite | { |
526 | 94befa45 | Peter A. G. Crosthwaite | xilinx_spips_update_ixr((XilinxSPIPS *)opaque); |
527 | 94befa45 | Peter A. G. Crosthwaite | xilinx_spips_update_cs_lines((XilinxSPIPS *)opaque); |
528 | 94befa45 | Peter A. G. Crosthwaite | return 0; |
529 | 94befa45 | Peter A. G. Crosthwaite | } |
530 | 94befa45 | Peter A. G. Crosthwaite | |
531 | 94befa45 | Peter A. G. Crosthwaite | static const VMStateDescription vmstate_xilinx_spips = { |
532 | 94befa45 | Peter A. G. Crosthwaite | .name = "xilinx_spips",
|
533 | f1241144 | Peter Crosthwaite | .version_id = 2,
|
534 | f1241144 | Peter Crosthwaite | .minimum_version_id = 2,
|
535 | f1241144 | Peter Crosthwaite | .minimum_version_id_old = 2,
|
536 | 94befa45 | Peter A. G. Crosthwaite | .post_load = xilinx_spips_post_load, |
537 | 94befa45 | Peter A. G. Crosthwaite | .fields = (VMStateField[]) { |
538 | 94befa45 | Peter A. G. Crosthwaite | VMSTATE_FIFO8(tx_fifo, XilinxSPIPS), |
539 | 94befa45 | Peter A. G. Crosthwaite | VMSTATE_FIFO8(rx_fifo, XilinxSPIPS), |
540 | 94befa45 | Peter A. G. Crosthwaite | VMSTATE_UINT32_ARRAY(regs, XilinxSPIPS, R_MAX), |
541 | f1241144 | Peter Crosthwaite | VMSTATE_UINT8(snoop_state, XilinxSPIPS), |
542 | 94befa45 | Peter A. G. Crosthwaite | VMSTATE_END_OF_LIST() |
543 | 94befa45 | Peter A. G. Crosthwaite | } |
544 | 94befa45 | Peter A. G. Crosthwaite | }; |
545 | 94befa45 | Peter A. G. Crosthwaite | |
546 | f1241144 | Peter Crosthwaite | static Property xilinx_spips_properties[] = {
|
547 | f1241144 | Peter Crosthwaite | DEFINE_PROP_UINT8("num-busses", XilinxSPIPS, num_busses, 1), |
548 | f1241144 | Peter Crosthwaite | DEFINE_PROP_UINT8("num-ss-bits", XilinxSPIPS, num_cs, 4), |
549 | f1241144 | Peter Crosthwaite | DEFINE_PROP_UINT8("num-txrx-bytes", XilinxSPIPS, num_txrx_bytes, 1), |
550 | f1241144 | Peter Crosthwaite | DEFINE_PROP_END_OF_LIST(), |
551 | f1241144 | Peter Crosthwaite | }; |
552 | 94befa45 | Peter A. G. Crosthwaite | static void xilinx_spips_class_init(ObjectClass *klass, void *data) |
553 | 94befa45 | Peter A. G. Crosthwaite | { |
554 | 94befa45 | Peter A. G. Crosthwaite | DeviceClass *dc = DEVICE_CLASS(klass); |
555 | 94befa45 | Peter A. G. Crosthwaite | SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass); |
556 | 94befa45 | Peter A. G. Crosthwaite | |
557 | 94befa45 | Peter A. G. Crosthwaite | sdc->init = xilinx_spips_init; |
558 | 94befa45 | Peter A. G. Crosthwaite | dc->reset = xilinx_spips_reset; |
559 | f1241144 | Peter Crosthwaite | dc->props = xilinx_spips_properties; |
560 | 94befa45 | Peter A. G. Crosthwaite | dc->vmsd = &vmstate_xilinx_spips; |
561 | 94befa45 | Peter A. G. Crosthwaite | } |
562 | 94befa45 | Peter A. G. Crosthwaite | |
563 | 94befa45 | Peter A. G. Crosthwaite | static const TypeInfo xilinx_spips_info = { |
564 | 94befa45 | Peter A. G. Crosthwaite | .name = "xilinx,spips",
|
565 | 94befa45 | Peter A. G. Crosthwaite | .parent = TYPE_SYS_BUS_DEVICE, |
566 | 94befa45 | Peter A. G. Crosthwaite | .instance_size = sizeof(XilinxSPIPS),
|
567 | 94befa45 | Peter A. G. Crosthwaite | .class_init = xilinx_spips_class_init, |
568 | 94befa45 | Peter A. G. Crosthwaite | }; |
569 | 94befa45 | Peter A. G. Crosthwaite | |
570 | 94befa45 | Peter A. G. Crosthwaite | static void xilinx_spips_register_types(void) |
571 | 94befa45 | Peter A. G. Crosthwaite | { |
572 | 94befa45 | Peter A. G. Crosthwaite | type_register_static(&xilinx_spips_info); |
573 | 94befa45 | Peter A. G. Crosthwaite | } |
574 | 94befa45 | Peter A. G. Crosthwaite | |
575 | 94befa45 | Peter A. G. Crosthwaite | type_init(xilinx_spips_register_types) |