1 #include <linux/kernel.h>
2 #include <linux/module.h>
3 #include <linux/errno.h>
4 #include <linux/string.h>
6 #include <linux/slab.h>
7 #include <linux/delay.h>
9 #include <linux/ioport.h>
10 #include <linux/init.h>
11 #include <linux/pci.h>
12 #include <linux/mm_types.h>
13 #include <linux/vmalloc.h>
14 #include <linux/pagemap.h>
15 #include <linux/screen_info.h>
16 #include <linux/console.h>
19 #include "sm750_accel.h"
20 #include "sm750_cursor.h"
24 * ssize_t lynxfb_ops_write(struct fb_info *info, const char __user *buf,
25 * size_t count, loff_t *ppos);
26 * ssize_t lynxfb_ops_read(struct fb_info *info, char __user *buf,
27 * size_t count, loff_t *ppos);
31 /* common var for all device */
32 static int g_hwcursor
= 1;
35 static const char *g_fbmode
[] = {NULL
, NULL
};
36 static const char *g_def_fbmode
= "1024x768-32@60";
37 static char *g_settings
;
38 static int g_dualview
;
39 static char *g_option
;
41 static const struct fb_videomode lynx750_ext
[] = {
42 /* 1024x600-60 VESA [1.71:1] */
43 {NULL
, 60, 1024, 600, 20423, 144, 40, 18, 1, 104, 3,
44 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
45 FB_VMODE_NONINTERLACED
},
47 /* 1024x600-70 VESA */
48 {NULL
, 70, 1024, 600, 17211, 152, 48, 21, 1, 104, 3,
49 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
50 FB_VMODE_NONINTERLACED
},
52 /* 1024x600-75 VESA */
53 {NULL
, 75, 1024, 600, 15822, 160, 56, 23, 1, 104, 3,
54 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
55 FB_VMODE_NONINTERLACED
},
57 /* 1024x600-85 VESA */
58 {NULL
, 85, 1024, 600, 13730, 168, 56, 26, 1, 112, 3,
59 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
60 FB_VMODE_NONINTERLACED
},
63 {NULL
, 60, 720, 480, 37427, 88, 16, 13, 1, 72, 3,
64 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
65 FB_VMODE_NONINTERLACED
},
67 /* 1280x720 [1.78:1] */
68 {NULL
, 60, 1280, 720, 13426, 162, 86, 22, 1, 136, 3,
69 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
70 FB_VMODE_NONINTERLACED
},
73 {NULL
, 60, 1280, 768, 12579, 192, 64, 20, 3, 128, 7,
74 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
75 FB_VMODE_NONINTERLACED
},
77 /* 1360 x 768 [1.77083:1] */
78 {NULL
, 60, 1360, 768, 11804, 208, 64, 23, 1, 144, 3,
79 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
80 FB_VMODE_NONINTERLACED
},
82 /* 1368 x 768 [1.78:1] */
83 {NULL
, 60, 1368, 768, 11647, 216, 72, 23, 1, 144, 3,
84 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
85 FB_VMODE_NONINTERLACED
},
87 /* 1440 x 900 [16:10] */
88 {NULL
, 60, 1440, 900, 9392, 232, 80, 28, 1, 152, 3,
89 FB_SYNC_VERT_HIGH_ACT
,
90 FB_VMODE_NONINTERLACED
},
92 /* 1440x960 [15:10] */
93 {NULL
, 60, 1440, 960, 8733, 240, 88, 30, 1, 152, 3,
94 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
95 FB_VMODE_NONINTERLACED
},
97 /* 1920x1080 [16:9] */
98 {NULL
, 60, 1920, 1080, 6734, 148, 88, 41, 1, 44, 3,
99 FB_SYNC_VERT_HIGH_ACT
,
100 FB_VMODE_NONINTERLACED
},
103 /* no hardware cursor supported under version 2.6.10, kernel bug */
104 static int lynxfb_ops_cursor(struct fb_info
*info
, struct fb_cursor
*fbcursor
)
106 struct lynxfb_par
*par
;
107 struct lynxfb_crtc
*crtc
;
108 struct lynx_cursor
*cursor
;
112 cursor
= &crtc
->cursor
;
114 if (fbcursor
->image
.width
> cursor
->maxW
||
115 fbcursor
->image
.height
> cursor
->maxH
||
116 fbcursor
->image
.depth
> 1) {
120 sm750_hw_cursor_disable(cursor
);
121 if (fbcursor
->set
& FB_CUR_SETSIZE
)
122 sm750_hw_cursor_setSize(cursor
,
123 fbcursor
->image
.width
,
124 fbcursor
->image
.height
);
126 if (fbcursor
->set
& FB_CUR_SETPOS
)
127 sm750_hw_cursor_setPos(cursor
,
128 fbcursor
->image
.dx
- info
->var
.xoffset
,
129 fbcursor
->image
.dy
- info
->var
.yoffset
);
131 if (fbcursor
->set
& FB_CUR_SETCMAP
) {
132 /* get the 16bit color of kernel means */
135 fg
= ((info
->cmap
.red
[fbcursor
->image
.fg_color
] & 0xf800)) |
136 ((info
->cmap
.green
[fbcursor
->image
.fg_color
] & 0xfc00) >> 5) |
137 ((info
->cmap
.blue
[fbcursor
->image
.fg_color
] & 0xf800) >> 11);
139 bg
= ((info
->cmap
.red
[fbcursor
->image
.bg_color
] & 0xf800)) |
140 ((info
->cmap
.green
[fbcursor
->image
.bg_color
] & 0xfc00) >> 5) |
141 ((info
->cmap
.blue
[fbcursor
->image
.bg_color
] & 0xf800) >> 11);
143 sm750_hw_cursor_setColor(cursor
, fg
, bg
);
146 if (fbcursor
->set
& (FB_CUR_SETSHAPE
| FB_CUR_SETIMAGE
)) {
147 sm750_hw_cursor_setData(cursor
,
149 fbcursor
->image
.data
,
153 if (fbcursor
->enable
)
154 sm750_hw_cursor_enable(cursor
);
159 static void lynxfb_ops_fillrect(struct fb_info
*info
,
160 const struct fb_fillrect
*region
)
162 struct lynxfb_par
*par
;
163 struct sm750_dev
*sm750_dev
;
164 unsigned int base
, pitch
, Bpp
, rop
;
167 if (info
->state
!= FBINFO_STATE_RUNNING
)
171 sm750_dev
= par
->dev
;
174 * each time 2d function begin to work,below three variable always need
175 * be set, seems we can put them together in some place
177 base
= par
->crtc
.oScreen
;
178 pitch
= info
->fix
.line_length
;
179 Bpp
= info
->var
.bits_per_pixel
>> 3;
181 color
= (Bpp
== 1) ? region
->color
:
182 ((u32
*)info
->pseudo_palette
)[region
->color
];
183 rop
= (region
->rop
!= ROP_COPY
) ? HW_ROP2_XOR
: HW_ROP2_COPY
;
186 * If not use spin_lock, system will die if user load driver
187 * and immediately unload driver frequently (dual)
188 * since they fb_count could change during the lifetime of
189 * this lock, we are holding it for all cases.
191 spin_lock(&sm750_dev
->slock
);
193 sm750_dev
->accel
.de_fillrect(&sm750_dev
->accel
,
195 region
->dx
, region
->dy
,
196 region
->width
, region
->height
,
198 spin_unlock(&sm750_dev
->slock
);
201 static void lynxfb_ops_copyarea(struct fb_info
*info
,
202 const struct fb_copyarea
*region
)
204 struct lynxfb_par
*par
;
205 struct sm750_dev
*sm750_dev
;
206 unsigned int base
, pitch
, Bpp
;
209 sm750_dev
= par
->dev
;
212 * each time 2d function begin to work,below three variable always need
213 * be set, seems we can put them together in some place
215 base
= par
->crtc
.oScreen
;
216 pitch
= info
->fix
.line_length
;
217 Bpp
= info
->var
.bits_per_pixel
>> 3;
220 * If not use spin_lock, system will die if user load driver
221 * and immediately unload driver frequently (dual)
222 * since they fb_count could change during the lifetime of
223 * this lock, we are holding it for all cases.
225 spin_lock(&sm750_dev
->slock
);
227 sm750_dev
->accel
.de_copyarea(&sm750_dev
->accel
,
228 base
, pitch
, region
->sx
, region
->sy
,
229 base
, pitch
, Bpp
, region
->dx
, region
->dy
,
230 region
->width
, region
->height
,
232 spin_unlock(&sm750_dev
->slock
);
235 static void lynxfb_ops_imageblit(struct fb_info
*info
,
236 const struct fb_image
*image
)
238 unsigned int base
, pitch
, Bpp
;
239 unsigned int fgcol
, bgcol
;
240 struct lynxfb_par
*par
;
241 struct sm750_dev
*sm750_dev
;
244 sm750_dev
= par
->dev
;
246 * each time 2d function begin to work,below three variable always need
247 * be set, seems we can put them together in some place
249 base
= par
->crtc
.oScreen
;
250 pitch
= info
->fix
.line_length
;
251 Bpp
= info
->var
.bits_per_pixel
>> 3;
253 /* TODO: Implement hardware acceleration for image->depth > 1 */
254 if (image
->depth
!= 1) {
255 cfb_imageblit(info
, image
);
259 if (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
||
260 info
->fix
.visual
== FB_VISUAL_DIRECTCOLOR
) {
261 fgcol
= ((u32
*)info
->pseudo_palette
)[image
->fg_color
];
262 bgcol
= ((u32
*)info
->pseudo_palette
)[image
->bg_color
];
264 fgcol
= image
->fg_color
;
265 bgcol
= image
->bg_color
;
269 * If not use spin_lock, system will die if user load driver
270 * and immediately unload driver frequently (dual)
271 * since they fb_count could change during the lifetime of
272 * this lock, we are holding it for all cases.
274 spin_lock(&sm750_dev
->slock
);
276 sm750_dev
->accel
.de_imageblit(&sm750_dev
->accel
,
277 image
->data
, image
->width
>> 3, 0,
279 image
->dx
, image
->dy
,
280 image
->width
, image
->height
,
281 fgcol
, bgcol
, HW_ROP2_COPY
);
282 spin_unlock(&sm750_dev
->slock
);
285 static int lynxfb_ops_pan_display(struct fb_var_screeninfo
*var
,
286 struct fb_info
*info
)
288 struct lynxfb_par
*par
;
289 struct lynxfb_crtc
*crtc
;
296 return hw_sm750_pan_display(crtc
, var
, info
);
299 static int lynxfb_ops_set_par(struct fb_info
*info
)
301 struct lynxfb_par
*par
;
302 struct lynxfb_crtc
*crtc
;
303 struct lynxfb_output
*output
;
304 struct fb_var_screeninfo
*var
;
305 struct fb_fix_screeninfo
*fix
;
307 unsigned int line_length
;
315 output
= &par
->output
;
319 /* fix structure is not so FIX ... */
320 line_length
= var
->xres_virtual
* var
->bits_per_pixel
/ 8;
321 line_length
= ALIGN(line_length
, crtc
->line_pad
);
322 fix
->line_length
= line_length
;
323 pr_info("fix->line_length = %d\n", fix
->line_length
);
326 * var->red,green,blue,transp are need to be set by driver
327 * and these data should be set before setcolreg routine
330 switch (var
->bits_per_pixel
) {
332 fix
->visual
= FB_VISUAL_PSEUDOCOLOR
;
335 var
->green
.offset
= 0;
336 var
->green
.length
= 8;
337 var
->blue
.offset
= 0;
338 var
->blue
.length
= 8;
339 var
->transp
.length
= 0;
340 var
->transp
.offset
= 0;
343 var
->red
.offset
= 11;
345 var
->green
.offset
= 5;
346 var
->green
.length
= 6;
347 var
->blue
.offset
= 0;
348 var
->blue
.length
= 5;
349 var
->transp
.length
= 0;
350 var
->transp
.offset
= 0;
351 fix
->visual
= FB_VISUAL_TRUECOLOR
;
355 var
->red
.offset
= 16;
357 var
->green
.offset
= 8;
358 var
->green
.length
= 8;
359 var
->blue
.offset
= 0;
360 var
->blue
.length
= 8;
361 fix
->visual
= FB_VISUAL_TRUECOLOR
;
367 var
->height
= var
->width
= -1;
368 var
->accel_flags
= 0;/*FB_ACCELF_TEXT;*/
371 pr_err("pixel bpp format not satisfied\n.");
374 ret
= hw_sm750_crtc_setMode(crtc
, var
, fix
);
376 ret
= hw_sm750_output_setMode(output
, var
, fix
);
380 static inline unsigned int chan_to_field(unsigned int chan
,
381 struct fb_bitfield
*bf
)
384 chan
>>= 16 - bf
->length
;
385 return chan
<< bf
->offset
;
389 static int lynxfb_suspend(struct pci_dev
*pdev
, pm_message_t mesg
)
391 struct fb_info
*info
;
392 struct sm750_dev
*sm750_dev
;
395 if (mesg
.event
== pdev
->dev
.power
.power_state
.event
)
399 sm750_dev
= pci_get_drvdata(pdev
);
400 switch (mesg
.event
) {
401 case PM_EVENT_FREEZE
:
402 case PM_EVENT_PRETHAW
:
403 pdev
->dev
.power
.power_state
= mesg
;
408 if (mesg
.event
& PM_EVENT_SLEEP
) {
409 info
= sm750_dev
->fbinfo
[0];
411 /* 1 means do suspend */
412 fb_set_suspend(info
, 1);
413 info
= sm750_dev
->fbinfo
[1];
415 /* 1 means do suspend */
416 fb_set_suspend(info
, 1);
418 ret
= pci_save_state(pdev
);
421 "error:%d occurred in pci_save_state\n", ret
);
422 goto lynxfb_suspend_err
;
425 ret
= pci_set_power_state(pdev
, pci_choose_state(pdev
, mesg
));
428 "error:%d occurred in pci_set_power_state\n",
430 goto lynxfb_suspend_err
;
434 pdev
->dev
.power
.power_state
= mesg
;
441 static int lynxfb_resume(struct pci_dev
*pdev
)
443 struct fb_info
*info
;
444 struct sm750_dev
*sm750_dev
;
446 struct lynxfb_par
*par
;
447 struct lynxfb_crtc
*crtc
;
448 struct lynx_cursor
*cursor
;
453 sm750_dev
= pci_get_drvdata(pdev
);
457 ret
= pci_set_power_state(pdev
, PCI_D0
);
460 "error:%d occurred in pci_set_power_state\n", ret
);
461 goto lynxfb_resume_err
;
464 if (pdev
->dev
.power
.power_state
.event
!= PM_EVENT_FREEZE
) {
465 pci_restore_state(pdev
);
466 ret
= pci_enable_device(pdev
);
469 "error:%d occurred in pci_enable_device\n",
471 goto lynxfb_resume_err
;
473 pci_set_master(pdev
);
476 hw_sm750_inithw(sm750_dev
, pdev
);
478 info
= sm750_dev
->fbinfo
[0];
483 cursor
= &crtc
->cursor
;
484 memset_io(cursor
->vstart
, 0x0, cursor
->size
);
485 memset_io(crtc
->vScreen
, 0x0, crtc
->vidmem_size
);
486 lynxfb_ops_set_par(info
);
487 fb_set_suspend(info
, 0);
490 info
= sm750_dev
->fbinfo
[1];
495 cursor
= &crtc
->cursor
;
496 memset_io(cursor
->vstart
, 0x0, cursor
->size
);
497 memset_io(crtc
->vScreen
, 0x0, crtc
->vidmem_size
);
498 lynxfb_ops_set_par(info
);
499 fb_set_suspend(info
, 0);
502 pdev
->dev
.power
.power_state
.event
= PM_EVENT_RESUME
;
510 static int lynxfb_ops_check_var(struct fb_var_screeninfo
*var
,
511 struct fb_info
*info
)
513 struct lynxfb_par
*par
;
514 struct lynxfb_crtc
*crtc
;
515 struct lynxfb_output
*output
;
516 resource_size_t request
;
520 output
= &par
->output
;
522 pr_debug("check var:%dx%d-%d\n",
525 var
->bits_per_pixel
);
527 switch (var
->bits_per_pixel
) {
529 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
532 var
->green
.offset
= 0;
533 var
->green
.length
= 8;
534 var
->blue
.offset
= 0;
535 var
->blue
.length
= 8;
536 var
->transp
.length
= 0;
537 var
->transp
.offset
= 0;
540 var
->red
.offset
= 11;
542 var
->green
.offset
= 5;
543 var
->green
.length
= 6;
544 var
->blue
.offset
= 0;
545 var
->blue
.length
= 5;
546 var
->transp
.length
= 0;
547 var
->transp
.offset
= 0;
548 info
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
552 var
->red
.offset
= 16;
554 var
->green
.offset
= 8;
555 var
->green
.length
= 8;
556 var
->blue
.offset
= 0;
557 var
->blue
.length
= 8;
558 info
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
561 pr_err("bpp %d not supported\n", var
->bits_per_pixel
);
564 var
->height
= var
->width
= -1;
565 var
->accel_flags
= 0;/* FB_ACCELF_TEXT; */
567 /* check if current fb's video memory big enought to hold the onscreen*/
568 request
= var
->xres_virtual
* (var
->bits_per_pixel
>> 3);
569 /* defaulty crtc->channel go with par->index */
571 request
= ALIGN(request
, crtc
->line_pad
);
572 request
= request
* var
->yres_virtual
;
573 if (crtc
->vidmem_size
< request
) {
574 pr_err("not enough video memory for mode\n");
578 return hw_sm750_crtc_checkMode(crtc
, var
);
581 static int lynxfb_ops_setcolreg(unsigned int regno
,
586 struct fb_info
*info
)
588 struct lynxfb_par
*par
;
589 struct lynxfb_crtc
*crtc
;
590 struct fb_var_screeninfo
*var
;
599 pr_err("regno = %d\n", regno
);
603 if (info
->var
.grayscale
)
604 red
= green
= blue
= (red
* 77 + green
* 151 + blue
* 28) >> 8;
606 if (var
->bits_per_pixel
== 8 &&
607 info
->fix
.visual
== FB_VISUAL_PSEUDOCOLOR
) {
611 ret
= hw_sm750_setColReg(crtc
, regno
, red
, green
, blue
);
615 if (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
&& regno
< 256) {
618 if (var
->bits_per_pixel
== 16 ||
619 var
->bits_per_pixel
== 32 ||
620 var
->bits_per_pixel
== 24) {
621 val
= chan_to_field(red
, &var
->red
);
622 val
|= chan_to_field(green
, &var
->green
);
623 val
|= chan_to_field(blue
, &var
->blue
);
624 par
->pseudo_palette
[regno
] = val
;
635 static int lynxfb_ops_blank(int blank
, struct fb_info
*info
)
637 struct lynxfb_par
*par
;
638 struct lynxfb_output
*output
;
640 pr_debug("blank = %d.\n", blank
);
642 output
= &par
->output
;
643 return output
->proc_setBLANK(output
, blank
);
646 static int sm750fb_set_drv(struct lynxfb_par
*par
)
649 struct sm750_dev
*sm750_dev
;
650 struct lynxfb_output
*output
;
651 struct lynxfb_crtc
*crtc
;
655 sm750_dev
= par
->dev
;
656 output
= &par
->output
;
659 crtc
->vidmem_size
= sm750_dev
->vidmem_size
;
660 if (sm750_dev
->fb_count
> 1)
661 crtc
->vidmem_size
>>= 1;
663 /* setup crtc and output member */
664 sm750_dev
->hwCursor
= g_hwcursor
;
671 output
->proc_setBLANK
= (sm750_dev
->revid
== SM750LE_REVISION_ID
) ?
672 hw_sm750le_setBLANK
: hw_sm750_setBLANK
;
673 /* chip specific phase */
674 sm750_dev
->accel
.de_wait
= (sm750_dev
->revid
== SM750LE_REVISION_ID
) ?
675 hw_sm750le_deWait
: hw_sm750_deWait
;
676 switch (sm750_dev
->dataflow
) {
677 case sm750_simul_pri
:
678 output
->paths
= sm750_pnc
;
679 crtc
->channel
= sm750_primary
;
681 crtc
->vScreen
= sm750_dev
->pvMem
;
682 pr_info("use simul primary mode\n");
684 case sm750_simul_sec
:
685 output
->paths
= sm750_pnc
;
686 crtc
->channel
= sm750_secondary
;
688 crtc
->vScreen
= sm750_dev
->pvMem
;
690 case sm750_dual_normal
:
691 if (par
->index
== 0) {
692 output
->paths
= sm750_panel
;
693 crtc
->channel
= sm750_primary
;
695 crtc
->vScreen
= sm750_dev
->pvMem
;
697 output
->paths
= sm750_crt
;
698 crtc
->channel
= sm750_secondary
;
699 /* not consider of padding stuffs for oScreen,need fix */
700 crtc
->oScreen
= (sm750_dev
->vidmem_size
>> 1);
701 crtc
->vScreen
= sm750_dev
->pvMem
+ crtc
->oScreen
;
704 case sm750_dual_swap
:
705 if (par
->index
== 0) {
706 output
->paths
= sm750_panel
;
707 crtc
->channel
= sm750_secondary
;
709 crtc
->vScreen
= sm750_dev
->pvMem
;
711 output
->paths
= sm750_crt
;
712 crtc
->channel
= sm750_primary
;
713 /* not consider of padding stuffs for oScreen,need fix */
714 crtc
->oScreen
= (sm750_dev
->vidmem_size
>> 1);
715 crtc
->vScreen
= sm750_dev
->pvMem
+ crtc
->oScreen
;
725 static struct fb_ops lynxfb_ops
= {
726 .owner
= THIS_MODULE
,
727 .fb_check_var
= lynxfb_ops_check_var
,
728 .fb_set_par
= lynxfb_ops_set_par
,
729 .fb_setcolreg
= lynxfb_ops_setcolreg
,
730 .fb_blank
= lynxfb_ops_blank
,
731 .fb_fillrect
= cfb_fillrect
,
732 .fb_imageblit
= cfb_imageblit
,
733 .fb_copyarea
= cfb_copyarea
,
735 .fb_cursor
= lynxfb_ops_cursor
,
738 static int lynxfb_set_fbinfo(struct fb_info
*info
, int index
)
741 struct lynxfb_par
*par
;
742 struct sm750_dev
*sm750_dev
;
743 struct lynxfb_crtc
*crtc
;
744 struct lynxfb_output
*output
;
745 struct fb_var_screeninfo
*var
;
746 struct fb_fix_screeninfo
*fix
;
748 const struct fb_videomode
*pdb
[] = {
749 lynx750_ext
, NULL
, vesa_modes
,
751 int cdb
[] = {ARRAY_SIZE(lynx750_ext
), 0, VESA_MODEDB_SIZE
};
752 static const char *mdb_desc
[] = {
753 "driver prepared modes",
754 "kernel prepared default modedb",
755 "kernel HELPERS prepared vesa_modes",
758 static const char *fixId
[2] = {
759 "sm750_fb1", "sm750_fb2",
762 int ret
, line_length
;
765 par
= (struct lynxfb_par
*)info
->par
;
766 sm750_dev
= par
->dev
;
768 output
= &par
->output
;
774 output
->channel
= &crtc
->channel
;
775 sm750fb_set_drv(par
);
776 lynxfb_ops
.fb_pan_display
= lynxfb_ops_pan_display
;
779 * set current cursor variable and proc pointer,
780 * must be set after crtc member initialized
782 crtc
->cursor
.offset
= crtc
->oScreen
+ crtc
->vidmem_size
- 1024;
783 crtc
->cursor
.mmio
= sm750_dev
->pvReg
+
784 0x800f0 + (int)crtc
->channel
* 0x140;
786 pr_info("crtc->cursor.mmio = %p\n", crtc
->cursor
.mmio
);
787 crtc
->cursor
.maxH
= crtc
->cursor
.maxW
= 64;
788 crtc
->cursor
.size
= crtc
->cursor
.maxH
* crtc
->cursor
.maxW
* 2 / 8;
789 crtc
->cursor
.vstart
= sm750_dev
->pvMem
+ crtc
->cursor
.offset
;
791 memset_io(crtc
->cursor
.vstart
, 0, crtc
->cursor
.size
);
793 lynxfb_ops
.fb_cursor
= NULL
;
794 sm750_hw_cursor_disable(&crtc
->cursor
);
797 /* set info->fbops, must be set before fb_find_mode */
798 if (!sm750_dev
->accel_off
) {
799 /* use 2d acceleration */
800 lynxfb_ops
.fb_fillrect
= lynxfb_ops_fillrect
;
801 lynxfb_ops
.fb_copyarea
= lynxfb_ops_copyarea
;
802 lynxfb_ops
.fb_imageblit
= lynxfb_ops_imageblit
;
804 info
->fbops
= &lynxfb_ops
;
806 if (!g_fbmode
[index
]) {
807 g_fbmode
[index
] = g_def_fbmode
;
809 g_fbmode
[index
] = g_fbmode
[0];
812 for (i
= 0; i
< 3; i
++) {
813 ret
= fb_find_mode(var
, info
, g_fbmode
[index
],
814 pdb
[i
], cdb
[i
], NULL
, 8);
817 pr_info("success! use specified mode:%s in %s\n",
821 } else if (ret
== 2) {
822 pr_warn("use specified mode:%s in %s,with an ignored refresh rate\n",
826 } else if (ret
== 3) {
827 pr_warn("wanna use default mode\n");
829 } else if (ret
== 4) {
830 pr_warn("fall back to any valid mode\n");
832 pr_warn("ret = %d,fb_find_mode failed,with %s\n",
838 /* some member of info->var had been set by fb_find_mode */
840 pr_info("Member of info->var is :\n"
847 "bits_per_pixel=%d\n"
855 var
->bits_per_pixel
);
861 line_length
= ALIGN((var
->xres_virtual
* var
->bits_per_pixel
/ 8),
864 info
->pseudo_palette
= &par
->pseudo_palette
[0];
865 info
->screen_base
= crtc
->vScreen
;
866 pr_debug("screen_base vaddr = %p\n", info
->screen_base
);
867 info
->screen_size
= line_length
* var
->yres_virtual
;
868 info
->flags
= FBINFO_FLAG_DEFAULT
| 0;
871 fix
->type
= FB_TYPE_PACKED_PIXELS
;
873 fix
->xpanstep
= crtc
->xpanstep
;
874 fix
->ypanstep
= crtc
->ypanstep
;
875 fix
->ywrapstep
= crtc
->ywrapstep
;
876 fix
->accel
= FB_ACCEL_SMI
;
878 strlcpy(fix
->id
, fixId
[index
], sizeof(fix
->id
));
880 fix
->smem_start
= crtc
->oScreen
+ sm750_dev
->vidmem_start
;
881 pr_info("fix->smem_start = %lx\n", fix
->smem_start
);
883 * according to mmap experiment from user space application,
884 * fix->mmio_len should not larger than virtual size
885 * (xres_virtual x yres_virtual x ByPP)
886 * Below line maybe buggy when user mmap fb dev node and write
887 * data into the bound over virtual size
889 fix
->smem_len
= crtc
->vidmem_size
;
890 pr_info("fix->smem_len = %x\n", fix
->smem_len
);
891 info
->screen_size
= fix
->smem_len
;
892 fix
->line_length
= line_length
;
893 fix
->mmio_start
= sm750_dev
->vidreg_start
;
894 pr_info("fix->mmio_start = %lx\n", fix
->mmio_start
);
895 fix
->mmio_len
= sm750_dev
->vidreg_size
;
896 pr_info("fix->mmio_len = %x\n", fix
->mmio_len
);
897 switch (var
->bits_per_pixel
) {
899 fix
->visual
= FB_VISUAL_PSEUDOCOLOR
;
903 fix
->visual
= FB_VISUAL_TRUECOLOR
;
908 var
->activate
= FB_ACTIVATE_NOW
;
909 var
->accel_flags
= 0;
910 var
->vmode
= FB_VMODE_NONINTERLACED
;
912 pr_debug("#1 show info->cmap :\nstart=%d,len=%d,red=%p,green=%p,blue=%p,transp=%p\n",
913 info
->cmap
.start
, info
->cmap
.len
,
914 info
->cmap
.red
, info
->cmap
.green
, info
->cmap
.blue
,
917 ret
= fb_alloc_cmap(&info
->cmap
, 256, 0);
919 pr_err("Could not allocate memory for cmap.\n");
923 pr_debug("#2 show info->cmap :\nstart=%d,len=%d,red=%p,green=%p,blue=%p,transp=%p\n",
924 info
->cmap
.start
, info
->cmap
.len
,
925 info
->cmap
.red
, info
->cmap
.green
, info
->cmap
.blue
,
929 lynxfb_ops_check_var(var
, info
);
933 /* chip specific g_option configuration routine */
934 static void sm750fb_setup(struct sm750_dev
*sm750_dev
, char *src
)
941 sm750_dev
->initParm
.chip_clk
= 0;
942 sm750_dev
->initParm
.mem_clk
= 0;
943 sm750_dev
->initParm
.master_clk
= 0;
944 sm750_dev
->initParm
.powerMode
= 0;
945 sm750_dev
->initParm
.setAllEngOff
= 0;
946 sm750_dev
->initParm
.resetMemory
= 1;
948 /* defaultly turn g_hwcursor on for both view */
952 dev_warn(&sm750_dev
->pdev
->dev
, "no specific g_option.\n");
956 while ((opt
= strsep(&src
, ":")) != NULL
&& *opt
!= 0) {
957 dev_info(&sm750_dev
->pdev
->dev
, "opt=%s\n", opt
);
958 dev_info(&sm750_dev
->pdev
->dev
, "src=%s\n", src
);
960 if (!strncmp(opt
, "swap", strlen("swap"))) {
962 } else if (!strncmp(opt
, "nocrt", strlen("nocrt"))) {
963 sm750_dev
->nocrt
= 1;
964 } else if (!strncmp(opt
, "36bit", strlen("36bit"))) {
965 sm750_dev
->pnltype
= sm750_doubleTFT
;
966 } else if (!strncmp(opt
, "18bit", strlen("18bit"))) {
967 sm750_dev
->pnltype
= sm750_dualTFT
;
968 } else if (!strncmp(opt
, "24bit", strlen("24bit"))) {
969 sm750_dev
->pnltype
= sm750_24TFT
;
970 } else if (!strncmp(opt
, "nohwc0", strlen("nohwc0"))) {
972 } else if (!strncmp(opt
, "nohwc1", strlen("nohwc1"))) {
974 } else if (!strncmp(opt
, "nohwc", strlen("nohwc"))) {
979 dev_info(&sm750_dev
->pdev
->dev
,
980 "find fbmode0 : %s\n", g_fbmode
[0]);
981 } else if (!g_fbmode
[1]) {
983 dev_info(&sm750_dev
->pdev
->dev
,
984 "find fbmode1 : %s\n", g_fbmode
[1]);
986 dev_warn(&sm750_dev
->pdev
->dev
, "How many view you wann set?\n");
992 if (sm750_dev
->revid
!= SM750LE_REVISION_ID
) {
993 if (sm750_dev
->fb_count
> 1) {
995 sm750_dev
->dataflow
= sm750_dual_swap
;
997 sm750_dev
->dataflow
= sm750_dual_normal
;
1000 sm750_dev
->dataflow
= sm750_simul_sec
;
1002 sm750_dev
->dataflow
= sm750_simul_pri
;
1005 /* SM750LE only have one crt channel */
1006 sm750_dev
->dataflow
= sm750_simul_sec
;
1007 /* sm750le do not have complex attributes */
1008 sm750_dev
->nocrt
= 0;
1012 static void sm750fb_frambuffer_release(struct sm750_dev
*sm750_dev
)
1014 struct fb_info
*fb_info
;
1016 while (sm750_dev
->fb_count
) {
1017 fb_info
= sm750_dev
->fbinfo
[sm750_dev
->fb_count
- 1];
1018 unregister_framebuffer(fb_info
);
1019 framebuffer_release(fb_info
);
1020 sm750_dev
->fb_count
--;
1024 static int sm750fb_frambuffer_alloc(struct sm750_dev
*sm750_dev
, int fbidx
)
1026 struct fb_info
*fb_info
;
1027 struct lynxfb_par
*par
;
1030 fb_info
= framebuffer_alloc(sizeof(struct lynxfb_par
),
1031 &sm750_dev
->pdev
->dev
);
1035 sm750_dev
->fbinfo
[fbidx
] = fb_info
;
1037 par
->dev
= sm750_dev
;
1039 err
= lynxfb_set_fbinfo(fb_info
, fbidx
);
1043 err
= register_framebuffer(fb_info
);
1047 sm750_dev
->fb_count
++;
1052 framebuffer_release(fb_info
);
1056 static int lynxfb_kick_out_firmware_fb(struct pci_dev
*pdev
)
1058 struct apertures_struct
*ap
;
1059 bool primary
= false;
1061 ap
= alloc_apertures(1);
1065 ap
->ranges
[0].base
= pci_resource_start(pdev
, 0);
1066 ap
->ranges
[0].size
= pci_resource_len(pdev
, 0);
1068 primary
= pdev
->resource
[PCI_ROM_RESOURCE
].flags
&
1069 IORESOURCE_ROM_SHADOW
;
1071 remove_conflicting_framebuffers(ap
, "sm750_fb1", primary
);
1076 static int lynxfb_pci_probe(struct pci_dev
*pdev
,
1077 const struct pci_device_id
*ent
)
1079 struct sm750_dev
*sm750_dev
= NULL
;
1084 err
= lynxfb_kick_out_firmware_fb(pdev
);
1089 err
= pcim_enable_device(pdev
);
1094 sm750_dev
= devm_kzalloc(&pdev
->dev
, sizeof(*sm750_dev
), GFP_KERNEL
);
1098 sm750_dev
->fbinfo
[0] = sm750_dev
->fbinfo
[1] = NULL
;
1099 sm750_dev
->devid
= pdev
->device
;
1100 sm750_dev
->revid
= pdev
->revision
;
1101 sm750_dev
->pdev
= pdev
;
1102 sm750_dev
->mtrr_off
= g_nomtrr
;
1103 sm750_dev
->mtrr
.vram
= 0;
1104 sm750_dev
->accel_off
= g_noaccel
;
1105 spin_lock_init(&sm750_dev
->slock
);
1107 if (!sm750_dev
->accel_off
) {
1109 * hook deInit and 2d routines, notes that below hw_xxx
1110 * routine can work on most of lynx chips
1111 * if some chip need specific function,
1112 * please hook it in smXXX_set_drv routine
1114 sm750_dev
->accel
.de_init
= sm750_hw_de_init
;
1115 sm750_dev
->accel
.de_fillrect
= sm750_hw_fillrect
;
1116 sm750_dev
->accel
.de_copyarea
= sm750_hw_copyarea
;
1117 sm750_dev
->accel
.de_imageblit
= sm750_hw_imageblit
;
1120 /* call chip specific setup routine */
1121 sm750fb_setup(sm750_dev
, g_settings
);
1123 /* call chip specific mmap routine */
1124 err
= hw_sm750_map(sm750_dev
, pdev
);
1128 if (!sm750_dev
->mtrr_off
)
1129 sm750_dev
->mtrr
.vram
= arch_phys_wc_add(sm750_dev
->vidmem_start
,
1130 sm750_dev
->vidmem_size
);
1132 memset_io(sm750_dev
->pvMem
, 0, sm750_dev
->vidmem_size
);
1134 pci_set_drvdata(pdev
, sm750_dev
);
1136 /* call chipInit routine */
1137 hw_sm750_inithw(sm750_dev
, pdev
);
1139 /* allocate frame buffer info structures according to g_dualview */
1140 max_fb
= g_dualview
? 2 : 1;
1141 for (fbidx
= 0; fbidx
< max_fb
; fbidx
++) {
1142 err
= sm750fb_frambuffer_alloc(sm750_dev
, fbidx
);
1150 sm750fb_frambuffer_release(sm750_dev
);
1154 static void lynxfb_pci_remove(struct pci_dev
*pdev
)
1156 struct sm750_dev
*sm750_dev
;
1158 sm750_dev
= pci_get_drvdata(pdev
);
1160 sm750fb_frambuffer_release(sm750_dev
);
1161 arch_phys_wc_del(sm750_dev
->mtrr
.vram
);
1163 iounmap(sm750_dev
->pvReg
);
1164 iounmap(sm750_dev
->pvMem
);
1168 static int __init
lynxfb_setup(char *options
)
1173 if (!options
|| !*options
) {
1174 pr_warn("no options.\n");
1178 pr_info("options:%s\n", options
);
1180 len
= strlen(options
) + 1;
1181 g_settings
= kzalloc(len
, GFP_KERNEL
);
1189 * char * strsep(char **s,const char * ct);
1190 * @s: the string to be searched
1191 * @ct :the characters to search for
1193 * strsep() updates @options to pointer after the first found token
1194 * it also returns the pointer ahead the token.
1196 while ((opt
= strsep(&options
, ":")) != NULL
) {
1197 /* options that mean for any lynx chips are configured here */
1198 if (!strncmp(opt
, "noaccel", strlen("noaccel"))) {
1200 } else if (!strncmp(opt
, "nomtrr", strlen("nomtrr"))) {
1202 } else if (!strncmp(opt
, "dual", strlen("dual"))) {
1214 /* misc g_settings are transport to chip specific routines */
1215 pr_info("parameter left for chip specific analysis:%s\n", g_settings
);
1219 static const struct pci_device_id smi_pci_table
[] = {
1220 { PCI_DEVICE(0x126f, 0x0750), },
1224 MODULE_DEVICE_TABLE(pci
, smi_pci_table
);
1226 static struct pci_driver lynxfb_driver
= {
1228 .id_table
= smi_pci_table
,
1229 .probe
= lynxfb_pci_probe
,
1230 .remove
= lynxfb_pci_remove
,
1232 .suspend
= lynxfb_suspend
,
1233 .resume
= lynxfb_resume
,
1237 static int __init
lynxfb_init(void)
1244 if (fb_get_options("sm750fb", &option
))
1248 lynxfb_setup(option
);
1249 return pci_register_driver(&lynxfb_driver
);
1251 module_init(lynxfb_init
);
1253 static void __exit
lynxfb_exit(void)
1255 pci_unregister_driver(&lynxfb_driver
);
1257 module_exit(lynxfb_exit
);
1259 module_param(g_option
, charp
, 0444);
1261 MODULE_PARM_DESC(g_option
,
1262 "\n\t\tCommon options:\n"
1263 "\t\tnoaccel:disable 2d capabilities\n"
1264 "\t\tnomtrr:disable MTRR attribute for video memory\n"
1265 "\t\tdualview:dual frame buffer feature enabled\n"
1266 "\t\tnohwc:disable hardware cursor\n"
1267 "\t\tUsual example:\n"
1268 "\t\tinsmod ./sm750fb.ko g_option=\"noaccel,nohwc,1280x1024-8@60\"\n"
1271 MODULE_AUTHOR("monk liu <monk.liu@siliconmotion.com>");
1272 MODULE_AUTHOR("Sudip Mukherjee <sudip@vectorindia.org>");
1273 MODULE_DESCRIPTION("Frame buffer driver for SM750 chipset");
1274 MODULE_LICENSE("Dual BSD/GPL");