From 98869f9f9e7dfca97de3505bcdfa1115abe9b893 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Thu, 9 Nov 2017 08:05:52 -0800 Subject: serdev: Make .remove in struct serdev_device_driver optional Using devres infrastructure it is possible to write a serdev driver that doesn't have any code that needs to be called as a part of .remove. Add code to make .remove optional. Cc: linux-kernel@vger.kernel.org Cc: linux-serial@vger.kernel.org Cc: Rob Herring Cc: cphealy@gmail.com Cc: Guenter Roeck Cc: Lucas Stach Cc: Nikita Yushchenko Cc: Lee Jones Cc: Greg Kroah-Hartman Cc: Pavel Machek Cc: Andy Shevchenko Cc: Johan Hovold Cc: Sebastian Reichel Acked-by: Rob Herring Reviewed-by: Sebastian Reichel Reviewed-by: Guenter Roeck Signed-off-by: Andrey Smirnov Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serdev/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/tty/serdev') diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c index 1bef39828ca7..34050b439c1f 100644 --- a/drivers/tty/serdev/core.c +++ b/drivers/tty/serdev/core.c @@ -268,8 +268,8 @@ static int serdev_drv_probe(struct device *dev) static int serdev_drv_remove(struct device *dev) { const struct serdev_device_driver *sdrv = to_serdev_device_driver(dev->driver); - - sdrv->remove(to_serdev_device(dev)); + if (sdrv->remove) + sdrv->remove(to_serdev_device(dev)); return 0; } -- cgit v1.2.3 From 525ba62c96abec9130b8edb877d1128864cee01c Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Thu, 9 Nov 2017 08:05:53 -0800 Subject: serdev: Introduce devm_serdev_device_open() Add code implementing managed version of serdev_device_open() for serdev device drivers that "open" the device during driver's lifecycle only once (e.g. opened in .probe() and closed in .remove()). Cc: linux-kernel@vger.kernel.org Cc: linux-serial@vger.kernel.org Cc: Rob Herring Cc: cphealy@gmail.com Cc: Guenter Roeck Cc: Lucas Stach Cc: Nikita Yushchenko Cc: Lee Jones Cc: Greg Kroah-Hartman Cc: Pavel Machek Cc: Andy Shevchenko Cc: Johan Hovold Cc: Sebastian Reichel Acked-by: Rob Herring Reviewed-by: Sebastian Reichel Reviewed-by: Guenter Roeck Signed-off-by: Andrey Smirnov Signed-off-by: Greg Kroah-Hartman --- Documentation/driver-model/devres.txt | 3 +++ drivers/tty/serdev/core.c | 27 +++++++++++++++++++++++++++ include/linux/serdev.h | 1 + 3 files changed, 31 insertions(+) (limited to 'drivers/tty/serdev') diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index c180045eb43b..7c1bb3d0c222 100644 --- a/Documentation/driver-model/devres.txt +++ b/Documentation/driver-model/devres.txt @@ -384,6 +384,9 @@ RESET devm_reset_control_get() devm_reset_controller_register() +SERDEV + devm_serdev_device_open() + SLAVE DMA ENGINE devm_acpi_dma_controller_register() diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c index 34050b439c1f..28133dbd2808 100644 --- a/drivers/tty/serdev/core.c +++ b/drivers/tty/serdev/core.c @@ -132,6 +132,33 @@ void serdev_device_close(struct serdev_device *serdev) } EXPORT_SYMBOL_GPL(serdev_device_close); +static void devm_serdev_device_release(struct device *dev, void *dr) +{ + serdev_device_close(*(struct serdev_device **)dr); +} + +int devm_serdev_device_open(struct device *dev, struct serdev_device *serdev) +{ + struct serdev_device **dr; + int ret; + + dr = devres_alloc(devm_serdev_device_release, sizeof(*dr), GFP_KERNEL); + if (!dr) + return -ENOMEM; + + ret = serdev_device_open(serdev); + if (ret) { + devres_free(dr); + return ret; + } + + *dr = serdev; + devres_add(dev, dr); + + return 0; +} +EXPORT_SYMBOL_GPL(devm_serdev_device_open); + void serdev_device_write_wakeup(struct serdev_device *serdev) { complete(&serdev->write_comp); diff --git a/include/linux/serdev.h b/include/linux/serdev.h index e69402d4a8ae..9929063bd45d 100644 --- a/include/linux/serdev.h +++ b/include/linux/serdev.h @@ -193,6 +193,7 @@ static inline int serdev_controller_receive_buf(struct serdev_controller *ctrl, int serdev_device_open(struct serdev_device *); void serdev_device_close(struct serdev_device *); +int devm_serdev_device_open(struct device *, struct serdev_device *); unsigned int serdev_device_set_baudrate(struct serdev_device *, unsigned int); void serdev_device_set_flow_control(struct serdev_device *, bool); int serdev_device_write_buf(struct serdev_device *, const unsigned char *, size_t); -- cgit v1.2.3 From 51899a63b42ee01df676b0624df4e81a517c3571 Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Fri, 3 Nov 2017 15:30:57 +0100 Subject: serdev: ttyport: release tty lock sooner on open Release the tty lock once tty-driver open returns to make it clear that it does not protect neither tty->termios or the serport flags. Signed-off-by: Johan Hovold Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serdev/serdev-ttyport.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/tty/serdev') diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c index ce7ad0acee7a..f76a8e044e4e 100644 --- a/drivers/tty/serdev/serdev-ttyport.c +++ b/drivers/tty/serdev/serdev-ttyport.c @@ -104,6 +104,8 @@ static int ttyport_open(struct serdev_controller *ctrl) if (ret) goto err_close; + tty_unlock(serport->tty); + /* Bring the UART into a known 8 bits no parity hw fc state */ ktermios = tty->termios; ktermios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | @@ -117,7 +119,6 @@ static int ttyport_open(struct serdev_controller *ctrl) set_bit(SERPORT_ACTIVE, &serport->flags); - tty_unlock(serport->tty); return 0; err_close: -- cgit v1.2.3 From cda64188ca918fcddc8c6e89bbee5a38b029117a Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Fri, 3 Nov 2017 15:30:58 +0100 Subject: serdev: ttyport: ignore carrier detect to avoid hangups Serdev currently does not support hangups so make sure to set CLOCAL to prevent loss of carrier from triggering one. Note however that not all tty drivers honour CLOCAL. Signed-off-by: Johan Hovold Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serdev/serdev-ttyport.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/tty/serdev') diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c index f76a8e044e4e..75f312ed96e8 100644 --- a/drivers/tty/serdev/serdev-ttyport.c +++ b/drivers/tty/serdev/serdev-ttyport.c @@ -115,6 +115,8 @@ static int ttyport_open(struct serdev_controller *ctrl) ktermios.c_cflag &= ~(CSIZE | PARENB); ktermios.c_cflag |= CS8; ktermios.c_cflag |= CRTSCTS; + /* Hangups are not supported so make sure to ignore carrier detect. */ + ktermios.c_cflag |= CLOCAL; tty_set_termios(tty, &ktermios); set_bit(SERPORT_ACTIVE, &serport->flags); -- cgit v1.2.3 From afe3eb60fa82a5d812378530b50755f58acc029c Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Mon, 18 Dec 2017 12:00:19 +0100 Subject: serdev: ttyport: do not used keyed wakeup in write_wakeup Serdev does not use the file abstraction and specifically there will never be anyone polling a file descriptor for POLLOUT events. Just use plain wake_up_interruptible() in the write_wakeup callback and document why it's there. Signed-off-by: Johan Hovold Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serdev/serdev-ttyport.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/tty/serdev') diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c index c2629ab1bbcf..a5abb05be67d 100644 --- a/drivers/tty/serdev/serdev-ttyport.c +++ b/drivers/tty/serdev/serdev-ttyport.c @@ -59,7 +59,8 @@ static void ttyport_write_wakeup(struct tty_port *port) test_bit(SERPORT_ACTIVE, &serport->flags)) serdev_controller_write_wakeup(ctrl); - wake_up_interruptible_poll(&tty->write_wait, POLLOUT); + /* Wake up any tty_wait_until_sent() */ + wake_up_interruptible(&tty->write_wait); tty_kref_put(tty); } -- cgit v1.2.3 From 7d09995dcb0577b4a56aad7f2bb56f28604e8f1a Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Mon, 25 Dec 2017 21:50:45 +0100 Subject: serdev: Fix serdev_uevent failure on ACPI enumerated serdev-controllers ACPI enumerated serdev-controllers do not have an ACPI companion, the ACPI companion belongs to the serdev-device child of the serdev-controller, not to the controller itself. This was causing serdev_uevent to always return -ENODEV when called on a serdev-controller leading to errors like these: kernel: serial serial0: uevent: failed to send synthetic uevent being logged. This commit modifies serdev_uevent to directly return 0 when called on an ACPI enumerated serdev-controller fixing this. Note: I do not think that setting a modalias on a devicetree enumerated serdev-controller makes sense either. So perhaps the !dev->of_node part of the check can be dropped too, but I'm not entirely sure that doing this on devicetree too is correct. Signed-off-by: Hans de Goede Acked-by: Johan Hovold Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serdev/core.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'drivers/tty/serdev') diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c index 28133dbd2808..5dc88f61f506 100644 --- a/drivers/tty/serdev/core.c +++ b/drivers/tty/serdev/core.c @@ -54,6 +54,11 @@ static int serdev_uevent(struct device *dev, struct kobj_uevent_env *env) int rc; /* TODO: platform modalias */ + + /* ACPI enumerated controllers do not have a modalias */ + if (!dev->of_node && dev->type == &serdev_ctrl_type) + return 0; + rc = acpi_device_uevent_modalias(dev, env); if (rc != -ENODEV) return rc; -- cgit v1.2.3 From 2460942f51f1f262e77072c9a7c963a1b047a367 Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Tue, 9 Jan 2018 17:09:16 +0100 Subject: serdev: do not generate modaliases for controllers Serdev controllers are not bound to any drivers and it therefore makes no sense to generate modaliases for them. This has already been fixed separately for ACPI controllers for which uevent errors were also being logged during probe due to the missing ACPI companions (from which ACPI modaliases are generated). This patch moves the modalias handling from the bus type to the client device type. Specifically, this means that only serdev devices (a.k.a. clients or slaves) will have have MODALIAS fields in their uevent environments and corresponding modalias sysfs attributes. Also add the missing static keyword for the modalias device attribute when moving the definition. Reported-by: Hans de Goede Signed-off-by: Johan Hovold Reviewed-by: Sebastian Reichel Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serdev/core.c | 72 ++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 38 deletions(-) (limited to 'drivers/tty/serdev') diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c index 5dc88f61f506..c8c43834477b 100644 --- a/drivers/tty/serdev/core.c +++ b/drivers/tty/serdev/core.c @@ -19,6 +19,38 @@ static bool is_registered; static DEFINE_IDA(ctrl_ida); +static ssize_t modalias_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int len; + + len = acpi_device_modalias(dev, buf, PAGE_SIZE - 1); + if (len != -ENODEV) + return len; + + return of_device_modalias(dev, buf, PAGE_SIZE); +} +static DEVICE_ATTR_RO(modalias); + +static struct attribute *serdev_device_attrs[] = { + &dev_attr_modalias.attr, + NULL, +}; +ATTRIBUTE_GROUPS(serdev_device); + +static int serdev_device_uevent(struct device *dev, struct kobj_uevent_env *env) +{ + int rc; + + /* TODO: platform modalias */ + + rc = acpi_device_uevent_modalias(dev, env); + if (rc != -ENODEV) + return rc; + + return of_device_uevent_modalias(dev, env); +} + static void serdev_device_release(struct device *dev) { struct serdev_device *serdev = to_serdev_device(dev); @@ -26,6 +58,8 @@ static void serdev_device_release(struct device *dev) } static const struct device_type serdev_device_type = { + .groups = serdev_device_groups, + .uevent = serdev_device_uevent, .release = serdev_device_release, }; @@ -49,23 +83,6 @@ static int serdev_device_match(struct device *dev, struct device_driver *drv) return of_driver_match_device(dev, drv); } -static int serdev_uevent(struct device *dev, struct kobj_uevent_env *env) -{ - int rc; - - /* TODO: platform modalias */ - - /* ACPI enumerated controllers do not have a modalias */ - if (!dev->of_node && dev->type == &serdev_ctrl_type) - return 0; - - rc = acpi_device_uevent_modalias(dev, env); - if (rc != -ENODEV) - return rc; - - return of_device_uevent_modalias(dev, env); -} - /** * serdev_device_add() - add a device previously constructed via serdev_device_alloc() * @serdev: serdev_device to be added @@ -305,32 +322,11 @@ static int serdev_drv_remove(struct device *dev) return 0; } -static ssize_t modalias_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - int len; - - len = acpi_device_modalias(dev, buf, PAGE_SIZE - 1); - if (len != -ENODEV) - return len; - - return of_device_modalias(dev, buf, PAGE_SIZE); -} -DEVICE_ATTR_RO(modalias); - -static struct attribute *serdev_device_attrs[] = { - &dev_attr_modalias.attr, - NULL, -}; -ATTRIBUTE_GROUPS(serdev_device); - static struct bus_type serdev_bus_type = { .name = "serial", .match = serdev_device_match, .probe = serdev_drv_probe, .remove = serdev_drv_remove, - .uevent = serdev_uevent, - .dev_groups = serdev_device_groups, }; /** -- cgit v1.2.3 From 7ee69102dbc4eea90f46a24f16961226a477dd4c Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Tue, 9 Jan 2018 17:09:17 +0100 Subject: serdev: only match serdev devices Only serdev devices (a.k.a. clients or slaves) are bound to drivers so bail out early from match() in case the device is not a serdev device (i.e. if it's a serdev controller). Signed-off-by: Johan Hovold Reviewed-by: Sebastian Reichel Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serdev/core.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'drivers/tty/serdev') diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c index c8c43834477b..f710862f5c06 100644 --- a/drivers/tty/serdev/core.c +++ b/drivers/tty/serdev/core.c @@ -63,6 +63,11 @@ static const struct device_type serdev_device_type = { .release = serdev_device_release, }; +static bool is_serdev_device(const struct device *dev) +{ + return dev->type == &serdev_device_type; +} + static void serdev_ctrl_release(struct device *dev) { struct serdev_controller *ctrl = to_serdev_controller(dev); @@ -76,6 +81,9 @@ static const struct device_type serdev_ctrl_type = { static int serdev_device_match(struct device *dev, struct device_driver *drv) { + if (!is_serdev_device(dev)) + return 0; + /* TODO: platform matching */ if (acpi_driver_match_device(dev, drv)) return 1; -- cgit v1.2.3