blob: 2870cfad813ac7bf6ea0fe3c839f4d3384ebad5a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
// SPDX-License-Identifier: GPL-2.0
//
// Copyright (c) 2019 BayLibre, SAS.
// Author: Jerome Brunet <jbrunet@baylibre.com>
#include <linux/module.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/soc-dai.h>
#include "meson-codec-glue.h"
static struct snd_soc_dapm_widget *
meson_codec_glue_get_input(struct snd_soc_dapm_widget *w)
{
struct snd_soc_dapm_path *p = NULL;
struct snd_soc_dapm_widget *in;
snd_soc_dapm_widget_for_each_source_path(w, p) {
if (!p->connect)
continue;
/* Check that we still are in the same component */
if (snd_soc_dapm_to_component(w->dapm) !=
snd_soc_dapm_to_component(p->source->dapm))
continue;
if (p->source->id == snd_soc_dapm_dai_in)
return p->source;
in = meson_codec_glue_get_input(p->source);
if (in)
return in;
}
return NULL;
}
static void meson_codec_glue_input_set_data(struct snd_soc_dai *dai,
struct meson_codec_glue_input *data)
{
dai->playback_dma_data = data;
}
struct meson_codec_glue_input *
meson_codec_glue_input_get_data(struct snd_soc_dai *dai)
{
return dai->playback_dma_data;
}
EXPORT_SYMBOL_GPL(meson_codec_glue_input_get_data);
static struct meson_codec_glue_input *
meson_codec_glue_output_get_input_data(struct snd_soc_dapm_widget *w)
{
struct snd_soc_dapm_widget *in =
meson_codec_glue_get_input(w);
struct snd_soc_dai *dai;
if (WARN_ON(!in))
return NULL;
dai = in->priv;
return meson_codec_glue_input_get_data(dai);
}
int meson_codec_glue_input_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params,
struct snd_soc_dai *dai)
{
struct meson_codec_glue_input *data =
meson_codec_glue_input_get_data(dai);
data->params.rates = snd_pcm_rate_to_rate_bit(params_rate(params));
data->params.rate_min = params_rate(params);
data->params.rate_max = params_rate(params);
data->params.formats = 1ULL << (__force int) params_format(params);
data->params.channels_min = params_channels(params);
data->params.channels_max = params_channels(params);
data->params.sig_bits = dai->driver->playback.sig_bits;
return 0;
}
EXPORT_SYMBOL_GPL(meson_codec_glue_input_hw_params);
int meson_codec_glue_input_set_fmt(struct snd_soc_dai *dai,
unsigned int fmt)
{
struct meson_codec_glue_input *data =
meson_codec_glue_input_get_data(dai);
/* Save the source stream format for the downstream link */
data->fmt = fmt;
return 0;
}
EXPORT_SYMBOL_GPL(meson_codec_glue_input_set_fmt);
int meson_codec_glue_output_startup(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
struct meson_codec_glue_input *in_data =
meson_codec_glue_output_get_input_data(dai->capture_widget);
if (!in_data)
return -ENODEV;
if (WARN_ON(!rtd->dai_link->params)) {
dev_warn(dai->dev, "codec2codec link expected\n");
return -EINVAL;
}
/* Replace link params with the input params */
rtd->dai_link->params = &in_data->params;
return snd_soc_runtime_set_dai_fmt(rtd, in_data->fmt);
}
EXPORT_SYMBOL_GPL(meson_codec_glue_output_startup);
int meson_codec_glue_input_dai_probe(struct snd_soc_dai *dai)
{
struct meson_codec_glue_input *data;
data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
meson_codec_glue_input_set_data(dai, data);
return 0;
}
EXPORT_SYMBOL_GPL(meson_codec_glue_input_dai_probe);
int meson_codec_glue_input_dai_remove(struct snd_soc_dai *dai)
{
struct meson_codec_glue_input *data =
meson_codec_glue_input_get_data(dai);
kfree(data);
return 0;
}
EXPORT_SYMBOL_GPL(meson_codec_glue_input_dai_remove);
MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
MODULE_DESCRIPTION("Amlogic Codec Glue Helpers");
MODULE_LICENSE("GPL v2");
|