2018-07-02 00:30:44 -06:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0
|
|
|
|
*
|
2016-12-01 22:27:30 -07:00
|
|
|
* simple_card_utils.h
|
2016-05-31 03:00:14 -06:00
|
|
|
*
|
|
|
|
* Copyright (c) 2016 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
|
|
|
|
*/
|
2018-07-02 00:30:44 -06:00
|
|
|
|
2016-12-01 22:27:30 -07:00
|
|
|
#ifndef __SIMPLE_CARD_UTILS_H
|
|
|
|
#define __SIMPLE_CARD_UTILS_H
|
2016-05-31 03:00:14 -06:00
|
|
|
|
|
|
|
#include <sound/soc.h>
|
|
|
|
|
2018-06-11 02:32:12 -06:00
|
|
|
#define asoc_simple_card_init_hp(card, sjack, prefix) \
|
|
|
|
asoc_simple_card_init_jack(card, sjack, 1, prefix)
|
|
|
|
#define asoc_simple_card_init_mic(card, sjack, prefix) \
|
|
|
|
asoc_simple_card_init_jack(card, sjack, 0, prefix)
|
|
|
|
|
2016-06-30 00:02:46 -06:00
|
|
|
struct asoc_simple_dai {
|
|
|
|
const char *name;
|
|
|
|
unsigned int sysclk;
|
2017-08-17 05:42:36 -06:00
|
|
|
int clk_direction;
|
2016-06-30 00:02:46 -06:00
|
|
|
int slots;
|
|
|
|
int slot_width;
|
|
|
|
unsigned int tx_slot_mask;
|
|
|
|
unsigned int rx_slot_mask;
|
|
|
|
struct clk *clk;
|
|
|
|
};
|
|
|
|
|
2017-06-14 18:24:09 -06:00
|
|
|
struct asoc_simple_card_data {
|
|
|
|
u32 convert_rate;
|
|
|
|
u32 convert_channels;
|
|
|
|
};
|
|
|
|
|
2018-06-11 02:32:12 -06:00
|
|
|
struct asoc_simple_jack {
|
|
|
|
struct snd_soc_jack jack;
|
|
|
|
struct snd_soc_jack_pin pin;
|
|
|
|
struct snd_soc_jack_gpio gpio;
|
|
|
|
};
|
|
|
|
|
ASoC: simple_card_utils: share common priv for simple-card/audio-graph
Historically, simple-card/simple-scu-card/audio-graph/audio-graph-scu
are similar but different generic sound card.
simple-scu-card which was for DPCM was merged into simple-card, and
audio-graph-scu which was for DPCM was merged into audio-graph.
simple-card is for non OF graph sound card, and
audio-graph is for OF graph sound card.
And, small detail difference (= function parameter, naming, etc)
between simple-card/audio-graph has been unified.
So today, the difference between simple-card/audio-graph are
just using OF graph style, or not.
In other words, there should no difference other than OF graph sytle.
simple-card/audio-graph are using own priv today , but we can merge it.
This patch merge it at simple_card_utils.
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2019-03-19 22:54:59 -06:00
|
|
|
struct asoc_simple_priv {
|
|
|
|
struct snd_soc_card snd_card;
|
|
|
|
struct simple_dai_props {
|
|
|
|
struct asoc_simple_dai *cpu_dai;
|
|
|
|
struct asoc_simple_dai *codec_dai;
|
|
|
|
struct snd_soc_dai_link_component codecs; /* single codec */
|
|
|
|
struct snd_soc_dai_link_component platforms;
|
|
|
|
struct asoc_simple_card_data adata;
|
|
|
|
struct snd_soc_codec_conf *codec_conf;
|
|
|
|
unsigned int mclk_fs;
|
|
|
|
} *dai_props;
|
|
|
|
struct asoc_simple_jack hp_jack;
|
|
|
|
struct asoc_simple_jack mic_jack;
|
|
|
|
struct snd_soc_dai_link *dai_link;
|
|
|
|
struct asoc_simple_dai *dais;
|
|
|
|
struct snd_soc_codec_conf *codec_conf;
|
|
|
|
struct gpio_desc *pa_gpio;
|
|
|
|
};
|
|
|
|
#define simple_priv_to_card(priv) (&(priv)->snd_card)
|
|
|
|
#define simple_priv_to_props(priv, i) ((priv)->dai_props + (i))
|
|
|
|
#define simple_priv_to_dev(priv) (simple_priv_to_card(priv)->dev)
|
|
|
|
#define simple_priv_to_link(priv, i) (simple_priv_to_card(priv)->dai_link + (i))
|
|
|
|
|
2016-05-31 03:00:14 -06:00
|
|
|
int asoc_simple_card_parse_daifmt(struct device *dev,
|
|
|
|
struct device_node *node,
|
|
|
|
struct device_node *codec,
|
|
|
|
char *prefix,
|
|
|
|
unsigned int *retfmt);
|
2016-08-23 02:51:22 -06:00
|
|
|
__printf(3, 4)
|
2016-07-11 17:57:14 -06:00
|
|
|
int asoc_simple_card_set_dailink_name(struct device *dev,
|
|
|
|
struct snd_soc_dai_link *dai_link,
|
|
|
|
const char *fmt, ...);
|
2016-07-11 17:59:16 -06:00
|
|
|
int asoc_simple_card_parse_card_name(struct snd_soc_card *card,
|
|
|
|
char *prefix);
|
2016-05-31 03:00:14 -06:00
|
|
|
|
2017-01-23 00:29:42 -07:00
|
|
|
#define asoc_simple_card_parse_clk_cpu(dev, node, dai_link, simple_dai) \
|
2017-06-04 22:28:45 -06:00
|
|
|
asoc_simple_card_parse_clk(dev, node, dai_link->cpu_of_node, simple_dai, \
|
2018-08-30 21:08:09 -06:00
|
|
|
dai_link->cpu_dai_name, NULL)
|
2017-01-23 00:29:42 -07:00
|
|
|
#define asoc_simple_card_parse_clk_codec(dev, node, dai_link, simple_dai) \
|
2017-06-04 22:28:45 -06:00
|
|
|
asoc_simple_card_parse_clk(dev, node, dai_link->codec_of_node, simple_dai,\
|
2018-08-30 21:08:09 -06:00
|
|
|
dai_link->codec_dai_name, dai_link->codecs)
|
2017-01-23 00:29:42 -07:00
|
|
|
int asoc_simple_card_parse_clk(struct device *dev,
|
|
|
|
struct device_node *node,
|
2016-08-07 23:59:56 -06:00
|
|
|
struct device_node *dai_of_node,
|
2017-06-04 22:28:45 -06:00
|
|
|
struct asoc_simple_dai *simple_dai,
|
2018-08-30 21:08:09 -06:00
|
|
|
const char *dai_name,
|
|
|
|
struct snd_soc_dai_link_component *dlc);
|
2019-03-19 22:55:14 -06:00
|
|
|
int asoc_simple_startup(struct snd_pcm_substream *substream);
|
2019-03-19 22:55:27 -06:00
|
|
|
void asoc_simple_shutdown(struct snd_pcm_substream *substream);
|
2016-08-07 23:59:56 -06:00
|
|
|
|
2016-08-08 00:01:43 -06:00
|
|
|
#define asoc_simple_card_parse_cpu(node, dai_link, \
|
|
|
|
list_name, cells_name, is_single_link) \
|
2018-08-30 21:08:09 -06:00
|
|
|
asoc_simple_card_parse_dai(node, NULL, \
|
|
|
|
&dai_link->cpu_of_node, \
|
2016-08-08 00:01:43 -06:00
|
|
|
&dai_link->cpu_dai_name, list_name, cells_name, is_single_link)
|
|
|
|
#define asoc_simple_card_parse_codec(node, dai_link, list_name, cells_name) \
|
2018-08-30 21:08:09 -06:00
|
|
|
asoc_simple_card_parse_dai(node, dai_link->codecs, \
|
|
|
|
&dai_link->codec_of_node, \
|
|
|
|
&dai_link->codec_dai_name, \
|
|
|
|
list_name, cells_name, NULL)
|
2016-08-08 00:01:43 -06:00
|
|
|
#define asoc_simple_card_parse_platform(node, dai_link, list_name, cells_name) \
|
2019-01-20 17:32:32 -07:00
|
|
|
asoc_simple_card_parse_dai(node, dai_link->platforms, \
|
2018-08-30 21:08:09 -06:00
|
|
|
&dai_link->platform_of_node, \
|
2016-08-08 00:01:43 -06:00
|
|
|
NULL, list_name, cells_name, NULL)
|
|
|
|
int asoc_simple_card_parse_dai(struct device_node *node,
|
2018-08-30 21:08:09 -06:00
|
|
|
struct snd_soc_dai_link_component *dlc,
|
2016-08-08 00:01:43 -06:00
|
|
|
struct device_node **endpoint_np,
|
|
|
|
const char **dai_name,
|
|
|
|
const char *list_name,
|
|
|
|
const char *cells_name,
|
|
|
|
int *is_single_links);
|
|
|
|
|
2017-04-19 19:35:18 -06:00
|
|
|
#define asoc_simple_card_parse_graph_cpu(ep, dai_link) \
|
2018-08-30 21:08:09 -06:00
|
|
|
asoc_simple_card_parse_graph_dai(ep, NULL, \
|
|
|
|
&dai_link->cpu_of_node, \
|
2017-04-19 19:35:18 -06:00
|
|
|
&dai_link->cpu_dai_name)
|
|
|
|
#define asoc_simple_card_parse_graph_codec(ep, dai_link) \
|
2018-08-30 21:08:09 -06:00
|
|
|
asoc_simple_card_parse_graph_dai(ep, dai_link->codecs, \
|
|
|
|
&dai_link->codec_of_node, \
|
2017-04-19 19:35:18 -06:00
|
|
|
&dai_link->codec_dai_name)
|
|
|
|
int asoc_simple_card_parse_graph_dai(struct device_node *ep,
|
2018-08-30 21:08:09 -06:00
|
|
|
struct snd_soc_dai_link_component *dlc,
|
2017-04-19 19:35:18 -06:00
|
|
|
struct device_node **endpoint_np,
|
|
|
|
const char **dai_name);
|
|
|
|
|
2017-06-13 18:34:35 -06:00
|
|
|
#define asoc_simple_card_of_parse_tdm(np, dai) \
|
|
|
|
snd_soc_of_parse_tdm_slot(np, &(dai)->tx_slot_mask, \
|
|
|
|
&(dai)->rx_slot_mask, \
|
|
|
|
&(dai)->slots, \
|
|
|
|
&(dai)->slot_width);
|
|
|
|
|
2016-08-08 23:48:30 -06:00
|
|
|
int asoc_simple_card_init_dai(struct snd_soc_dai *dai,
|
|
|
|
struct asoc_simple_dai *simple_dai);
|
2016-08-08 23:49:41 -06:00
|
|
|
|
2019-01-21 00:40:59 -07:00
|
|
|
void asoc_simple_card_canonicalize_platform(struct snd_soc_dai_link *dai_link);
|
2016-08-09 20:20:19 -06:00
|
|
|
void asoc_simple_card_canonicalize_cpu(struct snd_soc_dai_link *dai_link,
|
|
|
|
int is_single_links);
|
2016-08-08 23:49:41 -06:00
|
|
|
|
2016-08-09 20:21:25 -06:00
|
|
|
int asoc_simple_card_clean_reference(struct snd_soc_card *card);
|
|
|
|
|
2017-06-14 18:24:09 -06:00
|
|
|
void asoc_simple_card_convert_fixup(struct asoc_simple_card_data *data,
|
|
|
|
struct snd_pcm_hw_params *params);
|
2018-11-20 19:10:51 -07:00
|
|
|
void asoc_simple_card_parse_convert(struct device *dev,
|
|
|
|
struct device_node *np, char *prefix,
|
2017-06-14 18:24:09 -06:00
|
|
|
struct asoc_simple_card_data *data);
|
|
|
|
|
2017-06-14 18:25:02 -06:00
|
|
|
int asoc_simple_card_of_parse_routing(struct snd_soc_card *card,
|
2018-11-20 19:11:13 -07:00
|
|
|
char *prefix);
|
2017-06-15 19:38:50 -06:00
|
|
|
int asoc_simple_card_of_parse_widgets(struct snd_soc_card *card,
|
|
|
|
char *prefix);
|
2017-06-14 18:25:02 -06:00
|
|
|
|
2018-06-11 02:32:12 -06:00
|
|
|
int asoc_simple_card_init_jack(struct snd_soc_card *card,
|
|
|
|
struct asoc_simple_jack *sjack,
|
|
|
|
int is_hp, char *prefix);
|
|
|
|
|
2019-03-19 22:54:42 -06:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
inline void asoc_simple_debug_dai(struct asoc_simple_priv *priv,
|
|
|
|
char *name,
|
|
|
|
struct asoc_simple_dai *dai)
|
|
|
|
{
|
|
|
|
struct device *dev = simple_priv_to_dev(priv);
|
|
|
|
|
|
|
|
if (dai->name)
|
|
|
|
dev_dbg(dev, "%s dai name = %s\n",
|
|
|
|
name, dai->name);
|
|
|
|
if (dai->sysclk)
|
|
|
|
dev_dbg(dev, "%s sysclk = %d\n",
|
|
|
|
name, dai->sysclk);
|
|
|
|
|
|
|
|
dev_dbg(dev, "%s direction = %s\n",
|
|
|
|
name, dai->clk_direction ? "OUT" : "IN");
|
|
|
|
|
|
|
|
if (dai->slots)
|
|
|
|
dev_dbg(dev, "%s slots = %d\n", name, dai->slots);
|
|
|
|
if (dai->slot_width)
|
|
|
|
dev_dbg(dev, "%s slot width = %d\n", name, dai->slot_width);
|
|
|
|
if (dai->tx_slot_mask)
|
|
|
|
dev_dbg(dev, "%s tx slot mask = %d\n", name, dai->tx_slot_mask);
|
|
|
|
if (dai->rx_slot_mask)
|
|
|
|
dev_dbg(dev, "%s rx slot mask = %d\n", name, dai->rx_slot_mask);
|
|
|
|
if (dai->clk)
|
|
|
|
dev_dbg(dev, "%s clk %luHz\n", name, clk_get_rate(dai->clk));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void asoc_simple_debug_info(struct asoc_simple_priv *priv)
|
|
|
|
{
|
|
|
|
struct snd_soc_card *card = simple_priv_to_card(priv);
|
|
|
|
struct device *dev = simple_priv_to_dev(priv);
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (card->name)
|
|
|
|
dev_dbg(dev, "Card Name: %s\n", card->name);
|
|
|
|
|
|
|
|
for (i = 0; i < card->num_links; i++) {
|
|
|
|
struct simple_dai_props *props = simple_priv_to_props(priv, i);
|
|
|
|
struct snd_soc_dai_link *link = simple_priv_to_link(priv, i);
|
|
|
|
|
|
|
|
dev_dbg(dev, "DAI%d\n", i);
|
|
|
|
|
|
|
|
asoc_simple_debug_dai(priv, "cpu", props->cpu_dai);
|
|
|
|
asoc_simple_debug_dai(priv, "codec", props->codec_dai);
|
|
|
|
|
|
|
|
if (link->name)
|
|
|
|
dev_dbg(dev, "dai name = %s\n", link->name);
|
|
|
|
|
|
|
|
dev_dbg(dev, "dai format = %04x\n", link->dai_fmt);
|
|
|
|
|
|
|
|
if (props->adata.convert_rate)
|
|
|
|
dev_dbg(dev, "convert_rate = %d\n",
|
|
|
|
props->adata.convert_rate);
|
|
|
|
if (props->adata.convert_channels)
|
|
|
|
dev_dbg(dev, "convert_channels = %d\n",
|
|
|
|
props->adata.convert_channels);
|
|
|
|
if (props->codec_conf && props->codec_conf->name_prefix)
|
|
|
|
dev_dbg(dev, "name prefix = %s\n",
|
|
|
|
props->codec_conf->name_prefix);
|
|
|
|
if (props->mclk_fs)
|
|
|
|
dev_dbg(dev, "mclk-fs = %d\n",
|
|
|
|
props->mclk_fs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define asoc_simple_debug_info(priv)
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2016-12-01 22:27:30 -07:00
|
|
|
#endif /* __SIMPLE_CARD_UTILS_H */
|