net/freescale: remove __dev* attributes
[linux/fpc-iii.git] / drivers / usb / serial / bus.c
blobc15f2e7cefc77e4782dfb39fcedc54e5b0bc6329
1 /*
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.
9 */
11 #include <linux/kernel.h>
12 #include <linux/errno.h>
13 #include <linux/tty.h>
14 #include <linux/slab.h>
15 #include <linux/module.h>
16 #include <linux/usb.h>
17 #include <linux/usb/serial.h>
19 static int usb_serial_device_match(struct device *dev,
20 struct device_driver *drv)
22 struct usb_serial_driver *driver;
23 const struct usb_serial_port *port;
26 * drivers are already assigned to ports in serial_probe so it's
27 * a simple check here.
29 port = to_usb_serial_port(dev);
30 if (!port)
31 return 0;
33 driver = to_usb_serial_driver(drv);
35 if (driver == port->serial->type)
36 return 1;
38 return 0;
41 static ssize_t show_port_number(struct device *dev,
42 struct device_attribute *attr, char *buf)
44 struct usb_serial_port *port = to_usb_serial_port(dev);
46 return sprintf(buf, "%d\n", port->number - port->serial->minor);
49 static DEVICE_ATTR(port_number, S_IRUGO, show_port_number, NULL);
51 static int usb_serial_device_probe(struct device *dev)
53 struct usb_serial_driver *driver;
54 struct usb_serial_port *port;
55 int retval = 0;
56 int minor;
58 port = to_usb_serial_port(dev);
59 if (!port) {
60 retval = -ENODEV;
61 goto exit;
64 /* make sure suspend/resume doesn't race against port_probe */
65 retval = usb_autopm_get_interface(port->serial->interface);
66 if (retval)
67 goto exit;
69 driver = port->serial->type;
70 if (driver->port_probe) {
71 retval = driver->port_probe(port);
72 if (retval)
73 goto exit_with_autopm;
76 retval = device_create_file(dev, &dev_attr_port_number);
77 if (retval) {
78 if (driver->port_remove)
79 retval = driver->port_remove(port);
80 goto exit_with_autopm;
83 minor = port->number;
84 tty_register_device(usb_serial_tty_driver, minor, dev);
85 dev_info(&port->serial->dev->dev,
86 "%s converter now attached to ttyUSB%d\n",
87 driver->description, minor);
89 exit_with_autopm:
90 usb_autopm_put_interface(port->serial->interface);
91 exit:
92 return retval;
95 static int usb_serial_device_remove(struct device *dev)
97 struct usb_serial_driver *driver;
98 struct usb_serial_port *port;
99 int retval = 0;
100 int minor;
102 port = to_usb_serial_port(dev);
103 if (!port)
104 return -ENODEV;
106 /* make sure suspend/resume doesn't race against port_remove */
107 usb_autopm_get_interface(port->serial->interface);
109 device_remove_file(&port->dev, &dev_attr_port_number);
111 driver = port->serial->type;
112 if (driver->port_remove)
113 retval = driver->port_remove(port);
115 minor = port->number;
116 tty_unregister_device(usb_serial_tty_driver, minor);
117 dev_info(dev, "%s converter now disconnected from ttyUSB%d\n",
118 driver->description, minor);
120 usb_autopm_put_interface(port->serial->interface);
121 return retval;
124 #ifdef CONFIG_HOTPLUG
125 static ssize_t store_new_id(struct device_driver *driver,
126 const char *buf, size_t count)
128 struct usb_serial_driver *usb_drv = to_usb_serial_driver(driver);
129 ssize_t retval = usb_store_new_id(&usb_drv->dynids, driver, buf, count);
131 if (retval >= 0 && usb_drv->usb_driver != NULL)
132 retval = usb_store_new_id(&usb_drv->usb_driver->dynids,
133 &usb_drv->usb_driver->drvwrap.driver,
134 buf, count);
135 return retval;
138 static ssize_t show_dynids(struct device_driver *driver, char *buf)
140 struct usb_serial_driver *usb_drv = to_usb_serial_driver(driver);
142 return usb_show_dynids(&usb_drv->dynids, buf);
145 static struct driver_attribute drv_attrs[] = {
146 __ATTR(new_id, S_IRUGO | S_IWUSR, show_dynids, store_new_id),
147 __ATTR_NULL,
150 static void free_dynids(struct usb_serial_driver *drv)
152 struct usb_dynid *dynid, *n;
154 spin_lock(&drv->dynids.lock);
155 list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) {
156 list_del(&dynid->node);
157 kfree(dynid);
159 spin_unlock(&drv->dynids.lock);
162 #else
163 static struct driver_attribute drv_attrs[] = {
164 __ATTR_NULL,
166 static inline void free_dynids(struct usb_serial_driver *drv)
169 #endif
171 struct bus_type usb_serial_bus_type = {
172 .name = "usb-serial",
173 .match = usb_serial_device_match,
174 .probe = usb_serial_device_probe,
175 .remove = usb_serial_device_remove,
176 .drv_attrs = drv_attrs,
179 int usb_serial_bus_register(struct usb_serial_driver *driver)
181 int retval;
183 driver->driver.bus = &usb_serial_bus_type;
184 spin_lock_init(&driver->dynids.lock);
185 INIT_LIST_HEAD(&driver->dynids.list);
187 retval = driver_register(&driver->driver);
189 return retval;
192 void usb_serial_bus_deregister(struct usb_serial_driver *driver)
194 free_dynids(driver);
195 driver_unregister(&driver->driver);