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