Device Driver (MT6219)
Liu Yong20050310
2
Overview
Layer 1Device Driver
BluetoothBluetooth
IrDAIrDA
SD/SD/MMMCMC
USBUSBAudioIn/Out
AudioCodec
Synthe-sizer
RF PMIC Module
LCDLCDDisplayDisplay
LCDLCDDisplayDisplay
MediaMediaICIC
CameraCameraTouchTouchPanelPanel
MMI
L4
Baseband Chipset
Accessories:
Bluetoothheadset
USB data cable
3
MCU Clock
MCU_26M, MCU_52MMCU_13M, MCU_26M
MCU ClockMCU_CLOCK
EXT_13M, EXT_26MEXT_13M, EXT_26M
External PLL
EXT_CLOCK
MT6205B MT6218/MT6219
ChipsetDescriptionNotation
\mcu\make\ $(CUSTOM)_$(PROJECT).mak
4
Boot up and Initialization
Receiving start-up pattern via UART1
within 150ms?
Boot fromBOOTROM
RESET NOSwitch PC to External
Device Bank #0
YES
META Mode
Assign Supervisor Mode SP
If abnormal resetIs detected?
NO
YESResponse the
abnormal reset
Configure EMI
Data copy from flash to SRAM
Assign SP to various operation modes defined by ARM CPU.
Application initialization
Receiving start-up pattern via UART1
within 150ms?
Boot fromBOOTROM
RESET NOSwitch PC to External
Device Bank #0
YES
META Mode
Assign Supervisor Mode SP
If abnormal resetIs detected?
NO
YESResponse the
abnormal reset
Configure EMI
Data copy from flash to SRAM
Assign SP to various operation modes defined by ARM CPU.
Application initialization
mcu\init\src\bootarm.s
mcu\init\src\ini.c
5
Flash Configuration (Main differences between NOR & NAND)
interfaced serially via complicated I/O interface, which may vary from one device to another or from vendor to vendor. NAND is typically accessed in burst of 512 bytes. The same 8 pins convey control, address and data info.
Memory mapped, very similar to a random access device (RAM). Easy to access each byte of the entire media.
Interface
Over 10 times more than NORLess than 10% the life span of NAND.Life Span
100,000 – 1,000,00010,000 – 100,000Erase Cycles
Low:Requires 1-4 bit EDC/EEC due to bit-flipping issue.Requires bad block management.
Standard:Bit-flipping issues reportedLess than 10% the life span of NAND.
Reliability
Fast erase (3 ms)Fast writeFast read
VERY SLOW erase (5 sec)Slow writeFast read (slightly faster)
Performance
NoYeseXecute In Place (XIP) capabilities (Code Execution)
16MB – 512MB1MB – 32MBCapacity
NANDNOR
6
Flash Configuration (Main differences between NOR & NAND)
SequentialRandomAccess Method
ComplicatedEasyEase-of-use (Hardware0
LowHighPrice
Data storage only – due to complicated flash management. Code will usually not be stored in raw NAND flash.Examples:PC CardsCompact FlashSecure DigitalMP3 players (music storage)Digital cameras (image storage)
Code storage – limited capacity due to price in high capacity. May store limited data as well.
Examples:Simple home appliancesEmbedded designsLow-end set top boxesLow-end mobile handsetsPC BIOS chips
Ideal Usage
Hard. A simplistic FFS driver may be ported.
EasyFull System Integration (Hardware & Software)
NANDNOR
7
Flash ConfigurationNOR flash
..\mcu\custom\flash\XXX_BB\FlashConf.c5 steps configuration
Step4.
Set TOTAL_BLOCKS 23
Step5.
Set PARTITION_SECTORS 0
Step1.
FLASH_BASE_ADDRESS
Step3.
Set RegionInfo[]Step2.
ALLOCATED_FAT_SPACE = 0x100000
8
Flash ConfigurationNAND flash
..\mcu\custom\flash\XXX_BB\NANDFlashConf.c3 steps configuration
Step1.
TOTAL_SIZES 32 // Mega Byte
Step2.
PAGES_PER_BLOCK 32 // 16 or 32
BLOCK:
Erase Unit
PAGE:
Program UnitPartition1
Partition2
Total FAT sectors
Partition 1 sectors = PARTITION_SIZE
Partition 2 sectors =Total FAT sectors - Partition 1 sectors
Step3.
PARTITION_SECTORS 0
9
Flash ConfigurationNOR flash
..\mcu\custom\flash\XXX_BB\FlashConf.c
..\mcu\custom\system\XXX_BB\santXXX.txt5 steps configuration
Step1: Set FLASH_BASE_ADDRESSStep2: Set ALLOCATED_FAT_SPACE Step3: Set RegionInfo[]Step4: Set TOTAL_BLOCKSStep5: Set PARTITION_SECTORS
NAND flash..\mcu\custom\flash\XXX_BB\NANDFlashConf.c..\mcu\custom\system\XXX_BB\santXXX.txt3 steps configuration
Step1: Set TOTAL_SIZESStep2: Set PAGES_PER_BLOCK Step3: Set PARTITION_SECTORS
10
Flash
Example: (32+8)Nor
11
Flash
READ cycle
Write cycle
Refer to Baseband chip datasheet and system configuration guide for details of EMI.
ECLK
RLT+1EA
ECSn#
C2RSERD#
ED
EADV
RLT=4, C2RS=2
ECLK
WST+C2WH+2EA
ECSn#
C2WS C2WH+1EWR#
ED
EADV
WST=3, C2WS=2, C2WH=1
12
Flash\mcu\custom\system\[XXX_BB]\custom_emi.c
13
PMIC
Connection with BaseBand
PMIC
BaseBand
Ext. ChargerPowerOr USB
0.2 OHM
FET
VbatBat-TempBat-TypeBattery
Pack
ResetChr_DetChr-cntl
Pwr_BBSR_Clk_En
- Pwr_keyChr-drv
Vchr
ResetGPIOGPIO
BB_WakeupSR_Clk_En
Keypad
InterruptAux_ADC_1
Aux_ADC_2Aux_ADC_3Aux_ADC_4
Vd Va VioVrtc Vtcxo Vm Vsim
Charger
Bat_DetI-charger SIM…
GPIO
14
SIM
PMIC/Level shift
SIM I/F(MT62xx)
SIMVCC,SIMSEL,SIMRST,SIMCLK
SIMDATA
VCC,RST, CLK,DATA
SIM Card
15
SIM
T0
Any State
De-Activate->Activate
ATR PTS
Allow to accept MCU command
16
SIMDriver State Diagram
SIM_WAIT_FOR_ATR
SIM_PROCESS_ATR
ATR fail
SIM_PROCESS_PTS
SIM_PROCESSCMD
Reset
CommandMiner State
PTS fail
SIM_SERIOUSERR
17
SIMDriver State Diagram –Command minor state (T = 0 Controller)
SIM_WaitCmdEnd
SIM_ProcessClk CMD_Error/CMD_COMPLETE
L1sim_cmd(MajorState:
SIM_PROCESSCMD)
SIM_StopClk
18
SIMGeneric Drivers
mcu\drv\src\simd.c : • Implement SIM protocol and interface for upper layer
•L1sim_PowerOff•L1sim_Reset•L1sim_Configure•L1sim_Cmd•L1sim_Init
mcu\drv\include\sim_hw.h : • SIM HW port definitions
mcu\interface\hwdrv\sim_al.h : • Definitions for Data structure, SIM Commands and etc
mcu\interface\hwdrv\sim_sw.h : • States, Protocol Constants and Macros for SIM protocol
19
ADC
A channel used by auxiliary deviceBattery monitoringCharger controlPeripheral device detectionTemperature measurement
One physical channel may have many logical owners
Auto measureTDMA timer trigger
ADC Channel
ADC User 1 ADC User 2 ADC User 3
20
ADC
customize\custom\drv\misc_drv\[PRJ]\adc_channel.c
5 ADC channels in MT6205B, 7 in MT6218B & MT6219Customized ADC channel definitions
21
EINT
\custom\drv\misc_drv\[PRJ]\eint_def.cExternal Interrupt channel assignment
Channel assignment.De-bounce time delay setting.Example:
22
AUX task
Plug-in Detection
UEM Task
5
MSG_ID_AUX_ID
According the return adc value to decide what is plug in
aux_read_adc_channel(aux_adc_logic_id);
(MSG_ID_BMT_ADC_ADD_ITEM_REQ)
BMT Task1Aux TaskExt_ISR 2
4MSG_ID_AUX_PLUGIN
MSG_ID_BMT_ADC_MEASURE_DONE_CONF
3
23
AUX task
Plug- out Detection
UEM Task
MSG_ID_AUX_ID 2
BMT Task
aux_remove_adc_channel(kal_uint8 logic_id)(
(MSG_ID_BMT_ADC_REMOVE_ITEM_REQ)
3
Aux Task1
Ext_ISRMSG_ID_AUX_PLUGOUT
24
AUX task
Send Key Detection
1.Ring 2.Hook up 3.Hang-up
Time
Aux stop turn on microphone bias and keep polling ADC value
Aux sop to poll ADC value
Aux start to poll ADC value
25
AUX task
mcu\custom\drv\misc_drv\[PRJ]\aux_main.cAUX Task is to
detect earphone, UART plug-in and plug-out detect PTT-key press Support ADC report in Engineer mode
26
AUX taskGeneric Driversmcu\interface\hwdrv\eint.h :External declaration and constant definitions for external INT.
Customizationmcu\custom\drv\misc_drv\ ”Custom_Proj” \aux_main.c : AUX Task to
To detect earphone, uart plug-in and plug out To detect send_end key press Support ADC report in Engineer mode
mcu\custom\drv\misc_drv\ ”Custom_Proj” \eint_def.c :Definition and query APIs for external INT channels,
e.g. AUX_EINT_NO = 0;CHRDET_EINT_NO = 1;CLAMDET_EINT_NO=2;
27
BMT
MMI AUX task
ADC scheduler
Charging Algorithm BMT Task
ADC driver
NVRAM
PMICdriver
28
BMTLi-Ion battery Charging Diagram
29
BMT
Pre-charge state
Chargecomplete
state
Fast (CC)charge
state
Top -off (CV)charge state
Init state
Charger detected
Vbat_off > CHVBATOFF
I < ICHARGE1_LI
I < ICHARGE2_LI
Pause state
Vbat_off >CVPROTECT_HIGHand in talking mode
Vbat_off < CVPROTECT_LOW or in stand by
mode
Vbat_off < CHVBATOFF2_LI or NIVbat_off CVPROTECT_HIGHand in talking mode
Vbat_off >CVPROTECT_HIGHand in talking mode
Init safety timer
Vbat_off >CVPROTECT_HIGHand in talking mode
30
Battery level Setting
Open \mcu\custom\drv\misc_drv\[project]\custom_hw_default.c and locate NVRAM_EF_CUST_HW_LEVEL_TBL_DEFAULTModify accordingly
Level 4------------------ 3.88VLevel 3------------------ 3.74VLevel 2------------------ 3.60VLevel 1------------------ 3.55VLow Battery ------------------ 3.40VMo Limit------------------ 3.39VPower Off
Bump up version of data itemNVRAM_EF_CUST_HW_LEVEL_TBL_LID
\mcu\custom\drv\misc_drv\[project]\custom_nvram_editor_data_item.h
31
Keypad
Keypad ISR (Kbd_LISR)
Keypad Task&decoder (kbd_task_main)
KBD.event
Keypad-scanner Hardware
Key pressed Key Released
UEM Task
Keypad bufferMSG_ID_DRVUEM_KEYPAD_IND
Kbd_GetKeyData
32
Keypad
BB Keypadkeypad Interface
MT6205B
MT6205B
KROW0
KROW1
KROW2
KROW3
KROW4
KCOL0 KCOL1 KCOL2 KCOL3
SEND
UP DOWNLEFT RIGHT
[ 1] [ 2] [ 3]
[ 4][ 5] [ 6][ 7]
[ 8] [ 9][ *] [ 0] [ #]
MenuP Book
KCOL4
PWROn/Off
OK
Null
Null Null
Null
33
Keypad
\custom\drv\misc_drv\[PRJ]\keypad_def.cKeypad mapping definition
5X5 matrix in MT6205B7X6 matrix in MT6218B,MT6219
34
Keypadplutommi\mmi\framewortk\osl\oslsrc\KeyBrd.cKeypad mapping definition
If defined in MMI_Features[PRJ].hIf defined in MMI_Features[PRJ].hoo __MMI_WITH_C_KEY____MMI_WITH_C_KEY__oo __MMI_WITH_WAP_KEY__ __MMI_WITH_WAP_KEY__
35
LED/LCD/VIB Patterns Setting
Related Files:\mcu\custom\app\[project]\custom_led_patterns.h\mcu\custom\app\[project]\custom_led_patterns.c
Example:Example:
36
LED/LCD/VIB Patterns Setting
MTK provides 20 LED patternsTypically 3 GPIOs (Red, Green, Blue)6 levels (0 ~ 5)
MTK provides 2 LCD patternsTypically 1 GPIO2 levels (0 / 1)
MTK provides 3 vibrator patternsTypically 1 GPIO2 levels (0 / 1)
37
GPIO
\custom\drv\misc_drv\[PRJ]\gpio_drv.cGPIO Initialization
Not be changed once the hardware is finalizedRefer to Base band chip datasheet and HW layout
38
GPIO\mcu\custom\drv\misc_drv\[PRJ]\custom_equipment.c
39
PWM
Internal Counter
Threshold
PWM Signal
PWM Clock, 13MHz,13/2 MHZ , 13/4MHz, 13/8MHz
PWM counter,(12 bits)
PWM threshold(12 bits)
40
PWM Setting
Open \mcu\custom\drv\misc_drv\[project]\custom_hw_default.c and locate NVRAM_EF_CUST_HW_LEVEL_TBL_DEFAULTModify at
Bump up version of data itemNVRAM_EF_CUST_HW_LEVEL_TBL_LID
\mcu\custom\drv\misc_drv\[project]\custom_nvram_editor_data_item.h
41
Alerter
Internal Counter 1
Alerter Threshold
Internal Counter 2
Enhanced PWM out (Mode1)
Enhanced PWM out (Mode2)
Enhanced PWM out (Mode3)
42
UART
\custom\drv\misc_drv\[PRJ]\uart_def.cThe size of UART ring buffer definition
43
UART
Set UART Flow Controlfc_none: no flow controlfc_sw: software flow controlfc_hw: hardware flow control
44
USB..\mcu\custom\drv\misc_drv\usb_custom.cDevice description parameter
USB_MANUFACTURER_STRING[]USB_PRODUCT_STRING[]USB_SERIAL_STRING[]
Mass storage parametersINQUIRE_DATA[]USB_MS_INTERFACE_STRING[]
45
USBCDC ACM parameters
GPIO as power control pinEx. GPIO16 should be reserved in gpio_drv.c
46
USB Charging
USB device can announce it’s consuming current in the descriptor.500mA is announced in our USB device including CDC ACM Class and Mass Storage Class.If the host grants it, using the current from USB hub to charging MS battery.No matter host grants 500mA request or not, sucks the current 0f 400mA directly from the hub.Only support one of AC charger or USB cable exist.
47
USB charging – circuit diagram
VCHG USBPWR
VBAT
ADC4_VCHGEINT2_USB
EINT1_CHRDET
GPIO18_CHR_CTL
ADC_ISENSE
ADC_VBAT
R406
100K
R416
0.4 (1% 0805 1/4W)
D411RB160M-30
12
C401
1u (0805 Y5V 16V)
R407
24K
R415
56K
R414
43K
BT401
BATTERY CONN.
12
3
VBATTEMP
GND
C402
1u (0805 Y5V 16V)D411RB160M-30
12
PMIC
PMIC
/2
/2
This part of circuit is cut off at USB_CHARGE_ETHAN.
48
MTK USB feature and detect sequence
Feature Mass storage
Support NAND flash, MSDC cardsUSB mass storage class
Virtual comportThe same as UART functionUSB CDC ACM class
Detect sequence USB cable plug in when power on
Features selected by user (mass storage or virtual comport)If mass storage mode is selected, device will shutdown and reboot as mass storage mode
USB cable plug in when power offAlways boot as mass storage mode
49
MTK USB 1.1 operation
FunctionHandle the setup procedure between PC and device
PC detect and recognize the USB device by the enumeration of control endpoint
Operate in USB HISRUSB hardware interrupt trigger
USB hardware
Interrupt (2)
(3)
USB HISR(4)
Configure hardware to responseUSB LISR
Start (receive packets)
(1)
50
USB Storage manager
USB storage manager
SD driver
MMCdriver
NAND flash driver
NOR flash driver
USB Mass Storage interface
LUN
Register API
51
USB adaptation API for Mass Storage
kal_uint8 usbms_get_max_LUN(void). (MS manager)Register_API(&MS_DRVAPI_Group). (MS manager)Read_APIWrite_APICHECK_MEDIA_EXIST_APIMount_API(Format_API)PREVMEDIA_REMOVAL_APIREAD_CAPACITY_API max_lba,sec_len
52
MSDC – System Architecture
File System USB mass storage
MS Driver
MSDC Controller
MS-PRO Driver SD/MMC Driver
MS Card MS-PRO Card SD/MMC Card
MS Adaptation MS-PRO Adaptation SD/MMC Adaptation
hardware
software
card
53
MSDC features
32 bytes FIFO shared for transmit and receiveBuilt-in CRC DMA supportInterrupt supportAuto-command execution for MSPower down supportSerial clock rate is programmableCard detection capabilities (wake up MCU)Output driving capability and Slew rate of IO pads are configurable
54
Chip Support Table
MT6205B MT6218B MT6219
SD/MMC None Yes Yes
MS None Yes Yes
MS-PRO None None Yes
55
SD vs. MMC
Yes
Yes
25MHz1,4SD
NoWrite protect switch
NoCopy right protection
20MHzMax clock rate
1Bus widthMMC
56
Card Detection
MSDC HISR FMT
MSDC HISR FMT
MSG_ID_MSDC_CARD_DETECT_IND (MSG)
MSDC_GetCardStatus (FUNC)
MountDevice (FUNC)
Card plug in/out
57
MSDC Driver Architecture
MSDC Controller
Card
MSDC HISR FMT
Send Commands and suspended
Driver
FMT
MSDC HISR
FMT
Response
Set event to wake up the suspend task
Generate INT and activate HISR
Send/receive Data using DMA and suspended
Generate INT and activate HISR
Set event to wake up the suspend task
task suspended
task suspended
58
APIs of SD Driver
SD_InitializeSD_ReadSingleBlockSD_ReadMultiBlockSD_WriteSingleBlockSD_WriteMultiBlock
59
SD Adaptation Layer
MountDeviceReadSectorsWriteSectorsMediaChangedGetDiskGeometry
60
Audio
61
Audio
MMI Layer 4
SpeechPCM, WAV, MP3, Melody, Wavetable, SMF,AMR, iMelody, Voice memoand etc
Audio TypeAUD
L1 Audio
DSP L1 Audio Adaptation Layer
External MIDI Chips (opt.)(MT6205B only)
AFE
62
LCD
LCMEMI/NFI8080/6800 Parallel
AcceleratorMain-PanelLCDModule LCD
DMA Controller
MT 62XX
Serial Accelerator
LCD DATASub-PanelLCDModule (Opt.)
LCD CLK
LCD CS0/1LCD A0
63
LCD
MMIUEM GDI
LCM
DRV_RGB_TO_HW(R,G,B)DRV_LCD_SET_BUFFER_PIXELDRV_LCD_GET_BUFFER_PIXEL
LCD InterfaceRGB LEDBacklightControl
Functionpointer
get_lcd_frame_buffer_address()
LCM Driver 1
LCM Driver 2
LCM Driver n
64
LCD8-bit SPI Interface
D 7 D 5 D 3D 4D6 D 2 D 1 D 0 D 0
C LK
D ATA
C S
A 0
9-bit SPI Interface
A0 D6 D4D5D7 D3 D2 D1 D0
CLK
DATA
CS
65
LCD
6800-Series MPU Interface
8080-Series MPU Interface
66
LCD
Files:\custom\drv\LCD\[PRJ]\lcd.c\custom\drv\LCD\[PRJ]\lcd_hw.h\custom\drv\LCD\[PRJ]\lcd_sw.h\custom\drv\LCD\[PRJ]\lcd_sw_inc.h\custom\drv\LCD\[PRJ]\lcd_sw_rnd.h
Function:Function:
67
LCDInit
This function is to initialize LCD module. In this function, LCD will exit sleep mode, power on, clean the screen, screen on, and configure to a suitable mode.
BlockWriteDMA
68
LCD Contrast Setting
Open \mcu\custom\drv\misc_drv\[project]\custom_hw_default.c and locate NVRAM_EF_CUST_HW_LEVEL_TBL_DEFAULTModify at
69
Camera
LCM
BasebandSensor
MT6219
70
Camera Software Architecture
MMI Task
MDI Camera GDI
LCD InterfaceCamera Driver
HW- (LCM, ISP, MT6218, MT6219...)
MEDIA Task
Camera MMI
71
Camera
MMI Task
MDI Camera GDI
LCD InterfaceCamera Driver
MEDIA Task
Camera MMI
LCM
ISP
Layer 0blt_layer_flag == LAYER 0 | LAYER 1 | LAYER 2
preview_layer_flag == LAYER 0
Layer 1
Layer 2
MT6219
Layer 0Layer 1Layer 2
72
Camera
E X T _ C A M E R A _ C AP T U R E _ S T A T E
E X T _ C A M E R A _ P R EV I E W _ S T A T E
E X T _ C A M E R A _ P OW E R _ O F F _ S T A T E
E X T _ C A M E R A _ I N IT I A L _ S T A T E
E X T _ C A M E R A _ S T AN D B Y _ S T A T E
ext_camera_power_off () ext_camera_power_on()
ext_camera_reset_status()=True
ext_camera_preview()
ext_camera_ready_check()
ext_camera_capture()
ext_camera_power_off()
ext_camera_power_off()
ext_camera_power_off()
ext_camera_ready_check()
73
Camera
Files:\custom\drv\cam_module\XXX\cam_module.c\custom\drv\cam_module\XXX\cam_module.h
Function:Function:
74
Q&A