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