static int redrat3_dev_probe(struct usb_interface *intf, const struct usb_device_id *id) { struct usb_device *udev = interface_to_usbdev(intf); struct device *dev = &intf->dev; struct usb_host_interface *uhi; struct redrat3_dev *rr3; struct usb_endpoint_descriptor *ep; struct usb_endpoint_descriptor *ep_in = NULL; struct usb_endpoint_descriptor *ep_out = NULL; u8 addr, attrs; int pipe, i; int retval = -ENOMEM; rr3_ftr(dev, "%s called\n", __func__); uhi = intf->cur_altsetting; /* find our bulk-in and bulk-out endpoints */ for (i = 0; i < uhi->desc.bNumEndpoints; ++i) { ep = &uhi->endpoint[i].desc; addr = ep->bEndpointAddress; attrs = ep->bmAttributes; if ((ep_in == NULL) && ((addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) && ((attrs & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK)) { rr3_dbg(dev, "found bulk-in endpoint at 0x%02x\n", ep->bEndpointAddress); /* data comes in on 0x82, 0x81 is for other data... */ if (ep->bEndpointAddress == RR3_BULK_IN_EP_ADDR) ep_in = ep; } if ((ep_out == NULL) && ((addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) && ((attrs & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK)) { rr3_dbg(dev, "found bulk-out endpoint at 0x%02x\n", ep->bEndpointAddress); ep_out = ep; } } if (!ep_in || !ep_out) { dev_err(dev, "Couldn't find both in and out endpoints\n"); retval = -ENODEV; goto no_endpoints; } /* allocate memory for our device state and initialize it */ rr3 = kzalloc(sizeof(*rr3), GFP_KERNEL); if (rr3 == NULL) { dev_err(dev, "Memory allocation failure\n"); goto no_endpoints; } rr3->dev = &intf->dev; /* set up bulk-in endpoint */ rr3->read_urb = usb_alloc_urb(0, GFP_KERNEL); if (!rr3->read_urb) { dev_err(dev, "Read urb allocation failure\n"); goto error; } rr3->ep_in = ep_in; rr3->bulk_in_buf = usb_alloc_coherent(udev, le16_to_cpu(ep_in->wMaxPacketSize), GFP_ATOMIC, &rr3->dma_in); if (!rr3->bulk_in_buf) { dev_err(dev, "Read buffer allocation failure\n"); goto error; } pipe = usb_rcvbulkpipe(udev, ep_in->bEndpointAddress); usb_fill_bulk_urb(rr3->read_urb, udev, pipe, rr3->bulk_in_buf, le16_to_cpu(ep_in->wMaxPacketSize), redrat3_handle_async, rr3); rr3->ep_out = ep_out; rr3->udev = udev; redrat3_reset(rr3); redrat3_get_firmware_rev(rr3); /* might be all we need to do? */ retval = redrat3_enable_detector(rr3); if (retval < 0) goto error; /* store current hardware timeout, in us, will use for kfifo resets */ rr3->hw_timeout = redrat3_get_timeout(rr3); /* default.. will get overridden by any sends with a freq defined */ rr3->carrier = 38000; /* led control */ rr3->led.name = "redrat3:red:feedback"; rr3->led.default_trigger = "rc-feedback"; rr3->led.brightness_set = redrat3_brightness_set; retval = led_classdev_register(&intf->dev, &rr3->led); if (retval) goto error; atomic_set(&rr3->flash, 0); rr3->flash_urb = usb_alloc_urb(0, GFP_KERNEL); if (!rr3->flash_urb) { retval = -ENOMEM; goto led_free_error; } /* setup packet is 'c0 b9 0000 0000 0001' */ rr3->flash_control.bRequestType = 0xc0; rr3->flash_control.bRequest = RR3_BLINK_LED; rr3->flash_control.wLength = cpu_to_le16(1); usb_fill_control_urb(rr3->flash_urb, udev, usb_rcvctrlpipe(udev, 0), (unsigned char *)&rr3->flash_control, &rr3->flash_in_buf, sizeof(rr3->flash_in_buf), redrat3_led_complete, rr3); rr3->rc = redrat3_init_rc_dev(rr3); if (!rr3->rc) { retval = -ENOMEM; goto led_free_error; } setup_timer(&rr3->rx_timeout, redrat3_rx_timeout, (unsigned long)rr3); /* we can register the device now, as it is ready */ usb_set_intfdata(intf, rr3); rr3_ftr(dev, "Exiting %s\n", __func__); return 0; led_free_error: led_classdev_unregister(&rr3->led); error: redrat3_delete(rr3, rr3->udev); no_endpoints: dev_err(dev, "%s: retval = %x", __func__, retval); return retval; }
static int __devinit redrat3_dev_probe(struct usb_interface *intf, const struct usb_device_id *id) { struct usb_device *udev = interface_to_usbdev(intf); struct device *dev = &intf->dev; struct usb_host_interface *uhi; struct redrat3_dev *rr3; struct usb_endpoint_descriptor *ep; struct usb_endpoint_descriptor *ep_in = NULL; struct usb_endpoint_descriptor *ep_out = NULL; u8 addr, attrs; int pipe, i; int retval = -ENOMEM; rr3_ftr(dev, "%s called\n", __func__); uhi = intf->cur_altsetting; /* */ for (i = 0; i < uhi->desc.bNumEndpoints; ++i) { ep = &uhi->endpoint[i].desc; addr = ep->bEndpointAddress; attrs = ep->bmAttributes; if ((ep_in == NULL) && ((addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) && ((attrs & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK)) { rr3_dbg(dev, "found bulk-in endpoint at 0x%02x\n", ep->bEndpointAddress); /* */ if (ep->bEndpointAddress == RR3_BULK_IN_EP_ADDR) ep_in = ep; } if ((ep_out == NULL) && ((addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) && ((attrs & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK)) { rr3_dbg(dev, "found bulk-out endpoint at 0x%02x\n", ep->bEndpointAddress); ep_out = ep; } } if (!ep_in || !ep_out) { dev_err(dev, "Couldn't find both in and out endpoints\n"); retval = -ENODEV; goto no_endpoints; } /* */ rr3 = kzalloc(sizeof(*rr3), GFP_KERNEL); if (rr3 == NULL) { dev_err(dev, "Memory allocation failure\n"); goto no_endpoints; } rr3->dev = &intf->dev; /* */ rr3->read_urb = usb_alloc_urb(0, GFP_KERNEL); if (!rr3->read_urb) { dev_err(dev, "Read urb allocation failure\n"); goto error; } rr3->ep_in = ep_in; rr3->bulk_in_buf = usb_alloc_coherent(udev, ep_in->wMaxPacketSize, GFP_ATOMIC, &rr3->dma_in); if (!rr3->bulk_in_buf) { dev_err(dev, "Read buffer allocation failure\n"); goto error; } pipe = usb_rcvbulkpipe(udev, ep_in->bEndpointAddress); usb_fill_bulk_urb(rr3->read_urb, udev, pipe, rr3->bulk_in_buf, ep_in->wMaxPacketSize, (usb_complete_t)redrat3_handle_async, rr3); /* */ rr3->write_urb = usb_alloc_urb(0, GFP_KERNEL); if (!rr3->write_urb) { dev_err(dev, "Write urb allocation failure\n"); goto error; } rr3->ep_out = ep_out; rr3->bulk_out_buf = usb_alloc_coherent(udev, ep_out->wMaxPacketSize, GFP_ATOMIC, &rr3->dma_out); if (!rr3->bulk_out_buf) { dev_err(dev, "Write buffer allocation failure\n"); goto error; } pipe = usb_sndbulkpipe(udev, ep_out->bEndpointAddress); usb_fill_bulk_urb(rr3->write_urb, udev, pipe, rr3->bulk_out_buf, ep_out->wMaxPacketSize, (usb_complete_t)redrat3_write_bulk_callback, rr3); mutex_init(&rr3->lock); rr3->udev = udev; redrat3_reset(rr3); redrat3_get_firmware_rev(rr3); /* */ retval = redrat3_enable_detector(rr3); if (retval < 0) goto error; /* */ rr3->hw_timeout = redrat3_get_timeout(rr3); /* */ rr3->carrier = 38000; rr3->rc = redrat3_init_rc_dev(rr3); if (!rr3->rc) goto error; setup_timer(&rr3->rx_timeout, redrat3_rx_timeout, (unsigned long)rr3); /* */ usb_set_intfdata(intf, rr3); rr3_ftr(dev, "Exiting %s\n", __func__); return 0; error: redrat3_delete(rr3, rr3->udev); no_endpoints: dev_err(dev, "%s: retval = %x", __func__, retval); return retval; }
static int redrat3_dev_probe(struct usb_interface *intf, const struct usb_device_id *id) { struct usb_device *udev = interface_to_usbdev(intf); struct device *dev = &intf->dev; struct usb_host_interface *uhi; struct redrat3_dev *rr3; struct usb_endpoint_descriptor *ep; struct usb_endpoint_descriptor *ep_narrow = NULL; struct usb_endpoint_descriptor *ep_wide = NULL; struct usb_endpoint_descriptor *ep_out = NULL; u8 addr, attrs; int pipe, i; int retval = -ENOMEM; uhi = intf->cur_altsetting; /* find our bulk-in and bulk-out endpoints */ for (i = 0; i < uhi->desc.bNumEndpoints; ++i) { ep = &uhi->endpoint[i].desc; addr = ep->bEndpointAddress; attrs = ep->bmAttributes; if (((addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) && ((attrs & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK)) { dev_dbg(dev, "found bulk-in endpoint at 0x%02x\n", ep->bEndpointAddress); /* data comes in on 0x82, 0x81 is for learning */ if (ep->bEndpointAddress == RR3_NARROW_IN_EP_ADDR) ep_narrow = ep; if (ep->bEndpointAddress == RR3_WIDE_IN_EP_ADDR) ep_wide = ep; } if ((ep_out == NULL) && ((addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) && ((attrs & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK)) { dev_dbg(dev, "found bulk-out endpoint at 0x%02x\n", ep->bEndpointAddress); ep_out = ep; } } if (!ep_narrow || !ep_out || !ep_wide) { dev_err(dev, "Couldn't find all endpoints\n"); retval = -ENODEV; goto no_endpoints; } /* allocate memory for our device state and initialize it */ rr3 = kzalloc(sizeof(*rr3), GFP_KERNEL); if (!rr3) goto no_endpoints; rr3->dev = &intf->dev; rr3->ep_narrow = ep_narrow; rr3->ep_out = ep_out; rr3->udev = udev; /* set up bulk-in endpoint */ rr3->narrow_urb = usb_alloc_urb(0, GFP_KERNEL); if (!rr3->narrow_urb) goto redrat_free; rr3->wide_urb = usb_alloc_urb(0, GFP_KERNEL); if (!rr3->wide_urb) goto redrat_free; rr3->bulk_in_buf = usb_alloc_coherent(udev, le16_to_cpu(ep_narrow->wMaxPacketSize), GFP_KERNEL, &rr3->dma_in); if (!rr3->bulk_in_buf) goto redrat_free; pipe = usb_rcvbulkpipe(udev, ep_narrow->bEndpointAddress); usb_fill_bulk_urb(rr3->narrow_urb, udev, pipe, rr3->bulk_in_buf, le16_to_cpu(ep_narrow->wMaxPacketSize), redrat3_handle_async, rr3); rr3->narrow_urb->transfer_dma = rr3->dma_in; rr3->narrow_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; pipe = usb_rcvbulkpipe(udev, ep_wide->bEndpointAddress); usb_fill_bulk_urb(rr3->wide_urb, udev, pipe, rr3->bulk_in_buf, le16_to_cpu(ep_narrow->wMaxPacketSize), redrat3_handle_async, rr3); rr3->wide_urb->transfer_dma = rr3->dma_in; rr3->wide_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; redrat3_reset(rr3); redrat3_get_firmware_rev(rr3); /* default.. will get overridden by any sends with a freq defined */ rr3->carrier = 38000; atomic_set(&rr3->flash, 0); rr3->flash_urb = usb_alloc_urb(0, GFP_KERNEL); if (!rr3->flash_urb) goto redrat_free; /* learn urb */ rr3->learn_urb = usb_alloc_urb(0, GFP_KERNEL); if (!rr3->learn_urb) goto redrat_free; /* setup packet is 'c0 b2 0000 0000 0001' */ rr3->learn_control.bRequestType = 0xc0; rr3->learn_control.bRequest = RR3_MODSIG_CAPTURE; rr3->learn_control.wLength = cpu_to_le16(1); usb_fill_control_urb(rr3->learn_urb, udev, usb_rcvctrlpipe(udev, 0), (unsigned char *)&rr3->learn_control, &rr3->learn_buf, sizeof(rr3->learn_buf), redrat3_learn_complete, rr3); /* setup packet is 'c0 b9 0000 0000 0001' */ rr3->flash_control.bRequestType = 0xc0; rr3->flash_control.bRequest = RR3_BLINK_LED; rr3->flash_control.wLength = cpu_to_le16(1); usb_fill_control_urb(rr3->flash_urb, udev, usb_rcvctrlpipe(udev, 0), (unsigned char *)&rr3->flash_control, &rr3->flash_in_buf, sizeof(rr3->flash_in_buf), redrat3_led_complete, rr3); /* led control */ rr3->led.name = "redrat3:red:feedback"; rr3->led.default_trigger = "rc-feedback"; rr3->led.brightness_set = redrat3_brightness_set; retval = led_classdev_register(&intf->dev, &rr3->led); if (retval) goto redrat_free; rr3->rc = redrat3_init_rc_dev(rr3); if (!rr3->rc) { retval = -ENOMEM; goto led_free; } /* might be all we need to do? */ retval = redrat3_enable_detector(rr3); if (retval < 0) goto led_free; /* we can register the device now, as it is ready */ usb_set_intfdata(intf, rr3); return 0; led_free: led_classdev_unregister(&rr3->led); redrat_free: redrat3_delete(rr3, rr3->udev); no_endpoints: return retval; }