From: Vaibhav Gupta <vaibhavgupta40@gmail.com>
To: Bjorn Helgaas <helgaas@kernel.org>,
Bjorn Helgaas <bhelgaas@google.com>,
Bjorn Helgaas <bjorn@helgaas.com>,
Vaibhav Gupta <vaibhav.varodek@gmail.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Hans Verkuil <hverkuil-cisco@xs4all.nl>
Cc: linux-media@vger.kernel.org,
linux-kernel-mentees@lists.linuxfoundation.org,
linux-kernel@vger.kernel.org,
Vaibhav Gupta <vaibhavgupta40@gmail.com>
Subject: [Linux-kernel-mentees] [PATCH v1] [media] bttv: use generic power management
Date: Tue, 28 Jul 2020 15:54:18 +0530 [thread overview]
Message-ID: <20200728102418.1069512-1-vaibhavgupta40@gmail.com> (raw)
Drivers using legacy power management .suspen()/.resume() callbacks
have to manage PCI states and device's PM states themselves. They also
need to take care of standard configuration registers.
Switch to generic power management framework using a single
"struct dev_pm_ops" variable to take the unnecessary load from the driver.
This also avoids the need for the driver to directly call most of the PCI
helper functions and device power state control functions, as through
the generic framework PCI Core takes care of the necessary operations,
and drivers are required to do only device-specific jobs.
Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
---
drivers/media/pci/bt8xx/bttv-driver.c | 56 ++++++++-------------------
1 file changed, 16 insertions(+), 40 deletions(-)
diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c
index 9144f795fb93..cb8d955d1d5d 100644
--- a/drivers/media/pci/bt8xx/bttv-driver.c
+++ b/drivers/media/pci/bt8xx/bttv-driver.c
@@ -4263,15 +4263,14 @@ static void bttv_remove(struct pci_dev *pci_dev)
return;
}
-#ifdef CONFIG_PM
-static int bttv_suspend(struct pci_dev *pci_dev, pm_message_t state)
+static int __maybe_unused bttv_suspend(struct device *dev)
{
- struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
+ struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
struct bttv *btv = to_bttv(v4l2_dev);
struct bttv_buffer_set idle;
unsigned long flags;
- dprintk("%d: suspend %d\n", btv->c.nr, state.event);
+ dprintk("%d: suspend\n", btv->c.nr);
/* stop dma + irqs */
spin_lock_irqsave(&btv->s_lock,flags);
@@ -4291,42 +4290,19 @@ static int bttv_suspend(struct pci_dev *pci_dev, pm_message_t state)
btv->state.gpio_enable = btread(BT848_GPIO_OUT_EN);
btv->state.gpio_data = gpio_read();
- /* save pci state */
- pci_save_state(pci_dev);
- if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) {
- pci_disable_device(pci_dev);
- btv->state.disabled = 1;
- }
+ btv->state.disabled = 1;
return 0;
}
-static int bttv_resume(struct pci_dev *pci_dev)
+static int __maybe_unused bttv_resume(struct device *dev)
{
- struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
+ struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
struct bttv *btv = to_bttv(v4l2_dev);
unsigned long flags;
- int err;
dprintk("%d: resume\n", btv->c.nr);
- /* restore pci state */
- if (btv->state.disabled) {
- err=pci_enable_device(pci_dev);
- if (err) {
- pr_warn("%d: Can't enable device\n", btv->c.nr);
- return err;
- }
- btv->state.disabled = 0;
- }
- err=pci_set_power_state(pci_dev, PCI_D0);
- if (err) {
- pci_disable_device(pci_dev);
- pr_warn("%d: Can't enable device\n", btv->c.nr);
- btv->state.disabled = 1;
- return err;
- }
-
- pci_restore_state(pci_dev);
+ btv->state.disabled = 0;
/* restore bt878 state */
bttv_reinit_bt848(btv);
@@ -4344,7 +4320,6 @@ static int bttv_resume(struct pci_dev *pci_dev)
spin_unlock_irqrestore(&btv->s_lock,flags);
return 0;
}
-#endif
static const struct pci_device_id bttv_pci_tbl[] = {
{PCI_VDEVICE(BROOKTREE, PCI_DEVICE_ID_BT848), 0},
@@ -4357,15 +4332,16 @@ static const struct pci_device_id bttv_pci_tbl[] = {
MODULE_DEVICE_TABLE(pci, bttv_pci_tbl);
+static SIMPLE_DEV_PM_OPS(bttv_pm_ops,
+ bttv_suspend,
+ bttv_resume);
+
static struct pci_driver bttv_pci_driver = {
- .name = "bttv",
- .id_table = bttv_pci_tbl,
- .probe = bttv_probe,
- .remove = bttv_remove,
-#ifdef CONFIG_PM
- .suspend = bttv_suspend,
- .resume = bttv_resume,
-#endif
+ .name = "bttv",
+ .id_table = bttv_pci_tbl,
+ .probe = bttv_probe,
+ .remove = bttv_remove,
+ .driver.pm = &bttv_pm_ops,
};
static int __init bttv_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
WARNING: multiple messages have this Message-ID (diff)
From: Vaibhav Gupta <vaibhavgupta40@gmail.com>
To: Bjorn Helgaas <helgaas@kernel.org>,
Bjorn Helgaas <bhelgaas@google.com>,
Bjorn Helgaas <bjorn@helgaas.com>,
Vaibhav Gupta <vaibhav.varodek@gmail.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Hans Verkuil <hverkuil-cisco@xs4all.nl>
Cc: Vaibhav Gupta <vaibhavgupta40@gmail.com>,
linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
linux-kernel-mentees@lists.linuxfoundation.org,
Shuah Khan <skhan@linuxfoundation.org>
Subject: [PATCH v1] [media] bttv: use generic power management
Date: Tue, 28 Jul 2020 15:54:18 +0530 [thread overview]
Message-ID: <20200728102418.1069512-1-vaibhavgupta40@gmail.com> (raw)
Drivers using legacy power management .suspen()/.resume() callbacks
have to manage PCI states and device's PM states themselves. They also
need to take care of standard configuration registers.
Switch to generic power management framework using a single
"struct dev_pm_ops" variable to take the unnecessary load from the driver.
This also avoids the need for the driver to directly call most of the PCI
helper functions and device power state control functions, as through
the generic framework PCI Core takes care of the necessary operations,
and drivers are required to do only device-specific jobs.
Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
---
drivers/media/pci/bt8xx/bttv-driver.c | 56 ++++++++-------------------
1 file changed, 16 insertions(+), 40 deletions(-)
diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c
index 9144f795fb93..cb8d955d1d5d 100644
--- a/drivers/media/pci/bt8xx/bttv-driver.c
+++ b/drivers/media/pci/bt8xx/bttv-driver.c
@@ -4263,15 +4263,14 @@ static void bttv_remove(struct pci_dev *pci_dev)
return;
}
-#ifdef CONFIG_PM
-static int bttv_suspend(struct pci_dev *pci_dev, pm_message_t state)
+static int __maybe_unused bttv_suspend(struct device *dev)
{
- struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
+ struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
struct bttv *btv = to_bttv(v4l2_dev);
struct bttv_buffer_set idle;
unsigned long flags;
- dprintk("%d: suspend %d\n", btv->c.nr, state.event);
+ dprintk("%d: suspend\n", btv->c.nr);
/* stop dma + irqs */
spin_lock_irqsave(&btv->s_lock,flags);
@@ -4291,42 +4290,19 @@ static int bttv_suspend(struct pci_dev *pci_dev, pm_message_t state)
btv->state.gpio_enable = btread(BT848_GPIO_OUT_EN);
btv->state.gpio_data = gpio_read();
- /* save pci state */
- pci_save_state(pci_dev);
- if (0 != pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state))) {
- pci_disable_device(pci_dev);
- btv->state.disabled = 1;
- }
+ btv->state.disabled = 1;
return 0;
}
-static int bttv_resume(struct pci_dev *pci_dev)
+static int __maybe_unused bttv_resume(struct device *dev)
{
- struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
+ struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
struct bttv *btv = to_bttv(v4l2_dev);
unsigned long flags;
- int err;
dprintk("%d: resume\n", btv->c.nr);
- /* restore pci state */
- if (btv->state.disabled) {
- err=pci_enable_device(pci_dev);
- if (err) {
- pr_warn("%d: Can't enable device\n", btv->c.nr);
- return err;
- }
- btv->state.disabled = 0;
- }
- err=pci_set_power_state(pci_dev, PCI_D0);
- if (err) {
- pci_disable_device(pci_dev);
- pr_warn("%d: Can't enable device\n", btv->c.nr);
- btv->state.disabled = 1;
- return err;
- }
-
- pci_restore_state(pci_dev);
+ btv->state.disabled = 0;
/* restore bt878 state */
bttv_reinit_bt848(btv);
@@ -4344,7 +4320,6 @@ static int bttv_resume(struct pci_dev *pci_dev)
spin_unlock_irqrestore(&btv->s_lock,flags);
return 0;
}
-#endif
static const struct pci_device_id bttv_pci_tbl[] = {
{PCI_VDEVICE(BROOKTREE, PCI_DEVICE_ID_BT848), 0},
@@ -4357,15 +4332,16 @@ static const struct pci_device_id bttv_pci_tbl[] = {
MODULE_DEVICE_TABLE(pci, bttv_pci_tbl);
+static SIMPLE_DEV_PM_OPS(bttv_pm_ops,
+ bttv_suspend,
+ bttv_resume);
+
static struct pci_driver bttv_pci_driver = {
- .name = "bttv",
- .id_table = bttv_pci_tbl,
- .probe = bttv_probe,
- .remove = bttv_remove,
-#ifdef CONFIG_PM
- .suspend = bttv_suspend,
- .resume = bttv_resume,
-#endif
+ .name = "bttv",
+ .id_table = bttv_pci_tbl,
+ .probe = bttv_probe,
+ .remove = bttv_remove,
+ .driver.pm = &bttv_pm_ops,
};
static int __init bttv_init_module(void)
--
2.27.0
next reply other threads:[~2020-07-28 10:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-28 10:24 Vaibhav Gupta [this message]
2020-07-28 10:24 ` [PATCH v1] [media] bttv: use generic power management Vaibhav Gupta
2020-07-28 12:38 ` [Linux-kernel-mentees] " Vaibhav Gupta
2020-07-28 12:38 ` Vaibhav Gupta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200728102418.1069512-1-vaibhavgupta40@gmail.com \
--to=vaibhavgupta40@gmail.com \
--cc=bhelgaas@google.com \
--cc=bjorn@helgaas.com \
--cc=helgaas@kernel.org \
--cc=hverkuil-cisco@xs4all.nl \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=vaibhav.varodek@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.