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