Googler | 9398cc3 | 2022-12-02 17:21:52 +0800 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 2 | /* |
Googler | 9398cc3 | 2022-12-02 17:21:52 +0800 | [diff] [blame^] | 3 | * ALSA SoC dummy codec driver |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 4 | * |
Googler | 9398cc3 | 2022-12-02 17:21:52 +0800 | [diff] [blame^] | 5 | * Copyright (C) 2019 Amlogic,inc |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 6 | * |
| 7 | */ |
| 8 | |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 9 | #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 | |
Googler | 9398cc3 | 2022-12-02 17:21:52 +0800 | [diff] [blame^] | 19 | #define DRV_NAME "dummy" |
| 20 | |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 21 | struct dummy_codec_private { |
Googler | 9398cc3 | 2022-12-02 17:21:52 +0800 | [diff] [blame^] | 22 | struct snd_soc_component component; |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 23 | }; |
| 24 | |
Googler | 9398cc3 | 2022-12-02 17:21:52 +0800 | [diff] [blame^] | 25 | #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) |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 29 | |
| 30 | static const struct snd_soc_dapm_widget dummy_codec_dapm_widgets[] = { |
| 31 | /* Output Side */ |
| 32 | /* DACs */ |
Googler | 9398cc3 | 2022-12-02 17:21:52 +0800 | [diff] [blame^] | 33 | 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), |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 35 | |
| 36 | /* Output Lines */ |
| 37 | SND_SOC_DAPM_OUTPUT("LOUTL"), |
| 38 | SND_SOC_DAPM_OUTPUT("LOUTR"), |
| 39 | |
| 40 | }; |
| 41 | |
| 42 | static const struct snd_soc_dapm_route dummy_codec_dapm_routes[] = { |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 43 | {"LOUTL", NULL, "Left DAC"}, |
| 44 | {"LOUTR", NULL, "Right DAC"}, |
| 45 | }; |
| 46 | |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 47 | struct snd_soc_dai_driver dummy_codec_dai = { |
Googler | 9398cc3 | 2022-12-02 17:21:52 +0800 | [diff] [blame^] | 48 | .name = DRV_NAME, |
| 49 | .id = 0, |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 50 | .playback = { |
Googler | 9398cc3 | 2022-12-02 17:21:52 +0800 | [diff] [blame^] | 51 | .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 | }, |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 64 | }; |
| 65 | |
Googler | 9398cc3 | 2022-12-02 17:21:52 +0800 | [diff] [blame^] | 66 | static const struct snd_soc_component_driver soc_codec_dev_dummy_codec = { |
| 67 | .name = DRV_NAME, |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 68 | |
Googler | 9398cc3 | 2022-12-02 17:21:52 +0800 | [diff] [blame^] | 69 | .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), |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 73 | }; |
| 74 | |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 75 | static const struct of_device_id amlogic_codec_dt_match[] = { |
| 76 | {.compatible = "amlogic, aml_dummy_codec", |
| 77 | }, |
| 78 | {}, |
| 79 | }; |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 80 | |
| 81 | static int dummy_codec_platform_probe(struct platform_device *pdev) |
| 82 | { |
| 83 | struct dummy_codec_private *dummy_codec; |
| 84 | int ret; |
| 85 | |
Googler | 9398cc3 | 2022-12-02 17:21:52 +0800 | [diff] [blame^] | 86 | dummy_codec = kzalloc(sizeof(*dummy_codec), GFP_KERNEL); |
| 87 | if (!dummy_codec) |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 88 | return -ENOMEM; |
| 89 | |
| 90 | platform_set_drvdata(pdev, dummy_codec); |
Googler | 9398cc3 | 2022-12-02 17:21:52 +0800 | [diff] [blame^] | 91 | ret = devm_snd_soc_register_component(&pdev->dev, |
| 92 | &soc_codec_dev_dummy_codec, |
| 93 | &dummy_codec_dai, 1); |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 94 | |
| 95 | if (ret < 0) |
| 96 | kfree(dummy_codec); |
| 97 | |
| 98 | return ret; |
| 99 | } |
| 100 | |
| 101 | static int dummy_codec_platform_remove(struct platform_device *pdev) |
| 102 | { |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 103 | kfree(platform_get_drvdata(pdev)); |
Googler | 9398cc3 | 2022-12-02 17:21:52 +0800 | [diff] [blame^] | 104 | |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static struct platform_driver dummy_codec_platform_driver = { |
| 109 | .driver = { |
Googler | 9398cc3 | 2022-12-02 17:21:52 +0800 | [diff] [blame^] | 110 | .name = DRV_NAME, |
| 111 | .owner = THIS_MODULE, |
| 112 | .of_match_table = of_match_ptr(amlogic_codec_dt_match), |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 113 | }, |
Googler | 9398cc3 | 2022-12-02 17:21:52 +0800 | [diff] [blame^] | 114 | .probe = dummy_codec_platform_probe, |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 115 | .remove = dummy_codec_platform_remove, |
| 116 | }; |
| 117 | |
Googler | 9398cc3 | 2022-12-02 17:21:52 +0800 | [diff] [blame^] | 118 | module_platform_driver(dummy_codec_platform_driver); |
Googler | 4f18c0c | 2022-09-20 17:23:36 +0800 | [diff] [blame] | 119 | |
| 120 | MODULE_AUTHOR("AMLogic, Inc."); |
| 121 | MODULE_DESCRIPTION("ASoC dummy_codec driver"); |
| 122 | MODULE_LICENSE("GPL"); |
Googler | 9398cc3 | 2022-12-02 17:21:52 +0800 | [diff] [blame^] | 123 | |