aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Coyne <edcoyne@google.com>2017-09-26 15:16:33 -0700
committerTreeHugger Robot <treehugger-gerrit@google.com>2018-03-06 00:20:34 +0000
commitc35deccc57423571c7ee7d50ccb73d3b09f8a681 (patch)
tree49276f838b4792ea5c1ee8ecf29102fd7befba67
parentaa0802fe23ba5a794e55c2aab30eca8d7ac60ddb (diff)
downloadimx-v4.9-c35deccc57423571c7ee7d50ccb73d3b09f8a681.tar.gz
Add memrt kernel driver.
Introduce the driver/android/things path to store kernel drivers related to the Android Things platform. The first of which is the memrt UIO driver. It exposes a block of shared memory that is used to implement an in-memory serial channel. The location and size of this block is read from the device tree for flexability. Test: Running locally with non-committed changes. Change-Id: I3178e3a96b394292b4fabde6abc0e41c18db85a1
-rw-r--r--drivers/android/Kconfig2
-rw-r--r--drivers/android/Makefile2
-rw-r--r--drivers/android/things/Kconfig6
-rw-r--r--drivers/android/things/Makefile1
-rw-r--r--drivers/android/things/realtime/Makefile1
-rw-r--r--drivers/android/things/realtime/memrt-uio.c89
6 files changed, 101 insertions, 0 deletions
diff --git a/drivers/android/Kconfig b/drivers/android/Kconfig
index 01de42c8b74b..2804034a82b6 100644
--- a/drivers/android/Kconfig
+++ b/drivers/android/Kconfig
@@ -1,5 +1,7 @@
menu "Android"
+source "drivers/android/things/Kconfig"
+
config ANDROID
bool "Android Drivers"
---help---
diff --git a/drivers/android/Makefile b/drivers/android/Makefile
index a01254c43ee3..9b5c7a538e0c 100644
--- a/drivers/android/Makefile
+++ b/drivers/android/Makefile
@@ -1,3 +1,5 @@
+obj-y += things/
+
ccflags-y += -I$(src) # needed for trace events
obj-$(CONFIG_ANDROID_BINDER_IPC) += binder.o binder_alloc.o
diff --git a/drivers/android/things/Kconfig b/drivers/android/things/Kconfig
new file mode 100644
index 000000000000..6a0ffbdd48cf
--- /dev/null
+++ b/drivers/android/things/Kconfig
@@ -0,0 +1,6 @@
+config ANDROIDTHINGS_REALTIME
+ bool "Build drivers for realtime subsystem of Android Things."
+ select UIO
+ help
+ Say Yes here to build shared memory based drivers to communicate
+ between Realtime process and Android.
diff --git a/drivers/android/things/Makefile b/drivers/android/things/Makefile
new file mode 100644
index 000000000000..3dc06084c50f
--- /dev/null
+++ b/drivers/android/things/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_ANDROIDTHINGS_REALTIME) += realtime/
diff --git a/drivers/android/things/realtime/Makefile b/drivers/android/things/realtime/Makefile
new file mode 100644
index 000000000000..b22c0ae84461
--- /dev/null
+++ b/drivers/android/things/realtime/Makefile
@@ -0,0 +1 @@
+obj-y += memrt-uio.o
diff --git a/drivers/android/things/realtime/memrt-uio.c b/drivers/android/things/realtime/memrt-uio.c
new file mode 100644
index 000000000000..84fd30a90761
--- /dev/null
+++ b/drivers/android/things/realtime/memrt-uio.c
@@ -0,0 +1,89 @@
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_device.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/types.h>
+#include <linux/uio_driver.h>
+
+#define DEVICE_NAME "memrt"
+#define DEVICE_VERSION "1.0"
+
+static DEFINE_SPINLOCK(is_open_lock);
+static bool is_open; // Initialized to false by kernel.
+
+static const struct of_device_id memrt_match[] = {
+ { .compatible = "android,memrt", },
+ {}
+};
+
+static int open(struct uio_info *uio, struct inode *node)
+{
+ spin_lock(&is_open_lock);
+ if (is_open)
+ return -EBUSY;
+ is_open = true;
+ spin_unlock(&is_open_lock);
+ return 0;
+}
+
+static int close(struct uio_info *uio, struct inode *node)
+{
+ spin_lock(&is_open_lock);
+ is_open = false;
+ spin_unlock(&is_open_lock);
+ return 0;
+}
+
+static int probe(struct platform_device *platform)
+{
+ const struct of_device_id *match = NULL;
+ struct uio_info *uio = NULL;
+ u64 size = 0;
+
+ match = of_match_device(memrt_match, &platform->dev);
+ if (!match)
+ return -EINVAL;
+
+ uio = devm_kzalloc(&platform->dev, sizeof(struct uio_info), GFP_KERNEL);
+ uio->name = DEVICE_NAME;
+ uio->version = DEVICE_VERSION;
+ uio->irq = UIO_IRQ_NONE;
+ uio->open = open;
+ uio->release = close;
+
+ uio->mem[0].memtype = UIO_MEM_PHYS;
+ uio->mem[0].addr =
+ of_translate_address(platform->dev.of_node,
+ of_get_address(platform->dev.of_node, 0,
+ &size, NULL));
+ uio->mem[0].size = (resource_size_t)size;
+
+ if (!uio->mem[0].addr || uio->mem[0].addr == OF_BAD_ADDR) {
+ pr_err("MemRt failed to map shared memory.\n");
+ return -ENOMEM;
+ }
+
+ return uio_register_device(&platform->dev, uio);
+}
+
+MODULE_DEVICE_TABLE(of, memrt_match);
+
+static struct platform_driver memrt_driver = {
+ .probe = probe,
+ .driver = {
+ .name = DEVICE_NAME,
+ .of_match_table = memrt_match,
+ },
+};
+
+module_platform_driver(memrt_driver);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Ed Coyne, Google Inc.");
+MODULE_DESCRIPTION("Shared memory serial channel between processors.");