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