ps3fb.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. /*
  2. * linux/drivers/video/ps3fb.c -- PS3 GPU frame buffer device
  3. *
  4. * Copyright (C) 2006 Sony Computer Entertainment Inc.
  5. * Copyright 2006, 2007 Sony Corporation
  6. *
  7. * This file is based on :
  8. *
  9. * linux/drivers/video/vfb.c -- Virtual frame buffer device
  10. *
  11. * Copyright (C) 2002 James Simmons
  12. *
  13. * Copyright (C) 1997 Geert Uytterhoeven
  14. *
  15. * This file is subject to the terms and conditions of the GNU General Public
  16. * License. See the file COPYING in the main directory of this archive for
  17. * more details.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/kernel.h>
  21. #include <linux/errno.h>
  22. #include <linux/string.h>
  23. #include <linux/mm.h>
  24. #include <linux/tty.h>
  25. #include <linux/slab.h>
  26. #include <linux/vmalloc.h>
  27. #include <linux/delay.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/console.h>
  31. #include <linux/ioctl.h>
  32. #include <linux/notifier.h>
  33. #include <linux/reboot.h>
  34. #include <linux/kthread.h>
  35. #include <linux/freezer.h>
  36. #include <asm/uaccess.h>
  37. #include <linux/fb.h>
  38. #include <linux/init.h>
  39. #include <asm/time.h>
  40. #include <asm/abs_addr.h>
  41. #include <asm/lv1call.h>
  42. #include <asm/ps3av.h>
  43. #include <asm/ps3fb.h>
  44. #include <asm/ps3.h>
  45. #ifdef PS3FB_DEBUG
  46. #define DPRINTK(fmt, args...) printk("%s: " fmt, __FUNCTION__ , ##args)
  47. #else
  48. #define DPRINTK(fmt, args...)
  49. #endif
  50. #define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC 0x101
  51. #define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP 0x102
  52. #define L1GPU_CONTEXT_ATTRIBUTE_FB_SETUP 0x600
  53. #define L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT 0x601
  54. #define L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT_SYNC 0x602
  55. #define L1GPU_FB_BLIT_WAIT_FOR_COMPLETION (1ULL << 32)
  56. #define L1GPU_DISPLAY_SYNC_HSYNC 1
  57. #define L1GPU_DISPLAY_SYNC_VSYNC 2
  58. #define DDR_SIZE (0) /* used no ddr */
  59. #define GPU_OFFSET (64 * 1024)
  60. #define GPU_IOIF (0x0d000000UL)
  61. #define PS3FB_FULL_MODE_BIT 0x80
  62. #define GPU_INTR_STATUS_VSYNC_0 0 /* vsync on head A */
  63. #define GPU_INTR_STATUS_VSYNC_1 1 /* vsync on head B */
  64. #define GPU_INTR_STATUS_FLIP_0 3 /* flip head A */
  65. #define GPU_INTR_STATUS_FLIP_1 4 /* flip head B */
  66. #define GPU_INTR_STATUS_QUEUE_0 5 /* queue head A */
  67. #define GPU_INTR_STATUS_QUEUE_1 6 /* queue head B */
  68. #define GPU_DRIVER_INFO_VERSION 0x211
  69. /* gpu internals */
  70. struct display_head {
  71. u64 be_time_stamp;
  72. u32 status;
  73. u32 offset;
  74. u32 res1;
  75. u32 res2;
  76. u32 field;
  77. u32 reserved1;
  78. u64 res3;
  79. u32 raster;
  80. u64 vblank_count;
  81. u32 field_vsync;
  82. u32 reserved2;
  83. };
  84. struct gpu_irq {
  85. u32 irq_outlet;
  86. u32 status;
  87. u32 mask;
  88. u32 video_cause;
  89. u32 graph_cause;
  90. u32 user_cause;
  91. u32 res1;
  92. u64 res2;
  93. u32 reserved[4];
  94. };
  95. struct gpu_driver_info {
  96. u32 version_driver;
  97. u32 version_gpu;
  98. u32 memory_size;
  99. u32 hardware_channel;
  100. u32 nvcore_frequency;
  101. u32 memory_frequency;
  102. u32 reserved[1063];
  103. struct display_head display_head[8];
  104. struct gpu_irq irq;
  105. };
  106. struct ps3fb_priv {
  107. unsigned int irq_no;
  108. void *dev;
  109. u64 context_handle, memory_handle;
  110. void *xdr_ea;
  111. struct gpu_driver_info *dinfo;
  112. u32 res_index;
  113. u64 vblank_count; /* frame count */
  114. wait_queue_head_t wait_vsync;
  115. u32 num_frames; /* num of frame buffers */
  116. atomic_t ext_flip; /* on/off flip with vsync */
  117. atomic_t f_count; /* fb_open count */
  118. int is_blanked;
  119. int is_kicked;
  120. struct task_struct *task;
  121. };
  122. static struct ps3fb_priv ps3fb;
  123. struct ps3fb_res_table {
  124. u32 xres;
  125. u32 yres;
  126. u32 xoff;
  127. u32 yoff;
  128. u32 type;
  129. };
  130. #define PS3FB_RES_FULL 1
  131. static const struct ps3fb_res_table ps3fb_res[] = {
  132. /* res_x,y margin_x,y full */
  133. { 720, 480, 72, 48 , 0},
  134. { 720, 576, 72, 58 , 0},
  135. { 1280, 720, 78, 38 , 0},
  136. { 1920, 1080, 116, 58 , 0},
  137. /* full mode */
  138. { 720, 480, 0, 0 , PS3FB_RES_FULL},
  139. { 720, 576, 0, 0 , PS3FB_RES_FULL},
  140. { 1280, 720, 0, 0 , PS3FB_RES_FULL},
  141. { 1920, 1080, 0, 0 , PS3FB_RES_FULL},
  142. /* vesa: normally full mode */
  143. { 1280, 768, 0, 0 , 0},
  144. { 1280, 1024, 0, 0 , 0},
  145. { 1920, 1200, 0, 0 , 0},
  146. { 0, 0, 0, 0 , 0} };
  147. /* default resolution */
  148. #define GPU_RES_INDEX 0 /* 720 x 480 */
  149. static const struct fb_videomode ps3fb_modedb[] = {
  150. /* 60 Hz broadcast modes (modes "1" to "5") */
  151. {
  152. /* 480i */
  153. "480i", 60, 576, 384, 74074, 130, 89, 78, 57, 63, 6,
  154. FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
  155. }, {
  156. /* 480p */
  157. "480p", 60, 576, 384, 37037, 130, 89, 78, 57, 63, 6,
  158. FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
  159. }, {
  160. /* 720p */
  161. "720p", 60, 1124, 644, 13481, 298, 148, 57, 44, 80, 5,
  162. FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
  163. }, {
  164. /* 1080i */
  165. "1080i", 60, 1688, 964, 13481, 264, 160, 94, 62, 88, 5,
  166. FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
  167. }, {
  168. /* 1080p */
  169. "1080p", 60, 1688, 964, 6741, 264, 160, 94, 62, 88, 5,
  170. FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
  171. },
  172. /* 50 Hz broadcast modes (modes "6" to "10") */
  173. {
  174. /* 576i */
  175. "576i", 50, 576, 460, 74074, 142, 83, 97, 63, 63, 5,
  176. FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
  177. }, {
  178. /* 576p */
  179. "576p", 50, 576, 460, 37037, 142, 83, 97, 63, 63, 5,
  180. FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
  181. }, {
  182. /* 720p */
  183. "720p", 50, 1124, 644, 13468, 298, 478, 57, 44, 80, 5,
  184. FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
  185. }, {
  186. /* 1080 */
  187. "1080i", 50, 1688, 964, 13468, 264, 600, 94, 62, 88, 5,
  188. FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
  189. }, {
  190. /* 1080p */
  191. "1080p", 50, 1688, 964, 6734, 264, 600, 94, 62, 88, 5,
  192. FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
  193. },
  194. /* VESA modes (modes "11" to "13") */
  195. {
  196. /* WXGA */
  197. "wxga", 60, 1280, 768, 12924, 160, 24, 29, 3, 136, 6,
  198. 0, FB_VMODE_NONINTERLACED,
  199. FB_MODE_IS_VESA
  200. }, {
  201. /* SXGA */
  202. "sxga", 60, 1280, 1024, 9259, 248, 48, 38, 1, 112, 3,
  203. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED,
  204. FB_MODE_IS_VESA
  205. }, {
  206. /* WUXGA */
  207. "wuxga", 60, 1920, 1200, 6494, 80, 48, 26, 3, 32, 6,
  208. FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED,
  209. FB_MODE_IS_VESA
  210. },
  211. /* 60 Hz broadcast modes (full resolution versions of modes "1" to "5") */
  212. {
  213. /* 480if */
  214. "480if", 60, 720, 480, 74074, 58, 17, 30, 9, 63, 6,
  215. FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
  216. }, {
  217. /* 480pf */
  218. "480pf", 60, 720, 480, 37037, 58, 17, 30, 9, 63, 6,
  219. FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
  220. }, {
  221. /* 720pf */
  222. "720pf", 60, 1280, 720, 13481, 220, 70, 19, 6, 80, 5,
  223. FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
  224. }, {
  225. /* 1080if */
  226. "1080if", 60, 1920, 1080, 13481, 148, 44, 36, 4, 88, 5,
  227. FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
  228. }, {
  229. /* 1080pf */
  230. "1080pf", 60, 1920, 1080, 6741, 148, 44, 36, 4, 88, 5,
  231. FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
  232. },
  233. /* 50 Hz broadcast modes (full resolution versions of modes "6" to "10") */
  234. {
  235. /* 576if */
  236. "576if", 50, 720, 576, 74074, 70, 11, 39, 5, 63, 5,
  237. FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
  238. }, {
  239. /* 576pf */
  240. "576pf", 50, 720, 576, 37037, 70, 11, 39, 5, 63, 5,
  241. FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
  242. }, {
  243. /* 720pf */
  244. "720pf", 50, 1280, 720, 13468, 220, 400, 19, 6, 80, 5,
  245. FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
  246. }, {
  247. /* 1080if */
  248. "1080f", 50, 1920, 1080, 13468, 148, 484, 36, 4, 88, 5,
  249. FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
  250. }, {
  251. /* 1080pf */
  252. "1080pf", 50, 1920, 1080, 6734, 148, 484, 36, 4, 88, 5,
  253. FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
  254. }
  255. };
  256. #define HEAD_A
  257. #define HEAD_B
  258. #define X_OFF(i) (ps3fb_res[i].xoff) /* left/right margin (pixel) */
  259. #define Y_OFF(i) (ps3fb_res[i].yoff) /* top/bottom margin (pixel) */
  260. #define WIDTH(i) (ps3fb_res[i].xres) /* width of FB */
  261. #define HEIGHT(i) (ps3fb_res[i].yres) /* height of FB */
  262. #define BPP 4 /* number of bytes per pixel */
  263. #define VP_OFF(i) (WIDTH(i) * Y_OFF(i) * BPP + X_OFF(i) * BPP)
  264. #define FB_OFF(i) (GPU_OFFSET - VP_OFF(i) % GPU_OFFSET)
  265. static int ps3fb_mode = 0;
  266. module_param(ps3fb_mode, bool, 0);
  267. static char *mode_option __initdata = NULL;
  268. static int ps3fb_get_res_table(u32 xres, u32 yres)
  269. {
  270. int full_mode;
  271. unsigned int i;
  272. u32 x, y, f;
  273. full_mode = (ps3fb_mode & PS3FB_FULL_MODE_BIT) ? PS3FB_RES_FULL : 0;
  274. for (i = 0;; i++) {
  275. x = ps3fb_res[i].xres;
  276. y = ps3fb_res[i].yres;
  277. f = ps3fb_res[i].type;
  278. if (!x) {
  279. DPRINTK("ERROR: ps3fb_get_res_table()\n");
  280. return -1;
  281. }
  282. if (full_mode == PS3FB_RES_FULL && f != PS3FB_RES_FULL)
  283. continue;
  284. if (x == xres && (yres == 0 || y == yres))
  285. break;
  286. x = x - 2 * ps3fb_res[i].xoff;
  287. y = y - 2 * ps3fb_res[i].yoff;
  288. if (x == xres && (yres == 0 || y == yres))
  289. break;
  290. }
  291. return i;
  292. }
  293. static unsigned int ps3fb_find_mode(const struct fb_var_screeninfo *var,
  294. u32 *line_length)
  295. {
  296. unsigned int i, mode;
  297. for (i = 0; i < ARRAY_SIZE(ps3fb_modedb); i++)
  298. if (var->xres == ps3fb_modedb[i].xres &&
  299. var->yres == ps3fb_modedb[i].yres &&
  300. var->pixclock == ps3fb_modedb[i].pixclock &&
  301. var->hsync_len == ps3fb_modedb[i].hsync_len &&
  302. var->vsync_len == ps3fb_modedb[i].vsync_len &&
  303. var->left_margin == ps3fb_modedb[i].left_margin &&
  304. var->right_margin == ps3fb_modedb[i].right_margin &&
  305. var->upper_margin == ps3fb_modedb[i].upper_margin &&
  306. var->lower_margin == ps3fb_modedb[i].lower_margin &&
  307. var->sync == ps3fb_modedb[i].sync &&
  308. (var->vmode & FB_VMODE_MASK) == ps3fb_modedb[i].vmode) {
  309. /* Cropped broadcast modes use the full line_length */
  310. *line_length =
  311. ps3fb_modedb[i < 10 ? i + 13 : i].xres * 4;
  312. /* Full broadcast modes have the full mode bit set */
  313. mode = i > 12 ? (i - 12) | PS3FB_FULL_MODE_BIT : i + 1;
  314. DPRINTK("ps3fb_find_mode: mode %u\n", mode);
  315. return mode;
  316. }
  317. DPRINTK("ps3fb_find_mode: mode not found\n");
  318. return 0;
  319. }
  320. static const struct fb_videomode *ps3fb_default_mode(void)
  321. {
  322. u32 mode = ps3fb_mode & PS3AV_MODE_MASK;
  323. u32 flags;
  324. if (mode < 1 || mode > 13)
  325. return NULL;
  326. flags = ps3fb_mode & ~PS3AV_MODE_MASK;
  327. if (mode <= 10 && flags & PS3FB_FULL_MODE_BIT) {
  328. /* Full broadcast mode */
  329. return &ps3fb_modedb[mode + 12];
  330. }
  331. return &ps3fb_modedb[mode - 1];
  332. }
  333. static int ps3fb_sync(u32 frame)
  334. {
  335. int i, status;
  336. u32 xres, yres;
  337. u64 fb_ioif, offset;
  338. i = ps3fb.res_index;
  339. xres = ps3fb_res[i].xres;
  340. yres = ps3fb_res[i].yres;
  341. if (frame > ps3fb.num_frames - 1) {
  342. printk(KERN_WARNING "%s: invalid frame number (%u)\n",
  343. __FUNCTION__, frame);
  344. return -EINVAL;
  345. }
  346. offset = xres * yres * BPP * frame;
  347. fb_ioif = GPU_IOIF + FB_OFF(i) + offset;
  348. status = lv1_gpu_context_attribute(ps3fb.context_handle,
  349. L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT,
  350. offset, fb_ioif,
  351. L1GPU_FB_BLIT_WAIT_FOR_COMPLETION |
  352. (xres << 16) | yres,
  353. xres * BPP); /* line_length */
  354. if (status)
  355. printk(KERN_ERR "%s: lv1_gpu_context_attribute FB_BLIT failed: %d\n",
  356. __FUNCTION__, status);
  357. #ifdef HEAD_A
  358. status = lv1_gpu_context_attribute(ps3fb.context_handle,
  359. L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP,
  360. 0, offset, 0, 0);
  361. if (status)
  362. printk(KERN_ERR "%s: lv1_gpu_context_attribute FLIP failed: %d\n",
  363. __FUNCTION__, status);
  364. #endif
  365. #ifdef HEAD_B
  366. status = lv1_gpu_context_attribute(ps3fb.context_handle,
  367. L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP,
  368. 1, offset, 0, 0);
  369. if (status)
  370. printk(KERN_ERR "%s: lv1_gpu_context_attribute FLIP failed: %d\n",
  371. __FUNCTION__, status);
  372. #endif
  373. return 0;
  374. }
  375. static int ps3fb_open(struct fb_info *info, int user)
  376. {
  377. atomic_inc(&ps3fb.f_count);
  378. return 0;
  379. }
  380. static int ps3fb_release(struct fb_info *info, int user)
  381. {
  382. if (atomic_dec_and_test(&ps3fb.f_count)) {
  383. if (atomic_read(&ps3fb.ext_flip)) {
  384. atomic_set(&ps3fb.ext_flip, 0);
  385. ps3fb_sync(0); /* single buffer */
  386. }
  387. }
  388. return 0;
  389. }
  390. /*
  391. * Setting the video mode has been split into two parts.
  392. * First part, xxxfb_check_var, must not write anything
  393. * to hardware, it should only verify and adjust var.
  394. * This means it doesn't alter par but it does use hardware
  395. * data from it to check this var.
  396. */
  397. static int ps3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  398. {
  399. u32 line_length;
  400. int mode;
  401. int i;
  402. DPRINTK("var->xres:%u info->var.xres:%u\n", var->xres, info->var.xres);
  403. DPRINTK("var->yres:%u info->var.yres:%u\n", var->yres, info->var.yres);
  404. /* FIXME For now we do exact matches only */
  405. mode = ps3fb_find_mode(var, &line_length);
  406. if (!mode)
  407. return -EINVAL;
  408. /*
  409. * FB_VMODE_CONUPDATE and FB_VMODE_SMOOTH_XPAN are equal!
  410. * as FB_VMODE_SMOOTH_XPAN is only used internally
  411. */
  412. if (var->vmode & FB_VMODE_CONUPDATE) {
  413. var->vmode |= FB_VMODE_YWRAP;
  414. var->xoffset = info->var.xoffset;
  415. var->yoffset = info->var.yoffset;
  416. }
  417. /* Virtual screen and panning are not supported */
  418. if (var->xres_virtual > var->xres || var->yres_virtual > var->yres ||
  419. var->xoffset || var->yoffset) {
  420. DPRINTK("Virtual screen and panning are not supported\n");
  421. return -EINVAL;
  422. }
  423. var->xres_virtual = var->xres;
  424. var->yres_virtual = var->yres;
  425. /* We support ARGB8888 only */
  426. if (var->bits_per_pixel > 32 || var->grayscale ||
  427. var->red.offset > 16 || var->green.offset > 8 ||
  428. var->blue.offset > 0 || var->transp.offset > 24 ||
  429. var->red.length > 8 || var->green.length > 8 ||
  430. var->blue.length > 8 || var->transp.length > 8 ||
  431. var->red.msb_right || var->green.msb_right ||
  432. var->blue.msb_right || var->transp.msb_right || var->nonstd) {
  433. DPRINTK("We support ARGB8888 only\n");
  434. return -EINVAL;
  435. }
  436. var->bits_per_pixel = 32;
  437. var->red.offset = 16;
  438. var->green.offset = 8;
  439. var->blue.offset = 0;
  440. var->transp.offset = 24;
  441. var->red.length = 8;
  442. var->green.length = 8;
  443. var->blue.length = 8;
  444. var->transp.length = 8;
  445. var->red.msb_right = 0;
  446. var->green.msb_right = 0;
  447. var->blue.msb_right = 0;
  448. var->transp.msb_right = 0;
  449. /* Rotation is not supported */
  450. if (var->rotate) {
  451. DPRINTK("Rotation is not supported\n");
  452. return -EINVAL;
  453. }
  454. /* Memory limit */
  455. i = ps3fb_get_res_table(var->xres, var->yres);
  456. if (ps3fb_res[i].xres*ps3fb_res[i].yres*BPP > ps3fb_videomemory.size) {
  457. DPRINTK("Not enough memory\n");
  458. return -ENOMEM;
  459. }
  460. var->height = -1;
  461. var->width = -1;
  462. return 0;
  463. }
  464. /*
  465. * This routine actually sets the video mode.
  466. */
  467. static int ps3fb_set_par(struct fb_info *info)
  468. {
  469. unsigned int mode;
  470. int i;
  471. unsigned long offset;
  472. static int first = 1;
  473. DPRINTK("xres:%d xv:%d yres:%d yv:%d clock:%d\n",
  474. info->var.xres, info->var.xres_virtual,
  475. info->var.yres, info->var.yres_virtual, info->var.pixclock);
  476. i = ps3fb_get_res_table(info->var.xres, info->var.yres);
  477. ps3fb.res_index = i;
  478. mode = ps3fb_find_mode(&info->var, &info->fix.line_length);
  479. if (!mode)
  480. return -EINVAL;
  481. offset = FB_OFF(i) + VP_OFF(i);
  482. info->fix.smem_len = ps3fb_videomemory.size - offset;
  483. info->screen_base = (char __iomem *)ps3fb.xdr_ea + offset;
  484. memset(ps3fb.xdr_ea, 0, ps3fb_videomemory.size);
  485. ps3fb.num_frames = ps3fb_videomemory.size/
  486. (ps3fb_res[i].xres*ps3fb_res[i].yres*BPP);
  487. /* Keep the special bits we cannot set using fb_var_screeninfo */
  488. ps3fb_mode = (ps3fb_mode & ~PS3AV_MODE_MASK) | mode;
  489. if (ps3av_set_video_mode(ps3fb_mode, first))
  490. return -EINVAL;
  491. first = 0;
  492. return 0;
  493. }
  494. /*
  495. * Set a single color register. The values supplied are already
  496. * rounded down to the hardware's capabilities (according to the
  497. * entries in the var structure). Return != 0 for invalid regno.
  498. */
  499. static int ps3fb_setcolreg(unsigned int regno, unsigned int red,
  500. unsigned int green, unsigned int blue,
  501. unsigned int transp, struct fb_info *info)
  502. {
  503. if (regno >= 16)
  504. return 1;
  505. red >>= 8;
  506. green >>= 8;
  507. blue >>= 8;
  508. transp >>= 8;
  509. ((u32 *)info->pseudo_palette)[regno] = transp << 24 | red << 16 |
  510. green << 8 | blue;
  511. return 0;
  512. }
  513. /*
  514. * As we have a virtual frame buffer, we need our own mmap function
  515. */
  516. static int ps3fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
  517. {
  518. unsigned long size, offset;
  519. int i;
  520. i = ps3fb_get_res_table(info->var.xres, info->var.yres);
  521. if (i == -1)
  522. return -EINVAL;
  523. size = vma->vm_end - vma->vm_start;
  524. offset = vma->vm_pgoff << PAGE_SHIFT;
  525. if (offset + size > info->fix.smem_len)
  526. return -EINVAL;
  527. offset += info->fix.smem_start + FB_OFF(i) + VP_OFF(i);
  528. if (remap_pfn_range(vma, vma->vm_start, offset >> PAGE_SHIFT,
  529. size, vma->vm_page_prot))
  530. return -EAGAIN;
  531. printk(KERN_DEBUG "ps3fb: mmap framebuffer P(%lx)->V(%lx)\n", offset,
  532. vma->vm_start);
  533. return 0;
  534. }
  535. /*
  536. * Blank the display
  537. */
  538. static int ps3fb_blank(int blank, struct fb_info *info)
  539. {
  540. int retval;
  541. DPRINTK("%s: blank:%d\n", __FUNCTION__, blank);
  542. switch (blank) {
  543. case FB_BLANK_POWERDOWN:
  544. case FB_BLANK_HSYNC_SUSPEND:
  545. case FB_BLANK_VSYNC_SUSPEND:
  546. case FB_BLANK_NORMAL:
  547. retval = ps3av_video_mute(1); /* mute on */
  548. if (!retval)
  549. ps3fb.is_blanked = 1;
  550. break;
  551. default: /* unblank */
  552. retval = ps3av_video_mute(0); /* mute off */
  553. if (!retval)
  554. ps3fb.is_blanked = 0;
  555. break;
  556. }
  557. return retval;
  558. }
  559. static int ps3fb_get_vblank(struct fb_vblank *vblank)
  560. {
  561. memset(vblank, 0, sizeof(&vblank));
  562. vblank->flags = FB_VBLANK_HAVE_VSYNC;
  563. return 0;
  564. }
  565. int ps3fb_wait_for_vsync(u32 crtc)
  566. {
  567. int ret;
  568. u64 count;
  569. count = ps3fb.vblank_count;
  570. ret = wait_event_interruptible_timeout(ps3fb.wait_vsync,
  571. count != ps3fb.vblank_count,
  572. HZ / 10);
  573. if (!ret)
  574. return -ETIMEDOUT;
  575. return 0;
  576. }
  577. EXPORT_SYMBOL_GPL(ps3fb_wait_for_vsync);
  578. void ps3fb_flip_ctl(int on)
  579. {
  580. if (on) {
  581. if (atomic_read(&ps3fb.ext_flip) > 0) {
  582. atomic_dec(&ps3fb.ext_flip);
  583. }
  584. } else {
  585. atomic_inc(&ps3fb.ext_flip);
  586. }
  587. }
  588. EXPORT_SYMBOL_GPL(ps3fb_flip_ctl);
  589. /*
  590. * ioctl
  591. */
  592. static int ps3fb_ioctl(struct fb_info *info, unsigned int cmd,
  593. unsigned long arg)
  594. {
  595. void __user *argp = (void __user *)arg;
  596. u32 val, old_mode;
  597. int retval = -EFAULT;
  598. switch (cmd) {
  599. case FBIOGET_VBLANK:
  600. {
  601. struct fb_vblank vblank;
  602. DPRINTK("FBIOGET_VBLANK:\n");
  603. retval = ps3fb_get_vblank(&vblank);
  604. if (retval)
  605. break;
  606. if (copy_to_user(argp, &vblank, sizeof(vblank)))
  607. retval = -EFAULT;
  608. break;
  609. }
  610. case FBIO_WAITFORVSYNC:
  611. {
  612. u32 crt;
  613. DPRINTK("FBIO_WAITFORVSYNC:\n");
  614. if (get_user(crt, (u32 __user *) arg))
  615. break;
  616. retval = ps3fb_wait_for_vsync(crt);
  617. break;
  618. }
  619. case PS3FB_IOCTL_SETMODE:
  620. {
  621. const struct fb_videomode *mode;
  622. struct fb_var_screeninfo var;
  623. if (copy_from_user(&val, argp, sizeof(val)))
  624. break;
  625. DPRINTK("PS3FB_IOCTL_SETMODE:%x\n", val);
  626. retval = -EINVAL;
  627. old_mode = ps3fb_mode;
  628. ps3fb_mode = val;
  629. mode = ps3fb_default_mode();
  630. if (mode) {
  631. var = info->var;
  632. fb_videomode_to_var(&var, mode);
  633. acquire_console_sem();
  634. info->flags |= FBINFO_MISC_USEREVENT;
  635. /* Force, in case only special bits changed */
  636. var.activate |= FB_ACTIVATE_FORCE;
  637. retval = fb_set_var(info, &var);
  638. info->flags &= ~FBINFO_MISC_USEREVENT;
  639. release_console_sem();
  640. }
  641. if (retval)
  642. ps3fb_mode = old_mode;
  643. break;
  644. }
  645. case PS3FB_IOCTL_GETMODE:
  646. val = ps3av_get_mode();
  647. DPRINTK("PS3FB_IOCTL_GETMODE:%x\n", val);
  648. if (!copy_to_user(argp, &val, sizeof(val)))
  649. retval = 0;
  650. break;
  651. case PS3FB_IOCTL_SCREENINFO:
  652. {
  653. struct ps3fb_ioctl_res res;
  654. int i = ps3fb.res_index;
  655. DPRINTK("PS3FB_IOCTL_SCREENINFO:\n");
  656. res.xres = ps3fb_res[i].xres;
  657. res.yres = ps3fb_res[i].yres;
  658. res.xoff = ps3fb_res[i].xoff;
  659. res.yoff = ps3fb_res[i].yoff;
  660. res.num_frames = ps3fb.num_frames;
  661. if (!copy_to_user(argp, &res, sizeof(res)))
  662. retval = 0;
  663. break;
  664. }
  665. case PS3FB_IOCTL_ON:
  666. DPRINTK("PS3FB_IOCTL_ON:\n");
  667. atomic_inc(&ps3fb.ext_flip);
  668. retval = 0;
  669. break;
  670. case PS3FB_IOCTL_OFF:
  671. DPRINTK("PS3FB_IOCTL_OFF:\n");
  672. if (atomic_read(&ps3fb.ext_flip) > 0)
  673. atomic_dec(&ps3fb.ext_flip);
  674. retval = 0;
  675. break;
  676. case PS3FB_IOCTL_FSEL:
  677. if (copy_from_user(&val, argp, sizeof(val)))
  678. break;
  679. DPRINTK("PS3FB_IOCTL_FSEL:%d\n", val);
  680. retval = ps3fb_sync(val);
  681. break;
  682. default:
  683. retval = -ENOIOCTLCMD;
  684. break;
  685. }
  686. return retval;
  687. }
  688. static int ps3fbd(void *arg)
  689. {
  690. while (!kthread_should_stop()) {
  691. try_to_freeze();
  692. set_current_state(TASK_INTERRUPTIBLE);
  693. if (ps3fb.is_kicked) {
  694. ps3fb.is_kicked = 0;
  695. ps3fb_sync(0); /* single buffer */
  696. }
  697. schedule();
  698. }
  699. return 0;
  700. }
  701. static irqreturn_t ps3fb_vsync_interrupt(int irq, void *ptr)
  702. {
  703. u64 v1;
  704. int status;
  705. struct display_head *head = &ps3fb.dinfo->display_head[1];
  706. status = lv1_gpu_context_intr(ps3fb.context_handle, &v1);
  707. if (status) {
  708. printk(KERN_ERR "%s: lv1_gpu_context_intr failed: %d\n",
  709. __FUNCTION__, status);
  710. return IRQ_NONE;
  711. }
  712. if (v1 & (1 << GPU_INTR_STATUS_VSYNC_1)) {
  713. /* VSYNC */
  714. ps3fb.vblank_count = head->vblank_count;
  715. if (ps3fb.task && !ps3fb.is_blanked &&
  716. !atomic_read(&ps3fb.ext_flip)) {
  717. ps3fb.is_kicked = 1;
  718. wake_up_process(ps3fb.task);
  719. }
  720. wake_up_interruptible(&ps3fb.wait_vsync);
  721. }
  722. return IRQ_HANDLED;
  723. }
  724. #ifndef MODULE
  725. static int __init ps3fb_setup(char *options)
  726. {
  727. char *this_opt;
  728. int mode = 0;
  729. if (!options || !*options)
  730. return 0; /* no options */
  731. while ((this_opt = strsep(&options, ",")) != NULL) {
  732. if (!*this_opt)
  733. continue;
  734. if (!strncmp(this_opt, "mode:", 5))
  735. mode = simple_strtoul(this_opt + 5, NULL, 0);
  736. else
  737. mode_option = this_opt;
  738. }
  739. return mode;
  740. }
  741. #endif /* MODULE */
  742. /*
  743. * Initialisation
  744. */
  745. static void ps3fb_platform_release(struct device *device)
  746. {
  747. /* This is called when the reference count goes to zero. */
  748. }
  749. static int ps3fb_vsync_settings(struct gpu_driver_info *dinfo, void *dev)
  750. {
  751. int error;
  752. DPRINTK("version_driver:%x\n", dinfo->version_driver);
  753. DPRINTK("irq outlet:%x\n", dinfo->irq.irq_outlet);
  754. DPRINTK("version_gpu:%x memory_size:%x ch:%x core_freq:%d mem_freq:%d\n",
  755. dinfo->version_gpu, dinfo->memory_size, dinfo->hardware_channel,
  756. dinfo->nvcore_frequency/1000000, dinfo->memory_frequency/1000000);
  757. if (dinfo->version_driver != GPU_DRIVER_INFO_VERSION) {
  758. printk(KERN_ERR "%s: version_driver err:%x\n", __FUNCTION__,
  759. dinfo->version_driver);
  760. return -EINVAL;
  761. }
  762. ps3fb.dev = dev;
  763. error = ps3_alloc_irq(PS3_BINDING_CPU_ANY, dinfo->irq.irq_outlet,
  764. &ps3fb.irq_no);
  765. if (error) {
  766. printk(KERN_ERR "%s: ps3_alloc_irq failed %d\n", __FUNCTION__,
  767. error);
  768. return error;
  769. }
  770. error = request_irq(ps3fb.irq_no, ps3fb_vsync_interrupt, IRQF_DISABLED,
  771. "ps3fb vsync", ps3fb.dev);
  772. if (error) {
  773. printk(KERN_ERR "%s: request_irq failed %d\n", __FUNCTION__,
  774. error);
  775. ps3_free_irq(ps3fb.irq_no);
  776. return error;
  777. }
  778. dinfo->irq.mask = (1 << GPU_INTR_STATUS_VSYNC_1) |
  779. (1 << GPU_INTR_STATUS_FLIP_1);
  780. return 0;
  781. }
  782. static int ps3fb_xdr_settings(u64 xdr_lpar)
  783. {
  784. int status;
  785. status = lv1_gpu_context_iomap(ps3fb.context_handle, GPU_IOIF,
  786. xdr_lpar, ps3fb_videomemory.size, 0);
  787. if (status) {
  788. printk(KERN_ERR "%s: lv1_gpu_context_iomap failed: %d\n",
  789. __FUNCTION__, status);
  790. return -ENXIO;
  791. }
  792. DPRINTK("video:%p xdr_ea:%p ioif:%lx lpar:%lx phys:%lx size:%lx\n",
  793. ps3fb_videomemory.address, ps3fb.xdr_ea, GPU_IOIF, xdr_lpar,
  794. virt_to_abs(ps3fb.xdr_ea), ps3fb_videomemory.size);
  795. status = lv1_gpu_context_attribute(ps3fb.context_handle,
  796. L1GPU_CONTEXT_ATTRIBUTE_FB_SETUP,
  797. xdr_lpar, ps3fb_videomemory.size,
  798. GPU_IOIF, 0);
  799. if (status) {
  800. printk(KERN_ERR "%s: lv1_gpu_context_attribute FB_SETUP failed: %d\n",
  801. __FUNCTION__, status);
  802. return -ENXIO;
  803. }
  804. return 0;
  805. }
  806. static struct fb_ops ps3fb_ops = {
  807. .fb_open = ps3fb_open,
  808. .fb_release = ps3fb_release,
  809. .fb_check_var = ps3fb_check_var,
  810. .fb_set_par = ps3fb_set_par,
  811. .fb_setcolreg = ps3fb_setcolreg,
  812. .fb_fillrect = cfb_fillrect,
  813. .fb_copyarea = cfb_copyarea,
  814. .fb_imageblit = cfb_imageblit,
  815. .fb_mmap = ps3fb_mmap,
  816. .fb_blank = ps3fb_blank,
  817. .fb_ioctl = ps3fb_ioctl,
  818. .fb_compat_ioctl = ps3fb_ioctl
  819. };
  820. static struct fb_fix_screeninfo ps3fb_fix __initdata = {
  821. .id = "PS3 FB",
  822. .type = FB_TYPE_PACKED_PIXELS,
  823. .visual = FB_VISUAL_TRUECOLOR,
  824. .accel = FB_ACCEL_NONE,
  825. };
  826. static int __init ps3fb_probe(struct platform_device *dev)
  827. {
  828. struct fb_info *info;
  829. int retval = -ENOMEM;
  830. u64 ddr_lpar = 0;
  831. u64 lpar_dma_control = 0;
  832. u64 lpar_driver_info = 0;
  833. u64 lpar_reports = 0;
  834. u64 lpar_reports_size = 0;
  835. u64 xdr_lpar;
  836. int status;
  837. unsigned long offset;
  838. struct task_struct *task;
  839. /* get gpu context handle */
  840. status = lv1_gpu_memory_allocate(DDR_SIZE, 0, 0, 0, 0,
  841. &ps3fb.memory_handle, &ddr_lpar);
  842. if (status) {
  843. printk(KERN_ERR "%s: lv1_gpu_memory_allocate failed: %d\n",
  844. __FUNCTION__, status);
  845. goto err;
  846. }
  847. DPRINTK("ddr:lpar:0x%lx\n", ddr_lpar);
  848. status = lv1_gpu_context_allocate(ps3fb.memory_handle, 0,
  849. &ps3fb.context_handle,
  850. &lpar_dma_control, &lpar_driver_info,
  851. &lpar_reports, &lpar_reports_size);
  852. if (status) {
  853. printk(KERN_ERR "%s: lv1_gpu_context_attribute failed: %d\n",
  854. __FUNCTION__, status);
  855. goto err_gpu_memory_free;
  856. }
  857. /* vsync interrupt */
  858. ps3fb.dinfo = ioremap(lpar_driver_info, 128 * 1024);
  859. if (!ps3fb.dinfo) {
  860. printk(KERN_ERR "%s: ioremap failed\n", __FUNCTION__);
  861. goto err_gpu_context_free;
  862. }
  863. retval = ps3fb_vsync_settings(ps3fb.dinfo, dev);
  864. if (retval)
  865. goto err_iounmap_dinfo;
  866. /* xdr frame buffer */
  867. ps3fb.xdr_ea = ps3fb_videomemory.address;
  868. xdr_lpar = ps3_mm_phys_to_lpar(__pa(ps3fb.xdr_ea));
  869. retval = ps3fb_xdr_settings(xdr_lpar);
  870. if (retval)
  871. goto err_free_irq;
  872. /*
  873. * ps3fb must clear memory to prevent kernel info
  874. * leakage into userspace
  875. */
  876. memset(ps3fb.xdr_ea, 0, ps3fb_videomemory.size);
  877. info = framebuffer_alloc(sizeof(u32) * 16, &dev->dev);
  878. if (!info)
  879. goto err_free_irq;
  880. offset = FB_OFF(ps3fb.res_index) + VP_OFF(ps3fb.res_index);
  881. info->screen_base = (char __iomem *)ps3fb.xdr_ea + offset;
  882. info->fbops = &ps3fb_ops;
  883. info->fix = ps3fb_fix;
  884. info->fix.smem_start = virt_to_abs(ps3fb.xdr_ea);
  885. info->fix.smem_len = ps3fb_videomemory.size - offset;
  886. info->pseudo_palette = info->par;
  887. info->par = NULL;
  888. info->flags = FBINFO_FLAG_DEFAULT;
  889. retval = fb_alloc_cmap(&info->cmap, 256, 0);
  890. if (retval < 0)
  891. goto err_framebuffer_release;
  892. if (!fb_find_mode(&info->var, info, mode_option, ps3fb_modedb,
  893. ARRAY_SIZE(ps3fb_modedb), ps3fb_default_mode(), 32)) {
  894. retval = -EINVAL;
  895. goto err_fb_dealloc;
  896. }
  897. fb_videomode_to_modelist(ps3fb_modedb, ARRAY_SIZE(ps3fb_modedb),
  898. &info->modelist);
  899. retval = register_framebuffer(info);
  900. if (retval < 0)
  901. goto err_fb_dealloc;
  902. platform_set_drvdata(dev, info);
  903. printk(KERN_INFO
  904. "fb%d: PS3 frame buffer device, using %ld KiB of video memory\n",
  905. info->node, ps3fb_videomemory.size >> 10);
  906. task = kthread_run(ps3fbd, info, "ps3fbd");
  907. if (IS_ERR(task)) {
  908. retval = PTR_ERR(task);
  909. goto err_unregister_framebuffer;
  910. }
  911. ps3fb.task = task;
  912. return 0;
  913. err_unregister_framebuffer:
  914. unregister_framebuffer(info);
  915. err_fb_dealloc:
  916. fb_dealloc_cmap(&info->cmap);
  917. err_framebuffer_release:
  918. framebuffer_release(info);
  919. err_free_irq:
  920. free_irq(ps3fb.irq_no, ps3fb.dev);
  921. ps3_free_irq(ps3fb.irq_no);
  922. err_iounmap_dinfo:
  923. iounmap((u8 __iomem *)ps3fb.dinfo);
  924. err_gpu_context_free:
  925. lv1_gpu_context_free(ps3fb.context_handle);
  926. err_gpu_memory_free:
  927. lv1_gpu_memory_free(ps3fb.memory_handle);
  928. err:
  929. return retval;
  930. }
  931. static void ps3fb_shutdown(struct platform_device *dev)
  932. {
  933. ps3fb_flip_ctl(0); /* flip off */
  934. ps3fb.dinfo->irq.mask = 0;
  935. free_irq(ps3fb.irq_no, ps3fb.dev);
  936. ps3_free_irq(ps3fb.irq_no);
  937. iounmap((u8 __iomem *)ps3fb.dinfo);
  938. }
  939. void ps3fb_cleanup(void)
  940. {
  941. int status;
  942. if (ps3fb.task) {
  943. struct task_struct *task = ps3fb.task;
  944. ps3fb.task = NULL;
  945. kthread_stop(task);
  946. }
  947. if (ps3fb.irq_no) {
  948. free_irq(ps3fb.irq_no, ps3fb.dev);
  949. ps3_free_irq(ps3fb.irq_no);
  950. }
  951. iounmap((u8 __iomem *)ps3fb.dinfo);
  952. status = lv1_gpu_context_free(ps3fb.context_handle);
  953. if (status)
  954. DPRINTK("lv1_gpu_context_free failed: %d\n", status);
  955. status = lv1_gpu_memory_free(ps3fb.memory_handle);
  956. if (status)
  957. DPRINTK("lv1_gpu_memory_free failed: %d\n", status);
  958. ps3av_dev_close();
  959. }
  960. EXPORT_SYMBOL_GPL(ps3fb_cleanup);
  961. static int ps3fb_remove(struct platform_device *dev)
  962. {
  963. struct fb_info *info = platform_get_drvdata(dev);
  964. if (info) {
  965. unregister_framebuffer(info);
  966. fb_dealloc_cmap(&info->cmap);
  967. framebuffer_release(info);
  968. }
  969. ps3fb_cleanup();
  970. return 0;
  971. }
  972. static struct platform_driver ps3fb_driver = {
  973. .probe = ps3fb_probe,
  974. .remove = ps3fb_remove,
  975. .shutdown = ps3fb_shutdown,
  976. .driver = { .name = "ps3fb" }
  977. };
  978. static struct platform_device ps3fb_device = {
  979. .name = "ps3fb",
  980. .id = 0,
  981. .dev = { .release = ps3fb_platform_release }
  982. };
  983. int ps3fb_set_sync(void)
  984. {
  985. int status;
  986. #ifdef HEAD_A
  987. status = lv1_gpu_context_attribute(0x0,
  988. L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
  989. 0, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0);
  990. if (status) {
  991. printk(KERN_ERR "%s: lv1_gpu_context_attribute DISPLAY_SYNC failed: %d\n",
  992. __FUNCTION__, status);
  993. return -1;
  994. }
  995. #endif
  996. #ifdef HEAD_B
  997. status = lv1_gpu_context_attribute(0x0,
  998. L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
  999. 1, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0);
  1000. if (status) {
  1001. printk(KERN_ERR "%s: lv1_gpu_context_attribute DISPLAY_MODE failed: %d\n",
  1002. __FUNCTION__, status);
  1003. return -1;
  1004. }
  1005. #endif
  1006. return 0;
  1007. }
  1008. EXPORT_SYMBOL_GPL(ps3fb_set_sync);
  1009. static int __init ps3fb_init(void)
  1010. {
  1011. int error;
  1012. #ifndef MODULE
  1013. int mode;
  1014. char *option = NULL;
  1015. if (fb_get_options("ps3fb", &option))
  1016. goto err;
  1017. #endif
  1018. if (!ps3fb_videomemory.address)
  1019. goto err;
  1020. error = ps3av_dev_open();
  1021. if (error) {
  1022. printk(KERN_ERR "%s: ps3av_dev_open failed\n", __FUNCTION__);
  1023. goto err;
  1024. }
  1025. ps3fb_mode = ps3av_get_mode();
  1026. DPRINTK("ps3av_mode:%d\n", ps3fb_mode);
  1027. #ifndef MODULE
  1028. mode = ps3fb_setup(option); /* check boot option */
  1029. if (mode)
  1030. ps3fb_mode = mode;
  1031. #endif
  1032. if (ps3fb_mode > 0) {
  1033. u32 xres, yres;
  1034. ps3av_video_mode2res(ps3fb_mode, &xres, &yres);
  1035. ps3fb.res_index = ps3fb_get_res_table(xres, yres);
  1036. DPRINTK("res_index:%d\n", ps3fb.res_index);
  1037. } else
  1038. ps3fb.res_index = GPU_RES_INDEX;
  1039. atomic_set(&ps3fb.f_count, -1); /* fbcon opens ps3fb */
  1040. atomic_set(&ps3fb.ext_flip, 0); /* for flip with vsync */
  1041. init_waitqueue_head(&ps3fb.wait_vsync);
  1042. ps3fb.num_frames = 1;
  1043. error = platform_driver_register(&ps3fb_driver);
  1044. if (!error) {
  1045. error = platform_device_register(&ps3fb_device);
  1046. if (error)
  1047. platform_driver_unregister(&ps3fb_driver);
  1048. }
  1049. ps3fb_set_sync();
  1050. return error;
  1051. err:
  1052. return -ENXIO;
  1053. }
  1054. module_init(ps3fb_init);
  1055. #ifdef MODULE
  1056. static void __exit ps3fb_exit(void)
  1057. {
  1058. platform_device_unregister(&ps3fb_device);
  1059. platform_driver_unregister(&ps3fb_driver);
  1060. }
  1061. module_exit(ps3fb_exit);
  1062. MODULE_LICENSE("GPL");
  1063. #endif /* MODULE */