ps3fb.c 30 KB

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