lkml.org 
[lkml]   [2011]   [Nov]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[RFC PATCH 5/7] drivers/zio: add the zio-zero device driver
From: Federico Vaga <federico.vaga@gmail.com>

zio-zero is a demonstration driver that generates /dev/zero-like data.
I can be used to test the default trigger and the default buffer.
The files match commit 7d37663 in git://ohwr.org/misc/zio.git .

Signed-off-by: Federico Vaga <federico.vaga@gmail.com>
Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
Acked-by: Juan David Gonzalez Cobas <dcobas@cern.ch>
Acked-by: Samuel Iglesias Gonsalvez <siglesia@cern.ch>
Acked-by: Manohar Vanga <manohar.vanga@cern.ch>
---
drivers/zio/drivers/Makefile | 1 +
drivers/zio/drivers/zio-zero.c | 87 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 88 insertions(+), 0 deletions(-)
create mode 100644 drivers/zio/drivers/Makefile
create mode 100644 drivers/zio/drivers/zio-zero.c

diff --git a/drivers/zio/drivers/Makefile b/drivers/zio/drivers/Makefile
new file mode 100644
index 0000000..d59387b
--- /dev/null
+++ b/drivers/zio/drivers/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_ZIO) += zio-zero.o
diff --git a/drivers/zio/drivers/zio-zero.c b/drivers/zio/drivers/zio-zero.c
new file mode 100644
index 0000000..f803e09
--- /dev/null
+++ b/drivers/zio/drivers/zio-zero.c
@@ -0,0 +1,87 @@
+/* Federico Vaga for CERN, 2011, GNU GPLv2 or later */
+/*
+ * zero-zio is a simple zio driver which fill buffer with 0. From the ZIO
+ * point of view is an input device
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/random.h>
+
+#include <linux/zio.h>
+#include <linux/zio-buffer.h>
+
+static char *zzero_trigger;
+static char *zzero_buffer;
+module_param_named(trigger, zzero_trigger, charp, 0444);
+module_param_named(buffer, zzero_buffer, charp, 0444);
+
+static int zzero_input(struct zio_cset *cset)
+{
+ struct zio_channel *chan;
+ struct zio_block *block;
+ static uint8_t datum;
+ uint8_t *data;
+ int i;
+
+ /* Return immediately: just fill the blocks */
+ cset_for_each(cset, chan) {
+ block = chan->active_block;
+ if (!block)
+ continue;
+ switch (chan->index) {
+ case 0: /* zero */
+ memset(block->data, 0x0, block->datalen);
+ break;
+ case 1: /* random */
+ get_random_bytes(block->data, block->datalen);
+ break;
+ case 2: /* sequence */
+ data = block->data;
+ for (i = 0; i < block->datalen; i++)
+ data[i] = datum++;
+ }
+ }
+ return 1; /* Already done */
+}
+
+static const struct zio_device_operations zzero_d_op = {
+ .input_cset = zzero_input,
+};
+
+static struct zio_cset zzero_cset[] = {
+ {
+ .n_chan = 3,
+ .ssize = 1,
+ .flags = ZIO_DIR_INPUT | ZCSET_TYPE_ANALOG,
+ },
+};
+
+static struct zio_device zzero_dev = {
+ .owner = THIS_MODULE,
+ .d_op = &zzero_d_op,
+ .cset = zzero_cset,
+ .n_cset = ARRAY_SIZE(zzero_cset),
+};
+
+static int __init zzero_init(void)
+{
+ if (zzero_trigger)
+ zzero_dev.preferred_trigger = zzero_trigger;
+ if (zzero_buffer)
+ zzero_dev.preferred_buffer = zzero_buffer;
+ return zio_register_dev(&zzero_dev, "zzero");
+}
+
+static void __exit zzero_exit(void)
+{
+ zio_unregister_dev(&zzero_dev);
+}
+
+module_init(zzero_init);
+module_exit(zzero_exit);
+
+MODULE_AUTHOR("Federico Vaga <federico.vaga@gmail.com>");
+MODULE_DESCRIPTION("A zio driver which fakes zero, random and sawtooth input");
+MODULE_LICENSE("GPL");
--
1.7.7.2

\
 
 \ /
  Last update: 2011-11-26 18:33    [W:0.160 / U:0.624 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site