diff options
Diffstat (limited to 'schulung_tools/drivers/modules/hellodriver/patches-leds/0003-hello-add-led-toggling-via-chardev-read-write.patch')
| -rw-r--r-- | schulung_tools/drivers/modules/hellodriver/patches-leds/0003-hello-add-led-toggling-via-chardev-read-write.patch | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/schulung_tools/drivers/modules/hellodriver/patches-leds/0003-hello-add-led-toggling-via-chardev-read-write.patch b/schulung_tools/drivers/modules/hellodriver/patches-leds/0003-hello-add-led-toggling-via-chardev-read-write.patch new file mode 100644 index 0000000..8f81e39 --- /dev/null +++ b/schulung_tools/drivers/modules/hellodriver/patches-leds/0003-hello-add-led-toggling-via-chardev-read-write.patch @@ -0,0 +1,56 @@ +From c7a4c4448632af43383818654dd79d2251b27e3e Mon Sep 17 00:00:00 2001 +From: John Ogness <john.ogness@linutronix.de> +Date: Fri, 15 Feb 2019 11:04:56 +0106 +Subject: [PATCH 4/7] hello: add led toggling via chardev read/write + +Signed-off-by: John Ogness <john.ogness@linutronix.de> +--- + hello.c | 28 +++++++++++++++++++++++++++- + 1 file changed, 27 insertions(+), 1 deletion(-) + +diff --git a/hello.c b/hello.c +index 58a64e5..f664121 100644 +--- a/hello.c ++++ b/hello.c +@@ -61,11 +61,37 @@ static ssize_t hello_read(struct file *f, char __user *u, size_t s, loff_t *l) + return len; + } + ++static void toggle_led(struct hello_dev *hello, int offset) ++{ ++ if (readb(hello->mem + offset)) ++ writeb(0, hello->mem + offset); ++ else ++ writeb(0xff, hello->mem + offset); ++} ++ + static ssize_t hello_write(struct file *f, const char __user *u, size_t s, + loff_t *l) + { + struct hello_dev *hello = f->private_data; +- dev_info(hello->dev, "%s: size=%zu offset=%llu\n", __func__, s, *l); ++ size_t sz = s; ++ char buf[32]; ++ ++ if (sz >= sizeof(buf)) ++ sz = sizeof(buf) - 1; ++ if (copy_from_user(buf, u, sz) != 0) ++ return -EFAULT; ++ buf[sz] = 0; ++ ++ dev_info(hello->dev, "%s: size=%zu offset=%llu buf=%s\n", __func__, ++ s, *l, buf); ++ ++ if (strstarts(buf, "heartbeat")) ++ toggle_led(hello, 0); ++ else if (strstarts(buf, "net")) ++ toggle_led(hello, 1); ++ else if (strstarts(buf, "disk")) ++ toggle_led(hello, 2); ++ + return s; + } + +-- +2.11.0 + |
