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