Rev 846 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1049 | mauro | 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 <linuxcomp.h> |
||
12 | |||
13 | #include <linux/config.h> |
||
14 | #include <linux/kernel.h> |
||
15 | #include <linux/errno.h> |
||
16 | #include <linux/tty.h> |
||
17 | #include <linux/module.h> |
||
18 | #include <linux/usb.h> |
||
19 | |||
20 | #ifdef CONFIG_USB_SERIAL_DEBUG |
||
21 | static int debug = 1; |
||
22 | #else |
||
23 | static int debug; |
||
24 | #endif |
||
25 | |||
26 | #include "usb-serial.h" |
||
27 | |||
28 | static int usb_serial_device_match (struct device *dev, struct device_driver *drv) |
||
29 | { |
||
30 | struct usb_serial_device_type *driver; |
||
31 | const struct usb_serial_port *port; |
||
32 | |||
33 | /* |
||
34 | * drivers are already assigned to ports in serial_probe so it's |
||
35 | * a simple check here. |
||
36 | */ |
||
37 | port = to_usb_serial_port(dev); |
||
38 | if (!port) |
||
39 | return 0; |
||
40 | |||
41 | driver = to_usb_serial_driver(drv); |
||
42 | |||
43 | if (driver == port->serial->type) |
||
44 | return 1; |
||
45 | |||
46 | return 0; |
||
47 | } |
||
48 | |||
49 | struct bus_type usb_serial_bus_type = { |
||
50 | .name = "usb-serial", |
||
51 | .match = usb_serial_device_match, |
||
52 | }; |
||
53 | |||
54 | static int usb_serial_device_probe (struct device *dev) |
||
55 | { |
||
56 | struct usb_serial_device_type *driver; |
||
57 | struct usb_serial_port *port; |
||
58 | int retval = 0; |
||
59 | int minor; |
||
60 | int i; |
||
61 | |||
62 | port = to_usb_serial_port(dev); |
||
63 | if (!port) { |
||
64 | retval = -ENODEV; |
||
65 | goto exit; |
||
66 | } |
||
67 | |||
68 | driver = port->serial->type; |
||
69 | if (driver->port_probe) { |
||
70 | if (!try_module_get(driver->owner)) { |
||
71 | dev_err(dev, "module get failed, exiting\n"); |
||
72 | retval = -EIO; |
||
73 | goto exit; |
||
74 | } |
||
75 | retval = driver->port_probe (port); |
||
76 | module_put(driver->owner); |
||
77 | if (retval) |
||
78 | goto exit; |
||
79 | } |
||
80 | |||
81 | minor = port->number; |
||
82 | tty_register_device (usb_serial_tty_driver, minor, dev); |
||
83 | dev_info(&port->serial->dev->dev, |
||
84 | "%s converter now attached to ttyUSB%d (or usb/tts/%d for devfs)\n", |
||
85 | driver->name, minor, minor); |
||
86 | /* for (i=0; i<20; i++) |
||
87 | printk("ttyusb%d\n", minor);*/ |
||
88 | |||
89 | exit: |
||
90 | return retval; |
||
91 | } |
||
92 | |||
93 | static int usb_serial_device_remove (struct device *dev) |
||
94 | { |
||
95 | struct usb_serial_device_type *driver; |
||
96 | struct usb_serial_port *port; |
||
97 | int retval = 0; |
||
98 | int minor; |
||
99 | |||
100 | port = to_usb_serial_port(dev); |
||
101 | if (!port) { |
||
102 | return -ENODEV; |
||
103 | } |
||
104 | |||
105 | driver = port->serial->type; |
||
106 | if (driver->port_remove) { |
||
107 | if (!try_module_get(driver->owner)) { |
||
108 | dev_err(dev, "module get failed, exiting\n"); |
||
109 | retval = -EIO; |
||
110 | goto exit; |
||
111 | } |
||
112 | retval = driver->port_remove (port); |
||
113 | module_put(driver->owner); |
||
114 | } |
||
115 | exit: |
||
116 | minor = port->number; |
||
117 | tty_unregister_device (usb_serial_tty_driver, minor); |
||
118 | dev_info(dev, "%s converter now disconnected from ttyUSB%d\n", |
||
119 | driver->name, minor); |
||
120 | |||
121 | return retval; |
||
122 | } |
||
123 | |||
124 | int usb_serial_bus_register(struct usb_serial_device_type *device) |
||
125 | { |
||
126 | int retval; |
||
127 | |||
128 | if (device->short_name) |
||
129 | device->driver.name = (char *)device->short_name; |
||
130 | else |
||
131 | device->driver.name = (char *)device->name; |
||
132 | device->driver.bus = &usb_serial_bus_type; |
||
133 | device->driver.probe = usb_serial_device_probe; |
||
134 | device->driver.remove = usb_serial_device_remove; |
||
135 | |||
136 | retval = driver_register(&device->driver); |
||
137 | |||
138 | return retval; |
||
139 | } |
||
140 | |||
141 | void usb_serial_bus_deregister(struct usb_serial_device_type *device) |
||
142 | { |
||
143 | driver_unregister (&device->driver); |
||
144 | } |
||
145 |