From patchwork Thu Oct 26 13:28:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeffy Chen X-Patchwork-Id: 10028183 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5AADB60381 for ; Thu, 26 Oct 2017 13:29:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E32E22376 for ; Thu, 26 Oct 2017 13:29:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 42D9A26E7B; Thu, 26 Oct 2017 13:29:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 668D022376 for ; Thu, 26 Oct 2017 13:29:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932468AbdJZN3h (ORCPT ); Thu, 26 Oct 2017 09:29:37 -0400 Received: from regular1.263xmail.com ([211.150.99.138]:47883 "EHLO regular1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932464AbdJZN3d (ORCPT ); Thu, 26 Oct 2017 09:29:33 -0400 Received: from jeffy.chen?rock-chips.com (unknown [192.168.167.183]) by regular1.263xmail.com (Postfix) with ESMTP id DB6497908; Thu, 26 Oct 2017 21:29:26 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id 7672533B; Thu, 26 Oct 2017 21:29:25 +0800 (CST) X-RL-SENDER: jeffy.chen@rock-chips.com X-FST-TO: linux-kernel@vger.kernel.org X-SENDER-IP: 103.29.142.67 X-LOGIN-NAME: jeffy.chen@rock-chips.com X-UNIQUE-TAG: <041b219d83855e77129dceeb8877c9ed> X-ATTACHMENT-NUM: 0 X-SENDER: cjf@rock-chips.com X-DNS-TYPE: 0 Received: from localhost (unknown [103.29.142.67]) by smtp.263.net (Postfix) whith ESMTP id 16571UD1WX; Thu, 26 Oct 2017 21:29:29 +0800 (CST) From: Jeffy Chen To: linux-kernel@vger.kernel.org, bhelgaas@google.com Cc: linux-pm@vger.kernel.org, tony@atomide.com, shawn.lin@rock-chips.com, briannorris@chromium.org, rjw@rjwysocki.net, dianders@chromium.org, Jeffy Chen , linux-pci@vger.kernel.org Subject: [RFC PATCH v8 5/7] PCI: Make pci_platform_pm_ops's callbacks optional Date: Thu, 26 Oct 2017 21:28:38 +0800 Message-Id: <20171026132840.20946-6-jeffy.chen@rock-chips.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171026132840.20946-1-jeffy.chen@rock-chips.com> References: <20171026132840.20946-1-jeffy.chen@rock-chips.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Allow platforms not to provide some of the pci_platform_pm_ops's callbacks. Also change the return value -ENOSYS to -ENODEV for: warning: drivers/pci/pci.c,594: ENOSYS means 'invalid syscall nr' and nothing else Signed-off-by: Jeffy Chen --- Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v3: None Changes in v2: None drivers/pci/pci.c | 38 +++++++++++++++++++++++++------------- drivers/pci/pci.h | 5 +---- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index f0d68066c726..e120b00a9017 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -572,46 +572,58 @@ static void pci_restore_bars(struct pci_dev *dev) static const struct pci_platform_pm_ops *pci_platform_pm; -int pci_set_platform_pm(const struct pci_platform_pm_ops *ops) +void pci_set_platform_pm(const struct pci_platform_pm_ops *ops) { - if (!ops->is_manageable || !ops->set_state || !ops->get_state || - !ops->choose_state || !ops->set_wakeup || !ops->need_resume) - return -EINVAL; pci_platform_pm = ops; - return 0; } static inline bool platform_pci_power_manageable(struct pci_dev *dev) { - return pci_platform_pm ? pci_platform_pm->is_manageable(dev) : false; + if (pci_platform_pm && pci_platform_pm->is_manageable) + return pci_platform_pm->is_manageable(dev); + + return false; } static inline int platform_pci_set_power_state(struct pci_dev *dev, pci_power_t t) { - return pci_platform_pm ? pci_platform_pm->set_state(dev, t) : -ENOSYS; + if (pci_platform_pm && pci_platform_pm->set_state) + return pci_platform_pm->set_state(dev, t); + + return -ENODEV; } static inline pci_power_t platform_pci_get_power_state(struct pci_dev *dev) { - return pci_platform_pm ? pci_platform_pm->get_state(dev) : PCI_UNKNOWN; + if (pci_platform_pm && pci_platform_pm->get_state) + return pci_platform_pm->get_state(dev); + + return PCI_UNKNOWN; } static inline pci_power_t platform_pci_choose_state(struct pci_dev *dev) { - return pci_platform_pm ? - pci_platform_pm->choose_state(dev) : PCI_POWER_ERROR; + if (pci_platform_pm && pci_platform_pm->choose_state) + return pci_platform_pm->choose_state(dev); + + return PCI_POWER_ERROR; } static inline int platform_pci_set_wakeup(struct pci_dev *dev, bool enable) { - return pci_platform_pm ? - pci_platform_pm->set_wakeup(dev, enable) : -ENODEV; + if (pci_platform_pm && pci_platform_pm->set_wakeup) + return pci_platform_pm->set_wakeup(dev, enable); + + return -ENODEV; } static inline bool platform_pci_need_resume(struct pci_dev *dev) { - return pci_platform_pm ? pci_platform_pm->need_resume(dev) : false; + if (pci_platform_pm && pci_platform_pm->need_resume) + return pci_platform_pm->need_resume(dev); + + return false; } /** diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index e816a13e6259..048668271014 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -52,9 +52,6 @@ int pci_probe_reset_function(struct pci_dev *dev); * @need_resume: returns 'true' if the given device (which is currently * suspended) needs to be resumed to be configured for system * wakeup. - * - * If given platform is generally capable of power managing PCI devices, all of - * these callbacks are mandatory. */ struct pci_platform_pm_ops { bool (*is_manageable)(struct pci_dev *dev); @@ -65,7 +62,7 @@ struct pci_platform_pm_ops { bool (*need_resume)(struct pci_dev *dev); }; -int pci_set_platform_pm(const struct pci_platform_pm_ops *ops); +void pci_set_platform_pm(const struct pci_platform_pm_ops *ops); void pci_update_current_state(struct pci_dev *dev, pci_power_t state); void pci_power_up(struct pci_dev *dev); void pci_disable_enabled_device(struct pci_dev *dev);