diff options
| author | John Ogness <john.ogness@linutronix.de> | 2019-02-15 13:10:21 +0106 |
|---|---|---|
| committer | John Ogness <john.ogness@linutronix.de> | 2019-02-15 13:10:21 +0106 |
| commit | aed79d1121a9c65dead95fb6ea8c2d8541d01143 (patch) | |
| tree | 6917e9570dfd2d60f357759e096cb013bc0c001c /schulung_tools/drivers/modules/hellodriver/patches-leds/0003-hello-add-led-toggling-via-chardev-read-write.patch | |
| parent | 2d2484928560dd0ffec90069166b0161cdc84a54 (diff) | |
schulung_tools: hellodriver: add patches for use with leds
These patches are based heavily on the work by Manu to make the
driver lessons more interesting. Rather than create a new driver,
I took his work and created a series of patches that do
interesting modifications to the hello driver.
These patches can be used together with the "leds" program to
do live blinking demonstrations.
Signed-off-by: John Ogness <john.ogness@linutronix.de>
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 + |
