usb: Add driver/usb/core/(port.c,hub.h) files
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / usb / core / port.c
1 /*
2  * usb port device code
3  *
4  * Copyright (C) 2012 Intel Corp
5  *
6  * Author: Lan Tianyu <tianyu.lan@intel.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15  * for more details.
16  *
17  */
18
19 #include "hub.h"
20
21 static void usb_port_device_release(struct device *dev)
22 {
23         struct usb_port *port_dev = to_usb_port(dev);
24
25         kfree(port_dev);
26 }
27
28 struct device_type usb_port_device_type = {
29         .name =         "usb_port",
30         .release =      usb_port_device_release,
31 };
32
33 int usb_hub_create_port_device(struct usb_hub *hub, int port1)
34 {
35         struct usb_port *port_dev = NULL;
36         int retval;
37
38         port_dev = kzalloc(sizeof(*port_dev), GFP_KERNEL);
39         if (!port_dev) {
40                 retval = -ENOMEM;
41                 goto exit;
42         }
43
44         hub->ports[port1 - 1] = port_dev;
45         port_dev->dev.parent = hub->intfdev;
46         port_dev->dev.type = &usb_port_device_type;
47         dev_set_name(&port_dev->dev, "port%d", port1);
48
49         retval = device_register(&port_dev->dev);
50         if (retval)
51                 goto error_register;
52
53         return 0;
54
55 error_register:
56         put_device(&port_dev->dev);
57 exit:
58         return retval;
59 }
60
61 void usb_hub_remove_port_device(struct usb_hub *hub,
62                                        int port1)
63 {
64         device_unregister(&hub->ports[port1 - 1]->dev);
65 }
66