Driver Overview
Speaking of Android drivers, Linux drivers are indispensable. The android kernel uses the linux2.6 kernel (Linux 3.3 has recently included some Android code ). However, Android does not completely copy the Linux kernel. In addition to some modifications to Linux, a lot of content has been added. Android drivers can be divided into two types: Android drivers and Android device drivers (Linux ).
Android proprietary DRIVER:
1) The Android ashmem anonymous shared memory provides a memory allocation mechanism for user space programs, provides a large shared memory for processes, and also provides the kernel with memory recovery and management.
2) Lightweight log driver for Android logger;
3) Android binder is a Driver Based on the openbinder framework;
4) Android power management module;
5) low memory killer low memory manager;
6) Android pmem physical memory driver;
7) USB Gadget USB driver (based on gaeget framework );
8) the ram console is used to debug devices that write log information;
9) time device timed control device;
10) android alarm hardware clock;
Device drivers on Android:
1) framebuff display driver;
2) event input device driver;
3) ALSA audio driver;
4) OSS audio driver;
5) v412 camera: video drive;
6) MTD driver;
7) Bluetooth driver;
8) WLAN device driver;
Android proprietary driver
1. Android ashmem
It provides a memory allocation mechanism for user space programs, provides large shared memory for processes, and also provides memory recovery and management for the kernel.
Device node:/dev/ashmen. master device No. 10.
Source code: Include/Linux/ashmen. h kernel/MM/ashmen. c
Compared with the traditional memory allocation mechanisms such as malloc and anonymous/named MMAP, the advantage is that the kernel driver provides a secondary kernel memory recovery algorithm mechanism (PIN/unoin)
2. Android Logger
You can use the logger Log Device to view and debug the underlying source code and upper-layer applications.
Device node:/dev/log/main/dev/log/event/dev/log/Radio
Source code: Include/Linux/logger. h include/Linux/logger. c
3. Android Binder
IPC binder is a mechanism for inter-process communication. This process can provide services for other processes-calling APIs through standard Linux systems.
Device node:/dev/binder
Source code 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. When one of these thresholds is in the same range as oom_adj in the process description, the process will be killed (specify the minimum value of oome_adj in parameters/adj ). It is similar to the standard Linux OOM mechanism, but the implementation method is different.
Source code location: Drivers/MISC/lowmemorykiller. c
6. Android pmem
Pmem is mainly used to provide continuous physical memory areas to the user space.
1. Share the CPU core with the GPU or VPU buffer.
2. Used for Android Service heap.
Source code: Include/Linux/android_pmem.h Drivers/Android/pmem. c
7. USB Gadget
Device Driver Based on the standard Linux USB gaeget driver framework.
Source code location: Drivers/USB/gadet/
8. Ram Console
To provide debugging functions, Android allows you to write debugging log information to this device, which is a ram-based buffer.
Source code: Drivers/staging/Android/ram_lele.c
9. Time Device
Timed control, which provides the timed control function for devices.
Source code: Drivers/staging/Android/timed_output.c (timed_gpio.c)
10. android alarm
A timer is provided to wake up the device from its sleep state. It also provides a clock benchmark that runs even when the device is sleeping.
Device node:/dev/alarm
Source code location: Drivers/trc/alarm. c
Android device driver
1. framebuffer frame cache Device
The framebuffer driver is the driver of a standard display device in Linux. For PC systems, it is the driver of the video card; for Embedded SoC processor systems, it is the driver of the LCD controller or other display controllers. It is a character device. In the file system, the device node is usually/dev/fbx. Each system can have multiple display devices, with/dev/FBO,/dev/FB L
. In the Android system, the primary device number is 29, and the secondary device number is generated progressively.
Android uses the framebuffer driver in a standard way. The node of the framebuffer device in/dev/graphie/is automatically created by the INIT process and called by the libui library. In the android GUI system, the standard interface of the framebuffer driver is called to abstract display devices.
Framework and implementation of framebuff:
Linux LCD Driver (II) -- framebuffer
Linux LCD Driver (IV)-driver implementation
2. Event Input Device Driver
The input driver is a driver for Linux input devices. It can be divided into three drivers: joystick, mouse, and mice. The event driver is a common program that supports multiple input devices, such as the keyboard, mouse, and touch screen. The main device Number of the input driver is L3. Each input device occupies 5 digits from the device number ~ 61; mouse 33
~ 62; mice mouse 63; event device 64 ~ 95. Specific devices are in directories such as MISC, touchscreen, and keyboard.
The event device uses interfaces of file systems such as read, ioctl, and poll to read input information, IOCTL to obtain and set information, and poll to block user space, when the kernel is interrupted, such as a key, it is implemented by awakening the kernel's poll during the interruption.
Architecture and Implementation of event input DRIVER:
Linux Device Driver-Input subsystem
3. ALSA audio driver
Advanced Linux sound architecture (ALSA) is a Linux kernel component that provides drivers for the audio system to replace 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 function library to simplify application programming, and OSS-based
Compared with the original programming interfaces such as ioctl, the Alsa function library is easier to use.
With this function library, developers can easily and quickly develop their own applications, leaving the details to the function library for internal processing. Therefore, though ALSA also provides a system interface similar to OSS, it is recommended that application developers use the audio function library instead of directly calling the driver function.
The main device Number of the Alsa driver is 116, which is defined separately by each device. The main device nodes are as follows:
/Dev/snd/contmlcx -- master control;
/Dev/snd/pcmxxxc -- PCM data channel;
/Dev/snd/seq -- sequencer;
/Dev/snd/timer -- definer.
In the user's blank question, the Alsa driver is usually used with the Alsa library, and the library calls the device node of the Alsa driver through interfaces such as IOCTL. The call of the aijsa driver calls the Alsa library interface of the user space, rather than directly calling the Alsa driver. Shows the architecture of the Alsa audio driver:
The main header file of the Alsa driver is include/sound. /sound. h. The registration function that drives the core data structure and specific drivers is include/sound/core. h. The core implementation of the driver is sound/CORE/sound. c file.
The ALSA driver registers controls and devices using the following functions:
Int snd _ PCM _ new (struct snd _ card * card, char * ID, int device, int playback _ count, int capture _ count, struct snd _ PCM ** RPCM );
Int snd CTL _ add (struct snd _ card * card, struct snd _ kcontrol * kcontro1 );
When the Alsa audio driver configures menuconfig in the kernel, the configuration options are "device drivers"> "sound C ard support" 1> "Advanced Linux sound architecture ". Sub-options include generic sound devices, ARM architecture support, and OSS compatibility. The file corresponding to the Alsa audio driver configuration is sound.
/CORE/kconfig.
Android does not directly use the Alsa driver, you can implement the hardware abstraction layer of Android audio Based on the A-LSA driver and ALSA library; ALSA library calls the Alsa driver of the kernel, and the hardware abstraction layer of audio calls the Alsa library.
4. OSS audio driver
OSS (Open Sound System) is the first sound card driver in Linux. OSS consists of a complete set of kernel driver modules, which can provide unified programming interfaces for most sound cards.
OSS is a character device with the master device number 14. It mainly includes the following device files:
1)/dev/sndstat
It is a simple interface provided by the sound card driver. It is usually a read-only file and only serves to report the current status of the sound card. (Used to detect sound cards)
2)/dev/DSP
Device Files used for digital sampling and digital recording. It is very important for audio programming. Converts analog and digital signals.
3)/dev/Audio
Similar to/dev/DSP, Mu-Law encoding is used.
4)/dev/Mixer
It is used for combination or combination of multiple signals. For different sound cards, the effect of the mixer may be different.
5)/dev/sequencer
This device is used to operate the built-in wave table synthesizer of the sound card or to control the instrument on the Midi bus.
The OSS driver involves the following files:
Kernel/include/Linux/Soundcard. h
Kernel/include/Linux/sound. h defines the sub-device number and registration function of the OSS driver
Kernel/sound_core.c core implementation of OSS
OSS driver architecture diagram:
5. v4l2 video driver
V4l2 is an upgraded version of v4l. It provides a set of interface specifications for Video device programs in Linux. Includes a set of data structures and underlying v4l2 driver interfaces. V4l2 provides many access interfaces. You can select an operation method as needed. Note that few drivers fully implement all interface functions. Therefore, you need to refer to the driver source code or carefully read the instructions for use by the driver provider.
The primary device Number of v4l2 is 81, and the secondary device number is from 0 ~ 255, these device numbers also contain several types of devices (video devices, Radio devices, teletext, and VBI ).
V4l2 device nodes:/dev/videox,/dev/vbix and/dev/radiox
V4l2 framework: