From: Chen Feng <puck.chen@hisilicon.com>
To: <gregkh@linuxfoundation.org>, <arve@android.com>,
<riandrews@android.com>, <tranmanphong@gmail.com>,
<mitchelh@codeaurora.org>, <tapaswenipathak@gmail.com>,
<sumit.semwal@linaro.org>, <paul.gortmaker@windriver.com>,
<gioh.kim@lge.com>, <devel@driverdev.osuosl.org>,
<linux-kernel@vger.kernel.org>, <puck.chen@hisilicon.com>,
<yudongbin@hisilicon.com>, <saberlily.xia@hisilicon.com>,
<suzhuangluan@hisilicon.com>, <kong.kongxinwei@hisilicon.com>,
<xuyiping@hisilicon.com>, <z.liuxinliang@hisilicon.com>,
<weidong2@hisilicon.com>, <w.f@huawei.com>,
<dan.carpenter@oracle.com>
Cc: <qijiwen@hisilicon.com>, <peter.panshilin@hisilicon.com>,
<dan.zhao@hisilicon.com>, <linuxarm@huawei.com>
Subject: [PATCH V1 2/3] taging: android: ion: Add ion driver for Hi6220 SoC platform
Date: Sat, 10 Oct 2015 14:48:22 +0800 [thread overview]
Message-ID: <1444459703-183909-2-git-send-email-puck.chen@hisilicon.com> (raw)
In-Reply-To: <1444459703-183909-1-git-send-email-puck.chen@hisilicon.com>
Add ion support for hi6220 SoC platform.
Signed-off-by: Chen Feng <puck.chen@hisilicon.com>
Signed-off-by: Yu Dongbin <yudongbin@hisilicon.com>
---
drivers/staging/android/ion/Kconfig | 7 +
drivers/staging/android/ion/Makefile | 1 +
drivers/staging/android/ion/hisilicon/Kconfig | 5 +
drivers/staging/android/ion/hisilicon/Makefile | 1 +
drivers/staging/android/ion/hisilicon/hi6220_ion.c | 204 +++++++++++++++++++++
5 files changed, 218 insertions(+)
create mode 100644 drivers/staging/android/ion/hisilicon/Kconfig
create mode 100644 drivers/staging/android/ion/hisilicon/Makefile
create mode 100644 drivers/staging/android/ion/hisilicon/hi6220_ion.c
diff --git a/drivers/staging/android/ion/Kconfig b/drivers/staging/android/ion/Kconfig
index 3452346..19c1572 100644
--- a/drivers/staging/android/ion/Kconfig
+++ b/drivers/staging/android/ion/Kconfig
@@ -33,3 +33,10 @@ config ION_TEGRA
help
Choose this option if you wish to use ion on an nVidia Tegra.
+config ION_HISI
+ tristate "Ion for Hisilicon"
+ depends on ARCH_HISI && ION
+ help
+ Choose this option if you wish to use ion on Hisilicon Platform.
+
+source "drivers/staging/android/ion/hisilicon/Kconfig"
diff --git a/drivers/staging/android/ion/Makefile b/drivers/staging/android/ion/Makefile
index b56fd2b..18cc2aa 100644
--- a/drivers/staging/android/ion/Makefile
+++ b/drivers/staging/android/ion/Makefile
@@ -7,4 +7,5 @@ endif
obj-$(CONFIG_ION_DUMMY) += ion_dummy_driver.o
obj-$(CONFIG_ION_TEGRA) += tegra/
+obj-$(CONFIG_ION_HISI) += hisilicon/
diff --git a/drivers/staging/android/ion/hisilicon/Kconfig b/drivers/staging/android/ion/hisilicon/Kconfig
new file mode 100644
index 0000000..2b4bd07
--- /dev/null
+++ b/drivers/staging/android/ion/hisilicon/Kconfig
@@ -0,0 +1,5 @@
+config HI6220_ION
+ bool "Hi6220 ION Driver"
+ depends on ARCH_HISI && ION
+ help
+ Build the Hisilicon Hi6220 ion driver.
diff --git a/drivers/staging/android/ion/hisilicon/Makefile b/drivers/staging/android/ion/hisilicon/Makefile
new file mode 100644
index 0000000..2a89414
--- /dev/null
+++ b/drivers/staging/android/ion/hisilicon/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_HI6220_ION) += hi6220_ion.o
diff --git a/drivers/staging/android/ion/hisilicon/hi6220_ion.c b/drivers/staging/android/ion/hisilicon/hi6220_ion.c
new file mode 100644
index 0000000..0e8632a
--- /dev/null
+++ b/drivers/staging/android/ion/hisilicon/hi6220_ion.c
@@ -0,0 +1,204 @@
+#define pr_fmt(fmt) "Ion: " fmt
+
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/mm.h>
+#include "../ion_priv.h"
+#include "../ion.h"
+
+struct hi6220_ion_type_table {
+ const char *name;
+ enum ion_heap_type type;
+};
+
+static struct hi6220_ion_type_table ion_type_table[] = {
+ {"ion_system", ION_HEAP_TYPE_SYSTEM},
+ {"ion_system_contig", ION_HEAP_TYPE_SYSTEM_CONTIG},
+ {"ion_carveout", ION_HEAP_TYPE_CARVEOUT},
+ {"ion_chunk", ION_HEAP_TYPE_CHUNK},
+ {"ion_dma", ION_HEAP_TYPE_DMA},
+ {"ion_custom", ION_HEAP_TYPE_CUSTOM},
+};
+
+static struct ion_device *idev;
+static int num_heaps;
+static struct ion_heap **heaps;
+static struct ion_platform_heap **heaps_data;
+
+static int get_type_by_name(const char *name, enum ion_heap_type *type)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(ion_type_table); i++) {
+ if (strncmp(name, ion_type_table[i].name, strlen(name)))
+ continue;
+
+ *type = ion_type_table[i].type;
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
+static int hi6220_set_platform_data(struct platform_device *pdev)
+{
+ unsigned int base;
+ unsigned int size;
+ unsigned int id;
+ const char *heap_name;
+ const char *type_name;
+ enum ion_heap_type type;
+ int ret;
+ struct device_node *np;
+ struct ion_platform_heap *p_data;
+ const struct device_node *dt_node = pdev->dev.of_node;
+ int index = 0;
+
+ for_each_child_of_node(dt_node, np)
+ num_heaps++;
+
+ heaps_data = devm_kzalloc(&pdev->dev,
+ sizeof(struct ion_platform_heap *) *
+ num_heaps,
+ GFP_KERNEL);
+ if (!heaps_data)
+ return -ENOMEM;
+
+ for_each_child_of_node(dt_node, np) {
+ ret = of_property_read_string(np, "heap-name", &heap_name);
+ if (ret < 0) {
+ pr_err("check the name of node %s\n", np->name);
+ continue;
+ }
+
+ ret = of_property_read_u32(np, "heap-id", &id);
+ if (ret < 0) {
+ pr_err("check the id %s\n", np->name);
+ continue;
+ }
+
+ ret = of_property_read_u32(np, "heap-base", &base);
+ if (ret < 0) {
+ pr_err("check the base of node %s\n", np->name);
+ continue;
+ }
+
+ ret = of_property_read_u32(np, "heap-size", &size);
+ if (ret < 0) {
+ pr_err("check the size of node %s\n", np->name);
+ continue;
+ }
+
+ ret = of_property_read_string(np, "heap-type", &type_name);
+ if (ret < 0) {
+ pr_err("check the type of node %s\n", np->name);
+ continue;
+ }
+
+ ret = get_type_by_name(type_name, &type);
+ if (ret < 0) {
+ pr_err("type name error %s!\n", type_name);
+ continue;
+ }
+ pr_info("heap index %d : name %s base 0x%x size 0x%x id %d type %d\n",
+ index, heap_name, base, size, id, type);
+
+ p_data = devm_kzalloc(&pdev->dev,
+ sizeof(struct ion_platform_heap),
+ GFP_KERNEL);
+ if (!p_data)
+ return -ENOMEM;
+
+ p_data->name = heap_name;
+ p_data->base = base;
+ p_data->size = size;
+ p_data->id = id;
+ p_data->type = type;
+
+ heaps_data[index] = p_data;
+ index++;
+ }
+ return 0;
+}
+
+static int hi6220_ion_probe(struct platform_device *pdev)
+{
+ int i;
+ int err = 0;
+ static struct ion_platform_heap *p_heap;
+
+ idev = ion_device_create(NULL);
+ hi6220_set_platform_data(pdev);
+ heaps = devm_kzalloc(&pdev->dev,
+ sizeof(struct ion_heap *) * num_heaps,
+ GFP_KERNEL);
+ if (!heaps)
+ return -ENOMEM;
+
+ /*
+ * create the heaps as specified in the dts file
+ */
+ for (i = 0; i < num_heaps; i++) {
+ p_heap = heaps_data[i];
+ heaps[i] = ion_heap_create(p_heap);
+ if (IS_ERR_OR_NULL(heaps[i])) {
+ err = PTR_ERR(heaps[i]);
+ goto err_free_heaps;
+ }
+
+ ion_device_add_heap(idev, heaps[i]);
+
+ pr_info("%s: adding heap %s of type %d with %lx@%lx\n",
+ __func__, p_heap->name, p_heap->type,
+ p_heap->base, (unsigned long)p_heap->size);
+ }
+ return err;
+
+err_free_heaps:
+ ion_device_destroy(idev);
+ for (i = 0; i < num_heaps; ++i) {
+ ion_heap_destroy(heaps[i]);
+ heaps[i] = NULL;
+ }
+
+ return err;
+}
+
+static int hi6220_ion_remove(struct platform_device *pdev)
+{
+ int i;
+
+ ion_device_destroy(idev);
+ for (i = 0; i < num_heaps; i++) {
+ ion_heap_destroy(heaps[i]);
+ heaps[i] = NULL;
+ }
+
+ return 0;
+}
+
+static const struct of_device_id hi6220_ion_match_table[] = {
+ {.compatible = "hisilicon,hi6220-ion"},
+ {},
+};
+
+static struct platform_driver hi6220_ion_driver = {
+ .probe = hi6220_ion_probe,
+ .remove = hi6220_ion_remove,
+ .driver = {
+ .name = "ion-hi6220",
+ .of_match_table = hi6220_ion_match_table,
+ },
+};
+
+static int __init hi6220_ion_init(void)
+{
+ int ret;
+
+ ret = platform_driver_register(&hi6220_ion_driver);
+ return ret;
+}
+
+subsys_initcall(hi6220_ion_init);
--
1.9.1
next prev parent reply other threads:[~2015-10-10 6:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-10 6:48 [PATCH V1 1/3] docs: dts: Add documentation for hi6220 SoC ION node Chen Feng
2015-10-10 6:48 ` Chen Feng [this message]
2015-10-10 15:00 ` [PATCH V1 2/3] taging: android: ion: Add ion driver for Hi6220 SoC platform Dan Carpenter
2015-10-12 1:15 ` chenfeng
2015-10-10 6:48 ` [PATCH V1 3/3] arm64: dts: Add dts files to enable ION on Hi6220 SoC Chen Feng
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=1444459703-183909-2-git-send-email-puck.chen@hisilicon.com \
--to=puck.chen@hisilicon.com \
--cc=arve@android.com \
--cc=dan.carpenter@oracle.com \
--cc=dan.zhao@hisilicon.com \
--cc=devel@driverdev.osuosl.org \
--cc=gioh.kim@lge.com \
--cc=gregkh@linuxfoundation.org \
--cc=kong.kongxinwei@hisilicon.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=mitchelh@codeaurora.org \
--cc=paul.gortmaker@windriver.com \
--cc=peter.panshilin@hisilicon.com \
--cc=qijiwen@hisilicon.com \
--cc=riandrews@android.com \
--cc=saberlily.xia@hisilicon.com \
--cc=sumit.semwal@linaro.org \
--cc=suzhuangluan@hisilicon.com \
--cc=tapaswenipathak@gmail.com \
--cc=tranmanphong@gmail.com \
--cc=w.f@huawei.com \
--cc=weidong2@hisilicon.com \
--cc=xuyiping@hisilicon.com \
--cc=yudongbin@hisilicon.com \
--cc=z.liuxinliang@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®