2019-05-29 22:17:58 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2015-03-13 16:01:05 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010-2011,2013-2015 The Linux Foundation. All rights reserved.
|
|
|
|
*
|
|
|
|
* storm.c -- ALSA SoC machine driver for QTi ipq806x-based Storm board
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/mod_devicetable.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/soc.h>
|
|
|
|
|
|
|
|
#define STORM_SYSCLK_MULT 4
|
|
|
|
|
|
|
|
static int storm_ops_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *params)
|
|
|
|
{
|
2020-07-20 09:19:00 +08:00
|
|
|
struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
|
2015-03-13 16:01:05 +08:00
|
|
|
struct snd_soc_card *card = soc_runtime->card;
|
|
|
|
snd_pcm_format_t format = params_format(params);
|
|
|
|
unsigned int rate = params_rate(params);
|
|
|
|
unsigned int sysclk_freq;
|
|
|
|
int bitwidth, ret;
|
|
|
|
|
|
|
|
bitwidth = snd_pcm_format_width(format);
|
|
|
|
if (bitwidth < 0) {
|
2017-01-31 05:03:37 +08:00
|
|
|
dev_err(card->dev, "invalid bit width given: %d\n", bitwidth);
|
2015-03-13 16:01:05 +08:00
|
|
|
return bitwidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* as the CPU DAI is the I2S bus master and no system clock is needed by
|
|
|
|
* the MAX98357a DAC, simply set the system clock to be a constant
|
|
|
|
* multiple of the bit clock for the clock divider
|
|
|
|
*/
|
|
|
|
sysclk_freq = rate * bitwidth * 2 * STORM_SYSCLK_MULT;
|
|
|
|
|
2020-03-23 13:20:01 +08:00
|
|
|
ret = snd_soc_dai_set_sysclk(asoc_rtd_to_cpu(soc_runtime, 0), 0, sysclk_freq, 0);
|
2015-03-13 16:01:05 +08:00
|
|
|
if (ret) {
|
2017-01-31 05:03:37 +08:00
|
|
|
dev_err(card->dev, "error setting sysclk to %u: %d\n",
|
|
|
|
sysclk_freq, ret);
|
2015-03-13 16:01:05 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-15 22:55:48 +08:00
|
|
|
static const struct snd_soc_ops storm_soc_ops = {
|
2015-03-13 16:01:05 +08:00
|
|
|
.hw_params = storm_ops_hw_params,
|
|
|
|
};
|
|
|
|
|
2019-06-06 12:16:51 +08:00
|
|
|
SND_SOC_DAILINK_DEFS(hifi,
|
|
|
|
DAILINK_COMP_ARRAY(COMP_EMPTY()),
|
2019-06-28 09:47:50 +08:00
|
|
|
DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "HiFi")),
|
|
|
|
DAILINK_COMP_ARRAY(COMP_EMPTY()));
|
2019-06-06 12:16:51 +08:00
|
|
|
|
2015-03-13 16:01:05 +08:00
|
|
|
static struct snd_soc_dai_link storm_dai_link = {
|
|
|
|
.name = "Primary",
|
|
|
|
.stream_name = "Primary",
|
|
|
|
.ops = &storm_soc_ops,
|
2019-06-06 12:16:51 +08:00
|
|
|
SND_SOC_DAILINK_REG(hifi),
|
2015-03-13 16:01:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int storm_parse_of(struct snd_soc_card *card)
|
|
|
|
{
|
|
|
|
struct snd_soc_dai_link *dai_link = card->dai_link;
|
|
|
|
struct device_node *np = card->dev->of_node;
|
|
|
|
|
2019-06-06 12:16:51 +08:00
|
|
|
dai_link->cpus->of_node = of_parse_phandle(np, "cpu", 0);
|
|
|
|
if (!dai_link->cpus->of_node) {
|
2017-01-31 05:03:37 +08:00
|
|
|
dev_err(card->dev, "error getting cpu phandle\n");
|
2015-03-13 16:01:05 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2019-06-28 09:47:50 +08:00
|
|
|
dai_link->platforms->of_node = dai_link->cpus->of_node;
|
2015-03-13 16:01:05 +08:00
|
|
|
|
2019-06-06 12:16:51 +08:00
|
|
|
dai_link->codecs->of_node = of_parse_phandle(np, "codec", 0);
|
|
|
|
if (!dai_link->codecs->of_node) {
|
2017-01-31 05:03:37 +08:00
|
|
|
dev_err(card->dev, "error getting codec phandle\n");
|
2015-03-13 16:01:05 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int storm_platform_probe(struct platform_device *pdev)
|
|
|
|
{
|
2015-06-09 21:34:21 +08:00
|
|
|
struct snd_soc_card *card;
|
2015-03-13 16:01:05 +08:00
|
|
|
int ret;
|
|
|
|
|
2015-06-09 21:34:21 +08:00
|
|
|
card = devm_kzalloc(&pdev->dev, sizeof(*card), GFP_KERNEL);
|
|
|
|
if (!card)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2015-03-13 16:01:05 +08:00
|
|
|
card->dev = &pdev->dev;
|
2020-08-20 23:45:11 +08:00
|
|
|
card->owner = THIS_MODULE;
|
2015-03-13 16:01:05 +08:00
|
|
|
|
|
|
|
ret = snd_soc_of_parse_card_name(card, "qcom,model");
|
|
|
|
if (ret) {
|
2017-01-31 05:03:37 +08:00
|
|
|
dev_err(&pdev->dev, "error parsing card name: %d\n", ret);
|
2015-03-13 16:01:05 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
card->dai_link = &storm_dai_link;
|
|
|
|
card->num_links = 1;
|
|
|
|
|
|
|
|
ret = storm_parse_of(card);
|
|
|
|
if (ret) {
|
2017-01-31 05:03:37 +08:00
|
|
|
dev_err(&pdev->dev, "error resolving dai links: %d\n", ret);
|
2015-03-13 16:01:05 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = devm_snd_soc_register_card(&pdev->dev, card);
|
2015-06-09 21:35:22 +08:00
|
|
|
if (ret)
|
2017-01-31 05:03:37 +08:00
|
|
|
dev_err(&pdev->dev, "error registering soundcard: %d\n", ret);
|
2015-03-13 16:01:05 +08:00
|
|
|
|
2015-06-09 21:35:22 +08:00
|
|
|
return ret;
|
|
|
|
|
2015-03-13 16:01:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_OF
|
|
|
|
static const struct of_device_id storm_device_id[] = {
|
|
|
|
{ .compatible = "google,storm-audio" },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, storm_device_id);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct platform_driver storm_platform_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "storm-audio",
|
|
|
|
.of_match_table =
|
|
|
|
of_match_ptr(storm_device_id),
|
|
|
|
},
|
|
|
|
.probe = storm_platform_probe,
|
|
|
|
};
|
|
|
|
module_platform_driver(storm_platform_driver);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("QTi IPQ806x-based Storm Machine Driver");
|
|
|
|
MODULE_LICENSE("GPL v2");
|