Lines Matching refs:rphy

237 static inline struct regmap *get_reg_base(struct rockchip_usb2phy *rphy)  in get_reg_base()  argument
239 return rphy->usbgrf == NULL ? rphy->grf : rphy->usbgrf; in get_reg_base()
271 struct rockchip_usb2phy *rphy = in rockchip_usb2phy_clk480m_prepare() local
273 struct regmap *base = get_reg_base(rphy); in rockchip_usb2phy_clk480m_prepare()
277 if (!property_enabled(base, &rphy->phy_cfg->clkout_ctl)) { in rockchip_usb2phy_clk480m_prepare()
278 ret = property_enable(base, &rphy->phy_cfg->clkout_ctl, true); in rockchip_usb2phy_clk480m_prepare()
291 struct rockchip_usb2phy *rphy = in rockchip_usb2phy_clk480m_unprepare() local
293 struct regmap *base = get_reg_base(rphy); in rockchip_usb2phy_clk480m_unprepare()
296 property_enable(base, &rphy->phy_cfg->clkout_ctl, false); in rockchip_usb2phy_clk480m_unprepare()
301 struct rockchip_usb2phy *rphy = in rockchip_usb2phy_clk480m_prepared() local
303 struct regmap *base = get_reg_base(rphy); in rockchip_usb2phy_clk480m_prepared()
305 return property_enabled(base, &rphy->phy_cfg->clkout_ctl); in rockchip_usb2phy_clk480m_prepared()
324 struct rockchip_usb2phy *rphy = data; in rockchip_usb2phy_clk480m_unregister() local
326 of_clk_del_provider(rphy->dev->of_node); in rockchip_usb2phy_clk480m_unregister()
327 clk_unregister(rphy->clk480m); in rockchip_usb2phy_clk480m_unregister()
331 rockchip_usb2phy_clk480m_register(struct rockchip_usb2phy *rphy) in rockchip_usb2phy_clk480m_register() argument
333 struct device_node *node = rphy->dev->of_node; in rockchip_usb2phy_clk480m_register()
345 if (rphy->clk) { in rockchip_usb2phy_clk480m_register()
346 clk_name = __clk_get_name(rphy->clk); in rockchip_usb2phy_clk480m_register()
354 rphy->clk480m_hw.init = &init; in rockchip_usb2phy_clk480m_register()
357 rphy->clk480m = clk_register(rphy->dev, &rphy->clk480m_hw); in rockchip_usb2phy_clk480m_register()
358 if (IS_ERR(rphy->clk480m)) { in rockchip_usb2phy_clk480m_register()
359 ret = PTR_ERR(rphy->clk480m); in rockchip_usb2phy_clk480m_register()
363 ret = of_clk_add_provider(node, of_clk_src_simple_get, rphy->clk480m); in rockchip_usb2phy_clk480m_register()
367 return devm_add_action_or_reset(rphy->dev, rockchip_usb2phy_clk480m_unregister, rphy); in rockchip_usb2phy_clk480m_register()
370 clk_unregister(rphy->clk480m); in rockchip_usb2phy_clk480m_register()
375 static int rockchip_usb2phy_extcon_register(struct rockchip_usb2phy *rphy) in rockchip_usb2phy_extcon_register() argument
378 struct device_node *node = rphy->dev->of_node; in rockchip_usb2phy_extcon_register()
382 edev = extcon_get_edev_by_phandle(rphy->dev, 0); in rockchip_usb2phy_extcon_register()
385 dev_err(rphy->dev, "Invalid or missing extcon\n"); in rockchip_usb2phy_extcon_register()
390 edev = devm_extcon_dev_allocate(rphy->dev, in rockchip_usb2phy_extcon_register()
396 ret = devm_extcon_dev_register(rphy->dev, edev); in rockchip_usb2phy_extcon_register()
398 dev_err(rphy->dev, "failed to register extcon device\n"); in rockchip_usb2phy_extcon_register()
403 rphy->edev = edev; in rockchip_usb2phy_extcon_register()
411 struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent); in rockchip_usb2phy_init() local
420 ret = property_enable(rphy->grf, in rockchip_usb2phy_init()
426 ret = property_enable(rphy->grf, in rockchip_usb2phy_init()
433 ret = property_enable(rphy->grf, in rockchip_usb2phy_init()
439 ret = property_enable(rphy->grf, in rockchip_usb2phy_init()
453 ret = property_enable(rphy->grf, in rockchip_usb2phy_init()
458 ret = property_enable(rphy->grf, in rockchip_usb2phy_init()
474 struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent); in rockchip_usb2phy_power_on() local
475 struct regmap *base = get_reg_base(rphy); in rockchip_usb2phy_power_on()
483 ret = clk_prepare_enable(rphy->clk480m); in rockchip_usb2phy_power_on()
489 clk_disable_unprepare(rphy->clk480m); in rockchip_usb2phy_power_on()
503 struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent); in rockchip_usb2phy_power_off() local
504 struct regmap *base = get_reg_base(rphy); in rockchip_usb2phy_power_off()
517 clk_disable_unprepare(rphy->clk480m); in rockchip_usb2phy_power_off()
550 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_otg_sm_work() local
555 vbus_attach = property_enabled(rphy->grf, in rockchip_usb2phy_otg_sm_work()
571 if (extcon_get_state(rphy->edev, EXTCON_USB_HOST) > 0) { in rockchip_usb2phy_otg_sm_work()
578 switch (rphy->chg_state) { in rockchip_usb2phy_otg_sm_work()
583 switch (rphy->chg_type) { in rockchip_usb2phy_otg_sm_work()
616 rphy->chg_state = USB_CHG_STATE_UNDEFINED; in rockchip_usb2phy_otg_sm_work()
617 rphy->chg_type = POWER_SUPPLY_TYPE_UNKNOWN; in rockchip_usb2phy_otg_sm_work()
623 if (notify_charger && rphy->edev) { in rockchip_usb2phy_otg_sm_work()
624 extcon_set_state_sync(rphy->edev, in rockchip_usb2phy_otg_sm_work()
627 extcon_set_state_sync(rphy->edev, in rockchip_usb2phy_otg_sm_work()
636 rphy->chg_state = USB_CHG_STATE_UNDEFINED; in rockchip_usb2phy_otg_sm_work()
637 rphy->chg_type = POWER_SUPPLY_TYPE_UNKNOWN; in rockchip_usb2phy_otg_sm_work()
645 if (extcon_get_state(rphy->edev, EXTCON_USB_HOST) == 0) { in rockchip_usb2phy_otg_sm_work()
673 static void rockchip_chg_enable_dcd(struct rockchip_usb2phy *rphy, in rockchip_chg_enable_dcd() argument
676 struct regmap *base = get_reg_base(rphy); in rockchip_chg_enable_dcd()
678 property_enable(base, &rphy->phy_cfg->chg_det.rdm_pdwn_en, en); in rockchip_chg_enable_dcd()
679 property_enable(base, &rphy->phy_cfg->chg_det.idp_src_en, en); in rockchip_chg_enable_dcd()
682 static void rockchip_chg_enable_primary_det(struct rockchip_usb2phy *rphy, in rockchip_chg_enable_primary_det() argument
685 struct regmap *base = get_reg_base(rphy); in rockchip_chg_enable_primary_det()
687 property_enable(base, &rphy->phy_cfg->chg_det.vdp_src_en, en); in rockchip_chg_enable_primary_det()
688 property_enable(base, &rphy->phy_cfg->chg_det.idm_sink_en, en); in rockchip_chg_enable_primary_det()
691 static void rockchip_chg_enable_secondary_det(struct rockchip_usb2phy *rphy, in rockchip_chg_enable_secondary_det() argument
694 struct regmap *base = get_reg_base(rphy); in rockchip_chg_enable_secondary_det()
696 property_enable(base, &rphy->phy_cfg->chg_det.vdm_src_en, en); in rockchip_chg_enable_secondary_det()
697 property_enable(base, &rphy->phy_cfg->chg_det.idp_sink_en, en); in rockchip_chg_enable_secondary_det()
708 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_chg_detect_work() local
709 struct regmap *base = get_reg_base(rphy); in rockchip_chg_detect_work()
714 rphy->chg_state); in rockchip_chg_detect_work()
715 switch (rphy->chg_state) { in rockchip_chg_detect_work()
720 property_enable(base, &rphy->phy_cfg->chg_det.opmode, false); in rockchip_chg_detect_work()
722 rockchip_chg_enable_dcd(rphy, true); in rockchip_chg_detect_work()
723 rphy->chg_state = USB_CHG_STATE_WAIT_FOR_DCD; in rockchip_chg_detect_work()
724 rphy->dcd_retries = 0; in rockchip_chg_detect_work()
729 is_dcd = property_enabled(rphy->grf, in rockchip_chg_detect_work()
730 &rphy->phy_cfg->chg_det.dp_det); in rockchip_chg_detect_work()
731 tmout = ++rphy->dcd_retries == CHG_DCD_MAX_RETRIES; in rockchip_chg_detect_work()
736 rockchip_chg_enable_dcd(rphy, false); in rockchip_chg_detect_work()
738 rockchip_chg_enable_primary_det(rphy, true); in rockchip_chg_detect_work()
740 rphy->chg_state = USB_CHG_STATE_DCD_DONE; in rockchip_chg_detect_work()
747 vout = property_enabled(rphy->grf, in rockchip_chg_detect_work()
748 &rphy->phy_cfg->chg_det.cp_det); in rockchip_chg_detect_work()
749 rockchip_chg_enable_primary_det(rphy, false); in rockchip_chg_detect_work()
752 rockchip_chg_enable_secondary_det(rphy, true); in rockchip_chg_detect_work()
754 rphy->chg_state = USB_CHG_STATE_PRIMARY_DONE; in rockchip_chg_detect_work()
756 if (rphy->dcd_retries == CHG_DCD_MAX_RETRIES) { in rockchip_chg_detect_work()
758 rphy->chg_type = POWER_SUPPLY_TYPE_USB_DCP; in rockchip_chg_detect_work()
759 rphy->chg_state = USB_CHG_STATE_DETECTED; in rockchip_chg_detect_work()
762 rphy->chg_type = POWER_SUPPLY_TYPE_USB; in rockchip_chg_detect_work()
763 rphy->chg_state = USB_CHG_STATE_DETECTED; in rockchip_chg_detect_work()
769 vout = property_enabled(rphy->grf, in rockchip_chg_detect_work()
770 &rphy->phy_cfg->chg_det.dcp_det); in rockchip_chg_detect_work()
772 rockchip_chg_enable_secondary_det(rphy, false); in rockchip_chg_detect_work()
774 rphy->chg_type = POWER_SUPPLY_TYPE_USB_DCP; in rockchip_chg_detect_work()
776 rphy->chg_type = POWER_SUPPLY_TYPE_USB_CDP; in rockchip_chg_detect_work()
779 rphy->chg_state = USB_CHG_STATE_DETECTED; in rockchip_chg_detect_work()
783 property_enable(base, &rphy->phy_cfg->chg_det.opmode, true); in rockchip_chg_detect_work()
786 chg_to_string(rphy->chg_type)); in rockchip_chg_detect_work()
812 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_sm_work() local
821 ret = regmap_read(rphy->grf, rport->port_cfg->utmi_ls.offset, &ul); in rockchip_usb2phy_sm_work()
825 ret = regmap_read(rphy->grf, rport->port_cfg->utmi_hstdet.offset, &uhd); in rockchip_usb2phy_sm_work()
879 property_enable(rphy->grf, &rport->port_cfg->ls_det_clr, true); in rockchip_usb2phy_sm_work()
880 property_enable(rphy->grf, &rport->port_cfg->ls_det_en, true); in rockchip_usb2phy_sm_work()
901 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_linestate_irq() local
903 if (!property_enabled(rphy->grf, &rport->port_cfg->ls_det_st)) in rockchip_usb2phy_linestate_irq()
909 property_enable(rphy->grf, &rport->port_cfg->ls_det_en, false); in rockchip_usb2phy_linestate_irq()
910 property_enable(rphy->grf, &rport->port_cfg->ls_det_clr, true); in rockchip_usb2phy_linestate_irq()
928 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_bvalid_irq() local
930 if (!property_enabled(rphy->grf, &rport->port_cfg->bvalid_det_st)) in rockchip_usb2phy_bvalid_irq()
934 property_enable(rphy->grf, &rport->port_cfg->bvalid_det_clr, true); in rockchip_usb2phy_bvalid_irq()
944 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_id_irq() local
947 if (!property_enabled(rphy->grf, &rport->port_cfg->id_det_st)) in rockchip_usb2phy_id_irq()
951 property_enable(rphy->grf, &rport->port_cfg->id_det_clr, true); in rockchip_usb2phy_id_irq()
953 id = property_enabled(rphy->grf, &rport->port_cfg->utmi_id); in rockchip_usb2phy_id_irq()
954 extcon_set_state_sync(rphy->edev, EXTCON_USB_HOST, !id); in rockchip_usb2phy_id_irq()
971 struct rockchip_usb2phy *rphy = data; in rockchip_usb2phy_irq() local
976 for (index = 0; index < rphy->phy_cfg->num_ports; index++) { in rockchip_usb2phy_irq()
977 rport = &rphy->ports[index]; in rockchip_usb2phy_irq()
996 static int rockchip_usb2phy_port_irq_init(struct rockchip_usb2phy *rphy, in rockchip_usb2phy_port_irq_init() argument
1006 if (rphy->irq > 0) in rockchip_usb2phy_port_irq_init()
1013 dev_err(rphy->dev, "no linestate irq provided\n"); in rockchip_usb2phy_port_irq_init()
1017 ret = devm_request_threaded_irq(rphy->dev, rport->ls_irq, NULL, in rockchip_usb2phy_port_irq_init()
1022 dev_err(rphy->dev, "failed to request linestate irq handle\n"); in rockchip_usb2phy_port_irq_init()
1034 ret = devm_request_threaded_irq(rphy->dev, rport->otg_mux_irq, in rockchip_usb2phy_port_irq_init()
1041 dev_err(rphy->dev, in rockchip_usb2phy_port_irq_init()
1048 dev_err(rphy->dev, "no vbus valid irq provided\n"); in rockchip_usb2phy_port_irq_init()
1053 ret = devm_request_threaded_irq(rphy->dev, rport->bvalid_irq, in rockchip_usb2phy_port_irq_init()
1060 dev_err(rphy->dev, in rockchip_usb2phy_port_irq_init()
1067 dev_err(rphy->dev, "no otg-id irq provided\n"); in rockchip_usb2phy_port_irq_init()
1072 ret = devm_request_threaded_irq(rphy->dev, rport->id_irq, in rockchip_usb2phy_port_irq_init()
1079 dev_err(rphy->dev, in rockchip_usb2phy_port_irq_init()
1092 static int rockchip_usb2phy_host_port_init(struct rockchip_usb2phy *rphy, in rockchip_usb2phy_host_port_init() argument
1099 rport->port_cfg = &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_HOST]; in rockchip_usb2phy_host_port_init()
1105 ret = rockchip_usb2phy_port_irq_init(rphy, rport, child_np); in rockchip_usb2phy_host_port_init()
1107 dev_err(rphy->dev, "failed to setup host irq\n"); in rockchip_usb2phy_host_port_init()
1125 static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy, in rockchip_usb2phy_otg_port_init() argument
1132 rport->port_cfg = &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_OTG]; in rockchip_usb2phy_otg_port_init()
1156 ret = rockchip_usb2phy_port_irq_init(rphy, rport, child_np); in rockchip_usb2phy_otg_port_init()
1158 dev_err(rphy->dev, "failed to init irq for host port\n"); in rockchip_usb2phy_otg_port_init()
1162 if (!IS_ERR(rphy->edev)) { in rockchip_usb2phy_otg_port_init()
1165 ret = devm_extcon_register_notifier(rphy->dev, rphy->edev, in rockchip_usb2phy_otg_port_init()
1168 dev_err(rphy->dev, "register USB HOST notifier failed\n"); in rockchip_usb2phy_otg_port_init()
1172 if (!of_property_read_bool(rphy->dev->of_node, "extcon")) { in rockchip_usb2phy_otg_port_init()
1174 id = property_enabled(rphy->grf, &rport->port_cfg->utmi_id); in rockchip_usb2phy_otg_port_init()
1175 extcon_set_state_sync(rphy->edev, EXTCON_USB_HOST, !id); in rockchip_usb2phy_otg_port_init()
1189 struct rockchip_usb2phy *rphy; in rockchip_usb2phy_probe() local
1195 rphy = devm_kzalloc(dev, sizeof(*rphy), GFP_KERNEL); in rockchip_usb2phy_probe()
1196 if (!rphy) in rockchip_usb2phy_probe()
1206 rphy->grf = syscon_regmap_lookup_by_phandle(np, "rockchip,usbgrf"); in rockchip_usb2phy_probe()
1207 if (IS_ERR(rphy->grf)) { in rockchip_usb2phy_probe()
1209 return PTR_ERR(rphy->grf); in rockchip_usb2phy_probe()
1214 rphy->grf = syscon_node_to_regmap(dev->parent->of_node); in rockchip_usb2phy_probe()
1215 if (IS_ERR(rphy->grf)) in rockchip_usb2phy_probe()
1216 return PTR_ERR(rphy->grf); in rockchip_usb2phy_probe()
1220 rphy->usbgrf = in rockchip_usb2phy_probe()
1223 if (IS_ERR(rphy->usbgrf)) in rockchip_usb2phy_probe()
1224 return PTR_ERR(rphy->usbgrf); in rockchip_usb2phy_probe()
1226 rphy->usbgrf = NULL; in rockchip_usb2phy_probe()
1244 rphy->dev = dev; in rockchip_usb2phy_probe()
1246 rphy->chg_state = USB_CHG_STATE_UNDEFINED; in rockchip_usb2phy_probe()
1247 rphy->chg_type = POWER_SUPPLY_TYPE_UNKNOWN; in rockchip_usb2phy_probe()
1248 rphy->irq = platform_get_irq_optional(pdev, 0); in rockchip_usb2phy_probe()
1249 platform_set_drvdata(pdev, rphy); in rockchip_usb2phy_probe()
1251 ret = rockchip_usb2phy_extcon_register(rphy); in rockchip_usb2phy_probe()
1259 rphy->phy_cfg = &phy_cfgs[index]; in rockchip_usb2phy_probe()
1266 if (!rphy->phy_cfg) { in rockchip_usb2phy_probe()
1272 rphy->clk = of_clk_get_by_name(np, "phyclk"); in rockchip_usb2phy_probe()
1273 if (!IS_ERR(rphy->clk)) { in rockchip_usb2phy_probe()
1274 clk_prepare_enable(rphy->clk); in rockchip_usb2phy_probe()
1277 rphy->clk = NULL; in rockchip_usb2phy_probe()
1280 ret = rockchip_usb2phy_clk480m_register(rphy); in rockchip_usb2phy_probe()
1288 struct rockchip_usb2phy_port *rport = &rphy->ports[index]; in rockchip_usb2phy_probe()
1308 ret = rockchip_usb2phy_host_port_init(rphy, rport, in rockchip_usb2phy_probe()
1313 ret = rockchip_usb2phy_otg_port_init(rphy, rport, in rockchip_usb2phy_probe()
1321 if (++index >= rphy->phy_cfg->num_ports) { in rockchip_usb2phy_probe()
1329 if (rphy->irq > 0) { in rockchip_usb2phy_probe()
1330 ret = devm_request_threaded_irq(rphy->dev, rphy->irq, NULL, in rockchip_usb2phy_probe()
1334 rphy); in rockchip_usb2phy_probe()
1336 dev_err(rphy->dev, in rockchip_usb2phy_probe()
1347 if (rphy->clk) { in rockchip_usb2phy_probe()
1348 clk_disable_unprepare(rphy->clk); in rockchip_usb2phy_probe()
1349 clk_put(rphy->clk); in rockchip_usb2phy_probe()