diff options
author | Lan Tianyu <tianyu.lan@intel.com> | 2013-01-11 07:10:38 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-01-18 18:49:00 -0500 |
commit | 6e30d7cba992d626c9d16b3873a7b90c700d0e95 (patch) | |
tree | 5e9ac38284a4a23c87ef51e884b428cb4ef86725 /drivers | |
parent | a29c408521b2b8969fead6aa3c7819800d6b473a (diff) |
usb: Add driver/usb/core/(port.c,hub.h) files
This patch is to create driver/usb/core/(port.c,hub.h) files and move usb
port related code into port.c.
Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/usb/core/Makefile | 1 | ||||
-rw-r--r-- | drivers/usb/core/hub.c | 107 | ||||
-rw-r--r-- | drivers/usb/core/hub.h | 97 | ||||
-rw-r--r-- | drivers/usb/core/port.c | 66 |
4 files changed, 165 insertions, 106 deletions
diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile index 26059b93dbf4..5e847ad2f58a 100644 --- a/drivers/usb/core/Makefile +++ b/drivers/usb/core/Makefile | |||
@@ -7,6 +7,7 @@ ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG | |||
7 | usbcore-y := usb.o hub.o hcd.o urb.o message.o driver.o | 7 | usbcore-y := usb.o hub.o hcd.o urb.o message.o driver.o |
8 | usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o | 8 | usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o |
9 | usbcore-y += devio.o notify.o generic.o quirks.o devices.o | 9 | usbcore-y += devio.o notify.o generic.o quirks.o devices.o |
10 | usbcore-y += port.o | ||
10 | 11 | ||
11 | usbcore-$(CONFIG_PCI) += hcd-pci.o | 12 | usbcore-$(CONFIG_PCI) += hcd-pci.o |
12 | usbcore-$(CONFIG_ACPI) += usb-acpi.o | 13 | usbcore-$(CONFIG_ACPI) += usb-acpi.o |
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index dc6ebd1d88da..f6ff1302f343 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -30,7 +30,7 @@ | |||
30 | #include <asm/uaccess.h> | 30 | #include <asm/uaccess.h> |
31 | #include <asm/byteorder.h> | 31 | #include <asm/byteorder.h> |
32 | 32 | ||
33 | #include "usb.h" | 33 | #include "hub.h" |
34 | 34 | ||
35 | /* if we are in debug mode, always announce new devices */ | 35 | /* if we are in debug mode, always announce new devices */ |
36 | #ifdef DEBUG | 36 | #ifdef DEBUG |
@@ -42,62 +42,6 @@ | |||
42 | #define USB_VENDOR_GENESYS_LOGIC 0x05e3 | 42 | #define USB_VENDOR_GENESYS_LOGIC 0x05e3 |
43 | #define HUB_QUIRK_CHECK_PORT_AUTOSUSPEND 0x01 | 43 | #define HUB_QUIRK_CHECK_PORT_AUTOSUSPEND 0x01 |
44 | 44 | ||
45 | struct usb_port { | ||
46 | struct usb_device *child; | ||
47 | struct device dev; | ||
48 | struct dev_state *port_owner; | ||
49 | enum usb_port_connect_type connect_type; | ||
50 | }; | ||
51 | |||
52 | struct usb_hub { | ||
53 | struct device *intfdev; /* the "interface" device */ | ||
54 | struct usb_device *hdev; | ||
55 | struct kref kref; | ||
56 | struct urb *urb; /* for interrupt polling pipe */ | ||
57 | |||
58 | /* buffer for urb ... with extra space in case of babble */ | ||
59 | char (*buffer)[8]; | ||
60 | union { | ||
61 | struct usb_hub_status hub; | ||
62 | struct usb_port_status port; | ||
63 | } *status; /* buffer for status reports */ | ||
64 | struct mutex status_mutex; /* for the status buffer */ | ||
65 | |||
66 | int error; /* last reported error */ | ||
67 | int nerrors; /* track consecutive errors */ | ||
68 | |||
69 | struct list_head event_list; /* hubs w/data or errs ready */ | ||
70 | unsigned long event_bits[1]; /* status change bitmask */ | ||
71 | unsigned long change_bits[1]; /* ports with logical connect | ||
72 | status change */ | ||
73 | unsigned long busy_bits[1]; /* ports being reset or | ||
74 | resumed */ | ||
75 | unsigned long removed_bits[1]; /* ports with a "removed" | ||
76 | device present */ | ||
77 | unsigned long wakeup_bits[1]; /* ports that have signaled | ||
78 | remote wakeup */ | ||
79 | #if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */ | ||
80 | #error event_bits[] is too short! | ||
81 | #endif | ||
82 | |||
83 | struct usb_hub_descriptor *descriptor; /* class descriptor */ | ||
84 | struct usb_tt tt; /* Transaction Translator */ | ||
85 | |||
86 | unsigned mA_per_port; /* current for each child */ | ||
87 | |||
88 | unsigned limited_power:1; | ||
89 | unsigned quiescing:1; | ||
90 | unsigned disconnected:1; | ||
91 | |||
92 | unsigned quirk_check_port_auto_suspend:1; | ||
93 | |||
94 | unsigned has_indicators:1; | ||
95 | u8 indicator[USB_MAXCHILDREN]; | ||
96 | struct delayed_work leds; | ||
97 | struct delayed_work init_work; | ||
98 | struct usb_port **ports; | ||
99 | }; | ||
100 | |||
101 | static inline int hub_is_superspeed(struct usb_device *hdev) | 45 | static inline int hub_is_superspeed(struct usb_device *hdev) |
102 | { | 46 | { |
103 | return (hdev->descriptor.bDeviceProtocol == USB_HUB_PR_SS); | 47 | return (hdev->descriptor.bDeviceProtocol == USB_HUB_PR_SS); |
@@ -168,9 +112,6 @@ EXPORT_SYMBOL_GPL(ehci_cf_port_reset_rwsem); | |||
168 | #define HUB_DEBOUNCE_STEP 25 | 112 | #define HUB_DEBOUNCE_STEP 25 |
169 | #define HUB_DEBOUNCE_STABLE 100 | 113 | #define HUB_DEBOUNCE_STABLE 100 |
170 | 114 | ||
171 | #define to_usb_port(_dev) \ | ||
172 | container_of(_dev, struct usb_port, dev) | ||
173 | |||
174 | static int usb_reset_and_verify_device(struct usb_device *udev); | 115 | static int usb_reset_and_verify_device(struct usb_device *udev); |
175 | 116 | ||
176 | static inline char *portspeed(struct usb_hub *hub, int portstatus) | 117 | static inline char *portspeed(struct usb_hub *hub, int portstatus) |
@@ -1294,52 +1235,6 @@ static int hub_post_reset(struct usb_interface *intf) | |||
1294 | return 0; | 1235 | return 0; |
1295 | } | 1236 | } |
1296 | 1237 | ||
1297 | static void usb_port_device_release(struct device *dev) | ||
1298 | { | ||
1299 | struct usb_port *port_dev = to_usb_port(dev); | ||
1300 | |||
1301 | kfree(port_dev); | ||
1302 | } | ||
1303 | |||
1304 | static void usb_hub_remove_port_device(struct usb_hub *hub, | ||
1305 | int port1) | ||
1306 | { | ||
1307 | device_unregister(&hub->ports[port1 - 1]->dev); | ||
1308 | } | ||
1309 | |||
1310 | struct device_type usb_port_device_type = { | ||
1311 | .name = "usb_port", | ||
1312 | .release = usb_port_device_release, | ||
1313 | }; | ||
1314 | |||
1315 | static int usb_hub_create_port_device(struct usb_hub *hub, | ||
1316 | int port1) | ||
1317 | { | ||
1318 | struct usb_port *port_dev = NULL; | ||
1319 | int retval; | ||
1320 | |||
1321 | port_dev = kzalloc(sizeof(*port_dev), GFP_KERNEL); | ||
1322 | if (!port_dev) { | ||
1323 | retval = -ENOMEM; | ||
1324 | goto exit; | ||
1325 | } | ||
1326 | |||
1327 | hub->ports[port1 - 1] = port_dev; | ||
1328 | port_dev->dev.parent = hub->intfdev; | ||
1329 | port_dev->dev.type = &usb_port_device_type; | ||
1330 | dev_set_name(&port_dev->dev, "port%d", port1); | ||
1331 | |||
1332 | retval = device_register(&port_dev->dev); | ||
1333 | if (retval) | ||
1334 | goto error_register; | ||
1335 | return 0; | ||
1336 | |||
1337 | error_register: | ||
1338 | put_device(&port_dev->dev); | ||
1339 | exit: | ||
1340 | return retval; | ||
1341 | } | ||
1342 | |||
1343 | static int hub_configure(struct usb_hub *hub, | 1238 | static int hub_configure(struct usb_hub *hub, |
1344 | struct usb_endpoint_descriptor *endpoint) | 1239 | struct usb_endpoint_descriptor *endpoint) |
1345 | { | 1240 | { |
diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h new file mode 100644 index 000000000000..d16a7c98aea9 --- /dev/null +++ b/drivers/usb/core/hub.h | |||
@@ -0,0 +1,97 @@ | |||
1 | /* | ||
2 | * usb hub driver head file | ||
3 | * | ||
4 | * Copyright (C) 1999 Linus Torvalds | ||
5 | * Copyright (C) 1999 Johannes Erdfelt | ||
6 | * Copyright (C) 1999 Gregory P. Smith | ||
7 | * Copyright (C) 2001 Brad Hards (bhards@bigpond.net.au) | ||
8 | * Copyright (C) 2012 Intel Corp (tianyu.lan@intel.com) | ||
9 | * | ||
10 | * move struct usb_hub to this file. | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify | ||
13 | * it under the terms of the GNU General Public License version 2 as | ||
14 | * published by the Free Software Foundation. | ||
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, but | ||
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
18 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
19 | * for more details. | ||
20 | */ | ||
21 | |||
22 | #include <linux/usb.h> | ||
23 | #include <linux/usb/ch11.h> | ||
24 | #include <linux/usb/hcd.h> | ||
25 | #include "usb.h" | ||
26 | |||
27 | struct usb_hub { | ||
28 | struct device *intfdev; /* the "interface" device */ | ||
29 | struct usb_device *hdev; | ||
30 | struct kref kref; | ||
31 | struct urb *urb; /* for interrupt polling pipe */ | ||
32 | |||
33 | /* buffer for urb ... with extra space in case of babble */ | ||
34 | char (*buffer)[8]; | ||
35 | union { | ||
36 | struct usb_hub_status hub; | ||
37 | struct usb_port_status port; | ||
38 | } *status; /* buffer for status reports */ | ||
39 | struct mutex status_mutex; /* for the status buffer */ | ||
40 | |||
41 | int error; /* last reported error */ | ||
42 | int nerrors; /* track consecutive errors */ | ||
43 | |||
44 | struct list_head event_list; /* hubs w/data or errs ready */ | ||
45 | unsigned long event_bits[1]; /* status change bitmask */ | ||
46 | unsigned long change_bits[1]; /* ports with logical connect | ||
47 | status change */ | ||
48 | unsigned long busy_bits[1]; /* ports being reset or | ||
49 | resumed */ | ||
50 | unsigned long removed_bits[1]; /* ports with a "removed" | ||
51 | device present */ | ||
52 | unsigned long wakeup_bits[1]; /* ports that have signaled | ||
53 | remote wakeup */ | ||
54 | #if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */ | ||
55 | #error event_bits[] is too short! | ||
56 | #endif | ||
57 | |||
58 | struct usb_hub_descriptor *descriptor; /* class descriptor */ | ||
59 | struct usb_tt tt; /* Transaction Translator */ | ||
60 | |||
61 | unsigned mA_per_port; /* current for each child */ | ||
62 | |||
63 | unsigned limited_power:1; | ||
64 | unsigned quiescing:1; | ||
65 | unsigned disconnected:1; | ||
66 | |||
67 | unsigned quirk_check_port_auto_suspend:1; | ||
68 | |||
69 | unsigned has_indicators:1; | ||
70 | u8 indicator[USB_MAXCHILDREN]; | ||
71 | struct delayed_work leds; | ||
72 | struct delayed_work init_work; | ||
73 | struct usb_port **ports; | ||
74 | }; | ||
75 | |||
76 | /** | ||
77 | * struct usb port - kernel's representation of a usb port | ||
78 | * @child: usb device attatched to the port | ||
79 | * @dev: generic device interface | ||
80 | * @port_owner: port's owner | ||
81 | * @connect_type: port's connect type | ||
82 | */ | ||
83 | struct usb_port { | ||
84 | struct usb_device *child; | ||
85 | struct device dev; | ||
86 | struct dev_state *port_owner; | ||
87 | enum usb_port_connect_type connect_type; | ||
88 | }; | ||
89 | |||
90 | #define to_usb_port(_dev) \ | ||
91 | container_of(_dev, struct usb_port, dev) | ||
92 | |||
93 | extern int usb_hub_create_port_device(struct usb_hub *hub, | ||
94 | int port1); | ||
95 | extern void usb_hub_remove_port_device(struct usb_hub *hub, | ||
96 | int port1); | ||
97 | |||
diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c new file mode 100644 index 000000000000..2bc1cef4e478 --- /dev/null +++ b/drivers/usb/core/port.c | |||
@@ -0,0 +1,66 @@ | |||
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 | |||