2 * USB Serial Converter Bus specific functions
4 * Copyright (C) 2002 Greg Kroah-Hartman (greg@kroah.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
11 #include <linux/kernel.h>
12 #include <linux/errno.h>
13 #include <linux/tty.h>
14 #include <linux/module.h>
15 #include <linux/usb.h>
16 #include "usb-serial.h"
18 static int usb_serial_device_match (struct device *dev, struct device_driver *drv)
20 struct usb_serial_driver *driver;
21 const struct usb_serial_port *port;
24 * drivers are already assigned to ports in serial_probe so it's
25 * a simple check here.
27 port = to_usb_serial_port(dev);
31 driver = to_usb_serial_driver(drv);
33 if (driver == port->serial->type)
39 static int usb_serial_device_probe (struct device *dev)
41 struct usb_serial_driver *driver;
42 struct usb_serial_port *port;
46 port = to_usb_serial_port(dev);
52 driver = port->serial->type;
53 if (driver->port_probe) {
54 if (!try_module_get(driver->driver.owner)) {
55 dev_err(dev, "module get failed, exiting\n");
59 retval = driver->port_probe (port);
60 module_put(driver->driver.owner);
66 tty_register_device (usb_serial_tty_driver, minor, dev);
67 dev_info(&port->serial->dev->dev,
68 "%s converter now attached to ttyUSB%d\n",
69 driver->description, minor);
75 static int usb_serial_device_remove (struct device *dev)
77 struct usb_serial_driver *driver;
78 struct usb_serial_port *port;
82 port = to_usb_serial_port(dev);
87 driver = port->serial->type;
88 if (driver->port_remove) {
89 if (!try_module_get(driver->driver.owner)) {
90 dev_err(dev, "module get failed, exiting\n");
94 retval = driver->port_remove (port);
95 module_put(driver->driver.owner);
99 tty_unregister_device (usb_serial_tty_driver, minor);
100 dev_info(dev, "%s converter now disconnected from ttyUSB%d\n",
101 driver->description, minor);
106 struct bus_type usb_serial_bus_type = {
107 .name = "usb-serial",
108 .match = usb_serial_device_match,
109 .probe = usb_serial_device_probe,
110 .remove = usb_serial_device_remove,
113 int usb_serial_bus_register(struct usb_serial_driver *driver)
117 driver->driver.bus = &usb_serial_bus_type;
118 retval = driver_register(&driver->driver);
123 void usb_serial_bus_deregister(struct usb_serial_driver *driver)
125 driver_unregister(&driver->driver);