Introduction to USB hardware driver in Linux (1)

Source: Internet
Author: User

USB stands for "Universal Serial Bus", meaning "Universal Serial Bus ".It was proposed jointly by Compaq (Compaq), DEC, IBM, Intel, NEC, Microsoft, and Northern Telecom in November 1994, the main purpose is to solve the drawbacks of too many interface standards. USB uses a 4-pin connector as the standard connector to connect all peripherals in the form of chrysanthemum petals. It transmits data in serial mode. Currently, the maximum data transmission rate is 12 Mbps, supports concurrent operations on multiple data streams and multiple devices, and supports hot swapping of peripherals.

Although USB interfaces only develop 2 generations of USB 1.1/, USB), USB integrates all the advantages of a multi-platform standard, including cost reduction and compatibility increase, A large number of external devices can be connected, combining advanced features and quality. It gradually became a PC interface standard and entered a period of rapid development.

Correctly supporting and configuring common USB devices for Linux is an essential step.

◆ Related technical basics

Module driver)

Module) is a program running in the kernel space. It is actually a target object file without links and cannot run independently. However, it can be loaded into the system and run as part of the kernel, in this way, the kernel functions can be dynamically expanded. The main use of the module is to implement the device driver.

In Linux, a hardware driver can be directly loaded into the kernel code. When the kernel is started, the hardware device can be driven. The other is to compile a. o file in the module mode. When the application needs to be added to the kernel space for running. Therefore, a hardware driver usually refers to a driver module.

Device Files

For a device, it can have a corresponding logical device node under/dev. This node exists as a file, but it is not a file in the general sense. It is a device file, more specifically, it is a device node. This node is created using the mknod command, which specifies the master device number and secondary device number. The primary device number indicates a certain type of device, which generally corresponds to a specific driver. The secondary device number generally distinguishes different attributes, such as different usage methods, locations, and operations. This device number is obtained from the/proc/devices file. Therefore, the device node is in the directory only when the driver is in the kernel. The main function of this device number is to declare the driver used by the device. Drivers correspond to device numbers one by one. When you open a device file, the operating system knows the driver corresponding to the device.

SCSI Device

SCSI is a standard computer interface different from IDE. Nowadays, most flat-board scanners, CD-R recorders, MO optical transceiver and so on gradually tend to use the SCSI interface, coupled with SCSI and can provide a high-speed transmission channel, so, access to SCSI devices more and more users. Linux supports many SCSI devices, such as SCSI hard drives, SCSI optical drives, and SCSI tape drives. More importantly, Linux provides an IDE device to simulate the ide-scsi.o module for SCSI), we usually simulate the IDE drive to the SCSI drive for access. In Linux, many software can only operate the SCSI Optical Drive. For example, most of the recording software and some media playing software. Generally, our USB storage device simulates access to the SCSI hard disk.

Linux hardware driver architecture

For a hardware, the Linux driver is like this: first, we must provide a. o driver module File. Here we only describe the module mode, in fact, the kernel mode is similar ). To use this driver, first load and run it insmod *. o ). In this way, the driver registers with the system based on its own type of character device type or block device type, for example, the mouse is a character device and the hard disk is a block device. After successful registration, the system will report a master device number, the primary device number is the unique identifier of the system. For example, the primary device Number shown in/proc/devices for a hard disk block device is 3, the main device we see with ls-l/dev/had must be 3 ). The driver creates a device file named mknod in the/dev directory based on the master device number. The mknod command must be set to the master device number ). To access this hardware, you can run open, read, write, and other commands on the device file. The driver will receive the corresponding read and write operations and proceed according to the corresponding functions in its module.

There are also a few more related things: one is the/lib/modules/2.4.XX Directory, which is the module for the current kernel version. As long as your module dependency is correct, you can set it through depmod), you can load the file by using the modprobe command without knowing the location of the specific module File. The other is the/etc/modules. conf file, which defines aliases of some common devices. The system can find the driver module correctly when this device is needed. For example, alias eth0 e100 indicates that the driver module of the first Nic is e100.o. Their relationship diagram is as follows:

498) this. style. width = 498; ">

◆ Configure a USB device

Kernel configuration.

To enable Linux USB support, first go to the "USB Support" section and enable the "support for USB" option. The corresponding module is USB core. o ). Although this step is quite straightforward, the subsequent Linux USB settings will be confusing. In particular, you now need to select the correct USB master controller driver for the system. The option is "EHCI" corresponds to a ehci-hcd.o), "UHCI" corresponds to a usb-uhci.o), "UHCI (alternate driver)", and "OHCI" corresponds to a usb-ohci.o ). This is where many people are confused about Linux USB.

To understand "EHCI" and what it is like, you must first know that each motherboard or PCI Card that supports inserting a USB device requires a USB master controller chipset. This special chipset operates with the USB device that is inserted into the system and handles all low-level details necessary to allow the USB device to communicate with other parts of the system.

Linux USB drivers have three different USB master controller options because there are three different types of USB chips on the motherboard and PCI Card. The "EHCI" driver is designed to support new high-speed USB 2.0 chips. The "OHCI" driver is used to support non-PC systems and PC boards with SiS and ALi chipset) USB chips. The "UHCI" driver is used to support USB implementations on most other PC boards, including Intel and. You only need to select the type corresponding to the USB support you want to enable "? HCI driver. If you have any questions, you can enable either of "EHCI" or "UHCI" for the sake of insurance. There is no obvious difference between them) and "OHCI ". Zhao Ming Note: According to the document, EHCI already includes UHCI and OHCI, but currently I personally test it, it is impossible to add EHCI separately, generally, I load UHCI or OHCI Based on the motherboard type, and then load EHCI to support the USB2.0 device ).

Enable "USB support" and appropriate "? After HCI "USB master controller driver, you only need to perform a few steps to enable and run USB. You should enable "Preliminary USB device filesystem" and ensure that all drivers specific to the actual USB Peripheral that will be used with Linux are enabled. For example, to enable support for USB game controllers, I enabled "USB Human Interface Device (full HID) support ". I also enabled "Input core support" and "Joystick support" under the main "Input core support" section ".

If no USB device information is available under/proc/bus/usb, enter the following command to manually mount the USB device file system to/proc/bus/usb:

# mount -t usbdevfs none /proc/bus/usb 

To automatically mount the USB file system during system boot, add the following line to the/proc mounting line in/etc/fstab:

none /proc/bus/usb usbdevfs defaults 0 0 

Module configuration method.

In many cases, our USB driver is not included in the kernel. In fact, we only need to load them one by one based on the modules it needs. You can enable it.

First, make sure that the corresponding support is selected in the module mode during kernel compilation. In this way, we can see the corresponding. o file in the/lib/modules/2.4.XX directory. When Loading modules, we only need to run modprobe xxx. o to load the modules that have been registered by the depmod system. insmod is generally used to load specific. o files)

It is critical to correspond to some modules under the USB device.

Usbcore. o Basic modules required to support usb
Usb-uhci.o Already mentioned)
Usb-ohci.o Already mentioned)
Uhci. o I don't know how to use another uhci driver. Generally, I don't want to load it. It will crash.
Ehci-hcd.o I have already mentioned usb2.0)
Hid. o USB man-machine interface device, like mouse and keyboard
Usb-storage.o USB storage devices and USB flash drives

Related modules

Ide-disk.o IDE Hard Drive
Ide-scsi.o Simulate the SCSI interface of the IDE Device
Scsi_mod.o SCSI support

Note one of the following:

 Probe all LUNs on each SCSI device

It is recommended that you choose not to display only one card reader that supports multiple ports at the same time. If the module mode is used, install it with parameters or add the following items to/etc/modules. conf in advance to support multiple Luns.

 add options scsi_mod max_scsi_luns=9  

Sd_mod.o SCSI hard disk
Sr_mod.o SCSI Disc
Sg. o SCSI general support will be used in some USB flash drives and SCSI probes)



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.