xref: /openbmc/qemu/hw/audio/intel-hda.h (revision b7639b7dd05de6d4f5ac2a30bb4a7a789286992f)
147b43a1fSPaolo Bonzini #ifndef HW_INTEL_HDA_H
247b43a1fSPaolo Bonzini #define HW_INTEL_HDA_H
347b43a1fSPaolo Bonzini 
4a27bd6c7SMarkus Armbruster #include "hw/qdev-core.h"
5db1015e9SEduardo Habkost #include "qom/object.h"
647b43a1fSPaolo Bonzini 
747b43a1fSPaolo Bonzini /* --------------------------------------------------------------------- */
847b43a1fSPaolo Bonzini /* hda bus                                                               */
947b43a1fSPaolo Bonzini 
1047b43a1fSPaolo Bonzini #define TYPE_HDA_CODEC_DEVICE "hda-codec"
11c821774aSEduardo Habkost OBJECT_DECLARE_TYPE(HDACodecDevice, HDACodecDeviceClass,
1230b5707cSEduardo Habkost                     HDA_CODEC_DEVICE)
1347b43a1fSPaolo Bonzini 
1447b43a1fSPaolo Bonzini #define TYPE_HDA_BUS "HDA"
158063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(HDACodecBus, HDA_BUS)
1647b43a1fSPaolo Bonzini 
1747b43a1fSPaolo Bonzini 
1847b43a1fSPaolo Bonzini typedef void (*hda_codec_response_func)(HDACodecDevice *dev,
1947b43a1fSPaolo Bonzini                                         bool solicited, uint32_t response);
2047b43a1fSPaolo Bonzini typedef bool (*hda_codec_xfer_func)(HDACodecDevice *dev,
2147b43a1fSPaolo Bonzini                                     uint32_t stnr, bool output,
2247b43a1fSPaolo Bonzini                                     uint8_t *buf, uint32_t len);
2347b43a1fSPaolo Bonzini 
2447b43a1fSPaolo Bonzini struct HDACodecBus {
2547b43a1fSPaolo Bonzini     BusState qbus;
2647b43a1fSPaolo Bonzini     uint32_t next_cad;
2747b43a1fSPaolo Bonzini     hda_codec_response_func response;
2847b43a1fSPaolo Bonzini     hda_codec_xfer_func xfer;
2947b43a1fSPaolo Bonzini };
3047b43a1fSPaolo Bonzini 
31db1015e9SEduardo Habkost struct HDACodecDeviceClass {
3247b43a1fSPaolo Bonzini     DeviceClass parent_class;
3347b43a1fSPaolo Bonzini 
34*b7639b7dSMartin Kletzander     void (*init)(HDACodecDevice *dev, Error **errp);
355eaa8e1eSZihan Yang     void (*exit)(HDACodecDevice *dev);
3647b43a1fSPaolo Bonzini     void (*command)(HDACodecDevice *dev, uint32_t nid, uint32_t data);
3747b43a1fSPaolo Bonzini     void (*stream)(HDACodecDevice *dev, uint32_t stnr, bool running, bool output);
38db1015e9SEduardo Habkost };
3947b43a1fSPaolo Bonzini 
4047b43a1fSPaolo Bonzini struct HDACodecDevice {
4147b43a1fSPaolo Bonzini     DeviceState         qdev;
4247b43a1fSPaolo Bonzini     uint32_t            cad;    /* codec address */
4347b43a1fSPaolo Bonzini };
4447b43a1fSPaolo Bonzini 
45ab809e84SAndreas Färber void hda_codec_bus_init(DeviceState *dev, HDACodecBus *bus, size_t bus_size,
4647b43a1fSPaolo Bonzini                         hda_codec_response_func response,
4747b43a1fSPaolo Bonzini                         hda_codec_xfer_func xfer);
4847b43a1fSPaolo Bonzini HDACodecDevice *hda_codec_find(HDACodecBus *bus, uint32_t cad);
4947b43a1fSPaolo Bonzini 
5047b43a1fSPaolo Bonzini void hda_codec_response(HDACodecDevice *dev, bool solicited, uint32_t response);
5147b43a1fSPaolo Bonzini bool hda_codec_xfer(HDACodecDevice *dev, uint32_t stnr, bool output,
5247b43a1fSPaolo Bonzini                     uint8_t *buf, uint32_t len);
5347b43a1fSPaolo Bonzini 
5447b43a1fSPaolo Bonzini /* --------------------------------------------------------------------- */
5547b43a1fSPaolo Bonzini 
5647b43a1fSPaolo Bonzini #define dprint(_dev, _level, _fmt, ...)                                 \
5747b43a1fSPaolo Bonzini     do {                                                                \
5847b43a1fSPaolo Bonzini         if (_dev->debug >= _level) {                                    \
5947b43a1fSPaolo Bonzini             fprintf(stderr, "%s: ", _dev->name);                        \
6047b43a1fSPaolo Bonzini             fprintf(stderr, _fmt, ## __VA_ARGS__);                      \
6147b43a1fSPaolo Bonzini         }                                                               \
6247b43a1fSPaolo Bonzini     } while (0)
6347b43a1fSPaolo Bonzini 
6447b43a1fSPaolo Bonzini /* --------------------------------------------------------------------- */
6547b43a1fSPaolo Bonzini 
6647b43a1fSPaolo Bonzini #endif
67