4 * Copyright (C) 2012 Intel Corp
6 * Author: Lan Tianyu <tianyu.lan@intel.com>
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.
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
19 #include <linux/slab.h>
23 static const struct attribute_group *port_dev_group[];
25 static ssize_t show_port_connect_type(struct device *dev,
26 struct device_attribute *attr, char *buf)
28 struct usb_port *port_dev = to_usb_port(dev);
31 switch (port_dev->connect_type) {
32 case USB_PORT_CONNECT_TYPE_HOT_PLUG:
35 case USB_PORT_CONNECT_TYPE_HARD_WIRED:
38 case USB_PORT_NOT_USED:
46 return sprintf(buf, "%s\n", result);
48 static DEVICE_ATTR(connect_type, S_IRUGO, show_port_connect_type,
51 static struct attribute *port_dev_attrs[] = {
52 &dev_attr_connect_type.attr,
56 static struct attribute_group port_dev_attr_grp = {
57 .attrs = port_dev_attrs,
60 static const struct attribute_group *port_dev_group[] = {
65 static void usb_port_device_release(struct device *dev)
67 struct usb_port *port_dev = to_usb_port(dev);
72 struct device_type usb_port_device_type = {
74 .release = usb_port_device_release,
77 int usb_hub_create_port_device(struct usb_hub *hub, int port1)
79 struct usb_port *port_dev = NULL;
82 port_dev = kzalloc(sizeof(*port_dev), GFP_KERNEL);
88 hub->ports[port1 - 1] = port_dev;
89 port_dev->dev.parent = hub->intfdev;
90 port_dev->dev.groups = port_dev_group;
91 port_dev->dev.type = &usb_port_device_type;
92 dev_set_name(&port_dev->dev, "port%d", port1);
94 retval = device_register(&port_dev->dev);
101 put_device(&port_dev->dev);
106 void usb_hub_remove_port_device(struct usb_hub *hub,
109 device_unregister(&hub->ports[port1 - 1]->dev);