Lines Matching +full:dcd +full:- +full:override

1 // SPDX-License-Identifier: GPL-2.0-or-later
9 #include <linux/clk-provider.h>
11 #include <linux/extcon-provider.h>
60 * enum usb_chg_state - Different states involved in USB charger detection.
100 * struct rockchip_chg_det_reg - usb charger detect registers
126 * struct rockchip_usb2phy_port_cfg - usb-phy port configuration.
209 * struct rockchip_usb2phy_cfg - usb-phy configuration.
210 * @reg: the address offset of grf for usb-phy config.
218 * @port_cfgs: usb-phy port configurations.
237 * struct rockchip_usb2phy_port - usb-phy port data.
245 * @typec_vbus_det: Type-C otg vbus detect.
247 * true - use avalid to get vbus status
248 * false - use bvalid to get vbus status
258 * @otg_mux_irq: IRQ number which multiplex otg-id/otg-bvalid/linestate
259 * irqs to one irq in otg-port.
266 * @sw: orientation switch, communicate with TCPM (Type-C Port Manager).
307 * struct rockchip_usb2phy - usb2.0 phy driver data.
357 return rphy->usbgrf == NULL ? rphy->grf : rphy->usbgrf; in get_reg_base()
365 tmp = en ? reg->enable : reg->disable; in property_enable()
366 mask = GENMASK(reg->bitend, reg->bitstart); in property_enable()
367 val = (tmp << reg->bitstart) | (mask << BIT_WRITEABLE_SHIFT); in property_enable()
369 return regmap_write(base, reg->offset, val); in property_enable()
377 unsigned int mask = GENMASK(reg->bitend, reg->bitstart); in property_enabled()
379 ret = regmap_read(base, reg->offset, &orig); in property_enabled()
383 tmp = (orig & mask) >> reg->bitstart; in property_enabled()
384 return tmp == reg->enable; in property_enabled()
392 val = readl(base + reg->offset); in phy_property_enable()
393 tmp = en ? reg->enable : reg->disable; in phy_property_enable()
394 val &= ~GENMASK(reg->bitend, reg->bitstart); in phy_property_enable()
395 val |= tmp << reg->bitstart; in phy_property_enable()
396 writel(val, base + reg->offset); in phy_property_enable()
403 unsigned int mask = GENMASK(reg->bitend, reg->bitstart); in phy_property_enabled()
405 orig = readl(base + reg->offset); in phy_property_enabled()
406 tmp = (orig & mask) >> reg->bitstart; in phy_property_enabled()
407 return tmp == reg->enable; in phy_property_enabled()
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()
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()
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()
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()
527 of_clk_del_provider(rphy->dev->of_node); in rockchip_usb2phy_clk480m_unregister()
528 clk_unregister(rphy->clk480m); in rockchip_usb2phy_clk480m_unregister()
534 struct device_node *node = rphy->dev->of_node; in rockchip_usb2phy_clk480m_register()
544 /* optional override of the clockname */ in rockchip_usb2phy_clk480m_register()
545 of_property_read_string(node, "clock-output-names", &init.name); 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()
579 clk_unregister(rphy->clk480m); in rockchip_usb2phy_clk480m_register()
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()
593 if (PTR_ERR(edev) != -EPROBE_DEFER) 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()
603 return -ENOMEM; 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()
619 /* The caller must hold rport->mutex lock */
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()
643 /* The caller must hold rport->mutex lock */
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()
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()
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()
701 const struct usb2phy_reg *iomux = &rport->port_cfg->bypass_iomux; in rockchip_usb_bypass_uart()
705 mutex_lock(&rport->mutex); in rockchip_usb_bypass_uart()
707 if (en == property_enabled(base, &rport->port_cfg->bypass_sel)) { in rockchip_usb_bypass_uart()
708 dev_info(&rport->phy->dev, in rockchip_usb_bypass_uart()
713 dev_info(&rport->phy->dev, "bypass uart %s\n", en ? "on" : "off"); in rockchip_usb_bypass_uart()
722 * in non-driving mode to disable resistance when use USB in rockchip_usb_bypass_uart()
724 * set phy in non-driving mode, it will cause UART to print in rockchip_usb_bypass_uart()
727 ret |= property_enable(base, &rport->port_cfg->bypass_sel, in rockchip_usb_bypass_uart()
729 ret |= property_enable(base, &rport->port_cfg->bypass_dm_en, in rockchip_usb_bypass_uart()
733 if (iomux->offset) in rockchip_usb_bypass_uart()
734 ret |= property_enable(rphy->grf, iomux, true); in rockchip_usb_bypass_uart()
737 ret |= property_enable(base, &rport->port_cfg->bypass_sel, in rockchip_usb_bypass_uart()
739 ret |= property_enable(base, &rport->port_cfg->bypass_dm_en, in rockchip_usb_bypass_uart()
743 if (iomux->offset) in rockchip_usb_bypass_uart()
744 ret |= property_enable(rphy->grf, iomux, false); in rockchip_usb_bypass_uart()
748 mutex_unlock(&rport->mutex); in rockchip_usb_bypass_uart()
758 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb_bypass_uart_work()
762 mutex_lock(&rport->mutex); in rockchip_usb_bypass_uart_work()
764 iddig = property_enabled(rphy->grf, &rport->port_cfg->utmi_iddig); in rockchip_usb_bypass_uart_work()
766 if (rport->utmi_avalid) 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()
771 mutex_unlock(&rport->mutex); in rockchip_usb_bypass_uart_work()
782 dev_warn(&rport->phy->dev, in rockchip_usb_bypass_uart_work()
785 schedule_delayed_work(&rport->bypass_uart_work, in rockchip_usb_bypass_uart_work()
793 struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent); in rockchip_usb2phy_init()
797 mutex_lock(&rport->mutex); in rockchip_usb2phy_init()
799 if (rport->sel_pipe_phystatus) in rockchip_usb2phy_init()
800 property_enable(rphy->usbctrl_grf, in rockchip_usb2phy_init()
801 &rport->port_cfg->pipe_phystatus, true); in rockchip_usb2phy_init()
803 if (rport->port_id == USB2PHY_PORT_OTG && in rockchip_usb2phy_init()
804 (rport->mode == USB_DR_MODE_PERIPHERAL || in rockchip_usb2phy_init()
805 rport->mode == USB_DR_MODE_OTG)) { in rockchip_usb2phy_init()
807 if (rport->id_irq > 0 || rport->otg_mux_irq > 0 || in rockchip_usb2phy_init()
808 rphy->irq > 0) { in rockchip_usb2phy_init()
812 dev_err(rphy->dev, in rockchip_usb2phy_init()
819 if ((rport->bvalid_irq > 0 || rport->otg_mux_irq > 0 || in rockchip_usb2phy_init()
820 rphy->irq > 0) && !rport->vbus_always_on) { in rockchip_usb2phy_init()
824 dev_err(rphy->dev, in rockchip_usb2phy_init()
828 schedule_delayed_work(&rport->otg_sm_work, in rockchip_usb2phy_init()
829 rport->typec_vbus_det ? 0 : OTG_SCHEDULE_DELAY); in rockchip_usb2phy_init()
831 } else if (rport->port_id == USB2PHY_PORT_HOST) { in rockchip_usb2phy_init()
832 if (rport->port_cfg->disfall_en.offset) { in rockchip_usb2phy_init()
833 ret = regmap_read(rphy->grf, rport->port_cfg->utmi_ls.offset, &ul); in rockchip_usb2phy_init()
836 ul_mask = GENMASK(rport->port_cfg->utmi_ls.bitend, in rockchip_usb2phy_init()
837 rport->port_cfg->utmi_ls.bitstart); in rockchip_usb2phy_init()
838 rport->host_disconnect = (ul & ul_mask) == 0 ? true : false; in rockchip_usb2phy_init()
841 dev_err(rphy->dev, "failed to enable disconnect irq\n"); in rockchip_usb2phy_init()
849 dev_err(rphy->dev, "failed to enable linestate irq\n"); in rockchip_usb2phy_init()
853 schedule_delayed_work(&rport->sm_work, SCHEDULE_DELAY); in rockchip_usb2phy_init()
857 mutex_unlock(&rport->mutex); in rockchip_usb2phy_init()
864 struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent); in rockchip_usb2phy_power_on()
868 dev_dbg(&rport->phy->dev, "port power on\n"); in rockchip_usb2phy_power_on()
870 if (rport->bypass_uart_en) { in rockchip_usb2phy_power_on()
873 dev_warn(&rport->phy->dev, in rockchip_usb2phy_power_on()
879 mutex_lock(&rport->mutex); in rockchip_usb2phy_power_on()
881 if (!rport->suspended) { in rockchip_usb2phy_power_on()
886 ret = clk_prepare_enable(rphy->clk480m); in rockchip_usb2phy_power_on()
890 ret = property_enable(base, &rport->port_cfg->phy_sus, false); in rockchip_usb2phy_power_on()
902 if (rport->port_id == USB2PHY_PORT_OTG && in rockchip_usb2phy_power_on()
903 of_device_is_compatible(rphy->dev->of_node, "rockchip,rk3588-usb2phy")) { in rockchip_usb2phy_power_on()
912 rport->suspended = false; in rockchip_usb2phy_power_on()
915 mutex_unlock(&rport->mutex); in rockchip_usb2phy_power_on()
918 if (rport->bypass_uart_en) in rockchip_usb2phy_power_on()
919 schedule_delayed_work(&rport->bypass_uart_work, 0); in rockchip_usb2phy_power_on()
928 struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent); in rockchip_usb2phy_power_off()
932 dev_dbg(&rport->phy->dev, "port power off\n"); in rockchip_usb2phy_power_off()
934 mutex_lock(&rport->mutex); in rockchip_usb2phy_power_off()
936 if (rport->suspended) { in rockchip_usb2phy_power_off()
941 ret = property_enable(base, &rport->port_cfg->phy_sus, true); in rockchip_usb2phy_power_off()
945 rport->suspended = true; in rockchip_usb2phy_power_off()
946 clk_disable_unprepare(rphy->clk480m); in rockchip_usb2phy_power_off()
949 mutex_unlock(&rport->mutex); in rockchip_usb2phy_power_off()
952 if (rport->bypass_uart_en) in rockchip_usb2phy_power_off()
953 schedule_delayed_work(&rport->bypass_uart_work, 0); in rockchip_usb2phy_power_off()
962 if (rport->port_id == USB2PHY_PORT_HOST) in rockchip_usb2phy_exit()
963 cancel_delayed_work_sync(&rport->sm_work); in rockchip_usb2phy_exit()
964 else if (rport->port_id == USB2PHY_PORT_OTG && in rockchip_usb2phy_exit()
965 rport->otg_sm_work.work.func) in rockchip_usb2phy_exit()
966 flush_delayed_work(&rport->otg_sm_work); in rockchip_usb2phy_exit()
976 if (!rport->vbus) in rockchip_set_vbus_power()
979 if (en && !rport->vbus_enabled) { in rockchip_set_vbus_power()
980 ret = regulator_enable(rport->vbus); in rockchip_set_vbus_power()
982 dev_err(&rport->phy->dev, in rockchip_set_vbus_power()
984 } else if (!en && rport->vbus_enabled) { in rockchip_set_vbus_power()
985 ret = regulator_disable(rport->vbus); in rockchip_set_vbus_power()
989 rport->vbus_enabled = en; in rockchip_set_vbus_power()
998 struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent); in rockchip_usb2phy_set_mode()
1002 if (rport->port_id != USB2PHY_PORT_OTG) in rockchip_usb2phy_set_mode()
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()
1029 if (rport->vbus_always_on) in rockchip_usb2phy_set_mode()
1030 extcon_set_state(rphy->edev, EXTCON_USB, true); in rockchip_usb2phy_set_mode()
1031 rport->perip_connected = true; in rockchip_usb2phy_set_mode()
1038 dev_err(&rport->phy->dev, in rockchip_usb2phy_set_mode()
1043 extcon_set_state_sync(rphy->edev, EXTCON_USB_VBUS_EN, true); in rockchip_usb2phy_set_mode()
1045 if (rport->vbus_always_on) in rockchip_usb2phy_set_mode()
1046 extcon_set_state(rphy->edev, EXTCON_USB, false); in rockchip_usb2phy_set_mode()
1047 rport->perip_connected = false; in rockchip_usb2phy_set_mode()
1053 dev_info(&rport->phy->dev, "illegal mode\n"); 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()
1085 for (index = 0; index < rphy->phy_cfg->num_ports; index++) { in otg_mode_show()
1086 rport = &rphy->ports[index]; in otg_mode_show()
1087 if (rport->port_id == USB2PHY_PORT_OTG) in otg_mode_show()
1092 dev_err(rphy->dev, "Fail to get otg port\n"); in otg_mode_show()
1093 return -EINVAL; in otg_mode_show()
1094 } else if (rport->port_id != USB2PHY_PORT_OTG) { in otg_mode_show()
1095 dev_err(rphy->dev, "No support otg\n"); in otg_mode_show()
1096 return -EINVAL; in otg_mode_show()
1099 switch (rport->mode) { in otg_mode_show()
1110 return -EINVAL; in otg_mode_show()
1124 for (index = 0; index < rphy->phy_cfg->num_ports; index++) { in otg_mode_store()
1125 rport = &rphy->ports[index]; in otg_mode_store()
1126 if (rport->port_id == USB2PHY_PORT_OTG) in otg_mode_store()
1131 dev_err(rphy->dev, "Fail to get otg port\n"); in otg_mode_store()
1132 rc = -EINVAL; in otg_mode_store()
1134 } else if (rport->port_id != USB2PHY_PORT_OTG || in otg_mode_store()
1135 rport->mode == USB_DR_MODE_UNKNOWN) { in otg_mode_store()
1136 dev_err(rphy->dev, "No support otg\n"); in otg_mode_store()
1137 rc = -EINVAL; in otg_mode_store()
1141 mutex_lock(&rport->mutex); in otg_mode_store()
1150 dev_err(rphy->dev, "Error mode! Input 'otg' or 'host' or 'peripheral'\n"); in otg_mode_store()
1151 rc = -EINVAL; in otg_mode_store()
1155 if (rport->mode == new_dr_mode) { in otg_mode_store()
1156 dev_warn(rphy->dev, "Same as current mode\n"); in otg_mode_store()
1160 rport->mode = new_dr_mode; in otg_mode_store()
1162 switch (rport->mode) { in otg_mode_store()
1164 rockchip_usb2phy_set_mode(rport->phy, PHY_MODE_USB_HOST, 0); in otg_mode_store()
1165 property_enable(base, &rport->port_cfg->iddig_output, false); in otg_mode_store()
1166 property_enable(base, &rport->port_cfg->iddig_en, true); in otg_mode_store()
1169 rockchip_usb2phy_set_mode(rport->phy, PHY_MODE_USB_DEVICE, 0); in otg_mode_store()
1170 property_enable(base, &rport->port_cfg->iddig_output, true); in otg_mode_store()
1171 property_enable(base, &rport->port_cfg->iddig_en, true); in otg_mode_store()
1174 rockchip_usb2phy_set_mode(rport->phy, PHY_MODE_USB_OTG, 0); in otg_mode_store()
1175 property_enable(base, &rport->port_cfg->iddig_output, false); in otg_mode_store()
1176 property_enable(base, &rport->port_cfg->iddig_en, false); in otg_mode_store()
1183 mutex_unlock(&rport->mutex); in otg_mode_store()
1206 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_otg_sm_work()
1211 mutex_lock(&rport->mutex); in rockchip_usb2phy_otg_sm_work()
1213 if (rport->port_cfg->bvalid_grf_con.enable && rport->typec_vbus_det) in rockchip_usb2phy_otg_sm_work()
1214 rport->vbus_attached = in rockchip_usb2phy_otg_sm_work()
1215 property_enabled(rphy->grf, &rport->port_cfg->bvalid_grf_con); in rockchip_usb2phy_otg_sm_work()
1216 else if (rport->utmi_avalid) in rockchip_usb2phy_otg_sm_work()
1217 rport->vbus_attached = in rockchip_usb2phy_otg_sm_work()
1218 property_enabled(rphy->grf, &rport->port_cfg->utmi_avalid); in rockchip_usb2phy_otg_sm_work()
1220 rport->vbus_attached = in rockchip_usb2phy_otg_sm_work()
1221 property_enabled(rphy->grf, &rport->port_cfg->utmi_bvalid); in rockchip_usb2phy_otg_sm_work()
1226 dev_dbg(&rport->phy->dev, "%s otg sm work\n", in rockchip_usb2phy_otg_sm_work()
1227 usb_otg_state_string(rport->state)); in rockchip_usb2phy_otg_sm_work()
1229 switch (rport->state) { in rockchip_usb2phy_otg_sm_work()
1231 rport->state = OTG_STATE_B_IDLE; in rockchip_usb2phy_otg_sm_work()
1232 if (!rport->vbus_attached) { in rockchip_usb2phy_otg_sm_work()
1233 mutex_unlock(&rport->mutex); in rockchip_usb2phy_otg_sm_work()
1234 if (!rport->dis_u2_susphy) in rockchip_usb2phy_otg_sm_work()
1235 rockchip_usb2phy_power_off(rport->phy); in rockchip_usb2phy_otg_sm_work()
1236 mutex_lock(&rport->mutex); 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()
1242 dev_dbg(&rport->phy->dev, "usb otg host connect\n"); in rockchip_usb2phy_otg_sm_work()
1243 rport->state = OTG_STATE_A_HOST; 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()
1246 mutex_unlock(&rport->mutex); in rockchip_usb2phy_otg_sm_work()
1247 rockchip_usb2phy_power_on(rport->phy); in rockchip_usb2phy_otg_sm_work()
1249 } else if (rport->vbus_attached) { in rockchip_usb2phy_otg_sm_work()
1250 dev_dbg(&rport->phy->dev, "vbus_attach\n"); in rockchip_usb2phy_otg_sm_work()
1251 switch (rphy->chg_state) { in rockchip_usb2phy_otg_sm_work()
1253 mutex_unlock(&rport->mutex); in rockchip_usb2phy_otg_sm_work()
1254 schedule_delayed_work(&rport->chg_work, 0); in rockchip_usb2phy_otg_sm_work()
1257 switch (rphy->chg_type) { in rockchip_usb2phy_otg_sm_work()
1259 dev_dbg(&rport->phy->dev, "sdp cable is connected\n"); in rockchip_usb2phy_otg_sm_work()
1260 wake_lock(&rport->wakelock); in rockchip_usb2phy_otg_sm_work()
1262 mutex_unlock(&rport->mutex); in rockchip_usb2phy_otg_sm_work()
1263 rockchip_usb2phy_power_on(rport->phy); in rockchip_usb2phy_otg_sm_work()
1264 mutex_lock(&rport->mutex); in rockchip_usb2phy_otg_sm_work()
1265 rport->state = OTG_STATE_B_PERIPHERAL; in rockchip_usb2phy_otg_sm_work()
1266 rport->perip_connected = true; in rockchip_usb2phy_otg_sm_work()
1270 dev_dbg(&rport->phy->dev, "dcp cable is connected\n"); in rockchip_usb2phy_otg_sm_work()
1275 dev_dbg(&rport->phy->dev, "cdp cable is connected\n"); in rockchip_usb2phy_otg_sm_work()
1276 wake_lock(&rport->wakelock); in rockchip_usb2phy_otg_sm_work()
1278 mutex_unlock(&rport->mutex); in rockchip_usb2phy_otg_sm_work()
1279 rockchip_usb2phy_power_on(rport->phy); in rockchip_usb2phy_otg_sm_work()
1280 mutex_lock(&rport->mutex); in rockchip_usb2phy_otg_sm_work()
1281 rport->state = OTG_STATE_B_PERIPHERAL; in rockchip_usb2phy_otg_sm_work()
1282 rport->perip_connected = true; 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()
1295 rport->perip_connected = false; in rockchip_usb2phy_otg_sm_work()
1296 mutex_unlock(&rport->mutex); in rockchip_usb2phy_otg_sm_work()
1297 if (!rport->dis_u2_susphy) in rockchip_usb2phy_otg_sm_work()
1298 rockchip_usb2phy_power_off(rport->phy); in rockchip_usb2phy_otg_sm_work()
1299 mutex_lock(&rport->mutex); 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()
1308 dev_dbg(&rport->phy->dev, "usb otg host connect\n"); in rockchip_usb2phy_otg_sm_work()
1309 rport->state = OTG_STATE_A_HOST; 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()
1312 rport->perip_connected = false; in rockchip_usb2phy_otg_sm_work()
1314 wake_unlock(&rport->wakelock); in rockchip_usb2phy_otg_sm_work()
1315 } else if (!rport->vbus_attached) { in rockchip_usb2phy_otg_sm_work()
1316 dev_dbg(&rport->phy->dev, "usb disconnect\n"); in rockchip_usb2phy_otg_sm_work()
1317 rport->state = OTG_STATE_B_IDLE; in rockchip_usb2phy_otg_sm_work()
1318 rport->perip_connected = false; 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()
1322 wake_unlock(&rport->wakelock); in rockchip_usb2phy_otg_sm_work()
1326 if (extcon_get_state(rphy->edev, EXTCON_USB_HOST) == 0) { in rockchip_usb2phy_otg_sm_work()
1327 dev_dbg(&rport->phy->dev, "usb otg host disconnect\n"); in rockchip_usb2phy_otg_sm_work()
1328 rport->state = OTG_STATE_B_IDLE; in rockchip_usb2phy_otg_sm_work()
1331 mutex_unlock(&rport->mutex); in rockchip_usb2phy_otg_sm_work()
1336 mutex_unlock(&rport->mutex); 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()
1342 cable, rport->vbus_attached); in rockchip_usb2phy_otg_sm_work()
1344 if (!rport->vbus_attached) in rockchip_usb2phy_otg_sm_work()
1346 } else if (rport->state == OTG_STATE_A_HOST && in rockchip_usb2phy_otg_sm_work()
1347 extcon_get_state(rphy->edev, cable)) { in rockchip_usb2phy_otg_sm_work()
1351 * in high, so the rport->vbus_attached may not be 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()
1360 rport->perip_connected)) { in rockchip_usb2phy_otg_sm_work()
1361 extcon_set_state_sync(rphy->edev, in rockchip_usb2phy_otg_sm_work()
1363 rport->perip_connected); in rockchip_usb2phy_otg_sm_work()
1364 extcon_sync(rphy->edev, EXTCON_USB_HOST); in rockchip_usb2phy_otg_sm_work()
1367 schedule_delayed_work(&rport->otg_sm_work, delay); in rockchip_usb2phy_otg_sm_work()
1369 mutex_unlock(&rport->mutex); in rockchip_usb2phy_otg_sm_work()
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()
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()
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()
1429 dev_dbg(&rport->phy->dev, "chg detection work state = %d\n", in rockchip_chg_detect_work()
1430 rphy->chg_state); in rockchip_chg_detect_work()
1435 * 2. Set the utmi_opmode in non-driving mode. in rockchip_chg_detect_work()
1440 switch (rphy->chg_state) { in rockchip_chg_detect_work()
1442 mutex_lock(&rport->mutex); in rockchip_chg_detect_work()
1444 phy_sus_reg = &rport->port_cfg->phy_sus; in rockchip_chg_detect_work()
1445 ret = regmap_read(base, phy_sus_reg->offset, in rockchip_chg_detect_work()
1446 &rphy->phy_sus_cfg); in rockchip_chg_detect_work()
1448 dev_err(&rport->phy->dev, in rockchip_chg_detect_work()
1450 phy_sus_reg->offset, ret); in rockchip_chg_detect_work()
1451 mutex_unlock(&rport->mutex); in rockchip_chg_detect_work()
1456 property_enable(base, &rphy->phy_cfg->chg_det.chg_mode, true); in rockchip_chg_detect_work()
1457 /* Start DCD processing stage 1 */ 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()
1472 /* Turn off DCD circuitry */ 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()
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()
1500 /* Turn off DCD circuitry */ 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()
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()
1533 rport->port_cfg->phy_sus.offset) in rockchip_chg_detect_work()
1534 property_enable(base, &rphy->phy_cfg->chg_det.chg_mode, false); in rockchip_chg_detect_work()
1537 phy_sus_reg = &rport->port_cfg->phy_sus; in rockchip_chg_detect_work()
1538 mask = GENMASK(phy_sus_reg->bitend, phy_sus_reg->bitstart); in rockchip_chg_detect_work()
1539 ret = regmap_write(base, phy_sus_reg->offset, in rockchip_chg_detect_work()
1540 (rphy->phy_sus_cfg | (mask << BIT_WRITEABLE_SHIFT))); in rockchip_chg_detect_work()
1542 dev_err(&rport->phy->dev, in rockchip_chg_detect_work()
1544 phy_sus_reg->offset, ret); in rockchip_chg_detect_work()
1545 mutex_unlock(&rport->mutex); in rockchip_chg_detect_work()
1546 rockchip_usb2phy_otg_sm_work(&rport->otg_sm_work.work); in rockchip_chg_detect_work()
1547 dev_dbg(&rport->phy->dev, "charger = %s\n", in rockchip_chg_detect_work()
1548 chg_to_string(rphy->chg_type)); in rockchip_chg_detect_work()
1551 mutex_unlock(&rport->mutex); in rockchip_chg_detect_work()
1560 schedule_delayed_work(&rport->chg_work, delay); in rockchip_chg_detect_work()
1564 * The function manage host-phy port state and suspend/resume phy port
1580 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_sm_work()
1585 if (!rport->port_cfg->utmi_ls.offset || in rockchip_usb2phy_sm_work()
1586 (!rport->port_cfg->utmi_hstdet.offset && in rockchip_usb2phy_sm_work()
1587 !rport->port_cfg->disfall_en.offset)) { in rockchip_usb2phy_sm_work()
1588 dev_dbg(&rport->phy->dev, "some property may not be specified\n"); in rockchip_usb2phy_sm_work()
1592 mutex_lock(&rport->mutex); in rockchip_usb2phy_sm_work()
1594 ret = regmap_read(rphy->grf, rport->port_cfg->utmi_ls.offset, &ul); in rockchip_usb2phy_sm_work()
1598 ul_mask = GENMASK(rport->port_cfg->utmi_ls.bitend, in rockchip_usb2phy_sm_work()
1599 rport->port_cfg->utmi_ls.bitstart); in rockchip_usb2phy_sm_work()
1601 if (rport->port_cfg->utmi_hstdet.offset) { in rockchip_usb2phy_sm_work()
1602 ret = regmap_read(rphy->grf, rport->port_cfg->utmi_hstdet.offset, &uhd); in rockchip_usb2phy_sm_work()
1606 uhd_mask = GENMASK(rport->port_cfg->utmi_hstdet.bitend, in rockchip_usb2phy_sm_work()
1607 rport->port_cfg->utmi_hstdet.bitstart); in rockchip_usb2phy_sm_work()
1609 sh = rport->port_cfg->utmi_hstdet.bitend - in rockchip_usb2phy_sm_work()
1610 rport->port_cfg->utmi_hstdet.bitstart + 1; in rockchip_usb2phy_sm_work()
1612 state = ((uhd & uhd_mask) >> rport->port_cfg->utmi_hstdet.bitstart) | in rockchip_usb2phy_sm_work()
1613 (((ul & ul_mask) >> rport->port_cfg->utmi_ls.bitstart) << sh); in rockchip_usb2phy_sm_work()
1615 state = ((ul & ul_mask) >> rport->port_cfg->utmi_ls.bitstart) << 1 | in rockchip_usb2phy_sm_work()
1616 rport->host_disconnect; in rockchip_usb2phy_sm_work()
1621 dev_dbg(&rport->phy->dev, "HS online\n"); in rockchip_usb2phy_sm_work()
1629 * Plus, there are two cases, one is D- Line pull-up, and D+ in rockchip_usb2phy_sm_work()
1630 * line pull-down, the state is 4; another is D+ line pull-up, in rockchip_usb2phy_sm_work()
1631 * and D- line pull-down, the state is 2. in rockchip_usb2phy_sm_work()
1633 if (!rport->suspended) { in rockchip_usb2phy_sm_work()
1634 /* D- line pull-up, D+ line pull-down */ in rockchip_usb2phy_sm_work()
1635 dev_dbg(&rport->phy->dev, "FS/LS online\n"); in rockchip_usb2phy_sm_work()
1640 if (rport->suspended) { in rockchip_usb2phy_sm_work()
1641 dev_dbg(&rport->phy->dev, "Connected\n"); in rockchip_usb2phy_sm_work()
1642 mutex_unlock(&rport->mutex); in rockchip_usb2phy_sm_work()
1643 rockchip_usb2phy_power_on(rport->phy); in rockchip_usb2phy_sm_work()
1644 mutex_lock(&rport->mutex); in rockchip_usb2phy_sm_work()
1645 rport->suspended = false; in rockchip_usb2phy_sm_work()
1647 /* D+ line pull-up, D- line pull-down */ in rockchip_usb2phy_sm_work()
1648 dev_dbg(&rport->phy->dev, "FS/LS online\n"); in rockchip_usb2phy_sm_work()
1652 if (rport->suspended) { in rockchip_usb2phy_sm_work()
1653 dev_dbg(&rport->phy->dev, "linestate is SE1, power on phy\n"); in rockchip_usb2phy_sm_work()
1654 mutex_unlock(&rport->mutex); in rockchip_usb2phy_sm_work()
1655 rockchip_usb2phy_power_on(rport->phy); in rockchip_usb2phy_sm_work()
1656 mutex_lock(&rport->mutex); in rockchip_usb2phy_sm_work()
1657 rport->suspended = false; in rockchip_usb2phy_sm_work()
1661 if (!rport->suspended) { in rockchip_usb2phy_sm_work()
1662 dev_dbg(&rport->phy->dev, "Disconnected\n"); in rockchip_usb2phy_sm_work()
1663 mutex_unlock(&rport->mutex); in rockchip_usb2phy_sm_work()
1664 rockchip_usb2phy_power_off(rport->phy); in rockchip_usb2phy_sm_work()
1665 mutex_lock(&rport->mutex); in rockchip_usb2phy_sm_work()
1666 rport->suspended = true; in rockchip_usb2phy_sm_work()
1671 * plug-in irq. in rockchip_usb2phy_sm_work()
1679 mutex_unlock(&rport->mutex); in rockchip_usb2phy_sm_work()
1682 dev_dbg(&rport->phy->dev, "unknown phy state %d\n", state); in rockchip_usb2phy_sm_work()
1687 mutex_unlock(&rport->mutex); in rockchip_usb2phy_sm_work()
1688 schedule_delayed_work(&rport->sm_work, SCHEDULE_DELAY); in rockchip_usb2phy_sm_work()
1694 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_linestate_irq()
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()
1700 dev_dbg(&rport->phy->dev, "linestate interrupt\n"); in rockchip_usb2phy_linestate_irq()
1702 mutex_lock(&rport->mutex); in rockchip_usb2phy_linestate_irq()
1712 if (rport->port_id == USB2PHY_PORT_HOST && rport->port_cfg->disfall_en.offset) in rockchip_usb2phy_linestate_irq()
1713 rport->host_disconnect = false; in rockchip_usb2phy_linestate_irq()
1715 mutex_unlock(&rport->mutex); in rockchip_usb2phy_linestate_irq()
1722 if (rport->suspended && rport->port_id == USB2PHY_PORT_HOST) in rockchip_usb2phy_linestate_irq()
1723 rockchip_usb2phy_sm_work(&rport->sm_work.work); in rockchip_usb2phy_linestate_irq()
1731 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_bvalid_irq()
1733 if (!property_enabled(rphy->grf, &rport->port_cfg->bvalid_det_st)) in rockchip_usb2phy_bvalid_irq()
1736 mutex_lock(&rport->mutex); in rockchip_usb2phy_bvalid_irq()
1739 property_enable(rphy->grf, &rport->port_cfg->bvalid_det_clr, true); in rockchip_usb2phy_bvalid_irq()
1741 mutex_unlock(&rport->mutex); in rockchip_usb2phy_bvalid_irq()
1743 if (rport->bypass_uart_en) in rockchip_usb2phy_bvalid_irq()
1746 if (rport->otg_sm_work.work.func) { in rockchip_usb2phy_bvalid_irq()
1747 cancel_delayed_work_sync(&rport->otg_sm_work); in rockchip_usb2phy_bvalid_irq()
1748 rockchip_usb2phy_otg_sm_work(&rport->otg_sm_work.work); in rockchip_usb2phy_bvalid_irq()
1757 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_id_irq()
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()
1764 mutex_lock(&rport->mutex); 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()
1787 mutex_unlock(&rport->mutex); in rockchip_usb2phy_id_irq()
1795 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_host_disc_irq()
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()
1801 mutex_lock(&rport->mutex); 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()
1807 rport->host_disconnect = false; 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()
1811 rport->host_disconnect = true; in rockchip_usb2phy_host_disc_irq()
1814 mutex_unlock(&rport->mutex); in rockchip_usb2phy_host_disc_irq()
1838 for (index = 0; index < rphy->phy_cfg->num_ports; index++) { in rockchip_usb2phy_irq()
1839 rport = &rphy->ports[index]; in rockchip_usb2phy_irq()
1840 if (!rport->phy) in rockchip_usb2phy_irq()
1847 if (rport->port_id == USB2PHY_PORT_HOST && in rockchip_usb2phy_irq()
1848 rport->port_cfg->disfall_en.offset) in rockchip_usb2phy_irq()
1858 if (rport->port_id == USB2PHY_PORT_OTG && in rockchip_usb2phy_irq()
1859 rport->mode != USB_DR_MODE_UNKNOWN) { in rockchip_usb2phy_irq()
1860 if (rport->mode == USB_DR_MODE_HOST) { in rockchip_usb2phy_irq()
1869 force_mode = property_enabled(rphy->grf, in rockchip_usb2phy_irq()
1870 &rport->port_cfg->iddig_en); in rockchip_usb2phy_irq()
1875 if (!rport->vbus_always_on) in rockchip_usb2phy_irq()
1895 if (rphy->irq > 0) in rockchip_usb2phy_port_irq_init()
1900 * the irqs of otg port. So probe the otg-mux interrupt first, in rockchip_usb2phy_port_irq_init()
1903 rport->otg_mux_irq = of_irq_get_byname(child_np, "otg-mux"); in rockchip_usb2phy_port_irq_init()
1904 if (rport->otg_mux_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()
1913 "failed to request otg-mux irq handle\n"); in rockchip_usb2phy_port_irq_init()
1919 rport->ls_irq = of_irq_get_byname(child_np, "linestate"); in rockchip_usb2phy_port_irq_init()
1920 if (rport->ls_irq <= 0) { in rockchip_usb2phy_port_irq_init()
1921 dev_err(rphy->dev, "no linestate irq provided\n"); in rockchip_usb2phy_port_irq_init()
1922 return -EINVAL; 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()
1939 if (rport->port_id == USB2PHY_PORT_HOST || in rockchip_usb2phy_port_irq_init()
1940 rport->mode == USB_DR_MODE_HOST || in rockchip_usb2phy_port_irq_init()
1941 rport->mode == USB_DR_MODE_UNKNOWN) in rockchip_usb2phy_port_irq_init()
1945 if (!rport->vbus_always_on) { in rockchip_usb2phy_port_irq_init()
1946 rport->bvalid_irq = of_irq_get_byname(child_np, in rockchip_usb2phy_port_irq_init()
1947 "otg-bvalid"); in rockchip_usb2phy_port_irq_init()
1948 if (rport->bvalid_irq <= 0) { in rockchip_usb2phy_port_irq_init()
1949 dev_err(rphy->dev, "no bvalid irq provided\n"); in rockchip_usb2phy_port_irq_init()
1950 return -EINVAL; in rockchip_usb2phy_port_irq_init()
1953 ret = devm_request_threaded_irq(rphy->dev, in rockchip_usb2phy_port_irq_init()
1954 rport->bvalid_irq, in rockchip_usb2phy_port_irq_init()
1961 dev_err(rphy->dev, in rockchip_usb2phy_port_irq_init()
1962 "failed to request otg-bvalid irq handle\n"); in rockchip_usb2phy_port_irq_init()
1968 if (rphy->edev_self) { in rockchip_usb2phy_port_irq_init()
1969 rport->id_irq = of_irq_get_byname(child_np, "otg-id"); in rockchip_usb2phy_port_irq_init()
1970 if (rport->id_irq <= 0) { in rockchip_usb2phy_port_irq_init()
1971 dev_err(rphy->dev, "no otg id irq provided\n"); in rockchip_usb2phy_port_irq_init()
1972 return -EINVAL; in rockchip_usb2phy_port_irq_init()
1975 ret = devm_request_threaded_irq(rphy->dev, in rockchip_usb2phy_port_irq_init()
1976 rport->id_irq, NULL, in rockchip_usb2phy_port_irq_init()
1982 dev_err(rphy->dev, in rockchip_usb2phy_port_irq_init()
1983 "failed to request otg-id irq handle\n"); in rockchip_usb2phy_port_irq_init()
1994 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_usb_bvalid_enable()
1995 const struct rockchip_usb2phy_port_cfg *cfg = rport->port_cfg; in rockchip_usb2phy_usb_bvalid_enable()
1997 if (cfg->bvalid_phy_con.enable) in rockchip_usb2phy_usb_bvalid_enable()
1998 property_enable(rphy->grf, &cfg->bvalid_phy_con, enable); in rockchip_usb2phy_usb_bvalid_enable()
2000 if (cfg->bvalid_grf_con.enable) in rockchip_usb2phy_usb_bvalid_enable()
2001 property_enable(rphy->grf, &cfg->bvalid_grf_con, enable); in rockchip_usb2phy_usb_bvalid_enable()
2009 dev_dbg(&rport->phy->dev, "type-c orientation: %d\n", orien); in rockchip_usb2phy_orien_sw_set()
2011 mutex_lock(&rport->mutex); in rockchip_usb2phy_orien_sw_set()
2013 mutex_unlock(&rport->mutex); in rockchip_usb2phy_orien_sw_set()
2023 struct device *dev = rphy->dev; in rockchip_usb2phy_setup_orien_switch()
2029 rport->sw = typec_switch_register(dev, &sw_desc); in rockchip_usb2phy_setup_orien_switch()
2030 if (IS_ERR(rport->sw)) { in rockchip_usb2phy_setup_orien_switch()
2032 PTR_ERR(rport->sw)); in rockchip_usb2phy_setup_orien_switch()
2033 return PTR_ERR(rport->sw); in rockchip_usb2phy_setup_orien_switch()
2043 typec_switch_unregister(rport->sw); in rockchip_usb2phy_orien_switch_unregister()
2053 rport->port_id = USB2PHY_PORT_HOST; in rockchip_usb2phy_host_port_init()
2054 rport->port_cfg = &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_HOST]; in rockchip_usb2phy_host_port_init()
2057 rport->low_power_en = in rockchip_usb2phy_host_port_init()
2058 of_property_read_bool(child_np, "rockchip,low-power-mode"); in rockchip_usb2phy_host_port_init()
2060 mutex_init(&rport->mutex); in rockchip_usb2phy_host_port_init()
2061 INIT_DELAYED_WORK(&rport->sm_work, rockchip_usb2phy_sm_work); 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()
2070 * Let us put phy-port into suspend mode here for saving power in rockchip_usb2phy_host_port_init()
2074 ret = property_enable(base, &rport->port_cfg->phy_sus, true); in rockchip_usb2phy_host_port_init()
2077 rport->suspended = true; in rockchip_usb2phy_host_port_init()
2088 schedule_delayed_work(&rport->otg_sm_work, OTG_SCHEDULE_DELAY); in rockchip_otg_event()
2106 rport->port_id = USB2PHY_PORT_OTG; in rockchip_usb2phy_otg_port_init()
2107 rport->port_cfg = &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_OTG]; in rockchip_usb2phy_otg_port_init()
2108 rport->state = OTG_STATE_UNDEFINED; in rockchip_usb2phy_otg_port_init()
2109 rport->vbus_attached = false; in rockchip_usb2phy_otg_port_init()
2110 rport->vbus_enabled = false; in rockchip_usb2phy_otg_port_init()
2111 rport->perip_connected = false; in rockchip_usb2phy_otg_port_init()
2112 rport->prev_iddig = true; in rockchip_usb2phy_otg_port_init()
2114 mutex_init(&rport->mutex); in rockchip_usb2phy_otg_port_init()
2117 rport->bypass_uart_en = in rockchip_usb2phy_otg_port_init()
2118 of_property_read_bool(child_np, "rockchip,bypass-uart"); in rockchip_usb2phy_otg_port_init()
2119 rport->vbus_always_on = in rockchip_usb2phy_otg_port_init()
2120 of_property_read_bool(child_np, "rockchip,vbus-always-on"); in rockchip_usb2phy_otg_port_init()
2121 rport->utmi_avalid = in rockchip_usb2phy_otg_port_init()
2122 of_property_read_bool(child_np, "rockchip,utmi-avalid"); in rockchip_usb2phy_otg_port_init()
2123 rport->dis_u2_susphy = in rockchip_usb2phy_otg_port_init()
2124 of_property_read_bool(child_np, "rockchip,dis-u2-susphy"); in rockchip_usb2phy_otg_port_init()
2127 rport->low_power_en = in rockchip_usb2phy_otg_port_init()
2128 of_property_read_bool(child_np, "rockchip,low-power-mode"); in rockchip_usb2phy_otg_port_init()
2130 /* For type-c with vbus_det always pull up */ in rockchip_usb2phy_otg_port_init()
2131 rport->typec_vbus_det = in rockchip_usb2phy_otg_port_init()
2132 of_property_read_bool(child_np, "rockchip,typec-vbus-det"); in rockchip_usb2phy_otg_port_init()
2134 rport->sel_pipe_phystatus = in rockchip_usb2phy_otg_port_init()
2135 of_property_read_bool(child_np, "rockchip,sel-pipe-phystatus"); in rockchip_usb2phy_otg_port_init()
2137 if (rport->sel_pipe_phystatus) { 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()
2140 "rockchip,usbctrl-grf"); 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()
2148 rport->vbus = devm_regulator_get_optional(&rport->phy->dev, "vbus"); in rockchip_usb2phy_otg_port_init()
2149 if (IS_ERR(rport->vbus)) { in rockchip_usb2phy_otg_port_init()
2150 ret = PTR_ERR(rport->vbus); in rockchip_usb2phy_otg_port_init()
2151 if (ret == -EPROBE_DEFER) in rockchip_usb2phy_otg_port_init()
2154 if (rport->mode == USB_DR_MODE_OTG) in rockchip_usb2phy_otg_port_init()
2155 dev_warn(&rport->phy->dev, "No vbus specified for otg port\n"); in rockchip_usb2phy_otg_port_init()
2156 rport->vbus = NULL; in rockchip_usb2phy_otg_port_init()
2159 rport->mode = of_usb_get_dr_mode_by_phy(child_np, -1); 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()
2162 rport->mode == USB_DR_MODE_UNKNOWN || !iddig)) { 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()
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()
2184 ret = devm_add_action_or_reset(rphy->dev, in rockchip_usb2phy_otg_port_init()
2201 if (rport->port_cfg->bvalid_grf_sel.enable != 0) { in rockchip_usb2phy_otg_port_init()
2203 property_enable(base, &rport->port_cfg->bvalid_grf_sel, true); in rockchip_usb2phy_otg_port_init()
2205 property_enable(base, &rport->port_cfg->bvalid_grf_sel, false); in rockchip_usb2phy_otg_port_init()
2208 if (rport->vbus_always_on) in rockchip_usb2phy_otg_port_init()
2209 extcon_set_state(rphy->edev, EXTCON_USB, true); in rockchip_usb2phy_otg_port_init()
2211 if (rport->vbus_always_on || rport->mode == USB_DR_MODE_HOST || in rockchip_usb2phy_otg_port_init()
2212 rport->mode == USB_DR_MODE_UNKNOWN) in rockchip_usb2phy_otg_port_init()
2215 wake_lock_init(&rport->wakelock, WAKE_LOCK_SUSPEND, "rockchip_otg"); 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()
2217 &rport->wakelock); in rockchip_usb2phy_otg_port_init()
2221 INIT_DELAYED_WORK(&rport->bypass_uart_work, in rockchip_usb2phy_otg_port_init()
2223 INIT_DELAYED_WORK(&rport->chg_work, rockchip_chg_detect_work); in rockchip_usb2phy_otg_port_init()
2224 INIT_DELAYED_WORK(&rport->otg_sm_work, rockchip_usb2phy_otg_sm_work); in rockchip_usb2phy_otg_port_init()
2226 if (!IS_ERR(rphy->edev)) { in rockchip_usb2phy_otg_port_init()
2227 rport->event_nb.notifier_call = rockchip_otg_event; in rockchip_usb2phy_otg_port_init()
2229 ret = devm_extcon_register_notifier(rphy->dev, rphy->edev, in rockchip_usb2phy_otg_port_init()
2230 EXTCON_USB_HOST, &rport->event_nb); in rockchip_usb2phy_otg_port_init()
2232 dev_err(rphy->dev, "register USB HOST notifier failed\n"); in rockchip_usb2phy_otg_port_init()
2239 * Let us put phy-port into suspend mode here for saving power in rockchip_usb2phy_otg_port_init()
2243 ret = property_enable(base, &rport->port_cfg->phy_sus, true); in rockchip_usb2phy_otg_port_init()
2246 rport->suspended = true; in rockchip_usb2phy_otg_port_init()
2253 struct device *dev = &pdev->dev; in rockchip_usb2phy_probe()
2254 struct device_node *np = dev->of_node; in rockchip_usb2phy_probe()
2267 return -ENOMEM; in rockchip_usb2phy_probe()
2269 match = of_match_device(dev->driver->of_match_table, dev); in rockchip_usb2phy_probe()
2270 if (!match || !match->data) { in rockchip_usb2phy_probe()
2272 return -EINVAL; in rockchip_usb2phy_probe()
2275 if (!dev->parent || !dev->parent->of_node) { in rockchip_usb2phy_probe()
2279 return -ENODEV; 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()
2291 reg = res->start; 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()
2297 if (of_device_is_compatible(np, "rockchip,rv1108-usb2phy")) { in rockchip_usb2phy_probe()
2298 rphy->usbgrf = in rockchip_usb2phy_probe()
2299 syscon_regmap_lookup_by_phandle(dev->of_node, 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()
2309 np->name); in rockchip_usb2phy_probe()
2310 return -EINVAL; in rockchip_usb2phy_probe()
2314 rphy->dev = dev; in rockchip_usb2phy_probe()
2315 phy_cfgs = match->data; 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()
2330 rphy->phy_cfg = &phy_cfgs[index]; in rockchip_usb2phy_probe()
2337 if (!rphy->phy_cfg) { in rockchip_usb2phy_probe()
2338 dev_err(dev, "no phy-config can be matched with %pOFn node\n", in rockchip_usb2phy_probe()
2340 return -EINVAL; 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()
2353 if (ret == -EPROBE_DEFER) 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()
2377 /* This driver aims to support both otg-port and host-port */ in rockchip_usb2phy_probe()
2378 if (!of_node_name_eq(child_np, "host-port") && in rockchip_usb2phy_probe()
2379 !of_node_name_eq(child_np, "otg-port")) in rockchip_usb2phy_probe()
2389 rport->phy = phy; in rockchip_usb2phy_probe()
2390 phy_set_drvdata(rport->phy, rport); in rockchip_usb2phy_probe()
2393 if (of_node_name_eq(child_np, "host-port")) { in rockchip_usb2phy_probe()
2407 if (++index >= rphy->phy_cfg->num_ports) in rockchip_usb2phy_probe()
2419 ret = sysfs_create_group(&dev->kobj, &usb2_phy_attr_group); 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()
2438 dev_err(rphy->dev, in rockchip_usb2phy_probe()
2444 if (of_property_read_bool(np, "wakeup-source")) 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()
2467 if (!rport->low_power_en) in rockchip_usb2phy_low_power_enable()
2470 if (rport->port_id == USB2PHY_PORT_OTG) { in rockchip_usb2phy_low_power_enable()
2471 dev_info(&rport->phy->dev, "set otg port low power state %d\n", in rockchip_usb2phy_low_power_enable()
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()
2485 } else if (rport->port_id == USB2PHY_PORT_HOST) { in rockchip_usb2phy_low_power_enable()
2486 dev_info(&rport->phy->dev, "set host port low power state %d\n", in rockchip_usb2phy_low_power_enable()
2489 ret = property_enable(rphy->grf, &rport->port_cfg->bypass_host, in rockchip_usb2phy_low_power_enable()
2501 ret = regmap_write(rphy->grf, 0x298, 0x00040000); in rk312x_usb2phy_tuning()
2512 /* Open pre-emphasize in non-chirp state for PHY0 otg port */ in rk3228_usb2phy_tuning()
2513 if (rphy->phy_cfg->reg == 0x760) in rk3228_usb2phy_tuning()
2514 ret = regmap_write(rphy->grf, 0x76c, 0x00070004); in rk3228_usb2phy_tuning()
2525 ret = regmap_update_bits(rphy->grf, 0x30, BIT(2), 0); in rk3308_usb2phy_tuning()
2529 /* Enable otg port pre-emphasis during non-chirp phase */ 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()
2543 /* Enable host port pre-emphasis during non-chirp phase */ 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()
2557 /* Open pre-emphasize in non-chirp state for otg port */ in rk3308_usb2phy_tuning()
2558 ret = regmap_write(rphy->grf, 0x0, 0x00070004); in rk3308_usb2phy_tuning()
2562 /* Open pre-emphasize in non-chirp state for host port */ 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()
2581 /* Enable otg port pre-emphasis during non-chirp phase */ in rk3328_usb2phy_tuning()
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()
2600 /* Enable host port pre-emphasis during non-chirp phase */ 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()
2624 /* Open pre-emphasize in non-chirp state for otg port */ in rk3328_usb2phy_tuning()
2625 ret = regmap_write(rphy->grf, 0x0, 0x00070004); in rk3328_usb2phy_tuning()
2629 /* Open pre-emphasize in non-chirp state for host port */ 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()
2649 /* open HS pre-emphasize to expand HS slew rate for each port. */ in rk3366_usb2phy_tuning()
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()
2663 struct device_node *node = rphy->dev->of_node; in rk3399_usb2phy_tuning()
2666 if (rphy->phy_cfg->reg == 0xe450) { in rk3399_usb2phy_tuning()
2668 * Disable the pre-emphasize in eop state in rk3399_usb2phy_tuning()
2669 * and chirp state to avoid mis-trigger the 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()
2679 * Disable the pre-emphasize in eop state in rk3399_usb2phy_tuning()
2680 * and chirp state to avoid mis-trigger the 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()
2690 if (!of_property_read_bool(node, "rockchip,u2phy-tuning")) 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()
2701 /* Set max pre-emphasis level for PHY0 */ 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()
2718 /* Set max pre-emphasis level for PHY1 */ 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()
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()
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()
2765 /* Enable pre-emphasis during non-chirp phase */ 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()
2790 phy_clear_bits(rphy->phy_base + 0x30, BIT(2)); in rk3568_usb2phy_tuning()
2792 /* Enable otg port pre-emphasis during non-chirp phase */ in rk3568_usb2phy_tuning()
2793 phy_update_bits(rphy->phy_base, GENMASK(2, 0), 0x04); in rk3568_usb2phy_tuning()
2795 /* Enable host port pre-emphasis during non-chirp phase */ 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()
2823 /* Always enable pre-emphasis in SOF & EOP & chirp & non-chirp state */ in rv1106_usb2phy_tuning()
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()
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()
2877 ret = regmap_read(rphy->grf, 0x0008, &reg); in rk3588_usb2phy_tuning()
2883 ret = regmap_write(rphy->grf, 0x0008, in rk3588_usb2phy_tuning()
2894 if (rphy->phy_cfg->reg == 0x0000) { in rk3588_usb2phy_tuning()
2899 * 3. Set utmi_opmode to 2'b01 (no-driving) 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()
2908 /* HS Transmitter Pre-Emphasis Current Control 2'b10 : 2x */ 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()
2920 * 3. Set utmi_opmode to 2'b01 (no-driving) 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()
2929 /* HS Transmitter Pre-Emphasis Current Control 2'b10 : 2x */ 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()
2950 /* HS Transmitter Pre-Emphasis Current Control 2'b10 : 2x */ 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()
2967 /* HS Transmitter Pre-Emphasis Current Control 2'b10 : 2x */ in rk3588_usb2phy_tuning()
2968 ret |= regmap_write(rphy->grf, 0x0008, in rk3588_usb2phy_tuning()
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()
2992 if (phy_cfg->ls_filter_con.enable) { in rockchip_usb2phy_pm_suspend()
2993 ret = regmap_write(rphy->grf, phy_cfg->ls_filter_con.offset, in rockchip_usb2phy_pm_suspend()
2994 phy_cfg->ls_filter_con.enable); in rockchip_usb2phy_pm_suspend()
2996 dev_err(rphy->dev, "failed to set ls filter %d\n", ret); in rockchip_usb2phy_pm_suspend()
2999 for (index = 0; index < phy_cfg->num_ports; index++) { in rockchip_usb2phy_pm_suspend()
3000 rport = &rphy->ports[index]; in rockchip_usb2phy_pm_suspend()
3001 if (!rport->phy) in rockchip_usb2phy_pm_suspend()
3004 if (rport->port_cfg->port_ls_filter_con.enable) { in rockchip_usb2phy_pm_suspend()
3005 ret = regmap_write(rphy->grf, in rockchip_usb2phy_pm_suspend()
3006 rport->port_cfg->port_ls_filter_con.offset, in rockchip_usb2phy_pm_suspend()
3007 rport->port_cfg->port_ls_filter_con.enable); in rockchip_usb2phy_pm_suspend()
3009 dev_err(rphy->dev, "failed to set port ls filter %d\n", ret); in rockchip_usb2phy_pm_suspend()
3012 if (rport->port_id == USB2PHY_PORT_OTG && in rockchip_usb2phy_pm_suspend()
3013 (rport->id_irq > 0 || rphy->irq > 0)) { in rockchip_usb2phy_pm_suspend()
3014 mutex_lock(&rport->mutex); in rockchip_usb2phy_pm_suspend()
3015 rport->prev_iddig = property_enabled(rphy->grf, in rockchip_usb2phy_pm_suspend()
3016 &rport->port_cfg->utmi_iddig); in rockchip_usb2phy_pm_suspend()
3019 mutex_unlock(&rport->mutex); in rockchip_usb2phy_pm_suspend()
3021 dev_err(rphy->dev, in rockchip_usb2phy_pm_suspend()
3027 if (rport->port_id == USB2PHY_PORT_OTG && wakeup_enable && in rockchip_usb2phy_pm_suspend()
3028 rport->bvalid_irq > 0) in rockchip_usb2phy_pm_suspend()
3029 enable_irq_wake(rport->bvalid_irq); in rockchip_usb2phy_pm_suspend()
3032 mutex_lock(&rport->mutex); in rockchip_usb2phy_pm_suspend()
3034 mutex_unlock(&rport->mutex); in rockchip_usb2phy_pm_suspend()
3036 dev_err(rphy->dev, "failed to enable linestate irq\n"); in rockchip_usb2phy_pm_suspend()
3040 if (wakeup_enable && rport->ls_irq > 0) in rockchip_usb2phy_pm_suspend()
3041 enable_irq_wake(rport->ls_irq); 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()
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()
3073 if (phy_cfg->phy_tuning) in rockchip_usb2phy_pm_resume()
3074 ret = phy_cfg->phy_tuning(rphy); in rockchip_usb2phy_pm_resume()
3076 if (phy_cfg->ls_filter_con.disable) { in rockchip_usb2phy_pm_resume()
3077 ret = regmap_write(rphy->grf, phy_cfg->ls_filter_con.offset, in rockchip_usb2phy_pm_resume()
3078 phy_cfg->ls_filter_con.disable); in rockchip_usb2phy_pm_resume()
3080 dev_err(rphy->dev, "failed to set ls filter %d\n", ret); in rockchip_usb2phy_pm_resume()
3083 for (index = 0; index < phy_cfg->num_ports; index++) { in rockchip_usb2phy_pm_resume()
3084 rport = &rphy->ports[index]; in rockchip_usb2phy_pm_resume()
3085 if (!rport->phy) in rockchip_usb2phy_pm_resume()
3088 if (rport->port_cfg->port_ls_filter_con.disable) { in rockchip_usb2phy_pm_resume()
3089 ret = regmap_write(rphy->grf, in rockchip_usb2phy_pm_resume()
3090 rport->port_cfg->port_ls_filter_con.offset, in rockchip_usb2phy_pm_resume()
3091 rport->port_cfg->port_ls_filter_con.disable); in rockchip_usb2phy_pm_resume()
3093 dev_err(rphy->dev, "failed to set port ls filter %d\n", ret); in rockchip_usb2phy_pm_resume()
3096 if (rport->port_id == USB2PHY_PORT_OTG && in rockchip_usb2phy_pm_resume()
3097 (rport->id_irq > 0 || rphy->irq > 0)) { in rockchip_usb2phy_pm_resume()
3098 mutex_lock(&rport->mutex); in rockchip_usb2phy_pm_resume()
3099 iddig = property_enabled(rphy->grf, in rockchip_usb2phy_pm_resume()
3100 &rport->port_cfg->utmi_iddig); in rockchip_usb2phy_pm_resume()
3103 mutex_unlock(&rport->mutex); in rockchip_usb2phy_pm_resume()
3105 dev_err(rphy->dev, in rockchip_usb2phy_pm_resume()
3110 if (iddig != rport->prev_iddig) { in rockchip_usb2phy_pm_resume()
3111 dev_dbg(&rport->phy->dev, in rockchip_usb2phy_pm_resume()
3113 rport->prev_iddig = iddig; 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()
3127 if (rport->port_id == USB2PHY_PORT_OTG && in rockchip_usb2phy_pm_resume()
3128 (rport->mode == USB_DR_MODE_PERIPHERAL || in rockchip_usb2phy_pm_resume()
3129 rport->mode == USB_DR_MODE_OTG) && in rockchip_usb2phy_pm_resume()
3130 (rport->bvalid_irq > 0 || rport->otg_mux_irq > 0 || rphy->irq > 0) && in rockchip_usb2phy_pm_resume()
3131 !rport->vbus_always_on) { 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()
3141 schedule_delayed_work(&rport->otg_sm_work, in rockchip_usb2phy_pm_resume()
3146 if (rport->port_id == USB2PHY_PORT_OTG && wakeup_enable && in rockchip_usb2phy_pm_resume()
3147 rport->bvalid_irq > 0) in rockchip_usb2phy_pm_resume()
3148 disable_irq_wake(rport->bvalid_irq); in rockchip_usb2phy_pm_resume()
3150 if (wakeup_enable && rport->ls_irq > 0) in rockchip_usb2phy_pm_resume()
3151 disable_irq_wake(rport->ls_irq); 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()
4083 { .compatible = "rockchip,px30-usb2phy", .data = &rk3328_phy_cfgs },
4086 { .compatible = "rockchip,rk1808-usb2phy", .data = &rk1808_phy_cfgs },
4089 { .compatible = "rockchip,rk3128-usb2phy", .data = &rk312x_phy_cfgs },
4092 { .compatible = "rockchip,rk3228-usb2phy", .data = &rk3228_phy_cfgs },
4095 { .compatible = "rockchip,rk3308-usb2phy", .data = &rk3308_phy_cfgs },
4098 { .compatible = "rockchip,rk3328-usb2phy", .data = &rk3328_phy_cfgs },
4101 { .compatible = "rockchip,rk3366-usb2phy", .data = &rk3366_phy_cfgs },
4104 { .compatible = "rockchip,rk3368-usb2phy", .data = &rk3368_phy_cfgs },
4107 { .compatible = "rockchip,rk3399-usb2phy", .data = &rk3399_phy_cfgs },
4110 { .compatible = "rockchip,rk3528-usb2phy", .data = &rk3528_phy_cfgs },
4113 { .compatible = "rockchip,rk3562-usb2phy", .data = &rk3562_phy_cfgs },
4116 { .compatible = "rockchip,rk3568-usb2phy", .data = &rk3568_phy_cfgs },
4119 { .compatible = "rockchip,rk3588-usb2phy", .data = &rk3588_phy_cfgs },
4122 { .compatible = "rockchip,rv1106-usb2phy", .data = &rv1106_phy_cfgs },
4125 { .compatible = "rockchip,rv1108-usb2phy", .data = &rv1108_phy_cfgs },
4134 .name = "rockchip-usb2phy",
4141 MODULE_AUTHOR("Frank Wang <frank.wang@rock-chips.com>");