| .. | .. |
|---|
| 86 | 86 | { |
|---|
| 87 | 87 | enum usb_port_connect_type connect_type = USB_PORT_CONNECT_TYPE_UNKNOWN; |
|---|
| 88 | 88 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
|---|
| 89 | | - union acpi_object *upc; |
|---|
| 89 | + union acpi_object *upc = NULL; |
|---|
| 90 | 90 | acpi_status status; |
|---|
| 91 | 91 | |
|---|
| 92 | 92 | /* |
|---|
| .. | .. |
|---|
| 98 | 98 | * no connectable, the port would be not used. |
|---|
| 99 | 99 | */ |
|---|
| 100 | 100 | status = acpi_evaluate_object(handle, "_UPC", NULL, &buffer); |
|---|
| 101 | | - upc = buffer.pointer; |
|---|
| 102 | | - if (!upc || (upc->type != ACPI_TYPE_PACKAGE) |
|---|
| 103 | | - || upc->package.count != 4) { |
|---|
| 101 | + if (ACPI_FAILURE(status)) |
|---|
| 104 | 102 | goto out; |
|---|
| 105 | | - } |
|---|
| 103 | + |
|---|
| 104 | + upc = buffer.pointer; |
|---|
| 105 | + if (!upc || (upc->type != ACPI_TYPE_PACKAGE) || upc->package.count != 4) |
|---|
| 106 | + goto out; |
|---|
| 106 | 107 | |
|---|
| 107 | 108 | if (upc->package.elements[0].integer.value) |
|---|
| 108 | 109 | if (pld->user_visible) |
|---|
| .. | .. |
|---|
| 139 | 140 | return acpi_find_child_device(parent, raw, false); |
|---|
| 140 | 141 | } |
|---|
| 141 | 142 | |
|---|
| 142 | | -static struct acpi_device *usb_acpi_find_companion(struct device *dev) |
|---|
| 143 | +static struct acpi_device * |
|---|
| 144 | +usb_acpi_get_companion_for_port(struct usb_port *port_dev) |
|---|
| 143 | 145 | { |
|---|
| 144 | 146 | struct usb_device *udev; |
|---|
| 145 | 147 | struct acpi_device *adev; |
|---|
| 146 | 148 | acpi_handle *parent_handle; |
|---|
| 149 | + int port1; |
|---|
| 150 | + |
|---|
| 151 | + /* Get the struct usb_device point of port's hub */ |
|---|
| 152 | + udev = to_usb_device(port_dev->dev.parent->parent); |
|---|
| 147 | 153 | |
|---|
| 148 | 154 | /* |
|---|
| 149 | | - * In the ACPI DSDT table, only usb root hub and usb ports are |
|---|
| 150 | | - * acpi device nodes. The hierarchy like following. |
|---|
| 155 | + * The root hub ports' parent is the root hub. The non-root-hub |
|---|
| 156 | + * ports' parent is the parent hub port which the hub is |
|---|
| 157 | + * connected to. |
|---|
| 158 | + */ |
|---|
| 159 | + if (!udev->parent) { |
|---|
| 160 | + adev = ACPI_COMPANION(&udev->dev); |
|---|
| 161 | + port1 = usb_hcd_find_raw_port_number(bus_to_hcd(udev->bus), |
|---|
| 162 | + port_dev->portnum); |
|---|
| 163 | + } else { |
|---|
| 164 | + parent_handle = usb_get_hub_port_acpi_handle(udev->parent, |
|---|
| 165 | + udev->portnum); |
|---|
| 166 | + if (!parent_handle) |
|---|
| 167 | + return NULL; |
|---|
| 168 | + |
|---|
| 169 | + acpi_bus_get_device(parent_handle, &adev); |
|---|
| 170 | + port1 = port_dev->portnum; |
|---|
| 171 | + } |
|---|
| 172 | + |
|---|
| 173 | + return usb_acpi_find_port(adev, port1); |
|---|
| 174 | +} |
|---|
| 175 | + |
|---|
| 176 | +static struct acpi_device * |
|---|
| 177 | +usb_acpi_find_companion_for_port(struct usb_port *port_dev) |
|---|
| 178 | +{ |
|---|
| 179 | + struct acpi_device *adev; |
|---|
| 180 | + struct acpi_pld_info *pld; |
|---|
| 181 | + acpi_handle *handle; |
|---|
| 182 | + acpi_status status; |
|---|
| 183 | + |
|---|
| 184 | + adev = usb_acpi_get_companion_for_port(port_dev); |
|---|
| 185 | + if (!adev) |
|---|
| 186 | + return NULL; |
|---|
| 187 | + |
|---|
| 188 | + handle = adev->handle; |
|---|
| 189 | + status = acpi_get_physical_device_location(handle, &pld); |
|---|
| 190 | + if (ACPI_SUCCESS(status) && pld) { |
|---|
| 191 | + port_dev->location = USB_ACPI_LOCATION_VALID |
|---|
| 192 | + | pld->group_token << 8 | pld->group_position; |
|---|
| 193 | + port_dev->connect_type = usb_acpi_get_connect_type(handle, pld); |
|---|
| 194 | + ACPI_FREE(pld); |
|---|
| 195 | + } |
|---|
| 196 | + |
|---|
| 197 | + return adev; |
|---|
| 198 | +} |
|---|
| 199 | + |
|---|
| 200 | +static struct acpi_device * |
|---|
| 201 | +usb_acpi_find_companion_for_device(struct usb_device *udev) |
|---|
| 202 | +{ |
|---|
| 203 | + struct acpi_device *adev; |
|---|
| 204 | + struct usb_port *port_dev; |
|---|
| 205 | + struct usb_hub *hub; |
|---|
| 206 | + |
|---|
| 207 | + if (!udev->parent) { |
|---|
| 208 | + /* root hub is only child (_ADR=0) under its parent, the HC */ |
|---|
| 209 | + adev = ACPI_COMPANION(udev->dev.parent); |
|---|
| 210 | + return acpi_find_child_device(adev, 0, false); |
|---|
| 211 | + } |
|---|
| 212 | + |
|---|
| 213 | + hub = usb_hub_to_struct_hub(udev->parent); |
|---|
| 214 | + if (!hub) |
|---|
| 215 | + return NULL; |
|---|
| 216 | + |
|---|
| 217 | + /* |
|---|
| 218 | + * This is an embedded USB device connected to a port and such |
|---|
| 219 | + * devices share port's ACPI companion. |
|---|
| 220 | + */ |
|---|
| 221 | + port_dev = hub->ports[udev->portnum - 1]; |
|---|
| 222 | + return usb_acpi_get_companion_for_port(port_dev); |
|---|
| 223 | +} |
|---|
| 224 | + |
|---|
| 225 | +static struct acpi_device *usb_acpi_find_companion(struct device *dev) |
|---|
| 226 | +{ |
|---|
| 227 | + /* |
|---|
| 228 | + * The USB hierarchy like following: |
|---|
| 229 | + * |
|---|
| 151 | 230 | * Device (EHC1) |
|---|
| 152 | 231 | * Device (HUBN) |
|---|
| 153 | 232 | * Device (PR01) |
|---|
| 154 | 233 | * Device (PR11) |
|---|
| 155 | 234 | * Device (PR12) |
|---|
| 235 | + * Device (FN12) |
|---|
| 236 | + * Device (FN13) |
|---|
| 156 | 237 | * Device (PR13) |
|---|
| 157 | 238 | * ... |
|---|
| 158 | | - * So all binding process is divided into two parts. binding |
|---|
| 159 | | - * root hub and usb ports. |
|---|
| 239 | + * where HUBN is root hub, and PRNN are USB ports and devices |
|---|
| 240 | + * connected to them, and FNNN are individualk functions for |
|---|
| 241 | + * connected composite USB devices. PRNN and FNNN may contain |
|---|
| 242 | + * _CRS and other methods describing sideband resources for |
|---|
| 243 | + * the connected device. |
|---|
| 244 | + * |
|---|
| 245 | + * On the kernel side both root hub and embedded USB devices are |
|---|
| 246 | + * represented as instances of usb_device structure, and ports |
|---|
| 247 | + * are represented as usb_port structures, so the whole process |
|---|
| 248 | + * is split into 2 parts: finding companions for devices and |
|---|
| 249 | + * finding companions for ports. |
|---|
| 250 | + * |
|---|
| 251 | + * Note that we do not handle individual functions of composite |
|---|
| 252 | + * devices yet, for that we would need to assign companions to |
|---|
| 253 | + * devices corresponding to USB interfaces. |
|---|
| 160 | 254 | */ |
|---|
| 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 | | - } |
|---|
| 255 | + if (is_usb_device(dev)) |
|---|
| 256 | + return usb_acpi_find_companion_for_device(to_usb_device(dev)); |
|---|
| 257 | + else if (is_usb_port(dev)) |
|---|
| 258 | + return usb_acpi_find_companion_for_port(to_usb_port(dev)); |
|---|
| 221 | 259 | |
|---|
| 222 | 260 | return NULL; |
|---|
| 223 | 261 | } |
|---|