staging: sm750fb: Use kzalloc rather than kmalloc followed by memset with 0
[deliverable/linux.git] / drivers / staging / sm750fb / sm750.c
1 #include<linux/kernel.h>
2 #include<linux/module.h>
3 #include<linux/errno.h>
4 #include<linux/string.h>
5 #include<linux/mm.h>
6 #include<linux/slab.h>
7 #include<linux/delay.h>
8 #include<linux/fb.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/vmalloc.h>
17 #include<linux/pagemap.h>
18 #include <linux/console.h>
19 #ifdef CONFIG_MTRR
20 #include <asm/mtrr.h>
21 #endif
22 #include <asm/fb.h>
23 #include "sm750.h"
24 #include "sm750_hw.h"
25 #include "sm750_accel.h"
26 #include "sm750_cursor.h"
27
28 #include "modedb.h"
29
30 int smi_indent = 0;
31
32
33 /*
34 #ifdef __BIG_ENDIAN
35 ssize_t lynxfb_ops_write(struct fb_info *info, const char __user *buf,
36 size_t count, loff_t *ppos);
37 ssize_t lynxfb_ops_read(struct fb_info *info, char __user *buf,
38 size_t count, loff_t *ppos);
39 #endif
40 */
41
42 typedef void (*PROC_SPEC_SETUP)(struct lynx_share*,char *);
43 typedef int (*PROC_SPEC_MAP)(struct lynx_share*,struct pci_dev*);
44 typedef int (*PROC_SPEC_INITHW)(struct lynx_share*,struct pci_dev*);
45
46
47 /* common var for all device */
48 static int g_hwcursor = 1;
49 static int g_noaccel = 0;
50 #ifdef CONFIG_MTRR
51 static int g_nomtrr = 0;
52 #endif
53 static const char * g_fbmode[] = {NULL,NULL};
54 static const char * g_def_fbmode = "800x600-16@60";
55 static char * g_settings = NULL;
56 static int g_dualview = 0;
57 static char * g_option = NULL;
58
59 /* if not use spin_lock,system will die if user load driver
60 * and immediatly unload driver frequently (dual)*/
61 static inline void myspin_lock(spinlock_t * sl){
62 struct lynx_share * share;
63 share = container_of(sl,struct lynx_share,slock);
64 if(share->dual){
65 spin_lock(sl);
66 }
67 }
68
69 static inline void myspin_unlock(spinlock_t * sl){
70 struct lynx_share * share;
71 share = container_of(sl,struct lynx_share,slock);
72 if(share->dual){
73 spin_unlock(sl);
74 }
75 }
76 static const struct fb_videomode lynx750_ext[] = {
77 /* 1024x600-60 VESA [1.71:1] */
78 {NULL, 60, 1024, 600, 20423, 144, 40, 18, 1, 104, 3,
79 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},
80
81 /* 1024x600-70 VESA */
82 {NULL, 70, 1024, 600, 17211, 152, 48, 21, 1, 104, 3,
83 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},
84
85 /* 1024x600-75 VESA */
86 {NULL, 75, 1024, 600, 15822, 160, 56, 23, 1, 104, 3,
87 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},
88
89 /* 1024x600-85 VESA */
90 {NULL, 85, 1024, 600, 13730, 168, 56, 26, 1, 112, 3,
91 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},
92
93 /* 720x480 */
94 {NULL, 60, 720, 480, 37427, 88, 16, 13, 1, 72, 3,
95 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},
96
97 /* 1280x720 [1.78:1] */
98 {NULL, 60, 1280, 720, 13426, 162, 86, 22, 1, 136, 3,
99 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,FB_VMODE_NONINTERLACED},
100
101 /* 1280x768@60 */
102 {NULL,60,1280,768,12579,192,64,20,3,128,7,
103 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,FB_VMODE_NONINTERLACED},
104
105 {NULL,60,1360,768,11804,208,64,23,1,144,3,
106 FB_SYNC_HOR_HIGH_ACT|FB_VMODE_NONINTERLACED},
107
108 /* 1360 x 768 [1.77083:1] */
109 {NULL, 60, 1360, 768, 11804, 208, 64, 23, 1, 144, 3,
110 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},
111
112 /* 1368 x 768 [1.78:1] */
113 {NULL, 60, 1368, 768, 11647, 216, 72, 23, 1, 144, 3,
114 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},
115
116 /* 1440 x 900 [16:10] */
117 {NULL, 60, 1440, 900, 9392, 232, 80, 28, 1, 152, 3,
118 FB_SYNC_VERT_HIGH_ACT,FB_VMODE_NONINTERLACED},
119
120 /* 1440x960 [15:10] */
121 {NULL, 60, 1440, 960, 8733, 240, 88, 30, 1, 152, 3,
122 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED},
123
124 /* 1920x1080 [16:9] */
125 {NULL, 60, 1920, 1080, 6734, 148, 88, 41, 1, 44, 3,
126 FB_SYNC_VERT_HIGH_ACT,FB_VMODE_NONINTERLACED},
127 };
128
129
130
131
132 /* no hardware cursor supported under version 2.6.10, kernel bug */
133 static int lynxfb_ops_cursor(struct fb_info* info,struct fb_cursor* fbcursor)
134 {
135 struct lynxfb_par * par;
136 struct lynxfb_crtc * crtc;
137 struct lynx_cursor * cursor;
138
139 par = info->par;
140 crtc = &par->crtc;
141 cursor = &crtc->cursor;
142
143 if(fbcursor->image.width > cursor->maxW ||
144 fbcursor->image.height > cursor->maxH ||
145 fbcursor->image.depth > 1){
146 return -ENXIO;
147 }
148
149 cursor->disable(cursor);
150 if(fbcursor->set & FB_CUR_SETSIZE){
151 cursor->setSize(cursor,fbcursor->image.width,fbcursor->image.height);
152 }
153
154 if(fbcursor->set & FB_CUR_SETPOS){
155 cursor->setPos(cursor,fbcursor->image.dx - info->var.xoffset,
156 fbcursor->image.dy - info->var.yoffset);
157 }
158
159 if(fbcursor->set & FB_CUR_SETCMAP){
160 /* get the 16bit color of kernel means */
161 u16 fg,bg;
162 fg = ((info->cmap.red[fbcursor->image.fg_color] & 0xf800))|
163 ((info->cmap.green[fbcursor->image.fg_color] & 0xfc00) >> 5)|
164 ((info->cmap.blue[fbcursor->image.fg_color] & 0xf800) >> 11);
165
166 bg = ((info->cmap.red[fbcursor->image.bg_color] & 0xf800))|
167 ((info->cmap.green[fbcursor->image.bg_color] & 0xfc00) >> 5)|
168 ((info->cmap.blue[fbcursor->image.bg_color] & 0xf800) >> 11);
169
170 cursor->setColor(cursor,fg,bg);
171 }
172
173
174 if(fbcursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE))
175 {
176 cursor->setData(cursor,
177 fbcursor->rop,
178 fbcursor->image.data,
179 fbcursor->mask);
180 }
181
182 if(fbcursor->enable){
183 cursor->enable(cursor);
184 }
185
186 return 0;
187 }
188
189 static void lynxfb_ops_fillrect(struct fb_info* info,const struct fb_fillrect* region)
190 {
191 struct lynxfb_par * par;
192 struct lynx_share * share;
193 unsigned int base,pitch,Bpp,rop;
194 u32 color;
195
196 if(info->state != FBINFO_STATE_RUNNING){
197 return;
198 }
199
200 par = info->par;
201 share = par->share;
202
203 /* each time 2d function begin to work,below three variable always need
204 * be set, seems we can put them together in some place */
205 base = par->crtc.oScreen;
206 pitch = info->fix.line_length;
207 Bpp = info->var.bits_per_pixel >> 3;
208
209 color = (Bpp == 1)?region->color:((u32*)info->pseudo_palette)[region->color];
210 rop = ( region->rop != ROP_COPY ) ? HW_ROP2_XOR:HW_ROP2_COPY;
211
212 myspin_lock(&share->slock);
213 share->accel.de_fillrect(&share->accel,
214 base,pitch,Bpp,
215 region->dx,region->dy,
216 region->width,region->height,
217 color,rop);
218 myspin_unlock(&share->slock);
219 }
220
221 static void lynxfb_ops_copyarea(struct fb_info * info,const struct fb_copyarea * region)
222 {
223 struct lynxfb_par * par;
224 struct lynx_share * share;
225 unsigned int base,pitch,Bpp;
226
227 par = info->par;
228 share = par->share;
229
230 /* each time 2d function begin to work,below three variable always need
231 * be set, seems we can put them together in some place */
232 base = par->crtc.oScreen;
233 pitch = info->fix.line_length;
234 Bpp = info->var.bits_per_pixel >> 3;
235
236 myspin_lock(&share->slock);
237 share->accel.de_copyarea(&share->accel,
238 base,pitch,region->sx,region->sy,
239 base,pitch,Bpp,region->dx,region->dy,
240 region->width,region->height,HW_ROP2_COPY);
241 myspin_unlock(&share->slock);
242 }
243
244 static void lynxfb_ops_imageblit(struct fb_info*info,const struct fb_image* image)
245 {
246 unsigned int base,pitch,Bpp;
247 unsigned int fgcol,bgcol;
248 struct lynxfb_par * par;
249 struct lynx_share * share;
250
251 par = info->par;
252 share = par->share;
253 /* each time 2d function begin to work,below three variable always need
254 * be set, seems we can put them together in some place */
255 base = par->crtc.oScreen;
256 pitch = info->fix.line_length;
257 Bpp = info->var.bits_per_pixel >> 3;
258
259 if(image->depth == 1){
260 if(info->fix.visual == FB_VISUAL_TRUECOLOR ||
261 info->fix.visual == FB_VISUAL_DIRECTCOLOR)
262 {
263 fgcol = ((u32*)info->pseudo_palette)[image->fg_color];
264 bgcol = ((u32*)info->pseudo_palette)[image->bg_color];
265 }
266 else
267 {
268 fgcol = image->fg_color;
269 bgcol = image->bg_color;
270 }
271 goto _do_work;
272 }
273 return;
274 _do_work:
275 myspin_lock(&share->slock);
276 share->accel.de_imageblit(&share->accel,
277 image->data,image->width>>3,0,
278 base,pitch,Bpp,
279 image->dx,image->dy,
280 image->width,image->height,
281 fgcol,bgcol,HW_ROP2_COPY);
282 myspin_unlock(&share->slock);
283 }
284
285 static int lynxfb_ops_pan_display(struct fb_var_screeninfo *var,
286 struct fb_info *info)
287 {
288 struct lynxfb_par * par;
289 struct lynxfb_crtc * crtc;
290 int ret;
291
292
293 if(!info)
294 return -EINVAL;
295
296 ret = 0;
297 par = info->par;
298 crtc = &par->crtc;
299 ret = crtc->proc_panDisplay(crtc, var, info);
300
301 return ret;
302 }
303
304 static int lynxfb_ops_set_par(struct fb_info * info)
305 {
306 struct lynxfb_par * par;
307 struct lynx_share * share;
308 struct lynxfb_crtc * crtc;
309 struct lynxfb_output * output;
310 struct fb_var_screeninfo * var;
311 struct fb_fix_screeninfo * fix;
312 int ret;
313 unsigned int line_length;
314
315 if(!info)
316 return -EINVAL;
317
318 ret = 0;
319 par = info->par;
320 share = par->share;
321 crtc = &par->crtc;
322 output = &par->output;
323 var = &info->var;
324 fix = &info->fix;
325
326 /* fix structur is not so FIX ... */
327 line_length = var->xres_virtual * var->bits_per_pixel / 8;
328 line_length = PADDING(crtc->line_pad,line_length);
329 fix->line_length = line_length;
330 pr_err("fix->line_length = %d\n",fix->line_length);
331
332 /* var->red,green,blue,transp are need to be set by driver
333 * and these data should be set before setcolreg routine
334 * */
335
336 switch(var->bits_per_pixel){
337 case 8:
338 fix->visual = FB_VISUAL_PSEUDOCOLOR;
339 var->red.offset = 0;
340 var->red.length = 8;
341 var->green.offset = 0;
342 var->green.length = 8;
343 var->blue.offset = 0;
344 var->blue.length = 8;
345 var->transp.length = 0;
346 var->transp.offset = 0;
347 break;
348 case 16:
349 var->red.offset = 11;
350 var->red.length = 5;
351 var->green.offset = 5;
352 var->green.length = 6;
353 var->blue.offset = 0;
354 var->blue.length = 5;
355 var->transp.length = 0;
356 var->transp.offset = 0;
357 fix->visual = FB_VISUAL_TRUECOLOR;
358 break;
359 case 24:
360 case 32:
361 var->red.offset = 16;
362 var->red.length = 8;
363 var->green.offset = 8;
364 var->green.length = 8;
365 var->blue.offset = 0 ;
366 var->blue.length = 8;
367 fix->visual = FB_VISUAL_TRUECOLOR;
368 break;
369 default:
370 ret = -EINVAL;
371 break;
372 }
373 var->height = var->width = -1;
374 var->accel_flags = 0;/*FB_ACCELF_TEXT;*/
375
376 if(ret){
377 pr_err("pixel bpp format not satisfied\n.");
378 return ret;
379 }
380 ret = crtc->proc_setMode(crtc,var,fix);
381 if(!ret)
382 ret = output->proc_setMode(output,var,fix);
383 return ret;
384 }
385
386 static inline unsigned int chan_to_field(unsigned int chan,struct fb_bitfield * bf)
387 {
388 chan &= 0xffff;
389 chan >>= 16 - bf->length;
390 return chan << bf->offset;
391 }
392
393 #ifdef CONFIG_PM
394 static int lynxfb_suspend(struct pci_dev *pdev, pm_message_t mesg)
395 {
396 struct fb_info *info;
397 struct lynx_share *share;
398 int ret;
399
400 if (mesg.event == pdev->dev.power.power_state.event)
401 return 0;
402
403 ret = 0;
404 share = pci_get_drvdata(pdev);
405 switch (mesg.event) {
406 case PM_EVENT_FREEZE:
407 case PM_EVENT_PRETHAW:
408 pdev->dev.power.power_state = mesg;
409 return 0;
410 }
411
412 console_lock();
413 if (mesg.event & PM_EVENT_SLEEP) {
414 info = share->fbinfo[0];
415 if (info)
416 /* 1 means do suspend*/
417 fb_set_suspend(info, 1);
418 info = share->fbinfo[1];
419 if (info)
420 /* 1 means do suspend*/
421 fb_set_suspend(info, 1);
422
423 ret = pci_save_state(pdev);
424 if (ret) {
425 pr_err("error:%d occurred in pci_save_state\n", ret);
426 return ret;
427 }
428
429 /* set chip to sleep mode*/
430 if (share->suspend)
431 (*share->suspend)(share);
432
433 pci_disable_device(pdev);
434 ret = pci_set_power_state(pdev, pci_choose_state(pdev, mesg));
435 if (ret) {
436 pr_err("error:%d occurred in pci_set_power_state\n", ret);
437 return ret;
438 }
439 }
440
441 pdev->dev.power.power_state = mesg;
442 console_unlock();
443 return ret;
444 }
445
446 static int lynxfb_resume(struct pci_dev* pdev)
447 {
448 struct fb_info * info;
449 struct lynx_share * share;
450
451 struct lynxfb_par * par;
452 struct lynxfb_crtc * crtc;
453 struct lynx_cursor * cursor;
454
455 int ret;
456
457
458 ret = 0;
459 share = pci_get_drvdata(pdev);
460
461 console_lock();
462
463 if((ret = pci_set_power_state(pdev, PCI_D0)) != 0){
464 pr_err("error:%d occured in pci_set_power_state\n",ret);
465 return ret;
466 }
467
468
469 if(pdev->dev.power.power_state.event != PM_EVENT_FREEZE){
470 pci_restore_state(pdev);
471 if ((ret = pci_enable_device(pdev)) != 0){
472 pr_err("error:%d occured in pci_enable_device\n",ret);
473 return ret;
474 }
475 pci_set_master(pdev);
476 }
477 if(share->resume)
478 (*share->resume)(share);
479
480 hw_sm750_inithw(share,pdev);
481
482
483 info = share->fbinfo[0];
484
485 if(info){
486 par = info->par;
487 crtc = &par->crtc;
488 cursor = &crtc->cursor;
489 memset(cursor->vstart, 0x0, cursor->size);
490 memset(crtc->vScreen,0x0,crtc->vidmem_size);
491 lynxfb_ops_set_par(info);
492 fb_set_suspend(info, 0);
493 }
494
495 info = share->fbinfo[1];
496
497 if(info){
498 par = info->par;
499 crtc = &par->crtc;
500 cursor = &crtc->cursor;
501 memset(cursor->vstart, 0x0, cursor->size);
502 memset(crtc->vScreen,0x0,crtc->vidmem_size);
503 lynxfb_ops_set_par(info);
504 fb_set_suspend(info, 0);
505 }
506
507
508 console_unlock();
509 return ret;
510 }
511 #endif
512
513 static int lynxfb_ops_check_var(struct fb_var_screeninfo* var,struct fb_info* info)
514 {
515 struct lynxfb_par * par;
516 struct lynxfb_crtc * crtc;
517 struct lynxfb_output * output;
518 struct lynx_share * share;
519 int ret;
520 resource_size_t request;
521
522
523 par = info->par;
524 crtc = &par->crtc;
525 output = &par->output;
526 share = par->share;
527 ret = 0;
528
529 pr_debug("check var:%dx%d-%d\n",
530 var->xres,
531 var->yres,
532 var->bits_per_pixel);
533
534
535 switch(var->bits_per_pixel){
536 case 8:
537 case 16:
538 case 24: /* support 24 bpp for only lynx712/722/720 */
539 case 32:
540 break;
541 default:
542 pr_err("bpp %d not supported\n",var->bits_per_pixel);
543 ret = -EINVAL;
544 goto exit;
545 }
546
547 switch(var->bits_per_pixel){
548 case 8:
549 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
550 var->red.offset = 0;
551 var->red.length = 8;
552 var->green.offset = 0;
553 var->green.length = 8;
554 var->blue.offset = 0;
555 var->blue.length = 8;
556 var->transp.length = 0;
557 var->transp.offset = 0;
558 break;
559 case 16:
560 var->red.offset = 11;
561 var->red.length = 5;
562 var->green.offset = 5;
563 var->green.length = 6;
564 var->blue.offset = 0;
565 var->blue.length = 5;
566 var->transp.length = 0;
567 var->transp.offset = 0;
568 info->fix.visual = FB_VISUAL_TRUECOLOR;
569 break;
570 case 24:
571 case 32:
572 var->red.offset = 16;
573 var->red.length = 8;
574 var->green.offset = 8;
575 var->green.length = 8;
576 var->blue.offset = 0 ;
577 var->blue.length = 8;
578 info->fix.visual = FB_VISUAL_TRUECOLOR;
579 break;
580 default:
581 ret = -EINVAL;
582 break;
583 }
584 var->height = var->width = -1;
585 var->accel_flags = 0;/*FB_ACCELF_TEXT;*/
586
587 /* check if current fb's video memory big enought to hold the onscreen */
588 request = var->xres_virtual * (var->bits_per_pixel >> 3);
589 /* defaulty crtc->channel go with par->index */
590
591 request = PADDING(crtc->line_pad,request);
592 request = request * var->yres_virtual;
593 if(crtc->vidmem_size < request){
594 pr_err("not enough video memory for mode\n");
595 return -ENOMEM;
596 }
597
598 ret = output->proc_checkMode(output,var);
599 if(!ret)
600 ret = crtc->proc_checkMode(crtc,var);
601 exit:
602 return ret;
603 }
604
605
606 static int lynxfb_ops_setcolreg(unsigned regno,unsigned red,
607 unsigned green,unsigned blue,
608 unsigned transp,struct fb_info * info)
609 {
610 struct lynxfb_par * par;
611 struct lynxfb_crtc * crtc;
612 struct fb_var_screeninfo * var;
613 int ret;
614
615 par = info->par;
616 crtc = &par->crtc;
617 var = &info->var;
618 ret = 0;
619
620 //pr_debug("regno=%d,red=%d,green=%d,blue=%d\n",regno,red,green,blue);
621 if(regno > 256){
622 pr_err("regno = %d\n",regno);
623 return -EINVAL;
624 }
625
626 if(info->var.grayscale)
627 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
628
629 if(var->bits_per_pixel == 8 && info->fix.visual == FB_VISUAL_PSEUDOCOLOR)
630 {
631 red >>= 8;
632 green >>= 8;
633 blue >>= 8;
634 ret = crtc->proc_setColReg(crtc,regno,red,green,blue);
635 goto exit;
636 }
637
638
639 if(info->fix.visual == FB_VISUAL_TRUECOLOR && regno < 256 )
640 {
641 u32 val;
642 if(var->bits_per_pixel == 16 ||
643 var->bits_per_pixel == 32 ||
644 var->bits_per_pixel == 24)
645 {
646 val = chan_to_field(red,&var->red);
647 val |= chan_to_field(green,&var->green);
648 val |= chan_to_field(blue,&var->blue);
649 par->pseudo_palette[regno] = val;
650 goto exit;
651 }
652 }
653
654 ret = -EINVAL;
655
656 exit:
657 return ret;
658 }
659
660 static int lynxfb_ops_blank(int blank,struct fb_info* info)
661 {
662 struct lynxfb_par * par;
663 struct lynxfb_output * output;
664
665 pr_debug("blank = %d.\n",blank);
666 par = info->par;
667 output = &par->output;
668 return output->proc_setBLANK(output,blank);
669 }
670
671 static int sm750fb_set_drv(struct lynxfb_par * par)
672 {
673 int ret;
674 struct lynx_share * share;
675 struct sm750_share * spec_share;
676 struct lynxfb_output * output;
677 struct lynxfb_crtc * crtc;
678
679 ret = 0;
680
681 share = par->share;
682 spec_share = container_of(share,struct sm750_share,share);
683 output = &par->output;
684 crtc = &par->crtc;
685
686 crtc->vidmem_size = (share->dual)?share->vidmem_size>>1:share->vidmem_size;
687 /* setup crtc and output member */
688 spec_share->hwCursor = g_hwcursor;
689
690 crtc->proc_setMode = hw_sm750_crtc_setMode;
691 crtc->proc_checkMode = hw_sm750_crtc_checkMode;
692 crtc->proc_setColReg = hw_sm750_setColReg;
693 crtc->proc_panDisplay = hw_sm750_pan_display;
694 crtc->clear = hw_sm750_crtc_clear;
695 crtc->line_pad = 16;
696 //crtc->xpanstep = crtc->ypanstep = crtc->ywrapstep = 0;
697 crtc->xpanstep = 8;
698 crtc->ypanstep = 1;
699 crtc->ywrapstep = 0;
700
701 output->proc_setMode = hw_sm750_output_setMode;
702 output->proc_checkMode = hw_sm750_output_checkMode;
703
704 output->proc_setBLANK = (share->revid == SM750LE_REVISION_ID)?hw_sm750le_setBLANK:hw_sm750_setBLANK;
705 output->clear = hw_sm750_output_clear;
706 /* chip specific phase */
707 share->accel.de_wait = (share->revid == SM750LE_REVISION_ID)?hw_sm750le_deWait: hw_sm750_deWait;
708 switch (spec_share->state.dataflow)
709 {
710 case sm750_simul_pri:
711 output->paths = sm750_pnc;
712 crtc->channel = sm750_primary;
713 crtc->oScreen = 0;
714 crtc->vScreen = share->pvMem;
715 pr_info("use simul primary mode\n");
716 break;
717 case sm750_simul_sec:
718 output->paths = sm750_pnc;
719 crtc->channel = sm750_secondary;
720 crtc->oScreen = 0;
721 crtc->vScreen = share->pvMem;
722 break;
723 case sm750_dual_normal:
724 if(par->index == 0){
725 output->paths = sm750_panel;
726 crtc->channel = sm750_primary;
727 crtc->oScreen = 0;
728 crtc->vScreen = share->pvMem;
729 }else{
730 output->paths = sm750_crt;
731 crtc->channel = sm750_secondary;
732 /* not consider of padding stuffs for oScreen,need fix*/
733 crtc->oScreen = (share->vidmem_size >> 1);
734 crtc->vScreen = share->pvMem + crtc->oScreen;
735 }
736 break;
737 case sm750_dual_swap:
738 if(par->index == 0){
739 output->paths = sm750_panel;
740 crtc->channel = sm750_secondary;
741 crtc->oScreen = 0;
742 crtc->vScreen = share->pvMem;
743 }else{
744 output->paths = sm750_crt;
745 crtc->channel = sm750_primary;
746 /* not consider of padding stuffs for oScreen,need fix*/
747 crtc->oScreen = (share->vidmem_size >> 1);
748 crtc->vScreen = share->pvMem + crtc->oScreen;
749 }
750 break;
751 default:
752 ret = -EINVAL;
753 }
754
755 return ret;
756 }
757
758 static struct fb_ops lynxfb_ops={
759 .owner = THIS_MODULE,
760 .fb_check_var = lynxfb_ops_check_var,
761 .fb_set_par = lynxfb_ops_set_par,
762 .fb_setcolreg = lynxfb_ops_setcolreg,
763 .fb_blank = lynxfb_ops_blank,
764 .fb_fillrect = cfb_fillrect,
765 .fb_imageblit = cfb_imageblit,
766 .fb_copyarea = cfb_copyarea,
767 /* cursor */
768 .fb_cursor = lynxfb_ops_cursor,
769 };
770
771
772 static int lynxfb_set_fbinfo(struct fb_info* info,int index)
773 {
774 int i;
775 struct lynxfb_par * par;
776 struct lynx_share * share;
777 struct lynxfb_crtc * crtc;
778 struct lynxfb_output * output;
779 struct fb_var_screeninfo * var;
780 struct fb_fix_screeninfo * fix;
781
782 const struct fb_videomode * pdb[] = {
783 lynx750_ext, NULL,vesa_modes,
784 };
785 int cdb[] = {ARRAY_SIZE(lynx750_ext),0,VESA_MODEDB_SIZE};
786 static const char * mdb_desc[] ={
787 "driver prepared modes",
788 "kernel prepared default modedb",
789 "kernel HELPERS prepared vesa_modes",
790 };
791
792
793 static const char * fixId[2]=
794 {
795 "sm750_fb1","sm750_fb2",
796 };
797
798 int ret,line_length;
799
800 ret = 0;
801 par = (struct lynxfb_par *)info->par;
802 share = par->share;
803 crtc = &par->crtc;
804 output = &par->output;
805 var = &info->var;
806 fix = &info->fix;
807
808 /* set index */
809 par->index = index;
810 output->channel = &crtc->channel;
811 sm750fb_set_drv(par);
812 lynxfb_ops.fb_pan_display = lynxfb_ops_pan_display;
813
814
815 /* set current cursor variable and proc pointer,
816 * must be set after crtc member initialized */
817 crtc->cursor.offset = crtc->oScreen + crtc->vidmem_size - 1024;
818 crtc->cursor.mmio = share->pvReg + 0x800f0 + (int)crtc->channel * 0x140;
819
820 pr_info("crtc->cursor.mmio = %p\n",crtc->cursor.mmio);
821 crtc->cursor.maxH = crtc->cursor.maxW = 64;
822 crtc->cursor.size = crtc->cursor.maxH*crtc->cursor.maxW*2/8;
823 crtc->cursor.disable = hw_cursor_disable;
824 crtc->cursor.enable = hw_cursor_enable;
825 crtc->cursor.setColor = hw_cursor_setColor;
826 crtc->cursor.setPos = hw_cursor_setPos;
827 crtc->cursor.setSize = hw_cursor_setSize;
828 crtc->cursor.setData = hw_cursor_setData;
829 crtc->cursor.vstart = share->pvMem + crtc->cursor.offset;
830
831
832 crtc->cursor.share = share;
833 memset(crtc->cursor.vstart, 0, crtc->cursor.size);
834 if(!g_hwcursor){
835 lynxfb_ops.fb_cursor = NULL;
836 crtc->cursor.disable(&crtc->cursor);
837 }
838
839
840 /* set info->fbops, must be set before fb_find_mode */
841 if(!share->accel_off){
842 /* use 2d acceleration */
843 lynxfb_ops.fb_fillrect = lynxfb_ops_fillrect;
844 lynxfb_ops.fb_copyarea = lynxfb_ops_copyarea;
845 lynxfb_ops.fb_imageblit = lynxfb_ops_imageblit;
846 }
847 info->fbops = &lynxfb_ops;
848
849 if(!g_fbmode[index]){
850 g_fbmode[index] = g_def_fbmode;
851 if(index)
852 g_fbmode[index] = g_fbmode[0];
853 }
854
855
856 for(i=0;i<3;i++){
857
858 ret = fb_find_mode(var,info,g_fbmode[index],
859 pdb[i],cdb[i],NULL,8);
860
861 if(ret == 1){
862 pr_info("success! use specified mode:%s in %s\n",
863 g_fbmode[index],
864 mdb_desc[i]);
865 break;
866 }else if(ret == 2){
867 pr_warn("use specified mode:%s in %s,with an ignored refresh rate\n",
868 g_fbmode[index],
869 mdb_desc[i]);
870 break;
871 }else if(ret == 3){
872 pr_warn("wanna use default mode\n");
873 // break;
874 }else if(ret == 4){
875 pr_warn("fall back to any valid mode\n");
876 }else{
877 pr_warn("ret = %d,fb_find_mode failed,with %s\n",ret,mdb_desc[i]);
878 }
879 }
880
881 /* some member of info->var had been set by fb_find_mode */
882
883 pr_info("Member of info->var is :\n\
884 xres=%d\n\
885 yres=%d\n\
886 xres_virtual=%d\n\
887 yres_virtual=%d\n\
888 xoffset=%d\n\
889 yoffset=%d\n\
890 bits_per_pixel=%d\n \
891 ...\n",var->xres,var->yres,var->xres_virtual,var->yres_virtual,
892 var->xoffset,var->yoffset,var->bits_per_pixel);
893
894 /* set par */
895 par->info = info;
896
897 /* set info */
898 line_length = PADDING(crtc->line_pad,
899 (var->xres_virtual * var->bits_per_pixel/8));
900
901 info->pseudo_palette = &par->pseudo_palette[0];
902 info->screen_base = crtc->vScreen;
903 pr_debug("screen_base vaddr = %p\n",info->screen_base);
904 info->screen_size = line_length * var->yres_virtual;
905 info->flags = FBINFO_FLAG_DEFAULT|0;
906
907 /* set info->fix */
908 fix->type = FB_TYPE_PACKED_PIXELS;
909 fix->type_aux = 0;
910 fix->xpanstep = crtc->xpanstep;
911 fix->ypanstep = crtc->ypanstep;
912 fix->ywrapstep = crtc->ywrapstep;
913 fix->accel = FB_ACCEL_SMI;
914
915 strlcpy(fix->id,fixId[index],sizeof(fix->id));
916
917
918 fix->smem_start = crtc->oScreen + share->vidmem_start;
919 pr_info("fix->smem_start = %lx\n",fix->smem_start);
920 /* according to mmap experiment from user space application,
921 * fix->mmio_len should not larger than virtual size
922 * (xres_virtual x yres_virtual x ByPP)
923 * Below line maybe buggy when user mmap fb dev node and write
924 * data into the bound over virtual size
925 * */
926 fix->smem_len = crtc->vidmem_size;
927 pr_info("fix->smem_len = %x\n",fix->smem_len);
928 info->screen_size = fix->smem_len;
929 fix->line_length = line_length;
930 fix->mmio_start = share->vidreg_start;
931 pr_info("fix->mmio_start = %lx\n",fix->mmio_start);
932 fix->mmio_len = share->vidreg_size;
933 pr_info("fix->mmio_len = %x\n",fix->mmio_len);
934 switch(var->bits_per_pixel)
935 {
936 case 8:
937 fix->visual = FB_VISUAL_PSEUDOCOLOR;
938 break;
939 case 16:
940 case 32:
941 fix->visual = FB_VISUAL_TRUECOLOR;
942 break;
943 }
944
945 /* set var */
946 var->activate = FB_ACTIVATE_NOW;
947 var->accel_flags = 0;
948 var->vmode = FB_VMODE_NONINTERLACED;
949
950 pr_debug("#1 show info->cmap : \nstart=%d,len=%d,red=%p,green=%p,blue=%p,transp=%p\n",
951 info->cmap.start,info->cmap.len,
952 info->cmap.red,info->cmap.green,info->cmap.blue,
953 info->cmap.transp);
954
955 if((ret = fb_alloc_cmap(&info->cmap,256,0)) < 0){
956 pr_err("Could not allcate memory for cmap.\n");
957 goto exit;
958 }
959
960 pr_debug("#2 show info->cmap : \nstart=%d,len=%d,red=%p,green=%p,blue=%p,transp=%p\n",
961 info->cmap.start,info->cmap.len,
962 info->cmap.red,info->cmap.green,info->cmap.blue,
963 info->cmap.transp);
964
965 exit:
966 lynxfb_ops_check_var(var,info);
967 // lynxfb_ops_set_par(info);
968 return ret;
969 }
970
971 /* chip specific g_option configuration routine */
972 static void sm750fb_setup(struct lynx_share * share,char * src)
973 {
974 struct sm750_share * spec_share;
975 char * opt;
976 #ifdef CAP_EXPENSION
977 char * exp_res;
978 #endif
979 int swap;
980
981
982 spec_share = container_of(share,struct sm750_share,share);
983 #ifdef CAP_EXPENSIION
984 exp_res = NULL;
985 #endif
986 swap = 0;
987
988 spec_share->state.initParm.chip_clk = 0;
989 spec_share->state.initParm.mem_clk = 0;
990 spec_share->state.initParm.master_clk = 0;
991 spec_share->state.initParm.powerMode = 0;
992 spec_share->state.initParm.setAllEngOff = 0;
993 spec_share->state.initParm.resetMemory = 1;
994
995 /*defaultly turn g_hwcursor on for both view */
996 g_hwcursor = 3;
997
998 if(!src || !*src){
999 pr_warn("no specific g_option.\n");
1000 goto NO_PARAM;
1001 }
1002
1003 while((opt = strsep(&src,":")) != NULL && *opt != 0){
1004 pr_err("opt=%s\n",opt);
1005 pr_err("src=%s\n",src);
1006
1007 if(!strncmp(opt,"swap",strlen("swap")))
1008 swap = 1;
1009 else if(!strncmp(opt,"nocrt",strlen("nocrt")))
1010 spec_share->state.nocrt = 1;
1011 else if(!strncmp(opt,"36bit",strlen("36bit")))
1012 spec_share->state.pnltype = sm750_doubleTFT;
1013 else if(!strncmp(opt,"18bit",strlen("18bit")))
1014 spec_share->state.pnltype = sm750_dualTFT;
1015 else if(!strncmp(opt,"24bit",strlen("24bit")))
1016 spec_share->state.pnltype = sm750_24TFT;
1017 #ifdef CAP_EXPANSION
1018 else if(!strncmp(opt,"exp:",strlen("exp:")))
1019 exp_res = opt + strlen("exp:");
1020 #endif
1021 else if(!strncmp(opt,"nohwc0",strlen("nohwc0")))
1022 g_hwcursor &= ~0x1;
1023 else if(!strncmp(opt,"nohwc1",strlen("nohwc1")))
1024 g_hwcursor &= ~0x2;
1025 else if(!strncmp(opt,"nohwc",strlen("nohwc")))
1026 g_hwcursor = 0;
1027 else
1028 {
1029 if(!g_fbmode[0]){
1030 g_fbmode[0] = opt;
1031 pr_info("find fbmode0 : %s\n",g_fbmode[0]);
1032 }else if(!g_fbmode[1]){
1033 g_fbmode[1] = opt;
1034 pr_info("find fbmode1 : %s\n",g_fbmode[1]);
1035 }else{
1036 pr_warn("How many view you wann set?\n");
1037 }
1038 }
1039 }
1040 #ifdef CAP_EXPANSION
1041 if(getExpRes(exp_res,&spec_share->state.xLCD,&spec_share->state.yLCD))
1042 {
1043 /* seems exp_res is not valid*/
1044 spec_share->state.xLCD = spec_share->state.yLCD = 0;
1045 }
1046 #endif
1047
1048 NO_PARAM:
1049 if(share->revid != SM750LE_REVISION_ID){
1050 if(share->dual)
1051 {
1052 if(swap)
1053 spec_share->state.dataflow = sm750_dual_swap;
1054 else
1055 spec_share->state.dataflow = sm750_dual_normal;
1056 }else{
1057 if(swap)
1058 spec_share->state.dataflow = sm750_simul_sec;
1059 else
1060 spec_share->state.dataflow = sm750_simul_pri;
1061 }
1062 }else{
1063 /* SM750LE only have one crt channel */
1064 spec_share->state.dataflow = sm750_simul_sec;
1065 /* sm750le do not have complex attributes*/
1066 spec_share->state.nocrt = 0;
1067 }
1068 }
1069
1070 static int lynxfb_pci_probe(struct pci_dev * pdev,
1071 const struct pci_device_id * ent)
1072 {
1073 struct fb_info * info[] = {NULL,NULL};
1074 struct lynx_share * share = NULL;
1075
1076 struct sm750_share *spec_share = NULL;
1077 size_t spec_offset = 0;
1078 int fbidx;
1079
1080
1081 /* enable device */
1082 if(pci_enable_device(pdev)){
1083 pr_err("can not enable device.\n");
1084 goto err_enable;
1085 }
1086
1087 /* though offset of share in sm750_share is 0,
1088 * we use this marcro as the same */
1089 spec_offset = offsetof(struct sm750_share,share);
1090
1091 spec_share = kzalloc(sizeof(*spec_share),GFP_KERNEL);
1092 if(!spec_share){
1093 pr_err("Could not allocate memory for share.\n");
1094 goto err_share;
1095 }
1096
1097 /* setting share structure */
1098 share = (struct lynx_share * )(&(spec_share->share));
1099 share->fbinfo[0] = share->fbinfo[1] = NULL;
1100 share->devid = pdev->device;
1101 share->revid = pdev->revision;
1102
1103 pr_info("share->revid = %02x\n",share->revid);
1104 share->pdev = pdev;
1105 #ifdef CONFIG_MTRR
1106 share->mtrr_off = g_nomtrr;
1107 share->mtrr.vram = 0;
1108 share->mtrr.vram_added = 0;
1109 #endif
1110 share->accel_off = g_noaccel;
1111 share->dual = g_dualview;
1112 spin_lock_init(&share->slock);
1113
1114 if(!share->accel_off){
1115 /* hook deInit and 2d routines, notes that below hw_xxx
1116 * routine can work on most of lynx chips
1117 * if some chip need specific function,please hook it in smXXX_set_drv
1118 * routine */
1119 share->accel.de_init = hw_de_init;
1120 share->accel.de_fillrect = hw_fillrect;
1121 share->accel.de_copyarea = hw_copyarea;
1122 share->accel.de_imageblit = hw_imageblit;
1123 pr_info("enable 2d acceleration\n");
1124 }else{
1125 pr_info("disable 2d acceleration\n");
1126 }
1127
1128 /* call chip specific setup routine */
1129 sm750fb_setup(share,g_settings);
1130
1131 /* call chip specific mmap routine */
1132 if(hw_sm750_map(share,pdev)){
1133 pr_err("Memory map failed\n");
1134 goto err_map;
1135 }
1136
1137 #ifdef CONFIG_MTRR
1138 if(!share->mtrr_off){
1139 pr_info("enable mtrr\n");
1140 share->mtrr.vram = mtrr_add(share->vidmem_start,
1141 share->vidmem_size,
1142 MTRR_TYPE_WRCOMB,1);
1143
1144 if(share->mtrr.vram < 0){
1145 /* don't block driver with the failure of MTRR */
1146 pr_err("Unable to setup MTRR.\n");
1147 }else{
1148 share->mtrr.vram_added = 1;
1149 pr_info("MTRR added succesfully\n");
1150 }
1151 }
1152 #endif
1153
1154 memset(share->pvMem,0,share->vidmem_size);
1155
1156 pr_info("sm%3x mmio address = %p\n",share->devid,share->pvReg);
1157
1158 pci_set_drvdata(pdev,share);
1159
1160 /* call chipInit routine */
1161 hw_sm750_inithw(share,pdev);
1162
1163 /* allocate frame buffer info structor according to g_dualview */
1164 fbidx = 0;
1165 ALLOC_FB:
1166 info[fbidx] = framebuffer_alloc(sizeof(struct lynxfb_par),&pdev->dev);
1167 if(!info[fbidx])
1168 {
1169 pr_err("Could not allocate framebuffer #%d.\n",fbidx);
1170 if(fbidx == 0)
1171 goto err_info0_alloc;
1172 else
1173 goto err_info1_alloc;
1174 }
1175 else
1176 {
1177 struct lynxfb_par * par;
1178 int errno;
1179 pr_info("framebuffer #%d alloc okay\n",fbidx);
1180 share->fbinfo[fbidx] = info[fbidx];
1181 par = info[fbidx]->par;
1182 par->share = share;
1183
1184 /* set fb_info structure */
1185 if(lynxfb_set_fbinfo(info[fbidx],fbidx)){
1186 pr_err("Failed to initial fb_info #%d.\n",fbidx);
1187 if(fbidx == 0)
1188 goto err_info0_set;
1189 else
1190 goto err_info1_set;
1191 }
1192
1193 /* register frame buffer*/
1194 pr_info("Ready to register framebuffer #%d.\n",fbidx);
1195 errno = register_framebuffer(info[fbidx]);
1196 if (errno < 0) {
1197 pr_err("Failed to register fb_info #%d. err %d\n",fbidx, errno);
1198 if(fbidx == 0)
1199 goto err_register0;
1200 else
1201 goto err_register1;
1202 }
1203 pr_info("Accomplished register framebuffer #%d.\n",fbidx);
1204 }
1205
1206 /* no dual view by far */
1207 fbidx++;
1208 if(share->dual && fbidx < 2)
1209 goto ALLOC_FB;
1210
1211 return 0;
1212
1213 err_register1:
1214 err_info1_set:
1215 framebuffer_release(info[1]);
1216 err_info1_alloc:
1217 unregister_framebuffer(info[0]);
1218 err_register0:
1219 err_info0_set:
1220 framebuffer_release(info[0]);
1221 err_info0_alloc:
1222 err_map:
1223 kfree(spec_share);
1224 err_share:
1225 err_enable:
1226 return -ENODEV;
1227 }
1228
1229 static void __exit lynxfb_pci_remove(struct pci_dev * pdev)
1230 {
1231 struct fb_info * info;
1232 struct lynx_share * share;
1233 void * spec_share;
1234 struct lynxfb_par * par;
1235 int cnt;
1236
1237 cnt = 2;
1238 share = pci_get_drvdata(pdev);
1239
1240 while(cnt-- > 0){
1241 info = share->fbinfo[cnt];
1242 if(!info)
1243 continue;
1244 par = info->par;
1245
1246 unregister_framebuffer(info);
1247 /* clean crtc & output allocations*/
1248 par->crtc.clear(&par->crtc);
1249 par->output.clear(&par->output);
1250 /* release frame buffer*/
1251 framebuffer_release(info);
1252 }
1253 #ifdef CONFIG_MTRR
1254 if(share->mtrr.vram_added)
1255 mtrr_del(share->mtrr.vram,share->vidmem_start,share->vidmem_size);
1256 #endif
1257 // pci_release_regions(pdev);
1258
1259 iounmap(share->pvReg);
1260 iounmap(share->pvMem);
1261 spec_share = container_of(share,struct sm750_share,share);
1262 kfree(g_settings);
1263 kfree(spec_share);
1264 pci_set_drvdata(pdev,NULL);
1265 }
1266
1267 static int __init lynxfb_setup(char * options)
1268 {
1269 int len;
1270 char * opt,*tmp;
1271
1272
1273 if(!options || !*options){
1274 pr_warn("no options.\n");
1275 return 0;
1276 }
1277
1278 pr_info("options:%s\n",options);
1279
1280 len = strlen(options) + 1;
1281 g_settings = kzalloc(len, GFP_KERNEL);
1282 if(!g_settings)
1283 return -ENOMEM;
1284
1285 tmp = g_settings;
1286
1287 /* Notes:
1288 char * strsep(char **s,const char * ct);
1289 @s: the string to be searched
1290 @ct :the characters to search for
1291
1292 strsep() updates @options to pointer after the first found token
1293 it also returns the pointer ahead the token.
1294 */
1295 while((opt = strsep(&options,":"))!=NULL)
1296 {
1297 /* options that mean for any lynx chips are configured here */
1298 if(!strncmp(opt,"noaccel",strlen("noaccel")))
1299 g_noaccel = 1;
1300 #ifdef CONFIG_MTRR
1301 else if(!strncmp(opt,"nomtrr",strlen("nomtrr")))
1302 g_nomtrr = 1;
1303 #endif
1304 else if(!strncmp(opt,"dual",strlen("dual")))
1305 g_dualview = 1;
1306 else
1307 {
1308 strcat(tmp,opt);
1309 tmp += strlen(opt);
1310 if(options != NULL)
1311 *tmp++ = ':';
1312 else
1313 *tmp++ = 0;
1314 }
1315 }
1316
1317 /* misc g_settings are transport to chip specific routines */
1318 pr_info("parameter left for chip specific analysis:%s\n",g_settings);
1319 return 0;
1320 }
1321
1322 static struct pci_device_id smi_pci_table[] = {
1323 { PCI_DEVICE(0x126f, 0x0750), },
1324 {0,}
1325 };
1326
1327 MODULE_DEVICE_TABLE(pci,smi_pci_table);
1328
1329 static struct pci_driver lynxfb_driver = {
1330 .name = "sm750fb",
1331 .id_table = smi_pci_table,
1332 .probe = lynxfb_pci_probe,
1333 .remove = lynxfb_pci_remove,
1334 #ifdef CONFIG_PM
1335 .suspend = lynxfb_suspend,
1336 .resume = lynxfb_resume,
1337 #endif
1338 };
1339
1340
1341 static int __init lynxfb_init(void)
1342 {
1343 char *option ;
1344 int ret;
1345
1346 #ifdef MODULE
1347 option = g_option;
1348 #else
1349 if(fb_get_options("sm750fb",&option))
1350 return -ENODEV;
1351 #endif
1352
1353 lynxfb_setup(option);
1354 ret = pci_register_driver(&lynxfb_driver);
1355 return ret;
1356 }
1357 module_init(lynxfb_init);
1358
1359 static void __exit lynxfb_exit(void)
1360 {
1361 pci_unregister_driver(&lynxfb_driver);
1362 }
1363 module_exit(lynxfb_exit);
1364
1365 module_param(g_option,charp,S_IRUGO);
1366
1367 MODULE_PARM_DESC(g_option,
1368 "\n\t\tCommon options:\n"
1369 "\t\tnoaccel:disable 2d capabilities\n"
1370 "\t\tnomtrr:disable MTRR attribute for video memory\n"
1371 "\t\tdualview:dual frame buffer feature enabled\n"
1372 "\t\tnohwc:disable hardware cursor\n"
1373 "\t\tUsual example:\n"
1374 "\t\tinsmod ./sm750fb.ko g_option=\"noaccel,nohwc,1280x1024-8@60\"\n"
1375 );
1376
1377 MODULE_AUTHOR("monk liu <monk.liu@siliconmotion.com>");
1378 MODULE_AUTHOR("Sudip Mukherjee <sudip@vectorindia.org>");
1379 MODULE_DESCRIPTION("Frame buffer driver for SM750 chipset");
1380 MODULE_LICENSE("GPL v2");
This page took 0.060738 seconds and 6 git commands to generate.