ASoC/soundwire: filter out invalid PARITY errors
Subsystems (5)
Bard Liao
maintainerv2 cover ASoC/soundwire: filter out invalid PARITY errors
Some codecs may report fake PARITY errors in the initial state. This series will filter them out.
Pierre-Louis Bossart (7):
ASoC/soundwire: bus: use property to set interrupt masks
soundwire: bus: filter-out unwanted interrupt reports
soundwire: slave: add first_interrupt_done status
soundwire: bus: use quirk to filter out invalid parity errors
ASoC: codecs: realtek-soundwire: ignore initial PARITY errors
soundwire: bus: export broadcast read/write capability for tests
soundwire: cadence: add parity error injection through debugfs
drivers/soundwire/bus.c | 93 ++++++++++++++++++++++++------ drivers/soundwire/bus.h | 4 ++ drivers/soundwire/cadence_master.c | 86 +++++++++++++++++++++++++++ drivers/soundwire/slave.c | 1 + include/linux/soundwire/sdw.h | 9 +++ sound/soc/codecs/max98373-sdw.c | 3 + sound/soc/codecs/rt1308-sdw.c | 3 + sound/soc/codecs/rt5682-sdw.c | 5 ++ sound/soc/codecs/rt700-sdw.c | 5 ++ sound/soc/codecs/rt711-sdw.c | 5 ++ sound/soc/codecs/rt715-sdw.c | 5 ++ sound/soc/codecs/wsa881x.c | 1 + 12 files changed, 202 insertions(+), 18 deletions(-)
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH v2 1/7 ASoC/soundwire: bus: use property to set interrupt masks
From: Pierre-Louis Bossart <[email protected]>
Add a slave-level property and program the SCP_INT1_MASK as desired by the codec driver. Since there is no DisCo property this has to be an implementation-specific firmware property or hard-coded in the driver.
The only functionality change is that implementation-defined interrupts are no longer set for amplifiers - those interrupts are typically for jack detection or acoustic event detection/hotwording.
--- drivers/soundwire/bus.c | 12 ++++++------ include/linux/soundwire/sdw.h | 2 ++ sound/soc/codecs/max98373-sdw.c | 3 +++ sound/soc/codecs/rt1308-sdw.c | 2 ++ sound/soc/codecs/rt5682-sdw.c | 4 ++++ sound/soc/codecs/rt700-sdw.c | 4 ++++ sound/soc/codecs/rt711-sdw.c | 4 ++++ sound/soc/codecs/rt715-sdw.c | 4 ++++ sound/soc/codecs/wsa881x.c | 1 + 9 files changed, 30 insertions(+), 6 deletions(-)
drivers/soundwire/bus.c +6 -6
@@ -1184,13 +1184,13 @@ static int sdw_initialize_slave(struct sdw_slave *slave)return ret;/* -* Set bus clash, parity and SCP implementation -* defined interrupt mask -* TODO: Read implementation defined interrupt mask -* from Slave property +* Set SCP_INT1_MASK register, typically bus clash and +* implementation-defined interrupt mask. The Parity detection +* may not always be correct on startup so its use is +* device-dependent, it might e.g. only be enabled in +* steady-state after a couple of frames. */ - val =SDW_SCP_INT1_IMPL_DEF |SDW_SCP_INT1_BUS_CLASH | -SDW_SCP_INT1_PARITY ; + val = slave->prop.scp_int1_mask;/* Enable SCP interrupts */ ret =sdw_update (slave,SDW_SCP_INTMASK1 , val, val);
include/linux/soundwire/sdw.h +2 -0
@@ -357,6 +357,7 @@ struct sdw_dpn_prop {* @dp0_prop: Data Port 0 properties * @src_dpn_prop: Source Data Port N properties * @sink_dpn_prop: Sink Data Port N properties +* @scp_int1_mask: SCP_INT1_MASK desired settings */ struct sdw_slave_prop {u32 mipi_revision;
@@ -378,6 +379,7 @@ struct sdw_slave_prop {struct sdw_dp0_prop *dp0_prop;struct sdw_dpn_prop *src_dpn_prop;struct sdw_dpn_prop *sink_dpn_prop; +u8 scp_int1_mask; };/**
sound/soc/codecs/max98373-sdw.c +3 -0
@@ -15,6 +15,7 @@#include <linux/of.h> #include <linux/soundwire/sdw.h> #include <linux/soundwire/sdw_type.h> +#include <linux/soundwire/sdw_registers.h> #include "max98373.h" #include "max98373-sdw.h"
@@ -287,6 +288,8 @@ static int max98373_read_prop(struct sdw_slave *slave)unsigned long addr;struct sdw_dpn_prop *dpn; + prop->scp_int1_mask =SDW_SCP_INT1_BUS_CLASH |SDW_SCP_INT1_PARITY ; +/* BITMAP: 00001000 Dataport 3 is active */ prop->source_ports =BIT (3 );/* BITMAP: 00000010 Dataport 1 is active */
sound/soc/codecs/rt1308-sdw.c +2 -0
@@ -123,6 +123,8 @@ static int rt1308_read_prop(struct sdw_slave *slave)unsigned long addr;struct sdw_dpn_prop *dpn; + prop->scp_int1_mask =SDW_SCP_INT1_BUS_CLASH |SDW_SCP_INT1_PARITY ; + prop->paging_support = true;/* first we need to allocate memory for set bits in port lists */
sound/soc/codecs/rt5682-sdw.c +4 -0
@@ -19,6 +19,7 @@#include <linux/mutex.h> #include <linux/soundwire/sdw.h> #include <linux/soundwire/sdw_type.h> +#include <linux/soundwire/sdw_registers.h> #include <sound/core.h> #include <sound/pcm.h> #include <sound/pcm_params.h>
@@ -542,6 +543,9 @@ static int rt5682_read_prop(struct sdw_slave *slave)unsigned long addr;struct sdw_dpn_prop *dpn; + prop->scp_int1_mask =SDW_SCP_INT1_IMPL_DEF |SDW_SCP_INT1_BUS_CLASH | +SDW_SCP_INT1_PARITY ; + prop->paging_support = false;/* first we need to allocate memory for set bits in port lists */
sound/soc/codecs/rt700-sdw.c +4 -0
@@ -11,6 +11,7 @@#include <linux/mod_devicetable.h> #include <linux/soundwire/sdw.h> #include <linux/soundwire/sdw_type.h> +#include <linux/soundwire/sdw_registers.h> #include <linux/module.h> #include <linux/regmap.h> #include <sound/soc.h>
@@ -338,6 +339,9 @@ static int rt700_read_prop(struct sdw_slave *slave)unsigned long addr;struct sdw_dpn_prop *dpn; + prop->scp_int1_mask =SDW_SCP_INT1_IMPL_DEF |SDW_SCP_INT1_BUS_CLASH | +SDW_SCP_INT1_PARITY ; + prop->paging_support = false;/* first we need to allocate memory for set bits in port lists */
sound/soc/codecs/rt711-sdw.c +4 -0
@@ -11,6 +11,7 @@#include <linux/mod_devicetable.h> #include <linux/soundwire/sdw.h> #include <linux/soundwire/sdw_type.h> +#include <linux/soundwire/sdw_registers.h> #include <linux/module.h> #include <linux/regmap.h> #include <sound/soc.h>
@@ -342,6 +343,9 @@ static int rt711_read_prop(struct sdw_slave *slave)unsigned long addr;struct sdw_dpn_prop *dpn; + prop->scp_int1_mask =SDW_SCP_INT1_IMPL_DEF |SDW_SCP_INT1_BUS_CLASH | +SDW_SCP_INT1_PARITY ; + prop->paging_support = false;/* first we need to allocate memory for set bits in port lists */
sound/soc/codecs/rt715-sdw.c +4 -0
@@ -12,6 +12,7 @@#include <linux/mod_devicetable.h> #include <linux/soundwire/sdw.h> #include <linux/soundwire/sdw_type.h> +#include <linux/soundwire/sdw_registers.h> #include <linux/module.h> #include <linux/of.h> #include <linux/regmap.h>
@@ -436,6 +437,9 @@ static int rt715_read_prop(struct sdw_slave *slave)unsigned long addr;struct sdw_dpn_prop *dpn; + prop->scp_int1_mask =SDW_SCP_INT1_IMPL_DEF |SDW_SCP_INT1_BUS_CLASH | +SDW_SCP_INT1_PARITY ; + prop->paging_support = false;/* first we need to allocate memory for set bits in port lists */
sound/soc/codecs/wsa881x.c +1 -0
@@ -1112,6 +1112,7 @@ static int wsa881x_probe(struct sdw_slave *pdev, wsa881x->sconfig.type =SDW_STREAM_PDM ; pdev->prop.sink_ports =GENMASK (WSA881X_MAX_SWR_PORTS ,0 ); pdev->prop.sink_dpn_prop = wsa_sink_dpn_prop; + pdev->prop.scp_int1_mask =SDW_SCP_INT1_BUS_CLASH |SDW_SCP_INT1_PARITY ;gpiod_direction_output (wsa881x->sd_n,1 ); wsa881x->regmap =devm_regmap_init_sdw (pdev, &wsa881x_regmap_config);
Signature · 1 line
2.17.1
Re: [PATCH v2 1/7] ASoC/soundwire: bus: use property to set interrupt masks
Quoted 5 lines · Bard Liao
From: Pierre-Louis Bossart <[email protected]>
Add a slave-level property and program the
SCP_INT1_MASKas desired by the codec driver. Since there is no DisCo property this has to be an implementation-specific firmware property or hard-coded in the driver.
Bard Liao
maintainerPATCH v2 2/7 soundwire: bus: filter-out unwanted interrupt reports
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
Unlike the traditional usage, in the SoundWire specification the interrupt masks only gate the propagation of an interrupt condition to the PING frame status. They do not gate the changes of the INT_STAT registers, which will happen regardless of the mask settings. See Figure 116 of the SoundWire 1.2 specification for an in-depth description of the interrupt model.
When the bus driver reads the SCP_INT1_STAT register, it will retrieve all the interrupt status, including for the mask fields that were not explicitly set. For example, even if the PARITY mask is not set, the PARITY error status will be reported if an implementation-defined interrupt for jack detection is enabled and occurs.
Filtering undesired interrupt reports and handling has to be implemented in software. This patch enables this filtering for the INT1_IMPL_DEF, PARITY and BUS_CLASH interrupt sources.
--- drivers/soundwire/bus.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/soundwire/bus.c +8 -4
@@ -1394,12 +1394,14 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave)* interrupt */ if (buf &SDW_SCP_INT1_PARITY ) { -dev_err (&slave->dev,"Parity error detected\n" ); +if (slave->prop.scp_int1_mask &SDW_SCP_INT1_PARITY ) +dev_err (&slave->dev,"Parity error detected\n" ); clear |=SDW_SCP_INT1_PARITY ; }if (buf &SDW_SCP_INT1_BUS_CLASH ) { -dev_err (&slave->dev,"Bus clash error detected\n" ); +if (slave->prop.scp_int1_mask &SDW_SCP_INT1_BUS_CLASH ) +dev_err (&slave->dev,"Bus clash detected\n" ); clear |=SDW_SCP_INT1_BUS_CLASH ; }
@@ -1411,9 +1413,11 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave)*/ if (buf &SDW_SCP_INT1_IMPL_DEF ) { -dev_dbg (&slave->dev,"Slave impl defined interrupt\n" ); +if (slave->prop.scp_int1_mask &SDW_SCP_INT1_IMPL_DEF ) { +dev_dbg (&slave->dev,"Slave impl defined interrupt\n" ); + slave_notify = true; + } clear |=SDW_SCP_INT1_IMPL_DEF ; - slave_notify = true; }/* Check port 0 - 3 interrupts */
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH v2 3/7 soundwire: slave: add first_interrupt_done status
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
Some Slaves report incorrect information in their interrupt status registers after a master/bus reset, track the initial interrupt handling so that quirks can be introduced to filter out incorrect information while keeping interrupts enabled in steady state.
--- drivers/soundwire/bus.c | 7 ++++++- drivers/soundwire/slave.c | 1 + include/linux/soundwire/sdw.h | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-)
drivers/soundwire/bus.c +6 -1
@@ -1472,6 +1472,9 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave) goto io_err; } +/* at this point all initial interrupt sources were handled */ + slave->first_interrupt_done = true; +/* * Read status again to ensure no new interrupts arrived * while servicing interrupts.
@@ -1674,8 +1677,10 @@ void sdw_clear_slave_status(struct sdw_bus *bus, u32 request)if (!slave)continue ; -if (slave->status !=SDW_SLAVE_UNATTACHED ) +if (slave->status !=SDW_SLAVE_UNATTACHED ) {sdw_modify_slave_status (slave,SDW_SLAVE_UNATTACHED ); + slave->first_interrupt_done = false; + }/* keep track of request, used in pm_runtime resume */ slave->unattach_request = request;
drivers/soundwire/slave.c +1 -0
@@ -58,6 +58,7 @@ static int sdw_slave_add(struct sdw_bus *bus, slave->dev_num =0 ;init_completion (&slave->probe_complete); slave->probed = false; + slave->first_interrupt_done = false;for (i =0 ; i <SDW_MAX_PORTS ; i++)init_completion (&slave->port_ready[i]);
include/linux/soundwire/sdw.h +3 -0
@@ -616,6 +616,8 @@ struct sdw_slave_ops {* between the Master suspending and the codec resuming, and make sure that * when the Master triggered a reset the Slave is properly enumerated and * initialized +* @first_interrupt_done: status flag tracking if the interrupt handling +* for a Slave happens for the first time after enumeration */ struct sdw_slave {struct sdw_slave_id id;
@@ -637,6 +639,7 @@ struct sdw_slave {struct completion enumeration_complete;struct completion initialization_complete;u32 unattach_request; +bool first_interrupt_done; };#define dev_to_sdw_dev (_dev) container_of(_dev, struct sdw_slave, dev)
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH v2 4/7 soundwire: bus: use quirk to filter out invalid parity errors
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
If a Slave device reports with a quirk that its initial parity check may be incorrect, filter it but keep the parity checks active in steady state.
--- drivers/soundwire/bus.c | 8 +++++++- include/linux/soundwire/sdw.h | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-)
drivers/soundwire/bus.c +7 -1
@@ -1362,6 +1362,8 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave)unsigned long port;bool slave_notify = false;u8 buf, buf2[2 ], _buf, _buf2[2 ]; +bool parity_check; +bool parity_quirk;sdw_modify_slave_status (slave,SDW_SLAVE_ALERT );
@@ -1394,7 +1396,11 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave)* interrupt */ if (buf &SDW_SCP_INT1_PARITY ) { -if (slave->prop.scp_int1_mask &SDW_SCP_INT1_PARITY ) + parity_check = slave->prop.scp_int1_mask &SDW_SCP_INT1_PARITY ; + parity_quirk = !slave->first_interrupt_done && + (slave->prop.quirks &SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY ); + +if (parity_check && !parity_quirk)dev_err (&slave->dev,"Parity error detected\n" ); clear |=SDW_SCP_INT1_PARITY ; }
include/linux/soundwire/sdw.h +4 -0
@@ -358,6 +358,7 @@ struct sdw_dpn_prop {* @src_dpn_prop: Source Data Port N properties * @sink_dpn_prop: Sink Data Port N properties * @scp_int1_mask: SCP_INT1_MASK desired settings +* @quirks: bitmask identifying deltas from the MIPI specification */ struct sdw_slave_prop {u32 mipi_revision;
@@ -380,8 +381,11 @@ struct sdw_slave_prop {struct sdw_dpn_prop *src_dpn_prop;struct sdw_dpn_prop *sink_dpn_prop;u8 scp_int1_mask; +u32 quirks; }; +#define SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY BIT(0) +/** * struct sdw_master_prop - Master properties * @revision: MIPI spec version of the implementation
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH v2 5/7 ASoC: codecs: realtek-soundwire: ignore initial PARITY errors
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
The parity calculation is not reset on a Severe Reset, which leads to misleading/harmless errors reported on startup. The addition of a quirk helps filter out such errors while leaving the error checks on in steady-state.
--- sound/soc/codecs/rt1308-sdw.c | 1 + sound/soc/codecs/rt5682-sdw.c | 1 + sound/soc/codecs/rt700-sdw.c | 1 + sound/soc/codecs/rt711-sdw.c | 1 + sound/soc/codecs/rt715-sdw.c | 1 + 5 files changed, 5 insertions(+)
sound/soc/codecs/rt1308-sdw.c +1 -0
@@ -124,6 +124,7 @@ static int rt1308_read_prop(struct sdw_slave *slave)struct sdw_dpn_prop *dpn; prop->scp_int1_mask =SDW_SCP_INT1_BUS_CLASH |SDW_SCP_INT1_PARITY ; + prop->quirks =SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY ; prop->paging_support = true;
sound/soc/codecs/rt5682-sdw.c +1 -0
@@ -545,6 +545,7 @@ static int rt5682_read_prop(struct sdw_slave *slave) prop->scp_int1_mask =SDW_SCP_INT1_IMPL_DEF |SDW_SCP_INT1_BUS_CLASH |SDW_SCP_INT1_PARITY ; + prop->quirks =SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY ; prop->paging_support = false;
sound/soc/codecs/rt700-sdw.c +1 -0
@@ -341,6 +341,7 @@ static int rt700_read_prop(struct sdw_slave *slave) prop->scp_int1_mask =SDW_SCP_INT1_IMPL_DEF |SDW_SCP_INT1_BUS_CLASH |SDW_SCP_INT1_PARITY ; + prop->quirks =SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY ; prop->paging_support = false;
sound/soc/codecs/rt711-sdw.c +1 -0
@@ -345,6 +345,7 @@ static int rt711_read_prop(struct sdw_slave *slave) prop->scp_int1_mask =SDW_SCP_INT1_IMPL_DEF |SDW_SCP_INT1_BUS_CLASH |SDW_SCP_INT1_PARITY ; + prop->quirks =SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY ; prop->paging_support = false;
sound/soc/codecs/rt715-sdw.c +1 -0
@@ -439,6 +439,7 @@ static int rt715_read_prop(struct sdw_slave *slave) prop->scp_int1_mask =SDW_SCP_INT1_IMPL_DEF |SDW_SCP_INT1_BUS_CLASH |SDW_SCP_INT1_PARITY ; + prop->quirks =SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY ; prop->paging_support = false;
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH v2 6/7 soundwire: bus: export broadcast read/write capability for tests
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
Provide prototype and export symbol to enable tests. The bus lock is handled externally to avoid conflicts e.g. between kernel-generated traffic and test traffic.
--- drivers/soundwire/bus.c | 56 +++++++++++++++++++++++++++++++++++------ drivers/soundwire/bus.h | 4 +++ 2 files changed, 53 insertions(+), 7 deletions(-)
drivers/soundwire/bus.c +49 -7
@@ -255,6 +255,21 @@ static int sdw_reset_page(struct sdw_bus *bus, u16 dev_num)return ret; } +static int sdw_transfer_unlocked (struct sdw_bus *bus,struct sdw_msg *msg) +{ +int ret; + + ret =do_transfer (bus, msg); +if (ret !=0 && ret != -ENODATA ) +dev_err (bus->dev,"trf on Slave %d failed:%d\n" , + msg->dev_num, ret); + +if (msg->page) +sdw_reset_page (bus, msg->dev_num); + +return ret; +} +/** * sdw_transfer() - Synchronous transfer message to a SDW Slave device * @bus: SDW bus
@@ -266,13 +281,7 @@ int sdw_transfer(struct sdw_bus *bus, struct sdw_msg *msg)mutex_lock (&bus->msg_lock); - ret =do_transfer (bus, msg); -if (ret !=0 && ret != -ENODATA ) -dev_err (bus->dev,"trf on Slave %d failed:%d\n" , - msg->dev_num, ret); - -if (msg->page) -sdw_reset_page (bus, msg->dev_num); + ret =sdw_transfer_unlocked (bus, msg);mutex_unlock (&bus->msg_lock);
@@ -428,6 +437,39 @@ sdw_bwrite_no_pm(struct sdw_bus *bus, u16 dev_num, u32 addr, u8 value)return sdw_transfer (bus, &msg); } +int sdw_bread_no_pm_unlocked (struct sdw_bus *bus,u16 dev_num,u32 addr) +{ +struct sdw_msg msg; +u8 buf; +int ret; + + ret =sdw_fill_msg (&msg,NULL , addr,1 , dev_num, +SDW_MSG_FLAG_READ , &buf); +if (ret) +return ret; + + ret =sdw_transfer_unlocked (bus, &msg); +if (ret <0 ) +return ret; + +return buf; +} +EXPORT_SYMBOL (sdw_bread_no_pm_unlocked); + +int sdw_bwrite_no_pm_unlocked (struct sdw_bus *bus,u16 dev_num,u32 addr,u8 value) +{ +struct sdw_msg msg; +int ret; + + ret =sdw_fill_msg (&msg,NULL , addr,1 , dev_num, +SDW_MSG_FLAG_WRITE , &value); +if (ret) +return ret; + +return sdw_transfer_unlocked (bus, &msg); +} +EXPORT_SYMBOL (sdw_bwrite_no_pm_unlocked); +static int sdw_read_no_pm (struct sdw_slave *slave,u32 addr) {
drivers/soundwire/bus.h +4 -0
@@ -168,6 +168,10 @@ sdw_update(struct sdw_slave *slave, u32 addr, u8 mask, u8 val)return sdw_write (slave, addr, tmp); } +/* broadcast read/write for tests */ +int sdw_bread_no_pm_unlocked (struct sdw_bus *bus,u16 dev_num,u32 addr); +int sdw_bwrite_no_pm_unlocked (struct sdw_bus *bus,u16 dev_num,u32 addr,u8 value); +/* * At the moment we only track Master-initiated hw_reset. * Additional fields can be added as needed
Signature · 1 line
2.17.1
Bard Liao
maintainerPATCH v2 7/7 soundwire: cadence: add parity error injection through debugfs
In reply to Bard LiaoFrom: Pierre-Louis Bossart <[email protected]>
The Cadence IP can inject errors, let's make use of this capability to test Slave parity error checks.
See e.g. example log where both the master and slave detect the parity error injected on a dummy read command.
cd /sys/kernel/debug/soundwire/master-1/intel-sdw/ echo 1 > cdns-parity-error-injection
[ 44.756249] intel-master sdw-master-1: Parity error [ 44.756313] intel-master sdw-master-1: Msg NACK received [ 44.756366] intel-master sdw-master-1: Msg NACKed for Slave 15 [ 44.756375] intel-master sdw-master-1: trf on Slave 15 failed:-5 [ 44.756382] intel-master sdw-master-1: parity error injection, read: -5 [ 44.756649] rt1308 sdw:1:25d:1308:0: Parity error detected
The code makes sure the Master device is resumed, hence the clock restarted, before sending a parity error.
--- drivers/soundwire/cadence_master.c | 86 ++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+)
drivers/soundwire/cadence_master.c +86 -0
@@ -13,6 +13,7 @@#include <linux/io.h> #include <linux/module.h> #include <linux/mod_devicetable.h> +#include <linux/pm_runtime.h> #include <linux/soundwire/sdw_registers.h> #include <linux/soundwire/sdw.h> #include <sound/pcm_params.h>
@@ -50,6 +51,9 @@ MODULE_PARM_DESC(cdns_mcp_int_mask, "Cadence MCP IntMask");#define CDNS_MCP_CONTROL_BLOCK_WAKEUP BIT(0)#define CDNS_MCP_CMDCTRL 0x8 + +#define CDNS_MCP_CMDCTRL_INSERT_PARITY_ERR BIT(2) +#define CDNS_MCP_SSPSTAT 0xC#define CDNS_MCP_FRAME_SHAPE 0x10#define CDNS_MCP_FRAME_SHAPE_INIT 0x14
@@ -366,6 +370,85 @@ static int cdns_hw_reset(void *data, u64 value)DEFINE_DEBUGFS_ATTRIBUTE (cdns_hw_reset_fops,NULL , cdns_hw_reset,"%llu\n" ); +static int cdns_parity_error_injection (void *data,u64 value) +{ +struct sdw_cdns *cdns = data; +struct sdw_bus *bus; +int ret; + +if (value !=1 ) +return -EINVAL ; + + bus = &cdns->bus; + +/* +* Resume Master device. If this results in a bus reset, the +* Slave devices will re-attach and be re-enumerated. +*/ + ret =pm_runtime_get_sync (bus->dev); +if (ret <0 && ret != -EACCES ) { +dev_err_ratelimited (cdns->dev, +"pm_runtime_get_sync failed in %s, ret %d\n" , + __func__, ret); +pm_runtime_put_noidle (bus->dev); +return ret; + } + +/* +* wait long enough for Slave(s) to be in steady state. This +* does not need to be super precise. +*/ +msleep (200 ); + +/* +* Take the bus lock here to make sure that any bus transactions +* will be queued while we inject a parity error on a dummy read +*/ +mutex_lock (&bus->bus_lock); + +/* program hardware to inject parity error */ +cdns_updatel (cdns,CDNS_MCP_CMDCTRL , +CDNS_MCP_CMDCTRL_INSERT_PARITY_ERR , +CDNS_MCP_CMDCTRL_INSERT_PARITY_ERR ); + +/* commit changes */ +cdns_updatel (cdns,CDNS_MCP_CONFIG_UPDATE , +CDNS_MCP_CONFIG_UPDATE_BIT , +CDNS_MCP_CONFIG_UPDATE_BIT ); + +/* do a broadcast dummy read to avoid bus clashes */ + ret =sdw_bread_no_pm_unlocked (&cdns->bus,0xf ,SDW_SCP_DEVID_0 ); +dev_info (cdns->dev,"parity error injection, read: %d\n" , ret); + +/* program hardware to disable parity error */ +cdns_updatel (cdns,CDNS_MCP_CMDCTRL , +CDNS_MCP_CMDCTRL_INSERT_PARITY_ERR , +0 ); + +/* commit changes */ +cdns_updatel (cdns,CDNS_MCP_CONFIG_UPDATE , +CDNS_MCP_CONFIG_UPDATE_BIT , +CDNS_MCP_CONFIG_UPDATE_BIT ); + +/* Continue bus operation with parity error injection disabled */ +mutex_unlock (&bus->bus_lock); + +/* Userspace changed the hardware state behind the kernel's back */ +add_taint (TAINT_USER ,LOCKDEP_STILL_OK ); + +/* +* allow Master device to enter pm_runtime suspend. This may +* also result in Slave devices suspending. +*/ +pm_runtime_mark_last_busy (bus->dev); +pm_runtime_put_autosuspend (bus->dev); + +return 0 ; +} + +DEFINE_DEBUGFS_ATTRIBUTE (cdns_parity_error_fops,NULL , + cdns_parity_error_injection,"%llu\n" ); +/** * sdw_cdns_debugfs_init() - Cadence debugfs init * @cdns: Cadence instance
@@ -377,6 +460,9 @@ void sdw_cdns_debugfs_init(struct sdw_cdns *cdns, struct dentry *root)debugfs_create_file ("cdns-hw-reset" ,0200 , root, cdns, &cdns_hw_reset_fops); + +debugfs_create_file ("cdns-parity-error-injection" ,0200 , root, cdns, + &cdns_parity_error_fops); }EXPORT_SYMBOL_GPL (sdw_cdns_debugfs_init);
Signature · 1 line
2.17.1
Quoted 2 lines · Bard Liao
Some codecs may report fake PARITY errors in the initial state. This series will filter them out.
Applied, thanks
Signature · 1 line
~Vinod