|
16 | 16 | #include <linux/bitops.h>
|
17 | 17 | #include <linux/delay.h>
|
18 | 18 | #include <linux/module.h>
|
| 19 | +#include <linux/serdev.h> |
19 | 20 |
|
20 | 21 | static int tty_port_default_receive_buf(struct tty_port *port,
|
21 | 22 | const unsigned char *p,
|
@@ -136,6 +137,80 @@ struct device *tty_port_register_device_attr(struct tty_port *port,
|
136 | 137 | }
|
137 | 138 | EXPORT_SYMBOL_GPL(tty_port_register_device_attr);
|
138 | 139 |
|
| 140 | +/** |
| 141 | + * tty_port_register_device_attr_serdev - register tty or serdev device |
| 142 | + * @port: tty_port of the device |
| 143 | + * @driver: tty_driver for this device |
| 144 | + * @index: index of the tty |
| 145 | + * @device: parent if exists, otherwise NULL |
| 146 | + * @drvdata: driver data for the device |
| 147 | + * @attr_grp: attribute group for the device |
| 148 | + * |
| 149 | + * Register a serdev or tty device depending on if the parent device has any |
| 150 | + * defined serdev clients or not. |
| 151 | + */ |
| 152 | +struct device *tty_port_register_device_attr_serdev(struct tty_port *port, |
| 153 | + struct tty_driver *driver, unsigned index, |
| 154 | + struct device *device, void *drvdata, |
| 155 | + const struct attribute_group **attr_grp) |
| 156 | +{ |
| 157 | + struct device *dev; |
| 158 | + |
| 159 | + tty_port_link_device(port, driver, index); |
| 160 | + |
| 161 | + dev = serdev_tty_port_register(port, device, driver, index); |
| 162 | + if (PTR_ERR(dev) != -ENODEV) { |
| 163 | + /* Skip creating cdev if we registered a serdev device */ |
| 164 | + return dev; |
| 165 | + } |
| 166 | + |
| 167 | + return tty_register_device_attr(driver, index, device, drvdata, |
| 168 | + attr_grp); |
| 169 | +} |
| 170 | +EXPORT_SYMBOL_GPL(tty_port_register_device_attr_serdev); |
| 171 | + |
| 172 | +/** |
| 173 | + * tty_port_register_device_serdev - register tty or serdev device |
| 174 | + * @port: tty_port of the device |
| 175 | + * @driver: tty_driver for this device |
| 176 | + * @index: index of the tty |
| 177 | + * @device: parent if exists, otherwise NULL |
| 178 | + * |
| 179 | + * Register a serdev or tty device depending on if the parent device has any |
| 180 | + * defined serdev clients or not. |
| 181 | + */ |
| 182 | +struct device *tty_port_register_device_serdev(struct tty_port *port, |
| 183 | + struct tty_driver *driver, unsigned index, |
| 184 | + struct device *device) |
| 185 | +{ |
| 186 | + return tty_port_register_device_attr_serdev(port, driver, index, |
| 187 | + device, NULL, NULL); |
| 188 | +} |
| 189 | +EXPORT_SYMBOL_GPL(tty_port_register_device_serdev); |
| 190 | + |
| 191 | +/** |
| 192 | + * tty_port_unregister_device - deregister a tty or serdev device |
| 193 | + * @port: tty_port of the device |
| 194 | + * @driver: tty_driver for this device |
| 195 | + * @index: index of the tty |
| 196 | + * |
| 197 | + * If a tty or serdev device is registered with a call to |
| 198 | + * tty_port_register_device_serdev() then this function must be called when |
| 199 | + * the device is gone. |
| 200 | + */ |
| 201 | +void tty_port_unregister_device(struct tty_port *port, |
| 202 | + struct tty_driver *driver, unsigned index) |
| 203 | +{ |
| 204 | + int ret; |
| 205 | + |
| 206 | + ret = serdev_tty_port_unregister(port); |
| 207 | + if (ret == 0) |
| 208 | + return; |
| 209 | + |
| 210 | + tty_unregister_device(driver, index); |
| 211 | +} |
| 212 | +EXPORT_SYMBOL_GPL(tty_port_unregister_device); |
| 213 | + |
139 | 214 | int tty_port_alloc_xmit_buf(struct tty_port *port)
|
140 | 215 | {
|
141 | 216 | /* We may sleep in get_zeroed_page() */
|
|
0 commit comments