Skip to content

Commit

Permalink
ASoC: SOF: amd: refactor PSP smn_read
Browse files Browse the repository at this point in the history
Use the read_poll_timeout marco for PSP smn_read calls.

Signed-off-by: Mastan Katragadda <[email protected]>
  • Loading branch information
mkatraga committed Jun 15, 2023
1 parent 8597031 commit 29b070b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
34 changes: 15 additions & 19 deletions sound/soc/sof/amd/acp.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ static int smn_write(struct pci_dev *dev, u32 smn_addr, u32 data)
return 0;
}

static int smn_read(struct pci_dev *dev, u32 smn_addr, u32 *data)
static int smn_read(struct pci_dev *dev, u32 smn_addr)
{
u32 data = 0;

pci_write_config_dword(dev, 0x60, smn_addr);
pci_read_config_dword(dev, 0x64, data);
pci_read_config_dword(dev, 0x64, &data);

return 0;
return data;
}

static void init_dma_descriptor(struct acp_dev_data *adata)
Expand Down Expand Up @@ -150,15 +152,13 @@ int configure_and_run_dma(struct acp_dev_data *adata, unsigned int src_addr,
static int psp_mbox_ready(struct acp_dev_data *adata, bool ack)
{
struct snd_sof_dev *sdev = adata->dev;
int timeout;
int ret;
u32 data;

for (timeout = ACP_PSP_TIMEOUT_COUNTER; timeout > 0; timeout--) {
msleep(20);
smn_read(adata->smn_dev, MP0_C2PMSG_114_REG, &data);
if (data & MBOX_READY_MASK)
return 0;
}
ret = read_poll_timeout(smn_read, data, data & MBOX_READY_MASK, MBOX_DELAY_US,
ACP_PSP_TIMEOUT, false, adata->smn_dev, MP0_C2PMSG_114_REG);
if (!ret)
return 0;

dev_err(sdev->dev, "PSP error status %x\n", data & MBOX_STATUS_MASK);

Expand All @@ -177,23 +177,19 @@ static int psp_mbox_ready(struct acp_dev_data *adata, bool ack)
static int psp_send_cmd(struct acp_dev_data *adata, int cmd)
{
struct snd_sof_dev *sdev = adata->dev;
int ret, timeout;
int ret;
u32 data;

if (!cmd)
return -EINVAL;

/* Get a non-zero Doorbell value from PSP */
for (timeout = ACP_PSP_TIMEOUT_COUNTER; timeout > 0; timeout--) {
msleep(MBOX_DELAY);
smn_read(adata->smn_dev, MP0_C2PMSG_73_REG, &data);
if (data)
break;
}
ret = read_poll_timeout(smn_read, data, data, MBOX_DELAY_US, ACP_PSP_TIMEOUT, false,
adata->smn_dev, MP0_C2PMSG_73_REG);

if (!timeout) {
if (ret) {
dev_err(sdev->dev, "Failed to get Doorbell from MBOX %x\n", MP0_C2PMSG_73_REG);
return -EINVAL;
return ret;
}

/* Check if PSP is ready for new command */
Expand Down
4 changes: 2 additions & 2 deletions sound/soc/sof/amd/acp.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@
#define HOST_BRIDGE_CZN 0x1630
#define HOST_BRIDGE_RMB 0x14B5
#define ACP_SHA_STAT 0x8000
#define ACP_PSP_TIMEOUT_COUNTER 5
#define ACP_PSP_TIMEOUT 1000000
#define ACP_EXT_INTR_ERROR_STAT 0x20000000
#define MP0_C2PMSG_114_REG 0x3810AC8
#define MP0_C2PMSG_73_REG 0x3810A24
#define MBOX_ACP_SHA_DMA_COMMAND 0x70000
#define MBOX_DELAY 1000
#define MBOX_DELAY_US 1000
#define MBOX_READY_MASK 0x80000000
#define MBOX_STATUS_MASK 0xFFFF

Expand Down

0 comments on commit 29b070b

Please sign in to comment.