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. 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
ac9a786
commit 2f298f9
Showing
9 changed files
with
557 additions
and
27 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,35 @@ | ||
/* SPDX-License-Identifier: GPL-2.0+ */ | ||
/* | ||
* Serial core related functions, serial port device drivers do not need this. | ||
* | ||
* Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/ | ||
* Author: Tony Lindgren <tony@atomide.com> | ||
*/ | ||
|
||
struct uart_driver; | ||
struct uart_port; | ||
struct device_driver; | ||
struct device; | ||
|
||
int serial_base_ctrl_init(void); | ||
void serial_base_ctrl_exit(void); | ||
|
||
int serial_base_port_init(void); | ||
void serial_base_port_exit(void); | ||
|
||
int serial_base_driver_register(struct device_driver *driver); | ||
void serial_base_driver_unregister(struct device_driver *driver); | ||
|
||
struct device *serial_base_ctrl_add(struct uart_port *port, | ||
struct device *parent_dev); | ||
struct device *serial_base_port_add(struct uart_port *port, | ||
struct device *parent_dev); | ||
void serial_base_device_remove(struct device *dev); | ||
|
||
struct uart_port *serial_base_get_port(struct device *dev); | ||
|
||
int serial_ctrl_register_port(struct uart_driver *drv, struct uart_port *port); | ||
void serial_ctrl_unregister_port(struct uart_driver *drv, struct uart_port *port); | ||
|
||
int serial_core_register_port(struct uart_driver *drv, struct uart_port *port); | ||
void serial_core_unregister_port(struct uart_driver *drv, struct uart_port *port); |
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,179 @@ | ||
// SPDX-License-Identifier: GPL-2.0+ | ||
/* | ||
* Serial base bus layer for controllers | ||
* | ||
* Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/ | ||
* Author: Tony Lindgren <tony@atomide.com> | ||
* | ||
* The serial core bus manages the serial core controller instances. | ||
*/ | ||
|
||
#include <linux/container_of.h> | ||
#include <linux/device.h> | ||
#include <linux/module.h> | ||
#include <linux/serial_core.h> | ||
#include <linux/slab.h> | ||
#include <linux/spinlock.h> | ||
|
||
#include "serial_base.h" | ||
|
||
struct serial_base_device { | ||
struct device dev; | ||
struct uart_port *port; | ||
}; | ||
|
||
#define to_serial_base_device(d) container_of((d), struct serial_base_device, dev) | ||
|
||
struct uart_port *serial_base_get_port(struct device *dev) | ||
{ | ||
struct serial_base_device *sbd; | ||
|
||
if (!dev) | ||
return NULL; | ||
|
||
sbd = to_serial_base_device(dev); | ||
|
||
return sbd->port; | ||
} | ||
|
||
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); | ||
} | ||
|
||
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); | ||
} | ||
|
||
void serial_base_driver_unregister(struct device_driver *driver) | ||
{ | ||
driver_unregister(driver); | ||
} | ||
|
||
static void serial_base_release(struct device *dev) | ||
{ | ||
struct serial_base_device *sbd = to_serial_base_device(dev); | ||
|
||
kfree(sbd); | ||
} | ||
|
||
static const struct device_type serial_ctrl_type = { | ||
.name = "ctrl", | ||
}; | ||
|
||
static const struct device_type serial_port_type = { | ||
.name = "port", | ||
}; | ||
|
||
static struct device *serial_base_device_add(struct uart_port *port, | ||
struct device *parent_dev, | ||
const struct device_type *type) | ||
{ | ||
struct serial_base_device *sbd; | ||
int err, id; | ||
|
||
sbd = kzalloc(sizeof(*sbd), GFP_KERNEL); | ||
if (!sbd) | ||
return NULL; | ||
|
||
device_initialize(&sbd->dev); | ||
sbd->dev.type = type; | ||
sbd->dev.parent = parent_dev; | ||
sbd->dev.bus = &serial_base_bus_type; | ||
sbd->dev.release = &serial_base_release; | ||
|
||
if (type == &serial_ctrl_type) { | ||
id = port->ctrl_id; | ||
} else if (type == &serial_port_type) { | ||
id = port->line; | ||
sbd->port = port; | ||
} | ||
|
||
err = dev_set_name(&sbd->dev, "%s.%s.%d", type->name, dev_name(port->dev), id); | ||
if (err) | ||
goto err_free_dev; | ||
|
||
err = device_add(&sbd->dev); | ||
if (err) | ||
goto err_put_device; | ||
|
||
return &sbd->dev; | ||
|
||
err_put_device: | ||
put_device(&sbd->dev); | ||
|
||
err_free_dev: | ||
kfree(sbd); | ||
|
||
return NULL; | ||
} | ||
|
||
struct device *serial_base_ctrl_add(struct uart_port *port, | ||
struct device *parent_dev) | ||
{ | ||
return serial_base_device_add(port, parent_dev, &serial_ctrl_type); | ||
} | ||
|
||
struct device *serial_base_port_add(struct uart_port *port, | ||
struct device *parent_dev) | ||
{ | ||
return serial_base_device_add(port, parent_dev, &serial_port_type); | ||
} | ||
|
||
void serial_base_device_remove(struct device *dev) | ||
{ | ||
if (!dev) | ||
return; | ||
|
||
device_del(dev); | ||
} | ||
|
||
static int serial_base_init(void) | ||
{ | ||
int ret; | ||
|
||
ret = bus_register(&serial_base_bus_type); | ||
if (ret) | ||
return ret; | ||
|
||
ret = serial_base_ctrl_init(); | ||
if (ret) | ||
goto err_bus_unregister; | ||
|
||
ret = serial_base_port_init(); | ||
if (ret) | ||
goto err_ctrl_exit; | ||
|
||
return 0; | ||
|
||
err_ctrl_exit: | ||
serial_base_ctrl_exit(); | ||
|
||
err_bus_unregister: | ||
bus_unregister(&serial_base_bus_type); | ||
|
||
return ret; | ||
} | ||
module_init(serial_base_init); | ||
|
||
static void serial_base_exit(void) | ||
{ | ||
serial_base_port_exit(); | ||
serial_base_ctrl_exit(); | ||
bus_unregister(&serial_base_bus_type); | ||
} | ||
module_exit(serial_base_exit); | ||
|
||
MODULE_AUTHOR("Tony Lindgren <tony@atomide.com>"); | ||
MODULE_DESCRIPTION("Serial core bus"); | ||
MODULE_LICENSE("GPL"); |
Oops, something went wrong.