xref: /openbmc/qemu/hw/audio/intel-hda.h (revision 53ba2eee)
1 #ifndef HW_INTEL_HDA_H
2 #define HW_INTEL_HDA_H
3 
4 #include "hw/qdev-core.h"
5 #include "qom/object.h"
6 
7 /* --------------------------------------------------------------------- */
8 /* hda bus                                                               */
9 
10 #define TYPE_HDA_CODEC_DEVICE "hda-codec"
11 OBJECT_DECLARE_TYPE(HDACodecDevice, HDACodecDeviceClass,
12                     HDA_CODEC_DEVICE)
13 
14 #define TYPE_HDA_BUS "HDA"
15 OBJECT_DECLARE_SIMPLE_TYPE(HDACodecBus, HDA_BUS)
16 
17 
18 typedef void (*hda_codec_response_func)(HDACodecDevice *dev,
19                                         bool solicited, uint32_t response);
20 typedef bool (*hda_codec_xfer_func)(HDACodecDevice *dev,
21                                     uint32_t stnr, bool output,
22                                     uint8_t *buf, uint32_t len);
23 
24 struct HDACodecBus {
25     BusState qbus;
26     uint32_t next_cad;
27     hda_codec_response_func response;
28     hda_codec_xfer_func xfer;
29 };
30 
31 struct HDACodecDeviceClass {
32     DeviceClass parent_class;
33 
34     int (*init)(HDACodecDevice *dev);
35     void (*exit)(HDACodecDevice *dev);
36     void (*command)(HDACodecDevice *dev, uint32_t nid, uint32_t data);
37     void (*stream)(HDACodecDevice *dev, uint32_t stnr, bool running, bool output);
38 };
39 
40 struct HDACodecDevice {
41     DeviceState         qdev;
42     uint32_t            cad;    /* codec address */
43 };
44 
45 void hda_codec_bus_init(DeviceState *dev, HDACodecBus *bus, size_t bus_size,
46                         hda_codec_response_func response,
47                         hda_codec_xfer_func xfer);
48 HDACodecDevice *hda_codec_find(HDACodecBus *bus, uint32_t cad);
49 
50 void hda_codec_response(HDACodecDevice *dev, bool solicited, uint32_t response);
51 bool hda_codec_xfer(HDACodecDevice *dev, uint32_t stnr, bool output,
52                     uint8_t *buf, uint32_t len);
53 
54 /* --------------------------------------------------------------------- */
55 
56 #define dprint(_dev, _level, _fmt, ...)                                 \
57     do {                                                                \
58         if (_dev->debug >= _level) {                                    \
59             fprintf(stderr, "%s: ", _dev->name);                        \
60             fprintf(stderr, _fmt, ## __VA_ARGS__);                      \
61         }                                                               \
62     } while (0)
63 
64 /* --------------------------------------------------------------------- */
65 
66 #endif
67