Skip to content

Commit 846aef1

Browse files
ajitkupandeybroonie
authored andcommitted
ASoC: SOF: amd: Add Renoir ACP HW support
This patch initializes ACP HW block to support SOF on AMD Renoir platform. Signed-off-by: Ajit Kumar Pandey <[email protected]> Reviewed-by: Bard Liao <[email protected]> Reviewed-by: Kai Vehmanen <[email protected]> Signed-off-by: Daniel Baluta <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 7548a39 commit 846aef1

File tree

8 files changed

+251
-0
lines changed

8 files changed

+251
-0
lines changed

sound/soc/sof/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ config SND_SOC_SOF_PROBE_WORK_QUEUE
225225
When selected, the probe is handled in two steps, for example to
226226
avoid lockdeps if request_module is used in the probe.
227227

228+
source "sound/soc/sof/amd/Kconfig"
228229
source "sound/soc/sof/imx/Kconfig"
229230
source "sound/soc/sof/intel/Kconfig"
230231
source "sound/soc/sof/xtensa/Kconfig"

sound/soc/sof/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ obj-$(CONFIG_SND_SOC_SOF_PCI_DEV) += snd-sof-pci.o
2222

2323
obj-$(CONFIG_SND_SOC_SOF_INTEL_TOPLEVEL) += intel/
2424
obj-$(CONFIG_SND_SOC_SOF_IMX_TOPLEVEL) += imx/
25+
obj-$(CONFIG_SND_SOC_SOF_AMD_TOPLEVEL) += amd/
2526
obj-$(CONFIG_SND_SOC_SOF_XTENSA) += xtensa/

sound/soc/sof/amd/Kconfig

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2+
# This file is provided under a dual BSD/GPLv2 license. When using or
3+
# redistributing this file, you may do so under either license.
4+
#
5+
# Copyright(c) 2021 Advanced Micro Devices, Inc. All rights reserved.
6+
7+
config SND_SOC_SOF_AMD_TOPLEVEL
8+
tristate "SOF support for AMD audio DSPs"
9+
depends on X86 || COMPILE_TEST
10+
help
11+
This adds support for Sound Open Firmware for AMD platforms.
12+
Say Y if you have such a device.
13+
If unsure select "N".
14+
15+
if SND_SOC_SOF_AMD_TOPLEVEL
16+
17+
config SND_SOC_SOF_AMD_COMMON
18+
tristate
19+
select SND_SOC_SOF
20+
help
21+
This option is not user-selectable but automatically handled by
22+
'select' statements at a higher level
23+
24+
config SND_SOC_SOF_AMD_RENOIR
25+
tristate "SOF support for RENOIR"
26+
select SND_SOC_SOF_AMD_COMMON
27+
help
28+
Select this option for SOF support on AMD Renoir platform
29+
30+
endif

sound/soc/sof/amd/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2+
# This file is provided under a dual BSD/GPLv2 license. When using or
3+
# redistributing this file, you may do so under either license.
4+
#
5+
# Copyright(c) 2021 Advanced Micro Devices, Inc. All rights reserved.
6+
7+
snd-sof-amd-acp-objs := acp.o
8+
snd-sof-amd-renoir-objs := renoir.o
9+
10+
obj-$(CONFIG_SND_SOC_SOF_AMD_COMMON) += snd-sof-amd-acp.o
11+
obj-$(CONFIG_SND_SOC_SOF_AMD_RENOIR) +=snd-sof-amd-renoir.o

sound/soc/sof/amd/acp-dsp-offset.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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. All rights reserved.
7+
*
8+
* Author: Ajit Kumar Pandey <[email protected]>
9+
*/
10+
11+
#ifndef _ACP_DSP_IP_OFFSET_H
12+
#define _ACP_DSP_IP_OFFSET_H
13+
14+
#define ACP_SOFT_RESET 0x1000
15+
16+
/* Registers from ACP_PGFSM block */
17+
#define ACP_PGFSM_CONTROL 0x141C
18+
#define ACP_PGFSM_STATUS 0x1420
19+
20+
#endif

sound/soc/sof/amd/acp.c

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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. All rights reserved.
7+
//
8+
// Authors: Vijendar Mukunda <[email protected]>
9+
// Ajit Kumar Pandey <[email protected]>
10+
11+
/*
12+
* Hardware interface for generic AMD ACP processor
13+
*/
14+
15+
#include <linux/io.h>
16+
#include <linux/module.h>
17+
#include <linux/pci.h>
18+
19+
#include "../ops.h"
20+
#include "acp.h"
21+
#include "acp-dsp-offset.h"
22+
23+
static int acp_power_on(struct snd_sof_dev *sdev)
24+
{
25+
unsigned int val;
26+
int ret;
27+
28+
val = snd_sof_dsp_read(sdev, ACP_DSP_BAR, ACP_PGFSM_STATUS);
29+
30+
if (val == ACP_POWERED_ON)
31+
return 0;
32+
33+
if (val & ACP_PGFSM_STATUS_MASK)
34+
snd_sof_dsp_write(sdev, ACP_DSP_BAR, ACP_PGFSM_CONTROL,
35+
ACP_PGFSM_CNTL_POWER_ON_MASK);
36+
37+
ret = snd_sof_dsp_read_poll_timeout(sdev, ACP_DSP_BAR, ACP_PGFSM_STATUS, val, !val,
38+
ACP_REG_POLL_INTERVAL, ACP_REG_POLL_TIMEOUT_US);
39+
if (ret < 0)
40+
dev_err(sdev->dev, "timeout in ACP_PGFSM_STATUS read\n");
41+
42+
return ret;
43+
}
44+
45+
static int acp_reset(struct snd_sof_dev *sdev)
46+
{
47+
unsigned int val;
48+
int ret;
49+
50+
snd_sof_dsp_write(sdev, ACP_DSP_BAR, ACP_SOFT_RESET, ACP_ASSERT_RESET);
51+
52+
ret = snd_sof_dsp_read_poll_timeout(sdev, ACP_DSP_BAR, ACP_SOFT_RESET, val,
53+
val & ACP_SOFT_RESET_DONE_MASK,
54+
ACP_REG_POLL_INTERVAL, ACP_REG_POLL_TIMEOUT_US);
55+
if (ret < 0) {
56+
dev_err(sdev->dev, "timeout asserting reset\n");
57+
return ret;
58+
}
59+
60+
snd_sof_dsp_write(sdev, ACP_DSP_BAR, ACP_SOFT_RESET, ACP_RELEASE_RESET);
61+
62+
ret = snd_sof_dsp_read_poll_timeout(sdev, ACP_DSP_BAR, ACP_SOFT_RESET, val, !val,
63+
ACP_REG_POLL_INTERVAL, ACP_REG_POLL_TIMEOUT_US);
64+
if (ret < 0)
65+
dev_err(sdev->dev, "timeout in releasing reset\n");
66+
67+
return ret;
68+
}
69+
70+
static int acp_init(struct snd_sof_dev *sdev)
71+
{
72+
int ret;
73+
74+
/* power on */
75+
ret = acp_power_on(sdev);
76+
if (ret) {
77+
dev_err(sdev->dev, "ACP power on failed\n");
78+
return ret;
79+
}
80+
/* Reset */
81+
return acp_reset(sdev);
82+
}
83+
84+
int amd_sof_acp_probe(struct snd_sof_dev *sdev)
85+
{
86+
struct pci_dev *pci = to_pci_dev(sdev->dev);
87+
struct acp_dev_data *adata;
88+
unsigned int addr;
89+
90+
adata = devm_kzalloc(sdev->dev, sizeof(struct acp_dev_data),
91+
GFP_KERNEL);
92+
if (!adata)
93+
return -ENOMEM;
94+
95+
adata->dev = sdev;
96+
addr = pci_resource_start(pci, ACP_DSP_BAR);
97+
sdev->bar[ACP_DSP_BAR] = devm_ioremap(sdev->dev, addr, pci_resource_len(pci, ACP_DSP_BAR));
98+
if (!sdev->bar[ACP_DSP_BAR]) {
99+
dev_err(sdev->dev, "ioremap error\n");
100+
return -ENXIO;
101+
}
102+
103+
pci_set_master(pci);
104+
105+
sdev->pdata->hw_pdata = adata;
106+
107+
return acp_init(sdev);
108+
}
109+
EXPORT_SYMBOL_NS(amd_sof_acp_probe, SND_SOC_SOF_AMD_COMMON);
110+
111+
int amd_sof_acp_remove(struct snd_sof_dev *sdev)
112+
{
113+
return acp_reset(sdev);
114+
}
115+
EXPORT_SYMBOL_NS(amd_sof_acp_remove, SND_SOC_SOF_AMD_COMMON);
116+
117+
MODULE_DESCRIPTION("AMD ACP sof driver");
118+
MODULE_LICENSE("Dual BSD/GPL");

sound/soc/sof/amd/acp.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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. All rights reserved.
7+
*
8+
* Author: Ajit Kumar Pandey <[email protected]>
9+
*/
10+
11+
#ifndef __SOF_AMD_ACP_H
12+
#define __SOF_AMD_ACP_H
13+
14+
#define ACP_DSP_BAR 0
15+
16+
#define ACP_REG_POLL_INTERVAL 500
17+
#define ACP_REG_POLL_TIMEOUT_US 2000
18+
19+
#define ACP_PGFSM_CNTL_POWER_ON_MASK 0x01
20+
#define ACP_PGFSM_STATUS_MASK 0x03
21+
#define ACP_POWERED_ON 0x00
22+
#define ACP_ASSERT_RESET 0x01
23+
#define ACP_RELEASE_RESET 0x00
24+
#define ACP_SOFT_RESET_DONE_MASK 0x00010001
25+
26+
/* Common device data struct for ACP devices */
27+
struct acp_dev_data {
28+
struct snd_sof_dev *dev;
29+
};
30+
31+
/* ACP device probe/remove */
32+
int amd_sof_acp_probe(struct snd_sof_dev *sdev);
33+
int amd_sof_acp_remove(struct snd_sof_dev *sdev);
34+
35+
extern const struct snd_sof_dsp_ops sof_renoir_ops;
36+
#endif

sound/soc/sof/amd/renoir.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 <[email protected]>
9+
10+
/*
11+
* Hardware interface for Audio DSP on Renoir platform
12+
*/
13+
14+
#include <linux/platform_device.h>
15+
#include <linux/module.h>
16+
17+
#include "../ops.h"
18+
#include "acp.h"
19+
20+
/* AMD Renoir DSP ops */
21+
const struct snd_sof_dsp_ops sof_renoir_ops = {
22+
/* probe and remove */
23+
.probe = amd_sof_acp_probe,
24+
.remove = amd_sof_acp_remove,
25+
26+
/* Register IO */
27+
.write = sof_io_write,
28+
.read = sof_io_read,
29+
};
30+
EXPORT_SYMBOL(sof_renoir_ops);
31+
32+
MODULE_IMPORT_NS(SND_SOC_SOF_AMD_COMMON);
33+
MODULE_DESCRIPTION("RENOIR SOF Driver");
34+
MODULE_LICENSE("Dual BSD/GPL");

0 commit comments

Comments
 (0)