Driver overview
When it comes to Android drivers, it's Linux-driven. The Android kernel uses the Linux2.6 kernel (some Android code has been recently included in Linux 3.3). But Android does not completely copy the Linux system kernel, in addition to a partial revision of Linux, but also added a lot of content. There are two main types of Android drivers: the Android dedicated driver and the device driver (Linux) used by Android.
Android Proprietary drivers:
1) Android Ashmem Anonymous shared memory, provides a mechanism for user space programs to allocate memory, provides large chunks of shared memory between processes, and provides the kernel with the capacity to reclaim and manage this memory.
2) Android Logger Lightweight log (log) driver;
3) Android Binder based on a driver of the openbinder framework;
4) Power Management module of Android power Management;
5) Low Memory Killer
6) Android Pmem physical memory drive;
7) USB Gadget USB driver (based on gaeget frame);
8) Ram Console for debugging devices that write log information;
9) Time device timing control equipment;
Android Alarm hardware clock;
Device drivers on Android:
1) framebuff display drive;
2) Event input device driver;
3) ALSA audio driver;
4) OSS audio driver;
5) v412 camera: Video driver;
6) MTD Drive;
7) Bluetooth driver;
8) WLAN device driver;
Android Proprietary Drivers
1.Android Ashmem
Provides a mechanism for user-space programs to allocate memory, providing large chunks of shared memory between processes, while providing the kernel with the capacity to reclaim and manage this memory.
Device node:/dev/ashmen. Main device Number 10.
SOURCE Location: Include/linux/ashmen.h kernel/mm/ashmen.c
Compared to the traditional memory allocation mechanism such as malloc and anonymous/named Mmap, the advantage is that the kernel driver provides the auxiliary kernel's memory recovery algorithm mechanism (pin/unoin)
2.Android Logger
Whether it is the underlying source code or the upper layer of the application, we can use logger this log device to see, to debug.
Device node:/dev/log/main/dev/log/event/dev/log/radio
SOURCE Location: Include/linux/logger.h include/linux/logger.c
3.Android Binder
IPC Binder an inter-process communication mechanism. His process can serve other processes-----Call the API through a standard Linux system.
Device node:/dev/binder
SOURCE Location: Kernel/include/linux/binder.h kernel/drivers/misc/binder.c
4.Android Power Management
A lightweight Android power management system based on standard Linux power management, in DRIVERS/ANDROID/POWER.C kernel/power/
5.Low Memory Killer
It specifies a set of memory thresholds in the user space, and when one of the values is in the same range as the Oom_adj value in the process description, the process is killed (the minimum value of OOME_ADJ is specified in Parameters/adj). It is similar to the standard Linux oom mechanism, except that the implementation method is different
SOURCE Location: drivers/misc/lowmemorykiller.c
6.Android Pmem
The main function of PMEM is to provide contiguous physical memory areas to the user space.
1. Let the GPU or VPU buffer share the CPU core.
2. For Android service heap.
SOURCE Location: Include/linux/android_pmem.h drivers/android/pmem.c
7.USB Gadget
Device drivers based on the standard Linux USB gaeget driver Framework.
SOURCE Location: drivers/usb/gadet/
8.Ram Console
To provide debugging functionality, Android allows the debug log information to be written to this device, which is RAM-based buffer.
SOURCE Location: drivers/staging/android/ram_console.c
9.Time Device
Timing control, provides the function of timing control of the equipment.
SOURCE Location: drivers/staging/android/timed_output.c (TIMED_GPIO.C)
10.Android Alarm
A timer is provided to wake the device from sleep, and it provides a clock reference that runs even when the device is asleep.
Device node:/dev/alarm
SOURCE Location: DRIVERS/TRC/ALARM.C
Android Device Driver
1. Framebuffer Frame Cache Device
The Framebuffer driver is the driver of the standard display device in Linux. For PC system, it is the driver of graphics card, and for embedded SOC processor system, it is the driver of LCD controller or other display controller. It is a character device, and the device node in the file system is usually/dev/fbx. Each system can have multiple display devices, followed by/DEV/FBO,/DEV/FB l
Wait to say. In the Android system, the main device number is 29, and the secondary device number is incremented.
Android's use of the Framebuffer driver is standard, and the Framebuffer device node in/Dev/graphie//is automatically created by the Init process and called by the Libui Library. In Android's GUI system, the display device abstraction is realized by invoking the standard interface of the Framebuffer driver.
Framebuff framework and implementation of the structure:
Linux LCD Driver (ii)--framebuffer
Linux LCD Driver (quad)--drive implementation
2.Event input Device driver
The input driver is a driver for the Linux input device and is divided into 3 drivers for the joystick (joystick), mouse (mouse and mice), and event queue. The event driver is a common program, which can support keyboard, mouse, touch screen and other input devices. The main device number of the input driver is L3, each input device takes 5 bits from the device number, and 3 is allocated from the device number: Joystick 0 ~ Mouse; mice mouse 63; Event Device 64 ~ 95, each specific Devices in Misc, touchscreen, keyboard and other directories.
Event device in the user empty ask using Read, IOCTL, poll and other file system interface operation, read for reading input information, IOCTL used to get and set information, poll for user space blocking, when the kernel has a key interrupt, such as when the core is awakened by the poll in the interrupt Realize.
Event input-driven architecture and implementation:
Linux device-driven--input subsystem
3.ALSA Audio Driver
The Advanced Linux Sound System (ALSA) is a Linux kernel component that provides drivers for audio systems, replacing the original sound system OSS. It is a fully open source audio driver Assembly, in addition to providing a set of kernel driver modules like OSS, ALSA also provides a library of functions for simplifying application writing, and the ALSA library is more convenient to use than the original programming interface based on IOCTL provided by OSS. Some
With this library, developers can easily and quickly develop their own applications, details are left to the function library for internal processing. So although ALSA also provides a system interface similar to OSS, it is recommended that application developers use the audio library instead of calling the driver function directly.
 ALSA drive The main device number is 116, the secondary device number is defined separately by each device, the main device node is as follows:
/dev/snd/ contmlcx--master Control
&NB sp;/DEV/SND/PCMXXXC--PCM data channel,
&NB Sp /dev/snd/seq--order,
&NB Sp /dev/snd/timer--definition.
in user air, the ALSA driver is typically used with the ALSA library, and the library calls the device node of the ALSA driver through interfaces such as the IOCTL. For Aijsa-driven calls, the interface to the ALsA Library of user space is called instead of the direct call to the ALSA driver. The architecture of the ALSA audio driver is as shown in the following:
The primary header file for the ALSA driver is include/sound./sound. h, the registration function that drives the core data structure and the specific driver is include/sound/core. H, the core implementation of the driver is sound/core/sound. C file.
The ALSA driver uses the following functions to register controls and devices:
int snd _ pcm _ New (struct SND _ card * Card, char * ID, int device, int playback _ count, int capture _ count, Stru CT snd _ PCM * * RPCM);
int SnD ctl _ Add (struct snd _ card * Card, struct snd _ Kcontrol * kcontro1);
ALSA Audio driver configuration options for menuconfig configuration in the kernel are "Device Drivers" > "Sound C ard support" one > "Advanced Linux Sound Archit Ecture ". The sub-options include Generic sound devices (Universal audio Device), ARM architecture support, and several options compatible with OSS. The file that corresponds to the ALsA audio driver configuration is sound/core/kconfig.
Android does not directly use the ALSA driver, can be based on the A-lsa driver and ALSA Library implementation of Android Audio hardware abstraction layer, ALSA library calls the kernel of the ALSA driver, Audio hardware abstraction layer call ALSA library.
4.OSS Audio Driver
The OSS (open Sound System) is the first sound card driver to appear on Linux. The OSS consists of a complete set of kernel driver modules, which provide a unified programming interface for most sound cards.
OSS is a character device, the main device number 14, mainly includes the following several device files:
1)/dev/sndstat
It is a simple interface provided by the sound card driver, which is usually a read-only file and is limited to reporting the current state of the sound card. (for sound card detection)
2)/DEV/DSP
Device files for digital sampling and digital recording. is important for audio programming. Realize the conversion of analog and digital signals.
3)/dev/audio
Similar to/DEV/DSP, the Mu-law encoding method is used.
4)/dev/mixer
For multiple signal combinations or overlays, the mixer may have different effects for various sound cards.
5)/dev/sequencer
This device is used to operate a wave-table synthesizer built into the sound card, or to control instruments on the MIDI bus.
The files involved in OSS drivers mainly include:
Kernel/include/linux/soundcard.h
Kernel/include/linux/sound.h defining the secondary device number and registration function of the OSS driver
KERNEL/SOUND_CORE.C OSS Core Implementation Section
OSS Driver Architecture Diagram:
5.v4l2 Video Driver
V4L2 is an upgraded version of V4L, which provides a set of interface specifications for Linux under the video device program. Includes a set of data structures and the underlying V4L2 driver interface. V4L2 provides a number of access interfaces, and you can choose how you want to do it, depending on your needs. It is important to note that there are very few drivers that fully implement all of the interface functions. So you need to refer to the driver source code when using, or read the instructions of the driver provider carefully.
V4L2 The main device number is 81, the second device number: 0~255, these secondary device numbers also have several devices (video devices, radio devices, Teletext, VBI).
V4L2 Device node:/dev/videox,/dev/vbix And/dev/radiox
V4L2 Frame diagram:
Android development----Underlying driver development (i)