2 * QEMU Crystal CS4231 audio chip emulation
4 * Copyright (c) 2006 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 * In addition to Crystal CS4231 there is a DMA controller on Sparc.
34 #define CS_MAXDREG (CS_DREGS - 1)
36 typedef struct CSState
{
39 uint32_t regs
[CS_REGS
];
40 uint8_t dregs
[CS_DREGS
];
43 #define CS_RAP(s) ((s)->regs[0] & CS_MAXDREG)
45 #define CS_CDC_VER 0x8a
47 static void cs_reset(DeviceState
*d
)
49 CSState
*s
= container_of(d
, CSState
, busdev
.qdev
);
51 memset(s
->regs
, 0, CS_REGS
* 4);
52 memset(s
->dregs
, 0, CS_DREGS
);
53 s
->dregs
[12] = CS_CDC_VER
;
54 s
->dregs
[25] = CS_VER
;
57 static uint32_t cs_mem_readl(void *opaque
, target_phys_addr_t addr
)
70 ret
= s
->dregs
[CS_RAP(s
)];
73 trace_cs4231_mem_readl_dreg(CS_RAP(s
), ret
);
77 trace_cs4231_mem_readl_reg(saddr
, ret
);
83 static void cs_mem_writel(void *opaque
, target_phys_addr_t addr
, uint32_t val
)
89 trace_cs4231_mem_writel_reg(saddr
, s
->regs
[saddr
], val
);
92 trace_cs4231_mem_writel_dreg(CS_RAP(s
), s
->dregs
[CS_RAP(s
)], val
);
99 val
|= CS_CDC_VER
; // Codec version
100 s
->dregs
[CS_RAP(s
)] = val
;
103 s
->dregs
[CS_RAP(s
)] = val
;
111 cs_reset(&s
->busdev
.qdev
);
114 s
->regs
[saddr
] = val
;
117 s
->regs
[saddr
] = val
;
122 static CPUReadMemoryFunc
* const cs_mem_read
[3] = {
128 static CPUWriteMemoryFunc
* const cs_mem_write
[3] = {
134 static const VMStateDescription vmstate_cs4231
= {
137 .minimum_version_id
= 1,
138 .minimum_version_id_old
= 1,
139 .fields
= (VMStateField
[]) {
140 VMSTATE_UINT32_ARRAY(regs
, CSState
, CS_REGS
),
141 VMSTATE_UINT8_ARRAY(dregs
, CSState
, CS_DREGS
),
142 VMSTATE_END_OF_LIST()
146 static int cs4231_init1(SysBusDevice
*dev
)
149 CSState
*s
= FROM_SYSBUS(CSState
, dev
);
151 io
= cpu_register_io_memory(cs_mem_read
, cs_mem_write
, s
,
152 DEVICE_NATIVE_ENDIAN
);
153 sysbus_init_mmio(dev
, CS_SIZE
, io
);
154 sysbus_init_irq(dev
, &s
->irq
);
159 static SysBusDeviceInfo cs4231_info
= {
160 .init
= cs4231_init1
,
161 .qdev
.name
= "SUNW,CS4231",
162 .qdev
.size
= sizeof(CSState
),
163 .qdev
.vmsd
= &vmstate_cs4231
,
164 .qdev
.reset
= cs_reset
,
165 .qdev
.props
= (Property
[]) {
170 static void cs4231_register_devices(void)
172 sysbus_register_withprop(&cs4231_info
);
175 device_init(cs4231_register_devices
)