[V4,8/8] soundwire: amd: add pm_prepare callback and pm ops support

Message ID 20230227154801.50319-9-Vijendar.Mukunda@amd.com
State New
Headers
Series [V4,1/8] soundwire: export sdw_compute_slave_ports() function |

Commit Message

Mukunda,Vijendar Feb. 27, 2023, 3:48 p.m. UTC
  Add pm_prepare callback and System level pm ops support for
AMD SoundWire manager driver.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
Signed-off-by: Mastan Katragadda <Mastan.Katragadda@amd.com>
---
 drivers/soundwire/amd_manager.c | 89 +++++++++++++++++++++++++++++++++
 1 file changed, 89 insertions(+)
  

Comments

Pierre-Louis Bossart Feb. 27, 2023, 5:07 p.m. UTC | #1
On 2/27/23 10:48, Vijendar Mukunda wrote:
> Add pm_prepare callback and System level pm ops support for
> AMD SoundWire manager driver.
> 
> Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
> Signed-off-by: Mastan Katragadda <Mastan.Katragadda@amd.com>

seems like you missed my comments in
https://lore.kernel.org/alsa-devel/7d32d552-6ca0-3c40-11ce-c8d727cadc05@linux.intel.com/

> ---
>  drivers/soundwire/amd_manager.c | 89 +++++++++++++++++++++++++++++++++
>  1 file changed, 89 insertions(+)
> 
> diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c
> index 88f0ad7ea7ec..5337443d9aea 100644
> --- a/drivers/soundwire/amd_manager.c
> +++ b/drivers/soundwire/amd_manager.c
> @@ -1141,6 +1141,93 @@ static int amd_sdw_clock_stop_exit(struct amd_sdw_manager *amd_manager)
>  	return 0;
>  }
>  
> +static int amd_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, "skipping device, no probed driver\n");
> +		return 0;
> +	}
> +	if (!slave->dev_num_sticky) {
> +		dev_dbg(dev, "skipping device, never detected on bus\n");
> +		return 0;
> +	}
> +	if (!pm_runtime_suspended(dev))
> +		return 0;
> +	ret = pm_request_resume(dev);

I think it's just better to let the pm_runtime framework deal with the
states than do this is two steps.

> +	if (ret < 0)
> +		dev_err(dev, "pm_request_resume failed: %d\n", ret);
> +
> +	return ret;
> +}
> +
> +static int __maybe_unused amd_pm_prepare(struct device *dev)
> +{
> +	struct amd_sdw_manager *amd_manager = dev_get_drvdata(dev);
> +	struct sdw_bus *bus = &amd_manager->bus;
> +	int ret;
> +
> +	if (bus->prop.hw_disabled) {
> +		dev_dbg(bus->dev, "SoundWire manager %d is disabled, ignoring\n",
> +			bus->link_id);
> +		return 0;
> +	}
> +	/*
> +	 * When multiple peripheral devices connected over the same link, if SoundWire manager
> +	 * device is not in runtime suspend state, observed that device alerts are missing
> +	 * without pm_prepare on AMD platforms in clockstop mode0.
> +	 */
> +	if (pm_runtime_suspended(dev) && amd_manager->power_mode_mask & AMD_SDW_CLK_STOP_MODE) {
> +		ret = pm_request_resume(dev);

same here.

> +		if (ret < 0) {
> +			dev_err(bus->dev, "pm_request_resume failed: %d\n", ret);
> +			return 0;
> +		}
> +	}
> +	/* To force peripheral devices to system level suspend state, resume the devices
> +	 * from runtime suspend state first. Without that unable to dispatch the alert
> +	 * status to peripheral driver during system level resume as they are in runtime
> +	 * suspend state.
> +	 */
> +	ret = device_for_each_child(bus->dev, NULL, amd_resume_child_device);
> +	if (ret < 0)
> +		dev_err(dev, "amd_resume_child_device failed: %d\n", ret);
> +	return 0;
> +}
> +
> +static int __maybe_unused amd_suspend(struct device *dev)
> +{
> +	struct amd_sdw_manager *amd_manager = dev_get_drvdata(dev);
> +	struct sdw_bus *bus = &amd_manager->bus;
> +	int ret;
> +
> +	if (bus->prop.hw_disabled) {
> +		dev_dbg(bus->dev, "SoundWire manager %d is disabled, ignoring\n",
> +			bus->link_id);
> +		return 0;
> +	}
> +
> +	if (amd_manager->power_mode_mask & AMD_SDW_CLK_STOP_MODE) {
> +		ret = amd_sdw_clock_stop(amd_manager);
> +		if (ret)
> +			return ret;
> +	} else if (amd_manager->power_mode_mask & AMD_SDW_POWER_OFF_MODE) {
> +		/*
> +		 * As per hardware programming sequence on AMD platforms,
> +		 * clock stop should be invoked first before powering-off
> +		 */
> +		ret = amd_sdw_clock_stop(amd_manager);
> +		if (ret)
> +			return ret;
> +		ret = amd_deinit_sdw_manager(amd_manager);
> +		if (ret)
> +			return ret;
> +	}
> +	return 0;
> +}
> +
>  static int __maybe_unused amd_suspend_runtime(struct device *dev)
>  {
>  	struct amd_sdw_manager *amd_manager = dev_get_drvdata(dev);
> @@ -1213,6 +1300,8 @@ static int __maybe_unused amd_resume_runtime(struct device *dev)
>  }
>  
>  static const struct dev_pm_ops amd_pm = {
> +	.prepare = amd_pm_prepare,
> +	SET_SYSTEM_SLEEP_PM_OPS(amd_suspend, amd_resume_runtime)
>  	SET_RUNTIME_PM_OPS(amd_suspend_runtime, amd_resume_runtime, NULL)
>  };
>
  
Mukunda,Vijendar Feb. 27, 2023, 6:42 p.m. UTC | #2
On 27/02/23 22:37, Pierre-Louis Bossart wrote:
>
> On 2/27/23 10:48, Vijendar Mukunda wrote:
>> Add pm_prepare callback and System level pm ops support for
>> AMD SoundWire manager driver.
>>
>> Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
>> Signed-off-by: Mastan Katragadda <Mastan.Katragadda@amd.com>
> seems like you missed my comments in
> https://lore.kernel.org/alsa-devel/7d32d552-6ca0-3c40-11ce-c8d727cadc05@linux.intel.com/
you missed my mail in reply thread. That's why we couldn't
get a chance to check your review comments.
>
>> ---
>>  drivers/soundwire/amd_manager.c | 89 +++++++++++++++++++++++++++++++++
>>  1 file changed, 89 insertions(+)
>>
>> diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c
>> index 88f0ad7ea7ec..5337443d9aea 100644
>> --- a/drivers/soundwire/amd_manager.c
>> +++ b/drivers/soundwire/amd_manager.c
>> @@ -1141,6 +1141,93 @@ static int amd_sdw_clock_stop_exit(struct amd_sdw_manager *amd_manager)
>>  	return 0;
>>  }
>>  
>> +static int amd_resume_child_device(struct device *dev, void *data)
>> +{
>> +	int ret;
>> +	struct sdw_slave *slave = dev_to_sdw_dev(dev);
>> +
    will fix inverting above two lines.
>> +	if (!slave->probed) {
>> +		dev_dbg(dev, "skipping device, no probed driver\n");
>> +		return 0;
>> +	}
>> +	if (!slave->dev_num_sticky) {
>> +		dev_dbg(dev, "skipping device, never detected on bus\n");
>> +		return 0;
>> +	}
>> +	if (!pm_runtime_suspended(dev))
>> +		return 0;
This will break when multiple peripheral devices connected
over the same link and any of the peripheral devices is active.
As amd_resume_child_device() will check for each peripheral
device on the bus. We want to resume peripheral devices,
which are runtime suspended. Rest of it, it should return 0
so that it could continue the iteration for the bus.

The other way we can fix it by always return 0 from
amd_resume_child_device(). In this case no need to check
whether device is runtime suspended or not.
>> +	ret = pm_request_resume(dev);
> I think it's just better to let the pm_runtime framework deal with the
> states than do this is two steps.
>
>> +	if (ret < 0)
>> +		dev_err(dev, "pm_request_resume failed: %d\n", ret);
>> +
>> +	return ret;
>> +}
>> +
>> +static int __maybe_unused amd_pm_prepare(struct device *dev)
>> +{
>> +	struct amd_sdw_manager *amd_manager = dev_get_drvdata(dev);
>> +	struct sdw_bus *bus = &amd_manager->bus;
>> +	int ret;
>> +
>> +	if (bus->prop.hw_disabled) {
>> +		dev_dbg(bus->dev, "SoundWire manager %d is disabled, ignoring\n",
>> +			bus->link_id);
>> +		return 0;
>> +	}
>> +	/*
>> +	 * When multiple peripheral devices connected over the same link, if SoundWire manager
>> +	 * device is not in runtime suspend state, observed that device alerts are missing
>> +	 * without pm_prepare on AMD platforms in clockstop mode0.
>> +	 */
>> +	if (pm_runtime_suspended(dev) && amd_manager->power_mode_mask & AMD_SDW_CLK_STOP_MODE) {
>> +		ret = pm_request_resume(dev);
> same here.
will check.
>> +		if (ret < 0) {
>> +			dev_err(bus->dev, "pm_request_resume failed: %d\n", ret);
>> +			return 0;
>> +		}
>> +	}
>> +	/* To force peripheral devices to system level suspend state, resume the devices
>> +	 * from runtime suspend state first. Without that unable to dispatch the alert
>> +	 * status to peripheral driver during system level resume as they are in runtime
>> +	 * suspend state.
>> +	 */
>> +	ret = device_for_each_child(bus->dev, NULL, amd_resume_child_device);
>> +	if (ret < 0)
>> +		dev_err(dev, "amd_resume_child_device failed: %d\n", ret);
>> +	return 0;
>> +}
>> +
>> +static int __maybe_unused amd_suspend(struct device *dev)
>> +{
>> +	struct amd_sdw_manager *amd_manager = dev_get_drvdata(dev);
>> +	struct sdw_bus *bus = &amd_manager->bus;
>> +	int ret;
>> +
>> +	if (bus->prop.hw_disabled) {
>> +		dev_dbg(bus->dev, "SoundWire manager %d is disabled, ignoring\n",
>> +			bus->link_id);
>> +		return 0;
>> +	}
>> +
>> +	if (amd_manager->power_mode_mask & AMD_SDW_CLK_STOP_MODE) {
>> +		ret = amd_sdw_clock_stop(amd_manager);
>> +		if (ret)
>> +			return ret;
will fix it.
>> +	} else if (amd_manager->power_mode_mask & AMD_SDW_POWER_OFF_MODE) {
>> +		/*
>> +		 * As per hardware programming sequence on AMD platforms,
>> +		 * clock stop should be invoked first before powering-off
>> +		 */
>> +		ret = amd_sdw_clock_stop(amd_manager);
>> +		if (ret)
>> +			return ret;
>> +		ret = amd_deinit_sdw_manager(amd_manager);
>> +		if (ret)
>> +			return ret;
>> +	}
>> +	return 0;
>> +}
>> +
>>  static int __maybe_unused amd_suspend_runtime(struct device *dev)
>>  {
>>  	struct amd_sdw_manager *amd_manager = dev_get_drvdata(dev);
>> @@ -1213,6 +1300,8 @@ static int __maybe_unused amd_resume_runtime(struct device *dev)
>>  }
>>  
>>  static const struct dev_pm_ops amd_pm = {
>> +	.prepare = amd_pm_prepare,
>> +	SET_SYSTEM_SLEEP_PM_OPS(amd_suspend, amd_resume_runtime)
>>  	SET_RUNTIME_PM_OPS(amd_suspend_runtime, amd_resume_runtime, NULL)
>>  };
>>
  
Pierre-Louis Bossart Feb. 27, 2023, 7:40 p.m. UTC | #3
On 2/27/23 13:42, Mukunda,Vijendar wrote:
> On 27/02/23 22:37, Pierre-Louis Bossart wrote:
>>
>> On 2/27/23 10:48, Vijendar Mukunda wrote:
>>> Add pm_prepare callback and System level pm ops support for
>>> AMD SoundWire manager driver.
>>>
>>> Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
>>> Signed-off-by: Mastan Katragadda <Mastan.Katragadda@amd.com>
>> seems like you missed my comments in
>> https://lore.kernel.org/alsa-devel/7d32d552-6ca0-3c40-11ce-c8d727cadc05@linux.intel.com/
> you missed my mail in reply thread. That's why we couldn't
> get a chance to check your review comments.

I don't see a reply be it in my local mail client or lore?
  
Mukunda,Vijendar Feb. 28, 2023, 1:03 a.m. UTC | #4
On 28/02/23 01:10, Pierre-Louis Bossart wrote:
>
> On 2/27/23 13:42, Mukunda,Vijendar wrote:
>> On 27/02/23 22:37, Pierre-Louis Bossart wrote:
>>> On 2/27/23 10:48, Vijendar Mukunda wrote:
>>>> Add pm_prepare callback and System level pm ops support for
>>>> AMD SoundWire manager driver.
>>>>
>>>> Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
>>>> Signed-off-by: Mastan Katragadda <Mastan.Katragadda@amd.com>
>>> seems like you missed my comments in
>>> https://lore.kernel.org/alsa-devel/7d32d552-6ca0-3c40-11ce-c8d727cadc05@linux.intel.com/
>> you missed my mail in reply thread. That's why we couldn't
>> get a chance to check your review comments.
> I don't see a reply be it in my local mail client or lore?
we have provided replies for your comments in below link.
https://lore.kernel.org/lkml/acd3a560-1218-9f1d-06ec-19e4d3d4e2c9@amd.com/
  

Patch

diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c
index 88f0ad7ea7ec..5337443d9aea 100644
--- a/drivers/soundwire/amd_manager.c
+++ b/drivers/soundwire/amd_manager.c
@@ -1141,6 +1141,93 @@  static int amd_sdw_clock_stop_exit(struct amd_sdw_manager *amd_manager)
 	return 0;
 }
 
+static int amd_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, "skipping device, no probed driver\n");
+		return 0;
+	}
+	if (!slave->dev_num_sticky) {
+		dev_dbg(dev, "skipping device, never detected on bus\n");
+		return 0;
+	}
+	if (!pm_runtime_suspended(dev))
+		return 0;
+	ret = pm_request_resume(dev);
+	if (ret < 0)
+		dev_err(dev, "pm_request_resume failed: %d\n", ret);
+
+	return ret;
+}
+
+static int __maybe_unused amd_pm_prepare(struct device *dev)
+{
+	struct amd_sdw_manager *amd_manager = dev_get_drvdata(dev);
+	struct sdw_bus *bus = &amd_manager->bus;
+	int ret;
+
+	if (bus->prop.hw_disabled) {
+		dev_dbg(bus->dev, "SoundWire manager %d is disabled, ignoring\n",
+			bus->link_id);
+		return 0;
+	}
+	/*
+	 * When multiple peripheral devices connected over the same link, if SoundWire manager
+	 * device is not in runtime suspend state, observed that device alerts are missing
+	 * without pm_prepare on AMD platforms in clockstop mode0.
+	 */
+	if (pm_runtime_suspended(dev) && amd_manager->power_mode_mask & AMD_SDW_CLK_STOP_MODE) {
+		ret = pm_request_resume(dev);
+		if (ret < 0) {
+			dev_err(bus->dev, "pm_request_resume failed: %d\n", ret);
+			return 0;
+		}
+	}
+	/* To force peripheral devices to system level suspend state, resume the devices
+	 * from runtime suspend state first. Without that unable to dispatch the alert
+	 * status to peripheral driver during system level resume as they are in runtime
+	 * suspend state.
+	 */
+	ret = device_for_each_child(bus->dev, NULL, amd_resume_child_device);
+	if (ret < 0)
+		dev_err(dev, "amd_resume_child_device failed: %d\n", ret);
+	return 0;
+}
+
+static int __maybe_unused amd_suspend(struct device *dev)
+{
+	struct amd_sdw_manager *amd_manager = dev_get_drvdata(dev);
+	struct sdw_bus *bus = &amd_manager->bus;
+	int ret;
+
+	if (bus->prop.hw_disabled) {
+		dev_dbg(bus->dev, "SoundWire manager %d is disabled, ignoring\n",
+			bus->link_id);
+		return 0;
+	}
+
+	if (amd_manager->power_mode_mask & AMD_SDW_CLK_STOP_MODE) {
+		ret = amd_sdw_clock_stop(amd_manager);
+		if (ret)
+			return ret;
+	} else if (amd_manager->power_mode_mask & AMD_SDW_POWER_OFF_MODE) {
+		/*
+		 * As per hardware programming sequence on AMD platforms,
+		 * clock stop should be invoked first before powering-off
+		 */
+		ret = amd_sdw_clock_stop(amd_manager);
+		if (ret)
+			return ret;
+		ret = amd_deinit_sdw_manager(amd_manager);
+		if (ret)
+			return ret;
+	}
+	return 0;
+}
+
 static int __maybe_unused amd_suspend_runtime(struct device *dev)
 {
 	struct amd_sdw_manager *amd_manager = dev_get_drvdata(dev);
@@ -1213,6 +1300,8 @@  static int __maybe_unused amd_resume_runtime(struct device *dev)
 }
 
 static const struct dev_pm_ops amd_pm = {
+	.prepare = amd_pm_prepare,
+	SET_SYSTEM_SLEEP_PM_OPS(amd_suspend, amd_resume_runtime)
 	SET_RUNTIME_PM_OPS(amd_suspend_runtime, amd_resume_runtime, NULL)
 };