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