1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2e3d280fcSTakashi Iwai /* 3e3d280fcSTakashi Iwai * HD-audio core stuff 4e3d280fcSTakashi Iwai */ 5e3d280fcSTakashi Iwai 6e3d280fcSTakashi Iwai #ifndef __SOUND_HDAUDIO_H 7e3d280fcSTakashi Iwai #define __SOUND_HDAUDIO_H 8e3d280fcSTakashi Iwai 9e3d280fcSTakashi Iwai #include <linux/device.h> 1014752412STakashi Iwai #include <linux/interrupt.h> 1114752412STakashi Iwai #include <linux/timecounter.h> 1214752412STakashi Iwai #include <sound/core.h> 1314752412STakashi Iwai #include <sound/memalloc.h> 14d068ebc2STakashi Iwai #include <sound/hda_verbs.h> 1598d8fc6cSMengdong Lin #include <drm/i915_component.h> 16d068ebc2STakashi Iwai 177639a06cSTakashi Iwai /* codec node id */ 187639a06cSTakashi Iwai typedef u16 hda_nid_t; 197639a06cSTakashi Iwai 20d068ebc2STakashi Iwai struct hdac_bus; 2114752412STakashi Iwai struct hdac_stream; 22d068ebc2STakashi Iwai struct hdac_device; 23d068ebc2STakashi Iwai struct hdac_driver; 243256be65STakashi Iwai struct hdac_widget_tree; 25da23ac1eSSubhransu S. Prusty struct hda_device_id; 26e3d280fcSTakashi Iwai 27e3d280fcSTakashi Iwai /* 28e3d280fcSTakashi Iwai * exported bus type 29e3d280fcSTakashi Iwai */ 30e3d280fcSTakashi Iwai extern struct bus_type snd_hda_bus_type; 31e3d280fcSTakashi Iwai 32e3d280fcSTakashi Iwai /* 3371fc4c7eSTakashi Iwai * generic arrays 3471fc4c7eSTakashi Iwai */ 3571fc4c7eSTakashi Iwai struct snd_array { 3671fc4c7eSTakashi Iwai unsigned int used; 3771fc4c7eSTakashi Iwai unsigned int alloced; 3871fc4c7eSTakashi Iwai unsigned int elem_size; 3971fc4c7eSTakashi Iwai unsigned int alloc_align; 4071fc4c7eSTakashi Iwai void *list; 4171fc4c7eSTakashi Iwai }; 4271fc4c7eSTakashi Iwai 4371fc4c7eSTakashi Iwai /* 44e3d280fcSTakashi Iwai * HD-audio codec base device 45e3d280fcSTakashi Iwai */ 46e3d280fcSTakashi Iwai struct hdac_device { 47e3d280fcSTakashi Iwai struct device dev; 48e3d280fcSTakashi Iwai int type; 49d068ebc2STakashi Iwai struct hdac_bus *bus; 50d068ebc2STakashi Iwai unsigned int addr; /* codec address */ 51d068ebc2STakashi Iwai struct list_head list; /* list point for bus codec_list */ 527639a06cSTakashi Iwai 537639a06cSTakashi Iwai hda_nid_t afg; /* AFG node id */ 547639a06cSTakashi Iwai hda_nid_t mfg; /* MFG node id */ 557639a06cSTakashi Iwai 567639a06cSTakashi Iwai /* ids */ 577639a06cSTakashi Iwai unsigned int vendor_id; 587639a06cSTakashi Iwai unsigned int subsystem_id; 597639a06cSTakashi Iwai unsigned int revision_id; 607639a06cSTakashi Iwai unsigned int afg_function_id; 617639a06cSTakashi Iwai unsigned int mfg_function_id; 627639a06cSTakashi Iwai unsigned int afg_unsol:1; 637639a06cSTakashi Iwai unsigned int mfg_unsol:1; 647639a06cSTakashi Iwai 657639a06cSTakashi Iwai unsigned int power_caps; /* FG power caps */ 667639a06cSTakashi Iwai 677639a06cSTakashi Iwai const char *vendor_name; /* codec vendor name */ 687639a06cSTakashi Iwai const char *chip_name; /* codec chip name */ 697639a06cSTakashi Iwai 7005852448STakashi Iwai /* verb exec op override */ 7105852448STakashi Iwai int (*exec_verb)(struct hdac_device *dev, unsigned int cmd, 7205852448STakashi Iwai unsigned int flags, unsigned int *res); 7305852448STakashi Iwai 747639a06cSTakashi Iwai /* widgets */ 757639a06cSTakashi Iwai unsigned int num_nodes; 767639a06cSTakashi Iwai hda_nid_t start_nid, end_nid; 777639a06cSTakashi Iwai 787639a06cSTakashi Iwai /* misc flags */ 797639a06cSTakashi Iwai atomic_t in_pm; /* suspend/resume being performed */ 80a5e7e07cSMengdong Lin bool link_power_control:1; 813256be65STakashi Iwai 823256be65STakashi Iwai /* sysfs */ 833256be65STakashi Iwai struct hdac_widget_tree *widgets; 844d75faa0STakashi Iwai 854d75faa0STakashi Iwai /* regmap */ 864d75faa0STakashi Iwai struct regmap *regmap; 875e56bceaSTakashi Iwai struct snd_array vendor_verbs; 884d75faa0STakashi Iwai bool lazy_cache:1; /* don't wake up for writes */ 89faa75f8aSTakashi Iwai bool caps_overwriting:1; /* caps overwrite being in process */ 9040ba66a7STakashi Iwai bool cache_coef:1; /* cache COEF read/write too */ 91e3d280fcSTakashi Iwai }; 92e3d280fcSTakashi Iwai 93e3d280fcSTakashi Iwai /* device/driver type used for matching */ 94e3d280fcSTakashi Iwai enum { 95e3d280fcSTakashi Iwai HDA_DEV_CORE, 96e3d280fcSTakashi Iwai HDA_DEV_LEGACY, 97c1cc18b1SRamesh Babu HDA_DEV_ASOC, 98e3d280fcSTakashi Iwai }; 99e3d280fcSTakashi Iwai 1007639a06cSTakashi Iwai /* direction */ 1017639a06cSTakashi Iwai enum { 1027639a06cSTakashi Iwai HDA_INPUT, HDA_OUTPUT 1037639a06cSTakashi Iwai }; 1047639a06cSTakashi Iwai 105e3d280fcSTakashi Iwai #define dev_to_hdac_dev(_dev) container_of(_dev, struct hdac_device, dev) 106e3d280fcSTakashi Iwai 1077639a06cSTakashi Iwai int snd_hdac_device_init(struct hdac_device *dev, struct hdac_bus *bus, 1087639a06cSTakashi Iwai const char *name, unsigned int addr); 1097639a06cSTakashi Iwai void snd_hdac_device_exit(struct hdac_device *dev); 1103256be65STakashi Iwai int snd_hdac_device_register(struct hdac_device *codec); 1113256be65STakashi Iwai void snd_hdac_device_unregister(struct hdac_device *codec); 112ded255beSTakashi Iwai int snd_hdac_device_set_chip_name(struct hdac_device *codec, const char *name); 1134f9e0c38STakashi Iwai int snd_hdac_codec_modalias(struct hdac_device *hdac, char *buf, size_t size); 1147639a06cSTakashi Iwai 1159780ded3STakashi Iwai int snd_hdac_refresh_widgets(struct hdac_device *codec, bool sysfs); 1167639a06cSTakashi Iwai 1177639a06cSTakashi Iwai unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid, 1187639a06cSTakashi Iwai unsigned int verb, unsigned int parm); 11905852448STakashi Iwai int snd_hdac_exec_verb(struct hdac_device *codec, unsigned int cmd, 12005852448STakashi Iwai unsigned int flags, unsigned int *res); 1217639a06cSTakashi Iwai int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid, 1227639a06cSTakashi Iwai unsigned int verb, unsigned int parm, unsigned int *res); 12301ed3c06STakashi Iwai int _snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm, 12401ed3c06STakashi Iwai unsigned int *res); 1259ba17b4dSTakashi Iwai int snd_hdac_read_parm_uncached(struct hdac_device *codec, hda_nid_t nid, 1269ba17b4dSTakashi Iwai int parm); 127faa75f8aSTakashi Iwai int snd_hdac_override_parm(struct hdac_device *codec, hda_nid_t nid, 128faa75f8aSTakashi Iwai unsigned int parm, unsigned int val); 1297639a06cSTakashi Iwai int snd_hdac_get_connections(struct hdac_device *codec, hda_nid_t nid, 1307639a06cSTakashi Iwai hda_nid_t *conn_list, int max_conns); 1317639a06cSTakashi Iwai int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid, 1327639a06cSTakashi Iwai hda_nid_t *start_id); 133b7d023e1STakashi Iwai unsigned int snd_hdac_calc_stream_format(unsigned int rate, 134b7d023e1STakashi Iwai unsigned int channels, 135b7d023e1STakashi Iwai unsigned int format, 136b7d023e1STakashi Iwai unsigned int maxbps, 137b7d023e1STakashi Iwai unsigned short spdif_ctls); 138b7d023e1STakashi Iwai int snd_hdac_query_supported_pcm(struct hdac_device *codec, hda_nid_t nid, 139b7d023e1STakashi Iwai u32 *ratesp, u64 *formatsp, unsigned int *bpsp); 140b7d023e1STakashi Iwai bool snd_hdac_is_supported_format(struct hdac_device *codec, hda_nid_t nid, 141b7d023e1STakashi Iwai unsigned int format); 1427639a06cSTakashi Iwai 1431b5e6167SSubhransu S. Prusty int snd_hdac_codec_read(struct hdac_device *hdac, hda_nid_t nid, 1441b5e6167SSubhransu S. Prusty int flags, unsigned int verb, unsigned int parm); 1451b5e6167SSubhransu S. Prusty int snd_hdac_codec_write(struct hdac_device *hdac, hda_nid_t nid, 1461b5e6167SSubhransu S. Prusty int flags, unsigned int verb, unsigned int parm); 1471b5e6167SSubhransu S. Prusty bool snd_hdac_check_power_state(struct hdac_device *hdac, 1481b5e6167SSubhransu S. Prusty hda_nid_t nid, unsigned int target_state); 149*09787492SAbhijeet Kumar unsigned int snd_hdac_sync_power_state(struct hdac_device *hdac, 150*09787492SAbhijeet Kumar hda_nid_t nid, unsigned int target_state); 15101ed3c06STakashi Iwai /** 15201ed3c06STakashi Iwai * snd_hdac_read_parm - read a codec parameter 15301ed3c06STakashi Iwai * @codec: the codec object 15401ed3c06STakashi Iwai * @nid: NID to read a parameter 15501ed3c06STakashi Iwai * @parm: parameter to read 15601ed3c06STakashi Iwai * 15701ed3c06STakashi Iwai * Returns -1 for error. If you need to distinguish the error more 15801ed3c06STakashi Iwai * strictly, use _snd_hdac_read_parm() directly. 15901ed3c06STakashi Iwai */ 16001ed3c06STakashi Iwai static inline int snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, 16101ed3c06STakashi Iwai int parm) 16201ed3c06STakashi Iwai { 16301ed3c06STakashi Iwai unsigned int val; 16401ed3c06STakashi Iwai 16501ed3c06STakashi Iwai return _snd_hdac_read_parm(codec, nid, parm, &val) < 0 ? -1 : val; 16601ed3c06STakashi Iwai } 16701ed3c06STakashi Iwai 1687639a06cSTakashi Iwai #ifdef CONFIG_PM 169fbce23a0STakashi Iwai int snd_hdac_power_up(struct hdac_device *codec); 170fbce23a0STakashi Iwai int snd_hdac_power_down(struct hdac_device *codec); 171fbce23a0STakashi Iwai int snd_hdac_power_up_pm(struct hdac_device *codec); 172fbce23a0STakashi Iwai int snd_hdac_power_down_pm(struct hdac_device *codec); 173fc4f000bSTakashi Iwai int snd_hdac_keep_power_up(struct hdac_device *codec); 1747639a06cSTakashi Iwai #else 175fbce23a0STakashi Iwai static inline int snd_hdac_power_up(struct hdac_device *codec) { return 0; } 176fbce23a0STakashi Iwai static inline int snd_hdac_power_down(struct hdac_device *codec) { return 0; } 177fbce23a0STakashi Iwai static inline int snd_hdac_power_up_pm(struct hdac_device *codec) { return 0; } 178fbce23a0STakashi Iwai static inline int snd_hdac_power_down_pm(struct hdac_device *codec) { return 0; } 179fc4f000bSTakashi Iwai static inline int snd_hdac_keep_power_up(struct hdac_device *codec) { return 0; } 1807639a06cSTakashi Iwai #endif 1817639a06cSTakashi Iwai 182e3d280fcSTakashi Iwai /* 183e3d280fcSTakashi Iwai * HD-audio codec base driver 184e3d280fcSTakashi Iwai */ 185e3d280fcSTakashi Iwai struct hdac_driver { 186e3d280fcSTakashi Iwai struct device_driver driver; 187e3d280fcSTakashi Iwai int type; 188ec71efc9SVinod Koul const struct hda_device_id *id_table; 189e3d280fcSTakashi Iwai int (*match)(struct hdac_device *dev, struct hdac_driver *drv); 190d068ebc2STakashi Iwai void (*unsol_event)(struct hdac_device *dev, unsigned int event); 191e3d280fcSTakashi Iwai }; 192e3d280fcSTakashi Iwai 193e3d280fcSTakashi Iwai #define drv_to_hdac_driver(_drv) container_of(_drv, struct hdac_driver, driver) 194e3d280fcSTakashi Iwai 195ec71efc9SVinod Koul const struct hda_device_id * 196ec71efc9SVinod Koul hdac_get_device_id(struct hdac_device *hdev, struct hdac_driver *drv); 197ec71efc9SVinod Koul 198d068ebc2STakashi Iwai /* 19914752412STakashi Iwai * Bus verb operators 200d068ebc2STakashi Iwai */ 201d068ebc2STakashi Iwai struct hdac_bus_ops { 202d068ebc2STakashi Iwai /* send a single command */ 203d068ebc2STakashi Iwai int (*command)(struct hdac_bus *bus, unsigned int cmd); 204d068ebc2STakashi Iwai /* get a response from the last command */ 205d068ebc2STakashi Iwai int (*get_response)(struct hdac_bus *bus, unsigned int addr, 206d068ebc2STakashi Iwai unsigned int *res); 207a5e7e07cSMengdong Lin /* control the link power */ 208a5e7e07cSMengdong Lin int (*link_power)(struct hdac_bus *bus, bool enable); 209d068ebc2STakashi Iwai }; 210d068ebc2STakashi Iwai 21114752412STakashi Iwai /* 21214752412STakashi Iwai * Lowlevel I/O operators 21314752412STakashi Iwai */ 21414752412STakashi Iwai struct hdac_io_ops { 21514752412STakashi Iwai /* mapped register accesses */ 21614752412STakashi Iwai void (*reg_writel)(u32 value, u32 __iomem *addr); 21714752412STakashi Iwai u32 (*reg_readl)(u32 __iomem *addr); 21814752412STakashi Iwai void (*reg_writew)(u16 value, u16 __iomem *addr); 21914752412STakashi Iwai u16 (*reg_readw)(u16 __iomem *addr); 22014752412STakashi Iwai void (*reg_writeb)(u8 value, u8 __iomem *addr); 22114752412STakashi Iwai u8 (*reg_readb)(u8 __iomem *addr); 2228f3f600bSTakashi Iwai /* Allocation ops */ 2238f3f600bSTakashi Iwai int (*dma_alloc_pages)(struct hdac_bus *bus, int type, size_t size, 2248f3f600bSTakashi Iwai struct snd_dma_buffer *buf); 2258f3f600bSTakashi Iwai void (*dma_free_pages)(struct hdac_bus *bus, 2268f3f600bSTakashi Iwai struct snd_dma_buffer *buf); 22714752412STakashi Iwai }; 228d068ebc2STakashi Iwai 22914752412STakashi Iwai #define HDA_UNSOL_QUEUE_SIZE 64 23014752412STakashi Iwai #define HDA_MAX_CODECS 8 /* limit by controller side */ 23114752412STakashi Iwai 23214752412STakashi Iwai /* HD Audio class code */ 23314752412STakashi Iwai #define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403 23414752412STakashi Iwai 23514752412STakashi Iwai /* 23614752412STakashi Iwai * CORB/RIRB 23714752412STakashi Iwai * 23814752412STakashi Iwai * Each CORB entry is 4byte, RIRB is 8byte 23914752412STakashi Iwai */ 24014752412STakashi Iwai struct hdac_rb { 24114752412STakashi Iwai __le32 *buf; /* virtual address of CORB/RIRB buffer */ 24214752412STakashi Iwai dma_addr_t addr; /* physical address of CORB/RIRB buffer */ 24314752412STakashi Iwai unsigned short rp, wp; /* RIRB read/write pointers */ 24414752412STakashi Iwai int cmds[HDA_MAX_CODECS]; /* number of pending requests */ 24514752412STakashi Iwai u32 res[HDA_MAX_CODECS]; /* last read value */ 24614752412STakashi Iwai }; 24714752412STakashi Iwai 24814752412STakashi Iwai /* 24914752412STakashi Iwai * HD-audio bus base driver 2506720b384SVinod Koul * 2516720b384SVinod Koul * @ppcap: pp capabilities pointer 2526720b384SVinod Koul * @spbcap: SPIB capabilities pointer 2536720b384SVinod Koul * @mlcap: MultiLink capabilities pointer 2546720b384SVinod Koul * @gtscap: gts capabilities pointer 2556720b384SVinod Koul * @drsmcap: dma resume capabilities pointer 25614752412STakashi Iwai */ 257d068ebc2STakashi Iwai struct hdac_bus { 258d068ebc2STakashi Iwai struct device *dev; 259d068ebc2STakashi Iwai const struct hdac_bus_ops *ops; 26014752412STakashi Iwai const struct hdac_io_ops *io_ops; 26114752412STakashi Iwai 26214752412STakashi Iwai /* h/w resources */ 26314752412STakashi Iwai unsigned long addr; 26414752412STakashi Iwai void __iomem *remap_addr; 26514752412STakashi Iwai int irq; 266d068ebc2STakashi Iwai 2676720b384SVinod Koul void __iomem *ppcap; 2686720b384SVinod Koul void __iomem *spbcap; 2696720b384SVinod Koul void __iomem *mlcap; 2706720b384SVinod Koul void __iomem *gtscap; 2716720b384SVinod Koul void __iomem *drsmcap; 2726720b384SVinod Koul 273d068ebc2STakashi Iwai /* codec linked list */ 274d068ebc2STakashi Iwai struct list_head codec_list; 275d068ebc2STakashi Iwai unsigned int num_codecs; 276d068ebc2STakashi Iwai 277d068ebc2STakashi Iwai /* link caddr -> codec */ 278d068ebc2STakashi Iwai struct hdac_device *caddr_tbl[HDA_MAX_CODEC_ADDRESS + 1]; 279d068ebc2STakashi Iwai 280d068ebc2STakashi Iwai /* unsolicited event queue */ 281d068ebc2STakashi Iwai u32 unsol_queue[HDA_UNSOL_QUEUE_SIZE * 2]; /* ring buffer */ 282d068ebc2STakashi Iwai unsigned int unsol_rp, unsol_wp; 283d068ebc2STakashi Iwai struct work_struct unsol_work; 284d068ebc2STakashi Iwai 28514752412STakashi Iwai /* bit flags of detected codecs */ 28614752412STakashi Iwai unsigned long codec_mask; 28714752412STakashi Iwai 288d068ebc2STakashi Iwai /* bit flags of powered codecs */ 289d068ebc2STakashi Iwai unsigned long codec_powered; 290d068ebc2STakashi Iwai 29114752412STakashi Iwai /* CORB/RIRB */ 29214752412STakashi Iwai struct hdac_rb corb; 29314752412STakashi Iwai struct hdac_rb rirb; 29414752412STakashi Iwai unsigned int last_cmd[HDA_MAX_CODECS]; /* last sent command */ 29514752412STakashi Iwai 29614752412STakashi Iwai /* CORB/RIRB and position buffers */ 29714752412STakashi Iwai struct snd_dma_buffer rb; 29814752412STakashi Iwai struct snd_dma_buffer posbuf; 29914752412STakashi Iwai 30014752412STakashi Iwai /* hdac_stream linked list */ 30114752412STakashi Iwai struct list_head stream_list; 30214752412STakashi Iwai 30314752412STakashi Iwai /* operation state */ 30414752412STakashi Iwai bool chip_init:1; /* h/w initialized */ 30514752412STakashi Iwai 30614752412STakashi Iwai /* behavior flags */ 307d068ebc2STakashi Iwai bool sync_write:1; /* sync after verb write */ 30814752412STakashi Iwai bool use_posbuf:1; /* use position buffer */ 30914752412STakashi Iwai bool snoop:1; /* enable snooping */ 31014752412STakashi Iwai bool align_bdle_4k:1; /* BDLE align 4K boundary */ 31114752412STakashi Iwai bool reverse_assign:1; /* assign devices in reverse order */ 31214752412STakashi Iwai bool corbrp_self_clear:1; /* CORBRP clears itself after reset */ 31314752412STakashi Iwai 31414752412STakashi Iwai int bdl_pos_adj; /* BDL position adjustment */ 315d068ebc2STakashi Iwai 316d068ebc2STakashi Iwai /* locks */ 31714752412STakashi Iwai spinlock_t reg_lock; 318d068ebc2STakashi Iwai struct mutex cmd_mutex; 31998d8fc6cSMengdong Lin 32098d8fc6cSMengdong Lin /* i915 component interface */ 32198d8fc6cSMengdong Lin struct i915_audio_component *audio_component; 32298d8fc6cSMengdong Lin int i915_power_refcount; 323d068ebc2STakashi Iwai }; 324d068ebc2STakashi Iwai 325d068ebc2STakashi Iwai int snd_hdac_bus_init(struct hdac_bus *bus, struct device *dev, 32614752412STakashi Iwai const struct hdac_bus_ops *ops, 32714752412STakashi Iwai const struct hdac_io_ops *io_ops); 328d068ebc2STakashi Iwai void snd_hdac_bus_exit(struct hdac_bus *bus); 329d068ebc2STakashi Iwai int snd_hdac_bus_exec_verb(struct hdac_bus *bus, unsigned int addr, 330d068ebc2STakashi Iwai unsigned int cmd, unsigned int *res); 331d068ebc2STakashi Iwai int snd_hdac_bus_exec_verb_unlocked(struct hdac_bus *bus, unsigned int addr, 332d068ebc2STakashi Iwai unsigned int cmd, unsigned int *res); 333d068ebc2STakashi Iwai void snd_hdac_bus_queue_event(struct hdac_bus *bus, u32 res, u32 res_ex); 334d068ebc2STakashi Iwai 335d068ebc2STakashi Iwai int snd_hdac_bus_add_device(struct hdac_bus *bus, struct hdac_device *codec); 336d068ebc2STakashi Iwai void snd_hdac_bus_remove_device(struct hdac_bus *bus, 337d068ebc2STakashi Iwai struct hdac_device *codec); 338d068ebc2STakashi Iwai 3397639a06cSTakashi Iwai static inline void snd_hdac_codec_link_up(struct hdac_device *codec) 3407639a06cSTakashi Iwai { 3417639a06cSTakashi Iwai set_bit(codec->addr, &codec->bus->codec_powered); 3427639a06cSTakashi Iwai } 3437639a06cSTakashi Iwai 3447639a06cSTakashi Iwai static inline void snd_hdac_codec_link_down(struct hdac_device *codec) 3457639a06cSTakashi Iwai { 3467639a06cSTakashi Iwai clear_bit(codec->addr, &codec->bus->codec_powered); 3477639a06cSTakashi Iwai } 3487639a06cSTakashi Iwai 34914752412STakashi Iwai int snd_hdac_bus_send_cmd(struct hdac_bus *bus, unsigned int val); 35014752412STakashi Iwai int snd_hdac_bus_get_response(struct hdac_bus *bus, unsigned int addr, 35114752412STakashi Iwai unsigned int *res); 3526720b384SVinod Koul int snd_hdac_bus_parse_capabilities(struct hdac_bus *bus); 353a5e7e07cSMengdong Lin int snd_hdac_link_power(struct hdac_device *codec, bool enable); 35414752412STakashi Iwai 35514752412STakashi Iwai bool snd_hdac_bus_init_chip(struct hdac_bus *bus, bool full_reset); 35614752412STakashi Iwai void snd_hdac_bus_stop_chip(struct hdac_bus *bus); 35714752412STakashi Iwai void snd_hdac_bus_init_cmd_io(struct hdac_bus *bus); 35814752412STakashi Iwai void snd_hdac_bus_stop_cmd_io(struct hdac_bus *bus); 35914752412STakashi Iwai void snd_hdac_bus_enter_link_reset(struct hdac_bus *bus); 36014752412STakashi Iwai void snd_hdac_bus_exit_link_reset(struct hdac_bus *bus); 36114752412STakashi Iwai 36214752412STakashi Iwai void snd_hdac_bus_update_rirb(struct hdac_bus *bus); 363473f4145STakashi Iwai int snd_hdac_bus_handle_stream_irq(struct hdac_bus *bus, unsigned int status, 36414752412STakashi Iwai void (*ack)(struct hdac_bus *, 36514752412STakashi Iwai struct hdac_stream *)); 36614752412STakashi Iwai 367304dad30SJeeja KP int snd_hdac_bus_alloc_stream_pages(struct hdac_bus *bus); 368304dad30SJeeja KP void snd_hdac_bus_free_stream_pages(struct hdac_bus *bus); 369304dad30SJeeja KP 37014752412STakashi Iwai /* 37114752412STakashi Iwai * macros for easy use 37214752412STakashi Iwai */ 3732c1f8138STakashi Iwai #define _snd_hdac_chip_writeb(chip, reg, value) \ 3742c1f8138STakashi Iwai ((chip)->io_ops->reg_writeb(value, (chip)->remap_addr + (reg))) 3752c1f8138STakashi Iwai #define _snd_hdac_chip_readb(chip, reg) \ 3762c1f8138STakashi Iwai ((chip)->io_ops->reg_readb((chip)->remap_addr + (reg))) 3772c1f8138STakashi Iwai #define _snd_hdac_chip_writew(chip, reg, value) \ 3782c1f8138STakashi Iwai ((chip)->io_ops->reg_writew(value, (chip)->remap_addr + (reg))) 3792c1f8138STakashi Iwai #define _snd_hdac_chip_readw(chip, reg) \ 3802c1f8138STakashi Iwai ((chip)->io_ops->reg_readw((chip)->remap_addr + (reg))) 3812c1f8138STakashi Iwai #define _snd_hdac_chip_writel(chip, reg, value) \ 3822c1f8138STakashi Iwai ((chip)->io_ops->reg_writel(value, (chip)->remap_addr + (reg))) 3832c1f8138STakashi Iwai #define _snd_hdac_chip_readl(chip, reg) \ 3842c1f8138STakashi Iwai ((chip)->io_ops->reg_readl((chip)->remap_addr + (reg))) 38514752412STakashi Iwai 38614752412STakashi Iwai /* read/write a register, pass without AZX_REG_ prefix */ 38714752412STakashi Iwai #define snd_hdac_chip_writel(chip, reg, value) \ 3882c1f8138STakashi Iwai _snd_hdac_chip_writel(chip, AZX_REG_ ## reg, value) 38914752412STakashi Iwai #define snd_hdac_chip_writew(chip, reg, value) \ 3902c1f8138STakashi Iwai _snd_hdac_chip_writew(chip, AZX_REG_ ## reg, value) 39114752412STakashi Iwai #define snd_hdac_chip_writeb(chip, reg, value) \ 3922c1f8138STakashi Iwai _snd_hdac_chip_writeb(chip, AZX_REG_ ## reg, value) 39314752412STakashi Iwai #define snd_hdac_chip_readl(chip, reg) \ 3942c1f8138STakashi Iwai _snd_hdac_chip_readl(chip, AZX_REG_ ## reg) 39514752412STakashi Iwai #define snd_hdac_chip_readw(chip, reg) \ 3962c1f8138STakashi Iwai _snd_hdac_chip_readw(chip, AZX_REG_ ## reg) 39714752412STakashi Iwai #define snd_hdac_chip_readb(chip, reg) \ 3982c1f8138STakashi Iwai _snd_hdac_chip_readb(chip, AZX_REG_ ## reg) 39914752412STakashi Iwai 40014752412STakashi Iwai /* update a register, pass without AZX_REG_ prefix */ 40114752412STakashi Iwai #define snd_hdac_chip_updatel(chip, reg, mask, val) \ 40214752412STakashi Iwai snd_hdac_chip_writel(chip, reg, \ 40314752412STakashi Iwai (snd_hdac_chip_readl(chip, reg) & ~(mask)) | (val)) 40414752412STakashi Iwai #define snd_hdac_chip_updatew(chip, reg, mask, val) \ 40514752412STakashi Iwai snd_hdac_chip_writew(chip, reg, \ 40614752412STakashi Iwai (snd_hdac_chip_readw(chip, reg) & ~(mask)) | (val)) 40714752412STakashi Iwai #define snd_hdac_chip_updateb(chip, reg, mask, val) \ 40814752412STakashi Iwai snd_hdac_chip_writeb(chip, reg, \ 40914752412STakashi Iwai (snd_hdac_chip_readb(chip, reg) & ~(mask)) | (val)) 41014752412STakashi Iwai 41114752412STakashi Iwai /* 41214752412STakashi Iwai * HD-audio stream 41314752412STakashi Iwai */ 41414752412STakashi Iwai struct hdac_stream { 41514752412STakashi Iwai struct hdac_bus *bus; 41614752412STakashi Iwai struct snd_dma_buffer bdl; /* BDL buffer */ 41714752412STakashi Iwai __le32 *posbuf; /* position buffer pointer */ 41814752412STakashi Iwai int direction; /* playback / capture (SNDRV_PCM_STREAM_*) */ 41914752412STakashi Iwai 42014752412STakashi Iwai unsigned int bufsize; /* size of the play buffer in bytes */ 42114752412STakashi Iwai unsigned int period_bytes; /* size of the period in bytes */ 42214752412STakashi Iwai unsigned int frags; /* number for period in the play buffer */ 42314752412STakashi Iwai unsigned int fifo_size; /* FIFO size */ 42414752412STakashi Iwai 42514752412STakashi Iwai void __iomem *sd_addr; /* stream descriptor pointer */ 42614752412STakashi Iwai 42714752412STakashi Iwai u32 sd_int_sta_mask; /* stream int status mask */ 42814752412STakashi Iwai 42914752412STakashi Iwai /* pcm support */ 43014752412STakashi Iwai struct snd_pcm_substream *substream; /* assigned substream, 43114752412STakashi Iwai * set in PCM open 43214752412STakashi Iwai */ 43314752412STakashi Iwai unsigned int format_val; /* format value to be set in the 43414752412STakashi Iwai * controller and the codec 43514752412STakashi Iwai */ 43614752412STakashi Iwai unsigned char stream_tag; /* assigned stream */ 43714752412STakashi Iwai unsigned char index; /* stream index */ 43814752412STakashi Iwai int assigned_key; /* last device# key assigned to */ 43914752412STakashi Iwai 44014752412STakashi Iwai bool opened:1; 44114752412STakashi Iwai bool running:1; 4426d23c8f5STakashi Iwai bool prepared:1; 44314752412STakashi Iwai bool no_period_wakeup:1; 4448f3f600bSTakashi Iwai bool locked:1; 44514752412STakashi Iwai 44614752412STakashi Iwai /* timestamp */ 44714752412STakashi Iwai unsigned long start_wallclk; /* start + minimum wallclk */ 44814752412STakashi Iwai unsigned long period_wallclk; /* wallclk for period */ 44914752412STakashi Iwai struct timecounter tc; 45014752412STakashi Iwai struct cyclecounter cc; 45114752412STakashi Iwai int delay_negative_threshold; 45214752412STakashi Iwai 45314752412STakashi Iwai struct list_head list; 4548f3f600bSTakashi Iwai #ifdef CONFIG_SND_HDA_DSP_LOADER 4558f3f600bSTakashi Iwai /* DSP access mutex */ 4568f3f600bSTakashi Iwai struct mutex dsp_mutex; 4578f3f600bSTakashi Iwai #endif 45814752412STakashi Iwai }; 45914752412STakashi Iwai 46014752412STakashi Iwai void snd_hdac_stream_init(struct hdac_bus *bus, struct hdac_stream *azx_dev, 46114752412STakashi Iwai int idx, int direction, int tag); 46214752412STakashi Iwai struct hdac_stream *snd_hdac_stream_assign(struct hdac_bus *bus, 46314752412STakashi Iwai struct snd_pcm_substream *substream); 46414752412STakashi Iwai void snd_hdac_stream_release(struct hdac_stream *azx_dev); 4654308c9b0SJeeja KP struct hdac_stream *snd_hdac_get_stream(struct hdac_bus *bus, 4664308c9b0SJeeja KP int dir, int stream_tag); 46714752412STakashi Iwai 46814752412STakashi Iwai int snd_hdac_stream_setup(struct hdac_stream *azx_dev); 46914752412STakashi Iwai void snd_hdac_stream_cleanup(struct hdac_stream *azx_dev); 47014752412STakashi Iwai int snd_hdac_stream_setup_periods(struct hdac_stream *azx_dev); 47186f6501bSJeeja KP int snd_hdac_stream_set_params(struct hdac_stream *azx_dev, 47286f6501bSJeeja KP unsigned int format_val); 47314752412STakashi Iwai void snd_hdac_stream_start(struct hdac_stream *azx_dev, bool fresh_start); 47414752412STakashi Iwai void snd_hdac_stream_clear(struct hdac_stream *azx_dev); 47514752412STakashi Iwai void snd_hdac_stream_stop(struct hdac_stream *azx_dev); 47614752412STakashi Iwai void snd_hdac_stream_reset(struct hdac_stream *azx_dev); 47714752412STakashi Iwai void snd_hdac_stream_sync_trigger(struct hdac_stream *azx_dev, bool set, 47814752412STakashi Iwai unsigned int streams, unsigned int reg); 47914752412STakashi Iwai void snd_hdac_stream_sync(struct hdac_stream *azx_dev, bool start, 48014752412STakashi Iwai unsigned int streams); 48114752412STakashi Iwai void snd_hdac_stream_timecounter_init(struct hdac_stream *azx_dev, 48214752412STakashi Iwai unsigned int streams); 48314752412STakashi Iwai /* 48414752412STakashi Iwai * macros for easy use 48514752412STakashi Iwai */ 48614752412STakashi Iwai #define _snd_hdac_stream_write(type, dev, reg, value) \ 48714752412STakashi Iwai ((dev)->bus->io_ops->reg_write ## type(value, (dev)->sd_addr + (reg))) 48814752412STakashi Iwai #define _snd_hdac_stream_read(type, dev, reg) \ 48914752412STakashi Iwai ((dev)->bus->io_ops->reg_read ## type((dev)->sd_addr + (reg))) 49014752412STakashi Iwai 49114752412STakashi Iwai /* read/write a register, pass without AZX_REG_ prefix */ 49214752412STakashi Iwai #define snd_hdac_stream_writel(dev, reg, value) \ 49314752412STakashi Iwai _snd_hdac_stream_write(l, dev, AZX_REG_ ## reg, value) 49414752412STakashi Iwai #define snd_hdac_stream_writew(dev, reg, value) \ 49514752412STakashi Iwai _snd_hdac_stream_write(w, dev, AZX_REG_ ## reg, value) 49614752412STakashi Iwai #define snd_hdac_stream_writeb(dev, reg, value) \ 49714752412STakashi Iwai _snd_hdac_stream_write(b, dev, AZX_REG_ ## reg, value) 49814752412STakashi Iwai #define snd_hdac_stream_readl(dev, reg) \ 49914752412STakashi Iwai _snd_hdac_stream_read(l, dev, AZX_REG_ ## reg) 50014752412STakashi Iwai #define snd_hdac_stream_readw(dev, reg) \ 50114752412STakashi Iwai _snd_hdac_stream_read(w, dev, AZX_REG_ ## reg) 50214752412STakashi Iwai #define snd_hdac_stream_readb(dev, reg) \ 50314752412STakashi Iwai _snd_hdac_stream_read(b, dev, AZX_REG_ ## reg) 50414752412STakashi Iwai 50514752412STakashi Iwai /* update a register, pass without AZX_REG_ prefix */ 50614752412STakashi Iwai #define snd_hdac_stream_updatel(dev, reg, mask, val) \ 50714752412STakashi Iwai snd_hdac_stream_writel(dev, reg, \ 50814752412STakashi Iwai (snd_hdac_stream_readl(dev, reg) & \ 50914752412STakashi Iwai ~(mask)) | (val)) 51014752412STakashi Iwai #define snd_hdac_stream_updatew(dev, reg, mask, val) \ 51114752412STakashi Iwai snd_hdac_stream_writew(dev, reg, \ 51214752412STakashi Iwai (snd_hdac_stream_readw(dev, reg) & \ 51314752412STakashi Iwai ~(mask)) | (val)) 51414752412STakashi Iwai #define snd_hdac_stream_updateb(dev, reg, mask, val) \ 51514752412STakashi Iwai snd_hdac_stream_writeb(dev, reg, \ 51614752412STakashi Iwai (snd_hdac_stream_readb(dev, reg) & \ 51714752412STakashi Iwai ~(mask)) | (val)) 51814752412STakashi Iwai 5198f3f600bSTakashi Iwai #ifdef CONFIG_SND_HDA_DSP_LOADER 5208f3f600bSTakashi Iwai /* DSP lock helpers */ 5218f3f600bSTakashi Iwai #define snd_hdac_dsp_lock_init(dev) mutex_init(&(dev)->dsp_mutex) 5228f3f600bSTakashi Iwai #define snd_hdac_dsp_lock(dev) mutex_lock(&(dev)->dsp_mutex) 5238f3f600bSTakashi Iwai #define snd_hdac_dsp_unlock(dev) mutex_unlock(&(dev)->dsp_mutex) 5248f3f600bSTakashi Iwai #define snd_hdac_stream_is_locked(dev) ((dev)->locked) 5258f3f600bSTakashi Iwai /* DSP loader helpers */ 5268f3f600bSTakashi Iwai int snd_hdac_dsp_prepare(struct hdac_stream *azx_dev, unsigned int format, 5278f3f600bSTakashi Iwai unsigned int byte_size, struct snd_dma_buffer *bufp); 5288f3f600bSTakashi Iwai void snd_hdac_dsp_trigger(struct hdac_stream *azx_dev, bool start); 5298f3f600bSTakashi Iwai void snd_hdac_dsp_cleanup(struct hdac_stream *azx_dev, 5308f3f600bSTakashi Iwai struct snd_dma_buffer *dmab); 5318f3f600bSTakashi Iwai #else /* CONFIG_SND_HDA_DSP_LOADER */ 5328f3f600bSTakashi Iwai #define snd_hdac_dsp_lock_init(dev) do {} while (0) 5338f3f600bSTakashi Iwai #define snd_hdac_dsp_lock(dev) do {} while (0) 5348f3f600bSTakashi Iwai #define snd_hdac_dsp_unlock(dev) do {} while (0) 5358f3f600bSTakashi Iwai #define snd_hdac_stream_is_locked(dev) 0 5368f3f600bSTakashi Iwai 5378f3f600bSTakashi Iwai static inline int 5388f3f600bSTakashi Iwai snd_hdac_dsp_prepare(struct hdac_stream *azx_dev, unsigned int format, 5398f3f600bSTakashi Iwai unsigned int byte_size, struct snd_dma_buffer *bufp) 5408f3f600bSTakashi Iwai { 5418f3f600bSTakashi Iwai return 0; 5428f3f600bSTakashi Iwai } 5438f3f600bSTakashi Iwai 5448f3f600bSTakashi Iwai static inline void snd_hdac_dsp_trigger(struct hdac_stream *azx_dev, bool start) 5458f3f600bSTakashi Iwai { 5468f3f600bSTakashi Iwai } 5478f3f600bSTakashi Iwai 5488f3f600bSTakashi Iwai static inline void snd_hdac_dsp_cleanup(struct hdac_stream *azx_dev, 5498f3f600bSTakashi Iwai struct snd_dma_buffer *dmab) 5508f3f600bSTakashi Iwai { 5518f3f600bSTakashi Iwai } 5528f3f600bSTakashi Iwai #endif /* CONFIG_SND_HDA_DSP_LOADER */ 5538f3f600bSTakashi Iwai 5548f3f600bSTakashi Iwai 55571fc4c7eSTakashi Iwai /* 55671fc4c7eSTakashi Iwai * generic array helpers 55771fc4c7eSTakashi Iwai */ 55871fc4c7eSTakashi Iwai void *snd_array_new(struct snd_array *array); 55971fc4c7eSTakashi Iwai void snd_array_free(struct snd_array *array); 56071fc4c7eSTakashi Iwai static inline void snd_array_init(struct snd_array *array, unsigned int size, 56171fc4c7eSTakashi Iwai unsigned int align) 56271fc4c7eSTakashi Iwai { 56371fc4c7eSTakashi Iwai array->elem_size = size; 56471fc4c7eSTakashi Iwai array->alloc_align = align; 56571fc4c7eSTakashi Iwai } 56671fc4c7eSTakashi Iwai 56771fc4c7eSTakashi Iwai static inline void *snd_array_elem(struct snd_array *array, unsigned int idx) 56871fc4c7eSTakashi Iwai { 56971fc4c7eSTakashi Iwai return array->list + idx * array->elem_size; 57071fc4c7eSTakashi Iwai } 57171fc4c7eSTakashi Iwai 57271fc4c7eSTakashi Iwai static inline unsigned int snd_array_index(struct snd_array *array, void *ptr) 57371fc4c7eSTakashi Iwai { 57471fc4c7eSTakashi Iwai return (unsigned long)(ptr - array->list) / array->elem_size; 57571fc4c7eSTakashi Iwai } 57671fc4c7eSTakashi Iwai 577e3d280fcSTakashi Iwai #endif /* __SOUND_HDAUDIO_H */ 578