PM/Qos: Expose dev_pm_qos_flags symbol
[linux-2.6-block.git] / drivers / usb / core / port.c
CommitLineData
6e30d7cb
LT
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
9f7344fb
LT
19#include <linux/slab.h>
20
6e30d7cb
LT
21#include "hub.h"
22
cef7468c
LT
23static const struct attribute_group *port_dev_group[];
24
25static ssize_t show_port_connect_type(struct device *dev,
26 struct device_attribute *attr, char *buf)
27{
28 struct usb_port *port_dev = to_usb_port(dev);
29 char *result;
30
31 switch (port_dev->connect_type) {
32 case USB_PORT_CONNECT_TYPE_HOT_PLUG:
33 result = "hotplug";
34 break;
35 case USB_PORT_CONNECT_TYPE_HARD_WIRED:
36 result = "hardwired";
37 break;
38 case USB_PORT_NOT_USED:
39 result = "not used";
40 break;
41 default:
42 result = "unknown";
43 break;
44 }
45
46 return sprintf(buf, "%s\n", result);
47}
48static DEVICE_ATTR(connect_type, S_IRUGO, show_port_connect_type,
49 NULL);
50
51static struct attribute *port_dev_attrs[] = {
52 &dev_attr_connect_type.attr,
53 NULL,
54};
55
56static struct attribute_group port_dev_attr_grp = {
57 .attrs = port_dev_attrs,
58};
59
60static const struct attribute_group *port_dev_group[] = {
61 &port_dev_attr_grp,
62 NULL,
63};
64
6e30d7cb
LT
65static void usb_port_device_release(struct device *dev)
66{
67 struct usb_port *port_dev = to_usb_port(dev);
68
88bb965e 69 usb_acpi_unregister_power_resources(dev);
6e30d7cb
LT
70 kfree(port_dev);
71}
72
73struct device_type usb_port_device_type = {
74 .name = "usb_port",
75 .release = usb_port_device_release,
76};
77
78int usb_hub_create_port_device(struct usb_hub *hub, int port1)
79{
80 struct usb_port *port_dev = NULL;
81 int retval;
82
83 port_dev = kzalloc(sizeof(*port_dev), GFP_KERNEL);
84 if (!port_dev) {
85 retval = -ENOMEM;
86 goto exit;
87 }
88
89 hub->ports[port1 - 1] = port_dev;
90 port_dev->dev.parent = hub->intfdev;
cef7468c 91 port_dev->dev.groups = port_dev_group;
6e30d7cb
LT
92 port_dev->dev.type = &usb_port_device_type;
93 dev_set_name(&port_dev->dev, "port%d", port1);
94
95 retval = device_register(&port_dev->dev);
96 if (retval)
97 goto error_register;
98
88bb965e
LT
99 retval = usb_acpi_register_power_resources(&port_dev->dev);
100 if (retval && retval != -ENODEV)
101 dev_warn(&port_dev->dev, "the port can't register its ACPI power resource.\n");
102
6e30d7cb
LT
103 return 0;
104
105error_register:
106 put_device(&port_dev->dev);
107exit:
108 return retval;
109}
110
111void usb_hub_remove_port_device(struct usb_hub *hub,
112 int port1)
113{
114 device_unregister(&hub->ports[port1 - 1]->dev);
115}
116