omapfb_main.c 48 KB

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