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"
22 #define MP_MISC_BASE 0x80002000
23 #define MP_MISC_SIZE 0x00001000
25 #define MP_ETH_BASE 0x80008000
26 #define MP_ETH_SIZE 0x00001000
28 #define MP_WLAN_BASE 0x8000C000
29 #define MP_WLAN_SIZE 0x00000800
31 #define MP_UART1_BASE 0x8000C840
32 #define MP_UART2_BASE 0x8000C940
34 #define MP_GPIO_BASE 0x8000D000
35 #define MP_GPIO_SIZE 0x00001000
37 #define MP_FLASHCFG_BASE 0x90006000
38 #define MP_FLASHCFG_SIZE 0x00001000
40 #define MP_AUDIO_BASE 0x90007000
42 #define MP_PIC_BASE 0x90008000
43 #define MP_PIC_SIZE 0x00001000
45 #define MP_PIT_BASE 0x90009000
46 #define MP_PIT_SIZE 0x00001000
48 #define MP_LCD_BASE 0x9000c000
49 #define MP_LCD_SIZE 0x00001000
51 #define MP_SRAM_BASE 0xC0000000
52 #define MP_SRAM_SIZE 0x00020000
54 #define MP_RAM_DEFAULT_SIZE 32*1024*1024
55 #define MP_FLASH_SIZE_MAX 32*1024*1024
57 #define MP_TIMER1_IRQ 4
58 #define MP_TIMER2_IRQ 5
59 #define MP_TIMER3_IRQ 6
60 #define MP_TIMER4_IRQ 7
63 #define MP_UART1_IRQ 11
64 #define MP_UART2_IRQ 11
65 #define MP_GPIO_IRQ 12
67 #define MP_AUDIO_IRQ 30
69 /* Wolfson 8750 I2C address */
70 #define MP_WM_ADDR 0x34
72 /* Ethernet register offsets */
73 #define MP_ETH_SMIR 0x010
74 #define MP_ETH_PCXR 0x408
75 #define MP_ETH_SDCMR 0x448
76 #define MP_ETH_ICR 0x450
77 #define MP_ETH_IMR 0x458
78 #define MP_ETH_FRDP0 0x480
79 #define MP_ETH_FRDP1 0x484
80 #define MP_ETH_FRDP2 0x488
81 #define MP_ETH_FRDP3 0x48C
82 #define MP_ETH_CRDP0 0x4A0
83 #define MP_ETH_CRDP1 0x4A4
84 #define MP_ETH_CRDP2 0x4A8
85 #define MP_ETH_CRDP3 0x4AC
86 #define MP_ETH_CTDP0 0x4E0
87 #define MP_ETH_CTDP1 0x4E4
88 #define MP_ETH_CTDP2 0x4E8
89 #define MP_ETH_CTDP3 0x4EC
92 #define MP_ETH_SMIR_DATA 0x0000FFFF
93 #define MP_ETH_SMIR_ADDR 0x03FF0000
94 #define MP_ETH_SMIR_OPCODE (1 << 26) /* Read value */
95 #define MP_ETH_SMIR_RDVALID (1 << 27)
98 #define MP_ETH_PHY1_BMSR 0x00210000
99 #define MP_ETH_PHY1_PHYSID1 0x00410000
100 #define MP_ETH_PHY1_PHYSID2 0x00610000
102 #define MP_PHY_BMSR_LINK 0x0004
103 #define MP_PHY_BMSR_AUTONEG 0x0008
105 #define MP_PHY_88E3015 0x01410E20
107 /* TX descriptor status */
108 #define MP_ETH_TX_OWN (1 << 31)
110 /* RX descriptor status */
111 #define MP_ETH_RX_OWN (1 << 31)
113 /* Interrupt cause/mask bits */
114 #define MP_ETH_IRQ_RX_BIT 0
115 #define MP_ETH_IRQ_RX (1 << MP_ETH_IRQ_RX_BIT)
116 #define MP_ETH_IRQ_TXHI_BIT 2
117 #define MP_ETH_IRQ_TXLO_BIT 3
119 /* Port config bits */
120 #define MP_ETH_PCXR_2BSM_BIT 28 /* 2-byte incoming suffix */
122 /* SDMA command bits */
123 #define MP_ETH_CMD_TXHI (1 << 23)
124 #define MP_ETH_CMD_TXLO (1 << 22)
126 typedef struct mv88w8618_tx_desc
{
134 typedef struct mv88w8618_rx_desc
{
137 uint16_t buffer_size
;
142 typedef struct mv88w8618_eth_state
{
149 uint32_t vlan_header
;
150 uint32_t tx_queue
[2];
151 uint32_t rx_queue
[4];
152 uint32_t frx_queue
[4];
156 } mv88w8618_eth_state
;
158 static void eth_rx_desc_put(uint32_t addr
, mv88w8618_rx_desc
*desc
)
160 cpu_to_le32s(&desc
->cmdstat
);
161 cpu_to_le16s(&desc
->bytes
);
162 cpu_to_le16s(&desc
->buffer_size
);
163 cpu_to_le32s(&desc
->buffer
);
164 cpu_to_le32s(&desc
->next
);
165 cpu_physical_memory_write(addr
, (void *)desc
, sizeof(*desc
));
168 static void eth_rx_desc_get(uint32_t addr
, mv88w8618_rx_desc
*desc
)
170 cpu_physical_memory_read(addr
, (void *)desc
, sizeof(*desc
));
171 le32_to_cpus(&desc
->cmdstat
);
172 le16_to_cpus(&desc
->bytes
);
173 le16_to_cpus(&desc
->buffer_size
);
174 le32_to_cpus(&desc
->buffer
);
175 le32_to_cpus(&desc
->next
);
178 static int eth_can_receive(VLANClientState
*nc
)
183 static ssize_t
eth_receive(VLANClientState
*nc
, const uint8_t *buf
, size_t size
)
185 mv88w8618_eth_state
*s
= DO_UPCAST(NICState
, nc
, nc
)->opaque
;
187 mv88w8618_rx_desc desc
;
190 for (i
= 0; i
< 4; i
++) {
191 desc_addr
= s
->cur_rx
[i
];
196 eth_rx_desc_get(desc_addr
, &desc
);
197 if ((desc
.cmdstat
& MP_ETH_RX_OWN
) && desc
.buffer_size
>= size
) {
198 cpu_physical_memory_write(desc
.buffer
+ s
->vlan_header
,
200 desc
.bytes
= size
+ s
->vlan_header
;
201 desc
.cmdstat
&= ~MP_ETH_RX_OWN
;
202 s
->cur_rx
[i
] = desc
.next
;
204 s
->icr
|= MP_ETH_IRQ_RX
;
205 if (s
->icr
& s
->imr
) {
206 qemu_irq_raise(s
->irq
);
208 eth_rx_desc_put(desc_addr
, &desc
);
211 desc_addr
= desc
.next
;
212 } while (desc_addr
!= s
->rx_queue
[i
]);
217 static void eth_tx_desc_put(uint32_t addr
, mv88w8618_tx_desc
*desc
)
219 cpu_to_le32s(&desc
->cmdstat
);
220 cpu_to_le16s(&desc
->res
);
221 cpu_to_le16s(&desc
->bytes
);
222 cpu_to_le32s(&desc
->buffer
);
223 cpu_to_le32s(&desc
->next
);
224 cpu_physical_memory_write(addr
, (void *)desc
, sizeof(*desc
));
227 static void eth_tx_desc_get(uint32_t addr
, mv88w8618_tx_desc
*desc
)
229 cpu_physical_memory_read(addr
, (void *)desc
, sizeof(*desc
));
230 le32_to_cpus(&desc
->cmdstat
);
231 le16_to_cpus(&desc
->res
);
232 le16_to_cpus(&desc
->bytes
);
233 le32_to_cpus(&desc
->buffer
);
234 le32_to_cpus(&desc
->next
);
237 static void eth_send(mv88w8618_eth_state
*s
, int queue_index
)
239 uint32_t desc_addr
= s
->tx_queue
[queue_index
];
240 mv88w8618_tx_desc desc
;
248 eth_tx_desc_get(desc_addr
, &desc
);
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
= desc
.next
;
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 musicpal_gpio_reset(&dev
->qdev
);
1301 qdev_init_gpio_out(&dev
->qdev
, s
->out
, ARRAY_SIZE(s
->out
));
1303 qdev_init_gpio_in(&dev
->qdev
, musicpal_gpio_pin_event
, 32);
1308 static const VMStateDescription musicpal_gpio_vmsd
= {
1309 .name
= "musicpal_gpio",
1311 .minimum_version_id
= 1,
1312 .minimum_version_id_old
= 1,
1313 .fields
= (VMStateField
[]) {
1314 VMSTATE_UINT32(lcd_brightness
, musicpal_gpio_state
),
1315 VMSTATE_UINT32(out_state
, musicpal_gpio_state
),
1316 VMSTATE_UINT32(in_state
, musicpal_gpio_state
),
1317 VMSTATE_UINT32(ier
, musicpal_gpio_state
),
1318 VMSTATE_UINT32(imr
, musicpal_gpio_state
),
1319 VMSTATE_UINT32(isr
, musicpal_gpio_state
),
1320 VMSTATE_END_OF_LIST()
1324 static SysBusDeviceInfo musicpal_gpio_info
= {
1325 .init
= musicpal_gpio_init
,
1326 .qdev
.name
= "musicpal_gpio",
1327 .qdev
.size
= sizeof(musicpal_gpio_state
),
1328 .qdev
.reset
= musicpal_gpio_reset
,
1329 .qdev
.vmsd
= &musicpal_gpio_vmsd
,
1332 /* Keyboard codes & masks */
1333 #define KEY_RELEASED 0x80
1334 #define KEY_CODE 0x7f
1336 #define KEYCODE_TAB 0x0f
1337 #define KEYCODE_ENTER 0x1c
1338 #define KEYCODE_F 0x21
1339 #define KEYCODE_M 0x32
1341 #define KEYCODE_EXTENDED 0xe0
1342 #define KEYCODE_UP 0x48
1343 #define KEYCODE_DOWN 0x50
1344 #define KEYCODE_LEFT 0x4b
1345 #define KEYCODE_RIGHT 0x4d
1347 #define MP_KEY_WHEEL_VOL (1 << 0)
1348 #define MP_KEY_WHEEL_VOL_INV (1 << 1)
1349 #define MP_KEY_WHEEL_NAV (1 << 2)
1350 #define MP_KEY_WHEEL_NAV_INV (1 << 3)
1351 #define MP_KEY_BTN_FAVORITS (1 << 4)
1352 #define MP_KEY_BTN_MENU (1 << 5)
1353 #define MP_KEY_BTN_VOLUME (1 << 6)
1354 #define MP_KEY_BTN_NAVIGATION (1 << 7)
1356 typedef struct musicpal_key_state
{
1357 SysBusDevice busdev
;
1358 uint32_t kbd_extended
;
1359 uint32_t pressed_keys
;
1361 } musicpal_key_state
;
1363 static void musicpal_key_event(void *opaque
, int keycode
)
1365 musicpal_key_state
*s
= opaque
;
1369 if (keycode
== KEYCODE_EXTENDED
) {
1370 s
->kbd_extended
= 1;
1374 if (s
->kbd_extended
) {
1375 switch (keycode
& KEY_CODE
) {
1377 event
= MP_KEY_WHEEL_NAV
| MP_KEY_WHEEL_NAV_INV
;
1381 event
= MP_KEY_WHEEL_NAV
;
1385 event
= MP_KEY_WHEEL_VOL
| MP_KEY_WHEEL_VOL_INV
;
1389 event
= MP_KEY_WHEEL_VOL
;
1393 switch (keycode
& KEY_CODE
) {
1395 event
= MP_KEY_BTN_FAVORITS
;
1399 event
= MP_KEY_BTN_VOLUME
;
1403 event
= MP_KEY_BTN_NAVIGATION
;
1407 event
= MP_KEY_BTN_MENU
;
1410 /* Do not repeat already pressed buttons */
1411 if (!(keycode
& KEY_RELEASED
) && (s
->pressed_keys
& event
)) {
1417 /* Raise GPIO pin first if repeating a key */
1418 if (!(keycode
& KEY_RELEASED
) && (s
->pressed_keys
& event
)) {
1419 for (i
= 0; i
<= 7; i
++) {
1420 if (event
& (1 << i
)) {
1421 qemu_set_irq(s
->out
[i
], 1);
1425 for (i
= 0; i
<= 7; i
++) {
1426 if (event
& (1 << i
)) {
1427 qemu_set_irq(s
->out
[i
], !!(keycode
& KEY_RELEASED
));
1430 if (keycode
& KEY_RELEASED
) {
1431 s
->pressed_keys
&= ~event
;
1433 s
->pressed_keys
|= event
;
1437 s
->kbd_extended
= 0;
1440 static int musicpal_key_init(SysBusDevice
*dev
)
1442 musicpal_key_state
*s
= FROM_SYSBUS(musicpal_key_state
, dev
);
1444 sysbus_init_mmio(dev
, 0x0, 0);
1446 s
->kbd_extended
= 0;
1447 s
->pressed_keys
= 0;
1449 qdev_init_gpio_out(&dev
->qdev
, s
->out
, ARRAY_SIZE(s
->out
));
1451 qemu_add_kbd_event_handler(musicpal_key_event
, s
);
1456 static const VMStateDescription musicpal_key_vmsd
= {
1457 .name
= "musicpal_key",
1459 .minimum_version_id
= 1,
1460 .minimum_version_id_old
= 1,
1461 .fields
= (VMStateField
[]) {
1462 VMSTATE_UINT32(kbd_extended
, musicpal_key_state
),
1463 VMSTATE_UINT32(pressed_keys
, musicpal_key_state
),
1464 VMSTATE_END_OF_LIST()
1468 static SysBusDeviceInfo musicpal_key_info
= {
1469 .init
= musicpal_key_init
,
1470 .qdev
.name
= "musicpal_key",
1471 .qdev
.size
= sizeof(musicpal_key_state
),
1472 .qdev
.vmsd
= &musicpal_key_vmsd
,
1475 static struct arm_boot_info musicpal_binfo
= {
1476 .loader_start
= 0x0,
1480 static void musicpal_init(ram_addr_t ram_size
,
1481 const char *boot_device
,
1482 const char *kernel_filename
, const char *kernel_cmdline
,
1483 const char *initrd_filename
, const char *cpu_model
)
1489 DeviceState
*i2c_dev
;
1490 DeviceState
*lcd_dev
;
1491 DeviceState
*key_dev
;
1493 DeviceState
*wm8750_dev
;
1498 unsigned long flash_size
;
1500 ram_addr_t sram_off
;
1503 cpu_model
= "arm926";
1505 env
= cpu_init(cpu_model
);
1507 fprintf(stderr
, "Unable to find CPU definition\n");
1510 cpu_pic
= arm_pic_init_cpu(env
);
1512 /* For now we use a fixed - the original - RAM size */
1513 cpu_register_physical_memory(0, MP_RAM_DEFAULT_SIZE
,
1514 qemu_ram_alloc(MP_RAM_DEFAULT_SIZE
));
1516 sram_off
= qemu_ram_alloc(MP_SRAM_SIZE
);
1517 cpu_register_physical_memory(MP_SRAM_BASE
, MP_SRAM_SIZE
, sram_off
);
1519 dev
= sysbus_create_simple("mv88w8618_pic", MP_PIC_BASE
,
1520 cpu_pic
[ARM_PIC_CPU_IRQ
]);
1521 for (i
= 0; i
< 32; i
++) {
1522 pic
[i
] = qdev_get_gpio_in(dev
, i
);
1524 sysbus_create_varargs("mv88w8618_pit", MP_PIT_BASE
, pic
[MP_TIMER1_IRQ
],
1525 pic
[MP_TIMER2_IRQ
], pic
[MP_TIMER3_IRQ
],
1526 pic
[MP_TIMER4_IRQ
], NULL
);
1528 if (serial_hds
[0]) {
1529 serial_mm_init(MP_UART1_BASE
, 2, pic
[MP_UART1_IRQ
], 1825000,
1532 if (serial_hds
[1]) {
1533 serial_mm_init(MP_UART2_BASE
, 2, pic
[MP_UART2_IRQ
], 1825000,
1537 /* Register flash */
1538 dinfo
= drive_get(IF_PFLASH
, 0, 0);
1540 flash_size
= bdrv_getlength(dinfo
->bdrv
);
1541 if (flash_size
!= 8*1024*1024 && flash_size
!= 16*1024*1024 &&
1542 flash_size
!= 32*1024*1024) {
1543 fprintf(stderr
, "Invalid flash image size\n");
1548 * The original U-Boot accesses the flash at 0xFE000000 instead of
1549 * 0xFF800000 (if there is 8 MB flash). So remap flash access if the
1550 * image is smaller than 32 MB.
1552 pflash_cfi02_register(0-MP_FLASH_SIZE_MAX
, qemu_ram_alloc(flash_size
),
1553 dinfo
->bdrv
, 0x10000,
1554 (flash_size
+ 0xffff) >> 16,
1555 MP_FLASH_SIZE_MAX
/ flash_size
,
1556 2, 0x00BF, 0x236D, 0x0000, 0x0000,
1559 sysbus_create_simple("mv88w8618_flashcfg", MP_FLASHCFG_BASE
, NULL
);
1561 qemu_check_nic_model(&nd_table
[0], "mv88w8618");
1562 dev
= qdev_create(NULL
, "mv88w8618_eth");
1563 qdev_set_nic_properties(dev
, &nd_table
[0]);
1564 qdev_init_nofail(dev
);
1565 sysbus_mmio_map(sysbus_from_qdev(dev
), 0, MP_ETH_BASE
);
1566 sysbus_connect_irq(sysbus_from_qdev(dev
), 0, pic
[MP_ETH_IRQ
]);
1568 sysbus_create_simple("mv88w8618_wlan", MP_WLAN_BASE
, NULL
);
1570 musicpal_misc_init();
1572 dev
= sysbus_create_simple("musicpal_gpio", MP_GPIO_BASE
, pic
[MP_GPIO_IRQ
]);
1573 i2c_dev
= sysbus_create_simple("gpio_i2c", 0, NULL
);
1574 i2c
= (i2c_bus
*)qdev_get_child_bus(i2c_dev
, "i2c");
1576 lcd_dev
= sysbus_create_simple("musicpal_lcd", MP_LCD_BASE
, NULL
);
1577 key_dev
= sysbus_create_simple("musicpal_key", 0, NULL
);
1580 qdev_connect_gpio_out(i2c_dev
, 0,
1581 qdev_get_gpio_in(dev
, MP_GPIO_I2C_DATA_BIT
));
1583 qdev_connect_gpio_out(dev
, 3, qdev_get_gpio_in(i2c_dev
, 0));
1585 qdev_connect_gpio_out(dev
, 4, qdev_get_gpio_in(i2c_dev
, 1));
1587 for (i
= 0; i
< 3; i
++) {
1588 qdev_connect_gpio_out(dev
, i
, qdev_get_gpio_in(lcd_dev
, i
));
1590 for (i
= 0; i
< 4; i
++) {
1591 qdev_connect_gpio_out(key_dev
, i
, qdev_get_gpio_in(dev
, i
+ 8));
1593 for (i
= 4; i
< 8; i
++) {
1594 qdev_connect_gpio_out(key_dev
, i
, qdev_get_gpio_in(dev
, i
+ 15));
1598 wm8750_dev
= i2c_create_slave(i2c
, "wm8750", MP_WM_ADDR
);
1599 dev
= qdev_create(NULL
, "mv88w8618_audio");
1600 s
= sysbus_from_qdev(dev
);
1601 qdev_prop_set_ptr(dev
, "wm8750", wm8750_dev
);
1602 qdev_init_nofail(dev
);
1603 sysbus_mmio_map(s
, 0, MP_AUDIO_BASE
);
1604 sysbus_connect_irq(s
, 0, pic
[MP_AUDIO_IRQ
]);
1607 musicpal_binfo
.ram_size
= MP_RAM_DEFAULT_SIZE
;
1608 musicpal_binfo
.kernel_filename
= kernel_filename
;
1609 musicpal_binfo
.kernel_cmdline
= kernel_cmdline
;
1610 musicpal_binfo
.initrd_filename
= initrd_filename
;
1611 arm_load_kernel(env
, &musicpal_binfo
);
1614 static QEMUMachine musicpal_machine
= {
1616 .desc
= "Marvell 88w8618 / MusicPal (ARM926EJ-S)",
1617 .init
= musicpal_init
,
1620 static void musicpal_machine_init(void)
1622 qemu_register_machine(&musicpal_machine
);
1625 machine_init(musicpal_machine_init
);
1627 static void musicpal_register_devices(void)
1629 sysbus_register_withprop(&mv88w8618_pic_info
);
1630 sysbus_register_withprop(&mv88w8618_pit_info
);
1631 sysbus_register_withprop(&mv88w8618_flashcfg_info
);
1632 sysbus_register_withprop(&mv88w8618_eth_info
);
1633 sysbus_register_dev("mv88w8618_wlan", sizeof(SysBusDevice
),
1634 mv88w8618_wlan_init
);
1635 sysbus_register_withprop(&musicpal_lcd_info
);
1636 sysbus_register_withprop(&musicpal_gpio_info
);
1637 sysbus_register_withprop(&musicpal_key_info
);
1640 device_init(musicpal_register_devices
)