Lines Matching refs:cdns
28 static int cdns_set_mode(struct cdns *cdns, enum usb_dr_mode mode) in cdns_set_mode() argument
39 dev_dbg(cdns->dev, "Set controller to OTG mode\n"); in cdns_set_mode()
41 if (cdns->version == CDNSP_CONTROLLER_V2) in cdns_set_mode()
42 override_reg = &cdns->otg_cdnsp_regs->override; in cdns_set_mode()
43 else if (cdns->version == CDNS3_CONTROLLER_V1) in cdns_set_mode()
44 override_reg = &cdns->otg_v1_regs->override; in cdns_set_mode()
46 override_reg = &cdns->otg_v0_regs->ctrl1; in cdns_set_mode()
50 if (cdns->version != CDNS3_CONTROLLER_V0) in cdns_set_mode()
57 if (cdns->version == CDNS3_CONTROLLER_V1) { in cdns_set_mode()
64 if (cdns->phyrst_a_enable) { in cdns_set_mode()
65 reg = readl(&cdns->otg_v1_regs->phyrst_cfg); in cdns_set_mode()
67 writel(reg, &cdns->otg_v1_regs->phyrst_cfg); in cdns_set_mode()
79 dev_err(cdns->dev, "Unsupported mode of operation %d\n", mode); in cdns_set_mode()
86 int cdns_get_id(struct cdns *cdns) in cdns_get_id() argument
90 id = readl(&cdns->otg_regs->sts) & OTGSTS_ID_VALUE; in cdns_get_id()
91 dev_dbg(cdns->dev, "OTG ID: %d", id); in cdns_get_id()
96 int cdns_get_vbus(struct cdns *cdns) in cdns_get_vbus() argument
100 vbus = !!(readl(&cdns->otg_regs->sts) & OTGSTS_VBUS_VALID); in cdns_get_vbus()
101 dev_dbg(cdns->dev, "OTG VBUS: %d", vbus); in cdns_get_vbus()
106 void cdns_clear_vbus(struct cdns *cdns) in cdns_clear_vbus() argument
110 if (cdns->version != CDNSP_CONTROLLER_V2) in cdns_clear_vbus()
113 reg = readl(&cdns->otg_cdnsp_regs->override); in cdns_clear_vbus()
115 writel(reg, &cdns->otg_cdnsp_regs->override); in cdns_clear_vbus()
119 void cdns_set_vbus(struct cdns *cdns) in cdns_set_vbus() argument
123 if (cdns->version != CDNSP_CONTROLLER_V2) in cdns_set_vbus()
126 reg = readl(&cdns->otg_cdnsp_regs->override); in cdns_set_vbus()
128 writel(reg, &cdns->otg_cdnsp_regs->override); in cdns_set_vbus()
132 bool cdns_is_host(struct cdns *cdns) in cdns_is_host() argument
134 if (cdns->dr_mode == USB_DR_MODE_HOST) in cdns_is_host()
136 else if (cdns_get_id(cdns) == CDNS3_ID_HOST) in cdns_is_host()
142 bool cdns_is_device(struct cdns *cdns) in cdns_is_device() argument
144 if (cdns->dr_mode == USB_DR_MODE_PERIPHERAL) in cdns_is_device()
146 else if (cdns->dr_mode == USB_DR_MODE_OTG) in cdns_is_device()
147 if (cdns_get_id(cdns) == CDNS3_ID_PERIPHERAL) in cdns_is_device()
157 static void cdns_otg_disable_irq(struct cdns *cdns) in cdns_otg_disable_irq() argument
159 if (cdns->version) in cdns_otg_disable_irq()
160 writel(0, &cdns->otg_irq_regs->ien); in cdns_otg_disable_irq()
167 static void cdns_otg_enable_irq(struct cdns *cdns) in cdns_otg_enable_irq() argument
170 OTGIEN_VBUSVALID_FALL_INT, &cdns->otg_irq_regs->ien); in cdns_otg_enable_irq()
179 int cdns_drd_host_on(struct cdns *cdns) in cdns_drd_host_on() argument
186 &cdns->otg_regs->cmd); in cdns_drd_host_on()
188 if (cdns->version == CDNSP_CONTROLLER_V2) in cdns_drd_host_on()
193 dev_dbg(cdns->dev, "Waiting till Host mode is turned on\n"); in cdns_drd_host_on()
194 ret = readl_poll_timeout_atomic(&cdns->otg_regs->sts, val, in cdns_drd_host_on()
198 dev_err(cdns->dev, "timeout waiting for xhci_ready\n"); in cdns_drd_host_on()
200 phy_set_mode(cdns->usb3_phy, PHY_MODE_USB_HOST); in cdns_drd_host_on()
208 void cdns_drd_host_off(struct cdns *cdns) in cdns_drd_host_off() argument
214 &cdns->otg_regs->cmd); in cdns_drd_host_off()
217 readl_poll_timeout_atomic(&cdns->otg_regs->state, val, in cdns_drd_host_off()
220 phy_set_mode(cdns->usb3_phy, PHY_MODE_INVALID); in cdns_drd_host_off()
229 int cdns_drd_gadget_on(struct cdns *cdns) in cdns_drd_gadget_on() argument
236 writel(OTGCMD_DEV_BUS_REQ | reg, &cdns->otg_regs->cmd); in cdns_drd_gadget_on()
238 dev_dbg(cdns->dev, "Waiting till Device mode is turned on\n"); in cdns_drd_gadget_on()
240 if (cdns->version == CDNSP_CONTROLLER_V2) in cdns_drd_gadget_on()
245 ret = readl_poll_timeout_atomic(&cdns->otg_regs->sts, val, in cdns_drd_gadget_on()
248 dev_err(cdns->dev, "timeout waiting for dev_ready\n"); in cdns_drd_gadget_on()
252 phy_set_mode(cdns->usb3_phy, PHY_MODE_USB_DEVICE); in cdns_drd_gadget_on()
261 void cdns_drd_gadget_off(struct cdns *cdns) in cdns_drd_gadget_off() argument
272 &cdns->otg_regs->cmd); in cdns_drd_gadget_off()
274 readl_poll_timeout_atomic(&cdns->otg_regs->state, val, in cdns_drd_gadget_off()
277 phy_set_mode(cdns->usb3_phy, PHY_MODE_INVALID); in cdns_drd_gadget_off()
287 static int cdns_init_otg_mode(struct cdns *cdns) in cdns_init_otg_mode() argument
291 cdns_otg_disable_irq(cdns); in cdns_init_otg_mode()
293 writel(~0, &cdns->otg_irq_regs->ivect); in cdns_init_otg_mode()
295 ret = cdns_set_mode(cdns, USB_DR_MODE_OTG); in cdns_init_otg_mode()
299 cdns_otg_enable_irq(cdns); in cdns_init_otg_mode()
310 int cdns_drd_update_mode(struct cdns *cdns) in cdns_drd_update_mode() argument
314 switch (cdns->dr_mode) { in cdns_drd_update_mode()
316 ret = cdns_set_mode(cdns, USB_DR_MODE_PERIPHERAL); in cdns_drd_update_mode()
319 ret = cdns_set_mode(cdns, USB_DR_MODE_HOST); in cdns_drd_update_mode()
322 ret = cdns_init_otg_mode(cdns); in cdns_drd_update_mode()
325 dev_err(cdns->dev, "Unsupported mode of operation %d\n", in cdns_drd_update_mode()
326 cdns->dr_mode); in cdns_drd_update_mode()
335 struct cdns *cdns = data; in cdns_drd_thread_irq() local
337 cdns_hw_role_switch(cdns); in cdns_drd_thread_irq()
353 struct cdns *cdns = data; in cdns_drd_irq() local
356 if (cdns->dr_mode != USB_DR_MODE_OTG) in cdns_drd_irq()
359 if (cdns->in_lpm) in cdns_drd_irq()
362 reg = readl(&cdns->otg_irq_regs->ivect); in cdns_drd_irq()
368 dev_dbg(cdns->dev, "OTG IRQ: new ID: %d\n", in cdns_drd_irq()
369 cdns_get_id(cdns)); in cdns_drd_irq()
375 dev_dbg(cdns->dev, "OTG IRQ: new VBUS: %d\n", in cdns_drd_irq()
376 cdns_get_vbus(cdns)); in cdns_drd_irq()
381 writel(~0, &cdns->otg_irq_regs->ivect); in cdns_drd_irq()
385 int cdns_drd_init(struct cdns *cdns) in cdns_drd_init() argument
391 regs = devm_ioremap_resource(cdns->dev, &cdns->otg_res); in cdns_drd_init()
404 cdns->otg_v0_regs = regs; in cdns_drd_init()
405 if (!readl(&cdns->otg_v0_regs->cmd)) { in cdns_drd_init()
406 cdns->version = CDNS3_CONTROLLER_V0; in cdns_drd_init()
407 cdns->otg_v1_regs = NULL; in cdns_drd_init()
408 cdns->otg_cdnsp_regs = NULL; in cdns_drd_init()
409 cdns->otg_regs = regs; in cdns_drd_init()
410 cdns->otg_irq_regs = (struct cdns_otg_irq_regs __iomem *) in cdns_drd_init()
411 &cdns->otg_v0_regs->ien; in cdns_drd_init()
412 writel(1, &cdns->otg_v0_regs->simulate); in cdns_drd_init()
413 dev_dbg(cdns->dev, "DRD version v0 (%08x)\n", in cdns_drd_init()
414 readl(&cdns->otg_v0_regs->version)); in cdns_drd_init()
416 cdns->otg_v0_regs = NULL; in cdns_drd_init()
417 cdns->otg_v1_regs = regs; in cdns_drd_init()
418 cdns->otg_cdnsp_regs = regs; in cdns_drd_init()
420 cdns->otg_regs = (void __iomem *)&cdns->otg_v1_regs->cmd; in cdns_drd_init()
422 state = readl(&cdns->otg_cdnsp_regs->did); in cdns_drd_init()
425 cdns->otg_irq_regs = (struct cdns_otg_irq_regs __iomem *) in cdns_drd_init()
426 &cdns->otg_cdnsp_regs->ien; in cdns_drd_init()
427 cdns->version = CDNSP_CONTROLLER_V2; in cdns_drd_init()
429 cdns->otg_irq_regs = (struct cdns_otg_irq_regs __iomem *) in cdns_drd_init()
430 &cdns->otg_v1_regs->ien; in cdns_drd_init()
431 writel(1, &cdns->otg_v1_regs->simulate); in cdns_drd_init()
432 cdns->version = CDNS3_CONTROLLER_V1; in cdns_drd_init()
434 dev_err(cdns->dev, "not supporte DID=0x%08x\n", state); in cdns_drd_init()
438 dev_dbg(cdns->dev, "DRD version v1 (ID: %08x, rev: %08x)\n", in cdns_drd_init()
439 readl(&cdns->otg_v1_regs->did), in cdns_drd_init()
440 readl(&cdns->otg_v1_regs->rid)); in cdns_drd_init()
443 state = OTGSTS_STRAP(readl(&cdns->otg_regs->sts)); in cdns_drd_init()
446 cdns->dr_mode = USB_DR_MODE_OTG; in cdns_drd_init()
448 if ((cdns->version == CDNSP_CONTROLLER_V2 && in cdns_drd_init()
450 (cdns->version != CDNSP_CONTROLLER_V2 && in cdns_drd_init()
452 dev_dbg(cdns->dev, "Controller strapped to HOST\n"); in cdns_drd_init()
453 cdns->dr_mode = USB_DR_MODE_HOST; in cdns_drd_init()
454 } else if ((cdns->version == CDNSP_CONTROLLER_V2 && in cdns_drd_init()
456 (cdns->version != CDNSP_CONTROLLER_V2 && in cdns_drd_init()
458 dev_dbg(cdns->dev, "Controller strapped to PERIPHERAL\n"); in cdns_drd_init()
459 cdns->dr_mode = USB_DR_MODE_PERIPHERAL; in cdns_drd_init()
462 ret = devm_request_threaded_irq(cdns->dev, cdns->otg_irq, in cdns_drd_init()
466 dev_name(cdns->dev), cdns); in cdns_drd_init()
468 dev_err(cdns->dev, "couldn't get otg_irq\n"); in cdns_drd_init()
472 state = readl(&cdns->otg_regs->sts); in cdns_drd_init()
474 dev_err(cdns->dev, "Cadence USB3 OTG device not ready\n"); in cdns_drd_init()
481 int cdns_drd_exit(struct cdns *cdns) in cdns_drd_exit() argument
483 cdns_otg_disable_irq(cdns); in cdns_drd_exit()
489 bool cdns_power_is_lost(struct cdns *cdns) in cdns_power_is_lost() argument
491 if (cdns->version == CDNS3_CONTROLLER_V0) { in cdns_power_is_lost()
492 if (!(readl(&cdns->otg_v0_regs->simulate) & BIT(0))) in cdns_power_is_lost()
495 if (!(readl(&cdns->otg_v1_regs->simulate) & BIT(0))) in cdns_power_is_lost()