Srinivas Kandagatla | a6f933f | 2018-05-18 13:56:10 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | // Copyright (c) 2018, Linaro Limited |
| 3 | |
Srinivas Kandagatla | a6f933f | 2018-05-18 13:56:10 +0100 | [diff] [blame] | 4 | #include <linux/module.h> |
Srinivas Kandagatla | a6f933f | 2018-05-18 13:56:10 +0100 | [diff] [blame] | 5 | #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 kumar | c25e295c | 2018-08-01 14:31:08 +0530 | [diff] [blame] | 10 | #include "common.h" |
Srinivas Kandagatla | a6f933f | 2018-05-18 13:56:10 +0100 | [diff] [blame] | 11 | |
| 12 | static 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 kumar | c25e295c | 2018-08-01 14:31:08 +0530 | [diff] [blame] | 26 | static void apq8096_add_be_ops(struct snd_soc_card *card) |
Srinivas Kandagatla | a6f933f | 2018-05-18 13:56:10 +0100 | [diff] [blame] | 27 | { |
Kuninori Morimoto | 7fe072b | 2018-09-18 01:28:49 +0000 | [diff] [blame] | 28 | struct snd_soc_dai_link *link; |
| 29 | int i; |
Srinivas Kandagatla | a6f933f | 2018-05-18 13:56:10 +0100 | [diff] [blame] | 30 | |
Kuninori Morimoto | 7fe072b | 2018-09-18 01:28:49 +0000 | [diff] [blame] | 31 | for_each_card_prelinks(card, i, link) { |
Rohit kumar | c25e295c | 2018-08-01 14:31:08 +0530 | [diff] [blame] | 32 | if (link->no_pcm == 1) |
Srinivas Kandagatla | a6f933f | 2018-05-18 13:56:10 +0100 | [diff] [blame] | 33 | link->be_hw_params_fixup = apq8096_be_hw_params_fixup; |
Srinivas Kandagatla | a6f933f | 2018-05-18 13:56:10 +0100 | [diff] [blame] | 34 | } |
Srinivas Kandagatla | a6f933f | 2018-05-18 13:56:10 +0100 | [diff] [blame] | 35 | } |
| 36 | |
Srinivas Kandagatla | 90ae710 | 2018-07-13 16:36:32 +0100 | [diff] [blame] | 37 | static int apq8096_platform_probe(struct platform_device *pdev) |
Srinivas Kandagatla | a6f933f | 2018-05-18 13:56:10 +0100 | [diff] [blame] | 38 | { |
| 39 | struct snd_soc_card *card; |
Srinivas Kandagatla | 90ae710 | 2018-07-13 16:36:32 +0100 | [diff] [blame] | 40 | struct device *dev = &pdev->dev; |
Srinivas Kandagatla | a6f933f | 2018-05-18 13:56:10 +0100 | [diff] [blame] | 41 | int ret; |
| 42 | |
| 43 | card = kzalloc(sizeof(*card), GFP_KERNEL); |
| 44 | if (!card) |
| 45 | return -ENOMEM; |
| 46 | |
Srinivas Kandagatla | a6f933f | 2018-05-18 13:56:10 +0100 | [diff] [blame] | 47 | card->dev = dev; |
Rohit Kumar | d5c4e97 | 2018-06-06 14:25:24 +0530 | [diff] [blame] | 48 | dev_set_drvdata(dev, card); |
Rohit kumar | c25e295c | 2018-08-01 14:31:08 +0530 | [diff] [blame] | 49 | ret = qcom_snd_parse_of(card); |
Srinivas Kandagatla | a6f933f | 2018-05-18 13:56:10 +0100 | [diff] [blame] | 50 | if (ret) { |
| 51 | dev_err(dev, "Error parsing OF data\n"); |
| 52 | goto err; |
| 53 | } |
| 54 | |
Rohit kumar | c25e295c | 2018-08-01 14:31:08 +0530 | [diff] [blame] | 55 | apq8096_add_be_ops(card); |
Srinivas Kandagatla | a6f933f | 2018-05-18 13:56:10 +0100 | [diff] [blame] | 56 | ret = snd_soc_register_card(card); |
| 57 | if (ret) |
Rohit kumar | c25e295c | 2018-08-01 14:31:08 +0530 | [diff] [blame] | 58 | goto err_card_register; |
Srinivas Kandagatla | a6f933f | 2018-05-18 13:56:10 +0100 | [diff] [blame] | 59 | |
| 60 | return 0; |
| 61 | |
Rohit kumar | c25e295c | 2018-08-01 14:31:08 +0530 | [diff] [blame] | 62 | err_card_register: |
| 63 | kfree(card->dai_link); |
Srinivas Kandagatla | a6f933f | 2018-05-18 13:56:10 +0100 | [diff] [blame] | 64 | err: |
Srinivas Kandagatla | a6f933f | 2018-05-18 13:56:10 +0100 | [diff] [blame] | 65 | kfree(card); |
| 66 | return ret; |
| 67 | } |
| 68 | |
Srinivas Kandagatla | a6f933f | 2018-05-18 13:56:10 +0100 | [diff] [blame] | 69 | static int apq8096_platform_remove(struct platform_device *pdev) |
| 70 | { |
Srinivas Kandagatla | 90ae710 | 2018-07-13 16:36:32 +0100 | [diff] [blame] | 71 | struct snd_soc_card *card = dev_get_drvdata(&pdev->dev); |
| 72 | |
Srinivas Kandagatla | 90ae710 | 2018-07-13 16:36:32 +0100 | [diff] [blame] | 73 | snd_soc_unregister_card(card); |
| 74 | kfree(card->dai_link); |
| 75 | kfree(card); |
Srinivas Kandagatla | a6f933f | 2018-05-18 13:56:10 +0100 | [diff] [blame] | 76 | |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | static const struct of_device_id msm_snd_apq8096_dt_match[] = { |
| 81 | {.compatible = "qcom,apq8096-sndcard"}, |
| 82 | {} |
| 83 | }; |
| 84 | |
| 85 | MODULE_DEVICE_TABLE(of, msm_snd_apq8096_dt_match); |
| 86 | |
| 87 | static 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 Kandagatla | a6f933f | 2018-05-18 13:56:10 +0100 | [diff] [blame] | 92 | .of_match_table = msm_snd_apq8096_dt_match, |
| 93 | }, |
| 94 | }; |
| 95 | module_platform_driver(msm_snd_apq8096_driver); |
| 96 | MODULE_AUTHOR("Srinivas Kandagatla <srinivas.kandagatla@linaro.org"); |
| 97 | MODULE_DESCRIPTION("APQ8096 ASoC Machine Driver"); |
| 98 | MODULE_LICENSE("GPL v2"); |