Lines Matching +full:usb +full:- +full:sdp
1 // SPDX-License-Identifier: GPL-2.0-or-later
9 #include <linux/clk-provider.h>
11 #include <linux/extcon-provider.h>
28 #include <linux/usb/of.h>
29 #include <linux/usb/otg.h>
49 * enum usb_chg_state - Different states involved in USB charger detection.
50 * @USB_CHG_STATE_UNDEFINED: USB charger is not connected or detection
55 * between SDP and DCP/CDP).
58 * @USB_CHG_STATE_DETECTED: USB charger type is determined.
88 * struct rockchip_chg_det_reg - usb charger detect registers
114 * struct rockchip_usb2phy_port_cfg - usb-phy port configuration.
142 * struct rockchip_usb2phy_cfg - usb-phy configuration.
143 * @reg: the address offset of grf for usb-phy config.
146 * @port_cfgs: usb-phy port configurations.
158 * struct rockchip_usb2phy_port - usb-phy port data.
165 * @otg_mux_irq: IRQ number which multiplex otg-id/otg-bvalid/linestate
166 * irqs to one irq in otg-port.
195 * struct rockchip_usb2phy - usb2.0 phy driver data.
198 * @usbgrf: USB General Register Files regmap.
202 * @chg_state: states involved in USB charger detection.
203 * @chg_type: USB charger types.
227 return rphy->usbgrf == NULL ? rphy->grf : rphy->usbgrf; in get_reg_base()
235 tmp = en ? reg->enable : reg->disable; in property_enable()
236 mask = GENMASK(reg->bitend, reg->bitstart); in property_enable()
237 val = (tmp << reg->bitstart) | (mask << BIT_WRITEABLE_SHIFT); in property_enable()
239 return regmap_write(base, reg->offset, val); in property_enable()
247 unsigned int mask = GENMASK(reg->bitend, reg->bitstart); in property_enabled()
249 ret = regmap_read(base, reg->offset, &orig); in property_enabled()
253 tmp = (orig & mask) >> reg->bitstart; in property_enabled()
254 return tmp == reg->enable; in property_enabled()
265 if (!property_enabled(base, &rphy->phy_cfg->clkout_ctl)) { in rockchip_usb2phy_clk480m_prepare()
266 ret = property_enable(base, &rphy->phy_cfg->clkout_ctl, true); in rockchip_usb2phy_clk480m_prepare()
284 property_enable(base, &rphy->phy_cfg->clkout_ctl, false); in rockchip_usb2phy_clk480m_unprepare()
293 return property_enabled(base, &rphy->phy_cfg->clkout_ctl); in rockchip_usb2phy_clk480m_prepared()
314 of_clk_del_provider(rphy->dev->of_node); in rockchip_usb2phy_clk480m_unregister()
315 clk_unregister(rphy->clk480m); in rockchip_usb2phy_clk480m_unregister()
321 struct device_node *node = rphy->dev->of_node; in rockchip_usb2phy_clk480m_register()
331 of_property_read_string(node, "clock-output-names", &init.name); in rockchip_usb2phy_clk480m_register()
333 if (rphy->clk) { in rockchip_usb2phy_clk480m_register()
334 clk_name = __clk_get_name(rphy->clk); in rockchip_usb2phy_clk480m_register()
342 rphy->clk480m_hw.init = &init; in rockchip_usb2phy_clk480m_register()
345 rphy->clk480m = clk_register(rphy->dev, &rphy->clk480m_hw); in rockchip_usb2phy_clk480m_register()
346 if (IS_ERR(rphy->clk480m)) { in rockchip_usb2phy_clk480m_register()
347 ret = PTR_ERR(rphy->clk480m); in rockchip_usb2phy_clk480m_register()
351 ret = of_clk_add_provider(node, of_clk_src_simple_get, rphy->clk480m); in rockchip_usb2phy_clk480m_register()
355 ret = devm_add_action(rphy->dev, rockchip_usb2phy_clk480m_unregister, in rockchip_usb2phy_clk480m_register()
365 clk_unregister(rphy->clk480m); in rockchip_usb2phy_clk480m_register()
373 struct device_node *node = rphy->dev->of_node; in rockchip_usb2phy_extcon_register()
377 edev = extcon_get_edev_by_phandle(rphy->dev, 0); in rockchip_usb2phy_extcon_register()
379 if (PTR_ERR(edev) != -EPROBE_DEFER) in rockchip_usb2phy_extcon_register()
380 dev_err(rphy->dev, "Invalid or missing extcon\n"); in rockchip_usb2phy_extcon_register()
385 edev = devm_extcon_dev_allocate(rphy->dev, in rockchip_usb2phy_extcon_register()
389 return -ENOMEM; in rockchip_usb2phy_extcon_register()
391 ret = devm_extcon_dev_register(rphy->dev, edev); in rockchip_usb2phy_extcon_register()
393 dev_err(rphy->dev, "failed to register extcon device\n"); in rockchip_usb2phy_extcon_register()
398 rphy->edev = edev; in rockchip_usb2phy_extcon_register()
406 struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent); in rockchip_usb2phy_init()
409 mutex_lock(&rport->mutex); in rockchip_usb2phy_init()
411 if (rport->port_id == USB2PHY_PORT_OTG) { in rockchip_usb2phy_init()
412 if (rport->mode != USB_DR_MODE_HOST && in rockchip_usb2phy_init()
413 rport->mode != USB_DR_MODE_UNKNOWN) { in rockchip_usb2phy_init()
415 ret = property_enable(rphy->grf, in rockchip_usb2phy_init()
416 &rport->port_cfg->bvalid_det_clr, in rockchip_usb2phy_init()
421 ret = property_enable(rphy->grf, in rockchip_usb2phy_init()
422 &rport->port_cfg->bvalid_det_en, in rockchip_usb2phy_init()
427 schedule_delayed_work(&rport->otg_sm_work, in rockchip_usb2phy_init()
431 dev_dbg(&rport->phy->dev, "mode %d\n", rport->mode); in rockchip_usb2phy_init()
433 } else if (rport->port_id == USB2PHY_PORT_HOST) { in rockchip_usb2phy_init()
435 ret = property_enable(rphy->grf, in rockchip_usb2phy_init()
436 &rport->port_cfg->ls_det_clr, true); in rockchip_usb2phy_init()
440 ret = property_enable(rphy->grf, in rockchip_usb2phy_init()
441 &rport->port_cfg->ls_det_en, true); in rockchip_usb2phy_init()
445 schedule_delayed_work(&rport->sm_work, SCHEDULE_DELAY); in rockchip_usb2phy_init()
449 mutex_unlock(&rport->mutex); in rockchip_usb2phy_init()
456 struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent); in rockchip_usb2phy_power_on()
460 dev_dbg(&rport->phy->dev, "port power on\n"); in rockchip_usb2phy_power_on()
462 if (!rport->suspended) in rockchip_usb2phy_power_on()
465 ret = clk_prepare_enable(rphy->clk480m); in rockchip_usb2phy_power_on()
469 ret = property_enable(base, &rport->port_cfg->phy_sus, false); in rockchip_usb2phy_power_on()
476 rport->suspended = false; in rockchip_usb2phy_power_on()
483 struct rockchip_usb2phy *rphy = dev_get_drvdata(phy->dev.parent); in rockchip_usb2phy_power_off()
487 dev_dbg(&rport->phy->dev, "port power off\n"); in rockchip_usb2phy_power_off()
489 if (rport->suspended) in rockchip_usb2phy_power_off()
492 ret = property_enable(base, &rport->port_cfg->phy_sus, true); in rockchip_usb2phy_power_off()
496 rport->suspended = true; in rockchip_usb2phy_power_off()
497 clk_disable_unprepare(rphy->clk480m); in rockchip_usb2phy_power_off()
506 if (rport->port_id == USB2PHY_PORT_OTG && in rockchip_usb2phy_exit()
507 rport->mode != USB_DR_MODE_HOST && in rockchip_usb2phy_exit()
508 rport->mode != USB_DR_MODE_UNKNOWN) { in rockchip_usb2phy_exit()
509 cancel_delayed_work_sync(&rport->otg_sm_work); in rockchip_usb2phy_exit()
510 cancel_delayed_work_sync(&rport->chg_work); in rockchip_usb2phy_exit()
511 } else if (rport->port_id == USB2PHY_PORT_HOST) in rockchip_usb2phy_exit()
512 cancel_delayed_work_sync(&rport->sm_work); in rockchip_usb2phy_exit()
530 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_otg_sm_work()
535 vbus_attach = property_enabled(rphy->grf, in rockchip_usb2phy_otg_sm_work()
536 &rport->port_cfg->utmi_bvalid); in rockchip_usb2phy_otg_sm_work()
541 dev_dbg(&rport->phy->dev, "%s otg sm work\n", in rockchip_usb2phy_otg_sm_work()
542 usb_otg_state_string(rport->state)); in rockchip_usb2phy_otg_sm_work()
544 switch (rport->state) { in rockchip_usb2phy_otg_sm_work()
546 rport->state = OTG_STATE_B_IDLE; in rockchip_usb2phy_otg_sm_work()
548 rockchip_usb2phy_power_off(rport->phy); in rockchip_usb2phy_otg_sm_work()
551 if (extcon_get_state(rphy->edev, EXTCON_USB_HOST) > 0) { in rockchip_usb2phy_otg_sm_work()
552 dev_dbg(&rport->phy->dev, "usb otg host connect\n"); in rockchip_usb2phy_otg_sm_work()
553 rport->state = OTG_STATE_A_HOST; in rockchip_usb2phy_otg_sm_work()
554 rockchip_usb2phy_power_on(rport->phy); in rockchip_usb2phy_otg_sm_work()
557 dev_dbg(&rport->phy->dev, "vbus_attach\n"); in rockchip_usb2phy_otg_sm_work()
558 switch (rphy->chg_state) { in rockchip_usb2phy_otg_sm_work()
560 schedule_delayed_work(&rport->chg_work, 0); in rockchip_usb2phy_otg_sm_work()
563 switch (rphy->chg_type) { in rockchip_usb2phy_otg_sm_work()
565 dev_dbg(&rport->phy->dev, "sdp cable is connected\n"); in rockchip_usb2phy_otg_sm_work()
566 rockchip_usb2phy_power_on(rport->phy); in rockchip_usb2phy_otg_sm_work()
567 rport->state = OTG_STATE_B_PERIPHERAL; in rockchip_usb2phy_otg_sm_work()
573 dev_dbg(&rport->phy->dev, "dcp cable is connected\n"); in rockchip_usb2phy_otg_sm_work()
574 rockchip_usb2phy_power_off(rport->phy); in rockchip_usb2phy_otg_sm_work()
580 dev_dbg(&rport->phy->dev, "cdp cable is connected\n"); in rockchip_usb2phy_otg_sm_work()
581 rockchip_usb2phy_power_on(rport->phy); in rockchip_usb2phy_otg_sm_work()
582 rport->state = OTG_STATE_B_PERIPHERAL; in rockchip_usb2phy_otg_sm_work()
596 rphy->chg_state = USB_CHG_STATE_UNDEFINED; in rockchip_usb2phy_otg_sm_work()
597 rphy->chg_type = POWER_SUPPLY_TYPE_UNKNOWN; in rockchip_usb2phy_otg_sm_work()
600 if (rport->vbus_attached != vbus_attach) { in rockchip_usb2phy_otg_sm_work()
601 rport->vbus_attached = vbus_attach; in rockchip_usb2phy_otg_sm_work()
603 if (notify_charger && rphy->edev) { in rockchip_usb2phy_otg_sm_work()
604 extcon_set_state_sync(rphy->edev, in rockchip_usb2phy_otg_sm_work()
607 extcon_set_state_sync(rphy->edev, in rockchip_usb2phy_otg_sm_work()
615 dev_dbg(&rport->phy->dev, "usb disconnect\n"); 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()
618 rport->state = OTG_STATE_B_IDLE; in rockchip_usb2phy_otg_sm_work()
620 rockchip_usb2phy_power_off(rport->phy); in rockchip_usb2phy_otg_sm_work()
625 if (extcon_get_state(rphy->edev, EXTCON_USB_HOST) == 0) { in rockchip_usb2phy_otg_sm_work()
626 dev_dbg(&rport->phy->dev, "usb otg host disconnect\n"); in rockchip_usb2phy_otg_sm_work()
627 rport->state = OTG_STATE_B_IDLE; in rockchip_usb2phy_otg_sm_work()
628 rockchip_usb2phy_power_off(rport->phy); in rockchip_usb2phy_otg_sm_work()
636 schedule_delayed_work(&rport->otg_sm_work, delay); in rockchip_usb2phy_otg_sm_work()
658 property_enable(base, &rphy->phy_cfg->chg_det.rdm_pdwn_en, en); in rockchip_chg_enable_dcd()
659 property_enable(base, &rphy->phy_cfg->chg_det.idp_src_en, en); in rockchip_chg_enable_dcd()
667 property_enable(base, &rphy->phy_cfg->chg_det.vdp_src_en, en); in rockchip_chg_enable_primary_det()
668 property_enable(base, &rphy->phy_cfg->chg_det.idm_sink_en, en); in rockchip_chg_enable_primary_det()
676 property_enable(base, &rphy->phy_cfg->chg_det.vdm_src_en, en); in rockchip_chg_enable_secondary_det()
677 property_enable(base, &rphy->phy_cfg->chg_det.idp_sink_en, en); in rockchip_chg_enable_secondary_det()
688 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_chg_detect_work()
693 dev_dbg(&rport->phy->dev, "chg detection work state = %d\n", in rockchip_chg_detect_work()
694 rphy->chg_state); in rockchip_chg_detect_work()
695 switch (rphy->chg_state) { in rockchip_chg_detect_work()
697 if (!rport->suspended) in rockchip_chg_detect_work()
698 rockchip_usb2phy_power_off(rport->phy); in rockchip_chg_detect_work()
699 /* put the controller in non-driving mode */ in rockchip_chg_detect_work()
700 property_enable(base, &rphy->phy_cfg->chg_det.opmode, false); in rockchip_chg_detect_work()
703 rphy->chg_state = USB_CHG_STATE_WAIT_FOR_DCD; in rockchip_chg_detect_work()
704 rphy->dcd_retries = 0; in rockchip_chg_detect_work()
709 is_dcd = property_enabled(rphy->grf, in rockchip_chg_detect_work()
710 &rphy->phy_cfg->chg_det.dp_det); in rockchip_chg_detect_work()
711 tmout = ++rphy->dcd_retries == CHG_DCD_MAX_RETRIES; in rockchip_chg_detect_work()
720 rphy->chg_state = USB_CHG_STATE_DCD_DONE; in rockchip_chg_detect_work()
727 vout = property_enabled(rphy->grf, in rockchip_chg_detect_work()
728 &rphy->phy_cfg->chg_det.cp_det); in rockchip_chg_detect_work()
734 rphy->chg_state = USB_CHG_STATE_PRIMARY_DONE; in rockchip_chg_detect_work()
736 if (rphy->dcd_retries == CHG_DCD_MAX_RETRIES) { in rockchip_chg_detect_work()
738 rphy->chg_type = POWER_SUPPLY_TYPE_USB_DCP; in rockchip_chg_detect_work()
739 rphy->chg_state = USB_CHG_STATE_DETECTED; in rockchip_chg_detect_work()
742 rphy->chg_type = POWER_SUPPLY_TYPE_USB; in rockchip_chg_detect_work()
743 rphy->chg_state = USB_CHG_STATE_DETECTED; in rockchip_chg_detect_work()
749 vout = property_enabled(rphy->grf, in rockchip_chg_detect_work()
750 &rphy->phy_cfg->chg_det.dcp_det); in rockchip_chg_detect_work()
754 rphy->chg_type = POWER_SUPPLY_TYPE_USB_DCP; in rockchip_chg_detect_work()
756 rphy->chg_type = POWER_SUPPLY_TYPE_USB_CDP; in rockchip_chg_detect_work()
759 rphy->chg_state = USB_CHG_STATE_DETECTED; in rockchip_chg_detect_work()
764 property_enable(base, &rphy->phy_cfg->chg_det.opmode, true); in rockchip_chg_detect_work()
765 rockchip_usb2phy_otg_sm_work(&rport->otg_sm_work.work); in rockchip_chg_detect_work()
766 dev_dbg(&rport->phy->dev, "charger = %s\n", in rockchip_chg_detect_work()
767 chg_to_string(rphy->chg_type)); in rockchip_chg_detect_work()
773 schedule_delayed_work(&rport->chg_work, delay); in rockchip_chg_detect_work()
777 * The function manage host-phy port state and suspend/resume phy port
793 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_sm_work()
794 unsigned int sh = rport->port_cfg->utmi_hstdet.bitend - in rockchip_usb2phy_sm_work()
795 rport->port_cfg->utmi_hstdet.bitstart + 1; in rockchip_usb2phy_sm_work()
800 mutex_lock(&rport->mutex); in rockchip_usb2phy_sm_work()
802 ret = regmap_read(rphy->grf, rport->port_cfg->utmi_ls.offset, &ul); in rockchip_usb2phy_sm_work()
806 ret = regmap_read(rphy->grf, rport->port_cfg->utmi_hstdet.offset, &uhd); in rockchip_usb2phy_sm_work()
810 uhd_mask = GENMASK(rport->port_cfg->utmi_hstdet.bitend, in rockchip_usb2phy_sm_work()
811 rport->port_cfg->utmi_hstdet.bitstart); in rockchip_usb2phy_sm_work()
812 ul_mask = GENMASK(rport->port_cfg->utmi_ls.bitend, in rockchip_usb2phy_sm_work()
813 rport->port_cfg->utmi_ls.bitstart); in rockchip_usb2phy_sm_work()
816 state = ((uhd & uhd_mask) >> rport->port_cfg->utmi_hstdet.bitstart) | in rockchip_usb2phy_sm_work()
817 (((ul & ul_mask) >> rport->port_cfg->utmi_ls.bitstart) << sh); in rockchip_usb2phy_sm_work()
821 dev_dbg(&rport->phy->dev, "HS online\n"); in rockchip_usb2phy_sm_work()
829 * Plus, there are two cases, one is D- Line pull-up, and D+ in rockchip_usb2phy_sm_work()
830 * line pull-down, the state is 4; another is D+ line pull-up, in rockchip_usb2phy_sm_work()
831 * and D- line pull-down, the state is 2. in rockchip_usb2phy_sm_work()
833 if (!rport->suspended) { in rockchip_usb2phy_sm_work()
834 /* D- line pull-up, D+ line pull-down */ in rockchip_usb2phy_sm_work()
835 dev_dbg(&rport->phy->dev, "FS/LS online\n"); in rockchip_usb2phy_sm_work()
840 if (rport->suspended) { in rockchip_usb2phy_sm_work()
841 dev_dbg(&rport->phy->dev, "Connected\n"); in rockchip_usb2phy_sm_work()
842 rockchip_usb2phy_power_on(rport->phy); in rockchip_usb2phy_sm_work()
843 rport->suspended = false; in rockchip_usb2phy_sm_work()
845 /* D+ line pull-up, D- line pull-down */ in rockchip_usb2phy_sm_work()
846 dev_dbg(&rport->phy->dev, "FS/LS online\n"); in rockchip_usb2phy_sm_work()
850 if (!rport->suspended) { in rockchip_usb2phy_sm_work()
851 dev_dbg(&rport->phy->dev, "Disconnected\n"); in rockchip_usb2phy_sm_work()
852 rockchip_usb2phy_power_off(rport->phy); in rockchip_usb2phy_sm_work()
853 rport->suspended = true; in rockchip_usb2phy_sm_work()
858 * plug-in irq. in rockchip_usb2phy_sm_work()
860 property_enable(rphy->grf, &rport->port_cfg->ls_det_clr, true); in rockchip_usb2phy_sm_work()
861 property_enable(rphy->grf, &rport->port_cfg->ls_det_en, true); in rockchip_usb2phy_sm_work()
867 mutex_unlock(&rport->mutex); in rockchip_usb2phy_sm_work()
870 dev_dbg(&rport->phy->dev, "unknown phy state\n"); in rockchip_usb2phy_sm_work()
875 mutex_unlock(&rport->mutex); in rockchip_usb2phy_sm_work()
876 schedule_delayed_work(&rport->sm_work, SCHEDULE_DELAY); in rockchip_usb2phy_sm_work()
882 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_linestate_irq()
884 if (!property_enabled(rphy->grf, &rport->port_cfg->ls_det_st)) in rockchip_usb2phy_linestate_irq()
887 mutex_lock(&rport->mutex); in rockchip_usb2phy_linestate_irq()
890 property_enable(rphy->grf, &rport->port_cfg->ls_det_en, false); in rockchip_usb2phy_linestate_irq()
891 property_enable(rphy->grf, &rport->port_cfg->ls_det_clr, true); in rockchip_usb2phy_linestate_irq()
893 mutex_unlock(&rport->mutex); in rockchip_usb2phy_linestate_irq()
900 if (rport->suspended && rport->port_id == USB2PHY_PORT_HOST) in rockchip_usb2phy_linestate_irq()
901 rockchip_usb2phy_sm_work(&rport->sm_work.work); in rockchip_usb2phy_linestate_irq()
909 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_bvalid_irq()
911 if (!property_enabled(rphy->grf, &rport->port_cfg->bvalid_det_st)) in rockchip_usb2phy_bvalid_irq()
914 mutex_lock(&rport->mutex); in rockchip_usb2phy_bvalid_irq()
917 property_enable(rphy->grf, &rport->port_cfg->bvalid_det_clr, true); in rockchip_usb2phy_bvalid_irq()
919 mutex_unlock(&rport->mutex); in rockchip_usb2phy_bvalid_irq()
921 rockchip_usb2phy_otg_sm_work(&rport->otg_sm_work.work); in rockchip_usb2phy_bvalid_irq()
929 struct rockchip_usb2phy *rphy = dev_get_drvdata(rport->phy->dev.parent); in rockchip_usb2phy_otg_mux_irq()
931 if (property_enabled(rphy->grf, &rport->port_cfg->bvalid_det_st)) in rockchip_usb2phy_otg_mux_irq()
943 rport->port_id = USB2PHY_PORT_HOST; in rockchip_usb2phy_host_port_init()
944 rport->port_cfg = &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_HOST]; in rockchip_usb2phy_host_port_init()
945 rport->suspended = true; in rockchip_usb2phy_host_port_init()
947 mutex_init(&rport->mutex); in rockchip_usb2phy_host_port_init()
948 INIT_DELAYED_WORK(&rport->sm_work, rockchip_usb2phy_sm_work); in rockchip_usb2phy_host_port_init()
950 rport->ls_irq = of_irq_get_byname(child_np, "linestate"); in rockchip_usb2phy_host_port_init()
951 if (rport->ls_irq < 0) { in rockchip_usb2phy_host_port_init()
952 dev_err(rphy->dev, "no linestate irq provided\n"); in rockchip_usb2phy_host_port_init()
953 return rport->ls_irq; in rockchip_usb2phy_host_port_init()
956 ret = devm_request_threaded_irq(rphy->dev, rport->ls_irq, NULL, in rockchip_usb2phy_host_port_init()
961 dev_err(rphy->dev, "failed to request linestate irq handle\n"); in rockchip_usb2phy_host_port_init()
974 schedule_delayed_work(&rport->otg_sm_work, OTG_SCHEDULE_DELAY); in rockchip_otg_event()
985 rport->port_id = USB2PHY_PORT_OTG; in rockchip_usb2phy_otg_port_init()
986 rport->port_cfg = &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_OTG]; in rockchip_usb2phy_otg_port_init()
987 rport->state = OTG_STATE_UNDEFINED; in rockchip_usb2phy_otg_port_init()
991 * put phy in suspend mode, it aims to enable usb in rockchip_usb2phy_otg_port_init()
992 * phy and clock in power_on() called by usb controller in rockchip_usb2phy_otg_port_init()
995 rport->suspended = true; in rockchip_usb2phy_otg_port_init()
996 rport->vbus_attached = false; in rockchip_usb2phy_otg_port_init()
998 mutex_init(&rport->mutex); in rockchip_usb2phy_otg_port_init()
1000 rport->mode = of_usb_get_dr_mode_by_phy(child_np, -1); in rockchip_usb2phy_otg_port_init()
1001 if (rport->mode == USB_DR_MODE_HOST || in rockchip_usb2phy_otg_port_init()
1002 rport->mode == USB_DR_MODE_UNKNOWN) { in rockchip_usb2phy_otg_port_init()
1007 INIT_DELAYED_WORK(&rport->chg_work, rockchip_chg_detect_work); in rockchip_usb2phy_otg_port_init()
1008 INIT_DELAYED_WORK(&rport->otg_sm_work, rockchip_usb2phy_otg_sm_work); in rockchip_usb2phy_otg_port_init()
1011 * Some SoCs use one interrupt with otg-id/otg-bvalid/linestate in rockchip_usb2phy_otg_port_init()
1012 * interrupts muxed together, so probe the otg-mux interrupt first, in rockchip_usb2phy_otg_port_init()
1015 rport->otg_mux_irq = of_irq_get_byname(child_np, "otg-mux"); in rockchip_usb2phy_otg_port_init()
1016 if (rport->otg_mux_irq > 0) { in rockchip_usb2phy_otg_port_init()
1017 ret = devm_request_threaded_irq(rphy->dev, rport->otg_mux_irq, in rockchip_usb2phy_otg_port_init()
1024 dev_err(rphy->dev, in rockchip_usb2phy_otg_port_init()
1025 "failed to request otg-mux irq handle\n"); in rockchip_usb2phy_otg_port_init()
1029 rport->bvalid_irq = of_irq_get_byname(child_np, "otg-bvalid"); in rockchip_usb2phy_otg_port_init()
1030 if (rport->bvalid_irq < 0) { in rockchip_usb2phy_otg_port_init()
1031 dev_err(rphy->dev, "no vbus valid irq provided\n"); in rockchip_usb2phy_otg_port_init()
1032 ret = rport->bvalid_irq; in rockchip_usb2phy_otg_port_init()
1036 ret = devm_request_threaded_irq(rphy->dev, rport->bvalid_irq, in rockchip_usb2phy_otg_port_init()
1043 dev_err(rphy->dev, in rockchip_usb2phy_otg_port_init()
1044 "failed to request otg-bvalid irq handle\n"); in rockchip_usb2phy_otg_port_init()
1049 if (!IS_ERR(rphy->edev)) { in rockchip_usb2phy_otg_port_init()
1050 rport->event_nb.notifier_call = rockchip_otg_event; in rockchip_usb2phy_otg_port_init()
1052 ret = devm_extcon_register_notifier(rphy->dev, rphy->edev, in rockchip_usb2phy_otg_port_init()
1053 EXTCON_USB_HOST, &rport->event_nb); in rockchip_usb2phy_otg_port_init()
1055 dev_err(rphy->dev, "register USB HOST notifier failed\n"); in rockchip_usb2phy_otg_port_init()
1064 struct device *dev = &pdev->dev; in rockchip_usb2phy_probe()
1065 struct device_node *np = dev->of_node; in rockchip_usb2phy_probe()
1076 return -ENOMEM; in rockchip_usb2phy_probe()
1078 match = of_match_device(dev->driver->of_match_table, dev); in rockchip_usb2phy_probe()
1079 if (!match || !match->data) { in rockchip_usb2phy_probe()
1081 return -EINVAL; in rockchip_usb2phy_probe()
1084 if (!dev->parent || !dev->parent->of_node) in rockchip_usb2phy_probe()
1085 return -EINVAL; in rockchip_usb2phy_probe()
1087 rphy->grf = syscon_node_to_regmap(dev->parent->of_node); in rockchip_usb2phy_probe()
1088 if (IS_ERR(rphy->grf)) in rockchip_usb2phy_probe()
1089 return PTR_ERR(rphy->grf); in rockchip_usb2phy_probe()
1091 if (of_device_is_compatible(np, "rockchip,rv1108-usb2phy")) { in rockchip_usb2phy_probe()
1092 rphy->usbgrf = in rockchip_usb2phy_probe()
1093 syscon_regmap_lookup_by_phandle(dev->of_node, in rockchip_usb2phy_probe()
1095 if (IS_ERR(rphy->usbgrf)) in rockchip_usb2phy_probe()
1096 return PTR_ERR(rphy->usbgrf); in rockchip_usb2phy_probe()
1098 rphy->usbgrf = NULL; in rockchip_usb2phy_probe()
1104 return -EINVAL; in rockchip_usb2phy_probe()
1107 rphy->dev = dev; in rockchip_usb2phy_probe()
1108 phy_cfgs = match->data; in rockchip_usb2phy_probe()
1109 rphy->chg_state = USB_CHG_STATE_UNDEFINED; in rockchip_usb2phy_probe()
1110 rphy->chg_type = POWER_SUPPLY_TYPE_UNKNOWN; in rockchip_usb2phy_probe()
1121 rphy->phy_cfg = &phy_cfgs[index]; in rockchip_usb2phy_probe()
1128 if (!rphy->phy_cfg) { in rockchip_usb2phy_probe()
1129 dev_err(dev, "no phy-config can be matched with %pOFn node\n", in rockchip_usb2phy_probe()
1131 return -EINVAL; in rockchip_usb2phy_probe()
1134 rphy->clk = of_clk_get_by_name(np, "phyclk"); in rockchip_usb2phy_probe()
1135 if (!IS_ERR(rphy->clk)) { in rockchip_usb2phy_probe()
1136 clk_prepare_enable(rphy->clk); in rockchip_usb2phy_probe()
1138 dev_info(&pdev->dev, "no phyclk specified\n"); in rockchip_usb2phy_probe()
1139 rphy->clk = NULL; in rockchip_usb2phy_probe()
1150 struct rockchip_usb2phy_port *rport = &rphy->ports[index]; in rockchip_usb2phy_probe()
1153 /* This driver aims to support both otg-port and host-port */ in rockchip_usb2phy_probe()
1154 if (!of_node_name_eq(child_np, "host-port") && in rockchip_usb2phy_probe()
1155 !of_node_name_eq(child_np, "otg-port")) in rockchip_usb2phy_probe()
1165 rport->phy = phy; in rockchip_usb2phy_probe()
1166 phy_set_drvdata(rport->phy, rport); in rockchip_usb2phy_probe()
1169 if (of_node_name_eq(child_np, "host-port")) { in rockchip_usb2phy_probe()
1183 if (++index >= rphy->phy_cfg->num_ports) in rockchip_usb2phy_probe()
1193 if (rphy->clk) { in rockchip_usb2phy_probe()
1194 clk_disable_unprepare(rphy->clk); in rockchip_usb2phy_probe()
1195 clk_put(rphy->clk); in rockchip_usb2phy_probe()
1426 { .compatible = "rockchip,px30-usb2phy", .data = &rk3328_phy_cfgs },
1427 { .compatible = "rockchip,rk3228-usb2phy", .data = &rk3228_phy_cfgs },
1428 { .compatible = "rockchip,rk3328-usb2phy", .data = &rk3328_phy_cfgs },
1429 { .compatible = "rockchip,rk3366-usb2phy", .data = &rk3366_phy_cfgs },
1430 { .compatible = "rockchip,rk3399-usb2phy", .data = &rk3399_phy_cfgs },
1431 { .compatible = "rockchip,rv1108-usb2phy", .data = &rv1108_phy_cfgs },
1439 .name = "rockchip-usb2phy",
1445 MODULE_AUTHOR("Frank Wang <frank.wang@rock-chips.com>");