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