xref: /openbmc/linux/sound/soc/amd/acp/acp-renoir.c (revision a9ebfc40)
1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2 //
3 // This file is provided under a dual BSD/GPLv2 license. When using or
4 // redistributing this file, you may do so under either license.
5 //
6 // Copyright(c) 2021 Advanced Micro Devices, Inc.
7 //
8 // Authors: Ajit Kumar Pandey <AjitKumar.Pandey@amd.com>
9 //
10 
11 /*
12  * Hardware interface for Renoir ACP block
13  */
14 
15 #include <linux/platform_device.h>
16 #include <linux/module.h>
17 #include <linux/err.h>
18 #include <linux/io.h>
19 #include <sound/pcm_params.h>
20 #include <sound/soc.h>
21 #include <sound/soc-dai.h>
22 #include <linux/dma-mapping.h>
23 
24 #include "amd.h"
25 
26 #define DRV_NAME "acp_asoc_renoir"
27 
28 static struct acp_resource rsrc = {
29 	.offset = 20,
30 	.no_of_ctrls = 1,
31 	.irqp_used = 0,
32 	.irq_reg_offset = 0x1800,
33 	.i2s_pin_cfg_offset = 0x1400,
34 	.i2s_mode = 0x04,
35 	.scratch_reg_offset = 0x12800,
36 	.sram_pte_offset = 0x02052800,
37 };
38 
39 static struct snd_soc_acpi_codecs amp_rt1019 = {
40 	.num_codecs = 1,
41 	.codecs = {"10EC1019"}
42 };
43 
44 static struct snd_soc_acpi_codecs amp_max = {
45 	.num_codecs = 1,
46 	.codecs = {"MX98360A"}
47 };
48 
49 static struct snd_soc_acpi_mach snd_soc_acpi_amd_acp_machines[] = {
50 	{
51 		.id = "10EC5682",
52 		.drv_name = "acp3xalc56821019",
53 		.machine_quirk = snd_soc_acpi_codec_list,
54 		.quirk_data = &amp_rt1019,
55 	},
56 	{
57 		.id = "RTL5682",
58 		.drv_name = "acp3xalc5682sm98360",
59 		.machine_quirk = snd_soc_acpi_codec_list,
60 		.quirk_data = &amp_max,
61 	},
62 	{
63 		.id = "RTL5682",
64 		.drv_name = "acp3xalc5682s1019",
65 		.machine_quirk = snd_soc_acpi_codec_list,
66 		.quirk_data = &amp_rt1019,
67 	},
68 	{
69 		.id = "AMDI1019",
70 		.drv_name = "renoir-acp",
71 	},
72 	{},
73 };
74 
75 static struct snd_soc_dai_driver acp_renoir_dai[] = {
76 {
77 	.name = "acp-i2s-sp",
78 	.id = I2S_SP_INSTANCE,
79 	.playback = {
80 		.stream_name = "I2S SP Playback",
81 		.rates = SNDRV_PCM_RATE_8000_96000,
82 		.formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 |
83 			   SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S32_LE,
84 		.channels_min = 2,
85 		.channels_max = 8,
86 		.rate_min = 8000,
87 		.rate_max = 96000,
88 	},
89 	.capture = {
90 		.stream_name = "I2S SP Capture",
91 		.rates = SNDRV_PCM_RATE_8000_48000,
92 		.formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 |
93 			   SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S32_LE,
94 		.channels_min = 2,
95 		.channels_max = 2,
96 		.rate_min = 8000,
97 		.rate_max = 48000,
98 	},
99 	.ops = &asoc_acp_cpu_dai_ops,
100 },
101 {
102 	.name = "acp-i2s-bt",
103 	.id = I2S_BT_INSTANCE,
104 	.playback = {
105 		.stream_name = "I2S BT Playback",
106 		.rates = SNDRV_PCM_RATE_8000_96000,
107 		.formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 |
108 			   SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S32_LE,
109 		.channels_min = 2,
110 		.channels_max = 8,
111 		.rate_min = 8000,
112 		.rate_max = 96000,
113 	},
114 	.capture = {
115 		.stream_name = "I2S BT Capture",
116 		.rates = SNDRV_PCM_RATE_8000_48000,
117 		.formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 |
118 			   SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S32_LE,
119 		.channels_min = 2,
120 		.channels_max = 2,
121 		.rate_min = 8000,
122 		.rate_max = 48000,
123 	},
124 	.ops = &asoc_acp_cpu_dai_ops,
125 },
126 {
127 	.name = "acp-pdm-dmic",
128 	.id = DMIC_INSTANCE,
129 	.capture = {
130 		.rates = SNDRV_PCM_RATE_8000_48000,
131 		.formats = SNDRV_PCM_FMTBIT_S32_LE,
132 		.channels_min = 2,
133 		.channels_max = 2,
134 		.rate_min = 8000,
135 		.rate_max = 48000,
136 	},
137 	.ops = &acp_dmic_dai_ops,
138 },
139 };
140 
141 
142 static int renoir_audio_probe(struct platform_device *pdev)
143 {
144 	struct device *dev = &pdev->dev;
145 	struct acp_chip_info *chip;
146 	struct acp_dev_data *adata;
147 	struct resource *res;
148 	int ret;
149 
150 	chip = dev_get_platdata(&pdev->dev);
151 	if (!chip || !chip->base) {
152 		dev_err(&pdev->dev, "ACP chip data is NULL\n");
153 		return -ENODEV;
154 	}
155 
156 	if (chip->acp_rev != ACP3X_DEV) {
157 		dev_err(&pdev->dev, "Un-supported ACP Revision %d\n", chip->acp_rev);
158 		return -ENODEV;
159 	}
160 
161 	adata = devm_kzalloc(dev, sizeof(struct acp_dev_data), GFP_KERNEL);
162 	if (!adata)
163 		return -ENOMEM;
164 
165 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "acp_mem");
166 	if (!res) {
167 		dev_err(&pdev->dev, "IORESOURCE_MEM FAILED\n");
168 		return -ENODEV;
169 	}
170 
171 	adata->acp_base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
172 	if (!adata->acp_base)
173 		return -ENOMEM;
174 
175 	ret = platform_get_irq_byname(pdev, "acp_dai_irq");
176 	if (ret < 0)
177 		return ret;
178 	adata->i2s_irq = ret;
179 
180 	adata->dev = dev;
181 	adata->dai_driver = acp_renoir_dai;
182 	adata->num_dai = ARRAY_SIZE(acp_renoir_dai);
183 	adata->rsrc = &rsrc;
184 
185 	adata->machines = snd_soc_acpi_amd_acp_machines;
186 	acp_machine_select(adata);
187 
188 	dev_set_drvdata(dev, adata);
189 	acp_enable_interrupts(adata);
190 	acp_platform_register(dev);
191 
192 	return 0;
193 }
194 
195 static void renoir_audio_remove(struct platform_device *pdev)
196 {
197 	struct device *dev = &pdev->dev;
198 	struct acp_dev_data *adata = dev_get_drvdata(dev);
199 
200 	acp_disable_interrupts(adata);
201 	acp_platform_unregister(dev);
202 }
203 
204 static struct platform_driver renoir_driver = {
205 	.probe = renoir_audio_probe,
206 	.remove_new = renoir_audio_remove,
207 	.driver = {
208 		.name = "acp_asoc_renoir",
209 	},
210 };
211 
212 module_platform_driver(renoir_driver);
213 
214 MODULE_DESCRIPTION("AMD ACP Renoir Driver");
215 MODULE_IMPORT_NS(SND_SOC_ACP_COMMON);
216 MODULE_LICENSE("Dual BSD/GPL");
217 MODULE_ALIAS("platform:" DRV_NAME);
218