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