root / hw / cs4231.c @ 3ced9f7a
History | View | Annotate | Download (4.7 kB)
1 | b8174937 | bellard | /*
|
---|---|---|---|
2 | b8174937 | bellard | * QEMU Crystal CS4231 audio chip emulation
|
3 | b8174937 | bellard | *
|
4 | b8174937 | bellard | * Copyright (c) 2006 Fabrice Bellard
|
5 | b8174937 | bellard | *
|
6 | b8174937 | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | b8174937 | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | b8174937 | bellard | * in the Software without restriction, including without limitation the rights
|
9 | b8174937 | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | b8174937 | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | b8174937 | bellard | * furnished to do so, subject to the following conditions:
|
12 | b8174937 | bellard | *
|
13 | b8174937 | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | b8174937 | bellard | * all copies or substantial portions of the Software.
|
15 | b8174937 | bellard | *
|
16 | b8174937 | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | b8174937 | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | b8174937 | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | b8174937 | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | b8174937 | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | b8174937 | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | b8174937 | bellard | * THE SOFTWARE.
|
23 | b8174937 | bellard | */
|
24 | fa28ec52 | Blue Swirl | |
25 | fa28ec52 | Blue Swirl | #include "sysbus.h" |
26 | b8174937 | bellard | |
27 | b8174937 | bellard | /* debug CS4231 */
|
28 | b8174937 | bellard | //#define DEBUG_CS
|
29 | b8174937 | bellard | |
30 | b8174937 | bellard | /*
|
31 | b8174937 | bellard | * In addition to Crystal CS4231 there is a DMA controller on Sparc.
|
32 | b8174937 | bellard | */
|
33 | e64d7d59 | blueswir1 | #define CS_SIZE 0x40 |
34 | b8174937 | bellard | #define CS_REGS 16 |
35 | b8174937 | bellard | #define CS_DREGS 32 |
36 | b8174937 | bellard | #define CS_MAXDREG (CS_DREGS - 1) |
37 | b8174937 | bellard | |
38 | b8174937 | bellard | typedef struct CSState { |
39 | fa28ec52 | Blue Swirl | SysBusDevice busdev; |
40 | fa28ec52 | Blue Swirl | qemu_irq irq; |
41 | b8174937 | bellard | uint32_t regs[CS_REGS]; |
42 | b8174937 | bellard | uint8_t dregs[CS_DREGS]; |
43 | b8174937 | bellard | } CSState; |
44 | b8174937 | bellard | |
45 | b8174937 | bellard | #define CS_RAP(s) ((s)->regs[0] & CS_MAXDREG) |
46 | b8174937 | bellard | #define CS_VER 0xa0 |
47 | b8174937 | bellard | #define CS_CDC_VER 0x8a |
48 | b8174937 | bellard | |
49 | b8174937 | bellard | #ifdef DEBUG_CS
|
50 | 001faf32 | Blue Swirl | #define DPRINTF(fmt, ...) \
|
51 | 001faf32 | Blue Swirl | do { printf("CS: " fmt , ## __VA_ARGS__); } while (0) |
52 | b8174937 | bellard | #else
|
53 | 001faf32 | Blue Swirl | #define DPRINTF(fmt, ...)
|
54 | b8174937 | bellard | #endif
|
55 | b8174937 | bellard | |
56 | 82d4c6e6 | Blue Swirl | static void cs_reset(DeviceState *d) |
57 | b8174937 | bellard | { |
58 | 82d4c6e6 | Blue Swirl | CSState *s = container_of(d, CSState, busdev.qdev); |
59 | b8174937 | bellard | |
60 | b8174937 | bellard | memset(s->regs, 0, CS_REGS * 4); |
61 | b8174937 | bellard | memset(s->dregs, 0, CS_DREGS);
|
62 | b8174937 | bellard | s->dregs[12] = CS_CDC_VER;
|
63 | b8174937 | bellard | s->dregs[25] = CS_VER;
|
64 | b8174937 | bellard | } |
65 | b8174937 | bellard | |
66 | c227f099 | Anthony Liguori | static uint32_t cs_mem_readl(void *opaque, target_phys_addr_t addr) |
67 | b8174937 | bellard | { |
68 | b8174937 | bellard | CSState *s = opaque; |
69 | b8174937 | bellard | uint32_t saddr, ret; |
70 | b8174937 | bellard | |
71 | e64d7d59 | blueswir1 | saddr = addr >> 2;
|
72 | b8174937 | bellard | switch (saddr) {
|
73 | b8174937 | bellard | case 1: |
74 | b8174937 | bellard | switch (CS_RAP(s)) {
|
75 | b8174937 | bellard | case 3: // Write only |
76 | b8174937 | bellard | ret = 0;
|
77 | b8174937 | bellard | break;
|
78 | b8174937 | bellard | default:
|
79 | b8174937 | bellard | ret = s->dregs[CS_RAP(s)]; |
80 | b8174937 | bellard | break;
|
81 | b8174937 | bellard | } |
82 | b8174937 | bellard | DPRINTF("read dreg[%d]: 0x%8.8x\n", CS_RAP(s), ret);
|
83 | f930d07e | blueswir1 | break;
|
84 | b8174937 | bellard | default:
|
85 | b8174937 | bellard | ret = s->regs[saddr]; |
86 | b8174937 | bellard | DPRINTF("read reg[%d]: 0x%8.8x\n", saddr, ret);
|
87 | f930d07e | blueswir1 | break;
|
88 | b8174937 | bellard | } |
89 | b8174937 | bellard | return ret;
|
90 | b8174937 | bellard | } |
91 | b8174937 | bellard | |
92 | c227f099 | Anthony Liguori | static void cs_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val) |
93 | b8174937 | bellard | { |
94 | b8174937 | bellard | CSState *s = opaque; |
95 | b8174937 | bellard | uint32_t saddr; |
96 | b8174937 | bellard | |
97 | e64d7d59 | blueswir1 | saddr = addr >> 2;
|
98 | b8174937 | bellard | DPRINTF("write reg[%d]: 0x%8.8x -> 0x%8.8x\n", saddr, s->regs[saddr], val);
|
99 | b8174937 | bellard | switch (saddr) {
|
100 | b8174937 | bellard | case 1: |
101 | 77f193da | blueswir1 | DPRINTF("write dreg[%d]: 0x%2.2x -> 0x%2.2x\n", CS_RAP(s),
|
102 | 77f193da | blueswir1 | s->dregs[CS_RAP(s)], val); |
103 | b8174937 | bellard | switch(CS_RAP(s)) {
|
104 | b8174937 | bellard | case 11: |
105 | b8174937 | bellard | case 25: // Read only |
106 | b8174937 | bellard | break;
|
107 | b8174937 | bellard | case 12: |
108 | b8174937 | bellard | val &= 0x40;
|
109 | b8174937 | bellard | val |= CS_CDC_VER; // Codec version
|
110 | b8174937 | bellard | s->dregs[CS_RAP(s)] = val; |
111 | b8174937 | bellard | break;
|
112 | b8174937 | bellard | default:
|
113 | b8174937 | bellard | s->dregs[CS_RAP(s)] = val; |
114 | b8174937 | bellard | break;
|
115 | b8174937 | bellard | } |
116 | b8174937 | bellard | break;
|
117 | b8174937 | bellard | case 2: // Read only |
118 | b8174937 | bellard | break;
|
119 | b8174937 | bellard | case 4: |
120 | 82d4c6e6 | Blue Swirl | if (val & 1) { |
121 | 82d4c6e6 | Blue Swirl | cs_reset(&s->busdev.qdev); |
122 | 82d4c6e6 | Blue Swirl | } |
123 | b8174937 | bellard | val &= 0x7f;
|
124 | b8174937 | bellard | s->regs[saddr] = val; |
125 | b8174937 | bellard | break;
|
126 | b8174937 | bellard | default:
|
127 | b8174937 | bellard | s->regs[saddr] = val; |
128 | f930d07e | blueswir1 | break;
|
129 | b8174937 | bellard | } |
130 | b8174937 | bellard | } |
131 | b8174937 | bellard | |
132 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const cs_mem_read[3] = { |
133 | b8174937 | bellard | cs_mem_readl, |
134 | b8174937 | bellard | cs_mem_readl, |
135 | b8174937 | bellard | cs_mem_readl, |
136 | b8174937 | bellard | }; |
137 | b8174937 | bellard | |
138 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const cs_mem_write[3] = { |
139 | b8174937 | bellard | cs_mem_writel, |
140 | b8174937 | bellard | cs_mem_writel, |
141 | b8174937 | bellard | cs_mem_writel, |
142 | b8174937 | bellard | }; |
143 | b8174937 | bellard | |
144 | 82d4c6e6 | Blue Swirl | static const VMStateDescription vmstate_cs4231 = { |
145 | 82d4c6e6 | Blue Swirl | .name ="cs4231",
|
146 | 82d4c6e6 | Blue Swirl | .version_id = 1,
|
147 | 82d4c6e6 | Blue Swirl | .minimum_version_id = 1,
|
148 | 82d4c6e6 | Blue Swirl | .minimum_version_id_old = 1,
|
149 | 82d4c6e6 | Blue Swirl | .fields = (VMStateField []) { |
150 | 82d4c6e6 | Blue Swirl | VMSTATE_UINT32_ARRAY(regs, CSState, CS_REGS), |
151 | 82d4c6e6 | Blue Swirl | VMSTATE_UINT8_ARRAY(dregs, CSState, CS_DREGS), |
152 | 82d4c6e6 | Blue Swirl | VMSTATE_END_OF_LIST() |
153 | 82d4c6e6 | Blue Swirl | } |
154 | 82d4c6e6 | Blue Swirl | }; |
155 | b8174937 | bellard | |
156 | 81a322d4 | Gerd Hoffmann | static int cs4231_init1(SysBusDevice *dev) |
157 | b8174937 | bellard | { |
158 | fa28ec52 | Blue Swirl | int io;
|
159 | fa28ec52 | Blue Swirl | CSState *s = FROM_SYSBUS(CSState, dev); |
160 | b8174937 | bellard | |
161 | fa28ec52 | Blue Swirl | io = cpu_register_io_memory(cs_mem_read, cs_mem_write, s); |
162 | fa28ec52 | Blue Swirl | sysbus_init_mmio(dev, CS_SIZE, io); |
163 | fa28ec52 | Blue Swirl | sysbus_init_irq(dev, &s->irq); |
164 | b8174937 | bellard | |
165 | 81a322d4 | Gerd Hoffmann | return 0; |
166 | b8174937 | bellard | } |
167 | fa28ec52 | Blue Swirl | |
168 | fa28ec52 | Blue Swirl | static SysBusDeviceInfo cs4231_info = {
|
169 | fa28ec52 | Blue Swirl | .init = cs4231_init1, |
170 | fa28ec52 | Blue Swirl | .qdev.name = "SUNW,CS4231",
|
171 | fa28ec52 | Blue Swirl | .qdev.size = sizeof(CSState),
|
172 | 82d4c6e6 | Blue Swirl | .qdev.vmsd = &vmstate_cs4231, |
173 | 82d4c6e6 | Blue Swirl | .qdev.reset = cs_reset, |
174 | ee6847d1 | Gerd Hoffmann | .qdev.props = (Property[]) { |
175 | fa28ec52 | Blue Swirl | {.name = NULL}
|
176 | fa28ec52 | Blue Swirl | } |
177 | fa28ec52 | Blue Swirl | }; |
178 | fa28ec52 | Blue Swirl | |
179 | fa28ec52 | Blue Swirl | static void cs4231_register_devices(void) |
180 | fa28ec52 | Blue Swirl | { |
181 | fa28ec52 | Blue Swirl | sysbus_register_withprop(&cs4231_info); |
182 | fa28ec52 | Blue Swirl | } |
183 | fa28ec52 | Blue Swirl | |
184 | fa28ec52 | Blue Swirl | device_init(cs4231_register_devices) |