Lines Matching +full:usb +full:- +full:attach
1 // SPDX-License-Identifier: GPL-1.0+
3 * Renesas USB driver
13 #include <linux/usb.h>
14 #include <linux/usb/hcd.h>
25 * the pipe will be re-used for each devices.
33 * +--------+
34 * | udev 0 | --> it is used when set address
35 * +--------+
37 * +--------+ pipes are reused for each uep.
38 * | udev 1 |-+- [uep 0 (dcp) ] --+ pipe will be switched when
39 * +--------+ | | other device requested
40 * +- [uep 1 (bulk)] --|---+ +--------------+
41 * | +--------------> | pipe0 (dcp) |
42 * +- [uep 2 (bulk)] -@ | +--------------+
44 * +--------+ | +--------------+
45 * | udev 2 |-+- [uep 0 (dcp) ] -@ +----------> | pipe2 (bulk) |
46 * +--------+ | +--------------+
47 * +- [uep 1 (int) ] ----+ +------> | pipe3 (bulk) |
48 * | | +--------------+
49 * +--------+ +-----|------> | pipe4 (int) |
50 * | udev 3 |-+- [uep 0 (dcp) ] -@ | +--------------+
51 * +--------+ | | | .... |
52 * +- [uep 1 (bulk)] -@ | | .... |
54 * +- [uep 2 (bulk)]-----------+
79 unsigned int counter; /* pipe attach counter */
106 ((i) < USBHSH_DEVICE_MAX) && ((pos) = (h)->udev + (i)); \
115 #define usbhsh_hcd_to_hpriv(h) (struct usbhsh_hpriv *)((h)->hcd_priv)
116 #define usbhsh_hcd_to_dev(h) ((h)->self.controller)
118 #define usbhsh_hpriv_to_priv(h) ((h)->mod.priv)
119 #define usbhsh_hpriv_to_dcp(h) ((h)->dcp)
123 #define usbhsh_ep_to_uep(u) ((u)->hcpriv)
124 #define usbhsh_uep_to_pipe(u) ((u)->pipe)
125 #define usbhsh_uep_to_udev(u) ((u)->udev)
126 #define usbhsh_uep_to_ep(u) ((u)->ep)
128 #define usbhsh_urb_to_ureq(u) ((u)->hcpriv)
129 #define usbhsh_urb_to_usbv(u) ((u)->dev)
131 #define usbhsh_usbv_to_udev(d) dev_get_drvdata(&(d)->dev)
133 #define usbhsh_udev_to_usbv(h) ((h)->usbv)
136 #define usbhsh_pipe_to_uep(p) ((p)->mod_private)
138 #define usbhsh_device_parent(d) (usbhsh_usbv_to_udev((d)->usbv->parent))
139 #define usbhsh_device_hubport(d) ((d)->usbv->portnum)
140 #define usbhsh_device_number(h, d) ((int)((d) - (h)->udev))
141 #define usbhsh_device_nth(h, d) ((h)->udev + d)
144 #define usbhsh_port_stat_init(h) ((h)->port_stat = 0)
145 #define usbhsh_port_stat_set(h, s) ((h)->port_stat |= (s))
146 #define usbhsh_port_stat_clear(h, s) ((h)->port_stat &= ~(s))
147 #define usbhsh_port_stat_get(h) ((h)->port_stat)
165 usbhs_pkt_init(&ureq->pkt); in usbhsh_ureq_alloc()
166 ureq->urb = urb; in usbhsh_ureq_alloc()
175 usbhsh_urb_to_ureq(ureq->urb) = NULL; in usbhsh_ureq_free()
176 ureq->urb = NULL; in usbhsh_ureq_free()
193 return (hpriv->mod.irq_attch == NULL); in usbhsh_is_running()
203 int len = urb->actual_length; in usbhsh_endpoint_sequence_save()
204 int maxp = usb_endpoint_maxp(&urb->ep->desc); in usbhsh_endpoint_sequence_save()
208 if (usb_pipecontrol(urb->pipe)) in usbhsh_endpoint_sequence_save()
213 * So, driver should re-use the limited pipe for each device/endpoint. in usbhsh_endpoint_sequence_save()
231 if (pkt->zero) in usbhsh_endpoint_sequence_save()
236 usb_dotoggle(urb->dev, in usbhsh_endpoint_sequence_save()
237 usb_pipeendpoint(urb->pipe), in usbhsh_endpoint_sequence_save()
238 usb_pipeout(urb->pipe)); in usbhsh_endpoint_sequence_save()
248 struct usbhsh_ep *uep = usbhsh_ep_to_uep(urb->ep); in usbhsh_pipe_attach()
251 struct usb_endpoint_descriptor *desc = &urb->ep->desc; in usbhsh_pipe_attach()
254 int dir_in_req = !!usb_pipein(urb->pipe); in usbhsh_pipe_attach()
257 int ret = -EBUSY; in usbhsh_pipe_attach()
280 if (0 != (dir_in - dir_in_req)) in usbhsh_pipe_attach()
289 * attach pipe to uep in usbhsh_pipe_attach()
304 dev_dbg(dev, "%s [%d-%d(%s:%s)]\n", __func__, in usbhsh_pipe_attach()
316 uep->counter++; in usbhsh_pipe_attach()
344 } else if (1 == uep->counter--) { /* last user */ in usbhsh_pipe_detach()
352 dev_dbg(dev, "%s [%d-%d(%s)]\n", __func__, in usbhsh_pipe_detach()
354 usb_endpoint_num(&ep->desc), in usbhsh_pipe_detach()
371 struct usb_host_endpoint *ep = urb->ep; in usbhsh_endpoint_attach()
374 struct usb_endpoint_descriptor *desc = &ep->desc; in usbhsh_endpoint_attach()
379 return -ENOMEM; in usbhsh_endpoint_attach()
387 uep->counter = 0; in usbhsh_endpoint_attach()
388 INIT_LIST_HEAD(&uep->ep_list); in usbhsh_endpoint_attach()
389 list_add_tail(&uep->ep_list, &udev->ep_list_head); in usbhsh_endpoint_attach()
398 dev_dbg(dev, "%s [%d-%d]\n", __func__, in usbhsh_endpoint_attach()
416 dev_dbg(dev, "%s [%d-%d]\n", __func__, in usbhsh_endpoint_detach()
418 usb_endpoint_num(&ep->desc)); in usbhsh_endpoint_detach()
427 list_del_init(&uep->ep_list); in usbhsh_endpoint_detach()
444 list_for_each_entry_safe(uep, next, &udev->ep_list_head, ep_list) in usbhsh_endpoint_detach_all()
456 return hcd->self.root_hub == usbv->parent; in usbhsh_connected_to_rhdev()
461 return !list_empty(&udev->ep_list_head); in usbhsh_device_has_endpoint()
475 if (0 == usb_pipedevice(urb->pipe)) in usbhsh_device_get()
498 * It will attach unused usbhsh_device to urb (usbv), in usbhsh_device_attach()
503 if (0 != usb_pipedevice(urb->pipe)) { in usbhsh_device_attach()
527 dev_set_drvdata(&usbv->dev, udev); in usbhsh_device_attach()
528 udev->usbv = usbv; in usbhsh_device_attach()
550 INIT_LIST_HEAD(&udev0->ep_list_head); in usbhsh_device_attach()
551 INIT_LIST_HEAD(&udev->ep_list_head); in usbhsh_device_attach()
557 0, 0, 0, usbv->speed); in usbhsh_device_attach()
577 upphub, hubport, usbv->speed); in usbhsh_device_attach()
619 dev_set_drvdata(&usbv->dev, NULL); in usbhsh_device_detach()
620 udev->usbv = NULL; in usbhsh_device_detach()
634 struct urb *urb = ureq->urb; in usbhsh_queue_done()
646 status = -ESHUTDOWN; in usbhsh_queue_done()
648 urb->actual_length = pkt->actual; in usbhsh_queue_done()
653 usbhsh_pipe_detach(hpriv, usbhsh_ep_to_uep(urb->ep)); in usbhsh_queue_done()
664 struct usbhsh_ep *uep = usbhsh_ep_to_uep(urb->ep); in usbhsh_queue_push()
671 if (usb_pipeisoc(urb->pipe)) { in usbhsh_queue_push()
673 return -EIO; in usbhsh_queue_push()
680 return -ENOMEM; in usbhsh_queue_push()
683 if (usb_pipein(urb->pipe)) in usbhsh_queue_push()
684 pipe->handler = &usbhs_fifo_dma_pop_handler; in usbhsh_queue_push()
686 pipe->handler = &usbhs_fifo_dma_push_handler; in usbhsh_queue_push()
688 buf = (void *)(urb->transfer_buffer + urb->actual_length); in usbhsh_queue_push()
689 len = urb->transfer_buffer_length - urb->actual_length; in usbhsh_queue_push()
691 sequence = usb_gettoggle(urb->dev, in usbhsh_queue_push()
692 usb_pipeendpoint(urb->pipe), in usbhsh_queue_push()
693 usb_pipeout(urb->pipe)); in usbhsh_queue_push()
696 usbhs_pkt_push(pipe, &ureq->pkt, usbhsh_queue_done, in usbhsh_queue_push()
697 buf, len, (urb->transfer_flags & URB_ZERO_PACKET), in usbhsh_queue_push()
740 req = (struct usb_ctrlrequest *)urb->setup_packet; in usbhsh_is_request_address()
742 if ((DeviceOutRequest == req->bRequestType << 8) && in usbhsh_is_request_address()
743 (USB_REQ_SET_ADDRESS == req->bRequest)) in usbhsh_is_request_address()
763 init_completion(&hpriv->setup_ack_done); in usbhsh_setup_stage_packet_push()
766 memcpy(&req, urb->setup_packet, sizeof(struct usb_ctrlrequest)); in usbhsh_setup_stage_packet_push()
769 * renesas_usbhs can not use original usb address. in usbhsh_setup_stage_packet_push()
771 * modify usb address here to use attached device. in usbhsh_setup_stage_packet_push()
780 dev_dbg(dev, "create new address - %d\n", req.wValue); in usbhsh_setup_stage_packet_push()
789 wait_for_completion(&hpriv->setup_ack_done); in usbhsh_setup_stage_packet_push()
819 return -ENOMEM; in usbhsh_data_stage_packet_push()
821 if (usb_pipein(urb->pipe)) in usbhsh_data_stage_packet_push()
822 pipe->handler = &usbhs_dcp_data_stage_in_handler; in usbhsh_data_stage_packet_push()
824 pipe->handler = &usbhs_dcp_data_stage_out_handler; in usbhsh_data_stage_packet_push()
826 usbhs_pkt_push(pipe, &ureq->pkt, in usbhsh_data_stage_packet_push()
828 urb->transfer_buffer, in usbhsh_data_stage_packet_push()
829 urb->transfer_buffer_length, in usbhsh_data_stage_packet_push()
830 (urb->transfer_flags & URB_ZERO_PACKET), in usbhsh_data_stage_packet_push()
831 -1); in usbhsh_data_stage_packet_push()
849 return -ENOMEM; in usbhsh_status_stage_packet_push()
851 if (usb_pipein(urb->pipe)) in usbhsh_status_stage_packet_push()
852 pipe->handler = &usbhs_dcp_status_stage_in_handler; in usbhsh_status_stage_packet_push()
854 pipe->handler = &usbhs_dcp_status_stage_out_handler; in usbhsh_status_stage_packet_push()
856 usbhs_pkt_push(pipe, &ureq->pkt, in usbhsh_status_stage_packet_push()
859 urb->transfer_buffer_length, in usbhsh_status_stage_packet_push()
860 0, -1); in usbhsh_status_stage_packet_push()
870 struct usbhsh_ep *uep = usbhsh_ep_to_uep(urb->ep); in usbhsh_dcp_queue_push()
889 if (urb->transfer_buffer_length) { in usbhsh_dcp_queue_push()
922 struct urb *urb = ureq->urb; in usbhsh_dma_map_ctrl()
925 if (urb->num_sgs) in usbhsh_dma_map_ctrl()
926 return -EINVAL; in usbhsh_dma_map_ctrl()
928 pkt->dma = urb->transfer_dma; in usbhsh_dma_map_ctrl()
929 if (!pkt->dma) in usbhsh_dma_map_ctrl()
930 return -EINVAL; in usbhsh_dma_map_ctrl()
955 struct usb_host_endpoint *ep = urb->ep; in usbhsh_urb_enqueue()
957 int is_dir_in = usb_pipein(urb->pipe); in usbhsh_urb_enqueue()
963 ret = -EIO; in usbhsh_urb_enqueue()
975 * attach udev if needed in usbhsh_urb_enqueue()
981 ret = -EIO; in usbhsh_urb_enqueue()
982 dev_err(dev, "device attach failed\n"); in usbhsh_urb_enqueue()
988 * attach endpoint if needed in usbhsh_urb_enqueue()
994 dev_err(dev, "endpoint attach failed\n"); in usbhsh_urb_enqueue()
1000 * attach pipe to endpoint in usbhsh_urb_enqueue()
1005 dev_err(dev, "pipe attach failed\n"); in usbhsh_urb_enqueue()
1012 if (usb_pipecontrol(urb->pipe)) in usbhsh_urb_enqueue()
1038 struct usbhs_pkt *pkt = &ureq->pkt; in usbhsh_urb_dequeue()
1040 usbhs_pkt_pop(pkt->pipe, pkt); in usbhsh_urb_dequeue()
1056 * in-endpoint == out-endpoint if ep == dcp. in usbhsh_endpoint_disable()
1105 return -EPIPE; in __usbhsh_hub_hub_feature()
1120 return -EPIPE; in __usbhsh_hub_port_feature()
1168 return -EPIPE; in __usbhsh_hub_port_feature()
1181 return -EPIPE; in __usbhsh_hub_port_feature()
1211 return -EPIPE; in __usbhsh_hub_get_status()
1218 desc->bDescriptorType = USB_DT_HUB; in __usbhsh_hub_get_status()
1219 desc->bHubContrCurrent = 0; in __usbhsh_hub_get_status()
1220 desc->bNbrPorts = roothub_id; in __usbhsh_hub_get_status()
1221 desc->bDescLength = 9; in __usbhsh_hub_get_status()
1222 desc->bPwrOn2PwrGood = 0; in __usbhsh_hub_get_status()
1223 desc->wHubCharacteristics = in __usbhsh_hub_get_status()
1225 desc->u.hs.DeviceRemovable[0] = (roothub_id << 1); in __usbhsh_hub_get_status()
1226 desc->u.hs.DeviceRemovable[1] = ~0; in __usbhsh_hub_get_status()
1240 int ret = -EPIPE; in usbhsh_hub_control()
1323 * (on self power USB hub ?) in usbhsh_irq_attch()
1332 hpriv->mod.irq_attch = NULL; in usbhsh_irq_attch()
1333 usbhs_irq_callback_update(priv, &hpriv->mod); in usbhsh_irq_attch()
1358 hpriv->mod.irq_attch = usbhsh_irq_attch; in usbhsh_irq_dtch()
1359 usbhs_irq_callback_update(priv, &hpriv->mod); in usbhsh_irq_dtch()
1378 complete(&hpriv->setup_ack_done); /* see usbhsh_urb_enqueue() */ in usbhsh_irq_setup_ack()
1391 complete(&hpriv->setup_ack_done); /* see usbhsh_urb_enqueue() */ in usbhsh_irq_setup_err()
1425 * USB_ENDPOINT_XFER_ISOC -> dir out in usbhsh_pipe_init_for_host()
1426 * USB_ENDPOINT_XFER_ISOC -> dir in in usbhsh_pipe_init_for_host()
1427 * USB_ENDPOINT_XFER_BULK -> dir out in usbhsh_pipe_init_for_host()
1428 * USB_ENDPOINT_XFER_BULK -> dir in in usbhsh_pipe_init_for_host()
1429 * USB_ENDPOINT_XFER_BULK -> dir in in usbhsh_pipe_init_for_host()
1444 pipe->mod_private = NULL; in usbhsh_pipe_init_for_host()
1460 device_wakeup_enable(hcd->self.controller); in usbhsh_start()
1472 * - HI speed in usbhsh_start()
1473 * - host in usbhsh_start()
1474 * - usb module in usbhsh_start()
1481 mod->irq_attch = usbhsh_irq_attch; in usbhsh_start()
1482 mod->irq_dtch = usbhsh_irq_dtch; in usbhsh_start()
1483 mod->irq_sack = usbhsh_irq_setup_ack; in usbhsh_start()
1484 mod->irq_sign = usbhsh_irq_setup_err; in usbhsh_start()
1502 mod->irq_attch = NULL; in usbhsh_stop()
1503 mod->irq_dtch = NULL; in usbhsh_stop()
1504 mod->irq_sack = NULL; in usbhsh_stop()
1505 mod->irq_sign = NULL; in usbhsh_stop()
1530 return -ENOMEM; in usbhs_mod_host_probe()
1532 hcd->has_tt = 1; /* for low/full speed */ in usbhs_mod_host_probe()
1537 * There is no guarantee that it is possible to access usb module here. in usbhs_mod_host_probe()
1547 usbhs_mod_register(priv, &hpriv->mod, USBHS_HOST); in usbhs_mod_host_probe()
1550 hpriv->mod.name = "host"; in usbhs_mod_host_probe()
1551 hpriv->mod.start = usbhsh_start; in usbhs_mod_host_probe()
1552 hpriv->mod.stop = usbhsh_stop; in usbhs_mod_host_probe()
1557 udev->usbv = NULL; in usbhs_mod_host_probe()
1558 INIT_LIST_HEAD(&udev->ep_list_head); in usbhs_mod_host_probe()