ps3fb.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259
  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, __func__ , ##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;
  266. module_param(ps3fb_mode, bool, 0);
  267. static char *mode_option __initdata;
  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. __func__, 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
  356. "%s: lv1_gpu_context_attribute FB_BLIT failed: %d\n",
  357. __func__, status);
  358. #ifdef HEAD_A
  359. status = lv1_gpu_context_attribute(ps3fb.context_handle,
  360. L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP,
  361. 0, offset, 0, 0);
  362. if (status)
  363. printk(KERN_ERR
  364. "%s: lv1_gpu_context_attribute FLIP failed: %d\n",
  365. __func__, status);
  366. #endif
  367. #ifdef HEAD_B
  368. status = lv1_gpu_context_attribute(ps3fb.context_handle,
  369. L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP,
  370. 1, offset, 0, 0);
  371. if (status)
  372. printk(KERN_ERR
  373. "%s: lv1_gpu_context_attribute FLIP failed: %d\n",
  374. __func__, status);
  375. #endif
  376. return 0;
  377. }
  378. static int ps3fb_open(struct fb_info *info, int user)
  379. {
  380. atomic_inc(&ps3fb.f_count);
  381. return 0;
  382. }
  383. static int ps3fb_release(struct fb_info *info, int user)
  384. {
  385. if (atomic_dec_and_test(&ps3fb.f_count)) {
  386. if (atomic_read(&ps3fb.ext_flip)) {
  387. atomic_set(&ps3fb.ext_flip, 0);
  388. ps3fb_sync(0); /* single buffer */
  389. }
  390. }
  391. return 0;
  392. }
  393. /*
  394. * Setting the video mode has been split into two parts.
  395. * First part, xxxfb_check_var, must not write anything
  396. * to hardware, it should only verify and adjust var.
  397. * This means it doesn't alter par but it does use hardware
  398. * data from it to check this var.
  399. */
  400. static int ps3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  401. {
  402. u32 line_length;
  403. int mode;
  404. int i;
  405. DPRINTK("var->xres:%u info->var.xres:%u\n", var->xres, info->var.xres);
  406. DPRINTK("var->yres:%u info->var.yres:%u\n", var->yres, info->var.yres);
  407. /* FIXME For now we do exact matches only */
  408. mode = ps3fb_find_mode(var, &line_length);
  409. if (!mode)
  410. return -EINVAL;
  411. /*
  412. * FB_VMODE_CONUPDATE and FB_VMODE_SMOOTH_XPAN are equal!
  413. * as FB_VMODE_SMOOTH_XPAN is only used internally
  414. */
  415. if (var->vmode & FB_VMODE_CONUPDATE) {
  416. var->vmode |= FB_VMODE_YWRAP;
  417. var->xoffset = info->var.xoffset;
  418. var->yoffset = info->var.yoffset;
  419. }
  420. /* Virtual screen and panning are not supported */
  421. if (var->xres_virtual > var->xres || var->yres_virtual > var->yres ||
  422. var->xoffset || var->yoffset) {
  423. DPRINTK("Virtual screen and panning are not supported\n");
  424. return -EINVAL;
  425. }
  426. var->xres_virtual = var->xres;
  427. var->yres_virtual = var->yres;
  428. /* We support ARGB8888 only */
  429. if (var->bits_per_pixel > 32 || var->grayscale ||
  430. var->red.offset > 16 || var->green.offset > 8 ||
  431. var->blue.offset > 0 || var->transp.offset > 24 ||
  432. var->red.length > 8 || var->green.length > 8 ||
  433. var->blue.length > 8 || var->transp.length > 8 ||
  434. var->red.msb_right || var->green.msb_right ||
  435. var->blue.msb_right || var->transp.msb_right || var->nonstd) {
  436. DPRINTK("We support ARGB8888 only\n");
  437. return -EINVAL;
  438. }
  439. var->bits_per_pixel = 32;
  440. var->red.offset = 16;
  441. var->green.offset = 8;
  442. var->blue.offset = 0;
  443. var->transp.offset = 24;
  444. var->red.length = 8;
  445. var->green.length = 8;
  446. var->blue.length = 8;
  447. var->transp.length = 8;
  448. var->red.msb_right = 0;
  449. var->green.msb_right = 0;
  450. var->blue.msb_right = 0;
  451. var->transp.msb_right = 0;
  452. /* Rotation is not supported */
  453. if (var->rotate) {
  454. DPRINTK("Rotation is not supported\n");
  455. return -EINVAL;
  456. }
  457. /* Memory limit */
  458. i = ps3fb_get_res_table(var->xres, var->yres);
  459. if (ps3fb_res[i].xres*ps3fb_res[i].yres*BPP > ps3fb_videomemory.size) {
  460. DPRINTK("Not enough memory\n");
  461. return -ENOMEM;
  462. }
  463. var->height = -1;
  464. var->width = -1;
  465. return 0;
  466. }
  467. /*
  468. * This routine actually sets the video mode.
  469. */
  470. static int ps3fb_set_par(struct fb_info *info)
  471. {
  472. unsigned int mode;
  473. int i;
  474. unsigned long offset;
  475. static int first = 1;
  476. DPRINTK("xres:%d xv:%d yres:%d yv:%d clock:%d\n",
  477. info->var.xres, info->var.xres_virtual,
  478. info->var.yres, info->var.yres_virtual, info->var.pixclock);
  479. i = ps3fb_get_res_table(info->var.xres, info->var.yres);
  480. ps3fb.res_index = i;
  481. mode = ps3fb_find_mode(&info->var, &info->fix.line_length);
  482. if (!mode)
  483. return -EINVAL;
  484. offset = FB_OFF(i) + VP_OFF(i);
  485. info->fix.smem_len = ps3fb_videomemory.size - offset;
  486. info->screen_base = (char __iomem *)ps3fb.xdr_ea + offset;
  487. memset(ps3fb.xdr_ea, 0, ps3fb_videomemory.size);
  488. ps3fb.num_frames = ps3fb_videomemory.size/
  489. (ps3fb_res[i].xres*ps3fb_res[i].yres*BPP);
  490. /* Keep the special bits we cannot set using fb_var_screeninfo */
  491. ps3fb_mode = (ps3fb_mode & ~PS3AV_MODE_MASK) | mode;
  492. if (ps3av_set_video_mode(ps3fb_mode, first))
  493. return -EINVAL;
  494. first = 0;
  495. return 0;
  496. }
  497. /*
  498. * Set a single color register. The values supplied are already
  499. * rounded down to the hardware's capabilities (according to the
  500. * entries in the var structure). Return != 0 for invalid regno.
  501. */
  502. static int ps3fb_setcolreg(unsigned int regno, unsigned int red,
  503. unsigned int green, unsigned int blue,
  504. unsigned int transp, struct fb_info *info)
  505. {
  506. if (regno >= 16)
  507. return 1;
  508. red >>= 8;
  509. green >>= 8;
  510. blue >>= 8;
  511. transp >>= 8;
  512. ((u32 *)info->pseudo_palette)[regno] = transp << 24 | red << 16 |
  513. green << 8 | blue;
  514. return 0;
  515. }
  516. /*
  517. * As we have a virtual frame buffer, we need our own mmap function
  518. */
  519. static int ps3fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
  520. {
  521. unsigned long size, offset;
  522. int i;
  523. i = ps3fb_get_res_table(info->var.xres, info->var.yres);
  524. if (i == -1)
  525. return -EINVAL;
  526. size = vma->vm_end - vma->vm_start;
  527. offset = vma->vm_pgoff << PAGE_SHIFT;
  528. if (offset + size > info->fix.smem_len)
  529. return -EINVAL;
  530. offset += info->fix.smem_start + FB_OFF(i) + VP_OFF(i);
  531. if (remap_pfn_range(vma, vma->vm_start, offset >> PAGE_SHIFT,
  532. size, vma->vm_page_prot))
  533. return -EAGAIN;
  534. printk(KERN_DEBUG "ps3fb: mmap framebuffer P(%lx)->V(%lx)\n", offset,
  535. vma->vm_start);
  536. return 0;
  537. }
  538. /*
  539. * Blank the display
  540. */
  541. static int ps3fb_blank(int blank, struct fb_info *info)
  542. {
  543. int retval;
  544. DPRINTK("%s: blank:%d\n", __func__, blank);
  545. switch (blank) {
  546. case FB_BLANK_POWERDOWN:
  547. case FB_BLANK_HSYNC_SUSPEND:
  548. case FB_BLANK_VSYNC_SUSPEND:
  549. case FB_BLANK_NORMAL:
  550. retval = ps3av_video_mute(1); /* mute on */
  551. if (!retval)
  552. ps3fb.is_blanked = 1;
  553. break;
  554. default: /* unblank */
  555. retval = ps3av_video_mute(0); /* mute off */
  556. if (!retval)
  557. ps3fb.is_blanked = 0;
  558. break;
  559. }
  560. return retval;
  561. }
  562. static int ps3fb_get_vblank(struct fb_vblank *vblank)
  563. {
  564. memset(vblank, 0, sizeof(&vblank));
  565. vblank->flags = FB_VBLANK_HAVE_VSYNC;
  566. return 0;
  567. }
  568. int ps3fb_wait_for_vsync(u32 crtc)
  569. {
  570. int ret;
  571. u64 count;
  572. count = ps3fb.vblank_count;
  573. ret = wait_event_interruptible_timeout(ps3fb.wait_vsync,
  574. count != ps3fb.vblank_count,
  575. HZ / 10);
  576. if (!ret)
  577. return -ETIMEDOUT;
  578. return 0;
  579. }
  580. EXPORT_SYMBOL_GPL(ps3fb_wait_for_vsync);
  581. void ps3fb_flip_ctl(int on)
  582. {
  583. if (on)
  584. atomic_dec_if_positive(&ps3fb.ext_flip);
  585. else
  586. atomic_inc(&ps3fb.ext_flip);
  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. if (!(val & PS3AV_MODE_MASK)) {
  626. u32 id = ps3av_get_auto_mode(0);
  627. if (id > 0)
  628. val = (val & ~PS3AV_MODE_MASK) | id;
  629. }
  630. DPRINTK("PS3FB_IOCTL_SETMODE:%x\n", val);
  631. retval = -EINVAL;
  632. old_mode = ps3fb_mode;
  633. ps3fb_mode = val;
  634. mode = ps3fb_default_mode();
  635. if (mode) {
  636. var = info->var;
  637. fb_videomode_to_var(&var, mode);
  638. acquire_console_sem();
  639. info->flags |= FBINFO_MISC_USEREVENT;
  640. /* Force, in case only special bits changed */
  641. var.activate |= FB_ACTIVATE_FORCE;
  642. retval = fb_set_var(info, &var);
  643. info->flags &= ~FBINFO_MISC_USEREVENT;
  644. release_console_sem();
  645. }
  646. if (retval)
  647. ps3fb_mode = old_mode;
  648. break;
  649. }
  650. case PS3FB_IOCTL_GETMODE:
  651. val = ps3av_get_mode();
  652. DPRINTK("PS3FB_IOCTL_GETMODE:%x\n", val);
  653. if (!copy_to_user(argp, &val, sizeof(val)))
  654. retval = 0;
  655. break;
  656. case PS3FB_IOCTL_SCREENINFO:
  657. {
  658. struct ps3fb_ioctl_res res;
  659. int i = ps3fb.res_index;
  660. DPRINTK("PS3FB_IOCTL_SCREENINFO:\n");
  661. res.xres = ps3fb_res[i].xres;
  662. res.yres = ps3fb_res[i].yres;
  663. res.xoff = ps3fb_res[i].xoff;
  664. res.yoff = ps3fb_res[i].yoff;
  665. res.num_frames = ps3fb.num_frames;
  666. if (!copy_to_user(argp, &res, sizeof(res)))
  667. retval = 0;
  668. break;
  669. }
  670. case PS3FB_IOCTL_ON:
  671. DPRINTK("PS3FB_IOCTL_ON:\n");
  672. atomic_inc(&ps3fb.ext_flip);
  673. retval = 0;
  674. break;
  675. case PS3FB_IOCTL_OFF:
  676. DPRINTK("PS3FB_IOCTL_OFF:\n");
  677. atomic_dec_if_positive(&ps3fb.ext_flip);
  678. retval = 0;
  679. break;
  680. case PS3FB_IOCTL_FSEL:
  681. if (copy_from_user(&val, argp, sizeof(val)))
  682. break;
  683. DPRINTK("PS3FB_IOCTL_FSEL:%d\n", val);
  684. retval = ps3fb_sync(val);
  685. break;
  686. default:
  687. retval = -ENOIOCTLCMD;
  688. break;
  689. }
  690. return retval;
  691. }
  692. static int ps3fbd(void *arg)
  693. {
  694. while (!kthread_should_stop()) {
  695. try_to_freeze();
  696. set_current_state(TASK_INTERRUPTIBLE);
  697. if (ps3fb.is_kicked) {
  698. ps3fb.is_kicked = 0;
  699. ps3fb_sync(0); /* single buffer */
  700. }
  701. schedule();
  702. }
  703. return 0;
  704. }
  705. static irqreturn_t ps3fb_vsync_interrupt(int irq, void *ptr)
  706. {
  707. u64 v1;
  708. int status;
  709. struct display_head *head = &ps3fb.dinfo->display_head[1];
  710. status = lv1_gpu_context_intr(ps3fb.context_handle, &v1);
  711. if (status) {
  712. printk(KERN_ERR "%s: lv1_gpu_context_intr failed: %d\n",
  713. __func__, status);
  714. return IRQ_NONE;
  715. }
  716. if (v1 & (1 << GPU_INTR_STATUS_VSYNC_1)) {
  717. /* VSYNC */
  718. ps3fb.vblank_count = head->vblank_count;
  719. if (ps3fb.task && !ps3fb.is_blanked &&
  720. !atomic_read(&ps3fb.ext_flip)) {
  721. ps3fb.is_kicked = 1;
  722. wake_up_process(ps3fb.task);
  723. }
  724. wake_up_interruptible(&ps3fb.wait_vsync);
  725. }
  726. return IRQ_HANDLED;
  727. }
  728. #ifndef MODULE
  729. static int __init ps3fb_setup(char *options)
  730. {
  731. char *this_opt;
  732. int mode = 0;
  733. if (!options || !*options)
  734. return 0; /* no options */
  735. while ((this_opt = strsep(&options, ",")) != NULL) {
  736. if (!*this_opt)
  737. continue;
  738. if (!strncmp(this_opt, "mode:", 5))
  739. mode = simple_strtoul(this_opt + 5, NULL, 0);
  740. else
  741. mode_option = this_opt;
  742. }
  743. return mode;
  744. }
  745. #endif /* MODULE */
  746. /*
  747. * Initialisation
  748. */
  749. static void ps3fb_platform_release(struct device *device)
  750. {
  751. /* This is called when the reference count goes to zero. */
  752. }
  753. static int ps3fb_vsync_settings(struct gpu_driver_info *dinfo, void *dev)
  754. {
  755. int error;
  756. DPRINTK("version_driver:%x\n", dinfo->version_driver);
  757. DPRINTK("irq outlet:%x\n", dinfo->irq.irq_outlet);
  758. DPRINTK("version_gpu:%x memory_size:%x ch:%x core_freq:%d mem_freq:%d\n",
  759. dinfo->version_gpu, dinfo->memory_size, dinfo->hardware_channel,
  760. dinfo->nvcore_frequency/1000000, dinfo->memory_frequency/1000000);
  761. if (dinfo->version_driver != GPU_DRIVER_INFO_VERSION) {
  762. printk(KERN_ERR "%s: version_driver err:%x\n", __func__,
  763. dinfo->version_driver);
  764. return -EINVAL;
  765. }
  766. ps3fb.dev = dev;
  767. error = ps3_irq_plug_setup(PS3_BINDING_CPU_ANY, dinfo->irq.irq_outlet,
  768. &ps3fb.irq_no);
  769. if (error) {
  770. printk(KERN_ERR "%s: ps3_alloc_irq failed %d\n", __func__,
  771. error);
  772. return error;
  773. }
  774. error = request_irq(ps3fb.irq_no, ps3fb_vsync_interrupt, IRQF_DISABLED,
  775. "ps3fb vsync", ps3fb.dev);
  776. if (error) {
  777. printk(KERN_ERR "%s: request_irq failed %d\n", __func__,
  778. error);
  779. ps3_irq_plug_destroy(ps3fb.irq_no);
  780. return error;
  781. }
  782. dinfo->irq.mask = (1 << GPU_INTR_STATUS_VSYNC_1) |
  783. (1 << GPU_INTR_STATUS_FLIP_1);
  784. return 0;
  785. }
  786. static int ps3fb_xdr_settings(u64 xdr_lpar)
  787. {
  788. int status;
  789. status = lv1_gpu_context_iomap(ps3fb.context_handle, GPU_IOIF,
  790. xdr_lpar, ps3fb_videomemory.size, 0);
  791. if (status) {
  792. printk(KERN_ERR "%s: lv1_gpu_context_iomap failed: %d\n",
  793. __func__, status);
  794. return -ENXIO;
  795. }
  796. DPRINTK("video:%p xdr_ea:%p ioif:%lx lpar:%lx phys:%lx size:%lx\n",
  797. ps3fb_videomemory.address, ps3fb.xdr_ea, GPU_IOIF, xdr_lpar,
  798. virt_to_abs(ps3fb.xdr_ea), ps3fb_videomemory.size);
  799. status = lv1_gpu_context_attribute(ps3fb.context_handle,
  800. L1GPU_CONTEXT_ATTRIBUTE_FB_SETUP,
  801. xdr_lpar, ps3fb_videomemory.size,
  802. GPU_IOIF, 0);
  803. if (status) {
  804. printk(KERN_ERR
  805. "%s: lv1_gpu_context_attribute FB_SETUP failed: %d\n",
  806. __func__, status);
  807. return -ENXIO;
  808. }
  809. return 0;
  810. }
  811. static struct fb_ops ps3fb_ops = {
  812. .fb_open = ps3fb_open,
  813. .fb_release = ps3fb_release,
  814. .fb_check_var = ps3fb_check_var,
  815. .fb_set_par = ps3fb_set_par,
  816. .fb_setcolreg = ps3fb_setcolreg,
  817. .fb_fillrect = cfb_fillrect,
  818. .fb_copyarea = cfb_copyarea,
  819. .fb_imageblit = cfb_imageblit,
  820. .fb_mmap = ps3fb_mmap,
  821. .fb_blank = ps3fb_blank,
  822. .fb_ioctl = ps3fb_ioctl,
  823. .fb_compat_ioctl = ps3fb_ioctl
  824. };
  825. static struct fb_fix_screeninfo ps3fb_fix __initdata = {
  826. .id = "PS3 FB",
  827. .type = FB_TYPE_PACKED_PIXELS,
  828. .visual = FB_VISUAL_TRUECOLOR,
  829. .accel = FB_ACCEL_NONE,
  830. };
  831. static int __init ps3fb_probe(struct platform_device *dev)
  832. {
  833. struct fb_info *info;
  834. int retval = -ENOMEM;
  835. u64 ddr_lpar = 0;
  836. u64 lpar_dma_control = 0;
  837. u64 lpar_driver_info = 0;
  838. u64 lpar_reports = 0;
  839. u64 lpar_reports_size = 0;
  840. u64 xdr_lpar;
  841. int status;
  842. unsigned long offset;
  843. struct task_struct *task;
  844. /* get gpu context handle */
  845. status = lv1_gpu_memory_allocate(DDR_SIZE, 0, 0, 0, 0,
  846. &ps3fb.memory_handle, &ddr_lpar);
  847. if (status) {
  848. printk(KERN_ERR "%s: lv1_gpu_memory_allocate failed: %d\n",
  849. __func__, status);
  850. goto err;
  851. }
  852. DPRINTK("ddr:lpar:0x%lx\n", ddr_lpar);
  853. status = lv1_gpu_context_allocate(ps3fb.memory_handle, 0,
  854. &ps3fb.context_handle,
  855. &lpar_dma_control, &lpar_driver_info,
  856. &lpar_reports, &lpar_reports_size);
  857. if (status) {
  858. printk(KERN_ERR "%s: lv1_gpu_context_attribute failed: %d\n",
  859. __func__, status);
  860. goto err_gpu_memory_free;
  861. }
  862. /* vsync interrupt */
  863. ps3fb.dinfo = ioremap(lpar_driver_info, 128 * 1024);
  864. if (!ps3fb.dinfo) {
  865. printk(KERN_ERR "%s: ioremap failed\n", __func__);
  866. goto err_gpu_context_free;
  867. }
  868. retval = ps3fb_vsync_settings(ps3fb.dinfo, dev);
  869. if (retval)
  870. goto err_iounmap_dinfo;
  871. /* xdr frame buffer */
  872. ps3fb.xdr_ea = ps3fb_videomemory.address;
  873. xdr_lpar = ps3_mm_phys_to_lpar(__pa(ps3fb.xdr_ea));
  874. retval = ps3fb_xdr_settings(xdr_lpar);
  875. if (retval)
  876. goto err_free_irq;
  877. /*
  878. * ps3fb must clear memory to prevent kernel info
  879. * leakage into userspace
  880. */
  881. memset(ps3fb.xdr_ea, 0, ps3fb_videomemory.size);
  882. info = framebuffer_alloc(sizeof(u32) * 16, &dev->dev);
  883. if (!info)
  884. goto err_free_irq;
  885. offset = FB_OFF(ps3fb.res_index) + VP_OFF(ps3fb.res_index);
  886. info->screen_base = (char __iomem *)ps3fb.xdr_ea + offset;
  887. info->fbops = &ps3fb_ops;
  888. info->fix = ps3fb_fix;
  889. info->fix.smem_start = virt_to_abs(ps3fb.xdr_ea);
  890. info->fix.smem_len = ps3fb_videomemory.size - offset;
  891. info->pseudo_palette = info->par;
  892. info->par = NULL;
  893. info->flags = FBINFO_FLAG_DEFAULT;
  894. retval = fb_alloc_cmap(&info->cmap, 256, 0);
  895. if (retval < 0)
  896. goto err_framebuffer_release;
  897. if (!fb_find_mode(&info->var, info, mode_option, ps3fb_modedb,
  898. ARRAY_SIZE(ps3fb_modedb), ps3fb_default_mode(), 32)) {
  899. retval = -EINVAL;
  900. goto err_fb_dealloc;
  901. }
  902. fb_videomode_to_modelist(ps3fb_modedb, ARRAY_SIZE(ps3fb_modedb),
  903. &info->modelist);
  904. retval = register_framebuffer(info);
  905. if (retval < 0)
  906. goto err_fb_dealloc;
  907. platform_set_drvdata(dev, info);
  908. printk(KERN_INFO
  909. "fb%d: PS3 frame buffer device, using %ld KiB of video memory\n",
  910. info->node, ps3fb_videomemory.size >> 10);
  911. task = kthread_run(ps3fbd, info, "ps3fbd");
  912. if (IS_ERR(task)) {
  913. retval = PTR_ERR(task);
  914. goto err_unregister_framebuffer;
  915. }
  916. ps3fb.task = task;
  917. return 0;
  918. err_unregister_framebuffer:
  919. unregister_framebuffer(info);
  920. err_fb_dealloc:
  921. fb_dealloc_cmap(&info->cmap);
  922. err_framebuffer_release:
  923. framebuffer_release(info);
  924. err_free_irq:
  925. free_irq(ps3fb.irq_no, ps3fb.dev);
  926. ps3_irq_plug_destroy(ps3fb.irq_no);
  927. err_iounmap_dinfo:
  928. iounmap((u8 __iomem *)ps3fb.dinfo);
  929. err_gpu_context_free:
  930. lv1_gpu_context_free(ps3fb.context_handle);
  931. err_gpu_memory_free:
  932. lv1_gpu_memory_free(ps3fb.memory_handle);
  933. err:
  934. return retval;
  935. }
  936. static void ps3fb_shutdown(struct platform_device *dev)
  937. {
  938. ps3fb_flip_ctl(0); /* flip off */
  939. ps3fb.dinfo->irq.mask = 0;
  940. free_irq(ps3fb.irq_no, ps3fb.dev);
  941. ps3_irq_plug_destroy(ps3fb.irq_no);
  942. iounmap((u8 __iomem *)ps3fb.dinfo);
  943. }
  944. void ps3fb_cleanup(void)
  945. {
  946. int status;
  947. if (ps3fb.task) {
  948. struct task_struct *task = ps3fb.task;
  949. ps3fb.task = NULL;
  950. kthread_stop(task);
  951. }
  952. if (ps3fb.irq_no) {
  953. free_irq(ps3fb.irq_no, ps3fb.dev);
  954. ps3_irq_plug_destroy(ps3fb.irq_no);
  955. }
  956. iounmap((u8 __iomem *)ps3fb.dinfo);
  957. status = lv1_gpu_context_free(ps3fb.context_handle);
  958. if (status)
  959. DPRINTK("lv1_gpu_context_free failed: %d\n", status);
  960. status = lv1_gpu_memory_free(ps3fb.memory_handle);
  961. if (status)
  962. DPRINTK("lv1_gpu_memory_free failed: %d\n", status);
  963. ps3av_dev_close();
  964. }
  965. EXPORT_SYMBOL_GPL(ps3fb_cleanup);
  966. static int ps3fb_remove(struct platform_device *dev)
  967. {
  968. struct fb_info *info = platform_get_drvdata(dev);
  969. if (info) {
  970. unregister_framebuffer(info);
  971. fb_dealloc_cmap(&info->cmap);
  972. framebuffer_release(info);
  973. }
  974. ps3fb_cleanup();
  975. return 0;
  976. }
  977. static struct platform_driver ps3fb_driver = {
  978. .probe = ps3fb_probe,
  979. .remove = ps3fb_remove,
  980. .shutdown = ps3fb_shutdown,
  981. .driver = { .name = "ps3fb" }
  982. };
  983. static struct platform_device ps3fb_device = {
  984. .name = "ps3fb",
  985. .id = 0,
  986. .dev = { .release = ps3fb_platform_release }
  987. };
  988. int ps3fb_set_sync(void)
  989. {
  990. int status;
  991. #ifdef HEAD_A
  992. status = lv1_gpu_context_attribute(0x0,
  993. L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
  994. 0, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0);
  995. if (status) {
  996. printk(KERN_ERR
  997. "%s: lv1_gpu_context_attribute DISPLAY_SYNC failed: %d\n",
  998. __func__, status);
  999. return -1;
  1000. }
  1001. #endif
  1002. #ifdef HEAD_B
  1003. status = lv1_gpu_context_attribute(0x0,
  1004. L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
  1005. 1, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0);
  1006. if (status) {
  1007. printk(KERN_ERR
  1008. "%s: lv1_gpu_context_attribute DISPLAY_MODE failed: %d\n",
  1009. __func__, status);
  1010. return -1;
  1011. }
  1012. #endif
  1013. return 0;
  1014. }
  1015. EXPORT_SYMBOL_GPL(ps3fb_set_sync);
  1016. static int __init ps3fb_init(void)
  1017. {
  1018. int error;
  1019. #ifndef MODULE
  1020. int mode;
  1021. char *option = NULL;
  1022. if (fb_get_options("ps3fb", &option))
  1023. goto err;
  1024. #endif
  1025. if (!ps3fb_videomemory.address)
  1026. goto err;
  1027. error = ps3av_dev_open();
  1028. if (error) {
  1029. printk(KERN_ERR "%s: ps3av_dev_open failed\n", __func__);
  1030. goto err;
  1031. }
  1032. ps3fb_mode = ps3av_get_mode();
  1033. DPRINTK("ps3av_mode:%d\n", ps3fb_mode);
  1034. #ifndef MODULE
  1035. mode = ps3fb_setup(option); /* check boot option */
  1036. if (mode)
  1037. ps3fb_mode = mode;
  1038. #endif
  1039. if (ps3fb_mode > 0) {
  1040. u32 xres, yres;
  1041. ps3av_video_mode2res(ps3fb_mode, &xres, &yres);
  1042. ps3fb.res_index = ps3fb_get_res_table(xres, yres);
  1043. DPRINTK("res_index:%d\n", ps3fb.res_index);
  1044. } else
  1045. ps3fb.res_index = GPU_RES_INDEX;
  1046. atomic_set(&ps3fb.f_count, -1); /* fbcon opens ps3fb */
  1047. atomic_set(&ps3fb.ext_flip, 0); /* for flip with vsync */
  1048. init_waitqueue_head(&ps3fb.wait_vsync);
  1049. ps3fb.num_frames = 1;
  1050. error = platform_driver_register(&ps3fb_driver);
  1051. if (!error) {
  1052. error = platform_device_register(&ps3fb_device);
  1053. if (error)
  1054. platform_driver_unregister(&ps3fb_driver);
  1055. }
  1056. ps3fb_set_sync();
  1057. return error;
  1058. err:
  1059. return -ENXIO;
  1060. }
  1061. module_init(ps3fb_init);
  1062. #ifdef MODULE
  1063. static void __exit ps3fb_exit(void)
  1064. {
  1065. platform_device_unregister(&ps3fb_device);
  1066. platform_driver_unregister(&ps3fb_driver);
  1067. }
  1068. module_exit(ps3fb_exit);
  1069. MODULE_LICENSE("GPL");
  1070. #endif /* MODULE */