Statistics
| Branch: | Revision:

root / hw / cs4231.c @ 17786d52

History | View | Annotate | Download (4.4 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 97bf4851 Blue Swirl
#include "trace.h"
27 b8174937 bellard
28 b8174937 bellard
/*
29 b8174937 bellard
 * In addition to Crystal CS4231 there is a DMA controller on Sparc.
30 b8174937 bellard
 */
31 e64d7d59 blueswir1
#define CS_SIZE 0x40
32 b8174937 bellard
#define CS_REGS 16
33 b8174937 bellard
#define CS_DREGS 32
34 b8174937 bellard
#define CS_MAXDREG (CS_DREGS - 1)
35 b8174937 bellard
36 b8174937 bellard
typedef struct CSState {
37 fa28ec52 Blue Swirl
    SysBusDevice busdev;
38 fa28ec52 Blue Swirl
    qemu_irq irq;
39 b8174937 bellard
    uint32_t regs[CS_REGS];
40 b8174937 bellard
    uint8_t dregs[CS_DREGS];
41 b8174937 bellard
} CSState;
42 b8174937 bellard
43 b8174937 bellard
#define CS_RAP(s) ((s)->regs[0] & CS_MAXDREG)
44 b8174937 bellard
#define CS_VER 0xa0
45 b8174937 bellard
#define CS_CDC_VER 0x8a
46 b8174937 bellard
47 82d4c6e6 Blue Swirl
static void cs_reset(DeviceState *d)
48 b8174937 bellard
{
49 82d4c6e6 Blue Swirl
    CSState *s = container_of(d, CSState, busdev.qdev);
50 b8174937 bellard
51 b8174937 bellard
    memset(s->regs, 0, CS_REGS * 4);
52 b8174937 bellard
    memset(s->dregs, 0, CS_DREGS);
53 b8174937 bellard
    s->dregs[12] = CS_CDC_VER;
54 b8174937 bellard
    s->dregs[25] = CS_VER;
55 b8174937 bellard
}
56 b8174937 bellard
57 c227f099 Anthony Liguori
static uint32_t cs_mem_readl(void *opaque, target_phys_addr_t addr)
58 b8174937 bellard
{
59 b8174937 bellard
    CSState *s = opaque;
60 b8174937 bellard
    uint32_t saddr, ret;
61 b8174937 bellard
62 e64d7d59 blueswir1
    saddr = addr >> 2;
63 b8174937 bellard
    switch (saddr) {
64 b8174937 bellard
    case 1:
65 b8174937 bellard
        switch (CS_RAP(s)) {
66 b8174937 bellard
        case 3: // Write only
67 b8174937 bellard
            ret = 0;
68 b8174937 bellard
            break;
69 b8174937 bellard
        default:
70 b8174937 bellard
            ret = s->dregs[CS_RAP(s)];
71 b8174937 bellard
            break;
72 b8174937 bellard
        }
73 97bf4851 Blue Swirl
        trace_cs4231_mem_readl_dreg(CS_RAP(s), ret);
74 f930d07e blueswir1
        break;
75 b8174937 bellard
    default:
76 b8174937 bellard
        ret = s->regs[saddr];
77 97bf4851 Blue Swirl
        trace_cs4231_mem_readl_reg(saddr, ret);
78 f930d07e blueswir1
        break;
79 b8174937 bellard
    }
80 b8174937 bellard
    return ret;
81 b8174937 bellard
}
82 b8174937 bellard
83 c227f099 Anthony Liguori
static void cs_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
84 b8174937 bellard
{
85 b8174937 bellard
    CSState *s = opaque;
86 b8174937 bellard
    uint32_t saddr;
87 b8174937 bellard
88 e64d7d59 blueswir1
    saddr = addr >> 2;
89 97bf4851 Blue Swirl
    trace_cs4231_mem_writel_reg(saddr, s->regs[saddr], val);
90 b8174937 bellard
    switch (saddr) {
91 b8174937 bellard
    case 1:
92 97bf4851 Blue Swirl
        trace_cs4231_mem_writel_dreg(CS_RAP(s), s->dregs[CS_RAP(s)], val);
93 b8174937 bellard
        switch(CS_RAP(s)) {
94 b8174937 bellard
        case 11:
95 b8174937 bellard
        case 25: // Read only
96 b8174937 bellard
            break;
97 b8174937 bellard
        case 12:
98 b8174937 bellard
            val &= 0x40;
99 b8174937 bellard
            val |= CS_CDC_VER; // Codec version
100 b8174937 bellard
            s->dregs[CS_RAP(s)] = val;
101 b8174937 bellard
            break;
102 b8174937 bellard
        default:
103 b8174937 bellard
            s->dregs[CS_RAP(s)] = val;
104 b8174937 bellard
            break;
105 b8174937 bellard
        }
106 b8174937 bellard
        break;
107 b8174937 bellard
    case 2: // Read only
108 b8174937 bellard
        break;
109 b8174937 bellard
    case 4:
110 82d4c6e6 Blue Swirl
        if (val & 1) {
111 82d4c6e6 Blue Swirl
            cs_reset(&s->busdev.qdev);
112 82d4c6e6 Blue Swirl
        }
113 b8174937 bellard
        val &= 0x7f;
114 b8174937 bellard
        s->regs[saddr] = val;
115 b8174937 bellard
        break;
116 b8174937 bellard
    default:
117 b8174937 bellard
        s->regs[saddr] = val;
118 f930d07e blueswir1
        break;
119 b8174937 bellard
    }
120 b8174937 bellard
}
121 b8174937 bellard
122 d60efc6b Blue Swirl
static CPUReadMemoryFunc * const cs_mem_read[3] = {
123 b8174937 bellard
    cs_mem_readl,
124 b8174937 bellard
    cs_mem_readl,
125 b8174937 bellard
    cs_mem_readl,
126 b8174937 bellard
};
127 b8174937 bellard
128 d60efc6b Blue Swirl
static CPUWriteMemoryFunc * const cs_mem_write[3] = {
129 b8174937 bellard
    cs_mem_writel,
130 b8174937 bellard
    cs_mem_writel,
131 b8174937 bellard
    cs_mem_writel,
132 b8174937 bellard
};
133 b8174937 bellard
134 82d4c6e6 Blue Swirl
static const VMStateDescription vmstate_cs4231 = {
135 82d4c6e6 Blue Swirl
    .name ="cs4231",
136 82d4c6e6 Blue Swirl
    .version_id = 1,
137 82d4c6e6 Blue Swirl
    .minimum_version_id = 1,
138 82d4c6e6 Blue Swirl
    .minimum_version_id_old = 1,
139 82d4c6e6 Blue Swirl
    .fields      = (VMStateField []) {
140 82d4c6e6 Blue Swirl
        VMSTATE_UINT32_ARRAY(regs, CSState, CS_REGS),
141 82d4c6e6 Blue Swirl
        VMSTATE_UINT8_ARRAY(dregs, CSState, CS_DREGS),
142 82d4c6e6 Blue Swirl
        VMSTATE_END_OF_LIST()
143 82d4c6e6 Blue Swirl
    }
144 82d4c6e6 Blue Swirl
};
145 b8174937 bellard
146 81a322d4 Gerd Hoffmann
static int cs4231_init1(SysBusDevice *dev)
147 b8174937 bellard
{
148 fa28ec52 Blue Swirl
    int io;
149 fa28ec52 Blue Swirl
    CSState *s = FROM_SYSBUS(CSState, dev);
150 b8174937 bellard
151 fa28ec52 Blue Swirl
    io = cpu_register_io_memory(cs_mem_read, cs_mem_write, s);
152 fa28ec52 Blue Swirl
    sysbus_init_mmio(dev, CS_SIZE, io);
153 fa28ec52 Blue Swirl
    sysbus_init_irq(dev, &s->irq);
154 b8174937 bellard
155 81a322d4 Gerd Hoffmann
    return 0;
156 b8174937 bellard
}
157 fa28ec52 Blue Swirl
158 fa28ec52 Blue Swirl
static SysBusDeviceInfo cs4231_info = {
159 fa28ec52 Blue Swirl
    .init = cs4231_init1,
160 fa28ec52 Blue Swirl
    .qdev.name  = "SUNW,CS4231",
161 fa28ec52 Blue Swirl
    .qdev.size  = sizeof(CSState),
162 82d4c6e6 Blue Swirl
    .qdev.vmsd  = &vmstate_cs4231,
163 82d4c6e6 Blue Swirl
    .qdev.reset = cs_reset,
164 ee6847d1 Gerd Hoffmann
    .qdev.props = (Property[]) {
165 fa28ec52 Blue Swirl
        {.name = NULL}
166 fa28ec52 Blue Swirl
    }
167 fa28ec52 Blue Swirl
};
168 fa28ec52 Blue Swirl
169 fa28ec52 Blue Swirl
static void cs4231_register_devices(void)
170 fa28ec52 Blue Swirl
{
171 fa28ec52 Blue Swirl
    sysbus_register_withprop(&cs4231_info);
172 fa28ec52 Blue Swirl
}
173 fa28ec52 Blue Swirl
174 fa28ec52 Blue Swirl
device_init(cs4231_register_devices)