linux/include/sound/hdaudio_ext.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2#ifndef __SOUND_HDAUDIO_EXT_H
   3#define __SOUND_HDAUDIO_EXT_H
   4
   5#include <sound/hdaudio.h>
   6
   7/**
   8 * hdac_ext_bus: HDAC extended bus for extended HDA caps
   9 *
  10 * @bus: hdac bus
  11 * @num_streams: streams supported
  12 * @hlink_list: link list of HDA links
  13 * @lock: lock for link mgmt
  14 * @cmd_dma_state: state of cmd DMAs: CORB and RIRB
  15 */
  16struct hdac_ext_bus {
  17        struct hdac_bus bus;
  18        int num_streams;
  19        int idx;
  20
  21        struct list_head hlink_list;
  22
  23        struct mutex lock;
  24        bool cmd_dma_state;
  25};
  26
  27int snd_hdac_ext_bus_init(struct hdac_ext_bus *sbus, struct device *dev,
  28                      const struct hdac_bus_ops *ops,
  29                      const struct hdac_io_ops *io_ops);
  30
  31void snd_hdac_ext_bus_exit(struct hdac_ext_bus *sbus);
  32int snd_hdac_ext_bus_device_init(struct hdac_ext_bus *sbus, int addr);
  33void snd_hdac_ext_bus_device_exit(struct hdac_device *hdev);
  34void snd_hdac_ext_bus_device_remove(struct hdac_ext_bus *ebus);
  35
  36#define ebus_to_hbus(ebus)      (&(ebus)->bus)
  37#define hbus_to_ebus(_bus) \
  38        container_of(_bus, struct hdac_ext_bus, bus)
  39
  40#define HDA_CODEC_REV_EXT_ENTRY(_vid, _rev, _name, drv_data) \
  41        { .vendor_id = (_vid), .rev_id = (_rev), .name = (_name), \
  42          .api_version = HDA_DEV_ASOC, \
  43          .driver_data = (unsigned long)(drv_data) }
  44#define HDA_CODEC_EXT_ENTRY(_vid, _revid, _name, _drv_data) \
  45        HDA_CODEC_REV_EXT_ENTRY(_vid, _revid, _name, _drv_data)
  46
  47void snd_hdac_ext_bus_ppcap_enable(struct hdac_ext_bus *chip, bool enable);
  48void snd_hdac_ext_bus_ppcap_int_enable(struct hdac_ext_bus *chip, bool enable);
  49
  50void snd_hdac_ext_stream_spbcap_enable(struct hdac_ext_bus *chip,
  51                                 bool enable, int index);
  52
  53int snd_hdac_ext_bus_get_ml_capabilities(struct hdac_ext_bus *bus);
  54int snd_hdac_ext_bus_map_codec_to_link(struct hdac_ext_bus *bus, int addr);
  55struct hdac_ext_link *snd_hdac_ext_bus_get_link(struct hdac_ext_bus *bus,
  56                                                const char *codec_name);
  57
  58enum hdac_ext_stream_type {
  59        HDAC_EXT_STREAM_TYPE_COUPLED = 0,
  60        HDAC_EXT_STREAM_TYPE_HOST,
  61        HDAC_EXT_STREAM_TYPE_LINK
  62};
  63
  64/**
  65 * hdac_ext_stream: HDAC extended stream for extended HDA caps
  66 *
  67 * @hstream: hdac_stream
  68 * @pphc_addr: processing pipe host stream pointer
  69 * @pplc_addr: processing pipe link stream pointer
  70 * @spib_addr: software position in buffers stream pointer
  71 * @fifo_addr: software position Max fifos stream pointer
  72 * @dpibr_addr: DMA position in buffer resume pointer
  73 * @dpib: DMA position in buffer
  74 * @lpib: Linear position in buffer
  75 * @decoupled: stream host and link is decoupled
  76 * @link_locked: link is locked
  77 * @link_prepared: link is prepared
  78 * link_substream: link substream
  79 */
  80struct hdac_ext_stream {
  81        struct hdac_stream hstream;
  82
  83        void __iomem *pphc_addr;
  84        void __iomem *pplc_addr;
  85
  86        void __iomem *spib_addr;
  87        void __iomem *fifo_addr;
  88
  89        void __iomem *dpibr_addr;
  90
  91        u32 dpib;
  92        u32 lpib;
  93        bool decoupled:1;
  94        bool link_locked:1;
  95        bool link_prepared;
  96
  97        struct snd_pcm_substream *link_substream;
  98};
  99
 100#define hdac_stream(s)          (&(s)->hstream)
 101#define stream_to_hdac_ext_stream(s) \
 102        container_of(s, struct hdac_ext_stream, hstream)
 103
 104void snd_hdac_ext_stream_init(struct hdac_ext_bus *bus,
 105                                struct hdac_ext_stream *stream, int idx,
 106                                int direction, int tag);
 107int snd_hdac_ext_stream_init_all(struct hdac_ext_bus *ebus, int start_idx,
 108                int num_stream, int dir);
 109void snd_hdac_stream_free_all(struct hdac_ext_bus *ebus);
 110void snd_hdac_link_free_all(struct hdac_ext_bus *ebus);
 111struct hdac_ext_stream *snd_hdac_ext_stream_assign(struct hdac_ext_bus *bus,
 112                                           struct snd_pcm_substream *substream,
 113                                           int type);
 114void snd_hdac_ext_stream_release(struct hdac_ext_stream *azx_dev, int type);
 115void snd_hdac_ext_stream_decouple(struct hdac_ext_bus *bus,
 116                                struct hdac_ext_stream *azx_dev, bool decouple);
 117void snd_hdac_ext_stop_streams(struct hdac_ext_bus *sbus);
 118
 119int snd_hdac_ext_stream_set_spib(struct hdac_ext_bus *ebus,
 120                                 struct hdac_ext_stream *stream, u32 value);
 121int snd_hdac_ext_stream_get_spbmaxfifo(struct hdac_ext_bus *ebus,
 122                                 struct hdac_ext_stream *stream);
 123void snd_hdac_ext_stream_drsm_enable(struct hdac_ext_bus *ebus,
 124                                bool enable, int index);
 125int snd_hdac_ext_stream_set_dpibr(struct hdac_ext_bus *ebus,
 126                                struct hdac_ext_stream *stream, u32 value);
 127int snd_hdac_ext_stream_set_lpib(struct hdac_ext_stream *stream, u32 value);
 128
 129void snd_hdac_ext_link_stream_start(struct hdac_ext_stream *hstream);
 130void snd_hdac_ext_link_stream_clear(struct hdac_ext_stream *hstream);
 131void snd_hdac_ext_link_stream_reset(struct hdac_ext_stream *hstream);
 132int snd_hdac_ext_link_stream_setup(struct hdac_ext_stream *stream, int fmt);
 133
 134struct hdac_ext_link {
 135        struct hdac_bus *bus;
 136        int index;
 137        void __iomem *ml_addr; /* link output stream reg pointer */
 138        u32 lcaps;   /* link capablities */
 139        u16 lsdiid;  /* link sdi identifier */
 140
 141        int ref_count;
 142
 143        struct list_head list;
 144};
 145
 146int snd_hdac_ext_bus_link_power_up(struct hdac_ext_link *link);
 147int snd_hdac_ext_bus_link_power_down(struct hdac_ext_link *link);
 148int snd_hdac_ext_bus_link_power_up_all(struct hdac_ext_bus *ebus);
 149int snd_hdac_ext_bus_link_power_down_all(struct hdac_ext_bus *ebus);
 150void snd_hdac_ext_link_set_stream_id(struct hdac_ext_link *link,
 151                                 int stream);
 152void snd_hdac_ext_link_clear_stream_id(struct hdac_ext_link *link,
 153                                 int stream);
 154
 155int snd_hdac_ext_bus_link_get(struct hdac_ext_bus *ebus,
 156                                struct hdac_ext_link *link);
 157int snd_hdac_ext_bus_link_put(struct hdac_ext_bus *ebus,
 158                                struct hdac_ext_link *link);
 159
 160/* update register macro */
 161#define snd_hdac_updatel(addr, reg, mask, val)          \
 162        writel(((readl(addr + reg) & ~(mask)) | (val)), \
 163                addr + reg)
 164
 165#define snd_hdac_updatew(addr, reg, mask, val)          \
 166        writew(((readw(addr + reg) & ~(mask)) | (val)), \
 167                addr + reg)
 168
 169
 170struct hdac_ext_device;
 171
 172/* ops common to all codec drivers */
 173struct hdac_ext_codec_ops {
 174        int (*build_controls)(struct hdac_ext_device *dev);
 175        int (*init)(struct hdac_ext_device *dev);
 176        void (*free)(struct hdac_ext_device *dev);
 177};
 178
 179struct hda_dai_map {
 180        char *dai_name;
 181        hda_nid_t nid;
 182        u32     maxbps;
 183};
 184
 185#define HDA_MAX_NIDS 16
 186
 187/**
 188 * struct hdac_ext_device - HDAC Ext device
 189 *
 190 * @hdac: hdac core device
 191 * @nid_list - the dai map which matches the dai-name with the nid
 192 * @map_cur_idx - the idx in use in dai_map
 193 * @ops - the hda codec ops common to all codec drivers
 194 * @pvt_data - private data, for asoc contains asoc codec object
 195 */
 196struct hdac_ext_device {
 197        struct hdac_device hdev;
 198        struct hdac_ext_bus *ebus;
 199
 200        /* soc-dai to nid map */
 201        struct hda_dai_map nid_list[HDA_MAX_NIDS];
 202        unsigned int map_cur_idx;
 203
 204        /* codec ops */
 205        struct hdac_ext_codec_ops ops;
 206
 207        struct snd_card *card;
 208        void *scodec;
 209        void *private_data;
 210};
 211
 212struct hdac_ext_dma_params {
 213        u32 format;
 214        u8 stream_tag;
 215};
 216#define to_ehdac_device(dev) (container_of((dev), \
 217                                 struct hdac_ext_device, hdev))
 218/*
 219 * HD-audio codec base driver
 220 */
 221struct hdac_ext_driver {
 222        struct hdac_driver hdac;
 223
 224        int     (*probe)(struct hdac_ext_device *dev);
 225        int     (*remove)(struct hdac_ext_device *dev);
 226        void    (*shutdown)(struct hdac_ext_device *dev);
 227};
 228
 229int snd_hda_ext_driver_register(struct hdac_ext_driver *drv);
 230void snd_hda_ext_driver_unregister(struct hdac_ext_driver *drv);
 231
 232#define to_ehdac_driver(_drv) container_of(_drv, struct hdac_ext_driver, hdac)
 233
 234#endif /* __SOUND_HDAUDIO_EXT_H */
 235