Commit 49ea07d3 authored by Pierre-Louis Bossart's avatar Pierre-Louis Bossart Committed by Vinod Koul

soundwire: intel/cadence: fix startup sequence

Multiple changes squashed in single patch to avoid tick-tock effect
and avoid breaking compilation/bisect

1. Per the hardware documentation, all changes to MCP_CONFIG,
MCP_CONTROL, MCP_CMDCTRL and MCP_PHYCTRL need to be validated with a
self-clearing write to MCP_CONFIG_UPDATE. Add a helper and do the
update when the CONFIG is changed.

2. Move interrupt enable after interrupt handler registration

3. Add a new helper to start the hardware bus reset with maximum duration
to make sure the Slave(s) correctly detect the reset pattern and to
ensure electrical conflicts can be resolved.

4. flush command FIFOs

Better error handling will be provided after interrupt disable is
provided in follow-up patches.
Signed-off-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20191022235448.17586-2-pierre-louis.bossart@linux.intel.comSigned-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent 3fc40449
...@@ -228,6 +228,22 @@ static int cdns_clear_bit(struct sdw_cdns *cdns, int offset, u32 value) ...@@ -228,6 +228,22 @@ static int cdns_clear_bit(struct sdw_cdns *cdns, int offset, u32 value)
return -EAGAIN; return -EAGAIN;
} }
/*
* all changes to the MCP_CONFIG, MCP_CONTROL, MCP_CMDCTRL and MCP_PHYCTRL
* need to be confirmed with a write to MCP_CONFIG_UPDATE
*/
static int cdns_update_config(struct sdw_cdns *cdns)
{
int ret;
ret = cdns_clear_bit(cdns, CDNS_MCP_CONFIG_UPDATE,
CDNS_MCP_CONFIG_UPDATE_BIT);
if (ret < 0)
dev_err(cdns->dev, "Config update timedout\n");
return ret;
}
/* /*
* debugfs * debugfs
*/ */
...@@ -745,7 +761,38 @@ EXPORT_SYMBOL(sdw_cdns_thread); ...@@ -745,7 +761,38 @@ EXPORT_SYMBOL(sdw_cdns_thread);
/* /*
* init routines * init routines
*/ */
static int _cdns_enable_interrupt(struct sdw_cdns *cdns)
/**
* sdw_cdns_exit_reset() - Program reset parameters and start bus operations
* @cdns: Cadence instance
*/
int sdw_cdns_exit_reset(struct sdw_cdns *cdns)
{
/* program maximum length reset to be safe */
cdns_updatel(cdns, CDNS_MCP_CONTROL,
CDNS_MCP_CONTROL_RST_DELAY,
CDNS_MCP_CONTROL_RST_DELAY);
/* use hardware generated reset */
cdns_updatel(cdns, CDNS_MCP_CONTROL,
CDNS_MCP_CONTROL_HW_RST,
CDNS_MCP_CONTROL_HW_RST);
/* enable bus operations with clock and data */
cdns_updatel(cdns, CDNS_MCP_CONFIG,
CDNS_MCP_CONFIG_OP,
CDNS_MCP_CONFIG_OP_NORMAL);
/* commit changes */
return cdns_update_config(cdns);
}
EXPORT_SYMBOL(sdw_cdns_exit_reset);
/**
* sdw_cdns_enable_interrupt() - Enable SDW interrupts and update config
* @cdns: Cadence instance
*/
int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns)
{ {
u32 mask; u32 mask;
...@@ -777,24 +824,8 @@ static int _cdns_enable_interrupt(struct sdw_cdns *cdns) ...@@ -777,24 +824,8 @@ static int _cdns_enable_interrupt(struct sdw_cdns *cdns)
cdns_writel(cdns, CDNS_MCP_INTMASK, mask); cdns_writel(cdns, CDNS_MCP_INTMASK, mask);
return 0; /* commit changes */
} return cdns_update_config(cdns);
/**
* sdw_cdns_enable_interrupt() - Enable SDW interrupts and update config
* @cdns: Cadence instance
*/
int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns)
{
int ret;
_cdns_enable_interrupt(cdns);
ret = cdns_clear_bit(cdns, CDNS_MCP_CONFIG_UPDATE,
CDNS_MCP_CONFIG_UPDATE_BIT);
if (ret < 0)
dev_err(cdns->dev, "Config update timedout\n");
return ret;
} }
EXPORT_SYMBOL(sdw_cdns_enable_interrupt); EXPORT_SYMBOL(sdw_cdns_enable_interrupt);
...@@ -955,6 +986,10 @@ int sdw_cdns_init(struct sdw_cdns *cdns) ...@@ -955,6 +986,10 @@ int sdw_cdns_init(struct sdw_cdns *cdns)
cdns_writel(cdns, CDNS_MCP_SSP_CTRL0, CDNS_DEFAULT_SSP_INTERVAL); cdns_writel(cdns, CDNS_MCP_SSP_CTRL0, CDNS_DEFAULT_SSP_INTERVAL);
cdns_writel(cdns, CDNS_MCP_SSP_CTRL1, CDNS_DEFAULT_SSP_INTERVAL); cdns_writel(cdns, CDNS_MCP_SSP_CTRL1, CDNS_DEFAULT_SSP_INTERVAL);
/* flush command FIFOs */
cdns_updatel(cdns, CDNS_MCP_CONTROL, CDNS_MCP_CONTROL_CMD_RST,
CDNS_MCP_CONTROL_CMD_RST);
/* Set cmd accept mode */ /* Set cmd accept mode */
cdns_updatel(cdns, CDNS_MCP_CONTROL, CDNS_MCP_CONTROL_CMD_ACCEPT, cdns_updatel(cdns, CDNS_MCP_CONTROL, CDNS_MCP_CONTROL_CMD_ACCEPT,
CDNS_MCP_CONTROL_CMD_ACCEPT); CDNS_MCP_CONTROL_CMD_ACCEPT);
...@@ -977,13 +1012,10 @@ int sdw_cdns_init(struct sdw_cdns *cdns) ...@@ -977,13 +1012,10 @@ int sdw_cdns_init(struct sdw_cdns *cdns)
/* Set cmd mode for Tx and Rx cmds */ /* Set cmd mode for Tx and Rx cmds */
val &= ~CDNS_MCP_CONFIG_CMD; val &= ~CDNS_MCP_CONFIG_CMD;
/* Set operation to normal */
val &= ~CDNS_MCP_CONFIG_OP;
val |= CDNS_MCP_CONFIG_OP_NORMAL;
cdns_writel(cdns, CDNS_MCP_CONFIG, val); cdns_writel(cdns, CDNS_MCP_CONFIG, val);
return 0; /* commit changes */
return cdns_update_config(cdns);
} }
EXPORT_SYMBOL(sdw_cdns_init); EXPORT_SYMBOL(sdw_cdns_init);
......
...@@ -141,6 +141,7 @@ irqreturn_t sdw_cdns_thread(int irq, void *dev_id); ...@@ -141,6 +141,7 @@ irqreturn_t sdw_cdns_thread(int irq, void *dev_id);
int sdw_cdns_init(struct sdw_cdns *cdns); int sdw_cdns_init(struct sdw_cdns *cdns);
int sdw_cdns_pdi_init(struct sdw_cdns *cdns, int sdw_cdns_pdi_init(struct sdw_cdns *cdns,
struct sdw_cdns_stream_config config); struct sdw_cdns_stream_config config);
int sdw_cdns_exit_reset(struct sdw_cdns *cdns);
int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns); int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns);
#ifdef CONFIG_DEBUG_FS #ifdef CONFIG_DEBUG_FS
......
...@@ -947,8 +947,6 @@ static int intel_probe(struct platform_device *pdev) ...@@ -947,8 +947,6 @@ static int intel_probe(struct platform_device *pdev)
if (ret) if (ret)
goto err_init; goto err_init;
ret = sdw_cdns_enable_interrupt(&sdw->cdns);
/* Read the PDI config and initialize cadence PDI */ /* Read the PDI config and initialize cadence PDI */
intel_pdi_init(sdw, &config); intel_pdi_init(sdw, &config);
ret = sdw_cdns_pdi_init(&sdw->cdns, config); ret = sdw_cdns_pdi_init(&sdw->cdns, config);
...@@ -966,6 +964,18 @@ static int intel_probe(struct platform_device *pdev) ...@@ -966,6 +964,18 @@ static int intel_probe(struct platform_device *pdev)
goto err_init; goto err_init;
} }
ret = sdw_cdns_enable_interrupt(&sdw->cdns);
if (ret < 0) {
dev_err(sdw->cdns.dev, "cannot enable interrupts\n");
goto err_init;
}
ret = sdw_cdns_exit_reset(&sdw->cdns);
if (ret < 0) {
dev_err(sdw->cdns.dev, "unable to exit bus reset sequence\n");
goto err_init;
}
/* Register DAIs */ /* Register DAIs */
ret = intel_register_dai(sdw); ret = intel_register_dai(sdw);
if (ret) { if (ret) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment