xref: /linux/sound/pci/cs46xx/cs46xx_lib.h (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*1a59d1b8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  *  The driver for the Cirrus Logic's Sound Fusion CS46XX based soundcards
4c1017a4cSJaroslav Kysela  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
51da177e4SLinus Torvalds  */
61da177e4SLinus Torvalds 
71da177e4SLinus Torvalds #ifndef __CS46XX_LIB_H__
81da177e4SLinus Torvalds #define __CS46XX_LIB_H__
91da177e4SLinus Torvalds 
101da177e4SLinus Torvalds /*
111da177e4SLinus Torvalds  *  constants
121da177e4SLinus Torvalds  */
131da177e4SLinus Torvalds 
141da177e4SLinus Torvalds #define CS46XX_BA0_SIZE		  0x1000
151da177e4SLinus Torvalds #define CS46XX_BA1_DATA0_SIZE 0x3000
161da177e4SLinus Torvalds #define CS46XX_BA1_DATA1_SIZE 0x3800
171da177e4SLinus Torvalds #define CS46XX_BA1_PRG_SIZE	  0x7000
181da177e4SLinus Torvalds #define CS46XX_BA1_REG_SIZE	  0x0100
191da177e4SLinus Torvalds 
201da177e4SLinus Torvalds 
211da177e4SLinus Torvalds 
221da177e4SLinus Torvalds #ifdef CONFIG_SND_CS46XX_NEW_DSP
236148b130SSophie Hamilton #define CS46XX_MIN_PERIOD_SIZE 64
241da177e4SLinus Torvalds #define CS46XX_MAX_PERIOD_SIZE 1024*1024
251da177e4SLinus Torvalds #else
261da177e4SLinus Torvalds #define CS46XX_MIN_PERIOD_SIZE 2048
271da177e4SLinus Torvalds #define CS46XX_MAX_PERIOD_SIZE 2048
281da177e4SLinus Torvalds #endif
291da177e4SLinus Torvalds 
301da177e4SLinus Torvalds #define CS46XX_FRAGS 2
311da177e4SLinus Torvalds /* #define CS46XX_BUFFER_SIZE CS46XX_MAX_PERIOD_SIZE * CS46XX_FRAGS */
321da177e4SLinus Torvalds 
331da177e4SLinus Torvalds #define SCB_NO_PARENT             0
341da177e4SLinus Torvalds #define SCB_ON_PARENT_NEXT_SCB    1
351da177e4SLinus Torvalds #define SCB_ON_PARENT_SUBLIST_SCB 2
361da177e4SLinus Torvalds 
371da177e4SLinus Torvalds /* 3*1024 parameter, 3.5*1024 sample, 2*3.5*1024 code */
381da177e4SLinus Torvalds #define BA1_DWORD_SIZE		(13 * 1024 + 512)
391da177e4SLinus Torvalds #define BA1_MEMORY_COUNT	3
401da177e4SLinus Torvalds 
411da177e4SLinus Torvalds /*
421da177e4SLinus Torvalds  *  common I/O routines
431da177e4SLinus Torvalds  */
441da177e4SLinus Torvalds 
snd_cs46xx_poke(struct snd_cs46xx * chip,unsigned long reg,unsigned int val)453d19f804STakashi Iwai static inline void snd_cs46xx_poke(struct snd_cs46xx *chip, unsigned long reg, unsigned int val)
461da177e4SLinus Torvalds {
471da177e4SLinus Torvalds 	unsigned int bank = reg >> 16;
481da177e4SLinus Torvalds 	unsigned int offset = reg & 0xffff;
491da177e4SLinus Torvalds 
50ee419653STakashi Iwai 	/*
51ee419653STakashi Iwai 	if (bank == 0)
52ee419653STakashi Iwai 		printk(KERN_DEBUG "snd_cs46xx_poke: %04X - %08X\n",
53ee419653STakashi Iwai 		       reg >> 2,val);
54ee419653STakashi Iwai 	*/
551da177e4SLinus Torvalds 	writel(val, chip->region.idx[bank+1].remap_addr + offset);
561da177e4SLinus Torvalds }
571da177e4SLinus Torvalds 
snd_cs46xx_peek(struct snd_cs46xx * chip,unsigned long reg)583d19f804STakashi Iwai static inline unsigned int snd_cs46xx_peek(struct snd_cs46xx *chip, unsigned long reg)
591da177e4SLinus Torvalds {
601da177e4SLinus Torvalds 	unsigned int bank = reg >> 16;
611da177e4SLinus Torvalds 	unsigned int offset = reg & 0xffff;
621da177e4SLinus Torvalds 	return readl(chip->region.idx[bank+1].remap_addr + offset);
631da177e4SLinus Torvalds }
641da177e4SLinus Torvalds 
snd_cs46xx_pokeBA0(struct snd_cs46xx * chip,unsigned long offset,unsigned int val)653d19f804STakashi Iwai static inline void snd_cs46xx_pokeBA0(struct snd_cs46xx *chip, unsigned long offset, unsigned int val)
661da177e4SLinus Torvalds {
671da177e4SLinus Torvalds 	writel(val, chip->region.name.ba0.remap_addr + offset);
681da177e4SLinus Torvalds }
691da177e4SLinus Torvalds 
snd_cs46xx_peekBA0(struct snd_cs46xx * chip,unsigned long offset)703d19f804STakashi Iwai static inline unsigned int snd_cs46xx_peekBA0(struct snd_cs46xx *chip, unsigned long offset)
711da177e4SLinus Torvalds {
721da177e4SLinus Torvalds 	return readl(chip->region.name.ba0.remap_addr + offset);
731da177e4SLinus Torvalds }
741da177e4SLinus Torvalds 
753d19f804STakashi Iwai struct dsp_spos_instance *cs46xx_dsp_spos_create (struct snd_cs46xx * chip);
763d19f804STakashi Iwai void cs46xx_dsp_spos_destroy (struct snd_cs46xx * chip);
773d19f804STakashi Iwai int cs46xx_dsp_load_module (struct snd_cs46xx * chip, struct dsp_module_desc * module);
78c7561cd8STakashi Iwai #ifdef CONFIG_PM_SLEEP
7989f157d9STakashi Iwai int cs46xx_dsp_resume(struct snd_cs46xx * chip);
8089f157d9STakashi Iwai #endif
813d19f804STakashi Iwai struct dsp_symbol_entry *cs46xx_dsp_lookup_symbol (struct snd_cs46xx * chip, char * symbol_name,
823d19f804STakashi Iwai 						   int symbol_type);
8395bb6258STakashi Iwai #ifdef CONFIG_SND_PROC_FS
843d19f804STakashi Iwai int cs46xx_dsp_proc_init (struct snd_card *card, struct snd_cs46xx *chip);
853d19f804STakashi Iwai int cs46xx_dsp_proc_done (struct snd_cs46xx *chip);
86adf1b3d2STakashi Iwai #else
87adf1b3d2STakashi Iwai #define cs46xx_dsp_proc_init(card, chip)
88adf1b3d2STakashi Iwai #define cs46xx_dsp_proc_done(chip)
89adf1b3d2STakashi Iwai #endif
903d19f804STakashi Iwai int cs46xx_dsp_scb_and_task_init (struct snd_cs46xx *chip);
913d19f804STakashi Iwai int snd_cs46xx_download (struct snd_cs46xx *chip, u32 *src, unsigned long offset,
921da177e4SLinus Torvalds 			 unsigned long len);
933d19f804STakashi Iwai int snd_cs46xx_clear_BA1(struct snd_cs46xx *chip, unsigned long offset, unsigned long len);
943d19f804STakashi Iwai int cs46xx_dsp_enable_spdif_out (struct snd_cs46xx *chip);
953d19f804STakashi Iwai int cs46xx_dsp_enable_spdif_hw (struct snd_cs46xx *chip);
963d19f804STakashi Iwai int cs46xx_dsp_disable_spdif_out (struct snd_cs46xx *chip);
973d19f804STakashi Iwai int cs46xx_dsp_enable_spdif_in (struct snd_cs46xx *chip);
983d19f804STakashi Iwai int cs46xx_dsp_disable_spdif_in (struct snd_cs46xx *chip);
993d19f804STakashi Iwai int cs46xx_dsp_enable_pcm_capture (struct snd_cs46xx *chip);
1003d19f804STakashi Iwai int cs46xx_dsp_disable_pcm_capture (struct snd_cs46xx *chip);
1013d19f804STakashi Iwai int cs46xx_dsp_enable_adc_capture (struct snd_cs46xx *chip);
1023d19f804STakashi Iwai int cs46xx_dsp_disable_adc_capture (struct snd_cs46xx *chip);
1033d19f804STakashi Iwai int cs46xx_poke_via_dsp (struct snd_cs46xx *chip, u32 address, u32 data);
1043d19f804STakashi Iwai struct dsp_scb_descriptor * cs46xx_dsp_create_scb (struct snd_cs46xx *chip, char * name,
1053d19f804STakashi Iwai 						   u32 * scb_data, u32 dest);
10695bb6258STakashi Iwai #ifdef CONFIG_SND_PROC_FS
1073d19f804STakashi Iwai void cs46xx_dsp_proc_free_scb_desc (struct dsp_scb_descriptor * scb);
1083d19f804STakashi Iwai void cs46xx_dsp_proc_register_scb_desc (struct snd_cs46xx *chip,
1093d19f804STakashi Iwai 					struct dsp_scb_descriptor * scb);
110adf1b3d2STakashi Iwai #else
111adf1b3d2STakashi Iwai #define cs46xx_dsp_proc_free_scb_desc(scb)
112adf1b3d2STakashi Iwai #define cs46xx_dsp_proc_register_scb_desc(chip, scb)
113adf1b3d2STakashi Iwai #endif
1143d19f804STakashi Iwai struct dsp_scb_descriptor * cs46xx_dsp_create_timing_master_scb (struct snd_cs46xx *chip);
1153d19f804STakashi Iwai struct dsp_scb_descriptor *
1163d19f804STakashi Iwai cs46xx_dsp_create_codec_out_scb(struct snd_cs46xx * chip,
1173d19f804STakashi Iwai 				char * codec_name, u16 channel_disp, u16 fifo_addr,
1183d19f804STakashi Iwai 				u16 child_scb_addr, u32 dest,
1193d19f804STakashi Iwai 				struct dsp_scb_descriptor * parent_scb,
1201da177e4SLinus Torvalds 				int scb_child_type);
1213d19f804STakashi Iwai struct dsp_scb_descriptor *
1223d19f804STakashi Iwai cs46xx_dsp_create_codec_in_scb(struct snd_cs46xx * chip, char * codec_name,
1231da177e4SLinus Torvalds 			       u16 channel_disp, u16 fifo_addr,
1243d19f804STakashi Iwai 			       u16 sample_buffer_addr, u32 dest,
1253d19f804STakashi Iwai 			       struct dsp_scb_descriptor * parent_scb,
1261da177e4SLinus Torvalds 			       int scb_child_type);
1273d19f804STakashi Iwai void cs46xx_dsp_remove_scb (struct snd_cs46xx *chip,
1283d19f804STakashi Iwai 			    struct dsp_scb_descriptor * scb);
1293d19f804STakashi Iwai struct dsp_scb_descriptor *
1303d19f804STakashi Iwai cs46xx_dsp_create_codec_in_scb(struct snd_cs46xx * chip, char * codec_name,
1311da177e4SLinus Torvalds 			       u16 channel_disp, u16 fifo_addr,
1323d19f804STakashi Iwai 			       u16 sample_buffer_addr, u32 dest,
1333d19f804STakashi Iwai 			       struct dsp_scb_descriptor * parent_scb,
1341da177e4SLinus Torvalds 			       int scb_child_type);
1353d19f804STakashi Iwai struct dsp_scb_descriptor *
1363d19f804STakashi Iwai cs46xx_dsp_create_src_task_scb(struct snd_cs46xx * chip, char * scb_name,
1373d19f804STakashi Iwai 			       int sample_rate, u16 src_buffer_addr,
1381da177e4SLinus Torvalds 			       u16 src_delay_buffer_addr, u32 dest,
1393d19f804STakashi Iwai 			       struct dsp_scb_descriptor * parent_scb,
1403d19f804STakashi Iwai 			       int scb_child_type, int pass_through);
1413d19f804STakashi Iwai struct dsp_scb_descriptor *
1423d19f804STakashi Iwai cs46xx_dsp_create_mix_only_scb(struct snd_cs46xx * chip, char * scb_name,
1431da177e4SLinus Torvalds 			       u16 mix_buffer_addr, u32 dest,
1443d19f804STakashi Iwai 			       struct dsp_scb_descriptor * parent_scb,
1451da177e4SLinus Torvalds 			       int scb_child_type);
1461da177e4SLinus Torvalds 
1473d19f804STakashi Iwai struct dsp_scb_descriptor *
1483d19f804STakashi Iwai cs46xx_dsp_create_vari_decimate_scb(struct snd_cs46xx * chip, char * scb_name,
1493d19f804STakashi Iwai 				    u16 vari_buffer_addr0, u16 vari_buffer_addr1, u32 dest,
1503d19f804STakashi Iwai 				    struct dsp_scb_descriptor * parent_scb,
1511da177e4SLinus Torvalds 				    int scb_child_type);
1523d19f804STakashi Iwai struct dsp_scb_descriptor *
1533d19f804STakashi Iwai cs46xx_dsp_create_asynch_fg_rx_scb(struct snd_cs46xx * chip, char * scb_name,
1543d19f804STakashi Iwai 				   u32 dest, u16 hfg_scb_address, u16 asynch_buffer_address,
1553d19f804STakashi Iwai 				   struct dsp_scb_descriptor * parent_scb,
1561da177e4SLinus Torvalds 				   int scb_child_type);
1573d19f804STakashi Iwai struct dsp_scb_descriptor *
1583d19f804STakashi Iwai cs46xx_dsp_create_spio_write_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest,
1593d19f804STakashi Iwai 				 struct dsp_scb_descriptor * parent_scb,
1601da177e4SLinus Torvalds 				 int scb_child_type);
1613d19f804STakashi Iwai struct dsp_scb_descriptor *
1623d19f804STakashi Iwai cs46xx_dsp_create_mix_to_ostream_scb(struct snd_cs46xx * chip, char * scb_name,
1631da177e4SLinus Torvalds 				     u16 mix_buffer_addr, u16 writeback_spb, u32 dest,
1643d19f804STakashi Iwai 				     struct dsp_scb_descriptor * parent_scb,
1651da177e4SLinus Torvalds 				     int scb_child_type);
1663d19f804STakashi Iwai struct dsp_scb_descriptor *
1673d19f804STakashi Iwai cs46xx_dsp_create_magic_snoop_scb(struct snd_cs46xx * chip, char * scb_name,
1683d19f804STakashi Iwai 				  u32 dest, u16 snoop_buffer_address,
1693d19f804STakashi Iwai 				  struct dsp_scb_descriptor * snoop_scb,
1703d19f804STakashi Iwai 				  struct dsp_scb_descriptor * parent_scb,
1711da177e4SLinus Torvalds 				  int scb_child_type);
1723d19f804STakashi Iwai struct dsp_pcm_channel_descriptor *
1733d19f804STakashi Iwai cs46xx_dsp_create_pcm_channel (struct snd_cs46xx * chip, u32 sample_rate,
1743d19f804STakashi Iwai 			       void * private_data, u32 hw_dma_addr,
1751da177e4SLinus Torvalds 			       int pcm_channel_id);
1763d19f804STakashi Iwai void cs46xx_dsp_destroy_pcm_channel (struct snd_cs46xx * chip,
1773d19f804STakashi Iwai 				     struct dsp_pcm_channel_descriptor * pcm_channel);
1783d19f804STakashi Iwai int cs46xx_dsp_pcm_unlink (struct snd_cs46xx * chip,
1793d19f804STakashi Iwai 			   struct dsp_pcm_channel_descriptor * pcm_channel);
1803d19f804STakashi Iwai int cs46xx_dsp_pcm_link (struct snd_cs46xx * chip,
1813d19f804STakashi Iwai 			 struct dsp_pcm_channel_descriptor * pcm_channel);
1823d19f804STakashi Iwai struct dsp_scb_descriptor *
1833d19f804STakashi Iwai cs46xx_add_record_source (struct snd_cs46xx *chip, struct dsp_scb_descriptor * source,
1841da177e4SLinus Torvalds 			  u16 addr, char * scb_name);
1853d19f804STakashi Iwai int cs46xx_src_unlink(struct snd_cs46xx *chip, struct dsp_scb_descriptor * src);
1863d19f804STakashi Iwai int cs46xx_src_link(struct snd_cs46xx *chip, struct dsp_scb_descriptor * src);
1873d19f804STakashi Iwai int cs46xx_iec958_pre_open (struct snd_cs46xx *chip);
1883d19f804STakashi Iwai int cs46xx_iec958_post_close (struct snd_cs46xx *chip);
1893d19f804STakashi Iwai int cs46xx_dsp_pcm_channel_set_period (struct snd_cs46xx * chip,
1903d19f804STakashi Iwai 				       struct dsp_pcm_channel_descriptor * pcm_channel,
1911da177e4SLinus Torvalds 				       int period_size);
1923d19f804STakashi Iwai int cs46xx_dsp_pcm_ostream_set_period (struct snd_cs46xx * chip, int period_size);
1933d19f804STakashi Iwai int cs46xx_dsp_set_dac_volume (struct snd_cs46xx * chip, u16 left, u16 right);
1943d19f804STakashi Iwai int cs46xx_dsp_set_iec958_volume (struct snd_cs46xx * chip, u16 left, u16 right);
1951da177e4SLinus Torvalds #endif /* __CS46XX_LIB_H__ */
196