18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * The driver for the Cirrus Logic's Sound Fusion CS46XX based soundcards 48c2ecf20Sopenharmony_ci * Copyright (c) by Jaroslav Kysela <perex@perex.cz> 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#ifndef __CS46XX_LIB_H__ 88c2ecf20Sopenharmony_ci#define __CS46XX_LIB_H__ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci/* 118c2ecf20Sopenharmony_ci * constants 128c2ecf20Sopenharmony_ci */ 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#define CS46XX_BA0_SIZE 0x1000 158c2ecf20Sopenharmony_ci#define CS46XX_BA1_DATA0_SIZE 0x3000 168c2ecf20Sopenharmony_ci#define CS46XX_BA1_DATA1_SIZE 0x3800 178c2ecf20Sopenharmony_ci#define CS46XX_BA1_PRG_SIZE 0x7000 188c2ecf20Sopenharmony_ci#define CS46XX_BA1_REG_SIZE 0x0100 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_CS46XX_NEW_DSP 238c2ecf20Sopenharmony_ci#define CS46XX_MIN_PERIOD_SIZE 64 248c2ecf20Sopenharmony_ci#define CS46XX_MAX_PERIOD_SIZE 1024*1024 258c2ecf20Sopenharmony_ci#else 268c2ecf20Sopenharmony_ci#define CS46XX_MIN_PERIOD_SIZE 2048 278c2ecf20Sopenharmony_ci#define CS46XX_MAX_PERIOD_SIZE 2048 288c2ecf20Sopenharmony_ci#endif 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#define CS46XX_FRAGS 2 318c2ecf20Sopenharmony_ci/* #define CS46XX_BUFFER_SIZE CS46XX_MAX_PERIOD_SIZE * CS46XX_FRAGS */ 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define SCB_NO_PARENT 0 348c2ecf20Sopenharmony_ci#define SCB_ON_PARENT_NEXT_SCB 1 358c2ecf20Sopenharmony_ci#define SCB_ON_PARENT_SUBLIST_SCB 2 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci/* 3*1024 parameter, 3.5*1024 sample, 2*3.5*1024 code */ 388c2ecf20Sopenharmony_ci#define BA1_DWORD_SIZE (13 * 1024 + 512) 398c2ecf20Sopenharmony_ci#define BA1_MEMORY_COUNT 3 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/* 428c2ecf20Sopenharmony_ci * common I/O routines 438c2ecf20Sopenharmony_ci */ 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_cistatic inline void snd_cs46xx_poke(struct snd_cs46xx *chip, unsigned long reg, unsigned int val) 468c2ecf20Sopenharmony_ci{ 478c2ecf20Sopenharmony_ci unsigned int bank = reg >> 16; 488c2ecf20Sopenharmony_ci unsigned int offset = reg & 0xffff; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci /* 518c2ecf20Sopenharmony_ci if (bank == 0) 528c2ecf20Sopenharmony_ci printk(KERN_DEBUG "snd_cs46xx_poke: %04X - %08X\n", 538c2ecf20Sopenharmony_ci reg >> 2,val); 548c2ecf20Sopenharmony_ci */ 558c2ecf20Sopenharmony_ci writel(val, chip->region.idx[bank+1].remap_addr + offset); 568c2ecf20Sopenharmony_ci} 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cistatic inline unsigned int snd_cs46xx_peek(struct snd_cs46xx *chip, unsigned long reg) 598c2ecf20Sopenharmony_ci{ 608c2ecf20Sopenharmony_ci unsigned int bank = reg >> 16; 618c2ecf20Sopenharmony_ci unsigned int offset = reg & 0xffff; 628c2ecf20Sopenharmony_ci return readl(chip->region.idx[bank+1].remap_addr + offset); 638c2ecf20Sopenharmony_ci} 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_cistatic inline void snd_cs46xx_pokeBA0(struct snd_cs46xx *chip, unsigned long offset, unsigned int val) 668c2ecf20Sopenharmony_ci{ 678c2ecf20Sopenharmony_ci writel(val, chip->region.name.ba0.remap_addr + offset); 688c2ecf20Sopenharmony_ci} 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_cistatic inline unsigned int snd_cs46xx_peekBA0(struct snd_cs46xx *chip, unsigned long offset) 718c2ecf20Sopenharmony_ci{ 728c2ecf20Sopenharmony_ci return readl(chip->region.name.ba0.remap_addr + offset); 738c2ecf20Sopenharmony_ci} 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_cistruct dsp_spos_instance *cs46xx_dsp_spos_create (struct snd_cs46xx * chip); 768c2ecf20Sopenharmony_civoid cs46xx_dsp_spos_destroy (struct snd_cs46xx * chip); 778c2ecf20Sopenharmony_ciint cs46xx_dsp_load_module (struct snd_cs46xx * chip, struct dsp_module_desc * module); 788c2ecf20Sopenharmony_ci#ifdef CONFIG_PM_SLEEP 798c2ecf20Sopenharmony_ciint cs46xx_dsp_resume(struct snd_cs46xx * chip); 808c2ecf20Sopenharmony_ci#endif 818c2ecf20Sopenharmony_cistruct dsp_symbol_entry *cs46xx_dsp_lookup_symbol (struct snd_cs46xx * chip, char * symbol_name, 828c2ecf20Sopenharmony_ci int symbol_type); 838c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_PROC_FS 848c2ecf20Sopenharmony_ciint cs46xx_dsp_proc_init (struct snd_card *card, struct snd_cs46xx *chip); 858c2ecf20Sopenharmony_ciint cs46xx_dsp_proc_done (struct snd_cs46xx *chip); 868c2ecf20Sopenharmony_ci#else 878c2ecf20Sopenharmony_ci#define cs46xx_dsp_proc_init(card, chip) 888c2ecf20Sopenharmony_ci#define cs46xx_dsp_proc_done(chip) 898c2ecf20Sopenharmony_ci#endif 908c2ecf20Sopenharmony_ciint cs46xx_dsp_scb_and_task_init (struct snd_cs46xx *chip); 918c2ecf20Sopenharmony_ciint snd_cs46xx_download (struct snd_cs46xx *chip, u32 *src, unsigned long offset, 928c2ecf20Sopenharmony_ci unsigned long len); 938c2ecf20Sopenharmony_ciint snd_cs46xx_clear_BA1(struct snd_cs46xx *chip, unsigned long offset, unsigned long len); 948c2ecf20Sopenharmony_ciint cs46xx_dsp_enable_spdif_out (struct snd_cs46xx *chip); 958c2ecf20Sopenharmony_ciint cs46xx_dsp_enable_spdif_hw (struct snd_cs46xx *chip); 968c2ecf20Sopenharmony_ciint cs46xx_dsp_disable_spdif_out (struct snd_cs46xx *chip); 978c2ecf20Sopenharmony_ciint cs46xx_dsp_enable_spdif_in (struct snd_cs46xx *chip); 988c2ecf20Sopenharmony_ciint cs46xx_dsp_disable_spdif_in (struct snd_cs46xx *chip); 998c2ecf20Sopenharmony_ciint cs46xx_dsp_enable_pcm_capture (struct snd_cs46xx *chip); 1008c2ecf20Sopenharmony_ciint cs46xx_dsp_disable_pcm_capture (struct snd_cs46xx *chip); 1018c2ecf20Sopenharmony_ciint cs46xx_dsp_enable_adc_capture (struct snd_cs46xx *chip); 1028c2ecf20Sopenharmony_ciint cs46xx_dsp_disable_adc_capture (struct snd_cs46xx *chip); 1038c2ecf20Sopenharmony_ciint cs46xx_poke_via_dsp (struct snd_cs46xx *chip, u32 address, u32 data); 1048c2ecf20Sopenharmony_cistruct dsp_scb_descriptor * cs46xx_dsp_create_scb (struct snd_cs46xx *chip, char * name, 1058c2ecf20Sopenharmony_ci u32 * scb_data, u32 dest); 1068c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_PROC_FS 1078c2ecf20Sopenharmony_civoid cs46xx_dsp_proc_free_scb_desc (struct dsp_scb_descriptor * scb); 1088c2ecf20Sopenharmony_civoid cs46xx_dsp_proc_register_scb_desc (struct snd_cs46xx *chip, 1098c2ecf20Sopenharmony_ci struct dsp_scb_descriptor * scb); 1108c2ecf20Sopenharmony_ci#else 1118c2ecf20Sopenharmony_ci#define cs46xx_dsp_proc_free_scb_desc(scb) 1128c2ecf20Sopenharmony_ci#define cs46xx_dsp_proc_register_scb_desc(chip, scb) 1138c2ecf20Sopenharmony_ci#endif 1148c2ecf20Sopenharmony_cistruct dsp_scb_descriptor * cs46xx_dsp_create_timing_master_scb (struct snd_cs46xx *chip); 1158c2ecf20Sopenharmony_cistruct dsp_scb_descriptor * 1168c2ecf20Sopenharmony_cics46xx_dsp_create_codec_out_scb(struct snd_cs46xx * chip, 1178c2ecf20Sopenharmony_ci char * codec_name, u16 channel_disp, u16 fifo_addr, 1188c2ecf20Sopenharmony_ci u16 child_scb_addr, u32 dest, 1198c2ecf20Sopenharmony_ci struct dsp_scb_descriptor * parent_scb, 1208c2ecf20Sopenharmony_ci int scb_child_type); 1218c2ecf20Sopenharmony_cistruct dsp_scb_descriptor * 1228c2ecf20Sopenharmony_cics46xx_dsp_create_codec_in_scb(struct snd_cs46xx * chip, char * codec_name, 1238c2ecf20Sopenharmony_ci u16 channel_disp, u16 fifo_addr, 1248c2ecf20Sopenharmony_ci u16 sample_buffer_addr, u32 dest, 1258c2ecf20Sopenharmony_ci struct dsp_scb_descriptor * parent_scb, 1268c2ecf20Sopenharmony_ci int scb_child_type); 1278c2ecf20Sopenharmony_civoid cs46xx_dsp_remove_scb (struct snd_cs46xx *chip, 1288c2ecf20Sopenharmony_ci struct dsp_scb_descriptor * scb); 1298c2ecf20Sopenharmony_cistruct dsp_scb_descriptor * 1308c2ecf20Sopenharmony_cics46xx_dsp_create_codec_in_scb(struct snd_cs46xx * chip, char * codec_name, 1318c2ecf20Sopenharmony_ci u16 channel_disp, u16 fifo_addr, 1328c2ecf20Sopenharmony_ci u16 sample_buffer_addr, u32 dest, 1338c2ecf20Sopenharmony_ci struct dsp_scb_descriptor * parent_scb, 1348c2ecf20Sopenharmony_ci int scb_child_type); 1358c2ecf20Sopenharmony_cistruct dsp_scb_descriptor * 1368c2ecf20Sopenharmony_cics46xx_dsp_create_src_task_scb(struct snd_cs46xx * chip, char * scb_name, 1378c2ecf20Sopenharmony_ci int sample_rate, u16 src_buffer_addr, 1388c2ecf20Sopenharmony_ci u16 src_delay_buffer_addr, u32 dest, 1398c2ecf20Sopenharmony_ci struct dsp_scb_descriptor * parent_scb, 1408c2ecf20Sopenharmony_ci int scb_child_type, int pass_through); 1418c2ecf20Sopenharmony_cistruct dsp_scb_descriptor * 1428c2ecf20Sopenharmony_cics46xx_dsp_create_mix_only_scb(struct snd_cs46xx * chip, char * scb_name, 1438c2ecf20Sopenharmony_ci u16 mix_buffer_addr, u32 dest, 1448c2ecf20Sopenharmony_ci struct dsp_scb_descriptor * parent_scb, 1458c2ecf20Sopenharmony_ci int scb_child_type); 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_cistruct dsp_scb_descriptor * 1488c2ecf20Sopenharmony_cics46xx_dsp_create_vari_decimate_scb(struct snd_cs46xx * chip, char * scb_name, 1498c2ecf20Sopenharmony_ci u16 vari_buffer_addr0, u16 vari_buffer_addr1, u32 dest, 1508c2ecf20Sopenharmony_ci struct dsp_scb_descriptor * parent_scb, 1518c2ecf20Sopenharmony_ci int scb_child_type); 1528c2ecf20Sopenharmony_cistruct dsp_scb_descriptor * 1538c2ecf20Sopenharmony_cics46xx_dsp_create_asynch_fg_rx_scb(struct snd_cs46xx * chip, char * scb_name, 1548c2ecf20Sopenharmony_ci u32 dest, u16 hfg_scb_address, u16 asynch_buffer_address, 1558c2ecf20Sopenharmony_ci struct dsp_scb_descriptor * parent_scb, 1568c2ecf20Sopenharmony_ci int scb_child_type); 1578c2ecf20Sopenharmony_cistruct dsp_scb_descriptor * 1588c2ecf20Sopenharmony_cics46xx_dsp_create_spio_write_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest, 1598c2ecf20Sopenharmony_ci struct dsp_scb_descriptor * parent_scb, 1608c2ecf20Sopenharmony_ci int scb_child_type); 1618c2ecf20Sopenharmony_cistruct dsp_scb_descriptor * 1628c2ecf20Sopenharmony_cics46xx_dsp_create_mix_to_ostream_scb(struct snd_cs46xx * chip, char * scb_name, 1638c2ecf20Sopenharmony_ci u16 mix_buffer_addr, u16 writeback_spb, u32 dest, 1648c2ecf20Sopenharmony_ci struct dsp_scb_descriptor * parent_scb, 1658c2ecf20Sopenharmony_ci int scb_child_type); 1668c2ecf20Sopenharmony_cistruct dsp_scb_descriptor * 1678c2ecf20Sopenharmony_cics46xx_dsp_create_magic_snoop_scb(struct snd_cs46xx * chip, char * scb_name, 1688c2ecf20Sopenharmony_ci u32 dest, u16 snoop_buffer_address, 1698c2ecf20Sopenharmony_ci struct dsp_scb_descriptor * snoop_scb, 1708c2ecf20Sopenharmony_ci struct dsp_scb_descriptor * parent_scb, 1718c2ecf20Sopenharmony_ci int scb_child_type); 1728c2ecf20Sopenharmony_cistruct dsp_pcm_channel_descriptor * 1738c2ecf20Sopenharmony_cics46xx_dsp_create_pcm_channel (struct snd_cs46xx * chip, u32 sample_rate, 1748c2ecf20Sopenharmony_ci void * private_data, u32 hw_dma_addr, 1758c2ecf20Sopenharmony_ci int pcm_channel_id); 1768c2ecf20Sopenharmony_civoid cs46xx_dsp_destroy_pcm_channel (struct snd_cs46xx * chip, 1778c2ecf20Sopenharmony_ci struct dsp_pcm_channel_descriptor * pcm_channel); 1788c2ecf20Sopenharmony_ciint cs46xx_dsp_pcm_unlink (struct snd_cs46xx * chip, 1798c2ecf20Sopenharmony_ci struct dsp_pcm_channel_descriptor * pcm_channel); 1808c2ecf20Sopenharmony_ciint cs46xx_dsp_pcm_link (struct snd_cs46xx * chip, 1818c2ecf20Sopenharmony_ci struct dsp_pcm_channel_descriptor * pcm_channel); 1828c2ecf20Sopenharmony_cistruct dsp_scb_descriptor * 1838c2ecf20Sopenharmony_cics46xx_add_record_source (struct snd_cs46xx *chip, struct dsp_scb_descriptor * source, 1848c2ecf20Sopenharmony_ci u16 addr, char * scb_name); 1858c2ecf20Sopenharmony_ciint cs46xx_src_unlink(struct snd_cs46xx *chip, struct dsp_scb_descriptor * src); 1868c2ecf20Sopenharmony_ciint cs46xx_src_link(struct snd_cs46xx *chip, struct dsp_scb_descriptor * src); 1878c2ecf20Sopenharmony_ciint cs46xx_iec958_pre_open (struct snd_cs46xx *chip); 1888c2ecf20Sopenharmony_ciint cs46xx_iec958_post_close (struct snd_cs46xx *chip); 1898c2ecf20Sopenharmony_ciint cs46xx_dsp_pcm_channel_set_period (struct snd_cs46xx * chip, 1908c2ecf20Sopenharmony_ci struct dsp_pcm_channel_descriptor * pcm_channel, 1918c2ecf20Sopenharmony_ci int period_size); 1928c2ecf20Sopenharmony_ciint cs46xx_dsp_pcm_ostream_set_period (struct snd_cs46xx * chip, int period_size); 1938c2ecf20Sopenharmony_ciint cs46xx_dsp_set_dac_volume (struct snd_cs46xx * chip, u16 left, u16 right); 1948c2ecf20Sopenharmony_ciint cs46xx_dsp_set_iec958_volume (struct snd_cs46xx * chip, u16 left, u16 right); 1958c2ecf20Sopenharmony_ci#endif /* __CS46XX_LIB_H__ */ 196