Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Mediatek Developer Reference

⚠️ This book is WIP, there might be missing information. ⚠️

This book contains every possible bit of information about Mediatek platform and it's components.

Research was done mostly on t-alps-q0.mp1-V9.122.1 ALPS branch, so if you are a Mediatek partner developer with newer ALPS version, this information might be outdated.

Kernel drivers are highly unstable when using ALSA API manually and they may cause a kernel panic. Consider interfacing with Audio HAL instead.

Audio

Modern kernel drivers use kernel streaming, multiple buffers are allocated and are routed dynamically using ALSA controls.

Terminology

  • ADDA - Analog to Digital & Digital to Analog Converter. Usually used for headphones due to ADDA's ability to handle both headset and it's microphone.
  • I2S - Inter-Integrated Circuit Sound. Usually used for speakers.
  • DL - Downlink/sink.
  • UL - Uplink/source.

Buffers

  • Playback_1/DL1 - Default playback buffer.
  • Playback_2/DL2 - Isolated deep buffer.
  • Playback_3/DL3 - Isolated deep buffer fallback, used when Playback_2 isn't available.
  • Playback_12/DL12 - VoIP playback buffer.

Even though these buffers have specific roles in Audio HAL, they are multipurpose and can be used for anything (e.g. Playback_12 can be used for music playback).

ALSA Controls

Scenario

  • deep_buffer_scenario - Controls if route is using deep buffer or not.

Headphones

  • HPL Mux - Headphones left channel muxer. Default is Open, should switch to Audio Playback when playing audio through headphones.
  • HPR Mux - Headphones right channel muxer. Default is Open, should switch to Audio Playback when playing audio through headphones.
  • ADDA_DL_GAIN - ADDA total gain.

Routing

Note: Usually CH1 is left channel and CH2 is right channel. It's not possible to route CH1 to CH2 and vice versa.

  • ADDA_DL_CHn DLx_CHn - Route channel n of ADDA to channel n of downlink x.
  • I2Sx_CHn DLy_CHn - Route channel n of I2S device x to channel n of downlink y.

Hi-Res Audio

Kernel drivers provide sample formats S24_LE and S32_LE as well as sample rates up to 192000.

If you get distorted audio when using S24_LE or S32_LE sample formats, it means your volume is too high, you can try lowering it by 48dB:

# ffmpeg -i [path to audio file] -af volume=-48dB -ac 2 -ar 48000 -f s32le - | aplay -D hw:0,2 -r 48000 -c 2 -f S32_LE

Note: Some devices might have problems with sample rates above 48000.

Examples

Routing deep buffer to headphones and playing audio using aplay

# amixer sset "HPL Mux" "Audio Playback"
# amixer sset "HPR Mux" "Audio Playback"
# amixer sset "ADDA_DL_CH1 DL2_CH1" on
# amixer sset "ADDA_DL_CH2 DL2_CH2" on
# amixer sset "deep_buffer_scenario" on
# aplay -D hw:0,2 [path to .wav file]
Kernel drivers expect vpud to run in userspace. Encoding and decoding won't work without vpud.

VCU and VPU

VCU (Video Communication Unit) and VPU (Video Processor Unit) are used for encoding and decoding videos. Both terms can be used interchangeably, but VPU is a more prevalent term, it will be used throughout this book.

API

Mediatek provides V4L2 M2M API for high-level VPU operations.

/dev/vcu and /dev/vpu devices are meant for vpud and don't have any relevant encoding/decoding interfaces.

DMA

Most kernel configurations enable CONFIG_VB2_MEDIATEK_DMA_CONTIG. When this config is enabled, kernel drivers use their own mtk_dma_contig_memops, this struct lacks VB2_MMAP and VB2_USERPTR support, which breaks many applications that use these modes.

Devices

  • /dev/video0 - Decoding.
  • /dev/video1 - Encoding.

Decoding Support

SoCAVCHEVCVP8VP9AV1
MT6768

Encoding Support

SoCAVCHEVCVP8VP9AV1
MT6768

JPEG

VPU has a JPEG codec, but it's not exposed via V4L2 M2M API, instead it's provided via /proc/mtk_jpeg.

Buffers provided to the API should be allocated using M4U.

M4U

M4U (Multimedia Memory Management Unit) is used to provide memory buffers for internal SoC components. You can access it using /proc/m4u.