From: Bastian Stender <bst@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Bastian Stender <bst@pengutronix.de>
Subject: [PATCH v2 2/4] console: expose consoles in devfs
Date: Tue, 28 Feb 2017 15:31:25 +0100 [thread overview]
Message-ID: <20170228143127.2945-3-bst@pengutronix.de> (raw)
In-Reply-To: <20170228143127.2945-1-bst@pengutronix.de>
This enables displaying text on e.g. a framebuffer console by issueing
echo -o /dev/fbconsole0 abc123
Signed-off-by: Bastian Stender <bst@pengutronix.de>
---
common/console.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
include/console.h | 3 +++
2 files changed, 56 insertions(+)
diff --git a/common/console.c b/common/console.c
index eccbeed0ca..668c870ab4 100644
--- a/common/console.c
+++ b/common/console.c
@@ -272,6 +272,40 @@ static int __console_puts(struct console_device *cdev, const char *s)
return n;
}
+static int fops_open(struct cdev *cdev, unsigned long flags)
+{
+ struct console_device *priv = cdev->priv;
+
+ return console_open(priv);
+}
+
+static int fops_close(struct cdev *dev)
+{
+ struct console_device *priv = dev->priv;
+
+ return console_close(priv);
+}
+
+static int fops_flush(struct cdev *dev)
+{
+ struct console_device *priv = dev->priv;
+
+ if (priv->flush)
+ priv->flush(priv);
+
+ return 0;
+}
+
+static int fops_write(struct cdev* dev, const void* buf, size_t count,
+ loff_t offset, ulong flags)
+{
+ struct console_device *priv = dev->priv;
+
+ priv->puts(priv, buf);
+
+ return 0;
+}
+
int console_register(struct console_device *newcdev)
{
struct device_d *dev = &newcdev->class_dev;
@@ -326,6 +360,25 @@ int console_register(struct console_device *newcdev)
console_set_active(newcdev, CONSOLE_STDIN |
CONSOLE_STDOUT | CONSOLE_STDERR);
+ /* expose console as device in fs */
+ newcdev->devfs.name = basprintf("%s%d", newcdev->class_dev.name,
+ newcdev->class_dev.id);
+ newcdev->devfs.priv = newcdev;
+ newcdev->devfs.dev = dev;
+ newcdev->devfs.ops = &newcdev->fops;
+ newcdev->devfs.flags = DEVFS_IS_CHARACTER_DEV;
+ newcdev->fops.open = fops_open;
+ newcdev->fops.close = fops_close;
+ newcdev->fops.flush = fops_flush;
+ newcdev->fops.write = fops_write;
+
+ ret = devfs_create(&newcdev->devfs);
+
+ if (ret) {
+ pr_err("device creation failed with %s\n", strerror(-ret));
+ return ret;
+ }
+
return 0;
}
EXPORT_SYMBOL(console_register);
diff --git a/include/console.h b/include/console.h
index a1ebc8581b..126c2e8aa3 100644
--- a/include/console.h
+++ b/include/console.h
@@ -61,6 +61,9 @@ struct console_device {
unsigned int baudrate_param;
const char *linux_console_name;
+
+ struct cdev devfs;
+ struct file_operations fops;
};
int console_register(struct console_device *cdev);
--
2.11.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2017-02-28 14:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-28 14:31 [PATCH v2 0/4] Prepare consoles, add fb flush and Solomon SSD1307 OLED controller support Bastian Stender
2017-02-28 14:31 ` [PATCH v2 1/4] console: replace set_active by open/close Bastian Stender
2017-02-28 14:31 ` Bastian Stender [this message]
2017-02-28 14:31 ` [PATCH v2 3/4] fb: introduce flush for virtual framebuffer Bastian Stender
2017-02-28 14:31 ` [PATCH v2 4/4] video: add support for Solomon SSD1307 OLED controller family Bastian Stender
2017-03-03 9:06 ` [PATCH] fixup! " Uwe Kleine-König
2017-03-06 7:10 ` Sascha Hauer
2017-03-01 7:03 ` [PATCH v2 0/4] Prepare consoles, add fb flush and Solomon SSD1307 OLED controller support Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170228143127.2945-3-bst@pengutronix.de \
--to=bst@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox