blob: b23d64070eefcca3d540320091759c9aeb35f63c [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
Geert Uytterhoeven9ac67a32007-12-19 11:16:41 +010054#define GPU_CMD_BUF_SIZE (2 * 1024 * 1024)
55#define GPU_FB_START (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
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -080060#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 */
70struct 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
87struct 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
101struct 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
115struct ps3fb_priv {
116 unsigned int irq_no;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800117
118 u64 context_handle, memory_handle;
119 void *xdr_ea;
Geert Uytterhoeven2ce32e12007-10-16 01:29:48 -0700120 size_t xdr_size;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800121 struct gpu_driver_info *dinfo;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800122
123 u64 vblank_count; /* frame count */
124 wait_queue_head_t wait_vsync;
125
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800126 atomic_t ext_flip; /* on/off flip with vsync */
127 atomic_t f_count; /* fb_open count */
128 int is_blanked;
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +0200129 int is_kicked;
130 struct task_struct *task;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800131};
132static struct ps3fb_priv ps3fb;
133
Geert Uytterhoeven0333d832007-10-16 01:29:48 -0700134struct ps3fb_par {
135 u32 pseudo_palette[16];
136 int mode_id, new_mode_id;
Geert Uytterhoeven0333d832007-10-16 01:29:48 -0700137 unsigned int num_frames; /* num of frame buffers */
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700138 unsigned int width;
139 unsigned int height;
Geert Uytterhoeven9f4f21b2008-02-06 01:39:31 -0800140 unsigned int ddr_line_length;
141 unsigned int ddr_frame_size;
142 unsigned int xdr_frame_size;
Geert Uytterhoeven7974f722008-02-06 01:39:32 -0800143 unsigned int full_offset; /* start of fullscreen DDR fb */
144 unsigned int fb_offset; /* start of actual DDR fb */
145 unsigned int pan_offset;
Geert Uytterhoeven0333d832007-10-16 01:29:48 -0700146};
147
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800148
149static 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 Uytterhoeven2ce32e12007-10-16 01:29:48 -0700265#define BPP 4 /* number of bytes per pixel */
266
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800267
Geert Uytterhoevenbd685ac2007-05-02 14:48:34 +0200268static int ps3fb_mode;
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000269module_param(ps3fb_mode, int, 0);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800270
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000271static char *mode_option __devinitdata;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800272
Geert Uytterhoeven633bd112008-02-06 01:39:33 -0800273static int ps3fb_cmp_mode(const struct fb_videomode *vmode,
274 const struct fb_var_screeninfo *var)
275{
276 /* resolution + black border must match a native resolution */
277 if (vmode->left_margin + vmode->xres + vmode->right_margin !=
278 var->left_margin + var->xres + var->right_margin ||
279 vmode->upper_margin + vmode->yres + vmode->lower_margin !=
280 var->upper_margin + var->yres + var->lower_margin)
281 return -1;
282
283 /* minimum limits for margins */
284 if (vmode->left_margin > var->left_margin ||
285 vmode->right_margin > var->right_margin ||
286 vmode->upper_margin > var->upper_margin ||
287 vmode->lower_margin > var->lower_margin)
288 return -1;
289
290 /* these fields must match exactly */
291 if (vmode->pixclock != var->pixclock ||
292 vmode->hsync_len != var->hsync_len ||
293 vmode->vsync_len != var->vsync_len ||
294 vmode->sync != var->sync ||
295 vmode->vmode != (var->vmode & FB_VMODE_MASK))
296 return -1;
297
298 return 0;
299}
300
301static unsigned int ps3fb_find_mode(struct fb_var_screeninfo *var,
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700302 u32 *ddr_line_length, u32 *xdr_line_length)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800303{
Geert Uytterhoeven633bd112008-02-06 01:39:33 -0800304 unsigned int i, mode;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800305
Geert Uytterhoeven633bd112008-02-06 01:39:33 -0800306 for (i = PS3AV_MODE_1080P50; i < ARRAY_SIZE(ps3fb_modedb); i++)
307 if (!ps3fb_cmp_mode(&ps3fb_modedb[i], var))
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700308 goto found;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800309
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700310 pr_debug("ps3fb_find_mode: mode not found\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800311 return 0;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700312
313found:
Geert Uytterhoeven633bd112008-02-06 01:39:33 -0800314 *ddr_line_length = ps3fb_modedb[i].xres * BPP;
315
316 if (!var->xres) {
317 var->xres = 1;
318 var->right_margin--;
319 }
320 if (!var->yres) {
321 var->yres = 1;
322 var->lower_margin--;
323 }
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700324
325 if (ps3_compare_firmware_version(1, 9, 0) >= 0) {
326 *xdr_line_length = GPU_ALIGN_UP(max(var->xres,
327 var->xres_virtual) * BPP);
328 if (*xdr_line_length > GPU_MAX_LINE_LENGTH)
329 *xdr_line_length = GPU_MAX_LINE_LENGTH;
330 } else
331 *xdr_line_length = *ddr_line_length;
332
Geert Uytterhoeven084ffff2008-02-06 01:39:29 -0800333 mode = i+1;
Geert Uytterhoeven633bd112008-02-06 01:39:33 -0800334 if (mode > PS3AV_MODE_WUXGA) {
335 mode -= PS3AV_MODE_WUXGA;
336 /* Full broadcast modes have the full mode bit set */
337 if (ps3fb_modedb[i].xres == var->xres &&
338 ps3fb_modedb[i].yres == var->yres)
339 mode |= PS3AV_MODE_FULL;
340 }
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700341
342 pr_debug("ps3fb_find_mode: mode %u\n", mode);
343
344 return mode;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800345}
346
Geert Uytterhoeven0333d832007-10-16 01:29:48 -0700347static const struct fb_videomode *ps3fb_default_mode(int id)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800348{
Geert Uytterhoeven0333d832007-10-16 01:29:48 -0700349 u32 mode = id & PS3AV_MODE_MASK;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800350 u32 flags;
351
Geert Uytterhoeven084ffff2008-02-06 01:39:29 -0800352 if (mode < PS3AV_MODE_480I || mode > PS3AV_MODE_WUXGA)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800353 return NULL;
354
Geert Uytterhoeven0333d832007-10-16 01:29:48 -0700355 flags = id & ~PS3AV_MODE_MASK;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800356
Geert Uytterhoevenbbcfe342008-02-06 01:39:30 -0800357 if (mode <= PS3AV_MODE_1080P50 && flags & PS3AV_MODE_FULL) {
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800358 /* Full broadcast mode */
Geert Uytterhoeven084ffff2008-02-06 01:39:29 -0800359 return &ps3fb_modedb[mode + PS3AV_MODE_WUXGA - 1];
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800360 }
361
362 return &ps3fb_modedb[mode - 1];
363}
364
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700365static void ps3fb_sync_image(struct device *dev, u64 frame_offset,
366 u64 dst_offset, u64 src_offset, u32 width,
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700367 u32 height, u32 dst_line_length,
368 u32 src_line_length)
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700369{
370 int status;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700371 u64 line_length;
372
373 line_length = dst_line_length;
374 if (src_line_length != dst_line_length)
375 line_length |= (u64)src_line_length << 32;
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700376
Geert Uytterhoeven9ac67a32007-12-19 11:16:41 +0100377 src_offset += GPU_FB_START;
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700378 status = lv1_gpu_context_attribute(ps3fb.context_handle,
379 L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT,
380 dst_offset, GPU_IOIF + src_offset,
381 L1GPU_FB_BLIT_WAIT_FOR_COMPLETION |
382 (width << 16) | height,
383 line_length);
384 if (status)
385 dev_err(dev,
386 "%s: lv1_gpu_context_attribute FB_BLIT failed: %d\n",
387 __func__, status);
388#ifdef HEAD_A
389 status = lv1_gpu_context_attribute(ps3fb.context_handle,
390 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP,
391 0, frame_offset, 0, 0);
392 if (status)
393 dev_err(dev, "%s: lv1_gpu_context_attribute FLIP failed: %d\n",
394 __func__, status);
395#endif
396#ifdef HEAD_B
397 status = lv1_gpu_context_attribute(ps3fb.context_handle,
398 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP,
399 1, frame_offset, 0, 0);
400 if (status)
401 dev_err(dev, "%s: lv1_gpu_context_attribute FLIP failed: %d\n",
402 __func__, status);
403#endif
404}
405
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700406static int ps3fb_sync(struct fb_info *info, u32 frame)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800407{
Geert Uytterhoeven0333d832007-10-16 01:29:48 -0700408 struct ps3fb_par *par = info->par;
Geert Uytterhoeven9f4f21b2008-02-06 01:39:31 -0800409 int error = 0;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700410 u64 ddr_base, xdr_base;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800411
Geert Uytterhoeven0333d832007-10-16 01:29:48 -0700412 if (frame > par->num_frames - 1) {
Geert Uytterhoeven0138bd82007-10-16 01:29:46 -0700413 dev_dbg(info->device, "%s: invalid frame number (%u)\n",
414 __func__, frame);
Geert Uytterhoeven0333d832007-10-16 01:29:48 -0700415 error = -EINVAL;
416 goto out;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800417 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800418
Geert Uytterhoeven9f4f21b2008-02-06 01:39:31 -0800419 xdr_base = frame * par->xdr_frame_size;
420 ddr_base = frame * par->ddr_frame_size;
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700421
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700422 ps3fb_sync_image(info->device, ddr_base + par->full_offset,
423 ddr_base + par->fb_offset, xdr_base + par->pan_offset,
Geert Uytterhoeven9f4f21b2008-02-06 01:39:31 -0800424 par->width, par->height, par->ddr_line_length,
425 info->fix.line_length);
Geert Uytterhoeven0333d832007-10-16 01:29:48 -0700426
427out:
Geert Uytterhoeven0333d832007-10-16 01:29:48 -0700428 return error;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800429}
430
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800431static int ps3fb_open(struct fb_info *info, int user)
432{
433 atomic_inc(&ps3fb.f_count);
434 return 0;
435}
436
437static int ps3fb_release(struct fb_info *info, int user)
438{
439 if (atomic_dec_and_test(&ps3fb.f_count)) {
440 if (atomic_read(&ps3fb.ext_flip)) {
441 atomic_set(&ps3fb.ext_flip, 0);
Jeremy Kerr8dab6372008-01-11 14:28:04 +0100442 if (!try_acquire_console_sem()) {
443 ps3fb_sync(info, 0); /* single buffer */
444 release_console_sem();
445 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800446 }
447 }
448 return 0;
449}
450
451 /*
452 * Setting the video mode has been split into two parts.
453 * First part, xxxfb_check_var, must not write anything
454 * to hardware, it should only verify and adjust var.
455 * This means it doesn't alter par but it does use hardware
456 * data from it to check this var.
457 */
458
459static int ps3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
460{
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700461 u32 xdr_line_length, ddr_line_length;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800462 int mode;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800463
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700464 dev_dbg(info->device, "var->xres:%u info->var.xres:%u\n", var->xres,
465 info->var.xres);
466 dev_dbg(info->device, "var->yres:%u info->var.yres:%u\n", var->yres,
467 info->var.yres);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800468
469 /* FIXME For now we do exact matches only */
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700470 mode = ps3fb_find_mode(var, &ddr_line_length, &xdr_line_length);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800471 if (!mode)
472 return -EINVAL;
473
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700474 /* Virtual screen */
475 if (var->xres_virtual < var->xres)
476 var->xres_virtual = var->xres;
477 if (var->yres_virtual < var->yres)
478 var->yres_virtual = var->yres;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800479
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700480 if (var->xres_virtual > xdr_line_length / BPP) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700481 dev_dbg(info->device,
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700482 "Horizontal virtual screen size too large\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800483 return -EINVAL;
484 }
485
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700486 if (var->xoffset + var->xres > var->xres_virtual ||
487 var->yoffset + var->yres > var->yres_virtual) {
488 dev_dbg(info->device, "panning out-of-range\n");
489 return -EINVAL;
490 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800491
492 /* We support ARGB8888 only */
493 if (var->bits_per_pixel > 32 || var->grayscale ||
494 var->red.offset > 16 || var->green.offset > 8 ||
495 var->blue.offset > 0 || var->transp.offset > 24 ||
496 var->red.length > 8 || var->green.length > 8 ||
497 var->blue.length > 8 || var->transp.length > 8 ||
498 var->red.msb_right || var->green.msb_right ||
499 var->blue.msb_right || var->transp.msb_right || var->nonstd) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700500 dev_dbg(info->device, "We support ARGB8888 only\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800501 return -EINVAL;
502 }
503
504 var->bits_per_pixel = 32;
505 var->red.offset = 16;
506 var->green.offset = 8;
507 var->blue.offset = 0;
508 var->transp.offset = 24;
509 var->red.length = 8;
510 var->green.length = 8;
511 var->blue.length = 8;
512 var->transp.length = 8;
513 var->red.msb_right = 0;
514 var->green.msb_right = 0;
515 var->blue.msb_right = 0;
516 var->transp.msb_right = 0;
517
518 /* Rotation is not supported */
519 if (var->rotate) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700520 dev_dbg(info->device, "Rotation is not supported\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800521 return -EINVAL;
522 }
523
524 /* Memory limit */
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700525 if (var->yres_virtual * xdr_line_length > ps3fb.xdr_size) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700526 dev_dbg(info->device, "Not enough memory\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800527 return -ENOMEM;
528 }
529
530 var->height = -1;
531 var->width = -1;
532
533 return 0;
534}
535
536 /*
537 * This routine actually sets the video mode.
538 */
539
540static int ps3fb_set_par(struct fb_info *info)
541{
Geert Uytterhoeven0333d832007-10-16 01:29:48 -0700542 struct ps3fb_par *par = info->par;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700543 unsigned int mode, ddr_line_length, xdr_line_length, lines, maxlines;
Geert Uytterhoeven7974f722008-02-06 01:39:32 -0800544 unsigned int ddr_xoff, ddr_yoff, offset;
Geert Uytterhoeven9f4f21b2008-02-06 01:39:31 -0800545 const struct fb_videomode *vmode;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700546 u64 dst;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800547
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700548 dev_dbg(info->device, "xres:%d xv:%d yres:%d yv:%d clock:%d\n",
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800549 info->var.xres, info->var.xres_virtual,
550 info->var.yres, info->var.yres_virtual, info->var.pixclock);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800551
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700552 mode = ps3fb_find_mode(&info->var, &ddr_line_length, &xdr_line_length);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800553 if (!mode)
554 return -EINVAL;
555
Geert Uytterhoeven9f4f21b2008-02-06 01:39:31 -0800556 vmode = ps3fb_default_mode(mode | PS3AV_MODE_FULL);
Geert Uytterhoevenc95344a2007-10-16 01:29:25 -0700557
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700558 info->fix.smem_start = virt_to_abs(ps3fb.xdr_ea);
559 info->fix.smem_len = ps3fb.xdr_size;
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700560 info->fix.xpanstep = info->var.xres_virtual > info->var.xres ? 1 : 0;
561 info->fix.ypanstep = info->var.yres_virtual > info->var.yres ? 1 : 0;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700562 info->fix.line_length = xdr_line_length;
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700563
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700564 info->screen_base = (char __iomem *)ps3fb.xdr_ea;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800565
Geert Uytterhoeven9f4f21b2008-02-06 01:39:31 -0800566 par->ddr_line_length = ddr_line_length;
567 par->ddr_frame_size = vmode->yres * ddr_line_length;
568 par->xdr_frame_size = info->var.yres_virtual * xdr_line_length;
569
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700570 par->num_frames = ps3fb.xdr_size /
Geert Uytterhoeven9f4f21b2008-02-06 01:39:31 -0800571 max(par->ddr_frame_size, par->xdr_frame_size);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800572
573 /* Keep the special bits we cannot set using fb_var_screeninfo */
Geert Uytterhoeven0333d832007-10-16 01:29:48 -0700574 par->new_mode_id = (par->new_mode_id & ~PS3AV_MODE_MASK) | mode;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800575
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700576 par->width = info->var.xres;
577 par->height = info->var.yres;
Geert Uytterhoevend9a4ba62008-02-06 01:39:31 -0800578
579 /* Start of the virtual frame buffer (relative to fullscreen) */
Geert Uytterhoeven9f4f21b2008-02-06 01:39:31 -0800580 ddr_xoff = info->var.left_margin - vmode->left_margin;
581 ddr_yoff = info->var.upper_margin - vmode->upper_margin;
582 offset = ddr_yoff * ddr_line_length + ddr_xoff * BPP;
Geert Uytterhoevend9a4ba62008-02-06 01:39:31 -0800583
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700584 par->fb_offset = GPU_ALIGN_UP(offset);
585 par->full_offset = par->fb_offset - offset;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700586 par->pan_offset = info->var.yoffset * xdr_line_length +
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700587 info->var.xoffset * BPP;
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700588
Geert Uytterhoeven0333d832007-10-16 01:29:48 -0700589 if (par->new_mode_id != par->mode_id) {
590 if (ps3av_set_video_mode(par->new_mode_id)) {
591 par->new_mode_id = par->mode_id;
592 return -EINVAL;
593 }
594 par->mode_id = par->new_mode_id;
595 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800596
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700597 /* Clear XDR frame buffer memory */
598 memset(ps3fb.xdr_ea, 0, ps3fb.xdr_size);
599
600 /* Clear DDR frame buffer memory */
Geert Uytterhoeven9f4f21b2008-02-06 01:39:31 -0800601 lines = vmode->yres * par->num_frames;
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700602 if (par->full_offset)
603 lines++;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700604 maxlines = ps3fb.xdr_size / ddr_line_length;
605 for (dst = 0; lines; dst += maxlines * ddr_line_length) {
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700606 unsigned int l = min(lines, maxlines);
Geert Uytterhoeven9f4f21b2008-02-06 01:39:31 -0800607 ps3fb_sync_image(info->device, 0, dst, 0, vmode->xres, l,
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700608 ddr_line_length, ddr_line_length);
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700609 lines -= l;
610 }
611
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800612 return 0;
613}
614
615 /*
616 * Set a single color register. The values supplied are already
617 * rounded down to the hardware's capabilities (according to the
618 * entries in the var structure). Return != 0 for invalid regno.
619 */
620
621static int ps3fb_setcolreg(unsigned int regno, unsigned int red,
622 unsigned int green, unsigned int blue,
623 unsigned int transp, struct fb_info *info)
624{
625 if (regno >= 16)
626 return 1;
627
628 red >>= 8;
629 green >>= 8;
630 blue >>= 8;
631 transp >>= 8;
632
633 ((u32 *)info->pseudo_palette)[regno] = transp << 24 | red << 16 |
634 green << 8 | blue;
635 return 0;
636}
637
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700638static int ps3fb_pan_display(struct fb_var_screeninfo *var,
639 struct fb_info *info)
640{
641 struct ps3fb_par *par = info->par;
642
643 par->pan_offset = var->yoffset * info->fix.line_length +
644 var->xoffset * BPP;
645 return 0;
646}
647
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800648 /*
649 * As we have a virtual frame buffer, we need our own mmap function
650 */
651
652static int ps3fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
653{
654 unsigned long size, offset;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800655
656 size = vma->vm_end - vma->vm_start;
657 offset = vma->vm_pgoff << PAGE_SHIFT;
658 if (offset + size > info->fix.smem_len)
659 return -EINVAL;
660
Geert Uytterhoeven2ce32e12007-10-16 01:29:48 -0700661 offset += info->fix.smem_start;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800662 if (remap_pfn_range(vma, vma->vm_start, offset >> PAGE_SHIFT,
663 size, vma->vm_page_prot))
664 return -EAGAIN;
665
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700666 dev_dbg(info->device, "ps3fb: mmap framebuffer P(%lx)->V(%lx)\n",
667 offset, vma->vm_start);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800668 return 0;
669}
670
671 /*
672 * Blank the display
673 */
674
675static int ps3fb_blank(int blank, struct fb_info *info)
676{
677 int retval;
678
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700679 dev_dbg(info->device, "%s: blank:%d\n", __func__, blank);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800680 switch (blank) {
681 case FB_BLANK_POWERDOWN:
682 case FB_BLANK_HSYNC_SUSPEND:
683 case FB_BLANK_VSYNC_SUSPEND:
684 case FB_BLANK_NORMAL:
685 retval = ps3av_video_mute(1); /* mute on */
686 if (!retval)
687 ps3fb.is_blanked = 1;
688 break;
689
690 default: /* unblank */
691 retval = ps3av_video_mute(0); /* mute off */
692 if (!retval)
693 ps3fb.is_blanked = 0;
694 break;
695 }
696 return retval;
697}
698
699static int ps3fb_get_vblank(struct fb_vblank *vblank)
700{
Li Zefan3cc2c172007-11-14 16:58:33 -0800701 memset(vblank, 0, sizeof(*vblank));
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800702 vblank->flags = FB_VBLANK_HAVE_VSYNC;
703 return 0;
704}
705
Geert Uytterhoeven15e4d002007-10-16 01:29:47 -0700706static int ps3fb_wait_for_vsync(u32 crtc)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800707{
708 int ret;
709 u64 count;
710
711 count = ps3fb.vblank_count;
712 ret = wait_event_interruptible_timeout(ps3fb.wait_vsync,
713 count != ps3fb.vblank_count,
714 HZ / 10);
715 if (!ret)
716 return -ETIMEDOUT;
717
718 return 0;
719}
720
Geert Uytterhoeven15e4d002007-10-16 01:29:47 -0700721static void ps3fb_flip_ctl(int on, void *data)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800722{
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000723 struct ps3fb_priv *priv = data;
Geert Uytterhoeveneca28742007-05-02 14:48:32 +0200724 if (on)
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000725 atomic_dec_if_positive(&priv->ext_flip);
Geert Uytterhoeveneca28742007-05-02 14:48:32 +0200726 else
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000727 atomic_inc(&priv->ext_flip);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800728}
729
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800730
731 /*
732 * ioctl
733 */
734
735static int ps3fb_ioctl(struct fb_info *info, unsigned int cmd,
736 unsigned long arg)
737{
738 void __user *argp = (void __user *)arg;
Geert Uytterhoeven0333d832007-10-16 01:29:48 -0700739 u32 val;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800740 int retval = -EFAULT;
741
742 switch (cmd) {
743 case FBIOGET_VBLANK:
744 {
745 struct fb_vblank vblank;
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700746 dev_dbg(info->device, "FBIOGET_VBLANK:\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800747 retval = ps3fb_get_vblank(&vblank);
748 if (retval)
749 break;
750
751 if (copy_to_user(argp, &vblank, sizeof(vblank)))
752 retval = -EFAULT;
753 break;
754 }
755
756 case FBIO_WAITFORVSYNC:
757 {
758 u32 crt;
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700759 dev_dbg(info->device, "FBIO_WAITFORVSYNC:\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800760 if (get_user(crt, (u32 __user *) arg))
761 break;
762
763 retval = ps3fb_wait_for_vsync(crt);
764 break;
765 }
766
767 case PS3FB_IOCTL_SETMODE:
768 {
Geert Uytterhoeven0333d832007-10-16 01:29:48 -0700769 struct ps3fb_par *par = info->par;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800770 const struct fb_videomode *mode;
771 struct fb_var_screeninfo var;
772
773 if (copy_from_user(&val, argp, sizeof(val)))
774 break;
775
Masashi Kimoto64072902007-05-02 14:48:36 +0200776 if (!(val & PS3AV_MODE_MASK)) {
Geert Uytterhoevence4c3712007-10-16 01:29:44 -0700777 u32 id = ps3av_get_auto_mode();
Masashi Kimoto64072902007-05-02 14:48:36 +0200778 if (id > 0)
779 val = (val & ~PS3AV_MODE_MASK) | id;
780 }
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700781 dev_dbg(info->device, "PS3FB_IOCTL_SETMODE:%x\n", val);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800782 retval = -EINVAL;
Geert Uytterhoeven0333d832007-10-16 01:29:48 -0700783 mode = ps3fb_default_mode(val);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800784 if (mode) {
785 var = info->var;
786 fb_videomode_to_var(&var, mode);
787 acquire_console_sem();
788 info->flags |= FBINFO_MISC_USEREVENT;
789 /* Force, in case only special bits changed */
790 var.activate |= FB_ACTIVATE_FORCE;
Geert Uytterhoeven0333d832007-10-16 01:29:48 -0700791 par->new_mode_id = val;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800792 retval = fb_set_var(info, &var);
793 info->flags &= ~FBINFO_MISC_USEREVENT;
794 release_console_sem();
795 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800796 break;
797 }
798
799 case PS3FB_IOCTL_GETMODE:
800 val = ps3av_get_mode();
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700801 dev_dbg(info->device, "PS3FB_IOCTL_GETMODE:%x\n", val);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800802 if (!copy_to_user(argp, &val, sizeof(val)))
803 retval = 0;
804 break;
805
806 case PS3FB_IOCTL_SCREENINFO:
807 {
Geert Uytterhoeven0333d832007-10-16 01:29:48 -0700808 struct ps3fb_par *par = info->par;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800809 struct ps3fb_ioctl_res res;
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700810 dev_dbg(info->device, "PS3FB_IOCTL_SCREENINFO:\n");
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700811 res.xres = info->fix.line_length / BPP;
812 res.yres = info->var.yres_virtual;
813 res.xoff = (res.xres - info->var.xres) / 2;
814 res.yoff = (res.yres - info->var.yres) / 2;
Geert Uytterhoeven0333d832007-10-16 01:29:48 -0700815 res.num_frames = par->num_frames;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800816 if (!copy_to_user(argp, &res, sizeof(res)))
817 retval = 0;
818 break;
819 }
820
821 case PS3FB_IOCTL_ON:
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700822 dev_dbg(info->device, "PS3FB_IOCTL_ON:\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800823 atomic_inc(&ps3fb.ext_flip);
824 retval = 0;
825 break;
826
827 case PS3FB_IOCTL_OFF:
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700828 dev_dbg(info->device, "PS3FB_IOCTL_OFF:\n");
Geert Uytterhoeveneca28742007-05-02 14:48:32 +0200829 atomic_dec_if_positive(&ps3fb.ext_flip);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800830 retval = 0;
831 break;
832
833 case PS3FB_IOCTL_FSEL:
834 if (copy_from_user(&val, argp, sizeof(val)))
835 break;
836
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700837 dev_dbg(info->device, "PS3FB_IOCTL_FSEL:%d\n", val);
Jeremy Kerr8dab6372008-01-11 14:28:04 +0100838 acquire_console_sem();
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700839 retval = ps3fb_sync(info, val);
Jeremy Kerr8dab6372008-01-11 14:28:04 +0100840 release_console_sem();
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800841 break;
842
843 default:
844 retval = -ENOIOCTLCMD;
845 break;
846 }
847 return retval;
848}
849
850static int ps3fbd(void *arg)
851{
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700852 struct fb_info *info = arg;
853
Rafael J. Wysocki83144182007-07-17 04:03:35 -0700854 set_freezable();
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +0200855 while (!kthread_should_stop()) {
856 try_to_freeze();
857 set_current_state(TASK_INTERRUPTIBLE);
858 if (ps3fb.is_kicked) {
859 ps3fb.is_kicked = 0;
Jeremy Kerr8dab6372008-01-11 14:28:04 +0100860 acquire_console_sem();
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700861 ps3fb_sync(info, 0); /* single buffer */
Jeremy Kerr8dab6372008-01-11 14:28:04 +0100862 release_console_sem();
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +0200863 }
864 schedule();
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800865 }
866 return 0;
867}
868
869static irqreturn_t ps3fb_vsync_interrupt(int irq, void *ptr)
870{
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700871 struct device *dev = ptr;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800872 u64 v1;
873 int status;
874 struct display_head *head = &ps3fb.dinfo->display_head[1];
875
876 status = lv1_gpu_context_intr(ps3fb.context_handle, &v1);
877 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700878 dev_err(dev, "%s: lv1_gpu_context_intr failed: %d\n", __func__,
879 status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800880 return IRQ_NONE;
881 }
882
883 if (v1 & (1 << GPU_INTR_STATUS_VSYNC_1)) {
884 /* VSYNC */
885 ps3fb.vblank_count = head->vblank_count;
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +0200886 if (ps3fb.task && !ps3fb.is_blanked &&
887 !atomic_read(&ps3fb.ext_flip)) {
888 ps3fb.is_kicked = 1;
889 wake_up_process(ps3fb.task);
890 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800891 wake_up_interruptible(&ps3fb.wait_vsync);
892 }
893
894 return IRQ_HANDLED;
895}
896
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800897
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000898static int ps3fb_vsync_settings(struct gpu_driver_info *dinfo,
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700899 struct device *dev)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800900{
901 int error;
902
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700903 dev_dbg(dev, "version_driver:%x\n", dinfo->version_driver);
904 dev_dbg(dev, "irq outlet:%x\n", dinfo->irq.irq_outlet);
905 dev_dbg(dev,
906 "version_gpu: %x memory_size: %x ch: %x core_freq: %d "
907 "mem_freq:%d\n",
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800908 dinfo->version_gpu, dinfo->memory_size, dinfo->hardware_channel,
909 dinfo->nvcore_frequency/1000000, dinfo->memory_frequency/1000000);
910
911 if (dinfo->version_driver != GPU_DRIVER_INFO_VERSION) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700912 dev_err(dev, "%s: version_driver err:%x\n", __func__,
913 dinfo->version_driver);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800914 return -EINVAL;
915 }
916
Geoff Levanddc4f60c2007-05-01 07:01:01 +1000917 error = ps3_irq_plug_setup(PS3_BINDING_CPU_ANY, dinfo->irq.irq_outlet,
918 &ps3fb.irq_no);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800919 if (error) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700920 dev_err(dev, "%s: ps3_alloc_irq failed %d\n", __func__, error);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800921 return error;
922 }
923
924 error = request_irq(ps3fb.irq_no, ps3fb_vsync_interrupt, IRQF_DISABLED,
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000925 DEVICE_NAME, dev);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800926 if (error) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700927 dev_err(dev, "%s: request_irq failed %d\n", __func__, error);
Geoff Levanddc4f60c2007-05-01 07:01:01 +1000928 ps3_irq_plug_destroy(ps3fb.irq_no);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800929 return error;
930 }
931
932 dinfo->irq.mask = (1 << GPU_INTR_STATUS_VSYNC_1) |
933 (1 << GPU_INTR_STATUS_FLIP_1);
934 return 0;
935}
936
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700937static int ps3fb_xdr_settings(u64 xdr_lpar, struct device *dev)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800938{
939 int status;
940
941 status = lv1_gpu_context_iomap(ps3fb.context_handle, GPU_IOIF,
942 xdr_lpar, ps3fb_videomemory.size, 0);
943 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700944 dev_err(dev, "%s: lv1_gpu_context_iomap failed: %d\n",
945 __func__, status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800946 return -ENXIO;
947 }
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700948 dev_dbg(dev,
949 "video:%p xdr_ea:%p ioif:%lx lpar:%lx phys:%lx size:%lx\n",
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800950 ps3fb_videomemory.address, ps3fb.xdr_ea, GPU_IOIF, xdr_lpar,
951 virt_to_abs(ps3fb.xdr_ea), ps3fb_videomemory.size);
952
953 status = lv1_gpu_context_attribute(ps3fb.context_handle,
954 L1GPU_CONTEXT_ATTRIBUTE_FB_SETUP,
Geert Uytterhoeven9ac67a32007-12-19 11:16:41 +0100955 xdr_lpar, GPU_CMD_BUF_SIZE,
956 GPU_IOIF, 0);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800957 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700958 dev_err(dev,
959 "%s: lv1_gpu_context_attribute FB_SETUP failed: %d\n",
960 __func__, status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800961 return -ENXIO;
962 }
963 return 0;
964}
965
966static struct fb_ops ps3fb_ops = {
967 .fb_open = ps3fb_open,
968 .fb_release = ps3fb_release,
Geert Uytterhoeven92c45792007-05-23 13:57:50 -0700969 .fb_read = fb_sys_read,
970 .fb_write = fb_sys_write,
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800971 .fb_check_var = ps3fb_check_var,
972 .fb_set_par = ps3fb_set_par,
973 .fb_setcolreg = ps3fb_setcolreg,
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700974 .fb_pan_display = ps3fb_pan_display,
Geert Uytterhoeven92c45792007-05-23 13:57:50 -0700975 .fb_fillrect = sys_fillrect,
976 .fb_copyarea = sys_copyarea,
977 .fb_imageblit = sys_imageblit,
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800978 .fb_mmap = ps3fb_mmap,
979 .fb_blank = ps3fb_blank,
980 .fb_ioctl = ps3fb_ioctl,
981 .fb_compat_ioctl = ps3fb_ioctl
982};
983
984static struct fb_fix_screeninfo ps3fb_fix __initdata = {
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000985 .id = DEVICE_NAME,
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800986 .type = FB_TYPE_PACKED_PIXELS,
987 .visual = FB_VISUAL_TRUECOLOR,
988 .accel = FB_ACCEL_NONE,
989};
990
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700991static int ps3fb_set_sync(struct device *dev)
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000992{
993 int status;
994
995#ifdef HEAD_A
996 status = lv1_gpu_context_attribute(0x0,
997 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
998 0, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0);
999 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001000 dev_err(dev,
1001 "%s: lv1_gpu_context_attribute DISPLAY_SYNC failed: "
1002 "%d\n",
1003 __func__, status);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001004 return -1;
1005 }
1006#endif
1007#ifdef HEAD_B
1008 status = lv1_gpu_context_attribute(0x0,
1009 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
1010 1, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0);
1011
1012 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001013 dev_err(dev,
1014 "%s: lv1_gpu_context_attribute DISPLAY_SYNC failed: "
1015 "%d\n",
1016 __func__, status);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001017 return -1;
1018 }
1019#endif
1020 return 0;
1021}
1022
1023static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001024{
1025 struct fb_info *info;
Geert Uytterhoeven0333d832007-10-16 01:29:48 -07001026 struct ps3fb_par *par;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001027 int retval = -ENOMEM;
1028 u64 ddr_lpar = 0;
1029 u64 lpar_dma_control = 0;
1030 u64 lpar_driver_info = 0;
1031 u64 lpar_reports = 0;
1032 u64 lpar_reports_size = 0;
1033 u64 xdr_lpar;
Geert Uytterhoeven9f4f21b2008-02-06 01:39:31 -08001034 int status;
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +02001035 struct task_struct *task;
Geert Uytterhoevenee592a52007-11-28 16:21:11 -08001036 unsigned long max_ps3fb_size;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001037
Geert Uytterhoeven9ac67a32007-12-19 11:16:41 +01001038 if (ps3fb_videomemory.size < GPU_CMD_BUF_SIZE) {
1039 dev_err(&dev->core, "%s: Not enough video memory\n", __func__);
1040 return -ENOMEM;
1041 }
1042
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001043 status = ps3_open_hv_device(dev);
1044 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001045 dev_err(&dev->core, "%s: ps3_open_hv_device failed\n",
1046 __func__);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001047 goto err;
1048 }
1049
1050 if (!ps3fb_mode)
1051 ps3fb_mode = ps3av_get_mode();
Geert Uytterhoeven084ffff2008-02-06 01:39:29 -08001052 dev_dbg(&dev->core, "ps3fb_mode: %d\n", ps3fb_mode);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001053
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001054 atomic_set(&ps3fb.f_count, -1); /* fbcon opens ps3fb */
1055 atomic_set(&ps3fb.ext_flip, 0); /* for flip with vsync */
1056 init_waitqueue_head(&ps3fb.wait_vsync);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001057
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001058 ps3fb_set_sync(&dev->core);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001059
Geert Uytterhoevenee592a52007-11-28 16:21:11 -08001060 max_ps3fb_size = _ALIGN_UP(GPU_IOIF, 256*1024*1024) - GPU_IOIF;
1061 if (ps3fb_videomemory.size > max_ps3fb_size) {
1062 dev_info(&dev->core, "Limiting ps3fb mem size to %lu bytes\n",
1063 max_ps3fb_size);
1064 ps3fb_videomemory.size = max_ps3fb_size;
1065 }
1066
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001067 /* get gpu context handle */
Geert Uytterhoevenee592a52007-11-28 16:21:11 -08001068 status = lv1_gpu_memory_allocate(ps3fb_videomemory.size, 0, 0, 0, 0,
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001069 &ps3fb.memory_handle, &ddr_lpar);
1070 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001071 dev_err(&dev->core, "%s: lv1_gpu_memory_allocate failed: %d\n",
1072 __func__, status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001073 goto err;
1074 }
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001075 dev_dbg(&dev->core, "ddr:lpar:0x%lx\n", ddr_lpar);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001076
1077 status = lv1_gpu_context_allocate(ps3fb.memory_handle, 0,
1078 &ps3fb.context_handle,
1079 &lpar_dma_control, &lpar_driver_info,
1080 &lpar_reports, &lpar_reports_size);
1081 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001082 dev_err(&dev->core,
1083 "%s: lv1_gpu_context_attribute failed: %d\n", __func__,
1084 status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001085 goto err_gpu_memory_free;
1086 }
1087
1088 /* vsync interrupt */
1089 ps3fb.dinfo = ioremap(lpar_driver_info, 128 * 1024);
1090 if (!ps3fb.dinfo) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001091 dev_err(&dev->core, "%s: ioremap failed\n", __func__);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001092 goto err_gpu_context_free;
1093 }
1094
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001095 retval = ps3fb_vsync_settings(ps3fb.dinfo, &dev->core);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001096 if (retval)
1097 goto err_iounmap_dinfo;
1098
Geert Uytterhoeven2ce32e12007-10-16 01:29:48 -07001099 /* XDR frame buffer */
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001100 ps3fb.xdr_ea = ps3fb_videomemory.address;
1101 xdr_lpar = ps3_mm_phys_to_lpar(__pa(ps3fb.xdr_ea));
Geert Uytterhoeven2ce32e12007-10-16 01:29:48 -07001102
1103 /* Clear memory to prevent kernel info leakage into userspace */
1104 memset(ps3fb.xdr_ea, 0, ps3fb_videomemory.size);
1105
Geert Uytterhoeven9ac67a32007-12-19 11:16:41 +01001106 /*
1107 * The GPU command buffer is at the start of video memory
1108 * As we don't use the full command buffer, we can put the actual
1109 * frame buffer at offset GPU_FB_START and save some precious XDR
1110 * memory
1111 */
1112 ps3fb.xdr_ea += GPU_FB_START;
1113 ps3fb.xdr_size = ps3fb_videomemory.size - GPU_FB_START;
Geert Uytterhoeven2ce32e12007-10-16 01:29:48 -07001114
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001115 retval = ps3fb_xdr_settings(xdr_lpar, &dev->core);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001116 if (retval)
1117 goto err_free_irq;
1118
Geert Uytterhoeven0333d832007-10-16 01:29:48 -07001119 info = framebuffer_alloc(sizeof(struct ps3fb_par), &dev->core);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001120 if (!info)
1121 goto err_free_irq;
1122
Geert Uytterhoeven0333d832007-10-16 01:29:48 -07001123 par = info->par;
1124 par->mode_id = ~ps3fb_mode; /* != ps3fb_mode, to trigger change */
1125 par->new_mode_id = ps3fb_mode;
Geert Uytterhoeven0333d832007-10-16 01:29:48 -07001126 par->num_frames = 1;
1127
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -07001128 info->screen_base = (char __iomem *)ps3fb.xdr_ea;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001129 info->fbops = &ps3fb_ops;
1130
1131 info->fix = ps3fb_fix;
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -07001132 info->fix.smem_start = virt_to_abs(ps3fb.xdr_ea);
1133 info->fix.smem_len = ps3fb.xdr_size;
Geert Uytterhoeven0333d832007-10-16 01:29:48 -07001134 info->pseudo_palette = par->pseudo_palette;
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -07001135 info->flags = FBINFO_DEFAULT | FBINFO_READS_FAST |
1136 FBINFO_HWACCEL_XPAN | FBINFO_HWACCEL_YPAN;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001137
1138 retval = fb_alloc_cmap(&info->cmap, 256, 0);
1139 if (retval < 0)
1140 goto err_framebuffer_release;
1141
1142 if (!fb_find_mode(&info->var, info, mode_option, ps3fb_modedb,
Geert Uytterhoeven0333d832007-10-16 01:29:48 -07001143 ARRAY_SIZE(ps3fb_modedb),
1144 ps3fb_default_mode(par->new_mode_id), 32)) {
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001145 retval = -EINVAL;
1146 goto err_fb_dealloc;
1147 }
1148
1149 fb_videomode_to_modelist(ps3fb_modedb, ARRAY_SIZE(ps3fb_modedb),
1150 &info->modelist);
1151
1152 retval = register_framebuffer(info);
1153 if (retval < 0)
1154 goto err_fb_dealloc;
1155
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001156 dev->core.driver_data = info;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001157
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001158 dev_info(info->device, "%s %s, using %lu KiB of video memory\n",
1159 dev_driver_string(info->dev), info->dev->bus_id,
Geert Uytterhoeven2ce32e12007-10-16 01:29:48 -07001160 ps3fb.xdr_size >> 10);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001161
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001162 task = kthread_run(ps3fbd, info, DEVICE_NAME);
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +02001163 if (IS_ERR(task)) {
1164 retval = PTR_ERR(task);
1165 goto err_unregister_framebuffer;
1166 }
1167
1168 ps3fb.task = task;
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001169 ps3av_register_flip_ctl(ps3fb_flip_ctl, &ps3fb);
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +02001170
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001171 return 0;
1172
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +02001173err_unregister_framebuffer:
1174 unregister_framebuffer(info);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001175err_fb_dealloc:
1176 fb_dealloc_cmap(&info->cmap);
1177err_framebuffer_release:
1178 framebuffer_release(info);
1179err_free_irq:
Geoff Levandfcbe6e92007-12-19 11:17:31 +01001180 free_irq(ps3fb.irq_no, &dev->core);
Geoff Levanddc4f60c2007-05-01 07:01:01 +10001181 ps3_irq_plug_destroy(ps3fb.irq_no);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001182err_iounmap_dinfo:
1183 iounmap((u8 __iomem *)ps3fb.dinfo);
1184err_gpu_context_free:
1185 lv1_gpu_context_free(ps3fb.context_handle);
1186err_gpu_memory_free:
1187 lv1_gpu_memory_free(ps3fb.memory_handle);
1188err:
1189 return retval;
1190}
1191
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001192static int ps3fb_shutdown(struct ps3_system_bus_device *dev)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001193{
1194 int status;
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001195 struct fb_info *info = dev->core.driver_data;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001196
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001197 dev_dbg(&dev->core, " -> %s:%d\n", __func__, __LINE__);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001198
1199 ps3fb_flip_ctl(0, &ps3fb); /* flip off */
1200 ps3fb.dinfo->irq.mask = 0;
1201
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001202 ps3av_register_flip_ctl(NULL, NULL);
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +02001203 if (ps3fb.task) {
1204 struct task_struct *task = ps3fb.task;
1205 ps3fb.task = NULL;
1206 kthread_stop(task);
1207 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001208 if (ps3fb.irq_no) {
Geoff Levandfcbe6e92007-12-19 11:17:31 +01001209 free_irq(ps3fb.irq_no, &dev->core);
Geoff Levanddc4f60c2007-05-01 07:01:01 +10001210 ps3_irq_plug_destroy(ps3fb.irq_no);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001211 }
Jeremy Kerrba216112008-01-11 14:27:10 +01001212 if (info) {
1213 unregister_framebuffer(info);
1214 fb_dealloc_cmap(&info->cmap);
1215 framebuffer_release(info);
1216 info = dev->core.driver_data = NULL;
1217 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001218 iounmap((u8 __iomem *)ps3fb.dinfo);
1219
1220 status = lv1_gpu_context_free(ps3fb.context_handle);
1221 if (status)
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001222 dev_dbg(&dev->core, "lv1_gpu_context_free failed: %d\n",
1223 status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001224
1225 status = lv1_gpu_memory_free(ps3fb.memory_handle);
1226 if (status)
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001227 dev_dbg(&dev->core, "lv1_gpu_memory_free failed: %d\n",
1228 status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001229
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001230 ps3_close_hv_device(dev);
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001231 dev_dbg(&dev->core, " <- %s:%d\n", __func__, __LINE__);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001232
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001233 return 0;
1234}
1235
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001236static struct ps3_system_bus_driver ps3fb_driver = {
1237 .match_id = PS3_MATCH_ID_GRAPHICS,
1238 .core.name = DEVICE_NAME,
1239 .core.owner = THIS_MODULE,
1240 .probe = ps3fb_probe,
1241 .remove = ps3fb_shutdown,
1242 .shutdown = ps3fb_shutdown,
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001243};
1244
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001245static int __init ps3fb_setup(void)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001246{
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001247 char *options;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001248
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001249#ifdef MODULE
1250 return 0;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001251#endif
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001252
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001253 if (fb_get_options(DEVICE_NAME, &options))
1254 return -ENXIO;
1255
1256 if (!options || !*options)
1257 return 0;
1258
1259 while (1) {
1260 char *this_opt = strsep(&options, ",");
1261
1262 if (!this_opt)
1263 break;
1264 if (!*this_opt)
1265 continue;
1266 if (!strncmp(this_opt, "mode:", 5))
1267 ps3fb_mode = simple_strtoul(this_opt + 5, NULL, 0);
1268 else
1269 mode_option = this_opt;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001270 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001271 return 0;
1272}
1273
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001274static int __init ps3fb_init(void)
1275{
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001276 if (!ps3fb_videomemory.address || ps3fb_setup())
1277 return -ENXIO;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001278
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001279 return ps3_system_bus_driver_register(&ps3fb_driver);
1280}
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001281
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001282static void __exit ps3fb_exit(void)
1283{
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001284 pr_debug(" -> %s:%d\n", __func__, __LINE__);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001285 ps3_system_bus_driver_unregister(&ps3fb_driver);
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001286 pr_debug(" <- %s:%d\n", __func__, __LINE__);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001287}
1288
1289module_init(ps3fb_init);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001290module_exit(ps3fb_exit);
1291
1292MODULE_LICENSE("GPL");
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001293MODULE_DESCRIPTION("PS3 GPU Frame Buffer Driver");
1294MODULE_AUTHOR("Sony Computer Entertainment Inc.");
1295MODULE_ALIAS(PS3_MODULE_ALIAS_GRAPHICS);