rt1308-sdw.c (cecdd52a3dd312564f81a39df08378b7b39a2654) rt1308-sdw.c (ce8ffc1bac7bee5015eb68faf214b39fcbd65d15)
1// SPDX-License-Identifier: GPL-2.0
2//
3// rt1308-sdw.c -- rt1308 ALSA SoC audio driver
4//
5// Copyright(c) 2019 Realtek Semiconductor Corp.
6//
7//
8#include <linux/delay.h>

--- 482 unchanged lines hidden (view full) ---

491 { "CLASS D", NULL, "DAC R" },
492 { "SPOL", NULL, "CLASS D" },
493 { "SPOR", NULL, "CLASS D" },
494};
495
496static int rt1308_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream,
497 int direction)
498{
1// SPDX-License-Identifier: GPL-2.0
2//
3// rt1308-sdw.c -- rt1308 ALSA SoC audio driver
4//
5// Copyright(c) 2019 Realtek Semiconductor Corp.
6//
7//
8#include <linux/delay.h>

--- 482 unchanged lines hidden (view full) ---

491 { "CLASS D", NULL, "DAC R" },
492 { "SPOL", NULL, "CLASS D" },
493 { "SPOR", NULL, "CLASS D" },
494};
495
496static int rt1308_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream,
497 int direction)
498{
499 struct sdw_stream_data *stream;
499 snd_soc_dai_dma_data_set(dai, direction, sdw_stream);
500
500
501 if (!sdw_stream)
502 return 0;
503
504 stream = kzalloc(sizeof(*stream), GFP_KERNEL);
505 if (!stream)
506 return -ENOMEM;
507
508 stream->sdw_stream = sdw_stream;
509
510 /* Use tx_mask or rx_mask to configure stream tag and set dma_data */
511 snd_soc_dai_dma_data_set(dai, direction, stream);
512
513 return 0;
514}
515
516static void rt1308_sdw_shutdown(struct snd_pcm_substream *substream,
517 struct snd_soc_dai *dai)
518{
501 return 0;
502}
503
504static void rt1308_sdw_shutdown(struct snd_pcm_substream *substream,
505 struct snd_soc_dai *dai)
506{
519 struct sdw_stream_data *stream;
520
521 stream = snd_soc_dai_get_dma_data(dai, substream);
522 snd_soc_dai_set_dma_data(dai, substream, NULL);
507 snd_soc_dai_set_dma_data(dai, substream, NULL);
523 kfree(stream);
524}
525
526static int rt1308_sdw_set_tdm_slot(struct snd_soc_dai *dai,
527 unsigned int tx_mask,
528 unsigned int rx_mask,
529 int slots, int slot_width)
530{
531 struct snd_soc_component *component = dai->component;

--- 16 unchanged lines hidden (view full) ---

548static int rt1308_sdw_hw_params(struct snd_pcm_substream *substream,
549 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
550{
551 struct snd_soc_component *component = dai->component;
552 struct rt1308_sdw_priv *rt1308 =
553 snd_soc_component_get_drvdata(component);
554 struct sdw_stream_config stream_config = {0};
555 struct sdw_port_config port_config = {0};
508}
509
510static int rt1308_sdw_set_tdm_slot(struct snd_soc_dai *dai,
511 unsigned int tx_mask,
512 unsigned int rx_mask,
513 int slots, int slot_width)
514{
515 struct snd_soc_component *component = dai->component;

--- 16 unchanged lines hidden (view full) ---

532static int rt1308_sdw_hw_params(struct snd_pcm_substream *substream,
533 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
534{
535 struct snd_soc_component *component = dai->component;
536 struct rt1308_sdw_priv *rt1308 =
537 snd_soc_component_get_drvdata(component);
538 struct sdw_stream_config stream_config = {0};
539 struct sdw_port_config port_config = {0};
556 struct sdw_stream_data *stream;
540 struct sdw_stream_runtime *sdw_stream;
557 int retval;
558
559 dev_dbg(dai->dev, "%s %s", __func__, dai->name);
541 int retval;
542
543 dev_dbg(dai->dev, "%s %s", __func__, dai->name);
560 stream = snd_soc_dai_get_dma_data(dai, substream);
544 sdw_stream = snd_soc_dai_get_dma_data(dai, substream);
561
545
562 if (!stream)
546 if (!sdw_stream)
563 return -EINVAL;
564
565 if (!rt1308->sdw_slave)
566 return -EINVAL;
567
568 /* SoundWire specific configuration */
569 snd_sdw_params_to_config(substream, params, &stream_config, &port_config);
570

--- 4 unchanged lines hidden (view full) ---

575 return -EINVAL;
576
577 if (rt1308->slots) {
578 stream_config.ch_count = rt1308->slots;
579 port_config.ch_mask = rt1308->rx_mask;
580 }
581
582 retval = sdw_stream_add_slave(rt1308->sdw_slave, &stream_config,
547 return -EINVAL;
548
549 if (!rt1308->sdw_slave)
550 return -EINVAL;
551
552 /* SoundWire specific configuration */
553 snd_sdw_params_to_config(substream, params, &stream_config, &port_config);
554

--- 4 unchanged lines hidden (view full) ---

559 return -EINVAL;
560
561 if (rt1308->slots) {
562 stream_config.ch_count = rt1308->slots;
563 port_config.ch_mask = rt1308->rx_mask;
564 }
565
566 retval = sdw_stream_add_slave(rt1308->sdw_slave, &stream_config,
583 &port_config, 1, stream->sdw_stream);
567 &port_config, 1, sdw_stream);
584 if (retval) {
585 dev_err(dai->dev, "Unable to configure port\n");
586 return retval;
587 }
588
589 return retval;
590}
591
592static int rt1308_sdw_pcm_hw_free(struct snd_pcm_substream *substream,
593 struct snd_soc_dai *dai)
594{
595 struct snd_soc_component *component = dai->component;
596 struct rt1308_sdw_priv *rt1308 =
597 snd_soc_component_get_drvdata(component);
568 if (retval) {
569 dev_err(dai->dev, "Unable to configure port\n");
570 return retval;
571 }
572
573 return retval;
574}
575
576static int rt1308_sdw_pcm_hw_free(struct snd_pcm_substream *substream,
577 struct snd_soc_dai *dai)
578{
579 struct snd_soc_component *component = dai->component;
580 struct rt1308_sdw_priv *rt1308 =
581 snd_soc_component_get_drvdata(component);
598 struct sdw_stream_data *stream =
582 struct sdw_stream_runtime *sdw_stream =
599 snd_soc_dai_get_dma_data(dai, substream);
600
601 if (!rt1308->sdw_slave)
602 return -EINVAL;
603
583 snd_soc_dai_get_dma_data(dai, substream);
584
585 if (!rt1308->sdw_slave)
586 return -EINVAL;
587
604 sdw_stream_remove_slave(rt1308->sdw_slave, stream->sdw_stream);
588 sdw_stream_remove_slave(rt1308->sdw_slave, sdw_stream);
605 return 0;
606}
607
608/*
609 * slave_ops: callbacks for get_clock_stop_mode, clock_stop and
610 * port_prep are not defined for now
611 */
612static const struct sdw_slave_ops rt1308_slave_ops = {

--- 209 unchanged lines hidden ---
589 return 0;
590}
591
592/*
593 * slave_ops: callbacks for get_clock_stop_mode, clock_stop and
594 * port_prep are not defined for now
595 */
596static const struct sdw_slave_ops rt1308_slave_ops = {

--- 209 unchanged lines hidden ---