Lines Matching +full:self +full:- +full:powered

1 // SPDX-License-Identifier: GPL-2.0+
3 * Driver for Microchip USB251xB USB 2.0 Hi-Speed Hub Controller
9 * a not-accepted patch by Fabien Lahoudere, see:
110 #define DRIVER_DESC "Microchip USB 2.0 Hi-Speed Hub Controller"
234 if (dev->type == &i2c_adapter_type) { in usb251xb_check_dev_children()
244 struct gpio_chip *gc = gpiod_to_chip(hub->gpio_reset); in usb251x_check_gpio_chip()
245 struct i2c_adapter *adap = hub->i2c->adapter; in usb251x_check_gpio_chip()
248 if (!hub->gpio_reset) in usb251x_check_gpio_chip()
252 return -EINVAL; in usb251x_check_gpio_chip()
254 ret = usb251xb_check_dev_children(&adap->dev, gc->parent); in usb251x_check_gpio_chip()
256 dev_err(hub->dev, "Reset GPIO chip is at the same i2c-bus\n"); in usb251x_check_gpio_chip()
257 return -EINVAL; in usb251x_check_gpio_chip()
271 if (!hub->gpio_reset) in usb251xb_reset()
274 i2c_lock_bus(hub->i2c->adapter, I2C_LOCK_SEGMENT); in usb251xb_reset()
276 gpiod_set_value_cansleep(hub->gpio_reset, 1); in usb251xb_reset()
278 gpiod_set_value_cansleep(hub->gpio_reset, 0); in usb251xb_reset()
283 i2c_unlock_bus(hub->i2c->adapter, I2C_LOCK_SEGMENT); in usb251xb_reset()
288 struct device *dev = hub->dev; in usb251xb_connect()
294 if (hub->skip_config) { in usb251xb_connect()
301 err = i2c_smbus_write_i2c_block_data(hub->i2c, in usb251xb_connect()
310 i2c_wb[USB251XB_ADDR_VENDOR_ID_MSB] = (hub->vendor_id >> 8) & 0xFF; in usb251xb_connect()
311 i2c_wb[USB251XB_ADDR_VENDOR_ID_LSB] = hub->vendor_id & 0xFF; in usb251xb_connect()
312 i2c_wb[USB251XB_ADDR_PRODUCT_ID_MSB] = (hub->product_id >> 8) & 0xFF; in usb251xb_connect()
313 i2c_wb[USB251XB_ADDR_PRODUCT_ID_LSB] = hub->product_id & 0xFF; in usb251xb_connect()
314 i2c_wb[USB251XB_ADDR_DEVICE_ID_MSB] = (hub->device_id >> 8) & 0xFF; in usb251xb_connect()
315 i2c_wb[USB251XB_ADDR_DEVICE_ID_LSB] = hub->device_id & 0xFF; in usb251xb_connect()
316 i2c_wb[USB251XB_ADDR_CONFIG_DATA_1] = hub->conf_data1; in usb251xb_connect()
317 i2c_wb[USB251XB_ADDR_CONFIG_DATA_2] = hub->conf_data2; in usb251xb_connect()
318 i2c_wb[USB251XB_ADDR_CONFIG_DATA_3] = hub->conf_data3; in usb251xb_connect()
319 i2c_wb[USB251XB_ADDR_NON_REMOVABLE_DEVICES] = hub->non_rem_dev; in usb251xb_connect()
320 i2c_wb[USB251XB_ADDR_PORT_DISABLE_SELF] = hub->port_disable_sp; in usb251xb_connect()
321 i2c_wb[USB251XB_ADDR_PORT_DISABLE_BUS] = hub->port_disable_bp; in usb251xb_connect()
322 i2c_wb[USB251XB_ADDR_MAX_POWER_SELF] = hub->max_power_sp; in usb251xb_connect()
323 i2c_wb[USB251XB_ADDR_MAX_POWER_BUS] = hub->max_power_bp; in usb251xb_connect()
324 i2c_wb[USB251XB_ADDR_MAX_CURRENT_SELF] = hub->max_current_sp; in usb251xb_connect()
325 i2c_wb[USB251XB_ADDR_MAX_CURRENT_BUS] = hub->max_current_bp; in usb251xb_connect()
326 i2c_wb[USB251XB_ADDR_POWER_ON_TIME] = hub->power_on_time; in usb251xb_connect()
327 i2c_wb[USB251XB_ADDR_LANGUAGE_ID_HIGH] = (hub->lang_id >> 8) & 0xFF; in usb251xb_connect()
328 i2c_wb[USB251XB_ADDR_LANGUAGE_ID_LOW] = hub->lang_id & 0xFF; in usb251xb_connect()
329 i2c_wb[USB251XB_ADDR_MANUFACTURER_STRING_LEN] = hub->manufacturer_len; in usb251xb_connect()
330 i2c_wb[USB251XB_ADDR_PRODUCT_STRING_LEN] = hub->product_len; in usb251xb_connect()
331 i2c_wb[USB251XB_ADDR_SERIAL_STRING_LEN] = hub->serial_len; in usb251xb_connect()
332 memcpy(&i2c_wb[USB251XB_ADDR_MANUFACTURER_STRING], hub->manufacturer, in usb251xb_connect()
334 memcpy(&i2c_wb[USB251XB_ADDR_SERIAL_STRING], hub->serial, in usb251xb_connect()
336 memcpy(&i2c_wb[USB251XB_ADDR_PRODUCT_STRING], hub->product, in usb251xb_connect()
338 i2c_wb[USB251XB_ADDR_BATTERY_CHARGING_ENABLE] = hub->bat_charge_en; in usb251xb_connect()
339 i2c_wb[USB251XB_ADDR_BOOST_UP] = hub->boost_up; in usb251xb_connect()
340 i2c_wb[USB251XB_ADDR_BOOST_57] = hub->boost_57; in usb251xb_connect()
341 i2c_wb[USB251XB_ADDR_BOOST_14] = hub->boost_14; in usb251xb_connect()
342 i2c_wb[USB251XB_ADDR_PORT_SWAP] = hub->port_swap; in usb251xb_connect()
343 i2c_wb[USB251XB_ADDR_PORT_MAP_12] = hub->port_map12; in usb251xb_connect()
344 i2c_wb[USB251XB_ADDR_PORT_MAP_34] = hub->port_map34; in usb251xb_connect()
345 i2c_wb[USB251XB_ADDR_PORT_MAP_56] = hub->port_map56; in usb251xb_connect()
346 i2c_wb[USB251XB_ADDR_PORT_MAP_7] = hub->port_map7; in usb251xb_connect()
365 err = i2c_smbus_write_i2c_block_data(hub->i2c, offset, in usb251xb_connect()
385 struct device *dev = hub->dev; in usb251xb_get_ports_field()
390 of_property_for_each_u32(dev->of_node, prop_name, prop, p, port) { in usb251xb_get_ports_field()
401 struct device *dev = hub->dev; in usb251xb_get_ofdata()
402 struct device_node *np = dev->of_node; in usb251xb_get_ofdata()
410 return -ENODEV; in usb251xb_get_ofdata()
413 if (of_get_property(np, "skip-config", NULL)) in usb251xb_get_ofdata()
414 hub->skip_config = 1; in usb251xb_get_ofdata()
416 hub->skip_config = 0; in usb251xb_get_ofdata()
418 hub->gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); in usb251xb_get_ofdata()
419 if (PTR_ERR(hub->gpio_reset) == -EPROBE_DEFER) { in usb251xb_get_ofdata()
420 return -EPROBE_DEFER; in usb251xb_get_ofdata()
421 } else if (IS_ERR(hub->gpio_reset)) { in usb251xb_get_ofdata()
422 err = PTR_ERR(hub->gpio_reset); in usb251xb_get_ofdata()
427 if (of_property_read_u16_array(np, "vendor-id", &hub->vendor_id, 1)) in usb251xb_get_ofdata()
428 hub->vendor_id = USB251XB_DEF_VENDOR_ID; in usb251xb_get_ofdata()
430 if (of_property_read_u16_array(np, "product-id", in usb251xb_get_ofdata()
431 &hub->product_id, 1)) in usb251xb_get_ofdata()
432 hub->product_id = data->product_id; in usb251xb_get_ofdata()
434 if (of_property_read_u16_array(np, "device-id", &hub->device_id, 1)) in usb251xb_get_ofdata()
435 hub->device_id = USB251XB_DEF_DEVICE_ID; in usb251xb_get_ofdata()
437 hub->conf_data1 = USB251XB_DEF_CONFIG_DATA_1; in usb251xb_get_ofdata()
438 if (of_get_property(np, "self-powered", NULL)) { in usb251xb_get_ofdata()
439 hub->conf_data1 |= BIT(7); in usb251xb_get_ofdata()
441 /* Configure Over-Current sens when self-powered */ in usb251xb_get_ofdata()
442 hub->conf_data1 &= ~BIT(2); in usb251xb_get_ofdata()
443 if (of_get_property(np, "ganged-sensing", NULL)) in usb251xb_get_ofdata()
444 hub->conf_data1 &= ~BIT(1); in usb251xb_get_ofdata()
445 else if (of_get_property(np, "individual-sensing", NULL)) in usb251xb_get_ofdata()
446 hub->conf_data1 |= BIT(1); in usb251xb_get_ofdata()
447 } else if (of_get_property(np, "bus-powered", NULL)) { in usb251xb_get_ofdata()
448 hub->conf_data1 &= ~BIT(7); in usb251xb_get_ofdata()
450 /* Disable Over-Current sense when bus-powered */ in usb251xb_get_ofdata()
451 hub->conf_data1 |= BIT(2); in usb251xb_get_ofdata()
454 if (of_get_property(np, "disable-hi-speed", NULL)) in usb251xb_get_ofdata()
455 hub->conf_data1 |= BIT(5); in usb251xb_get_ofdata()
457 if (of_get_property(np, "multi-tt", NULL)) in usb251xb_get_ofdata()
458 hub->conf_data1 |= BIT(4); in usb251xb_get_ofdata()
459 else if (of_get_property(np, "single-tt", NULL)) in usb251xb_get_ofdata()
460 hub->conf_data1 &= ~BIT(4); in usb251xb_get_ofdata()
462 if (of_get_property(np, "disable-eop", NULL)) in usb251xb_get_ofdata()
463 hub->conf_data1 |= BIT(3); in usb251xb_get_ofdata()
465 if (of_get_property(np, "individual-port-switching", NULL)) in usb251xb_get_ofdata()
466 hub->conf_data1 |= BIT(0); in usb251xb_get_ofdata()
467 else if (of_get_property(np, "ganged-port-switching", NULL)) in usb251xb_get_ofdata()
468 hub->conf_data1 &= ~BIT(0); in usb251xb_get_ofdata()
470 hub->conf_data2 = USB251XB_DEF_CONFIG_DATA_2; in usb251xb_get_ofdata()
471 if (of_get_property(np, "dynamic-power-switching", NULL)) in usb251xb_get_ofdata()
472 hub->conf_data2 |= BIT(7); in usb251xb_get_ofdata()
474 if (!of_property_read_u32(np, "oc-delay-us", &property_u32)) { in usb251xb_get_ofdata()
477 hub->conf_data2 &= ~BIT(5); in usb251xb_get_ofdata()
478 hub->conf_data2 &= ~BIT(4); in usb251xb_get_ofdata()
481 hub->conf_data2 &= ~BIT(5); in usb251xb_get_ofdata()
482 hub->conf_data2 |= BIT(4); in usb251xb_get_ofdata()
485 hub->conf_data2 |= BIT(5); in usb251xb_get_ofdata()
486 hub->conf_data2 |= BIT(4); in usb251xb_get_ofdata()
489 hub->conf_data2 |= BIT(5); in usb251xb_get_ofdata()
490 hub->conf_data2 &= ~BIT(4); in usb251xb_get_ofdata()
494 if (of_get_property(np, "compound-device", NULL)) in usb251xb_get_ofdata()
495 hub->conf_data2 |= BIT(3); in usb251xb_get_ofdata()
497 hub->conf_data3 = USB251XB_DEF_CONFIG_DATA_3; in usb251xb_get_ofdata()
498 if (of_get_property(np, "port-mapping-mode", NULL)) in usb251xb_get_ofdata()
499 hub->conf_data3 |= BIT(3); in usb251xb_get_ofdata()
501 if (data->led_support && of_get_property(np, "led-usb-mode", NULL)) in usb251xb_get_ofdata()
502 hub->conf_data3 &= ~BIT(1); in usb251xb_get_ofdata()
504 if (of_get_property(np, "string-support", NULL)) in usb251xb_get_ofdata()
505 hub->conf_data3 |= BIT(0); in usb251xb_get_ofdata()
507 hub->non_rem_dev = USB251XB_DEF_NON_REMOVABLE_DEVICES; in usb251xb_get_ofdata()
508 usb251xb_get_ports_field(hub, "non-removable-ports", data->port_cnt, in usb251xb_get_ofdata()
509 true, &hub->non_rem_dev); in usb251xb_get_ofdata()
511 hub->port_disable_sp = USB251XB_DEF_PORT_DISABLE_SELF; in usb251xb_get_ofdata()
512 usb251xb_get_ports_field(hub, "sp-disabled-ports", data->port_cnt, in usb251xb_get_ofdata()
513 true, &hub->port_disable_sp); in usb251xb_get_ofdata()
515 hub->port_disable_bp = USB251XB_DEF_PORT_DISABLE_BUS; in usb251xb_get_ofdata()
516 usb251xb_get_ports_field(hub, "bp-disabled-ports", data->port_cnt, in usb251xb_get_ofdata()
517 true, &hub->port_disable_bp); in usb251xb_get_ofdata()
519 hub->max_power_sp = USB251XB_DEF_MAX_POWER_SELF; in usb251xb_get_ofdata()
520 if (!of_property_read_u32(np, "sp-max-total-current-microamp", in usb251xb_get_ofdata()
522 hub->max_power_sp = min_t(u8, property_u32 / 2000, 50); in usb251xb_get_ofdata()
524 hub->max_power_bp = USB251XB_DEF_MAX_POWER_BUS; in usb251xb_get_ofdata()
525 if (!of_property_read_u32(np, "bp-max-total-current-microamp", in usb251xb_get_ofdata()
527 hub->max_power_bp = min_t(u8, property_u32 / 2000, 255); in usb251xb_get_ofdata()
529 hub->max_current_sp = USB251XB_DEF_MAX_CURRENT_SELF; in usb251xb_get_ofdata()
530 if (!of_property_read_u32(np, "sp-max-removable-current-microamp", in usb251xb_get_ofdata()
532 hub->max_current_sp = min_t(u8, property_u32 / 2000, 50); in usb251xb_get_ofdata()
534 hub->max_current_bp = USB251XB_DEF_MAX_CURRENT_BUS; in usb251xb_get_ofdata()
535 if (!of_property_read_u32(np, "bp-max-removable-current-microamp", in usb251xb_get_ofdata()
537 hub->max_current_bp = min_t(u8, property_u32 / 2000, 255); in usb251xb_get_ofdata()
539 hub->power_on_time = USB251XB_DEF_POWER_ON_TIME; in usb251xb_get_ofdata()
540 if (!of_property_read_u32(np, "power-on-time-ms", &property_u32)) in usb251xb_get_ofdata()
541 hub->power_on_time = min_t(u8, property_u32 / 2, 255); in usb251xb_get_ofdata()
543 if (of_property_read_u16_array(np, "language-id", &hub->lang_id, 1)) in usb251xb_get_ofdata()
544 hub->lang_id = USB251XB_DEF_LANGUAGE_ID; in usb251xb_get_ofdata()
549 hub->manufacturer_len = strlen(str) & 0xFF; in usb251xb_get_ofdata()
550 memset(hub->manufacturer, 0, USB251XB_STRING_BUFSIZE); in usb251xb_get_ofdata()
553 (wchar_t *)hub->manufacturer, in usb251xb_get_ofdata()
557 strlcpy(str, cproperty_char ? : data->product_str, sizeof(str)); in usb251xb_get_ofdata()
558 hub->product_len = strlen(str) & 0xFF; in usb251xb_get_ofdata()
559 memset(hub->product, 0, USB251XB_STRING_BUFSIZE); in usb251xb_get_ofdata()
562 (wchar_t *)hub->product, in usb251xb_get_ofdata()
568 hub->serial_len = strlen(str) & 0xFF; in usb251xb_get_ofdata()
569 memset(hub->serial, 0, USB251XB_STRING_BUFSIZE); in usb251xb_get_ofdata()
572 (wchar_t *)hub->serial, in usb251xb_get_ofdata()
579 hub->port_swap = USB251XB_DEF_PORT_SWAP; in usb251xb_get_ofdata()
580 usb251xb_get_ports_field(hub, "swap-dx-lanes", data->port_cnt, in usb251xb_get_ofdata()
581 false, &hub->port_swap); in usb251xb_get_ofdata()
586 hub->bat_charge_en = USB251XB_DEF_BATTERY_CHARGING_ENABLE; in usb251xb_get_ofdata()
587 hub->boost_up = USB251XB_DEF_BOOST_UP; in usb251xb_get_ofdata()
588 hub->boost_57 = USB251XB_DEF_BOOST_57; in usb251xb_get_ofdata()
589 hub->boost_14 = USB251XB_DEF_BOOST_14; in usb251xb_get_ofdata()
590 hub->port_map12 = USB251XB_DEF_PORT_MAP_12; in usb251xb_get_ofdata()
591 hub->port_map34 = USB251XB_DEF_PORT_MAP_34; in usb251xb_get_ofdata()
592 hub->port_map56 = USB251XB_DEF_PORT_MAP_56; in usb251xb_get_ofdata()
593 hub->port_map7 = USB251XB_DEF_PORT_MAP_7; in usb251xb_get_ofdata()
643 regulator_disable(hub->vdd); in usb251xb_regulator_disable_action()
648 struct device *dev = hub->dev; in usb251xb_probe()
649 struct device_node *np = dev->of_node; in usb251xb_probe()
656 (struct usb251xb_data *)of_id->data); in usb251xb_probe()
664 * usb251x SMBus-slave SCL lane is muxed with CFG_SEL0 pin. So if anyone in usb251xb_probe()
668 * value without SMBus-slave interface activation. If the hub in usb251xb_probe()
669 * accidentally gets this mode, this will cause the driver SMBus- in usb251xb_probe()
670 * functions failure. Normally we could just lock the SMBus-segment the in usb251xb_probe()
671 * hub i2c-interface resides for the device-specific reset timing. But in usb251xb_probe()
673 * placed at the same i2c-bus segment. In this case an error should be in usb251xb_probe()
676 * the i2c-bus segment (it will cause a deadlock). in usb251xb_probe()
682 hub->vdd = devm_regulator_get(dev, "vdd"); in usb251xb_probe()
683 if (IS_ERR(hub->vdd)) in usb251xb_probe()
684 return PTR_ERR(hub->vdd); in usb251xb_probe()
686 err = regulator_enable(hub->vdd); in usb251xb_probe()
711 hub = devm_kzalloc(&i2c->dev, sizeof(struct usb251xb), GFP_KERNEL); in usb251xb_i2c_probe()
713 return -ENOMEM; in usb251xb_i2c_probe()
716 hub->dev = &i2c->dev; in usb251xb_i2c_probe()
717 hub->i2c = i2c; in usb251xb_i2c_probe()
727 return regulator_disable(hub->vdd); in usb251xb_suspend()
736 err = regulator_enable(hub->vdd); in usb251xb_resume()