xref: /linux/sound/pci/cs46xx/cs46xx_lib.h (revision 4b132aacb0768ac1e652cf517097ea6f237214b9)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  *  The driver for the Cirrus Logic's Sound Fusion CS46XX based soundcards
4  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
5  */
6 
7 #ifndef __CS46XX_LIB_H__
8 #define __CS46XX_LIB_H__
9 
10 /*
11  *  constants
12  */
13 
14 #define CS46XX_BA0_SIZE		  0x1000
15 #define CS46XX_BA1_DATA0_SIZE 0x3000
16 #define CS46XX_BA1_DATA1_SIZE 0x3800
17 #define CS46XX_BA1_PRG_SIZE	  0x7000
18 #define CS46XX_BA1_REG_SIZE	  0x0100
19 
20 
21 
22 #ifdef CONFIG_SND_CS46XX_NEW_DSP
23 #define CS46XX_MIN_PERIOD_SIZE 64
24 #define CS46XX_MAX_PERIOD_SIZE 1024*1024
25 #else
26 #define CS46XX_MIN_PERIOD_SIZE 2048
27 #define CS46XX_MAX_PERIOD_SIZE 2048
28 #endif
29 
30 #define CS46XX_FRAGS 2
31 /* #define CS46XX_BUFFER_SIZE CS46XX_MAX_PERIOD_SIZE * CS46XX_FRAGS */
32 
33 #define SCB_NO_PARENT             0
34 #define SCB_ON_PARENT_NEXT_SCB    1
35 #define SCB_ON_PARENT_SUBLIST_SCB 2
36 
37 /* 3*1024 parameter, 3.5*1024 sample, 2*3.5*1024 code */
38 #define BA1_DWORD_SIZE		(13 * 1024 + 512)
39 #define BA1_MEMORY_COUNT	3
40 
41 /*
42  *  common I/O routines
43  */
44 
45 static inline void snd_cs46xx_poke(struct snd_cs46xx *chip, unsigned long reg, unsigned int val)
46 {
47 	unsigned int bank = reg >> 16;
48 	unsigned int offset = reg & 0xffff;
49 
50 	/*
51 	if (bank == 0)
52 		printk(KERN_DEBUG "snd_cs46xx_poke: %04X - %08X\n",
53 		       reg >> 2,val);
54 	*/
55 	writel(val, chip->region.idx[bank+1].remap_addr + offset);
56 }
57 
58 static inline unsigned int snd_cs46xx_peek(struct snd_cs46xx *chip, unsigned long reg)
59 {
60 	unsigned int bank = reg >> 16;
61 	unsigned int offset = reg & 0xffff;
62 	return readl(chip->region.idx[bank+1].remap_addr + offset);
63 }
64 
65 static inline void snd_cs46xx_pokeBA0(struct snd_cs46xx *chip, unsigned long offset, unsigned int val)
66 {
67 	writel(val, chip->region.name.ba0.remap_addr + offset);
68 }
69 
70 static inline unsigned int snd_cs46xx_peekBA0(struct snd_cs46xx *chip, unsigned long offset)
71 {
72 	return readl(chip->region.name.ba0.remap_addr + offset);
73 }
74 
75 struct dsp_spos_instance *cs46xx_dsp_spos_create (struct snd_cs46xx * chip);
76 void cs46xx_dsp_spos_destroy (struct snd_cs46xx * chip);
77 int cs46xx_dsp_load_module (struct snd_cs46xx * chip, struct dsp_module_desc * module);
78 #ifdef CONFIG_PM_SLEEP
79 int cs46xx_dsp_resume(struct snd_cs46xx * chip);
80 #endif
81 struct dsp_symbol_entry *cs46xx_dsp_lookup_symbol (struct snd_cs46xx * chip, char * symbol_name,
82 						   int symbol_type);
83 #ifdef CONFIG_SND_PROC_FS
84 int cs46xx_dsp_proc_init (struct snd_card *card, struct snd_cs46xx *chip);
85 int cs46xx_dsp_proc_done (struct snd_cs46xx *chip);
86 #else
87 #define cs46xx_dsp_proc_init(card, chip)
88 #define cs46xx_dsp_proc_done(chip)
89 #endif
90 int cs46xx_dsp_scb_and_task_init (struct snd_cs46xx *chip);
91 int snd_cs46xx_download (struct snd_cs46xx *chip, u32 *src, unsigned long offset,
92 			 unsigned long len);
93 int snd_cs46xx_clear_BA1(struct snd_cs46xx *chip, unsigned long offset, unsigned long len);
94 int cs46xx_dsp_enable_spdif_out (struct snd_cs46xx *chip);
95 int cs46xx_dsp_enable_spdif_hw (struct snd_cs46xx *chip);
96 int cs46xx_dsp_disable_spdif_out (struct snd_cs46xx *chip);
97 int cs46xx_dsp_enable_spdif_in (struct snd_cs46xx *chip);
98 int cs46xx_dsp_disable_spdif_in (struct snd_cs46xx *chip);
99 int cs46xx_dsp_enable_pcm_capture (struct snd_cs46xx *chip);
100 int cs46xx_dsp_disable_pcm_capture (struct snd_cs46xx *chip);
101 int cs46xx_dsp_enable_adc_capture (struct snd_cs46xx *chip);
102 int cs46xx_dsp_disable_adc_capture (struct snd_cs46xx *chip);
103 int cs46xx_poke_via_dsp (struct snd_cs46xx *chip, u32 address, u32 data);
104 struct dsp_scb_descriptor * cs46xx_dsp_create_scb (struct snd_cs46xx *chip, char * name,
105 						   u32 * scb_data, u32 dest);
106 #ifdef CONFIG_SND_PROC_FS
107 void cs46xx_dsp_proc_free_scb_desc (struct dsp_scb_descriptor * scb);
108 void cs46xx_dsp_proc_register_scb_desc (struct snd_cs46xx *chip,
109 					struct dsp_scb_descriptor * scb);
110 #else
111 #define cs46xx_dsp_proc_free_scb_desc(scb)
112 #define cs46xx_dsp_proc_register_scb_desc(chip, scb)
113 #endif
114 struct dsp_scb_descriptor * cs46xx_dsp_create_timing_master_scb (struct snd_cs46xx *chip);
115 struct dsp_scb_descriptor *
116 cs46xx_dsp_create_codec_out_scb(struct snd_cs46xx * chip,
117 				char * codec_name, u16 channel_disp, u16 fifo_addr,
118 				u16 child_scb_addr, u32 dest,
119 				struct dsp_scb_descriptor * parent_scb,
120 				int scb_child_type);
121 struct dsp_scb_descriptor *
122 cs46xx_dsp_create_codec_in_scb(struct snd_cs46xx * chip, char * codec_name,
123 			       u16 channel_disp, u16 fifo_addr,
124 			       u16 sample_buffer_addr, u32 dest,
125 			       struct dsp_scb_descriptor * parent_scb,
126 			       int scb_child_type);
127 void cs46xx_dsp_remove_scb (struct snd_cs46xx *chip,
128 			    struct dsp_scb_descriptor * scb);
129 struct dsp_scb_descriptor *
130 cs46xx_dsp_create_codec_in_scb(struct snd_cs46xx * chip, char * codec_name,
131 			       u16 channel_disp, u16 fifo_addr,
132 			       u16 sample_buffer_addr, u32 dest,
133 			       struct dsp_scb_descriptor * parent_scb,
134 			       int scb_child_type);
135 struct dsp_scb_descriptor *
136 cs46xx_dsp_create_src_task_scb(struct snd_cs46xx * chip, char * scb_name,
137 			       int sample_rate, u16 src_buffer_addr,
138 			       u16 src_delay_buffer_addr, u32 dest,
139 			       struct dsp_scb_descriptor * parent_scb,
140 			       int scb_child_type, int pass_through);
141 struct dsp_scb_descriptor *
142 cs46xx_dsp_create_mix_only_scb(struct snd_cs46xx * chip, char * scb_name,
143 			       u16 mix_buffer_addr, u32 dest,
144 			       struct dsp_scb_descriptor * parent_scb,
145 			       int scb_child_type);
146 
147 struct dsp_scb_descriptor *
148 cs46xx_dsp_create_vari_decimate_scb(struct snd_cs46xx * chip, char * scb_name,
149 				    u16 vari_buffer_addr0, u16 vari_buffer_addr1, u32 dest,
150 				    struct dsp_scb_descriptor * parent_scb,
151 				    int scb_child_type);
152 struct dsp_scb_descriptor *
153 cs46xx_dsp_create_asynch_fg_rx_scb(struct snd_cs46xx * chip, char * scb_name,
154 				   u32 dest, u16 hfg_scb_address, u16 asynch_buffer_address,
155 				   struct dsp_scb_descriptor * parent_scb,
156 				   int scb_child_type);
157 struct dsp_scb_descriptor *
158 cs46xx_dsp_create_spio_write_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest,
159 				 struct dsp_scb_descriptor * parent_scb,
160 				 int scb_child_type);
161 struct dsp_scb_descriptor *
162 cs46xx_dsp_create_mix_to_ostream_scb(struct snd_cs46xx * chip, char * scb_name,
163 				     u16 mix_buffer_addr, u16 writeback_spb, u32 dest,
164 				     struct dsp_scb_descriptor * parent_scb,
165 				     int scb_child_type);
166 struct dsp_scb_descriptor *
167 cs46xx_dsp_create_magic_snoop_scb(struct snd_cs46xx * chip, char * scb_name,
168 				  u32 dest, u16 snoop_buffer_address,
169 				  struct dsp_scb_descriptor * snoop_scb,
170 				  struct dsp_scb_descriptor * parent_scb,
171 				  int scb_child_type);
172 struct dsp_pcm_channel_descriptor *
173 cs46xx_dsp_create_pcm_channel (struct snd_cs46xx * chip, u32 sample_rate,
174 			       void * private_data, u32 hw_dma_addr,
175 			       int pcm_channel_id);
176 void cs46xx_dsp_destroy_pcm_channel (struct snd_cs46xx * chip,
177 				     struct dsp_pcm_channel_descriptor * pcm_channel);
178 int cs46xx_dsp_pcm_unlink (struct snd_cs46xx * chip,
179 			   struct dsp_pcm_channel_descriptor * pcm_channel);
180 int cs46xx_dsp_pcm_link (struct snd_cs46xx * chip,
181 			 struct dsp_pcm_channel_descriptor * pcm_channel);
182 struct dsp_scb_descriptor *
183 cs46xx_add_record_source (struct snd_cs46xx *chip, struct dsp_scb_descriptor * source,
184 			  u16 addr, char * scb_name);
185 int cs46xx_src_unlink(struct snd_cs46xx *chip, struct dsp_scb_descriptor * src);
186 int cs46xx_src_link(struct snd_cs46xx *chip, struct dsp_scb_descriptor * src);
187 int cs46xx_iec958_pre_open (struct snd_cs46xx *chip);
188 int cs46xx_iec958_post_close (struct snd_cs46xx *chip);
189 int cs46xx_dsp_pcm_channel_set_period (struct snd_cs46xx * chip,
190 				       struct dsp_pcm_channel_descriptor * pcm_channel,
191 				       int period_size);
192 int cs46xx_dsp_pcm_ostream_set_period (struct snd_cs46xx * chip, int period_size);
193 int cs46xx_dsp_set_dac_volume (struct snd_cs46xx * chip, u16 left, u16 right);
194 int cs46xx_dsp_set_iec958_volume (struct snd_cs46xx * chip, u16 left, u16 right);
195 #endif /* __CS46XX_LIB_H__ */
196