Your SlideShare is downloading. ×
© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
All Rights Reserved.
USB Drivers
2© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
All Rights Reserved.
What to Expect?
USB Evolution
USB Subsystem
Unders...
3© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
All Rights Reserved.
USB Prologue
What was USB designed for?
A Unified ...
4© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
All Rights Reserved.
USB Device Driver Types
2 Types: Both written for ...
5© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
All Rights Reserved.
USB Subsystem View
FS
Layer
USB Device Drivers
USB...
6© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
All Rights Reserved.
USB Subsystem
UHC Driver (uhci, ohci, ehci, otg)
H...
7© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
All Rights Reserved.
USB & sysfs
Command: /sbin/lspci
<dom>:<bus>:<dev>...
8© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
All Rights Reserved.
USB Device Overview
Device
Config Interface
Endpoi...
9© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
All Rights Reserved.
USB Endpoints
Also called Pipes
Direction
OUT (hos...
10© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
All Rights Reserved.
USB Device Data Structures
Header: <linux/usb.h>
...
11© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
All Rights Reserved.
USB Core Functionality
USB Driver Registration / ...
12© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
All Rights Reserved.
USB Driver Registration
Header: <linux/usb.h>
Dat...
13© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
All Rights Reserved.
USB Request Block
Header: <linux/usb.h>
Data Stru...
14© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
All Rights Reserved.
URB Operations
Header: <linux/usb.h>
URB Storage
...
15© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
All Rights Reserved.
USB Transfer Wrappers
Header: <linux/usb.h>
APIs
...
16© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
All Rights Reserved.
USB Device Hot-plug-ability
Callback probe
int us...
17© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
All Rights Reserved.
What all have we learnt?
Evolution of USB
USB Sub...
18© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
All Rights Reserved.
Any Queries?
Upcoming SlideShare
Loading in...5
×

USB Drivers

15,246

Published on

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
15,246
On Slideshare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
0
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Transcript of "USB Drivers"

  1. 1. © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved. USB Drivers
  2. 2. 2© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved. What to Expect? USB Evolution USB Subsystem Understanding of USB Protocol Writing a USB Driver Registration Hot Plug-ability Transfers
  3. 3. 3© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved. USB Prologue What was USB designed for? A Unified Bus for Slow Devices So, design based on Master-Slave concept USB (Host) Controller is the “Single Master” UHC polls the Slave Peripherals / Devices Later Additions High Speed Specifications Bandwidth Allocation Ability But even today, the polling continues
  4. 4. 4© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved. USB Device Driver Types 2 Types: Both written for the Device USB 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
  5. 5. 5© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved. USB Subsystem View FS Layer USB Device Drivers USB Core USB Host Controller Drivers ... TTY Layer Char Layer Net Layer Block Layer Kernel Space User Applications USB Host Controller USB Device Hardware Space User Space usbfs User Mode Drivers
  6. 6. 6© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved. USB Subsystem UHC 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 Core USB Core Module (usbcore) Provides the generic USB Protocol APIs for the kernel, in general By interfacing with the underlying UHC driver USB File System Module (usbfs) Uses USB Core to provide Kernel Windows & USB Devices as entries under /sys Enables writing User Mode USB Drivers USB 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
  7. 7. 7© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved. USB & sysfs Command: /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
  8. 8. 8© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved. USB Device Overview Device Config Interface Endpoint ... Endpoint Endpoint ... Interface USB Driver USB Driver ...
  9. 9. 9© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved. USB Endpoints Also called Pipes Direction OUT (host->device) IN (device->host) Four Types Control Interrupt Bulk Isochronous
  10. 10. 10© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved. USB Device Data Structures Header: <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
  11. 11. 11© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved. USB Core Functionality USB Driver Registration / Unregistration USB Device Hot Plugability probe: USB Device Registration disconnect: USB Device Unregistration USB Transfers through URBs
  12. 12. 12© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved. USB Driver Registration Header: <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 *);
  13. 13. 13© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved. USB Request Block Header: <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
  14. 14. 14© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved. URB Operations Header: <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 *);
  15. 15. 15© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved. USB Transfer Wrappers Header: <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);
  16. 16. 16© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved. USB Device Hot-plug-ability Callback 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);
  17. 17. 17© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved. What all have we learnt? Evolution of USB USB Subsystem The Four Components Understanding of USB Protocol What does a valid USB device do? Writing a USB Driver Registration Hot Plug-ability Transfers
  18. 18. 18© 2010 Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved. Any Queries?

×