blob: 75836aa8319196345d5a24123af97e509a643543 [file] [log] [blame]
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001/*
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 Uytterhoeven310d8c12007-02-12 00:55:23 -080025#include <linux/interrupt.h>
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -080026#include <linux/console.h>
27#include <linux/ioctl.h>
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +020028#include <linux/kthread.h>
29#include <linux/freezer.h>
Krzysztof Helt84902b72007-10-16 01:29:04 -070030#include <linux/uaccess.h>
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -080031#include <linux/fb.h>
32#include <linux/init.h>
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -080033
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 Uytterhoeven9e6b99b2007-06-16 08:05:38 +100040
41#define DEVICE_NAME "ps3fb"
42
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -080043#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
54#define DDR_SIZE (0) /* used no ddr */
Geert Uytterhoeven2ce32e12007-10-16 01:29:48 -070055#define GPU_CMD_BUF_SIZE (64 * 1024)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -080056#define GPU_IOIF (0x0d000000UL)
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -070057#define GPU_ALIGN_UP(x) _ALIGN_UP((x), 64)
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -070058#define GPU_MAX_LINE_LENGTH (65536 - 64)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -080059
60#define PS3FB_FULL_MODE_BIT 0x80
61
62#define GPU_INTR_STATUS_VSYNC_0 0 /* vsync on head A */
63#define GPU_INTR_STATUS_VSYNC_1 1 /* vsync on head B */
64#define GPU_INTR_STATUS_FLIP_0 3 /* flip head A */
65#define GPU_INTR_STATUS_FLIP_1 4 /* flip head B */
66#define GPU_INTR_STATUS_QUEUE_0 5 /* queue head A */
67#define GPU_INTR_STATUS_QUEUE_1 6 /* queue head B */
68
69#define GPU_DRIVER_INFO_VERSION 0x211
70
71/* gpu internals */
72struct display_head {
73 u64 be_time_stamp;
74 u32 status;
75 u32 offset;
76 u32 res1;
77 u32 res2;
78 u32 field;
79 u32 reserved1;
80
81 u64 res3;
82 u32 raster;
83
84 u64 vblank_count;
85 u32 field_vsync;
86 u32 reserved2;
87};
88
89struct gpu_irq {
90 u32 irq_outlet;
91 u32 status;
92 u32 mask;
93 u32 video_cause;
94 u32 graph_cause;
95 u32 user_cause;
96
97 u32 res1;
98 u64 res2;
99
100 u32 reserved[4];
101};
102
103struct gpu_driver_info {
104 u32 version_driver;
105 u32 version_gpu;
106 u32 memory_size;
107 u32 hardware_channel;
108
109 u32 nvcore_frequency;
110 u32 memory_frequency;
111
112 u32 reserved[1063];
113 struct display_head display_head[8];
114 struct gpu_irq irq;
115};
116
117struct ps3fb_priv {
118 unsigned int irq_no;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800119
120 u64 context_handle, memory_handle;
121 void *xdr_ea;
Geert Uytterhoeven2ce32e12007-10-16 01:29:48 -0700122 size_t xdr_size;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800123 struct gpu_driver_info *dinfo;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800124
125 u64 vblank_count; /* frame count */
126 wait_queue_head_t wait_vsync;
127
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800128 atomic_t ext_flip; /* on/off flip with vsync */
129 atomic_t f_count; /* fb_open count */
130 int is_blanked;
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +0200131 int is_kicked;
132 struct task_struct *task;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800133};
134static struct ps3fb_priv ps3fb;
135
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700136struct ps3fb_par {
137 u32 pseudo_palette[16];
138 int mode_id, new_mode_id;
139 int res_index;
140 unsigned int num_frames; /* num of frame buffers */
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700141 unsigned int width;
142 unsigned int height;
143 unsigned long full_offset; /* start of fullscreen DDR fb */
144 unsigned long fb_offset; /* start of actual DDR fb */
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700145 unsigned long pan_offset;
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700146};
147
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800148struct ps3fb_res_table {
149 u32 xres;
150 u32 yres;
151 u32 xoff;
152 u32 yoff;
153 u32 type;
154};
155#define PS3FB_RES_FULL 1
156static const struct ps3fb_res_table ps3fb_res[] = {
157 /* res_x,y margin_x,y full */
158 { 720, 480, 72, 48 , 0},
159 { 720, 576, 72, 58 , 0},
160 { 1280, 720, 78, 38 , 0},
161 { 1920, 1080, 116, 58 , 0},
162 /* full mode */
163 { 720, 480, 0, 0 , PS3FB_RES_FULL},
164 { 720, 576, 0, 0 , PS3FB_RES_FULL},
165 { 1280, 720, 0, 0 , PS3FB_RES_FULL},
166 { 1920, 1080, 0, 0 , PS3FB_RES_FULL},
167 /* vesa: normally full mode */
168 { 1280, 768, 0, 0 , 0},
169 { 1280, 1024, 0, 0 , 0},
170 { 1920, 1200, 0, 0 , 0},
171 { 0, 0, 0, 0 , 0} };
172
173/* default resolution */
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000174#define GPU_RES_INDEX 0 /* 720 x 480 */
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800175
176static const struct fb_videomode ps3fb_modedb[] = {
177 /* 60 Hz broadcast modes (modes "1" to "5") */
178 {
179 /* 480i */
180 "480i", 60, 576, 384, 74074, 130, 89, 78, 57, 63, 6,
181 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
182 }, {
183 /* 480p */
184 "480p", 60, 576, 384, 37037, 130, 89, 78, 57, 63, 6,
185 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
186 }, {
187 /* 720p */
188 "720p", 60, 1124, 644, 13481, 298, 148, 57, 44, 80, 5,
189 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
190 }, {
191 /* 1080i */
192 "1080i", 60, 1688, 964, 13481, 264, 160, 94, 62, 88, 5,
193 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
194 }, {
195 /* 1080p */
196 "1080p", 60, 1688, 964, 6741, 264, 160, 94, 62, 88, 5,
197 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
198 },
199
200 /* 50 Hz broadcast modes (modes "6" to "10") */
201 {
202 /* 576i */
203 "576i", 50, 576, 460, 74074, 142, 83, 97, 63, 63, 5,
204 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
205 }, {
206 /* 576p */
207 "576p", 50, 576, 460, 37037, 142, 83, 97, 63, 63, 5,
208 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
209 }, {
210 /* 720p */
211 "720p", 50, 1124, 644, 13468, 298, 478, 57, 44, 80, 5,
212 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
213 }, {
214 /* 1080 */
215 "1080i", 50, 1688, 964, 13468, 264, 600, 94, 62, 88, 5,
216 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
217 }, {
218 /* 1080p */
219 "1080p", 50, 1688, 964, 6734, 264, 600, 94, 62, 88, 5,
220 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
221 },
222
223 /* VESA modes (modes "11" to "13") */
224 {
225 /* WXGA */
226 "wxga", 60, 1280, 768, 12924, 160, 24, 29, 3, 136, 6,
227 0, FB_VMODE_NONINTERLACED,
228 FB_MODE_IS_VESA
229 }, {
230 /* SXGA */
231 "sxga", 60, 1280, 1024, 9259, 248, 48, 38, 1, 112, 3,
232 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED,
233 FB_MODE_IS_VESA
234 }, {
235 /* WUXGA */
236 "wuxga", 60, 1920, 1200, 6494, 80, 48, 26, 3, 32, 6,
237 FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED,
238 FB_MODE_IS_VESA
239 },
240
241 /* 60 Hz broadcast modes (full resolution versions of modes "1" to "5") */
242 {
243 /* 480if */
244 "480if", 60, 720, 480, 74074, 58, 17, 30, 9, 63, 6,
245 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
246 }, {
247 /* 480pf */
248 "480pf", 60, 720, 480, 37037, 58, 17, 30, 9, 63, 6,
249 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
250 }, {
251 /* 720pf */
252 "720pf", 60, 1280, 720, 13481, 220, 70, 19, 6, 80, 5,
253 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
254 }, {
255 /* 1080if */
256 "1080if", 60, 1920, 1080, 13481, 148, 44, 36, 4, 88, 5,
257 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
258 }, {
259 /* 1080pf */
260 "1080pf", 60, 1920, 1080, 6741, 148, 44, 36, 4, 88, 5,
261 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
262 },
263
264 /* 50 Hz broadcast modes (full resolution versions of modes "6" to "10") */
265 {
266 /* 576if */
267 "576if", 50, 720, 576, 74074, 70, 11, 39, 5, 63, 5,
268 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
269 }, {
270 /* 576pf */
271 "576pf", 50, 720, 576, 37037, 70, 11, 39, 5, 63, 5,
272 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
273 }, {
274 /* 720pf */
275 "720pf", 50, 1280, 720, 13468, 220, 400, 19, 6, 80, 5,
276 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
277 }, {
278 /* 1080if */
279 "1080f", 50, 1920, 1080, 13468, 148, 484, 36, 4, 88, 5,
280 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
281 }, {
282 /* 1080pf */
283 "1080pf", 50, 1920, 1080, 6734, 148, 484, 36, 4, 88, 5,
284 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
285 }
286};
287
288
289#define HEAD_A
290#define HEAD_B
291
292#define X_OFF(i) (ps3fb_res[i].xoff) /* left/right margin (pixel) */
293#define Y_OFF(i) (ps3fb_res[i].yoff) /* top/bottom margin (pixel) */
294#define WIDTH(i) (ps3fb_res[i].xres) /* width of FB */
295#define HEIGHT(i) (ps3fb_res[i].yres) /* height of FB */
Geert Uytterhoeven2ce32e12007-10-16 01:29:48 -0700296#define BPP 4 /* number of bytes per pixel */
297
298/* Start of the virtual frame buffer (relative to fullscreen ) */
299#define VP_OFF(i) ((WIDTH(i) * Y_OFF(i) + X_OFF(i)) * BPP)
300
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800301
Geert Uytterhoevenbd685ac2007-05-02 14:48:34 +0200302static int ps3fb_mode;
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000303module_param(ps3fb_mode, int, 0);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800304
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000305static char *mode_option __devinitdata;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800306
Geert Uytterhoevenc95344a2007-10-16 01:29:25 -0700307static int ps3fb_get_res_table(u32 xres, u32 yres, int mode)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800308{
309 int full_mode;
310 unsigned int i;
311 u32 x, y, f;
312
Geert Uytterhoevenc95344a2007-10-16 01:29:25 -0700313 full_mode = (mode & PS3FB_FULL_MODE_BIT) ? PS3FB_RES_FULL : 0;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800314 for (i = 0;; i++) {
315 x = ps3fb_res[i].xres;
316 y = ps3fb_res[i].yres;
317 f = ps3fb_res[i].type;
318
319 if (!x) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700320 pr_debug("ERROR: ps3fb_get_res_table()\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800321 return -1;
322 }
323
324 if (full_mode == PS3FB_RES_FULL && f != PS3FB_RES_FULL)
325 continue;
326
327 if (x == xres && (yres == 0 || y == yres))
328 break;
329
330 x = x - 2 * ps3fb_res[i].xoff;
331 y = y - 2 * ps3fb_res[i].yoff;
332 if (x == xres && (yres == 0 || y == yres))
333 break;
334 }
335 return i;
336}
337
338static unsigned int ps3fb_find_mode(const struct fb_var_screeninfo *var,
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700339 u32 *ddr_line_length, u32 *xdr_line_length)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800340{
341 unsigned int i, mode;
342
343 for (i = 0; i < ARRAY_SIZE(ps3fb_modedb); i++)
344 if (var->xres == ps3fb_modedb[i].xres &&
345 var->yres == ps3fb_modedb[i].yres &&
346 var->pixclock == ps3fb_modedb[i].pixclock &&
347 var->hsync_len == ps3fb_modedb[i].hsync_len &&
348 var->vsync_len == ps3fb_modedb[i].vsync_len &&
349 var->left_margin == ps3fb_modedb[i].left_margin &&
350 var->right_margin == ps3fb_modedb[i].right_margin &&
351 var->upper_margin == ps3fb_modedb[i].upper_margin &&
352 var->lower_margin == ps3fb_modedb[i].lower_margin &&
353 var->sync == ps3fb_modedb[i].sync &&
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700354 (var->vmode & FB_VMODE_MASK) == ps3fb_modedb[i].vmode)
355 goto found;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800356
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700357 pr_debug("ps3fb_find_mode: mode not found\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800358 return 0;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700359
360found:
361 /* Cropped broadcast modes use the full line length */
362 *ddr_line_length = ps3fb_modedb[i < 10 ? i + 13 : i].xres * BPP;
363
364 if (ps3_compare_firmware_version(1, 9, 0) >= 0) {
365 *xdr_line_length = GPU_ALIGN_UP(max(var->xres,
366 var->xres_virtual) * BPP);
367 if (*xdr_line_length > GPU_MAX_LINE_LENGTH)
368 *xdr_line_length = GPU_MAX_LINE_LENGTH;
369 } else
370 *xdr_line_length = *ddr_line_length;
371
372 /* Full broadcast modes have the full mode bit set */
373 mode = i > 12 ? (i - 12) | PS3FB_FULL_MODE_BIT : i + 1;
374
375 pr_debug("ps3fb_find_mode: mode %u\n", mode);
376
377 return mode;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800378}
379
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700380static const struct fb_videomode *ps3fb_default_mode(int id)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800381{
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700382 u32 mode = id & PS3AV_MODE_MASK;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800383 u32 flags;
384
385 if (mode < 1 || mode > 13)
386 return NULL;
387
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700388 flags = id & ~PS3AV_MODE_MASK;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800389
390 if (mode <= 10 && flags & PS3FB_FULL_MODE_BIT) {
391 /* Full broadcast mode */
392 return &ps3fb_modedb[mode + 12];
393 }
394
395 return &ps3fb_modedb[mode - 1];
396}
397
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700398static void ps3fb_sync_image(struct device *dev, u64 frame_offset,
399 u64 dst_offset, u64 src_offset, u32 width,
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700400 u32 height, u32 dst_line_length,
401 u32 src_line_length)
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700402{
403 int status;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700404 u64 line_length;
405
406 line_length = dst_line_length;
407 if (src_line_length != dst_line_length)
408 line_length |= (u64)src_line_length << 32;
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700409
410 status = lv1_gpu_context_attribute(ps3fb.context_handle,
411 L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT,
412 dst_offset, GPU_IOIF + src_offset,
413 L1GPU_FB_BLIT_WAIT_FOR_COMPLETION |
414 (width << 16) | height,
415 line_length);
416 if (status)
417 dev_err(dev,
418 "%s: lv1_gpu_context_attribute FB_BLIT failed: %d\n",
419 __func__, status);
420#ifdef HEAD_A
421 status = lv1_gpu_context_attribute(ps3fb.context_handle,
422 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP,
423 0, frame_offset, 0, 0);
424 if (status)
425 dev_err(dev, "%s: lv1_gpu_context_attribute FLIP failed: %d\n",
426 __func__, status);
427#endif
428#ifdef HEAD_B
429 status = lv1_gpu_context_attribute(ps3fb.context_handle,
430 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP,
431 1, frame_offset, 0, 0);
432 if (status)
433 dev_err(dev, "%s: lv1_gpu_context_attribute FLIP failed: %d\n",
434 __func__, status);
435#endif
436}
437
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700438static int ps3fb_sync(struct fb_info *info, u32 frame)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800439{
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700440 struct ps3fb_par *par = info->par;
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700441 int i, error = 0;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700442 u32 ddr_line_length, xdr_line_length;
443 u64 ddr_base, xdr_base;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800444
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700445 acquire_console_sem();
446
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700447 if (frame > par->num_frames - 1) {
Geert Uytterhoeven0138bd82007-10-16 01:29:46 -0700448 dev_dbg(info->device, "%s: invalid frame number (%u)\n",
449 __func__, frame);
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700450 error = -EINVAL;
451 goto out;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800452 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800453
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700454 i = par->res_index;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700455 xdr_line_length = info->fix.line_length;
456 ddr_line_length = ps3fb_res[i].xres * BPP;
457 xdr_base = frame * info->var.yres_virtual * xdr_line_length;
458 ddr_base = frame * ps3fb_res[i].yres * ddr_line_length;
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700459
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700460 ps3fb_sync_image(info->device, ddr_base + par->full_offset,
461 ddr_base + par->fb_offset, xdr_base + par->pan_offset,
462 par->width, par->height, ddr_line_length,
463 xdr_line_length);
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700464
465out:
466 release_console_sem();
467 return error;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800468}
469
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800470static int ps3fb_open(struct fb_info *info, int user)
471{
472 atomic_inc(&ps3fb.f_count);
473 return 0;
474}
475
476static int ps3fb_release(struct fb_info *info, int user)
477{
478 if (atomic_dec_and_test(&ps3fb.f_count)) {
479 if (atomic_read(&ps3fb.ext_flip)) {
480 atomic_set(&ps3fb.ext_flip, 0);
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700481 ps3fb_sync(info, 0); /* single buffer */
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800482 }
483 }
484 return 0;
485}
486
487 /*
488 * Setting the video mode has been split into two parts.
489 * First part, xxxfb_check_var, must not write anything
490 * to hardware, it should only verify and adjust var.
491 * This means it doesn't alter par but it does use hardware
492 * data from it to check this var.
493 */
494
495static int ps3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
496{
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700497 u32 xdr_line_length, ddr_line_length;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800498 int mode;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800499
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700500 dev_dbg(info->device, "var->xres:%u info->var.xres:%u\n", var->xres,
501 info->var.xres);
502 dev_dbg(info->device, "var->yres:%u info->var.yres:%u\n", var->yres,
503 info->var.yres);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800504
505 /* FIXME For now we do exact matches only */
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700506 mode = ps3fb_find_mode(var, &ddr_line_length, &xdr_line_length);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800507 if (!mode)
508 return -EINVAL;
509
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700510 /* Virtual screen */
511 if (var->xres_virtual < var->xres)
512 var->xres_virtual = var->xres;
513 if (var->yres_virtual < var->yres)
514 var->yres_virtual = var->yres;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800515
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700516 if (var->xres_virtual > xdr_line_length / BPP) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700517 dev_dbg(info->device,
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700518 "Horizontal virtual screen size too large\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800519 return -EINVAL;
520 }
521
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700522 if (var->xoffset + var->xres > var->xres_virtual ||
523 var->yoffset + var->yres > var->yres_virtual) {
524 dev_dbg(info->device, "panning out-of-range\n");
525 return -EINVAL;
526 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800527
528 /* We support ARGB8888 only */
529 if (var->bits_per_pixel > 32 || var->grayscale ||
530 var->red.offset > 16 || var->green.offset > 8 ||
531 var->blue.offset > 0 || var->transp.offset > 24 ||
532 var->red.length > 8 || var->green.length > 8 ||
533 var->blue.length > 8 || var->transp.length > 8 ||
534 var->red.msb_right || var->green.msb_right ||
535 var->blue.msb_right || var->transp.msb_right || var->nonstd) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700536 dev_dbg(info->device, "We support ARGB8888 only\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800537 return -EINVAL;
538 }
539
540 var->bits_per_pixel = 32;
541 var->red.offset = 16;
542 var->green.offset = 8;
543 var->blue.offset = 0;
544 var->transp.offset = 24;
545 var->red.length = 8;
546 var->green.length = 8;
547 var->blue.length = 8;
548 var->transp.length = 8;
549 var->red.msb_right = 0;
550 var->green.msb_right = 0;
551 var->blue.msb_right = 0;
552 var->transp.msb_right = 0;
553
554 /* Rotation is not supported */
555 if (var->rotate) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700556 dev_dbg(info->device, "Rotation is not supported\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800557 return -EINVAL;
558 }
559
560 /* Memory limit */
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700561 if (var->yres_virtual * xdr_line_length > ps3fb.xdr_size) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700562 dev_dbg(info->device, "Not enough memory\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800563 return -ENOMEM;
564 }
565
566 var->height = -1;
567 var->width = -1;
568
569 return 0;
570}
571
572 /*
573 * This routine actually sets the video mode.
574 */
575
576static int ps3fb_set_par(struct fb_info *info)
577{
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700578 struct ps3fb_par *par = info->par;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700579 unsigned int mode, ddr_line_length, xdr_line_length, lines, maxlines;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800580 int i;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700581 unsigned long offset;
582 u64 dst;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800583
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700584 dev_dbg(info->device, "xres:%d xv:%d yres:%d yv:%d clock:%d\n",
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800585 info->var.xres, info->var.xres_virtual,
586 info->var.yres, info->var.yres_virtual, info->var.pixclock);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800587
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700588 mode = ps3fb_find_mode(&info->var, &ddr_line_length, &xdr_line_length);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800589 if (!mode)
590 return -EINVAL;
591
Geert Uytterhoevenc95344a2007-10-16 01:29:25 -0700592 i = ps3fb_get_res_table(info->var.xres, info->var.yres, mode);
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700593 par->res_index = i;
Geert Uytterhoevenc95344a2007-10-16 01:29:25 -0700594
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700595 info->fix.smem_start = virt_to_abs(ps3fb.xdr_ea);
596 info->fix.smem_len = ps3fb.xdr_size;
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700597 info->fix.xpanstep = info->var.xres_virtual > info->var.xres ? 1 : 0;
598 info->fix.ypanstep = info->var.yres_virtual > info->var.yres ? 1 : 0;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700599 info->fix.line_length = xdr_line_length;
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700600
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700601 info->screen_base = (char __iomem *)ps3fb.xdr_ea;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800602
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700603 par->num_frames = ps3fb.xdr_size /
604 max(ps3fb_res[i].yres * ddr_line_length,
605 info->var.yres_virtual * xdr_line_length);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800606
607 /* Keep the special bits we cannot set using fb_var_screeninfo */
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700608 par->new_mode_id = (par->new_mode_id & ~PS3AV_MODE_MASK) | mode;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800609
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700610 par->width = info->var.xres;
611 par->height = info->var.yres;
612 offset = VP_OFF(i);
613 par->fb_offset = GPU_ALIGN_UP(offset);
614 par->full_offset = par->fb_offset - offset;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700615 par->pan_offset = info->var.yoffset * xdr_line_length +
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700616 info->var.xoffset * BPP;
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700617
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700618 if (par->new_mode_id != par->mode_id) {
619 if (ps3av_set_video_mode(par->new_mode_id)) {
620 par->new_mode_id = par->mode_id;
621 return -EINVAL;
622 }
623 par->mode_id = par->new_mode_id;
624 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800625
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700626 /* Clear XDR frame buffer memory */
627 memset(ps3fb.xdr_ea, 0, ps3fb.xdr_size);
628
629 /* Clear DDR frame buffer memory */
630 lines = ps3fb_res[i].yres * par->num_frames;
631 if (par->full_offset)
632 lines++;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700633 maxlines = ps3fb.xdr_size / ddr_line_length;
634 for (dst = 0; lines; dst += maxlines * ddr_line_length) {
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700635 unsigned int l = min(lines, maxlines);
636 ps3fb_sync_image(info->device, 0, dst, 0, ps3fb_res[i].xres, l,
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700637 ddr_line_length, ddr_line_length);
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700638 lines -= l;
639 }
640
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800641 return 0;
642}
643
644 /*
645 * Set a single color register. The values supplied are already
646 * rounded down to the hardware's capabilities (according to the
647 * entries in the var structure). Return != 0 for invalid regno.
648 */
649
650static int ps3fb_setcolreg(unsigned int regno, unsigned int red,
651 unsigned int green, unsigned int blue,
652 unsigned int transp, struct fb_info *info)
653{
654 if (regno >= 16)
655 return 1;
656
657 red >>= 8;
658 green >>= 8;
659 blue >>= 8;
660 transp >>= 8;
661
662 ((u32 *)info->pseudo_palette)[regno] = transp << 24 | red << 16 |
663 green << 8 | blue;
664 return 0;
665}
666
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700667static int ps3fb_pan_display(struct fb_var_screeninfo *var,
668 struct fb_info *info)
669{
670 struct ps3fb_par *par = info->par;
671
672 par->pan_offset = var->yoffset * info->fix.line_length +
673 var->xoffset * BPP;
674 return 0;
675}
676
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800677 /*
678 * As we have a virtual frame buffer, we need our own mmap function
679 */
680
681static int ps3fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
682{
683 unsigned long size, offset;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800684
685 size = vma->vm_end - vma->vm_start;
686 offset = vma->vm_pgoff << PAGE_SHIFT;
687 if (offset + size > info->fix.smem_len)
688 return -EINVAL;
689
Geert Uytterhoeven2ce32e12007-10-16 01:29:48 -0700690 offset += info->fix.smem_start;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800691 if (remap_pfn_range(vma, vma->vm_start, offset >> PAGE_SHIFT,
692 size, vma->vm_page_prot))
693 return -EAGAIN;
694
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700695 dev_dbg(info->device, "ps3fb: mmap framebuffer P(%lx)->V(%lx)\n",
696 offset, vma->vm_start);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800697 return 0;
698}
699
700 /*
701 * Blank the display
702 */
703
704static int ps3fb_blank(int blank, struct fb_info *info)
705{
706 int retval;
707
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700708 dev_dbg(info->device, "%s: blank:%d\n", __func__, blank);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800709 switch (blank) {
710 case FB_BLANK_POWERDOWN:
711 case FB_BLANK_HSYNC_SUSPEND:
712 case FB_BLANK_VSYNC_SUSPEND:
713 case FB_BLANK_NORMAL:
714 retval = ps3av_video_mute(1); /* mute on */
715 if (!retval)
716 ps3fb.is_blanked = 1;
717 break;
718
719 default: /* unblank */
720 retval = ps3av_video_mute(0); /* mute off */
721 if (!retval)
722 ps3fb.is_blanked = 0;
723 break;
724 }
725 return retval;
726}
727
728static int ps3fb_get_vblank(struct fb_vblank *vblank)
729{
Li Zefan3cc2c172007-11-14 16:58:33 -0800730 memset(vblank, 0, sizeof(*vblank));
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800731 vblank->flags = FB_VBLANK_HAVE_VSYNC;
732 return 0;
733}
734
Geert Uytterhoeven15e4d002007-10-16 01:29:47 -0700735static int ps3fb_wait_for_vsync(u32 crtc)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800736{
737 int ret;
738 u64 count;
739
740 count = ps3fb.vblank_count;
741 ret = wait_event_interruptible_timeout(ps3fb.wait_vsync,
742 count != ps3fb.vblank_count,
743 HZ / 10);
744 if (!ret)
745 return -ETIMEDOUT;
746
747 return 0;
748}
749
Geert Uytterhoeven15e4d002007-10-16 01:29:47 -0700750static void ps3fb_flip_ctl(int on, void *data)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800751{
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000752 struct ps3fb_priv *priv = data;
Geert Uytterhoeveneca28742007-05-02 14:48:32 +0200753 if (on)
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000754 atomic_dec_if_positive(&priv->ext_flip);
Geert Uytterhoeveneca28742007-05-02 14:48:32 +0200755 else
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000756 atomic_inc(&priv->ext_flip);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800757}
758
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800759
760 /*
761 * ioctl
762 */
763
764static int ps3fb_ioctl(struct fb_info *info, unsigned int cmd,
765 unsigned long arg)
766{
767 void __user *argp = (void __user *)arg;
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700768 u32 val;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800769 int retval = -EFAULT;
770
771 switch (cmd) {
772 case FBIOGET_VBLANK:
773 {
774 struct fb_vblank vblank;
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700775 dev_dbg(info->device, "FBIOGET_VBLANK:\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800776 retval = ps3fb_get_vblank(&vblank);
777 if (retval)
778 break;
779
780 if (copy_to_user(argp, &vblank, sizeof(vblank)))
781 retval = -EFAULT;
782 break;
783 }
784
785 case FBIO_WAITFORVSYNC:
786 {
787 u32 crt;
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700788 dev_dbg(info->device, "FBIO_WAITFORVSYNC:\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800789 if (get_user(crt, (u32 __user *) arg))
790 break;
791
792 retval = ps3fb_wait_for_vsync(crt);
793 break;
794 }
795
796 case PS3FB_IOCTL_SETMODE:
797 {
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700798 struct ps3fb_par *par = info->par;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800799 const struct fb_videomode *mode;
800 struct fb_var_screeninfo var;
801
802 if (copy_from_user(&val, argp, sizeof(val)))
803 break;
804
Masashi Kimoto64072902007-05-02 14:48:36 +0200805 if (!(val & PS3AV_MODE_MASK)) {
Geert Uytterhoevence4c3712007-10-16 01:29:44 -0700806 u32 id = ps3av_get_auto_mode();
Masashi Kimoto64072902007-05-02 14:48:36 +0200807 if (id > 0)
808 val = (val & ~PS3AV_MODE_MASK) | id;
809 }
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700810 dev_dbg(info->device, "PS3FB_IOCTL_SETMODE:%x\n", val);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800811 retval = -EINVAL;
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700812 mode = ps3fb_default_mode(val);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800813 if (mode) {
814 var = info->var;
815 fb_videomode_to_var(&var, mode);
816 acquire_console_sem();
817 info->flags |= FBINFO_MISC_USEREVENT;
818 /* Force, in case only special bits changed */
819 var.activate |= FB_ACTIVATE_FORCE;
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700820 par->new_mode_id = val;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800821 retval = fb_set_var(info, &var);
822 info->flags &= ~FBINFO_MISC_USEREVENT;
823 release_console_sem();
824 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800825 break;
826 }
827
828 case PS3FB_IOCTL_GETMODE:
829 val = ps3av_get_mode();
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700830 dev_dbg(info->device, "PS3FB_IOCTL_GETMODE:%x\n", val);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800831 if (!copy_to_user(argp, &val, sizeof(val)))
832 retval = 0;
833 break;
834
835 case PS3FB_IOCTL_SCREENINFO:
836 {
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700837 struct ps3fb_par *par = info->par;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800838 struct ps3fb_ioctl_res res;
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700839 dev_dbg(info->device, "PS3FB_IOCTL_SCREENINFO:\n");
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700840 res.xres = info->fix.line_length / BPP;
841 res.yres = info->var.yres_virtual;
842 res.xoff = (res.xres - info->var.xres) / 2;
843 res.yoff = (res.yres - info->var.yres) / 2;
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700844 res.num_frames = par->num_frames;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800845 if (!copy_to_user(argp, &res, sizeof(res)))
846 retval = 0;
847 break;
848 }
849
850 case PS3FB_IOCTL_ON:
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700851 dev_dbg(info->device, "PS3FB_IOCTL_ON:\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800852 atomic_inc(&ps3fb.ext_flip);
853 retval = 0;
854 break;
855
856 case PS3FB_IOCTL_OFF:
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700857 dev_dbg(info->device, "PS3FB_IOCTL_OFF:\n");
Geert Uytterhoeveneca28742007-05-02 14:48:32 +0200858 atomic_dec_if_positive(&ps3fb.ext_flip);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800859 retval = 0;
860 break;
861
862 case PS3FB_IOCTL_FSEL:
863 if (copy_from_user(&val, argp, sizeof(val)))
864 break;
865
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700866 dev_dbg(info->device, "PS3FB_IOCTL_FSEL:%d\n", val);
867 retval = ps3fb_sync(info, val);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800868 break;
869
870 default:
871 retval = -ENOIOCTLCMD;
872 break;
873 }
874 return retval;
875}
876
877static int ps3fbd(void *arg)
878{
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700879 struct fb_info *info = arg;
880
Rafael J. Wysocki83144182007-07-17 04:03:35 -0700881 set_freezable();
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +0200882 while (!kthread_should_stop()) {
883 try_to_freeze();
884 set_current_state(TASK_INTERRUPTIBLE);
885 if (ps3fb.is_kicked) {
886 ps3fb.is_kicked = 0;
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700887 ps3fb_sync(info, 0); /* single buffer */
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +0200888 }
889 schedule();
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800890 }
891 return 0;
892}
893
894static irqreturn_t ps3fb_vsync_interrupt(int irq, void *ptr)
895{
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700896 struct device *dev = ptr;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800897 u64 v1;
898 int status;
899 struct display_head *head = &ps3fb.dinfo->display_head[1];
900
901 status = lv1_gpu_context_intr(ps3fb.context_handle, &v1);
902 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700903 dev_err(dev, "%s: lv1_gpu_context_intr failed: %d\n", __func__,
904 status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800905 return IRQ_NONE;
906 }
907
908 if (v1 & (1 << GPU_INTR_STATUS_VSYNC_1)) {
909 /* VSYNC */
910 ps3fb.vblank_count = head->vblank_count;
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +0200911 if (ps3fb.task && !ps3fb.is_blanked &&
912 !atomic_read(&ps3fb.ext_flip)) {
913 ps3fb.is_kicked = 1;
914 wake_up_process(ps3fb.task);
915 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800916 wake_up_interruptible(&ps3fb.wait_vsync);
917 }
918
919 return IRQ_HANDLED;
920}
921
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800922
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000923static int ps3fb_vsync_settings(struct gpu_driver_info *dinfo,
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700924 struct device *dev)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800925{
926 int error;
927
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700928 dev_dbg(dev, "version_driver:%x\n", dinfo->version_driver);
929 dev_dbg(dev, "irq outlet:%x\n", dinfo->irq.irq_outlet);
930 dev_dbg(dev,
931 "version_gpu: %x memory_size: %x ch: %x core_freq: %d "
932 "mem_freq:%d\n",
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800933 dinfo->version_gpu, dinfo->memory_size, dinfo->hardware_channel,
934 dinfo->nvcore_frequency/1000000, dinfo->memory_frequency/1000000);
935
936 if (dinfo->version_driver != GPU_DRIVER_INFO_VERSION) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700937 dev_err(dev, "%s: version_driver err:%x\n", __func__,
938 dinfo->version_driver);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800939 return -EINVAL;
940 }
941
Geoff Levanddc4f60c2007-05-01 07:01:01 +1000942 error = ps3_irq_plug_setup(PS3_BINDING_CPU_ANY, dinfo->irq.irq_outlet,
943 &ps3fb.irq_no);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800944 if (error) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700945 dev_err(dev, "%s: ps3_alloc_irq failed %d\n", __func__, error);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800946 return error;
947 }
948
949 error = request_irq(ps3fb.irq_no, ps3fb_vsync_interrupt, IRQF_DISABLED,
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000950 DEVICE_NAME, dev);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800951 if (error) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700952 dev_err(dev, "%s: request_irq failed %d\n", __func__, error);
Geoff Levanddc4f60c2007-05-01 07:01:01 +1000953 ps3_irq_plug_destroy(ps3fb.irq_no);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800954 return error;
955 }
956
957 dinfo->irq.mask = (1 << GPU_INTR_STATUS_VSYNC_1) |
958 (1 << GPU_INTR_STATUS_FLIP_1);
959 return 0;
960}
961
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700962static int ps3fb_xdr_settings(u64 xdr_lpar, struct device *dev)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800963{
964 int status;
965
966 status = lv1_gpu_context_iomap(ps3fb.context_handle, GPU_IOIF,
967 xdr_lpar, ps3fb_videomemory.size, 0);
968 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700969 dev_err(dev, "%s: lv1_gpu_context_iomap failed: %d\n",
970 __func__, status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800971 return -ENXIO;
972 }
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700973 dev_dbg(dev,
974 "video:%p xdr_ea:%p ioif:%lx lpar:%lx phys:%lx size:%lx\n",
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800975 ps3fb_videomemory.address, ps3fb.xdr_ea, GPU_IOIF, xdr_lpar,
976 virt_to_abs(ps3fb.xdr_ea), ps3fb_videomemory.size);
977
978 status = lv1_gpu_context_attribute(ps3fb.context_handle,
979 L1GPU_CONTEXT_ATTRIBUTE_FB_SETUP,
Geert Uytterhoeven2ce32e12007-10-16 01:29:48 -0700980 xdr_lpar + ps3fb.xdr_size,
981 GPU_CMD_BUF_SIZE,
982 GPU_IOIF + ps3fb.xdr_size, 0);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800983 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700984 dev_err(dev,
985 "%s: lv1_gpu_context_attribute FB_SETUP failed: %d\n",
986 __func__, status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800987 return -ENXIO;
988 }
989 return 0;
990}
991
992static struct fb_ops ps3fb_ops = {
993 .fb_open = ps3fb_open,
994 .fb_release = ps3fb_release,
Geert Uytterhoeven92c45792007-05-23 13:57:50 -0700995 .fb_read = fb_sys_read,
996 .fb_write = fb_sys_write,
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800997 .fb_check_var = ps3fb_check_var,
998 .fb_set_par = ps3fb_set_par,
999 .fb_setcolreg = ps3fb_setcolreg,
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -07001000 .fb_pan_display = ps3fb_pan_display,
Geert Uytterhoeven92c45792007-05-23 13:57:50 -07001001 .fb_fillrect = sys_fillrect,
1002 .fb_copyarea = sys_copyarea,
1003 .fb_imageblit = sys_imageblit,
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001004 .fb_mmap = ps3fb_mmap,
1005 .fb_blank = ps3fb_blank,
1006 .fb_ioctl = ps3fb_ioctl,
1007 .fb_compat_ioctl = ps3fb_ioctl
1008};
1009
1010static struct fb_fix_screeninfo ps3fb_fix __initdata = {
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001011 .id = DEVICE_NAME,
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001012 .type = FB_TYPE_PACKED_PIXELS,
1013 .visual = FB_VISUAL_TRUECOLOR,
1014 .accel = FB_ACCEL_NONE,
1015};
1016
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001017static int ps3fb_set_sync(struct device *dev)
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001018{
1019 int status;
1020
1021#ifdef HEAD_A
1022 status = lv1_gpu_context_attribute(0x0,
1023 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
1024 0, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0);
1025 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001026 dev_err(dev,
1027 "%s: lv1_gpu_context_attribute DISPLAY_SYNC failed: "
1028 "%d\n",
1029 __func__, status);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001030 return -1;
1031 }
1032#endif
1033#ifdef HEAD_B
1034 status = lv1_gpu_context_attribute(0x0,
1035 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
1036 1, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0);
1037
1038 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001039 dev_err(dev,
1040 "%s: lv1_gpu_context_attribute DISPLAY_SYNC failed: "
1041 "%d\n",
1042 __func__, status);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001043 return -1;
1044 }
1045#endif
1046 return 0;
1047}
1048
1049static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001050{
1051 struct fb_info *info;
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -07001052 struct ps3fb_par *par;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001053 int retval = -ENOMEM;
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001054 u32 xres, yres;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001055 u64 ddr_lpar = 0;
1056 u64 lpar_dma_control = 0;
1057 u64 lpar_driver_info = 0;
1058 u64 lpar_reports = 0;
1059 u64 lpar_reports_size = 0;
1060 u64 xdr_lpar;
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -07001061 int status, res_index;
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +02001062 struct task_struct *task;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001063
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001064 status = ps3_open_hv_device(dev);
1065 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001066 dev_err(&dev->core, "%s: ps3_open_hv_device failed\n",
1067 __func__);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001068 goto err;
1069 }
1070
1071 if (!ps3fb_mode)
1072 ps3fb_mode = ps3av_get_mode();
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001073 dev_dbg(&dev->core, "ps3av_mode:%d\n", ps3fb_mode);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001074
1075 if (ps3fb_mode > 0 &&
1076 !ps3av_video_mode2res(ps3fb_mode, &xres, &yres)) {
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -07001077 res_index = ps3fb_get_res_table(xres, yres, ps3fb_mode);
1078 dev_dbg(&dev->core, "res_index:%d\n", res_index);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001079 } else
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -07001080 res_index = GPU_RES_INDEX;
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001081
1082 atomic_set(&ps3fb.f_count, -1); /* fbcon opens ps3fb */
1083 atomic_set(&ps3fb.ext_flip, 0); /* for flip with vsync */
1084 init_waitqueue_head(&ps3fb.wait_vsync);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001085
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001086 ps3fb_set_sync(&dev->core);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001087
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001088 /* get gpu context handle */
1089 status = lv1_gpu_memory_allocate(DDR_SIZE, 0, 0, 0, 0,
1090 &ps3fb.memory_handle, &ddr_lpar);
1091 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001092 dev_err(&dev->core, "%s: lv1_gpu_memory_allocate failed: %d\n",
1093 __func__, status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001094 goto err;
1095 }
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001096 dev_dbg(&dev->core, "ddr:lpar:0x%lx\n", ddr_lpar);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001097
1098 status = lv1_gpu_context_allocate(ps3fb.memory_handle, 0,
1099 &ps3fb.context_handle,
1100 &lpar_dma_control, &lpar_driver_info,
1101 &lpar_reports, &lpar_reports_size);
1102 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001103 dev_err(&dev->core,
1104 "%s: lv1_gpu_context_attribute failed: %d\n", __func__,
1105 status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001106 goto err_gpu_memory_free;
1107 }
1108
1109 /* vsync interrupt */
1110 ps3fb.dinfo = ioremap(lpar_driver_info, 128 * 1024);
1111 if (!ps3fb.dinfo) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001112 dev_err(&dev->core, "%s: ioremap failed\n", __func__);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001113 goto err_gpu_context_free;
1114 }
1115
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001116 retval = ps3fb_vsync_settings(ps3fb.dinfo, &dev->core);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001117 if (retval)
1118 goto err_iounmap_dinfo;
1119
Geert Uytterhoeven2ce32e12007-10-16 01:29:48 -07001120 /* XDR frame buffer */
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001121 ps3fb.xdr_ea = ps3fb_videomemory.address;
1122 xdr_lpar = ps3_mm_phys_to_lpar(__pa(ps3fb.xdr_ea));
Geert Uytterhoeven2ce32e12007-10-16 01:29:48 -07001123
1124 /* Clear memory to prevent kernel info leakage into userspace */
1125 memset(ps3fb.xdr_ea, 0, ps3fb_videomemory.size);
1126
1127 /* The GPU command buffer is at the end of video memory */
1128 ps3fb.xdr_size = ps3fb_videomemory.size - GPU_CMD_BUF_SIZE;
1129
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001130 retval = ps3fb_xdr_settings(xdr_lpar, &dev->core);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001131 if (retval)
1132 goto err_free_irq;
1133
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -07001134 info = framebuffer_alloc(sizeof(struct ps3fb_par), &dev->core);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001135 if (!info)
1136 goto err_free_irq;
1137
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -07001138 par = info->par;
1139 par->mode_id = ~ps3fb_mode; /* != ps3fb_mode, to trigger change */
1140 par->new_mode_id = ps3fb_mode;
1141 par->res_index = res_index;
1142 par->num_frames = 1;
1143
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -07001144 info->screen_base = (char __iomem *)ps3fb.xdr_ea;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001145 info->fbops = &ps3fb_ops;
1146
1147 info->fix = ps3fb_fix;
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -07001148 info->fix.smem_start = virt_to_abs(ps3fb.xdr_ea);
1149 info->fix.smem_len = ps3fb.xdr_size;
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -07001150 info->pseudo_palette = par->pseudo_palette;
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -07001151 info->flags = FBINFO_DEFAULT | FBINFO_READS_FAST |
1152 FBINFO_HWACCEL_XPAN | FBINFO_HWACCEL_YPAN;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001153
1154 retval = fb_alloc_cmap(&info->cmap, 256, 0);
1155 if (retval < 0)
1156 goto err_framebuffer_release;
1157
1158 if (!fb_find_mode(&info->var, info, mode_option, ps3fb_modedb,
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -07001159 ARRAY_SIZE(ps3fb_modedb),
1160 ps3fb_default_mode(par->new_mode_id), 32)) {
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001161 retval = -EINVAL;
1162 goto err_fb_dealloc;
1163 }
1164
1165 fb_videomode_to_modelist(ps3fb_modedb, ARRAY_SIZE(ps3fb_modedb),
1166 &info->modelist);
1167
1168 retval = register_framebuffer(info);
1169 if (retval < 0)
1170 goto err_fb_dealloc;
1171
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001172 dev->core.driver_data = info;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001173
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001174 dev_info(info->device, "%s %s, using %lu KiB of video memory\n",
1175 dev_driver_string(info->dev), info->dev->bus_id,
Geert Uytterhoeven2ce32e12007-10-16 01:29:48 -07001176 ps3fb.xdr_size >> 10);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001177
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001178 task = kthread_run(ps3fbd, info, DEVICE_NAME);
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +02001179 if (IS_ERR(task)) {
1180 retval = PTR_ERR(task);
1181 goto err_unregister_framebuffer;
1182 }
1183
1184 ps3fb.task = task;
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001185 ps3av_register_flip_ctl(ps3fb_flip_ctl, &ps3fb);
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +02001186
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001187 return 0;
1188
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +02001189err_unregister_framebuffer:
1190 unregister_framebuffer(info);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001191err_fb_dealloc:
1192 fb_dealloc_cmap(&info->cmap);
1193err_framebuffer_release:
1194 framebuffer_release(info);
1195err_free_irq:
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001196 free_irq(ps3fb.irq_no, dev);
Geoff Levanddc4f60c2007-05-01 07:01:01 +10001197 ps3_irq_plug_destroy(ps3fb.irq_no);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001198err_iounmap_dinfo:
1199 iounmap((u8 __iomem *)ps3fb.dinfo);
1200err_gpu_context_free:
1201 lv1_gpu_context_free(ps3fb.context_handle);
1202err_gpu_memory_free:
1203 lv1_gpu_memory_free(ps3fb.memory_handle);
1204err:
1205 return retval;
1206}
1207
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001208static int ps3fb_shutdown(struct ps3_system_bus_device *dev)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001209{
1210 int status;
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001211 struct fb_info *info = dev->core.driver_data;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001212
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001213 dev_dbg(&dev->core, " -> %s:%d\n", __func__, __LINE__);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001214
1215 ps3fb_flip_ctl(0, &ps3fb); /* flip off */
1216 ps3fb.dinfo->irq.mask = 0;
1217
1218 if (info) {
1219 unregister_framebuffer(info);
1220 fb_dealloc_cmap(&info->cmap);
1221 framebuffer_release(info);
1222 }
1223
1224 ps3av_register_flip_ctl(NULL, NULL);
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +02001225 if (ps3fb.task) {
1226 struct task_struct *task = ps3fb.task;
1227 ps3fb.task = NULL;
1228 kthread_stop(task);
1229 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001230 if (ps3fb.irq_no) {
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001231 free_irq(ps3fb.irq_no, dev);
Geoff Levanddc4f60c2007-05-01 07:01:01 +10001232 ps3_irq_plug_destroy(ps3fb.irq_no);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001233 }
1234 iounmap((u8 __iomem *)ps3fb.dinfo);
1235
1236 status = lv1_gpu_context_free(ps3fb.context_handle);
1237 if (status)
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001238 dev_dbg(&dev->core, "lv1_gpu_context_free failed: %d\n",
1239 status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001240
1241 status = lv1_gpu_memory_free(ps3fb.memory_handle);
1242 if (status)
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001243 dev_dbg(&dev->core, "lv1_gpu_memory_free failed: %d\n",
1244 status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001245
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001246 ps3_close_hv_device(dev);
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001247 dev_dbg(&dev->core, " <- %s:%d\n", __func__, __LINE__);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001248
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001249 return 0;
1250}
1251
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001252static struct ps3_system_bus_driver ps3fb_driver = {
1253 .match_id = PS3_MATCH_ID_GRAPHICS,
1254 .core.name = DEVICE_NAME,
1255 .core.owner = THIS_MODULE,
1256 .probe = ps3fb_probe,
1257 .remove = ps3fb_shutdown,
1258 .shutdown = ps3fb_shutdown,
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001259};
1260
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001261static int __init ps3fb_setup(void)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001262{
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001263 char *options;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001264
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001265#ifdef MODULE
1266 return 0;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001267#endif
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001268
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001269 if (fb_get_options(DEVICE_NAME, &options))
1270 return -ENXIO;
1271
1272 if (!options || !*options)
1273 return 0;
1274
1275 while (1) {
1276 char *this_opt = strsep(&options, ",");
1277
1278 if (!this_opt)
1279 break;
1280 if (!*this_opt)
1281 continue;
1282 if (!strncmp(this_opt, "mode:", 5))
1283 ps3fb_mode = simple_strtoul(this_opt + 5, NULL, 0);
1284 else
1285 mode_option = this_opt;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001286 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001287 return 0;
1288}
1289
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001290static int __init ps3fb_init(void)
1291{
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001292 if (!ps3fb_videomemory.address || ps3fb_setup())
1293 return -ENXIO;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001294
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001295 return ps3_system_bus_driver_register(&ps3fb_driver);
1296}
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001297
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001298static void __exit ps3fb_exit(void)
1299{
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001300 pr_debug(" -> %s:%d\n", __func__, __LINE__);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001301 ps3_system_bus_driver_unregister(&ps3fb_driver);
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001302 pr_debug(" <- %s:%d\n", __func__, __LINE__);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001303}
1304
1305module_init(ps3fb_init);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001306module_exit(ps3fb_exit);
1307
1308MODULE_LICENSE("GPL");
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001309MODULE_DESCRIPTION("PS3 GPU Frame Buffer Driver");
1310MODULE_AUTHOR("Sony Computer Entertainment Inc.");
1311MODULE_ALIAS(PS3_MODULE_ALIAS_GRAPHICS);