md: factor out parsing of fixed-point numbers
[safe/jmp/linux-2.6] / drivers / video / ps3fb.c
index d61e321..9c0144e 100644 (file)
 #include <linux/init.h>
 
 #include <asm/abs_addr.h>
+#include <asm/cell-regs.h>
 #include <asm/lv1call.h>
 #include <asm/ps3av.h>
 #include <asm/ps3fb.h>
 #include <asm/ps3.h>
+#include <asm/ps3gpu.h>
 
 
 #define DEVICE_NAME            "ps3fb"
 
-#define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC   0x101
-#define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP   0x102
-#define L1GPU_CONTEXT_ATTRIBUTE_FB_SETUP       0x600
-#define L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT                0x601
-#define L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT_SYNC   0x602
-
-#define L1GPU_FB_BLIT_WAIT_FOR_COMPLETION      (1ULL << 32)
-
-#define L1GPU_DISPLAY_SYNC_HSYNC               1
-#define L1GPU_DISPLAY_SYNC_VSYNC               2
-
 #define GPU_CMD_BUF_SIZE                       (2 * 1024 * 1024)
 #define GPU_FB_START                           (64 * 1024)
 #define GPU_IOIF                               (0x0d000000UL)
@@ -116,8 +107,6 @@ struct ps3fb_priv {
        unsigned int irq_no;
 
        u64 context_handle, memory_handle;
-       void *xdr_ea;
-       size_t xdr_size;
        struct gpu_driver_info *dinfo;
 
        u64 vblank_count;       /* frame count */
@@ -186,7 +175,7 @@ static const struct fb_videomode ps3fb_modedb[] = {
         "720p", 50, 1124, 644, 13468, 298, 478, 57, 44, 80, 5,
         FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
     },    {
-        /* 1080 */
+        /* 1080i */
         "1080i", 50, 1688, 964, 13468, 264, 600, 94, 62, 88, 5,
         FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
     },    {
@@ -234,7 +223,7 @@ static const struct fb_videomode ps3fb_modedb[] = {
        FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
     }, {
        /* 1080if */
-       "1080f", 50, 1920, 1080, 13468, 148, 484, 36, 4, 88, 5,
+       "1080if", 50, 1920, 1080, 13468, 148, 484, 36, 4, 88, 5,
        FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
     }, {
        /* 1080pf */
@@ -276,29 +265,49 @@ static char *mode_option __devinitdata;
 static int ps3fb_cmp_mode(const struct fb_videomode *vmode,
                          const struct fb_var_screeninfo *var)
 {
-       /* resolution + black border must match a native resolution */
-       if (vmode->left_margin + vmode->xres + vmode->right_margin !=
-           var->left_margin + var->xres + var->right_margin ||
-           vmode->upper_margin + vmode->yres + vmode->lower_margin !=
-           var->upper_margin + var->yres + var->lower_margin)
+       long xres, yres, left_margin, right_margin, upper_margin, lower_margin;
+       long dx, dy;
+
+       /* maximum values */
+       if (var->xres > vmode->xres || var->yres > vmode->yres ||
+           var->pixclock > vmode->pixclock ||
+           var->hsync_len > vmode->hsync_len ||
+           var->vsync_len > vmode->vsync_len)
                return -1;
 
-       /* minimum limits for margins */
-       if (vmode->left_margin > var->left_margin ||
-           vmode->right_margin > var->right_margin ||
-           vmode->upper_margin > var->upper_margin ||
-           vmode->lower_margin > var->lower_margin)
+       /* progressive/interlaced must match */
+       if ((var->vmode & FB_VMODE_MASK) != vmode->vmode)
                return -1;
 
-       /* these fields must match exactly */
-       if (vmode->pixclock != var->pixclock ||
-           vmode->hsync_len != var->hsync_len ||
-           vmode->vsync_len != var->vsync_len ||
-           vmode->sync != var->sync ||
-           vmode->vmode != (var->vmode & FB_VMODE_MASK))
+       /* minimum resolution */
+       xres = max(var->xres, 1U);
+       yres = max(var->yres, 1U);
+
+       /* minimum margins */
+       left_margin = max(var->left_margin, vmode->left_margin);
+       right_margin = max(var->right_margin, vmode->right_margin);
+       upper_margin = max(var->upper_margin, vmode->upper_margin);
+       lower_margin = max(var->lower_margin, vmode->lower_margin);
+
+       /* resolution + margins may not exceed native parameters */
+       dx = ((long)vmode->left_margin + (long)vmode->xres +
+             (long)vmode->right_margin) -
+            (left_margin + xres + right_margin);
+       if (dx < 0)
                return -1;
 
-       return 0;
+       dy = ((long)vmode->upper_margin + (long)vmode->yres +
+             (long)vmode->lower_margin) -
+            (upper_margin + yres + lower_margin);
+       if (dy < 0)
+               return -1;
+
+       /* exact match */
+       if (!dx && !dy)
+               return 0;
+
+       /* resolution difference */
+       return (vmode->xres - xres) * (vmode->yres - yres);
 }
 
 static const struct fb_videomode *ps3fb_native_vmode(enum ps3av_mode_num id)
@@ -324,33 +333,96 @@ static const struct fb_videomode *ps3fb_vmode(int id)
 static unsigned int ps3fb_find_mode(struct fb_var_screeninfo *var,
                                    u32 *ddr_line_length, u32 *xdr_line_length)
 {
-       unsigned int id;
+       unsigned int id, best_id;
+       int diff, best_diff;
        const struct fb_videomode *vmode;
+       long gap;
 
+       best_id = 0;
+       best_diff = INT_MAX;
+       pr_debug("%s: wanted %u [%u] %u x %u [%u] %u\n", __func__,
+                var->left_margin, var->xres, var->right_margin,
+                var->upper_margin, var->yres, var->lower_margin);
        for (id = PS3AV_MODE_480I; id <= PS3AV_MODE_WUXGA; id++) {
                vmode = ps3fb_native_vmode(id);
-               if (!ps3fb_cmp_mode(vmode, var))
-                       goto found;
+               diff = ps3fb_cmp_mode(vmode, var);
+               pr_debug("%s: mode %u: %u [%u] %u x %u [%u] %u: diff = %d\n",
+                        __func__, id, vmode->left_margin, vmode->xres,
+                        vmode->right_margin, vmode->upper_margin,
+                        vmode->yres, vmode->lower_margin, diff);
+               if (diff < 0)
+                       continue;
+               if (diff < best_diff) {
+                       best_id = id;
+                       if (!diff)
+                               break;
+                       best_diff = diff;
+               }
        }
 
-       pr_debug("%s: mode not found\n", __func__);
-       return 0;
+       if (!best_id) {
+               pr_debug("%s: no suitable mode found\n", __func__);
+               return 0;
+       }
+
+       id = best_id;
+       vmode = ps3fb_native_vmode(id);
 
-found:
        *ddr_line_length = vmode->xres * BPP;
 
-       if (!var->xres) {
+       /* minimum resolution */
+       if (!var->xres)
                var->xres = 1;
-               var->right_margin--;
-       }
-       if (!var->yres) {
+       if (!var->yres)
                var->yres = 1;
-               var->lower_margin--;
+
+       /* minimum virtual resolution */
+       if (var->xres_virtual < var->xres)
+               var->xres_virtual = var->xres;
+       if (var->yres_virtual < var->yres)
+               var->yres_virtual = var->yres;
+
+       /* minimum margins */
+       if (var->left_margin < vmode->left_margin)
+               var->left_margin = vmode->left_margin;
+       if (var->right_margin < vmode->right_margin)
+               var->right_margin = vmode->right_margin;
+       if (var->upper_margin < vmode->upper_margin)
+               var->upper_margin = vmode->upper_margin;
+       if (var->lower_margin < vmode->lower_margin)
+               var->lower_margin = vmode->lower_margin;
+
+       /* extra margins */
+       gap = ((long)vmode->left_margin + (long)vmode->xres +
+              (long)vmode->right_margin) -
+             ((long)var->left_margin + (long)var->xres +
+              (long)var->right_margin);
+       if (gap > 0) {
+               var->left_margin += gap/2;
+               var->right_margin += (gap+1)/2;
+               pr_debug("%s: rounded up H to %u [%u] %u\n", __func__,
+                        var->left_margin, var->xres, var->right_margin);
+       }
+
+       gap = ((long)vmode->upper_margin + (long)vmode->yres +
+              (long)vmode->lower_margin) -
+             ((long)var->upper_margin + (long)var->yres +
+              (long)var->lower_margin);
+       if (gap > 0) {
+               var->upper_margin += gap/2;
+               var->lower_margin += (gap+1)/2;
+               pr_debug("%s: rounded up V to %u [%u] %u\n", __func__,
+                        var->upper_margin, var->yres, var->lower_margin);
        }
 
+       /* fixed fields */
+       var->pixclock = vmode->pixclock;
+       var->hsync_len = vmode->hsync_len;
+       var->vsync_len = vmode->vsync_len;
+       var->sync = vmode->sync;
+
        if (ps3_compare_firmware_version(1, 9, 0) >= 0) {
-               *xdr_line_length = GPU_ALIGN_UP(max(var->xres,
-                                                   var->xres_virtual) * BPP);
+               *xdr_line_length = GPU_ALIGN_UP(var->xres_virtual * BPP);
                if (*xdr_line_length > GPU_MAX_LINE_LENGTH)
                        *xdr_line_length = GPU_MAX_LINE_LENGTH;
        } else
@@ -379,31 +451,29 @@ static void ps3fb_sync_image(struct device *dev, u64 frame_offset,
                line_length |= (u64)src_line_length << 32;
 
        src_offset += GPU_FB_START;
-       status = lv1_gpu_context_attribute(ps3fb.context_handle,
-                                          L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT,
-                                          dst_offset, GPU_IOIF + src_offset,
-                                          L1GPU_FB_BLIT_WAIT_FOR_COMPLETION |
-                                          (width << 16) | height,
-                                          line_length);
+
+       mutex_lock(&ps3_gpu_mutex);
+       status = lv1_gpu_fb_blit(ps3fb.context_handle, dst_offset,
+                                GPU_IOIF + src_offset,
+                                L1GPU_FB_BLIT_WAIT_FOR_COMPLETION |
+                                (width << 16) | height,
+                                line_length);
+       mutex_unlock(&ps3_gpu_mutex);
+
        if (status)
-               dev_err(dev,
-                       "%s: lv1_gpu_context_attribute FB_BLIT failed: %d\n",
-                       __func__, status);
+               dev_err(dev, "%s: lv1_gpu_fb_blit failed: %d\n", __func__,
+                       status);
 #ifdef HEAD_A
-       status = lv1_gpu_context_attribute(ps3fb.context_handle,
-                                          L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP,
-                                          0, frame_offset, 0, 0);
+       status = lv1_gpu_display_flip(ps3fb.context_handle, 0, frame_offset);
        if (status)
-               dev_err(dev, "%s: lv1_gpu_context_attribute FLIP failed: %d\n",
-                       __func__, status);
+               dev_err(dev, "%s: lv1_gpu_display_flip failed: %d\n", __func__,
+                       status);
 #endif
 #ifdef HEAD_B
-       status = lv1_gpu_context_attribute(ps3fb.context_handle,
-                                          L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP,
-                                          1, frame_offset, 0, 0);
+       status = lv1_gpu_display_flip(ps3fb.context_handle, 1, frame_offset);
        if (status)
-               dev_err(dev, "%s: lv1_gpu_context_attribute FLIP failed: %d\n",
-                       __func__, status);
+               dev_err(dev, "%s: lv1_gpu_display_flip failed: %d\n", __func__,
+                       status);
 #endif
 }
 
@@ -465,22 +535,11 @@ static int ps3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
        u32 xdr_line_length, ddr_line_length;
        int mode;
 
-       dev_dbg(info->device, "var->xres:%u info->var.xres:%u\n", var->xres,
-               info->var.xres);
-       dev_dbg(info->device, "var->yres:%u info->var.yres:%u\n", var->yres,
-               info->var.yres);
-
-       /* FIXME For now we do exact matches only */
        mode = ps3fb_find_mode(var, &ddr_line_length, &xdr_line_length);
        if (!mode)
                return -EINVAL;
 
        /* Virtual screen */
-       if (var->xres_virtual < var->xres)
-               var->xres_virtual = var->xres;
-       if (var->yres_virtual < var->yres)
-               var->yres_virtual = var->yres;
-
        if (var->xres_virtual > xdr_line_length / BPP) {
                dev_dbg(info->device,
                        "Horizontal virtual screen size too large\n");
@@ -526,7 +585,7 @@ static int ps3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
        }
 
        /* Memory limit */
-       if (var->yres_virtual * xdr_line_length > ps3fb.xdr_size) {
+       if (var->yres_virtual * xdr_line_length > info->fix.smem_len) {
                dev_dbg(info->device, "Not enough memory\n");
                return -ENOMEM;
        }
@@ -549,29 +608,21 @@ static int ps3fb_set_par(struct fb_info *info)
        const struct fb_videomode *vmode;
        u64 dst;
 
-       dev_dbg(info->device, "xres:%d xv:%d yres:%d yv:%d clock:%d\n",
-               info->var.xres, info->var.xres_virtual,
-               info->var.yres, info->var.yres_virtual, info->var.pixclock);
-
        mode = ps3fb_find_mode(&info->var, &ddr_line_length, &xdr_line_length);
        if (!mode)
                return -EINVAL;
 
        vmode = ps3fb_native_vmode(mode & PS3AV_MODE_MASK);
 
-       info->fix.smem_start = virt_to_abs(ps3fb.xdr_ea);
-       info->fix.smem_len = ps3fb.xdr_size;
        info->fix.xpanstep = info->var.xres_virtual > info->var.xres ? 1 : 0;
        info->fix.ypanstep = info->var.yres_virtual > info->var.yres ? 1 : 0;
        info->fix.line_length = xdr_line_length;
 
-       info->screen_base = (char __iomem *)ps3fb.xdr_ea;
-
        par->ddr_line_length = ddr_line_length;
        par->ddr_frame_size = vmode->yres * ddr_line_length;
        par->xdr_frame_size = info->var.yres_virtual * xdr_line_length;
 
-       par->num_frames = ps3fb.xdr_size /
+       par->num_frames = info->fix.smem_len /
                          max(par->ddr_frame_size, par->xdr_frame_size);
 
        /* Keep the special bits we cannot set using fb_var_screeninfo */
@@ -599,13 +650,13 @@ static int ps3fb_set_par(struct fb_info *info)
        }
 
        /* Clear XDR frame buffer memory */
-       memset(ps3fb.xdr_ea, 0, ps3fb.xdr_size);
+       memset((void __force *)info->screen_base, 0, info->fix.smem_len);
 
        /* Clear DDR frame buffer memory */
        lines = vmode->yres * par->num_frames;
        if (par->full_offset)
                lines++;
-       maxlines = ps3fb.xdr_size / ddr_line_length;
+       maxlines = info->fix.smem_len / ddr_line_length;
        for (dst = 0; lines; dst += maxlines * ddr_line_length) {
                unsigned int l = min(lines, maxlines);
                ps3fb_sync_image(info->device, 0, dst, 0, vmode->xres, l,
@@ -722,15 +773,6 @@ static int ps3fb_wait_for_vsync(u32 crtc)
        return 0;
 }
 
-static void ps3fb_flip_ctl(int on, void *data)
-{
-       struct ps3fb_priv *priv = data;
-       if (on)
-               atomic_dec_if_positive(&priv->ext_flip);
-       else
-               atomic_inc(&priv->ext_flip);
-}
-
 
     /*
      * ioctl
@@ -899,74 +941,6 @@ static irqreturn_t ps3fb_vsync_interrupt(int irq, void *ptr)
 }
 
 
-static int ps3fb_vsync_settings(struct gpu_driver_info *dinfo,
-                               struct device *dev)
-{
-       int error;
-
-       dev_dbg(dev, "version_driver:%x\n", dinfo->version_driver);
-       dev_dbg(dev, "irq outlet:%x\n", dinfo->irq.irq_outlet);
-       dev_dbg(dev,
-               "version_gpu: %x memory_size: %x ch: %x core_freq: %d "
-               "mem_freq:%d\n",
-               dinfo->version_gpu, dinfo->memory_size, dinfo->hardware_channel,
-               dinfo->nvcore_frequency/1000000, dinfo->memory_frequency/1000000);
-
-       if (dinfo->version_driver != GPU_DRIVER_INFO_VERSION) {
-               dev_err(dev, "%s: version_driver err:%x\n", __func__,
-                       dinfo->version_driver);
-               return -EINVAL;
-       }
-
-       error = ps3_irq_plug_setup(PS3_BINDING_CPU_ANY, dinfo->irq.irq_outlet,
-                                  &ps3fb.irq_no);
-       if (error) {
-               dev_err(dev, "%s: ps3_alloc_irq failed %d\n", __func__, error);
-               return error;
-       }
-
-       error = request_irq(ps3fb.irq_no, ps3fb_vsync_interrupt, IRQF_DISABLED,
-                           DEVICE_NAME, dev);
-       if (error) {
-               dev_err(dev, "%s: request_irq failed %d\n", __func__, error);
-               ps3_irq_plug_destroy(ps3fb.irq_no);
-               return error;
-       }
-
-       dinfo->irq.mask = (1 << GPU_INTR_STATUS_VSYNC_1) |
-                         (1 << GPU_INTR_STATUS_FLIP_1);
-       return 0;
-}
-
-static int ps3fb_xdr_settings(u64 xdr_lpar, struct device *dev)
-{
-       int status;
-
-       status = lv1_gpu_context_iomap(ps3fb.context_handle, GPU_IOIF,
-                                      xdr_lpar, ps3fb_videomemory.size, 0);
-       if (status) {
-               dev_err(dev, "%s: lv1_gpu_context_iomap failed: %d\n",
-                       __func__, status);
-               return -ENXIO;
-       }
-       dev_dbg(dev,
-               "video:%p xdr_ea:%p ioif:%lx lpar:%lx phys:%lx size:%lx\n",
-               ps3fb_videomemory.address, ps3fb.xdr_ea, GPU_IOIF, xdr_lpar,
-               virt_to_abs(ps3fb.xdr_ea), ps3fb_videomemory.size);
-
-       status = lv1_gpu_context_attribute(ps3fb.context_handle,
-                                          L1GPU_CONTEXT_ATTRIBUTE_FB_SETUP,
-                                          xdr_lpar, GPU_CMD_BUF_SIZE,
-                                          GPU_IOIF, 0);
-       if (status) {
-               dev_err(dev,
-                       "%s: lv1_gpu_context_attribute FB_SETUP failed: %d\n",
-                       __func__, status);
-               return -ENXIO;
-       }
-       return 0;
-}
-
 static struct fb_ops ps3fb_ops = {
        .fb_open        = ps3fb_open,
        .fb_release     = ps3fb_release,
@@ -992,49 +966,19 @@ static struct fb_fix_screeninfo ps3fb_fix __initdata = {
        .accel =        FB_ACCEL_NONE,
 };
 
-static int ps3fb_set_sync(struct device *dev)
-{
-       int status;
-
-#ifdef HEAD_A
-       status = lv1_gpu_context_attribute(0x0,
-                                          L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
-                                          0, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0);
-       if (status) {
-               dev_err(dev,
-                       "%s: lv1_gpu_context_attribute DISPLAY_SYNC failed: "
-                       "%d\n",
-                       __func__, status);
-               return -1;
-       }
-#endif
-#ifdef HEAD_B
-       status = lv1_gpu_context_attribute(0x0,
-                                          L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
-                                          1, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0);
-
-       if (status) {
-               dev_err(dev,
-                       "%s: lv1_gpu_context_attribute DISPLAY_SYNC failed: "
-                       "%d\n",
-                       __func__, status);
-               return -1;
-       }
-#endif
-       return 0;
-}
-
 static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
 {
        struct fb_info *info;
        struct ps3fb_par *par;
-       int retval = -ENOMEM;
+       int retval;
        u64 ddr_lpar = 0;
        u64 lpar_dma_control = 0;
        u64 lpar_driver_info = 0;
        u64 lpar_reports = 0;
        u64 lpar_reports_size = 0;
        u64 xdr_lpar;
+       struct gpu_driver_info *dinfo;
+       void *fb_start;
        int status;
        struct task_struct *task;
        unsigned long max_ps3fb_size;
@@ -1044,8 +988,8 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
                return -ENOMEM;
        }
 
-       status = ps3_open_hv_device(dev);
-       if (status) {
+       retval = ps3_open_hv_device(dev);
+       if (retval) {
                dev_err(&dev->core, "%s: ps3_open_hv_device failed\n",
                        __func__);
                goto err;
@@ -1059,7 +1003,24 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
        atomic_set(&ps3fb.ext_flip, 0); /* for flip with vsync */
        init_waitqueue_head(&ps3fb.wait_vsync);
 
-       ps3fb_set_sync(&dev->core);
+#ifdef HEAD_A
+       status = lv1_gpu_display_sync(0x0, 0, L1GPU_DISPLAY_SYNC_VSYNC);
+       if (status) {
+               dev_err(&dev->core, "%s: lv1_gpu_display_sync failed: %d\n",
+                       __func__, status);
+               retval = -ENODEV;
+               goto err_close_device;
+       }
+#endif
+#ifdef HEAD_B
+       status = lv1_gpu_display_sync(0x0, 1, L1GPU_DISPLAY_SYNC_VSYNC);
+       if (status) {
+               dev_err(&dev->core, "%s: lv1_gpu_display_sync failed: %d\n",
+                       __func__, status);
+               retval = -ENODEV;
+               goto err_close_device;
+       }
+#endif
 
        max_ps3fb_size = _ALIGN_UP(GPU_IOIF, 256*1024*1024) - GPU_IOIF;
        if (ps3fb_videomemory.size > max_ps3fb_size) {
@@ -1074,9 +1035,9 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
        if (status) {
                dev_err(&dev->core, "%s: lv1_gpu_memory_allocate failed: %d\n",
                        __func__, status);
-               goto err;
+               goto err_close_device;
        }
-       dev_dbg(&dev->core, "ddr:lpar:0x%lx\n", ddr_lpar);
+       dev_dbg(&dev->core, "ddr:lpar:0x%llx\n", ddr_lpar);
 
        status = lv1_gpu_context_allocate(ps3fb.memory_handle, 0,
                                          &ps3fb.context_handle,
@@ -1084,57 +1045,105 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
                                          &lpar_reports, &lpar_reports_size);
        if (status) {
                dev_err(&dev->core,
-                       "%s: lv1_gpu_context_attribute failed: %d\n", __func__,
+                       "%s: lv1_gpu_context_allocate failed: %d\n", __func__,
                        status);
                goto err_gpu_memory_free;
        }
 
        /* vsync interrupt */
-       ps3fb.dinfo = ioremap(lpar_driver_info, 128 * 1024);
-       if (!ps3fb.dinfo) {
+       dinfo = (void __force *)ioremap(lpar_driver_info, 128 * 1024);
+       if (!dinfo) {
                dev_err(&dev->core, "%s: ioremap failed\n", __func__);
                goto err_gpu_context_free;
        }
 
-       retval = ps3fb_vsync_settings(ps3fb.dinfo, &dev->core);
-       if (retval)
+       ps3fb.dinfo = dinfo;
+       dev_dbg(&dev->core, "version_driver:%x\n", dinfo->version_driver);
+       dev_dbg(&dev->core, "irq outlet:%x\n", dinfo->irq.irq_outlet);
+       dev_dbg(&dev->core, "version_gpu: %x memory_size: %x ch: %x "
+               "core_freq: %d mem_freq:%d\n", dinfo->version_gpu,
+               dinfo->memory_size, dinfo->hardware_channel,
+               dinfo->nvcore_frequency/1000000,
+               dinfo->memory_frequency/1000000);
+
+       if (dinfo->version_driver != GPU_DRIVER_INFO_VERSION) {
+               dev_err(&dev->core, "%s: version_driver err:%x\n", __func__,
+                       dinfo->version_driver);
+               retval = -EINVAL;
+               goto err_iounmap_dinfo;
+       }
+
+       retval = ps3_irq_plug_setup(PS3_BINDING_CPU_ANY, dinfo->irq.irq_outlet,
+                                   &ps3fb.irq_no);
+       if (retval) {
+               dev_err(&dev->core, "%s: ps3_alloc_irq failed %d\n", __func__,
+                       retval);
                goto err_iounmap_dinfo;
+       }
 
-       /* XDR frame buffer */
-       ps3fb.xdr_ea = ps3fb_videomemory.address;
-       xdr_lpar = ps3_mm_phys_to_lpar(__pa(ps3fb.xdr_ea));
+       retval = request_irq(ps3fb.irq_no, ps3fb_vsync_interrupt,
+                            IRQF_DISABLED, DEVICE_NAME, &dev->core);
+       if (retval) {
+               dev_err(&dev->core, "%s: request_irq failed %d\n", __func__,
+                       retval);
+               goto err_destroy_plug;
+       }
+
+       dinfo->irq.mask = (1 << GPU_INTR_STATUS_VSYNC_1) |
+                         (1 << GPU_INTR_STATUS_FLIP_1);
 
        /* Clear memory to prevent kernel info leakage into userspace */
-       memset(ps3fb.xdr_ea, 0, ps3fb_videomemory.size);
+       memset(ps3fb_videomemory.address, 0, ps3fb_videomemory.size);
 
-       /*
-        * The GPU command buffer is at the start of video memory
-        * As we don't use the full command buffer, we can put the actual
-        * frame buffer at offset GPU_FB_START and save some precious XDR
-        * memory
-        */
-       ps3fb.xdr_ea += GPU_FB_START;
-       ps3fb.xdr_size = ps3fb_videomemory.size - GPU_FB_START;
+       xdr_lpar = ps3_mm_phys_to_lpar(__pa(ps3fb_videomemory.address));
 
-       retval = ps3fb_xdr_settings(xdr_lpar, &dev->core);
-       if (retval)
+       status = lv1_gpu_context_iomap(ps3fb.context_handle, GPU_IOIF,
+                                      xdr_lpar, ps3fb_videomemory.size,
+                                      CBE_IOPTE_PP_W | CBE_IOPTE_PP_R |
+                                      CBE_IOPTE_M);
+       if (status) {
+               dev_err(&dev->core, "%s: lv1_gpu_context_iomap failed: %d\n",
+                       __func__, status);
+               retval =  -ENXIO;
                goto err_free_irq;
+       }
+
+       dev_dbg(&dev->core, "video:%p ioif:%lx lpar:%llx size:%lx\n",
+               ps3fb_videomemory.address, GPU_IOIF, xdr_lpar,
+               ps3fb_videomemory.size);
+
+       status = lv1_gpu_fb_setup(ps3fb.context_handle, xdr_lpar,
+                                 GPU_CMD_BUF_SIZE, GPU_IOIF);
+       if (status) {
+               dev_err(&dev->core, "%s: lv1_gpu_fb_setup failed: %d\n",
+                       __func__, status);
+               retval = -ENXIO;
+               goto err_context_unmap;
+       }
 
        info = framebuffer_alloc(sizeof(struct ps3fb_par), &dev->core);
        if (!info)
-               goto err_free_irq;
+               goto err_context_fb_close;
 
        par = info->par;
        par->mode_id = ~ps3fb_mode;     /* != ps3fb_mode, to trigger change */
        par->new_mode_id = ps3fb_mode;
        par->num_frames = 1;
 
-       info->screen_base = (char __iomem *)ps3fb.xdr_ea;
        info->fbops = &ps3fb_ops;
-
        info->fix = ps3fb_fix;
-       info->fix.smem_start = virt_to_abs(ps3fb.xdr_ea);
-       info->fix.smem_len = ps3fb.xdr_size;
+
+       /*
+        * The GPU command buffer is at the start of video memory
+        * As we don't use the full command buffer, we can put the actual
+        * frame buffer at offset GPU_FB_START and save some precious XDR
+        * memory
+        */
+       fb_start = ps3fb_videomemory.address + GPU_FB_START;
+       info->screen_base = (char __force __iomem *)fb_start;
+       info->fix.smem_start = virt_to_abs(fb_start);
+       info->fix.smem_len = ps3fb_videomemory.size - GPU_FB_START;
+
        info->pseudo_palette = par->pseudo_palette;
        info->flags = FBINFO_DEFAULT | FBINFO_READS_FAST |
                      FBINFO_HWACCEL_XPAN | FBINFO_HWACCEL_YPAN;
@@ -1157,11 +1166,11 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
        if (retval < 0)
                goto err_fb_dealloc;
 
-       dev->core.driver_data = info;
+       ps3_system_bus_set_drvdata(dev, info);
 
-       dev_info(info->device, "%s %s, using %lu KiB of video memory\n",
-                dev_driver_string(info->dev), info->dev->bus_id,
-                ps3fb.xdr_size >> 10);
+       dev_info(info->device, "%s %s, using %u KiB of video memory\n",
+                dev_driver_string(info->dev), dev_name(info->dev),
+                info->fix.smem_len >> 10);
 
        task = kthread_run(ps3fbd, info, DEVICE_NAME);
        if (IS_ERR(task)) {
@@ -1170,7 +1179,6 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
        }
 
        ps3fb.task = task;
-       ps3av_register_flip_ctl(ps3fb_flip_ctl, &ps3fb);
 
        return 0;
 
@@ -1180,30 +1188,37 @@ err_fb_dealloc:
        fb_dealloc_cmap(&info->cmap);
 err_framebuffer_release:
        framebuffer_release(info);
+err_context_fb_close:
+       lv1_gpu_fb_close(ps3fb.context_handle);
+err_context_unmap:
+       lv1_gpu_context_iomap(ps3fb.context_handle, GPU_IOIF, xdr_lpar,
+                             ps3fb_videomemory.size, CBE_IOPTE_M);
 err_free_irq:
        free_irq(ps3fb.irq_no, &dev->core);
+err_destroy_plug:
        ps3_irq_plug_destroy(ps3fb.irq_no);
 err_iounmap_dinfo:
-       iounmap((u8 __iomem *)ps3fb.dinfo);
+       iounmap((u8 __force __iomem *)ps3fb.dinfo);
 err_gpu_context_free:
        lv1_gpu_context_free(ps3fb.context_handle);
 err_gpu_memory_free:
        lv1_gpu_memory_free(ps3fb.memory_handle);
+err_close_device:
+       ps3_close_hv_device(dev);
 err:
        return retval;
 }
 
 static int ps3fb_shutdown(struct ps3_system_bus_device *dev)
 {
-       int status;
-       struct fb_info *info = dev->core.driver_data;
+       struct fb_info *info = ps3_system_bus_get_drvdata(dev);
+       u64 xdr_lpar = ps3_mm_phys_to_lpar(__pa(ps3fb_videomemory.address));
 
        dev_dbg(&dev->core, " -> %s:%d\n", __func__, __LINE__);
 
-       ps3fb_flip_ctl(0, &ps3fb);      /* flip off */
+       atomic_inc(&ps3fb.ext_flip);    /* flip off */
        ps3fb.dinfo->irq.mask = 0;
 
-       ps3av_register_flip_ctl(NULL, NULL);
        if (ps3fb.task) {
                struct task_struct *task = ps3fb.task;
                ps3fb.task = NULL;
@@ -1217,20 +1232,14 @@ static int ps3fb_shutdown(struct ps3_system_bus_device *dev)
                unregister_framebuffer(info);
                fb_dealloc_cmap(&info->cmap);
                framebuffer_release(info);
-               info = dev->core.driver_data = NULL;
+               ps3_system_bus_set_drvdata(dev, NULL);
        }
-       iounmap((u8 __iomem *)ps3fb.dinfo);
-
-       status = lv1_gpu_context_free(ps3fb.context_handle);
-       if (status)
-               dev_dbg(&dev->core, "lv1_gpu_context_free failed: %d\n",
-                       status);
-
-       status = lv1_gpu_memory_free(ps3fb.memory_handle);
-       if (status)
-               dev_dbg(&dev->core, "lv1_gpu_memory_free failed: %d\n",
-                       status);
-
+       iounmap((u8 __force __iomem *)ps3fb.dinfo);
+       lv1_gpu_fb_close(ps3fb.context_handle);
+       lv1_gpu_context_iomap(ps3fb.context_handle, GPU_IOIF, xdr_lpar,
+                             ps3fb_videomemory.size, CBE_IOPTE_M);
+       lv1_gpu_context_free(ps3fb.context_handle);
+       lv1_gpu_memory_free(ps3fb.memory_handle);
        ps3_close_hv_device(dev);
        dev_dbg(&dev->core, " <- %s:%d\n", __func__, __LINE__);
 
@@ -1238,7 +1247,8 @@ static int ps3fb_shutdown(struct ps3_system_bus_device *dev)
 }
 
 static struct ps3_system_bus_driver ps3fb_driver = {
-       .match_id       = PS3_MATCH_ID_GRAPHICS,
+       .match_id       = PS3_MATCH_ID_GPU,
+       .match_sub_id   = PS3_MATCH_SUB_ID_GPU_FB,
        .core.name      = DEVICE_NAME,
        .core.owner     = THIS_MODULE,
        .probe          = ps3fb_probe,
@@ -1296,4 +1306,4 @@ module_exit(ps3fb_exit);
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("PS3 GPU Frame Buffer Driver");
 MODULE_AUTHOR("Sony Computer Entertainment Inc.");
-MODULE_ALIAS(PS3_MODULE_ALIAS_GRAPHICS);
+MODULE_ALIAS(PS3_MODULE_ALIAS_GPU_FB);