aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/bus.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/usb/serial/bus.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/usb/serial/bus.c')
-rw-r--r--drivers/usb/serial/bus.c134
1 files changed, 134 insertions, 0 deletions
diff --git a/drivers/usb/serial/bus.c b/drivers/usb/serial/bus.c
new file mode 100644
index 000000000000..2f612c2d894b
--- /dev/null
+++ b/drivers/usb/serial/bus.c
@@ -0,0 +1,134 @@
1/*
2 * USB Serial Converter Bus specific functions
3 *
4 * Copyright (C) 2002 Greg Kroah-Hartman (greg@kroah.com)
5 *
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.
9 */
10
11#include <linux/config.h>
12#include <linux/kernel.h>
13#include <linux/errno.h>
14#include <linux/tty.h>
15#include <linux/module.h>
16#include <linux/usb.h>
17#include "usb-serial.h"
18
19static int usb_serial_device_match (struct device *dev, struct device_driver *drv)
20{
21 struct usb_serial_device_type *driver;
22 const struct usb_serial_port *port;
23
24 /*
25 * drivers are already assigned to ports in serial_probe so it's
26 * a simple check here.
27 */
28 port = to_usb_serial_port(dev);
29 if (!port)
30 return 0;
31
32 driver = to_usb_serial_driver(drv);
33
34 if (driver == port->serial->type)
35 return 1;
36
37 return 0;
38}
39
40struct bus_type usb_serial_bus_type = {
41 .name = "usb-serial",
42 .match = usb_serial_device_match,
43};
44
45static int usb_serial_device_probe (struct device *dev)
46{
47 struct usb_serial_device_type *driver;
48 struct usb_serial_port *port;
49 int retval = 0;
50 int minor;
51
52 port = to_usb_serial_port(dev);
53 if (!port) {
54 retval = -ENODEV;
55 goto exit;
56 }
57
58 driver = port->serial->type;
59 if (driver->port_probe) {
60 if (!try_module_get(driver->owner)) {
61 dev_err(dev, "module get failed, exiting\n");
62 retval = -EIO;
63 goto exit;
64 }
65 retval = driver->port_probe (port);
66 module_put(driver->owner);
67 if (retval)
68 goto exit;
69 }
70
71 minor = port->number;
72 tty_register_device (usb_serial_tty_driver, minor, dev);
73 dev_info(&port->serial->dev->dev,
74 "%s converter now attached to ttyUSB%d\n",
75 driver->name, minor);
76
77exit:
78 return retval;
79}
80
81static int usb_serial_device_remove (struct device *dev)
82{
83 struct usb_serial_device_type *driver;
84 struct usb_serial_port *port;
85 int retval = 0;
86 int minor;
87
88 port = to_usb_serial_port(dev);
89 if (!port) {
90 return -ENODEV;
91 }
92
93 driver = port->serial->type;
94 if (driver->port_remove) {
95 if (!try_module_get(driver->owner)) {
96 dev_err(dev, "module get failed, exiting\n");
97 retval = -EIO;
98 goto exit;
99 }
100 retval = driver->port_remove (port);
101 module_put(driver->owner);
102 }
103exit:
104 minor = port->number;
105 tty_unregister_device (usb_serial_tty_driver, minor);
106 dev_info(dev, "%s converter now disconnected from ttyUSB%d\n",
107 driver->name, minor);
108
109 return retval;
110}
111
112int usb_serial_bus_register(struct usb_serial_device_type *device)
113{
114 int retval;
115
116 if (device->short_name)
117 device->driver.name = (char *)device->short_name;
118 else
119 device->driver.name = (char *)device->name;
120 device->driver.bus = &usb_serial_bus_type;
121 device->driver.probe = usb_serial_device_probe;
122 device->driver.remove = usb_serial_device_remove;
123 device->driver.owner = device->owner;
124
125 retval = driver_register(&device->driver);
126
127 return retval;
128}
129
130void usb_serial_bus_deregister(struct usb_serial_device_type *device)
131{
132 driver_unregister (&device->driver);
133}
134