From c2ee90fb9ed90c3612301e2b86c05cfb3c008fde Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Thu, 12 Apr 2018 14:33:14 -0700 Subject: console: Add simplified 'serdev' framework from Linux kernel Port 'serdev' UART-slave deivce framework found in recent Linux kernels (post 4.13) in order to be able to port 'serdev' slave drivers from Linux. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- common/console.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'common/console.c') diff --git a/common/console.c b/common/console.c index f4c799fa54..ab3d4d397c 100644 --- a/common/console.c +++ b/common/console.c @@ -305,10 +305,11 @@ static ssize_t fops_write(struct cdev* dev, const void* buf, size_t count, int console_register(struct console_device *newcdev) { + struct device_node *serdev_node = console_is_serdev_node(newcdev); struct device_d *dev = &newcdev->class_dev; int activate = 0, ret; - if (initialized == CONSOLE_UNINITIALIZED) + if (!serdev_node && initialized == CONSOLE_UNINITIALIZED) console_init_early(); if (newcdev->devname) { @@ -323,6 +324,17 @@ int console_register(struct console_device *newcdev) dev->parent = newcdev->dev; platform_device_register(dev); + newcdev->open_count = 0; + + /* + * If our console device is a serdev, we skip the creation of + * corresponding entry in /dev as well as registration in + * console_list and just go straight to populating child + * devices. + */ + if (serdev_node) + return of_platform_populate(serdev_node, NULL, dev); + if (newcdev->setbrg) { ret = newcdev->setbrg(newcdev, CONFIG_BAUDRATE); if (ret) @@ -335,8 +347,6 @@ int console_register(struct console_device *newcdev) if (newcdev->putc && !newcdev->puts) newcdev->puts = __console_puts; - newcdev->open_count = 0; - dev_add_param_string(dev, "active", console_active_set, console_active_get, &newcdev->active_string, newcdev); @@ -386,6 +396,14 @@ int console_unregister(struct console_device *cdev) struct device_d *dev = &cdev->class_dev; int status; + /* + * We don't do any sophisticated serdev device de-population + * and instead claim this console busy, preventing its + * de-initialization, 'till the very end of our execution. + */ + if (console_is_serdev_node(cdev)) + return -EBUSY; + devfs_remove(&cdev->devfs); list_del(&cdev->list); -- cgit v1.2.3