@@ -139,12 +139,79 @@ static struct acpi_device *usb_acpi_find_port(struct acpi_device *parent,
139
139
return acpi_find_child_device (parent , raw , false);
140
140
}
141
141
142
- static struct acpi_device * usb_acpi_find_companion (struct device * dev )
142
+ static struct acpi_device *
143
+ usb_acpi_get_companion_for_port (struct usb_port * port_dev )
143
144
{
144
145
struct usb_device * udev ;
145
146
struct acpi_device * adev ;
146
147
acpi_handle * parent_handle ;
148
+ int port1 ;
149
+
150
+ /* Get the struct usb_device point of port's hub */
151
+ udev = to_usb_device (port_dev -> dev .parent -> parent );
152
+
153
+ /*
154
+ * The root hub ports' parent is the root hub. The non-root-hub
155
+ * ports' parent is the parent hub port which the hub is
156
+ * connected to.
157
+ */
158
+ if (!udev -> parent ) {
159
+ adev = ACPI_COMPANION (& udev -> dev );
160
+ port1 = usb_hcd_find_raw_port_number (bus_to_hcd (udev -> bus ),
161
+ port_dev -> portnum );
162
+ } else {
163
+ parent_handle = usb_get_hub_port_acpi_handle (udev -> parent ,
164
+ udev -> portnum );
165
+ if (!parent_handle )
166
+ return NULL ;
167
+
168
+ acpi_bus_get_device (parent_handle , & adev );
169
+ port1 = port_dev -> portnum ;
170
+ }
171
+
172
+ return usb_acpi_find_port (adev , port1 );
173
+ }
174
+
175
+ static struct acpi_device *
176
+ usb_acpi_find_companion_for_port (struct usb_port * port_dev )
177
+ {
178
+ struct acpi_device * adev ;
179
+ struct acpi_pld_info * pld ;
180
+ acpi_handle * handle ;
181
+ acpi_status status ;
182
+
183
+ adev = usb_acpi_get_companion_for_port (port_dev );
184
+ if (!adev )
185
+ return NULL ;
186
+
187
+ handle = adev -> handle ;
188
+ status = acpi_get_physical_device_location (handle , & pld );
189
+ if (!ACPI_FAILURE (status ) && pld ) {
190
+ port_dev -> location = USB_ACPI_LOCATION_VALID
191
+ | pld -> group_token << 8 | pld -> group_position ;
192
+ port_dev -> connect_type = usb_acpi_get_connect_type (handle , pld );
193
+ ACPI_FREE (pld );
194
+ }
147
195
196
+ return adev ;
197
+ }
198
+
199
+ static struct acpi_device *
200
+ usb_acpi_find_companion_for_device (struct usb_device * udev )
201
+ {
202
+ struct acpi_device * adev ;
203
+
204
+ if (!udev -> parent )
205
+ return NULL ;
206
+
207
+ /* root hub is only child (_ADR=0) under its parent, the HC */
208
+ adev = ACPI_COMPANION (udev -> dev .parent );
209
+ return acpi_find_child_device (adev , 0 , false);
210
+ }
211
+
212
+
213
+ static struct acpi_device * usb_acpi_find_companion (struct device * dev )
214
+ {
148
215
/*
149
216
* In the ACPI DSDT table, only usb root hub and usb ports are
150
217
* acpi device nodes. The hierarchy like following.
@@ -158,66 +225,10 @@ static struct acpi_device *usb_acpi_find_companion(struct device *dev)
158
225
* So all binding process is divided into two parts. binding
159
226
* root hub and usb ports.
160
227
*/
161
- if (is_usb_device (dev )) {
162
- udev = to_usb_device (dev );
163
- if (udev -> parent )
164
- return NULL ;
165
-
166
- /* root hub is only child (_ADR=0) under its parent, the HC */
167
- adev = ACPI_COMPANION (dev -> parent );
168
- return acpi_find_child_device (adev , 0 , false);
169
- } else if (is_usb_port (dev )) {
170
- struct usb_port * port_dev = to_usb_port (dev );
171
- int port1 = port_dev -> portnum ;
172
- struct acpi_pld_info * pld ;
173
- acpi_handle * handle ;
174
- acpi_status status ;
175
-
176
- /* Get the struct usb_device point of port's hub */
177
- udev = to_usb_device (dev -> parent -> parent );
178
-
179
- /*
180
- * The root hub ports' parent is the root hub. The non-root-hub
181
- * ports' parent is the parent hub port which the hub is
182
- * connected to.
183
- */
184
- if (!udev -> parent ) {
185
- struct usb_hcd * hcd = bus_to_hcd (udev -> bus );
186
- int raw ;
187
-
188
- raw = usb_hcd_find_raw_port_number (hcd , port1 );
189
-
190
- adev = usb_acpi_find_port (ACPI_COMPANION (& udev -> dev ),
191
- raw );
192
-
193
- if (!adev )
194
- return NULL ;
195
- } else {
196
- parent_handle =
197
- usb_get_hub_port_acpi_handle (udev -> parent ,
198
- udev -> portnum );
199
- if (!parent_handle )
200
- return NULL ;
201
-
202
- acpi_bus_get_device (parent_handle , & adev );
203
-
204
- adev = usb_acpi_find_port (adev , port1 );
205
-
206
- if (!adev )
207
- return NULL ;
208
- }
209
- handle = adev -> handle ;
210
- status = acpi_get_physical_device_location (handle , & pld );
211
- if (ACPI_FAILURE (status ) || !pld )
212
- return adev ;
213
-
214
- port_dev -> location = USB_ACPI_LOCATION_VALID
215
- | pld -> group_token << 8 | pld -> group_position ;
216
- port_dev -> connect_type = usb_acpi_get_connect_type (handle , pld );
217
- ACPI_FREE (pld );
218
-
219
- return adev ;
220
- }
228
+ if (is_usb_device (dev ))
229
+ return usb_acpi_find_companion_for_device (to_usb_device (dev ));
230
+ else if (is_usb_port (dev ))
231
+ return usb_acpi_find_companion_for_port (to_usb_port (dev ));
221
232
222
233
return NULL ;
223
234
}
0 commit comments