2016-05-31 12:00:14 +03:00
|
|
|
/*
|
|
|
|
* simple-card-core.c
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
2016-08-08 08:59:56 +03:00
|
|
|
#include <linux/clk.h>
|
2016-08-03 04:24:05 +03:00
|
|
|
#include <linux/module.h>
|
2016-05-31 12:00:14 +03:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <sound/simple_card_utils.h>
|
|
|
|
|
|
|
|
int asoc_simple_card_parse_daifmt(struct device *dev,
|
|
|
|
struct device_node *node,
|
|
|
|
struct device_node *codec,
|
|
|
|
char *prefix,
|
|
|
|
unsigned int *retfmt)
|
|
|
|
{
|
|
|
|
struct device_node *bitclkmaster = NULL;
|
|
|
|
struct device_node *framemaster = NULL;
|
|
|
|
int prefix_len = prefix ? strlen(prefix) : 0;
|
|
|
|
unsigned int daifmt;
|
|
|
|
|
|
|
|
daifmt = snd_soc_of_parse_daifmt(node, prefix,
|
|
|
|
&bitclkmaster, &framemaster);
|
|
|
|
daifmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
|
|
|
|
|
|
|
|
if (prefix_len && !bitclkmaster && !framemaster) {
|
|
|
|
/*
|
|
|
|
* No dai-link level and master setting was not found from
|
|
|
|
* sound node level, revert back to legacy DT parsing and
|
|
|
|
* take the settings from codec node.
|
|
|
|
*/
|
|
|
|
dev_dbg(dev, "Revert to legacy daifmt parsing\n");
|
|
|
|
|
|
|
|
daifmt = snd_soc_of_parse_daifmt(codec, NULL, NULL, NULL) |
|
|
|
|
(daifmt & ~SND_SOC_DAIFMT_CLOCK_MASK);
|
|
|
|
} else {
|
|
|
|
if (codec == bitclkmaster)
|
|
|
|
daifmt |= (codec == framemaster) ?
|
|
|
|
SND_SOC_DAIFMT_CBM_CFM : SND_SOC_DAIFMT_CBM_CFS;
|
|
|
|
else
|
|
|
|
daifmt |= (codec == framemaster) ?
|
|
|
|
SND_SOC_DAIFMT_CBS_CFM : SND_SOC_DAIFMT_CBS_CFS;
|
|
|
|
}
|
|
|
|
|
|
|
|
of_node_put(bitclkmaster);
|
|
|
|
of_node_put(framemaster);
|
|
|
|
|
|
|
|
*retfmt = daifmt;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(asoc_simple_card_parse_daifmt);
|
2016-07-12 02:57:14 +03:00
|
|
|
|
|
|
|
int asoc_simple_card_set_dailink_name(struct device *dev,
|
|
|
|
struct snd_soc_dai_link *dai_link,
|
|
|
|
const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char *name = NULL;
|
|
|
|
int ret = -ENOMEM;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
name = devm_kvasprintf(dev, GFP_KERNEL, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
if (name) {
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
dai_link->name = name;
|
|
|
|
dai_link->stream_name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(asoc_simple_card_set_dailink_name);
|
2016-07-12 02:59:16 +03:00
|
|
|
|
|
|
|
int asoc_simple_card_parse_card_name(struct snd_soc_card *card,
|
|
|
|
char *prefix)
|
|
|
|
{
|
|
|
|
char prop[128];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
snprintf(prop, sizeof(prop), "%sname", prefix);
|
|
|
|
|
|
|
|
/* Parse the card name from DT */
|
|
|
|
ret = snd_soc_of_parse_card_name(card, prop);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (!card->name && card->dai_link)
|
|
|
|
card->name = card->dai_link->name;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(asoc_simple_card_parse_card_name);
|
2016-08-03 04:24:05 +03:00
|
|
|
|
2016-08-08 08:59:56 +03:00
|
|
|
int asoc_simple_card_parse_clk(struct device_node *node,
|
|
|
|
struct device_node *dai_of_node,
|
|
|
|
struct asoc_simple_dai *simple_dai)
|
|
|
|
{
|
|
|
|
struct clk *clk;
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse dai->sysclk come from "clocks = <&xxx>"
|
|
|
|
* (if system has common clock)
|
|
|
|
* or "system-clock-frequency = <xxx>"
|
|
|
|
* or device's module clock.
|
|
|
|
*/
|
|
|
|
clk = of_clk_get(node, 0);
|
|
|
|
if (!IS_ERR(clk)) {
|
|
|
|
simple_dai->sysclk = clk_get_rate(clk);
|
|
|
|
simple_dai->clk = clk;
|
|
|
|
} else if (!of_property_read_u32(node, "system-clock-frequency", &val)) {
|
|
|
|
simple_dai->sysclk = val;
|
|
|
|
} else {
|
|
|
|
clk = of_clk_get(dai_of_node, 0);
|
|
|
|
if (!IS_ERR(clk))
|
|
|
|
simple_dai->sysclk = clk_get_rate(clk);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(asoc_simple_card_parse_clk);
|
|
|
|
|
2016-08-03 04:24:05 +03:00
|
|
|
/* Module information */
|
|
|
|
MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
|
|
|
|
MODULE_DESCRIPTION("ALSA SoC Simple Card Utils");
|
|
|
|
MODULE_LICENSE("GPL v2");
|