ps3: use symbolic names for video modes
[deliverable/linux.git] / drivers / video / ps3fb.c
1 /*
2 * linux/drivers/video/ps3fb.c -- PS3 GPU frame buffer device
3 *
4 * Copyright (C) 2006 Sony Computer Entertainment Inc.
5 * Copyright 2006, 2007 Sony Corporation
6 *
7 * This file is based on :
8 *
9 * linux/drivers/video/vfb.c -- Virtual frame buffer device
10 *
11 * Copyright (C) 2002 James Simmons
12 *
13 * Copyright (C) 1997 Geert Uytterhoeven
14 *
15 * This file is subject to the terms and conditions of the GNU General Public
16 * License. See the file COPYING in the main directory of this archive for
17 * more details.
18 */
19
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/errno.h>
23 #include <linux/string.h>
24 #include <linux/mm.h>
25 #include <linux/interrupt.h>
26 #include <linux/console.h>
27 #include <linux/ioctl.h>
28 #include <linux/kthread.h>
29 #include <linux/freezer.h>
30 #include <linux/uaccess.h>
31 #include <linux/fb.h>
32 #include <linux/init.h>
33
34 #include <asm/abs_addr.h>
35 #include <asm/lv1call.h>
36 #include <asm/ps3av.h>
37 #include <asm/ps3fb.h>
38 #include <asm/ps3.h>
39
40
41 #define DEVICE_NAME "ps3fb"
42
43 #define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC 0x101
44 #define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP 0x102
45 #define L1GPU_CONTEXT_ATTRIBUTE_FB_SETUP 0x600
46 #define L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT 0x601
47 #define L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT_SYNC 0x602
48
49 #define L1GPU_FB_BLIT_WAIT_FOR_COMPLETION (1ULL << 32)
50
51 #define L1GPU_DISPLAY_SYNC_HSYNC 1
52 #define L1GPU_DISPLAY_SYNC_VSYNC 2
53
54 #define GPU_CMD_BUF_SIZE (2 * 1024 * 1024)
55 #define GPU_FB_START (64 * 1024)
56 #define GPU_IOIF (0x0d000000UL)
57 #define GPU_ALIGN_UP(x) _ALIGN_UP((x), 64)
58 #define GPU_MAX_LINE_LENGTH (65536 - 64)
59
60 #define PS3FB_FULL_MODE_BIT 0x80
61
62 #define GPU_INTR_STATUS_VSYNC_0 0 /* vsync on head A */
63 #define GPU_INTR_STATUS_VSYNC_1 1 /* vsync on head B */
64 #define GPU_INTR_STATUS_FLIP_0 3 /* flip head A */
65 #define GPU_INTR_STATUS_FLIP_1 4 /* flip head B */
66 #define GPU_INTR_STATUS_QUEUE_0 5 /* queue head A */
67 #define GPU_INTR_STATUS_QUEUE_1 6 /* queue head B */
68
69 #define GPU_DRIVER_INFO_VERSION 0x211
70
71 /* gpu internals */
72 struct display_head {
73 u64 be_time_stamp;
74 u32 status;
75 u32 offset;
76 u32 res1;
77 u32 res2;
78 u32 field;
79 u32 reserved1;
80
81 u64 res3;
82 u32 raster;
83
84 u64 vblank_count;
85 u32 field_vsync;
86 u32 reserved2;
87 };
88
89 struct gpu_irq {
90 u32 irq_outlet;
91 u32 status;
92 u32 mask;
93 u32 video_cause;
94 u32 graph_cause;
95 u32 user_cause;
96
97 u32 res1;
98 u64 res2;
99
100 u32 reserved[4];
101 };
102
103 struct gpu_driver_info {
104 u32 version_driver;
105 u32 version_gpu;
106 u32 memory_size;
107 u32 hardware_channel;
108
109 u32 nvcore_frequency;
110 u32 memory_frequency;
111
112 u32 reserved[1063];
113 struct display_head display_head[8];
114 struct gpu_irq irq;
115 };
116
117 struct ps3fb_priv {
118 unsigned int irq_no;
119
120 u64 context_handle, memory_handle;
121 void *xdr_ea;
122 size_t xdr_size;
123 struct gpu_driver_info *dinfo;
124
125 u64 vblank_count; /* frame count */
126 wait_queue_head_t wait_vsync;
127
128 atomic_t ext_flip; /* on/off flip with vsync */
129 atomic_t f_count; /* fb_open count */
130 int is_blanked;
131 int is_kicked;
132 struct task_struct *task;
133 };
134 static struct ps3fb_priv ps3fb;
135
136 struct ps3fb_par {
137 u32 pseudo_palette[16];
138 int mode_id, new_mode_id;
139 int res_index;
140 unsigned int num_frames; /* num of frame buffers */
141 unsigned int width;
142 unsigned int height;
143 unsigned long full_offset; /* start of fullscreen DDR fb */
144 unsigned long fb_offset; /* start of actual DDR fb */
145 unsigned long pan_offset;
146 };
147
148 struct ps3fb_res_table {
149 u32 xres;
150 u32 yres;
151 u32 xoff;
152 u32 yoff;
153 u32 type;
154 };
155 #define PS3FB_RES_FULL 1
156 static const struct ps3fb_res_table ps3fb_res[] = {
157 /* res_x,y margin_x,y full */
158 { 720, 480, 72, 48 , 0},
159 { 720, 576, 72, 58 , 0},
160 { 1280, 720, 78, 38 , 0},
161 { 1920, 1080, 116, 58 , 0},
162 /* full mode */
163 { 720, 480, 0, 0 , PS3FB_RES_FULL},
164 { 720, 576, 0, 0 , PS3FB_RES_FULL},
165 { 1280, 720, 0, 0 , PS3FB_RES_FULL},
166 { 1920, 1080, 0, 0 , PS3FB_RES_FULL},
167 /* vesa: normally full mode */
168 { 1280, 768, 0, 0 , 0},
169 { 1280, 1024, 0, 0 , 0},
170 { 1920, 1200, 0, 0 , 0},
171 { 0, 0, 0, 0 , 0} };
172
173 /* default resolution */
174 #define GPU_RES_INDEX 0 /* 720 x 480 */
175
176 static const struct fb_videomode ps3fb_modedb[] = {
177 /* 60 Hz broadcast modes (modes "1" to "5") */
178 {
179 /* 480i */
180 "480i", 60, 576, 384, 74074, 130, 89, 78, 57, 63, 6,
181 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
182 }, {
183 /* 480p */
184 "480p", 60, 576, 384, 37037, 130, 89, 78, 57, 63, 6,
185 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
186 }, {
187 /* 720p */
188 "720p", 60, 1124, 644, 13481, 298, 148, 57, 44, 80, 5,
189 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
190 }, {
191 /* 1080i */
192 "1080i", 60, 1688, 964, 13481, 264, 160, 94, 62, 88, 5,
193 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
194 }, {
195 /* 1080p */
196 "1080p", 60, 1688, 964, 6741, 264, 160, 94, 62, 88, 5,
197 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
198 },
199
200 /* 50 Hz broadcast modes (modes "6" to "10") */
201 {
202 /* 576i */
203 "576i", 50, 576, 460, 74074, 142, 83, 97, 63, 63, 5,
204 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
205 }, {
206 /* 576p */
207 "576p", 50, 576, 460, 37037, 142, 83, 97, 63, 63, 5,
208 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
209 }, {
210 /* 720p */
211 "720p", 50, 1124, 644, 13468, 298, 478, 57, 44, 80, 5,
212 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
213 }, {
214 /* 1080 */
215 "1080i", 50, 1688, 964, 13468, 264, 600, 94, 62, 88, 5,
216 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
217 }, {
218 /* 1080p */
219 "1080p", 50, 1688, 964, 6734, 264, 600, 94, 62, 88, 5,
220 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
221 },
222
223 /* VESA modes (modes "11" to "13") */
224 {
225 /* WXGA */
226 "wxga", 60, 1280, 768, 12924, 160, 24, 29, 3, 136, 6,
227 0, FB_VMODE_NONINTERLACED,
228 FB_MODE_IS_VESA
229 }, {
230 /* SXGA */
231 "sxga", 60, 1280, 1024, 9259, 248, 48, 38, 1, 112, 3,
232 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED,
233 FB_MODE_IS_VESA
234 }, {
235 /* WUXGA */
236 "wuxga", 60, 1920, 1200, 6494, 80, 48, 26, 3, 32, 6,
237 FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED,
238 FB_MODE_IS_VESA
239 },
240
241 /* 60 Hz broadcast modes (full resolution versions of modes "1" to "5") */
242 {
243 /* 480if */
244 "480if", 60, 720, 480, 74074, 58, 17, 30, 9, 63, 6,
245 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
246 }, {
247 /* 480pf */
248 "480pf", 60, 720, 480, 37037, 58, 17, 30, 9, 63, 6,
249 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
250 }, {
251 /* 720pf */
252 "720pf", 60, 1280, 720, 13481, 220, 70, 19, 6, 80, 5,
253 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
254 }, {
255 /* 1080if */
256 "1080if", 60, 1920, 1080, 13481, 148, 44, 36, 4, 88, 5,
257 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
258 }, {
259 /* 1080pf */
260 "1080pf", 60, 1920, 1080, 6741, 148, 44, 36, 4, 88, 5,
261 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
262 },
263
264 /* 50 Hz broadcast modes (full resolution versions of modes "6" to "10") */
265 {
266 /* 576if */
267 "576if", 50, 720, 576, 74074, 70, 11, 39, 5, 63, 5,
268 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
269 }, {
270 /* 576pf */
271 "576pf", 50, 720, 576, 37037, 70, 11, 39, 5, 63, 5,
272 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
273 }, {
274 /* 720pf */
275 "720pf", 50, 1280, 720, 13468, 220, 400, 19, 6, 80, 5,
276 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
277 }, {
278 /* 1080if */
279 "1080f", 50, 1920, 1080, 13468, 148, 484, 36, 4, 88, 5,
280 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
281 }, {
282 /* 1080pf */
283 "1080pf", 50, 1920, 1080, 6734, 148, 484, 36, 4, 88, 5,
284 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
285 }
286 };
287
288
289 #define HEAD_A
290 #define HEAD_B
291
292 #define X_OFF(i) (ps3fb_res[i].xoff) /* left/right margin (pixel) */
293 #define Y_OFF(i) (ps3fb_res[i].yoff) /* top/bottom margin (pixel) */
294 #define WIDTH(i) (ps3fb_res[i].xres) /* width of FB */
295 #define HEIGHT(i) (ps3fb_res[i].yres) /* height of FB */
296 #define BPP 4 /* number of bytes per pixel */
297
298 /* Start of the virtual frame buffer (relative to fullscreen ) */
299 #define VP_OFF(i) ((WIDTH(i) * Y_OFF(i) + X_OFF(i)) * BPP)
300
301
302 static int ps3fb_mode;
303 module_param(ps3fb_mode, int, 0);
304
305 static char *mode_option __devinitdata;
306
307 static int ps3fb_get_res_table(u32 xres, u32 yres, int mode)
308 {
309 int full_mode;
310 unsigned int i;
311 u32 x, y, f;
312
313 full_mode = (mode & PS3FB_FULL_MODE_BIT) ? PS3FB_RES_FULL : 0;
314 for (i = 0;; i++) {
315 x = ps3fb_res[i].xres;
316 y = ps3fb_res[i].yres;
317 f = ps3fb_res[i].type;
318
319 if (!x) {
320 pr_debug("ERROR: ps3fb_get_res_table()\n");
321 return -1;
322 }
323
324 if (full_mode == PS3FB_RES_FULL && f != PS3FB_RES_FULL)
325 continue;
326
327 if (x == xres && (yres == 0 || y == yres))
328 break;
329
330 x = x - 2 * ps3fb_res[i].xoff;
331 y = y - 2 * ps3fb_res[i].yoff;
332 if (x == xres && (yres == 0 || y == yres))
333 break;
334 }
335 return i;
336 }
337
338 static unsigned int ps3fb_find_mode(const struct fb_var_screeninfo *var,
339 u32 *ddr_line_length, u32 *xdr_line_length)
340 {
341 unsigned int i, fi, mode;
342
343 for (i = 0; i < ARRAY_SIZE(ps3fb_modedb); i++)
344 if (var->xres == ps3fb_modedb[i].xres &&
345 var->yres == ps3fb_modedb[i].yres &&
346 var->pixclock == ps3fb_modedb[i].pixclock &&
347 var->hsync_len == ps3fb_modedb[i].hsync_len &&
348 var->vsync_len == ps3fb_modedb[i].vsync_len &&
349 var->left_margin == ps3fb_modedb[i].left_margin &&
350 var->right_margin == ps3fb_modedb[i].right_margin &&
351 var->upper_margin == ps3fb_modedb[i].upper_margin &&
352 var->lower_margin == ps3fb_modedb[i].lower_margin &&
353 var->sync == ps3fb_modedb[i].sync &&
354 (var->vmode & FB_VMODE_MASK) == ps3fb_modedb[i].vmode)
355 goto found;
356
357 pr_debug("ps3fb_find_mode: mode not found\n");
358 return 0;
359
360 found:
361 /* Cropped broadcast modes use the full line length */
362 fi = i < PS3AV_MODE_1080P50 ? i + PS3AV_MODE_WUXGA : i;
363 *ddr_line_length = ps3fb_modedb[fi].xres * BPP;
364
365 if (ps3_compare_firmware_version(1, 9, 0) >= 0) {
366 *xdr_line_length = GPU_ALIGN_UP(max(var->xres,
367 var->xres_virtual) * BPP);
368 if (*xdr_line_length > GPU_MAX_LINE_LENGTH)
369 *xdr_line_length = GPU_MAX_LINE_LENGTH;
370 } else
371 *xdr_line_length = *ddr_line_length;
372
373 /* Full broadcast modes have the full mode bit set */
374 mode = i+1;
375 if (mode > PS3AV_MODE_WUXGA)
376 mode = (mode - PS3AV_MODE_WUXGA) | PS3FB_FULL_MODE_BIT;
377
378 pr_debug("ps3fb_find_mode: mode %u\n", mode);
379
380 return mode;
381 }
382
383 static const struct fb_videomode *ps3fb_default_mode(int id)
384 {
385 u32 mode = id & PS3AV_MODE_MASK;
386 u32 flags;
387
388 if (mode < PS3AV_MODE_480I || mode > PS3AV_MODE_WUXGA)
389 return NULL;
390
391 flags = id & ~PS3AV_MODE_MASK;
392
393 if (mode <= PS3AV_MODE_1080P50 && flags & PS3FB_FULL_MODE_BIT) {
394 /* Full broadcast mode */
395 return &ps3fb_modedb[mode + PS3AV_MODE_WUXGA - 1];
396 }
397
398 return &ps3fb_modedb[mode - 1];
399 }
400
401 static void ps3fb_sync_image(struct device *dev, u64 frame_offset,
402 u64 dst_offset, u64 src_offset, u32 width,
403 u32 height, u32 dst_line_length,
404 u32 src_line_length)
405 {
406 int status;
407 u64 line_length;
408
409 line_length = dst_line_length;
410 if (src_line_length != dst_line_length)
411 line_length |= (u64)src_line_length << 32;
412
413 src_offset += GPU_FB_START;
414 status = lv1_gpu_context_attribute(ps3fb.context_handle,
415 L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT,
416 dst_offset, GPU_IOIF + src_offset,
417 L1GPU_FB_BLIT_WAIT_FOR_COMPLETION |
418 (width << 16) | height,
419 line_length);
420 if (status)
421 dev_err(dev,
422 "%s: lv1_gpu_context_attribute FB_BLIT failed: %d\n",
423 __func__, status);
424 #ifdef HEAD_A
425 status = lv1_gpu_context_attribute(ps3fb.context_handle,
426 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP,
427 0, frame_offset, 0, 0);
428 if (status)
429 dev_err(dev, "%s: lv1_gpu_context_attribute FLIP failed: %d\n",
430 __func__, status);
431 #endif
432 #ifdef HEAD_B
433 status = lv1_gpu_context_attribute(ps3fb.context_handle,
434 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP,
435 1, frame_offset, 0, 0);
436 if (status)
437 dev_err(dev, "%s: lv1_gpu_context_attribute FLIP failed: %d\n",
438 __func__, status);
439 #endif
440 }
441
442 static int ps3fb_sync(struct fb_info *info, u32 frame)
443 {
444 struct ps3fb_par *par = info->par;
445 int i, error = 0;
446 u32 ddr_line_length, xdr_line_length;
447 u64 ddr_base, xdr_base;
448
449 if (frame > par->num_frames - 1) {
450 dev_dbg(info->device, "%s: invalid frame number (%u)\n",
451 __func__, frame);
452 error = -EINVAL;
453 goto out;
454 }
455
456 i = par->res_index;
457 xdr_line_length = info->fix.line_length;
458 ddr_line_length = ps3fb_res[i].xres * BPP;
459 xdr_base = frame * info->var.yres_virtual * xdr_line_length;
460 ddr_base = frame * ps3fb_res[i].yres * ddr_line_length;
461
462 ps3fb_sync_image(info->device, ddr_base + par->full_offset,
463 ddr_base + par->fb_offset, xdr_base + par->pan_offset,
464 par->width, par->height, ddr_line_length,
465 xdr_line_length);
466
467 out:
468 return error;
469 }
470
471 static int ps3fb_open(struct fb_info *info, int user)
472 {
473 atomic_inc(&ps3fb.f_count);
474 return 0;
475 }
476
477 static int ps3fb_release(struct fb_info *info, int user)
478 {
479 if (atomic_dec_and_test(&ps3fb.f_count)) {
480 if (atomic_read(&ps3fb.ext_flip)) {
481 atomic_set(&ps3fb.ext_flip, 0);
482 if (!try_acquire_console_sem()) {
483 ps3fb_sync(info, 0); /* single buffer */
484 release_console_sem();
485 }
486 }
487 }
488 return 0;
489 }
490
491 /*
492 * Setting the video mode has been split into two parts.
493 * First part, xxxfb_check_var, must not write anything
494 * to hardware, it should only verify and adjust var.
495 * This means it doesn't alter par but it does use hardware
496 * data from it to check this var.
497 */
498
499 static int ps3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
500 {
501 u32 xdr_line_length, ddr_line_length;
502 int mode;
503
504 dev_dbg(info->device, "var->xres:%u info->var.xres:%u\n", var->xres,
505 info->var.xres);
506 dev_dbg(info->device, "var->yres:%u info->var.yres:%u\n", var->yres,
507 info->var.yres);
508
509 /* FIXME For now we do exact matches only */
510 mode = ps3fb_find_mode(var, &ddr_line_length, &xdr_line_length);
511 if (!mode)
512 return -EINVAL;
513
514 /* Virtual screen */
515 if (var->xres_virtual < var->xres)
516 var->xres_virtual = var->xres;
517 if (var->yres_virtual < var->yres)
518 var->yres_virtual = var->yres;
519
520 if (var->xres_virtual > xdr_line_length / BPP) {
521 dev_dbg(info->device,
522 "Horizontal virtual screen size too large\n");
523 return -EINVAL;
524 }
525
526 if (var->xoffset + var->xres > var->xres_virtual ||
527 var->yoffset + var->yres > var->yres_virtual) {
528 dev_dbg(info->device, "panning out-of-range\n");
529 return -EINVAL;
530 }
531
532 /* We support ARGB8888 only */
533 if (var->bits_per_pixel > 32 || var->grayscale ||
534 var->red.offset > 16 || var->green.offset > 8 ||
535 var->blue.offset > 0 || var->transp.offset > 24 ||
536 var->red.length > 8 || var->green.length > 8 ||
537 var->blue.length > 8 || var->transp.length > 8 ||
538 var->red.msb_right || var->green.msb_right ||
539 var->blue.msb_right || var->transp.msb_right || var->nonstd) {
540 dev_dbg(info->device, "We support ARGB8888 only\n");
541 return -EINVAL;
542 }
543
544 var->bits_per_pixel = 32;
545 var->red.offset = 16;
546 var->green.offset = 8;
547 var->blue.offset = 0;
548 var->transp.offset = 24;
549 var->red.length = 8;
550 var->green.length = 8;
551 var->blue.length = 8;
552 var->transp.length = 8;
553 var->red.msb_right = 0;
554 var->green.msb_right = 0;
555 var->blue.msb_right = 0;
556 var->transp.msb_right = 0;
557
558 /* Rotation is not supported */
559 if (var->rotate) {
560 dev_dbg(info->device, "Rotation is not supported\n");
561 return -EINVAL;
562 }
563
564 /* Memory limit */
565 if (var->yres_virtual * xdr_line_length > ps3fb.xdr_size) {
566 dev_dbg(info->device, "Not enough memory\n");
567 return -ENOMEM;
568 }
569
570 var->height = -1;
571 var->width = -1;
572
573 return 0;
574 }
575
576 /*
577 * This routine actually sets the video mode.
578 */
579
580 static int ps3fb_set_par(struct fb_info *info)
581 {
582 struct ps3fb_par *par = info->par;
583 unsigned int mode, ddr_line_length, xdr_line_length, lines, maxlines;
584 int i;
585 unsigned long offset;
586 u64 dst;
587
588 dev_dbg(info->device, "xres:%d xv:%d yres:%d yv:%d clock:%d\n",
589 info->var.xres, info->var.xres_virtual,
590 info->var.yres, info->var.yres_virtual, info->var.pixclock);
591
592 mode = ps3fb_find_mode(&info->var, &ddr_line_length, &xdr_line_length);
593 if (!mode)
594 return -EINVAL;
595
596 i = ps3fb_get_res_table(info->var.xres, info->var.yres, mode);
597 par->res_index = i;
598
599 info->fix.smem_start = virt_to_abs(ps3fb.xdr_ea);
600 info->fix.smem_len = ps3fb.xdr_size;
601 info->fix.xpanstep = info->var.xres_virtual > info->var.xres ? 1 : 0;
602 info->fix.ypanstep = info->var.yres_virtual > info->var.yres ? 1 : 0;
603 info->fix.line_length = xdr_line_length;
604
605 info->screen_base = (char __iomem *)ps3fb.xdr_ea;
606
607 par->num_frames = ps3fb.xdr_size /
608 max(ps3fb_res[i].yres * ddr_line_length,
609 info->var.yres_virtual * xdr_line_length);
610
611 /* Keep the special bits we cannot set using fb_var_screeninfo */
612 par->new_mode_id = (par->new_mode_id & ~PS3AV_MODE_MASK) | mode;
613
614 par->width = info->var.xres;
615 par->height = info->var.yres;
616 offset = VP_OFF(i);
617 par->fb_offset = GPU_ALIGN_UP(offset);
618 par->full_offset = par->fb_offset - offset;
619 par->pan_offset = info->var.yoffset * xdr_line_length +
620 info->var.xoffset * BPP;
621
622 if (par->new_mode_id != par->mode_id) {
623 if (ps3av_set_video_mode(par->new_mode_id)) {
624 par->new_mode_id = par->mode_id;
625 return -EINVAL;
626 }
627 par->mode_id = par->new_mode_id;
628 }
629
630 /* Clear XDR frame buffer memory */
631 memset(ps3fb.xdr_ea, 0, ps3fb.xdr_size);
632
633 /* Clear DDR frame buffer memory */
634 lines = ps3fb_res[i].yres * par->num_frames;
635 if (par->full_offset)
636 lines++;
637 maxlines = ps3fb.xdr_size / ddr_line_length;
638 for (dst = 0; lines; dst += maxlines * ddr_line_length) {
639 unsigned int l = min(lines, maxlines);
640 ps3fb_sync_image(info->device, 0, dst, 0, ps3fb_res[i].xres, l,
641 ddr_line_length, ddr_line_length);
642 lines -= l;
643 }
644
645 return 0;
646 }
647
648 /*
649 * Set a single color register. The values supplied are already
650 * rounded down to the hardware's capabilities (according to the
651 * entries in the var structure). Return != 0 for invalid regno.
652 */
653
654 static int ps3fb_setcolreg(unsigned int regno, unsigned int red,
655 unsigned int green, unsigned int blue,
656 unsigned int transp, struct fb_info *info)
657 {
658 if (regno >= 16)
659 return 1;
660
661 red >>= 8;
662 green >>= 8;
663 blue >>= 8;
664 transp >>= 8;
665
666 ((u32 *)info->pseudo_palette)[regno] = transp << 24 | red << 16 |
667 green << 8 | blue;
668 return 0;
669 }
670
671 static int ps3fb_pan_display(struct fb_var_screeninfo *var,
672 struct fb_info *info)
673 {
674 struct ps3fb_par *par = info->par;
675
676 par->pan_offset = var->yoffset * info->fix.line_length +
677 var->xoffset * BPP;
678 return 0;
679 }
680
681 /*
682 * As we have a virtual frame buffer, we need our own mmap function
683 */
684
685 static int ps3fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
686 {
687 unsigned long size, offset;
688
689 size = vma->vm_end - vma->vm_start;
690 offset = vma->vm_pgoff << PAGE_SHIFT;
691 if (offset + size > info->fix.smem_len)
692 return -EINVAL;
693
694 offset += info->fix.smem_start;
695 if (remap_pfn_range(vma, vma->vm_start, offset >> PAGE_SHIFT,
696 size, vma->vm_page_prot))
697 return -EAGAIN;
698
699 dev_dbg(info->device, "ps3fb: mmap framebuffer P(%lx)->V(%lx)\n",
700 offset, vma->vm_start);
701 return 0;
702 }
703
704 /*
705 * Blank the display
706 */
707
708 static int ps3fb_blank(int blank, struct fb_info *info)
709 {
710 int retval;
711
712 dev_dbg(info->device, "%s: blank:%d\n", __func__, blank);
713 switch (blank) {
714 case FB_BLANK_POWERDOWN:
715 case FB_BLANK_HSYNC_SUSPEND:
716 case FB_BLANK_VSYNC_SUSPEND:
717 case FB_BLANK_NORMAL:
718 retval = ps3av_video_mute(1); /* mute on */
719 if (!retval)
720 ps3fb.is_blanked = 1;
721 break;
722
723 default: /* unblank */
724 retval = ps3av_video_mute(0); /* mute off */
725 if (!retval)
726 ps3fb.is_blanked = 0;
727 break;
728 }
729 return retval;
730 }
731
732 static int ps3fb_get_vblank(struct fb_vblank *vblank)
733 {
734 memset(vblank, 0, sizeof(*vblank));
735 vblank->flags = FB_VBLANK_HAVE_VSYNC;
736 return 0;
737 }
738
739 static int ps3fb_wait_for_vsync(u32 crtc)
740 {
741 int ret;
742 u64 count;
743
744 count = ps3fb.vblank_count;
745 ret = wait_event_interruptible_timeout(ps3fb.wait_vsync,
746 count != ps3fb.vblank_count,
747 HZ / 10);
748 if (!ret)
749 return -ETIMEDOUT;
750
751 return 0;
752 }
753
754 static void ps3fb_flip_ctl(int on, void *data)
755 {
756 struct ps3fb_priv *priv = data;
757 if (on)
758 atomic_dec_if_positive(&priv->ext_flip);
759 else
760 atomic_inc(&priv->ext_flip);
761 }
762
763
764 /*
765 * ioctl
766 */
767
768 static int ps3fb_ioctl(struct fb_info *info, unsigned int cmd,
769 unsigned long arg)
770 {
771 void __user *argp = (void __user *)arg;
772 u32 val;
773 int retval = -EFAULT;
774
775 switch (cmd) {
776 case FBIOGET_VBLANK:
777 {
778 struct fb_vblank vblank;
779 dev_dbg(info->device, "FBIOGET_VBLANK:\n");
780 retval = ps3fb_get_vblank(&vblank);
781 if (retval)
782 break;
783
784 if (copy_to_user(argp, &vblank, sizeof(vblank)))
785 retval = -EFAULT;
786 break;
787 }
788
789 case FBIO_WAITFORVSYNC:
790 {
791 u32 crt;
792 dev_dbg(info->device, "FBIO_WAITFORVSYNC:\n");
793 if (get_user(crt, (u32 __user *) arg))
794 break;
795
796 retval = ps3fb_wait_for_vsync(crt);
797 break;
798 }
799
800 case PS3FB_IOCTL_SETMODE:
801 {
802 struct ps3fb_par *par = info->par;
803 const struct fb_videomode *mode;
804 struct fb_var_screeninfo var;
805
806 if (copy_from_user(&val, argp, sizeof(val)))
807 break;
808
809 if (!(val & PS3AV_MODE_MASK)) {
810 u32 id = ps3av_get_auto_mode();
811 if (id > 0)
812 val = (val & ~PS3AV_MODE_MASK) | id;
813 }
814 dev_dbg(info->device, "PS3FB_IOCTL_SETMODE:%x\n", val);
815 retval = -EINVAL;
816 mode = ps3fb_default_mode(val);
817 if (mode) {
818 var = info->var;
819 fb_videomode_to_var(&var, mode);
820 acquire_console_sem();
821 info->flags |= FBINFO_MISC_USEREVENT;
822 /* Force, in case only special bits changed */
823 var.activate |= FB_ACTIVATE_FORCE;
824 par->new_mode_id = val;
825 retval = fb_set_var(info, &var);
826 info->flags &= ~FBINFO_MISC_USEREVENT;
827 release_console_sem();
828 }
829 break;
830 }
831
832 case PS3FB_IOCTL_GETMODE:
833 val = ps3av_get_mode();
834 dev_dbg(info->device, "PS3FB_IOCTL_GETMODE:%x\n", val);
835 if (!copy_to_user(argp, &val, sizeof(val)))
836 retval = 0;
837 break;
838
839 case PS3FB_IOCTL_SCREENINFO:
840 {
841 struct ps3fb_par *par = info->par;
842 struct ps3fb_ioctl_res res;
843 dev_dbg(info->device, "PS3FB_IOCTL_SCREENINFO:\n");
844 res.xres = info->fix.line_length / BPP;
845 res.yres = info->var.yres_virtual;
846 res.xoff = (res.xres - info->var.xres) / 2;
847 res.yoff = (res.yres - info->var.yres) / 2;
848 res.num_frames = par->num_frames;
849 if (!copy_to_user(argp, &res, sizeof(res)))
850 retval = 0;
851 break;
852 }
853
854 case PS3FB_IOCTL_ON:
855 dev_dbg(info->device, "PS3FB_IOCTL_ON:\n");
856 atomic_inc(&ps3fb.ext_flip);
857 retval = 0;
858 break;
859
860 case PS3FB_IOCTL_OFF:
861 dev_dbg(info->device, "PS3FB_IOCTL_OFF:\n");
862 atomic_dec_if_positive(&ps3fb.ext_flip);
863 retval = 0;
864 break;
865
866 case PS3FB_IOCTL_FSEL:
867 if (copy_from_user(&val, argp, sizeof(val)))
868 break;
869
870 dev_dbg(info->device, "PS3FB_IOCTL_FSEL:%d\n", val);
871 acquire_console_sem();
872 retval = ps3fb_sync(info, val);
873 release_console_sem();
874 break;
875
876 default:
877 retval = -ENOIOCTLCMD;
878 break;
879 }
880 return retval;
881 }
882
883 static int ps3fbd(void *arg)
884 {
885 struct fb_info *info = arg;
886
887 set_freezable();
888 while (!kthread_should_stop()) {
889 try_to_freeze();
890 set_current_state(TASK_INTERRUPTIBLE);
891 if (ps3fb.is_kicked) {
892 ps3fb.is_kicked = 0;
893 acquire_console_sem();
894 ps3fb_sync(info, 0); /* single buffer */
895 release_console_sem();
896 }
897 schedule();
898 }
899 return 0;
900 }
901
902 static irqreturn_t ps3fb_vsync_interrupt(int irq, void *ptr)
903 {
904 struct device *dev = ptr;
905 u64 v1;
906 int status;
907 struct display_head *head = &ps3fb.dinfo->display_head[1];
908
909 status = lv1_gpu_context_intr(ps3fb.context_handle, &v1);
910 if (status) {
911 dev_err(dev, "%s: lv1_gpu_context_intr failed: %d\n", __func__,
912 status);
913 return IRQ_NONE;
914 }
915
916 if (v1 & (1 << GPU_INTR_STATUS_VSYNC_1)) {
917 /* VSYNC */
918 ps3fb.vblank_count = head->vblank_count;
919 if (ps3fb.task && !ps3fb.is_blanked &&
920 !atomic_read(&ps3fb.ext_flip)) {
921 ps3fb.is_kicked = 1;
922 wake_up_process(ps3fb.task);
923 }
924 wake_up_interruptible(&ps3fb.wait_vsync);
925 }
926
927 return IRQ_HANDLED;
928 }
929
930
931 static int ps3fb_vsync_settings(struct gpu_driver_info *dinfo,
932 struct device *dev)
933 {
934 int error;
935
936 dev_dbg(dev, "version_driver:%x\n", dinfo->version_driver);
937 dev_dbg(dev, "irq outlet:%x\n", dinfo->irq.irq_outlet);
938 dev_dbg(dev,
939 "version_gpu: %x memory_size: %x ch: %x core_freq: %d "
940 "mem_freq:%d\n",
941 dinfo->version_gpu, dinfo->memory_size, dinfo->hardware_channel,
942 dinfo->nvcore_frequency/1000000, dinfo->memory_frequency/1000000);
943
944 if (dinfo->version_driver != GPU_DRIVER_INFO_VERSION) {
945 dev_err(dev, "%s: version_driver err:%x\n", __func__,
946 dinfo->version_driver);
947 return -EINVAL;
948 }
949
950 error = ps3_irq_plug_setup(PS3_BINDING_CPU_ANY, dinfo->irq.irq_outlet,
951 &ps3fb.irq_no);
952 if (error) {
953 dev_err(dev, "%s: ps3_alloc_irq failed %d\n", __func__, error);
954 return error;
955 }
956
957 error = request_irq(ps3fb.irq_no, ps3fb_vsync_interrupt, IRQF_DISABLED,
958 DEVICE_NAME, dev);
959 if (error) {
960 dev_err(dev, "%s: request_irq failed %d\n", __func__, error);
961 ps3_irq_plug_destroy(ps3fb.irq_no);
962 return error;
963 }
964
965 dinfo->irq.mask = (1 << GPU_INTR_STATUS_VSYNC_1) |
966 (1 << GPU_INTR_STATUS_FLIP_1);
967 return 0;
968 }
969
970 static int ps3fb_xdr_settings(u64 xdr_lpar, struct device *dev)
971 {
972 int status;
973
974 status = lv1_gpu_context_iomap(ps3fb.context_handle, GPU_IOIF,
975 xdr_lpar, ps3fb_videomemory.size, 0);
976 if (status) {
977 dev_err(dev, "%s: lv1_gpu_context_iomap failed: %d\n",
978 __func__, status);
979 return -ENXIO;
980 }
981 dev_dbg(dev,
982 "video:%p xdr_ea:%p ioif:%lx lpar:%lx phys:%lx size:%lx\n",
983 ps3fb_videomemory.address, ps3fb.xdr_ea, GPU_IOIF, xdr_lpar,
984 virt_to_abs(ps3fb.xdr_ea), ps3fb_videomemory.size);
985
986 status = lv1_gpu_context_attribute(ps3fb.context_handle,
987 L1GPU_CONTEXT_ATTRIBUTE_FB_SETUP,
988 xdr_lpar, GPU_CMD_BUF_SIZE,
989 GPU_IOIF, 0);
990 if (status) {
991 dev_err(dev,
992 "%s: lv1_gpu_context_attribute FB_SETUP failed: %d\n",
993 __func__, status);
994 return -ENXIO;
995 }
996 return 0;
997 }
998
999 static struct fb_ops ps3fb_ops = {
1000 .fb_open = ps3fb_open,
1001 .fb_release = ps3fb_release,
1002 .fb_read = fb_sys_read,
1003 .fb_write = fb_sys_write,
1004 .fb_check_var = ps3fb_check_var,
1005 .fb_set_par = ps3fb_set_par,
1006 .fb_setcolreg = ps3fb_setcolreg,
1007 .fb_pan_display = ps3fb_pan_display,
1008 .fb_fillrect = sys_fillrect,
1009 .fb_copyarea = sys_copyarea,
1010 .fb_imageblit = sys_imageblit,
1011 .fb_mmap = ps3fb_mmap,
1012 .fb_blank = ps3fb_blank,
1013 .fb_ioctl = ps3fb_ioctl,
1014 .fb_compat_ioctl = ps3fb_ioctl
1015 };
1016
1017 static struct fb_fix_screeninfo ps3fb_fix __initdata = {
1018 .id = DEVICE_NAME,
1019 .type = FB_TYPE_PACKED_PIXELS,
1020 .visual = FB_VISUAL_TRUECOLOR,
1021 .accel = FB_ACCEL_NONE,
1022 };
1023
1024 static int ps3fb_set_sync(struct device *dev)
1025 {
1026 int status;
1027
1028 #ifdef HEAD_A
1029 status = lv1_gpu_context_attribute(0x0,
1030 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
1031 0, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0);
1032 if (status) {
1033 dev_err(dev,
1034 "%s: lv1_gpu_context_attribute DISPLAY_SYNC failed: "
1035 "%d\n",
1036 __func__, status);
1037 return -1;
1038 }
1039 #endif
1040 #ifdef HEAD_B
1041 status = lv1_gpu_context_attribute(0x0,
1042 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
1043 1, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0);
1044
1045 if (status) {
1046 dev_err(dev,
1047 "%s: lv1_gpu_context_attribute DISPLAY_SYNC failed: "
1048 "%d\n",
1049 __func__, status);
1050 return -1;
1051 }
1052 #endif
1053 return 0;
1054 }
1055
1056 static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
1057 {
1058 struct fb_info *info;
1059 struct ps3fb_par *par;
1060 int retval = -ENOMEM;
1061 u32 xres, yres;
1062 u64 ddr_lpar = 0;
1063 u64 lpar_dma_control = 0;
1064 u64 lpar_driver_info = 0;
1065 u64 lpar_reports = 0;
1066 u64 lpar_reports_size = 0;
1067 u64 xdr_lpar;
1068 int status, res_index;
1069 struct task_struct *task;
1070 unsigned long max_ps3fb_size;
1071
1072 if (ps3fb_videomemory.size < GPU_CMD_BUF_SIZE) {
1073 dev_err(&dev->core, "%s: Not enough video memory\n", __func__);
1074 return -ENOMEM;
1075 }
1076
1077 status = ps3_open_hv_device(dev);
1078 if (status) {
1079 dev_err(&dev->core, "%s: ps3_open_hv_device failed\n",
1080 __func__);
1081 goto err;
1082 }
1083
1084 if (!ps3fb_mode)
1085 ps3fb_mode = ps3av_get_mode();
1086 dev_dbg(&dev->core, "ps3fb_mode: %d\n", ps3fb_mode);
1087
1088 if (ps3fb_mode > 0 &&
1089 !ps3av_video_mode2res(ps3fb_mode, &xres, &yres)) {
1090 res_index = ps3fb_get_res_table(xres, yres, ps3fb_mode);
1091 dev_dbg(&dev->core, "res_index:%d\n", res_index);
1092 } else
1093 res_index = GPU_RES_INDEX;
1094
1095 atomic_set(&ps3fb.f_count, -1); /* fbcon opens ps3fb */
1096 atomic_set(&ps3fb.ext_flip, 0); /* for flip with vsync */
1097 init_waitqueue_head(&ps3fb.wait_vsync);
1098
1099 ps3fb_set_sync(&dev->core);
1100
1101 max_ps3fb_size = _ALIGN_UP(GPU_IOIF, 256*1024*1024) - GPU_IOIF;
1102 if (ps3fb_videomemory.size > max_ps3fb_size) {
1103 dev_info(&dev->core, "Limiting ps3fb mem size to %lu bytes\n",
1104 max_ps3fb_size);
1105 ps3fb_videomemory.size = max_ps3fb_size;
1106 }
1107
1108 /* get gpu context handle */
1109 status = lv1_gpu_memory_allocate(ps3fb_videomemory.size, 0, 0, 0, 0,
1110 &ps3fb.memory_handle, &ddr_lpar);
1111 if (status) {
1112 dev_err(&dev->core, "%s: lv1_gpu_memory_allocate failed: %d\n",
1113 __func__, status);
1114 goto err;
1115 }
1116 dev_dbg(&dev->core, "ddr:lpar:0x%lx\n", ddr_lpar);
1117
1118 status = lv1_gpu_context_allocate(ps3fb.memory_handle, 0,
1119 &ps3fb.context_handle,
1120 &lpar_dma_control, &lpar_driver_info,
1121 &lpar_reports, &lpar_reports_size);
1122 if (status) {
1123 dev_err(&dev->core,
1124 "%s: lv1_gpu_context_attribute failed: %d\n", __func__,
1125 status);
1126 goto err_gpu_memory_free;
1127 }
1128
1129 /* vsync interrupt */
1130 ps3fb.dinfo = ioremap(lpar_driver_info, 128 * 1024);
1131 if (!ps3fb.dinfo) {
1132 dev_err(&dev->core, "%s: ioremap failed\n", __func__);
1133 goto err_gpu_context_free;
1134 }
1135
1136 retval = ps3fb_vsync_settings(ps3fb.dinfo, &dev->core);
1137 if (retval)
1138 goto err_iounmap_dinfo;
1139
1140 /* XDR frame buffer */
1141 ps3fb.xdr_ea = ps3fb_videomemory.address;
1142 xdr_lpar = ps3_mm_phys_to_lpar(__pa(ps3fb.xdr_ea));
1143
1144 /* Clear memory to prevent kernel info leakage into userspace */
1145 memset(ps3fb.xdr_ea, 0, ps3fb_videomemory.size);
1146
1147 /*
1148 * The GPU command buffer is at the start of video memory
1149 * As we don't use the full command buffer, we can put the actual
1150 * frame buffer at offset GPU_FB_START and save some precious XDR
1151 * memory
1152 */
1153 ps3fb.xdr_ea += GPU_FB_START;
1154 ps3fb.xdr_size = ps3fb_videomemory.size - GPU_FB_START;
1155
1156 retval = ps3fb_xdr_settings(xdr_lpar, &dev->core);
1157 if (retval)
1158 goto err_free_irq;
1159
1160 info = framebuffer_alloc(sizeof(struct ps3fb_par), &dev->core);
1161 if (!info)
1162 goto err_free_irq;
1163
1164 par = info->par;
1165 par->mode_id = ~ps3fb_mode; /* != ps3fb_mode, to trigger change */
1166 par->new_mode_id = ps3fb_mode;
1167 par->res_index = res_index;
1168 par->num_frames = 1;
1169
1170 info->screen_base = (char __iomem *)ps3fb.xdr_ea;
1171 info->fbops = &ps3fb_ops;
1172
1173 info->fix = ps3fb_fix;
1174 info->fix.smem_start = virt_to_abs(ps3fb.xdr_ea);
1175 info->fix.smem_len = ps3fb.xdr_size;
1176 info->pseudo_palette = par->pseudo_palette;
1177 info->flags = FBINFO_DEFAULT | FBINFO_READS_FAST |
1178 FBINFO_HWACCEL_XPAN | FBINFO_HWACCEL_YPAN;
1179
1180 retval = fb_alloc_cmap(&info->cmap, 256, 0);
1181 if (retval < 0)
1182 goto err_framebuffer_release;
1183
1184 if (!fb_find_mode(&info->var, info, mode_option, ps3fb_modedb,
1185 ARRAY_SIZE(ps3fb_modedb),
1186 ps3fb_default_mode(par->new_mode_id), 32)) {
1187 retval = -EINVAL;
1188 goto err_fb_dealloc;
1189 }
1190
1191 fb_videomode_to_modelist(ps3fb_modedb, ARRAY_SIZE(ps3fb_modedb),
1192 &info->modelist);
1193
1194 retval = register_framebuffer(info);
1195 if (retval < 0)
1196 goto err_fb_dealloc;
1197
1198 dev->core.driver_data = info;
1199
1200 dev_info(info->device, "%s %s, using %lu KiB of video memory\n",
1201 dev_driver_string(info->dev), info->dev->bus_id,
1202 ps3fb.xdr_size >> 10);
1203
1204 task = kthread_run(ps3fbd, info, DEVICE_NAME);
1205 if (IS_ERR(task)) {
1206 retval = PTR_ERR(task);
1207 goto err_unregister_framebuffer;
1208 }
1209
1210 ps3fb.task = task;
1211 ps3av_register_flip_ctl(ps3fb_flip_ctl, &ps3fb);
1212
1213 return 0;
1214
1215 err_unregister_framebuffer:
1216 unregister_framebuffer(info);
1217 err_fb_dealloc:
1218 fb_dealloc_cmap(&info->cmap);
1219 err_framebuffer_release:
1220 framebuffer_release(info);
1221 err_free_irq:
1222 free_irq(ps3fb.irq_no, &dev->core);
1223 ps3_irq_plug_destroy(ps3fb.irq_no);
1224 err_iounmap_dinfo:
1225 iounmap((u8 __iomem *)ps3fb.dinfo);
1226 err_gpu_context_free:
1227 lv1_gpu_context_free(ps3fb.context_handle);
1228 err_gpu_memory_free:
1229 lv1_gpu_memory_free(ps3fb.memory_handle);
1230 err:
1231 return retval;
1232 }
1233
1234 static int ps3fb_shutdown(struct ps3_system_bus_device *dev)
1235 {
1236 int status;
1237 struct fb_info *info = dev->core.driver_data;
1238
1239 dev_dbg(&dev->core, " -> %s:%d\n", __func__, __LINE__);
1240
1241 ps3fb_flip_ctl(0, &ps3fb); /* flip off */
1242 ps3fb.dinfo->irq.mask = 0;
1243
1244 ps3av_register_flip_ctl(NULL, NULL);
1245 if (ps3fb.task) {
1246 struct task_struct *task = ps3fb.task;
1247 ps3fb.task = NULL;
1248 kthread_stop(task);
1249 }
1250 if (ps3fb.irq_no) {
1251 free_irq(ps3fb.irq_no, &dev->core);
1252 ps3_irq_plug_destroy(ps3fb.irq_no);
1253 }
1254 if (info) {
1255 unregister_framebuffer(info);
1256 fb_dealloc_cmap(&info->cmap);
1257 framebuffer_release(info);
1258 info = dev->core.driver_data = NULL;
1259 }
1260 iounmap((u8 __iomem *)ps3fb.dinfo);
1261
1262 status = lv1_gpu_context_free(ps3fb.context_handle);
1263 if (status)
1264 dev_dbg(&dev->core, "lv1_gpu_context_free failed: %d\n",
1265 status);
1266
1267 status = lv1_gpu_memory_free(ps3fb.memory_handle);
1268 if (status)
1269 dev_dbg(&dev->core, "lv1_gpu_memory_free failed: %d\n",
1270 status);
1271
1272 ps3_close_hv_device(dev);
1273 dev_dbg(&dev->core, " <- %s:%d\n", __func__, __LINE__);
1274
1275 return 0;
1276 }
1277
1278 static struct ps3_system_bus_driver ps3fb_driver = {
1279 .match_id = PS3_MATCH_ID_GRAPHICS,
1280 .core.name = DEVICE_NAME,
1281 .core.owner = THIS_MODULE,
1282 .probe = ps3fb_probe,
1283 .remove = ps3fb_shutdown,
1284 .shutdown = ps3fb_shutdown,
1285 };
1286
1287 static int __init ps3fb_setup(void)
1288 {
1289 char *options;
1290
1291 #ifdef MODULE
1292 return 0;
1293 #endif
1294
1295 if (fb_get_options(DEVICE_NAME, &options))
1296 return -ENXIO;
1297
1298 if (!options || !*options)
1299 return 0;
1300
1301 while (1) {
1302 char *this_opt = strsep(&options, ",");
1303
1304 if (!this_opt)
1305 break;
1306 if (!*this_opt)
1307 continue;
1308 if (!strncmp(this_opt, "mode:", 5))
1309 ps3fb_mode = simple_strtoul(this_opt + 5, NULL, 0);
1310 else
1311 mode_option = this_opt;
1312 }
1313 return 0;
1314 }
1315
1316 static int __init ps3fb_init(void)
1317 {
1318 if (!ps3fb_videomemory.address || ps3fb_setup())
1319 return -ENXIO;
1320
1321 return ps3_system_bus_driver_register(&ps3fb_driver);
1322 }
1323
1324 static void __exit ps3fb_exit(void)
1325 {
1326 pr_debug(" -> %s:%d\n", __func__, __LINE__);
1327 ps3_system_bus_driver_unregister(&ps3fb_driver);
1328 pr_debug(" <- %s:%d\n", __func__, __LINE__);
1329 }
1330
1331 module_init(ps3fb_init);
1332 module_exit(ps3fb_exit);
1333
1334 MODULE_LICENSE("GPL");
1335 MODULE_DESCRIPTION("PS3 GPU Frame Buffer Driver");
1336 MODULE_AUTHOR("Sony Computer Entertainment Inc.");
1337 MODULE_ALIAS(PS3_MODULE_ALIAS_GRAPHICS);
This page took 0.055684 seconds and 6 git commands to generate.