ps3fb.c 29 KB

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