Commit 8c61951b authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman
Browse files

Merge tag 'soundwire-5.15-rc1' of...

Merge tag 'soundwire-5.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/vkoul/soundwire into char-misc-next

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
parents 96e9df33 2564a2d4
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -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,6 +902,7 @@ 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) {
			if (val != -ENODATA)
				dev_err(bus->dev, "SDW_SCP_STAT bread failed:%d\n", val);
			return val;
		}
@@ -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 */
+188 −41
Original line number Diff line number Diff line
@@ -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 (bank)
		dpn_config_off = CDNS_DPN_B1_CONFIG(p_params->num);
	else
		dpn_config_off = CDNS_DPN_B0_CONFIG(p_params->num);
	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_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);
	/* 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);
	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, dpn_config);
	}
	cdns_writel(cdns, dpn_config_off_target, dpn_config);

	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);
	cdns_writel(cdns, dpn_offsetctrl_off,  dpn_offsetctrl);
	} else {
		dpn_offsetctrl = cdns_readl(cdns, dpn_offsetctrl_off_source);
	}
	cdns_writel(cdns, dpn_offsetctrl_off_target,  dpn_offsetctrl);

	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");
+7 −0
Original line number Diff line number Diff line
@@ -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 */
+22 −14
Original line number Diff line number Diff line
@@ -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 = {
+133 −33
Original line number Diff line number Diff line
@@ -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);
	}

	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;
			/*
			 * 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.
			 */
		}
	}

	sdw->cdns.link_up = false;
	return 0;
	mutex_unlock(sdw->link_res->shim_lock);

	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,20 +1696,19 @@ 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 ((clock_stop_quirks & SDW_INTEL_CLK_STOP_BUS_RESET) ||
		    !clock_stop_quirks) {

			if (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
				 * 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)
};
Loading