omapfb_main.c 48 KB

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