linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wang Hongcheng <annie.wang@amd.com>
To: Vinod Koul <vinod.koul@intel.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Joerg Roedel <joro@8bytes.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-serial@vger.kernel.org, dmaengine@vger.kernel.org,
	iommu@lists.linux-foundation.org, Borislav Petkov <bp@alien8.de>,
	Huang Rui <ray.huang@amd.com>, Wan Zongshun <vincent.wan@amd.com>,
	Ken Xue <ken.xue@amd.com>, Tony Li <tony.li@amd.com>,
	Wang Hongcheng <annie.wang@amd.com>
Subject: [PATCH 1/9] ACPI: Add support for AMBA bus type
Date: Fri, 4 Dec 2015 11:24:18 +0800	[thread overview]
Message-ID: <1449199466-6081-2-git-send-email-annie.wang@amd.com> (raw)
In-Reply-To: <1449199466-6081-1-git-send-email-annie.wang@amd.com>

From: Huang Rui <ray.huang@amd.com>

Inspired by acpi platform bus type, to make driver "porting" more
straightforward, this patch introduces ACPI support to the AMBA bus
type. Instead of writing ACPI "glue" drivers for the exiting AMBA
drivers.

In the subsequent patches, we will use this function to support pl330
AMBA driver.

Signed-off-by: Huang Rui <ray.huang@amd.com>
Signed-off-by: Wang Hongcheng <annie.wang@amd.com>
---
 drivers/acpi/Makefile    |   1 +
 drivers/acpi/acpi_amba.c | 157 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/acpi.h     |  21 +++++++
 3 files changed, 179 insertions(+)
 create mode 100644 drivers/acpi/acpi_amba.c

diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 675eaf3..7d84446 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -42,6 +42,7 @@ acpi-$(CONFIG_ACPI_DOCK)	+= dock.o
 acpi-y				+= pci_root.o pci_link.o pci_irq.o
 acpi-y				+= acpi_lpss.o acpi_apd.o
 acpi-y				+= acpi_platform.o
+acpi-$(CONFIG_ARM_AMBA)		+= acpi_amba.o
 acpi-y				+= acpi_pnp.o
 acpi-y				+= int340x_thermal.o
 acpi-y				+= power.o
diff --git a/drivers/acpi/acpi_amba.c b/drivers/acpi/acpi_amba.c
new file mode 100644
index 0000000..4f0366a
--- /dev/null
+++ b/drivers/acpi/acpi_amba.c
@@ -0,0 +1,157 @@
+/*
+ * ACPI support for AMBA bus type.
+ *
+ * Copyright (C) 2015, Advanced Micro Devices, Inc.
+ * Authors: Huang Rui <ray.huang@amd.com>
+ *          Wang Hongcheng <annie.wang@amd.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/acpi.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/dma-mapping.h>
+#include <linux/amba/bus.h>
+#include <linux/clk-provider.h>
+#include <linux/clkdev.h>
+#include <linux/clk.h>
+
+#include "internal.h"
+
+ACPI_MODULE_NAME("amba");
+
+/**
+ * acpi_create_amba_device - Create AMBA device for ACPI device node.
+ * @adev: ACPI device node to create an AMBA device.
+ * @periphid: AMBA device periphid.
+ * @fixed_rate: Clock frequency.
+ * @pdata: Platform data specific to the device.
+ *
+ * Check if the given @adev can be represented as an AMBA device and, if
+ * that's the case, create and register an AMBA device, populate its
+ * common resources and returns a pointer to it.  Otherwise, return
+ * %NULL or ERR_PTR() on error.
+ *
+ * Name of the AMBA device will be the same as @adev's.
+ */
+struct amba_device *acpi_create_amba_device(struct acpi_device *adev,
+					    unsigned int periphid,
+					    unsigned long fixed_rate,
+					    void *pdata)
+{
+	struct amba_device *amba_dev = NULL;
+	struct device *parent;
+	struct acpi_device *acpi_parent;
+	struct resource_entry *rentry;
+	struct list_head resource_list;
+	struct resource *resource = NULL;
+	int count, ret = 0;
+	unsigned int i;
+	unsigned int irq[AMBA_NR_IRQS];
+	struct clk *clk = ERR_PTR(-ENODEV);
+
+	/*
+	 * If the ACPI node already has a physical device attached,
+	 * skip it.
+	 */
+	if (adev->physical_node_count)
+		return NULL;
+
+	INIT_LIST_HEAD(&resource_list);
+	count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
+	if (count <= 0)
+		return NULL;
+
+	resource = kzalloc(sizeof(*resource), GFP_KERNEL);
+	if (!resource)
+		goto resource_alloc_err;
+
+	count = 0;
+	list_for_each_entry(rentry, &resource_list, node) {
+		if (resource_type(rentry->res) == IORESOURCE_IRQ) {
+			irq[count] = rentry->res->start;
+			count++;
+		}
+		/*
+		 * there is only one io memory resource entry
+		 * at current AMBA device design
+		 */
+		if (resource_type(rentry->res) | IORESOURCE_MEM)
+			memcpy(resource, rentry->res, sizeof(struct resource));
+	}
+
+	amba_dev = amba_device_alloc(dev_name(&adev->dev),
+				     resource->start,
+				     resource_size(resource));
+
+	if (!amba_dev)
+		goto amba_alloc_err;
+
+	amba_dev->dev.coherent_dma_mask = acpi_dma_supported(adev) ? DMA_BIT_MASK(64) : 0;
+	amba_dev->dev.platform_data = pdata;
+	amba_dev->dev.fwnode = acpi_fwnode_handle(adev);
+
+	/*
+	 * If the ACPI node has a parent and that parent has a
+	 * physical device attached to it, that physical device should
+	 * be the parent of the AMBA device we are about to create.
+	 */
+	parent = NULL;
+	acpi_parent = adev->parent;
+	if (acpi_parent) {
+		struct acpi_device_physical_node *entry;
+		struct list_head *list;
+
+		mutex_lock(&acpi_parent->physical_node_lock);
+		list = &acpi_parent->physical_node_list;
+		if (!list_empty(list)) {
+			entry = list_first_entry(list, struct acpi_device_physical_node, node);
+			parent = entry->dev;
+		}
+		mutex_unlock(&acpi_parent->physical_node_lock);
+	}
+
+	amba_dev->dev.parent = parent;
+	amba_dev->periphid = periphid;
+
+	WARN_ON_ONCE(count > AMBA_NR_IRQS);
+
+	for (i = 0; i < count; i++)
+		amba_dev->irq[i] = irq[i];
+
+	clk = clk_register_fixed_rate(&amba_dev->dev,
+				      dev_name(&amba_dev->dev),
+				      NULL, CLK_IS_ROOT,
+				      fixed_rate);
+	if (IS_ERR_OR_NULL(clk))
+		goto amba_register_err;
+
+	ret = clk_register_clkdev(clk, "apb_pclk",
+				  dev_name(&amba_dev->dev));
+	if (ret)
+		goto amba_register_err;
+
+	ret = amba_device_add(amba_dev, resource);
+	if (ret)
+		goto amba_register_err;
+
+	acpi_dev_free_resource_list(&resource_list);
+	kfree(resource);
+	return amba_dev;
+
+amba_register_err:
+	amba_device_put(amba_dev);
+
+amba_alloc_err:
+	kfree(resource);
+
+resource_alloc_err:
+	acpi_dev_free_resource_list(&resource_list);
+
+	return ERR_PTR(ret);
+}
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 0548339..04827d8 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -37,6 +37,7 @@
 #include <linux/list.h>
 #include <linux/mod_devicetable.h>
 #include <linux/dynamic_debug.h>
+#include <linux/amba/bus.h>
 
 #include <acpi/acpi_bus.h>
 #include <acpi/acpi_drivers.h>
@@ -466,6 +467,26 @@ int acpi_device_modalias(struct device *, char *, int);
 void acpi_walk_dep_device_list(acpi_handle handle);
 
 struct platform_device *acpi_create_platform_device(struct acpi_device *);
+
+#ifdef CONFIG_ARM_AMBA
+
+struct amba_device *acpi_create_amba_device(struct acpi_device *adev,
+					    unsigned int periphid,
+					    unsigned long fixed_rate,
+					    void *pdata);
+
+#else /* !CONFIG_ARM_AMBA */
+
+static inline struct amba_device *acpi_create_amba_device(struct acpi_device *adev,
+							  unsigned int periphid,
+							  unsigned long fixed_rate,
+							  void *pdata)
+{
+	return NULL;
+}
+
+#endif
+
 #define ACPI_PTR(_ptr)	(_ptr)
 
 #else	/* !CONFIG_ACPI */
-- 
1.9.1


  reply	other threads:[~2015-12-04  3:24 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-04  3:24 [PATCH 0/9] 8250: AMD Carrizo UART PL300 DMA enablement Wang Hongcheng
2015-12-04  3:24 ` Wang Hongcheng [this message]
2015-12-04  8:50   ` [PATCH 1/9] ACPI: Add support for AMBA bus type Mika Westerberg
2015-12-04  9:17     ` Huang Rui
2015-12-04  9:42       ` Hanjun Guo
2015-12-04  9:59         ` G Gregory
2015-12-04 10:20           ` Huang Rui
2015-12-04 10:23             ` G Gregory
2015-12-04  3:24 ` [PATCH 2/9] 8250/Kconfig: add config option CONFIG_SERIAL_8250_AMD Wang Hongcheng
2015-12-04 11:11   ` Borislav Petkov
2015-12-04  3:24 ` [PATCH 3/9] ACPI: add struct acpi_amba_quirk for AMD pl330 specific device config Wang Hongcheng
     [not found]   ` <1449199466-6081-4-git-send-email-annie.wang-5C7GfCeVMHo@public.gmane.org>
2015-12-04 12:56     ` kbuild test robot
2015-12-04 13:16   ` Graeme Gregory
2015-12-11  6:57     ` Wang, Annie
     [not found]       ` <BLUPR12MB04339648B98F07977B6FA61F81EA0-7LeqcoF/hwrdEWIfrEWxYwdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2015-12-11  9:31         ` Vinod Koul
2015-12-04  3:24 ` [PATCH 4/9] dmaengine: pl330: add new items for pl330 private data Wang Hongcheng
2015-12-10  4:09   ` Vinod Koul
2015-12-10  6:38     ` Wang, Annie
     [not found]       ` <BLUPR12MB0433B81BB0AEB2D84505B55881E90-7LeqcoF/hwrdEWIfrEWxYwdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2015-12-11  9:29         ` Vinod Koul
2015-12-11 13:56           ` Andy Shevchenko
2015-12-04  3:24 ` [PATCH 5/9] dmaengine: pl330: provide ACPI dmaengine interface Wang Hongcheng
     [not found]   ` <1449199466-6081-6-git-send-email-annie.wang-5C7GfCeVMHo@public.gmane.org>
2015-12-13  2:21     ` Andy Shevchenko
2015-12-04  3:24 ` [PATCH 6/9] dmaengine:pl330: set segment_boundary_mask = 0cffffffff Wang Hongcheng
2015-12-04 14:59   ` Robin Murphy
2015-12-04  3:24 ` [PATCH 7/9] Serial:8250: New Port Type PORT_AMD_8250 Wang Hongcheng
     [not found]   ` <1449199466-6081-8-git-send-email-annie.wang-5C7GfCeVMHo@public.gmane.org>
2015-12-13  2:30     ` Andy Shevchenko
2015-12-04  3:24 ` [PATCH 8/9] Documentation: Add ivrs_acpihid kernel parameter description Wang Hongcheng
     [not found]   ` <1449199466-6081-9-git-send-email-annie.wang-5C7GfCeVMHo@public.gmane.org>
2015-12-04 12:21     ` Borislav Petkov
2015-12-04 13:19       ` Wan, Vincent
2015-12-04 14:38         ` Borislav Petkov
2015-12-04  3:24 ` [PATCH 9/9] iommu/amd: Add ACPI HID named devices IOMMU driver support Wang Hongcheng
2015-12-13  2:32 ` [PATCH 0/9] 8250: AMD Carrizo UART PL300 DMA enablement Andy Shevchenko

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=1449199466-6081-2-git-send-email-annie.wang@amd.com \
    --to=annie.wang@amd.com \
    --cc=bp@alien8.de \
    --cc=dmaengine@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=ken.xue@amd.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=ray.huang@amd.com \
    --cc=rjw@rjwysocki.net \
    --cc=tony.li@amd.com \
    --cc=vincent.wan@amd.com \
    --cc=vinod.koul@intel.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;
as well as URLs for NNTP newsgroup(s).