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 writel(0, &cdns->otg_irq_regs->ien); in cdns_otg_disable_irq()
166 static void cdns_otg_enable_irq(struct cdns *cdns) in cdns_otg_enable_irq() argument
169 OTGIEN_VBUSVALID_FALL_INT, &cdns->otg_irq_regs->ien); in cdns_otg_enable_irq()
178 int cdns_drd_host_on(struct cdns *cdns) in cdns_drd_host_on() argument
185 &cdns->otg_regs->cmd); in cdns_drd_host_on()
187 if (cdns->version == CDNSP_CONTROLLER_V2) in cdns_drd_host_on()
192 dev_dbg(cdns->dev, "Waiting till Host mode is turned on\n"); in cdns_drd_host_on()
193 ret = readl_poll_timeout_atomic(&cdns->otg_regs->sts, val, in cdns_drd_host_on()
197 dev_err(cdns->dev, "timeout waiting for xhci_ready\n"); in cdns_drd_host_on()
199 phy_set_mode(cdns->usb3_phy, PHY_MODE_USB_HOST); in cdns_drd_host_on()
207 void cdns_drd_host_off(struct cdns *cdns) in cdns_drd_host_off() argument
213 &cdns->otg_regs->cmd); in cdns_drd_host_off()
216 readl_poll_timeout_atomic(&cdns->otg_regs->state, val, in cdns_drd_host_off()
219 phy_set_mode(cdns->usb3_phy, PHY_MODE_INVALID); in cdns_drd_host_off()
228 int cdns_drd_gadget_on(struct cdns *cdns) in cdns_drd_gadget_on() argument
235 writel(OTGCMD_DEV_BUS_REQ | reg, &cdns->otg_regs->cmd); in cdns_drd_gadget_on()
237 dev_dbg(cdns->dev, "Waiting till Device mode is turned on\n"); in cdns_drd_gadget_on()
239 if (cdns->version == CDNSP_CONTROLLER_V2) in cdns_drd_gadget_on()
244 ret = readl_poll_timeout_atomic(&cdns->otg_regs->sts, val, in cdns_drd_gadget_on()
247 dev_err(cdns->dev, "timeout waiting for dev_ready\n"); in cdns_drd_gadget_on()
251 phy_set_mode(cdns->usb3_phy, PHY_MODE_USB_DEVICE); in cdns_drd_gadget_on()
260 void cdns_drd_gadget_off(struct cdns *cdns) in cdns_drd_gadget_off() argument
271 &cdns->otg_regs->cmd); in cdns_drd_gadget_off()
273 readl_poll_timeout_atomic(&cdns->otg_regs->state, val, in cdns_drd_gadget_off()
276 phy_set_mode(cdns->usb3_phy, PHY_MODE_INVALID); in cdns_drd_gadget_off()
286 static int cdns_init_otg_mode(struct cdns *cdns) in cdns_init_otg_mode() argument
290 cdns_otg_disable_irq(cdns); in cdns_init_otg_mode()
292 writel(~0, &cdns->otg_irq_regs->ivect); in cdns_init_otg_mode()
294 ret = cdns_set_mode(cdns, USB_DR_MODE_OTG); in cdns_init_otg_mode()
298 cdns_otg_enable_irq(cdns); in cdns_init_otg_mode()
309 int cdns_drd_update_mode(struct cdns *cdns) in cdns_drd_update_mode() argument
313 switch (cdns->dr_mode) { in cdns_drd_update_mode()
315 ret = cdns_set_mode(cdns, USB_DR_MODE_PERIPHERAL); in cdns_drd_update_mode()
318 ret = cdns_set_mode(cdns, USB_DR_MODE_HOST); in cdns_drd_update_mode()
321 ret = cdns_init_otg_mode(cdns); in cdns_drd_update_mode()
324 dev_err(cdns->dev, "Unsupported mode of operation %d\n", in cdns_drd_update_mode()
325 cdns->dr_mode); in cdns_drd_update_mode()
334 struct cdns *cdns = data; in cdns_drd_thread_irq() local
336 cdns_hw_role_switch(cdns); in cdns_drd_thread_irq()
352 struct cdns *cdns = data; in cdns_drd_irq() local
355 if (cdns->dr_mode != USB_DR_MODE_OTG) in cdns_drd_irq()
358 if (cdns->in_lpm) in cdns_drd_irq()
361 reg = readl(&cdns->otg_irq_regs->ivect); in cdns_drd_irq()
367 dev_dbg(cdns->dev, "OTG IRQ: new ID: %d\n", in cdns_drd_irq()
368 cdns_get_id(cdns)); in cdns_drd_irq()
374 dev_dbg(cdns->dev, "OTG IRQ: new VBUS: %d\n", in cdns_drd_irq()
375 cdns_get_vbus(cdns)); in cdns_drd_irq()
380 writel(~0, &cdns->otg_irq_regs->ivect); in cdns_drd_irq()
384 int cdns_drd_init(struct cdns *cdns) in cdns_drd_init() argument
390 regs = devm_ioremap_resource(cdns->dev, &cdns->otg_res); in cdns_drd_init()
403 cdns->otg_v0_regs = regs; in cdns_drd_init()
404 if (!readl(&cdns->otg_v0_regs->cmd)) { in cdns_drd_init()
405 cdns->version = CDNS3_CONTROLLER_V0; in cdns_drd_init()
406 cdns->otg_v1_regs = NULL; in cdns_drd_init()
407 cdns->otg_cdnsp_regs = NULL; in cdns_drd_init()
408 cdns->otg_regs = regs; in cdns_drd_init()
409 cdns->otg_irq_regs = (struct cdns_otg_irq_regs __iomem *) in cdns_drd_init()
410 &cdns->otg_v0_regs->ien; in cdns_drd_init()
411 writel(1, &cdns->otg_v0_regs->simulate); in cdns_drd_init()
412 dev_dbg(cdns->dev, "DRD version v0 (%08x)\n", in cdns_drd_init()
413 readl(&cdns->otg_v0_regs->version)); in cdns_drd_init()
415 cdns->otg_v0_regs = NULL; in cdns_drd_init()
416 cdns->otg_v1_regs = regs; in cdns_drd_init()
417 cdns->otg_cdnsp_regs = regs; in cdns_drd_init()
419 cdns->otg_regs = (void __iomem *)&cdns->otg_v1_regs->cmd; in cdns_drd_init()
421 if (readl(&cdns->otg_cdnsp_regs->did) == OTG_CDNSP_DID) { in cdns_drd_init()
422 cdns->otg_irq_regs = (struct cdns_otg_irq_regs __iomem *) in cdns_drd_init()
423 &cdns->otg_cdnsp_regs->ien; in cdns_drd_init()
424 cdns->version = CDNSP_CONTROLLER_V2; in cdns_drd_init()
426 cdns->otg_irq_regs = (struct cdns_otg_irq_regs __iomem *) in cdns_drd_init()
427 &cdns->otg_v1_regs->ien; in cdns_drd_init()
428 writel(1, &cdns->otg_v1_regs->simulate); in cdns_drd_init()
429 cdns->version = CDNS3_CONTROLLER_V1; in cdns_drd_init()
432 dev_dbg(cdns->dev, "DRD version v1 (ID: %08x, rev: %08x)\n", in cdns_drd_init()
433 readl(&cdns->otg_v1_regs->did), in cdns_drd_init()
434 readl(&cdns->otg_v1_regs->rid)); in cdns_drd_init()
437 state = OTGSTS_STRAP(readl(&cdns->otg_regs->sts)); in cdns_drd_init()
440 cdns->dr_mode = USB_DR_MODE_OTG; in cdns_drd_init()
442 if ((cdns->version == CDNSP_CONTROLLER_V2 && in cdns_drd_init()
444 (cdns->version != CDNSP_CONTROLLER_V2 && in cdns_drd_init()
446 dev_dbg(cdns->dev, "Controller strapped to HOST\n"); in cdns_drd_init()
447 cdns->dr_mode = USB_DR_MODE_HOST; in cdns_drd_init()
448 } else 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 PERIPHERAL\n"); in cdns_drd_init()
453 cdns->dr_mode = USB_DR_MODE_PERIPHERAL; in cdns_drd_init()
456 ret = devm_request_threaded_irq(cdns->dev, cdns->otg_irq, in cdns_drd_init()
460 dev_name(cdns->dev), cdns); in cdns_drd_init()
462 dev_err(cdns->dev, "couldn't get otg_irq\n"); in cdns_drd_init()
466 state = readl(&cdns->otg_regs->sts); in cdns_drd_init()
468 dev_err(cdns->dev, "Cadence USB3 OTG device not ready\n"); in cdns_drd_init()
475 int cdns_drd_exit(struct cdns *cdns) in cdns_drd_exit() argument
477 cdns_otg_disable_irq(cdns); in cdns_drd_exit()
484 bool cdns_power_is_lost(struct cdns *cdns) in cdns_power_is_lost() argument
486 if (cdns->version == CDNS3_CONTROLLER_V0) { in cdns_power_is_lost()
487 if (!(readl(&cdns->otg_v0_regs->simulate) & BIT(0))) in cdns_power_is_lost()
490 if (!(readl(&cdns->otg_v1_regs->simulate) & BIT(0))) in cdns_power_is_lost()