ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / sound / pci / cs46xx / cs46xx_lib.h
1 /*
2  *  The driver for the Cirrus Logic's Sound Fusion CS46XX based soundcards
3  *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
4  *
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program; if not, write to the Free Software
18  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19  *
20  */
21
22 #ifndef __CS46XX_LIB_H__
23 #define __CS46XX_LIB_H__
24
25 #define chip_t cs46xx_t
26
27 /*
28  *  constants
29  */
30
31 #define CS46XX_BA0_SIZE           0x1000
32 #define CS46XX_BA1_DATA0_SIZE 0x3000
33 #define CS46XX_BA1_DATA1_SIZE 0x3800
34 #define CS46XX_BA1_PRG_SIZE       0x7000
35 #define CS46XX_BA1_REG_SIZE       0x0100
36
37
38
39 #ifdef CONFIG_SND_CS46XX_NEW_DSP
40 #define CS46XX_MIN_PERIOD_SIZE 1
41 #define CS46XX_MAX_PERIOD_SIZE 1024*1024
42 #else
43 #define CS46XX_MIN_PERIOD_SIZE 2048
44 #define CS46XX_MAX_PERIOD_SIZE 2048
45 #endif
46
47 #define CS46XX_FRAGS 2
48 /* #define CS46XX_BUFFER_SIZE CS46XX_MAX_PERIOD_SIZE * CS46XX_FRAGS */
49
50 #define SCB_NO_PARENT             0
51 #define SCB_ON_PARENT_NEXT_SCB    1
52 #define SCB_ON_PARENT_SUBLIST_SCB 2
53
54 /* 3*1024 parameter, 3.5*1024 sample, 2*3.5*1024 code */
55 #define BA1_DWORD_SIZE          (13 * 1024 + 512)
56 #define BA1_MEMORY_COUNT        3
57
58 extern snd_pcm_ops_t snd_cs46xx_playback_ops;
59 extern snd_pcm_ops_t snd_cs46xx_playback_indirect_ops;
60 extern snd_pcm_ops_t snd_cs46xx_capture_ops;
61 extern snd_pcm_ops_t snd_cs46xx_capture_indirect_ops;
62 extern snd_pcm_ops_t snd_cs46xx_playback_rear_ops;
63 extern snd_pcm_ops_t snd_cs46xx_playback_indirect_rear_ops;
64 extern snd_pcm_ops_t snd_cs46xx_playback_iec958_ops;
65 extern snd_pcm_ops_t snd_cs46xx_playback_indirect_iec958_ops;
66 extern snd_pcm_ops_t snd_cs46xx_playback_clfe_ops;
67 extern snd_pcm_ops_t snd_cs46xx_playback_indirect_clfe_ops;
68
69
70 /*
71  *  common I/O routines
72  */
73
74 static inline void snd_cs46xx_poke(cs46xx_t *chip, unsigned long reg, unsigned int val)
75 {
76         unsigned int bank = reg >> 16;
77         unsigned int offset = reg & 0xffff;
78
79         /*if (bank == 0) printk("snd_cs46xx_poke: %04X - %08X\n",reg >> 2,val); */
80         writel(val, chip->region.idx[bank+1].remap_addr + offset);
81 }
82
83 static inline unsigned int snd_cs46xx_peek(cs46xx_t *chip, unsigned long reg)
84 {
85         unsigned int bank = reg >> 16;
86         unsigned int offset = reg & 0xffff;
87         return readl(chip->region.idx[bank+1].remap_addr + offset);
88 }
89
90 static inline void snd_cs46xx_pokeBA0(cs46xx_t *chip, unsigned long offset, unsigned int val)
91 {
92         writel(val, chip->region.name.ba0.remap_addr + offset);
93 }
94
95 static inline unsigned int snd_cs46xx_peekBA0(cs46xx_t *chip, unsigned long offset)
96 {
97         return readl(chip->region.name.ba0.remap_addr + offset);
98 }
99
100 dsp_spos_instance_t *  cs46xx_dsp_spos_create (cs46xx_t * chip);
101 void                   cs46xx_dsp_spos_destroy (cs46xx_t * chip);
102 int                    cs46xx_dsp_load_module (cs46xx_t * chip,dsp_module_desc_t * module);
103 symbol_entry_t *       cs46xx_dsp_lookup_symbol (cs46xx_t * chip,char * symbol_name,int symbol_type);
104 symbol_entry_t *       cs46xx_dsp_lookup_symbol_addr (cs46xx_t * chip,u32 address,int symbol_type);
105 int                    cs46xx_dsp_proc_init (snd_card_t * card, cs46xx_t *chip);
106 int                    cs46xx_dsp_proc_done (cs46xx_t *chip);
107 int                    cs46xx_dsp_scb_and_task_init (cs46xx_t *chip);
108 int                    cs46xx_dsp_async_init (cs46xx_t *chip,dsp_scb_descriptor_t * fg_entry);
109 int                    snd_cs46xx_download (cs46xx_t *chip,u32 *src,unsigned long offset,
110                                             unsigned long len);
111 int                    snd_cs46xx_clear_BA1(cs46xx_t *chip,unsigned long offset,unsigned long len);
112 int                    cs46xx_dsp_enable_spdif_out (cs46xx_t *chip);
113 int                    cs46xx_dsp_enable_spdif_hw (cs46xx_t *chip);
114 int                    cs46xx_dsp_disable_spdif_out (cs46xx_t *chip);
115 int                    cs46xx_dsp_enable_spdif_in (cs46xx_t *chip);
116 int                    cs46xx_dsp_disable_spdif_in (cs46xx_t *chip);
117 int                    cs46xx_dsp_enable_pcm_capture (cs46xx_t *chip);
118 int                    cs46xx_dsp_disable_pcm_capture (cs46xx_t *chip);
119 int                    cs46xx_dsp_enable_adc_capture (cs46xx_t *chip);
120 int                    cs46xx_dsp_disable_adc_capture (cs46xx_t *chip);
121 int                    cs46xx_poke_via_dsp (cs46xx_t *chip,u32 address,u32 data);
122 dsp_scb_descriptor_t * cs46xx_dsp_create_scb (cs46xx_t *chip,char * name, u32 * scb_data,u32 dest);
123 void                   cs46xx_dsp_proc_free_scb_desc (dsp_scb_descriptor_t * scb);
124 void                   cs46xx_dsp_proc_register_scb_desc (cs46xx_t *chip,dsp_scb_descriptor_t * scb);
125 dsp_task_descriptor_t * cs46xx_dsp_create_task_tree (cs46xx_t *chip,char * name, 
126                                                      u32 * task_data,u32 dest,int size);
127 dsp_scb_descriptor_t * cs46xx_dsp_create_timing_master_scb (cs46xx_t *chip);
128 dsp_scb_descriptor_t * cs46xx_dsp_create_codec_out_scb(cs46xx_t * chip,char * codec_name,
129                                                        u16 channel_disp,u16 fifo_addr,
130                                                        u16 child_scb_addr,
131                                                        u32 dest,
132                                                        dsp_scb_descriptor_t * parent_scb,
133                                                        int scb_child_type);
134 dsp_scb_descriptor_t * cs46xx_dsp_create_codec_in_scb(cs46xx_t * chip,char * codec_name,
135                                                       u16 channel_disp,u16 fifo_addr,
136                                                       u16 sample_buffer_addr,
137                                                       u32 dest,
138                                                       dsp_scb_descriptor_t * parent_scb,
139                                                       int scb_child_type);
140 void                   cs46xx_dsp_remove_scb (cs46xx_t *chip,dsp_scb_descriptor_t * scb);
141 dsp_scb_descriptor_t * cs46xx_dsp_create_generic_scb (cs46xx_t *chip,char * name, 
142                                                       u32 * scb_data,u32 dest,
143                                                       char * task_entry_name,
144                                                       dsp_scb_descriptor_t * parent_scb,
145                                                       int scb_child_type);
146 dsp_scb_descriptor_t *  cs46xx_dsp_create_codec_in_scb(cs46xx_t * chip,char * codec_name,
147                                                        u16 channel_disp,u16 fifo_addr,
148                                                        u16 sample_buffer_addr,
149                                                        u32 dest,dsp_scb_descriptor_t * parent_scb,
150                                                        int scb_child_type);
151 dsp_scb_descriptor_t * cs46xx_dsp_create_pcm_reader_scb(cs46xx_t * chip,char * scb_name,
152                                                         u16 sample_buffer_addr,u32 dest,
153                                                         int virtual_channel,u32 playback_hw_addr,
154                                                         dsp_scb_descriptor_t * parent_scb,
155                                                         int scb_child_type);
156 dsp_scb_descriptor_t *  cs46xx_dsp_create_src_task_scb(cs46xx_t * chip,char * scb_name,
157                                                        int sample_rate,
158                                                        u16 src_buffer_addr,
159                                                        u16 src_delay_buffer_addr,u32 dest,
160                                                        dsp_scb_descriptor_t * parent_scb,
161                                                        int scb_child_type,
162                                                        int pass_through);
163 dsp_scb_descriptor_t *  cs46xx_dsp_create_mix_only_scb(cs46xx_t * chip,char * scb_name,
164                                                        u16 mix_buffer_addr,u32 dest,
165                                                        dsp_scb_descriptor_t * parent_scb,
166                                                        int scb_child_type);
167
168 dsp_scb_descriptor_t *  cs46xx_dsp_create_vari_decimate_scb(cs46xx_t * chip,char * scb_name,
169                                                             u16 vari_buffer_addr0,
170                                                             u16 vari_buffer_addr1,
171                                                             u32 dest,
172                                                             dsp_scb_descriptor_t * parent_scb,
173                                                             int scb_child_type);
174 dsp_scb_descriptor_t *  cs46xx_dsp_create_pcm_serial_input_scb(cs46xx_t * chip,char * scb_name,u32 dest,
175                                                                dsp_scb_descriptor_t * input_scb,
176                                                                dsp_scb_descriptor_t * parent_scb,
177                                                                int scb_child_type);
178 dsp_scb_descriptor_t * cs46xx_dsp_create_asynch_fg_tx_scb(cs46xx_t * chip,char * scb_name,u32 dest,
179                                                           u16 hfg_scb_address,
180                                                           u16 asynch_buffer_address,
181                                                           dsp_scb_descriptor_t * parent_scb,
182                                                           int scb_child_type);
183 dsp_scb_descriptor_t * cs46xx_dsp_create_asynch_fg_rx_scb(cs46xx_t * chip,char * scb_name,u32 dest,
184                                                           u16 hfg_scb_address,
185                                                           u16 asynch_buffer_address,
186                                                           dsp_scb_descriptor_t * parent_scb,
187                                                           int scb_child_type);
188 dsp_scb_descriptor_t *  cs46xx_dsp_create_spio_write_scb(cs46xx_t * chip,char * scb_name,u32 dest,
189                                                          dsp_scb_descriptor_t * parent_scb,
190                                                          int scb_child_type);
191 dsp_scb_descriptor_t *  cs46xx_dsp_create_mix_to_ostream_scb(cs46xx_t * chip,char * scb_name,
192                                                              u16 mix_buffer_addr,u16 writeback_spb,u32 dest,
193                                                              dsp_scb_descriptor_t * parent_scb,
194                                                              int scb_child_type);
195 dsp_scb_descriptor_t *  cs46xx_dsp_create_output_snoop_scb(cs46xx_t * chip,char * scb_name,u32 dest,
196                                                            u16 snoop_buffer_address,
197                                                            dsp_scb_descriptor_t * snoop_scb,
198                                                            dsp_scb_descriptor_t * parent_scb,
199                                                            int scb_child_type);
200 dsp_scb_descriptor_t *  cs46xx_dsp_create_magic_snoop_scb(cs46xx_t * chip,char * scb_name,u32 dest,
201                                                           u16 snoop_buffer_address,
202                                                           dsp_scb_descriptor_t * snoop_scb,
203                                                           dsp_scb_descriptor_t * parent_scb,
204                                                           int scb_child_type);
205 pcm_channel_descriptor_t * cs46xx_dsp_create_pcm_channel (cs46xx_t * chip,u32 sample_rate, void * private_data, u32 hw_dma_addr,
206                                                           int pcm_channel_id);
207 void                       cs46xx_dsp_destroy_pcm_channel (cs46xx_t * chip,
208                                                            pcm_channel_descriptor_t * pcm_channel);
209 int                        cs46xx_dsp_pcm_unlink (cs46xx_t * chip,pcm_channel_descriptor_t * pcm_channel);
210 int                        cs46xx_dsp_pcm_link (cs46xx_t * chip,pcm_channel_descriptor_t * pcm_channel);
211 dsp_scb_descriptor_t *     cs46xx_add_record_source (cs46xx_t *chip,dsp_scb_descriptor_t * source,
212                                                      u16 addr,char * scb_name);
213 int                        cs46xx_src_unlink(cs46xx_t *chip,dsp_scb_descriptor_t * src);
214 int                        cs46xx_src_link(cs46xx_t *chip,dsp_scb_descriptor_t * src);
215 int                        cs46xx_iec958_pre_open (cs46xx_t *chip);
216 int                        cs46xx_iec958_post_close (cs46xx_t *chip);
217 int                        cs46xx_dsp_pcm_channel_set_period (cs46xx_t * chip,
218                                                                pcm_channel_descriptor_t * pcm_channel,
219                                                                int period_size);
220 int                        cs46xx_dsp_pcm_ostream_set_period (cs46xx_t * chip,
221                                                               int period_size);
222 int                        cs46xx_dsp_set_dac_volume (cs46xx_t * chip,u16 left,u16 right);
223 int                        cs46xx_dsp_set_iec958_volume (cs46xx_t * chip,u16 left,u16 right);
224 #endif /* __CS46XX_LIB_H__ */