2 * Marvell MV88W8618 / Freecom MusicPal emulation.
4 * Copyright (c) 2008 Jan Kiszka
6 * This code is licenced under the GNU GPL v2.
16 #include "qemu-timer.h"
23 #define MP_MISC_BASE 0x80002000
24 #define MP_MISC_SIZE 0x00001000
26 #define MP_ETH_BASE 0x80008000
27 #define MP_ETH_SIZE 0x00001000
29 #define MP_WLAN_BASE 0x8000C000
30 #define MP_WLAN_SIZE 0x00000800
32 #define MP_UART1_BASE 0x8000C840
33 #define MP_UART2_BASE 0x8000C940
35 #define MP_GPIO_BASE 0x8000D000
36 #define MP_GPIO_SIZE 0x00001000
38 #define MP_FLASHCFG_BASE 0x90006000
39 #define MP_FLASHCFG_SIZE 0x00001000
41 #define MP_AUDIO_BASE 0x90007000
43 #define MP_PIC_BASE 0x90008000
44 #define MP_PIC_SIZE 0x00001000
46 #define MP_PIT_BASE 0x90009000
47 #define MP_PIT_SIZE 0x00001000
49 #define MP_LCD_BASE 0x9000c000
50 #define MP_LCD_SIZE 0x00001000
52 #define MP_SRAM_BASE 0xC0000000
53 #define MP_SRAM_SIZE 0x00020000
55 #define MP_RAM_DEFAULT_SIZE 32*1024*1024
56 #define MP_FLASH_SIZE_MAX 32*1024*1024
58 #define MP_TIMER1_IRQ 4
59 #define MP_TIMER2_IRQ 5
60 #define MP_TIMER3_IRQ 6
61 #define MP_TIMER4_IRQ 7
64 #define MP_UART1_IRQ 11
65 #define MP_UART2_IRQ 11
66 #define MP_GPIO_IRQ 12
68 #define MP_AUDIO_IRQ 30
70 /* Wolfson 8750 I2C address */
71 #define MP_WM_ADDR 0x1A
73 /* Ethernet register offsets */
74 #define MP_ETH_SMIR 0x010
75 #define MP_ETH_PCXR 0x408
76 #define MP_ETH_SDCMR 0x448
77 #define MP_ETH_ICR 0x450
78 #define MP_ETH_IMR 0x458
79 #define MP_ETH_FRDP0 0x480
80 #define MP_ETH_FRDP1 0x484
81 #define MP_ETH_FRDP2 0x488
82 #define MP_ETH_FRDP3 0x48C
83 #define MP_ETH_CRDP0 0x4A0
84 #define MP_ETH_CRDP1 0x4A4
85 #define MP_ETH_CRDP2 0x4A8
86 #define MP_ETH_CRDP3 0x4AC
87 #define MP_ETH_CTDP0 0x4E0
88 #define MP_ETH_CTDP1 0x4E4
89 #define MP_ETH_CTDP2 0x4E8
90 #define MP_ETH_CTDP3 0x4EC
93 #define MP_ETH_SMIR_DATA 0x0000FFFF
94 #define MP_ETH_SMIR_ADDR 0x03FF0000
95 #define MP_ETH_SMIR_OPCODE (1 << 26) /* Read value */
96 #define MP_ETH_SMIR_RDVALID (1 << 27)
99 #define MP_ETH_PHY1_BMSR 0x00210000
100 #define MP_ETH_PHY1_PHYSID1 0x00410000
101 #define MP_ETH_PHY1_PHYSID2 0x00610000
103 #define MP_PHY_BMSR_LINK 0x0004
104 #define MP_PHY_BMSR_AUTONEG 0x0008
106 #define MP_PHY_88E3015 0x01410E20
108 /* TX descriptor status */
109 #define MP_ETH_TX_OWN (1 << 31)
111 /* RX descriptor status */
112 #define MP_ETH_RX_OWN (1 << 31)
114 /* Interrupt cause/mask bits */
115 #define MP_ETH_IRQ_RX_BIT 0
116 #define MP_ETH_IRQ_RX (1 << MP_ETH_IRQ_RX_BIT)
117 #define MP_ETH_IRQ_TXHI_BIT 2
118 #define MP_ETH_IRQ_TXLO_BIT 3
120 /* Port config bits */
121 #define MP_ETH_PCXR_2BSM_BIT 28 /* 2-byte incoming suffix */
123 /* SDMA command bits */
124 #define MP_ETH_CMD_TXHI (1 << 23)
125 #define MP_ETH_CMD_TXLO (1 << 22)
127 typedef struct mv88w8618_tx_desc
{
135 typedef struct mv88w8618_rx_desc
{
138 uint16_t buffer_size
;
143 typedef struct mv88w8618_eth_state
{
150 uint32_t vlan_header
;
151 uint32_t tx_queue
[2];
152 uint32_t rx_queue
[4];
153 uint32_t frx_queue
[4];
157 } mv88w8618_eth_state
;
159 static void eth_rx_desc_put(uint32_t addr
, mv88w8618_rx_desc
*desc
)
161 cpu_to_le32s(&desc
->cmdstat
);
162 cpu_to_le16s(&desc
->bytes
);
163 cpu_to_le16s(&desc
->buffer_size
);
164 cpu_to_le32s(&desc
->buffer
);
165 cpu_to_le32s(&desc
->next
);
166 cpu_physical_memory_write(addr
, (void *)desc
, sizeof(*desc
));
169 static void eth_rx_desc_get(uint32_t addr
, mv88w8618_rx_desc
*desc
)
171 cpu_physical_memory_read(addr
, (void *)desc
, sizeof(*desc
));
172 le32_to_cpus(&desc
->cmdstat
);
173 le16_to_cpus(&desc
->bytes
);
174 le16_to_cpus(&desc
->buffer_size
);
175 le32_to_cpus(&desc
->buffer
);
176 le32_to_cpus(&desc
->next
);
179 static int eth_can_receive(VLANClientState
*nc
)
184 static ssize_t
eth_receive(VLANClientState
*nc
, const uint8_t *buf
, size_t size
)
186 mv88w8618_eth_state
*s
= DO_UPCAST(NICState
, nc
, nc
)->opaque
;
188 mv88w8618_rx_desc desc
;
191 for (i
= 0; i
< 4; i
++) {
192 desc_addr
= s
->cur_rx
[i
];
197 eth_rx_desc_get(desc_addr
, &desc
);
198 if ((desc
.cmdstat
& MP_ETH_RX_OWN
) && desc
.buffer_size
>= size
) {
199 cpu_physical_memory_write(desc
.buffer
+ s
->vlan_header
,
201 desc
.bytes
= size
+ s
->vlan_header
;
202 desc
.cmdstat
&= ~MP_ETH_RX_OWN
;
203 s
->cur_rx
[i
] = desc
.next
;
205 s
->icr
|= MP_ETH_IRQ_RX
;
206 if (s
->icr
& s
->imr
) {
207 qemu_irq_raise(s
->irq
);
209 eth_rx_desc_put(desc_addr
, &desc
);
212 desc_addr
= desc
.next
;
213 } while (desc_addr
!= s
->rx_queue
[i
]);
218 static void eth_tx_desc_put(uint32_t addr
, mv88w8618_tx_desc
*desc
)
220 cpu_to_le32s(&desc
->cmdstat
);
221 cpu_to_le16s(&desc
->res
);
222 cpu_to_le16s(&desc
->bytes
);
223 cpu_to_le32s(&desc
->buffer
);
224 cpu_to_le32s(&desc
->next
);
225 cpu_physical_memory_write(addr
, (void *)desc
, sizeof(*desc
));
228 static void eth_tx_desc_get(uint32_t addr
, mv88w8618_tx_desc
*desc
)
230 cpu_physical_memory_read(addr
, (void *)desc
, sizeof(*desc
));
231 le32_to_cpus(&desc
->cmdstat
);
232 le16_to_cpus(&desc
->res
);
233 le16_to_cpus(&desc
->bytes
);
234 le32_to_cpus(&desc
->buffer
);
235 le32_to_cpus(&desc
->next
);
238 static void eth_send(mv88w8618_eth_state
*s
, int queue_index
)
240 uint32_t desc_addr
= s
->tx_queue
[queue_index
];
241 mv88w8618_tx_desc desc
;
247 eth_tx_desc_get(desc_addr
, &desc
);
248 next_desc
= desc
.next
;
249 if (desc
.cmdstat
& MP_ETH_TX_OWN
) {
252 cpu_physical_memory_read(desc
.buffer
, buf
, len
);
253 qemu_send_packet(&s
->nic
->nc
, buf
, len
);
255 desc
.cmdstat
&= ~MP_ETH_TX_OWN
;
256 s
->icr
|= 1 << (MP_ETH_IRQ_TXLO_BIT
- queue_index
);
257 eth_tx_desc_put(desc_addr
, &desc
);
259 desc_addr
= next_desc
;
260 } while (desc_addr
!= s
->tx_queue
[queue_index
]);
263 static uint32_t mv88w8618_eth_read(void *opaque
, target_phys_addr_t offset
)
265 mv88w8618_eth_state
*s
= opaque
;
269 if (s
->smir
& MP_ETH_SMIR_OPCODE
) {
270 switch (s
->smir
& MP_ETH_SMIR_ADDR
) {
271 case MP_ETH_PHY1_BMSR
:
272 return MP_PHY_BMSR_LINK
| MP_PHY_BMSR_AUTONEG
|
274 case MP_ETH_PHY1_PHYSID1
:
275 return (MP_PHY_88E3015
>> 16) | MP_ETH_SMIR_RDVALID
;
276 case MP_ETH_PHY1_PHYSID2
:
277 return (MP_PHY_88E3015
& 0xFFFF) | MP_ETH_SMIR_RDVALID
;
279 return MP_ETH_SMIR_RDVALID
;
290 case MP_ETH_FRDP0
... MP_ETH_FRDP3
:
291 return s
->frx_queue
[(offset
- MP_ETH_FRDP0
)/4];
293 case MP_ETH_CRDP0
... MP_ETH_CRDP3
:
294 return s
->rx_queue
[(offset
- MP_ETH_CRDP0
)/4];
296 case MP_ETH_CTDP0
... MP_ETH_CTDP3
:
297 return s
->tx_queue
[(offset
- MP_ETH_CTDP0
)/4];
304 static void mv88w8618_eth_write(void *opaque
, target_phys_addr_t offset
,
307 mv88w8618_eth_state
*s
= opaque
;
315 s
->vlan_header
= ((value
>> MP_ETH_PCXR_2BSM_BIT
) & 1) * 2;
319 if (value
& MP_ETH_CMD_TXHI
) {
322 if (value
& MP_ETH_CMD_TXLO
) {
325 if (value
& (MP_ETH_CMD_TXHI
| MP_ETH_CMD_TXLO
) && s
->icr
& s
->imr
) {
326 qemu_irq_raise(s
->irq
);
336 if (s
->icr
& s
->imr
) {
337 qemu_irq_raise(s
->irq
);
341 case MP_ETH_FRDP0
... MP_ETH_FRDP3
:
342 s
->frx_queue
[(offset
- MP_ETH_FRDP0
)/4] = value
;
345 case MP_ETH_CRDP0
... MP_ETH_CRDP3
:
346 s
->rx_queue
[(offset
- MP_ETH_CRDP0
)/4] =
347 s
->cur_rx
[(offset
- MP_ETH_CRDP0
)/4] = value
;
350 case MP_ETH_CTDP0
... MP_ETH_CTDP3
:
351 s
->tx_queue
[(offset
- MP_ETH_CTDP0
)/4] = value
;
356 static CPUReadMemoryFunc
* const mv88w8618_eth_readfn
[] = {
362 static CPUWriteMemoryFunc
* const mv88w8618_eth_writefn
[] = {
368 static void eth_cleanup(VLANClientState
*nc
)
370 mv88w8618_eth_state
*s
= DO_UPCAST(NICState
, nc
, nc
)->opaque
;
375 static NetClientInfo net_mv88w8618_info
= {
376 .type
= NET_CLIENT_TYPE_NIC
,
377 .size
= sizeof(NICState
),
378 .can_receive
= eth_can_receive
,
379 .receive
= eth_receive
,
380 .cleanup
= eth_cleanup
,
383 static int mv88w8618_eth_init(SysBusDevice
*dev
)
385 mv88w8618_eth_state
*s
= FROM_SYSBUS(mv88w8618_eth_state
, dev
);
387 sysbus_init_irq(dev
, &s
->irq
);
388 s
->nic
= qemu_new_nic(&net_mv88w8618_info
, &s
->conf
,
389 dev
->qdev
.info
->name
, dev
->qdev
.id
, s
);
390 s
->mmio_index
= cpu_register_io_memory(mv88w8618_eth_readfn
,
391 mv88w8618_eth_writefn
, s
);
392 sysbus_init_mmio(dev
, MP_ETH_SIZE
, s
->mmio_index
);
396 static const VMStateDescription mv88w8618_eth_vmsd
= {
397 .name
= "mv88w8618_eth",
399 .minimum_version_id
= 1,
400 .minimum_version_id_old
= 1,
401 .fields
= (VMStateField
[]) {
402 VMSTATE_UINT32(smir
, mv88w8618_eth_state
),
403 VMSTATE_UINT32(icr
, mv88w8618_eth_state
),
404 VMSTATE_UINT32(imr
, mv88w8618_eth_state
),
405 VMSTATE_UINT32(vlan_header
, mv88w8618_eth_state
),
406 VMSTATE_UINT32_ARRAY(tx_queue
, mv88w8618_eth_state
, 2),
407 VMSTATE_UINT32_ARRAY(rx_queue
, mv88w8618_eth_state
, 4),
408 VMSTATE_UINT32_ARRAY(frx_queue
, mv88w8618_eth_state
, 4),
409 VMSTATE_UINT32_ARRAY(cur_rx
, mv88w8618_eth_state
, 4),
410 VMSTATE_END_OF_LIST()
414 static SysBusDeviceInfo mv88w8618_eth_info
= {
415 .init
= mv88w8618_eth_init
,
416 .qdev
.name
= "mv88w8618_eth",
417 .qdev
.size
= sizeof(mv88w8618_eth_state
),
418 .qdev
.vmsd
= &mv88w8618_eth_vmsd
,
419 .qdev
.props
= (Property
[]) {
420 DEFINE_NIC_PROPERTIES(mv88w8618_eth_state
, conf
),
421 DEFINE_PROP_END_OF_LIST(),
425 /* LCD register offsets */
426 #define MP_LCD_IRQCTRL 0x180
427 #define MP_LCD_IRQSTAT 0x184
428 #define MP_LCD_SPICTRL 0x1ac
429 #define MP_LCD_INST 0x1bc
430 #define MP_LCD_DATA 0x1c0
433 #define MP_LCD_SPI_DATA 0x00100011
434 #define MP_LCD_SPI_CMD 0x00104011
435 #define MP_LCD_SPI_INVALID 0x00000000
438 #define MP_LCD_INST_SETPAGE0 0xB0
440 #define MP_LCD_INST_SETPAGE7 0xB7
442 #define MP_LCD_TEXTCOLOR 0xe0e0ff /* RRGGBB */
444 typedef struct musicpal_lcd_state
{
452 uint8_t video_ram
[128*64/8];
453 } musicpal_lcd_state
;
455 static uint8_t scale_lcd_color(musicpal_lcd_state
*s
, uint8_t col
)
457 switch (s
->brightness
) {
463 return (col
* s
->brightness
) / 7;
467 #define SET_LCD_PIXEL(depth, type) \
468 static inline void glue(set_lcd_pixel, depth) \
469 (musicpal_lcd_state *s, int x, int y, type col) \
472 type *pixel = &((type *) ds_get_data(s->ds))[(y * 128 * 3 + x) * 3]; \
474 for (dy = 0; dy < 3; dy++, pixel += 127 * 3) \
475 for (dx = 0; dx < 3; dx++, pixel++) \
478 SET_LCD_PIXEL(8, uint8_t)
479 SET_LCD_PIXEL(16, uint16_t)
480 SET_LCD_PIXEL(32, uint32_t)
482 #include "pixel_ops.h"
484 static void lcd_refresh(void *opaque
)
486 musicpal_lcd_state
*s
= opaque
;
489 switch (ds_get_bits_per_pixel(s
->ds
)) {
492 #define LCD_REFRESH(depth, func) \
494 col = func(scale_lcd_color(s, (MP_LCD_TEXTCOLOR >> 16) & 0xff), \
495 scale_lcd_color(s, (MP_LCD_TEXTCOLOR >> 8) & 0xff), \
496 scale_lcd_color(s, MP_LCD_TEXTCOLOR & 0xff)); \
497 for (x = 0; x < 128; x++) { \
498 for (y = 0; y < 64; y++) { \
499 if (s->video_ram[x + (y/8)*128] & (1 << (y % 8))) { \
500 glue(set_lcd_pixel, depth)(s, x, y, col); \
502 glue(set_lcd_pixel, depth)(s, x, y, 0); \
507 LCD_REFRESH(8, rgb_to_pixel8
)
508 LCD_REFRESH(16, rgb_to_pixel16
)
509 LCD_REFRESH(32, (is_surface_bgr(s
->ds
->surface
) ?
510 rgb_to_pixel32bgr
: rgb_to_pixel32
))
512 hw_error("unsupported colour depth %i\n",
513 ds_get_bits_per_pixel(s
->ds
));
516 dpy_update(s
->ds
, 0, 0, 128*3, 64*3);
519 static void lcd_invalidate(void *opaque
)
523 static void musicpal_lcd_gpio_brigthness_in(void *opaque
, int irq
, int level
)
525 musicpal_lcd_state
*s
= opaque
;
526 s
->brightness
&= ~(1 << irq
);
527 s
->brightness
|= level
<< irq
;
530 static uint32_t musicpal_lcd_read(void *opaque
, target_phys_addr_t offset
)
532 musicpal_lcd_state
*s
= opaque
;
543 static void musicpal_lcd_write(void *opaque
, target_phys_addr_t offset
,
546 musicpal_lcd_state
*s
= opaque
;
554 if (value
== MP_LCD_SPI_DATA
|| value
== MP_LCD_SPI_CMD
) {
557 s
->mode
= MP_LCD_SPI_INVALID
;
562 if (value
>= MP_LCD_INST_SETPAGE0
&& value
<= MP_LCD_INST_SETPAGE7
) {
563 s
->page
= value
- MP_LCD_INST_SETPAGE0
;
569 if (s
->mode
== MP_LCD_SPI_CMD
) {
570 if (value
>= MP_LCD_INST_SETPAGE0
&&
571 value
<= MP_LCD_INST_SETPAGE7
) {
572 s
->page
= value
- MP_LCD_INST_SETPAGE0
;
575 } else if (s
->mode
== MP_LCD_SPI_DATA
) {
576 s
->video_ram
[s
->page
*128 + s
->page_off
] = value
;
577 s
->page_off
= (s
->page_off
+ 1) & 127;
583 static CPUReadMemoryFunc
* const musicpal_lcd_readfn
[] = {
589 static CPUWriteMemoryFunc
* const musicpal_lcd_writefn
[] = {
595 static int musicpal_lcd_init(SysBusDevice
*dev
)
597 musicpal_lcd_state
*s
= FROM_SYSBUS(musicpal_lcd_state
, dev
);
602 iomemtype
= cpu_register_io_memory(musicpal_lcd_readfn
,
603 musicpal_lcd_writefn
, s
);
604 sysbus_init_mmio(dev
, MP_LCD_SIZE
, iomemtype
);
606 s
->ds
= graphic_console_init(lcd_refresh
, lcd_invalidate
,
608 qemu_console_resize(s
->ds
, 128*3, 64*3);
610 qdev_init_gpio_in(&dev
->qdev
, musicpal_lcd_gpio_brigthness_in
, 3);
615 static const VMStateDescription musicpal_lcd_vmsd
= {
616 .name
= "musicpal_lcd",
618 .minimum_version_id
= 1,
619 .minimum_version_id_old
= 1,
620 .fields
= (VMStateField
[]) {
621 VMSTATE_UINT32(brightness
, musicpal_lcd_state
),
622 VMSTATE_UINT32(mode
, musicpal_lcd_state
),
623 VMSTATE_UINT32(irqctrl
, musicpal_lcd_state
),
624 VMSTATE_UINT32(page
, musicpal_lcd_state
),
625 VMSTATE_UINT32(page_off
, musicpal_lcd_state
),
626 VMSTATE_BUFFER(video_ram
, musicpal_lcd_state
),
627 VMSTATE_END_OF_LIST()
631 static SysBusDeviceInfo musicpal_lcd_info
= {
632 .init
= musicpal_lcd_init
,
633 .qdev
.name
= "musicpal_lcd",
634 .qdev
.size
= sizeof(musicpal_lcd_state
),
635 .qdev
.vmsd
= &musicpal_lcd_vmsd
,
638 /* PIC register offsets */
639 #define MP_PIC_STATUS 0x00
640 #define MP_PIC_ENABLE_SET 0x08
641 #define MP_PIC_ENABLE_CLR 0x0C
643 typedef struct mv88w8618_pic_state
649 } mv88w8618_pic_state
;
651 static void mv88w8618_pic_update(mv88w8618_pic_state
*s
)
653 qemu_set_irq(s
->parent_irq
, (s
->level
& s
->enabled
));
656 static void mv88w8618_pic_set_irq(void *opaque
, int irq
, int level
)
658 mv88w8618_pic_state
*s
= opaque
;
661 s
->level
|= 1 << irq
;
663 s
->level
&= ~(1 << irq
);
665 mv88w8618_pic_update(s
);
668 static uint32_t mv88w8618_pic_read(void *opaque
, target_phys_addr_t offset
)
670 mv88w8618_pic_state
*s
= opaque
;
674 return s
->level
& s
->enabled
;
681 static void mv88w8618_pic_write(void *opaque
, target_phys_addr_t offset
,
684 mv88w8618_pic_state
*s
= opaque
;
687 case MP_PIC_ENABLE_SET
:
691 case MP_PIC_ENABLE_CLR
:
692 s
->enabled
&= ~value
;
696 mv88w8618_pic_update(s
);
699 static void mv88w8618_pic_reset(DeviceState
*d
)
701 mv88w8618_pic_state
*s
= FROM_SYSBUS(mv88w8618_pic_state
,
702 sysbus_from_qdev(d
));
708 static CPUReadMemoryFunc
* const mv88w8618_pic_readfn
[] = {
714 static CPUWriteMemoryFunc
* const mv88w8618_pic_writefn
[] = {
720 static int mv88w8618_pic_init(SysBusDevice
*dev
)
722 mv88w8618_pic_state
*s
= FROM_SYSBUS(mv88w8618_pic_state
, dev
);
725 qdev_init_gpio_in(&dev
->qdev
, mv88w8618_pic_set_irq
, 32);
726 sysbus_init_irq(dev
, &s
->parent_irq
);
727 iomemtype
= cpu_register_io_memory(mv88w8618_pic_readfn
,
728 mv88w8618_pic_writefn
, s
);
729 sysbus_init_mmio(dev
, MP_PIC_SIZE
, iomemtype
);
733 static const VMStateDescription mv88w8618_pic_vmsd
= {
734 .name
= "mv88w8618_pic",
736 .minimum_version_id
= 1,
737 .minimum_version_id_old
= 1,
738 .fields
= (VMStateField
[]) {
739 VMSTATE_UINT32(level
, mv88w8618_pic_state
),
740 VMSTATE_UINT32(enabled
, mv88w8618_pic_state
),
741 VMSTATE_END_OF_LIST()
745 static SysBusDeviceInfo mv88w8618_pic_info
= {
746 .init
= mv88w8618_pic_init
,
747 .qdev
.name
= "mv88w8618_pic",
748 .qdev
.size
= sizeof(mv88w8618_pic_state
),
749 .qdev
.reset
= mv88w8618_pic_reset
,
750 .qdev
.vmsd
= &mv88w8618_pic_vmsd
,
753 /* PIT register offsets */
754 #define MP_PIT_TIMER1_LENGTH 0x00
756 #define MP_PIT_TIMER4_LENGTH 0x0C
757 #define MP_PIT_CONTROL 0x10
758 #define MP_PIT_TIMER1_VALUE 0x14
760 #define MP_PIT_TIMER4_VALUE 0x20
761 #define MP_BOARD_RESET 0x34
763 /* Magic board reset value (probably some watchdog behind it) */
764 #define MP_BOARD_RESET_MAGIC 0x10000
766 typedef struct mv88w8618_timer_state
{
767 ptimer_state
*ptimer
;
771 } mv88w8618_timer_state
;
773 typedef struct mv88w8618_pit_state
{
775 mv88w8618_timer_state timer
[4];
776 } mv88w8618_pit_state
;
778 static void mv88w8618_timer_tick(void *opaque
)
780 mv88w8618_timer_state
*s
= opaque
;
782 qemu_irq_raise(s
->irq
);
785 static void mv88w8618_timer_init(SysBusDevice
*dev
, mv88w8618_timer_state
*s
,
790 sysbus_init_irq(dev
, &s
->irq
);
793 bh
= qemu_bh_new(mv88w8618_timer_tick
, s
);
794 s
->ptimer
= ptimer_init(bh
);
797 static uint32_t mv88w8618_pit_read(void *opaque
, target_phys_addr_t offset
)
799 mv88w8618_pit_state
*s
= opaque
;
800 mv88w8618_timer_state
*t
;
803 case MP_PIT_TIMER1_VALUE
... MP_PIT_TIMER4_VALUE
:
804 t
= &s
->timer
[(offset
-MP_PIT_TIMER1_VALUE
) >> 2];
805 return ptimer_get_count(t
->ptimer
);
812 static void mv88w8618_pit_write(void *opaque
, target_phys_addr_t offset
,
815 mv88w8618_pit_state
*s
= opaque
;
816 mv88w8618_timer_state
*t
;
820 case MP_PIT_TIMER1_LENGTH
... MP_PIT_TIMER4_LENGTH
:
821 t
= &s
->timer
[offset
>> 2];
824 ptimer_set_limit(t
->ptimer
, t
->limit
, 1);
826 ptimer_stop(t
->ptimer
);
831 for (i
= 0; i
< 4; i
++) {
833 if (value
& 0xf && t
->limit
> 0) {
834 ptimer_set_limit(t
->ptimer
, t
->limit
, 0);
835 ptimer_set_freq(t
->ptimer
, t
->freq
);
836 ptimer_run(t
->ptimer
, 0);
838 ptimer_stop(t
->ptimer
);
845 if (value
== MP_BOARD_RESET_MAGIC
) {
846 qemu_system_reset_request();
852 static void mv88w8618_pit_reset(DeviceState
*d
)
854 mv88w8618_pit_state
*s
= FROM_SYSBUS(mv88w8618_pit_state
,
855 sysbus_from_qdev(d
));
858 for (i
= 0; i
< 4; i
++) {
859 ptimer_stop(s
->timer
[i
].ptimer
);
860 s
->timer
[i
].limit
= 0;
864 static CPUReadMemoryFunc
* const mv88w8618_pit_readfn
[] = {
870 static CPUWriteMemoryFunc
* const mv88w8618_pit_writefn
[] = {
876 static int mv88w8618_pit_init(SysBusDevice
*dev
)
879 mv88w8618_pit_state
*s
= FROM_SYSBUS(mv88w8618_pit_state
, dev
);
882 /* Letting them all run at 1 MHz is likely just a pragmatic
884 for (i
= 0; i
< 4; i
++) {
885 mv88w8618_timer_init(dev
, &s
->timer
[i
], 1000000);
888 iomemtype
= cpu_register_io_memory(mv88w8618_pit_readfn
,
889 mv88w8618_pit_writefn
, s
);
890 sysbus_init_mmio(dev
, MP_PIT_SIZE
, iomemtype
);
894 static const VMStateDescription mv88w8618_timer_vmsd
= {
897 .minimum_version_id
= 1,
898 .minimum_version_id_old
= 1,
899 .fields
= (VMStateField
[]) {
900 VMSTATE_PTIMER(ptimer
, mv88w8618_timer_state
),
901 VMSTATE_UINT32(limit
, mv88w8618_timer_state
),
902 VMSTATE_END_OF_LIST()
906 static const VMStateDescription mv88w8618_pit_vmsd
= {
907 .name
= "mv88w8618_pit",
909 .minimum_version_id
= 1,
910 .minimum_version_id_old
= 1,
911 .fields
= (VMStateField
[]) {
912 VMSTATE_STRUCT_ARRAY(timer
, mv88w8618_pit_state
, 4, 1,
913 mv88w8618_timer_vmsd
, mv88w8618_timer_state
),
914 VMSTATE_END_OF_LIST()
918 static SysBusDeviceInfo mv88w8618_pit_info
= {
919 .init
= mv88w8618_pit_init
,
920 .qdev
.name
= "mv88w8618_pit",
921 .qdev
.size
= sizeof(mv88w8618_pit_state
),
922 .qdev
.reset
= mv88w8618_pit_reset
,
923 .qdev
.vmsd
= &mv88w8618_pit_vmsd
,
926 /* Flash config register offsets */
927 #define MP_FLASHCFG_CFGR0 0x04
929 typedef struct mv88w8618_flashcfg_state
{
932 } mv88w8618_flashcfg_state
;
934 static uint32_t mv88w8618_flashcfg_read(void *opaque
,
935 target_phys_addr_t offset
)
937 mv88w8618_flashcfg_state
*s
= opaque
;
940 case MP_FLASHCFG_CFGR0
:
948 static void mv88w8618_flashcfg_write(void *opaque
, target_phys_addr_t offset
,
951 mv88w8618_flashcfg_state
*s
= opaque
;
954 case MP_FLASHCFG_CFGR0
:
960 static CPUReadMemoryFunc
* const mv88w8618_flashcfg_readfn
[] = {
961 mv88w8618_flashcfg_read
,
962 mv88w8618_flashcfg_read
,
963 mv88w8618_flashcfg_read
966 static CPUWriteMemoryFunc
* const mv88w8618_flashcfg_writefn
[] = {
967 mv88w8618_flashcfg_write
,
968 mv88w8618_flashcfg_write
,
969 mv88w8618_flashcfg_write
972 static int mv88w8618_flashcfg_init(SysBusDevice
*dev
)
975 mv88w8618_flashcfg_state
*s
= FROM_SYSBUS(mv88w8618_flashcfg_state
, dev
);
977 s
->cfgr0
= 0xfffe4285; /* Default as set by U-Boot for 8 MB flash */
978 iomemtype
= cpu_register_io_memory(mv88w8618_flashcfg_readfn
,
979 mv88w8618_flashcfg_writefn
, s
);
980 sysbus_init_mmio(dev
, MP_FLASHCFG_SIZE
, iomemtype
);
984 static const VMStateDescription mv88w8618_flashcfg_vmsd
= {
985 .name
= "mv88w8618_flashcfg",
987 .minimum_version_id
= 1,
988 .minimum_version_id_old
= 1,
989 .fields
= (VMStateField
[]) {
990 VMSTATE_UINT32(cfgr0
, mv88w8618_flashcfg_state
),
991 VMSTATE_END_OF_LIST()
995 static SysBusDeviceInfo mv88w8618_flashcfg_info
= {
996 .init
= mv88w8618_flashcfg_init
,
997 .qdev
.name
= "mv88w8618_flashcfg",
998 .qdev
.size
= sizeof(mv88w8618_flashcfg_state
),
999 .qdev
.vmsd
= &mv88w8618_flashcfg_vmsd
,
1002 /* Misc register offsets */
1003 #define MP_MISC_BOARD_REVISION 0x18
1005 #define MP_BOARD_REVISION 0x31
1007 static uint32_t musicpal_misc_read(void *opaque
, target_phys_addr_t offset
)
1010 case MP_MISC_BOARD_REVISION
:
1011 return MP_BOARD_REVISION
;
1018 static void musicpal_misc_write(void *opaque
, target_phys_addr_t offset
,
1023 static CPUReadMemoryFunc
* const musicpal_misc_readfn
[] = {
1029 static CPUWriteMemoryFunc
* const musicpal_misc_writefn
[] = {
1030 musicpal_misc_write
,
1031 musicpal_misc_write
,
1032 musicpal_misc_write
,
1035 static void musicpal_misc_init(void)
1039 iomemtype
= cpu_register_io_memory(musicpal_misc_readfn
,
1040 musicpal_misc_writefn
, NULL
);
1041 cpu_register_physical_memory(MP_MISC_BASE
, MP_MISC_SIZE
, iomemtype
);
1044 /* WLAN register offsets */
1045 #define MP_WLAN_MAGIC1 0x11c
1046 #define MP_WLAN_MAGIC2 0x124
1048 static uint32_t mv88w8618_wlan_read(void *opaque
, target_phys_addr_t offset
)
1051 /* Workaround to allow loading the binary-only wlandrv.ko crap
1052 * from the original Freecom firmware. */
1053 case MP_WLAN_MAGIC1
:
1055 case MP_WLAN_MAGIC2
:
1063 static void mv88w8618_wlan_write(void *opaque
, target_phys_addr_t offset
,
1068 static CPUReadMemoryFunc
* const mv88w8618_wlan_readfn
[] = {
1069 mv88w8618_wlan_read
,
1070 mv88w8618_wlan_read
,
1071 mv88w8618_wlan_read
,
1074 static CPUWriteMemoryFunc
* const mv88w8618_wlan_writefn
[] = {
1075 mv88w8618_wlan_write
,
1076 mv88w8618_wlan_write
,
1077 mv88w8618_wlan_write
,
1080 static int mv88w8618_wlan_init(SysBusDevice
*dev
)
1084 iomemtype
= cpu_register_io_memory(mv88w8618_wlan_readfn
,
1085 mv88w8618_wlan_writefn
, NULL
);
1086 sysbus_init_mmio(dev
, MP_WLAN_SIZE
, iomemtype
);
1090 /* GPIO register offsets */
1091 #define MP_GPIO_OE_LO 0x008
1092 #define MP_GPIO_OUT_LO 0x00c
1093 #define MP_GPIO_IN_LO 0x010
1094 #define MP_GPIO_IER_LO 0x014
1095 #define MP_GPIO_IMR_LO 0x018
1096 #define MP_GPIO_ISR_LO 0x020
1097 #define MP_GPIO_OE_HI 0x508
1098 #define MP_GPIO_OUT_HI 0x50c
1099 #define MP_GPIO_IN_HI 0x510
1100 #define MP_GPIO_IER_HI 0x514
1101 #define MP_GPIO_IMR_HI 0x518
1102 #define MP_GPIO_ISR_HI 0x520
1104 /* GPIO bits & masks */
1105 #define MP_GPIO_LCD_BRIGHTNESS 0x00070000
1106 #define MP_GPIO_I2C_DATA_BIT 29
1107 #define MP_GPIO_I2C_CLOCK_BIT 30
1109 /* LCD brightness bits in GPIO_OE_HI */
1110 #define MP_OE_LCD_BRIGHTNESS 0x0007
1112 typedef struct musicpal_gpio_state
{
1113 SysBusDevice busdev
;
1114 uint32_t lcd_brightness
;
1121 qemu_irq out
[5]; /* 3 brightness out + 2 lcd (data and clock ) */
1122 } musicpal_gpio_state
;
1124 static void musicpal_gpio_brightness_update(musicpal_gpio_state
*s
) {
1126 uint32_t brightness
;
1128 /* compute brightness ratio */
1129 switch (s
->lcd_brightness
) {
1163 /* set lcd brightness GPIOs */
1164 for (i
= 0; i
<= 2; i
++) {
1165 qemu_set_irq(s
->out
[i
], (brightness
>> i
) & 1);
1169 static void musicpal_gpio_pin_event(void *opaque
, int pin
, int level
)
1171 musicpal_gpio_state
*s
= opaque
;
1172 uint32_t mask
= 1 << pin
;
1173 uint32_t delta
= level
<< pin
;
1174 uint32_t old
= s
->in_state
& mask
;
1176 s
->in_state
&= ~mask
;
1177 s
->in_state
|= delta
;
1179 if ((old
^ delta
) &&
1180 ((level
&& (s
->imr
& mask
)) || (!level
&& (s
->ier
& mask
)))) {
1182 qemu_irq_raise(s
->irq
);
1186 static uint32_t musicpal_gpio_read(void *opaque
, target_phys_addr_t offset
)
1188 musicpal_gpio_state
*s
= opaque
;
1191 case MP_GPIO_OE_HI
: /* used for LCD brightness control */
1192 return s
->lcd_brightness
& MP_OE_LCD_BRIGHTNESS
;
1194 case MP_GPIO_OUT_LO
:
1195 return s
->out_state
& 0xFFFF;
1196 case MP_GPIO_OUT_HI
:
1197 return s
->out_state
>> 16;
1200 return s
->in_state
& 0xFFFF;
1202 return s
->in_state
>> 16;
1204 case MP_GPIO_IER_LO
:
1205 return s
->ier
& 0xFFFF;
1206 case MP_GPIO_IER_HI
:
1207 return s
->ier
>> 16;
1209 case MP_GPIO_IMR_LO
:
1210 return s
->imr
& 0xFFFF;
1211 case MP_GPIO_IMR_HI
:
1212 return s
->imr
>> 16;
1214 case MP_GPIO_ISR_LO
:
1215 return s
->isr
& 0xFFFF;
1216 case MP_GPIO_ISR_HI
:
1217 return s
->isr
>> 16;
1224 static void musicpal_gpio_write(void *opaque
, target_phys_addr_t offset
,
1227 musicpal_gpio_state
*s
= opaque
;
1229 case MP_GPIO_OE_HI
: /* used for LCD brightness control */
1230 s
->lcd_brightness
= (s
->lcd_brightness
& MP_GPIO_LCD_BRIGHTNESS
) |
1231 (value
& MP_OE_LCD_BRIGHTNESS
);
1232 musicpal_gpio_brightness_update(s
);
1235 case MP_GPIO_OUT_LO
:
1236 s
->out_state
= (s
->out_state
& 0xFFFF0000) | (value
& 0xFFFF);
1238 case MP_GPIO_OUT_HI
:
1239 s
->out_state
= (s
->out_state
& 0xFFFF) | (value
<< 16);
1240 s
->lcd_brightness
= (s
->lcd_brightness
& 0xFFFF) |
1241 (s
->out_state
& MP_GPIO_LCD_BRIGHTNESS
);
1242 musicpal_gpio_brightness_update(s
);
1243 qemu_set_irq(s
->out
[3], (s
->out_state
>> MP_GPIO_I2C_DATA_BIT
) & 1);
1244 qemu_set_irq(s
->out
[4], (s
->out_state
>> MP_GPIO_I2C_CLOCK_BIT
) & 1);
1247 case MP_GPIO_IER_LO
:
1248 s
->ier
= (s
->ier
& 0xFFFF0000) | (value
& 0xFFFF);
1250 case MP_GPIO_IER_HI
:
1251 s
->ier
= (s
->ier
& 0xFFFF) | (value
<< 16);
1254 case MP_GPIO_IMR_LO
:
1255 s
->imr
= (s
->imr
& 0xFFFF0000) | (value
& 0xFFFF);
1257 case MP_GPIO_IMR_HI
:
1258 s
->imr
= (s
->imr
& 0xFFFF) | (value
<< 16);
1263 static CPUReadMemoryFunc
* const musicpal_gpio_readfn
[] = {
1269 static CPUWriteMemoryFunc
* const musicpal_gpio_writefn
[] = {
1270 musicpal_gpio_write
,
1271 musicpal_gpio_write
,
1272 musicpal_gpio_write
,
1275 static void musicpal_gpio_reset(DeviceState
*d
)
1277 musicpal_gpio_state
*s
= FROM_SYSBUS(musicpal_gpio_state
,
1278 sysbus_from_qdev(d
));
1280 s
->lcd_brightness
= 0;
1282 s
->in_state
= 0xffffffff;
1288 static int musicpal_gpio_init(SysBusDevice
*dev
)
1290 musicpal_gpio_state
*s
= FROM_SYSBUS(musicpal_gpio_state
, dev
);
1293 sysbus_init_irq(dev
, &s
->irq
);
1295 iomemtype
= cpu_register_io_memory(musicpal_gpio_readfn
,
1296 musicpal_gpio_writefn
, s
);
1297 sysbus_init_mmio(dev
, MP_GPIO_SIZE
, iomemtype
);
1299 qdev_init_gpio_out(&dev
->qdev
, s
->out
, ARRAY_SIZE(s
->out
));
1301 qdev_init_gpio_in(&dev
->qdev
, musicpal_gpio_pin_event
, 32);
1306 static const VMStateDescription musicpal_gpio_vmsd
= {
1307 .name
= "musicpal_gpio",
1309 .minimum_version_id
= 1,
1310 .minimum_version_id_old
= 1,
1311 .fields
= (VMStateField
[]) {
1312 VMSTATE_UINT32(lcd_brightness
, musicpal_gpio_state
),
1313 VMSTATE_UINT32(out_state
, musicpal_gpio_state
),
1314 VMSTATE_UINT32(in_state
, musicpal_gpio_state
),
1315 VMSTATE_UINT32(ier
, musicpal_gpio_state
),
1316 VMSTATE_UINT32(imr
, musicpal_gpio_state
),
1317 VMSTATE_UINT32(isr
, musicpal_gpio_state
),
1318 VMSTATE_END_OF_LIST()
1322 static SysBusDeviceInfo musicpal_gpio_info
= {
1323 .init
= musicpal_gpio_init
,
1324 .qdev
.name
= "musicpal_gpio",
1325 .qdev
.size
= sizeof(musicpal_gpio_state
),
1326 .qdev
.reset
= musicpal_gpio_reset
,
1327 .qdev
.vmsd
= &musicpal_gpio_vmsd
,
1330 /* Keyboard codes & masks */
1331 #define KEY_RELEASED 0x80
1332 #define KEY_CODE 0x7f
1334 #define KEYCODE_TAB 0x0f
1335 #define KEYCODE_ENTER 0x1c
1336 #define KEYCODE_F 0x21
1337 #define KEYCODE_M 0x32
1339 #define KEYCODE_EXTENDED 0xe0
1340 #define KEYCODE_UP 0x48
1341 #define KEYCODE_DOWN 0x50
1342 #define KEYCODE_LEFT 0x4b
1343 #define KEYCODE_RIGHT 0x4d
1345 #define MP_KEY_WHEEL_VOL (1 << 0)
1346 #define MP_KEY_WHEEL_VOL_INV (1 << 1)
1347 #define MP_KEY_WHEEL_NAV (1 << 2)
1348 #define MP_KEY_WHEEL_NAV_INV (1 << 3)
1349 #define MP_KEY_BTN_FAVORITS (1 << 4)
1350 #define MP_KEY_BTN_MENU (1 << 5)
1351 #define MP_KEY_BTN_VOLUME (1 << 6)
1352 #define MP_KEY_BTN_NAVIGATION (1 << 7)
1354 typedef struct musicpal_key_state
{
1355 SysBusDevice busdev
;
1356 uint32_t kbd_extended
;
1357 uint32_t pressed_keys
;
1359 } musicpal_key_state
;
1361 static void musicpal_key_event(void *opaque
, int keycode
)
1363 musicpal_key_state
*s
= opaque
;
1367 if (keycode
== KEYCODE_EXTENDED
) {
1368 s
->kbd_extended
= 1;
1372 if (s
->kbd_extended
) {
1373 switch (keycode
& KEY_CODE
) {
1375 event
= MP_KEY_WHEEL_NAV
| MP_KEY_WHEEL_NAV_INV
;
1379 event
= MP_KEY_WHEEL_NAV
;
1383 event
= MP_KEY_WHEEL_VOL
| MP_KEY_WHEEL_VOL_INV
;
1387 event
= MP_KEY_WHEEL_VOL
;
1391 switch (keycode
& KEY_CODE
) {
1393 event
= MP_KEY_BTN_FAVORITS
;
1397 event
= MP_KEY_BTN_VOLUME
;
1401 event
= MP_KEY_BTN_NAVIGATION
;
1405 event
= MP_KEY_BTN_MENU
;
1408 /* Do not repeat already pressed buttons */
1409 if (!(keycode
& KEY_RELEASED
) && (s
->pressed_keys
& event
)) {
1415 /* Raise GPIO pin first if repeating a key */
1416 if (!(keycode
& KEY_RELEASED
) && (s
->pressed_keys
& event
)) {
1417 for (i
= 0; i
<= 7; i
++) {
1418 if (event
& (1 << i
)) {
1419 qemu_set_irq(s
->out
[i
], 1);
1423 for (i
= 0; i
<= 7; i
++) {
1424 if (event
& (1 << i
)) {
1425 qemu_set_irq(s
->out
[i
], !!(keycode
& KEY_RELEASED
));
1428 if (keycode
& KEY_RELEASED
) {
1429 s
->pressed_keys
&= ~event
;
1431 s
->pressed_keys
|= event
;
1435 s
->kbd_extended
= 0;
1438 static int musicpal_key_init(SysBusDevice
*dev
)
1440 musicpal_key_state
*s
= FROM_SYSBUS(musicpal_key_state
, dev
);
1442 sysbus_init_mmio(dev
, 0x0, 0);
1444 s
->kbd_extended
= 0;
1445 s
->pressed_keys
= 0;
1447 qdev_init_gpio_out(&dev
->qdev
, s
->out
, ARRAY_SIZE(s
->out
));
1449 qemu_add_kbd_event_handler(musicpal_key_event
, s
);
1454 static const VMStateDescription musicpal_key_vmsd
= {
1455 .name
= "musicpal_key",
1457 .minimum_version_id
= 1,
1458 .minimum_version_id_old
= 1,
1459 .fields
= (VMStateField
[]) {
1460 VMSTATE_UINT32(kbd_extended
, musicpal_key_state
),
1461 VMSTATE_UINT32(pressed_keys
, musicpal_key_state
),
1462 VMSTATE_END_OF_LIST()
1466 static SysBusDeviceInfo musicpal_key_info
= {
1467 .init
= musicpal_key_init
,
1468 .qdev
.name
= "musicpal_key",
1469 .qdev
.size
= sizeof(musicpal_key_state
),
1470 .qdev
.vmsd
= &musicpal_key_vmsd
,
1473 static struct arm_boot_info musicpal_binfo
= {
1474 .loader_start
= 0x0,
1478 static void musicpal_init(ram_addr_t ram_size
,
1479 const char *boot_device
,
1480 const char *kernel_filename
, const char *kernel_cmdline
,
1481 const char *initrd_filename
, const char *cpu_model
)
1487 DeviceState
*i2c_dev
;
1488 DeviceState
*lcd_dev
;
1489 DeviceState
*key_dev
;
1490 DeviceState
*wm8750_dev
;
1494 unsigned long flash_size
;
1496 ram_addr_t sram_off
;
1499 cpu_model
= "arm926";
1501 env
= cpu_init(cpu_model
);
1503 fprintf(stderr
, "Unable to find CPU definition\n");
1506 cpu_pic
= arm_pic_init_cpu(env
);
1508 /* For now we use a fixed - the original - RAM size */
1509 cpu_register_physical_memory(0, MP_RAM_DEFAULT_SIZE
,
1510 qemu_ram_alloc(NULL
, "musicpal.ram",
1511 MP_RAM_DEFAULT_SIZE
));
1513 sram_off
= qemu_ram_alloc(NULL
, "musicpal.sram", MP_SRAM_SIZE
);
1514 cpu_register_physical_memory(MP_SRAM_BASE
, MP_SRAM_SIZE
, sram_off
);
1516 dev
= sysbus_create_simple("mv88w8618_pic", MP_PIC_BASE
,
1517 cpu_pic
[ARM_PIC_CPU_IRQ
]);
1518 for (i
= 0; i
< 32; i
++) {
1519 pic
[i
] = qdev_get_gpio_in(dev
, i
);
1521 sysbus_create_varargs("mv88w8618_pit", MP_PIT_BASE
, pic
[MP_TIMER1_IRQ
],
1522 pic
[MP_TIMER2_IRQ
], pic
[MP_TIMER3_IRQ
],
1523 pic
[MP_TIMER4_IRQ
], NULL
);
1525 if (serial_hds
[0]) {
1526 #ifdef TARGET_WORDS_BIGENDIAN
1527 serial_mm_init(MP_UART1_BASE
, 2, pic
[MP_UART1_IRQ
], 1825000,
1528 serial_hds
[0], 1, 1);
1530 serial_mm_init(MP_UART1_BASE
, 2, pic
[MP_UART1_IRQ
], 1825000,
1531 serial_hds
[0], 1, 0);
1534 if (serial_hds
[1]) {
1535 #ifdef TARGET_WORDS_BIGENDIAN
1536 serial_mm_init(MP_UART2_BASE
, 2, pic
[MP_UART2_IRQ
], 1825000,
1537 serial_hds
[1], 1, 1);
1539 serial_mm_init(MP_UART2_BASE
, 2, pic
[MP_UART2_IRQ
], 1825000,
1540 serial_hds
[1], 1, 0);
1544 /* Register flash */
1545 dinfo
= drive_get(IF_PFLASH
, 0, 0);
1547 flash_size
= bdrv_getlength(dinfo
->bdrv
);
1548 if (flash_size
!= 8*1024*1024 && flash_size
!= 16*1024*1024 &&
1549 flash_size
!= 32*1024*1024) {
1550 fprintf(stderr
, "Invalid flash image size\n");
1555 * The original U-Boot accesses the flash at 0xFE000000 instead of
1556 * 0xFF800000 (if there is 8 MB flash). So remap flash access if the
1557 * image is smaller than 32 MB.
1559 #ifdef TARGET_WORDS_BIGENDIAN
1560 pflash_cfi02_register(0-MP_FLASH_SIZE_MAX
, qemu_ram_alloc(NULL
,
1561 "musicpal.flash", flash_size
),
1562 dinfo
->bdrv
, 0x10000,
1563 (flash_size
+ 0xffff) >> 16,
1564 MP_FLASH_SIZE_MAX
/ flash_size
,
1565 2, 0x00BF, 0x236D, 0x0000, 0x0000,
1568 pflash_cfi02_register(0-MP_FLASH_SIZE_MAX
, qemu_ram_alloc(NULL
,
1569 "musicpal.flash", flash_size
),
1570 dinfo
->bdrv
, 0x10000,
1571 (flash_size
+ 0xffff) >> 16,
1572 MP_FLASH_SIZE_MAX
/ flash_size
,
1573 2, 0x00BF, 0x236D, 0x0000, 0x0000,
1578 sysbus_create_simple("mv88w8618_flashcfg", MP_FLASHCFG_BASE
, NULL
);
1580 qemu_check_nic_model(&nd_table
[0], "mv88w8618");
1581 dev
= qdev_create(NULL
, "mv88w8618_eth");
1582 qdev_set_nic_properties(dev
, &nd_table
[0]);
1583 qdev_init_nofail(dev
);
1584 sysbus_mmio_map(sysbus_from_qdev(dev
), 0, MP_ETH_BASE
);
1585 sysbus_connect_irq(sysbus_from_qdev(dev
), 0, pic
[MP_ETH_IRQ
]);
1587 sysbus_create_simple("mv88w8618_wlan", MP_WLAN_BASE
, NULL
);
1589 musicpal_misc_init();
1591 dev
= sysbus_create_simple("musicpal_gpio", MP_GPIO_BASE
, pic
[MP_GPIO_IRQ
]);
1592 i2c_dev
= sysbus_create_simple("gpio_i2c", 0, NULL
);
1593 i2c
= (i2c_bus
*)qdev_get_child_bus(i2c_dev
, "i2c");
1595 lcd_dev
= sysbus_create_simple("musicpal_lcd", MP_LCD_BASE
, NULL
);
1596 key_dev
= sysbus_create_simple("musicpal_key", 0, NULL
);
1599 qdev_connect_gpio_out(i2c_dev
, 0,
1600 qdev_get_gpio_in(dev
, MP_GPIO_I2C_DATA_BIT
));
1602 qdev_connect_gpio_out(dev
, 3, qdev_get_gpio_in(i2c_dev
, 0));
1604 qdev_connect_gpio_out(dev
, 4, qdev_get_gpio_in(i2c_dev
, 1));
1606 for (i
= 0; i
< 3; i
++) {
1607 qdev_connect_gpio_out(dev
, i
, qdev_get_gpio_in(lcd_dev
, i
));
1609 for (i
= 0; i
< 4; i
++) {
1610 qdev_connect_gpio_out(key_dev
, i
, qdev_get_gpio_in(dev
, i
+ 8));
1612 for (i
= 4; i
< 8; i
++) {
1613 qdev_connect_gpio_out(key_dev
, i
, qdev_get_gpio_in(dev
, i
+ 15));
1616 wm8750_dev
= i2c_create_slave(i2c
, "wm8750", MP_WM_ADDR
);
1617 dev
= qdev_create(NULL
, "mv88w8618_audio");
1618 s
= sysbus_from_qdev(dev
);
1619 qdev_prop_set_ptr(dev
, "wm8750", wm8750_dev
);
1620 qdev_init_nofail(dev
);
1621 sysbus_mmio_map(s
, 0, MP_AUDIO_BASE
);
1622 sysbus_connect_irq(s
, 0, pic
[MP_AUDIO_IRQ
]);
1624 musicpal_binfo
.ram_size
= MP_RAM_DEFAULT_SIZE
;
1625 musicpal_binfo
.kernel_filename
= kernel_filename
;
1626 musicpal_binfo
.kernel_cmdline
= kernel_cmdline
;
1627 musicpal_binfo
.initrd_filename
= initrd_filename
;
1628 arm_load_kernel(env
, &musicpal_binfo
);
1631 static QEMUMachine musicpal_machine
= {
1633 .desc
= "Marvell 88w8618 / MusicPal (ARM926EJ-S)",
1634 .init
= musicpal_init
,
1637 static void musicpal_machine_init(void)
1639 qemu_register_machine(&musicpal_machine
);
1642 machine_init(musicpal_machine_init
);
1644 static void musicpal_register_devices(void)
1646 sysbus_register_withprop(&mv88w8618_pic_info
);
1647 sysbus_register_withprop(&mv88w8618_pit_info
);
1648 sysbus_register_withprop(&mv88w8618_flashcfg_info
);
1649 sysbus_register_withprop(&mv88w8618_eth_info
);
1650 sysbus_register_dev("mv88w8618_wlan", sizeof(SysBusDevice
),
1651 mv88w8618_wlan_init
);
1652 sysbus_register_withprop(&musicpal_lcd_info
);
1653 sysbus_register_withprop(&musicpal_gpio_info
);
1654 sysbus_register_withprop(&musicpal_key_info
);
1657 device_init(musicpal_register_devices
)