vserver 1.9.3
[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 /*
26  *  constants
27  */
28
29 #define CS46XX_BA0_SIZE           0x1000
30 #define CS46XX_BA1_DATA0_SIZE 0x3000
31 #define CS46XX_BA1_DATA1_SIZE 0x3800
32 #define CS46XX_BA1_PRG_SIZE       0x7000
33 #define CS46XX_BA1_REG_SIZE       0x0100
34
35
36
37 #ifdef CONFIG_SND_CS46XX_NEW_DSP
38 #define CS46XX_MIN_PERIOD_SIZE 1
39 #define CS46XX_MAX_PERIOD_SIZE 1024*1024
40 #else
41 #define CS46XX_MIN_PERIOD_SIZE 2048
42 #define CS46XX_MAX_PERIOD_SIZE 2048
43 #endif
44
45 #define CS46XX_FRAGS 2
46 /* #define CS46XX_BUFFER_SIZE CS46XX_MAX_PERIOD_SIZE * CS46XX_FRAGS */
47
48 #define SCB_NO_PARENT             0
49 #define SCB_ON_PARENT_NEXT_SCB    1
50 #define SCB_ON_PARENT_SUBLIST_SCB 2
51
52 /* 3*1024 parameter, 3.5*1024 sample, 2*3.5*1024 code */
53 #define BA1_DWORD_SIZE          (13 * 1024 + 512)
54 #define BA1_MEMORY_COUNT        3
55
56 extern snd_pcm_ops_t snd_cs46xx_playback_ops;
57 extern snd_pcm_ops_t snd_cs46xx_playback_indirect_ops;
58 extern snd_pcm_ops_t snd_cs46xx_capture_ops;
59 extern snd_pcm_ops_t snd_cs46xx_capture_indirect_ops;
60 extern snd_pcm_ops_t snd_cs46xx_playback_rear_ops;
61 extern snd_pcm_ops_t snd_cs46xx_playback_indirect_rear_ops;
62 extern snd_pcm_ops_t snd_cs46xx_playback_iec958_ops;
63 extern snd_pcm_ops_t snd_cs46xx_playback_indirect_iec958_ops;
64 extern snd_pcm_ops_t snd_cs46xx_playback_clfe_ops;
65 extern snd_pcm_ops_t snd_cs46xx_playback_indirect_clfe_ops;
66
67
68 /*
69  *  common I/O routines
70  */
71
72 static inline void snd_cs46xx_poke(cs46xx_t *chip, unsigned long reg, unsigned int val)
73 {
74         unsigned int bank = reg >> 16;
75         unsigned int offset = reg & 0xffff;
76
77         /*if (bank == 0) printk("snd_cs46xx_poke: %04X - %08X\n",reg >> 2,val); */
78         writel(val, chip->region.idx[bank+1].remap_addr + offset);
79 }
80
81 static inline unsigned int snd_cs46xx_peek(cs46xx_t *chip, unsigned long reg)
82 {
83         unsigned int bank = reg >> 16;
84         unsigned int offset = reg & 0xffff;
85         return readl(chip->region.idx[bank+1].remap_addr + offset);
86 }
87
88 static inline void snd_cs46xx_pokeBA0(cs46xx_t *chip, unsigned long offset, unsigned int val)
89 {
90         writel(val, chip->region.name.ba0.remap_addr + offset);
91 }
92
93 static inline unsigned int snd_cs46xx_peekBA0(cs46xx_t *chip, unsigned long offset)
94 {
95         return readl(chip->region.name.ba0.remap_addr + offset);
96 }
97
98 dsp_spos_instance_t *  cs46xx_dsp_spos_create (cs46xx_t * chip);
99 void                   cs46xx_dsp_spos_destroy (cs46xx_t * chip);
100 int                    cs46xx_dsp_load_module (cs46xx_t * chip,dsp_module_desc_t * module);
101 symbol_entry_t *       cs46xx_dsp_lookup_symbol (cs46xx_t * chip,char * symbol_name,int symbol_type);
102 symbol_entry_t *       cs46xx_dsp_lookup_symbol_addr (cs46xx_t * chip,u32 address,int symbol_type);
103 int                    cs46xx_dsp_proc_init (snd_card_t * card, cs46xx_t *chip);
104 int                    cs46xx_dsp_proc_done (cs46xx_t *chip);
105 int                    cs46xx_dsp_scb_and_task_init (cs46xx_t *chip);
106 int                    cs46xx_dsp_async_init (cs46xx_t *chip,dsp_scb_descriptor_t * fg_entry);
107 int                    snd_cs46xx_download (cs46xx_t *chip,u32 *src,unsigned long offset,
108                                             unsigned long len);
109 int                    snd_cs46xx_clear_BA1(cs46xx_t *chip,unsigned long offset,unsigned long len);
110 int                    cs46xx_dsp_enable_spdif_out (cs46xx_t *chip);
111 int                    cs46xx_dsp_enable_spdif_hw (cs46xx_t *chip);
112 int                    cs46xx_dsp_disable_spdif_out (cs46xx_t *chip);
113 int                    cs46xx_dsp_enable_spdif_in (cs46xx_t *chip);
114 int                    cs46xx_dsp_disable_spdif_in (cs46xx_t *chip);
115 int                    cs46xx_dsp_enable_pcm_capture (cs46xx_t *chip);
116 int                    cs46xx_dsp_disable_pcm_capture (cs46xx_t *chip);
117 int                    cs46xx_dsp_enable_adc_capture (cs46xx_t *chip);
118 int                    cs46xx_dsp_disable_adc_capture (cs46xx_t *chip);
119 int                    cs46xx_poke_via_dsp (cs46xx_t *chip,u32 address,u32 data);
120 dsp_scb_descriptor_t * cs46xx_dsp_create_scb (cs46xx_t *chip,char * name, u32 * scb_data,u32 dest);
121 void                   cs46xx_dsp_proc_free_scb_desc (dsp_scb_descriptor_t * scb);
122 void                   cs46xx_dsp_proc_register_scb_desc (cs46xx_t *chip,dsp_scb_descriptor_t * scb);
123 dsp_task_descriptor_t * cs46xx_dsp_create_task_tree (cs46xx_t *chip,char * name, 
124                                                      u32 * task_data,u32 dest,int size);
125 dsp_scb_descriptor_t * cs46xx_dsp_create_timing_master_scb (cs46xx_t *chip);
126 dsp_scb_descriptor_t * cs46xx_dsp_create_codec_out_scb(cs46xx_t * chip,char * codec_name,
127                                                        u16 channel_disp,u16 fifo_addr,
128                                                        u16 child_scb_addr,
129                                                        u32 dest,
130                                                        dsp_scb_descriptor_t * parent_scb,
131                                                        int scb_child_type);
132 dsp_scb_descriptor_t * cs46xx_dsp_create_codec_in_scb(cs46xx_t * chip,char * codec_name,
133                                                       u16 channel_disp,u16 fifo_addr,
134                                                       u16 sample_buffer_addr,
135                                                       u32 dest,
136                                                       dsp_scb_descriptor_t * parent_scb,
137                                                       int scb_child_type);
138 void                   cs46xx_dsp_remove_scb (cs46xx_t *chip,dsp_scb_descriptor_t * scb);
139 dsp_scb_descriptor_t * cs46xx_dsp_create_generic_scb (cs46xx_t *chip,char * name, 
140                                                       u32 * scb_data,u32 dest,
141                                                       char * task_entry_name,
142                                                       dsp_scb_descriptor_t * parent_scb,
143                                                       int scb_child_type);
144 dsp_scb_descriptor_t *  cs46xx_dsp_create_codec_in_scb(cs46xx_t * chip,char * codec_name,
145                                                        u16 channel_disp,u16 fifo_addr,
146                                                        u16 sample_buffer_addr,
147                                                        u32 dest,dsp_scb_descriptor_t * parent_scb,
148                                                        int scb_child_type);
149 dsp_scb_descriptor_t * cs46xx_dsp_create_pcm_reader_scb(cs46xx_t * chip,char * scb_name,
150                                                         u16 sample_buffer_addr,u32 dest,
151                                                         int virtual_channel,u32 playback_hw_addr,
152                                                         dsp_scb_descriptor_t * parent_scb,
153                                                         int scb_child_type);
154 dsp_scb_descriptor_t *  cs46xx_dsp_create_src_task_scb(cs46xx_t * chip,char * scb_name,
155                                                        int sample_rate,
156                                                        u16 src_buffer_addr,
157                                                        u16 src_delay_buffer_addr,u32 dest,
158                                                        dsp_scb_descriptor_t * parent_scb,
159                                                        int scb_child_type,
160                                                        int pass_through);
161 dsp_scb_descriptor_t *  cs46xx_dsp_create_mix_only_scb(cs46xx_t * chip,char * scb_name,
162                                                        u16 mix_buffer_addr,u32 dest,
163                                                        dsp_scb_descriptor_t * parent_scb,
164                                                        int scb_child_type);
165
166 dsp_scb_descriptor_t *  cs46xx_dsp_create_vari_decimate_scb(cs46xx_t * chip,char * scb_name,
167                                                             u16 vari_buffer_addr0,
168                                                             u16 vari_buffer_addr1,
169                                                             u32 dest,
170                                                             dsp_scb_descriptor_t * parent_scb,
171                                                             int scb_child_type);
172 dsp_scb_descriptor_t *  cs46xx_dsp_create_pcm_serial_input_scb(cs46xx_t * chip,char * scb_name,u32 dest,
173                                                                dsp_scb_descriptor_t * input_scb,
174                                                                dsp_scb_descriptor_t * parent_scb,
175                                                                int scb_child_type);
176 dsp_scb_descriptor_t * cs46xx_dsp_create_asynch_fg_tx_scb(cs46xx_t * chip,char * scb_name,u32 dest,
177                                                           u16 hfg_scb_address,
178                                                           u16 asynch_buffer_address,
179                                                           dsp_scb_descriptor_t * parent_scb,
180                                                           int scb_child_type);
181 dsp_scb_descriptor_t * cs46xx_dsp_create_asynch_fg_rx_scb(cs46xx_t * chip,char * scb_name,u32 dest,
182                                                           u16 hfg_scb_address,
183                                                           u16 asynch_buffer_address,
184                                                           dsp_scb_descriptor_t * parent_scb,
185                                                           int scb_child_type);
186 dsp_scb_descriptor_t *  cs46xx_dsp_create_spio_write_scb(cs46xx_t * chip,char * scb_name,u32 dest,
187                                                          dsp_scb_descriptor_t * parent_scb,
188                                                          int scb_child_type);
189 dsp_scb_descriptor_t *  cs46xx_dsp_create_mix_to_ostream_scb(cs46xx_t * chip,char * scb_name,
190                                                              u16 mix_buffer_addr,u16 writeback_spb,u32 dest,
191                                                              dsp_scb_descriptor_t * parent_scb,
192                                                              int scb_child_type);
193 dsp_scb_descriptor_t *  cs46xx_dsp_create_output_snoop_scb(cs46xx_t * chip,char * scb_name,u32 dest,
194                                                            u16 snoop_buffer_address,
195                                                            dsp_scb_descriptor_t * snoop_scb,
196                                                            dsp_scb_descriptor_t * parent_scb,
197                                                            int scb_child_type);
198 dsp_scb_descriptor_t *  cs46xx_dsp_create_magic_snoop_scb(cs46xx_t * chip,char * scb_name,u32 dest,
199                                                           u16 snoop_buffer_address,
200                                                           dsp_scb_descriptor_t * snoop_scb,
201                                                           dsp_scb_descriptor_t * parent_scb,
202                                                           int scb_child_type);
203 pcm_channel_descriptor_t * cs46xx_dsp_create_pcm_channel (cs46xx_t * chip,u32 sample_rate, void * private_data, u32 hw_dma_addr,
204                                                           int pcm_channel_id);
205 void                       cs46xx_dsp_destroy_pcm_channel (cs46xx_t * chip,
206                                                            pcm_channel_descriptor_t * pcm_channel);
207 int                        cs46xx_dsp_pcm_unlink (cs46xx_t * chip,pcm_channel_descriptor_t * pcm_channel);
208 int                        cs46xx_dsp_pcm_link (cs46xx_t * chip,pcm_channel_descriptor_t * pcm_channel);
209 dsp_scb_descriptor_t *     cs46xx_add_record_source (cs46xx_t *chip,dsp_scb_descriptor_t * source,
210                                                      u16 addr,char * scb_name);
211 int                        cs46xx_src_unlink(cs46xx_t *chip,dsp_scb_descriptor_t * src);
212 int                        cs46xx_src_link(cs46xx_t *chip,dsp_scb_descriptor_t * src);
213 int                        cs46xx_iec958_pre_open (cs46xx_t *chip);
214 int                        cs46xx_iec958_post_close (cs46xx_t *chip);
215 int                        cs46xx_dsp_pcm_channel_set_period (cs46xx_t * chip,
216                                                                pcm_channel_descriptor_t * pcm_channel,
217                                                                int period_size);
218 int                        cs46xx_dsp_pcm_ostream_set_period (cs46xx_t * chip,
219                                                               int period_size);
220 int                        cs46xx_dsp_set_dac_volume (cs46xx_t * chip,u16 left,u16 right);
221 int                        cs46xx_dsp_set_iec958_volume (cs46xx_t * chip,u16 left,u16 right);
222 #endif /* __CS46XX_LIB_H__ */