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