Lines Matching refs:d

32 void ast_vhub_dev_irq(struct ast_vhub_dev *d)  in ast_vhub_dev_irq()  argument
34 u32 istat = readl(d->regs + AST_VHUB_DEV_ISR); in ast_vhub_dev_irq()
36 writel(istat, d->regs + AST_VHUB_DEV_ISR); in ast_vhub_dev_irq()
39 ast_vhub_ep0_handle_ack(&d->ep0, true); in ast_vhub_dev_irq()
41 ast_vhub_ep0_handle_ack(&d->ep0, false); in ast_vhub_dev_irq()
43 ast_vhub_ep0_handle_setup(&d->ep0); in ast_vhub_dev_irq()
46 static void ast_vhub_dev_enable(struct ast_vhub_dev *d) in ast_vhub_dev_enable() argument
50 if (d->enabled) in ast_vhub_dev_enable()
54 ast_vhub_reset_ep0(d); in ast_vhub_dev_enable()
61 if (d->gadget.speed == USB_SPEED_HIGH) in ast_vhub_dev_enable()
63 writel(reg, d->regs + AST_VHUB_DEV_EN_CTRL); in ast_vhub_dev_enable()
66 hmsk = VHUB_IRQ_DEVICE1 << d->index; in ast_vhub_dev_enable()
67 reg = readl(d->vhub->regs + AST_VHUB_IER); in ast_vhub_dev_enable()
69 writel(reg, d->vhub->regs + AST_VHUB_IER); in ast_vhub_dev_enable()
72 writel(d->ep0.buf_dma, d->regs + AST_VHUB_DEV_EP0_DATA); in ast_vhub_dev_enable()
75 for (i = 0; i < d->max_epns; i++) { in ast_vhub_dev_enable()
76 struct ast_vhub_ep *ep = d->epns[i]; in ast_vhub_dev_enable()
86 d->wakeup_en = false; in ast_vhub_dev_enable()
87 d->enabled = true; in ast_vhub_dev_enable()
90 static void ast_vhub_dev_disable(struct ast_vhub_dev *d) in ast_vhub_dev_disable() argument
94 if (!d->enabled) in ast_vhub_dev_disable()
98 hmsk = VHUB_IRQ_DEVICE1 << d->index; in ast_vhub_dev_disable()
99 reg = readl(d->vhub->regs + AST_VHUB_IER); in ast_vhub_dev_disable()
101 writel(reg, d->vhub->regs + AST_VHUB_IER); in ast_vhub_dev_disable()
104 writel(0, d->regs + AST_VHUB_DEV_EN_CTRL); in ast_vhub_dev_disable()
105 d->gadget.speed = USB_SPEED_UNKNOWN; in ast_vhub_dev_disable()
106 d->enabled = false; in ast_vhub_dev_disable()
109 static int ast_vhub_dev_feature(struct ast_vhub_dev *d, in ast_vhub_dev_feature() argument
115 DDBG(d, "%s_FEATURE(dev val=%02x)\n", in ast_vhub_dev_feature()
119 d->wakeup_en = is_set; in ast_vhub_dev_feature()
124 val = readl(d->vhub->regs + AST_VHUB_CTRL); in ast_vhub_dev_feature()
127 writel(val, d->vhub->regs + AST_VHUB_CTRL); in ast_vhub_dev_feature()
135 static int ast_vhub_ep_feature(struct ast_vhub_dev *d, in ast_vhub_ep_feature() argument
142 DDBG(d, "%s_FEATURE(ep%d val=%02x)\n", in ast_vhub_ep_feature()
146 if (ep_num >= d->max_epns || !d->epns[ep_num - 1]) in ast_vhub_ep_feature()
151 ep = d->epns[ep_num - 1]; in ast_vhub_ep_feature()
159 DDBG(d, "%s stall on EP %d\n", in ast_vhub_ep_feature()
167 static int ast_vhub_dev_status(struct ast_vhub_dev *d, in ast_vhub_dev_status() argument
172 DDBG(d, "GET_STATUS(dev)\n"); in ast_vhub_dev_status()
174 st0 = d->gadget.is_selfpowered << USB_DEVICE_SELF_POWERED; in ast_vhub_dev_status()
175 if (d->wakeup_en) in ast_vhub_dev_status()
178 return ast_vhub_simple_reply(&d->ep0, st0, 0); in ast_vhub_dev_status()
181 static int ast_vhub_ep_status(struct ast_vhub_dev *d, in ast_vhub_ep_status() argument
188 DDBG(d, "GET_STATUS(ep%d)\n", ep_num); in ast_vhub_ep_status()
190 if (ep_num >= d->max_epns) in ast_vhub_ep_status()
193 ep = d->epns[ep_num - 1]; in ast_vhub_ep_status()
203 return ast_vhub_simple_reply(&d->ep0, st0, 0); in ast_vhub_ep_status()
206 static void ast_vhub_dev_set_address(struct ast_vhub_dev *d, u8 addr) in ast_vhub_dev_set_address() argument
210 DDBG(d, "SET_ADDRESS: Got address %x\n", addr); in ast_vhub_dev_set_address()
212 reg = readl(d->regs + AST_VHUB_DEV_EN_CTRL); in ast_vhub_dev_set_address()
215 writel(reg, d->regs + AST_VHUB_DEV_EN_CTRL); in ast_vhub_dev_set_address()
221 struct ast_vhub_dev *d = ep->dev; in ast_vhub_std_dev_request() local
225 if (!d->driver || !d->enabled) { in ast_vhub_std_dev_request()
228 d->driver, d->enabled); in ast_vhub_std_dev_request()
239 if (d->gadget.speed == USB_SPEED_UNKNOWN) { in ast_vhub_std_dev_request()
240 d->gadget.speed = ep->vhub->speed; in ast_vhub_std_dev_request()
241 if (d->gadget.speed > d->driver->max_speed) in ast_vhub_std_dev_request()
242 d->gadget.speed = d->driver->max_speed; in ast_vhub_std_dev_request()
243 DDBG(d, "fist packet, captured speed %d\n", in ast_vhub_std_dev_request()
244 d->gadget.speed); in ast_vhub_std_dev_request()
253 ast_vhub_dev_set_address(d, wValue); in ast_vhub_std_dev_request()
258 return ast_vhub_dev_status(d, wIndex, wValue); in ast_vhub_std_dev_request()
262 return ast_vhub_ep_status(d, wIndex, wValue); in ast_vhub_std_dev_request()
266 return ast_vhub_dev_feature(d, wIndex, wValue, true); in ast_vhub_std_dev_request()
268 return ast_vhub_dev_feature(d, wIndex, wValue, false); in ast_vhub_std_dev_request()
270 return ast_vhub_ep_feature(d, wIndex, wValue, true); in ast_vhub_std_dev_request()
272 return ast_vhub_ep_feature(d, wIndex, wValue, false); in ast_vhub_std_dev_request()
279 struct ast_vhub_dev *d = to_ast_dev(gadget); in ast_vhub_udc_wakeup() local
283 spin_lock_irqsave(&d->vhub->lock, flags); in ast_vhub_udc_wakeup()
284 if (!d->wakeup_en) in ast_vhub_udc_wakeup()
287 DDBG(d, "Device initiated wakeup\n"); in ast_vhub_udc_wakeup()
290 ast_vhub_hub_wake_all(d->vhub); in ast_vhub_udc_wakeup()
293 spin_unlock_irqrestore(&d->vhub->lock, flags); in ast_vhub_udc_wakeup()
299 struct ast_vhub_dev *d = to_ast_dev(gadget); in ast_vhub_udc_get_frame() local
301 return (readl(d->vhub->regs + AST_VHUB_USBSTS) >> 16) & 0x7ff; in ast_vhub_udc_get_frame()
304 static void ast_vhub_dev_nuke(struct ast_vhub_dev *d) in ast_vhub_dev_nuke() argument
308 for (i = 0; i < d->max_epns; i++) { in ast_vhub_dev_nuke()
309 if (!d->epns[i]) in ast_vhub_dev_nuke()
311 ast_vhub_nuke(d->epns[i], -ESHUTDOWN); in ast_vhub_dev_nuke()
317 struct ast_vhub_dev *d = to_ast_dev(gadget); in ast_vhub_udc_pullup() local
320 spin_lock_irqsave(&d->vhub->lock, flags); in ast_vhub_udc_pullup()
322 DDBG(d, "pullup(%d)\n", on); in ast_vhub_udc_pullup()
325 ast_vhub_device_connect(d->vhub, d->index, on); in ast_vhub_udc_pullup()
331 if (d->enabled) { in ast_vhub_udc_pullup()
332 ast_vhub_dev_nuke(d); in ast_vhub_udc_pullup()
333 ast_vhub_dev_disable(d); in ast_vhub_udc_pullup()
336 spin_unlock_irqrestore(&d->vhub->lock, flags); in ast_vhub_udc_pullup()
344 struct ast_vhub_dev *d = to_ast_dev(gadget); in ast_vhub_udc_start() local
347 spin_lock_irqsave(&d->vhub->lock, flags); in ast_vhub_udc_start()
349 DDBG(d, "start\n"); in ast_vhub_udc_start()
352 d->driver = driver; in ast_vhub_udc_start()
353 d->gadget.is_selfpowered = 1; in ast_vhub_udc_start()
355 spin_unlock_irqrestore(&d->vhub->lock, flags); in ast_vhub_udc_start()
364 struct ast_vhub_dev *d = to_ast_dev(gadget); in ast_vhub_udc_match_ep() local
369 DDBG(d, "Match EP type %d\n", usb_endpoint_type(desc)); in ast_vhub_udc_match_ep()
379 DDBG(d, " -> using existing EP%d\n", in ast_vhub_udc_match_ep()
425 for (i = 0; i < d->max_epns; i++) in ast_vhub_udc_match_ep()
426 if (d->epns[i] == NULL) in ast_vhub_udc_match_ep()
428 if (i >= d->max_epns) in ast_vhub_udc_match_ep()
436 ep = ast_vhub_alloc_epn(d, addr); in ast_vhub_udc_match_ep()
439 DDBG(d, "Allocated epn#%d for port EP%d\n", in ast_vhub_udc_match_ep()
447 struct ast_vhub_dev *d = to_ast_dev(gadget); in ast_vhub_udc_stop() local
450 spin_lock_irqsave(&d->vhub->lock, flags); in ast_vhub_udc_stop()
452 DDBG(d, "stop\n"); in ast_vhub_udc_stop()
454 d->driver = NULL; in ast_vhub_udc_stop()
455 d->gadget.speed = USB_SPEED_UNKNOWN; in ast_vhub_udc_stop()
457 ast_vhub_dev_nuke(d); in ast_vhub_udc_stop()
459 if (d->enabled) in ast_vhub_udc_stop()
460 ast_vhub_dev_disable(d); in ast_vhub_udc_stop()
462 spin_unlock_irqrestore(&d->vhub->lock, flags); in ast_vhub_udc_stop()
476 void ast_vhub_dev_suspend(struct ast_vhub_dev *d) in ast_vhub_dev_suspend() argument
478 if (d->driver && d->driver->suspend) { in ast_vhub_dev_suspend()
479 spin_unlock(&d->vhub->lock); in ast_vhub_dev_suspend()
480 d->driver->suspend(&d->gadget); in ast_vhub_dev_suspend()
481 spin_lock(&d->vhub->lock); in ast_vhub_dev_suspend()
485 void ast_vhub_dev_resume(struct ast_vhub_dev *d) in ast_vhub_dev_resume() argument
487 if (d->driver && d->driver->resume) { in ast_vhub_dev_resume()
488 spin_unlock(&d->vhub->lock); in ast_vhub_dev_resume()
489 d->driver->resume(&d->gadget); in ast_vhub_dev_resume()
490 spin_lock(&d->vhub->lock); in ast_vhub_dev_resume()
494 void ast_vhub_dev_reset(struct ast_vhub_dev *d) in ast_vhub_dev_reset() argument
497 if (!d->driver) { in ast_vhub_dev_reset()
498 ast_vhub_dev_disable(d); in ast_vhub_dev_reset()
503 if (!d->enabled) { in ast_vhub_dev_reset()
504 DDBG(d, "Reset of disabled device, enabling...\n"); in ast_vhub_dev_reset()
505 ast_vhub_dev_enable(d); in ast_vhub_dev_reset()
507 DDBG(d, "Reset of enabled device, resetting...\n"); in ast_vhub_dev_reset()
508 spin_unlock(&d->vhub->lock); in ast_vhub_dev_reset()
509 usb_gadget_udc_reset(&d->gadget, d->driver); in ast_vhub_dev_reset()
510 spin_lock(&d->vhub->lock); in ast_vhub_dev_reset()
516 ast_vhub_dev_disable(d); in ast_vhub_dev_reset()
517 ast_vhub_dev_enable(d); in ast_vhub_dev_reset()
521 void ast_vhub_del_dev(struct ast_vhub_dev *d) in ast_vhub_del_dev() argument
525 spin_lock_irqsave(&d->vhub->lock, flags); in ast_vhub_del_dev()
526 if (!d->registered) { in ast_vhub_del_dev()
527 spin_unlock_irqrestore(&d->vhub->lock, flags); in ast_vhub_del_dev()
530 d->registered = false; in ast_vhub_del_dev()
531 spin_unlock_irqrestore(&d->vhub->lock, flags); in ast_vhub_del_dev()
533 usb_del_gadget_udc(&d->gadget); in ast_vhub_del_dev()
534 device_unregister(d->port_dev); in ast_vhub_del_dev()
535 kfree(d->epns); in ast_vhub_del_dev()
545 struct ast_vhub_dev *d = &vhub->ports[idx].dev; in ast_vhub_init_dev() local
549 d->vhub = vhub; in ast_vhub_init_dev()
550 d->index = idx; in ast_vhub_init_dev()
551 d->name = devm_kasprintf(parent, GFP_KERNEL, "port%d", idx+1); in ast_vhub_init_dev()
552 d->regs = vhub->regs + 0x100 + 0x10 * idx; in ast_vhub_init_dev()
554 ast_vhub_init_ep0(vhub, &d->ep0, d); in ast_vhub_init_dev()
560 d->max_epns = min_t(u32, vhub->max_epns, 30); in ast_vhub_init_dev()
561 d->epns = kcalloc(d->max_epns, sizeof(*d->epns), GFP_KERNEL); in ast_vhub_init_dev()
562 if (!d->epns) in ast_vhub_init_dev()
570 d->port_dev = kzalloc(sizeof(struct device), GFP_KERNEL); in ast_vhub_init_dev()
571 if (!d->port_dev) { in ast_vhub_init_dev()
575 device_initialize(d->port_dev); in ast_vhub_init_dev()
576 d->port_dev->release = ast_vhub_dev_release; in ast_vhub_init_dev()
577 d->port_dev->parent = parent; in ast_vhub_init_dev()
578 dev_set_name(d->port_dev, "%s:p%d", dev_name(parent), idx + 1); in ast_vhub_init_dev()
579 rc = device_add(d->port_dev); in ast_vhub_init_dev()
584 INIT_LIST_HEAD(&d->gadget.ep_list); in ast_vhub_init_dev()
585 d->gadget.ops = &ast_vhub_udc_ops; in ast_vhub_init_dev()
586 d->gadget.ep0 = &d->ep0.ep; in ast_vhub_init_dev()
587 d->gadget.name = KBUILD_MODNAME; in ast_vhub_init_dev()
589 d->gadget.max_speed = USB_SPEED_FULL; in ast_vhub_init_dev()
591 d->gadget.max_speed = USB_SPEED_HIGH; in ast_vhub_init_dev()
592 d->gadget.speed = USB_SPEED_UNKNOWN; in ast_vhub_init_dev()
593 d->gadget.dev.of_node = vhub->pdev->dev.of_node; in ast_vhub_init_dev()
594 d->gadget.dev.of_node_reused = true; in ast_vhub_init_dev()
596 rc = usb_add_gadget_udc(d->port_dev, &d->gadget); in ast_vhub_init_dev()
599 d->registered = true; in ast_vhub_init_dev()
603 device_del(d->port_dev); in ast_vhub_init_dev()
605 put_device(d->port_dev); in ast_vhub_init_dev()
607 kfree(d->epns); in ast_vhub_init_dev()