210 likes | 812 Views
s3c6410 을 이용한 리눅스 비디오 드라이버 포팅 가이드 – - Linux Video Driver Porting Guide Using s3c6410 –. 박영만 yucco@naver.com. Contents. Overview Video Driver Concept Video Driver Architecture Framebuffer Framebuffer Information Linux Framebuffer Driver Color Format Controller Overlay Alpha Blending
E N D
s3c6410을 이용한리눅스비디오 드라이버 포팅 가이드– - Linux Video Driver Porting Guide Using s3c6410 – 박영만yucco@naver.com
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 ※ 본 구조는 s3c6410 코드를 기반으로 작성된 것임. 코드에 따라 BSP 구조는 바뀔 수 있음. User System Call Kernel fbmem.c/fb.h 과 같은 커널의 Abstract Driver Framebuffer Controller Pannel BSP H/W /dev/fb0, 1… N과 같이 Framebuffer 개수에 따라 여러 Device Node로 나누어질 수 있음
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 ※ Pixel Clock : 1 Pixel 을 그리는 데 걸리는 시간 (Pico second) ex ) Dot Clock 이 60MHz 라고 하면 pixclock = 1/60 * 1000000 • pixclock • xres • yres • bpp • hsync_len • left_margin • right_margin • vsync_len • upper_margin • lower_margin • backlight_power • lcd_power upper margin left margin right margin hsync len xres yres lower margin ※ 함수 포인터로 관련 Operation 이 붙는다. vsync len
Linux Framebuffer Driver include/linux/fb.h • 커널 내 Abstract Display Driver • User Level 에게 표준화된 Interface 를 제공. 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 */ /* ... */ }; fbmem.c fb.h fb core 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 */ /* ... */ }; fb driver 1 fb driver N . . . . . 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 */ }; Memory 1 Memory N ※ 1개의 Device 가 여러 Memory(FB) 를 가질 수 있다.
Color Format • RGB • Palletized : Pallet를 통해 색상정보를 출력함. RGB 값이 Pallet의 Index를 의미함. ex) RGB 값이 3일 경우 Pallet 의 3번 색상을 출력. • Non-Palletized : RGB 값이 하나의 색상정보를 의미함. ※ Pallet 또한 Framebuffer 의 한 메모리 영역임.
Color Format • YUV • 일반적으로 YUV포맷 데이터는 Framebuffer 가 아닌 외부 장치(Camera등)에서 바로 넘어오는 경우가 많다. • YUV Format YUV444 (24bpp) YUV422 (16bpp) YUV420 (12bpp) Y U V ※ YUV pixel packing format • Planar Format Y U V Y Y Y Y Y Y ….. U U U U U U ….. V V V V V V ….. Y • Packed Format U V YUV YUVYUVYUVYUVYUV ….. YUV YUVYUVYUVYUVYUV ….. YUV YUVYUVYUVYUVYUV …..
Controller • 프레임버퍼의 내용(Data)을 화면(Pannel)에 출력할 수 있도록 지원해주는 Device • 오버레이(Overlay), 크로마 키(Chroma Key)등의 효과를 H/W적으로 지원 • 컨트롤러의 사용 • GPIO : LCD GPIO의 설정 ex) Input / Output PIN • REGISTER : REGISTER 를 이용하여 컨트롤러를 제어할 수 있다.
Controller • s3c6410 관련 Reigster ※ ‘x’는 0, 1, 2 … 로 확장됨을 의미함. ex) VIDTCONx : VIDTCON0, VIDTCON1, VIDTCON2 ….
Overlay Memory (Framebuffer) • 화면의 중첩 • H/W 따라 Overlay 정보 및 제어방법이 달라짐 첫 번째 화면 (Base) fb0 fb1 두 번째 화면 (Overlay 1) 세 번째 화면 (Overlay 2) fb2
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 관련 Register
Alpha Blending • 투명 효과 (Transparency Effect) • ARGB Color Format 이용 • ARGB • A : Alpha Channel (투명도를 나타냄) • s3c6410 관련 Register • Alpha Blending 기능 설정 • Alpha 값 셋팅 A R G B
Chroma key • Chroma Key 를 적용하여 특정 이미지를 제거 함 • s3c6410 관련 Register Layer 0 Layer 1
Alpha Blending & Chroma key • Alpha Blending과 Chroma Key를 동시 적용 • s3c6410 관련 Register
Virtual Screen • 실제 보여질 수 있는 화면(Pannel Size)보다 더 큰 영상을 보여줄 때 사용 • s3c6410 관련 Register ※ 위 Register의 VBASEU_F 값과 VBASEL_F 값에 따라 보여지는 화면의 위치가 변경된다. LCDBASEU LCDBASEL
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 구조 & 제어 방법 drivers/video/backlight/backlight.c Backlight core Core에서 제공하는 sysfs 인터페이스 제공 ex ) /sys/s3c-bl/brightness Backlight Driver Core에서 제공하는 sysfs 인터페이스에 실제 동작을 연결 PWM(H/W)
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 등… ) ※ s3c6410 video driver 기본 구조 Framebuffer alloc s3cfb.c fimd4xx.c s3cfb_xxx.c Controller Pannel