Merge tag 'soundwire-5.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/vkoul...
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 24 Aug 2021 13:39:01 +0000 (15:39 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 24 Aug 2021 13:39:01 +0000 (15:39 +0200)
Vinod writes:

soundwire updates for 5.15-rc1

- Core has updates to support SoundWire mockup device (includes tag from
  asoc), improved error handling and slave status.

- Drivers has update on Intel driver for new quriks and better handling of
  errors and suspend routines

* tag 'soundwire-5.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/vkoul/soundwire:
  soundwire: cadence: do not extend reset delay
  soundwire: intel: conditionally exit clock stop mode on system suspend
  soundwire: intel: skip suspend/resume/wake when link was not started
  soundwire: intel: fix potential race condition during power down
  soundwire: cadence: override PDI configurations to create loopback
  soundwire: cadence: add debugfs interface for PDI loopbacks
  soundwire: stream: don't program mockup device ports
  soundwire: bus: squelch error returned by mockup devices
  soundwire: add flag to ignore all command/control for mockup devices
  soundwire: stream: don't abort bank switch on Command_Ignored/-ENODATA
  soundwire: cadence: add paranoid check on self-clearing bits
  soundwire: dmi-quirks: add quirk for Intel 'Bishop County' NUC M15
  soundwire: bus: update Slave status in sdw_clear_slave_status
  soundwire: cadence: Remove ret variable from sdw_cdns_irq()
  soundwire: bus: filter out more -EDATA errors on clock stop
  soundwire: dmi-quirks: add ull suffix for SoundWire _ADR values
  ASoC: Intel: boards: sof_sdw: add SoundWire mockup codecs for tests
  ASoC: soc-acpi: tgl: add table for SoundWire mockup devices
  ASoC: soc-acpi: cnl: add table for SoundWire mockup devices
  ASoC: codecs: add SoundWire mockup device support

18 files changed:
drivers/soundwire/bus.c
drivers/soundwire/cadence_master.c
drivers/soundwire/cadence_master.h
drivers/soundwire/dmi-quirks.c
drivers/soundwire/intel.c
drivers/soundwire/intel.h
drivers/soundwire/stream.c
include/linux/soundwire/sdw.h
sound/soc/codecs/Kconfig
sound/soc/codecs/Makefile
sound/soc/codecs/sdw-mockup.c [new file with mode: 0644]
sound/soc/intel/boards/Kconfig
sound/soc/intel/boards/sof_sdw.c
sound/soc/intel/common/Makefile
sound/soc/intel/common/soc-acpi-intel-cnl-match.c
sound/soc/intel/common/soc-acpi-intel-sdw-mockup-match.c [new file with mode: 0644]
sound/soc/intel/common/soc-acpi-intel-sdw-mockup-match.h [new file with mode: 0644]
sound/soc/intel/common/soc-acpi-intel-tgl-match.c

index 3e6d4ad..1b11573 100644 (file)
@@ -390,7 +390,10 @@ sdw_nread_no_pm(struct sdw_slave *slave, u32 addr, size_t count, u8 *val)
        if (ret < 0)
                return ret;
 
-       return sdw_transfer(slave->bus, &msg);
+       ret = sdw_transfer(slave->bus, &msg);
+       if (slave->is_mockup_device)
+               ret = 0;
+       return ret;
 }
 
 static int
@@ -404,7 +407,10 @@ sdw_nwrite_no_pm(struct sdw_slave *slave, u32 addr, size_t count, const u8 *val)
        if (ret < 0)
                return ret;
 
-       return sdw_transfer(slave->bus, &msg);
+       ret = sdw_transfer(slave->bus, &msg);
+       if (slave->is_mockup_device)
+               ret = 0;
+       return ret;
 }
 
 int sdw_write_no_pm(struct sdw_slave *slave, u32 addr, u8 value)
@@ -896,7 +902,8 @@ static int sdw_bus_wait_for_clk_prep_deprep(struct sdw_bus *bus, u16 dev_num)
        do {
                val = sdw_bread_no_pm(bus, dev_num, SDW_SCP_STAT);
                if (val < 0) {
-                       dev_err(bus->dev, "SDW_SCP_STAT bread failed:%d\n", val);
+                       if (val != -ENODATA)
+                               dev_err(bus->dev, "SDW_SCP_STAT bread failed:%d\n", val);
                        return val;
                }
                val &= SDW_SCP_STAT_CLK_STP_NF;
@@ -1853,6 +1860,7 @@ void sdw_clear_slave_status(struct sdw_bus *bus, u32 request)
                if (slave->status != SDW_SLAVE_UNATTACHED) {
                        sdw_modify_slave_status(slave, SDW_SLAVE_UNATTACHED);
                        slave->first_interrupt_done = false;
+                       sdw_update_slave_status(slave, SDW_SLAVE_UNATTACHED);
                }
 
                /* keep track of request, used in pm_runtime resume */
index 2595042..4fcc3ba 100644 (file)
@@ -450,6 +450,40 @@ static int cdns_parity_error_injection(void *data, u64 value)
 DEFINE_DEBUGFS_ATTRIBUTE(cdns_parity_error_fops, NULL,
                         cdns_parity_error_injection, "%llu\n");
 
+static int cdns_set_pdi_loopback_source(void *data, u64 value)
+{
+       struct sdw_cdns *cdns = data;
+       unsigned int pdi_out_num = cdns->pcm.num_bd + cdns->pcm.num_out;
+
+       if (value > pdi_out_num)
+               return -EINVAL;
+
+       /* Userspace changed the hardware state behind the kernel's back */
+       add_taint(TAINT_USER, LOCKDEP_STILL_OK);
+
+       cdns->pdi_loopback_source = value;
+
+       return 0;
+}
+DEFINE_DEBUGFS_ATTRIBUTE(cdns_pdi_loopback_source_fops, NULL, cdns_set_pdi_loopback_source, "%llu\n");
+
+static int cdns_set_pdi_loopback_target(void *data, u64 value)
+{
+       struct sdw_cdns *cdns = data;
+       unsigned int pdi_in_num = cdns->pcm.num_bd + cdns->pcm.num_in;
+
+       if (value > pdi_in_num)
+               return -EINVAL;
+
+       /* Userspace changed the hardware state behind the kernel's back */
+       add_taint(TAINT_USER, LOCKDEP_STILL_OK);
+
+       cdns->pdi_loopback_target = value;
+
+       return 0;
+}
+DEFINE_DEBUGFS_ATTRIBUTE(cdns_pdi_loopback_target_fops, NULL, cdns_set_pdi_loopback_target, "%llu\n");
+
 /**
  * sdw_cdns_debugfs_init() - Cadence debugfs init
  * @cdns: Cadence instance
@@ -464,6 +498,16 @@ void sdw_cdns_debugfs_init(struct sdw_cdns *cdns, struct dentry *root)
 
        debugfs_create_file("cdns-parity-error-injection", 0200, root, cdns,
                            &cdns_parity_error_fops);
+
+       cdns->pdi_loopback_source = -1;
+       cdns->pdi_loopback_target = -1;
+
+       debugfs_create_file("cdns-pdi-loopback-source", 0200, root, cdns,
+                           &cdns_pdi_loopback_source_fops);
+
+       debugfs_create_file("cdns-pdi-loopback-target", 0200, root, cdns,
+                           &cdns_pdi_loopback_target_fops);
+
 }
 EXPORT_SYMBOL_GPL(sdw_cdns_debugfs_init);
 
@@ -822,7 +866,6 @@ irqreturn_t sdw_cdns_irq(int irq, void *dev_id)
 {
        struct sdw_cdns *cdns = dev_id;
        u32 int_status;
-       int ret = IRQ_HANDLED;
 
        /* Check if the link is up */
        if (!cdns->link_up)
@@ -900,7 +943,7 @@ irqreturn_t sdw_cdns_irq(int irq, void *dev_id)
        }
 
        cdns_writel(cdns, CDNS_MCP_INTSTAT, int_status);
-       return ret;
+       return IRQ_HANDLED;
 }
 EXPORT_SYMBOL(sdw_cdns_irq);
 
@@ -936,6 +979,49 @@ static void cdns_update_slave_status_work(struct work_struct *work)
 
 }
 
+/* paranoia check to make sure self-cleared bits are indeed cleared */
+void sdw_cdns_check_self_clearing_bits(struct sdw_cdns *cdns, const char *string,
+                                      bool initial_delay, int reset_iterations)
+{
+       u32 mcp_control;
+       u32 mcp_config_update;
+       int i;
+
+       if (initial_delay)
+               usleep_range(1000, 1500);
+
+       mcp_control = cdns_readl(cdns, CDNS_MCP_CONTROL);
+
+       /* the following bits should be cleared immediately */
+       if (mcp_control & CDNS_MCP_CONTROL_CMD_RST)
+               dev_err(cdns->dev, "%s failed: MCP_CONTROL_CMD_RST is not cleared\n", string);
+       if (mcp_control & CDNS_MCP_CONTROL_SOFT_RST)
+               dev_err(cdns->dev, "%s failed: MCP_CONTROL_SOFT_RST is not cleared\n", string);
+       if (mcp_control & CDNS_MCP_CONTROL_SW_RST)
+               dev_err(cdns->dev, "%s failed: MCP_CONTROL_SW_RST is not cleared\n", string);
+       if (mcp_control & CDNS_MCP_CONTROL_CLK_STOP_CLR)
+               dev_err(cdns->dev, "%s failed: MCP_CONTROL_CLK_STOP_CLR is not cleared\n", string);
+       mcp_config_update = cdns_readl(cdns, CDNS_MCP_CONFIG_UPDATE);
+       if (mcp_config_update & CDNS_MCP_CONFIG_UPDATE_BIT)
+               dev_err(cdns->dev, "%s failed: MCP_CONFIG_UPDATE_BIT is not cleared\n", string);
+
+       i = 0;
+       while (mcp_control & CDNS_MCP_CONTROL_HW_RST) {
+               if (i == reset_iterations) {
+                       dev_err(cdns->dev, "%s failed: MCP_CONTROL_HW_RST is not cleared\n", string);
+                       break;
+               }
+
+               dev_dbg(cdns->dev, "%s: MCP_CONTROL_HW_RST is not cleared at iteration %d\n", string, i);
+               i++;
+
+               usleep_range(1000, 1500);
+               mcp_control = cdns_readl(cdns, CDNS_MCP_CONTROL);
+       }
+
+}
+EXPORT_SYMBOL(sdw_cdns_check_self_clearing_bits);
+
 /*
  * init routines
  */
@@ -946,10 +1032,7 @@ static void cdns_update_slave_status_work(struct work_struct *work)
  */
 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);
+       /* keep reset delay unchanged to 4096 cycles */
 
        /* use hardware generated reset */
        cdns_updatel(cdns, CDNS_MCP_CONTROL,
@@ -1213,6 +1296,8 @@ int sdw_cdns_init(struct sdw_cdns *cdns)
 
        cdns_init_clock_ctrl(cdns);
 
+       sdw_cdns_check_self_clearing_bits(cdns, __func__, false, 0);
+
        /* reset msg_count to default value of FIFOLEVEL */
        cdns->msg_count = cdns_readl(cdns, CDNS_MCP_FIFOLEVEL);
 
@@ -1286,20 +1371,37 @@ static int cdns_port_params(struct sdw_bus *bus,
                            struct sdw_port_params *p_params, unsigned int bank)
 {
        struct sdw_cdns *cdns = bus_to_cdns(bus);
-       int dpn_config = 0, dpn_config_off;
+       int dpn_config_off_source;
+       int dpn_config_off_target;
+       int target_num = p_params->num;
+       int source_num = p_params->num;
+       bool override = false;
+       int dpn_config;
+
+       if (target_num == cdns->pdi_loopback_target &&
+           cdns->pdi_loopback_source != -1) {
+               source_num = cdns->pdi_loopback_source;
+               override = true;
+       }
 
-       if (bank)
-               dpn_config_off = CDNS_DPN_B1_CONFIG(p_params->num);
-       else
-               dpn_config_off = CDNS_DPN_B0_CONFIG(p_params->num);
+       if (bank) {
+               dpn_config_off_source = CDNS_DPN_B1_CONFIG(source_num);
+               dpn_config_off_target = CDNS_DPN_B1_CONFIG(target_num);
+       } else {
+               dpn_config_off_source = CDNS_DPN_B0_CONFIG(source_num);
+               dpn_config_off_target = CDNS_DPN_B0_CONFIG(target_num);
+       }
 
-       dpn_config = cdns_readl(cdns, dpn_config_off);
+       dpn_config = cdns_readl(cdns, dpn_config_off_source);
 
-       u32p_replace_bits(&dpn_config, (p_params->bps - 1), CDNS_DPN_CONFIG_WL);
-       u32p_replace_bits(&dpn_config, p_params->flow_mode, CDNS_DPN_CONFIG_PORT_FLOW);
-       u32p_replace_bits(&dpn_config, p_params->data_mode, CDNS_DPN_CONFIG_PORT_DAT);
+       /* use port params if there is no loopback, otherwise use source as is */
+       if (!override) {
+               u32p_replace_bits(&dpn_config, p_params->bps - 1, CDNS_DPN_CONFIG_WL);
+               u32p_replace_bits(&dpn_config, p_params->flow_mode, CDNS_DPN_CONFIG_PORT_FLOW);
+               u32p_replace_bits(&dpn_config, p_params->data_mode, CDNS_DPN_CONFIG_PORT_DAT);
+       }
 
-       cdns_writel(cdns, dpn_config_off, dpn_config);
+       cdns_writel(cdns, dpn_config_off_target, dpn_config);
 
        return 0;
 }
@@ -1309,11 +1411,27 @@ static int cdns_transport_params(struct sdw_bus *bus,
                                 enum sdw_reg_bank bank)
 {
        struct sdw_cdns *cdns = bus_to_cdns(bus);
-       int dpn_offsetctrl = 0, dpn_offsetctrl_off;
-       int dpn_config = 0, dpn_config_off;
-       int dpn_hctrl = 0, dpn_hctrl_off;
-       int num = t_params->port_num;
-       int dpn_samplectrl_off;
+       int dpn_config;
+       int dpn_config_off_source;
+       int dpn_config_off_target;
+       int dpn_hctrl;
+       int dpn_hctrl_off_source;
+       int dpn_hctrl_off_target;
+       int dpn_offsetctrl;
+       int dpn_offsetctrl_off_source;
+       int dpn_offsetctrl_off_target;
+       int dpn_samplectrl;
+       int dpn_samplectrl_off_source;
+       int dpn_samplectrl_off_target;
+       int source_num = t_params->port_num;
+       int target_num = t_params->port_num;
+       bool override = false;
+
+       if (target_num == cdns->pdi_loopback_target &&
+           cdns->pdi_loopback_source != -1) {
+               source_num = cdns->pdi_loopback_source;
+               override = true;
+       }
 
        /*
         * Note: Only full data port is supported on the Master side for
@@ -1321,32 +1439,59 @@ static int cdns_transport_params(struct sdw_bus *bus,
         */
 
        if (bank) {
-               dpn_config_off = CDNS_DPN_B1_CONFIG(num);
-               dpn_samplectrl_off = CDNS_DPN_B1_SAMPLE_CTRL(num);
-               dpn_hctrl_off = CDNS_DPN_B1_HCTRL(num);
-               dpn_offsetctrl_off = CDNS_DPN_B1_OFFSET_CTRL(num);
+               dpn_config_off_source = CDNS_DPN_B1_CONFIG(source_num);
+               dpn_hctrl_off_source = CDNS_DPN_B1_HCTRL(source_num);
+               dpn_offsetctrl_off_source = CDNS_DPN_B1_OFFSET_CTRL(source_num);
+               dpn_samplectrl_off_source = CDNS_DPN_B1_SAMPLE_CTRL(source_num);
+
+               dpn_config_off_target = CDNS_DPN_B1_CONFIG(target_num);
+               dpn_hctrl_off_target = CDNS_DPN_B1_HCTRL(target_num);
+               dpn_offsetctrl_off_target = CDNS_DPN_B1_OFFSET_CTRL(target_num);
+               dpn_samplectrl_off_target = CDNS_DPN_B1_SAMPLE_CTRL(target_num);
+
        } else {
-               dpn_config_off = CDNS_DPN_B0_CONFIG(num);
-               dpn_samplectrl_off = CDNS_DPN_B0_SAMPLE_CTRL(num);
-               dpn_hctrl_off = CDNS_DPN_B0_HCTRL(num);
-               dpn_offsetctrl_off = CDNS_DPN_B0_OFFSET_CTRL(num);
+               dpn_config_off_source = CDNS_DPN_B0_CONFIG(source_num);
+               dpn_hctrl_off_source = CDNS_DPN_B0_HCTRL(source_num);
+               dpn_offsetctrl_off_source = CDNS_DPN_B0_OFFSET_CTRL(source_num);
+               dpn_samplectrl_off_source = CDNS_DPN_B0_SAMPLE_CTRL(source_num);
+
+               dpn_config_off_target = CDNS_DPN_B0_CONFIG(target_num);
+               dpn_hctrl_off_target = CDNS_DPN_B0_HCTRL(target_num);
+               dpn_offsetctrl_off_target = CDNS_DPN_B0_OFFSET_CTRL(target_num);
+               dpn_samplectrl_off_target = CDNS_DPN_B0_SAMPLE_CTRL(target_num);
        }
 
-       dpn_config = cdns_readl(cdns, dpn_config_off);
-       u32p_replace_bits(&dpn_config, t_params->blk_grp_ctrl, CDNS_DPN_CONFIG_BGC);
-       u32p_replace_bits(&dpn_config, t_params->blk_pkg_mode, CDNS_DPN_CONFIG_BPM);
-       cdns_writel(cdns, dpn_config_off, dpn_config);
+       dpn_config = cdns_readl(cdns, dpn_config_off_source);
+       if (!override) {
+               u32p_replace_bits(&dpn_config, t_params->blk_grp_ctrl, CDNS_DPN_CONFIG_BGC);
+               u32p_replace_bits(&dpn_config, t_params->blk_pkg_mode, CDNS_DPN_CONFIG_BPM);
+       }
+       cdns_writel(cdns, dpn_config_off_target, dpn_config);
 
-       u32p_replace_bits(&dpn_offsetctrl, t_params->offset1, CDNS_DPN_OFFSET_CTRL_1);
-       u32p_replace_bits(&dpn_offsetctrl, t_params->offset2, CDNS_DPN_OFFSET_CTRL_2);
-       cdns_writel(cdns, dpn_offsetctrl_off,  dpn_offsetctrl);
+       if (!override) {
+               dpn_offsetctrl = 0;
+               u32p_replace_bits(&dpn_offsetctrl, t_params->offset1, CDNS_DPN_OFFSET_CTRL_1);
+               u32p_replace_bits(&dpn_offsetctrl, t_params->offset2, CDNS_DPN_OFFSET_CTRL_2);
+       } else {
+               dpn_offsetctrl = cdns_readl(cdns, dpn_offsetctrl_off_source);
+       }
+       cdns_writel(cdns, dpn_offsetctrl_off_target,  dpn_offsetctrl);
 
-       u32p_replace_bits(&dpn_hctrl, t_params->hstart, CDNS_DPN_HCTRL_HSTART);
-       u32p_replace_bits(&dpn_hctrl, t_params->hstop, CDNS_DPN_HCTRL_HSTOP);
-       u32p_replace_bits(&dpn_hctrl, t_params->lane_ctrl, CDNS_DPN_HCTRL_LCTRL);
+       if (!override) {
+               dpn_hctrl = 0;
+               u32p_replace_bits(&dpn_hctrl, t_params->hstart, CDNS_DPN_HCTRL_HSTART);
+               u32p_replace_bits(&dpn_hctrl, t_params->hstop, CDNS_DPN_HCTRL_HSTOP);
+               u32p_replace_bits(&dpn_hctrl, t_params->lane_ctrl, CDNS_DPN_HCTRL_LCTRL);
+       } else {
+               dpn_hctrl = cdns_readl(cdns, dpn_hctrl_off_source);
+       }
+       cdns_writel(cdns, dpn_hctrl_off_target, dpn_hctrl);
 
-       cdns_writel(cdns, dpn_hctrl_off, dpn_hctrl);
-       cdns_writel(cdns, dpn_samplectrl_off, (t_params->sample_interval - 1));
+       if (!override)
+               dpn_samplectrl = t_params->sample_interval - 1;
+       else
+               dpn_samplectrl = cdns_readl(cdns, dpn_samplectrl_off_source);
+       cdns_writel(cdns, dpn_samplectrl_off_target, dpn_samplectrl);
 
        return 0;
 }
@@ -1397,6 +1542,8 @@ int sdw_cdns_clock_stop(struct sdw_cdns *cdns, bool block_wake)
        struct sdw_slave *slave;
        int ret;
 
+       sdw_cdns_check_self_clearing_bits(cdns, __func__, false, 0);
+
        /* Check suspend status */
        if (sdw_cdns_is_clock_stop(cdns)) {
                dev_dbg(cdns->dev, "Clock is already stopped\n");
index 0e7f8b3..e587aed 100644 (file)
@@ -129,6 +129,9 @@ struct sdw_cdns {
        struct sdw_cdns_streams pcm;
        struct sdw_cdns_streams pdm;
 
+       int pdi_loopback_source;
+       int pdi_loopback_target;
+
        void __iomem *registers;
 
        bool link_up;
@@ -184,4 +187,8 @@ int cdns_bus_conf(struct sdw_bus *bus, struct sdw_bus_params *params);
 
 int cdns_set_sdw_stream(struct snd_soc_dai *dai,
                        void *stream, bool pcm, int direction);
+
+void sdw_cdns_check_self_clearing_bits(struct sdw_cdns *cdns, const char *string,
+                                      bool initial_delay, int reset_iterations);
+
 #endif /* __SDW_CADENCE_H */
index 5db0a24..0ca2a3e 100644 (file)
@@ -16,18 +16,18 @@ struct adr_remap {
 };
 
 /*
- * HP Spectre 360 Convertible devices do not expose the correct _ADR
- * in the DSDT.
+ * Some TigerLake devices based on an initial Intel BIOS do not expose
+ * the correct _ADR in the DSDT.
  * Remap the bad _ADR values to the ones reported by hardware
  */
-static const struct adr_remap hp_spectre_360[] = {
+static const struct adr_remap intel_tgl_bios[] = {
        {
-               0x000010025D070100,
-               0x000020025D071100
+               0x000010025D070100ull,
+               0x000020025D071100ull
        },
        {
-               0x000110025d070100,
-               0x000120025D130800
+               0x000110025d070100ull,
+               0x000120025D130800ull
        },
        {}
 };
@@ -39,18 +39,18 @@ static const struct adr_remap hp_spectre_360[] = {
 static const struct adr_remap dell_sku_0A3E[] = {
        /* rt715 on link0 */
        {
-               0x00020025d071100,
-               0x00021025d071500
+               0x00020025d071100ull,
+               0x00021025d071500ull
        },
        /* rt711 on link1 */
        {
-               0x000120025d130800,
-               0x000120025d071100,
+               0x000120025d130800ull,
+               0x000120025d071100ull,
        },
        /* rt1308 on link2 */
        {
-               0x000220025d071500,
-               0x000220025d130800
+               0x000220025d071500ull,
+               0x000220025d130800ull
        },
        {}
 };
@@ -61,7 +61,15 @@ static const struct dmi_system_id adr_remap_quirk_table[] = {
                        DMI_MATCH(DMI_SYS_VENDOR, "HP"),
                        DMI_MATCH(DMI_PRODUCT_NAME, "HP Spectre x360 Convertible"),
                },
-               .driver_data = (void *)hp_spectre_360,
+               .driver_data = (void *)intel_tgl_bios,
+       },
+       {
+               /* quirk used for NUC15 'Bishop County' LAPBC510 and LAPBC710 skews */
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "Intel(R) Client Systems"),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "LAPBC"),
+               },
+               .driver_data = (void *)intel_tgl_bios,
        },
        {
                .matches = {
index c11e3d8..f66fcbc 100644 (file)
@@ -23,6 +23,7 @@
 #include "intel.h"
 
 #define INTEL_MASTER_SUSPEND_DELAY_MS  3000
+#define INTEL_MASTER_RESET_ITERATIONS  10
 
 /*
  * debug/config flags for the Intel SoundWire Master.
@@ -537,12 +538,14 @@ static int intel_link_power_down(struct sdw_intel *sdw)
 
        mutex_lock(sdw->link_res->shim_lock);
 
-       intel_shim_master_ip_to_glue(sdw);
-
        if (!(*shim_mask & BIT(link_id)))
                dev_err(sdw->cdns.dev,
                        "%s: Unbalanced power-up/down calls\n", __func__);
 
+       sdw->cdns.link_up = false;
+
+       intel_shim_master_ip_to_glue(sdw);
+
        *shim_mask &= ~BIT(link_id);
 
        if (!*shim_mask) {
@@ -559,18 +562,19 @@ static int intel_link_power_down(struct sdw_intel *sdw)
                link_control &=  spa_mask;
 
                ret = intel_clear_bit(shim, SDW_SHIM_LCTL, link_control, cpa_mask);
+               if (ret < 0) {
+                       dev_err(sdw->cdns.dev, "%s: could not power down link\n", __func__);
+
+                       /*
+                        * we leave the sdw->cdns.link_up flag as false since we've disabled
+                        * the link at this point and cannot handle interrupts any longer.
+                        */
+               }
        }
 
        mutex_unlock(sdw->link_res->shim_lock);
 
-       if (ret < 0) {
-               dev_err(sdw->cdns.dev, "%s: could not power down link\n", __func__);
-
-               return ret;
-       }
-
-       sdw->cdns.link_up = false;
-       return 0;
+       return ret;
 }
 
 static void intel_shim_sync_arm(struct sdw_intel *sdw)
@@ -1467,6 +1471,8 @@ int intel_link_startup(struct auxiliary_device *auxdev)
                        goto err_interrupt;
                }
        }
+       sdw_cdns_check_self_clearing_bits(cdns, __func__,
+                                         true, INTEL_MASTER_RESET_ITERATIONS);
 
        /* Register DAIs */
        ret = intel_register_dai(sdw);
@@ -1519,6 +1525,7 @@ int intel_link_startup(struct auxiliary_device *auxdev)
        if (!(link_flags & SDW_INTEL_MASTER_DISABLE_PM_RUNTIME_IDLE))
                pm_runtime_idle(dev);
 
+       sdw->startup_done = true;
        return 0;
 
 err_interrupt:
@@ -1558,8 +1565,9 @@ int intel_link_process_wakeen_event(struct auxiliary_device *auxdev)
        sdw = dev_get_drvdata(dev);
        bus = &sdw->cdns.bus;
 
-       if (bus->prop.hw_disabled) {
-               dev_dbg(dev, "SoundWire master %d is disabled, ignoring\n", bus->link_id);
+       if (bus->prop.hw_disabled || !sdw->startup_done) {
+               dev_dbg(dev, "SoundWire master %d is disabled or not-started, ignoring\n",
+                       bus->link_id);
                return 0;
        }
 
@@ -1588,6 +1596,87 @@ int intel_link_process_wakeen_event(struct auxiliary_device *auxdev)
  * PM calls
  */
 
+static int intel_resume_child_device(struct device *dev, void *data)
+{
+       int ret;
+       struct sdw_slave *slave = dev_to_sdw_dev(dev);
+
+       if (!slave->probed) {
+               dev_dbg(dev, "%s: skipping device, no probed driver\n", __func__);
+               return 0;
+       }
+       if (!slave->dev_num_sticky) {
+               dev_dbg(dev, "%s: skipping device, never detected on bus\n", __func__);
+               return 0;
+       }
+
+       ret = pm_request_resume(dev);
+       if (ret < 0)
+               dev_err(dev, "%s: pm_request_resume failed: %d\n", __func__, ret);
+
+       return ret;
+}
+
+static int __maybe_unused intel_pm_prepare(struct device *dev)
+{
+       struct sdw_cdns *cdns = dev_get_drvdata(dev);
+       struct sdw_intel *sdw = cdns_to_intel(cdns);
+       struct sdw_bus *bus = &cdns->bus;
+       u32 clock_stop_quirks;
+       int ret = 0;
+
+       if (bus->prop.hw_disabled || !sdw->startup_done) {
+               dev_dbg(dev, "SoundWire master %d is disabled or not-started, ignoring\n",
+                       bus->link_id);
+               return 0;
+       }
+
+       clock_stop_quirks = sdw->link_res->clock_stop_quirks;
+
+       if (pm_runtime_suspended(dev) &&
+           pm_runtime_suspended(dev->parent) &&
+           ((clock_stop_quirks & SDW_INTEL_CLK_STOP_BUS_RESET) ||
+            !clock_stop_quirks)) {
+               /*
+                * if we've enabled clock stop, and the parent is suspended, the SHIM registers
+                * are not accessible and the shim wake cannot be disabled.
+                * The only solution is to resume the entire bus to full power
+                */
+
+               /*
+                * If any operation in this block fails, we keep going since we don't want
+                * to prevent system suspend from happening and errors should be recoverable
+                * on resume.
+                */
+
+               /*
+                * first resume the device for this link. This will also by construction
+                * resume the PCI parent device.
+                */
+               ret = pm_request_resume(dev);
+               if (ret < 0) {
+                       dev_err(dev, "%s: pm_request_resume failed: %d\n", __func__, ret);
+                       return 0;
+               }
+
+               /*
+                * Continue resuming the entire bus (parent + child devices) to exit
+                * the clock stop mode. If there are no devices connected on this link
+                * this is a no-op.
+                * The resume to full power could have been implemented with a .prepare
+                * step in SoundWire codec drivers. This would however require a lot
+                * of code to handle an Intel-specific corner case. It is simpler in
+                * practice to add a loop at the link level.
+                */
+               ret = device_for_each_child(bus->dev, NULL, intel_resume_child_device);
+
+               if (ret < 0)
+                       dev_err(dev, "%s: intel_resume_child_device failed: %d\n", __func__, ret);
+       }
+
+       return 0;
+}
+
 static int __maybe_unused intel_suspend(struct device *dev)
 {
        struct sdw_cdns *cdns = dev_get_drvdata(dev);
@@ -1596,8 +1685,8 @@ static int __maybe_unused intel_suspend(struct device *dev)
        u32 clock_stop_quirks;
        int ret;
 
-       if (bus->prop.hw_disabled) {
-               dev_dbg(dev, "SoundWire master %d is disabled, ignoring\n",
+       if (bus->prop.hw_disabled || !sdw->startup_done) {
+               dev_dbg(dev, "SoundWire master %d is disabled or not-started, ignoring\n",
                        bus->link_id);
                return 0;
        }
@@ -1607,19 +1696,18 @@ static int __maybe_unused intel_suspend(struct device *dev)
 
                clock_stop_quirks = sdw->link_res->clock_stop_quirks;
 
-               if ((clock_stop_quirks & SDW_INTEL_CLK_STOP_BUS_RESET ||
-                    !clock_stop_quirks) &&
-                   !pm_runtime_suspended(dev->parent)) {
-
-                       /*
-                        * if we've enabled clock stop, and the parent
-                        * is still active, disable shim wake. The
-                        * SHIM registers are not accessible if the
-                        * parent is already pm_runtime suspended so
-                        * it's too late to change that configuration
-                        */
-
-                       intel_shim_wake(sdw, false);
+               if ((clock_stop_quirks & SDW_INTEL_CLK_STOP_BUS_RESET) ||
+                   !clock_stop_quirks) {
+
+                       if (pm_runtime_suspended(dev->parent)) {
+                               /*
+                                * paranoia check: this should not happen with the .prepare
+                                * resume to full power
+                                */
+                               dev_err(dev, "%s: invalid config: parent is suspended\n", __func__);
+                       } else {
+                               intel_shim_wake(sdw, false);
+                       }
                }
 
                return 0;
@@ -1650,8 +1738,8 @@ static int __maybe_unused intel_suspend_runtime(struct device *dev)
        u32 clock_stop_quirks;
        int ret;
 
-       if (bus->prop.hw_disabled) {
-               dev_dbg(dev, "SoundWire master %d is disabled, ignoring\n",
+       if (bus->prop.hw_disabled || !sdw->startup_done) {
+               dev_dbg(dev, "SoundWire master %d is disabled or not-started, ignoring\n",
                        bus->link_id);
                return 0;
        }
@@ -1715,8 +1803,8 @@ static int __maybe_unused intel_resume(struct device *dev)
        bool multi_link;
        int ret;
 
-       if (bus->prop.hw_disabled) {
-               dev_dbg(dev, "SoundWire master %d is disabled, ignoring\n",
+       if (bus->prop.hw_disabled || !sdw->startup_done) {
+               dev_dbg(dev, "SoundWire master %d is disabled or not-started, ignoring\n",
                        bus->link_id);
                return 0;
        }
@@ -1783,6 +1871,8 @@ static int __maybe_unused intel_resume(struct device *dev)
                        return ret;
                }
        }
+       sdw_cdns_check_self_clearing_bits(cdns, __func__,
+                                         true, INTEL_MASTER_RESET_ITERATIONS);
 
        /*
         * after system resume, the pm_runtime suspend() may kick in
@@ -1811,8 +1901,8 @@ static int __maybe_unused intel_resume_runtime(struct device *dev)
        int status;
        int ret;
 
-       if (bus->prop.hw_disabled) {
-               dev_dbg(dev, "SoundWire master %d is disabled, ignoring\n",
+       if (bus->prop.hw_disabled || !sdw->startup_done) {
+               dev_dbg(dev, "SoundWire master %d is disabled or not-started, ignoring\n",
                        bus->link_id);
                return 0;
        }
@@ -1867,6 +1957,9 @@ static int __maybe_unused intel_resume_runtime(struct device *dev)
                                return ret;
                        }
                }
+               sdw_cdns_check_self_clearing_bits(cdns, "intel_resume_runtime TEARDOWN",
+                                                 true, INTEL_MASTER_RESET_ITERATIONS);
+
        } else if (clock_stop_quirks & SDW_INTEL_CLK_STOP_BUS_RESET) {
                ret = intel_init(sdw);
                if (ret) {
@@ -1940,6 +2033,9 @@ static int __maybe_unused intel_resume_runtime(struct device *dev)
                                }
                        }
                }
+               sdw_cdns_check_self_clearing_bits(cdns, "intel_resume_runtime BUS_RESET",
+                                                 true, INTEL_MASTER_RESET_ITERATIONS);
+
        } else if (!clock_stop_quirks) {
 
                clock_stop0 = sdw_cdns_is_clock_stop(&sdw->cdns);
@@ -1963,6 +2059,9 @@ static int __maybe_unused intel_resume_runtime(struct device *dev)
                        dev_err(dev, "unable to resume master during resume\n");
                        return ret;
                }
+
+               sdw_cdns_check_self_clearing_bits(cdns, "intel_resume_runtime no_quirks",
+                                                 true, INTEL_MASTER_RESET_ITERATIONS);
        } else {
                dev_err(dev, "%s clock_stop_quirks %x unsupported\n",
                        __func__, clock_stop_quirks);
@@ -1973,6 +2072,7 @@ static int __maybe_unused intel_resume_runtime(struct device *dev)
 }
 
 static const struct dev_pm_ops intel_pm = {
+       .prepare = intel_pm_prepare,
        SET_SYSTEM_SLEEP_PM_OPS(intel_suspend, intel_resume)
        SET_RUNTIME_PM_OPS(intel_suspend_runtime, intel_resume_runtime, NULL)
 };
index 0b47b14..cd93a44 100644 (file)
@@ -41,6 +41,7 @@ struct sdw_intel {
        struct sdw_cdns cdns;
        int instance;
        struct sdw_intel_link_res *link_res;
+       bool startup_done;
 #ifdef CONFIG_DEBUG_FS
        struct dentry *debugfs;
 #endif
index 1a18308..5d4f6b3 100644 (file)
@@ -133,6 +133,9 @@ static int sdw_program_slave_port_params(struct sdw_bus *bus,
        int ret;
        u8 wbuf;
 
+       if (s_rt->slave->is_mockup_device)
+               return 0;
+
        dpn_prop = sdw_get_slave_dpn_prop(s_rt->slave,
                                          s_rt->direction,
                                          t_params->port_num);
@@ -697,7 +700,7 @@ static int sdw_bank_switch(struct sdw_bus *bus, int m_rt_count)
        else
                ret = sdw_transfer(bus, wr_msg);
 
-       if (ret < 0) {
+       if (ret < 0 && ret != -ENODATA) {
                dev_err(bus->dev, "Slave frame_ctrl reg write failed\n");
                goto error;
        }
index a48ac3e..76ce3f3 100644 (file)
@@ -661,6 +661,8 @@ struct sdw_slave_ops {
  * initialized
  * @first_interrupt_done: status flag tracking if the interrupt handling
  * for a Slave happens for the first time after enumeration
+ * @is_mockup_device: status flag used to squelch errors in the command/control
+ * protocol for SoundWire mockup devices
  */
 struct sdw_slave {
        struct sdw_slave_id id;
@@ -683,6 +685,7 @@ struct sdw_slave {
        struct completion initialization_complete;
        u32 unattach_request;
        bool first_interrupt_done;
+       bool is_mockup_device;
 };
 
 #define dev_to_sdw_dev(_dev) container_of(_dev, struct sdw_slave, dev)
index db16071..9ff1600 100644 (file)
@@ -187,6 +187,7 @@ config SND_SOC_ALL_CODECS
        imply SND_SOC_RT715_SDCA_SDW
        imply SND_SOC_RT1308_SDW
        imply SND_SOC_RT1316_SDW
+       imply SND_SOC_SDW_MOCKUP
        imply SND_SOC_SGTL5000
        imply SND_SOC_SI476X
        imply SND_SOC_SIMPLE_AMPLIFIER
@@ -1287,6 +1288,23 @@ config SND_SOC_RT715_SDCA_SDW
        select REGMAP_SOUNDWIRE
        select REGMAP_SOUNDWIRE_MBQ
 
+config SND_SOC_SDW_MOCKUP
+       tristate "SoundWire mockup codec"
+       depends on EXPERT
+       depends on SOUNDWIRE
+       help
+         This option enables a SoundWire mockup codec that does not drive the
+         bus, take part in the command/command protocol or generate data on a
+         Source port.
+         This option is only intended to be used for tests on a device
+         with a connector, in combination with a bus analyzer, or to test new
+         topologies that differ from the actual hardware layout.
+         This mockup device could be totally virtual but could also be a
+         real physical one with one key restriction: it is not allowed by the
+         SoundWire specification to be configured via a sideband mechanism and
+         generate audio data for capture. However, nothing prevents such a
+         peripheral device from snooping the bus.
+
 #Freescale sgtl5000 codec
 config SND_SOC_SGTL5000
        tristate "Freescale SGTL5000 CODEC"
index 7bb38c3..8dcea2c 100644 (file)
@@ -203,6 +203,7 @@ snd-soc-rt711-objs := rt711.o rt711-sdw.o
 snd-soc-rt711-sdca-objs := rt711-sdca.o rt711-sdca-sdw.o
 snd-soc-rt715-objs := rt715.o rt715-sdw.o
 snd-soc-rt715-sdca-objs := rt715-sdca.o rt715-sdca-sdw.o
+snd-soc-sdw-mockup-objs := sdw-mockup.o
 snd-soc-sgtl5000-objs := sgtl5000.o
 snd-soc-alc5623-objs := alc5623.o
 snd-soc-alc5632-objs := alc5632.o
@@ -530,6 +531,7 @@ obj-$(CONFIG_SND_SOC_RT711)     += snd-soc-rt711.o
 obj-$(CONFIG_SND_SOC_RT711_SDCA_SDW)     += snd-soc-rt711-sdca.o
 obj-$(CONFIG_SND_SOC_RT715)     += snd-soc-rt715.o
 obj-$(CONFIG_SND_SOC_RT715_SDCA_SDW)     += snd-soc-rt715-sdca.o
+obj-$(CONFIG_SND_SOC_SDW_MOCKUP)     += snd-soc-sdw-mockup.o
 obj-$(CONFIG_SND_SOC_SGTL5000)  += snd-soc-sgtl5000.o
 obj-$(CONFIG_SND_SOC_SIGMADSP) += snd-soc-sigmadsp.o
 obj-$(CONFIG_SND_SOC_SIGMADSP_I2C)     += snd-soc-sigmadsp-i2c.o
diff --git a/sound/soc/codecs/sdw-mockup.c b/sound/soc/codecs/sdw-mockup.c
new file mode 100644 (file)
index 0000000..8ea13cf
--- /dev/null
@@ -0,0 +1,312 @@
+// SPDX-License-Identifier: GPL-2.0-only
+//
+// sdw-mockup.c -- a mockup SoundWire codec for tests where only the host
+// drives the bus.
+//
+// Copyright(c) 2021 Intel Corporation
+//
+//
+
+#include <linux/device.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.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>
+#include <sound/soc.h>
+
+struct  sdw_mockup_priv {
+       struct sdw_slave *slave;
+};
+
+struct sdw_stream_data {
+       struct sdw_stream_runtime *sdw_stream;
+};
+
+static int sdw_mockup_component_probe(struct snd_soc_component *component)
+{
+       return 0;
+}
+
+static void sdw_mockup_component_remove(struct snd_soc_component *component)
+{
+}
+
+static const struct snd_soc_component_driver snd_soc_sdw_mockup_component = {
+       .probe = sdw_mockup_component_probe,
+       .remove = sdw_mockup_component_remove,
+};
+
+static int sdw_mockup_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream,
+                                    int direction)
+{
+       struct sdw_stream_data *stream;
+
+       if (!sdw_stream)
+               return 0;
+
+       stream = kzalloc(sizeof(*stream), GFP_KERNEL);
+       if (!stream)
+               return -ENOMEM;
+
+       stream->sdw_stream = sdw_stream;
+
+       /* Use tx_mask or rx_mask to configure stream tag and set dma_data */
+       if (direction == SNDRV_PCM_STREAM_PLAYBACK)
+               dai->playback_dma_data = stream;
+       else
+               dai->capture_dma_data = stream;
+
+       return 0;
+}
+
+static void sdw_mockup_shutdown(struct snd_pcm_substream *substream,
+                               struct snd_soc_dai *dai)
+{
+       struct sdw_stream_data *stream;
+
+       stream = snd_soc_dai_get_dma_data(dai, substream);
+       snd_soc_dai_set_dma_data(dai, substream, NULL);
+       kfree(stream);
+}
+
+static int sdw_mockup_pcm_hw_params(struct snd_pcm_substream *substream,
+                                   struct snd_pcm_hw_params *params,
+                                   struct snd_soc_dai *dai)
+{
+       struct snd_soc_component *component = dai->component;
+       struct sdw_mockup_priv *sdw_mockup = snd_soc_component_get_drvdata(component);
+       struct sdw_stream_config stream_config;
+       struct sdw_port_config port_config;
+       enum sdw_data_direction direction;
+       struct sdw_stream_data *stream;
+       int num_channels;
+       int port;
+       int ret;
+
+       stream = snd_soc_dai_get_dma_data(dai, substream);
+       if (!stream)
+               return -EINVAL;
+
+       if (!sdw_mockup->slave)
+               return -EINVAL;
+
+       /* SoundWire specific configuration */
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+               direction = SDW_DATA_DIR_RX;
+               port = 1;
+       } else {
+               direction = SDW_DATA_DIR_TX;
+               port = 8;
+       }
+
+       stream_config.frame_rate = params_rate(params);
+       stream_config.ch_count = params_channels(params);
+       stream_config.bps = snd_pcm_format_width(params_format(params));
+       stream_config.direction = direction;
+
+       num_channels = params_channels(params);
+       port_config.ch_mask = (1 << num_channels) - 1;
+       port_config.num = port;
+
+       ret = sdw_stream_add_slave(sdw_mockup->slave, &stream_config,
+                                  &port_config, 1, stream->sdw_stream);
+       if (ret)
+               dev_err(dai->dev, "Unable to configure port\n");
+
+       return ret;
+}
+
+static int sdw_mockup_pcm_hw_free(struct snd_pcm_substream *substream,
+                                 struct snd_soc_dai *dai)
+{
+       struct snd_soc_component *component = dai->component;
+       struct sdw_mockup_priv *sdw_mockup = snd_soc_component_get_drvdata(component);
+       struct sdw_stream_data *stream =
+               snd_soc_dai_get_dma_data(dai, substream);
+
+       if (!sdw_mockup->slave)
+               return -EINVAL;
+
+       sdw_stream_remove_slave(sdw_mockup->slave, stream->sdw_stream);
+       return 0;
+}
+
+static const struct snd_soc_dai_ops sdw_mockup_ops = {
+       .hw_params      = sdw_mockup_pcm_hw_params,
+       .hw_free        = sdw_mockup_pcm_hw_free,
+       .set_sdw_stream = sdw_mockup_set_sdw_stream,
+       .shutdown       = sdw_mockup_shutdown,
+};
+
+static struct snd_soc_dai_driver sdw_mockup_dai[] = {
+       {
+               .name = "sdw-mockup-aif1",
+               .id = 1,
+               .playback = {
+                       .stream_name = "DP1 Playback",
+                       .channels_min = 1,
+                       .channels_max = 2,
+               },
+               .capture = {
+                       .stream_name = "DP8 Capture",
+                       .channels_min = 1,
+                       .channels_max = 2,
+               },
+               .ops = &sdw_mockup_ops,
+       },
+};
+
+static int sdw_mockup_update_status(struct sdw_slave *slave,
+                                   enum sdw_slave_status status)
+{
+       return 0;
+}
+
+static int sdw_mockup_read_prop(struct sdw_slave *slave)
+{
+       struct sdw_slave_prop *prop = &slave->prop;
+       int nval;
+       int i, j;
+       u32 bit;
+       unsigned long addr;
+       struct sdw_dpn_prop *dpn;
+
+       prop->paging_support = false;
+
+       /*
+        * first we need to allocate memory for set bits in port lists
+        * the port allocation is completely arbitrary:
+        * DP0 is not supported
+        * DP1 is sink
+        * DP8 is source
+        */
+       prop->source_ports = BIT(8);
+       prop->sink_ports = BIT(1);
+
+       nval = hweight32(prop->source_ports);
+       prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval,
+                                         sizeof(*prop->src_dpn_prop),
+                                         GFP_KERNEL);
+       if (!prop->src_dpn_prop)
+               return -ENOMEM;
+
+       i = 0;
+       dpn = prop->src_dpn_prop;
+       addr = prop->source_ports;
+       for_each_set_bit(bit, &addr, 32) {
+               dpn[i].num = bit;
+               dpn[i].type = SDW_DPN_FULL;
+               dpn[i].simple_ch_prep_sm = true;
+               i++;
+       }
+
+       /* do this again for sink now */
+       nval = hweight32(prop->sink_ports);
+       prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval,
+                                          sizeof(*prop->sink_dpn_prop),
+                                          GFP_KERNEL);
+       if (!prop->sink_dpn_prop)
+               return -ENOMEM;
+
+       j = 0;
+       dpn = prop->sink_dpn_prop;
+       addr = prop->sink_ports;
+       for_each_set_bit(bit, &addr, 32) {
+               dpn[j].num = bit;
+               dpn[j].type = SDW_DPN_FULL;
+               dpn[j].simple_ch_prep_sm = true;
+               j++;
+       }
+
+       prop->simple_clk_stop_capable = true;
+
+       /* wake-up event */
+       prop->wake_capable = 0;
+
+       return 0;
+}
+
+static int sdw_mockup_bus_config(struct sdw_slave *slave,
+                                struct sdw_bus_params *params)
+{
+       return 0;
+}
+
+static int sdw_mockup_interrupt_callback(struct sdw_slave *slave,
+                                        struct sdw_slave_intr_status *status)
+{
+       return 0;
+}
+
+static const struct sdw_slave_ops sdw_mockup_slave_ops = {
+       .read_prop = sdw_mockup_read_prop,
+       .interrupt_callback = sdw_mockup_interrupt_callback,
+       .update_status = sdw_mockup_update_status,
+       .bus_config = sdw_mockup_bus_config,
+};
+
+static int sdw_mockup_sdw_probe(struct sdw_slave *slave,
+                               const struct sdw_device_id *id)
+{
+       struct device *dev = &slave->dev;
+       struct sdw_mockup_priv *sdw_mockup;
+       int ret;
+
+       sdw_mockup = devm_kzalloc(dev, sizeof(*sdw_mockup), GFP_KERNEL);
+       if (!sdw_mockup)
+               return -ENOMEM;
+
+       dev_set_drvdata(dev, sdw_mockup);
+       sdw_mockup->slave = slave;
+
+       slave->is_mockup_device = true;
+
+       ret =  devm_snd_soc_register_component(dev,
+                                              &snd_soc_sdw_mockup_component,
+                                              sdw_mockup_dai,
+                                              ARRAY_SIZE(sdw_mockup_dai));
+
+       return ret;
+}
+
+static int sdw_mockup_sdw_remove(struct sdw_slave *slave)
+{
+       return 0;
+}
+
+/*
+ * Intel reserved parts ID with the following mapping expected:
+ * 0xAAAA: generic full-duplex codec
+ * 0xAA55: headset codec (mock-up of RT711/RT5682) - full-duplex
+ * 0x55AA: amplifier (mock-up of RT1308/Maxim 98373) - playback only with
+ * IV feedback
+ * 0x5555: mic codec (mock-up of RT715) - capture-only
+ */
+static const struct sdw_device_id sdw_mockup_id[] = {
+       SDW_SLAVE_ENTRY_EXT(0x0105, 0xAAAA, 0x0, 0, 0),
+       SDW_SLAVE_ENTRY_EXT(0x0105, 0xAA55, 0x0, 0, 0),
+       SDW_SLAVE_ENTRY_EXT(0x0105, 0x55AA, 0x0, 0, 0),
+       SDW_SLAVE_ENTRY_EXT(0x0105, 0x5555, 0x0, 0, 0),
+       {},
+};
+MODULE_DEVICE_TABLE(sdw, sdw_mockup_id);
+
+static struct sdw_driver sdw_mockup_sdw_driver = {
+       .driver = {
+               .name = "sdw-mockup",
+               .owner = THIS_MODULE,
+       },
+       .probe = sdw_mockup_sdw_probe,
+       .remove = sdw_mockup_sdw_remove,
+       .ops = &sdw_mockup_slave_ops,
+       .id_table = sdw_mockup_id,
+};
+module_sdw_driver(sdw_mockup_sdw_driver);
+
+MODULE_DESCRIPTION("ASoC SDW mockup codec driver");
+MODULE_AUTHOR("Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>");
+MODULE_LICENSE("GPL");
index 7e29b0d..046955b 100644 (file)
@@ -602,6 +602,7 @@ config SND_SOC_INTEL_SOUNDWIRE_SOF_MACH
        select SND_SOC_DMIC
        select SND_SOC_INTEL_HDA_DSP_COMMON
        select SND_SOC_INTEL_SOF_MAXIM_COMMON
+       select SND_SOC_SDW_MOCKUP
        help
          Add support for Intel SoundWire-based platforms connected to
          MAX98373, RT700, RT711, RT1308 and RT715
index 1a867c7..82d909e 100644 (file)
@@ -328,6 +328,19 @@ static const struct snd_soc_ops sdw_ops = {
        .shutdown = sdw_shutdown,
 };
 
+static int sof_sdw_mic_codec_mockup_init(const struct snd_soc_acpi_link_adr *link,
+                                        struct snd_soc_dai_link *dai_links,
+                                        struct sof_sdw_codec_info *info,
+                                        bool playback)
+{
+       /*
+        * force DAI link to use same ID as RT715 and DMIC
+        * to reuse topologies
+        */
+       dai_links->id = SDW_DMIC_DAI_ID;
+       return 0;
+}
+
 static struct sof_sdw_codec_info codec_info_list[] = {
        {
                .part_id = 0x700,
@@ -410,6 +423,34 @@ static struct sof_sdw_codec_info codec_info_list[] = {
                .dai_name = "rt5682-sdw",
                .init = sof_sdw_rt5682_init,
        },
+       {
+               .part_id = 0xaaaa, /* generic codec mockup */
+               .version_id = 0,
+               .direction = {true, true},
+               .dai_name = "sdw-mockup-aif1",
+               .init = NULL,
+       },
+       {
+               .part_id = 0xaa55, /* headset codec mockup */
+               .version_id = 0,
+               .direction = {true, true},
+               .dai_name = "sdw-mockup-aif1",
+               .init = NULL,
+       },
+       {
+               .part_id = 0x55aa, /* amplifier mockup */
+               .version_id = 0,
+               .direction = {true, false},
+               .dai_name = "sdw-mockup-aif1",
+               .init = NULL,
+       },
+       {
+               .part_id = 0x5555,
+               .version_id = 0,
+               .direction = {false, true},
+               .dai_name = "sdw-mockup-aif1",
+               .init = sof_sdw_mic_codec_mockup_init,
+       },
 };
 
 static inline int find_codec_info_part(u64 adr)
index 12a205c..fef0b2d 100644 (file)
@@ -9,7 +9,8 @@ snd-soc-acpi-intel-match-objs := soc-acpi-intel-byt-match.o soc-acpi-intel-cht-m
        soc-acpi-intel-cml-match.o soc-acpi-intel-icl-match.o \
        soc-acpi-intel-tgl-match.o soc-acpi-intel-ehl-match.o \
        soc-acpi-intel-jsl-match.o soc-acpi-intel-adl-match.o \
-       soc-acpi-intel-hda-match.o
+       soc-acpi-intel-hda-match.o \
+       soc-acpi-intel-sdw-mockup-match.o
 
 obj-$(CONFIG_SND_SOC_INTEL_SST) += snd-soc-sst-dsp.o snd-soc-sst-ipc.o
 obj-$(CONFIG_SND_SOC_ACPI_INTEL_MATCH) += snd-soc-acpi-intel-match.o
index 39dad32..94b6507 100644 (file)
@@ -9,6 +9,7 @@
 #include <sound/soc-acpi.h>
 #include <sound/soc-acpi-intel-match.h>
 #include "../skylake/skl.h"
+#include "soc-acpi-intel-sdw-mockup-match.h"
 
 static struct skl_machine_pdata cnl_pdata = {
        .use_tplg_pcm = true,
@@ -60,6 +61,20 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_cnl_sdw_machines[] = {
                .sof_fw_filename = "sof-cnl.ri",
                .sof_tplg_filename = "sof-cnl-rt5682-sdw2.tplg"
        },
+       {
+               .link_mask = GENMASK(3, 0),
+               .links = sdw_mockup_headset_2amps_mic,
+               .drv_name = "sof_sdw",
+               .sof_fw_filename = "sof-cnl.ri",
+               .sof_tplg_filename = "sof-cml-rt711-rt1308-rt715.tplg",
+       },
+       {
+               .link_mask = BIT(0) | BIT(1) | BIT(3),
+               .links = sdw_mockup_headset_1amp_mic,
+               .drv_name = "sof_sdw",
+               .sof_fw_filename = "sof-cnl.ri",
+               .sof_tplg_filename = "sof-cml-rt711-rt1308-mono-rt715.tplg",
+       },
        {}
 };
 EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_cnl_sdw_machines);
diff --git a/sound/soc/intel/common/soc-acpi-intel-sdw-mockup-match.c b/sound/soc/intel/common/soc-acpi-intel-sdw-mockup-match.c
new file mode 100644 (file)
index 0000000..a3d3399
--- /dev/null
@@ -0,0 +1,166 @@
+// SPDX-License-Identifier: GPL-2.0-only
+//
+// soc-acpi-intel-sdw-mockup-match.c - tables and support for SoundWire
+// mockup device ACPI enumeration.
+//
+// Copyright (c) 2021, Intel Corporation.
+//
+
+#include <sound/soc-acpi.h>
+#include <sound/soc-acpi-intel-match.h>
+#include "soc-acpi-intel-sdw-mockup-match.h"
+
+static const struct snd_soc_acpi_endpoint sdw_mockup_single_endpoint = {
+       .num = 0,
+       .aggregated = 0,
+       .group_position = 0,
+       .group_id = 0,
+};
+
+static const struct snd_soc_acpi_endpoint sdw_mockup_l_endpoint = {
+       .num = 0,
+       .aggregated = 1,
+       .group_position = 0,
+       .group_id = 1,
+};
+
+static const struct snd_soc_acpi_endpoint sdw_mockup_r_endpoint = {
+       .num = 0,
+       .aggregated = 1,
+       .group_position = 1,
+       .group_id = 1,
+};
+
+static const struct snd_soc_acpi_adr_device sdw_mockup_headset_0_adr[] = {
+       {
+               .adr = 0x0000000105AA5500ull,
+               .num_endpoints = 1,
+               .endpoints = &sdw_mockup_single_endpoint,
+               .name_prefix = "sdw_mockup_headset0"
+       }
+};
+
+static const struct snd_soc_acpi_adr_device sdw_mockup_headset_1_adr[] = {
+       {
+               .adr = 0x0001000105AA5500ull,
+               .num_endpoints = 1,
+               .endpoints = &sdw_mockup_single_endpoint,
+               .name_prefix = "sdw_mockup_headset1"
+       }
+};
+
+static const struct snd_soc_acpi_adr_device sdw_mockup_amp_1_adr[] = {
+       {
+               .adr = 0x000100010555AA00ull,
+               .num_endpoints = 1,
+               .endpoints = &sdw_mockup_single_endpoint,
+               .name_prefix = "sdw_mockup_amp1"
+       }
+};
+
+static const struct snd_soc_acpi_adr_device sdw_mockup_amp_2_adr[] = {
+       {
+               .adr = 0x000200010555AA00ull,
+               .num_endpoints = 1,
+               .endpoints = &sdw_mockup_single_endpoint,
+               .name_prefix = "sdw_mockup_amp2"
+       }
+};
+
+static const struct snd_soc_acpi_adr_device sdw_mockup_mic_0_adr[] = {
+       {
+               .adr = 0x0000000105555500ull,
+               .num_endpoints = 1,
+               .endpoints = &sdw_mockup_single_endpoint,
+               .name_prefix = "sdw_mockup_mic0"
+       }
+};
+
+static const struct snd_soc_acpi_adr_device sdw_mockup_mic_3_adr[] = {
+       {
+               .adr = 0x0003000105555500ull,
+               .num_endpoints = 1,
+               .endpoints = &sdw_mockup_single_endpoint,
+               .name_prefix = "sdw_mockup_mic3"
+       }
+};
+
+static const struct snd_soc_acpi_adr_device sdw_mockup_amp_1_group1_adr[] = {
+       {
+               .adr = 0x000100010555AA00ull,
+               .num_endpoints = 1,
+               .endpoints = &sdw_mockup_l_endpoint,
+               .name_prefix = "sdw_mockup_amp1_l"
+       }
+};
+
+static const struct snd_soc_acpi_adr_device sdw_mockup_amp_2_group1_adr[] = {
+       {
+               .adr = 0x000200010555AA00ull,
+               .num_endpoints = 1,
+               .endpoints = &sdw_mockup_r_endpoint,
+               .name_prefix = "sdw_mockup_amp2_r"
+       }
+};
+
+const struct snd_soc_acpi_link_adr sdw_mockup_headset_1amp_mic[] = {
+       {
+               .mask = BIT(0),
+               .num_adr = ARRAY_SIZE(sdw_mockup_headset_0_adr),
+               .adr_d = sdw_mockup_headset_0_adr,
+       },
+       {
+               .mask = BIT(1),
+               .num_adr = ARRAY_SIZE(sdw_mockup_amp_1_adr),
+               .adr_d = sdw_mockup_amp_1_adr,
+       },
+       {
+               .mask = BIT(3),
+               .num_adr = ARRAY_SIZE(sdw_mockup_mic_3_adr),
+               .adr_d = sdw_mockup_mic_3_adr,
+       },
+       {}
+};
+
+const struct snd_soc_acpi_link_adr sdw_mockup_headset_2amps_mic[] = {
+       {
+               .mask = BIT(0),
+               .num_adr = ARRAY_SIZE(sdw_mockup_headset_0_adr),
+               .adr_d = sdw_mockup_headset_0_adr,
+       },
+       {
+               .mask = BIT(1),
+               .num_adr = ARRAY_SIZE(sdw_mockup_amp_1_group1_adr),
+               .adr_d = sdw_mockup_amp_1_group1_adr,
+       },
+       {
+               .mask = BIT(2),
+               .num_adr = ARRAY_SIZE(sdw_mockup_amp_2_group1_adr),
+               .adr_d = sdw_mockup_amp_2_group1_adr,
+       },
+       {
+               .mask = BIT(3),
+               .num_adr = ARRAY_SIZE(sdw_mockup_mic_3_adr),
+               .adr_d = sdw_mockup_mic_3_adr,
+       },
+       {}
+};
+
+const struct snd_soc_acpi_link_adr sdw_mockup_mic_headset_1amp[] = {
+       {
+               .mask = BIT(1),
+               .num_adr = ARRAY_SIZE(sdw_mockup_headset_1_adr),
+               .adr_d = sdw_mockup_headset_1_adr,
+       },
+       {
+               .mask = BIT(2),
+               .num_adr = ARRAY_SIZE(sdw_mockup_amp_2_adr),
+               .adr_d = sdw_mockup_amp_2_adr,
+       },
+       {
+               .mask = BIT(0),
+               .num_adr = ARRAY_SIZE(sdw_mockup_mic_0_adr),
+               .adr_d = sdw_mockup_mic_0_adr,
+       },
+       {}
+};
diff --git a/sound/soc/intel/common/soc-acpi-intel-sdw-mockup-match.h b/sound/soc/intel/common/soc-acpi-intel-sdw-mockup-match.h
new file mode 100644 (file)
index 0000000..c99eecd
--- /dev/null
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * soc-acpi-intel-sdw-mockup-match.h - tables and support for SoundWire
+ * mockup device ACPI enumeration.
+ *
+ * Copyright (c) 2021, Intel Corporation.
+ *
+ */
+
+#ifndef _SND_SOC_ACPI_INTEL_SDW_MOCKUP_MATCH
+#define _SND_SOC_ACPI_INTEL_SDW_MOCKUP_MATCH
+
+extern const struct snd_soc_acpi_link_adr sdw_mockup_headset_1amp_mic[];
+extern const struct snd_soc_acpi_link_adr sdw_mockup_headset_2amps_mic[];
+extern const struct snd_soc_acpi_link_adr sdw_mockup_mic_headset_1amp[];
+
+#endif
index 66595e3..e2488f0 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <sound/soc-acpi.h>
 #include <sound/soc-acpi-intel-match.h>
+#include "soc-acpi-intel-sdw-mockup-match.h"
 
 static const struct snd_soc_acpi_codecs tgl_codecs = {
        .num_codecs = 1,
@@ -351,6 +352,28 @@ EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_tgl_machines);
 
 /* this table is used when there is no I2S codec present */
 struct snd_soc_acpi_mach snd_soc_acpi_intel_tgl_sdw_machines[] = {
+       /* mockup tests need to be first */
+       {
+               .link_mask = GENMASK(3, 0),
+               .links = sdw_mockup_headset_2amps_mic,
+               .drv_name = "sof_sdw",
+               .sof_fw_filename = "sof-tgl.ri",
+               .sof_tplg_filename = "sof-tgl-rt711-rt1308-rt715.tplg",
+       },
+       {
+               .link_mask = BIT(0) | BIT(1) | BIT(3),
+               .links = sdw_mockup_headset_1amp_mic,
+               .drv_name = "sof_sdw",
+               .sof_fw_filename = "sof-tgl.ri",
+               .sof_tplg_filename = "sof-tgl-rt711-rt1308-mono-rt715.tplg",
+       },
+       {
+               .link_mask = BIT(0) | BIT(1) | BIT(2),
+               .links = sdw_mockup_mic_headset_1amp,
+               .drv_name = "sof_sdw",
+               .sof_fw_filename = "sof-tgl.ri",
+               .sof_tplg_filename = "sof-tgl-rt715-rt711-rt1308-mono.tplg",
+       },
        {
                .link_mask = 0x7,
                .links = tgl_sdw_rt711_link1_rt1308_link2_rt715_link0,