omapfb_main.c 46 KB

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