omapfb_main.c 48 KB

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