@@ -151,6 +151,71 @@ int hda_dsp_pcm_hw_params(struct snd_sof_dev *sdev,
151151}
152152EXPORT_SYMBOL_NS (hda_dsp_pcm_hw_params , "SND_SOC_SOF_INTEL_HDA_COMMON" );
153153
154+ int hda_dsp_compr_hw_params (struct snd_sof_dev * sdev ,
155+ struct snd_compr_stream * cstream ,
156+ struct snd_compr_params * params ,
157+ struct snd_sof_platform_stream_params * platform_params )
158+ {
159+ struct hdac_stream * hstream = cstream -> runtime -> private_data ;
160+ struct hdac_ext_stream * hext_stream = stream_to_hdac_ext_stream (hstream );
161+ struct sof_intel_hda_dev * hda = sdev -> pdata -> hw_pdata ;
162+ struct snd_dma_buffer * dmab ;
163+ u32 bits , rate ;
164+ int bps ;
165+ int ret ;
166+
167+ hstream -> cstream = cstream ;
168+ dmab = cstream -> runtime -> dma_buffer_p ;
169+
170+ /* Use correct format based on the used codec */
171+ switch (params -> codec .id ) {
172+ case SND_AUDIOCODEC_PCM :
173+ bps = snd_pcm_format_physical_width (params -> codec .format );
174+ break ;
175+ case SND_AUDIOCODEC_VORBIS :
176+ bps = snd_pcm_format_physical_width (SNDRV_PCM_FORMAT_S16_LE );
177+ break ;
178+ case SND_AUDIOCODEC_FLAC :
179+ {
180+ struct snd_dec_flac * dec_flac = & params -> codec .options .flac_d ;
181+
182+ if (dec_flac -> sample_size == 16 )
183+ bps = snd_pcm_format_physical_width (SNDRV_PCM_FORMAT_S16_LE );
184+ else
185+ bps = snd_pcm_format_physical_width (SNDRV_PCM_FORMAT_S32_LE );
186+ break ;
187+ }
188+ default :
189+ bps = snd_pcm_format_physical_width (SNDRV_PCM_FORMAT_S32_LE );
190+ }
191+
192+ if (bps < 0 )
193+ return bps ;
194+ bits = hda_dsp_get_bits (sdev , bps );
195+ rate = hda_dsp_get_mult_div (sdev , params -> codec .sample_rate );
196+
197+ hstream -> format_val = rate | bits | (params -> codec .ch_out - 1 );
198+ hstream -> bufsize = cstream -> runtime -> buffer_size ;
199+ hstream -> period_bytes = cstream -> runtime -> fragment_size ;
200+ hstream -> no_period_wakeup = false;
201+
202+ /* params is not used so pass NULL */
203+ dmab = cstream -> runtime -> dma_buffer_p ;
204+ ret = hda_dsp_stream_hw_params (sdev , hext_stream , dmab , NULL );
205+ if (ret < 0 ) {
206+ dev_err (sdev -> dev , "%s: hdac prepare failed: %d\n" , __func__ , ret );
207+ return ret ;
208+ }
209+
210+ if (hda )
211+ platform_params -> no_ipc_position = hda -> no_ipc_position ;
212+
213+ platform_params -> stream_tag = hstream -> stream_tag ;
214+
215+ return 0 ;
216+ }
217+ EXPORT_SYMBOL_NS (hda_dsp_compr_hw_params , "SND_SOC_SOF_INTEL_HDA_COMMON" );
218+
154219/* update SPIB register with appl position */
155220int hda_dsp_pcm_ack (struct snd_sof_dev * sdev , struct snd_pcm_substream * substream )
156221{
@@ -184,6 +249,16 @@ int hda_dsp_pcm_trigger(struct snd_sof_dev *sdev,
184249}
185250EXPORT_SYMBOL_NS (hda_dsp_pcm_trigger , "SND_SOC_SOF_INTEL_HDA_COMMON" );
186251
252+ int hda_dsp_compr_trigger (struct snd_sof_dev * sdev ,
253+ struct snd_compr_stream * cstream , int cmd )
254+ {
255+ struct hdac_stream * hstream = cstream -> runtime -> private_data ;
256+ struct hdac_ext_stream * hext_stream = stream_to_hdac_ext_stream (hstream );
257+
258+ return hda_dsp_stream_trigger (sdev , hext_stream , cmd );
259+ }
260+ EXPORT_SYMBOL_NS (hda_dsp_compr_trigger , "SND_SOC_SOF_INTEL_HDA_COMMON" );
261+
187262snd_pcm_uframes_t hda_dsp_pcm_pointer (struct snd_sof_dev * sdev ,
188263 struct snd_pcm_substream * substream )
189264{
@@ -216,6 +291,20 @@ snd_pcm_uframes_t hda_dsp_pcm_pointer(struct snd_sof_dev *sdev,
216291}
217292EXPORT_SYMBOL_NS (hda_dsp_pcm_pointer , "SND_SOC_SOF_INTEL_HDA_COMMON" );
218293
294+ int hda_dsp_compr_pointer (struct snd_sof_dev * sdev , struct snd_compr_stream * cstream ,
295+ struct snd_compr_tstamp64 * tstamp )
296+ {
297+ struct hdac_stream * hstream = cstream -> runtime -> private_data ;
298+
299+ /* hstream->curr_pos is updated when we receive the ioc */
300+ tstamp -> copied_total += hstream -> curr_pos ;
301+
302+ tstamp -> byte_offset = hda_dsp_stream_get_position (hstream , cstream -> direction , true);
303+
304+ return 0 ;
305+ }
306+ EXPORT_SYMBOL_NS (hda_dsp_compr_pointer , "SND_SOC_SOF_INTEL_HDA_COMMON" );
307+
219308int hda_dsp_pcm_open (struct snd_sof_dev * sdev ,
220309 struct snd_pcm_substream * substream )
221310{
@@ -332,6 +421,41 @@ int hda_dsp_pcm_open(struct snd_sof_dev *sdev,
332421}
333422EXPORT_SYMBOL_NS (hda_dsp_pcm_open , "SND_SOC_SOF_INTEL_HDA_COMMON" );
334423
424+ int hda_dsp_compr_open (struct snd_sof_dev * sdev , struct snd_compr_stream * cstream )
425+ {
426+ struct snd_soc_pcm_runtime * rtd = cstream -> private_data ;
427+ struct snd_soc_component * scomp = sdev -> component ;
428+ struct hdac_ext_stream * dsp_stream ;
429+ struct snd_sof_pcm * spcm ;
430+ int direction = cstream -> direction ;
431+
432+ spcm = snd_sof_find_spcm_dai (scomp , rtd );
433+ if (!spcm ) {
434+ dev_err (sdev -> dev , "%s: can't find PCM with DAI ID %d\n" ,
435+ __func__ , rtd -> dai_link -> id );
436+ return - EINVAL ;
437+ }
438+
439+ dsp_stream = hda_dsp_stream_get (sdev , direction , 0 );
440+ if (!dsp_stream ) {
441+ dev_err (sdev -> dev , "%s: no stream available\n" , __func__ );
442+ return - ENODEV ;
443+ }
444+
445+ /* binding compr stream to hda stream */
446+ cstream -> runtime -> private_data = & dsp_stream -> hstream ;
447+
448+ /*
449+ * Reset the llp cache values (they are used for LLP compensation in
450+ * case the counter is not reset)
451+ */
452+ dsp_stream -> pplcllpl = 0 ;
453+ dsp_stream -> pplcllpu = 0 ;
454+
455+ return 0 ;
456+ }
457+ EXPORT_SYMBOL_NS (hda_dsp_compr_open , "SND_SOC_SOF_INTEL_HDA_COMMON" );
458+
335459int hda_dsp_pcm_close (struct snd_sof_dev * sdev ,
336460 struct snd_pcm_substream * substream )
337461{
@@ -351,3 +475,20 @@ int hda_dsp_pcm_close(struct snd_sof_dev *sdev,
351475 return 0 ;
352476}
353477EXPORT_SYMBOL_NS (hda_dsp_pcm_close , "SND_SOC_SOF_INTEL_HDA_COMMON" );
478+
479+ int hda_dsp_compr_close (struct snd_sof_dev * sdev , struct snd_compr_stream * cstream )
480+ {
481+ struct hdac_stream * hstream = cstream -> runtime -> private_data ;
482+ int direction = cstream -> direction ;
483+ int ret ;
484+
485+ ret = hda_dsp_stream_put (sdev , direction , hstream -> stream_tag );
486+ if (ret )
487+ return - ENODEV ;
488+
489+ /* unbinding compress stream to hda stream */
490+ hstream -> cstream = NULL ;
491+ cstream -> runtime -> private_data = NULL ;
492+ return 0 ;
493+ }
494+ EXPORT_SYMBOL_NS (hda_dsp_compr_close , "SND_SOC_SOF_INTEL_HDA_COMMON" );
0 commit comments