ps3fb.c 30 KB

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