Lines Matching refs:rphy
225 int (*phy_tuning)(struct rockchip_usb2phy *rphy);
226 int (*vbus_detect)(struct rockchip_usb2phy *rphy,
355 static inline struct regmap *get_reg_base(struct rockchip_usb2phy *rphy) in get_reg_base() argument
357 return rphy->usbgrf == NULL ? rphy->grf : rphy->usbgrf; in get_reg_base()
435 static int rockchip_usb2phy_reset(struct rockchip_usb2phy *rphy) in rockchip_usb2phy_reset() argument
439 if (!rphy->phy_reset) in rockchip_usb2phy_reset()
442 ret = reset_control_assert(rphy->phy_reset); in rockchip_usb2phy_reset()
448 ret = reset_control_deassert(rphy->phy_reset); in rockchip_usb2phy_reset()
459 struct rockchip_usb2phy *rphy = in rockchip_usb2phy_clk480m_prepare() local
461 struct regmap *base = get_reg_base(rphy); in rockchip_usb2phy_clk480m_prepare()
465 if (rphy->phy_cfg->clkout_ctl_phy.enable) { in rockchip_usb2phy_clk480m_prepare()
466 if (!phy_property_enabled(rphy->phy_base, &rphy->phy_cfg->clkout_ctl_phy)) { in rockchip_usb2phy_clk480m_prepare()
467 phy_property_enable(rphy->phy_base, &rphy->phy_cfg->clkout_ctl_phy, true); in rockchip_usb2phy_clk480m_prepare()
472 } else if (!property_enabled(base, &rphy->phy_cfg->clkout_ctl)) { in rockchip_usb2phy_clk480m_prepare()
473 ret = property_enable(base, &rphy->phy_cfg->clkout_ctl, true); in rockchip_usb2phy_clk480m_prepare()
486 struct rockchip_usb2phy *rphy = in rockchip_usb2phy_clk480m_unprepare() local
488 struct regmap *base = get_reg_base(rphy); in rockchip_usb2phy_clk480m_unprepare()
491 if (rphy->phy_cfg->clkout_ctl_phy.enable) in rockchip_usb2phy_clk480m_unprepare()
492 phy_property_enable(rphy->phy_base, &rphy->phy_cfg->clkout_ctl_phy, false); in rockchip_usb2phy_clk480m_unprepare()
494 property_enable(base, &rphy->phy_cfg->clkout_ctl, false); in rockchip_usb2phy_clk480m_unprepare()
499 struct rockchip_usb2phy *rphy = in rockchip_usb2phy_clk480m_prepared() local
501 struct regmap *base = get_reg_base(rphy); in rockchip_usb2phy_clk480m_prepared()
503 if (rphy->phy_cfg->clkout_ctl_phy.enable) in rockchip_usb2phy_clk480m_prepared()
504 return phy_property_enabled(rphy->phy_base, &rphy->phy_cfg->clkout_ctl_phy); in rockchip_usb2phy_clk480m_prepared()
506 return property_enabled(base, &rphy->phy_cfg->clkout_ctl); in rockchip_usb2phy_clk480m_prepared()
525 struct rockchip_usb2phy *rphy = data; in rockchip_usb2phy_clk480m_unregister() local
527 of_clk_del_provider(rphy->dev->of_node); in rockchip_usb2phy_clk480m_unregister()
528 clk_unregister(rphy->clk480m); in rockchip_usb2phy_clk480m_unregister()
532 rockchip_usb2phy_clk480m_register(struct rockchip_usb2phy *rphy) in rockchip_usb2phy_clk480m_register() argument
534 struct device_node *node = rphy->dev->of_node; in rockchip_usb2phy_clk480m_register()
556 rphy->clk480m_hw.init = &init; in rockchip_usb2phy_clk480m_register()
559 rphy->clk480m = clk_register(rphy->dev, &rphy->clk480m_hw); in rockchip_usb2phy_clk480m_register()
560 if (IS_ERR(rphy->clk480m)) { in rockchip_usb2phy_clk480m_register()
561 ret = PTR_ERR(rphy->clk480m); in rockchip_usb2phy_clk480m_register()
565 ret = of_clk_add_provider(node, of_clk_src_simple_get, rphy->clk480m); in rockchip_usb2phy_clk480m_register()
569 ret = devm_add_action(rphy->dev, rockchip_usb2phy_clk480m_unregister, in rockchip_usb2phy_clk480m_register()
570 rphy); in rockchip_usb2phy_clk480m_register()
579 clk_unregister(rphy->clk480m); in rockchip_usb2phy_clk480m_register()
584 static int rockchip_usb2phy_extcon_register(struct rockchip_usb2phy *rphy) in rockchip_usb2phy_extcon_register() argument
587 struct device_node *node = rphy->dev->of_node; in rockchip_usb2phy_extcon_register()
591 edev = extcon_get_edev_by_phandle(rphy->dev, 0); in rockchip_usb2phy_extcon_register()
594 dev_err(rphy->dev, "Invalid or missing extcon\n"); in rockchip_usb2phy_extcon_register()
599 edev = devm_extcon_dev_allocate(rphy->dev, in rockchip_usb2phy_extcon_register()
605 ret = devm_extcon_dev_register(rphy->dev, edev); in rockchip_usb2phy_extcon_register()
607 dev_err(rphy->dev, "failed to register extcon device\n"); in rockchip_usb2phy_extcon_register()
611 rphy->edev_self = true; in rockchip_usb2phy_extcon_register()
614 rphy->edev = edev; in rockchip_usb2phy_extcon_register()
620 static int rockchip_usb2phy_enable_id_irq(struct rockchip_usb2phy *rphy, in rockchip_usb2phy_enable_id_irq() argument
626 ret = property_enable(rphy->grf, &rport->port_cfg->idfall_det_clr, true); in rockchip_usb2phy_enable_id_irq()
630 ret = property_enable(rphy->grf, &rport->port_cfg->idfall_det_en, en); in rockchip_usb2phy_enable_id_irq()
634 ret = property_enable(rphy->grf, &rport->port_cfg->idrise_det_clr, true); in rockchip_usb2phy_enable_id_irq()
638 ret = property_enable(rphy->grf, &rport->port_cfg->idrise_det_en, en); in rockchip_usb2phy_enable_id_irq()
644 static int rockchip_usb2phy_enable_vbus_irq(struct rockchip_usb2phy *rphy, in rockchip_usb2phy_enable_vbus_irq() argument
650 ret = property_enable(rphy->grf, &rport->port_cfg->bvalid_det_clr, true); in rockchip_usb2phy_enable_vbus_irq()
654 ret = property_enable(rphy->grf, &rport->port_cfg->bvalid_det_en, en); in rockchip_usb2phy_enable_vbus_irq()
659 static int rockchip_usb2phy_enable_line_irq(struct rockchip_usb2phy *rphy, in rockchip_usb2phy_enable_line_irq() argument
665 ret = property_enable(rphy->grf, &rport->port_cfg->ls_det_clr, true); in rockchip_usb2phy_enable_line_irq()
669 ret = property_enable(rphy->grf, &rport->port_cfg->ls_det_en, en); in rockchip_usb2phy_enable_line_irq()
674 static int rockchip_usb2phy_enable_host_disc_irq(struct rockchip_usb2phy *rphy, in rockchip_usb2phy_enable_host_disc_irq() argument
680 ret = property_enable(rphy->grf, &rport->port_cfg->disfall_clr, true); in rockchip_usb2phy_enable_host_disc_irq()
684 ret = property_enable(rphy->grf, &rport->port_cfg->disfall_en, en); in rockchip_usb2phy_enable_host_disc_irq()
688 ret = property_enable(rphy->grf, &rport->port_cfg->disrise_clr, true); in rockchip_usb2phy_enable_host_disc_irq()
692 ret = property_enable(rphy->grf, &rport->port_cfg->disrise_en, en); in rockchip_usb2phy_enable_host_disc_irq()
700 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb_bypass_uart() local
702 struct regmap *base = get_reg_base(rphy); in rockchip_usb_bypass_uart()
734 ret |= property_enable(rphy->grf, iomux, true); in rockchip_usb_bypass_uart()
744 ret |= property_enable(rphy->grf, iomux, false); in rockchip_usb_bypass_uart()
758 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb_bypass_uart_work() local
764 iddig = property_enabled(rphy->grf, &rport->port_cfg->utmi_iddig); in rockchip_usb_bypass_uart_work()
767 vbus = property_enabled(rphy->grf, &rport->port_cfg->utmi_avalid); in rockchip_usb_bypass_uart_work()
769 vbus = property_enabled(rphy->grf, &rport->port_cfg->utmi_bvalid); in rockchip_usb_bypass_uart_work()
793 struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent); in rockchip_usb2phy_init() local
800 property_enable(rphy->usbctrl_grf, in rockchip_usb2phy_init()
808 rphy->irq > 0) { in rockchip_usb2phy_init()
809 ret = rockchip_usb2phy_enable_id_irq(rphy, rport, in rockchip_usb2phy_init()
812 dev_err(rphy->dev, in rockchip_usb2phy_init()
820 rphy->irq > 0) && !rport->vbus_always_on) { in rockchip_usb2phy_init()
821 ret = rockchip_usb2phy_enable_vbus_irq(rphy, rport, in rockchip_usb2phy_init()
824 dev_err(rphy->dev, in rockchip_usb2phy_init()
833 ret = regmap_read(rphy->grf, rport->port_cfg->utmi_ls.offset, &ul); in rockchip_usb2phy_init()
839 ret = rockchip_usb2phy_enable_host_disc_irq(rphy, rport, true); in rockchip_usb2phy_init()
841 dev_err(rphy->dev, "failed to enable disconnect irq\n"); in rockchip_usb2phy_init()
847 ret = rockchip_usb2phy_enable_line_irq(rphy, rport, true); in rockchip_usb2phy_init()
849 dev_err(rphy->dev, "failed to enable linestate irq\n"); in rockchip_usb2phy_init()
864 struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent); in rockchip_usb2phy_power_on() local
865 struct regmap *base = get_reg_base(rphy); in rockchip_usb2phy_power_on()
886 ret = clk_prepare_enable(rphy->clk480m); in rockchip_usb2phy_power_on()
903 of_device_is_compatible(rphy->dev->of_node, "rockchip,rk3588-usb2phy")) { in rockchip_usb2phy_power_on()
904 ret = rockchip_usb2phy_reset(rphy); in rockchip_usb2phy_power_on()
928 struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent); in rockchip_usb2phy_power_off() local
929 struct regmap *base = get_reg_base(rphy); in rockchip_usb2phy_power_off()
946 clk_disable_unprepare(rphy->clk480m); in rockchip_usb2phy_power_off()
998 struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent); in rockchip_usb2phy_set_mode() local
1007 if (rphy->edev_self && submode) { in rockchip_usb2phy_set_mode()
1009 extcon_set_state(rphy->edev, EXTCON_USB_HOST, true); in rockchip_usb2phy_set_mode()
1010 extcon_set_state(rphy->edev, EXTCON_USB, false); in rockchip_usb2phy_set_mode()
1012 extcon_set_state(rphy->edev, EXTCON_USB_HOST, false); in rockchip_usb2phy_set_mode()
1013 extcon_set_state(rphy->edev, EXTCON_USB, true); in rockchip_usb2phy_set_mode()
1027 extcon_set_state_sync(rphy->edev, EXTCON_USB_VBUS_EN, false); in rockchip_usb2phy_set_mode()
1030 extcon_set_state(rphy->edev, EXTCON_USB, true); in rockchip_usb2phy_set_mode()
1043 extcon_set_state_sync(rphy->edev, EXTCON_USB_VBUS_EN, true); in rockchip_usb2phy_set_mode()
1046 extcon_set_state(rphy->edev, EXTCON_USB, false); in rockchip_usb2phy_set_mode()
1057 if (rphy->phy_cfg->vbus_detect) in rockchip_usb2phy_set_mode()
1058 rphy->phy_cfg->vbus_detect(rphy, &rport->port_cfg->vbus_det_en, in rockchip_usb2phy_set_mode()
1061 ret = property_enable(rphy->grf, &rport->port_cfg->vbus_det_en, in rockchip_usb2phy_set_mode()
1081 struct rockchip_usb2phy *rphy = dev_get_drvdata(device); in otg_mode_show() local
1085 for (index = 0; index < rphy->phy_cfg->num_ports; index++) { in otg_mode_show()
1086 rport = &rphy->ports[index]; in otg_mode_show()
1092 dev_err(rphy->dev, "Fail to get otg port\n"); in otg_mode_show()
1095 dev_err(rphy->dev, "No support otg\n"); in otg_mode_show()
1117 struct rockchip_usb2phy *rphy = dev_get_drvdata(device); in otg_mode_store() local
1119 struct regmap *base = get_reg_base(rphy); in otg_mode_store()
1124 for (index = 0; index < rphy->phy_cfg->num_ports; index++) { in otg_mode_store()
1125 rport = &rphy->ports[index]; in otg_mode_store()
1131 dev_err(rphy->dev, "Fail to get otg port\n"); in otg_mode_store()
1136 dev_err(rphy->dev, "No support otg\n"); in otg_mode_store()
1150 dev_err(rphy->dev, "Error mode! Input 'otg' or 'host' or 'peripheral'\n"); in otg_mode_store()
1156 dev_warn(rphy->dev, "Same as current mode\n"); in otg_mode_store()
1206 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_otg_sm_work() local
1215 property_enabled(rphy->grf, &rport->port_cfg->bvalid_grf_con); in rockchip_usb2phy_otg_sm_work()
1218 property_enabled(rphy->grf, &rport->port_cfg->utmi_avalid); in rockchip_usb2phy_otg_sm_work()
1221 property_enabled(rphy->grf, &rport->port_cfg->utmi_bvalid); in rockchip_usb2phy_otg_sm_work()
1240 if (extcon_get_state(rphy->edev, EXTCON_USB_HOST) > 0 || in rockchip_usb2phy_otg_sm_work()
1241 extcon_get_state(rphy->edev, EXTCON_USB_VBUS_EN) > 0) { in rockchip_usb2phy_otg_sm_work()
1244 rphy->chg_state = USB_CHG_STATE_UNDEFINED; in rockchip_usb2phy_otg_sm_work()
1245 rphy->chg_type = POWER_SUPPLY_TYPE_UNKNOWN; in rockchip_usb2phy_otg_sm_work()
1251 switch (rphy->chg_state) { in rockchip_usb2phy_otg_sm_work()
1257 switch (rphy->chg_type) { in rockchip_usb2phy_otg_sm_work()
1293 rphy->chg_state = USB_CHG_STATE_UNDEFINED; in rockchip_usb2phy_otg_sm_work()
1294 rphy->chg_type = POWER_SUPPLY_TYPE_UNKNOWN; in rockchip_usb2phy_otg_sm_work()
1305 if (extcon_get_state(rphy->edev, EXTCON_USB_HOST) > 0 || in rockchip_usb2phy_otg_sm_work()
1306 extcon_get_state(rphy->edev, in rockchip_usb2phy_otg_sm_work()
1310 rphy->chg_state = USB_CHG_STATE_UNDEFINED; in rockchip_usb2phy_otg_sm_work()
1311 rphy->chg_type = POWER_SUPPLY_TYPE_UNKNOWN; in rockchip_usb2phy_otg_sm_work()
1319 rphy->chg_state = USB_CHG_STATE_UNDEFINED; in rockchip_usb2phy_otg_sm_work()
1320 rphy->chg_type = POWER_SUPPLY_TYPE_UNKNOWN; in rockchip_usb2phy_otg_sm_work()
1326 if (extcon_get_state(rphy->edev, EXTCON_USB_HOST) == 0) { in rockchip_usb2phy_otg_sm_work()
1340 if (extcon_get_state(rphy->edev, cable) != rport->vbus_attached) { in rockchip_usb2phy_otg_sm_work()
1341 extcon_set_state_sync(rphy->edev, in rockchip_usb2phy_otg_sm_work()
1347 extcon_get_state(rphy->edev, cable)) { in rockchip_usb2phy_otg_sm_work()
1354 extcon_set_state_sync(rphy->edev, cable, false); in rockchip_usb2phy_otg_sm_work()
1358 if (rphy->edev_self && in rockchip_usb2phy_otg_sm_work()
1359 (extcon_get_state(rphy->edev, EXTCON_USB) != in rockchip_usb2phy_otg_sm_work()
1361 extcon_set_state_sync(rphy->edev, in rockchip_usb2phy_otg_sm_work()
1364 extcon_sync(rphy->edev, EXTCON_USB_HOST); in rockchip_usb2phy_otg_sm_work()
1386 static void rockchip_chg_enable_dcd(struct rockchip_usb2phy *rphy, in rockchip_chg_enable_dcd() argument
1389 struct regmap *base = get_reg_base(rphy); in rockchip_chg_enable_dcd()
1391 property_enable(base, &rphy->phy_cfg->chg_det.rdm_pdwn_en, en); in rockchip_chg_enable_dcd()
1392 property_enable(base, &rphy->phy_cfg->chg_det.idp_src_en, en); in rockchip_chg_enable_dcd()
1395 static void rockchip_chg_enable_primary_det(struct rockchip_usb2phy *rphy, in rockchip_chg_enable_primary_det() argument
1398 struct regmap *base = get_reg_base(rphy); in rockchip_chg_enable_primary_det()
1400 property_enable(base, &rphy->phy_cfg->chg_det.vdp_src_en, en); in rockchip_chg_enable_primary_det()
1401 property_enable(base, &rphy->phy_cfg->chg_det.idm_sink_en, en); in rockchip_chg_enable_primary_det()
1404 static void rockchip_chg_enable_secondary_det(struct rockchip_usb2phy *rphy, in rockchip_chg_enable_secondary_det() argument
1407 struct regmap *base = get_reg_base(rphy); in rockchip_chg_enable_secondary_det()
1409 property_enable(base, &rphy->phy_cfg->chg_det.vdm_src_en, en); in rockchip_chg_enable_secondary_det()
1410 property_enable(base, &rphy->phy_cfg->chg_det.idp_sink_en, en); in rockchip_chg_enable_secondary_det()
1421 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_chg_detect_work() local
1422 struct regmap *base = get_reg_base(rphy); in rockchip_chg_detect_work()
1430 rphy->chg_state); in rockchip_chg_detect_work()
1440 switch (rphy->chg_state) { in rockchip_chg_detect_work()
1446 &rphy->phy_sus_cfg); in rockchip_chg_detect_work()
1456 property_enable(base, &rphy->phy_cfg->chg_det.chg_mode, true); in rockchip_chg_detect_work()
1458 rockchip_chg_enable_dcd(rphy, true); in rockchip_chg_detect_work()
1459 rphy->chg_state = USB_CHG_STATE_WAIT_FOR_DCD; in rockchip_chg_detect_work()
1460 rphy->dcd_retries = 0; in rockchip_chg_detect_work()
1461 rphy->primary_retries = 0; in rockchip_chg_detect_work()
1466 is_dcd = property_enabled(rphy->grf, in rockchip_chg_detect_work()
1467 &rphy->phy_cfg->chg_det.dp_det); in rockchip_chg_detect_work()
1468 tmout = ++rphy->dcd_retries == CHG_DCD_MAX_RETRIES; in rockchip_chg_detect_work()
1473 rockchip_chg_enable_dcd(rphy, false); in rockchip_chg_detect_work()
1475 rockchip_chg_enable_primary_det(rphy, true); in rockchip_chg_detect_work()
1477 rphy->chg_state = USB_CHG_STATE_DCD_DONE; in rockchip_chg_detect_work()
1484 vout = property_enabled(rphy->grf, in rockchip_chg_detect_work()
1485 &rphy->phy_cfg->chg_det.cp_det); in rockchip_chg_detect_work()
1486 rockchip_chg_enable_primary_det(rphy, false); in rockchip_chg_detect_work()
1489 rockchip_chg_enable_secondary_det(rphy, true); in rockchip_chg_detect_work()
1491 rphy->chg_state = USB_CHG_STATE_PRIMARY_DONE; in rockchip_chg_detect_work()
1493 if (rphy->dcd_retries == CHG_DCD_MAX_RETRIES) { in rockchip_chg_detect_work()
1495 rphy->chg_type = POWER_SUPPLY_TYPE_USB_DCP; in rockchip_chg_detect_work()
1496 rphy->chg_state = USB_CHG_STATE_DETECTED; in rockchip_chg_detect_work()
1499 if (rphy->primary_retries < 2) { in rockchip_chg_detect_work()
1501 rockchip_chg_enable_dcd(rphy, false); in rockchip_chg_detect_work()
1503 rockchip_chg_enable_primary_det(rphy, in rockchip_chg_detect_work()
1506 rphy->chg_state = in rockchip_chg_detect_work()
1508 rphy->primary_retries++; in rockchip_chg_detect_work()
1512 rphy->chg_type = POWER_SUPPLY_TYPE_USB; in rockchip_chg_detect_work()
1513 rphy->chg_state = USB_CHG_STATE_DETECTED; in rockchip_chg_detect_work()
1519 vout = property_enabled(rphy->grf, in rockchip_chg_detect_work()
1520 &rphy->phy_cfg->chg_det.dcp_det); in rockchip_chg_detect_work()
1522 rockchip_chg_enable_secondary_det(rphy, false); in rockchip_chg_detect_work()
1524 rphy->chg_type = POWER_SUPPLY_TYPE_USB_DCP; in rockchip_chg_detect_work()
1526 rphy->chg_type = POWER_SUPPLY_TYPE_USB_CDP; in rockchip_chg_detect_work()
1529 rphy->chg_state = USB_CHG_STATE_DETECTED; in rockchip_chg_detect_work()
1532 if (rphy->phy_cfg->chg_det.chg_mode.offset != in rockchip_chg_detect_work()
1534 property_enable(base, &rphy->phy_cfg->chg_det.chg_mode, false); in rockchip_chg_detect_work()
1540 (rphy->phy_sus_cfg | (mask << BIT_WRITEABLE_SHIFT))); in rockchip_chg_detect_work()
1548 chg_to_string(rphy->chg_type)); in rockchip_chg_detect_work()
1580 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_sm_work() local
1594 ret = regmap_read(rphy->grf, rport->port_cfg->utmi_ls.offset, &ul); in rockchip_usb2phy_sm_work()
1602 ret = regmap_read(rphy->grf, rport->port_cfg->utmi_hstdet.offset, &uhd); in rockchip_usb2phy_sm_work()
1673 rockchip_usb2phy_enable_line_irq(rphy, rport, true); in rockchip_usb2phy_sm_work()
1694 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_linestate_irq() local
1696 if (!property_enabled(rphy->grf, &rport->port_cfg->ls_det_st) || in rockchip_usb2phy_linestate_irq()
1697 !property_enabled(rphy->grf, &rport->port_cfg->ls_det_en)) in rockchip_usb2phy_linestate_irq()
1705 rockchip_usb2phy_enable_line_irq(rphy, rport, false); in rockchip_usb2phy_linestate_irq()
1731 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_bvalid_irq() local
1733 if (!property_enabled(rphy->grf, &rport->port_cfg->bvalid_det_st)) in rockchip_usb2phy_bvalid_irq()
1739 property_enable(rphy->grf, &rport->port_cfg->bvalid_det_clr, true); in rockchip_usb2phy_bvalid_irq()
1757 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_id_irq() local
1760 if (!property_enabled(rphy->grf, &rport->port_cfg->idfall_det_st) && in rockchip_usb2phy_id_irq()
1761 !property_enabled(rphy->grf, &rport->port_cfg->idrise_det_st)) in rockchip_usb2phy_id_irq()
1767 if (property_enabled(rphy->grf, &rport->port_cfg->idfall_det_st)) { in rockchip_usb2phy_id_irq()
1768 property_enable(rphy->grf, &rport->port_cfg->idfall_det_clr, in rockchip_usb2phy_id_irq()
1771 if (!property_enabled(rphy->grf, &rport->port_cfg->utmi_iddig)) in rockchip_usb2phy_id_irq()
1773 } else if (property_enabled(rphy->grf, &rport->port_cfg->idrise_det_st)) { in rockchip_usb2phy_id_irq()
1774 property_enable(rphy->grf, &rport->port_cfg->idrise_det_clr, in rockchip_usb2phy_id_irq()
1779 extcon_set_state(rphy->edev, EXTCON_USB_HOST, cable_vbus_state); in rockchip_usb2phy_id_irq()
1780 extcon_set_state(rphy->edev, EXTCON_USB_VBUS_EN, cable_vbus_state); in rockchip_usb2phy_id_irq()
1782 extcon_sync(rphy->edev, EXTCON_USB_HOST); in rockchip_usb2phy_id_irq()
1783 extcon_sync(rphy->edev, EXTCON_USB_VBUS_EN); in rockchip_usb2phy_id_irq()
1795 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_host_disc_irq() local
1797 if (!property_enabled(rphy->grf, &rport->port_cfg->disfall_st) && in rockchip_usb2phy_host_disc_irq()
1798 !property_enabled(rphy->grf, &rport->port_cfg->disrise_st)) in rockchip_usb2phy_host_disc_irq()
1804 if (property_enabled(rphy->grf, &rport->port_cfg->disfall_st)) { in rockchip_usb2phy_host_disc_irq()
1805 property_enable(rphy->grf, &rport->port_cfg->disfall_clr, in rockchip_usb2phy_host_disc_irq()
1808 } else if (property_enabled(rphy->grf, &rport->port_cfg->disrise_st)) { in rockchip_usb2phy_host_disc_irq()
1809 property_enable(rphy->grf, &rport->port_cfg->disrise_clr, in rockchip_usb2phy_host_disc_irq()
1832 struct rockchip_usb2phy *rphy = data; in rockchip_usb2phy_irq() local
1838 for (index = 0; index < rphy->phy_cfg->num_ports; index++) { in rockchip_usb2phy_irq()
1839 rport = &rphy->ports[index]; in rockchip_usb2phy_irq()
1869 force_mode = property_enabled(rphy->grf, in rockchip_usb2phy_irq()
1885 static int rockchip_usb2phy_port_irq_init(struct rockchip_usb2phy *rphy, in rockchip_usb2phy_port_irq_init() argument
1895 if (rphy->irq > 0) in rockchip_usb2phy_port_irq_init()
1905 ret = devm_request_threaded_irq(rphy->dev, rport->otg_mux_irq, in rockchip_usb2phy_port_irq_init()
1912 dev_err(rphy->dev, in rockchip_usb2phy_port_irq_init()
1921 dev_err(rphy->dev, "no linestate irq provided\n"); in rockchip_usb2phy_port_irq_init()
1925 ret = devm_request_threaded_irq(rphy->dev, rport->ls_irq, NULL, in rockchip_usb2phy_port_irq_init()
1930 dev_err(rphy->dev, "failed to request linestate irq handle\n"); in rockchip_usb2phy_port_irq_init()
1949 dev_err(rphy->dev, "no bvalid irq provided\n"); in rockchip_usb2phy_port_irq_init()
1953 ret = devm_request_threaded_irq(rphy->dev, in rockchip_usb2phy_port_irq_init()
1961 dev_err(rphy->dev, in rockchip_usb2phy_port_irq_init()
1968 if (rphy->edev_self) { in rockchip_usb2phy_port_irq_init()
1971 dev_err(rphy->dev, "no otg id irq provided\n"); in rockchip_usb2phy_port_irq_init()
1975 ret = devm_request_threaded_irq(rphy->dev, in rockchip_usb2phy_port_irq_init()
1982 dev_err(rphy->dev, in rockchip_usb2phy_port_irq_init()
1994 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_usb_bvalid_enable() local
1998 property_enable(rphy->grf, &cfg->bvalid_phy_con, enable); in rockchip_usb2phy_usb_bvalid_enable()
2001 property_enable(rphy->grf, &cfg->bvalid_grf_con, enable); in rockchip_usb2phy_usb_bvalid_enable()
2019 rockchip_usb2phy_setup_orien_switch(struct rockchip_usb2phy *rphy, in rockchip_usb2phy_setup_orien_switch() argument
2023 struct device *dev = rphy->dev; in rockchip_usb2phy_setup_orien_switch()
2046 static int rockchip_usb2phy_host_port_init(struct rockchip_usb2phy *rphy, in rockchip_usb2phy_host_port_init() argument
2051 struct regmap *base = get_reg_base(rphy); in rockchip_usb2phy_host_port_init()
2054 rport->port_cfg = &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_HOST]; in rockchip_usb2phy_host_port_init()
2063 ret = rockchip_usb2phy_port_irq_init(rphy, rport, child_np); in rockchip_usb2phy_host_port_init()
2065 dev_err(rphy->dev, "failed to init irq for host port\n"); in rockchip_usb2phy_host_port_init()
2098 static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy, in rockchip_usb2phy_otg_port_init() argument
2104 struct regmap *base = get_reg_base(rphy); in rockchip_usb2phy_otg_port_init()
2107 rport->port_cfg = &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_OTG]; in rockchip_usb2phy_otg_port_init()
2138 rphy->usbctrl_grf = in rockchip_usb2phy_otg_port_init()
2139 syscon_regmap_lookup_by_phandle(rphy->dev->of_node, in rockchip_usb2phy_otg_port_init()
2141 if (IS_ERR(rphy->usbctrl_grf)) { in rockchip_usb2phy_otg_port_init()
2142 dev_err(rphy->dev, "Failed to map usbctrl-grf\n"); in rockchip_usb2phy_otg_port_init()
2143 return PTR_ERR(rphy->usbctrl_grf); in rockchip_usb2phy_otg_port_init()
2160 iddig = property_enabled(rphy->grf, &rport->port_cfg->utmi_iddig); in rockchip_usb2phy_otg_port_init()
2161 if (rphy->edev_self && (rport->mode == USB_DR_MODE_HOST || in rockchip_usb2phy_otg_port_init()
2164 extcon_set_state(rphy->edev, EXTCON_USB, false); in rockchip_usb2phy_otg_port_init()
2165 extcon_set_state(rphy->edev, EXTCON_USB_HOST, true); in rockchip_usb2phy_otg_port_init()
2166 extcon_set_state(rphy->edev, EXTCON_USB_VBUS_EN, true); in rockchip_usb2phy_otg_port_init()
2172 ret = rockchip_usb2phy_port_irq_init(rphy, rport, child_np); in rockchip_usb2phy_otg_port_init()
2174 dev_err(rphy->dev, "failed to init irq for otg port\n"); in rockchip_usb2phy_otg_port_init()
2179 device_property_present(rphy->dev, "orientation-switch")) { in rockchip_usb2phy_otg_port_init()
2180 ret = rockchip_usb2phy_setup_orien_switch(rphy, rport); in rockchip_usb2phy_otg_port_init()
2184 ret = devm_add_action_or_reset(rphy->dev, in rockchip_usb2phy_otg_port_init()
2209 extcon_set_state(rphy->edev, EXTCON_USB, true); in rockchip_usb2phy_otg_port_init()
2216 ret = devm_add_action_or_reset(rphy->dev, rockchip_otg_wake_lock_destroy, in rockchip_usb2phy_otg_port_init()
2226 if (!IS_ERR(rphy->edev)) { in rockchip_usb2phy_otg_port_init()
2229 ret = devm_extcon_register_notifier(rphy->dev, rphy->edev, in rockchip_usb2phy_otg_port_init()
2232 dev_err(rphy->dev, "register USB HOST notifier failed\n"); in rockchip_usb2phy_otg_port_init()
2257 struct rockchip_usb2phy *rphy; in rockchip_usb2phy_probe() local
2265 rphy = devm_kzalloc(dev, sizeof(*rphy), GFP_KERNEL); in rockchip_usb2phy_probe()
2266 if (!rphy) in rockchip_usb2phy_probe()
2282 rphy->phy_base = devm_ioremap_resource(dev, res); in rockchip_usb2phy_probe()
2283 if (IS_ERR(rphy->phy_base)) in rockchip_usb2phy_probe()
2284 return PTR_ERR(rphy->phy_base); in rockchip_usb2phy_probe()
2286 rphy->grf = syscon_regmap_lookup_by_phandle(np, in rockchip_usb2phy_probe()
2288 if (IS_ERR(rphy->grf)) in rockchip_usb2phy_probe()
2289 return PTR_ERR(rphy->grf); in rockchip_usb2phy_probe()
2293 rphy->grf = syscon_node_to_regmap(dev->parent->of_node); in rockchip_usb2phy_probe()
2294 if (IS_ERR(rphy->grf)) in rockchip_usb2phy_probe()
2295 return PTR_ERR(rphy->grf); in rockchip_usb2phy_probe()
2298 rphy->usbgrf = in rockchip_usb2phy_probe()
2301 if (IS_ERR(rphy->usbgrf)) in rockchip_usb2phy_probe()
2302 return PTR_ERR(rphy->usbgrf); in rockchip_usb2phy_probe()
2304 rphy->usbgrf = NULL; in rockchip_usb2phy_probe()
2314 rphy->dev = dev; in rockchip_usb2phy_probe()
2316 rphy->chg_state = USB_CHG_STATE_UNDEFINED; in rockchip_usb2phy_probe()
2317 rphy->chg_type = POWER_SUPPLY_TYPE_UNKNOWN; in rockchip_usb2phy_probe()
2318 rphy->edev_self = false; in rockchip_usb2phy_probe()
2319 rphy->irq = platform_get_irq(pdev, 0); in rockchip_usb2phy_probe()
2320 platform_set_drvdata(pdev, rphy); in rockchip_usb2phy_probe()
2322 ret = rockchip_usb2phy_extcon_register(rphy); in rockchip_usb2phy_probe()
2330 rphy->phy_cfg = &phy_cfgs[index]; in rockchip_usb2phy_probe()
2337 if (!rphy->phy_cfg) { in rockchip_usb2phy_probe()
2348 rphy->phy_reset = devm_reset_control_get_optional(dev, "phy"); in rockchip_usb2phy_probe()
2349 if (IS_ERR(rphy->phy_reset)) in rockchip_usb2phy_probe()
2350 return PTR_ERR(rphy->phy_reset); in rockchip_usb2phy_probe()
2352 ret = devm_clk_bulk_get_all(dev, &rphy->clks); in rockchip_usb2phy_probe()
2358 rphy->num_clks = 0; in rockchip_usb2phy_probe()
2360 rphy->num_clks = ret; in rockchip_usb2phy_probe()
2362 ret = clk_bulk_prepare_enable(rphy->num_clks, rphy->clks); in rockchip_usb2phy_probe()
2366 if (rphy->phy_cfg->phy_tuning) { in rockchip_usb2phy_probe()
2367 ret = rphy->phy_cfg->phy_tuning(rphy); in rockchip_usb2phy_probe()
2374 struct rockchip_usb2phy_port *rport = &rphy->ports[index]; in rockchip_usb2phy_probe()
2394 ret = rockchip_usb2phy_host_port_init(rphy, rport, in rockchip_usb2phy_probe()
2399 ret = rockchip_usb2phy_otg_port_init(rphy, rport, in rockchip_usb2phy_probe()
2407 if (++index >= rphy->phy_cfg->num_ports) in rockchip_usb2phy_probe()
2425 ret = rockchip_usb2phy_clk480m_register(rphy); in rockchip_usb2phy_probe()
2431 if (rphy->irq > 0) { in rockchip_usb2phy_probe()
2432 ret = devm_request_threaded_irq(rphy->dev, rphy->irq, NULL, in rockchip_usb2phy_probe()
2436 rphy); in rockchip_usb2phy_probe()
2438 dev_err(rphy->dev, in rockchip_usb2phy_probe()
2445 device_init_wakeup(rphy->dev, true); in rockchip_usb2phy_probe()
2447 device_init_wakeup(rphy->dev, false); in rockchip_usb2phy_probe()
2456 clk_bulk_disable_unprepare(rphy->num_clks, rphy->clks); in rockchip_usb2phy_probe()
2461 rockchip_usb2phy_low_power_enable(struct rockchip_usb2phy *rphy, in rockchip_usb2phy_low_power_enable() argument
2473 ret = property_enable(rphy->grf, &rport->port_cfg->bypass_bc, in rockchip_usb2phy_low_power_enable()
2478 ret = property_enable(rphy->grf, &rport->port_cfg->bypass_otg, in rockchip_usb2phy_low_power_enable()
2483 ret = property_enable(rphy->grf, &rport->port_cfg->vbus_det_en, in rockchip_usb2phy_low_power_enable()
2489 ret = property_enable(rphy->grf, &rport->port_cfg->bypass_host, in rockchip_usb2phy_low_power_enable()
2496 static int rk312x_usb2phy_tuning(struct rockchip_usb2phy *rphy) in rk312x_usb2phy_tuning() argument
2501 ret = regmap_write(rphy->grf, 0x298, 0x00040000); in rk312x_usb2phy_tuning()
2508 static int rk3228_usb2phy_tuning(struct rockchip_usb2phy *rphy) in rk3228_usb2phy_tuning() argument
2513 if (rphy->phy_cfg->reg == 0x760) in rk3228_usb2phy_tuning()
2514 ret = regmap_write(rphy->grf, 0x76c, 0x00070004); in rk3228_usb2phy_tuning()
2519 static int rk3308_usb2phy_tuning(struct rockchip_usb2phy *rphy) in rk3308_usb2phy_tuning() argument
2525 ret = regmap_update_bits(rphy->grf, 0x30, BIT(2), 0); in rk3308_usb2phy_tuning()
2530 ret = regmap_update_bits(rphy->grf, 0, GENMASK(2, 0), BIT(2)); in rk3308_usb2phy_tuning()
2535 ret = regmap_update_bits(rphy->grf, 0x004, GENMASK(7, 5), 0x40); in rk3308_usb2phy_tuning()
2539 ret = regmap_update_bits(rphy->grf, 0x008, BIT(0), 0x1); in rk3308_usb2phy_tuning()
2544 ret = regmap_update_bits(rphy->grf, 0x400, GENMASK(2, 0), BIT(2)); in rk3308_usb2phy_tuning()
2549 ret = regmap_update_bits(rphy->grf, 0x404, GENMASK(7, 5), 0x40); in rk3308_usb2phy_tuning()
2553 ret = regmap_update_bits(rphy->grf, 0x408, BIT(0), 0x1); in rk3308_usb2phy_tuning()
2558 ret = regmap_write(rphy->grf, 0x0, 0x00070004); in rk3308_usb2phy_tuning()
2563 ret = regmap_write(rphy->grf, 0x30, 0x00070004); in rk3308_usb2phy_tuning()
2568 ret = regmap_write(rphy->grf, 0x18, 0x00040000); in rk3308_usb2phy_tuning()
2576 static int rk3328_usb2phy_tuning(struct rockchip_usb2phy *rphy) in rk3328_usb2phy_tuning() argument
2582 ret = regmap_update_bits(rphy->grf, 0x8000, GENMASK(2, 0), BIT(2)); in rk3328_usb2phy_tuning()
2587 ret = regmap_update_bits(rphy->grf, 0x8004, GENMASK(7, 5), 0x40); in rk3328_usb2phy_tuning()
2591 ret = regmap_update_bits(rphy->grf, 0x8008, BIT(0), 0x1); in rk3328_usb2phy_tuning()
2596 ret = regmap_update_bits(rphy->grf, 0x8030, BIT(2), 0); in rk3328_usb2phy_tuning()
2601 ret = regmap_update_bits(rphy->grf, 0x8400, GENMASK(2, 0), BIT(2)); in rk3328_usb2phy_tuning()
2606 ret = regmap_update_bits(rphy->grf, 0x8404, GENMASK(7, 5), 0x40); in rk3328_usb2phy_tuning()
2610 ret = regmap_update_bits(rphy->grf, 0x8408, BIT(0), 0x1); in rk3328_usb2phy_tuning()
2615 ret = regmap_update_bits(rphy->grf, 0x8430, BIT(2), 0); in rk3328_usb2phy_tuning()
2620 ret = regmap_write(rphy->grf, 0x2c, 0xffff0400); in rk3328_usb2phy_tuning()
2625 ret = regmap_write(rphy->grf, 0x0, 0x00070004); in rk3328_usb2phy_tuning()
2630 ret = regmap_write(rphy->grf, 0x30, 0x00070004); in rk3328_usb2phy_tuning()
2635 ret = regmap_write(rphy->grf, 0x18, 0x00040000); in rk3328_usb2phy_tuning()
2642 static int rk3366_usb2phy_tuning(struct rockchip_usb2phy *rphy) in rk3366_usb2phy_tuning() argument
2650 ret |= regmap_write(rphy->grf, 0x0780, open_pre_emphasize); in rk3366_usb2phy_tuning()
2651 ret |= regmap_write(rphy->grf, 0x079c, eye_height_tuning); in rk3366_usb2phy_tuning()
2652 ret |= regmap_write(rphy->grf, 0x07b0, open_pre_emphasize); in rk3366_usb2phy_tuning()
2653 ret |= regmap_write(rphy->grf, 0x07cc, eye_height_tuning); in rk3366_usb2phy_tuning()
2656 ret |= regmap_write(rphy->grf, 0x078c, compensation_tuning); in rk3366_usb2phy_tuning()
2661 static int rk3399_usb2phy_tuning(struct rockchip_usb2phy *rphy) in rk3399_usb2phy_tuning() argument
2663 struct device_node *node = rphy->dev->of_node; in rk3399_usb2phy_tuning()
2666 if (rphy->phy_cfg->reg == 0xe450) { in rk3399_usb2phy_tuning()
2673 ret |= regmap_write(rphy->grf, 0x4480, in rk3399_usb2phy_tuning()
2675 ret |= regmap_write(rphy->grf, 0x44b4, in rk3399_usb2phy_tuning()
2684 ret |= regmap_write(rphy->grf, 0x4500, in rk3399_usb2phy_tuning()
2686 ret |= regmap_write(rphy->grf, 0x4534, in rk3399_usb2phy_tuning()
2693 if (rphy->phy_cfg->reg == 0xe450) { in rk3399_usb2phy_tuning()
2698 ret |= regmap_write(rphy->grf, 0x448c, in rk3399_usb2phy_tuning()
2702 ret |= regmap_write(rphy->grf, 0x44b0, in rk3399_usb2phy_tuning()
2708 ret |= regmap_write(rphy->grf, 0x4480, in rk3399_usb2phy_tuning()
2715 ret |= regmap_write(rphy->grf, 0x450c, in rk3399_usb2phy_tuning()
2719 ret |= regmap_write(rphy->grf, 0x4530, in rk3399_usb2phy_tuning()
2725 ret |= regmap_write(rphy->grf, 0x4500, in rk3399_usb2phy_tuning()
2732 static int rk3528_usb2phy_tuning(struct rockchip_usb2phy *rphy) in rk3528_usb2phy_tuning() argument
2737 phy_clear_bits(rphy->phy_base + 0x30, BIT(2)); in rk3528_usb2phy_tuning()
2740 phy_clear_bits(rphy->phy_base + 0x430, BIT(2)); in rk3528_usb2phy_tuning()
2743 phy_update_bits(rphy->phy_base + 0x30, GENMASK(6, 4), (0x00 << 4)); in rk3528_usb2phy_tuning()
2746 phy_update_bits(rphy->phy_base + 0x430, GENMASK(6, 4), (0x00 << 4)); in rk3528_usb2phy_tuning()
2749 phy_update_bits(rphy->phy_base + 0x94, GENMASK(6, 3), (0x03 << 3)); in rk3528_usb2phy_tuning()
2752 ret |= regmap_write(rphy->grf, 0x80004, 0x00030003); in rk3528_usb2phy_tuning()
2757 static int rk3562_usb2phy_tuning(struct rockchip_usb2phy *rphy) in rk3562_usb2phy_tuning() argument
2762 phy_clear_bits(rphy->phy_base + 0x0030, BIT(2)); in rk3562_usb2phy_tuning()
2763 phy_clear_bits(rphy->phy_base + 0x0430, BIT(2)); in rk3562_usb2phy_tuning()
2766 phy_update_bits(rphy->phy_base, GENMASK(2, 0), 0x04); in rk3562_usb2phy_tuning()
2767 phy_update_bits(rphy->phy_base + 0x0400, GENMASK(2, 0), 0x04); in rk3562_usb2phy_tuning()
2770 phy_update_bits(rphy->phy_base + 0x0030, GENMASK(6, 4), (0x05 << 4)); in rk3562_usb2phy_tuning()
2771 phy_update_bits(rphy->phy_base + 0x0430, GENMASK(6, 4), (0x05 << 4)); in rk3562_usb2phy_tuning()
2774 ret |= regmap_write(rphy->grf, 0x0138, FILTER_COUNTER); in rk3562_usb2phy_tuning()
2777 ret |= regmap_write(rphy->grf, 0x013c, FILTER_COUNTER); in rk3562_usb2phy_tuning()
2780 ret |= regmap_write(rphy->grf, 0x010c, 0x80008000); in rk3562_usb2phy_tuning()
2785 static int rk3568_usb2phy_tuning(struct rockchip_usb2phy *rphy) in rk3568_usb2phy_tuning() argument
2790 phy_clear_bits(rphy->phy_base + 0x30, BIT(2)); in rk3568_usb2phy_tuning()
2793 phy_update_bits(rphy->phy_base, GENMASK(2, 0), 0x04); in rk3568_usb2phy_tuning()
2796 phy_update_bits(rphy->phy_base + 0x0400, GENMASK(2, 0), 0x04); in rk3568_usb2phy_tuning()
2798 if (rphy->phy_cfg->reg == 0xfe8a0000) { in rk3568_usb2phy_tuning()
2800 phy_update_bits(rphy->phy_base + 0x30, GENMASK(6, 4), (0x06 << 4)); in rk3568_usb2phy_tuning()
2806 ret |= regmap_write(rphy->grf, 0x0048, FILTER_COUNTER); in rk3568_usb2phy_tuning()
2812 ret |= regmap_write(rphy->grf, 0x004c, FILTER_COUNTER); in rk3568_usb2phy_tuning()
2816 ret |= regmap_write(rphy->grf, 0x000c, 0x80008000); in rk3568_usb2phy_tuning()
2821 static int rv1106_usb2phy_tuning(struct rockchip_usb2phy *rphy) in rv1106_usb2phy_tuning() argument
2824 phy_update_bits(rphy->phy_base + 0x30, GENMASK(2, 0), 0x07); in rv1106_usb2phy_tuning()
2828 phy_update_bits(rphy->phy_base + 0x40, GENMASK(5, 3), (0x01 << 3)); in rv1106_usb2phy_tuning()
2831 phy_update_bits(rphy->phy_base + 0x40, GENMASK(5, 3), (0x03 << 3)); in rv1106_usb2phy_tuning()
2835 phy_update_bits(rphy->phy_base + 0x64, GENMASK(6, 3), (0x00 << 3)); in rv1106_usb2phy_tuning()
2838 phy_clear_bits(rphy->phy_base + 0x100, BIT(6)); in rv1106_usb2phy_tuning()
2841 phy_update_bits(rphy->phy_base + 0x11c, GENMASK(4, 0), 0x17); in rv1106_usb2phy_tuning()
2844 phy_update_bits(rphy->phy_base + 0x124, GENMASK(4, 2), (0x03 << 2)); in rv1106_usb2phy_tuning()
2847 phy_update_bits(rphy->phy_base + 0x1a4, GENMASK(7, 4), (0x01 << 4)); in rv1106_usb2phy_tuning()
2848 phy_update_bits(rphy->phy_base + 0x1b4, GENMASK(7, 4), (0x01 << 4)); in rv1106_usb2phy_tuning()
2851 phy_set_bits(rphy->phy_base + 0x70, BIT(2)); in rv1106_usb2phy_tuning()
2856 static int rockchip_usb2phy_vbus_det_control(struct rockchip_usb2phy *rphy, in rockchip_usb2phy_vbus_det_control() argument
2862 phy_clear_bits(rphy->phy_base + vbus_det_en->offset, BIT(7)); in rockchip_usb2phy_vbus_det_control()
2865 phy_set_bits(rphy->phy_base + vbus_det_en->offset, BIT(7)); in rockchip_usb2phy_vbus_det_control()
2871 static int rk3588_usb2phy_tuning(struct rockchip_usb2phy *rphy) in rk3588_usb2phy_tuning() argument
2877 ret = regmap_read(rphy->grf, 0x0008, ®); in rk3588_usb2phy_tuning()
2883 ret = regmap_write(rphy->grf, 0x0008, in rk3588_usb2phy_tuning()
2889 ret = rockchip_usb2phy_reset(rphy); in rk3588_usb2phy_tuning()
2894 if (rphy->phy_cfg->reg == 0x0000) { in rk3588_usb2phy_tuning()
2901 ret |= regmap_write(rphy->grf, 0x000c, in rk3588_usb2phy_tuning()
2905 ret |= regmap_write(rphy->grf, 0x0004, in rk3588_usb2phy_tuning()
2909 ret |= regmap_write(rphy->grf, 0x0008, in rk3588_usb2phy_tuning()
2913 ret |= regmap_write(rphy->grf, 0x0010, in rk3588_usb2phy_tuning()
2915 } else if (rphy->phy_cfg->reg == 0x4000) { in rk3588_usb2phy_tuning()
2922 ret |= regmap_write(rphy->grf, 0x000c, in rk3588_usb2phy_tuning()
2926 ret |= regmap_write(rphy->grf, 0x0004, in rk3588_usb2phy_tuning()
2930 ret |= regmap_write(rphy->grf, 0x0008, in rk3588_usb2phy_tuning()
2934 ret |= regmap_write(rphy->grf, 0x0010, in rk3588_usb2phy_tuning()
2936 } else if (rphy->phy_cfg->reg == 0x8000) { in rk3588_usb2phy_tuning()
2943 ret |= regmap_write(rphy->grf, 0x000c, in rk3588_usb2phy_tuning()
2947 ret |= regmap_write(rphy->grf, 0x0004, in rk3588_usb2phy_tuning()
2951 ret |= regmap_write(rphy->grf, 0x0008, in rk3588_usb2phy_tuning()
2953 } else if (rphy->phy_cfg->reg == 0xc000) { in rk3588_usb2phy_tuning()
2960 ret |= regmap_write(rphy->grf, 0x000c, in rk3588_usb2phy_tuning()
2964 ret |= regmap_write(rphy->grf, 0x0004, in rk3588_usb2phy_tuning()
2968 ret |= regmap_write(rphy->grf, 0x0008, in rk3588_usb2phy_tuning()
2978 struct rockchip_usb2phy *rphy = dev_get_drvdata(dev); in rockchip_usb2phy_pm_suspend() local
2979 const struct rockchip_usb2phy_cfg *phy_cfg = rphy->phy_cfg; in rockchip_usb2phy_pm_suspend()
2985 if (device_may_wakeup(rphy->dev)) in rockchip_usb2phy_pm_suspend()
2993 ret = regmap_write(rphy->grf, phy_cfg->ls_filter_con.offset, in rockchip_usb2phy_pm_suspend()
2996 dev_err(rphy->dev, "failed to set ls filter %d\n", ret); in rockchip_usb2phy_pm_suspend()
3000 rport = &rphy->ports[index]; in rockchip_usb2phy_pm_suspend()
3005 ret = regmap_write(rphy->grf, in rockchip_usb2phy_pm_suspend()
3009 dev_err(rphy->dev, "failed to set port ls filter %d\n", ret); in rockchip_usb2phy_pm_suspend()
3013 (rport->id_irq > 0 || rphy->irq > 0)) { in rockchip_usb2phy_pm_suspend()
3015 rport->prev_iddig = property_enabled(rphy->grf, in rockchip_usb2phy_pm_suspend()
3017 ret = rockchip_usb2phy_enable_id_irq(rphy, rport, in rockchip_usb2phy_pm_suspend()
3021 dev_err(rphy->dev, in rockchip_usb2phy_pm_suspend()
3033 ret = rockchip_usb2phy_enable_line_irq(rphy, rport, true); in rockchip_usb2phy_pm_suspend()
3036 dev_err(rphy->dev, "failed to enable linestate irq\n"); in rockchip_usb2phy_pm_suspend()
3044 rockchip_usb2phy_low_power_enable(rphy, rport, true); in rockchip_usb2phy_pm_suspend()
3047 if (wakeup_enable && rphy->irq > 0) in rockchip_usb2phy_pm_suspend()
3048 enable_irq_wake(rphy->irq); in rockchip_usb2phy_pm_suspend()
3055 struct rockchip_usb2phy *rphy = dev_get_drvdata(dev); in rockchip_usb2phy_pm_resume() local
3056 const struct rockchip_usb2phy_cfg *phy_cfg = rphy->phy_cfg; in rockchip_usb2phy_pm_resume()
3063 if (device_may_wakeup(rphy->dev)) in rockchip_usb2phy_pm_resume()
3071 rockchip_usb2phy_reset(rphy); in rockchip_usb2phy_pm_resume()
3074 ret = phy_cfg->phy_tuning(rphy); in rockchip_usb2phy_pm_resume()
3077 ret = regmap_write(rphy->grf, phy_cfg->ls_filter_con.offset, in rockchip_usb2phy_pm_resume()
3080 dev_err(rphy->dev, "failed to set ls filter %d\n", ret); in rockchip_usb2phy_pm_resume()
3084 rport = &rphy->ports[index]; in rockchip_usb2phy_pm_resume()
3089 ret = regmap_write(rphy->grf, in rockchip_usb2phy_pm_resume()
3093 dev_err(rphy->dev, "failed to set port ls filter %d\n", ret); in rockchip_usb2phy_pm_resume()
3097 (rport->id_irq > 0 || rphy->irq > 0)) { in rockchip_usb2phy_pm_resume()
3099 iddig = property_enabled(rphy->grf, in rockchip_usb2phy_pm_resume()
3101 ret = rockchip_usb2phy_enable_id_irq(rphy, rport, in rockchip_usb2phy_pm_resume()
3105 dev_err(rphy->dev, in rockchip_usb2phy_pm_resume()
3114 extcon_set_state_sync(rphy->edev, in rockchip_usb2phy_pm_resume()
3117 extcon_set_state_sync(rphy->edev, in rockchip_usb2phy_pm_resume()
3130 (rport->bvalid_irq > 0 || rport->otg_mux_irq > 0 || rphy->irq > 0) && in rockchip_usb2phy_pm_resume()
3132 ret = rockchip_usb2phy_enable_vbus_irq(rphy, rport, in rockchip_usb2phy_pm_resume()
3135 dev_err(rphy->dev, in rockchip_usb2phy_pm_resume()
3140 if (property_enabled(rphy->grf, &rport->port_cfg->utmi_bvalid)) in rockchip_usb2phy_pm_resume()
3154 rockchip_usb2phy_low_power_enable(rphy, rport, false); in rockchip_usb2phy_pm_resume()
3157 if (wakeup_enable && rphy->irq > 0) in rockchip_usb2phy_pm_resume()
3158 disable_irq_wake(rphy->irq); in rockchip_usb2phy_pm_resume()