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
25 #include "qemu/osdep.h"
26 #include "hw/sysbus.h"
30 * In addition to Crystal CS4231 there is a DMA controller on Sparc.
35 #define CS_MAXDREG (CS_DREGS - 1)
37 #define TYPE_CS4231 "SUNW,CS4231"
39 OBJECT_CHECK(CSState, (obj), TYPE_CS4231)
41 typedef struct CSState
{
42 SysBusDevice parent_obj
;
46 uint32_t regs
[CS_REGS
];
47 uint8_t dregs
[CS_DREGS
];
50 #define CS_RAP(s) ((s)->regs[0] & CS_MAXDREG)
52 #define CS_CDC_VER 0x8a
54 static void cs_reset(DeviceState
*d
)
56 CSState
*s
= CS4231(d
);
58 memset(s
->regs
, 0, CS_REGS
* 4);
59 memset(s
->dregs
, 0, CS_DREGS
);
60 s
->dregs
[12] = CS_CDC_VER
;
61 s
->dregs
[25] = CS_VER
;
64 static uint64_t cs_mem_read(void *opaque
, hwaddr addr
,
78 ret
= s
->dregs
[CS_RAP(s
)];
81 trace_cs4231_mem_readl_dreg(CS_RAP(s
), ret
);
85 trace_cs4231_mem_readl_reg(saddr
, ret
);
91 static void cs_mem_write(void *opaque
, hwaddr addr
,
92 uint64_t val
, unsigned size
)
98 trace_cs4231_mem_writel_reg(saddr
, s
->regs
[saddr
], val
);
101 trace_cs4231_mem_writel_dreg(CS_RAP(s
), s
->dregs
[CS_RAP(s
)], val
);
104 case 25: // Read only
108 val
|= CS_CDC_VER
; // Codec version
109 s
->dregs
[CS_RAP(s
)] = val
;
112 s
->dregs
[CS_RAP(s
)] = val
;
123 s
->regs
[saddr
] = val
;
126 s
->regs
[saddr
] = val
;
131 static const MemoryRegionOps cs_mem_ops
= {
133 .write
= cs_mem_write
,
134 .endianness
= DEVICE_NATIVE_ENDIAN
,
137 static const VMStateDescription vmstate_cs4231
= {
140 .minimum_version_id
= 1,
141 .fields
= (VMStateField
[]) {
142 VMSTATE_UINT32_ARRAY(regs
, CSState
, CS_REGS
),
143 VMSTATE_UINT8_ARRAY(dregs
, CSState
, CS_DREGS
),
144 VMSTATE_END_OF_LIST()
148 static void cs4231_init(Object
*obj
)
150 CSState
*s
= CS4231(obj
);
151 SysBusDevice
*dev
= SYS_BUS_DEVICE(obj
);
153 memory_region_init_io(&s
->iomem
, obj
, &cs_mem_ops
, s
, "cs4321",
155 sysbus_init_mmio(dev
, &s
->iomem
);
156 sysbus_init_irq(dev
, &s
->irq
);
159 static Property cs4231_properties
[] = {
163 static void cs4231_class_init(ObjectClass
*klass
, void *data
)
165 DeviceClass
*dc
= DEVICE_CLASS(klass
);
167 dc
->reset
= cs_reset
;
168 dc
->vmsd
= &vmstate_cs4231
;
169 dc
->props
= cs4231_properties
;
172 static const TypeInfo cs4231_info
= {
174 .parent
= TYPE_SYS_BUS_DEVICE
,
175 .instance_size
= sizeof(CSState
),
176 .instance_init
= cs4231_init
,
177 .class_init
= cs4231_class_init
,
180 static void cs4231_register_types(void)
182 type_register_static(&cs4231_info
);
185 type_init(cs4231_register_types
)