1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/aperture.h>
3 #include <linux/kernel.h>
4 #include <linux/module.h>
5 #include <linux/errno.h>
6 #include <linux/string.h>
8 #include <linux/slab.h>
9 #include <linux/delay.h>
11 #include <linux/ioport.h>
12 #include <linux/init.h>
13 #include <linux/pci.h>
14 #include <linux/mm_types.h>
15 #include <linux/vmalloc.h>
16 #include <linux/pagemap.h>
17 #include <linux/screen_info.h>
18 #include <linux/console.h>
21 #include "sm750_accel.h"
22 #include "sm750_cursor.h"
26 * ssize_t lynxfb_ops_write(struct fb_info *info, const char __user *buf,
27 * size_t count, loff_t *ppos);
28 * ssize_t lynxfb_ops_read(struct fb_info *info, char __user *buf,
29 * size_t count, loff_t *ppos);
33 /* common var for all device */
34 static int g_hwcursor = 1;
37 static const char *g_fbmode[] = {NULL, NULL};
38 static const char *g_def_fbmode = "1024x768-32@60";
39 static char *g_settings;
40 static int g_dualview;
41 static char *g_option;
43 static const struct fb_videomode lynx750_ext[] = {
44 /* 1024x600-60 VESA [1.71:1] */
45 {NULL, 60, 1024, 600, 20423, 144, 40, 18, 1, 104, 3,
46 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
47 FB_VMODE_NONINTERLACED},
49 /* 1024x600-70 VESA */
50 {NULL, 70, 1024, 600, 17211, 152, 48, 21, 1, 104, 3,
51 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
52 FB_VMODE_NONINTERLACED},
54 /* 1024x600-75 VESA */
55 {NULL, 75, 1024, 600, 15822, 160, 56, 23, 1, 104, 3,
56 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
57 FB_VMODE_NONINTERLACED},
59 /* 1024x600-85 VESA */
60 {NULL, 85, 1024, 600, 13730, 168, 56, 26, 1, 112, 3,
61 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
62 FB_VMODE_NONINTERLACED},
65 {NULL, 60, 720, 480, 37427, 88, 16, 13, 1, 72, 3,
66 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
67 FB_VMODE_NONINTERLACED},
69 /* 1280x720 [1.78:1] */
70 {NULL, 60, 1280, 720, 13426, 162, 86, 22, 1, 136, 3,
71 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
72 FB_VMODE_NONINTERLACED},
75 {NULL, 60, 1280, 768, 12579, 192, 64, 20, 3, 128, 7,
76 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
77 FB_VMODE_NONINTERLACED},
79 /* 1360 x 768 [1.77083:1] */
80 {NULL, 60, 1360, 768, 11804, 208, 64, 23, 1, 144, 3,
81 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
82 FB_VMODE_NONINTERLACED},
84 /* 1368 x 768 [1.78:1] */
85 {NULL, 60, 1368, 768, 11647, 216, 72, 23, 1, 144, 3,
86 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
87 FB_VMODE_NONINTERLACED},
89 /* 1440 x 900 [16:10] */
90 {NULL, 60, 1440, 900, 9392, 232, 80, 28, 1, 152, 3,
91 FB_SYNC_VERT_HIGH_ACT,
92 FB_VMODE_NONINTERLACED},
94 /* 1440x960 [15:10] */
95 {NULL, 60, 1440, 960, 8733, 240, 88, 30, 1, 152, 3,
96 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
97 FB_VMODE_NONINTERLACED},
99 /* 1920x1080 [16:9] */
100 {NULL, 60, 1920, 1080, 6734, 148, 88, 41, 1, 44, 3,
101 FB_SYNC_VERT_HIGH_ACT,
102 FB_VMODE_NONINTERLACED},
105 /* no hardware cursor supported under version 2.6.10, kernel bug */
106 static int lynxfb_ops_cursor(struct fb_info *info, struct fb_cursor *fbcursor)
108 struct lynxfb_par *par;
109 struct lynxfb_crtc *crtc;
110 struct lynx_cursor *cursor;
114 cursor = &crtc->cursor;
116 if (fbcursor->image.width > cursor->max_w ||
117 fbcursor->image.height > cursor->max_h ||
118 fbcursor->image.depth > 1) {
122 sm750_hw_cursor_disable(cursor);
123 if (fbcursor->set & FB_CUR_SETSIZE)
124 sm750_hw_cursor_setSize(cursor,
125 fbcursor->image.width,
126 fbcursor->image.height);
128 if (fbcursor->set & FB_CUR_SETPOS)
129 sm750_hw_cursor_setPos(cursor,
130 fbcursor->image.dx - info->var.xoffset,
131 fbcursor->image.dy - info->var.yoffset);
133 if (fbcursor->set & FB_CUR_SETCMAP) {
134 /* get the 16bit color of kernel means */
137 fg = ((info->cmap.red[fbcursor->image.fg_color] & 0xf800)) |
138 ((info->cmap.green[fbcursor->image.fg_color] & 0xfc00) >> 5) |
139 ((info->cmap.blue[fbcursor->image.fg_color] & 0xf800) >> 11);
141 bg = ((info->cmap.red[fbcursor->image.bg_color] & 0xf800)) |
142 ((info->cmap.green[fbcursor->image.bg_color] & 0xfc00) >> 5) |
143 ((info->cmap.blue[fbcursor->image.bg_color] & 0xf800) >> 11);
145 sm750_hw_cursor_setColor(cursor, fg, bg);
148 if (fbcursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
149 sm750_hw_cursor_setData(cursor,
151 fbcursor->image.data,
155 if (fbcursor->enable)
156 sm750_hw_cursor_enable(cursor);
161 static void lynxfb_ops_fillrect(struct fb_info *info,
162 const struct fb_fillrect *region)
164 struct lynxfb_par *par;
165 struct sm750_dev *sm750_dev;
166 unsigned int base, pitch, Bpp, rop;
169 if (info->state != FBINFO_STATE_RUNNING)
173 sm750_dev = par->dev;
176 * each time 2d function begin to work,below three variable always need
177 * be set, seems we can put them together in some place
179 base = par->crtc.o_screen;
180 pitch = info->fix.line_length;
181 Bpp = info->var.bits_per_pixel >> 3;
183 color = (Bpp == 1) ? region->color :
184 ((u32 *)info->pseudo_palette)[region->color];
185 rop = (region->rop != ROP_COPY) ? HW_ROP2_XOR : HW_ROP2_COPY;
188 * If not use spin_lock, system will die if user load driver
189 * and immediately unload driver frequently (dual)
190 * since they fb_count could change during the lifetime of
191 * this lock, we are holding it for all cases.
193 spin_lock(&sm750_dev->slock);
195 sm750_dev->accel.de_fillrect(&sm750_dev->accel,
197 region->dx, region->dy,
198 region->width, region->height,
200 spin_unlock(&sm750_dev->slock);
203 static void lynxfb_ops_copyarea(struct fb_info *info,
204 const struct fb_copyarea *region)
206 struct lynxfb_par *par;
207 struct sm750_dev *sm750_dev;
208 unsigned int base, pitch, Bpp;
211 sm750_dev = par->dev;
214 * each time 2d function begin to work,below three variable always need
215 * be set, seems we can put them together in some place
217 base = par->crtc.o_screen;
218 pitch = info->fix.line_length;
219 Bpp = info->var.bits_per_pixel >> 3;
222 * If not use spin_lock, system will die if user load driver
223 * and immediately unload driver frequently (dual)
224 * since they fb_count could change during the lifetime of
225 * this lock, we are holding it for all cases.
227 spin_lock(&sm750_dev->slock);
229 sm750_dev->accel.de_copyarea(&sm750_dev->accel,
230 base, pitch, region->sx, region->sy,
231 base, pitch, Bpp, region->dx, region->dy,
232 region->width, region->height,
234 spin_unlock(&sm750_dev->slock);
237 static void lynxfb_ops_imageblit(struct fb_info *info,
238 const struct fb_image *image)
240 unsigned int base, pitch, Bpp;
241 unsigned int fgcol, bgcol;
242 struct lynxfb_par *par;
243 struct sm750_dev *sm750_dev;
246 sm750_dev = par->dev;
248 * each time 2d function begin to work,below three variable always need
249 * be set, seems we can put them together in some place
251 base = par->crtc.o_screen;
252 pitch = info->fix.line_length;
253 Bpp = info->var.bits_per_pixel >> 3;
255 /* TODO: Implement hardware acceleration for image->depth > 1 */
256 if (image->depth != 1) {
257 cfb_imageblit(info, image);
261 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
262 info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
263 fgcol = ((u32 *)info->pseudo_palette)[image->fg_color];
264 bgcol = ((u32 *)info->pseudo_palette)[image->bg_color];
266 fgcol = image->fg_color;
267 bgcol = image->bg_color;
271 * If not use spin_lock, system will die if user load driver
272 * and immediately unload driver frequently (dual)
273 * since they fb_count could change during the lifetime of
274 * this lock, we are holding it for all cases.
276 spin_lock(&sm750_dev->slock);
278 sm750_dev->accel.de_imageblit(&sm750_dev->accel,
279 image->data, image->width >> 3, 0,
281 image->dx, image->dy,
282 image->width, image->height,
283 fgcol, bgcol, HW_ROP2_COPY);
284 spin_unlock(&sm750_dev->slock);
287 static int lynxfb_ops_pan_display(struct fb_var_screeninfo *var,
288 struct fb_info *info)
290 struct lynxfb_par *par;
291 struct lynxfb_crtc *crtc;
298 return hw_sm750_pan_display(crtc, var, info);
301 static inline void lynxfb_set_visual_mode(struct fb_info *info)
303 switch (info->var.bits_per_pixel) {
305 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
310 info->fix.visual = FB_VISUAL_TRUECOLOR;
317 static inline int lynxfb_set_color_offsets(struct fb_info *info)
319 lynxfb_set_visual_mode(info);
321 switch (info->var.bits_per_pixel) {
323 info->var.red.offset = 0;
324 info->var.red.length = 8;
325 info->var.green.offset = 0;
326 info->var.green.length = 8;
327 info->var.blue.offset = 0;
328 info->var.blue.length = 8;
329 info->var.transp.length = 0;
330 info->var.transp.offset = 0;
333 info->var.red.offset = 11;
334 info->var.red.length = 5;
335 info->var.green.offset = 5;
336 info->var.green.length = 6;
337 info->var.blue.offset = 0;
338 info->var.blue.length = 5;
339 info->var.transp.length = 0;
340 info->var.transp.offset = 0;
344 info->var.red.offset = 16;
345 info->var.red.length = 8;
346 info->var.green.offset = 8;
347 info->var.green.length = 8;
348 info->var.blue.offset = 0;
349 info->var.blue.length = 8;
357 static int lynxfb_ops_set_par(struct fb_info *info)
359 struct lynxfb_par *par;
360 struct lynxfb_crtc *crtc;
361 struct lynxfb_output *output;
362 struct fb_var_screeninfo *var;
363 struct fb_fix_screeninfo *fix;
365 unsigned int line_length;
373 output = &par->output;
377 /* fix structure is not so FIX ... */
378 line_length = var->xres_virtual * var->bits_per_pixel / 8;
379 line_length = ALIGN(line_length, crtc->line_pad);
380 fix->line_length = line_length;
381 pr_info("fix->line_length = %d\n", fix->line_length);
384 * var->red,green,blue,transp are need to be set by driver
385 * and these data should be set before setcolreg routine
388 ret = lynxfb_set_color_offsets(info);
392 var->accel_flags = 0;/*FB_ACCELF_TEXT;*/
395 pr_err("bpp %d not supported\n", var->bits_per_pixel);
398 ret = hw_sm750_crtc_setMode(crtc, var, fix);
400 ret = hw_sm750_output_setMode(output, var, fix);
404 static inline unsigned int chan_to_field(unsigned int chan,
405 struct fb_bitfield *bf)
408 chan >>= 16 - bf->length;
409 return chan << bf->offset;
412 static int __maybe_unused lynxfb_suspend(struct device *dev)
414 struct fb_info *info;
415 struct sm750_dev *sm750_dev;
417 sm750_dev = dev_get_drvdata(dev);
420 info = sm750_dev->fbinfo[0];
422 /* 1 means do suspend */
423 fb_set_suspend(info, 1);
424 info = sm750_dev->fbinfo[1];
426 /* 1 means do suspend */
427 fb_set_suspend(info, 1);
433 static int __maybe_unused lynxfb_resume(struct device *dev)
435 struct pci_dev *pdev = to_pci_dev(dev);
436 struct fb_info *info;
437 struct sm750_dev *sm750_dev;
439 struct lynxfb_par *par;
440 struct lynxfb_crtc *crtc;
441 struct lynx_cursor *cursor;
443 sm750_dev = pci_get_drvdata(pdev);
447 hw_sm750_inithw(sm750_dev, pdev);
449 info = sm750_dev->fbinfo[0];
454 cursor = &crtc->cursor;
455 memset_io(cursor->vstart, 0x0, cursor->size);
456 memset_io(crtc->v_screen, 0x0, crtc->vidmem_size);
457 lynxfb_ops_set_par(info);
458 fb_set_suspend(info, 0);
461 info = sm750_dev->fbinfo[1];
466 cursor = &crtc->cursor;
467 memset_io(cursor->vstart, 0x0, cursor->size);
468 memset_io(crtc->v_screen, 0x0, crtc->vidmem_size);
469 lynxfb_ops_set_par(info);
470 fb_set_suspend(info, 0);
473 pdev->dev.power.power_state.event = PM_EVENT_RESUME;
479 static int lynxfb_ops_check_var(struct fb_var_screeninfo *var,
480 struct fb_info *info)
483 struct lynxfb_par *par;
484 struct lynxfb_crtc *crtc;
485 resource_size_t request;
491 pr_debug("check var:%dx%d-%d\n",
494 var->bits_per_pixel);
496 ret = lynxfb_set_color_offsets(info);
499 pr_err("bpp %d not supported\n", var->bits_per_pixel);
505 var->accel_flags = 0;/* FB_ACCELF_TEXT; */
507 /* check if current fb's video memory big enough to hold the onscreen*/
508 request = var->xres_virtual * (var->bits_per_pixel >> 3);
509 /* defaulty crtc->channel go with par->index */
511 request = ALIGN(request, crtc->line_pad);
512 request = request * var->yres_virtual;
513 if (crtc->vidmem_size < request) {
514 pr_err("not enough video memory for mode\n");
518 return hw_sm750_crtc_checkMode(crtc, var);
521 static int lynxfb_ops_setcolreg(unsigned int regno,
526 struct fb_info *info)
528 struct lynxfb_par *par;
529 struct lynxfb_crtc *crtc;
530 struct fb_var_screeninfo *var;
539 pr_err("regno = %d\n", regno);
543 if (info->var.grayscale)
544 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
546 if (var->bits_per_pixel == 8 &&
547 info->fix.visual == FB_VISUAL_PSEUDOCOLOR) {
551 ret = hw_sm750_setColReg(crtc, regno, red, green, blue);
555 if (info->fix.visual == FB_VISUAL_TRUECOLOR && regno < 256) {
558 if (var->bits_per_pixel == 16 ||
559 var->bits_per_pixel == 32 ||
560 var->bits_per_pixel == 24) {
561 val = chan_to_field(red, &var->red);
562 val |= chan_to_field(green, &var->green);
563 val |= chan_to_field(blue, &var->blue);
564 par->pseudo_palette[regno] = val;
575 static int lynxfb_ops_blank(int blank, struct fb_info *info)
577 struct lynxfb_par *par;
578 struct lynxfb_output *output;
580 pr_debug("blank = %d.\n", blank);
582 output = &par->output;
583 return output->proc_setBLANK(output, blank);
586 static int sm750fb_set_drv(struct lynxfb_par *par)
589 struct sm750_dev *sm750_dev;
590 struct lynxfb_output *output;
591 struct lynxfb_crtc *crtc;
595 sm750_dev = par->dev;
596 output = &par->output;
599 crtc->vidmem_size = sm750_dev->vidmem_size;
600 if (sm750_dev->fb_count > 1)
601 crtc->vidmem_size >>= 1;
603 /* setup crtc and output member */
604 sm750_dev->hwCursor = g_hwcursor;
611 output->proc_setBLANK = (sm750_dev->revid == SM750LE_REVISION_ID) ?
612 hw_sm750le_setBLANK : hw_sm750_setBLANK;
613 /* chip specific phase */
614 sm750_dev->accel.de_wait = (sm750_dev->revid == SM750LE_REVISION_ID) ?
615 hw_sm750le_deWait : hw_sm750_deWait;
616 switch (sm750_dev->dataflow) {
617 case sm750_simul_pri:
618 output->paths = sm750_pnc;
619 crtc->channel = sm750_primary;
621 crtc->v_screen = sm750_dev->pvMem;
622 pr_info("use simul primary mode\n");
624 case sm750_simul_sec:
625 output->paths = sm750_pnc;
626 crtc->channel = sm750_secondary;
628 crtc->v_screen = sm750_dev->pvMem;
630 case sm750_dual_normal:
631 if (par->index == 0) {
632 output->paths = sm750_panel;
633 crtc->channel = sm750_primary;
635 crtc->v_screen = sm750_dev->pvMem;
637 output->paths = sm750_crt;
638 crtc->channel = sm750_secondary;
639 /* not consider of padding stuffs for o_screen,need fix */
640 crtc->o_screen = sm750_dev->vidmem_size >> 1;
641 crtc->v_screen = sm750_dev->pvMem + crtc->o_screen;
644 case sm750_dual_swap:
645 if (par->index == 0) {
646 output->paths = sm750_panel;
647 crtc->channel = sm750_secondary;
649 crtc->v_screen = sm750_dev->pvMem;
651 output->paths = sm750_crt;
652 crtc->channel = sm750_primary;
653 /* not consider of padding stuffs for o_screen,
656 crtc->o_screen = sm750_dev->vidmem_size >> 1;
657 crtc->v_screen = sm750_dev->pvMem + crtc->o_screen;
667 static struct fb_ops lynxfb_ops = {
668 .owner = THIS_MODULE,
669 .fb_check_var = lynxfb_ops_check_var,
670 .fb_set_par = lynxfb_ops_set_par,
671 .fb_setcolreg = lynxfb_ops_setcolreg,
672 .fb_blank = lynxfb_ops_blank,
673 .fb_fillrect = cfb_fillrect,
674 .fb_imageblit = cfb_imageblit,
675 .fb_copyarea = cfb_copyarea,
677 .fb_cursor = lynxfb_ops_cursor,
680 static int lynxfb_set_fbinfo(struct fb_info *info, int index)
683 struct lynxfb_par *par;
684 struct sm750_dev *sm750_dev;
685 struct lynxfb_crtc *crtc;
686 struct lynxfb_output *output;
687 struct fb_var_screeninfo *var;
688 struct fb_fix_screeninfo *fix;
690 const struct fb_videomode *pdb[] = {
691 lynx750_ext, NULL, vesa_modes,
693 int cdb[] = {ARRAY_SIZE(lynx750_ext), 0, VESA_MODEDB_SIZE};
694 static const char * const mdb_desc[] = {
695 "driver prepared modes",
696 "kernel prepared default modedb",
697 "kernel HELPERS prepared vesa_modes",
700 static const char *fixId[2] = {
701 "sm750_fb1", "sm750_fb2",
704 int ret, line_length;
707 par = (struct lynxfb_par *)info->par;
708 sm750_dev = par->dev;
710 output = &par->output;
716 output->channel = &crtc->channel;
717 sm750fb_set_drv(par);
718 lynxfb_ops.fb_pan_display = lynxfb_ops_pan_display;
721 * set current cursor variable and proc pointer,
722 * must be set after crtc member initialized
724 crtc->cursor.offset = crtc->o_screen + crtc->vidmem_size - 1024;
725 crtc->cursor.mmio = sm750_dev->pvReg +
726 0x800f0 + (int)crtc->channel * 0x140;
728 pr_info("crtc->cursor.mmio = %p\n", crtc->cursor.mmio);
729 crtc->cursor.max_h = 64;
730 crtc->cursor.max_w = 64;
731 crtc->cursor.size = crtc->cursor.max_h * crtc->cursor.max_w * 2 / 8;
732 crtc->cursor.vstart = sm750_dev->pvMem + crtc->cursor.offset;
734 memset_io(crtc->cursor.vstart, 0, crtc->cursor.size);
736 lynxfb_ops.fb_cursor = NULL;
737 sm750_hw_cursor_disable(&crtc->cursor);
740 /* set info->fbops, must be set before fb_find_mode */
741 if (!sm750_dev->accel_off) {
742 /* use 2d acceleration */
743 lynxfb_ops.fb_fillrect = lynxfb_ops_fillrect;
744 lynxfb_ops.fb_copyarea = lynxfb_ops_copyarea;
745 lynxfb_ops.fb_imageblit = lynxfb_ops_imageblit;
747 info->fbops = &lynxfb_ops;
749 if (!g_fbmode[index]) {
750 g_fbmode[index] = g_def_fbmode;
752 g_fbmode[index] = g_fbmode[0];
755 for (i = 0; i < 3; i++) {
756 ret = fb_find_mode(var, info, g_fbmode[index],
757 pdb[i], cdb[i], NULL, 8);
760 pr_info("success! use specified mode:%s in %s\n",
764 } else if (ret == 2) {
765 pr_warn("use specified mode:%s in %s,with an ignored refresh rate\n",
769 } else if (ret == 3) {
770 pr_warn("wanna use default mode\n");
772 } else if (ret == 4) {
773 pr_warn("fall back to any valid mode\n");
775 pr_warn("ret = %d,fb_find_mode failed,with %s\n",
781 /* some member of info->var had been set by fb_find_mode */
783 pr_info("Member of info->var is :\n"
790 "bits_per_pixel=%d\n"
798 var->bits_per_pixel);
804 line_length = ALIGN((var->xres_virtual * var->bits_per_pixel / 8),
807 info->pseudo_palette = &par->pseudo_palette[0];
808 info->screen_base = crtc->v_screen;
809 pr_debug("screen_base vaddr = %p\n", info->screen_base);
810 info->screen_size = line_length * var->yres_virtual;
811 info->flags = FBINFO_FLAG_DEFAULT | 0;
814 fix->type = FB_TYPE_PACKED_PIXELS;
816 fix->xpanstep = crtc->xpanstep;
817 fix->ypanstep = crtc->ypanstep;
818 fix->ywrapstep = crtc->ywrapstep;
819 fix->accel = FB_ACCEL_SMI;
821 strscpy(fix->id, fixId[index], sizeof(fix->id));
823 fix->smem_start = crtc->o_screen + sm750_dev->vidmem_start;
824 pr_info("fix->smem_start = %lx\n", fix->smem_start);
826 * according to mmap experiment from user space application,
827 * fix->mmio_len should not larger than virtual size
828 * (xres_virtual x yres_virtual x ByPP)
829 * Below line maybe buggy when user mmap fb dev node and write
830 * data into the bound over virtual size
832 fix->smem_len = crtc->vidmem_size;
833 pr_info("fix->smem_len = %x\n", fix->smem_len);
834 info->screen_size = fix->smem_len;
835 fix->line_length = line_length;
836 fix->mmio_start = sm750_dev->vidreg_start;
837 pr_info("fix->mmio_start = %lx\n", fix->mmio_start);
838 fix->mmio_len = sm750_dev->vidreg_size;
839 pr_info("fix->mmio_len = %x\n", fix->mmio_len);
841 lynxfb_set_visual_mode(info);
844 var->activate = FB_ACTIVATE_NOW;
845 var->accel_flags = 0;
846 var->vmode = FB_VMODE_NONINTERLACED;
848 pr_debug("#1 show info->cmap :\nstart=%d,len=%d,red=%p,green=%p,blue=%p,transp=%p\n",
849 info->cmap.start, info->cmap.len,
850 info->cmap.red, info->cmap.green, info->cmap.blue,
853 ret = fb_alloc_cmap(&info->cmap, 256, 0);
855 pr_err("Could not allocate memory for cmap.\n");
859 pr_debug("#2 show info->cmap :\nstart=%d,len=%d,red=%p,green=%p,blue=%p,transp=%p\n",
860 info->cmap.start, info->cmap.len,
861 info->cmap.red, info->cmap.green, info->cmap.blue,
865 lynxfb_ops_check_var(var, info);
869 /* chip specific g_option configuration routine */
870 static void sm750fb_setup(struct sm750_dev *sm750_dev, char *src)
877 sm750_dev->initParm.chip_clk = 0;
878 sm750_dev->initParm.mem_clk = 0;
879 sm750_dev->initParm.master_clk = 0;
880 sm750_dev->initParm.powerMode = 0;
881 sm750_dev->initParm.setAllEngOff = 0;
882 sm750_dev->initParm.resetMemory = 1;
884 /* defaultly turn g_hwcursor on for both view */
888 dev_warn(&sm750_dev->pdev->dev, "no specific g_option.\n");
892 while ((opt = strsep(&src, ":")) != NULL && *opt != 0) {
893 dev_info(&sm750_dev->pdev->dev, "opt=%s\n", opt);
894 dev_info(&sm750_dev->pdev->dev, "src=%s\n", src);
896 if (!strncmp(opt, "swap", strlen("swap"))) {
898 } else if (!strncmp(opt, "nocrt", strlen("nocrt"))) {
899 sm750_dev->nocrt = 1;
900 } else if (!strncmp(opt, "36bit", strlen("36bit"))) {
901 sm750_dev->pnltype = sm750_doubleTFT;
902 } else if (!strncmp(opt, "18bit", strlen("18bit"))) {
903 sm750_dev->pnltype = sm750_dualTFT;
904 } else if (!strncmp(opt, "24bit", strlen("24bit"))) {
905 sm750_dev->pnltype = sm750_24TFT;
906 } else if (!strncmp(opt, "nohwc0", strlen("nohwc0"))) {
908 } else if (!strncmp(opt, "nohwc1", strlen("nohwc1"))) {
910 } else if (!strncmp(opt, "nohwc", strlen("nohwc"))) {
915 dev_info(&sm750_dev->pdev->dev,
916 "find fbmode0 : %s\n", g_fbmode[0]);
917 } else if (!g_fbmode[1]) {
919 dev_info(&sm750_dev->pdev->dev,
920 "find fbmode1 : %s\n", g_fbmode[1]);
922 dev_warn(&sm750_dev->pdev->dev, "How many view you wann set?\n");
928 if (sm750_dev->revid != SM750LE_REVISION_ID) {
929 if (sm750_dev->fb_count > 1) {
931 sm750_dev->dataflow = sm750_dual_swap;
933 sm750_dev->dataflow = sm750_dual_normal;
936 sm750_dev->dataflow = sm750_simul_sec;
938 sm750_dev->dataflow = sm750_simul_pri;
941 /* SM750LE only have one crt channel */
942 sm750_dev->dataflow = sm750_simul_sec;
943 /* sm750le do not have complex attributes */
944 sm750_dev->nocrt = 0;
948 static void sm750fb_framebuffer_release(struct sm750_dev *sm750_dev)
950 struct fb_info *fb_info;
952 while (sm750_dev->fb_count) {
953 fb_info = sm750_dev->fbinfo[sm750_dev->fb_count - 1];
954 unregister_framebuffer(fb_info);
955 framebuffer_release(fb_info);
956 sm750_dev->fb_count--;
960 static int sm750fb_framebuffer_alloc(struct sm750_dev *sm750_dev, int fbidx)
962 struct fb_info *fb_info;
963 struct lynxfb_par *par;
966 fb_info = framebuffer_alloc(sizeof(struct lynxfb_par),
967 &sm750_dev->pdev->dev);
971 sm750_dev->fbinfo[fbidx] = fb_info;
973 par->dev = sm750_dev;
975 err = lynxfb_set_fbinfo(fb_info, fbidx);
979 err = register_framebuffer(fb_info);
983 sm750_dev->fb_count++;
988 framebuffer_release(fb_info);
992 static int lynxfb_pci_probe(struct pci_dev *pdev,
993 const struct pci_device_id *ent)
995 struct sm750_dev *sm750_dev = NULL;
1000 err = aperture_remove_conflicting_pci_devices(pdev, "sm750_fb1");
1005 err = pcim_enable_device(pdev);
1010 sm750_dev = devm_kzalloc(&pdev->dev, sizeof(*sm750_dev), GFP_KERNEL);
1014 sm750_dev->fbinfo[0] = NULL;
1015 sm750_dev->fbinfo[1] = NULL;
1016 sm750_dev->devid = pdev->device;
1017 sm750_dev->revid = pdev->revision;
1018 sm750_dev->pdev = pdev;
1019 sm750_dev->mtrr_off = g_nomtrr;
1020 sm750_dev->mtrr.vram = 0;
1021 sm750_dev->accel_off = g_noaccel;
1022 spin_lock_init(&sm750_dev->slock);
1024 if (!sm750_dev->accel_off) {
1026 * hook deInit and 2d routines, notes that below hw_xxx
1027 * routine can work on most of lynx chips
1028 * if some chip need specific function,
1029 * please hook it in smXXX_set_drv routine
1031 sm750_dev->accel.de_init = sm750_hw_de_init;
1032 sm750_dev->accel.de_fillrect = sm750_hw_fillrect;
1033 sm750_dev->accel.de_copyarea = sm750_hw_copyarea;
1034 sm750_dev->accel.de_imageblit = sm750_hw_imageblit;
1037 /* call chip specific setup routine */
1038 sm750fb_setup(sm750_dev, g_settings);
1040 /* call chip specific mmap routine */
1041 err = hw_sm750_map(sm750_dev, pdev);
1045 if (!sm750_dev->mtrr_off)
1046 sm750_dev->mtrr.vram = arch_phys_wc_add(sm750_dev->vidmem_start,
1047 sm750_dev->vidmem_size);
1049 memset_io(sm750_dev->pvMem, 0, sm750_dev->vidmem_size);
1051 pci_set_drvdata(pdev, sm750_dev);
1053 /* call chipInit routine */
1054 hw_sm750_inithw(sm750_dev, pdev);
1056 /* allocate frame buffer info structures according to g_dualview */
1057 max_fb = g_dualview ? 2 : 1;
1058 for (fbidx = 0; fbidx < max_fb; fbidx++) {
1059 err = sm750fb_framebuffer_alloc(sm750_dev, fbidx);
1067 sm750fb_framebuffer_release(sm750_dev);
1071 static void lynxfb_pci_remove(struct pci_dev *pdev)
1073 struct sm750_dev *sm750_dev;
1075 sm750_dev = pci_get_drvdata(pdev);
1077 sm750fb_framebuffer_release(sm750_dev);
1078 arch_phys_wc_del(sm750_dev->mtrr.vram);
1080 iounmap(sm750_dev->pvReg);
1081 iounmap(sm750_dev->pvMem);
1085 static int __init lynxfb_setup(char *options)
1090 if (!options || !*options) {
1091 pr_warn("no options.\n");
1095 pr_info("options:%s\n", options);
1097 len = strlen(options) + 1;
1098 g_settings = kzalloc(len, GFP_KERNEL);
1106 * char * strsep(char **s,const char * ct);
1107 * @s: the string to be searched
1108 * @ct :the characters to search for
1110 * strsep() updates @options to pointer after the first found token
1111 * it also returns the pointer ahead the token.
1113 while ((opt = strsep(&options, ":")) != NULL) {
1114 /* options that mean for any lynx chips are configured here */
1115 if (!strncmp(opt, "noaccel", strlen("noaccel"))) {
1117 } else if (!strncmp(opt, "nomtrr", strlen("nomtrr"))) {
1119 } else if (!strncmp(opt, "dual", strlen("dual"))) {
1131 /* misc g_settings are transport to chip specific routines */
1132 pr_info("parameter left for chip specific analysis:%s\n", g_settings);
1136 static const struct pci_device_id smi_pci_table[] = {
1137 { PCI_DEVICE(0x126f, 0x0750), },
1141 MODULE_DEVICE_TABLE(pci, smi_pci_table);
1143 static SIMPLE_DEV_PM_OPS(lynxfb_pm_ops, lynxfb_suspend, lynxfb_resume);
1145 static struct pci_driver lynxfb_driver = {
1147 .id_table = smi_pci_table,
1148 .probe = lynxfb_pci_probe,
1149 .remove = lynxfb_pci_remove,
1150 .driver.pm = &lynxfb_pm_ops,
1153 static int __init lynxfb_init(void)
1157 if (fb_modesetting_disabled("sm750fb"))
1163 if (fb_get_options("sm750fb", &option))
1167 lynxfb_setup(option);
1168 return pci_register_driver(&lynxfb_driver);
1170 module_init(lynxfb_init);
1172 static void __exit lynxfb_exit(void)
1174 pci_unregister_driver(&lynxfb_driver);
1176 module_exit(lynxfb_exit);
1178 module_param(g_option, charp, 0444);
1180 MODULE_PARM_DESC(g_option,
1181 "\n\t\tCommon options:\n"
1182 "\t\tnoaccel:disable 2d capabilities\n"
1183 "\t\tnomtrr:disable MTRR attribute for video memory\n"
1184 "\t\tdualview:dual frame buffer feature enabled\n"
1185 "\t\tnohwc:disable hardware cursor\n"
1186 "\t\tUsual example:\n"
1187 "\t\tinsmod ./sm750fb.ko g_option=\"noaccel,nohwc,1280x1024-8@60\"\n"
1192 MODULE_DESCRIPTION("Frame buffer driver for SM750 chipset");
1193 MODULE_LICENSE("Dual BSD/GPL");