@@ -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{
@@ -342,6 +431,41 @@ int hda_dsp_pcm_open(struct snd_sof_dev *sdev,
342431}
343432EXPORT_SYMBOL_NS (hda_dsp_pcm_open , "SND_SOC_SOF_INTEL_HDA_COMMON" );
344433
434+ int hda_dsp_compr_open (struct snd_sof_dev * sdev , struct snd_compr_stream * cstream )
435+ {
436+ struct snd_soc_pcm_runtime * rtd = cstream -> private_data ;
437+ struct snd_soc_component * scomp = sdev -> component ;
438+ struct hdac_ext_stream * dsp_stream ;
439+ struct snd_sof_pcm * spcm ;
440+ int direction = cstream -> direction ;
441+
442+ spcm = snd_sof_find_spcm_dai (scomp , rtd );
443+ if (!spcm ) {
444+ dev_err (sdev -> dev , "%s: can't find PCM with DAI ID %d\n" ,
445+ __func__ , rtd -> dai_link -> id );
446+ return - EINVAL ;
447+ }
448+
449+ dsp_stream = hda_dsp_stream_get (sdev , direction , 0 );
450+ if (!dsp_stream ) {
451+ dev_err (sdev -> dev , "%s: no stream available\n" , __func__ );
452+ return - ENODEV ;
453+ }
454+
455+ /* binding compr stream to hda stream */
456+ cstream -> runtime -> private_data = & dsp_stream -> hstream ;
457+
458+ /*
459+ * Reset the llp cache values (they are used for LLP compensation in
460+ * case the counter is not reset)
461+ */
462+ dsp_stream -> pplcllpl = 0 ;
463+ dsp_stream -> pplcllpu = 0 ;
464+
465+ return 0 ;
466+ }
467+ EXPORT_SYMBOL_NS (hda_dsp_compr_open , "SND_SOC_SOF_INTEL_HDA_COMMON" );
468+
345469int hda_dsp_pcm_close (struct snd_sof_dev * sdev ,
346470 struct snd_pcm_substream * substream )
347471{
@@ -361,3 +485,21 @@ int hda_dsp_pcm_close(struct snd_sof_dev *sdev,
361485 return 0 ;
362486}
363487EXPORT_SYMBOL_NS (hda_dsp_pcm_close , "SND_SOC_SOF_INTEL_HDA_COMMON" );
488+
489+ int hda_dsp_compr_close (struct snd_sof_dev * sdev , struct snd_compr_stream * cstream )
490+ {
491+ struct hdac_stream * hstream = cstream -> runtime -> private_data ;
492+ int direction = cstream -> direction ;
493+ int ret ;
494+
495+ ret = hda_dsp_stream_put (sdev , direction , hstream -> stream_tag );
496+ if (ret )
497+ return - ENODEV ;
498+
499+ /* unbinding compress stream to hda stream */
500+ hstream -> cstream = NULL ;
501+ cstream -> runtime -> private_data = NULL ;
502+
503+ return 0 ;
504+ }
505+ EXPORT_SYMBOL_NS (hda_dsp_compr_close , "SND_SOC_SOF_INTEL_HDA_COMMON" );
0 commit comments