mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gabriele Paoloni <gabriele.paoloni@huawei.com>
To: <catalin.marinas@arm.com>, <will.deacon@arm.com>,
	<robh+dt@kernel.org>, <frowand.list@gmail.com>,
	<bhelgaas@google.com>, <rafael@kernel.org>, <arnd@arndb.de>,
	<linux-arm-kernel@lists.infradead.org>,
	<lorenzo.pieralisi@arm.com>
Cc: <gabriele.paoloni@huawei.com>, <mark.rutland@arm.com>,
	<brian.starkey@arm.com>, <olof@lixom.net>,
	<benh@kernel.crashing.org>, <linux-kernel@vger.kernel.org>,
	<linux-acpi@vger.kernel.org>, <linuxarm@huawei.com>,
	<linux-pci@vger.kernel.org>, <minyard@acm.org>,
	<john.garry@huawei.com>, <xuwei5@hisilicon.com>,
	"zhichang.yuan" <yuanzhichang@hisilicon.com>
Subject: [PATCH v10 8/9] LPC: Add the ACPI LPC support
Date: Fri, 27 Oct 2017 17:11:26 +0100	[thread overview]
Message-ID: <1509120687-7352-9-git-send-email-gabriele.paoloni@huawei.com> (raw)
In-Reply-To: <1509120687-7352-1-git-send-email-gabriele.paoloni@huawei.com>

From: "zhichang.yuan" <yuanzhichang@hisilicon.com>

Based on the provious patches, this patch supports the ACPI LPC host on
Hip06/Hip07.

Signed-off-by: zhichang.yuan <yuanzhichang@hisilicon.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Tested-by: dann frazier <dann.frazier@canonical.com>
---
 drivers/acpi/arm64/acpi_indirectio.c |   3 +
 drivers/acpi/arm64/acpi_indirectio.h |   4 +
 drivers/bus/hisi_lpc.c               | 164 +++++++++++++++++++++++++++++++----
 3 files changed, 154 insertions(+), 17 deletions(-)

diff --git a/drivers/acpi/arm64/acpi_indirectio.c b/drivers/acpi/arm64/acpi_indirectio.c
index 013db6f..424f3bd 100644
--- a/drivers/acpi/arm64/acpi_indirectio.c
+++ b/drivers/acpi/arm64/acpi_indirectio.c
@@ -123,6 +123,9 @@ int acpi_set_logicio_resource(struct device *child,
 
 /* All the host devices which apply indirect-IO can be listed here. */
 static const struct acpi_device_id acpi_indirect_host_id[] = {
+#ifdef CONFIG_HISILICON_LPC
+	{"HISI0191", INDIRECT_IO_INFO(lpc_host_desc)},
+#endif
 	{""},
 };
 
diff --git a/drivers/acpi/arm64/acpi_indirectio.h b/drivers/acpi/arm64/acpi_indirectio.h
index 8102ea0..1b18590 100644
--- a/drivers/acpi/arm64/acpi_indirectio.h
+++ b/drivers/acpi/arm64/acpi_indirectio.h
@@ -18,6 +18,10 @@ struct indirectio_device_desc {
 	int (*pre_setup)(struct acpi_device *adev, void *pdata);
 };
 
+#ifdef CONFIG_HISILICON_LPC
+extern const struct indirectio_device_desc lpc_host_desc;
+#endif
+
 int acpi_set_logicio_resource(struct device *child,
 		struct device *hostdev, const struct resource **res,
 		int *num_res);
diff --git a/drivers/bus/hisi_lpc.c b/drivers/bus/hisi_lpc.c
index c885483..26043f7 100644
--- a/drivers/bus/hisi_lpc.c
+++ b/drivers/bus/hisi_lpc.c
@@ -438,7 +438,6 @@ static int hisilpc_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct resource *res;
 	struct hisilpc_dev *lpcdev;
-	struct logic_pio_hwaddr *range;
 	int ret = 0;
 
 	lpcdev = devm_kzalloc(dev, sizeof(struct hisilpc_dev), GFP_KERNEL);
@@ -460,21 +459,32 @@ static int hisilpc_probe(struct platform_device *pdev)
 	}
 
 	/* register the LPC host PIO resources */
-	range = devm_kzalloc(dev, sizeof(*range), GFP_KERNEL);
-	if (!range)
-		return -ENOMEM;
-	range->fwnode = dev->fwnode;
-	range->flags = PIO_INDIRECT;
-	range->size = LPC_BUS_IO_SIZE;
-	range->hw_start = LPC_MIN_BUS_RANGE;
-
-	ret = logic_pio_register_range(range);
-	if (ret) {
-		kfree(range);
-		dev_err(dev, "OF: register IO range FAIL!\n");
-		return -ret;
+	if (has_acpi_companion(dev)) {
+		lpcdev->io_host = find_io_range_by_fwnode(dev->fwnode);
+		if (!lpcdev->io_host) {
+			dev_err(dev, "HiSilicon LPC range not registered!\n");
+			return -EFAULT;
+		}
+	} else {
+		struct logic_pio_hwaddr *range;
+
+		range = devm_kzalloc(dev, sizeof(*range), GFP_KERNEL);
+		if (!range)
+			return -ENOMEM;
+		range->fwnode = dev->fwnode;
+		range->flags = PIO_INDIRECT;
+		range->size = LPC_BUS_IO_SIZE;
+		range->hw_start = LPC_MIN_BUS_RANGE;
+
+		ret = logic_pio_register_range(range);
+		if (ret) {
+			kfree(range);
+			dev_err(dev, "OF: register IO range FAIL!\n");
+			return -ret;
+		}
+		lpcdev->io_host = range;
 	}
-	lpcdev->io_host = range;
+
 	lpcdev->io_host->devpara = lpcdev;
 	lpcdev->io_host->ops = &hisi_lpc_ops;
 
@@ -486,8 +496,11 @@ static int hisilpc_probe(struct platform_device *pdev)
 	 * to avoid some children which complete the scanning trigger the
 	 * MMIO accesses which will probably cause panic.
 	 */
-	dev_info(dev, " calling of_platform_populate");
-	ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
+	if (!has_acpi_companion(dev)) {
+		dev_info(dev, " calling of_platform_populate");
+		ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
+	}
+
 	if (ret) {
 		/*
 		 * When LPC probing is not completely successful, set 'devpara'
@@ -515,10 +528,127 @@ static const struct of_device_id hisilpc_of_match[] = {
 	{},
 };
 
+#ifdef CONFIG_ACPI
+#include "../acpi/arm64/acpi_indirectio.h"
+#include <linux/mfd/core.h>
+
+struct lpc_private_data {
+	resource_size_t io_size;
+	resource_size_t io_start;
+};
+
+static struct lpc_private_data lpc_data = {
+	.io_size = LPC_BUS_IO_SIZE,
+	.io_start = LPC_MIN_BUS_RANGE,
+};
+
+static struct mfd_cell_acpi_match hisi_lpc_ipmi_acpi_match = {
+	.pnpid = "IPI0001",
+};
+
+static const char *hisi_lpc_ipmi_name = "hisi_lpc_ipmi";
+
+static int lpc_host_io_setup(struct acpi_device *adev, void *pdata)
+{
+	int ret;
+	struct platform_device *pdev;
+	struct mfd_cell *ipmi_devs;
+	struct logic_pio_hwaddr *range;
+	struct lpc_private_data *lpc_private;
+	struct acpi_device *child;
+	int ipmi_dev_num = 0;
+
+	lpc_private = pdata;
+	range = kzalloc(sizeof(*range), GFP_KERNEL);
+	if (!range)
+		return -ENOMEM;
+	range->fwnode = &adev->fwnode;
+	range->flags = PIO_INDIRECT;
+	range->size = lpc_private->io_size;
+	range->hw_start = lpc_private->io_start;
+
+	ret = logic_pio_register_range(range);
+	if (ret)
+		goto free_range;
+
+	/* count the ipmi children first */
+	list_for_each_entry(child, &adev->children, node) {
+		if (!strcmp(hisi_lpc_ipmi_acpi_match.pnpid,
+			    acpi_device_hid(child)))
+			ipmi_dev_num++;
+	}
+
+	/* allocate the mfd cells */
+	ipmi_devs = kcalloc(ipmi_dev_num, sizeof(*ipmi_devs), GFP_KERNEL);
+	if (!ipmi_devs) {
+		dev_err(&adev->dev, "ipmi_devs kzalloc failed!\n");
+		ret = -ENOMEM;
+		goto free_range;
+	}
+
+	ipmi_dev_num = 0;
+	/* For hisilpc, only care about the sons of host. */
+	list_for_each_entry(child, &adev->children, node) {
+		if (!strcmp(hisi_lpc_ipmi_acpi_match.pnpid,
+			    acpi_device_hid(child))) {
+			ipmi_devs[ipmi_dev_num].name = hisi_lpc_ipmi_name;
+			ipmi_devs[ipmi_dev_num].acpi_match =
+					&hisi_lpc_ipmi_acpi_match;
+			ret = acpi_set_logicio_resource(&child->dev, &adev->dev,
+					&ipmi_devs[ipmi_dev_num].resources,
+					&ipmi_devs[ipmi_dev_num].num_resources);
+			if (ret) {
+				dev_err(&child->dev, "set resource failed..\n");
+				goto free_ipmi_devs;
+			}
+			ipmi_dev_num++;
+		}
+	}
+
+	pdev = acpi_create_platform_device(adev, NULL);
+	if (IS_ERR_OR_NULL(pdev)) {
+		dev_err(&adev->dev, "Create platform device for host FAIL!\n");
+		ret = -EFAULT;
+		goto free_ipmi_devs;
+	}
+	acpi_device_set_enumerated(adev);
+
+	ret = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE,
+			ipmi_devs, ipmi_dev_num, NULL, 0, NULL);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to add ipmi mfd cell\n");
+		goto free_ipmi_devs;
+	}
+
+	return ret;
+
+free_ipmi_devs:
+	while (ipmi_dev_num--)
+		kfree(ipmi_devs[ipmi_dev_num].resources);
+	kfree(ipmi_devs);
+free_range:
+	kfree(range);
+
+	return ret;
+}
+
+static const struct acpi_device_id hisilpc_acpi_match[] = {
+	{"HISI0191", },
+	{},
+};
+
+const struct indirectio_device_desc lpc_host_desc = {
+	.pdata = &lpc_data,
+	.pre_setup = lpc_host_io_setup,
+};
+
+#endif
+
 static struct platform_driver hisilpc_driver = {
 	.driver = {
 		.name           = "hisi_lpc",
 		.of_match_table = hisilpc_of_match,
+		.acpi_match_table = ACPI_PTR(hisilpc_acpi_match),
 	},
 	.probe = hisilpc_probe,
 };
-- 
2.7.4

  parent reply	other threads:[~2017-10-27 16:15 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-27 16:11 [PATCH v10 0/9] LPC: legacy ISA I/O support Gabriele Paoloni
2017-10-27 16:11 ` [PATCH v10 1/9] LIB: Introduce a generic PIO mapping method Gabriele Paoloni
2017-10-27 18:32   ` Corey Minyard
2017-10-30 15:31     ` Gabriele Paoloni
2017-10-27 16:11 ` [PATCH v10 2/9] PCI: remove unused __weak attribute in pci_register_io_range() Gabriele Paoloni
2017-11-07  0:23   ` Bjorn Helgaas
2017-11-07 10:50     ` Gabriele Paoloni
2017-11-07  0:25   ` Bjorn Helgaas
2017-11-07 10:50     ` Gabriele Paoloni
2017-10-27 16:11 ` [PATCH v10 3/9] PCI: add fwnode handler as input param of pci_register_io_range() Gabriele Paoloni
2017-10-27 16:11 ` [PATCH v10 4/9] PCI: Apply the new generic I/O management on PCI IO hosts Gabriele Paoloni
2017-10-27 16:11 ` [PATCH v10 5/9] OF: Add missing I/O range exception for indirect-IO devices Gabriele Paoloni
2017-10-27 16:11 ` [PATCH v10 6/9] LPC: Support the LPC host on Hip06/Hip07 with DT bindings Gabriele Paoloni
2017-10-27 16:44   ` Randy Dunlap
2017-10-30 15:55     ` Gabriele Paoloni
2017-11-09  0:46   ` dann frazier
2017-11-09 10:05     ` Gabriele Paoloni
2017-10-27 16:11 ` [PATCH v10 7/9] ACPI: Translate the I/O range of non-MMIO devices before scanning Gabriele Paoloni
2017-10-27 16:11 ` Gabriele Paoloni [this message]
2017-10-27 16:11 ` [PATCH v10 9/9] MANTAINERS: Add maintainer for HiSilicon LPC driver Gabriele Paoloni
2017-11-07  0:21   ` Bjorn Helgaas
2017-11-07 10:49     ` Gabriele Paoloni
2017-10-27 16:45 ` [PATCH v10 0/9] LPC: legacy ISA I/O support David Laight
2017-10-30 11:32   ` Gabriele Paoloni
2017-11-09 16:16 ` dann frazier
2017-11-09 16:18   ` Gabriele Paoloni

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=1509120687-7352-9-git-send-email-gabriele.paoloni@huawei.com \
    --to=gabriele.paoloni@huawei.com \
    --cc=arnd@arndb.de \
    --cc=benh@kernel.crashing.org \
    --cc=bhelgaas@google.com \
    --cc=brian.starkey@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=frowand.list@gmail.com \
    --cc=john.garry@huawei.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=mark.rutland@arm.com \
    --cc=minyard@acm.org \
    --cc=olof@lixom.net \
    --cc=rafael@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=will.deacon@arm.com \
    --cc=xuwei5@hisilicon.com \
    --cc=yuanzhichang@hisilicon.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®