Re: [PATCH v2] console: expose consoles in devfs

2017-02-27 Thread Sascha Hauer
On Mon, Feb 27, 2017 at 05:01:08PM +0100, Bastian Stender wrote:
> This enables displaying text on e.g. a framebuffer console by issueing
> 
>   echo -o /dev/fbconsole0 abc123
> 
> Signed-off-by: Bastian Stender 
> ---
>  common/console.c  | 52 
>  include/console.h |  3 +++
>  2 files changed, 55 insertions(+)
> 
> diff --git a/common/console.c b/common/console.c
> index 3ff32b8327..bde4c08414 100644
> --- a/common/console.c
> +++ b/common/console.c
> @@ -259,6 +259,39 @@ 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;
> +
> + priv->flush(priv);

cdev->flush() is optional, you have to test for presence before using
it.

When you have to resend patches from a series, please resend the whole
series. Scanning different mail threads to find the newest version of
the patches can get cumbersome quite fast.

Sascha

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2] console: expose consoles in devfs

2017-02-27 Thread Bastian Stender
This enables displaying text on e.g. a framebuffer console by issueing

echo -o /dev/fbconsole0 abc123

Signed-off-by: Bastian Stender 
---
 common/console.c  | 52 
 include/console.h |  3 +++
 2 files changed, 55 insertions(+)

diff --git a/common/console.c b/common/console.c
index 3ff32b8327..bde4c08414 100644
--- a/common/console.c
+++ b/common/console.c
@@ -259,6 +259,39 @@ 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;
+
+   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 = >class_dev;
@@ -311,6 +344,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 = >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(>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 85e15cad67..68edc3aaf1 100644
--- a/include/console.h
+++ b/include/console.h
@@ -63,6 +63,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