blob: 229727a5bc75f80e3b26f4be7b60e75da0e62105 [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 Uytterhoeven0333d8352007-10-16 01:29:48 -0700134struct ps3fb_par {
135 u32 pseudo_palette[16];
136 int mode_id, new_mode_id;
137 int res_index;
138 unsigned int num_frames; /* num of frame buffers */
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700139 unsigned int width;
140 unsigned int height;
141 unsigned long full_offset; /* start of fullscreen DDR fb */
142 unsigned long fb_offset; /* start of actual DDR fb */
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700143 unsigned long pan_offset;
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700144};
145
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800146struct ps3fb_res_table {
147 u32 xres;
148 u32 yres;
149 u32 xoff;
150 u32 yoff;
151 u32 type;
152};
153#define PS3FB_RES_FULL 1
154static const struct ps3fb_res_table ps3fb_res[] = {
155 /* res_x,y margin_x,y full */
156 { 720, 480, 72, 48 , 0},
157 { 720, 576, 72, 58 , 0},
158 { 1280, 720, 78, 38 , 0},
159 { 1920, 1080, 116, 58 , 0},
160 /* full mode */
161 { 720, 480, 0, 0 , PS3FB_RES_FULL},
162 { 720, 576, 0, 0 , PS3FB_RES_FULL},
163 { 1280, 720, 0, 0 , PS3FB_RES_FULL},
164 { 1920, 1080, 0, 0 , PS3FB_RES_FULL},
165 /* vesa: normally full mode */
166 { 1280, 768, 0, 0 , 0},
167 { 1280, 1024, 0, 0 , 0},
168 { 1920, 1200, 0, 0 , 0},
169 { 0, 0, 0, 0 , 0} };
170
171/* default resolution */
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000172#define GPU_RES_INDEX 0 /* 720 x 480 */
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800173
174static const struct fb_videomode ps3fb_modedb[] = {
175 /* 60 Hz broadcast modes (modes "1" to "5") */
176 {
177 /* 480i */
178 "480i", 60, 576, 384, 74074, 130, 89, 78, 57, 63, 6,
179 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
180 }, {
181 /* 480p */
182 "480p", 60, 576, 384, 37037, 130, 89, 78, 57, 63, 6,
183 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
184 }, {
185 /* 720p */
186 "720p", 60, 1124, 644, 13481, 298, 148, 57, 44, 80, 5,
187 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
188 }, {
189 /* 1080i */
190 "1080i", 60, 1688, 964, 13481, 264, 160, 94, 62, 88, 5,
191 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
192 }, {
193 /* 1080p */
194 "1080p", 60, 1688, 964, 6741, 264, 160, 94, 62, 88, 5,
195 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
196 },
197
198 /* 50 Hz broadcast modes (modes "6" to "10") */
199 {
200 /* 576i */
201 "576i", 50, 576, 460, 74074, 142, 83, 97, 63, 63, 5,
202 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
203 }, {
204 /* 576p */
205 "576p", 50, 576, 460, 37037, 142, 83, 97, 63, 63, 5,
206 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
207 }, {
208 /* 720p */
209 "720p", 50, 1124, 644, 13468, 298, 478, 57, 44, 80, 5,
210 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
211 }, {
212 /* 1080 */
213 "1080i", 50, 1688, 964, 13468, 264, 600, 94, 62, 88, 5,
214 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
215 }, {
216 /* 1080p */
217 "1080p", 50, 1688, 964, 6734, 264, 600, 94, 62, 88, 5,
218 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
219 },
220
221 /* VESA modes (modes "11" to "13") */
222 {
223 /* WXGA */
224 "wxga", 60, 1280, 768, 12924, 160, 24, 29, 3, 136, 6,
225 0, FB_VMODE_NONINTERLACED,
226 FB_MODE_IS_VESA
227 }, {
228 /* SXGA */
229 "sxga", 60, 1280, 1024, 9259, 248, 48, 38, 1, 112, 3,
230 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED,
231 FB_MODE_IS_VESA
232 }, {
233 /* WUXGA */
234 "wuxga", 60, 1920, 1200, 6494, 80, 48, 26, 3, 32, 6,
235 FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED,
236 FB_MODE_IS_VESA
237 },
238
239 /* 60 Hz broadcast modes (full resolution versions of modes "1" to "5") */
240 {
241 /* 480if */
242 "480if", 60, 720, 480, 74074, 58, 17, 30, 9, 63, 6,
243 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
244 }, {
245 /* 480pf */
246 "480pf", 60, 720, 480, 37037, 58, 17, 30, 9, 63, 6,
247 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
248 }, {
249 /* 720pf */
250 "720pf", 60, 1280, 720, 13481, 220, 70, 19, 6, 80, 5,
251 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
252 }, {
253 /* 1080if */
254 "1080if", 60, 1920, 1080, 13481, 148, 44, 36, 4, 88, 5,
255 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
256 }, {
257 /* 1080pf */
258 "1080pf", 60, 1920, 1080, 6741, 148, 44, 36, 4, 88, 5,
259 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
260 },
261
262 /* 50 Hz broadcast modes (full resolution versions of modes "6" to "10") */
263 {
264 /* 576if */
265 "576if", 50, 720, 576, 74074, 70, 11, 39, 5, 63, 5,
266 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
267 }, {
268 /* 576pf */
269 "576pf", 50, 720, 576, 37037, 70, 11, 39, 5, 63, 5,
270 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
271 }, {
272 /* 720pf */
273 "720pf", 50, 1280, 720, 13468, 220, 400, 19, 6, 80, 5,
274 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
275 }, {
276 /* 1080if */
277 "1080f", 50, 1920, 1080, 13468, 148, 484, 36, 4, 88, 5,
278 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
279 }, {
280 /* 1080pf */
281 "1080pf", 50, 1920, 1080, 6734, 148, 484, 36, 4, 88, 5,
282 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
283 }
284};
285
286
287#define HEAD_A
288#define HEAD_B
289
Geert Uytterhoeven2ce32e12007-10-16 01:29:48 -0700290#define BPP 4 /* number of bytes per pixel */
291
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800292
Geert Uytterhoevenbd685ac2007-05-02 14:48:34 +0200293static int ps3fb_mode;
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000294module_param(ps3fb_mode, int, 0);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800295
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000296static char *mode_option __devinitdata;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800297
Geert Uytterhoevenc95344a2007-10-16 01:29:25 -0700298static int ps3fb_get_res_table(u32 xres, u32 yres, int mode)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800299{
300 int full_mode;
301 unsigned int i;
302 u32 x, y, f;
303
Geert Uytterhoevenbbcfe342008-02-06 01:39:30 -0800304 full_mode = (mode & PS3AV_MODE_FULL) ? PS3FB_RES_FULL : 0;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800305 for (i = 0;; i++) {
306 x = ps3fb_res[i].xres;
307 y = ps3fb_res[i].yres;
308 f = ps3fb_res[i].type;
309
310 if (!x) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700311 pr_debug("ERROR: ps3fb_get_res_table()\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800312 return -1;
313 }
314
315 if (full_mode == PS3FB_RES_FULL && f != PS3FB_RES_FULL)
316 continue;
317
318 if (x == xres && (yres == 0 || y == yres))
319 break;
320
321 x = x - 2 * ps3fb_res[i].xoff;
322 y = y - 2 * ps3fb_res[i].yoff;
323 if (x == xres && (yres == 0 || y == yres))
324 break;
325 }
326 return i;
327}
328
329static unsigned int ps3fb_find_mode(const struct fb_var_screeninfo *var,
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700330 u32 *ddr_line_length, u32 *xdr_line_length)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800331{
Geert Uytterhoeven084ffff2008-02-06 01:39:29 -0800332 unsigned int i, fi, mode;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800333
334 for (i = 0; i < ARRAY_SIZE(ps3fb_modedb); i++)
335 if (var->xres == ps3fb_modedb[i].xres &&
336 var->yres == ps3fb_modedb[i].yres &&
337 var->pixclock == ps3fb_modedb[i].pixclock &&
338 var->hsync_len == ps3fb_modedb[i].hsync_len &&
339 var->vsync_len == ps3fb_modedb[i].vsync_len &&
340 var->left_margin == ps3fb_modedb[i].left_margin &&
341 var->right_margin == ps3fb_modedb[i].right_margin &&
342 var->upper_margin == ps3fb_modedb[i].upper_margin &&
343 var->lower_margin == ps3fb_modedb[i].lower_margin &&
344 var->sync == ps3fb_modedb[i].sync &&
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700345 (var->vmode & FB_VMODE_MASK) == ps3fb_modedb[i].vmode)
346 goto found;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800347
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700348 pr_debug("ps3fb_find_mode: mode not found\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800349 return 0;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700350
351found:
352 /* Cropped broadcast modes use the full line length */
Geert Uytterhoeven084ffff2008-02-06 01:39:29 -0800353 fi = i < PS3AV_MODE_1080P50 ? i + PS3AV_MODE_WUXGA : i;
354 *ddr_line_length = ps3fb_modedb[fi].xres * BPP;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700355
356 if (ps3_compare_firmware_version(1, 9, 0) >= 0) {
357 *xdr_line_length = GPU_ALIGN_UP(max(var->xres,
358 var->xres_virtual) * BPP);
359 if (*xdr_line_length > GPU_MAX_LINE_LENGTH)
360 *xdr_line_length = GPU_MAX_LINE_LENGTH;
361 } else
362 *xdr_line_length = *ddr_line_length;
363
364 /* Full broadcast modes have the full mode bit set */
Geert Uytterhoeven084ffff2008-02-06 01:39:29 -0800365 mode = i+1;
366 if (mode > PS3AV_MODE_WUXGA)
Geert Uytterhoevenbbcfe342008-02-06 01:39:30 -0800367 mode = (mode - PS3AV_MODE_WUXGA) | PS3AV_MODE_FULL;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700368
369 pr_debug("ps3fb_find_mode: mode %u\n", mode);
370
371 return mode;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800372}
373
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700374static const struct fb_videomode *ps3fb_default_mode(int id)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800375{
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700376 u32 mode = id & PS3AV_MODE_MASK;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800377 u32 flags;
378
Geert Uytterhoeven084ffff2008-02-06 01:39:29 -0800379 if (mode < PS3AV_MODE_480I || mode > PS3AV_MODE_WUXGA)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800380 return NULL;
381
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700382 flags = id & ~PS3AV_MODE_MASK;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800383
Geert Uytterhoevenbbcfe342008-02-06 01:39:30 -0800384 if (mode <= PS3AV_MODE_1080P50 && flags & PS3AV_MODE_FULL) {
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800385 /* Full broadcast mode */
Geert Uytterhoeven084ffff2008-02-06 01:39:29 -0800386 return &ps3fb_modedb[mode + PS3AV_MODE_WUXGA - 1];
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800387 }
388
389 return &ps3fb_modedb[mode - 1];
390}
391
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700392static void ps3fb_sync_image(struct device *dev, u64 frame_offset,
393 u64 dst_offset, u64 src_offset, u32 width,
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700394 u32 height, u32 dst_line_length,
395 u32 src_line_length)
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700396{
397 int status;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700398 u64 line_length;
399
400 line_length = dst_line_length;
401 if (src_line_length != dst_line_length)
402 line_length |= (u64)src_line_length << 32;
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700403
Geert Uytterhoeven9ac67a32007-12-19 11:16:41 +0100404 src_offset += GPU_FB_START;
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700405 status = lv1_gpu_context_attribute(ps3fb.context_handle,
406 L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT,
407 dst_offset, GPU_IOIF + src_offset,
408 L1GPU_FB_BLIT_WAIT_FOR_COMPLETION |
409 (width << 16) | height,
410 line_length);
411 if (status)
412 dev_err(dev,
413 "%s: lv1_gpu_context_attribute FB_BLIT failed: %d\n",
414 __func__, status);
415#ifdef HEAD_A
416 status = lv1_gpu_context_attribute(ps3fb.context_handle,
417 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP,
418 0, frame_offset, 0, 0);
419 if (status)
420 dev_err(dev, "%s: lv1_gpu_context_attribute FLIP failed: %d\n",
421 __func__, status);
422#endif
423#ifdef HEAD_B
424 status = lv1_gpu_context_attribute(ps3fb.context_handle,
425 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP,
426 1, frame_offset, 0, 0);
427 if (status)
428 dev_err(dev, "%s: lv1_gpu_context_attribute FLIP failed: %d\n",
429 __func__, status);
430#endif
431}
432
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700433static int ps3fb_sync(struct fb_info *info, u32 frame)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800434{
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700435 struct ps3fb_par *par = info->par;
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700436 int i, error = 0;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700437 u32 ddr_line_length, xdr_line_length;
438 u64 ddr_base, xdr_base;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800439
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700440 if (frame > par->num_frames - 1) {
Geert Uytterhoeven0138bd82007-10-16 01:29:46 -0700441 dev_dbg(info->device, "%s: invalid frame number (%u)\n",
442 __func__, frame);
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700443 error = -EINVAL;
444 goto out;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800445 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800446
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700447 i = par->res_index;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700448 xdr_line_length = info->fix.line_length;
449 ddr_line_length = ps3fb_res[i].xres * BPP;
450 xdr_base = frame * info->var.yres_virtual * xdr_line_length;
451 ddr_base = frame * ps3fb_res[i].yres * ddr_line_length;
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700452
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700453 ps3fb_sync_image(info->device, ddr_base + par->full_offset,
454 ddr_base + par->fb_offset, xdr_base + par->pan_offset,
455 par->width, par->height, ddr_line_length,
456 xdr_line_length);
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700457
458out:
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700459 return error;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800460}
461
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800462static int ps3fb_open(struct fb_info *info, int user)
463{
464 atomic_inc(&ps3fb.f_count);
465 return 0;
466}
467
468static int ps3fb_release(struct fb_info *info, int user)
469{
470 if (atomic_dec_and_test(&ps3fb.f_count)) {
471 if (atomic_read(&ps3fb.ext_flip)) {
472 atomic_set(&ps3fb.ext_flip, 0);
Jeremy Kerr8dab6372008-01-11 14:28:04 +0100473 if (!try_acquire_console_sem()) {
474 ps3fb_sync(info, 0); /* single buffer */
475 release_console_sem();
476 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800477 }
478 }
479 return 0;
480}
481
482 /*
483 * Setting the video mode has been split into two parts.
484 * First part, xxxfb_check_var, must not write anything
485 * to hardware, it should only verify and adjust var.
486 * This means it doesn't alter par but it does use hardware
487 * data from it to check this var.
488 */
489
490static int ps3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
491{
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700492 u32 xdr_line_length, ddr_line_length;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800493 int mode;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800494
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700495 dev_dbg(info->device, "var->xres:%u info->var.xres:%u\n", var->xres,
496 info->var.xres);
497 dev_dbg(info->device, "var->yres:%u info->var.yres:%u\n", var->yres,
498 info->var.yres);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800499
500 /* FIXME For now we do exact matches only */
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700501 mode = ps3fb_find_mode(var, &ddr_line_length, &xdr_line_length);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800502 if (!mode)
503 return -EINVAL;
504
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700505 /* Virtual screen */
506 if (var->xres_virtual < var->xres)
507 var->xres_virtual = var->xres;
508 if (var->yres_virtual < var->yres)
509 var->yres_virtual = var->yres;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800510
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700511 if (var->xres_virtual > xdr_line_length / BPP) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700512 dev_dbg(info->device,
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700513 "Horizontal virtual screen size too large\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800514 return -EINVAL;
515 }
516
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700517 if (var->xoffset + var->xres > var->xres_virtual ||
518 var->yoffset + var->yres > var->yres_virtual) {
519 dev_dbg(info->device, "panning out-of-range\n");
520 return -EINVAL;
521 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800522
523 /* We support ARGB8888 only */
524 if (var->bits_per_pixel > 32 || var->grayscale ||
525 var->red.offset > 16 || var->green.offset > 8 ||
526 var->blue.offset > 0 || var->transp.offset > 24 ||
527 var->red.length > 8 || var->green.length > 8 ||
528 var->blue.length > 8 || var->transp.length > 8 ||
529 var->red.msb_right || var->green.msb_right ||
530 var->blue.msb_right || var->transp.msb_right || var->nonstd) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700531 dev_dbg(info->device, "We support ARGB8888 only\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800532 return -EINVAL;
533 }
534
535 var->bits_per_pixel = 32;
536 var->red.offset = 16;
537 var->green.offset = 8;
538 var->blue.offset = 0;
539 var->transp.offset = 24;
540 var->red.length = 8;
541 var->green.length = 8;
542 var->blue.length = 8;
543 var->transp.length = 8;
544 var->red.msb_right = 0;
545 var->green.msb_right = 0;
546 var->blue.msb_right = 0;
547 var->transp.msb_right = 0;
548
549 /* Rotation is not supported */
550 if (var->rotate) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700551 dev_dbg(info->device, "Rotation is not supported\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800552 return -EINVAL;
553 }
554
555 /* Memory limit */
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700556 if (var->yres_virtual * xdr_line_length > ps3fb.xdr_size) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700557 dev_dbg(info->device, "Not enough memory\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800558 return -ENOMEM;
559 }
560
561 var->height = -1;
562 var->width = -1;
563
564 return 0;
565}
566
567 /*
568 * This routine actually sets the video mode.
569 */
570
571static int ps3fb_set_par(struct fb_info *info)
572{
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700573 struct ps3fb_par *par = info->par;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700574 unsigned int mode, ddr_line_length, xdr_line_length, lines, maxlines;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800575 int i;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700576 unsigned long offset;
577 u64 dst;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800578
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700579 dev_dbg(info->device, "xres:%d xv:%d yres:%d yv:%d clock:%d\n",
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800580 info->var.xres, info->var.xres_virtual,
581 info->var.yres, info->var.yres_virtual, info->var.pixclock);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800582
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700583 mode = ps3fb_find_mode(&info->var, &ddr_line_length, &xdr_line_length);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800584 if (!mode)
585 return -EINVAL;
586
Geert Uytterhoevenc95344a2007-10-16 01:29:25 -0700587 i = ps3fb_get_res_table(info->var.xres, info->var.yres, mode);
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700588 par->res_index = i;
Geert Uytterhoevenc95344a2007-10-16 01:29:25 -0700589
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700590 info->fix.smem_start = virt_to_abs(ps3fb.xdr_ea);
591 info->fix.smem_len = ps3fb.xdr_size;
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700592 info->fix.xpanstep = info->var.xres_virtual > info->var.xres ? 1 : 0;
593 info->fix.ypanstep = info->var.yres_virtual > info->var.yres ? 1 : 0;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700594 info->fix.line_length = xdr_line_length;
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700595
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700596 info->screen_base = (char __iomem *)ps3fb.xdr_ea;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800597
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700598 par->num_frames = ps3fb.xdr_size /
599 max(ps3fb_res[i].yres * ddr_line_length,
600 info->var.yres_virtual * xdr_line_length);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800601
602 /* Keep the special bits we cannot set using fb_var_screeninfo */
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700603 par->new_mode_id = (par->new_mode_id & ~PS3AV_MODE_MASK) | mode;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800604
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700605 par->width = info->var.xres;
606 par->height = info->var.yres;
Geert Uytterhoevend9a4ba62008-02-06 01:39:31 -0800607
608 /* Start of the virtual frame buffer (relative to fullscreen) */
609 offset = ps3fb_res[i].yoff * ddr_line_length + ps3fb_res[i].xoff * BPP;
610
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700611 par->fb_offset = GPU_ALIGN_UP(offset);
612 par->full_offset = par->fb_offset - offset;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700613 par->pan_offset = info->var.yoffset * xdr_line_length +
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700614 info->var.xoffset * BPP;
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700615
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700616 if (par->new_mode_id != par->mode_id) {
617 if (ps3av_set_video_mode(par->new_mode_id)) {
618 par->new_mode_id = par->mode_id;
619 return -EINVAL;
620 }
621 par->mode_id = par->new_mode_id;
622 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800623
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700624 /* Clear XDR frame buffer memory */
625 memset(ps3fb.xdr_ea, 0, ps3fb.xdr_size);
626
627 /* Clear DDR frame buffer memory */
628 lines = ps3fb_res[i].yres * par->num_frames;
629 if (par->full_offset)
630 lines++;
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700631 maxlines = ps3fb.xdr_size / ddr_line_length;
632 for (dst = 0; lines; dst += maxlines * ddr_line_length) {
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700633 unsigned int l = min(lines, maxlines);
634 ps3fb_sync_image(info->device, 0, dst, 0, ps3fb_res[i].xres, l,
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700635 ddr_line_length, ddr_line_length);
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -0700636 lines -= l;
637 }
638
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800639 return 0;
640}
641
642 /*
643 * Set a single color register. The values supplied are already
644 * rounded down to the hardware's capabilities (according to the
645 * entries in the var structure). Return != 0 for invalid regno.
646 */
647
648static int ps3fb_setcolreg(unsigned int regno, unsigned int red,
649 unsigned int green, unsigned int blue,
650 unsigned int transp, struct fb_info *info)
651{
652 if (regno >= 16)
653 return 1;
654
655 red >>= 8;
656 green >>= 8;
657 blue >>= 8;
658 transp >>= 8;
659
660 ((u32 *)info->pseudo_palette)[regno] = transp << 24 | red << 16 |
661 green << 8 | blue;
662 return 0;
663}
664
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -0700665static int ps3fb_pan_display(struct fb_var_screeninfo *var,
666 struct fb_info *info)
667{
668 struct ps3fb_par *par = info->par;
669
670 par->pan_offset = var->yoffset * info->fix.line_length +
671 var->xoffset * BPP;
672 return 0;
673}
674
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800675 /*
676 * As we have a virtual frame buffer, we need our own mmap function
677 */
678
679static int ps3fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
680{
681 unsigned long size, offset;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800682
683 size = vma->vm_end - vma->vm_start;
684 offset = vma->vm_pgoff << PAGE_SHIFT;
685 if (offset + size > info->fix.smem_len)
686 return -EINVAL;
687
Geert Uytterhoeven2ce32e12007-10-16 01:29:48 -0700688 offset += info->fix.smem_start;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800689 if (remap_pfn_range(vma, vma->vm_start, offset >> PAGE_SHIFT,
690 size, vma->vm_page_prot))
691 return -EAGAIN;
692
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700693 dev_dbg(info->device, "ps3fb: mmap framebuffer P(%lx)->V(%lx)\n",
694 offset, vma->vm_start);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800695 return 0;
696}
697
698 /*
699 * Blank the display
700 */
701
702static int ps3fb_blank(int blank, struct fb_info *info)
703{
704 int retval;
705
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700706 dev_dbg(info->device, "%s: blank:%d\n", __func__, blank);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800707 switch (blank) {
708 case FB_BLANK_POWERDOWN:
709 case FB_BLANK_HSYNC_SUSPEND:
710 case FB_BLANK_VSYNC_SUSPEND:
711 case FB_BLANK_NORMAL:
712 retval = ps3av_video_mute(1); /* mute on */
713 if (!retval)
714 ps3fb.is_blanked = 1;
715 break;
716
717 default: /* unblank */
718 retval = ps3av_video_mute(0); /* mute off */
719 if (!retval)
720 ps3fb.is_blanked = 0;
721 break;
722 }
723 return retval;
724}
725
726static int ps3fb_get_vblank(struct fb_vblank *vblank)
727{
Li Zefan3cc2c172007-11-14 16:58:33 -0800728 memset(vblank, 0, sizeof(*vblank));
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800729 vblank->flags = FB_VBLANK_HAVE_VSYNC;
730 return 0;
731}
732
Geert Uytterhoeven15e4d002007-10-16 01:29:47 -0700733static int ps3fb_wait_for_vsync(u32 crtc)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800734{
735 int ret;
736 u64 count;
737
738 count = ps3fb.vblank_count;
739 ret = wait_event_interruptible_timeout(ps3fb.wait_vsync,
740 count != ps3fb.vblank_count,
741 HZ / 10);
742 if (!ret)
743 return -ETIMEDOUT;
744
745 return 0;
746}
747
Geert Uytterhoeven15e4d002007-10-16 01:29:47 -0700748static void ps3fb_flip_ctl(int on, void *data)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800749{
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000750 struct ps3fb_priv *priv = data;
Geert Uytterhoeveneca28742007-05-02 14:48:32 +0200751 if (on)
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000752 atomic_dec_if_positive(&priv->ext_flip);
Geert Uytterhoeveneca28742007-05-02 14:48:32 +0200753 else
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000754 atomic_inc(&priv->ext_flip);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800755}
756
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800757
758 /*
759 * ioctl
760 */
761
762static int ps3fb_ioctl(struct fb_info *info, unsigned int cmd,
763 unsigned long arg)
764{
765 void __user *argp = (void __user *)arg;
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700766 u32 val;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800767 int retval = -EFAULT;
768
769 switch (cmd) {
770 case FBIOGET_VBLANK:
771 {
772 struct fb_vblank vblank;
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700773 dev_dbg(info->device, "FBIOGET_VBLANK:\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800774 retval = ps3fb_get_vblank(&vblank);
775 if (retval)
776 break;
777
778 if (copy_to_user(argp, &vblank, sizeof(vblank)))
779 retval = -EFAULT;
780 break;
781 }
782
783 case FBIO_WAITFORVSYNC:
784 {
785 u32 crt;
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700786 dev_dbg(info->device, "FBIO_WAITFORVSYNC:\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800787 if (get_user(crt, (u32 __user *) arg))
788 break;
789
790 retval = ps3fb_wait_for_vsync(crt);
791 break;
792 }
793
794 case PS3FB_IOCTL_SETMODE:
795 {
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700796 struct ps3fb_par *par = info->par;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800797 const struct fb_videomode *mode;
798 struct fb_var_screeninfo var;
799
800 if (copy_from_user(&val, argp, sizeof(val)))
801 break;
802
Masashi Kimoto64072902007-05-02 14:48:36 +0200803 if (!(val & PS3AV_MODE_MASK)) {
Geert Uytterhoevence4c3712007-10-16 01:29:44 -0700804 u32 id = ps3av_get_auto_mode();
Masashi Kimoto64072902007-05-02 14:48:36 +0200805 if (id > 0)
806 val = (val & ~PS3AV_MODE_MASK) | id;
807 }
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700808 dev_dbg(info->device, "PS3FB_IOCTL_SETMODE:%x\n", val);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800809 retval = -EINVAL;
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700810 mode = ps3fb_default_mode(val);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800811 if (mode) {
812 var = info->var;
813 fb_videomode_to_var(&var, mode);
814 acquire_console_sem();
815 info->flags |= FBINFO_MISC_USEREVENT;
816 /* Force, in case only special bits changed */
817 var.activate |= FB_ACTIVATE_FORCE;
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700818 par->new_mode_id = val;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800819 retval = fb_set_var(info, &var);
820 info->flags &= ~FBINFO_MISC_USEREVENT;
821 release_console_sem();
822 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800823 break;
824 }
825
826 case PS3FB_IOCTL_GETMODE:
827 val = ps3av_get_mode();
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700828 dev_dbg(info->device, "PS3FB_IOCTL_GETMODE:%x\n", val);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800829 if (!copy_to_user(argp, &val, sizeof(val)))
830 retval = 0;
831 break;
832
833 case PS3FB_IOCTL_SCREENINFO:
834 {
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700835 struct ps3fb_par *par = info->par;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800836 struct ps3fb_ioctl_res res;
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700837 dev_dbg(info->device, "PS3FB_IOCTL_SCREENINFO:\n");
Geert Uytterhoeven61e0b282007-10-16 01:29:51 -0700838 res.xres = info->fix.line_length / BPP;
839 res.yres = info->var.yres_virtual;
840 res.xoff = (res.xres - info->var.xres) / 2;
841 res.yoff = (res.yres - info->var.yres) / 2;
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -0700842 res.num_frames = par->num_frames;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800843 if (!copy_to_user(argp, &res, sizeof(res)))
844 retval = 0;
845 break;
846 }
847
848 case PS3FB_IOCTL_ON:
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700849 dev_dbg(info->device, "PS3FB_IOCTL_ON:\n");
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800850 atomic_inc(&ps3fb.ext_flip);
851 retval = 0;
852 break;
853
854 case PS3FB_IOCTL_OFF:
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700855 dev_dbg(info->device, "PS3FB_IOCTL_OFF:\n");
Geert Uytterhoeveneca28742007-05-02 14:48:32 +0200856 atomic_dec_if_positive(&ps3fb.ext_flip);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800857 retval = 0;
858 break;
859
860 case PS3FB_IOCTL_FSEL:
861 if (copy_from_user(&val, argp, sizeof(val)))
862 break;
863
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700864 dev_dbg(info->device, "PS3FB_IOCTL_FSEL:%d\n", val);
Jeremy Kerr8dab6372008-01-11 14:28:04 +0100865 acquire_console_sem();
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700866 retval = ps3fb_sync(info, val);
Jeremy Kerr8dab6372008-01-11 14:28:04 +0100867 release_console_sem();
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;
Jeremy Kerr8dab6372008-01-11 14:28:04 +0100887 acquire_console_sem();
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700888 ps3fb_sync(info, 0); /* single buffer */
Jeremy Kerr8dab6372008-01-11 14:28:04 +0100889 release_console_sem();
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +0200890 }
891 schedule();
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800892 }
893 return 0;
894}
895
896static irqreturn_t ps3fb_vsync_interrupt(int irq, void *ptr)
897{
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700898 struct device *dev = ptr;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800899 u64 v1;
900 int status;
901 struct display_head *head = &ps3fb.dinfo->display_head[1];
902
903 status = lv1_gpu_context_intr(ps3fb.context_handle, &v1);
904 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700905 dev_err(dev, "%s: lv1_gpu_context_intr failed: %d\n", __func__,
906 status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800907 return IRQ_NONE;
908 }
909
910 if (v1 & (1 << GPU_INTR_STATUS_VSYNC_1)) {
911 /* VSYNC */
912 ps3fb.vblank_count = head->vblank_count;
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +0200913 if (ps3fb.task && !ps3fb.is_blanked &&
914 !atomic_read(&ps3fb.ext_flip)) {
915 ps3fb.is_kicked = 1;
916 wake_up_process(ps3fb.task);
917 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800918 wake_up_interruptible(&ps3fb.wait_vsync);
919 }
920
921 return IRQ_HANDLED;
922}
923
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800924
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000925static int ps3fb_vsync_settings(struct gpu_driver_info *dinfo,
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700926 struct device *dev)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800927{
928 int error;
929
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700930 dev_dbg(dev, "version_driver:%x\n", dinfo->version_driver);
931 dev_dbg(dev, "irq outlet:%x\n", dinfo->irq.irq_outlet);
932 dev_dbg(dev,
933 "version_gpu: %x memory_size: %x ch: %x core_freq: %d "
934 "mem_freq:%d\n",
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800935 dinfo->version_gpu, dinfo->memory_size, dinfo->hardware_channel,
936 dinfo->nvcore_frequency/1000000, dinfo->memory_frequency/1000000);
937
938 if (dinfo->version_driver != GPU_DRIVER_INFO_VERSION) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700939 dev_err(dev, "%s: version_driver err:%x\n", __func__,
940 dinfo->version_driver);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800941 return -EINVAL;
942 }
943
Geoff Levanddc4f60c2007-05-01 07:01:01 +1000944 error = ps3_irq_plug_setup(PS3_BINDING_CPU_ANY, dinfo->irq.irq_outlet,
945 &ps3fb.irq_no);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800946 if (error) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700947 dev_err(dev, "%s: ps3_alloc_irq failed %d\n", __func__, error);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800948 return error;
949 }
950
951 error = request_irq(ps3fb.irq_no, ps3fb_vsync_interrupt, IRQF_DISABLED,
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +1000952 DEVICE_NAME, dev);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800953 if (error) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700954 dev_err(dev, "%s: request_irq failed %d\n", __func__, error);
Geoff Levanddc4f60c2007-05-01 07:01:01 +1000955 ps3_irq_plug_destroy(ps3fb.irq_no);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800956 return error;
957 }
958
959 dinfo->irq.mask = (1 << GPU_INTR_STATUS_VSYNC_1) |
960 (1 << GPU_INTR_STATUS_FLIP_1);
961 return 0;
962}
963
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700964static int ps3fb_xdr_settings(u64 xdr_lpar, struct device *dev)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800965{
966 int status;
967
968 status = lv1_gpu_context_iomap(ps3fb.context_handle, GPU_IOIF,
969 xdr_lpar, ps3fb_videomemory.size, 0);
970 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700971 dev_err(dev, "%s: lv1_gpu_context_iomap failed: %d\n",
972 __func__, status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800973 return -ENXIO;
974 }
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700975 dev_dbg(dev,
976 "video:%p xdr_ea:%p ioif:%lx lpar:%lx phys:%lx size:%lx\n",
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800977 ps3fb_videomemory.address, ps3fb.xdr_ea, GPU_IOIF, xdr_lpar,
978 virt_to_abs(ps3fb.xdr_ea), ps3fb_videomemory.size);
979
980 status = lv1_gpu_context_attribute(ps3fb.context_handle,
981 L1GPU_CONTEXT_ATTRIBUTE_FB_SETUP,
Geert Uytterhoeven9ac67a32007-12-19 11:16:41 +0100982 xdr_lpar, GPU_CMD_BUF_SIZE,
983 GPU_IOIF, 0);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800984 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -0700985 dev_err(dev,
986 "%s: lv1_gpu_context_attribute FB_SETUP failed: %d\n",
987 __func__, status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800988 return -ENXIO;
989 }
990 return 0;
991}
992
993static struct fb_ops ps3fb_ops = {
994 .fb_open = ps3fb_open,
995 .fb_release = ps3fb_release,
Geert Uytterhoeven92c45792007-05-23 13:57:50 -0700996 .fb_read = fb_sys_read,
997 .fb_write = fb_sys_write,
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -0800998 .fb_check_var = ps3fb_check_var,
999 .fb_set_par = ps3fb_set_par,
1000 .fb_setcolreg = ps3fb_setcolreg,
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -07001001 .fb_pan_display = ps3fb_pan_display,
Geert Uytterhoeven92c45792007-05-23 13:57:50 -07001002 .fb_fillrect = sys_fillrect,
1003 .fb_copyarea = sys_copyarea,
1004 .fb_imageblit = sys_imageblit,
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001005 .fb_mmap = ps3fb_mmap,
1006 .fb_blank = ps3fb_blank,
1007 .fb_ioctl = ps3fb_ioctl,
1008 .fb_compat_ioctl = ps3fb_ioctl
1009};
1010
1011static struct fb_fix_screeninfo ps3fb_fix __initdata = {
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001012 .id = DEVICE_NAME,
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001013 .type = FB_TYPE_PACKED_PIXELS,
1014 .visual = FB_VISUAL_TRUECOLOR,
1015 .accel = FB_ACCEL_NONE,
1016};
1017
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001018static int ps3fb_set_sync(struct device *dev)
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001019{
1020 int status;
1021
1022#ifdef HEAD_A
1023 status = lv1_gpu_context_attribute(0x0,
1024 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
1025 0, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0);
1026 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001027 dev_err(dev,
1028 "%s: lv1_gpu_context_attribute DISPLAY_SYNC failed: "
1029 "%d\n",
1030 __func__, status);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001031 return -1;
1032 }
1033#endif
1034#ifdef HEAD_B
1035 status = lv1_gpu_context_attribute(0x0,
1036 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
1037 1, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0);
1038
1039 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001040 dev_err(dev,
1041 "%s: lv1_gpu_context_attribute DISPLAY_SYNC failed: "
1042 "%d\n",
1043 __func__, status);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001044 return -1;
1045 }
1046#endif
1047 return 0;
1048}
1049
1050static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001051{
1052 struct fb_info *info;
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -07001053 struct ps3fb_par *par;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001054 int retval = -ENOMEM;
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001055 u32 xres, yres;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001056 u64 ddr_lpar = 0;
1057 u64 lpar_dma_control = 0;
1058 u64 lpar_driver_info = 0;
1059 u64 lpar_reports = 0;
1060 u64 lpar_reports_size = 0;
1061 u64 xdr_lpar;
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -07001062 int status, res_index;
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +02001063 struct task_struct *task;
Geert Uytterhoevenee592a52007-11-28 16:21:11 -08001064 unsigned long max_ps3fb_size;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001065
Geert Uytterhoeven9ac67a32007-12-19 11:16:41 +01001066 if (ps3fb_videomemory.size < GPU_CMD_BUF_SIZE) {
1067 dev_err(&dev->core, "%s: Not enough video memory\n", __func__);
1068 return -ENOMEM;
1069 }
1070
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001071 status = ps3_open_hv_device(dev);
1072 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001073 dev_err(&dev->core, "%s: ps3_open_hv_device failed\n",
1074 __func__);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001075 goto err;
1076 }
1077
1078 if (!ps3fb_mode)
1079 ps3fb_mode = ps3av_get_mode();
Geert Uytterhoeven084ffff2008-02-06 01:39:29 -08001080 dev_dbg(&dev->core, "ps3fb_mode: %d\n", ps3fb_mode);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001081
1082 if (ps3fb_mode > 0 &&
1083 !ps3av_video_mode2res(ps3fb_mode, &xres, &yres)) {
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -07001084 res_index = ps3fb_get_res_table(xres, yres, ps3fb_mode);
1085 dev_dbg(&dev->core, "res_index:%d\n", res_index);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001086 } else
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -07001087 res_index = GPU_RES_INDEX;
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001088
1089 atomic_set(&ps3fb.f_count, -1); /* fbcon opens ps3fb */
1090 atomic_set(&ps3fb.ext_flip, 0); /* for flip with vsync */
1091 init_waitqueue_head(&ps3fb.wait_vsync);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001092
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001093 ps3fb_set_sync(&dev->core);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001094
Geert Uytterhoevenee592a52007-11-28 16:21:11 -08001095 max_ps3fb_size = _ALIGN_UP(GPU_IOIF, 256*1024*1024) - GPU_IOIF;
1096 if (ps3fb_videomemory.size > max_ps3fb_size) {
1097 dev_info(&dev->core, "Limiting ps3fb mem size to %lu bytes\n",
1098 max_ps3fb_size);
1099 ps3fb_videomemory.size = max_ps3fb_size;
1100 }
1101
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001102 /* get gpu context handle */
Geert Uytterhoevenee592a52007-11-28 16:21:11 -08001103 status = lv1_gpu_memory_allocate(ps3fb_videomemory.size, 0, 0, 0, 0,
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001104 &ps3fb.memory_handle, &ddr_lpar);
1105 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001106 dev_err(&dev->core, "%s: lv1_gpu_memory_allocate failed: %d\n",
1107 __func__, status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001108 goto err;
1109 }
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001110 dev_dbg(&dev->core, "ddr:lpar:0x%lx\n", ddr_lpar);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001111
1112 status = lv1_gpu_context_allocate(ps3fb.memory_handle, 0,
1113 &ps3fb.context_handle,
1114 &lpar_dma_control, &lpar_driver_info,
1115 &lpar_reports, &lpar_reports_size);
1116 if (status) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001117 dev_err(&dev->core,
1118 "%s: lv1_gpu_context_attribute failed: %d\n", __func__,
1119 status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001120 goto err_gpu_memory_free;
1121 }
1122
1123 /* vsync interrupt */
1124 ps3fb.dinfo = ioremap(lpar_driver_info, 128 * 1024);
1125 if (!ps3fb.dinfo) {
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001126 dev_err(&dev->core, "%s: ioremap failed\n", __func__);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001127 goto err_gpu_context_free;
1128 }
1129
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001130 retval = ps3fb_vsync_settings(ps3fb.dinfo, &dev->core);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001131 if (retval)
1132 goto err_iounmap_dinfo;
1133
Geert Uytterhoeven2ce32e12007-10-16 01:29:48 -07001134 /* XDR frame buffer */
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001135 ps3fb.xdr_ea = ps3fb_videomemory.address;
1136 xdr_lpar = ps3_mm_phys_to_lpar(__pa(ps3fb.xdr_ea));
Geert Uytterhoeven2ce32e12007-10-16 01:29:48 -07001137
1138 /* Clear memory to prevent kernel info leakage into userspace */
1139 memset(ps3fb.xdr_ea, 0, ps3fb_videomemory.size);
1140
Geert Uytterhoeven9ac67a32007-12-19 11:16:41 +01001141 /*
1142 * The GPU command buffer is at the start of video memory
1143 * As we don't use the full command buffer, we can put the actual
1144 * frame buffer at offset GPU_FB_START and save some precious XDR
1145 * memory
1146 */
1147 ps3fb.xdr_ea += GPU_FB_START;
1148 ps3fb.xdr_size = ps3fb_videomemory.size - GPU_FB_START;
Geert Uytterhoeven2ce32e12007-10-16 01:29:48 -07001149
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001150 retval = ps3fb_xdr_settings(xdr_lpar, &dev->core);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001151 if (retval)
1152 goto err_free_irq;
1153
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -07001154 info = framebuffer_alloc(sizeof(struct ps3fb_par), &dev->core);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001155 if (!info)
1156 goto err_free_irq;
1157
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -07001158 par = info->par;
1159 par->mode_id = ~ps3fb_mode; /* != ps3fb_mode, to trigger change */
1160 par->new_mode_id = ps3fb_mode;
1161 par->res_index = res_index;
1162 par->num_frames = 1;
1163
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -07001164 info->screen_base = (char __iomem *)ps3fb.xdr_ea;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001165 info->fbops = &ps3fb_ops;
1166
1167 info->fix = ps3fb_fix;
Geert Uytterhoevenf1664ed2007-10-16 01:29:49 -07001168 info->fix.smem_start = virt_to_abs(ps3fb.xdr_ea);
1169 info->fix.smem_len = ps3fb.xdr_size;
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -07001170 info->pseudo_palette = par->pseudo_palette;
Geert Uytterhoevenfc7028b72007-10-16 01:29:50 -07001171 info->flags = FBINFO_DEFAULT | FBINFO_READS_FAST |
1172 FBINFO_HWACCEL_XPAN | FBINFO_HWACCEL_YPAN;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001173
1174 retval = fb_alloc_cmap(&info->cmap, 256, 0);
1175 if (retval < 0)
1176 goto err_framebuffer_release;
1177
1178 if (!fb_find_mode(&info->var, info, mode_option, ps3fb_modedb,
Geert Uytterhoeven0333d8352007-10-16 01:29:48 -07001179 ARRAY_SIZE(ps3fb_modedb),
1180 ps3fb_default_mode(par->new_mode_id), 32)) {
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001181 retval = -EINVAL;
1182 goto err_fb_dealloc;
1183 }
1184
1185 fb_videomode_to_modelist(ps3fb_modedb, ARRAY_SIZE(ps3fb_modedb),
1186 &info->modelist);
1187
1188 retval = register_framebuffer(info);
1189 if (retval < 0)
1190 goto err_fb_dealloc;
1191
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001192 dev->core.driver_data = info;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001193
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001194 dev_info(info->device, "%s %s, using %lu KiB of video memory\n",
1195 dev_driver_string(info->dev), info->dev->bus_id,
Geert Uytterhoeven2ce32e12007-10-16 01:29:48 -07001196 ps3fb.xdr_size >> 10);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001197
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001198 task = kthread_run(ps3fbd, info, DEVICE_NAME);
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +02001199 if (IS_ERR(task)) {
1200 retval = PTR_ERR(task);
1201 goto err_unregister_framebuffer;
1202 }
1203
1204 ps3fb.task = task;
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001205 ps3av_register_flip_ctl(ps3fb_flip_ctl, &ps3fb);
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +02001206
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001207 return 0;
1208
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +02001209err_unregister_framebuffer:
1210 unregister_framebuffer(info);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001211err_fb_dealloc:
1212 fb_dealloc_cmap(&info->cmap);
1213err_framebuffer_release:
1214 framebuffer_release(info);
1215err_free_irq:
Geoff Levandfcbe6e92007-12-19 11:17:31 +01001216 free_irq(ps3fb.irq_no, &dev->core);
Geoff Levanddc4f60c2007-05-01 07:01:01 +10001217 ps3_irq_plug_destroy(ps3fb.irq_no);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001218err_iounmap_dinfo:
1219 iounmap((u8 __iomem *)ps3fb.dinfo);
1220err_gpu_context_free:
1221 lv1_gpu_context_free(ps3fb.context_handle);
1222err_gpu_memory_free:
1223 lv1_gpu_memory_free(ps3fb.memory_handle);
1224err:
1225 return retval;
1226}
1227
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001228static int ps3fb_shutdown(struct ps3_system_bus_device *dev)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001229{
1230 int status;
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001231 struct fb_info *info = dev->core.driver_data;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001232
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001233 dev_dbg(&dev->core, " -> %s:%d\n", __func__, __LINE__);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001234
1235 ps3fb_flip_ctl(0, &ps3fb); /* flip off */
1236 ps3fb.dinfo->irq.mask = 0;
1237
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001238 ps3av_register_flip_ctl(NULL, NULL);
Geert Uytterhoeven1c0c8462007-05-02 14:48:31 +02001239 if (ps3fb.task) {
1240 struct task_struct *task = ps3fb.task;
1241 ps3fb.task = NULL;
1242 kthread_stop(task);
1243 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001244 if (ps3fb.irq_no) {
Geoff Levandfcbe6e92007-12-19 11:17:31 +01001245 free_irq(ps3fb.irq_no, &dev->core);
Geoff Levanddc4f60c2007-05-01 07:01:01 +10001246 ps3_irq_plug_destroy(ps3fb.irq_no);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001247 }
Jeremy Kerrba216112008-01-11 14:27:10 +01001248 if (info) {
1249 unregister_framebuffer(info);
1250 fb_dealloc_cmap(&info->cmap);
1251 framebuffer_release(info);
1252 info = dev->core.driver_data = NULL;
1253 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001254 iounmap((u8 __iomem *)ps3fb.dinfo);
1255
1256 status = lv1_gpu_context_free(ps3fb.context_handle);
1257 if (status)
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001258 dev_dbg(&dev->core, "lv1_gpu_context_free failed: %d\n",
1259 status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001260
1261 status = lv1_gpu_memory_free(ps3fb.memory_handle);
1262 if (status)
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001263 dev_dbg(&dev->core, "lv1_gpu_memory_free failed: %d\n",
1264 status);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001265
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001266 ps3_close_hv_device(dev);
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001267 dev_dbg(&dev->core, " <- %s:%d\n", __func__, __LINE__);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001268
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001269 return 0;
1270}
1271
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001272static struct ps3_system_bus_driver ps3fb_driver = {
1273 .match_id = PS3_MATCH_ID_GRAPHICS,
1274 .core.name = DEVICE_NAME,
1275 .core.owner = THIS_MODULE,
1276 .probe = ps3fb_probe,
1277 .remove = ps3fb_shutdown,
1278 .shutdown = ps3fb_shutdown,
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001279};
1280
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001281static int __init ps3fb_setup(void)
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001282{
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001283 char *options;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001284
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001285#ifdef MODULE
1286 return 0;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001287#endif
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001288
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001289 if (fb_get_options(DEVICE_NAME, &options))
1290 return -ENXIO;
1291
1292 if (!options || !*options)
1293 return 0;
1294
1295 while (1) {
1296 char *this_opt = strsep(&options, ",");
1297
1298 if (!this_opt)
1299 break;
1300 if (!*this_opt)
1301 continue;
1302 if (!strncmp(this_opt, "mode:", 5))
1303 ps3fb_mode = simple_strtoul(this_opt + 5, NULL, 0);
1304 else
1305 mode_option = this_opt;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001306 }
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001307 return 0;
1308}
1309
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001310static int __init ps3fb_init(void)
1311{
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001312 if (!ps3fb_videomemory.address || ps3fb_setup())
1313 return -ENXIO;
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001314
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001315 return ps3_system_bus_driver_register(&ps3fb_driver);
1316}
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001317
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001318static void __exit ps3fb_exit(void)
1319{
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001320 pr_debug(" -> %s:%d\n", __func__, __LINE__);
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001321 ps3_system_bus_driver_unregister(&ps3fb_driver);
Geert Uytterhoeven535da7f2007-10-16 01:29:45 -07001322 pr_debug(" <- %s:%d\n", __func__, __LINE__);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001323}
1324
1325module_init(ps3fb_init);
Geert Uytterhoeven310d8c12007-02-12 00:55:23 -08001326module_exit(ps3fb_exit);
1327
1328MODULE_LICENSE("GPL");
Geert Uytterhoeven9e6b99b2007-06-16 08:05:38 +10001329MODULE_DESCRIPTION("PS3 GPU Frame Buffer Driver");
1330MODULE_AUTHOR("Sony Computer Entertainment Inc.");
1331MODULE_ALIAS(PS3_MODULE_ALIAS_GRAPHICS);