blob: c026af3a340f0bdd468bca30c71901f57ebe4e68 [file] [log] [blame]
Googler9398cc32022-12-02 17:21:52 +08001// SPDX-License-Identifier: GPL-2.0
Googler4f18c0c2022-09-20 17:23:36 +08002/*
Googler9398cc32022-12-02 17:21:52 +08003 * ALSA SoC dummy codec driver
Googler4f18c0c2022-09-20 17:23:36 +08004 *
Googler9398cc32022-12-02 17:21:52 +08005 * Copyright (C) 2019 Amlogic,inc
Googler4f18c0c2022-09-20 17:23:36 +08006 *
7 */
8
Googler4f18c0c2022-09-20 17:23:36 +08009#include <linux/module.h>
10#include <linux/platform_device.h>
11#include <linux/slab.h>
12#include <sound/core.h>
13#include <sound/tlv.h>
14#include <sound/soc.h>
15#include <sound/soc-dapm.h>
16#include <sound/initval.h>
17#include <linux/of.h>
18
Googler9398cc32022-12-02 17:21:52 +080019#define DRV_NAME "dummy"
20
Googler4f18c0c2022-09-20 17:23:36 +080021struct dummy_codec_private {
Googler9398cc32022-12-02 17:21:52 +080022 struct snd_soc_component component;
Googler4f18c0c2022-09-20 17:23:36 +080023};
24
Googler9398cc32022-12-02 17:21:52 +080025#define DUMMY_CODEC_RATES (SNDRV_PCM_RATE_8000_192000)
26#define DUMMY_CODEC_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
27 SNDRV_PCM_FMTBIT_S24_LE | \
28 SNDRV_PCM_FMTBIT_S32_LE)
Googler4f18c0c2022-09-20 17:23:36 +080029
30static const struct snd_soc_dapm_widget dummy_codec_dapm_widgets[] = {
31 /* Output Side */
32 /* DACs */
Googler9398cc32022-12-02 17:21:52 +080033 SND_SOC_DAPM_DAC("Left DAC", "HIFI Playback", SND_SOC_NOPM, 0, 0),
34 SND_SOC_DAPM_DAC("Right DAC", "HIFI Playback", SND_SOC_NOPM, 7, 0),
Googler4f18c0c2022-09-20 17:23:36 +080035
36 /* Output Lines */
37 SND_SOC_DAPM_OUTPUT("LOUTL"),
38 SND_SOC_DAPM_OUTPUT("LOUTR"),
39
40};
41
42static const struct snd_soc_dapm_route dummy_codec_dapm_routes[] = {
Googler4f18c0c2022-09-20 17:23:36 +080043 {"LOUTL", NULL, "Left DAC"},
44 {"LOUTR", NULL, "Right DAC"},
45};
46
Googler4f18c0c2022-09-20 17:23:36 +080047struct snd_soc_dai_driver dummy_codec_dai = {
Googler9398cc32022-12-02 17:21:52 +080048 .name = DRV_NAME,
49 .id = 0,
Googler4f18c0c2022-09-20 17:23:36 +080050 .playback = {
Googler9398cc32022-12-02 17:21:52 +080051 .stream_name = "HIFI Playback",
52 .channels_min = 1,
53 .channels_max = 32,
54 .rates = DUMMY_CODEC_RATES,
55 .formats = DUMMY_CODEC_FORMATS,
56 },
57 .capture = {
58 .stream_name = "HIFI Capture",
59 .channels_min = 1,
60 .channels_max = 32,
61 .rates = DUMMY_CODEC_RATES,
62 .formats = DUMMY_CODEC_FORMATS,
63 },
Googler4f18c0c2022-09-20 17:23:36 +080064};
65
Googler9398cc32022-12-02 17:21:52 +080066static const struct snd_soc_component_driver soc_codec_dev_dummy_codec = {
67 .name = DRV_NAME,
Googler4f18c0c2022-09-20 17:23:36 +080068
Googler9398cc32022-12-02 17:21:52 +080069 .dapm_widgets = dummy_codec_dapm_widgets,
70 .num_dapm_widgets = ARRAY_SIZE(dummy_codec_dapm_widgets),
71 .dapm_routes = dummy_codec_dapm_routes,
72 .num_dapm_routes = ARRAY_SIZE(dummy_codec_dapm_routes),
Googler4f18c0c2022-09-20 17:23:36 +080073};
74
Googler4f18c0c2022-09-20 17:23:36 +080075static const struct of_device_id amlogic_codec_dt_match[] = {
76 {.compatible = "amlogic, aml_dummy_codec",
77 },
78 {},
79};
Googler4f18c0c2022-09-20 17:23:36 +080080
81static int dummy_codec_platform_probe(struct platform_device *pdev)
82{
83 struct dummy_codec_private *dummy_codec;
84 int ret;
85
Googler9398cc32022-12-02 17:21:52 +080086 dummy_codec = kzalloc(sizeof(*dummy_codec), GFP_KERNEL);
87 if (!dummy_codec)
Googler4f18c0c2022-09-20 17:23:36 +080088 return -ENOMEM;
89
90 platform_set_drvdata(pdev, dummy_codec);
Googler9398cc32022-12-02 17:21:52 +080091 ret = devm_snd_soc_register_component(&pdev->dev,
92 &soc_codec_dev_dummy_codec,
93 &dummy_codec_dai, 1);
Googler4f18c0c2022-09-20 17:23:36 +080094
95 if (ret < 0)
96 kfree(dummy_codec);
97
98 return ret;
99}
100
101static int dummy_codec_platform_remove(struct platform_device *pdev)
102{
Googler4f18c0c2022-09-20 17:23:36 +0800103 kfree(platform_get_drvdata(pdev));
Googler9398cc32022-12-02 17:21:52 +0800104
Googler4f18c0c2022-09-20 17:23:36 +0800105 return 0;
106}
107
108static struct platform_driver dummy_codec_platform_driver = {
109 .driver = {
Googler9398cc32022-12-02 17:21:52 +0800110 .name = DRV_NAME,
111 .owner = THIS_MODULE,
112 .of_match_table = of_match_ptr(amlogic_codec_dt_match),
Googler4f18c0c2022-09-20 17:23:36 +0800113 },
Googler9398cc32022-12-02 17:21:52 +0800114 .probe = dummy_codec_platform_probe,
Googler4f18c0c2022-09-20 17:23:36 +0800115 .remove = dummy_codec_platform_remove,
116};
117
Googler9398cc32022-12-02 17:21:52 +0800118module_platform_driver(dummy_codec_platform_driver);
Googler4f18c0c2022-09-20 17:23:36 +0800119
120MODULE_AUTHOR("AMLogic, Inc.");
121MODULE_DESCRIPTION("ASoC dummy_codec driver");
122MODULE_LICENSE("GPL");
Googler9398cc32022-12-02 17:21:52 +0800123