root / hw / musicpal.c @ 3320e56e
History | View | Annotate | Download (43.1 kB)
1 | 24859b68 | balrog | /*
|
---|---|---|---|
2 | 24859b68 | balrog | * Marvell MV88W8618 / Freecom MusicPal emulation.
|
3 | 24859b68 | balrog | *
|
4 | 24859b68 | balrog | * Copyright (c) 2008 Jan Kiszka
|
5 | 24859b68 | balrog | *
|
6 | 24859b68 | balrog | * This code is licenced under the GNU GPL v2.
|
7 | 24859b68 | balrog | */
|
8 | 24859b68 | balrog | |
9 | b47b50fa | Paul Brook | #include "sysbus.h" |
10 | 24859b68 | balrog | #include "arm-misc.h" |
11 | 24859b68 | balrog | #include "devices.h" |
12 | 24859b68 | balrog | #include "net.h" |
13 | 24859b68 | balrog | #include "sysemu.h" |
14 | 24859b68 | balrog | #include "boards.h" |
15 | 24859b68 | balrog | #include "pc.h" |
16 | 24859b68 | balrog | #include "qemu-timer.h" |
17 | 24859b68 | balrog | #include "block.h" |
18 | 24859b68 | balrog | #include "flash.h" |
19 | 24859b68 | balrog | #include "console.h" |
20 | 24859b68 | balrog | #include "audio/audio.h" |
21 | 24859b68 | balrog | #include "i2c.h" |
22 | 24859b68 | balrog | |
23 | 718ec0be | malc | #define MP_MISC_BASE 0x80002000 |
24 | 718ec0be | malc | #define MP_MISC_SIZE 0x00001000 |
25 | 718ec0be | malc | |
26 | 24859b68 | balrog | #define MP_ETH_BASE 0x80008000 |
27 | 24859b68 | balrog | #define MP_ETH_SIZE 0x00001000 |
28 | 24859b68 | balrog | |
29 | 718ec0be | malc | #define MP_WLAN_BASE 0x8000C000 |
30 | 718ec0be | malc | #define MP_WLAN_SIZE 0x00000800 |
31 | 718ec0be | malc | |
32 | 24859b68 | balrog | #define MP_UART1_BASE 0x8000C840 |
33 | 24859b68 | balrog | #define MP_UART2_BASE 0x8000C940 |
34 | 24859b68 | balrog | |
35 | 718ec0be | malc | #define MP_GPIO_BASE 0x8000D000 |
36 | 718ec0be | malc | #define MP_GPIO_SIZE 0x00001000 |
37 | 718ec0be | malc | |
38 | 24859b68 | balrog | #define MP_FLASHCFG_BASE 0x90006000 |
39 | 24859b68 | balrog | #define MP_FLASHCFG_SIZE 0x00001000 |
40 | 24859b68 | balrog | |
41 | 24859b68 | balrog | #define MP_AUDIO_BASE 0x90007000 |
42 | 24859b68 | balrog | #define MP_AUDIO_SIZE 0x00001000 |
43 | 24859b68 | balrog | |
44 | 24859b68 | balrog | #define MP_PIC_BASE 0x90008000 |
45 | 24859b68 | balrog | #define MP_PIC_SIZE 0x00001000 |
46 | 24859b68 | balrog | |
47 | 24859b68 | balrog | #define MP_PIT_BASE 0x90009000 |
48 | 24859b68 | balrog | #define MP_PIT_SIZE 0x00001000 |
49 | 24859b68 | balrog | |
50 | 24859b68 | balrog | #define MP_LCD_BASE 0x9000c000 |
51 | 24859b68 | balrog | #define MP_LCD_SIZE 0x00001000 |
52 | 24859b68 | balrog | |
53 | 24859b68 | balrog | #define MP_SRAM_BASE 0xC0000000 |
54 | 24859b68 | balrog | #define MP_SRAM_SIZE 0x00020000 |
55 | 24859b68 | balrog | |
56 | 24859b68 | balrog | #define MP_RAM_DEFAULT_SIZE 32*1024*1024 |
57 | 24859b68 | balrog | #define MP_FLASH_SIZE_MAX 32*1024*1024 |
58 | 24859b68 | balrog | |
59 | 24859b68 | balrog | #define MP_TIMER1_IRQ 4 |
60 | b47b50fa | Paul Brook | #define MP_TIMER2_IRQ 5 |
61 | b47b50fa | Paul Brook | #define MP_TIMER3_IRQ 6 |
62 | 24859b68 | balrog | #define MP_TIMER4_IRQ 7 |
63 | 24859b68 | balrog | #define MP_EHCI_IRQ 8 |
64 | 24859b68 | balrog | #define MP_ETH_IRQ 9 |
65 | 24859b68 | balrog | #define MP_UART1_IRQ 11 |
66 | 24859b68 | balrog | #define MP_UART2_IRQ 11 |
67 | 24859b68 | balrog | #define MP_GPIO_IRQ 12 |
68 | 24859b68 | balrog | #define MP_RTC_IRQ 28 |
69 | 24859b68 | balrog | #define MP_AUDIO_IRQ 30 |
70 | 24859b68 | balrog | |
71 | 24859b68 | balrog | static uint32_t gpio_in_state = 0xffffffff; |
72 | 7c6ce4ba | balrog | static uint32_t gpio_isr;
|
73 | 24859b68 | balrog | static uint32_t gpio_out_state;
|
74 | 24859b68 | balrog | static ram_addr_t sram_off;
|
75 | 24859b68 | balrog | |
76 | 24859b68 | balrog | typedef enum i2c_state { |
77 | 24859b68 | balrog | STOPPED = 0,
|
78 | 24859b68 | balrog | INITIALIZING, |
79 | 24859b68 | balrog | SENDING_BIT7, |
80 | 24859b68 | balrog | SENDING_BIT6, |
81 | 24859b68 | balrog | SENDING_BIT5, |
82 | 24859b68 | balrog | SENDING_BIT4, |
83 | 24859b68 | balrog | SENDING_BIT3, |
84 | 24859b68 | balrog | SENDING_BIT2, |
85 | 24859b68 | balrog | SENDING_BIT1, |
86 | 24859b68 | balrog | SENDING_BIT0, |
87 | 24859b68 | balrog | WAITING_FOR_ACK, |
88 | 24859b68 | balrog | RECEIVING_BIT7, |
89 | 24859b68 | balrog | RECEIVING_BIT6, |
90 | 24859b68 | balrog | RECEIVING_BIT5, |
91 | 24859b68 | balrog | RECEIVING_BIT4, |
92 | 24859b68 | balrog | RECEIVING_BIT3, |
93 | 24859b68 | balrog | RECEIVING_BIT2, |
94 | 24859b68 | balrog | RECEIVING_BIT1, |
95 | 24859b68 | balrog | RECEIVING_BIT0, |
96 | 24859b68 | balrog | SENDING_ACK |
97 | 24859b68 | balrog | } i2c_state; |
98 | 24859b68 | balrog | |
99 | 24859b68 | balrog | typedef struct i2c_interface { |
100 | 24859b68 | balrog | i2c_bus *bus; |
101 | 24859b68 | balrog | i2c_state state; |
102 | 24859b68 | balrog | int last_data;
|
103 | 24859b68 | balrog | int last_clock;
|
104 | 24859b68 | balrog | uint8_t buffer; |
105 | 24859b68 | balrog | int current_addr;
|
106 | 24859b68 | balrog | } i2c_interface; |
107 | 24859b68 | balrog | |
108 | 24859b68 | balrog | static void i2c_enter_stop(i2c_interface *i2c) |
109 | 24859b68 | balrog | { |
110 | 24859b68 | balrog | if (i2c->current_addr >= 0) |
111 | 24859b68 | balrog | i2c_end_transfer(i2c->bus); |
112 | 24859b68 | balrog | i2c->current_addr = -1;
|
113 | 24859b68 | balrog | i2c->state = STOPPED; |
114 | 24859b68 | balrog | } |
115 | 24859b68 | balrog | |
116 | 24859b68 | balrog | static void i2c_state_update(i2c_interface *i2c, int data, int clock) |
117 | 24859b68 | balrog | { |
118 | 24859b68 | balrog | if (!i2c)
|
119 | 24859b68 | balrog | return;
|
120 | 24859b68 | balrog | |
121 | 24859b68 | balrog | switch (i2c->state) {
|
122 | 24859b68 | balrog | case STOPPED:
|
123 | 24859b68 | balrog | if (data == 0 && i2c->last_data == 1 && clock == 1) |
124 | 24859b68 | balrog | i2c->state = INITIALIZING; |
125 | 24859b68 | balrog | break;
|
126 | 24859b68 | balrog | |
127 | 24859b68 | balrog | case INITIALIZING:
|
128 | 24859b68 | balrog | if (clock == 0 && i2c->last_clock == 1 && data == 0) |
129 | 24859b68 | balrog | i2c->state = SENDING_BIT7; |
130 | 24859b68 | balrog | else
|
131 | 24859b68 | balrog | i2c_enter_stop(i2c); |
132 | 24859b68 | balrog | break;
|
133 | 24859b68 | balrog | |
134 | 24859b68 | balrog | case SENDING_BIT7 ... SENDING_BIT0:
|
135 | 24859b68 | balrog | if (clock == 0 && i2c->last_clock == 1) { |
136 | 24859b68 | balrog | i2c->buffer = (i2c->buffer << 1) | data;
|
137 | 24859b68 | balrog | i2c->state++; /* will end up in WAITING_FOR_ACK */
|
138 | 24859b68 | balrog | } else if (data == 1 && i2c->last_data == 0 && clock == 1) |
139 | 24859b68 | balrog | i2c_enter_stop(i2c); |
140 | 24859b68 | balrog | break;
|
141 | 24859b68 | balrog | |
142 | 24859b68 | balrog | case WAITING_FOR_ACK:
|
143 | 24859b68 | balrog | if (clock == 0 && i2c->last_clock == 1) { |
144 | 24859b68 | balrog | if (i2c->current_addr < 0) { |
145 | 24859b68 | balrog | i2c->current_addr = i2c->buffer; |
146 | 24859b68 | balrog | i2c_start_transfer(i2c->bus, i2c->current_addr & 0xfe,
|
147 | 24859b68 | balrog | i2c->buffer & 1);
|
148 | 24859b68 | balrog | } else
|
149 | 24859b68 | balrog | i2c_send(i2c->bus, i2c->buffer); |
150 | 24859b68 | balrog | if (i2c->current_addr & 1) { |
151 | 24859b68 | balrog | i2c->state = RECEIVING_BIT7; |
152 | 24859b68 | balrog | i2c->buffer = i2c_recv(i2c->bus); |
153 | 24859b68 | balrog | } else
|
154 | 24859b68 | balrog | i2c->state = SENDING_BIT7; |
155 | 24859b68 | balrog | } else if (data == 1 && i2c->last_data == 0 && clock == 1) |
156 | 24859b68 | balrog | i2c_enter_stop(i2c); |
157 | 24859b68 | balrog | break;
|
158 | 24859b68 | balrog | |
159 | 24859b68 | balrog | case RECEIVING_BIT7 ... RECEIVING_BIT0:
|
160 | 24859b68 | balrog | if (clock == 0 && i2c->last_clock == 1) { |
161 | 24859b68 | balrog | i2c->state++; /* will end up in SENDING_ACK */
|
162 | 24859b68 | balrog | i2c->buffer <<= 1;
|
163 | 24859b68 | balrog | } else if (data == 1 && i2c->last_data == 0 && clock == 1) |
164 | 24859b68 | balrog | i2c_enter_stop(i2c); |
165 | 24859b68 | balrog | break;
|
166 | 24859b68 | balrog | |
167 | 24859b68 | balrog | case SENDING_ACK:
|
168 | 24859b68 | balrog | if (clock == 0 && i2c->last_clock == 1) { |
169 | 24859b68 | balrog | i2c->state = RECEIVING_BIT7; |
170 | 24859b68 | balrog | if (data == 0) |
171 | 24859b68 | balrog | i2c->buffer = i2c_recv(i2c->bus); |
172 | 24859b68 | balrog | else
|
173 | 24859b68 | balrog | i2c_nack(i2c->bus); |
174 | 24859b68 | balrog | } else if (data == 1 && i2c->last_data == 0 && clock == 1) |
175 | 24859b68 | balrog | i2c_enter_stop(i2c); |
176 | 24859b68 | balrog | break;
|
177 | 24859b68 | balrog | } |
178 | 24859b68 | balrog | |
179 | 24859b68 | balrog | i2c->last_data = data; |
180 | 24859b68 | balrog | i2c->last_clock = clock; |
181 | 24859b68 | balrog | } |
182 | 24859b68 | balrog | |
183 | 24859b68 | balrog | static int i2c_get_data(i2c_interface *i2c) |
184 | 24859b68 | balrog | { |
185 | 24859b68 | balrog | if (!i2c)
|
186 | 24859b68 | balrog | return 0; |
187 | 24859b68 | balrog | |
188 | 24859b68 | balrog | switch (i2c->state) {
|
189 | 24859b68 | balrog | case RECEIVING_BIT7 ... RECEIVING_BIT0:
|
190 | 24859b68 | balrog | return (i2c->buffer >> 7); |
191 | 24859b68 | balrog | |
192 | 24859b68 | balrog | case WAITING_FOR_ACK:
|
193 | 24859b68 | balrog | default:
|
194 | 24859b68 | balrog | return 0; |
195 | 24859b68 | balrog | } |
196 | 24859b68 | balrog | } |
197 | 24859b68 | balrog | |
198 | 24859b68 | balrog | static i2c_interface *mixer_i2c;
|
199 | 24859b68 | balrog | |
200 | 24859b68 | balrog | #ifdef HAS_AUDIO
|
201 | 24859b68 | balrog | |
202 | 24859b68 | balrog | /* Audio register offsets */
|
203 | 24859b68 | balrog | #define MP_AUDIO_PLAYBACK_MODE 0x00 |
204 | 24859b68 | balrog | #define MP_AUDIO_CLOCK_DIV 0x18 |
205 | 24859b68 | balrog | #define MP_AUDIO_IRQ_STATUS 0x20 |
206 | 24859b68 | balrog | #define MP_AUDIO_IRQ_ENABLE 0x24 |
207 | 24859b68 | balrog | #define MP_AUDIO_TX_START_LO 0x28 |
208 | 24859b68 | balrog | #define MP_AUDIO_TX_THRESHOLD 0x2C |
209 | 24859b68 | balrog | #define MP_AUDIO_TX_STATUS 0x38 |
210 | 24859b68 | balrog | #define MP_AUDIO_TX_START_HI 0x40 |
211 | 24859b68 | balrog | |
212 | 24859b68 | balrog | /* Status register and IRQ enable bits */
|
213 | 24859b68 | balrog | #define MP_AUDIO_TX_HALF (1 << 6) |
214 | 24859b68 | balrog | #define MP_AUDIO_TX_FULL (1 << 7) |
215 | 24859b68 | balrog | |
216 | 24859b68 | balrog | /* Playback mode bits */
|
217 | 24859b68 | balrog | #define MP_AUDIO_16BIT_SAMPLE (1 << 0) |
218 | 24859b68 | balrog | #define MP_AUDIO_PLAYBACK_EN (1 << 7) |
219 | 24859b68 | balrog | #define MP_AUDIO_CLOCK_24MHZ (1 << 9) |
220 | 4001a81e | balrog | #define MP_AUDIO_MONO (1 << 14) |
221 | 24859b68 | balrog | |
222 | 24859b68 | balrog | /* Wolfson 8750 I2C address */
|
223 | 24859b68 | balrog | #define MP_WM_ADDR 0x34 |
224 | 24859b68 | balrog | |
225 | b1d8e52e | blueswir1 | static const char audio_name[] = "mv88w8618"; |
226 | 24859b68 | balrog | |
227 | 24859b68 | balrog | typedef struct musicpal_audio_state { |
228 | 24859b68 | balrog | qemu_irq irq; |
229 | 24859b68 | balrog | uint32_t playback_mode; |
230 | 24859b68 | balrog | uint32_t status; |
231 | 24859b68 | balrog | uint32_t irq_enable; |
232 | 24859b68 | balrog | unsigned long phys_buf; |
233 | 930c8682 | pbrook | uint32_t target_buffer; |
234 | 24859b68 | balrog | unsigned int threshold; |
235 | 24859b68 | balrog | unsigned int play_pos; |
236 | 24859b68 | balrog | unsigned int last_free; |
237 | 24859b68 | balrog | uint32_t clock_div; |
238 | cdbe40ca | Paul Brook | DeviceState *wm; |
239 | 24859b68 | balrog | } musicpal_audio_state; |
240 | 24859b68 | balrog | |
241 | 24859b68 | balrog | static void audio_callback(void *opaque, int free_out, int free_in) |
242 | 24859b68 | balrog | { |
243 | 24859b68 | balrog | musicpal_audio_state *s = opaque; |
244 | 4f3cb3be | balrog | int16_t *codec_buffer; |
245 | 930c8682 | pbrook | int8_t buf[4096];
|
246 | a350e694 | balrog | int8_t *mem_buffer; |
247 | 24859b68 | balrog | int pos, block_size;
|
248 | 24859b68 | balrog | |
249 | 24859b68 | balrog | if (!(s->playback_mode & MP_AUDIO_PLAYBACK_EN))
|
250 | 24859b68 | balrog | return;
|
251 | 24859b68 | balrog | |
252 | 24859b68 | balrog | if (s->playback_mode & MP_AUDIO_16BIT_SAMPLE)
|
253 | 4001a81e | balrog | free_out <<= 1;
|
254 | 4001a81e | balrog | |
255 | 4001a81e | balrog | if (!(s->playback_mode & MP_AUDIO_MONO))
|
256 | 24859b68 | balrog | free_out <<= 1;
|
257 | 24859b68 | balrog | |
258 | 24859b68 | balrog | block_size = s->threshold/2;
|
259 | 24859b68 | balrog | if (free_out - s->last_free < block_size)
|
260 | 24859b68 | balrog | return;
|
261 | 24859b68 | balrog | |
262 | 930c8682 | pbrook | if (block_size > 4096) |
263 | 930c8682 | pbrook | return;
|
264 | 930c8682 | pbrook | |
265 | 930c8682 | pbrook | cpu_physical_memory_read(s->target_buffer + s->play_pos, (void *)buf,
|
266 | 930c8682 | pbrook | block_size); |
267 | 930c8682 | pbrook | mem_buffer = buf; |
268 | 4001a81e | balrog | if (s->playback_mode & MP_AUDIO_16BIT_SAMPLE) {
|
269 | 4001a81e | balrog | if (s->playback_mode & MP_AUDIO_MONO) {
|
270 | 4001a81e | balrog | codec_buffer = wm8750_dac_buffer(s->wm, block_size >> 1);
|
271 | 4001a81e | balrog | for (pos = 0; pos < block_size; pos += 2) { |
272 | a350e694 | balrog | *codec_buffer++ = *(int16_t *)mem_buffer; |
273 | a350e694 | balrog | *codec_buffer++ = *(int16_t *)mem_buffer; |
274 | 4f3cb3be | balrog | mem_buffer += 2;
|
275 | 4001a81e | balrog | } |
276 | 4001a81e | balrog | } else
|
277 | 4001a81e | balrog | memcpy(wm8750_dac_buffer(s->wm, block_size >> 2),
|
278 | 4001a81e | balrog | (uint32_t *)mem_buffer, block_size); |
279 | 4001a81e | balrog | } else {
|
280 | 4001a81e | balrog | if (s->playback_mode & MP_AUDIO_MONO) {
|
281 | 4001a81e | balrog | codec_buffer = wm8750_dac_buffer(s->wm, block_size); |
282 | 4001a81e | balrog | for (pos = 0; pos < block_size; pos++) { |
283 | a350e694 | balrog | *codec_buffer++ = cpu_to_le16(256 * *mem_buffer);
|
284 | a350e694 | balrog | *codec_buffer++ = cpu_to_le16(256 * *mem_buffer++);
|
285 | 4001a81e | balrog | } |
286 | 4001a81e | balrog | } else {
|
287 | 4001a81e | balrog | codec_buffer = wm8750_dac_buffer(s->wm, block_size >> 1);
|
288 | 4001a81e | balrog | for (pos = 0; pos < block_size; pos += 2) { |
289 | a350e694 | balrog | *codec_buffer++ = cpu_to_le16(256 * *mem_buffer++);
|
290 | a350e694 | balrog | *codec_buffer++ = cpu_to_le16(256 * *mem_buffer++);
|
291 | 4001a81e | balrog | } |
292 | 24859b68 | balrog | } |
293 | 662caa6f | balrog | } |
294 | 662caa6f | balrog | wm8750_dac_commit(s->wm); |
295 | 24859b68 | balrog | |
296 | 24859b68 | balrog | s->last_free = free_out - block_size; |
297 | 24859b68 | balrog | |
298 | 24859b68 | balrog | if (s->play_pos == 0) { |
299 | 24859b68 | balrog | s->status |= MP_AUDIO_TX_HALF; |
300 | 24859b68 | balrog | s->play_pos = block_size; |
301 | 24859b68 | balrog | } else {
|
302 | 24859b68 | balrog | s->status |= MP_AUDIO_TX_FULL; |
303 | 24859b68 | balrog | s->play_pos = 0;
|
304 | 24859b68 | balrog | } |
305 | 24859b68 | balrog | |
306 | 24859b68 | balrog | if (s->status & s->irq_enable)
|
307 | 24859b68 | balrog | qemu_irq_raise(s->irq); |
308 | 24859b68 | balrog | } |
309 | 24859b68 | balrog | |
310 | af83e09e | balrog | static void musicpal_audio_clock_update(musicpal_audio_state *s) |
311 | af83e09e | balrog | { |
312 | af83e09e | balrog | int rate;
|
313 | af83e09e | balrog | |
314 | af83e09e | balrog | if (s->playback_mode & MP_AUDIO_CLOCK_24MHZ)
|
315 | af83e09e | balrog | rate = 24576000 / 64; /* 24.576MHz */ |
316 | af83e09e | balrog | else
|
317 | af83e09e | balrog | rate = 11289600 / 64; /* 11.2896MHz */ |
318 | af83e09e | balrog | |
319 | af83e09e | balrog | rate /= ((s->clock_div >> 8) & 0xff) + 1; |
320 | af83e09e | balrog | |
321 | 91834991 | balrog | wm8750_set_bclk_in(s->wm, rate); |
322 | af83e09e | balrog | } |
323 | af83e09e | balrog | |
324 | 24859b68 | balrog | static uint32_t musicpal_audio_read(void *opaque, target_phys_addr_t offset) |
325 | 24859b68 | balrog | { |
326 | 24859b68 | balrog | musicpal_audio_state *s = opaque; |
327 | 24859b68 | balrog | |
328 | 24859b68 | balrog | switch (offset) {
|
329 | 24859b68 | balrog | case MP_AUDIO_PLAYBACK_MODE:
|
330 | 24859b68 | balrog | return s->playback_mode;
|
331 | 24859b68 | balrog | |
332 | 24859b68 | balrog | case MP_AUDIO_CLOCK_DIV:
|
333 | 24859b68 | balrog | return s->clock_div;
|
334 | 24859b68 | balrog | |
335 | 24859b68 | balrog | case MP_AUDIO_IRQ_STATUS:
|
336 | 24859b68 | balrog | return s->status;
|
337 | 24859b68 | balrog | |
338 | 24859b68 | balrog | case MP_AUDIO_IRQ_ENABLE:
|
339 | 24859b68 | balrog | return s->irq_enable;
|
340 | 24859b68 | balrog | |
341 | 24859b68 | balrog | case MP_AUDIO_TX_STATUS:
|
342 | 24859b68 | balrog | return s->play_pos >> 2; |
343 | 24859b68 | balrog | |
344 | 24859b68 | balrog | default:
|
345 | 24859b68 | balrog | return 0; |
346 | 24859b68 | balrog | } |
347 | 24859b68 | balrog | } |
348 | 24859b68 | balrog | |
349 | 24859b68 | balrog | static void musicpal_audio_write(void *opaque, target_phys_addr_t offset, |
350 | 24859b68 | balrog | uint32_t value) |
351 | 24859b68 | balrog | { |
352 | 24859b68 | balrog | musicpal_audio_state *s = opaque; |
353 | 24859b68 | balrog | |
354 | 24859b68 | balrog | switch (offset) {
|
355 | 24859b68 | balrog | case MP_AUDIO_PLAYBACK_MODE:
|
356 | 24859b68 | balrog | if (value & MP_AUDIO_PLAYBACK_EN &&
|
357 | 24859b68 | balrog | !(s->playback_mode & MP_AUDIO_PLAYBACK_EN)) { |
358 | 24859b68 | balrog | s->status = 0;
|
359 | 24859b68 | balrog | s->last_free = 0;
|
360 | 24859b68 | balrog | s->play_pos = 0;
|
361 | 24859b68 | balrog | } |
362 | 24859b68 | balrog | s->playback_mode = value; |
363 | af83e09e | balrog | musicpal_audio_clock_update(s); |
364 | 24859b68 | balrog | break;
|
365 | 24859b68 | balrog | |
366 | 24859b68 | balrog | case MP_AUDIO_CLOCK_DIV:
|
367 | 24859b68 | balrog | s->clock_div = value; |
368 | 24859b68 | balrog | s->last_free = 0;
|
369 | 24859b68 | balrog | s->play_pos = 0;
|
370 | af83e09e | balrog | musicpal_audio_clock_update(s); |
371 | 24859b68 | balrog | break;
|
372 | 24859b68 | balrog | |
373 | 24859b68 | balrog | case MP_AUDIO_IRQ_STATUS:
|
374 | 24859b68 | balrog | s->status &= ~value; |
375 | 24859b68 | balrog | break;
|
376 | 24859b68 | balrog | |
377 | 24859b68 | balrog | case MP_AUDIO_IRQ_ENABLE:
|
378 | 24859b68 | balrog | s->irq_enable = value; |
379 | 24859b68 | balrog | if (s->status & s->irq_enable)
|
380 | 24859b68 | balrog | qemu_irq_raise(s->irq); |
381 | 24859b68 | balrog | break;
|
382 | 24859b68 | balrog | |
383 | 24859b68 | balrog | case MP_AUDIO_TX_START_LO:
|
384 | 24859b68 | balrog | s->phys_buf = (s->phys_buf & 0xFFFF0000) | (value & 0xFFFF); |
385 | 930c8682 | pbrook | s->target_buffer = s->phys_buf; |
386 | 24859b68 | balrog | s->play_pos = 0;
|
387 | 24859b68 | balrog | s->last_free = 0;
|
388 | 24859b68 | balrog | break;
|
389 | 24859b68 | balrog | |
390 | 24859b68 | balrog | case MP_AUDIO_TX_THRESHOLD:
|
391 | 24859b68 | balrog | s->threshold = (value + 1) * 4; |
392 | 24859b68 | balrog | break;
|
393 | 24859b68 | balrog | |
394 | 24859b68 | balrog | case MP_AUDIO_TX_START_HI:
|
395 | 24859b68 | balrog | s->phys_buf = (s->phys_buf & 0xFFFF) | (value << 16); |
396 | 930c8682 | pbrook | s->target_buffer = s->phys_buf; |
397 | 24859b68 | balrog | s->play_pos = 0;
|
398 | 24859b68 | balrog | s->last_free = 0;
|
399 | 24859b68 | balrog | break;
|
400 | 24859b68 | balrog | } |
401 | 24859b68 | balrog | } |
402 | 24859b68 | balrog | |
403 | 24859b68 | balrog | static void musicpal_audio_reset(void *opaque) |
404 | 24859b68 | balrog | { |
405 | 24859b68 | balrog | musicpal_audio_state *s = opaque; |
406 | 24859b68 | balrog | |
407 | 24859b68 | balrog | s->playback_mode = 0;
|
408 | 24859b68 | balrog | s->status = 0;
|
409 | 24859b68 | balrog | s->irq_enable = 0;
|
410 | 24859b68 | balrog | } |
411 | 24859b68 | balrog | |
412 | 24859b68 | balrog | static CPUReadMemoryFunc *musicpal_audio_readfn[] = {
|
413 | 24859b68 | balrog | musicpal_audio_read, |
414 | 24859b68 | balrog | musicpal_audio_read, |
415 | 24859b68 | balrog | musicpal_audio_read |
416 | 24859b68 | balrog | }; |
417 | 24859b68 | balrog | |
418 | 24859b68 | balrog | static CPUWriteMemoryFunc *musicpal_audio_writefn[] = {
|
419 | 24859b68 | balrog | musicpal_audio_write, |
420 | 24859b68 | balrog | musicpal_audio_write, |
421 | 24859b68 | balrog | musicpal_audio_write |
422 | 24859b68 | balrog | }; |
423 | 24859b68 | balrog | |
424 | 718ec0be | malc | static i2c_interface *musicpal_audio_init(qemu_irq irq)
|
425 | 24859b68 | balrog | { |
426 | 24859b68 | balrog | musicpal_audio_state *s; |
427 | 24859b68 | balrog | i2c_interface *i2c; |
428 | 24859b68 | balrog | int iomemtype;
|
429 | 24859b68 | balrog | |
430 | 24859b68 | balrog | s = qemu_mallocz(sizeof(musicpal_audio_state));
|
431 | 24859b68 | balrog | s->irq = irq; |
432 | 24859b68 | balrog | |
433 | 24859b68 | balrog | i2c = qemu_mallocz(sizeof(i2c_interface));
|
434 | 02e2da45 | Paul Brook | i2c->bus = i2c_init_bus(NULL, "i2c"); |
435 | 24859b68 | balrog | i2c->current_addr = -1;
|
436 | 24859b68 | balrog | |
437 | cdbe40ca | Paul Brook | s->wm = i2c_create_slave(i2c->bus, "wm8750", MP_WM_ADDR);
|
438 | 24859b68 | balrog | wm8750_data_req_set(s->wm, audio_callback, s); |
439 | 24859b68 | balrog | |
440 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(musicpal_audio_readfn, |
441 | 24859b68 | balrog | musicpal_audio_writefn, s); |
442 | 718ec0be | malc | cpu_register_physical_memory(MP_AUDIO_BASE, MP_AUDIO_SIZE, iomemtype); |
443 | 24859b68 | balrog | |
444 | a08d4367 | Jan Kiszka | qemu_register_reset(musicpal_audio_reset, s); |
445 | 24859b68 | balrog | |
446 | 24859b68 | balrog | return i2c;
|
447 | 24859b68 | balrog | } |
448 | 24859b68 | balrog | #else /* !HAS_AUDIO */ |
449 | 718ec0be | malc | static i2c_interface *musicpal_audio_init(qemu_irq irq)
|
450 | 24859b68 | balrog | { |
451 | 24859b68 | balrog | return NULL; |
452 | 24859b68 | balrog | } |
453 | 24859b68 | balrog | #endif /* !HAS_AUDIO */ |
454 | 24859b68 | balrog | |
455 | 24859b68 | balrog | /* Ethernet register offsets */
|
456 | 24859b68 | balrog | #define MP_ETH_SMIR 0x010 |
457 | 24859b68 | balrog | #define MP_ETH_PCXR 0x408 |
458 | 24859b68 | balrog | #define MP_ETH_SDCMR 0x448 |
459 | 24859b68 | balrog | #define MP_ETH_ICR 0x450 |
460 | 24859b68 | balrog | #define MP_ETH_IMR 0x458 |
461 | 24859b68 | balrog | #define MP_ETH_FRDP0 0x480 |
462 | 24859b68 | balrog | #define MP_ETH_FRDP1 0x484 |
463 | 24859b68 | balrog | #define MP_ETH_FRDP2 0x488 |
464 | 24859b68 | balrog | #define MP_ETH_FRDP3 0x48C |
465 | 24859b68 | balrog | #define MP_ETH_CRDP0 0x4A0 |
466 | 24859b68 | balrog | #define MP_ETH_CRDP1 0x4A4 |
467 | 24859b68 | balrog | #define MP_ETH_CRDP2 0x4A8 |
468 | 24859b68 | balrog | #define MP_ETH_CRDP3 0x4AC |
469 | 24859b68 | balrog | #define MP_ETH_CTDP0 0x4E0 |
470 | 24859b68 | balrog | #define MP_ETH_CTDP1 0x4E4 |
471 | 24859b68 | balrog | #define MP_ETH_CTDP2 0x4E8 |
472 | 24859b68 | balrog | #define MP_ETH_CTDP3 0x4EC |
473 | 24859b68 | balrog | |
474 | 24859b68 | balrog | /* MII PHY access */
|
475 | 24859b68 | balrog | #define MP_ETH_SMIR_DATA 0x0000FFFF |
476 | 24859b68 | balrog | #define MP_ETH_SMIR_ADDR 0x03FF0000 |
477 | 24859b68 | balrog | #define MP_ETH_SMIR_OPCODE (1 << 26) /* Read value */ |
478 | 24859b68 | balrog | #define MP_ETH_SMIR_RDVALID (1 << 27) |
479 | 24859b68 | balrog | |
480 | 24859b68 | balrog | /* PHY registers */
|
481 | 24859b68 | balrog | #define MP_ETH_PHY1_BMSR 0x00210000 |
482 | 24859b68 | balrog | #define MP_ETH_PHY1_PHYSID1 0x00410000 |
483 | 24859b68 | balrog | #define MP_ETH_PHY1_PHYSID2 0x00610000 |
484 | 24859b68 | balrog | |
485 | 24859b68 | balrog | #define MP_PHY_BMSR_LINK 0x0004 |
486 | 24859b68 | balrog | #define MP_PHY_BMSR_AUTONEG 0x0008 |
487 | 24859b68 | balrog | |
488 | 24859b68 | balrog | #define MP_PHY_88E3015 0x01410E20 |
489 | 24859b68 | balrog | |
490 | 24859b68 | balrog | /* TX descriptor status */
|
491 | 24859b68 | balrog | #define MP_ETH_TX_OWN (1 << 31) |
492 | 24859b68 | balrog | |
493 | 24859b68 | balrog | /* RX descriptor status */
|
494 | 24859b68 | balrog | #define MP_ETH_RX_OWN (1 << 31) |
495 | 24859b68 | balrog | |
496 | 24859b68 | balrog | /* Interrupt cause/mask bits */
|
497 | 24859b68 | balrog | #define MP_ETH_IRQ_RX_BIT 0 |
498 | 24859b68 | balrog | #define MP_ETH_IRQ_RX (1 << MP_ETH_IRQ_RX_BIT) |
499 | 24859b68 | balrog | #define MP_ETH_IRQ_TXHI_BIT 2 |
500 | 24859b68 | balrog | #define MP_ETH_IRQ_TXLO_BIT 3 |
501 | 24859b68 | balrog | |
502 | 24859b68 | balrog | /* Port config bits */
|
503 | 24859b68 | balrog | #define MP_ETH_PCXR_2BSM_BIT 28 /* 2-byte incoming suffix */ |
504 | 24859b68 | balrog | |
505 | 24859b68 | balrog | /* SDMA command bits */
|
506 | 24859b68 | balrog | #define MP_ETH_CMD_TXHI (1 << 23) |
507 | 24859b68 | balrog | #define MP_ETH_CMD_TXLO (1 << 22) |
508 | 24859b68 | balrog | |
509 | 24859b68 | balrog | typedef struct mv88w8618_tx_desc { |
510 | 24859b68 | balrog | uint32_t cmdstat; |
511 | 24859b68 | balrog | uint16_t res; |
512 | 24859b68 | balrog | uint16_t bytes; |
513 | 24859b68 | balrog | uint32_t buffer; |
514 | 24859b68 | balrog | uint32_t next; |
515 | 24859b68 | balrog | } mv88w8618_tx_desc; |
516 | 24859b68 | balrog | |
517 | 24859b68 | balrog | typedef struct mv88w8618_rx_desc { |
518 | 24859b68 | balrog | uint32_t cmdstat; |
519 | 24859b68 | balrog | uint16_t bytes; |
520 | 24859b68 | balrog | uint16_t buffer_size; |
521 | 24859b68 | balrog | uint32_t buffer; |
522 | 24859b68 | balrog | uint32_t next; |
523 | 24859b68 | balrog | } mv88w8618_rx_desc; |
524 | 24859b68 | balrog | |
525 | 24859b68 | balrog | typedef struct mv88w8618_eth_state { |
526 | b47b50fa | Paul Brook | SysBusDevice busdev; |
527 | 24859b68 | balrog | qemu_irq irq; |
528 | 24859b68 | balrog | uint32_t smir; |
529 | 24859b68 | balrog | uint32_t icr; |
530 | 24859b68 | balrog | uint32_t imr; |
531 | b946a153 | aliguori | int mmio_index;
|
532 | 24859b68 | balrog | int vlan_header;
|
533 | 930c8682 | pbrook | uint32_t tx_queue[2];
|
534 | 930c8682 | pbrook | uint32_t rx_queue[4];
|
535 | 930c8682 | pbrook | uint32_t frx_queue[4];
|
536 | 930c8682 | pbrook | uint32_t cur_rx[4];
|
537 | 24859b68 | balrog | VLANClientState *vc; |
538 | 24859b68 | balrog | } mv88w8618_eth_state; |
539 | 24859b68 | balrog | |
540 | 930c8682 | pbrook | static void eth_rx_desc_put(uint32_t addr, mv88w8618_rx_desc *desc) |
541 | 930c8682 | pbrook | { |
542 | 930c8682 | pbrook | cpu_to_le32s(&desc->cmdstat); |
543 | 930c8682 | pbrook | cpu_to_le16s(&desc->bytes); |
544 | 930c8682 | pbrook | cpu_to_le16s(&desc->buffer_size); |
545 | 930c8682 | pbrook | cpu_to_le32s(&desc->buffer); |
546 | 930c8682 | pbrook | cpu_to_le32s(&desc->next); |
547 | 930c8682 | pbrook | cpu_physical_memory_write(addr, (void *)desc, sizeof(*desc)); |
548 | 930c8682 | pbrook | } |
549 | 930c8682 | pbrook | |
550 | 930c8682 | pbrook | static void eth_rx_desc_get(uint32_t addr, mv88w8618_rx_desc *desc) |
551 | 930c8682 | pbrook | { |
552 | 930c8682 | pbrook | cpu_physical_memory_read(addr, (void *)desc, sizeof(*desc)); |
553 | 930c8682 | pbrook | le32_to_cpus(&desc->cmdstat); |
554 | 930c8682 | pbrook | le16_to_cpus(&desc->bytes); |
555 | 930c8682 | pbrook | le16_to_cpus(&desc->buffer_size); |
556 | 930c8682 | pbrook | le32_to_cpus(&desc->buffer); |
557 | 930c8682 | pbrook | le32_to_cpus(&desc->next); |
558 | 930c8682 | pbrook | } |
559 | 930c8682 | pbrook | |
560 | e3f5ec2b | Mark McLoughlin | static int eth_can_receive(VLANClientState *vc) |
561 | 24859b68 | balrog | { |
562 | 24859b68 | balrog | return 1; |
563 | 24859b68 | balrog | } |
564 | 24859b68 | balrog | |
565 | 4f1c942b | Mark McLoughlin | static ssize_t eth_receive(VLANClientState *vc, const uint8_t *buf, size_t size) |
566 | 24859b68 | balrog | { |
567 | e3f5ec2b | Mark McLoughlin | mv88w8618_eth_state *s = vc->opaque; |
568 | 930c8682 | pbrook | uint32_t desc_addr; |
569 | 930c8682 | pbrook | mv88w8618_rx_desc desc; |
570 | 24859b68 | balrog | int i;
|
571 | 24859b68 | balrog | |
572 | 24859b68 | balrog | for (i = 0; i < 4; i++) { |
573 | 930c8682 | pbrook | desc_addr = s->cur_rx[i]; |
574 | 930c8682 | pbrook | if (!desc_addr)
|
575 | 24859b68 | balrog | continue;
|
576 | 24859b68 | balrog | do {
|
577 | 930c8682 | pbrook | eth_rx_desc_get(desc_addr, &desc); |
578 | 930c8682 | pbrook | if ((desc.cmdstat & MP_ETH_RX_OWN) && desc.buffer_size >= size) {
|
579 | 930c8682 | pbrook | cpu_physical_memory_write(desc.buffer + s->vlan_header, |
580 | 930c8682 | pbrook | buf, size); |
581 | 930c8682 | pbrook | desc.bytes = size + s->vlan_header; |
582 | 930c8682 | pbrook | desc.cmdstat &= ~MP_ETH_RX_OWN; |
583 | 930c8682 | pbrook | s->cur_rx[i] = desc.next; |
584 | 24859b68 | balrog | |
585 | 24859b68 | balrog | s->icr |= MP_ETH_IRQ_RX; |
586 | 24859b68 | balrog | if (s->icr & s->imr)
|
587 | 24859b68 | balrog | qemu_irq_raise(s->irq); |
588 | 930c8682 | pbrook | eth_rx_desc_put(desc_addr, &desc); |
589 | 4f1c942b | Mark McLoughlin | return size;
|
590 | 24859b68 | balrog | } |
591 | 930c8682 | pbrook | desc_addr = desc.next; |
592 | 930c8682 | pbrook | } while (desc_addr != s->rx_queue[i]);
|
593 | 24859b68 | balrog | } |
594 | 4f1c942b | Mark McLoughlin | return size;
|
595 | 24859b68 | balrog | } |
596 | 24859b68 | balrog | |
597 | 930c8682 | pbrook | static void eth_tx_desc_put(uint32_t addr, mv88w8618_tx_desc *desc) |
598 | 930c8682 | pbrook | { |
599 | 930c8682 | pbrook | cpu_to_le32s(&desc->cmdstat); |
600 | 930c8682 | pbrook | cpu_to_le16s(&desc->res); |
601 | 930c8682 | pbrook | cpu_to_le16s(&desc->bytes); |
602 | 930c8682 | pbrook | cpu_to_le32s(&desc->buffer); |
603 | 930c8682 | pbrook | cpu_to_le32s(&desc->next); |
604 | 930c8682 | pbrook | cpu_physical_memory_write(addr, (void *)desc, sizeof(*desc)); |
605 | 930c8682 | pbrook | } |
606 | 930c8682 | pbrook | |
607 | 930c8682 | pbrook | static void eth_tx_desc_get(uint32_t addr, mv88w8618_tx_desc *desc) |
608 | 930c8682 | pbrook | { |
609 | 930c8682 | pbrook | cpu_physical_memory_read(addr, (void *)desc, sizeof(*desc)); |
610 | 930c8682 | pbrook | le32_to_cpus(&desc->cmdstat); |
611 | 930c8682 | pbrook | le16_to_cpus(&desc->res); |
612 | 930c8682 | pbrook | le16_to_cpus(&desc->bytes); |
613 | 930c8682 | pbrook | le32_to_cpus(&desc->buffer); |
614 | 930c8682 | pbrook | le32_to_cpus(&desc->next); |
615 | 930c8682 | pbrook | } |
616 | 930c8682 | pbrook | |
617 | 24859b68 | balrog | static void eth_send(mv88w8618_eth_state *s, int queue_index) |
618 | 24859b68 | balrog | { |
619 | 930c8682 | pbrook | uint32_t desc_addr = s->tx_queue[queue_index]; |
620 | 930c8682 | pbrook | mv88w8618_tx_desc desc; |
621 | 930c8682 | pbrook | uint8_t buf[2048];
|
622 | 930c8682 | pbrook | int len;
|
623 | 930c8682 | pbrook | |
624 | 24859b68 | balrog | |
625 | 24859b68 | balrog | do {
|
626 | 930c8682 | pbrook | eth_tx_desc_get(desc_addr, &desc); |
627 | 930c8682 | pbrook | if (desc.cmdstat & MP_ETH_TX_OWN) {
|
628 | 930c8682 | pbrook | len = desc.bytes; |
629 | 930c8682 | pbrook | if (len < 2048) { |
630 | 930c8682 | pbrook | cpu_physical_memory_read(desc.buffer, buf, len); |
631 | 930c8682 | pbrook | qemu_send_packet(s->vc, buf, len); |
632 | 930c8682 | pbrook | } |
633 | 930c8682 | pbrook | desc.cmdstat &= ~MP_ETH_TX_OWN; |
634 | 24859b68 | balrog | s->icr |= 1 << (MP_ETH_IRQ_TXLO_BIT - queue_index);
|
635 | 930c8682 | pbrook | eth_tx_desc_put(desc_addr, &desc); |
636 | 24859b68 | balrog | } |
637 | 930c8682 | pbrook | desc_addr = desc.next; |
638 | 930c8682 | pbrook | } while (desc_addr != s->tx_queue[queue_index]);
|
639 | 24859b68 | balrog | } |
640 | 24859b68 | balrog | |
641 | 24859b68 | balrog | static uint32_t mv88w8618_eth_read(void *opaque, target_phys_addr_t offset) |
642 | 24859b68 | balrog | { |
643 | 24859b68 | balrog | mv88w8618_eth_state *s = opaque; |
644 | 24859b68 | balrog | |
645 | 24859b68 | balrog | switch (offset) {
|
646 | 24859b68 | balrog | case MP_ETH_SMIR:
|
647 | 24859b68 | balrog | if (s->smir & MP_ETH_SMIR_OPCODE) {
|
648 | 24859b68 | balrog | switch (s->smir & MP_ETH_SMIR_ADDR) {
|
649 | 24859b68 | balrog | case MP_ETH_PHY1_BMSR:
|
650 | 24859b68 | balrog | return MP_PHY_BMSR_LINK | MP_PHY_BMSR_AUTONEG |
|
651 | 24859b68 | balrog | MP_ETH_SMIR_RDVALID; |
652 | 24859b68 | balrog | case MP_ETH_PHY1_PHYSID1:
|
653 | 24859b68 | balrog | return (MP_PHY_88E3015 >> 16) | MP_ETH_SMIR_RDVALID; |
654 | 24859b68 | balrog | case MP_ETH_PHY1_PHYSID2:
|
655 | 24859b68 | balrog | return (MP_PHY_88E3015 & 0xFFFF) | MP_ETH_SMIR_RDVALID; |
656 | 24859b68 | balrog | default:
|
657 | 24859b68 | balrog | return MP_ETH_SMIR_RDVALID;
|
658 | 24859b68 | balrog | } |
659 | 24859b68 | balrog | } |
660 | 24859b68 | balrog | return 0; |
661 | 24859b68 | balrog | |
662 | 24859b68 | balrog | case MP_ETH_ICR:
|
663 | 24859b68 | balrog | return s->icr;
|
664 | 24859b68 | balrog | |
665 | 24859b68 | balrog | case MP_ETH_IMR:
|
666 | 24859b68 | balrog | return s->imr;
|
667 | 24859b68 | balrog | |
668 | 24859b68 | balrog | case MP_ETH_FRDP0 ... MP_ETH_FRDP3:
|
669 | 930c8682 | pbrook | return s->frx_queue[(offset - MP_ETH_FRDP0)/4]; |
670 | 24859b68 | balrog | |
671 | 24859b68 | balrog | case MP_ETH_CRDP0 ... MP_ETH_CRDP3:
|
672 | 930c8682 | pbrook | return s->rx_queue[(offset - MP_ETH_CRDP0)/4]; |
673 | 24859b68 | balrog | |
674 | 24859b68 | balrog | case MP_ETH_CTDP0 ... MP_ETH_CTDP3:
|
675 | 930c8682 | pbrook | return s->tx_queue[(offset - MP_ETH_CTDP0)/4]; |
676 | 24859b68 | balrog | |
677 | 24859b68 | balrog | default:
|
678 | 24859b68 | balrog | return 0; |
679 | 24859b68 | balrog | } |
680 | 24859b68 | balrog | } |
681 | 24859b68 | balrog | |
682 | 24859b68 | balrog | static void mv88w8618_eth_write(void *opaque, target_phys_addr_t offset, |
683 | 24859b68 | balrog | uint32_t value) |
684 | 24859b68 | balrog | { |
685 | 24859b68 | balrog | mv88w8618_eth_state *s = opaque; |
686 | 24859b68 | balrog | |
687 | 24859b68 | balrog | switch (offset) {
|
688 | 24859b68 | balrog | case MP_ETH_SMIR:
|
689 | 24859b68 | balrog | s->smir = value; |
690 | 24859b68 | balrog | break;
|
691 | 24859b68 | balrog | |
692 | 24859b68 | balrog | case MP_ETH_PCXR:
|
693 | 24859b68 | balrog | s->vlan_header = ((value >> MP_ETH_PCXR_2BSM_BIT) & 1) * 2; |
694 | 24859b68 | balrog | break;
|
695 | 24859b68 | balrog | |
696 | 24859b68 | balrog | case MP_ETH_SDCMR:
|
697 | 24859b68 | balrog | if (value & MP_ETH_CMD_TXHI)
|
698 | 24859b68 | balrog | eth_send(s, 1);
|
699 | 24859b68 | balrog | if (value & MP_ETH_CMD_TXLO)
|
700 | 24859b68 | balrog | eth_send(s, 0);
|
701 | 24859b68 | balrog | if (value & (MP_ETH_CMD_TXHI | MP_ETH_CMD_TXLO) && s->icr & s->imr)
|
702 | 24859b68 | balrog | qemu_irq_raise(s->irq); |
703 | 24859b68 | balrog | break;
|
704 | 24859b68 | balrog | |
705 | 24859b68 | balrog | case MP_ETH_ICR:
|
706 | 24859b68 | balrog | s->icr &= value; |
707 | 24859b68 | balrog | break;
|
708 | 24859b68 | balrog | |
709 | 24859b68 | balrog | case MP_ETH_IMR:
|
710 | 24859b68 | balrog | s->imr = value; |
711 | 24859b68 | balrog | if (s->icr & s->imr)
|
712 | 24859b68 | balrog | qemu_irq_raise(s->irq); |
713 | 24859b68 | balrog | break;
|
714 | 24859b68 | balrog | |
715 | 24859b68 | balrog | case MP_ETH_FRDP0 ... MP_ETH_FRDP3:
|
716 | 930c8682 | pbrook | s->frx_queue[(offset - MP_ETH_FRDP0)/4] = value;
|
717 | 24859b68 | balrog | break;
|
718 | 24859b68 | balrog | |
719 | 24859b68 | balrog | case MP_ETH_CRDP0 ... MP_ETH_CRDP3:
|
720 | 24859b68 | balrog | s->rx_queue[(offset - MP_ETH_CRDP0)/4] =
|
721 | 930c8682 | pbrook | s->cur_rx[(offset - MP_ETH_CRDP0)/4] = value;
|
722 | 24859b68 | balrog | break;
|
723 | 24859b68 | balrog | |
724 | 24859b68 | balrog | case MP_ETH_CTDP0 ... MP_ETH_CTDP3:
|
725 | 930c8682 | pbrook | s->tx_queue[(offset - MP_ETH_CTDP0)/4] = value;
|
726 | 24859b68 | balrog | break;
|
727 | 24859b68 | balrog | } |
728 | 24859b68 | balrog | } |
729 | 24859b68 | balrog | |
730 | 24859b68 | balrog | static CPUReadMemoryFunc *mv88w8618_eth_readfn[] = {
|
731 | 24859b68 | balrog | mv88w8618_eth_read, |
732 | 24859b68 | balrog | mv88w8618_eth_read, |
733 | 24859b68 | balrog | mv88w8618_eth_read |
734 | 24859b68 | balrog | }; |
735 | 24859b68 | balrog | |
736 | 24859b68 | balrog | static CPUWriteMemoryFunc *mv88w8618_eth_writefn[] = {
|
737 | 24859b68 | balrog | mv88w8618_eth_write, |
738 | 24859b68 | balrog | mv88w8618_eth_write, |
739 | 24859b68 | balrog | mv88w8618_eth_write |
740 | 24859b68 | balrog | }; |
741 | 24859b68 | balrog | |
742 | b946a153 | aliguori | static void eth_cleanup(VLANClientState *vc) |
743 | b946a153 | aliguori | { |
744 | b946a153 | aliguori | mv88w8618_eth_state *s = vc->opaque; |
745 | b946a153 | aliguori | |
746 | b946a153 | aliguori | cpu_unregister_io_memory(s->mmio_index); |
747 | b946a153 | aliguori | |
748 | b946a153 | aliguori | qemu_free(s); |
749 | b946a153 | aliguori | } |
750 | b946a153 | aliguori | |
751 | b47b50fa | Paul Brook | static void mv88w8618_eth_init(SysBusDevice *dev) |
752 | 24859b68 | balrog | { |
753 | b47b50fa | Paul Brook | mv88w8618_eth_state *s = FROM_SYSBUS(mv88w8618_eth_state, dev); |
754 | 0ae18cee | aliguori | |
755 | b47b50fa | Paul Brook | sysbus_init_irq(dev, &s->irq); |
756 | b47b50fa | Paul Brook | s->vc = qdev_get_vlan_client(&dev->qdev, |
757 | 463af534 | Mark McLoughlin | eth_can_receive, eth_receive, NULL,
|
758 | b946a153 | aliguori | eth_cleanup, s); |
759 | 1eed09cb | Avi Kivity | s->mmio_index = cpu_register_io_memory(mv88w8618_eth_readfn, |
760 | b946a153 | aliguori | mv88w8618_eth_writefn, s); |
761 | b47b50fa | Paul Brook | sysbus_init_mmio(dev, MP_ETH_SIZE, s->mmio_index); |
762 | 24859b68 | balrog | } |
763 | 24859b68 | balrog | |
764 | 24859b68 | balrog | /* LCD register offsets */
|
765 | 24859b68 | balrog | #define MP_LCD_IRQCTRL 0x180 |
766 | 24859b68 | balrog | #define MP_LCD_IRQSTAT 0x184 |
767 | 24859b68 | balrog | #define MP_LCD_SPICTRL 0x1ac |
768 | 24859b68 | balrog | #define MP_LCD_INST 0x1bc |
769 | 24859b68 | balrog | #define MP_LCD_DATA 0x1c0 |
770 | 24859b68 | balrog | |
771 | 24859b68 | balrog | /* Mode magics */
|
772 | 24859b68 | balrog | #define MP_LCD_SPI_DATA 0x00100011 |
773 | 24859b68 | balrog | #define MP_LCD_SPI_CMD 0x00104011 |
774 | 24859b68 | balrog | #define MP_LCD_SPI_INVALID 0x00000000 |
775 | 24859b68 | balrog | |
776 | 24859b68 | balrog | /* Commmands */
|
777 | 24859b68 | balrog | #define MP_LCD_INST_SETPAGE0 0xB0 |
778 | 24859b68 | balrog | /* ... */
|
779 | 24859b68 | balrog | #define MP_LCD_INST_SETPAGE7 0xB7 |
780 | 24859b68 | balrog | |
781 | 24859b68 | balrog | #define MP_LCD_TEXTCOLOR 0xe0e0ff /* RRGGBB */ |
782 | 24859b68 | balrog | |
783 | 24859b68 | balrog | typedef struct musicpal_lcd_state { |
784 | b47b50fa | Paul Brook | SysBusDevice busdev; |
785 | 24859b68 | balrog | uint32_t mode; |
786 | 24859b68 | balrog | uint32_t irqctrl; |
787 | 24859b68 | balrog | int page;
|
788 | 24859b68 | balrog | int page_off;
|
789 | 24859b68 | balrog | DisplayState *ds; |
790 | 24859b68 | balrog | uint8_t video_ram[128*64/8]; |
791 | 24859b68 | balrog | } musicpal_lcd_state; |
792 | 24859b68 | balrog | |
793 | 24859b68 | balrog | static uint32_t lcd_brightness;
|
794 | 24859b68 | balrog | |
795 | 24859b68 | balrog | static uint8_t scale_lcd_color(uint8_t col)
|
796 | 24859b68 | balrog | { |
797 | 24859b68 | balrog | int tmp = col;
|
798 | 24859b68 | balrog | |
799 | 24859b68 | balrog | switch (lcd_brightness) {
|
800 | 24859b68 | balrog | case 0x00000007: /* 0 */ |
801 | 24859b68 | balrog | return 0; |
802 | 24859b68 | balrog | |
803 | 24859b68 | balrog | case 0x00020000: /* 1 */ |
804 | 24859b68 | balrog | return (tmp * 1) / 7; |
805 | 24859b68 | balrog | |
806 | 24859b68 | balrog | case 0x00020001: /* 2 */ |
807 | 24859b68 | balrog | return (tmp * 2) / 7; |
808 | 24859b68 | balrog | |
809 | 24859b68 | balrog | case 0x00040000: /* 3 */ |
810 | 24859b68 | balrog | return (tmp * 3) / 7; |
811 | 24859b68 | balrog | |
812 | 24859b68 | balrog | case 0x00010006: /* 4 */ |
813 | 24859b68 | balrog | return (tmp * 4) / 7; |
814 | 24859b68 | balrog | |
815 | 24859b68 | balrog | case 0x00020005: /* 5 */ |
816 | 24859b68 | balrog | return (tmp * 5) / 7; |
817 | 24859b68 | balrog | |
818 | 24859b68 | balrog | case 0x00040003: /* 6 */ |
819 | 24859b68 | balrog | return (tmp * 6) / 7; |
820 | 24859b68 | balrog | |
821 | 24859b68 | balrog | case 0x00030004: /* 7 */ |
822 | 24859b68 | balrog | default:
|
823 | 24859b68 | balrog | return col;
|
824 | 24859b68 | balrog | } |
825 | 24859b68 | balrog | } |
826 | 24859b68 | balrog | |
827 | 0266f2c7 | balrog | #define SET_LCD_PIXEL(depth, type) \
|
828 | 0266f2c7 | balrog | static inline void glue(set_lcd_pixel, depth) \ |
829 | 0266f2c7 | balrog | (musicpal_lcd_state *s, int x, int y, type col) \ |
830 | 0266f2c7 | balrog | { \ |
831 | 0266f2c7 | balrog | int dx, dy; \
|
832 | 0e1f5a0c | aliguori | type *pixel = &((type *) ds_get_data(s->ds))[(y * 128 * 3 + x) * 3]; \ |
833 | 0266f2c7 | balrog | \ |
834 | 0266f2c7 | balrog | for (dy = 0; dy < 3; dy++, pixel += 127 * 3) \ |
835 | 0266f2c7 | balrog | for (dx = 0; dx < 3; dx++, pixel++) \ |
836 | 0266f2c7 | balrog | *pixel = col; \ |
837 | 24859b68 | balrog | } |
838 | 0266f2c7 | balrog | SET_LCD_PIXEL(8, uint8_t)
|
839 | 0266f2c7 | balrog | SET_LCD_PIXEL(16, uint16_t)
|
840 | 0266f2c7 | balrog | SET_LCD_PIXEL(32, uint32_t)
|
841 | 0266f2c7 | balrog | |
842 | 0266f2c7 | balrog | #include "pixel_ops.h" |
843 | 24859b68 | balrog | |
844 | 24859b68 | balrog | static void lcd_refresh(void *opaque) |
845 | 24859b68 | balrog | { |
846 | 24859b68 | balrog | musicpal_lcd_state *s = opaque; |
847 | 0266f2c7 | balrog | int x, y, col;
|
848 | 24859b68 | balrog | |
849 | 0e1f5a0c | aliguori | switch (ds_get_bits_per_pixel(s->ds)) {
|
850 | 0266f2c7 | balrog | case 0: |
851 | 0266f2c7 | balrog | return;
|
852 | 0266f2c7 | balrog | #define LCD_REFRESH(depth, func) \
|
853 | 0266f2c7 | balrog | case depth: \
|
854 | 0266f2c7 | balrog | col = func(scale_lcd_color((MP_LCD_TEXTCOLOR >> 16) & 0xff), \ |
855 | 0266f2c7 | balrog | scale_lcd_color((MP_LCD_TEXTCOLOR >> 8) & 0xff), \ |
856 | 0266f2c7 | balrog | scale_lcd_color(MP_LCD_TEXTCOLOR & 0xff)); \
|
857 | 0266f2c7 | balrog | for (x = 0; x < 128; x++) \ |
858 | 0266f2c7 | balrog | for (y = 0; y < 64; y++) \ |
859 | 0266f2c7 | balrog | if (s->video_ram[x + (y/8)*128] & (1 << (y % 8))) \ |
860 | 0266f2c7 | balrog | glue(set_lcd_pixel, depth)(s, x, y, col); \ |
861 | 0266f2c7 | balrog | else \
|
862 | 0266f2c7 | balrog | glue(set_lcd_pixel, depth)(s, x, y, 0); \
|
863 | 0266f2c7 | balrog | break;
|
864 | 0266f2c7 | balrog | LCD_REFRESH(8, rgb_to_pixel8)
|
865 | 0266f2c7 | balrog | LCD_REFRESH(16, rgb_to_pixel16)
|
866 | bf9b48af | aliguori | LCD_REFRESH(32, (is_surface_bgr(s->ds->surface) ?
|
867 | bf9b48af | aliguori | rgb_to_pixel32bgr : rgb_to_pixel32)) |
868 | 0266f2c7 | balrog | default:
|
869 | 2ac71179 | Paul Brook | hw_error("unsupported colour depth %i\n",
|
870 | 0e1f5a0c | aliguori | ds_get_bits_per_pixel(s->ds)); |
871 | 0266f2c7 | balrog | } |
872 | 24859b68 | balrog | |
873 | 24859b68 | balrog | dpy_update(s->ds, 0, 0, 128*3, 64*3); |
874 | 24859b68 | balrog | } |
875 | 24859b68 | balrog | |
876 | 167bc3d2 | balrog | static void lcd_invalidate(void *opaque) |
877 | 167bc3d2 | balrog | { |
878 | 167bc3d2 | balrog | } |
879 | 167bc3d2 | balrog | |
880 | 24859b68 | balrog | static uint32_t musicpal_lcd_read(void *opaque, target_phys_addr_t offset) |
881 | 24859b68 | balrog | { |
882 | 24859b68 | balrog | musicpal_lcd_state *s = opaque; |
883 | 24859b68 | balrog | |
884 | 24859b68 | balrog | switch (offset) {
|
885 | 24859b68 | balrog | case MP_LCD_IRQCTRL:
|
886 | 24859b68 | balrog | return s->irqctrl;
|
887 | 24859b68 | balrog | |
888 | 24859b68 | balrog | default:
|
889 | 24859b68 | balrog | return 0; |
890 | 24859b68 | balrog | } |
891 | 24859b68 | balrog | } |
892 | 24859b68 | balrog | |
893 | 24859b68 | balrog | static void musicpal_lcd_write(void *opaque, target_phys_addr_t offset, |
894 | 24859b68 | balrog | uint32_t value) |
895 | 24859b68 | balrog | { |
896 | 24859b68 | balrog | musicpal_lcd_state *s = opaque; |
897 | 24859b68 | balrog | |
898 | 24859b68 | balrog | switch (offset) {
|
899 | 24859b68 | balrog | case MP_LCD_IRQCTRL:
|
900 | 24859b68 | balrog | s->irqctrl = value; |
901 | 24859b68 | balrog | break;
|
902 | 24859b68 | balrog | |
903 | 24859b68 | balrog | case MP_LCD_SPICTRL:
|
904 | 24859b68 | balrog | if (value == MP_LCD_SPI_DATA || value == MP_LCD_SPI_CMD)
|
905 | 24859b68 | balrog | s->mode = value; |
906 | 24859b68 | balrog | else
|
907 | 24859b68 | balrog | s->mode = MP_LCD_SPI_INVALID; |
908 | 24859b68 | balrog | break;
|
909 | 24859b68 | balrog | |
910 | 24859b68 | balrog | case MP_LCD_INST:
|
911 | 24859b68 | balrog | if (value >= MP_LCD_INST_SETPAGE0 && value <= MP_LCD_INST_SETPAGE7) {
|
912 | 24859b68 | balrog | s->page = value - MP_LCD_INST_SETPAGE0; |
913 | 24859b68 | balrog | s->page_off = 0;
|
914 | 24859b68 | balrog | } |
915 | 24859b68 | balrog | break;
|
916 | 24859b68 | balrog | |
917 | 24859b68 | balrog | case MP_LCD_DATA:
|
918 | 24859b68 | balrog | if (s->mode == MP_LCD_SPI_CMD) {
|
919 | 24859b68 | balrog | if (value >= MP_LCD_INST_SETPAGE0 &&
|
920 | 24859b68 | balrog | value <= MP_LCD_INST_SETPAGE7) { |
921 | 24859b68 | balrog | s->page = value - MP_LCD_INST_SETPAGE0; |
922 | 24859b68 | balrog | s->page_off = 0;
|
923 | 24859b68 | balrog | } |
924 | 24859b68 | balrog | } else if (s->mode == MP_LCD_SPI_DATA) { |
925 | 24859b68 | balrog | s->video_ram[s->page*128 + s->page_off] = value;
|
926 | 24859b68 | balrog | s->page_off = (s->page_off + 1) & 127; |
927 | 24859b68 | balrog | } |
928 | 24859b68 | balrog | break;
|
929 | 24859b68 | balrog | } |
930 | 24859b68 | balrog | } |
931 | 24859b68 | balrog | |
932 | 24859b68 | balrog | static CPUReadMemoryFunc *musicpal_lcd_readfn[] = {
|
933 | 24859b68 | balrog | musicpal_lcd_read, |
934 | 24859b68 | balrog | musicpal_lcd_read, |
935 | 24859b68 | balrog | musicpal_lcd_read |
936 | 24859b68 | balrog | }; |
937 | 24859b68 | balrog | |
938 | 24859b68 | balrog | static CPUWriteMemoryFunc *musicpal_lcd_writefn[] = {
|
939 | 24859b68 | balrog | musicpal_lcd_write, |
940 | 24859b68 | balrog | musicpal_lcd_write, |
941 | 24859b68 | balrog | musicpal_lcd_write |
942 | 24859b68 | balrog | }; |
943 | 24859b68 | balrog | |
944 | b47b50fa | Paul Brook | static void musicpal_lcd_init(SysBusDevice *dev) |
945 | 24859b68 | balrog | { |
946 | b47b50fa | Paul Brook | musicpal_lcd_state *s = FROM_SYSBUS(musicpal_lcd_state, dev); |
947 | 24859b68 | balrog | int iomemtype;
|
948 | 24859b68 | balrog | |
949 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(musicpal_lcd_readfn, |
950 | 24859b68 | balrog | musicpal_lcd_writefn, s); |
951 | b47b50fa | Paul Brook | sysbus_init_mmio(dev, MP_LCD_SIZE, iomemtype); |
952 | 718ec0be | malc | cpu_register_physical_memory(MP_LCD_BASE, MP_LCD_SIZE, iomemtype); |
953 | 24859b68 | balrog | |
954 | 3023f332 | aliguori | s->ds = graphic_console_init(lcd_refresh, lcd_invalidate, |
955 | 3023f332 | aliguori | NULL, NULL, s); |
956 | 3023f332 | aliguori | qemu_console_resize(s->ds, 128*3, 64*3); |
957 | 24859b68 | balrog | } |
958 | 24859b68 | balrog | |
959 | 24859b68 | balrog | /* PIC register offsets */
|
960 | 24859b68 | balrog | #define MP_PIC_STATUS 0x00 |
961 | 24859b68 | balrog | #define MP_PIC_ENABLE_SET 0x08 |
962 | 24859b68 | balrog | #define MP_PIC_ENABLE_CLR 0x0C |
963 | 24859b68 | balrog | |
964 | 24859b68 | balrog | typedef struct mv88w8618_pic_state |
965 | 24859b68 | balrog | { |
966 | b47b50fa | Paul Brook | SysBusDevice busdev; |
967 | 24859b68 | balrog | uint32_t level; |
968 | 24859b68 | balrog | uint32_t enabled; |
969 | 24859b68 | balrog | qemu_irq parent_irq; |
970 | 24859b68 | balrog | } mv88w8618_pic_state; |
971 | 24859b68 | balrog | |
972 | 24859b68 | balrog | static void mv88w8618_pic_update(mv88w8618_pic_state *s) |
973 | 24859b68 | balrog | { |
974 | 24859b68 | balrog | qemu_set_irq(s->parent_irq, (s->level & s->enabled)); |
975 | 24859b68 | balrog | } |
976 | 24859b68 | balrog | |
977 | 24859b68 | balrog | static void mv88w8618_pic_set_irq(void *opaque, int irq, int level) |
978 | 24859b68 | balrog | { |
979 | 24859b68 | balrog | mv88w8618_pic_state *s = opaque; |
980 | 24859b68 | balrog | |
981 | 24859b68 | balrog | if (level)
|
982 | 24859b68 | balrog | s->level |= 1 << irq;
|
983 | 24859b68 | balrog | else
|
984 | 24859b68 | balrog | s->level &= ~(1 << irq);
|
985 | 24859b68 | balrog | mv88w8618_pic_update(s); |
986 | 24859b68 | balrog | } |
987 | 24859b68 | balrog | |
988 | 24859b68 | balrog | static uint32_t mv88w8618_pic_read(void *opaque, target_phys_addr_t offset) |
989 | 24859b68 | balrog | { |
990 | 24859b68 | balrog | mv88w8618_pic_state *s = opaque; |
991 | 24859b68 | balrog | |
992 | 24859b68 | balrog | switch (offset) {
|
993 | 24859b68 | balrog | case MP_PIC_STATUS:
|
994 | 24859b68 | balrog | return s->level & s->enabled;
|
995 | 24859b68 | balrog | |
996 | 24859b68 | balrog | default:
|
997 | 24859b68 | balrog | return 0; |
998 | 24859b68 | balrog | } |
999 | 24859b68 | balrog | } |
1000 | 24859b68 | balrog | |
1001 | 24859b68 | balrog | static void mv88w8618_pic_write(void *opaque, target_phys_addr_t offset, |
1002 | 24859b68 | balrog | uint32_t value) |
1003 | 24859b68 | balrog | { |
1004 | 24859b68 | balrog | mv88w8618_pic_state *s = opaque; |
1005 | 24859b68 | balrog | |
1006 | 24859b68 | balrog | switch (offset) {
|
1007 | 24859b68 | balrog | case MP_PIC_ENABLE_SET:
|
1008 | 24859b68 | balrog | s->enabled |= value; |
1009 | 24859b68 | balrog | break;
|
1010 | 24859b68 | balrog | |
1011 | 24859b68 | balrog | case MP_PIC_ENABLE_CLR:
|
1012 | 24859b68 | balrog | s->enabled &= ~value; |
1013 | 24859b68 | balrog | s->level &= ~value; |
1014 | 24859b68 | balrog | break;
|
1015 | 24859b68 | balrog | } |
1016 | 24859b68 | balrog | mv88w8618_pic_update(s); |
1017 | 24859b68 | balrog | } |
1018 | 24859b68 | balrog | |
1019 | 24859b68 | balrog | static void mv88w8618_pic_reset(void *opaque) |
1020 | 24859b68 | balrog | { |
1021 | 24859b68 | balrog | mv88w8618_pic_state *s = opaque; |
1022 | 24859b68 | balrog | |
1023 | 24859b68 | balrog | s->level = 0;
|
1024 | 24859b68 | balrog | s->enabled = 0;
|
1025 | 24859b68 | balrog | } |
1026 | 24859b68 | balrog | |
1027 | 24859b68 | balrog | static CPUReadMemoryFunc *mv88w8618_pic_readfn[] = {
|
1028 | 24859b68 | balrog | mv88w8618_pic_read, |
1029 | 24859b68 | balrog | mv88w8618_pic_read, |
1030 | 24859b68 | balrog | mv88w8618_pic_read |
1031 | 24859b68 | balrog | }; |
1032 | 24859b68 | balrog | |
1033 | 24859b68 | balrog | static CPUWriteMemoryFunc *mv88w8618_pic_writefn[] = {
|
1034 | 24859b68 | balrog | mv88w8618_pic_write, |
1035 | 24859b68 | balrog | mv88w8618_pic_write, |
1036 | 24859b68 | balrog | mv88w8618_pic_write |
1037 | 24859b68 | balrog | }; |
1038 | 24859b68 | balrog | |
1039 | b47b50fa | Paul Brook | static void mv88w8618_pic_init(SysBusDevice *dev) |
1040 | 24859b68 | balrog | { |
1041 | b47b50fa | Paul Brook | mv88w8618_pic_state *s = FROM_SYSBUS(mv88w8618_pic_state, dev); |
1042 | 24859b68 | balrog | int iomemtype;
|
1043 | 24859b68 | balrog | |
1044 | 067a3ddc | Paul Brook | qdev_init_gpio_in(&dev->qdev, mv88w8618_pic_set_irq, 32);
|
1045 | b47b50fa | Paul Brook | sysbus_init_irq(dev, &s->parent_irq); |
1046 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(mv88w8618_pic_readfn, |
1047 | 24859b68 | balrog | mv88w8618_pic_writefn, s); |
1048 | b47b50fa | Paul Brook | sysbus_init_mmio(dev, MP_PIC_SIZE, iomemtype); |
1049 | 24859b68 | balrog | |
1050 | a08d4367 | Jan Kiszka | qemu_register_reset(mv88w8618_pic_reset, s); |
1051 | 24859b68 | balrog | } |
1052 | 24859b68 | balrog | |
1053 | 24859b68 | balrog | /* PIT register offsets */
|
1054 | 24859b68 | balrog | #define MP_PIT_TIMER1_LENGTH 0x00 |
1055 | 24859b68 | balrog | /* ... */
|
1056 | 24859b68 | balrog | #define MP_PIT_TIMER4_LENGTH 0x0C |
1057 | 24859b68 | balrog | #define MP_PIT_CONTROL 0x10 |
1058 | 24859b68 | balrog | #define MP_PIT_TIMER1_VALUE 0x14 |
1059 | 24859b68 | balrog | /* ... */
|
1060 | 24859b68 | balrog | #define MP_PIT_TIMER4_VALUE 0x20 |
1061 | 24859b68 | balrog | #define MP_BOARD_RESET 0x34 |
1062 | 24859b68 | balrog | |
1063 | 24859b68 | balrog | /* Magic board reset value (probably some watchdog behind it) */
|
1064 | 24859b68 | balrog | #define MP_BOARD_RESET_MAGIC 0x10000 |
1065 | 24859b68 | balrog | |
1066 | 24859b68 | balrog | typedef struct mv88w8618_timer_state { |
1067 | b47b50fa | Paul Brook | ptimer_state *ptimer; |
1068 | 24859b68 | balrog | uint32_t limit; |
1069 | 24859b68 | balrog | int freq;
|
1070 | 24859b68 | balrog | qemu_irq irq; |
1071 | 24859b68 | balrog | } mv88w8618_timer_state; |
1072 | 24859b68 | balrog | |
1073 | 24859b68 | balrog | typedef struct mv88w8618_pit_state { |
1074 | b47b50fa | Paul Brook | SysBusDevice busdev; |
1075 | b47b50fa | Paul Brook | mv88w8618_timer_state timer[4];
|
1076 | 24859b68 | balrog | uint32_t control; |
1077 | 24859b68 | balrog | } mv88w8618_pit_state; |
1078 | 24859b68 | balrog | |
1079 | 24859b68 | balrog | static void mv88w8618_timer_tick(void *opaque) |
1080 | 24859b68 | balrog | { |
1081 | 24859b68 | balrog | mv88w8618_timer_state *s = opaque; |
1082 | 24859b68 | balrog | |
1083 | 24859b68 | balrog | qemu_irq_raise(s->irq); |
1084 | 24859b68 | balrog | } |
1085 | 24859b68 | balrog | |
1086 | b47b50fa | Paul Brook | static void mv88w8618_timer_init(SysBusDevice *dev, mv88w8618_timer_state *s, |
1087 | b47b50fa | Paul Brook | uint32_t freq) |
1088 | 24859b68 | balrog | { |
1089 | 24859b68 | balrog | QEMUBH *bh; |
1090 | 24859b68 | balrog | |
1091 | b47b50fa | Paul Brook | sysbus_init_irq(dev, &s->irq); |
1092 | 24859b68 | balrog | s->freq = freq; |
1093 | 24859b68 | balrog | |
1094 | 24859b68 | balrog | bh = qemu_bh_new(mv88w8618_timer_tick, s); |
1095 | b47b50fa | Paul Brook | s->ptimer = ptimer_init(bh); |
1096 | 24859b68 | balrog | } |
1097 | 24859b68 | balrog | |
1098 | 24859b68 | balrog | static uint32_t mv88w8618_pit_read(void *opaque, target_phys_addr_t offset) |
1099 | 24859b68 | balrog | { |
1100 | 24859b68 | balrog | mv88w8618_pit_state *s = opaque; |
1101 | 24859b68 | balrog | mv88w8618_timer_state *t; |
1102 | 24859b68 | balrog | |
1103 | 24859b68 | balrog | switch (offset) {
|
1104 | 24859b68 | balrog | case MP_PIT_TIMER1_VALUE ... MP_PIT_TIMER4_VALUE:
|
1105 | b47b50fa | Paul Brook | t = &s->timer[(offset-MP_PIT_TIMER1_VALUE) >> 2];
|
1106 | b47b50fa | Paul Brook | return ptimer_get_count(t->ptimer);
|
1107 | 24859b68 | balrog | |
1108 | 24859b68 | balrog | default:
|
1109 | 24859b68 | balrog | return 0; |
1110 | 24859b68 | balrog | } |
1111 | 24859b68 | balrog | } |
1112 | 24859b68 | balrog | |
1113 | 24859b68 | balrog | static void mv88w8618_pit_write(void *opaque, target_phys_addr_t offset, |
1114 | 24859b68 | balrog | uint32_t value) |
1115 | 24859b68 | balrog | { |
1116 | 24859b68 | balrog | mv88w8618_pit_state *s = opaque; |
1117 | 24859b68 | balrog | mv88w8618_timer_state *t; |
1118 | 24859b68 | balrog | int i;
|
1119 | 24859b68 | balrog | |
1120 | 24859b68 | balrog | switch (offset) {
|
1121 | 24859b68 | balrog | case MP_PIT_TIMER1_LENGTH ... MP_PIT_TIMER4_LENGTH:
|
1122 | b47b50fa | Paul Brook | t = &s->timer[offset >> 2];
|
1123 | 24859b68 | balrog | t->limit = value; |
1124 | b47b50fa | Paul Brook | ptimer_set_limit(t->ptimer, t->limit, 1);
|
1125 | 24859b68 | balrog | break;
|
1126 | 24859b68 | balrog | |
1127 | 24859b68 | balrog | case MP_PIT_CONTROL:
|
1128 | 24859b68 | balrog | for (i = 0; i < 4; i++) { |
1129 | 24859b68 | balrog | if (value & 0xf) { |
1130 | b47b50fa | Paul Brook | t = &s->timer[i]; |
1131 | b47b50fa | Paul Brook | ptimer_set_limit(t->ptimer, t->limit, 0);
|
1132 | b47b50fa | Paul Brook | ptimer_set_freq(t->ptimer, t->freq); |
1133 | b47b50fa | Paul Brook | ptimer_run(t->ptimer, 0);
|
1134 | 24859b68 | balrog | } |
1135 | 24859b68 | balrog | value >>= 4;
|
1136 | 24859b68 | balrog | } |
1137 | 24859b68 | balrog | break;
|
1138 | 24859b68 | balrog | |
1139 | 24859b68 | balrog | case MP_BOARD_RESET:
|
1140 | 24859b68 | balrog | if (value == MP_BOARD_RESET_MAGIC)
|
1141 | 24859b68 | balrog | qemu_system_reset_request(); |
1142 | 24859b68 | balrog | break;
|
1143 | 24859b68 | balrog | } |
1144 | 24859b68 | balrog | } |
1145 | 24859b68 | balrog | |
1146 | 24859b68 | balrog | static CPUReadMemoryFunc *mv88w8618_pit_readfn[] = {
|
1147 | 24859b68 | balrog | mv88w8618_pit_read, |
1148 | 24859b68 | balrog | mv88w8618_pit_read, |
1149 | 24859b68 | balrog | mv88w8618_pit_read |
1150 | 24859b68 | balrog | }; |
1151 | 24859b68 | balrog | |
1152 | 24859b68 | balrog | static CPUWriteMemoryFunc *mv88w8618_pit_writefn[] = {
|
1153 | 24859b68 | balrog | mv88w8618_pit_write, |
1154 | 24859b68 | balrog | mv88w8618_pit_write, |
1155 | 24859b68 | balrog | mv88w8618_pit_write |
1156 | 24859b68 | balrog | }; |
1157 | 24859b68 | balrog | |
1158 | b47b50fa | Paul Brook | static void mv88w8618_pit_init(SysBusDevice *dev) |
1159 | 24859b68 | balrog | { |
1160 | 24859b68 | balrog | int iomemtype;
|
1161 | b47b50fa | Paul Brook | mv88w8618_pit_state *s = FROM_SYSBUS(mv88w8618_pit_state, dev); |
1162 | b47b50fa | Paul Brook | int i;
|
1163 | 24859b68 | balrog | |
1164 | 24859b68 | balrog | /* Letting them all run at 1 MHz is likely just a pragmatic
|
1165 | 24859b68 | balrog | * simplification. */
|
1166 | b47b50fa | Paul Brook | for (i = 0; i < 4; i++) { |
1167 | b47b50fa | Paul Brook | mv88w8618_timer_init(dev, &s->timer[i], 1000000);
|
1168 | b47b50fa | Paul Brook | } |
1169 | 24859b68 | balrog | |
1170 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(mv88w8618_pit_readfn, |
1171 | 24859b68 | balrog | mv88w8618_pit_writefn, s); |
1172 | b47b50fa | Paul Brook | sysbus_init_mmio(dev, MP_PIT_SIZE, iomemtype); |
1173 | 24859b68 | balrog | } |
1174 | 24859b68 | balrog | |
1175 | 24859b68 | balrog | /* Flash config register offsets */
|
1176 | 24859b68 | balrog | #define MP_FLASHCFG_CFGR0 0x04 |
1177 | 24859b68 | balrog | |
1178 | 24859b68 | balrog | typedef struct mv88w8618_flashcfg_state { |
1179 | b47b50fa | Paul Brook | SysBusDevice busdev; |
1180 | 24859b68 | balrog | uint32_t cfgr0; |
1181 | 24859b68 | balrog | } mv88w8618_flashcfg_state; |
1182 | 24859b68 | balrog | |
1183 | 24859b68 | balrog | static uint32_t mv88w8618_flashcfg_read(void *opaque, |
1184 | 24859b68 | balrog | target_phys_addr_t offset) |
1185 | 24859b68 | balrog | { |
1186 | 24859b68 | balrog | mv88w8618_flashcfg_state *s = opaque; |
1187 | 24859b68 | balrog | |
1188 | 24859b68 | balrog | switch (offset) {
|
1189 | 24859b68 | balrog | case MP_FLASHCFG_CFGR0:
|
1190 | 24859b68 | balrog | return s->cfgr0;
|
1191 | 24859b68 | balrog | |
1192 | 24859b68 | balrog | default:
|
1193 | 24859b68 | balrog | return 0; |
1194 | 24859b68 | balrog | } |
1195 | 24859b68 | balrog | } |
1196 | 24859b68 | balrog | |
1197 | 24859b68 | balrog | static void mv88w8618_flashcfg_write(void *opaque, target_phys_addr_t offset, |
1198 | 24859b68 | balrog | uint32_t value) |
1199 | 24859b68 | balrog | { |
1200 | 24859b68 | balrog | mv88w8618_flashcfg_state *s = opaque; |
1201 | 24859b68 | balrog | |
1202 | 24859b68 | balrog | switch (offset) {
|
1203 | 24859b68 | balrog | case MP_FLASHCFG_CFGR0:
|
1204 | 24859b68 | balrog | s->cfgr0 = value; |
1205 | 24859b68 | balrog | break;
|
1206 | 24859b68 | balrog | } |
1207 | 24859b68 | balrog | } |
1208 | 24859b68 | balrog | |
1209 | 24859b68 | balrog | static CPUReadMemoryFunc *mv88w8618_flashcfg_readfn[] = {
|
1210 | 24859b68 | balrog | mv88w8618_flashcfg_read, |
1211 | 24859b68 | balrog | mv88w8618_flashcfg_read, |
1212 | 24859b68 | balrog | mv88w8618_flashcfg_read |
1213 | 24859b68 | balrog | }; |
1214 | 24859b68 | balrog | |
1215 | 24859b68 | balrog | static CPUWriteMemoryFunc *mv88w8618_flashcfg_writefn[] = {
|
1216 | 24859b68 | balrog | mv88w8618_flashcfg_write, |
1217 | 24859b68 | balrog | mv88w8618_flashcfg_write, |
1218 | 24859b68 | balrog | mv88w8618_flashcfg_write |
1219 | 24859b68 | balrog | }; |
1220 | 24859b68 | balrog | |
1221 | b47b50fa | Paul Brook | static void mv88w8618_flashcfg_init(SysBusDevice *dev) |
1222 | 24859b68 | balrog | { |
1223 | 24859b68 | balrog | int iomemtype;
|
1224 | b47b50fa | Paul Brook | mv88w8618_flashcfg_state *s = FROM_SYSBUS(mv88w8618_flashcfg_state, dev); |
1225 | 24859b68 | balrog | |
1226 | 24859b68 | balrog | s->cfgr0 = 0xfffe4285; /* Default as set by U-Boot for 8 MB flash */ |
1227 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(mv88w8618_flashcfg_readfn, |
1228 | 24859b68 | balrog | mv88w8618_flashcfg_writefn, s); |
1229 | b47b50fa | Paul Brook | sysbus_init_mmio(dev, MP_FLASHCFG_SIZE, iomemtype); |
1230 | 24859b68 | balrog | } |
1231 | 24859b68 | balrog | |
1232 | 718ec0be | malc | /* Misc register offsets */
|
1233 | 718ec0be | malc | #define MP_MISC_BOARD_REVISION 0x18 |
1234 | 718ec0be | malc | |
1235 | 718ec0be | malc | #define MP_BOARD_REVISION 0x31 |
1236 | 718ec0be | malc | |
1237 | 718ec0be | malc | static uint32_t musicpal_misc_read(void *opaque, target_phys_addr_t offset) |
1238 | 718ec0be | malc | { |
1239 | 718ec0be | malc | switch (offset) {
|
1240 | 718ec0be | malc | case MP_MISC_BOARD_REVISION:
|
1241 | 718ec0be | malc | return MP_BOARD_REVISION;
|
1242 | 718ec0be | malc | |
1243 | 718ec0be | malc | default:
|
1244 | 718ec0be | malc | return 0; |
1245 | 718ec0be | malc | } |
1246 | 718ec0be | malc | } |
1247 | 718ec0be | malc | |
1248 | 718ec0be | malc | static void musicpal_misc_write(void *opaque, target_phys_addr_t offset, |
1249 | 718ec0be | malc | uint32_t value) |
1250 | 718ec0be | malc | { |
1251 | 718ec0be | malc | } |
1252 | 718ec0be | malc | |
1253 | 718ec0be | malc | static CPUReadMemoryFunc *musicpal_misc_readfn[] = {
|
1254 | 718ec0be | malc | musicpal_misc_read, |
1255 | 718ec0be | malc | musicpal_misc_read, |
1256 | 718ec0be | malc | musicpal_misc_read, |
1257 | 718ec0be | malc | }; |
1258 | 718ec0be | malc | |
1259 | 718ec0be | malc | static CPUWriteMemoryFunc *musicpal_misc_writefn[] = {
|
1260 | 718ec0be | malc | musicpal_misc_write, |
1261 | 718ec0be | malc | musicpal_misc_write, |
1262 | 718ec0be | malc | musicpal_misc_write, |
1263 | 718ec0be | malc | }; |
1264 | 718ec0be | malc | |
1265 | 718ec0be | malc | static void musicpal_misc_init(void) |
1266 | 718ec0be | malc | { |
1267 | 718ec0be | malc | int iomemtype;
|
1268 | 718ec0be | malc | |
1269 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(musicpal_misc_readfn, |
1270 | 718ec0be | malc | musicpal_misc_writefn, NULL);
|
1271 | 718ec0be | malc | cpu_register_physical_memory(MP_MISC_BASE, MP_MISC_SIZE, iomemtype); |
1272 | 718ec0be | malc | } |
1273 | 718ec0be | malc | |
1274 | 718ec0be | malc | /* WLAN register offsets */
|
1275 | 718ec0be | malc | #define MP_WLAN_MAGIC1 0x11c |
1276 | 718ec0be | malc | #define MP_WLAN_MAGIC2 0x124 |
1277 | 718ec0be | malc | |
1278 | 718ec0be | malc | static uint32_t mv88w8618_wlan_read(void *opaque, target_phys_addr_t offset) |
1279 | 718ec0be | malc | { |
1280 | 718ec0be | malc | switch (offset) {
|
1281 | 718ec0be | malc | /* Workaround to allow loading the binary-only wlandrv.ko crap
|
1282 | 718ec0be | malc | * from the original Freecom firmware. */
|
1283 | 718ec0be | malc | case MP_WLAN_MAGIC1:
|
1284 | 718ec0be | malc | return ~3; |
1285 | 718ec0be | malc | case MP_WLAN_MAGIC2:
|
1286 | 718ec0be | malc | return -1; |
1287 | 718ec0be | malc | |
1288 | 718ec0be | malc | default:
|
1289 | 718ec0be | malc | return 0; |
1290 | 718ec0be | malc | } |
1291 | 718ec0be | malc | } |
1292 | 718ec0be | malc | |
1293 | 718ec0be | malc | static void mv88w8618_wlan_write(void *opaque, target_phys_addr_t offset, |
1294 | 718ec0be | malc | uint32_t value) |
1295 | 718ec0be | malc | { |
1296 | 718ec0be | malc | } |
1297 | 718ec0be | malc | |
1298 | 718ec0be | malc | static CPUReadMemoryFunc *mv88w8618_wlan_readfn[] = {
|
1299 | 718ec0be | malc | mv88w8618_wlan_read, |
1300 | 718ec0be | malc | mv88w8618_wlan_read, |
1301 | 718ec0be | malc | mv88w8618_wlan_read, |
1302 | 718ec0be | malc | }; |
1303 | 718ec0be | malc | |
1304 | 718ec0be | malc | static CPUWriteMemoryFunc *mv88w8618_wlan_writefn[] = {
|
1305 | 718ec0be | malc | mv88w8618_wlan_write, |
1306 | 718ec0be | malc | mv88w8618_wlan_write, |
1307 | 718ec0be | malc | mv88w8618_wlan_write, |
1308 | 718ec0be | malc | }; |
1309 | 718ec0be | malc | |
1310 | b47b50fa | Paul Brook | static void mv88w8618_wlan_init(SysBusDevice *dev) |
1311 | 718ec0be | malc | { |
1312 | 718ec0be | malc | int iomemtype;
|
1313 | 24859b68 | balrog | |
1314 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(mv88w8618_wlan_readfn, |
1315 | 718ec0be | malc | mv88w8618_wlan_writefn, NULL);
|
1316 | b47b50fa | Paul Brook | sysbus_init_mmio(dev, MP_WLAN_SIZE, iomemtype); |
1317 | 718ec0be | malc | } |
1318 | 24859b68 | balrog | |
1319 | 718ec0be | malc | /* GPIO register offsets */
|
1320 | 718ec0be | malc | #define MP_GPIO_OE_LO 0x008 |
1321 | 718ec0be | malc | #define MP_GPIO_OUT_LO 0x00c |
1322 | 718ec0be | malc | #define MP_GPIO_IN_LO 0x010 |
1323 | 718ec0be | malc | #define MP_GPIO_ISR_LO 0x020 |
1324 | 718ec0be | malc | #define MP_GPIO_OE_HI 0x508 |
1325 | 718ec0be | malc | #define MP_GPIO_OUT_HI 0x50c |
1326 | 718ec0be | malc | #define MP_GPIO_IN_HI 0x510 |
1327 | 718ec0be | malc | #define MP_GPIO_ISR_HI 0x520 |
1328 | 24859b68 | balrog | |
1329 | 24859b68 | balrog | /* GPIO bits & masks */
|
1330 | 24859b68 | balrog | #define MP_GPIO_WHEEL_VOL (1 << 8) |
1331 | 24859b68 | balrog | #define MP_GPIO_WHEEL_VOL_INV (1 << 9) |
1332 | 24859b68 | balrog | #define MP_GPIO_WHEEL_NAV (1 << 10) |
1333 | 24859b68 | balrog | #define MP_GPIO_WHEEL_NAV_INV (1 << 11) |
1334 | 24859b68 | balrog | #define MP_GPIO_LCD_BRIGHTNESS 0x00070000 |
1335 | 24859b68 | balrog | #define MP_GPIO_BTN_FAVORITS (1 << 19) |
1336 | 24859b68 | balrog | #define MP_GPIO_BTN_MENU (1 << 20) |
1337 | 24859b68 | balrog | #define MP_GPIO_BTN_VOLUME (1 << 21) |
1338 | 24859b68 | balrog | #define MP_GPIO_BTN_NAVIGATION (1 << 22) |
1339 | 24859b68 | balrog | #define MP_GPIO_I2C_DATA_BIT 29 |
1340 | 24859b68 | balrog | #define MP_GPIO_I2C_DATA (1 << MP_GPIO_I2C_DATA_BIT) |
1341 | 24859b68 | balrog | #define MP_GPIO_I2C_CLOCK_BIT 30 |
1342 | 24859b68 | balrog | |
1343 | 24859b68 | balrog | /* LCD brightness bits in GPIO_OE_HI */
|
1344 | 24859b68 | balrog | #define MP_OE_LCD_BRIGHTNESS 0x0007 |
1345 | 24859b68 | balrog | |
1346 | 718ec0be | malc | static uint32_t musicpal_gpio_read(void *opaque, target_phys_addr_t offset) |
1347 | 24859b68 | balrog | { |
1348 | 24859b68 | balrog | switch (offset) {
|
1349 | 24859b68 | balrog | case MP_GPIO_OE_HI: /* used for LCD brightness control */ |
1350 | 24859b68 | balrog | return lcd_brightness & MP_OE_LCD_BRIGHTNESS;
|
1351 | 24859b68 | balrog | |
1352 | 24859b68 | balrog | case MP_GPIO_OUT_LO:
|
1353 | 24859b68 | balrog | return gpio_out_state & 0xFFFF; |
1354 | 24859b68 | balrog | case MP_GPIO_OUT_HI:
|
1355 | 24859b68 | balrog | return gpio_out_state >> 16; |
1356 | 24859b68 | balrog | |
1357 | 24859b68 | balrog | case MP_GPIO_IN_LO:
|
1358 | 24859b68 | balrog | return gpio_in_state & 0xFFFF; |
1359 | 24859b68 | balrog | case MP_GPIO_IN_HI:
|
1360 | 24859b68 | balrog | /* Update received I2C data */
|
1361 | 24859b68 | balrog | gpio_in_state = (gpio_in_state & ~MP_GPIO_I2C_DATA) | |
1362 | 24859b68 | balrog | (i2c_get_data(mixer_i2c) << MP_GPIO_I2C_DATA_BIT); |
1363 | 24859b68 | balrog | return gpio_in_state >> 16; |
1364 | 24859b68 | balrog | |
1365 | 24859b68 | balrog | case MP_GPIO_ISR_LO:
|
1366 | 7c6ce4ba | balrog | return gpio_isr & 0xFFFF; |
1367 | 24859b68 | balrog | case MP_GPIO_ISR_HI:
|
1368 | 7c6ce4ba | balrog | return gpio_isr >> 16; |
1369 | 24859b68 | balrog | |
1370 | 24859b68 | balrog | default:
|
1371 | 24859b68 | balrog | return 0; |
1372 | 24859b68 | balrog | } |
1373 | 24859b68 | balrog | } |
1374 | 24859b68 | balrog | |
1375 | 718ec0be | malc | static void musicpal_gpio_write(void *opaque, target_phys_addr_t offset, |
1376 | 718ec0be | malc | uint32_t value) |
1377 | 24859b68 | balrog | { |
1378 | 24859b68 | balrog | switch (offset) {
|
1379 | 24859b68 | balrog | case MP_GPIO_OE_HI: /* used for LCD brightness control */ |
1380 | 24859b68 | balrog | lcd_brightness = (lcd_brightness & MP_GPIO_LCD_BRIGHTNESS) | |
1381 | 24859b68 | balrog | (value & MP_OE_LCD_BRIGHTNESS); |
1382 | 24859b68 | balrog | break;
|
1383 | 24859b68 | balrog | |
1384 | 24859b68 | balrog | case MP_GPIO_OUT_LO:
|
1385 | 24859b68 | balrog | gpio_out_state = (gpio_out_state & 0xFFFF0000) | (value & 0xFFFF); |
1386 | 24859b68 | balrog | break;
|
1387 | 24859b68 | balrog | case MP_GPIO_OUT_HI:
|
1388 | 24859b68 | balrog | gpio_out_state = (gpio_out_state & 0xFFFF) | (value << 16); |
1389 | 24859b68 | balrog | lcd_brightness = (lcd_brightness & 0xFFFF) |
|
1390 | 24859b68 | balrog | (gpio_out_state & MP_GPIO_LCD_BRIGHTNESS); |
1391 | 24859b68 | balrog | i2c_state_update(mixer_i2c, |
1392 | 24859b68 | balrog | (gpio_out_state >> MP_GPIO_I2C_DATA_BIT) & 1,
|
1393 | 24859b68 | balrog | (gpio_out_state >> MP_GPIO_I2C_CLOCK_BIT) & 1);
|
1394 | 24859b68 | balrog | break;
|
1395 | 24859b68 | balrog | |
1396 | 24859b68 | balrog | } |
1397 | 24859b68 | balrog | } |
1398 | 24859b68 | balrog | |
1399 | 718ec0be | malc | static CPUReadMemoryFunc *musicpal_gpio_readfn[] = {
|
1400 | 718ec0be | malc | musicpal_gpio_read, |
1401 | 718ec0be | malc | musicpal_gpio_read, |
1402 | 718ec0be | malc | musicpal_gpio_read, |
1403 | 718ec0be | malc | }; |
1404 | 718ec0be | malc | |
1405 | 718ec0be | malc | static CPUWriteMemoryFunc *musicpal_gpio_writefn[] = {
|
1406 | 718ec0be | malc | musicpal_gpio_write, |
1407 | 718ec0be | malc | musicpal_gpio_write, |
1408 | 718ec0be | malc | musicpal_gpio_write, |
1409 | 718ec0be | malc | }; |
1410 | 718ec0be | malc | |
1411 | 718ec0be | malc | static void musicpal_gpio_init(void) |
1412 | 718ec0be | malc | { |
1413 | 718ec0be | malc | int iomemtype;
|
1414 | 718ec0be | malc | |
1415 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(musicpal_gpio_readfn, |
1416 | 718ec0be | malc | musicpal_gpio_writefn, NULL);
|
1417 | 718ec0be | malc | cpu_register_physical_memory(MP_GPIO_BASE, MP_GPIO_SIZE, iomemtype); |
1418 | 718ec0be | malc | } |
1419 | 718ec0be | malc | |
1420 | 24859b68 | balrog | /* Keyboard codes & masks */
|
1421 | 7c6ce4ba | balrog | #define KEY_RELEASED 0x80 |
1422 | 24859b68 | balrog | #define KEY_CODE 0x7f |
1423 | 24859b68 | balrog | |
1424 | 24859b68 | balrog | #define KEYCODE_TAB 0x0f |
1425 | 24859b68 | balrog | #define KEYCODE_ENTER 0x1c |
1426 | 24859b68 | balrog | #define KEYCODE_F 0x21 |
1427 | 24859b68 | balrog | #define KEYCODE_M 0x32 |
1428 | 24859b68 | balrog | |
1429 | 24859b68 | balrog | #define KEYCODE_EXTENDED 0xe0 |
1430 | 24859b68 | balrog | #define KEYCODE_UP 0x48 |
1431 | 24859b68 | balrog | #define KEYCODE_DOWN 0x50 |
1432 | 24859b68 | balrog | #define KEYCODE_LEFT 0x4b |
1433 | 24859b68 | balrog | #define KEYCODE_RIGHT 0x4d |
1434 | 24859b68 | balrog | |
1435 | 24859b68 | balrog | static void musicpal_key_event(void *opaque, int keycode) |
1436 | 24859b68 | balrog | { |
1437 | 24859b68 | balrog | qemu_irq irq = opaque; |
1438 | 24859b68 | balrog | uint32_t event = 0;
|
1439 | 24859b68 | balrog | static int kbd_extended; |
1440 | 24859b68 | balrog | |
1441 | 24859b68 | balrog | if (keycode == KEYCODE_EXTENDED) {
|
1442 | 24859b68 | balrog | kbd_extended = 1;
|
1443 | 24859b68 | balrog | return;
|
1444 | 24859b68 | balrog | } |
1445 | 24859b68 | balrog | |
1446 | 24859b68 | balrog | if (kbd_extended)
|
1447 | 24859b68 | balrog | switch (keycode & KEY_CODE) {
|
1448 | 24859b68 | balrog | case KEYCODE_UP:
|
1449 | 24859b68 | balrog | event = MP_GPIO_WHEEL_NAV | MP_GPIO_WHEEL_NAV_INV; |
1450 | 24859b68 | balrog | break;
|
1451 | 24859b68 | balrog | |
1452 | 24859b68 | balrog | case KEYCODE_DOWN:
|
1453 | 24859b68 | balrog | event = MP_GPIO_WHEEL_NAV; |
1454 | 24859b68 | balrog | break;
|
1455 | 24859b68 | balrog | |
1456 | 24859b68 | balrog | case KEYCODE_LEFT:
|
1457 | 24859b68 | balrog | event = MP_GPIO_WHEEL_VOL | MP_GPIO_WHEEL_VOL_INV; |
1458 | 24859b68 | balrog | break;
|
1459 | 24859b68 | balrog | |
1460 | 24859b68 | balrog | case KEYCODE_RIGHT:
|
1461 | 24859b68 | balrog | event = MP_GPIO_WHEEL_VOL; |
1462 | 24859b68 | balrog | break;
|
1463 | 24859b68 | balrog | } |
1464 | 7c6ce4ba | balrog | else {
|
1465 | 24859b68 | balrog | switch (keycode & KEY_CODE) {
|
1466 | 24859b68 | balrog | case KEYCODE_F:
|
1467 | 24859b68 | balrog | event = MP_GPIO_BTN_FAVORITS; |
1468 | 24859b68 | balrog | break;
|
1469 | 24859b68 | balrog | |
1470 | 24859b68 | balrog | case KEYCODE_TAB:
|
1471 | 24859b68 | balrog | event = MP_GPIO_BTN_VOLUME; |
1472 | 24859b68 | balrog | break;
|
1473 | 24859b68 | balrog | |
1474 | 24859b68 | balrog | case KEYCODE_ENTER:
|
1475 | 24859b68 | balrog | event = MP_GPIO_BTN_NAVIGATION; |
1476 | 24859b68 | balrog | break;
|
1477 | 24859b68 | balrog | |
1478 | 24859b68 | balrog | case KEYCODE_M:
|
1479 | 24859b68 | balrog | event = MP_GPIO_BTN_MENU; |
1480 | 24859b68 | balrog | break;
|
1481 | 24859b68 | balrog | } |
1482 | 7c6ce4ba | balrog | /* Do not repeat already pressed buttons */
|
1483 | 7c6ce4ba | balrog | if (!(keycode & KEY_RELEASED) && !(gpio_in_state & event))
|
1484 | 7c6ce4ba | balrog | event = 0;
|
1485 | 7c6ce4ba | balrog | } |
1486 | 24859b68 | balrog | |
1487 | 7c6ce4ba | balrog | if (event) {
|
1488 | 7c6ce4ba | balrog | if (keycode & KEY_RELEASED) {
|
1489 | 7c6ce4ba | balrog | gpio_in_state |= event; |
1490 | 7c6ce4ba | balrog | } else {
|
1491 | 7c6ce4ba | balrog | gpio_in_state &= ~event; |
1492 | 7c6ce4ba | balrog | gpio_isr = event; |
1493 | 7c6ce4ba | balrog | qemu_irq_raise(irq); |
1494 | 7c6ce4ba | balrog | } |
1495 | 24859b68 | balrog | } |
1496 | 24859b68 | balrog | |
1497 | 24859b68 | balrog | kbd_extended = 0;
|
1498 | 24859b68 | balrog | } |
1499 | 24859b68 | balrog | |
1500 | 24859b68 | balrog | static struct arm_boot_info musicpal_binfo = { |
1501 | 24859b68 | balrog | .loader_start = 0x0,
|
1502 | 24859b68 | balrog | .board_id = 0x20e,
|
1503 | 24859b68 | balrog | }; |
1504 | 24859b68 | balrog | |
1505 | fbe1b595 | Paul Brook | static void musicpal_init(ram_addr_t ram_size, |
1506 | 3023f332 | aliguori | const char *boot_device, |
1507 | 24859b68 | balrog | const char *kernel_filename, const char *kernel_cmdline, |
1508 | 24859b68 | balrog | const char *initrd_filename, const char *cpu_model) |
1509 | 24859b68 | balrog | { |
1510 | 24859b68 | balrog | CPUState *env; |
1511 | b47b50fa | Paul Brook | qemu_irq *cpu_pic; |
1512 | b47b50fa | Paul Brook | qemu_irq pic[32];
|
1513 | b47b50fa | Paul Brook | DeviceState *dev; |
1514 | b47b50fa | Paul Brook | int i;
|
1515 | 24859b68 | balrog | int index;
|
1516 | 24859b68 | balrog | unsigned long flash_size; |
1517 | 24859b68 | balrog | |
1518 | 24859b68 | balrog | if (!cpu_model)
|
1519 | 24859b68 | balrog | cpu_model = "arm926";
|
1520 | 24859b68 | balrog | |
1521 | 24859b68 | balrog | env = cpu_init(cpu_model); |
1522 | 24859b68 | balrog | if (!env) {
|
1523 | 24859b68 | balrog | fprintf(stderr, "Unable to find CPU definition\n");
|
1524 | 24859b68 | balrog | exit(1);
|
1525 | 24859b68 | balrog | } |
1526 | b47b50fa | Paul Brook | cpu_pic = arm_pic_init_cpu(env); |
1527 | 24859b68 | balrog | |
1528 | 24859b68 | balrog | /* For now we use a fixed - the original - RAM size */
|
1529 | 24859b68 | balrog | cpu_register_physical_memory(0, MP_RAM_DEFAULT_SIZE,
|
1530 | 24859b68 | balrog | qemu_ram_alloc(MP_RAM_DEFAULT_SIZE)); |
1531 | 24859b68 | balrog | |
1532 | 24859b68 | balrog | sram_off = qemu_ram_alloc(MP_SRAM_SIZE); |
1533 | 24859b68 | balrog | cpu_register_physical_memory(MP_SRAM_BASE, MP_SRAM_SIZE, sram_off); |
1534 | 24859b68 | balrog | |
1535 | b47b50fa | Paul Brook | dev = sysbus_create_simple("mv88w8618_pic", MP_PIC_BASE,
|
1536 | b47b50fa | Paul Brook | cpu_pic[ARM_PIC_CPU_IRQ]); |
1537 | b47b50fa | Paul Brook | for (i = 0; i < 32; i++) { |
1538 | 067a3ddc | Paul Brook | pic[i] = qdev_get_gpio_in(dev, i); |
1539 | b47b50fa | Paul Brook | } |
1540 | b47b50fa | Paul Brook | sysbus_create_varargs("mv88w8618_pit", MP_PIT_BASE, pic[MP_TIMER1_IRQ],
|
1541 | b47b50fa | Paul Brook | pic[MP_TIMER2_IRQ], pic[MP_TIMER3_IRQ], |
1542 | b47b50fa | Paul Brook | pic[MP_TIMER4_IRQ], NULL);
|
1543 | 24859b68 | balrog | |
1544 | 24859b68 | balrog | if (serial_hds[0]) |
1545 | b6cd0ea1 | aurel32 | serial_mm_init(MP_UART1_BASE, 2, pic[MP_UART1_IRQ], 1825000, |
1546 | 24859b68 | balrog | serial_hds[0], 1); |
1547 | 24859b68 | balrog | if (serial_hds[1]) |
1548 | b6cd0ea1 | aurel32 | serial_mm_init(MP_UART2_BASE, 2, pic[MP_UART2_IRQ], 1825000, |
1549 | 24859b68 | balrog | serial_hds[1], 1); |
1550 | 24859b68 | balrog | |
1551 | 24859b68 | balrog | /* Register flash */
|
1552 | 24859b68 | balrog | index = drive_get_index(IF_PFLASH, 0, 0); |
1553 | 24859b68 | balrog | if (index != -1) { |
1554 | 24859b68 | balrog | flash_size = bdrv_getlength(drives_table[index].bdrv); |
1555 | 24859b68 | balrog | if (flash_size != 8*1024*1024 && flash_size != 16*1024*1024 && |
1556 | 24859b68 | balrog | flash_size != 32*1024*1024) { |
1557 | 24859b68 | balrog | fprintf(stderr, "Invalid flash image size\n");
|
1558 | 24859b68 | balrog | exit(1);
|
1559 | 24859b68 | balrog | } |
1560 | 24859b68 | balrog | |
1561 | 24859b68 | balrog | /*
|
1562 | 24859b68 | balrog | * The original U-Boot accesses the flash at 0xFE000000 instead of
|
1563 | 24859b68 | balrog | * 0xFF800000 (if there is 8 MB flash). So remap flash access if the
|
1564 | 24859b68 | balrog | * image is smaller than 32 MB.
|
1565 | 24859b68 | balrog | */
|
1566 | 24859b68 | balrog | pflash_cfi02_register(0-MP_FLASH_SIZE_MAX, qemu_ram_alloc(flash_size),
|
1567 | 24859b68 | balrog | drives_table[index].bdrv, 0x10000,
|
1568 | 24859b68 | balrog | (flash_size + 0xffff) >> 16, |
1569 | 24859b68 | balrog | MP_FLASH_SIZE_MAX / flash_size, |
1570 | 24859b68 | balrog | 2, 0x00BF, 0x236D, 0x0000, 0x0000, |
1571 | 24859b68 | balrog | 0x5555, 0x2AAA); |
1572 | 24859b68 | balrog | } |
1573 | b47b50fa | Paul Brook | sysbus_create_simple("mv88w8618_flashcfg", MP_FLASHCFG_BASE, NULL); |
1574 | 24859b68 | balrog | |
1575 | b47b50fa | Paul Brook | sysbus_create_simple("musicpal_lcd", MP_LCD_BASE, NULL); |
1576 | 24859b68 | balrog | |
1577 | 24859b68 | balrog | qemu_add_kbd_event_handler(musicpal_key_event, pic[MP_GPIO_IRQ]); |
1578 | 24859b68 | balrog | |
1579 | b47b50fa | Paul Brook | qemu_check_nic_model(&nd_table[0], "mv88w8618"); |
1580 | b47b50fa | Paul Brook | dev = qdev_create(NULL, "mv88w8618_eth"); |
1581 | ee6847d1 | Gerd Hoffmann | dev->nd = &nd_table[0];
|
1582 | b47b50fa | Paul Brook | qdev_init(dev); |
1583 | b47b50fa | Paul Brook | sysbus_mmio_map(sysbus_from_qdev(dev), 0, MP_ETH_BASE);
|
1584 | b47b50fa | Paul Brook | sysbus_connect_irq(sysbus_from_qdev(dev), 0, pic[MP_ETH_IRQ]);
|
1585 | 24859b68 | balrog | |
1586 | 718ec0be | malc | mixer_i2c = musicpal_audio_init(pic[MP_AUDIO_IRQ]); |
1587 | 718ec0be | malc | |
1588 | b47b50fa | Paul Brook | sysbus_create_simple("mv88w8618_wlan", MP_WLAN_BASE, NULL); |
1589 | 718ec0be | malc | |
1590 | 718ec0be | malc | musicpal_misc_init(); |
1591 | 718ec0be | malc | musicpal_gpio_init(); |
1592 | 24859b68 | balrog | |
1593 | 24859b68 | balrog | musicpal_binfo.ram_size = MP_RAM_DEFAULT_SIZE; |
1594 | 24859b68 | balrog | musicpal_binfo.kernel_filename = kernel_filename; |
1595 | 24859b68 | balrog | musicpal_binfo.kernel_cmdline = kernel_cmdline; |
1596 | 24859b68 | balrog | musicpal_binfo.initrd_filename = initrd_filename; |
1597 | b0f6edb1 | balrog | arm_load_kernel(env, &musicpal_binfo); |
1598 | 24859b68 | balrog | } |
1599 | 24859b68 | balrog | |
1600 | f80f9ec9 | Anthony Liguori | static QEMUMachine musicpal_machine = {
|
1601 | 4b32e168 | aliguori | .name = "musicpal",
|
1602 | 4b32e168 | aliguori | .desc = "Marvell 88w8618 / MusicPal (ARM926EJ-S)",
|
1603 | 4b32e168 | aliguori | .init = musicpal_init, |
1604 | 24859b68 | balrog | }; |
1605 | b47b50fa | Paul Brook | |
1606 | f80f9ec9 | Anthony Liguori | static void musicpal_machine_init(void) |
1607 | f80f9ec9 | Anthony Liguori | { |
1608 | f80f9ec9 | Anthony Liguori | qemu_register_machine(&musicpal_machine); |
1609 | f80f9ec9 | Anthony Liguori | } |
1610 | f80f9ec9 | Anthony Liguori | |
1611 | f80f9ec9 | Anthony Liguori | machine_init(musicpal_machine_init); |
1612 | f80f9ec9 | Anthony Liguori | |
1613 | b47b50fa | Paul Brook | static void musicpal_register_devices(void) |
1614 | b47b50fa | Paul Brook | { |
1615 | b47b50fa | Paul Brook | sysbus_register_dev("mv88w8618_pic", sizeof(mv88w8618_pic_state), |
1616 | b47b50fa | Paul Brook | mv88w8618_pic_init); |
1617 | b47b50fa | Paul Brook | sysbus_register_dev("mv88w8618_pit", sizeof(mv88w8618_pit_state), |
1618 | b47b50fa | Paul Brook | mv88w8618_pit_init); |
1619 | b47b50fa | Paul Brook | sysbus_register_dev("mv88w8618_flashcfg", sizeof(mv88w8618_flashcfg_state), |
1620 | b47b50fa | Paul Brook | mv88w8618_flashcfg_init); |
1621 | b47b50fa | Paul Brook | sysbus_register_dev("mv88w8618_eth", sizeof(mv88w8618_eth_state), |
1622 | b47b50fa | Paul Brook | mv88w8618_eth_init); |
1623 | b47b50fa | Paul Brook | sysbus_register_dev("mv88w8618_wlan", sizeof(SysBusDevice), |
1624 | b47b50fa | Paul Brook | mv88w8618_wlan_init); |
1625 | b47b50fa | Paul Brook | sysbus_register_dev("musicpal_lcd", sizeof(musicpal_lcd_state), |
1626 | b47b50fa | Paul Brook | musicpal_lcd_init); |
1627 | b47b50fa | Paul Brook | } |
1628 | b47b50fa | Paul Brook | |
1629 | b47b50fa | Paul Brook | device_init(musicpal_register_devices) |