omapfb_main.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942
  1. /*
  2. * Framebuffer driver for TI OMAP boards
  3. *
  4. * Copyright (C) 2004 Nokia Corporation
  5. * Author: Imre Deak <imre.deak@nokia.com>
  6. *
  7. * Acknowledgements:
  8. * Alex McMains <aam@ridgerun.com> - Original driver
  9. * Juha Yrjola <juha.yrjola@nokia.com> - Original driver and improvements
  10. * Dirk Behme <dirk.behme@de.bosch.com> - changes for 2.6 kernel API
  11. * Texas Instruments - H3 support
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the
  15. * Free Software Foundation; either version 2 of the License, or (at your
  16. * option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful, but
  19. * WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. * General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License along
  24. * with this program; if not, write to the Free Software Foundation, Inc.,
  25. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  26. */
  27. #include <linux/platform_device.h>
  28. #include <linux/mm.h>
  29. #include <linux/uaccess.h>
  30. #include <asm/mach-types.h>
  31. #include <asm/arch/dma.h>
  32. #include <asm/arch/omapfb.h>
  33. #define MODULE_NAME "omapfb"
  34. static unsigned int def_accel;
  35. static unsigned long def_vram[OMAPFB_PLANE_NUM];
  36. static int def_vram_cnt;
  37. static unsigned long def_vxres;
  38. static unsigned long def_vyres;
  39. static unsigned int def_rotate;
  40. static unsigned int def_mirror;
  41. #ifdef CONFIG_FB_OMAP_MANUAL_UPDATE
  42. static int manual_update = 1;
  43. #else
  44. static int manual_update;
  45. #endif
  46. static struct platform_device *fbdev_pdev;
  47. static struct lcd_panel *fbdev_panel;
  48. static struct omapfb_device *omapfb_dev;
  49. struct caps_table_struct {
  50. unsigned long flag;
  51. const char *name;
  52. };
  53. static struct caps_table_struct ctrl_caps[] = {
  54. { OMAPFB_CAPS_MANUAL_UPDATE, "manual update" },
  55. { OMAPFB_CAPS_TEARSYNC, "tearing synchronization" },
  56. { OMAPFB_CAPS_PLANE_RELOCATE_MEM, "relocate plane memory" },
  57. { OMAPFB_CAPS_PLANE_SCALE, "scale plane" },
  58. { OMAPFB_CAPS_WINDOW_PIXEL_DOUBLE, "pixel double window" },
  59. { OMAPFB_CAPS_WINDOW_SCALE, "scale window" },
  60. { OMAPFB_CAPS_WINDOW_OVERLAY, "overlay window" },
  61. { OMAPFB_CAPS_SET_BACKLIGHT, "backlight setting" },
  62. };
  63. static struct caps_table_struct color_caps[] = {
  64. { 1 << OMAPFB_COLOR_RGB565, "RGB565", },
  65. { 1 << OMAPFB_COLOR_YUV422, "YUV422", },
  66. { 1 << OMAPFB_COLOR_YUV420, "YUV420", },
  67. { 1 << OMAPFB_COLOR_CLUT_8BPP, "CLUT8", },
  68. { 1 << OMAPFB_COLOR_CLUT_4BPP, "CLUT4", },
  69. { 1 << OMAPFB_COLOR_CLUT_2BPP, "CLUT2", },
  70. { 1 << OMAPFB_COLOR_CLUT_1BPP, "CLUT1", },
  71. { 1 << OMAPFB_COLOR_RGB444, "RGB444", },
  72. { 1 << OMAPFB_COLOR_YUY422, "YUY422", },
  73. };
  74. /*
  75. * ---------------------------------------------------------------------------
  76. * LCD panel
  77. * ---------------------------------------------------------------------------
  78. */
  79. extern struct lcd_ctrl omap1_int_ctrl;
  80. extern struct lcd_ctrl omap2_int_ctrl;
  81. extern struct lcd_ctrl hwa742_ctrl;
  82. extern struct lcd_ctrl blizzard_ctrl;
  83. static struct lcd_ctrl *ctrls[] = {
  84. #ifdef CONFIG_ARCH_OMAP1
  85. &omap1_int_ctrl,
  86. #else
  87. &omap2_int_ctrl,
  88. #endif
  89. #ifdef CONFIG_FB_OMAP_LCDC_HWA742
  90. &hwa742_ctrl,
  91. #endif
  92. #ifdef CONFIG_FB_OMAP_LCDC_BLIZZARD
  93. &blizzard_ctrl,
  94. #endif
  95. };
  96. #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
  97. #ifdef CONFIG_ARCH_OMAP1
  98. extern struct lcd_ctrl_extif omap1_ext_if;
  99. #else
  100. extern struct lcd_ctrl_extif omap2_ext_if;
  101. #endif
  102. #endif
  103. static void omapfb_rqueue_lock(struct omapfb_device *fbdev)
  104. {
  105. mutex_lock(&fbdev->rqueue_mutex);
  106. }
  107. static void omapfb_rqueue_unlock(struct omapfb_device *fbdev)
  108. {
  109. mutex_unlock(&fbdev->rqueue_mutex);
  110. }
  111. /*
  112. * ---------------------------------------------------------------------------
  113. * LCD controller and LCD DMA
  114. * ---------------------------------------------------------------------------
  115. */
  116. /* Lookup table to map elem size to elem type. */
  117. static const int dma_elem_type[] = {
  118. 0,
  119. OMAP_DMA_DATA_TYPE_S8,
  120. OMAP_DMA_DATA_TYPE_S16,
  121. 0,
  122. OMAP_DMA_DATA_TYPE_S32,
  123. };
  124. /*
  125. * Allocate resources needed for LCD controller and LCD DMA operations. Video
  126. * memory is allocated from system memory according to the virtual display
  127. * size, except if a bigger memory size is specified explicitly as a kernel
  128. * parameter.
  129. */
  130. static int ctrl_init(struct omapfb_device *fbdev)
  131. {
  132. int r;
  133. int i;
  134. /* kernel/module vram parameters override boot tags/board config */
  135. if (def_vram_cnt) {
  136. for (i = 0; i < def_vram_cnt; i++)
  137. fbdev->mem_desc.region[i].size =
  138. PAGE_ALIGN(def_vram[i]);
  139. fbdev->mem_desc.region_cnt = i;
  140. } else {
  141. struct omapfb_platform_data *conf;
  142. conf = fbdev->dev->platform_data;
  143. fbdev->mem_desc = conf->mem_desc;
  144. }
  145. if (!fbdev->mem_desc.region_cnt) {
  146. struct lcd_panel *panel = fbdev->panel;
  147. int def_size;
  148. int bpp = panel->bpp;
  149. /* 12 bpp is packed in 16 bits */
  150. if (bpp == 12)
  151. bpp = 16;
  152. def_size = def_vxres * def_vyres * bpp / 8;
  153. fbdev->mem_desc.region_cnt = 1;
  154. fbdev->mem_desc.region[0].size = PAGE_ALIGN(def_size);
  155. }
  156. r = fbdev->ctrl->init(fbdev, 0, &fbdev->mem_desc);
  157. if (r < 0) {
  158. dev_err(fbdev->dev, "controller initialization failed (%d)\n",
  159. r);
  160. return r;
  161. }
  162. #ifdef DEBUG
  163. for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
  164. dev_dbg(fbdev->dev, "region%d phys %08x virt %p size=%lu\n",
  165. i,
  166. fbdev->mem_desc.region[i].paddr,
  167. fbdev->mem_desc.region[i].vaddr,
  168. fbdev->mem_desc.region[i].size);
  169. }
  170. #endif
  171. return 0;
  172. }
  173. static void ctrl_cleanup(struct omapfb_device *fbdev)
  174. {
  175. fbdev->ctrl->cleanup();
  176. }
  177. /* Must be called with fbdev->rqueue_mutex held. */
  178. static int ctrl_change_mode(struct fb_info *fbi)
  179. {
  180. int r;
  181. unsigned long offset;
  182. struct omapfb_plane_struct *plane = fbi->par;
  183. struct omapfb_device *fbdev = plane->fbdev;
  184. struct fb_var_screeninfo *var = &fbi->var;
  185. offset = var->yoffset * fbi->fix.line_length +
  186. var->xoffset * var->bits_per_pixel / 8;
  187. if (fbdev->ctrl->sync)
  188. fbdev->ctrl->sync();
  189. r = fbdev->ctrl->setup_plane(plane->idx, plane->info.channel_out,
  190. offset, var->xres_virtual,
  191. plane->info.pos_x, plane->info.pos_y,
  192. var->xres, var->yres, plane->color_mode);
  193. if (fbdev->ctrl->set_scale != NULL)
  194. r = fbdev->ctrl->set_scale(plane->idx,
  195. var->xres, var->yres,
  196. plane->info.out_width,
  197. plane->info.out_height);
  198. return r;
  199. }
  200. /*
  201. * ---------------------------------------------------------------------------
  202. * fbdev framework callbacks and the ioctl interface
  203. * ---------------------------------------------------------------------------
  204. */
  205. /* Called each time the omapfb device is opened */
  206. static int omapfb_open(struct fb_info *info, int user)
  207. {
  208. return 0;
  209. }
  210. static void omapfb_sync(struct fb_info *info);
  211. /* Called when the omapfb device is closed. We make sure that any pending
  212. * gfx DMA operations are ended, before we return. */
  213. static int omapfb_release(struct fb_info *info, int user)
  214. {
  215. omapfb_sync(info);
  216. return 0;
  217. }
  218. /* Store a single color palette entry into a pseudo palette or the hardware
  219. * palette if one is available. For now we support only 16bpp and thus store
  220. * the entry only to the pseudo palette.
  221. */
  222. static int _setcolreg(struct fb_info *info, u_int regno, u_int red, u_int green,
  223. u_int blue, u_int transp, int update_hw_pal)
  224. {
  225. struct omapfb_plane_struct *plane = info->par;
  226. struct omapfb_device *fbdev = plane->fbdev;
  227. struct fb_var_screeninfo *var = &info->var;
  228. int r = 0;
  229. switch (plane->color_mode) {
  230. case OMAPFB_COLOR_YUV422:
  231. case OMAPFB_COLOR_YUV420:
  232. case OMAPFB_COLOR_YUY422:
  233. r = -EINVAL;
  234. break;
  235. case OMAPFB_COLOR_CLUT_8BPP:
  236. case OMAPFB_COLOR_CLUT_4BPP:
  237. case OMAPFB_COLOR_CLUT_2BPP:
  238. case OMAPFB_COLOR_CLUT_1BPP:
  239. if (fbdev->ctrl->setcolreg)
  240. r = fbdev->ctrl->setcolreg(regno, red, green, blue,
  241. transp, update_hw_pal);
  242. /* Fallthrough */
  243. case OMAPFB_COLOR_RGB565:
  244. case OMAPFB_COLOR_RGB444:
  245. if (r != 0)
  246. break;
  247. if (regno < 0) {
  248. r = -EINVAL;
  249. break;
  250. }
  251. if (regno < 16) {
  252. u16 pal;
  253. pal = ((red >> (16 - var->red.length)) <<
  254. var->red.offset) |
  255. ((green >> (16 - var->green.length)) <<
  256. var->green.offset) |
  257. (blue >> (16 - var->blue.length));
  258. ((u32 *)(info->pseudo_palette))[regno] = pal;
  259. }
  260. break;
  261. default:
  262. BUG();
  263. }
  264. return r;
  265. }
  266. static int omapfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  267. u_int transp, struct fb_info *info)
  268. {
  269. return _setcolreg(info, regno, red, green, blue, transp, 1);
  270. }
  271. static int omapfb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
  272. {
  273. int count, index, r;
  274. u16 *red, *green, *blue, *transp;
  275. u16 trans = 0xffff;
  276. red = cmap->red;
  277. green = cmap->green;
  278. blue = cmap->blue;
  279. transp = cmap->transp;
  280. index = cmap->start;
  281. for (count = 0; count < cmap->len; count++) {
  282. if (transp)
  283. trans = *transp++;
  284. r = _setcolreg(info, index++, *red++, *green++, *blue++, trans,
  285. count == cmap->len - 1);
  286. if (r != 0)
  287. return r;
  288. }
  289. return 0;
  290. }
  291. static int omapfb_update_full_screen(struct fb_info *fbi);
  292. static int omapfb_blank(int blank, struct fb_info *fbi)
  293. {
  294. struct omapfb_plane_struct *plane = fbi->par;
  295. struct omapfb_device *fbdev = plane->fbdev;
  296. int do_update = 0;
  297. int r = 0;
  298. omapfb_rqueue_lock(fbdev);
  299. switch (blank) {
  300. case VESA_NO_BLANKING:
  301. if (fbdev->state == OMAPFB_SUSPENDED) {
  302. if (fbdev->ctrl->resume)
  303. fbdev->ctrl->resume();
  304. fbdev->panel->enable(fbdev->panel);
  305. fbdev->state = OMAPFB_ACTIVE;
  306. if (fbdev->ctrl->get_update_mode() ==
  307. OMAPFB_MANUAL_UPDATE)
  308. do_update = 1;
  309. }
  310. break;
  311. case VESA_POWERDOWN:
  312. if (fbdev->state == OMAPFB_ACTIVE) {
  313. fbdev->panel->disable(fbdev->panel);
  314. if (fbdev->ctrl->suspend)
  315. fbdev->ctrl->suspend();
  316. fbdev->state = OMAPFB_SUSPENDED;
  317. }
  318. break;
  319. default:
  320. r = -EINVAL;
  321. }
  322. omapfb_rqueue_unlock(fbdev);
  323. if (r == 0 && do_update)
  324. r = omapfb_update_full_screen(fbi);
  325. return r;
  326. }
  327. static void omapfb_sync(struct fb_info *fbi)
  328. {
  329. struct omapfb_plane_struct *plane = fbi->par;
  330. struct omapfb_device *fbdev = plane->fbdev;
  331. omapfb_rqueue_lock(fbdev);
  332. if (fbdev->ctrl->sync)
  333. fbdev->ctrl->sync();
  334. omapfb_rqueue_unlock(fbdev);
  335. }
  336. /*
  337. * Set fb_info.fix fields and also updates fbdev.
  338. * When calling this fb_info.var must be set up already.
  339. */
  340. static void set_fb_fix(struct fb_info *fbi)
  341. {
  342. struct fb_fix_screeninfo *fix = &fbi->fix;
  343. struct fb_var_screeninfo *var = &fbi->var;
  344. struct omapfb_plane_struct *plane = fbi->par;
  345. struct omapfb_mem_region *rg;
  346. int bpp;
  347. rg = &plane->fbdev->mem_desc.region[plane->idx];
  348. fbi->screen_base = (char __iomem *)rg->vaddr;
  349. fix->smem_start = rg->paddr;
  350. fix->smem_len = rg->size;
  351. fix->type = FB_TYPE_PACKED_PIXELS;
  352. bpp = var->bits_per_pixel;
  353. if (var->nonstd)
  354. fix->visual = FB_VISUAL_PSEUDOCOLOR;
  355. else switch (var->bits_per_pixel) {
  356. case 16:
  357. case 12:
  358. fix->visual = FB_VISUAL_TRUECOLOR;
  359. /* 12bpp is stored in 16 bits */
  360. bpp = 16;
  361. break;
  362. case 1:
  363. case 2:
  364. case 4:
  365. case 8:
  366. fix->visual = FB_VISUAL_PSEUDOCOLOR;
  367. break;
  368. }
  369. fix->accel = FB_ACCEL_OMAP1610;
  370. fix->line_length = var->xres_virtual * bpp / 8;
  371. }
  372. static int set_color_mode(struct omapfb_plane_struct *plane,
  373. struct fb_var_screeninfo *var)
  374. {
  375. switch (var->nonstd) {
  376. case 0:
  377. break;
  378. case OMAPFB_COLOR_YUV422:
  379. var->bits_per_pixel = 16;
  380. plane->color_mode = var->nonstd;
  381. return 0;
  382. case OMAPFB_COLOR_YUV420:
  383. var->bits_per_pixel = 12;
  384. plane->color_mode = var->nonstd;
  385. return 0;
  386. case OMAPFB_COLOR_YUY422:
  387. var->bits_per_pixel = 16;
  388. plane->color_mode = var->nonstd;
  389. return 0;
  390. default:
  391. return -EINVAL;
  392. }
  393. switch (var->bits_per_pixel) {
  394. case 1:
  395. plane->color_mode = OMAPFB_COLOR_CLUT_1BPP;
  396. return 0;
  397. case 2:
  398. plane->color_mode = OMAPFB_COLOR_CLUT_2BPP;
  399. return 0;
  400. case 4:
  401. plane->color_mode = OMAPFB_COLOR_CLUT_4BPP;
  402. return 0;
  403. case 8:
  404. plane->color_mode = OMAPFB_COLOR_CLUT_8BPP;
  405. return 0;
  406. case 12:
  407. var->bits_per_pixel = 16;
  408. plane->color_mode = OMAPFB_COLOR_RGB444;
  409. return 0;
  410. case 16:
  411. plane->color_mode = OMAPFB_COLOR_RGB565;
  412. return 0;
  413. default:
  414. return -EINVAL;
  415. }
  416. }
  417. /*
  418. * Check the values in var against our capabilities and in case of out of
  419. * bound values try to adjust them.
  420. */
  421. static int set_fb_var(struct fb_info *fbi,
  422. struct fb_var_screeninfo *var)
  423. {
  424. int bpp;
  425. unsigned long max_frame_size;
  426. unsigned long line_size;
  427. int xres_min, xres_max;
  428. int yres_min, yres_max;
  429. struct omapfb_plane_struct *plane = fbi->par;
  430. struct omapfb_device *fbdev = plane->fbdev;
  431. struct lcd_panel *panel = fbdev->panel;
  432. if (set_color_mode(plane, var) < 0)
  433. return -EINVAL;
  434. bpp = var->bits_per_pixel;
  435. if (plane->color_mode == OMAPFB_COLOR_RGB444)
  436. bpp = 16;
  437. switch (var->rotate) {
  438. case 0:
  439. case 180:
  440. xres_min = OMAPFB_PLANE_XRES_MIN;
  441. xres_max = panel->x_res;
  442. yres_min = OMAPFB_PLANE_YRES_MIN;
  443. yres_max = panel->y_res;
  444. if (cpu_is_omap15xx()) {
  445. var->xres = panel->x_res;
  446. var->yres = panel->y_res;
  447. }
  448. break;
  449. case 90:
  450. case 270:
  451. xres_min = OMAPFB_PLANE_YRES_MIN;
  452. xres_max = panel->y_res;
  453. yres_min = OMAPFB_PLANE_XRES_MIN;
  454. yres_max = panel->x_res;
  455. if (cpu_is_omap15xx()) {
  456. var->xres = panel->y_res;
  457. var->yres = panel->x_res;
  458. }
  459. break;
  460. default:
  461. return -EINVAL;
  462. }
  463. if (var->xres < xres_min)
  464. var->xres = xres_min;
  465. if (var->yres < yres_min)
  466. var->yres = yres_min;
  467. if (var->xres > xres_max)
  468. var->xres = xres_max;
  469. if (var->yres > yres_max)
  470. var->yres = yres_max;
  471. if (var->xres_virtual < var->xres)
  472. var->xres_virtual = var->xres;
  473. if (var->yres_virtual < var->yres)
  474. var->yres_virtual = var->yres;
  475. max_frame_size = fbdev->mem_desc.region[plane->idx].size;
  476. line_size = var->xres_virtual * bpp / 8;
  477. if (line_size * var->yres_virtual > max_frame_size) {
  478. /* Try to keep yres_virtual first */
  479. line_size = max_frame_size / var->yres_virtual;
  480. var->xres_virtual = line_size * 8 / bpp;
  481. if (var->xres_virtual < var->xres) {
  482. /* Still doesn't fit. Shrink yres_virtual too */
  483. var->xres_virtual = var->xres;
  484. line_size = var->xres * bpp / 8;
  485. var->yres_virtual = max_frame_size / line_size;
  486. }
  487. /* Recheck this, as the virtual size changed. */
  488. if (var->xres_virtual < var->xres)
  489. var->xres = var->xres_virtual;
  490. if (var->yres_virtual < var->yres)
  491. var->yres = var->yres_virtual;
  492. if (var->xres < xres_min || var->yres < yres_min)
  493. return -EINVAL;
  494. }
  495. if (var->xres + var->xoffset > var->xres_virtual)
  496. var->xoffset = var->xres_virtual - var->xres;
  497. if (var->yres + var->yoffset > var->yres_virtual)
  498. var->yoffset = var->yres_virtual - var->yres;
  499. line_size = var->xres * bpp / 8;
  500. if (plane->color_mode == OMAPFB_COLOR_RGB444) {
  501. var->red.offset = 8; var->red.length = 4;
  502. var->red.msb_right = 0;
  503. var->green.offset = 4; var->green.length = 4;
  504. var->green.msb_right = 0;
  505. var->blue.offset = 0; var->blue.length = 4;
  506. var->blue.msb_right = 0;
  507. } else {
  508. var->red.offset = 11; var->red.length = 5;
  509. var->red.msb_right = 0;
  510. var->green.offset = 5; var->green.length = 6;
  511. var->green.msb_right = 0;
  512. var->blue.offset = 0; var->blue.length = 5;
  513. var->blue.msb_right = 0;
  514. }
  515. var->height = -1;
  516. var->width = -1;
  517. var->grayscale = 0;
  518. /* pixclock in ps, the rest in pixclock */
  519. var->pixclock = 10000000 / (panel->pixel_clock / 100);
  520. var->left_margin = panel->hfp;
  521. var->right_margin = panel->hbp;
  522. var->upper_margin = panel->vfp;
  523. var->lower_margin = panel->vbp;
  524. var->hsync_len = panel->hsw;
  525. var->vsync_len = panel->vsw;
  526. /* TODO: get these from panel->config */
  527. var->vmode = FB_VMODE_NONINTERLACED;
  528. var->sync = 0;
  529. return 0;
  530. }
  531. /* Set rotation (0, 90, 180, 270 degree), and switch to the new mode. */
  532. static void omapfb_rotate(struct fb_info *fbi, int rotate)
  533. {
  534. struct omapfb_plane_struct *plane = fbi->par;
  535. struct omapfb_device *fbdev = plane->fbdev;
  536. omapfb_rqueue_lock(fbdev);
  537. if (cpu_is_omap15xx() && rotate != fbi->var.rotate) {
  538. struct fb_var_screeninfo *new_var = &fbdev->new_var;
  539. memcpy(new_var, &fbi->var, sizeof(*new_var));
  540. new_var->rotate = rotate;
  541. if (set_fb_var(fbi, new_var) == 0 &&
  542. memcmp(new_var, &fbi->var, sizeof(*new_var))) {
  543. memcpy(&fbi->var, new_var, sizeof(*new_var));
  544. ctrl_change_mode(fbi);
  545. }
  546. }
  547. omapfb_rqueue_unlock(fbdev);
  548. }
  549. /*
  550. * Set new x,y offsets in the virtual display for the visible area and switch
  551. * to the new mode.
  552. */
  553. static int omapfb_pan_display(struct fb_var_screeninfo *var,
  554. struct fb_info *fbi)
  555. {
  556. struct omapfb_plane_struct *plane = fbi->par;
  557. struct omapfb_device *fbdev = plane->fbdev;
  558. int r = 0;
  559. omapfb_rqueue_lock(fbdev);
  560. if (var->xoffset != fbi->var.xoffset ||
  561. var->yoffset != fbi->var.yoffset) {
  562. struct fb_var_screeninfo *new_var = &fbdev->new_var;
  563. memcpy(new_var, &fbi->var, sizeof(*new_var));
  564. new_var->xoffset = var->xoffset;
  565. new_var->yoffset = var->yoffset;
  566. if (set_fb_var(fbi, new_var))
  567. r = -EINVAL;
  568. else {
  569. memcpy(&fbi->var, new_var, sizeof(*new_var));
  570. ctrl_change_mode(fbi);
  571. }
  572. }
  573. omapfb_rqueue_unlock(fbdev);
  574. return r;
  575. }
  576. /* Set mirror to vertical axis and switch to the new mode. */
  577. static int omapfb_mirror(struct fb_info *fbi, int mirror)
  578. {
  579. struct omapfb_plane_struct *plane = fbi->par;
  580. struct omapfb_device *fbdev = plane->fbdev;
  581. int r = 0;
  582. omapfb_rqueue_lock(fbdev);
  583. mirror = mirror ? 1 : 0;
  584. if (cpu_is_omap15xx())
  585. r = -EINVAL;
  586. else if (mirror != plane->info.mirror) {
  587. plane->info.mirror = mirror;
  588. r = ctrl_change_mode(fbi);
  589. }
  590. omapfb_rqueue_unlock(fbdev);
  591. return r;
  592. }
  593. /*
  594. * Check values in var, try to adjust them in case of out of bound values if
  595. * possible, or return error.
  596. */
  597. static int omapfb_check_var(struct fb_var_screeninfo *var, struct fb_info *fbi)
  598. {
  599. struct omapfb_plane_struct *plane = fbi->par;
  600. struct omapfb_device *fbdev = plane->fbdev;
  601. int r;
  602. omapfb_rqueue_lock(fbdev);
  603. if (fbdev->ctrl->sync != NULL)
  604. fbdev->ctrl->sync();
  605. r = set_fb_var(fbi, var);
  606. omapfb_rqueue_unlock(fbdev);
  607. return r;
  608. }
  609. /*
  610. * Switch to a new mode. The parameters for it has been check already by
  611. * omapfb_check_var.
  612. */
  613. static int omapfb_set_par(struct fb_info *fbi)
  614. {
  615. struct omapfb_plane_struct *plane = fbi->par;
  616. struct omapfb_device *fbdev = plane->fbdev;
  617. int r = 0;
  618. omapfb_rqueue_lock(fbdev);
  619. set_fb_fix(fbi);
  620. r = ctrl_change_mode(fbi);
  621. omapfb_rqueue_unlock(fbdev);
  622. return r;
  623. }
  624. int omapfb_update_window_async(struct fb_info *fbi,
  625. struct omapfb_update_window *win,
  626. void (*callback)(void *),
  627. void *callback_data)
  628. {
  629. struct omapfb_plane_struct *plane = fbi->par;
  630. struct omapfb_device *fbdev = plane->fbdev;
  631. struct fb_var_screeninfo *var;
  632. var = &fbi->var;
  633. if (win->x >= var->xres || win->y >= var->yres ||
  634. win->out_x > var->xres || win->out_y >= var->yres)
  635. return -EINVAL;
  636. if (!fbdev->ctrl->update_window ||
  637. fbdev->ctrl->get_update_mode() != OMAPFB_MANUAL_UPDATE)
  638. return -ENODEV;
  639. if (win->x + win->width >= var->xres)
  640. win->width = var->xres - win->x;
  641. if (win->y + win->height >= var->yres)
  642. win->height = var->yres - win->y;
  643. /* The out sizes should be cropped to the LCD size */
  644. if (win->out_x + win->out_width > fbdev->panel->x_res)
  645. win->out_width = fbdev->panel->x_res - win->out_x;
  646. if (win->out_y + win->out_height > fbdev->panel->y_res)
  647. win->out_height = fbdev->panel->y_res - win->out_y;
  648. if (!win->width || !win->height || !win->out_width || !win->out_height)
  649. return 0;
  650. return fbdev->ctrl->update_window(fbi, win, callback, callback_data);
  651. }
  652. EXPORT_SYMBOL(omapfb_update_window_async);
  653. static int omapfb_update_win(struct fb_info *fbi,
  654. struct omapfb_update_window *win)
  655. {
  656. struct omapfb_plane_struct *plane = fbi->par;
  657. int ret;
  658. omapfb_rqueue_lock(plane->fbdev);
  659. ret = omapfb_update_window_async(fbi, win, NULL, 0);
  660. omapfb_rqueue_unlock(plane->fbdev);
  661. return ret;
  662. }
  663. static int omapfb_update_full_screen(struct fb_info *fbi)
  664. {
  665. struct omapfb_plane_struct *plane = fbi->par;
  666. struct omapfb_device *fbdev = plane->fbdev;
  667. struct omapfb_update_window win;
  668. int r;
  669. if (!fbdev->ctrl->update_window ||
  670. fbdev->ctrl->get_update_mode() != OMAPFB_MANUAL_UPDATE)
  671. return -ENODEV;
  672. win.x = 0;
  673. win.y = 0;
  674. win.width = fbi->var.xres;
  675. win.height = fbi->var.yres;
  676. win.out_x = 0;
  677. win.out_y = 0;
  678. win.out_width = fbi->var.xres;
  679. win.out_height = fbi->var.yres;
  680. win.format = 0;
  681. omapfb_rqueue_lock(fbdev);
  682. r = fbdev->ctrl->update_window(fbi, &win, NULL, 0);
  683. omapfb_rqueue_unlock(fbdev);
  684. return r;
  685. }
  686. static int omapfb_setup_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
  687. {
  688. struct omapfb_plane_struct *plane = fbi->par;
  689. struct omapfb_device *fbdev = plane->fbdev;
  690. struct lcd_panel *panel = fbdev->panel;
  691. struct omapfb_plane_info old_info;
  692. int r = 0;
  693. if (pi->pos_x + pi->out_width > panel->x_res ||
  694. pi->pos_y + pi->out_height > panel->y_res)
  695. return -EINVAL;
  696. omapfb_rqueue_lock(fbdev);
  697. if (pi->enabled && !fbdev->mem_desc.region[plane->idx].size) {
  698. /*
  699. * This plane's memory was freed, can't enable it
  700. * until it's reallocated.
  701. */
  702. r = -EINVAL;
  703. goto out;
  704. }
  705. old_info = plane->info;
  706. plane->info = *pi;
  707. if (pi->enabled) {
  708. r = ctrl_change_mode(fbi);
  709. if (r < 0) {
  710. plane->info = old_info;
  711. goto out;
  712. }
  713. }
  714. r = fbdev->ctrl->enable_plane(plane->idx, pi->enabled);
  715. if (r < 0) {
  716. plane->info = old_info;
  717. goto out;
  718. }
  719. out:
  720. omapfb_rqueue_unlock(fbdev);
  721. return r;
  722. }
  723. static int omapfb_query_plane(struct fb_info *fbi, struct omapfb_plane_info *pi)
  724. {
  725. struct omapfb_plane_struct *plane = fbi->par;
  726. *pi = plane->info;
  727. return 0;
  728. }
  729. static int omapfb_setup_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
  730. {
  731. struct omapfb_plane_struct *plane = fbi->par;
  732. struct omapfb_device *fbdev = plane->fbdev;
  733. struct omapfb_mem_region *rg = &fbdev->mem_desc.region[plane->idx];
  734. size_t size;
  735. int r = 0;
  736. if (fbdev->ctrl->setup_mem == NULL)
  737. return -ENODEV;
  738. if (mi->type > OMAPFB_MEMTYPE_MAX)
  739. return -EINVAL;
  740. size = PAGE_ALIGN(mi->size);
  741. omapfb_rqueue_lock(fbdev);
  742. if (plane->info.enabled) {
  743. r = -EBUSY;
  744. goto out;
  745. }
  746. if (rg->size != size || rg->type != mi->type) {
  747. struct fb_var_screeninfo *new_var = &fbdev->new_var;
  748. unsigned long old_size = rg->size;
  749. u8 old_type = rg->type;
  750. unsigned long paddr;
  751. rg->size = size;
  752. rg->type = mi->type;
  753. /*
  754. * size == 0 is a special case, for which we
  755. * don't check / adjust the screen parameters.
  756. * This isn't a problem since the plane can't
  757. * be reenabled unless its size is > 0.
  758. */
  759. if (old_size != size && size) {
  760. if (size) {
  761. memcpy(new_var, &fbi->var, sizeof(*new_var));
  762. r = set_fb_var(fbi, new_var);
  763. if (r < 0)
  764. goto out;
  765. }
  766. }
  767. if (fbdev->ctrl->sync)
  768. fbdev->ctrl->sync();
  769. r = fbdev->ctrl->setup_mem(plane->idx, size, mi->type, &paddr);
  770. if (r < 0) {
  771. /* Revert changes. */
  772. rg->size = old_size;
  773. rg->type = old_type;
  774. goto out;
  775. }
  776. rg->paddr = paddr;
  777. if (old_size != size) {
  778. if (size) {
  779. memcpy(&fbi->var, new_var, sizeof(fbi->var));
  780. set_fb_fix(fbi);
  781. } else {
  782. /*
  783. * Set these explicitly to indicate that the
  784. * plane memory is dealloce'd, the other
  785. * screen parameters in var / fix are invalid.
  786. */
  787. fbi->fix.smem_start = 0;
  788. fbi->fix.smem_len = 0;
  789. }
  790. }
  791. }
  792. out:
  793. omapfb_rqueue_unlock(fbdev);
  794. return r;
  795. }
  796. static int omapfb_query_mem(struct fb_info *fbi, struct omapfb_mem_info *mi)
  797. {
  798. struct omapfb_plane_struct *plane = fbi->par;
  799. struct omapfb_device *fbdev = plane->fbdev;
  800. struct omapfb_mem_region *rg;
  801. rg = &fbdev->mem_desc.region[plane->idx];
  802. memset(mi, 0, sizeof(*mi));
  803. mi->size = rg->size;
  804. mi->type = rg->type;
  805. return 0;
  806. }
  807. static int omapfb_set_color_key(struct omapfb_device *fbdev,
  808. struct omapfb_color_key *ck)
  809. {
  810. int r;
  811. if (!fbdev->ctrl->set_color_key)
  812. return -ENODEV;
  813. omapfb_rqueue_lock(fbdev);
  814. r = fbdev->ctrl->set_color_key(ck);
  815. omapfb_rqueue_unlock(fbdev);
  816. return r;
  817. }
  818. static int omapfb_get_color_key(struct omapfb_device *fbdev,
  819. struct omapfb_color_key *ck)
  820. {
  821. int r;
  822. if (!fbdev->ctrl->get_color_key)
  823. return -ENODEV;
  824. omapfb_rqueue_lock(fbdev);
  825. r = fbdev->ctrl->get_color_key(ck);
  826. omapfb_rqueue_unlock(fbdev);
  827. return r;
  828. }
  829. static struct blocking_notifier_head omapfb_client_list[OMAPFB_PLANE_NUM];
  830. static int notifier_inited;
  831. static void omapfb_init_notifier(void)
  832. {
  833. int i;
  834. for (i = 0; i < OMAPFB_PLANE_NUM; i++)
  835. BLOCKING_INIT_NOTIFIER_HEAD(&omapfb_client_list[i]);
  836. }
  837. int omapfb_register_client(struct omapfb_notifier_block *omapfb_nb,
  838. omapfb_notifier_callback_t callback,
  839. void *callback_data)
  840. {
  841. int r;
  842. if ((unsigned)omapfb_nb->plane_idx > OMAPFB_PLANE_NUM)
  843. return -EINVAL;
  844. if (!notifier_inited) {
  845. omapfb_init_notifier();
  846. notifier_inited = 1;
  847. }
  848. omapfb_nb->nb.notifier_call = (int (*)(struct notifier_block *,
  849. unsigned long, void *))callback;
  850. omapfb_nb->data = callback_data;
  851. r = blocking_notifier_chain_register(
  852. &omapfb_client_list[omapfb_nb->plane_idx],
  853. &omapfb_nb->nb);
  854. if (r)
  855. return r;
  856. if (omapfb_dev != NULL &&
  857. omapfb_dev->ctrl && omapfb_dev->ctrl->bind_client) {
  858. omapfb_dev->ctrl->bind_client(omapfb_nb);
  859. }
  860. return 0;
  861. }
  862. EXPORT_SYMBOL(omapfb_register_client);
  863. int omapfb_unregister_client(struct omapfb_notifier_block *omapfb_nb)
  864. {
  865. return blocking_notifier_chain_unregister(
  866. &omapfb_client_list[omapfb_nb->plane_idx], &omapfb_nb->nb);
  867. }
  868. EXPORT_SYMBOL(omapfb_unregister_client);
  869. void omapfb_notify_clients(struct omapfb_device *fbdev, unsigned long event)
  870. {
  871. int i;
  872. if (!notifier_inited)
  873. /* no client registered yet */
  874. return;
  875. for (i = 0; i < OMAPFB_PLANE_NUM; i++)
  876. blocking_notifier_call_chain(&omapfb_client_list[i], event,
  877. fbdev->fb_info[i]);
  878. }
  879. EXPORT_SYMBOL(omapfb_notify_clients);
  880. static int omapfb_set_update_mode(struct omapfb_device *fbdev,
  881. enum omapfb_update_mode mode)
  882. {
  883. int r;
  884. omapfb_rqueue_lock(fbdev);
  885. r = fbdev->ctrl->set_update_mode(mode);
  886. omapfb_rqueue_unlock(fbdev);
  887. return r;
  888. }
  889. static enum omapfb_update_mode omapfb_get_update_mode(struct omapfb_device *fbdev)
  890. {
  891. int r;
  892. omapfb_rqueue_lock(fbdev);
  893. r = fbdev->ctrl->get_update_mode();
  894. omapfb_rqueue_unlock(fbdev);
  895. return r;
  896. }
  897. static void omapfb_get_caps(struct omapfb_device *fbdev, int plane,
  898. struct omapfb_caps *caps)
  899. {
  900. memset(caps, 0, sizeof(*caps));
  901. fbdev->ctrl->get_caps(plane, caps);
  902. caps->ctrl |= fbdev->panel->get_caps(fbdev->panel);
  903. }
  904. /* For lcd testing */
  905. void omapfb_write_first_pixel(struct omapfb_device *fbdev, u16 pixval)
  906. {
  907. omapfb_rqueue_lock(fbdev);
  908. *(u16 *)fbdev->mem_desc.region[0].vaddr = pixval;
  909. if (fbdev->ctrl->get_update_mode() == OMAPFB_MANUAL_UPDATE) {
  910. struct omapfb_update_window win;
  911. memset(&win, 0, sizeof(win));
  912. win.width = 2;
  913. win.height = 2;
  914. win.out_width = 2;
  915. win.out_height = 2;
  916. fbdev->ctrl->update_window(fbdev->fb_info[0], &win, NULL, 0);
  917. }
  918. omapfb_rqueue_unlock(fbdev);
  919. }
  920. EXPORT_SYMBOL(omapfb_write_first_pixel);
  921. /*
  922. * Ioctl interface. Part of the kernel mode frame buffer API is duplicated
  923. * here to be accessible by user mode code.
  924. */
  925. static int omapfb_ioctl(struct fb_info *fbi, unsigned int cmd,
  926. unsigned long arg)
  927. {
  928. struct omapfb_plane_struct *plane = fbi->par;
  929. struct omapfb_device *fbdev = plane->fbdev;
  930. struct fb_ops *ops = fbi->fbops;
  931. union {
  932. struct omapfb_update_window update_window;
  933. struct omapfb_plane_info plane_info;
  934. struct omapfb_mem_info mem_info;
  935. struct omapfb_color_key color_key;
  936. enum omapfb_update_mode update_mode;
  937. struct omapfb_caps caps;
  938. unsigned int mirror;
  939. int plane_out;
  940. int enable_plane;
  941. } p;
  942. int r = 0;
  943. BUG_ON(!ops);
  944. switch (cmd) {
  945. case OMAPFB_MIRROR:
  946. if (get_user(p.mirror, (int __user *)arg))
  947. r = -EFAULT;
  948. else
  949. omapfb_mirror(fbi, p.mirror);
  950. break;
  951. case OMAPFB_SYNC_GFX:
  952. omapfb_sync(fbi);
  953. break;
  954. case OMAPFB_VSYNC:
  955. break;
  956. case OMAPFB_SET_UPDATE_MODE:
  957. if (get_user(p.update_mode, (int __user *)arg))
  958. r = -EFAULT;
  959. else
  960. r = omapfb_set_update_mode(fbdev, p.update_mode);
  961. break;
  962. case OMAPFB_GET_UPDATE_MODE:
  963. p.update_mode = omapfb_get_update_mode(fbdev);
  964. if (put_user(p.update_mode,
  965. (enum omapfb_update_mode __user *)arg))
  966. r = -EFAULT;
  967. break;
  968. case OMAPFB_UPDATE_WINDOW_OLD:
  969. if (copy_from_user(&p.update_window, (void __user *)arg,
  970. sizeof(struct omapfb_update_window_old)))
  971. r = -EFAULT;
  972. else {
  973. struct omapfb_update_window *u = &p.update_window;
  974. u->out_x = u->x;
  975. u->out_y = u->y;
  976. u->out_width = u->width;
  977. u->out_height = u->height;
  978. memset(u->reserved, 0, sizeof(u->reserved));
  979. r = omapfb_update_win(fbi, u);
  980. }
  981. break;
  982. case OMAPFB_UPDATE_WINDOW:
  983. if (copy_from_user(&p.update_window, (void __user *)arg,
  984. sizeof(p.update_window)))
  985. r = -EFAULT;
  986. else
  987. r = omapfb_update_win(fbi, &p.update_window);
  988. break;
  989. case OMAPFB_SETUP_PLANE:
  990. if (copy_from_user(&p.plane_info, (void __user *)arg,
  991. sizeof(p.plane_info)))
  992. r = -EFAULT;
  993. else
  994. r = omapfb_setup_plane(fbi, &p.plane_info);
  995. break;
  996. case OMAPFB_QUERY_PLANE:
  997. if ((r = omapfb_query_plane(fbi, &p.plane_info)) < 0)
  998. break;
  999. if (copy_to_user((void __user *)arg, &p.plane_info,
  1000. sizeof(p.plane_info)))
  1001. r = -EFAULT;
  1002. break;
  1003. case OMAPFB_SETUP_MEM:
  1004. if (copy_from_user(&p.mem_info, (void __user *)arg,
  1005. sizeof(p.mem_info)))
  1006. r = -EFAULT;
  1007. else
  1008. r = omapfb_setup_mem(fbi, &p.mem_info);
  1009. break;
  1010. case OMAPFB_QUERY_MEM:
  1011. if ((r = omapfb_query_mem(fbi, &p.mem_info)) < 0)
  1012. break;
  1013. if (copy_to_user((void __user *)arg, &p.mem_info,
  1014. sizeof(p.mem_info)))
  1015. r = -EFAULT;
  1016. break;
  1017. case OMAPFB_SET_COLOR_KEY:
  1018. if (copy_from_user(&p.color_key, (void __user *)arg,
  1019. sizeof(p.color_key)))
  1020. r = -EFAULT;
  1021. else
  1022. r = omapfb_set_color_key(fbdev, &p.color_key);
  1023. break;
  1024. case OMAPFB_GET_COLOR_KEY:
  1025. if ((r = omapfb_get_color_key(fbdev, &p.color_key)) < 0)
  1026. break;
  1027. if (copy_to_user((void __user *)arg, &p.color_key,
  1028. sizeof(p.color_key)))
  1029. r = -EFAULT;
  1030. break;
  1031. case OMAPFB_GET_CAPS:
  1032. omapfb_get_caps(fbdev, plane->idx, &p.caps);
  1033. if (copy_to_user((void __user *)arg, &p.caps, sizeof(p.caps)))
  1034. r = -EFAULT;
  1035. break;
  1036. case OMAPFB_LCD_TEST:
  1037. {
  1038. int test_num;
  1039. if (get_user(test_num, (int __user *)arg)) {
  1040. r = -EFAULT;
  1041. break;
  1042. }
  1043. if (!fbdev->panel->run_test) {
  1044. r = -EINVAL;
  1045. break;
  1046. }
  1047. r = fbdev->panel->run_test(fbdev->panel, test_num);
  1048. break;
  1049. }
  1050. case OMAPFB_CTRL_TEST:
  1051. {
  1052. int test_num;
  1053. if (get_user(test_num, (int __user *)arg)) {
  1054. r = -EFAULT;
  1055. break;
  1056. }
  1057. if (!fbdev->ctrl->run_test) {
  1058. r = -EINVAL;
  1059. break;
  1060. }
  1061. r = fbdev->ctrl->run_test(test_num);
  1062. break;
  1063. }
  1064. default:
  1065. r = -EINVAL;
  1066. }
  1067. return r;
  1068. }
  1069. static int omapfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
  1070. {
  1071. struct omapfb_plane_struct *plane = info->par;
  1072. struct omapfb_device *fbdev = plane->fbdev;
  1073. int r;
  1074. omapfb_rqueue_lock(fbdev);
  1075. r = fbdev->ctrl->mmap(info, vma);
  1076. omapfb_rqueue_unlock(fbdev);
  1077. return r;
  1078. }
  1079. /*
  1080. * Callback table for the frame buffer framework. Some of these pointers
  1081. * will be changed according to the current setting of fb_info->accel_flags.
  1082. */
  1083. static struct fb_ops omapfb_ops = {
  1084. .owner = THIS_MODULE,
  1085. .fb_open = omapfb_open,
  1086. .fb_release = omapfb_release,
  1087. .fb_setcolreg = omapfb_setcolreg,
  1088. .fb_setcmap = omapfb_setcmap,
  1089. .fb_fillrect = cfb_fillrect,
  1090. .fb_copyarea = cfb_copyarea,
  1091. .fb_imageblit = cfb_imageblit,
  1092. .fb_blank = omapfb_blank,
  1093. .fb_ioctl = omapfb_ioctl,
  1094. .fb_check_var = omapfb_check_var,
  1095. .fb_set_par = omapfb_set_par,
  1096. .fb_rotate = omapfb_rotate,
  1097. .fb_pan_display = omapfb_pan_display,
  1098. };
  1099. /*
  1100. * ---------------------------------------------------------------------------
  1101. * Sysfs interface
  1102. * ---------------------------------------------------------------------------
  1103. */
  1104. /* omapfbX sysfs entries */
  1105. static ssize_t omapfb_show_caps_num(struct device *dev,
  1106. struct device_attribute *attr, char *buf)
  1107. {
  1108. struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
  1109. int plane;
  1110. size_t size;
  1111. struct omapfb_caps caps;
  1112. plane = 0;
  1113. size = 0;
  1114. while (size < PAGE_SIZE && plane < OMAPFB_PLANE_NUM) {
  1115. omapfb_get_caps(fbdev, plane, &caps);
  1116. size += snprintf(&buf[size], PAGE_SIZE - size,
  1117. "plane#%d %#010x %#010x %#010x\n",
  1118. plane, caps.ctrl, caps.plane_color, caps.wnd_color);
  1119. plane++;
  1120. }
  1121. return size;
  1122. }
  1123. static ssize_t omapfb_show_caps_text(struct device *dev,
  1124. struct device_attribute *attr, char *buf)
  1125. {
  1126. struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
  1127. int i;
  1128. struct omapfb_caps caps;
  1129. int plane;
  1130. size_t size;
  1131. plane = 0;
  1132. size = 0;
  1133. while (size < PAGE_SIZE && plane < OMAPFB_PLANE_NUM) {
  1134. omapfb_get_caps(fbdev, plane, &caps);
  1135. size += snprintf(&buf[size], PAGE_SIZE - size,
  1136. "plane#%d:\n", plane);
  1137. for (i = 0; i < ARRAY_SIZE(ctrl_caps) &&
  1138. size < PAGE_SIZE; i++) {
  1139. if (ctrl_caps[i].flag & caps.ctrl)
  1140. size += snprintf(&buf[size], PAGE_SIZE - size,
  1141. " %s\n", ctrl_caps[i].name);
  1142. }
  1143. size += snprintf(&buf[size], PAGE_SIZE - size,
  1144. " plane colors:\n");
  1145. for (i = 0; i < ARRAY_SIZE(color_caps) &&
  1146. size < PAGE_SIZE; i++) {
  1147. if (color_caps[i].flag & caps.plane_color)
  1148. size += snprintf(&buf[size], PAGE_SIZE - size,
  1149. " %s\n", color_caps[i].name);
  1150. }
  1151. size += snprintf(&buf[size], PAGE_SIZE - size,
  1152. " window colors:\n");
  1153. for (i = 0; i < ARRAY_SIZE(color_caps) &&
  1154. size < PAGE_SIZE; i++) {
  1155. if (color_caps[i].flag & caps.wnd_color)
  1156. size += snprintf(&buf[size], PAGE_SIZE - size,
  1157. " %s\n", color_caps[i].name);
  1158. }
  1159. plane++;
  1160. }
  1161. return size;
  1162. }
  1163. static DEVICE_ATTR(caps_num, 0444, omapfb_show_caps_num, NULL);
  1164. static DEVICE_ATTR(caps_text, 0444, omapfb_show_caps_text, NULL);
  1165. /* panel sysfs entries */
  1166. static ssize_t omapfb_show_panel_name(struct device *dev,
  1167. struct device_attribute *attr, char *buf)
  1168. {
  1169. struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
  1170. return snprintf(buf, PAGE_SIZE, "%s\n", fbdev->panel->name);
  1171. }
  1172. static ssize_t omapfb_show_bklight_level(struct device *dev,
  1173. struct device_attribute *attr,
  1174. char *buf)
  1175. {
  1176. struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
  1177. int r;
  1178. if (fbdev->panel->get_bklight_level) {
  1179. r = snprintf(buf, PAGE_SIZE, "%d\n",
  1180. fbdev->panel->get_bklight_level(fbdev->panel));
  1181. } else
  1182. r = -ENODEV;
  1183. return r;
  1184. }
  1185. static ssize_t omapfb_store_bklight_level(struct device *dev,
  1186. struct device_attribute *attr,
  1187. const char *buf, size_t size)
  1188. {
  1189. struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
  1190. int r;
  1191. if (fbdev->panel->set_bklight_level) {
  1192. unsigned int level;
  1193. if (sscanf(buf, "%10d", &level) == 1) {
  1194. r = fbdev->panel->set_bklight_level(fbdev->panel,
  1195. level);
  1196. } else
  1197. r = -EINVAL;
  1198. } else
  1199. r = -ENODEV;
  1200. return r ? r : size;
  1201. }
  1202. static ssize_t omapfb_show_bklight_max(struct device *dev,
  1203. struct device_attribute *attr, char *buf)
  1204. {
  1205. struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
  1206. int r;
  1207. if (fbdev->panel->get_bklight_level) {
  1208. r = snprintf(buf, PAGE_SIZE, "%d\n",
  1209. fbdev->panel->get_bklight_max(fbdev->panel));
  1210. } else
  1211. r = -ENODEV;
  1212. return r;
  1213. }
  1214. static struct device_attribute dev_attr_panel_name =
  1215. __ATTR(name, 0444, omapfb_show_panel_name, NULL);
  1216. static DEVICE_ATTR(backlight_level, 0664,
  1217. omapfb_show_bklight_level, omapfb_store_bklight_level);
  1218. static DEVICE_ATTR(backlight_max, 0444, omapfb_show_bklight_max, NULL);
  1219. static struct attribute *panel_attrs[] = {
  1220. &dev_attr_panel_name.attr,
  1221. &dev_attr_backlight_level.attr,
  1222. &dev_attr_backlight_max.attr,
  1223. NULL,
  1224. };
  1225. static struct attribute_group panel_attr_grp = {
  1226. .name = "panel",
  1227. .attrs = panel_attrs,
  1228. };
  1229. /* ctrl sysfs entries */
  1230. static ssize_t omapfb_show_ctrl_name(struct device *dev,
  1231. struct device_attribute *attr, char *buf)
  1232. {
  1233. struct omapfb_device *fbdev = (struct omapfb_device *)dev->driver_data;
  1234. return snprintf(buf, PAGE_SIZE, "%s\n", fbdev->ctrl->name);
  1235. }
  1236. static struct device_attribute dev_attr_ctrl_name =
  1237. __ATTR(name, 0444, omapfb_show_ctrl_name, NULL);
  1238. static struct attribute *ctrl_attrs[] = {
  1239. &dev_attr_ctrl_name.attr,
  1240. NULL,
  1241. };
  1242. static struct attribute_group ctrl_attr_grp = {
  1243. .name = "ctrl",
  1244. .attrs = ctrl_attrs,
  1245. };
  1246. static int omapfb_register_sysfs(struct omapfb_device *fbdev)
  1247. {
  1248. int r;
  1249. if ((r = device_create_file(fbdev->dev, &dev_attr_caps_num)))
  1250. goto fail0;
  1251. if ((r = device_create_file(fbdev->dev, &dev_attr_caps_text)))
  1252. goto fail1;
  1253. if ((r = sysfs_create_group(&fbdev->dev->kobj, &panel_attr_grp)))
  1254. goto fail2;
  1255. if ((r = sysfs_create_group(&fbdev->dev->kobj, &ctrl_attr_grp)))
  1256. goto fail3;
  1257. return 0;
  1258. fail3:
  1259. sysfs_remove_group(&fbdev->dev->kobj, &panel_attr_grp);
  1260. fail2:
  1261. device_remove_file(fbdev->dev, &dev_attr_caps_text);
  1262. fail1:
  1263. device_remove_file(fbdev->dev, &dev_attr_caps_num);
  1264. fail0:
  1265. dev_err(fbdev->dev, "unable to register sysfs interface\n");
  1266. return r;
  1267. }
  1268. static void omapfb_unregister_sysfs(struct omapfb_device *fbdev)
  1269. {
  1270. sysfs_remove_group(&fbdev->dev->kobj, &ctrl_attr_grp);
  1271. sysfs_remove_group(&fbdev->dev->kobj, &panel_attr_grp);
  1272. device_remove_file(fbdev->dev, &dev_attr_caps_num);
  1273. device_remove_file(fbdev->dev, &dev_attr_caps_text);
  1274. }
  1275. /*
  1276. * ---------------------------------------------------------------------------
  1277. * LDM callbacks
  1278. * ---------------------------------------------------------------------------
  1279. */
  1280. /* Initialize system fb_info object and set the default video mode.
  1281. * The frame buffer memory already allocated by lcddma_init
  1282. */
  1283. static int fbinfo_init(struct omapfb_device *fbdev, struct fb_info *info)
  1284. {
  1285. struct fb_var_screeninfo *var = &info->var;
  1286. struct fb_fix_screeninfo *fix = &info->fix;
  1287. int r = 0;
  1288. info->fbops = &omapfb_ops;
  1289. info->flags = FBINFO_FLAG_DEFAULT;
  1290. strncpy(fix->id, MODULE_NAME, sizeof(fix->id));
  1291. info->pseudo_palette = fbdev->pseudo_palette;
  1292. var->accel_flags = def_accel ? FB_ACCELF_TEXT : 0;
  1293. var->xres = def_vxres;
  1294. var->yres = def_vyres;
  1295. var->xres_virtual = def_vxres;
  1296. var->yres_virtual = def_vyres;
  1297. var->rotate = def_rotate;
  1298. var->bits_per_pixel = fbdev->panel->bpp;
  1299. set_fb_var(info, var);
  1300. set_fb_fix(info);
  1301. r = fb_alloc_cmap(&info->cmap, 16, 0);
  1302. if (r != 0)
  1303. dev_err(fbdev->dev, "unable to allocate color map memory\n");
  1304. return r;
  1305. }
  1306. /* Release the fb_info object */
  1307. static void fbinfo_cleanup(struct omapfb_device *fbdev, struct fb_info *fbi)
  1308. {
  1309. fb_dealloc_cmap(&fbi->cmap);
  1310. }
  1311. static void planes_cleanup(struct omapfb_device *fbdev)
  1312. {
  1313. int i;
  1314. for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
  1315. if (fbdev->fb_info[i] == NULL)
  1316. break;
  1317. fbinfo_cleanup(fbdev, fbdev->fb_info[i]);
  1318. framebuffer_release(fbdev->fb_info[i]);
  1319. }
  1320. }
  1321. static int planes_init(struct omapfb_device *fbdev)
  1322. {
  1323. struct fb_info *fbi;
  1324. int i;
  1325. int r;
  1326. for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
  1327. struct omapfb_plane_struct *plane;
  1328. fbi = framebuffer_alloc(sizeof(struct omapfb_plane_struct),
  1329. fbdev->dev);
  1330. if (fbi == NULL) {
  1331. dev_err(fbdev->dev,
  1332. "unable to allocate memory for plane info\n");
  1333. planes_cleanup(fbdev);
  1334. return -ENOMEM;
  1335. }
  1336. plane = fbi->par;
  1337. plane->idx = i;
  1338. plane->fbdev = fbdev;
  1339. plane->info.mirror = def_mirror;
  1340. fbdev->fb_info[i] = fbi;
  1341. if ((r = fbinfo_init(fbdev, fbi)) < 0) {
  1342. framebuffer_release(fbi);
  1343. planes_cleanup(fbdev);
  1344. return r;
  1345. }
  1346. plane->info.out_width = fbi->var.xres;
  1347. plane->info.out_height = fbi->var.yres;
  1348. }
  1349. return 0;
  1350. }
  1351. /*
  1352. * Free driver resources. Can be called to rollback an aborted initialization
  1353. * sequence.
  1354. */
  1355. static void omapfb_free_resources(struct omapfb_device *fbdev, int state)
  1356. {
  1357. int i;
  1358. switch (state) {
  1359. case OMAPFB_ACTIVE:
  1360. for (i = 0; i < fbdev->mem_desc.region_cnt; i++)
  1361. unregister_framebuffer(fbdev->fb_info[i]);
  1362. case 7:
  1363. omapfb_unregister_sysfs(fbdev);
  1364. case 6:
  1365. fbdev->panel->disable(fbdev->panel);
  1366. case 5:
  1367. omapfb_set_update_mode(fbdev, OMAPFB_UPDATE_DISABLED);
  1368. case 4:
  1369. planes_cleanup(fbdev);
  1370. case 3:
  1371. ctrl_cleanup(fbdev);
  1372. case 2:
  1373. fbdev->panel->cleanup(fbdev->panel);
  1374. case 1:
  1375. dev_set_drvdata(fbdev->dev, NULL);
  1376. kfree(fbdev);
  1377. case 0:
  1378. /* nothing to free */
  1379. break;
  1380. default:
  1381. BUG();
  1382. }
  1383. }
  1384. static int omapfb_find_ctrl(struct omapfb_device *fbdev)
  1385. {
  1386. struct omapfb_platform_data *conf;
  1387. char name[17];
  1388. int i;
  1389. conf = fbdev->dev->platform_data;
  1390. fbdev->ctrl = NULL;
  1391. strncpy(name, conf->lcd.ctrl_name, sizeof(name) - 1);
  1392. name[sizeof(name) - 1] = '\0';
  1393. if (strcmp(name, "internal") == 0) {
  1394. fbdev->ctrl = fbdev->int_ctrl;
  1395. return 0;
  1396. }
  1397. for (i = 0; i < ARRAY_SIZE(ctrls); i++) {
  1398. dev_dbg(fbdev->dev, "ctrl %s\n", ctrls[i]->name);
  1399. if (strcmp(ctrls[i]->name, name) == 0) {
  1400. fbdev->ctrl = ctrls[i];
  1401. break;
  1402. }
  1403. }
  1404. if (fbdev->ctrl == NULL) {
  1405. dev_dbg(fbdev->dev, "ctrl %s not supported\n", name);
  1406. return -1;
  1407. }
  1408. return 0;
  1409. }
  1410. static void check_required_callbacks(struct omapfb_device *fbdev)
  1411. {
  1412. #define _C(x) (fbdev->ctrl->x != NULL)
  1413. #define _P(x) (fbdev->panel->x != NULL)
  1414. BUG_ON(fbdev->ctrl == NULL || fbdev->panel == NULL);
  1415. BUG_ON(!(_C(init) && _C(cleanup) && _C(get_caps) &&
  1416. _C(set_update_mode) && _C(setup_plane) && _C(enable_plane) &&
  1417. _P(init) && _P(cleanup) && _P(enable) && _P(disable) &&
  1418. _P(get_caps)));
  1419. #undef _P
  1420. #undef _C
  1421. }
  1422. /*
  1423. * Called by LDM binding to probe and attach a new device.
  1424. * Initialization sequence:
  1425. * 1. allocate system omapfb_device structure
  1426. * 2. select controller type according to platform configuration
  1427. * init LCD panel
  1428. * 3. init LCD controller and LCD DMA
  1429. * 4. init system fb_info structure for all planes
  1430. * 5. setup video mode for first plane and enable it
  1431. * 6. enable LCD panel
  1432. * 7. register sysfs attributes
  1433. * OMAPFB_ACTIVE: register system fb_info structure for all planes
  1434. */
  1435. static int omapfb_do_probe(struct platform_device *pdev,
  1436. struct lcd_panel *panel)
  1437. {
  1438. struct omapfb_device *fbdev = NULL;
  1439. int init_state;
  1440. unsigned long phz, hhz, vhz;
  1441. unsigned long vram;
  1442. int i;
  1443. int r = 0;
  1444. init_state = 0;
  1445. if (pdev->num_resources != 0) {
  1446. dev_err(&pdev->dev, "probed for an unknown device\n");
  1447. r = -ENODEV;
  1448. goto cleanup;
  1449. }
  1450. if (pdev->dev.platform_data == NULL) {
  1451. dev_err(&pdev->dev, "missing platform data\n");
  1452. r = -ENOENT;
  1453. goto cleanup;
  1454. }
  1455. fbdev = kzalloc(sizeof(struct omapfb_device), GFP_KERNEL);
  1456. if (fbdev == NULL) {
  1457. dev_err(&pdev->dev,
  1458. "unable to allocate memory for device info\n");
  1459. r = -ENOMEM;
  1460. goto cleanup;
  1461. }
  1462. init_state++;
  1463. fbdev->dev = &pdev->dev;
  1464. fbdev->panel = panel;
  1465. platform_set_drvdata(pdev, fbdev);
  1466. mutex_init(&fbdev->rqueue_mutex);
  1467. #ifdef CONFIG_ARCH_OMAP1
  1468. fbdev->int_ctrl = &omap1_int_ctrl;
  1469. #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
  1470. fbdev->ext_if = &omap1_ext_if;
  1471. #endif
  1472. #else /* OMAP2 */
  1473. fbdev->int_ctrl = &omap2_int_ctrl;
  1474. #ifdef CONFIG_FB_OMAP_LCDC_EXTERNAL
  1475. fbdev->ext_if = &omap2_ext_if;
  1476. #endif
  1477. #endif
  1478. if (omapfb_find_ctrl(fbdev) < 0) {
  1479. dev_err(fbdev->dev,
  1480. "LCD controller not found, board not supported\n");
  1481. r = -ENODEV;
  1482. goto cleanup;
  1483. }
  1484. r = fbdev->panel->init(fbdev->panel, fbdev);
  1485. if (r)
  1486. goto cleanup;
  1487. pr_info("omapfb: configured for panel %s\n", fbdev->panel->name);
  1488. def_vxres = def_vxres ? : fbdev->panel->x_res;
  1489. def_vyres = def_vyres ? : fbdev->panel->y_res;
  1490. init_state++;
  1491. r = ctrl_init(fbdev);
  1492. if (r)
  1493. goto cleanup;
  1494. if (fbdev->ctrl->mmap != NULL)
  1495. omapfb_ops.fb_mmap = omapfb_mmap;
  1496. init_state++;
  1497. check_required_callbacks(fbdev);
  1498. r = planes_init(fbdev);
  1499. if (r)
  1500. goto cleanup;
  1501. init_state++;
  1502. #ifdef CONFIG_FB_OMAP_DMA_TUNE
  1503. /* Set DMA priority for EMIFF access to highest */
  1504. if (cpu_class_is_omap1())
  1505. omap_set_dma_priority(0, OMAP_DMA_PORT_EMIFF, 15);
  1506. #endif
  1507. r = ctrl_change_mode(fbdev->fb_info[0]);
  1508. if (r) {
  1509. dev_err(fbdev->dev, "mode setting failed\n");
  1510. goto cleanup;
  1511. }
  1512. /* GFX plane is enabled by default */
  1513. r = fbdev->ctrl->enable_plane(OMAPFB_PLANE_GFX, 1);
  1514. if (r)
  1515. goto cleanup;
  1516. omapfb_set_update_mode(fbdev, manual_update ?
  1517. OMAPFB_MANUAL_UPDATE : OMAPFB_AUTO_UPDATE);
  1518. init_state++;
  1519. r = fbdev->panel->enable(fbdev->panel);
  1520. if (r)
  1521. goto cleanup;
  1522. init_state++;
  1523. r = omapfb_register_sysfs(fbdev);
  1524. if (r)
  1525. goto cleanup;
  1526. init_state++;
  1527. vram = 0;
  1528. for (i = 0; i < fbdev->mem_desc.region_cnt; i++) {
  1529. r = register_framebuffer(fbdev->fb_info[i]);
  1530. if (r != 0) {
  1531. dev_err(fbdev->dev,
  1532. "registering framebuffer %d failed\n", i);
  1533. goto cleanup;
  1534. }
  1535. vram += fbdev->mem_desc.region[i].size;
  1536. }
  1537. fbdev->state = OMAPFB_ACTIVE;
  1538. panel = fbdev->panel;
  1539. phz = panel->pixel_clock * 1000;
  1540. hhz = phz * 10 / (panel->hfp + panel->x_res + panel->hbp + panel->hsw);
  1541. vhz = hhz / (panel->vfp + panel->y_res + panel->vbp + panel->vsw);
  1542. omapfb_dev = fbdev;
  1543. pr_info("omapfb: Framebuffer initialized. Total vram %lu planes %d\n",
  1544. vram, fbdev->mem_desc.region_cnt);
  1545. pr_info("omapfb: Pixclock %lu kHz hfreq %lu.%lu kHz "
  1546. "vfreq %lu.%lu Hz\n",
  1547. phz / 1000, hhz / 10000, hhz % 10, vhz / 10, vhz % 10);
  1548. return 0;
  1549. cleanup:
  1550. omapfb_free_resources(fbdev, init_state);
  1551. return r;
  1552. }
  1553. static int omapfb_probe(struct platform_device *pdev)
  1554. {
  1555. BUG_ON(fbdev_pdev != NULL);
  1556. /* Delay actual initialization until the LCD is registered */
  1557. fbdev_pdev = pdev;
  1558. if (fbdev_panel != NULL)
  1559. omapfb_do_probe(fbdev_pdev, fbdev_panel);
  1560. return 0;
  1561. }
  1562. void omapfb_register_panel(struct lcd_panel *panel)
  1563. {
  1564. BUG_ON(fbdev_panel != NULL);
  1565. fbdev_panel = panel;
  1566. if (fbdev_pdev != NULL)
  1567. omapfb_do_probe(fbdev_pdev, fbdev_panel);
  1568. }
  1569. /* Called when the device is being detached from the driver */
  1570. static int omapfb_remove(struct platform_device *pdev)
  1571. {
  1572. struct omapfb_device *fbdev = platform_get_drvdata(pdev);
  1573. enum omapfb_state saved_state = fbdev->state;
  1574. /* FIXME: wait till completion of pending events */
  1575. fbdev->state = OMAPFB_DISABLED;
  1576. omapfb_free_resources(fbdev, saved_state);
  1577. return 0;
  1578. }
  1579. /* PM suspend */
  1580. static int omapfb_suspend(struct platform_device *pdev, pm_message_t mesg)
  1581. {
  1582. struct omapfb_device *fbdev = platform_get_drvdata(pdev);
  1583. omapfb_blank(VESA_POWERDOWN, fbdev->fb_info[0]);
  1584. return 0;
  1585. }
  1586. /* PM resume */
  1587. static int omapfb_resume(struct platform_device *pdev)
  1588. {
  1589. struct omapfb_device *fbdev = platform_get_drvdata(pdev);
  1590. omapfb_blank(VESA_NO_BLANKING, fbdev->fb_info[0]);
  1591. return 0;
  1592. }
  1593. static struct platform_driver omapfb_driver = {
  1594. .probe = omapfb_probe,
  1595. .remove = omapfb_remove,
  1596. .suspend = omapfb_suspend,
  1597. .resume = omapfb_resume,
  1598. .driver = {
  1599. .name = MODULE_NAME,
  1600. .owner = THIS_MODULE,
  1601. },
  1602. };
  1603. #ifndef MODULE
  1604. /* Process kernel command line parameters */
  1605. static int __init omapfb_setup(char *options)
  1606. {
  1607. char *this_opt = NULL;
  1608. int r = 0;
  1609. pr_debug("omapfb: options %s\n", options);
  1610. if (!options || !*options)
  1611. return 0;
  1612. while (!r && (this_opt = strsep(&options, ",")) != NULL) {
  1613. if (!strncmp(this_opt, "accel", 5))
  1614. def_accel = 1;
  1615. else if (!strncmp(this_opt, "vram:", 5)) {
  1616. char *suffix;
  1617. unsigned long vram;
  1618. vram = (simple_strtoul(this_opt + 5, &suffix, 0));
  1619. switch (suffix[0]) {
  1620. case '\0':
  1621. break;
  1622. case 'm':
  1623. case 'M':
  1624. vram *= 1024;
  1625. /* Fall through */
  1626. case 'k':
  1627. case 'K':
  1628. vram *= 1024;
  1629. break;
  1630. default:
  1631. pr_debug("omapfb: invalid vram suffix %c\n",
  1632. suffix[0]);
  1633. r = -1;
  1634. }
  1635. def_vram[def_vram_cnt++] = vram;
  1636. }
  1637. else if (!strncmp(this_opt, "vxres:", 6))
  1638. def_vxres = simple_strtoul(this_opt + 6, NULL, 0);
  1639. else if (!strncmp(this_opt, "vyres:", 6))
  1640. def_vyres = simple_strtoul(this_opt + 6, NULL, 0);
  1641. else if (!strncmp(this_opt, "rotate:", 7))
  1642. def_rotate = (simple_strtoul(this_opt + 7, NULL, 0));
  1643. else if (!strncmp(this_opt, "mirror:", 7))
  1644. def_mirror = (simple_strtoul(this_opt + 7, NULL, 0));
  1645. else if (!strncmp(this_opt, "manual_update", 13))
  1646. manual_update = 1;
  1647. else {
  1648. pr_debug("omapfb: invalid option\n");
  1649. r = -1;
  1650. }
  1651. }
  1652. return r;
  1653. }
  1654. #endif
  1655. /* Register both the driver and the device */
  1656. static int __init omapfb_init(void)
  1657. {
  1658. #ifndef MODULE
  1659. char *option;
  1660. if (fb_get_options("omapfb", &option))
  1661. return -ENODEV;
  1662. omapfb_setup(option);
  1663. #endif
  1664. /* Register the driver with LDM */
  1665. if (platform_driver_register(&omapfb_driver)) {
  1666. pr_debug("failed to register omapfb driver\n");
  1667. return -ENODEV;
  1668. }
  1669. return 0;
  1670. }
  1671. static void __exit omapfb_cleanup(void)
  1672. {
  1673. platform_driver_unregister(&omapfb_driver);
  1674. }
  1675. module_param_named(accel, def_accel, uint, 0664);
  1676. module_param_array_named(vram, def_vram, ulong, &def_vram_cnt, 0664);
  1677. module_param_named(vxres, def_vxres, long, 0664);
  1678. module_param_named(vyres, def_vyres, long, 0664);
  1679. module_param_named(rotate, def_rotate, uint, 0664);
  1680. module_param_named(mirror, def_mirror, uint, 0664);
  1681. module_param_named(manual_update, manual_update, bool, 0664);
  1682. module_init(omapfb_init);
  1683. module_exit(omapfb_cleanup);
  1684. MODULE_DESCRIPTION("TI OMAP framebuffer driver");
  1685. MODULE_AUTHOR("Imre Deak <imre.deak@nokia.com>");
  1686. MODULE_LICENSE("GPL");