2 * Framebuffer driver for EFI/UEFI based system
4 * (c) 2006 Edgar Hucek <gimli@dark-green.com>
5 * Original efi driver written by Gerd Knorr <kraxel@goldbach.in-berlin.de>
9 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/errno.h>
13 #include <linux/platform_device.h>
14 #include <linux/screen_info.h>
16 #include <video/vga.h>
18 static struct fb_var_screeninfo efifb_defined __initdata
= {
19 .activate
= FB_ACTIVATE_NOW
,
26 .vmode
= FB_VMODE_NONINTERLACED
,
29 static struct fb_fix_screeninfo efifb_fix __initdata
= {
31 .type
= FB_TYPE_PACKED_PIXELS
,
32 .accel
= FB_ACCEL_NONE
,
33 .visual
= FB_VISUAL_TRUECOLOR
,
36 static int efifb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
37 unsigned blue
, unsigned transp
,
41 * Set a single color register. The values supplied are
42 * already rounded down to the hardware's capabilities
43 * (according to the entries in the `var' structure). Return
44 * != 0 for invalid regno.
47 if (regno
>= info
->cmap
.len
)
54 ((u32
*)(info
->pseudo_palette
))[regno
] =
55 (red
<< info
->var
.red
.offset
) |
56 (green
<< info
->var
.green
.offset
) |
57 (blue
<< info
->var
.blue
.offset
);
62 static struct fb_ops efifb_ops
= {
64 .fb_setcolreg
= efifb_setcolreg
,
65 .fb_fillrect
= cfb_fillrect
,
66 .fb_copyarea
= cfb_copyarea
,
67 .fb_imageblit
= cfb_imageblit
,
70 static int __init
efifb_probe(struct platform_device
*dev
)
74 unsigned int size_vmode
;
75 unsigned int size_remap
;
76 unsigned int size_total
;
78 efifb_fix
.smem_start
= screen_info
.lfb_base
;
79 efifb_defined
.bits_per_pixel
= screen_info
.lfb_depth
;
80 efifb_defined
.xres
= screen_info
.lfb_width
;
81 efifb_defined
.yres
= screen_info
.lfb_height
;
82 efifb_fix
.line_length
= screen_info
.lfb_linelength
;
84 /* size_vmode -- that is the amount of memory needed for the
85 * used video mode, i.e. the minimum amount of
87 size_vmode
= efifb_defined
.yres
* efifb_fix
.line_length
;
89 /* size_total -- all video memory we have. Used for
90 * entries, ressource allocation and bounds
92 size_total
= screen_info
.lfb_size
;
93 if (size_total
< size_vmode
)
94 size_total
= size_vmode
;
96 /* size_remap -- the amount of video memory we are going to
97 * use for efifb. With modern cards it is no
98 * option to simply use size_total as that
99 * wastes plenty of kernel address space. */
100 size_remap
= size_vmode
* 2;
101 if (size_remap
< size_vmode
)
102 size_remap
= size_vmode
;
103 if (size_remap
> size_total
)
104 size_remap
= size_total
;
105 efifb_fix
.smem_len
= size_remap
;
107 if (!request_mem_region(efifb_fix
.smem_start
, size_total
, "efifb"))
108 /* We cannot make this fatal. Sometimes this comes from magic
109 spaces our resource handlers simply don't know about */
111 "efifb: cannot reserve video memory at 0x%lx\n",
112 efifb_fix
.smem_start
);
114 info
= framebuffer_alloc(sizeof(u32
) * 16, &dev
->dev
);
117 goto err_release_mem
;
119 info
->pseudo_palette
= info
->par
;
122 info
->screen_base
= ioremap(efifb_fix
.smem_start
, efifb_fix
.smem_len
);
123 if (!info
->screen_base
) {
124 printk(KERN_ERR
"efifb: abort, cannot ioremap video memory "
126 efifb_fix
.smem_len
, efifb_fix
.smem_start
);
131 printk(KERN_INFO
"efifb: framebuffer at 0x%lx, mapped to 0x%p, "
132 "using %dk, total %dk\n",
133 efifb_fix
.smem_start
, info
->screen_base
,
134 size_remap
/1024, size_total
/1024);
135 printk(KERN_INFO
"efifb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
136 efifb_defined
.xres
, efifb_defined
.yres
,
137 efifb_defined
.bits_per_pixel
, efifb_fix
.line_length
,
140 efifb_defined
.xres_virtual
= efifb_defined
.xres
;
141 efifb_defined
.yres_virtual
= efifb_fix
.smem_len
/
142 efifb_fix
.line_length
;
143 printk(KERN_INFO
"efifb: scrolling: redraw\n");
144 efifb_defined
.yres_virtual
= efifb_defined
.yres
;
146 /* some dummy values for timing to make fbset happy */
147 efifb_defined
.pixclock
= 10000000 / efifb_defined
.xres
*
148 1000 / efifb_defined
.yres
;
149 efifb_defined
.left_margin
= (efifb_defined
.xres
/ 8) & 0xf8;
150 efifb_defined
.hsync_len
= (efifb_defined
.xres
/ 8) & 0xf8;
152 efifb_defined
.red
.offset
= screen_info
.red_pos
;
153 efifb_defined
.red
.length
= screen_info
.red_size
;
154 efifb_defined
.green
.offset
= screen_info
.green_pos
;
155 efifb_defined
.green
.length
= screen_info
.green_size
;
156 efifb_defined
.blue
.offset
= screen_info
.blue_pos
;
157 efifb_defined
.blue
.length
= screen_info
.blue_size
;
158 efifb_defined
.transp
.offset
= screen_info
.rsvd_pos
;
159 efifb_defined
.transp
.length
= screen_info
.rsvd_size
;
161 printk(KERN_INFO
"efifb: %s: "
162 "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n",
164 screen_info
.rsvd_size
,
165 screen_info
.red_size
,
166 screen_info
.green_size
,
167 screen_info
.blue_size
,
168 screen_info
.rsvd_pos
,
170 screen_info
.green_pos
,
171 screen_info
.blue_pos
);
173 efifb_fix
.ypanstep
= 0;
174 efifb_fix
.ywrapstep
= 0;
176 info
->fbops
= &efifb_ops
;
177 info
->var
= efifb_defined
;
178 info
->fix
= efifb_fix
;
179 info
->flags
= FBINFO_FLAG_DEFAULT
;
181 if (fb_alloc_cmap(&info
->cmap
, 256, 0) < 0) {
185 if (register_framebuffer(info
) < 0) {
189 printk(KERN_INFO
"fb%d: %s frame buffer device\n",
190 info
->node
, info
->fix
.id
);
194 fb_dealloc_cmap(&info
->cmap
);
196 iounmap(info
->screen_base
);
197 framebuffer_release(info
);
199 release_mem_region(efifb_fix
.smem_start
, size_total
);
203 static struct platform_driver efifb_driver
= {
204 .probe
= efifb_probe
,
210 static struct platform_device efifb_device
= {
214 static int __init
efifb_init(void)
218 if (screen_info
.orig_video_isVGA
!= VIDEO_TYPE_EFI
)
221 ret
= platform_driver_register(&efifb_driver
);
224 ret
= platform_device_register(&efifb_device
);
226 platform_driver_unregister(&efifb_driver
);
230 module_init(efifb_init
);
232 MODULE_LICENSE("GPL");