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
{
40 uint32_t regs
[CS_REGS
];
41 uint8_t dregs
[CS_DREGS
];
44 #define CS_RAP(s) ((s)->regs[0] & CS_MAXDREG)
46 #define CS_CDC_VER 0x8a
48 static void cs_reset(DeviceState
*d
)
50 CSState
*s
= container_of(d
, CSState
, busdev
.qdev
);
52 memset(s
->regs
, 0, CS_REGS
* 4);
53 memset(s
->dregs
, 0, CS_DREGS
);
54 s
->dregs
[12] = CS_CDC_VER
;
55 s
->dregs
[25] = CS_VER
;
58 static uint64_t cs_mem_read(void *opaque
, target_phys_addr_t addr
,
72 ret
= s
->dregs
[CS_RAP(s
)];
75 trace_cs4231_mem_readl_dreg(CS_RAP(s
), ret
);
79 trace_cs4231_mem_readl_reg(saddr
, ret
);
85 static void cs_mem_write(void *opaque
, target_phys_addr_t addr
,
86 uint64_t val
, unsigned size
)
92 trace_cs4231_mem_writel_reg(saddr
, s
->regs
[saddr
], val
);
95 trace_cs4231_mem_writel_dreg(CS_RAP(s
), s
->dregs
[CS_RAP(s
)], val
);
102 val
|= CS_CDC_VER
; // Codec version
103 s
->dregs
[CS_RAP(s
)] = val
;
106 s
->dregs
[CS_RAP(s
)] = val
;
114 cs_reset(&s
->busdev
.qdev
);
117 s
->regs
[saddr
] = val
;
120 s
->regs
[saddr
] = val
;
125 static const MemoryRegionOps cs_mem_ops
= {
127 .write
= cs_mem_write
,
128 .endianness
= DEVICE_NATIVE_ENDIAN
,
131 static const VMStateDescription vmstate_cs4231
= {
134 .minimum_version_id
= 1,
135 .minimum_version_id_old
= 1,
136 .fields
= (VMStateField
[]) {
137 VMSTATE_UINT32_ARRAY(regs
, CSState
, CS_REGS
),
138 VMSTATE_UINT8_ARRAY(dregs
, CSState
, CS_DREGS
),
139 VMSTATE_END_OF_LIST()
143 static int cs4231_init1(SysBusDevice
*dev
)
145 CSState
*s
= FROM_SYSBUS(CSState
, dev
);
147 memory_region_init_io(&s
->iomem
, &cs_mem_ops
, s
, "cs4321", CS_SIZE
);
148 sysbus_init_mmio(dev
, &s
->iomem
);
149 sysbus_init_irq(dev
, &s
->irq
);
154 static Property cs4231_properties
[] = {
158 static void cs4231_class_init(ObjectClass
*klass
, void *data
)
160 DeviceClass
*dc
= DEVICE_CLASS(klass
);
161 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
163 k
->init
= cs4231_init1
;
164 dc
->reset
= cs_reset
;
165 dc
->vmsd
= &vmstate_cs4231
;
166 dc
->props
= cs4231_properties
;
169 static TypeInfo cs4231_info
= {
170 .name
= "SUNW,CS4231",
171 .parent
= TYPE_SYS_BUS_DEVICE
,
172 .instance_size
= sizeof(CSState
),
173 .class_init
= cs4231_class_init
,
176 static void cs4231_register_devices(void)
178 type_register_static(&cs4231_info
);
181 device_init(cs4231_register_devices
)