s3c6410 을 이용한 리눅스 비디오 드라이버 포팅 가이드 – - linux video driver...
DESCRIPTION
s3c6410 을 이용한 리눅스 비디오 드라이버 포팅 가이드 – - Linux Video Driver Porting Guide Using s3c6410 –. 박영만 [email protected]. Contents. Overview Video Driver Concept Video Driver Architecture Framebuffer Framebuffer Information Linux Framebuffer Driver Color Format Controller Overlay Alpha Blending - PowerPoint PPT PresentationTRANSCRIPT
s3c6410 을 이용한
리눅스 비디오 드라이버 포팅 가이드–
- Linux Video Driver Porting Guide Using s3c6410 –
Contents
• Overview– Video Driver Concept– Video Driver Architecture
• Framebuffer– Framebuffer Information– Linux Framebuffer Driver– Color Format
• Controller– Overlay– Alpha Blending– Chroma Key (Color Key)– Alpha Blending & Chroma Key
• Pannel• Backlight• Porting Sequence
Video Driver Concept
• Video 입출력을 지원하는 가장 Low Level 의 S/W
• Video Driver 의 구성 Module– Controller ex) Display Controller, Graphic Card …– Pannel ex) LCD, AMOLED, CRT …– Framebuffer ex) Overlay 1, 2 … ※ SRAM 을 의미함
• Controller 가 Framebuffer 의 Data 를 Pannel 에 출력한다 .
• 일반적으로 Framebuffer Driver 로 불리기도 함
Framebuffer Controller Pannel
Video Driver Architecture
Controller Pannel
H/W
Kernel
BSP
UserSystem Call
fbmem.c/fb.h 과 같은 커널의 Abstract Driver
/dev/fb0, 1… N 과 같이 Framebuffer 개수에 따라 여러 Device Node 로 나누어질 수 있음
Framebuffer
※ 본 구조는 s3c6410 코드를 기반으로 작성된 것임 . 코드에 따라 BSP 구조는 바뀔 수 있음 .
Framebuffer
• 실제 화면에 출력되게 될 메모리 영역– Framebuffer 에 Data 를 작성화면 , 작성된 Data 는 Controller 에 의해 Pannel 에 출력되게 된다 .
• Framebuffer Module– 커널에 포함되는 실제 Driver 모듈
• Framebuffer module 의 probe 함수가 호출되면서 driver 가 커널에 등록된다 .
– SRAM 에 Framebuffer 영역을 할당한다 .• dma_alloc_writecombine(device, memory_size, physical_memory_address, option) 으로 할당
※ Framebuffer 는 연속적인 Memory 영역을 가져야하기 때문에 dma_alloc_writecombine 으로 할당해야 한다 .
– Framebuffer 정보를 설정한다 . ex) bpp, width, height 정보• 기본적인 framebuffer 정보는 커널이 초기화되는 시점에 미리 할당되나 , Driver 가 올라간 후 부터는
Framebuffer module 에서 변경된 정보를 처리한다 .
– Controller/Pannel 모듈 관리 . + Backlight• 실제로 Operation 을 처리하는 Module 은 Controller 와 Pannel 이지만 User level 에서는 Framebuffer
Module 을 통해 Controller 와 Pannel 을 Access 하게 된다 . (Backlight 도 경우에 따라 Framebuffer 에서 관리한다 .)
• 또한 Framebuffer Module 의 초기화 부분에서 Controller 와 Pannel 의 초기화 함수를 호출한다 .
Framebuffer Information
• pixclock
• xres• yres• bpp• hsync_len• left_margin• right_margin• vsync_len• upper_margin• lower_margin
• backlight_power• lcd_power
xres
yres
leftmargin
rightmargin
hsynclen
vsynclen
lowermargin
uppermargin
※ 함수 포인터로 관련 Operation 이 붙는다 .
※ Pixel Clock : 1 Pixel 을 그리는 데 걸리는 시간 (Pico second) ex ) Dot Clock 이 60MHz 라고 하면 pixclock = 1/60 * 1000000
Linux Framebuffer Driver
struct fb_var_screeninfo { __u32 xres; /* Visible resolution in the X axis */ __u32 yres; /* Visible resolution in the Y axis */ /* ... */ __u32 bits_per_pixel; /* Number of bits required to hold a pixel */ /* ... */ __u32 pixclock; /* Pixel clock in picoseconds */ __u32 left_margin; /* Time from sync to picture */ __u32 right_margin; /* Time from picture to sync */ /* ... */ __u32 hsync_len; /* Length of horizontal sync */ __u32 vsync_len; /* Length of vertical sync */ /* ... */};
struct fb_fix_screeninfo { char id[16]; /* Identification string */ unsigned long smem_start; /* Start of frame buffer memory */ __u32 smem_len; /* Length of frame buffer memory */ /* ... */};struct fb_cmap { __u32 start; /* First entry */ __u32 len; /* Number of entries */ __u16 *red; /* Red values */ __u16 *green; /* Green values */ __u16 *blue; /* Blue values */ __u16 *transp; /* Transparency. Discussed later on */};
include/linux/fb.h
fb core
• 커널 내 Abstract Display Driver• User Level 에게 표준화된 Interface 를 제공 .
fbmem.c fb.h
fb driver 1 fb driver N
Memory 1 Memory N
. . . .
.※ 1 개의 Device 가 여러 Memory(FB) 를 가질 수 있다 .
Color Format
• RGB– Palletized : Pallet 를 통해 색상정보를 출력함 .
RGB 값이 Pallet 의 Index 를 의미함 .
ex) RGB 값이 3 일 경우
Pallet 의 3 번 색상을 출력 .
– Non-Palletized : RGB 값이 하나의 색상정보를 의미함 .
0 번 색 1 번 색 2 번 색 3 번 색 4 번 색 5 번 색 6 번 색 7 번 색 8 번 색 …..
R : 0 G : 1 B : 1
※ Pallet 또한 Framebuffer 의 한 메모리 영역임 .
Color Format
• YUV– 일반적으로 YUV 포맷 데이터는 Framebuffer 가 아닌 외부 장치 (Camera 등 ) 에서 바로 넘어오는 경우가 많다 .
– YUV Format
YUV444 (24bpp)
YUV422 (16bpp)
YUV420 (12bpp)
Y U V
Y U V
YU V
※ YUV pixel packing format
• Planar Format
• Packed Format
Y Y Y Y Y Y …..
U U U U U U …..
V V V V V V …..
YUV YUV YUV YUV YUV YUV …..YUV YUV YUV YUV YUV YUV …..YUV YUV YUV YUV YUV YUV …..
Controller
• 프레임버퍼의 내용 (Data) 을 화면 (Pannel) 에 출력할 수 있도록 지원해주는 Device• 오버레이 (Overlay), 크로마 키 (Chroma Key) 등의 효과를 H/W 적으로 지원• 컨트롤러의 사용
– GPIO : LCD GPIO 의 설정 ex) Input / Output PIN– REGISTER : REGISTER 를 이용하여 컨트롤러를 제어할 수 있다 .
Controller
• s3c6410 관련 Reigster
Register DescriptionMFPCON BY PASS & Normal Mode 선택SPCON Host I/F & RGB I/F 선택VIDCON0 출 력 Format 및 Display enable/disable
설정 VIDCON1 RGB I/F control signalI80IFCONx I80-system I/F signalITUIFCON0 ITU (BT.601) Interface ControlVIDTCONx 출력 Timing 및 화면 size 설정WINCONx 출력 Layer 별 Format 설정VIDOSDxA, VIDOSDxB 화면 위치 설정VIDOSDxC Alpha 값 설정 (for Alpha Blending)VIDWxxADDx Source Image Address 설정WxKEYCONx Color key 값 설정WINxMAP 화면 Color 제어WPALCON Palette 제어WxPDATAxx Window Palette Data of the each Index※ ‘x’ 는 0, 1, 2 … 로 확장됨을 의미함 . ex) VIDTCONx : VIDTCON0, VIDTCON1, VIDTCON2 ….
Overlay
• 화면의 중첩• H/W 따라 Overlay 정보 및 제어방법이 달라짐
fb0
fb1
fb2
첫 번째 화면(Base)
두 번째 화면(Overlay 1)
세 번째 화면(Overlay 2)
Memory (Framebuffer)
Overlay
• s3c6410 스펙– 5 개의 화면 지원 (1 Base 4 Overlay)– Layer 0, 1, 2 : Main Layer ( 화면 )
• 1, 2, 4 or 8-BPP (bit per pixel) palletized color• 16, 18 or 24-BPP non-palletized color• YCbCr (4:4:4) 로컬 버스로부터 직접 입력을 받음 (Win 0 :Post Processor. Win 1,2 :TV scaler)• RGB (8:8:8) 로컬 버스로부터 직접 입력을 받음 (Win 0 :Post Processor. Win 1,2 :TV scaler)
– Layer 3, 4 : Sub Layer ( 자막 , 커서 )• 1, 2 or 4-BPP (bit per pixel) palletized color• 16, 18 or 24-BPP non-palletized color
– 화면 순위 ( 고정 )Layer 5 > Layer 4 > Layer 3 > Layer 2 > Layer1
• s3c6410 관련 RegisterWINCONx 0x77100020 ~ 출력 Layer 별 Format 설정
Alpha Blending
• 투명 효과 (Transparency Effect)• ARGB Color Format 이용
• ARGB
– A : Alpha Channel ( 투명도를 나타냄 )
• s3c6410 관련 Register
– Alpha Blending 기능 설정
– Alpha 값 셋팅
A R G B
WINCONx 출력 Layer 별 Format 설정
VIDOSDxC Alpha 값 설정 (for Alpha Blending)
Chroma key
• Chroma Key 를 적용하여 특정 이미지를 제거 함• s3c6410 관련 Register
WxKEYCONx Color key 값 설정
Layer 0
Layer 1
Alpha Blending & Chroma key
• Alpha Blending 과 Chroma Key 를 동시 적용
• s3c6410 관련 RegisterWxKEYCONx Color key 값 설정
Virtual Screen
VIDWxxADDx Source Image Address 설정
• 실제 보여질 수 있는 화면 (Pannel Size) 보다 더 큰 영상을 보여줄 때 사용• s3c6410 관련 Register
LCDBASEU
LCDBASEL
※ 위 Register 의 VBASEU_F 값과 VBASEL_F 값에 따라 보여지는 화면의 위치가 변경된다 .
Pannel
• Timing sequence– Pannel On/Off 에 대한 Timing sequence 가 존재함 . (Pannel 매뉴얼이 별도로 존재 )– Timing sequence 에 맞게 On/Off 가능한 함수를 만든 후 fb_info(Framebuffer Information) 구조체에 삽입해서
컨트롤
ex ) < xxx.h >struct fb_info {
....void (*lcd_power)(int);
}
< xxx.c >probe() // 초기화 함수{
…..fb->lcd_power = pannel 함수 ;
}
※ Timing
- 전류의 흐름을 시간 간격에 따라 High 로 해줄 것인지 low 로 해줄 것인지를 나타냄- 위 그림에서는 xcs, sclk, si 3 핀간의 Timing 값을 보여준다 .
Backlight
• 화면의 밝기 조정• PWM(Pulse-Width Modulation Unit) 을 이용
• 기능 구현 방법– Framebuffer Driver 에 삽입하는 방법 : Framebuffer Driver 에서 직접 PWM 을 컨트롤– Backlight Driver 를 별도로 구현하는 방법 : Backlight Driver 작성 후 Backlight Driver 에서 PWM 컨트롤
※ Backlight Driver 구조 & 제어 방법
Backlight coredrivers/video/backlight/backlight.c
Backlight Driver
PWM(H/W)
Core 에서 제공하는 sysfs 인터페이스 제공ex ) /sys/s3c-bl/brightness
Core 에서 제공하는 sysfs 인터페이스에 실제 동작을 연결
Porting Sequence
※ 기본적으로 GPIO PIN 과 Register 의 Physical Address 는 정의되어 있다고 가정함
• 커널 초기화 부분에 Video Driver 와 관련된 기본 값을 설정한다 .( 일반적으로 fb_info 구조체를 만들어 기본 값들을 셋팅한다 .)
• Driver 가 Kernel 에 삽입될 수 있도록 Linux Device Driver Model 에 맞는 구조를 잡는다 . (platform_device / platform_driver 구조체 선언 및 셋팅 )※ 기본적으로 platform_device 는 커널 초기화 부분에서 , platform_driver 는 framebuffer module 에서 선언된다 .
• Driver 가 초기화될 때 일어나야 할 일들을 probe 에 순서대로 작성한다 .(Framebuffer 할당 및 초기화 , gpio 및 register 셋팅 , driver 등록 )
• 추가적인 사항 작성(ioctl 등… ) s3cfb.c
fimd4xx.c s3cfb_xxx.c
Controller Pannel
Framebuffer
alloc
※ s3c6410 video driver 기본 구조