Subversion Repositories shark

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
846 giacomo 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
 
61
        port = to_usb_serial_port(dev);
62
        if (!port) {
63
                retval = -ENODEV;
64
                goto exit;
65
        }
66
 
67
        driver = port->serial->type;
68
        if (driver->port_probe) {
69
                if (!try_module_get(driver->owner)) {
70
                        dev_err(dev, "module get failed, exiting\n");
71
                        retval = -EIO;
72
                        goto exit;
73
                }
74
                retval = driver->port_probe (port);
75
                module_put(driver->owner);
76
                if (retval)
77
                        goto exit;
78
        }
79
 
80
        minor = port->number;
81
        tty_register_device (usb_serial_tty_driver, minor, dev);
82
        dev_info(&port->serial->dev->dev,
83
                 "%s converter now attached to ttyUSB%d (or usb/tts/%d for devfs)\n",
84
                 driver->name, minor, minor);
85
 
86
exit:
87
        return retval;
88
}
89
 
90
static int usb_serial_device_remove (struct device *dev)
91
{
92
        struct usb_serial_device_type *driver;
93
        struct usb_serial_port *port;
94
        int retval = 0;
95
        int minor;
96
 
97
        port = to_usb_serial_port(dev);
98
        if (!port) {
99
                return -ENODEV;
100
        }
101
 
102
        driver = port->serial->type;
103
        if (driver->port_remove) {
104
                if (!try_module_get(driver->owner)) {
105
                        dev_err(dev, "module get failed, exiting\n");
106
                        retval = -EIO;
107
                        goto exit;
108
                }
109
                retval = driver->port_remove (port);
110
                module_put(driver->owner);
111
        }
112
exit:
113
        minor = port->number;
114
        tty_unregister_device (usb_serial_tty_driver, minor);
115
        dev_info(dev, "%s converter now disconnected from ttyUSB%d\n",
116
                 driver->name, minor);
117
 
118
        return retval;
119
}
120
 
121
int usb_serial_bus_register(struct usb_serial_device_type *device)
122
{
123
        int retval;
124
 
125
        if (device->short_name)
126
                device->driver.name = (char *)device->short_name;
127
        else
128
                device->driver.name = (char *)device->name;
129
        device->driver.bus = &usb_serial_bus_type;
130
        device->driver.probe = usb_serial_device_probe;
131
        device->driver.remove = usb_serial_device_remove;
132
 
133
        retval = driver_register(&device->driver);
134
 
135
        return retval;
136
}
137
 
138
void usb_serial_bus_deregister(struct usb_serial_device_type *device)
139
{
140
        driver_unregister (&device->driver);
141
}
142