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