forked from torvalds/linux
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
serial: core: Start managing serial controllers to enable runtime PM
We want to enable runtime PM for serial port device drivers in a generic way. To do this, we want to have the serial core layer manage the registered physical serial controller devices. To do this, let's set up a struct bus and struct device for the serial core controller as suggested by Greg and Jiri. The serial core controller devices are children of the physical serial port device. The serial core controller device is needed to support multiple different kind of ports connected to single physical serial port device. Let's also set up a struct device for the serial core port. The serial core port instances are children of the serial core controller device. We need to also update the documentation a bit as suggested by Andy. With the serial core port device we can now flush pending TX on the runtime PM resume as suggested by Johan. Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Suggested-by: Jiri Slaby <jirislaby@kernel.org> Suggested-by: Johan Hovold <johan@kernel.org> Signed-off-by: Tony Lindgren <tony@atomide.com>
- Loading branch information
1 parent
fe15c26
commit 08f76f2
Showing
9 changed files
with
474 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
/* | ||
* Serial core base layer for controllers | ||
* | ||
* The serial core bus manages the serial core controller instances. | ||
*/ | ||
|
||
#include <linux/device.h> | ||
#include <linux/module.h> | ||
#include <linux/serial_core.h> | ||
#include <linux/slab.h> | ||
|
||
#include "serial_base.h" | ||
|
||
static int serial_base_match(struct device *dev, struct device_driver *drv) | ||
{ | ||
int len = strlen(drv->name); | ||
|
||
return (strncmp(dev_name(dev), drv->name, len) == 0); | ||
} | ||
|
||
static struct bus_type serial_base_bus_type = { | ||
.name = "serial-base", | ||
.match = serial_base_match, | ||
}; | ||
|
||
int serial_base_driver_register(struct device_driver *driver) | ||
{ | ||
driver->bus = &serial_base_bus_type; | ||
|
||
return driver_register(driver); | ||
} | ||
EXPORT_SYMBOL_GPL(serial_base_driver_register); | ||
|
||
void serial_base_driver_unregister(struct device_driver *driver) | ||
{ | ||
driver_unregister(driver); | ||
} | ||
EXPORT_SYMBOL_GPL(serial_base_driver_unregister); | ||
|
||
struct serial_base_device *serial_base_device_add(struct uart_port *port, | ||
const char *name, | ||
struct device *parent_dev) | ||
{ | ||
struct serial_base_device *dev; | ||
int ret, id; | ||
|
||
dev = kzalloc(sizeof(*dev), GFP_KERNEL); | ||
if (!dev) | ||
return NULL; | ||
|
||
device_initialize(&dev->dev); | ||
dev->dev.parent = parent_dev; | ||
dev->dev.bus = &serial_base_bus_type; | ||
|
||
if (!strncmp(name, "ctrl", 4)) { | ||
id = port->ctrl_id; | ||
} else { | ||
id = port->line; | ||
dev->port = port; | ||
} | ||
|
||
dev_set_name(&dev->dev, "%s.%s.%d", name, dev_name(port->dev), id); | ||
|
||
ret = device_add(&dev->dev); | ||
if (ret) { | ||
kfree(dev); | ||
return NULL; | ||
} | ||
|
||
return dev; | ||
} | ||
EXPORT_SYMBOL_GPL(serial_base_device_add); | ||
|
||
void serial_base_device_remove(struct serial_base_device *dev) | ||
{ | ||
device_del(&dev->dev); | ||
kfree(dev); | ||
} | ||
EXPORT_SYMBOL_GPL(serial_base_device_remove); | ||
|
||
static int serial_base_init(void) | ||
{ | ||
return bus_register(&serial_base_bus_type); | ||
} | ||
|
||
static void serial_base_exit(void) | ||
{ | ||
bus_unregister(&serial_base_bus_type); | ||
} | ||
|
||
module_init(serial_base_init); | ||
module_exit(serial_base_exit); | ||
|
||
MODULE_AUTHOR("Tony Lindgren <tony@atomide.com>"); | ||
MODULE_DESCRIPTION("Serial core bus"); | ||
MODULE_LICENSE("GPL"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
|
||
/* Serial core related functions, serial port device drivers do not need this. */ | ||
|
||
struct device; | ||
struct uart_driver; | ||
struct uart_port; | ||
|
||
struct serial_base_device { | ||
struct device dev; | ||
struct uart_port *port; | ||
}; | ||
|
||
#define to_serial_base_device(x) container_of((x), struct serial_base_device, dev) | ||
|
||
extern int serial_base_driver_register(struct device_driver *driver); | ||
extern void serial_base_driver_unregister(struct device_driver *driver); | ||
extern struct serial_base_device *serial_base_device_add(struct uart_port *port, | ||
const char *name, | ||
struct device *parent_dev); | ||
extern void serial_base_device_remove(struct serial_base_device *dev); | ||
|
||
extern int serial_ctrl_register_port(struct uart_driver *drv, struct uart_port *port); | ||
extern void serial_ctrl_unregister_port(struct uart_driver *drv, struct uart_port *port); | ||
|
||
extern int serial_core_register_port(struct uart_driver *drv, struct uart_port *port); | ||
extern void serial_core_unregister_port(struct uart_driver *drv, struct uart_port *port); |
Oops, something went wrong.