ps3fb.c 30 KB

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