{"id":831130,"url":"http://patchwork.ozlabs.org/api/1.2/patches/831130/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/patch/20171027072612.26565-8-jeffy.chen@rock-chips.com/","project":{"id":28,"url":"http://patchwork.ozlabs.org/api/1.2/projects/28/?format=json","name":"Linux PCI development","link_name":"linux-pci","list_id":"linux-pci.vger.kernel.org","list_email":"linux-pci@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20171027072612.26565-8-jeffy.chen@rock-chips.com>","list_archive_url":null,"date":"2017-10-27T07:26:12","name":"[RFC,v10,7/7] PCI / PM: Add support for the PCIe WAKE# signal for OF","commit_ref":null,"pull_url":null,"state":"not-applicable","archived":false,"hash":"93be0f2776661d1573fbe3c016fc6cb9733b9478","submitter":{"id":67754,"url":"http://patchwork.ozlabs.org/api/1.2/people/67754/?format=json","name":"Jeffy Chen","email":"jeffy.chen@rock-chips.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-pci/patch/20171027072612.26565-8-jeffy.chen@rock-chips.com/mbox/","series":[{"id":10523,"url":"http://patchwork.ozlabs.org/api/1.2/series/10523/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-pci/list/?series=10523","date":"2017-10-27T07:26:06","name":"PCI: rockchip: Move PCIe WAKE# handling into pci core","version":10,"mbox":"http://patchwork.ozlabs.org/series/10523/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/831130/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/831130/checks/","tags":{},"related":[],"headers":{"Return-Path":"<linux-pci-owner@vger.kernel.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=linux-pci-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3yNb7p3yk8z9t2x\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 27 Oct 2017 18:28:06 +1100 (AEDT)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1752278AbdJ0H1v (ORCPT <rfc822;incoming@patchwork.ozlabs.org>);\n\tFri, 27 Oct 2017 03:27:51 -0400","from regular1.263xmail.com ([211.150.99.130]:45154 \"EHLO\n\tregular1.263xmail.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1752213AbdJ0H1b (ORCPT\n\t<rfc822; linux-pci@vger.kernel.org>); Fri, 27 Oct 2017 03:27:31 -0400","from jeffy.chen?rock-chips.com (unknown [192.168.167.228])\n\tby regular1.263xmail.com (Postfix) with ESMTP id AD229B23F;\n\tFri, 27 Oct 2017 15:27:27 +0800 (CST)","from localhost (localhost [127.0.0.1])\n\tby smtp.263.net (Postfix) with ESMTPA id 7801C3C3;\n\tFri, 27 Oct 2017 15:27:24 +0800 (CST)","from localhost (unknown [103.29.142.67])\n\tby smtp.263.net (Postfix) whith ESMTP id 10507LW0K2A;\n\tFri, 27 Oct 2017 15:27:27 +0800 (CST)"],"X-263anti-spam":"KSV:0;","X-MAIL-GRAY":"0","X-MAIL-DELIVERY":"1","X-KSVirus-check":"0","X-ABS-CHECKED":"4","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":"<461e159ed8b17613307189c7f4772576>","X-ATTACHMENT-NUM":"0","X-SENDER":"cjf@rock-chips.com","X-DNS-TYPE":"0","From":"Jeffy Chen <jeffy.chen@rock-chips.com>","To":"linux-kernel@vger.kernel.org, bhelgaas@google.com","Cc":"linux-pm@vger.kernel.org, tony@atomide.com,\n\tshawn.lin@rock-chips.com, briannorris@chromium.org,\n\trjw@rjwysocki.net, dianders@chromium.org,\n\tJeffy Chen <jeffy.chen@rock-chips.com>, linux-pci@vger.kernel.org","Subject":"[RFC PATCH v10 7/7] PCI / PM: Add support for the PCIe WAKE# signal\n\tfor OF","Date":"Fri, 27 Oct 2017 15:26:12 +0800","Message-Id":"<20171027072612.26565-8-jeffy.chen@rock-chips.com>","X-Mailer":"git-send-email 2.11.0","In-Reply-To":"<20171027072612.26565-1-jeffy.chen@rock-chips.com>","References":"<20171027072612.26565-1-jeffy.chen@rock-chips.com>","Sender":"linux-pci-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<linux-pci.vger.kernel.org>","X-Mailing-List":"linux-pci@vger.kernel.org"},"content":"Add pci-of.c to handle the PCIe WAKE# interrupt.\n\nAlso use the dedicated wakeirq infrastructure to simplify it.\n\nSigned-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>\n---\n\nChanges in v10:\nUse device_set_wakeup_capable() instead of device_set_wakeup_enable(),\nsince dedicated wakeirq will be lost in device_set_wakeup_enable(false).\n\nChanges in v9:\nFix check error in .cleanup().\nMove dedicated wakeirq setup to setup() callback and use\ndevice_set_wakeup_enable() to enable/disable.\n\nChanges in v8:\nAdd pci-of.c and use platform_pm_ops to handle the PCIe WAKE# signal.\n\nChanges in v7:\nMove PCIE_WAKE handling into pci core.\n\nChanges in v6:\nFix device_init_wake error handling, and add some comments.\n\nChanges in v5:\nRebase.\n\nChanges in v3:\nFix error handling.\n\nChanges in v2:\nUse dev_pm_set_dedicated_wake_irq.\n\n drivers/pci/Makefile |   2 +-\n drivers/pci/pci-of.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 128 insertions(+), 1 deletion(-)\n create mode 100644 drivers/pci/pci-of.c","diff":"diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile\nindex 66a21acad952..4f76dbdb024c 100644\n--- a/drivers/pci/Makefile\n+++ b/drivers/pci/Makefile\n@@ -49,7 +49,7 @@ obj-$(CONFIG_PCI_ECAM) += ecam.o\n \n obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o\n \n-obj-$(CONFIG_OF) += of.o\n+obj-$(CONFIG_OF) += of.o pci-of.o\n \n ccflags-$(CONFIG_PCI_DEBUG) := -DDEBUG\n \ndiff --git a/drivers/pci/pci-of.c b/drivers/pci/pci-of.c\nnew file mode 100644\nindex 000000000000..28f3c4a0eec8\n--- /dev/null\n+++ b/drivers/pci/pci-of.c\n@@ -0,0 +1,127 @@\n+/*\n+ * OF PCI PM support\n+ *\n+ * Copyright (c) 2017 Rockchip, Inc.\n+ *\n+ * Author: Jeffy Chen <jeffy.chen@rock-chips.com>\n+ *\n+ * This program is free software: you can redistribute it and/or modify\n+ * it under the terms of the GNU General Public License as published by\n+ * the Free Software Foundation, either version 2 of the License, or\n+ * (at your option) any later version.\n+ */\n+\n+#include <linux/init.h>\n+#include <linux/of_irq.h>\n+#include <linux/pci.h>\n+#include <linux/pm_wakeirq.h>\n+#include \"pci.h\"\n+\n+struct of_pci_pm_data {\n+\tstruct device\t*dev;\n+\tunsigned int\twakeup_irq;\n+\tatomic_t\twakeup_cnt;\n+};\n+\n+static void *of_pci_setup(struct device *dev)\n+{\n+\tstruct of_pci_pm_data *data;\n+\tint irq, ret;\n+\n+\tif (!dev->of_node)\n+\t\treturn NULL;\n+\n+\tdata = devm_kzalloc(dev, sizeof(struct of_pci_pm_data), GFP_KERNEL);\n+\tif (!data)\n+\t\treturn ERR_PTR(-ENOMEM);\n+\n+\tirq = of_irq_get_byname(dev->of_node, \"wakeup\");\n+\tif (irq < 0) {\n+\t\tif (irq == -EPROBE_DEFER)\n+\t\t\treturn ERR_PTR(irq);\n+\n+\t\treturn NULL;\n+\t}\n+\n+\tdata->wakeup_irq = irq;\n+\tdata->dev = dev;\n+\n+\tdevice_init_wakeup(dev, true);\n+\tret = dev_pm_set_dedicated_wake_irq(dev, irq);\n+\tif (ret < 0) {\n+\t\tdevice_init_wakeup(dev, false);\n+\t\treturn NULL;\n+\t}\n+\tdevice_set_wakeup_capable(dev, false);\n+\n+\tdev_info(dev, \"Wakeup IRQ %d\\n\", irq);\n+\treturn data;\n+}\n+\n+static void *of_pci_setup_dev(struct pci_dev *pci_dev)\n+{\n+\treturn of_pci_setup(&pci_dev->dev);\n+}\n+\n+static void *of_pci_setup_host_bridge(struct pci_host_bridge *bridge)\n+{\n+\treturn of_pci_setup(bridge->dev.parent);\n+}\n+\n+static void of_pci_cleanup(void *pmdata)\n+{\n+\tstruct of_pci_pm_data *data = pmdata;\n+\n+\tif (!IS_ERR_OR_NULL(data)) {\n+\t\tdevice_init_wakeup(data->dev, false);\n+\t\tdev_pm_clear_wake_irq(data->dev);\n+\t}\n+}\n+\n+static bool of_pci_can_wakeup(void *pmdata)\n+{\n+\tstruct of_pci_pm_data *data = pmdata;\n+\n+\tif (IS_ERR_OR_NULL(data))\n+\t\treturn false;\n+\n+\treturn data->wakeup_irq > 0;\n+}\n+\n+static int of_pci_dev_wakeup(void *pmdata, bool enable)\n+{\n+\tstruct of_pci_pm_data *data = pmdata;\n+\tstruct device *dev = data->dev;\n+\n+\tdevice_set_wakeup_capable(dev, enable);\n+\treturn 0;\n+}\n+\n+static int of_pci_bridge_wakeup(void *pmdata, bool enable)\n+{\n+\tstruct of_pci_pm_data *data = pmdata;\n+\n+\tif (enable && atomic_inc_return(&data->wakeup_cnt) != 1)\n+\t\treturn 0;\n+\n+\tif (!enable && atomic_dec_return(&data->wakeup_cnt) != 0)\n+\t\treturn 0;\n+\n+\treturn of_pci_dev_wakeup(pmdata, enable);\n+}\n+\n+static const struct pci_platform_pm_ops of_pci_platform_pm = {\n+\t.setup_dev\t\t= of_pci_setup_dev,\n+\t.setup_host_bridge\t= of_pci_setup_host_bridge,\n+\t.cleanup\t\t= of_pci_cleanup,\n+\t.can_wakeup\t\t= of_pci_can_wakeup,\n+\t.dev_wakeup\t\t= of_pci_dev_wakeup,\n+\t.bridge_wakeup\t\t= of_pci_bridge_wakeup,\n+};\n+\n+static int __init of_pci_init(void)\n+{\n+\tpci_set_platform_pm(&of_pci_platform_pm);\n+\treturn 0;\n+}\n+arch_initcall(of_pci_init);\n","prefixes":["RFC","v10","7/7"]}