Add rockchip ion
authorCMY <cmy@rock-chips.com>
Mon, 10 Feb 2014 02:36:02 +0000 (10:36 +0800)
committerCMY <cmy@rock-chips.com>
Tue, 11 Feb 2014 07:09:09 +0000 (15:09 +0800)
14 files changed:
arch/arm/boot/dts/rk3188.dtsi
drivers/gpu/ion/rockchip/Makefile [deleted file]
drivers/gpu/ion/rockchip/rockchip_ion.c [deleted file]
drivers/staging/android/ion/Kconfig
drivers/staging/android/ion/Makefile
drivers/staging/android/ion/ion.c [changed mode: 0644->0755]
drivers/staging/android/ion/ion.h [changed mode: 0644->0755]
drivers/staging/android/ion/ion_cma_heap.c [changed mode: 0644->0755]
drivers/staging/android/ion/ion_heap.c [changed mode: 0644->0755]
drivers/staging/android/ion/ion_system_heap.c [changed mode: 0644->0755]
drivers/staging/android/ion/rockchip/Makefile [new file with mode: 0644]
drivers/staging/android/ion/rockchip/rockchip_ion.c [new file with mode: 0755]
drivers/staging/android/uapi/ion.h [changed mode: 0644->0755]
drivers/staging/android/uapi/rockchip_ion.h [new file with mode: 0755]

index b87da55bd2b61148f026246f6f4b89f47d691c41..e4863fe38da519f09794265f4a887062e2a33100 100644 (file)
                        };
                };
        };
+       ion: ion{
+               compatible = "rockchip,ion";
+               #address-cells = <1>;
+               #size-cells = <0>;
+               rockchip,ion-heap@1 { /* VIDEO HEAP */
+                       reg = <1>;
+               };
+       };
 };
diff --git a/drivers/gpu/ion/rockchip/Makefile b/drivers/gpu/ion/rockchip/Makefile
deleted file mode 100644 (file)
index 5451bfd..0000000
+++ /dev/null
@@ -1 +0,0 @@
-obj-y += rockchip_ion.o
diff --git a/drivers/gpu/ion/rockchip/rockchip_ion.c b/drivers/gpu/ion/rockchip/rockchip_ion.c
deleted file mode 100755 (executable)
index 1fa4486..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * drivers/gpu/rockchip/rockchip_ion.c
- *
- * Copyright (C) 2011 Google, Inc.
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- */
-
-#include <linux/err.h>
-#include <linux/ion.h>
-#include <linux/platform_device.h>
-#include <linux/slab.h>
-#include "../ion_priv.h"
-
-static int num_heaps;
-static struct ion_heap **heaps;
-
-static long rockchip_custom_ioctl (struct ion_client *client, unsigned int cmd,
-                             unsigned long arg)
-{
-       return 0;
-}
-static int rockchip_ion_probe(struct platform_device *pdev)
-{
-    struct ion_device *idev;
-       struct ion_platform_data *pdata = pdev->dev.platform_data;
-       int err;
-       int i;
-
-       num_heaps = pdata->nr;
-       heaps = kzalloc(sizeof(struct ion_heap *) * pdata->nr, GFP_KERNEL);
-
-       idev = ion_device_create(rockchip_custom_ioctl);
-       if (IS_ERR_OR_NULL(idev)) {
-               kfree(heaps);
-               return PTR_ERR(idev);
-       }
-       /* create the heaps as specified in the board file */
-       for (i = 0; i < num_heaps; i++) {
-               struct ion_platform_heap *heap_data = &pdata->heaps[i];
-
-               heaps[i] = ion_heap_create(heap_data);
-               if (IS_ERR_OR_NULL(heaps[i])) {
-                       err = PTR_ERR(heaps[i]);
-                       goto err;
-               }
-               ion_device_add_heap(idev, heaps[i]);
-       }
-       platform_set_drvdata(pdev, idev);
-        pr_info("Rockchip ion module(version: %s) is successfully loaded\n", ION_VERSION);
-       return 0;
-err:
-       for (i = 0; i < num_heaps; i++) {
-               if (heaps[i])
-                       ion_heap_destroy(heaps[i]);
-       }
-       kfree(heaps);
-       return err;
-}
-
-static int rockchip_ion_remove(struct platform_device *pdev)
-{
-       struct ion_device *idev = platform_get_drvdata(pdev);
-       int i;
-
-       ion_device_destroy(idev);
-       for (i = 0; i < num_heaps; i++)
-               ion_heap_destroy(heaps[i]);
-       kfree(heaps);
-       return 0;
-}
-
-static struct platform_driver ion_driver = {
-       .probe = rockchip_ion_probe,
-       .remove = rockchip_ion_remove,
-       .driver = { .name = "ion-rockchip" }
-};
-
-static int __init ion_init(void)
-{
-       return platform_driver_register(&ion_driver);
-}
-
-static void __exit ion_exit(void)
-{
-       platform_driver_unregister(&ion_driver);
-}
-
-module_init(ion_init);
-module_exit(ion_exit);
-
index 0f8fec1f84e5571c055841b7f96d78432bedca39..a8a23602e662cd828af6523baad70107f079ca2c 100644 (file)
@@ -33,3 +33,8 @@ config ION_TEGRA
        help
          Choose this option if you wish to use ion on an nVidia Tegra.
 
+config ION_ROCKCHIP
+    tristate "Ion for Rockchip"
+    depends on ARCH_ROCKCHIP && ION
+    help
+      Choose this option if you wish to use ion on an Rockchip.
index b56fd2bf2b4f4853a56aac29958afdf4bf77b5b5..5c8fc6915b772bf1b412d37251543eaf2ba172f4 100644 (file)
@@ -7,4 +7,4 @@ endif
 
 obj-$(CONFIG_ION_DUMMY) += ion_dummy_driver.o
 obj-$(CONFIG_ION_TEGRA) += tegra/
-
+obj-$(CONFIG_ION_ROCKCHIP) += rockchip/
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index dcd2a0c..dbae7ae
@@ -20,6 +20,7 @@
 #include <linux/types.h>
 
 #include "../uapi/ion.h"
+#include "../uapi/rockchip_ion.h"
 
 struct ion_handle;
 struct ion_device;
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
diff --git a/drivers/staging/android/ion/rockchip/Makefile b/drivers/staging/android/ion/rockchip/Makefile
new file mode 100644 (file)
index 0000000..5451bfd
--- /dev/null
@@ -0,0 +1 @@
+obj-y += rockchip_ion.o
diff --git a/drivers/staging/android/ion/rockchip/rockchip_ion.c b/drivers/staging/android/ion/rockchip/rockchip_ion.c
new file mode 100755 (executable)
index 0000000..e82abcd
--- /dev/null
@@ -0,0 +1,273 @@
+/*
+ * drivers/gpu/rockchip/rockchip_ion.c
+ *
+ * Copyright (C) 2011 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include "../ion.h"
+#include "../ion_priv.h"
+
+#ifdef CONFIG_OF
+#include <linux/of.h>
+#include <linux/of_gpio.h>
+#include <video/of_display_timing.h>
+#endif
+
+static struct ion_device *idev;
+static int num_heaps;
+static struct ion_heap **heaps;
+/*
+static struct ion_platform_heap s_heap_data = {
+        .type = ION_HEAP_TYPE_DMA,
+        .id = 1,
+        .name = "norheap",
+        .size = 256*SZ_1M,
+        .align = SZ_1M,
+};
+*/
+struct ion_heap_desc {
+       unsigned int id;
+       enum ion_heap_type type;
+       const char *name;
+};
+
+static struct ion_heap_desc ion_heap_meta[] = {
+       {
+               .id     = ION_SYSTEM_HEAP_ID,
+               .type   = ION_HEAP_TYPE_SYSTEM,
+               .name   = ION_VMALLOC_HEAP_NAME,
+       },
+       {
+               .id     = ION_VIDEO_HEAP_ID,
+               .type   = ION_HEAP_TYPE_DMA,
+               .name   = ION_VIDEO_HEAP_NAME,
+       },
+       {
+               .id     = ION_AUDIO_HEAP_ID,
+               .type   = ION_HEAP_TYPE_DMA,
+               .name   = ION_AUDIO_HEAP_NAME,
+       },
+       {
+               .id     = ION_IOMMU_HEAP_ID,
+               .type   = ION_HEAP_TYPE_DMA,//ION_HEAP_TYPE_IOMMU,
+               .name   = ION_IOMMU_HEAP_NAME,
+       },
+       {
+               .id     = ION_CAMERA_HEAP_ID,
+               .type   = ION_HEAP_TYPE_DMA,
+               .name   = ION_CAMERA_HEAP_NAME,
+       },
+};
+
+static int rockchip_ion_populate_heap(struct ion_platform_heap *heap)
+{
+       unsigned int i;
+       int ret = -EINVAL;
+       unsigned int len = ARRAY_SIZE(ion_heap_meta);
+       for (i = 0; i < len; ++i) {
+               if (ion_heap_meta[i].id == heap->id) {
+                       heap->name = ion_heap_meta[i].name;
+                       heap->type = ion_heap_meta[i].type;
+                       ret = 0;
+                       break;
+               }
+       }
+       if (ret)
+               pr_err("%s: Unable to populate heap, error: %d", __func__, ret);
+       return ret;
+}
+
+static int rockchip_ion_get_heap_size(struct device_node *node,
+                                struct ion_platform_heap *heap)
+{
+       unsigned int val;
+       int ret = 0;
+
+       ret = of_property_read_u32(node, "rockchip,memory-reservation-size", &val);
+       if (!ret) {
+               heap->size = val;
+       } else {
+               ret = 0;
+       }
+
+       return ret;
+}
+
+static struct ion_platform_data *rockchip_ion_parse_dt(
+                                       struct device *dev)
+{
+        struct device_node *dt_node = dev->of_node;
+       struct ion_platform_data *pdata = 0;
+       struct device_node *node;
+       uint32_t val = 0;
+       int ret = 0;
+       uint32_t num_heaps = 0;
+       int idx = 0;
+
+       for_each_child_of_node(dt_node, node)
+               num_heaps++;
+
+        pr_info("%s: num_heaps = %d\n", __func__, num_heaps);
+        
+       if (!num_heaps)
+               return ERR_PTR(-EINVAL);
+
+       pdata = kzalloc(sizeof(struct ion_platform_data) +
+                       num_heaps*sizeof(struct ion_platform_heap), GFP_KERNEL);
+       if (!pdata)
+               return ERR_PTR(-ENOMEM);
+        pdata->heaps = (struct ion_platform_heap*)((void*)pdata+sizeof(struct ion_platform_data));
+       pdata->nr = num_heaps;
+        
+       for_each_child_of_node(dt_node, node) {
+               ret = of_property_read_u32(node, "reg", &val);
+               if (ret) {
+                       pr_err("%s: Unable to find reg key", __func__);
+                       goto free_heaps;
+               }
+               pdata->heaps[idx].id = val;
+
+               ret = rockchip_ion_populate_heap(&pdata->heaps[idx]);
+               if (ret)
+                       goto free_heaps;
+
+//             msm_ion_get_heap_align(node, &pdata->heaps[idx]);
+               ret = rockchip_ion_get_heap_size(node, &pdata->heaps[idx]);
+               if (ret)
+                       goto free_heaps;
+
+//             msm_ion_get_heap_adjacent(node, &pdata->heaps[idx]);
+                pdata->heaps[idx].priv = dev;
+                pr_info("%d:  %d  %d  %s  0x%08X\n", idx, pdata->heaps[idx].type, pdata->heaps[idx].id, pdata->heaps[idx].name, pdata->heaps[idx].size);
+
+               ++idx;
+       }
+
+       return pdata;
+
+free_heaps:
+       kfree(pdata);
+       return ERR_PTR(ret);
+}
+
+struct ion_client *rockchip_ion_client_create(const char *name)
+{
+       return ion_client_create(idev, name);
+}
+EXPORT_SYMBOL(rockchip_ion_client_create);
+
+static long rockchip_custom_ioctl (struct ion_client *client, unsigned int cmd,
+                             unsigned long arg)
+{
+       return 0;
+}
+
+static int rockchip_ion_probe(struct platform_device *pdev)
+{
+       struct ion_platform_data *pdata;
+        unsigned int pdata_needs_to_be_freed;
+       int err;
+       int i;
+
+        printk("%s\n", __func__);
+
+       if (pdev->dev.of_node) {
+               pdata = rockchip_ion_parse_dt(&pdev->dev);
+               if (IS_ERR(pdata)) {
+                       return PTR_ERR(pdata);
+               }
+               pdata_needs_to_be_freed = 1;
+       } else {
+               pdata = pdev->dev.platform_data;
+               pdata_needs_to_be_freed = 0;
+       }
+
+       num_heaps = pdata->nr;
+       heaps = kzalloc(sizeof(struct ion_heap *) * num_heaps, GFP_KERNEL);
+
+       idev = ion_device_create(rockchip_custom_ioctl);
+       if (IS_ERR_OR_NULL(idev)) {
+               kfree(heaps);
+               return PTR_ERR(idev);
+       }
+       /* create the heaps as specified in the board file */
+       for (i = 0; i < num_heaps; i++) {
+               struct ion_platform_heap *heap_data = &pdata->heaps[i];
+
+               heaps[i] = ion_heap_create(heap_data);
+               if (IS_ERR_OR_NULL(heaps[i])) {
+                       err = PTR_ERR(heaps[i]);
+                       goto err;
+               }
+               ion_device_add_heap(idev, heaps[i]);
+       }
+       platform_set_drvdata(pdev, idev);
+       if (pdata_needs_to_be_freed)
+               kfree(pdata);
+
+        pr_info("Rockchip ion module is successfully loaded\n");
+       return 0;
+err:
+       for (i = 0; i < num_heaps; i++) {
+               if (heaps[i])
+                       ion_heap_destroy(heaps[i]);
+       }
+       if (pdata_needs_to_be_freed)
+               kfree(pdata);
+       kfree(heaps);
+       return err;
+}
+
+static int rockchip_ion_remove(struct platform_device *pdev)
+{
+        struct ion_device *idev = platform_get_drvdata(pdev);
+        int i;
+
+        ion_device_destroy(idev);
+        for (i = 0; i < num_heaps; i++)
+                ion_heap_destroy(heaps[i]);
+        kfree(heaps);
+        return 0;
+}
+
+static const struct of_device_id rockchip_ion_dt_ids[] = {
+        { .compatible = "rockchip,ion", },
+        {}
+};
+
+static struct platform_driver ion_driver = {
+        .probe = rockchip_ion_probe,
+        .remove = rockchip_ion_remove,
+        .driver = {
+                .name = "ion-rockchip",
+                .owner = THIS_MODULE,
+                .of_match_table = of_match_ptr(rockchip_ion_dt_ids),
+        },
+};
+
+static int __init ion_init(void)
+{
+        return platform_driver_register(&ion_driver);
+}
+
+static void __exit ion_exit(void)
+{
+        platform_driver_unregister(&ion_driver);
+}
+
+subsys_initcall(ion_init);
+module_exit(ion_exit);
+
old mode 100644 (file)
new mode 100755 (executable)
diff --git a/drivers/staging/android/uapi/rockchip_ion.h b/drivers/staging/android/uapi/rockchip_ion.h
new file mode 100755 (executable)
index 0000000..4fa54d7
--- /dev/null
@@ -0,0 +1,87 @@
+/*\r
+ *\r
+ * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.\r
+ *\r
+ * This software is licensed under the terms of the GNU General Public\r
+ * License version 2, as published by the Free Software Foundation, and\r
+ * may be copied, distributed, and modified under those terms.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ */\r
+\r
+#ifndef _LINUX_ROCKCHIP_ION_H\r
+#define _LINUX_ROCKCHIP_ION_H\r
+\r
+enum ion_heap_ids {\r
+       INVALID_HEAP_ID = -1,\r
+       ION_VIDEO_HEAP_ID = 1,\r
+       ION_CAMERA_HEAP_ID,\r
+       ION_IOMMU_HEAP_ID,\r
+       ION_AUDIO_HEAP_ID,\r
+       ION_SYSTEM_HEAP_ID,\r
+\r
+       ION_HEAP_ID_RESERVED = 31\r
+};\r
+\r
+#define ION_HEAP(bit) (1 << (bit))\r
+\r
+#define ION_VIDEO_HEAP_NAME    "video"\r
+#define ION_AUDIO_HEAP_NAME    "audio"\r
+#define ION_CAMERA_HEAP_NAME   "camera_preview"\r
+#define ION_IOMMU_HEAP_NAME    "iommu"\r
+#define ION_VMALLOC_HEAP_NAME  "vmalloc"\r
+\r
+#define ION_SET_CACHED(__cache)                (__cache | ION_FLAG_CACHED)\r
+#define ION_SET_UNCACHED(__cache)      (__cache & ~ION_FLAG_CACHED)\r
+\r
+#define ION_IS_CACHED(__flags) ((__flags) & ION_FLAG_CACHED)\r
+\r
+/* struct ion_flush_data - data passed to ion for flushing caches\r
+ *\r
+ * @handle:    handle with data to flush\r
+ * @fd:                fd to flush\r
+ * @vaddr:     userspace virtual address mapped with mmap\r
+ * @offset:    offset into the handle to flush\r
+ * @length:    length of handle to flush\r
+ *\r
+ * Performs cache operations on the handle. If p is the start address\r
+ * of the handle, p + offset through p + offset + length will have\r
+ * the cache operations performed\r
+ */\r
+struct ion_flush_data {\r
+       struct ion_handle *handle;\r
+       int fd;\r
+       void *vaddr;\r
+       unsigned int offset;\r
+       unsigned int length;\r
+};\r
+\r
+#define ION_IOC_ROCKCHIP_MAGIC 'R'\r
+\r
+/**\r
+ * DOC: ION_IOC_CLEAN_CACHES - clean the caches\r
+ *\r
+ * Clean the caches of the handle specified.\r
+ */\r
+#define ION_IOC_CLEAN_CACHES   _IOWR(ION_IOC_ROCKCHIP_MAGIC, 0, \\r
+                                               struct ion_flush_data)\r
+/**\r
+ * DOC: ION_IOC_INV_CACHES - invalidate the caches\r
+ *\r
+ * Invalidate the caches of the handle specified.\r
+ */\r
+#define ION_IOC_INV_CACHES     _IOWR(ION_IOC_ROCKCHIP_MAGIC, 1, \\r
+                                               struct ion_flush_data)\r
+/**\r
+ * DOC: ION_IOC_CLEAN_INV_CACHES - clean and invalidate the caches\r
+ *\r
+ * Clean and invalidate the caches of the handle specified.\r
+ */\r
+#define ION_IOC_CLEAN_INV_CACHES       _IOWR(ION_IOC_ROCKCHIP_MAGIC, 2, \\r
+                                               struct ion_flush_data)\r
+\r
+#endif\r