一段s3c lcd framebuffer 的代码
1
int
__init s3c_fb_probe(
struct
platform_device
*
pdev)
2 {
3 char driver_name[] = " s3c_fb " ;
4 int ret;
5 int index = 0 ;
6
7 for (index = 0 ; index < S3C_FB_NUM; index ++ ){ // 遍历每一个fb,我们里只有一个lcd.
8 s3c_fb_init_fbinfo( & info[index], driver_name, index);
9
10 if (index == 0 ){ // 操作主lcd
11 s3c_fb_backlight_power( 1 ); // 开启背光,lcd电源源,开启背光等。
12 s3c_fb_lcd_power( 1 );
13 s3c_fb_backlight_level(DEFAULT_BACKLIGHT_LEVEL);
14
15 dprintk( " dev FB init\n " );
16
17 // 映射内存区域
18 if ( ! request_mem_region((unsigned long )S3C_VA_LCD, SZ_1M, " s3c-lcd " )) {
19 ret = - EBUSY;
20 goto dealloc_fb;
21 }
22
23 dprintk( " got LCD region\n " );
24
25 // 打开lcd_clock
26 lcd_clock = clk_get(NULL, " lcd " );
27 if ( ! lcd_clock) {
28 printk(KERN_INFO " failed to get lcd clock source\n " );
29 ret = - ENOENT;
30 goto release_irq;
31 }
32
33 clk_enable(lcd_clock);
34 printk( " S3C_LCD clock got enabled :: %ld.%03ld Mhz\n " , print_mhz(clk_get_rate(lcd_clock)));
35
36 msleep( 5 );
37 }
38
39 // 申请显存
40 /* Initialize video memory */
41 ret = s3c_fb_map_video_memory( & info[index]);
42 if (ret) {
43 printk( " Failed to allocate video RAM: %d\n " , ret);
44 ret = - ENOMEM;
45 goto release_clock;
46 }
47 dprintk( " got video memory\n " );
48
49 // 初始化寄存器,这里与具体的设备有关。
50 ret = s3c_fb_init_registers( & info[index]);
51 ret = s3c_fb_check_var( & info[index].fb.var, & info[index].fb);
52
53 // 所谓的色表(调色盘?),不清除是干啥的。
54 if (index < 2 ){
55 /* 2007-01-09-Tue. for RGB 8-8-8 palette */
56 if (fb_alloc_cmap( & info[index].fb.cmap, 256 , 0 ) < 0 ){
57 goto dealloc_fb;
58 }
59 }
60 else {
61 /* 2007-01-09-Tue. for RGB 8-8-8 palette */
62 if (fb_alloc_cmap( & info[index].fb.cmap, 16 , 0 ) < 0 ){
63 goto dealloc_fb;
64 }
65 }
66 // 注册framebuffer??
67 ret = register_framebuffer( & info[index].fb);
68 if (ret < 0 ) {
69 printk(KERN_ERR " Failed to register framebuffer device: %d\n " , ret);
70 goto free_video_memory;
71 }
72 } // for(index=0; index<CONFIG_FB_NUM; index++)
73
74 // initialize the struct for Waitforvsync
75 // 关于中断的初始化工作,貌似2412是注册以后又取消了
76 s3cfb_vSyncInfo.count = 0 ;
77 init_waitqueue_head( & s3cfb_vSyncInfo.waitQueue);
78
79 #if defined(CONFIG_ARCH_S3C2443)
80 ret = request_irq(IRQ_LCD3, s3c_fb_irq, 0 , " s3c-lcd " , pdev);
81 #elif defined(CONFIG_ARCH_S3C6400)
82 ret = request_irq(IRQ_LCD_VSYNC, s3c_fb_irq, 0 , " s3c-lcd " , pdev);
83 #elif defined (CONFIG_S3C_DVS) && defined (CONFIG_ARCH_S3C2412)
84 ret = request_irq(IRQ_LCD, s3c_dvs_irq, 0 , " s3c-lcd " , pdev);
85 #endif
86 if (ret != 0 ) {
87 printk( " Failed to install irq (%d)\n " , ret);
88 goto release_irq;
89 }
90
91 #if defined (CONFIG_S3C_DVS) & defined (CONFIG_ARCH_S3C2412)
92 disable_irq(IRQ_LCD);
93 #endif
94
95 // 在sys底下建立节点,用于和用户空间交互
96 /* create device files */
97 device_create_file( & (pdev -> dev), & dev_attr_backlight_power);
98 device_create_file( & (pdev -> dev), & dev_attr_backlight_level);
99 device_create_file( & (pdev -> dev), & dev_attr_lcd_power);
100
101 // 胜利退出
102 printk(KERN_INFO " fb%d: %s frame buffer device\n " ,
103 info[index].fb.node, info[index].fb.fix.id);
104 return 0 ;
105
106 free_video_memory:
107 s3c_fb_unmap_video_memory( & info[index]);
108
109 release_clock:
110 clk_disable(lcd_clock);
111 clk_put(lcd_clock);
112
113 release_irq:
114 #if defined(CONFIG_ARCH_S3C2443)
115 free_irq(IRQ_LCD3, & info);
116 #elif defined(CONFIG_ARCH_S3C6400)
117 free_irq(IRQ_LCD_VSYNC, & info);
118 #endif
119 // release_mem:
120 release_mem_region((unsigned long )S3C_VA_LCD, S3C_SZ_LCD);
121
122 dealloc_fb:
123 framebuffer_release( & info[index].fb);
124 return ret;
125 }
126
127
128
2 {
3 char driver_name[] = " s3c_fb " ;
4 int ret;
5 int index = 0 ;
6
7 for (index = 0 ; index < S3C_FB_NUM; index ++ ){ // 遍历每一个fb,我们里只有一个lcd.
8 s3c_fb_init_fbinfo( & info[index], driver_name, index);
9
10 if (index == 0 ){ // 操作主lcd
11 s3c_fb_backlight_power( 1 ); // 开启背光,lcd电源源,开启背光等。
12 s3c_fb_lcd_power( 1 );
13 s3c_fb_backlight_level(DEFAULT_BACKLIGHT_LEVEL);
14
15 dprintk( " dev FB init\n " );
16
17 // 映射内存区域
18 if ( ! request_mem_region((unsigned long )S3C_VA_LCD, SZ_1M, " s3c-lcd " )) {
19 ret = - EBUSY;
20 goto dealloc_fb;
21 }
22
23 dprintk( " got LCD region\n " );
24
25 // 打开lcd_clock
26 lcd_clock = clk_get(NULL, " lcd " );
27 if ( ! lcd_clock) {
28 printk(KERN_INFO " failed to get lcd clock source\n " );
29 ret = - ENOENT;
30 goto release_irq;
31 }
32
33 clk_enable(lcd_clock);
34 printk( " S3C_LCD clock got enabled :: %ld.%03ld Mhz\n " , print_mhz(clk_get_rate(lcd_clock)));
35
36 msleep( 5 );
37 }
38
39 // 申请显存
40 /* Initialize video memory */
41 ret = s3c_fb_map_video_memory( & info[index]);
42 if (ret) {
43 printk( " Failed to allocate video RAM: %d\n " , ret);
44 ret = - ENOMEM;
45 goto release_clock;
46 }
47 dprintk( " got video memory\n " );
48
49 // 初始化寄存器,这里与具体的设备有关。
50 ret = s3c_fb_init_registers( & info[index]);
51 ret = s3c_fb_check_var( & info[index].fb.var, & info[index].fb);
52
53 // 所谓的色表(调色盘?),不清除是干啥的。
54 if (index < 2 ){
55 /* 2007-01-09-Tue. for RGB 8-8-8 palette */
56 if (fb_alloc_cmap( & info[index].fb.cmap, 256 , 0 ) < 0 ){
57 goto dealloc_fb;
58 }
59 }
60 else {
61 /* 2007-01-09-Tue. for RGB 8-8-8 palette */
62 if (fb_alloc_cmap( & info[index].fb.cmap, 16 , 0 ) < 0 ){
63 goto dealloc_fb;
64 }
65 }
66 // 注册framebuffer??
67 ret = register_framebuffer( & info[index].fb);
68 if (ret < 0 ) {
69 printk(KERN_ERR " Failed to register framebuffer device: %d\n " , ret);
70 goto free_video_memory;
71 }
72 } // for(index=0; index<CONFIG_FB_NUM; index++)
73
74 // initialize the struct for Waitforvsync
75 // 关于中断的初始化工作,貌似2412是注册以后又取消了
76 s3cfb_vSyncInfo.count = 0 ;
77 init_waitqueue_head( & s3cfb_vSyncInfo.waitQueue);
78
79 #if defined(CONFIG_ARCH_S3C2443)
80 ret = request_irq(IRQ_LCD3, s3c_fb_irq, 0 , " s3c-lcd " , pdev);
81 #elif defined(CONFIG_ARCH_S3C6400)
82 ret = request_irq(IRQ_LCD_VSYNC, s3c_fb_irq, 0 , " s3c-lcd " , pdev);
83 #elif defined (CONFIG_S3C_DVS) && defined (CONFIG_ARCH_S3C2412)
84 ret = request_irq(IRQ_LCD, s3c_dvs_irq, 0 , " s3c-lcd " , pdev);
85 #endif
86 if (ret != 0 ) {
87 printk( " Failed to install irq (%d)\n " , ret);
88 goto release_irq;
89 }
90
91 #if defined (CONFIG_S3C_DVS) & defined (CONFIG_ARCH_S3C2412)
92 disable_irq(IRQ_LCD);
93 #endif
94
95 // 在sys底下建立节点,用于和用户空间交互
96 /* create device files */
97 device_create_file( & (pdev -> dev), & dev_attr_backlight_power);
98 device_create_file( & (pdev -> dev), & dev_attr_backlight_level);
99 device_create_file( & (pdev -> dev), & dev_attr_lcd_power);
100
101 // 胜利退出
102 printk(KERN_INFO " fb%d: %s frame buffer device\n " ,
103 info[index].fb.node, info[index].fb.fix.id);
104 return 0 ;
105
106 free_video_memory:
107 s3c_fb_unmap_video_memory( & info[index]);
108
109 release_clock:
110 clk_disable(lcd_clock);
111 clk_put(lcd_clock);
112
113 release_irq:
114 #if defined(CONFIG_ARCH_S3C2443)
115 free_irq(IRQ_LCD3, & info);
116 #elif defined(CONFIG_ARCH_S3C6400)
117 free_irq(IRQ_LCD_VSYNC, & info);
118 #endif
119 // release_mem:
120 release_mem_region((unsigned long )S3C_VA_LCD, S3C_SZ_LCD);
121
122 dealloc_fb:
123 framebuffer_release( & info[index].fb);
124 return ret;
125 }
126
127
128