linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 help / color / mirror / Atom feed
* [Linux-kernel-mentees] [PATCH v1 0/6] [media] pci: use generic power management
@ 2020-06-29  7:35 Vaibhav Gupta
  2020-06-29  7:35 ` [Linux-kernel-mentees] [PATCH v1 1/6] [media] sta2x11: " Vaibhav Gupta
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Vaibhav Gupta @ 2020-06-29  7:35 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas, bjorn, Vaibhav Gupta,
	Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel-mentees, linux-kernel, Vaibhav Gupta

Linux Kernel Mentee: Remove Legacy Power Management.

The purpose of this patch series is to remove legacy power management callbacks
from amd ethernet drivers.

The callbacks performing suspend() and resume() operations are still calling
pci_save_state(), pci_set_power_state(), etc. and handling the power management
themselves, which is not recommended.

The conversion requires the removal of the those function calls and change the
callback definition accordingly and make use of dev_pm_ops structure.

All patches are compile-tested only.

Vaibhav Gupta (6):
  [media] sta2x11: use generic power management
  [media] cx23885: use generic power management
  [media] cx25821: use generic power management
  [media] cx88: use generic power management
  [media] meye: use generic power management
  [media] tw68: use generic power management

 drivers/media/pci/cx23885/cx23885-core.c | 16 +++---
 drivers/media/pci/cx25821/cx25821-core.c |  8 ++-
 drivers/media/pci/cx88/cx88-video.c      | 52 +++++--------------
 drivers/media/pci/meye/meye.c            | 15 ++----
 drivers/media/pci/sta2x11/sta2x11_vip.c  | 63 ++++++------------------
 drivers/media/pci/tw68/tw68-core.c       | 30 +++++------
 6 files changed, 60 insertions(+), 124 deletions(-)

-- 
2.27.0

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Linux-kernel-mentees] [PATCH v1 1/6] [media] sta2x11: use generic power management
  2020-06-29  7:35 [Linux-kernel-mentees] [PATCH v1 0/6] [media] pci: use generic power management Vaibhav Gupta
@ 2020-06-29  7:35 ` Vaibhav Gupta
  2020-06-29  7:36 ` [Linux-kernel-mentees] [PATCH v1 2/6] [media] cx23885: " Vaibhav Gupta
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Vaibhav Gupta @ 2020-06-29  7:35 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas, bjorn, Vaibhav Gupta,
	Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel-mentees, linux-kernel, Vaibhav Gupta

With legacy PM, drivers themselves were responsible for managing the
device's power states and takes care of register states.

After upgrading to the generic structure, PCI core will take care of
required tasks and drivers should do only device-specific operations.

Thus, there is no need to call the PCI helper functions like
pci_enable_device(), pci_save/restore_sate(), etc.

Compile-tested only.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
---
 drivers/media/pci/sta2x11/sta2x11_vip.c | 63 ++++++-------------------
 1 file changed, 15 insertions(+), 48 deletions(-)

diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c b/drivers/media/pci/sta2x11/sta2x11_vip.c
index 798574cfad35..56804ab11c2d 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -1167,21 +1167,18 @@ static void sta2x11_vip_remove_one(struct pci_dev *pdev)
 	 */
 }
 
-#ifdef CONFIG_PM
-
 /**
  * sta2x11_vip_suspend - set device into power save mode
- * @pdev: PCI device
- * @state: new state of device
+ * @dev_d: PCI device
  *
  * all relevant registers are saved and an attempt to set a new state is made.
  *
  * return value: 0 always indicate success,
  * even if device could not be disabled. (workaround for hardware problem)
  */
-static int sta2x11_vip_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused sta2x11_vip_suspend(struct device *dev_d)
 {
-	struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
+	struct v4l2_device *v4l2_dev = dev_get_drvdata(dev_d);
 	struct sta2x11_vip *vip =
 	    container_of(v4l2_dev, struct sta2x11_vip, v4l2_dev);
 	unsigned long flags;
@@ -1198,15 +1195,8 @@ static int sta2x11_vip_suspend(struct pci_dev *pdev, pm_message_t state)
 		vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i] =
 		    reg_read(vip, registers_to_save[i]);
 	spin_unlock_irqrestore(&vip->slock, flags);
-	/* save pci state */
-	pci_save_state(pdev);
-	if (pci_set_power_state(pdev, pci_choose_state(pdev, state))) {
-		/*
-		 * do not call pci_disable_device on sta2x11 because it
-		 * break all other Bus masters on this EP
-		 */
-		vip->disabled = 1;
-	}
+
+	vip->disabled = 1;
 
 	pr_info("VIP: suspend\n");
 	return 0;
@@ -1214,45 +1204,23 @@ static int sta2x11_vip_suspend(struct pci_dev *pdev, pm_message_t state)
 
 /**
  * sta2x11_vip_resume - resume device operation
- * @pdev : PCI device
- *
- * re-enable device, set PCI state to powered and restore registers.
- * resume normal device operation afterwards.
+ * @dev : PCI device
  *
  * return value: 0, no error.
  *
  * other, could not set device to power on state.
  */
-static int sta2x11_vip_resume(struct pci_dev *pdev)
+static int __maybe_unused sta2x11_vip_resume(struct device *dev_d)
 {
-	struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
+	struct v4l2_device *v4l2_dev = dev_get_drvdata(dev_d);
 	struct sta2x11_vip *vip =
 	    container_of(v4l2_dev, struct sta2x11_vip, v4l2_dev);
 	unsigned long flags;
-	int ret, i;
+	int i;
 
 	pr_info("VIP: resume\n");
-	/* restore pci state */
-	if (vip->disabled) {
-		ret = pci_enable_device(pdev);
-		if (ret) {
-			pr_warn("VIP: Can't enable device.\n");
-			return ret;
-		}
-		vip->disabled = 0;
-	}
-	ret = pci_set_power_state(pdev, PCI_D0);
-	if (ret) {
-		/*
-		 * do not call pci_disable_device on sta2x11 because it
-		 * break all other Bus masters on this EP
-		 */
-		pr_warn("VIP: Can't enable device.\n");
-		vip->disabled = 1;
-		return ret;
-	}
 
-	pci_restore_state(pdev);
+	vip->disabled = 0;
 
 	spin_lock_irqsave(&vip->slock, flags);
 	for (i = 1; i < SAVE_COUNT; i++)
@@ -1266,22 +1234,21 @@ static int sta2x11_vip_resume(struct pci_dev *pdev)
 	return 0;
 }
 
-#endif
-
 static const struct pci_device_id sta2x11_vip_pci_tbl[] = {
 	{PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_VIP)},
 	{0,}
 };
 
+static SIMPLE_DEV_PM_OPS(sta2x11_vip_pm_ops,
+			 sta2x11_vip_suspend,
+			 sta2x11_vip_resume);
+
 static struct pci_driver sta2x11_vip_driver = {
 	.name = KBUILD_MODNAME,
 	.probe = sta2x11_vip_init_one,
 	.remove = sta2x11_vip_remove_one,
 	.id_table = sta2x11_vip_pci_tbl,
-#ifdef CONFIG_PM
-	.suspend = sta2x11_vip_suspend,
-	.resume = sta2x11_vip_resume,
-#endif
+	.driver.pm = &sta2x11_vip_pm_ops,
 };
 
 static int __init sta2x11_vip_init_module(void)
-- 
2.27.0

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [Linux-kernel-mentees] [PATCH v1 2/6] [media] cx23885: use generic power management
  2020-06-29  7:35 [Linux-kernel-mentees] [PATCH v1 0/6] [media] pci: use generic power management Vaibhav Gupta
  2020-06-29  7:35 ` [Linux-kernel-mentees] [PATCH v1 1/6] [media] sta2x11: " Vaibhav Gupta
@ 2020-06-29  7:36 ` Vaibhav Gupta
  2020-07-13 10:01   ` Hans Verkuil
  2020-06-29  7:36 ` [Linux-kernel-mentees] [PATCH v1 3/6] [media] cx25821: " Vaibhav Gupta
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: Vaibhav Gupta @ 2020-06-29  7:36 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas, bjorn, Vaibhav Gupta,
	Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel-mentees, linux-kernel, Vaibhav Gupta

The .suspend() and .resume() callbacks are not defined for this driver.
Still, their power managemgement stucture can be easily upgraded to
gemeric, without affecting its normal behaviour.

Hence, define them NULL and use struct dev_pm_ops type to bind them.

Compile-tested only.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
---
 drivers/media/pci/cx23885/cx23885-core.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/media/pci/cx23885/cx23885-core.c b/drivers/media/pci/cx23885/cx23885-core.c
index 7e0b0b7cc2a3..da9ee7270dfd 100644
--- a/drivers/media/pci/cx23885/cx23885-core.c
+++ b/drivers/media/pci/cx23885/cx23885-core.c
@@ -2230,14 +2230,18 @@ static const struct pci_device_id cx23885_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, cx23885_pci_tbl);
 
+#define cx23885_suspend NULL
+#define cx23885_resume NULL
+
+static SIMPLE_DEV_PM_OPS(cx23885_pm_ops, cx23885_suspend, cx23885_resume);
+
 static struct pci_driver cx23885_pci_driver = {
-	.name     = "cx23885",
-	.id_table = cx23885_pci_tbl,
-	.probe    = cx23885_initdev,
-	.remove   = cx23885_finidev,
+	.name      = "cx23885",
+	.id_table  = cx23885_pci_tbl,
+	.probe     = cx23885_initdev,
+	.remove    = cx23885_finidev,
 	/* TODO */
-	.suspend  = NULL,
-	.resume   = NULL,
+	.driver.pm = &cx23885_pm_ops,
 };
 
 static int __init cx23885_init(void)
-- 
2.27.0

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [Linux-kernel-mentees] [PATCH v1 3/6] [media] cx25821: use generic power management
  2020-06-29  7:35 [Linux-kernel-mentees] [PATCH v1 0/6] [media] pci: use generic power management Vaibhav Gupta
  2020-06-29  7:35 ` [Linux-kernel-mentees] [PATCH v1 1/6] [media] sta2x11: " Vaibhav Gupta
  2020-06-29  7:36 ` [Linux-kernel-mentees] [PATCH v1 2/6] [media] cx23885: " Vaibhav Gupta
@ 2020-06-29  7:36 ` Vaibhav Gupta
  2020-07-13 10:03   ` Hans Verkuil
  2020-06-29  7:36 ` [Linux-kernel-mentees] [PATCH v1 4/6] [media] cx88: " Vaibhav Gupta
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: Vaibhav Gupta @ 2020-06-29  7:36 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas, bjorn, Vaibhav Gupta,
	Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel-mentees, linux-kernel, Vaibhav Gupta

The .suspend() and .resume() callbacks are not defined for this driver.
Still, their power managemgement stucture can be easily upgraded to
gemeric, without affecting its normal behaviour.

Hence, define them NULL and use struct dev_pm_ops type to bind them.

Compile-tested only.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
---
 drivers/media/pci/cx25821/cx25821-core.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/media/pci/cx25821/cx25821-core.c b/drivers/media/pci/cx25821/cx25821-core.c
index 41be22ce66f3..59501939d741 100644
--- a/drivers/media/pci/cx25821/cx25821-core.c
+++ b/drivers/media/pci/cx25821/cx25821-core.c
@@ -1369,14 +1369,18 @@ static const struct pci_device_id cx25821_pci_tbl[] = {
 
 MODULE_DEVICE_TABLE(pci, cx25821_pci_tbl);
 
+#define cx25821_suspend NULL
+#define cx25821_resume NULL
+
+static SIMPLE_DEV_PM_OPS(cx25821_pm_ops, cx25821_suspend, cx25821_resume);
+
 static struct pci_driver cx25821_pci_driver = {
 	.name = "cx25821",
 	.id_table = cx25821_pci_tbl,
 	.probe = cx25821_initdev,
 	.remove = cx25821_finidev,
 	/* TODO */
-	.suspend = NULL,
-	.resume = NULL,
+	.driver.pm = &cx25821_pm_ops,
 };
 
 static int __init cx25821_init(void)
-- 
2.27.0

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [Linux-kernel-mentees] [PATCH v1 4/6] [media] cx88: use generic power management
  2020-06-29  7:35 [Linux-kernel-mentees] [PATCH v1 0/6] [media] pci: use generic power management Vaibhav Gupta
                   ` (2 preceding siblings ...)
  2020-06-29  7:36 ` [Linux-kernel-mentees] [PATCH v1 3/6] [media] cx25821: " Vaibhav Gupta
@ 2020-06-29  7:36 ` Vaibhav Gupta
  2020-06-29  7:36 ` [Linux-kernel-mentees] [PATCH v1 5/6] [media] meye: " Vaibhav Gupta
  2020-06-29  7:36 ` [Linux-kernel-mentees] [PATCH v1 6/6] [media] tw68: " Vaibhav Gupta
  5 siblings, 0 replies; 11+ messages in thread
From: Vaibhav Gupta @ 2020-06-29  7:36 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas, bjorn, Vaibhav Gupta,
	Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel-mentees, linux-kernel, Vaibhav Gupta

With legacy PM, drivers themselves were responsible for managing the
device's power states and takes care of register states.

After upgrading to the generic structure, PCI core will take care of
required tasks and drivers should do only device-specific operations.

The driver was invoking PCI helper functions like pci_save/restore_state(),
pci_enable/disable_device() and pci_set_power_state(), which is not
recommended.

Compile-tested only.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
---
 drivers/media/pci/cx88/cx88-video.c | 52 ++++++++---------------------
 1 file changed, 13 insertions(+), 39 deletions(-)

diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
index ba0e9660a047..a06d5b8f31b9 100644
--- a/drivers/media/pci/cx88/cx88-video.c
+++ b/drivers/media/pci/cx88/cx88-video.c
@@ -1551,10 +1551,9 @@ static void cx8800_finidev(struct pci_dev *pci_dev)
 	kfree(dev);
 }
 
-#ifdef CONFIG_PM
-static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
+static int __maybe_unused cx8800_suspend(struct device *dev_d)
 {
-	struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
+	struct cx8800_dev *dev = dev_get_drvdata(dev_d);
 	struct cx88_core *core = dev->core;
 	unsigned long flags;
 
@@ -1575,40 +1574,17 @@ static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
 	/* FIXME -- shutdown device */
 	cx88_shutdown(core);
 
-	pci_save_state(pci_dev);
-	if (pci_set_power_state(pci_dev,
-				pci_choose_state(pci_dev, state)) != 0) {
-		pci_disable_device(pci_dev);
-		dev->state.disabled = 1;
-	}
+	dev->state.disabled = 1;
 	return 0;
 }
 
-static int cx8800_resume(struct pci_dev *pci_dev)
+static int __maybe_unused cx8800_resume(struct device *dev_d)
 {
-	struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
+	struct cx8800_dev *dev = dev_get_drvdata(dev_d);
 	struct cx88_core *core = dev->core;
 	unsigned long flags;
-	int err;
-
-	if (dev->state.disabled) {
-		err = pci_enable_device(pci_dev);
-		if (err) {
-			pr_err("can't enable device\n");
-			return err;
-		}
-
-		dev->state.disabled = 0;
-	}
-	err = pci_set_power_state(pci_dev, PCI_D0);
-	if (err) {
-		pr_err("can't set power state\n");
-		pci_disable_device(pci_dev);
-		dev->state.disabled = 1;
 
-		return err;
-	}
-	pci_restore_state(pci_dev);
+	dev->state.disabled = 0;
 
 	/* FIXME: re-initialize hardware */
 	cx88_reset(core);
@@ -1631,7 +1607,6 @@ static int cx8800_resume(struct pci_dev *pci_dev)
 
 	return 0;
 }
-#endif
 
 /* ----------------------------------------------------------- */
 
@@ -1647,15 +1622,14 @@ static const struct pci_device_id cx8800_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, cx8800_pci_tbl);
 
+static SIMPLE_DEV_PM_OPS(cx8800_pm_ops, cx8800_suspend, cx8800_resume);
+
 static struct pci_driver cx8800_pci_driver = {
-	.name     = "cx8800",
-	.id_table = cx8800_pci_tbl,
-	.probe    = cx8800_initdev,
-	.remove   = cx8800_finidev,
-#ifdef CONFIG_PM
-	.suspend  = cx8800_suspend,
-	.resume   = cx8800_resume,
-#endif
+	.name      = "cx8800",
+	.id_table  = cx8800_pci_tbl,
+	.probe     = cx8800_initdev,
+	.remove    = cx8800_finidev,
+	.driver.pm = &cx8800_pm_ops,
 };
 
 module_pci_driver(cx8800_pci_driver);
-- 
2.27.0

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [Linux-kernel-mentees] [PATCH v1 5/6] [media] meye: use generic power management
  2020-06-29  7:35 [Linux-kernel-mentees] [PATCH v1 0/6] [media] pci: use generic power management Vaibhav Gupta
                   ` (3 preceding siblings ...)
  2020-06-29  7:36 ` [Linux-kernel-mentees] [PATCH v1 4/6] [media] cx88: " Vaibhav Gupta
@ 2020-06-29  7:36 ` Vaibhav Gupta
  2020-06-29  7:36 ` [Linux-kernel-mentees] [PATCH v1 6/6] [media] tw68: " Vaibhav Gupta
  5 siblings, 0 replies; 11+ messages in thread
From: Vaibhav Gupta @ 2020-06-29  7:36 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas, bjorn, Vaibhav Gupta,
	Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel-mentees, linux-kernel, Vaibhav Gupta

With legacy PM, drivers themselves were responsible for managing the
device's power states and takes care of register states.

After upgrading to the generic structure, PCI core will take care of
required tasks and drivers should do only device-specific operations.

The driver was invoking PCI helper functions like pci_save/restore_state()
which is not recommended.

Compile-tested only.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
---
 drivers/media/pci/meye/meye.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/media/pci/meye/meye.c b/drivers/media/pci/meye/meye.c
index 73e064e6f56d..7fb3b1853b87 100644
--- a/drivers/media/pci/meye/meye.c
+++ b/drivers/media/pci/meye/meye.c
@@ -1528,19 +1528,16 @@ static const struct v4l2_ctrl_ops meye_ctrl_ops = {
 	.s_ctrl = meye_s_ctrl,
 };
 
-#ifdef CONFIG_PM
-static int meye_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused meye_suspend(struct device *dev)
 {
-	pci_save_state(pdev);
 	meye.pm_mchip_mode = meye.mchip_mode;
 	mchip_hic_stop();
 	mchip_set(MCHIP_MM_INTA, 0x0);
 	return 0;
 }
 
-static int meye_resume(struct pci_dev *pdev)
+static int __maybe_unused meye_resume(struct device *dev)
 {
-	pci_restore_state(pdev);
 	pci_write_config_word(meye.mchip_dev, MCHIP_PCI_SOFTRESET_SET, 1);
 
 	mchip_delay(MCHIP_HIC_CMD, 0);
@@ -1562,7 +1559,6 @@ static int meye_resume(struct pci_dev *pdev)
 	}
 	return 0;
 }
-#endif
 
 static int meye_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
 {
@@ -1788,15 +1784,14 @@ static const struct pci_device_id meye_pci_tbl[] = {
 
 MODULE_DEVICE_TABLE(pci, meye_pci_tbl);
 
+static SIMPLE_DEV_PM_OPS(meye_pm_ops, meye_suspend, meye_resume);
+
 static struct pci_driver meye_driver = {
 	.name		= "meye",
 	.id_table	= meye_pci_tbl,
 	.probe		= meye_probe,
 	.remove		= meye_remove,
-#ifdef CONFIG_PM
-	.suspend	= meye_suspend,
-	.resume		= meye_resume,
-#endif
+	.driver.pm	= &meye_pm_ops,
 };
 
 static int __init meye_init(void)
-- 
2.27.0

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [Linux-kernel-mentees] [PATCH v1 6/6] [media] tw68: use generic power management
  2020-06-29  7:35 [Linux-kernel-mentees] [PATCH v1 0/6] [media] pci: use generic power management Vaibhav Gupta
                   ` (4 preceding siblings ...)
  2020-06-29  7:36 ` [Linux-kernel-mentees] [PATCH v1 5/6] [media] meye: " Vaibhav Gupta
@ 2020-06-29  7:36 ` Vaibhav Gupta
  5 siblings, 0 replies; 11+ messages in thread
From: Vaibhav Gupta @ 2020-06-29  7:36 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas, bjorn, Vaibhav Gupta,
	Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel-mentees, linux-kernel, Vaibhav Gupta

With legacy PM, drivers themselves were responsible for managing the
device's power states and takes care of register states.

After upgrading to the generic structure, PCI core will take care of
required tasks and drivers should do only device-specific operations.

The driver was invoking PCI helper functions like pci_save/restore_state()
which is not recommended.

Compile-Tested only.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
---
 drivers/media/pci/tw68/tw68-core.c | 30 +++++++++++-------------------
 1 file changed, 11 insertions(+), 19 deletions(-)

diff --git a/drivers/media/pci/tw68/tw68-core.c b/drivers/media/pci/tw68/tw68-core.c
index b45f3ffa3de5..065420b09250 100644
--- a/drivers/media/pci/tw68/tw68-core.c
+++ b/drivers/media/pci/tw68/tw68-core.c
@@ -359,10 +359,9 @@ static void tw68_finidev(struct pci_dev *pci_dev)
 	v4l2_device_unregister(&dev->v4l2_dev);
 }
 
-#ifdef CONFIG_PM
-
-static int tw68_suspend(struct pci_dev *pci_dev , pm_message_t state)
+static int __maybe_unused tw68_suspend(struct device *dev_d)
 {
+	struct pci_dev *pci_dev = to_pci_dev(dev_d);
 	struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
 	struct tw68_dev *dev = container_of(v4l2_dev,
 				struct tw68_dev, v4l2_dev);
@@ -373,24 +372,19 @@ static int tw68_suspend(struct pci_dev *pci_dev , pm_message_t state)
 
 	synchronize_irq(pci_dev->irq);
 
-	pci_save_state(pci_dev);
-	pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state));
 	vb2_discard_done(&dev->vidq);
 
 	return 0;
 }
 
-static int tw68_resume(struct pci_dev *pci_dev)
+static int __maybe_unused tw68_resume(struct device *dev_d)
 {
-	struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
+	struct v4l2_device *v4l2_dev = dev_get_drvdata(dev_d);
 	struct tw68_dev *dev = container_of(v4l2_dev,
 					    struct tw68_dev, v4l2_dev);
 	struct tw68_buf *buf;
 	unsigned long flags;
 
-	pci_set_power_state(pci_dev, PCI_D0);
-	pci_restore_state(pci_dev);
-
 	/* Do things that are done in tw68_initdev ,
 		except of initializing memory structures.*/
 
@@ -408,19 +402,17 @@ static int tw68_resume(struct pci_dev *pci_dev)
 
 	return 0;
 }
-#endif
 
 /* ----------------------------------------------------------- */
 
+static SIMPLE_DEV_PM_OPS(tw68_pm_ops, tw68_suspend, tw68_resume);
+
 static struct pci_driver tw68_pci_driver = {
-	.name	  = "tw68",
-	.id_table = tw68_pci_tbl,
-	.probe	  = tw68_initdev,
-	.remove	  = tw68_finidev,
-#ifdef CONFIG_PM
-	.suspend  = tw68_suspend,
-	.resume   = tw68_resume
-#endif
+	.name	   = "tw68",
+	.id_table  = tw68_pci_tbl,
+	.probe	   = tw68_initdev,
+	.remove	   = tw68_finidev,
+	.driver.pm = &tw68_pm_ops,
 };
 
 module_pci_driver(tw68_pci_driver);
-- 
2.27.0

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH v1 2/6] [media] cx23885: use generic power management
  2020-06-29  7:36 ` [Linux-kernel-mentees] [PATCH v1 2/6] [media] cx23885: " Vaibhav Gupta
@ 2020-07-13 10:01   ` Hans Verkuil
  2020-07-14  0:38     ` Bjorn Helgaas
  0 siblings, 1 reply; 11+ messages in thread
From: Hans Verkuil @ 2020-07-13 10:01 UTC (permalink / raw)
  To: Vaibhav Gupta, Bjorn Helgaas, Bjorn Helgaas, bjorn,
	Vaibhav Gupta, Mauro Carvalho Chehab
  Cc: linux-kernel-mentees, linux-kernel, linux-media

On 29/06/2020 09:36, Vaibhav Gupta wrote:
> The .suspend() and .resume() callbacks are not defined for this driver.
> Still, their power managemgement stucture can be easily upgraded to

management structure

> gemeric, without affecting its normal behaviour.

generic

> 
> Hence, define them NULL and use struct dev_pm_ops type to bind them.
> 
> Compile-tested only.
> 
> Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
> ---
>  drivers/media/pci/cx23885/cx23885-core.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/pci/cx23885/cx23885-core.c b/drivers/media/pci/cx23885/cx23885-core.c
> index 7e0b0b7cc2a3..da9ee7270dfd 100644
> --- a/drivers/media/pci/cx23885/cx23885-core.c
> +++ b/drivers/media/pci/cx23885/cx23885-core.c
> @@ -2230,14 +2230,18 @@ static const struct pci_device_id cx23885_pci_tbl[] = {
>  };
>  MODULE_DEVICE_TABLE(pci, cx23885_pci_tbl);
>  
> +#define cx23885_suspend NULL
> +#define cx23885_resume NULL
> +
> +static SIMPLE_DEV_PM_OPS(cx23885_pm_ops, cx23885_suspend, cx23885_resume);
> +
>  static struct pci_driver cx23885_pci_driver = {
> -	.name     = "cx23885",
> -	.id_table = cx23885_pci_tbl,
> -	.probe    = cx23885_initdev,
> -	.remove   = cx23885_finidev,
> +	.name      = "cx23885",
> +	.id_table  = cx23885_pci_tbl,
> +	.probe     = cx23885_initdev,
> +	.remove    = cx23885_finidev,
>  	/* TODO */
> -	.suspend  = NULL,
> -	.resume   = NULL,
> +	.driver.pm = &cx23885_pm_ops,

I don't entirely understand this. Wouldn't it be sufficient to just
drop the .suspend/.resume assignments here? It is now required for
driver.pm to be non-NULL?

I'm not up to speed on the changes, but normally you can leave things
NULL if you don't support a feature (PM in this case).

Regards,

	Hans

>  };
>  
>  static int __init cx23885_init(void)
> 

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH v1 3/6] [media] cx25821: use generic power management
  2020-06-29  7:36 ` [Linux-kernel-mentees] [PATCH v1 3/6] [media] cx25821: " Vaibhav Gupta
@ 2020-07-13 10:03   ` Hans Verkuil
  0 siblings, 0 replies; 11+ messages in thread
From: Hans Verkuil @ 2020-07-13 10:03 UTC (permalink / raw)
  To: Vaibhav Gupta, Bjorn Helgaas, Bjorn Helgaas, bjorn,
	Vaibhav Gupta, Mauro Carvalho Chehab
  Cc: linux-kernel-mentees, linux-kernel, linux-media

On 29/06/2020 09:36, Vaibhav Gupta wrote:
> The .suspend() and .resume() callbacks are not defined for this driver.
> Still, their power managemgement stucture can be easily upgraded to
> gemeric, without affecting its normal behaviour.
> 
> Hence, define them NULL and use struct dev_pm_ops type to bind them.
> 
> Compile-tested only.
> 
> Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
> ---
>  drivers/media/pci/cx25821/cx25821-core.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/pci/cx25821/cx25821-core.c b/drivers/media/pci/cx25821/cx25821-core.c
> index 41be22ce66f3..59501939d741 100644
> --- a/drivers/media/pci/cx25821/cx25821-core.c
> +++ b/drivers/media/pci/cx25821/cx25821-core.c
> @@ -1369,14 +1369,18 @@ static const struct pci_device_id cx25821_pci_tbl[] = {
>  
>  MODULE_DEVICE_TABLE(pci, cx25821_pci_tbl);
>  
> +#define cx25821_suspend NULL
> +#define cx25821_resume NULL
> +
> +static SIMPLE_DEV_PM_OPS(cx25821_pm_ops, cx25821_suspend, cx25821_resume);
> +
>  static struct pci_driver cx25821_pci_driver = {
>  	.name = "cx25821",
>  	.id_table = cx25821_pci_tbl,
>  	.probe = cx25821_initdev,
>  	.remove = cx25821_finidev,
>  	/* TODO */
> -	.suspend = NULL,
> -	.resume = NULL,
> +	.driver.pm = &cx25821_pm_ops,
>  };

Same question as for 2/6.

Regards,

	Hans

>  
>  static int __init cx25821_init(void)
> 

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH v1 2/6] [media] cx23885: use generic power management
  2020-07-13 10:01   ` Hans Verkuil
@ 2020-07-14  0:38     ` Bjorn Helgaas
  2020-07-14 10:52       ` Vaibhav Gupta
  0 siblings, 1 reply; 11+ messages in thread
From: Bjorn Helgaas @ 2020-07-14  0:38 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Vaibhav Gupta, linux-kernel, Bjorn Helgaas,
	Mauro Carvalho Chehab, linux-kernel-mentees, linux-media

On Mon, Jul 13, 2020 at 12:01:51PM +0200, Hans Verkuil wrote:
> On 29/06/2020 09:36, Vaibhav Gupta wrote:
> > The .suspend() and .resume() callbacks are not defined for this driver.
> > Still, their power managemgement stucture can be easily upgraded to
> 
> management structure
> 
> > gemeric, without affecting its normal behaviour.
> 
> generic
> 
> > Hence, define them NULL and use struct dev_pm_ops type to bind them.
> > 
> > Compile-tested only.
> > 
> > Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
> > ---
> >  drivers/media/pci/cx23885/cx23885-core.c | 16 ++++++++++------
> >  1 file changed, 10 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/media/pci/cx23885/cx23885-core.c b/drivers/media/pci/cx23885/cx23885-core.c
> > index 7e0b0b7cc2a3..da9ee7270dfd 100644
> > --- a/drivers/media/pci/cx23885/cx23885-core.c
> > +++ b/drivers/media/pci/cx23885/cx23885-core.c
> > @@ -2230,14 +2230,18 @@ static const struct pci_device_id cx23885_pci_tbl[] = {
> >  };
> >  MODULE_DEVICE_TABLE(pci, cx23885_pci_tbl);
> >  
> > +#define cx23885_suspend NULL
> > +#define cx23885_resume NULL
> > +
> > +static SIMPLE_DEV_PM_OPS(cx23885_pm_ops, cx23885_suspend, cx23885_resume);
> > +
> >  static struct pci_driver cx23885_pci_driver = {
> > -	.name     = "cx23885",
> > -	.id_table = cx23885_pci_tbl,
> > -	.probe    = cx23885_initdev,
> > -	.remove   = cx23885_finidev,
> > +	.name      = "cx23885",
> > +	.id_table  = cx23885_pci_tbl,
> > +	.probe     = cx23885_initdev,
> > +	.remove    = cx23885_finidev,
> >  	/* TODO */
> > -	.suspend  = NULL,
> > -	.resume   = NULL,
> > +	.driver.pm = &cx23885_pm_ops,
> 
> I don't entirely understand this. Wouldn't it be sufficient to just
> drop the .suspend/.resume assignments here? It is now required for
> driver.pm to be non-NULL?
> 
> I'm not up to speed on the changes, but normally you can leave things
> NULL if you don't support a feature (PM in this case).

I think this patch will break things.  Previously, we had:

  cx23885_pci_driver.suspend == NULL
  cx23885_pci_driver.resume == NULL
  cx23885_pci_driver.driver.pm == NULL

pci_pm_suspend() looks like:

  if (pci_has_legacy_pm_support(pci_dev))
    return pci_legacy_suspend(dev, PMSG_SUSPEND);

  if (!pm) {
    pci_pm_default_suspend(pci_dev);
    return 0;
  }

pci_has_legacy_pm_support() was false since drv->suspend and
drv->resume are both NULL, so we'd take the pci_pm_default_suspend()
path.  After this patch, driver.pm would no longer be NULL, so we'd
take a different path that is clearly not equivalent.

I think you should do this:

  - 	/* TODO */
  -	.suspend  = NULL,
  -	.resume   = NULL,

and leave .driver.pm NULL by not mentioning it at all.  That should be
identical at the object code level since those are the defaults
anyway.

That almost looks like useless churn, but the point of this patch is
to remove use of PCI legacy PM (pci_driver.suspend and .resume) so we
can completely remove that infrastructure from the PCI core, including
the .suspend and .resume members of struct pci_driver, so we really do
need to do it.

Bjorn
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH v1 2/6] [media] cx23885: use generic power management
  2020-07-14  0:38     ` Bjorn Helgaas
@ 2020-07-14 10:52       ` Vaibhav Gupta
  0 siblings, 0 replies; 11+ messages in thread
From: Vaibhav Gupta @ 2020-07-14 10:52 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Vaibhav Gupta, linux-kernel, Bjorn Helgaas,
	Mauro Carvalho Chehab, linux-kernel-mentees, linux-media

On Mon, Jul 13, 2020 at 07:38:14PM -0500, Bjorn Helgaas wrote:
> On Mon, Jul 13, 2020 at 12:01:51PM +0200, Hans Verkuil wrote:
> > On 29/06/2020 09:36, Vaibhav Gupta wrote:
> > 
> > I don't entirely understand this. Wouldn't it be sufficient to just
> > drop the .suspend/.resume assignments here? It is now required for
> > driver.pm to be non-NULL?
> > 
> > I'm not up to speed on the changes, but normally you can leave things
> > NULL if you don't support a feature (PM in this case).
> 
> I think this patch will break things.  Previously, we had:
> 
>   cx23885_pci_driver.suspend == NULL
>   cx23885_pci_driver.resume == NULL
>   cx23885_pci_driver.driver.pm == NULL
> 
> pci_pm_suspend() looks like:
> 
>   if (pci_has_legacy_pm_support(pci_dev))
>     return pci_legacy_suspend(dev, PMSG_SUSPEND);
> 
>   if (!pm) {
>     pci_pm_default_suspend(pci_dev);
>     return 0;
>   }
> 
> pci_has_legacy_pm_support() was false since drv->suspend and
> drv->resume are both NULL, so we'd take the pci_pm_default_suspend()
> path.  After this patch, driver.pm would no longer be NULL, so we'd
> take a different path that is clearly not equivalent.
> 
> I think you should do this:
> 
>   - 	/* TODO */
>   -	.suspend  = NULL,
>   -	.resume   = NULL,
> 
> and leave .driver.pm NULL by not mentioning it at all.  That should be
> identical at the object code level since those are the defaults
> anyway.
> 
> That almost looks like useless churn, but the point of this patch is
> to remove use of PCI legacy PM (pci_driver.suspend and .resume) so we
> can completely remove that infrastructure from the PCI core, including
> the .suspend and .resume members of struct pci_driver, so we really do
> need to do it.
Okay!

Thanks!
-- Vaibhav Gupta
> 
> Bjorn
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-07-14 10:54 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-29  7:35 [Linux-kernel-mentees] [PATCH v1 0/6] [media] pci: use generic power management Vaibhav Gupta
2020-06-29  7:35 ` [Linux-kernel-mentees] [PATCH v1 1/6] [media] sta2x11: " Vaibhav Gupta
2020-06-29  7:36 ` [Linux-kernel-mentees] [PATCH v1 2/6] [media] cx23885: " Vaibhav Gupta
2020-07-13 10:01   ` Hans Verkuil
2020-07-14  0:38     ` Bjorn Helgaas
2020-07-14 10:52       ` Vaibhav Gupta
2020-06-29  7:36 ` [Linux-kernel-mentees] [PATCH v1 3/6] [media] cx25821: " Vaibhav Gupta
2020-07-13 10:03   ` Hans Verkuil
2020-06-29  7:36 ` [Linux-kernel-mentees] [PATCH v1 4/6] [media] cx88: " Vaibhav Gupta
2020-06-29  7:36 ` [Linux-kernel-mentees] [PATCH v1 5/6] [media] meye: " Vaibhav Gupta
2020-06-29  7:36 ` [Linux-kernel-mentees] [PATCH v1 6/6] [media] tw68: " Vaibhav Gupta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).