blob: fb45f396ab4a7451618ef1cc6a328c992277263a [file] [log] [blame]
Srinivas Kandagatlaa6f933f2018-05-18 13:56:10 +01001// SPDX-License-Identifier: GPL-2.0
2// Copyright (c) 2018, Linaro Limited
3
Srinivas Kandagatlaa6f933f2018-05-18 13:56:10 +01004#include <linux/module.h>
Srinivas Kandagatlaa6f933f2018-05-18 13:56:10 +01005#include <linux/platform_device.h>
6#include <linux/of_device.h>
7#include <sound/soc.h>
8#include <sound/soc-dapm.h>
9#include <sound/pcm.h>
Rohit kumarc25e295c2018-08-01 14:31:08 +053010#include "common.h"
Srinivas Kandagatlaa6f933f2018-05-18 13:56:10 +010011
12static int apq8096_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
13 struct snd_pcm_hw_params *params)
14{
15 struct snd_interval *rate = hw_param_interval(params,
16 SNDRV_PCM_HW_PARAM_RATE);
17 struct snd_interval *channels = hw_param_interval(params,
18 SNDRV_PCM_HW_PARAM_CHANNELS);
19
20 rate->min = rate->max = 48000;
21 channels->min = channels->max = 2;
22
23 return 0;
24}
25
Rohit kumarc25e295c2018-08-01 14:31:08 +053026static void apq8096_add_be_ops(struct snd_soc_card *card)
Srinivas Kandagatlaa6f933f2018-05-18 13:56:10 +010027{
Kuninori Morimoto7fe072b2018-09-18 01:28:49 +000028 struct snd_soc_dai_link *link;
29 int i;
Srinivas Kandagatlaa6f933f2018-05-18 13:56:10 +010030
Kuninori Morimoto7fe072b2018-09-18 01:28:49 +000031 for_each_card_prelinks(card, i, link) {
Rohit kumarc25e295c2018-08-01 14:31:08 +053032 if (link->no_pcm == 1)
Srinivas Kandagatlaa6f933f2018-05-18 13:56:10 +010033 link->be_hw_params_fixup = apq8096_be_hw_params_fixup;
Srinivas Kandagatlaa6f933f2018-05-18 13:56:10 +010034 }
Srinivas Kandagatlaa6f933f2018-05-18 13:56:10 +010035}
36
Srinivas Kandagatla90ae7102018-07-13 16:36:32 +010037static int apq8096_platform_probe(struct platform_device *pdev)
Srinivas Kandagatlaa6f933f2018-05-18 13:56:10 +010038{
39 struct snd_soc_card *card;
Srinivas Kandagatla90ae7102018-07-13 16:36:32 +010040 struct device *dev = &pdev->dev;
Srinivas Kandagatlaa6f933f2018-05-18 13:56:10 +010041 int ret;
42
43 card = kzalloc(sizeof(*card), GFP_KERNEL);
44 if (!card)
45 return -ENOMEM;
46
Srinivas Kandagatlaa6f933f2018-05-18 13:56:10 +010047 card->dev = dev;
Rohit Kumard5c4e972018-06-06 14:25:24 +053048 dev_set_drvdata(dev, card);
Rohit kumarc25e295c2018-08-01 14:31:08 +053049 ret = qcom_snd_parse_of(card);
Srinivas Kandagatlaa6f933f2018-05-18 13:56:10 +010050 if (ret) {
51 dev_err(dev, "Error parsing OF data\n");
52 goto err;
53 }
54
Rohit kumarc25e295c2018-08-01 14:31:08 +053055 apq8096_add_be_ops(card);
Srinivas Kandagatlaa6f933f2018-05-18 13:56:10 +010056 ret = snd_soc_register_card(card);
57 if (ret)
Rohit kumarc25e295c2018-08-01 14:31:08 +053058 goto err_card_register;
Srinivas Kandagatlaa6f933f2018-05-18 13:56:10 +010059
60 return 0;
61
Rohit kumarc25e295c2018-08-01 14:31:08 +053062err_card_register:
63 kfree(card->dai_link);
Srinivas Kandagatlaa6f933f2018-05-18 13:56:10 +010064err:
Srinivas Kandagatlaa6f933f2018-05-18 13:56:10 +010065 kfree(card);
66 return ret;
67}
68
Srinivas Kandagatlaa6f933f2018-05-18 13:56:10 +010069static int apq8096_platform_remove(struct platform_device *pdev)
70{
Srinivas Kandagatla90ae7102018-07-13 16:36:32 +010071 struct snd_soc_card *card = dev_get_drvdata(&pdev->dev);
72
Srinivas Kandagatla90ae7102018-07-13 16:36:32 +010073 snd_soc_unregister_card(card);
74 kfree(card->dai_link);
75 kfree(card);
Srinivas Kandagatlaa6f933f2018-05-18 13:56:10 +010076
77 return 0;
78}
79
80static const struct of_device_id msm_snd_apq8096_dt_match[] = {
81 {.compatible = "qcom,apq8096-sndcard"},
82 {}
83};
84
85MODULE_DEVICE_TABLE(of, msm_snd_apq8096_dt_match);
86
87static struct platform_driver msm_snd_apq8096_driver = {
88 .probe = apq8096_platform_probe,
89 .remove = apq8096_platform_remove,
90 .driver = {
91 .name = "msm-snd-apq8096",
Srinivas Kandagatlaa6f933f2018-05-18 13:56:10 +010092 .of_match_table = msm_snd_apq8096_dt_match,
93 },
94};
95module_platform_driver(msm_snd_apq8096_driver);
96MODULE_AUTHOR("Srinivas Kandagatla <srinivas.kandagatla@linaro.org");
97MODULE_DESCRIPTION("APQ8096 ASoC Machine Driver");
98MODULE_LICENSE("GPL v2");