• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
USB Drivers

USB Drivers






Total Views
Views on SlideShare
Embed Views



11 Embeds 8,118

http://www.sysplay.in 3316
http://sysplay.in 2495
http://profession.sarika-pugs.com 2273
http://translate.googleusercontent.com 9
http://localhost 9
http://dspembeddedvlsi.blogspot.com 5
http://www.linkedin.com 4
url_unknown 3
http://www.slideshare.net 2
http://dspembeddedvlsi.blogspot.in 1
https://www.linkedin.com 1



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    USB Drivers USB Drivers Presentation Transcript

    • USB Drivers© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved.
    • What to Expect?USB EvolutionUSB SubsystemUnderstanding of USB ProtocolWriting a USB Driver Registration Hot Plug-ability Transfers © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 2 All Rights Reserved.
    • USB PrologueWhat was USB designed for? A Unified Bus for Slow DevicesSo, design based on Master-Slave concept USB (Host) Controller is the “Single Master” UHC polls the Slave Peripherals / DevicesLater Additions High Speed Specifications Bandwidth Allocation AbilityBut even today, the polling continues © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 3 All Rights Reserved.
    • USB Device Driver Types2 Types: Both written for the DeviceUSB Host Driver Runs on Host (Master) Drives the USB Device (Slave)USB Gadget Driver Runs on the USB Gadget / Device (Slave) Responds to a Host (Master) Pre-requisite: Gadget is Linux based © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 4 All Rights Reserved.
    • USB Subsystem View User Applications User Mode User Space Drivers FS Block Net Char TTY ...Layer Layer Layer Layer Layer usbfs USB Device Drivers Kernel Space USB Core USB Host Controller Drivers USB Host Controller Hardware Space USB Device © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 5 All Rights Reserved.
    • USB SubsystemUHC Driver (uhci, ohci, ehci, otg) Hardware-specific USB Host Controller driver Hides all the hardware details from the layers above Provides a uniform interface to USB CoreUSB Core Module (usbcore) Provides the generic USB Protocol APIs for the kernel, in general By interfacing with the underlying UHC driverUSB File System Module (usbfs) Uses USB Core to provide Kernel Windows & USB Devices as entries under /sys Enables writing User Mode USB DriversUSB Device Driver USB Device specific Driver Interfaces with the USB Device through the USB Core Provides interface to the User Space through the relevant Verticals © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 6 All Rights Reserved.
    • USB & sysfsCommand: /sbin/lspci <dom>:<bus>:<dev>:<fn> for <usbhubid>Kernel Window /sys/devices/pci0000:00/<usbhubid>/usb<hub> usb_device fields roothub-hubport:config.interface usb_interface fields © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 7 All Rights Reserved.
    • USB Device OverviewDevice Config Interface USB Endpoint Driver Endpoint ... Interface USB Endpoint Driver ... ... © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 8 All Rights Reserved.
    • USB EndpointsAlso called PipesDirection OUT (host->device) IN (device->host)Four Types Control Interrupt Bulk Isochronous © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 9 All Rights Reserved.
    • USB Device Data StructuresHeader: <linux/usb.h>Data Structures struct usb_host_endpoint struct usb_endpoint_descriptor struct usb_interface struct usb_host_config struct usb_device interface_to_usbdev © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 10 All Rights Reserved.
    • USB Core FunctionalityUSB Driver Registration / UnregistrationUSB Device Hot Plugability probe: USB Device Registration disconnect: USB Device UnregistrationUSB Transfers through URBs © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 11 All Rights Reserved.
    • USB Driver RegistrationHeader: <linux/usb.h>Data Structure: struct usb_driver struct module *owner const char *name const struct usb_device_id *id_table int (*probe)(struct usb_interface *, struct usb_device_id * ); int (*disconnect)(struct usb_interface *);APIs int usb_register(struct usb_driver *); int usb_deregister(struct usb_driver *); © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 12 All Rights Reserved.
    • USB Request BlockHeader: <linux/usb.h>Data Structure: struct urb struct usb_device *dev unsigned int pipe unsigned int transfer_flags void *transfer_buffer int transfer_buffer_length usb_complete_t complete int actual_length int status Pipe type specific fields © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 13 All Rights Reserved.
    • URB OperationsHeader: <linux/usb.h>URB Storage usb_alloc_urb(int iso_pkts, gfp_t flags); usb_free_urb(struct urb *);Populating the URB usb_fill_control_urb(urb, dev, pipe, req, buf, len, fn, ctxt); usb_fill_int_urb(urb, dev, pipe, buf, len, fn, ctxt, interval); usb_fill_bulk_urb(urb, dev, pipe, buf, len, fn, ctxt);Using the URB usb_submit_urb(struct urb *, gfp_t flags); usb_unlink_urb(struct urb *) / usb_kill_urb(struct urb *); © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 14 All Rights Reserved.
    • USB Transfer WrappersHeader: <linux/usb.h>APIs usb_control_msg(dev, pipe, req, req_type, value, index, data, size, timeout); usb_interrupt_msg(dev, pipe, data, len, &act_len, timeout); usb_bulk_msg(dev, pipe, data, len, &act_len, timeout); © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 15 All Rights Reserved.
    • USB Device Hot-plug-abilityCallback probe int usb_register_dev(intf, class);Callback disconnect int usb_deregister_dev(intf, class);Other Useful APIs (Header: <linux/usb.h> void usb_set_intfdata(intf, void *data); void *usb_get_intfdata(intf); © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 16 All Rights Reserved.
    • What all have we learnt?Evolution of USBUSB Subsystem The Four ComponentsUnderstanding of USB Protocol What does a valid USB device do?Writing a USB Driver Registration Hot Plug-ability Transfers © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 17 All Rights Reserved.
    • Any Queries?© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 18 All Rights Reserved.