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