omapfb-main.c 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624
  1. /*
  2. * linux/drivers/video/omap2/omapfb-main.c
  3. *
  4. * Copyright (C) 2008 Nokia Corporation
  5. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  6. *
  7. * Some code and ideas taken from drivers/video/omap/ driver
  8. * by Imre Deak.
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License version 2 as published by
  12. * the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along with
  20. * this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. #include <linux/module.h>
  23. #include <linux/delay.h>
  24. #include <linux/slab.h>
  25. #include <linux/fb.h>
  26. #include <linux/dma-mapping.h>
  27. #include <linux/vmalloc.h>
  28. #include <linux/device.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/omapfb.h>
  31. #include <video/omapdss.h>
  32. #include <video/omapvrfb.h>
  33. #include "omapfb.h"
  34. #define MODULE_NAME "omapfb"
  35. #define OMAPFB_PLANE_XRES_MIN 8
  36. #define OMAPFB_PLANE_YRES_MIN 8
  37. static char *def_mode;
  38. static char *def_vram;
  39. static bool def_vrfb;
  40. static int def_rotate;
  41. static bool def_mirror;
  42. static bool auto_update;
  43. static unsigned int auto_update_freq;
  44. module_param(auto_update, bool, 0);
  45. module_param(auto_update_freq, uint, 0644);
  46. #ifdef DEBUG
  47. bool omapfb_debug;
  48. module_param_named(debug, omapfb_debug, bool, 0644);
  49. static bool omapfb_test_pattern;
  50. module_param_named(test, omapfb_test_pattern, bool, 0644);
  51. #endif
  52. static int omapfb_fb_init(struct omapfb2_device *fbdev, struct fb_info *fbi);
  53. static int omapfb_get_recommended_bpp(struct omapfb2_device *fbdev,
  54. struct omap_dss_device *dssdev);
  55. #ifdef DEBUG
  56. static void draw_pixel(struct fb_info *fbi, int x, int y, unsigned color)
  57. {
  58. struct fb_var_screeninfo *var = &fbi->var;
  59. struct fb_fix_screeninfo *fix = &fbi->fix;
  60. void __iomem *addr = fbi->screen_base;
  61. const unsigned bytespp = var->bits_per_pixel >> 3;
  62. const unsigned line_len = fix->line_length / bytespp;
  63. int r = (color >> 16) & 0xff;
  64. int g = (color >> 8) & 0xff;
  65. int b = (color >> 0) & 0xff;
  66. if (var->bits_per_pixel == 16) {
  67. u16 __iomem *p = (u16 __iomem *)addr;
  68. p += y * line_len + x;
  69. r = r * 32 / 256;
  70. g = g * 64 / 256;
  71. b = b * 32 / 256;
  72. __raw_writew((r << 11) | (g << 5) | (b << 0), p);
  73. } else if (var->bits_per_pixel == 24) {
  74. u8 __iomem *p = (u8 __iomem *)addr;
  75. p += (y * line_len + x) * 3;
  76. __raw_writeb(b, p + 0);
  77. __raw_writeb(g, p + 1);
  78. __raw_writeb(r, p + 2);
  79. } else if (var->bits_per_pixel == 32) {
  80. u32 __iomem *p = (u32 __iomem *)addr;
  81. p += y * line_len + x;
  82. __raw_writel(color, p);
  83. }
  84. }
  85. static void fill_fb(struct fb_info *fbi)
  86. {
  87. struct fb_var_screeninfo *var = &fbi->var;
  88. const short w = var->xres_virtual;
  89. const short h = var->yres_virtual;
  90. void __iomem *addr = fbi->screen_base;
  91. int y, x;
  92. if (!addr)
  93. return;
  94. DBG("fill_fb %dx%d, line_len %d bytes\n", w, h, fbi->fix.line_length);
  95. for (y = 0; y < h; y++) {
  96. for (x = 0; x < w; x++) {
  97. if (x < 20 && y < 20)
  98. draw_pixel(fbi, x, y, 0xffffff);
  99. else if (x < 20 && (y > 20 && y < h - 20))
  100. draw_pixel(fbi, x, y, 0xff);
  101. else if (y < 20 && (x > 20 && x < w - 20))
  102. draw_pixel(fbi, x, y, 0xff00);
  103. else if (x > w - 20 && (y > 20 && y < h - 20))
  104. draw_pixel(fbi, x, y, 0xff0000);
  105. else if (y > h - 20 && (x > 20 && x < w - 20))
  106. draw_pixel(fbi, x, y, 0xffff00);
  107. else if (x == 20 || x == w - 20 ||
  108. y == 20 || y == h - 20)
  109. draw_pixel(fbi, x, y, 0xffffff);
  110. else if (x == y || w - x == h - y)
  111. draw_pixel(fbi, x, y, 0xff00ff);
  112. else if (w - x == y || x == h - y)
  113. draw_pixel(fbi, x, y, 0x00ffff);
  114. else if (x > 20 && y > 20 && x < w - 20 && y < h - 20) {
  115. int t = x * 3 / w;
  116. unsigned r = 0, g = 0, b = 0;
  117. unsigned c;
  118. if (var->bits_per_pixel == 16) {
  119. if (t == 0)
  120. b = (y % 32) * 256 / 32;
  121. else if (t == 1)
  122. g = (y % 64) * 256 / 64;
  123. else if (t == 2)
  124. r = (y % 32) * 256 / 32;
  125. } else {
  126. if (t == 0)
  127. b = (y % 256);
  128. else if (t == 1)
  129. g = (y % 256);
  130. else if (t == 2)
  131. r = (y % 256);
  132. }
  133. c = (r << 16) | (g << 8) | (b << 0);
  134. draw_pixel(fbi, x, y, c);
  135. } else {
  136. draw_pixel(fbi, x, y, 0);
  137. }
  138. }
  139. }
  140. }
  141. #endif
  142. static unsigned omapfb_get_vrfb_offset(const struct omapfb_info *ofbi, int rot)
  143. {
  144. const struct vrfb *vrfb = &ofbi->region->vrfb;
  145. unsigned offset;
  146. switch (rot) {
  147. case FB_ROTATE_UR:
  148. offset = 0;
  149. break;
  150. case FB_ROTATE_CW:
  151. offset = vrfb->yoffset;
  152. break;
  153. case FB_ROTATE_UD:
  154. offset = vrfb->yoffset * OMAP_VRFB_LINE_LEN + vrfb->xoffset;
  155. break;
  156. case FB_ROTATE_CCW:
  157. offset = vrfb->xoffset * OMAP_VRFB_LINE_LEN;
  158. break;
  159. default:
  160. BUG();
  161. return 0;
  162. }
  163. offset *= vrfb->bytespp;
  164. return offset;
  165. }
  166. static u32 omapfb_get_region_rot_paddr(const struct omapfb_info *ofbi, int rot)
  167. {
  168. if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) {
  169. return ofbi->region->vrfb.paddr[rot]
  170. + omapfb_get_vrfb_offset(ofbi, rot);
  171. } else {
  172. return ofbi->region->paddr;
  173. }
  174. }
  175. static u32 omapfb_get_region_paddr(const struct omapfb_info *ofbi)
  176. {
  177. if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB)
  178. return ofbi->region->vrfb.paddr[0];
  179. else
  180. return ofbi->region->paddr;
  181. }
  182. static void __iomem *omapfb_get_region_vaddr(const struct omapfb_info *ofbi)
  183. {
  184. if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB)
  185. return ofbi->region->vrfb.vaddr[0];
  186. else
  187. return ofbi->region->vaddr;
  188. }
  189. static struct omapfb_colormode omapfb_colormodes[] = {
  190. {
  191. .dssmode = OMAP_DSS_COLOR_UYVY,
  192. .bits_per_pixel = 16,
  193. .nonstd = OMAPFB_COLOR_YUV422,
  194. }, {
  195. .dssmode = OMAP_DSS_COLOR_YUV2,
  196. .bits_per_pixel = 16,
  197. .nonstd = OMAPFB_COLOR_YUY422,
  198. }, {
  199. .dssmode = OMAP_DSS_COLOR_ARGB16,
  200. .bits_per_pixel = 16,
  201. .red = { .length = 4, .offset = 8, .msb_right = 0 },
  202. .green = { .length = 4, .offset = 4, .msb_right = 0 },
  203. .blue = { .length = 4, .offset = 0, .msb_right = 0 },
  204. .transp = { .length = 4, .offset = 12, .msb_right = 0 },
  205. }, {
  206. .dssmode = OMAP_DSS_COLOR_RGB16,
  207. .bits_per_pixel = 16,
  208. .red = { .length = 5, .offset = 11, .msb_right = 0 },
  209. .green = { .length = 6, .offset = 5, .msb_right = 0 },
  210. .blue = { .length = 5, .offset = 0, .msb_right = 0 },
  211. .transp = { .length = 0, .offset = 0, .msb_right = 0 },
  212. }, {
  213. .dssmode = OMAP_DSS_COLOR_RGB24P,
  214. .bits_per_pixel = 24,
  215. .red = { .length = 8, .offset = 16, .msb_right = 0 },
  216. .green = { .length = 8, .offset = 8, .msb_right = 0 },
  217. .blue = { .length = 8, .offset = 0, .msb_right = 0 },
  218. .transp = { .length = 0, .offset = 0, .msb_right = 0 },
  219. }, {
  220. .dssmode = OMAP_DSS_COLOR_RGB24U,
  221. .bits_per_pixel = 32,
  222. .red = { .length = 8, .offset = 16, .msb_right = 0 },
  223. .green = { .length = 8, .offset = 8, .msb_right = 0 },
  224. .blue = { .length = 8, .offset = 0, .msb_right = 0 },
  225. .transp = { .length = 0, .offset = 0, .msb_right = 0 },
  226. }, {
  227. .dssmode = OMAP_DSS_COLOR_ARGB32,
  228. .bits_per_pixel = 32,
  229. .red = { .length = 8, .offset = 16, .msb_right = 0 },
  230. .green = { .length = 8, .offset = 8, .msb_right = 0 },
  231. .blue = { .length = 8, .offset = 0, .msb_right = 0 },
  232. .transp = { .length = 8, .offset = 24, .msb_right = 0 },
  233. }, {
  234. .dssmode = OMAP_DSS_COLOR_RGBA32,
  235. .bits_per_pixel = 32,
  236. .red = { .length = 8, .offset = 24, .msb_right = 0 },
  237. .green = { .length = 8, .offset = 16, .msb_right = 0 },
  238. .blue = { .length = 8, .offset = 8, .msb_right = 0 },
  239. .transp = { .length = 8, .offset = 0, .msb_right = 0 },
  240. }, {
  241. .dssmode = OMAP_DSS_COLOR_RGBX32,
  242. .bits_per_pixel = 32,
  243. .red = { .length = 8, .offset = 24, .msb_right = 0 },
  244. .green = { .length = 8, .offset = 16, .msb_right = 0 },
  245. .blue = { .length = 8, .offset = 8, .msb_right = 0 },
  246. .transp = { .length = 0, .offset = 0, .msb_right = 0 },
  247. },
  248. };
  249. static bool cmp_var_to_colormode(struct fb_var_screeninfo *var,
  250. struct omapfb_colormode *color)
  251. {
  252. bool cmp_component(struct fb_bitfield *f1, struct fb_bitfield *f2)
  253. {
  254. return f1->length == f2->length &&
  255. f1->offset == f2->offset &&
  256. f1->msb_right == f2->msb_right;
  257. }
  258. if (var->bits_per_pixel == 0 ||
  259. var->red.length == 0 ||
  260. var->blue.length == 0 ||
  261. var->green.length == 0)
  262. return 0;
  263. return var->bits_per_pixel == color->bits_per_pixel &&
  264. cmp_component(&var->red, &color->red) &&
  265. cmp_component(&var->green, &color->green) &&
  266. cmp_component(&var->blue, &color->blue) &&
  267. cmp_component(&var->transp, &color->transp);
  268. }
  269. static void assign_colormode_to_var(struct fb_var_screeninfo *var,
  270. struct omapfb_colormode *color)
  271. {
  272. var->bits_per_pixel = color->bits_per_pixel;
  273. var->nonstd = color->nonstd;
  274. var->red = color->red;
  275. var->green = color->green;
  276. var->blue = color->blue;
  277. var->transp = color->transp;
  278. }
  279. static int fb_mode_to_dss_mode(struct fb_var_screeninfo *var,
  280. enum omap_color_mode *mode)
  281. {
  282. enum omap_color_mode dssmode;
  283. int i;
  284. /* first match with nonstd field */
  285. if (var->nonstd) {
  286. for (i = 0; i < ARRAY_SIZE(omapfb_colormodes); ++i) {
  287. struct omapfb_colormode *m = &omapfb_colormodes[i];
  288. if (var->nonstd == m->nonstd) {
  289. assign_colormode_to_var(var, m);
  290. *mode = m->dssmode;
  291. return 0;
  292. }
  293. }
  294. return -EINVAL;
  295. }
  296. /* then try exact match of bpp and colors */
  297. for (i = 0; i < ARRAY_SIZE(omapfb_colormodes); ++i) {
  298. struct omapfb_colormode *m = &omapfb_colormodes[i];
  299. if (cmp_var_to_colormode(var, m)) {
  300. assign_colormode_to_var(var, m);
  301. *mode = m->dssmode;
  302. return 0;
  303. }
  304. }
  305. /* match with bpp if user has not filled color fields
  306. * properly */
  307. switch (var->bits_per_pixel) {
  308. case 1:
  309. dssmode = OMAP_DSS_COLOR_CLUT1;
  310. break;
  311. case 2:
  312. dssmode = OMAP_DSS_COLOR_CLUT2;
  313. break;
  314. case 4:
  315. dssmode = OMAP_DSS_COLOR_CLUT4;
  316. break;
  317. case 8:
  318. dssmode = OMAP_DSS_COLOR_CLUT8;
  319. break;
  320. case 12:
  321. dssmode = OMAP_DSS_COLOR_RGB12U;
  322. break;
  323. case 16:
  324. dssmode = OMAP_DSS_COLOR_RGB16;
  325. break;
  326. case 24:
  327. dssmode = OMAP_DSS_COLOR_RGB24P;
  328. break;
  329. case 32:
  330. dssmode = OMAP_DSS_COLOR_RGB24U;
  331. break;
  332. default:
  333. return -EINVAL;
  334. }
  335. for (i = 0; i < ARRAY_SIZE(omapfb_colormodes); ++i) {
  336. struct omapfb_colormode *m = &omapfb_colormodes[i];
  337. if (dssmode == m->dssmode) {
  338. assign_colormode_to_var(var, m);
  339. *mode = m->dssmode;
  340. return 0;
  341. }
  342. }
  343. return -EINVAL;
  344. }
  345. static int check_fb_res_bounds(struct fb_var_screeninfo *var)
  346. {
  347. int xres_min = OMAPFB_PLANE_XRES_MIN;
  348. int xres_max = 2048;
  349. int yres_min = OMAPFB_PLANE_YRES_MIN;
  350. int yres_max = 2048;
  351. /* XXX: some applications seem to set virtual res to 0. */
  352. if (var->xres_virtual == 0)
  353. var->xres_virtual = var->xres;
  354. if (var->yres_virtual == 0)
  355. var->yres_virtual = var->yres;
  356. if (var->xres_virtual < xres_min || var->yres_virtual < yres_min)
  357. return -EINVAL;
  358. if (var->xres < xres_min)
  359. var->xres = xres_min;
  360. if (var->yres < yres_min)
  361. var->yres = yres_min;
  362. if (var->xres > xres_max)
  363. var->xres = xres_max;
  364. if (var->yres > yres_max)
  365. var->yres = yres_max;
  366. if (var->xres > var->xres_virtual)
  367. var->xres = var->xres_virtual;
  368. if (var->yres > var->yres_virtual)
  369. var->yres = var->yres_virtual;
  370. return 0;
  371. }
  372. static void shrink_height(unsigned long max_frame_size,
  373. struct fb_var_screeninfo *var)
  374. {
  375. DBG("can't fit FB into memory, reducing y\n");
  376. var->yres_virtual = max_frame_size /
  377. (var->xres_virtual * var->bits_per_pixel >> 3);
  378. if (var->yres_virtual < OMAPFB_PLANE_YRES_MIN)
  379. var->yres_virtual = OMAPFB_PLANE_YRES_MIN;
  380. if (var->yres > var->yres_virtual)
  381. var->yres = var->yres_virtual;
  382. }
  383. static void shrink_width(unsigned long max_frame_size,
  384. struct fb_var_screeninfo *var)
  385. {
  386. DBG("can't fit FB into memory, reducing x\n");
  387. var->xres_virtual = max_frame_size / var->yres_virtual /
  388. (var->bits_per_pixel >> 3);
  389. if (var->xres_virtual < OMAPFB_PLANE_XRES_MIN)
  390. var->xres_virtual = OMAPFB_PLANE_XRES_MIN;
  391. if (var->xres > var->xres_virtual)
  392. var->xres = var->xres_virtual;
  393. }
  394. static int check_vrfb_fb_size(unsigned long region_size,
  395. const struct fb_var_screeninfo *var)
  396. {
  397. unsigned long min_phys_size = omap_vrfb_min_phys_size(var->xres_virtual,
  398. var->yres_virtual, var->bits_per_pixel >> 3);
  399. return min_phys_size > region_size ? -EINVAL : 0;
  400. }
  401. static int check_fb_size(const struct omapfb_info *ofbi,
  402. struct fb_var_screeninfo *var)
  403. {
  404. unsigned long max_frame_size = ofbi->region->size;
  405. int bytespp = var->bits_per_pixel >> 3;
  406. unsigned long line_size = var->xres_virtual * bytespp;
  407. if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) {
  408. /* One needs to check for both VRFB and OMAPFB limitations. */
  409. if (check_vrfb_fb_size(max_frame_size, var))
  410. shrink_height(omap_vrfb_max_height(
  411. max_frame_size, var->xres_virtual, bytespp) *
  412. line_size, var);
  413. if (check_vrfb_fb_size(max_frame_size, var)) {
  414. DBG("cannot fit FB to memory\n");
  415. return -EINVAL;
  416. }
  417. return 0;
  418. }
  419. DBG("max frame size %lu, line size %lu\n", max_frame_size, line_size);
  420. if (line_size * var->yres_virtual > max_frame_size)
  421. shrink_height(max_frame_size, var);
  422. if (line_size * var->yres_virtual > max_frame_size) {
  423. shrink_width(max_frame_size, var);
  424. line_size = var->xres_virtual * bytespp;
  425. }
  426. if (line_size * var->yres_virtual > max_frame_size) {
  427. DBG("cannot fit FB to memory\n");
  428. return -EINVAL;
  429. }
  430. return 0;
  431. }
  432. /*
  433. * Consider if VRFB assisted rotation is in use and if the virtual space for
  434. * the zero degree view needs to be mapped. The need for mapping also acts as
  435. * the trigger for setting up the hardware on the context in question. This
  436. * ensures that one does not attempt to access the virtual view before the
  437. * hardware is serving the address translations.
  438. */
  439. static int setup_vrfb_rotation(struct fb_info *fbi)
  440. {
  441. struct omapfb_info *ofbi = FB2OFB(fbi);
  442. struct omapfb2_mem_region *rg = ofbi->region;
  443. struct vrfb *vrfb = &rg->vrfb;
  444. struct fb_var_screeninfo *var = &fbi->var;
  445. struct fb_fix_screeninfo *fix = &fbi->fix;
  446. unsigned bytespp;
  447. bool yuv_mode;
  448. enum omap_color_mode mode;
  449. int r;
  450. bool reconf;
  451. if (!rg->size || ofbi->rotation_type != OMAP_DSS_ROT_VRFB)
  452. return 0;
  453. DBG("setup_vrfb_rotation\n");
  454. r = fb_mode_to_dss_mode(var, &mode);
  455. if (r)
  456. return r;
  457. bytespp = var->bits_per_pixel >> 3;
  458. yuv_mode = mode == OMAP_DSS_COLOR_YUV2 || mode == OMAP_DSS_COLOR_UYVY;
  459. /* We need to reconfigure VRFB if the resolution changes, if yuv mode
  460. * is enabled/disabled, or if bytes per pixel changes */
  461. /* XXX we shouldn't allow this when framebuffer is mmapped */
  462. reconf = false;
  463. if (yuv_mode != vrfb->yuv_mode)
  464. reconf = true;
  465. else if (bytespp != vrfb->bytespp)
  466. reconf = true;
  467. else if (vrfb->xres != var->xres_virtual ||
  468. vrfb->yres != var->yres_virtual)
  469. reconf = true;
  470. if (vrfb->vaddr[0] && reconf) {
  471. fbi->screen_base = NULL;
  472. fix->smem_start = 0;
  473. fix->smem_len = 0;
  474. iounmap(vrfb->vaddr[0]);
  475. vrfb->vaddr[0] = NULL;
  476. DBG("setup_vrfb_rotation: reset fb\n");
  477. }
  478. if (vrfb->vaddr[0])
  479. return 0;
  480. omap_vrfb_setup(&rg->vrfb, rg->paddr,
  481. var->xres_virtual,
  482. var->yres_virtual,
  483. bytespp, yuv_mode);
  484. /* Now one can ioremap the 0 angle view */
  485. r = omap_vrfb_map_angle(vrfb, var->yres_virtual, 0);
  486. if (r)
  487. return r;
  488. /* used by open/write in fbmem.c */
  489. fbi->screen_base = ofbi->region->vrfb.vaddr[0];
  490. fix->smem_start = ofbi->region->vrfb.paddr[0];
  491. switch (var->nonstd) {
  492. case OMAPFB_COLOR_YUV422:
  493. case OMAPFB_COLOR_YUY422:
  494. fix->line_length =
  495. (OMAP_VRFB_LINE_LEN * var->bits_per_pixel) >> 2;
  496. break;
  497. default:
  498. fix->line_length =
  499. (OMAP_VRFB_LINE_LEN * var->bits_per_pixel) >> 3;
  500. break;
  501. }
  502. fix->smem_len = var->yres_virtual * fix->line_length;
  503. return 0;
  504. }
  505. int dss_mode_to_fb_mode(enum omap_color_mode dssmode,
  506. struct fb_var_screeninfo *var)
  507. {
  508. int i;
  509. for (i = 0; i < ARRAY_SIZE(omapfb_colormodes); ++i) {
  510. struct omapfb_colormode *mode = &omapfb_colormodes[i];
  511. if (dssmode == mode->dssmode) {
  512. assign_colormode_to_var(var, mode);
  513. return 0;
  514. }
  515. }
  516. return -ENOENT;
  517. }
  518. void set_fb_fix(struct fb_info *fbi)
  519. {
  520. struct fb_fix_screeninfo *fix = &fbi->fix;
  521. struct fb_var_screeninfo *var = &fbi->var;
  522. struct omapfb_info *ofbi = FB2OFB(fbi);
  523. struct omapfb2_mem_region *rg = ofbi->region;
  524. DBG("set_fb_fix\n");
  525. /* used by open/write in fbmem.c */
  526. fbi->screen_base = (char __iomem *)omapfb_get_region_vaddr(ofbi);
  527. /* used by mmap in fbmem.c */
  528. if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) {
  529. switch (var->nonstd) {
  530. case OMAPFB_COLOR_YUV422:
  531. case OMAPFB_COLOR_YUY422:
  532. fix->line_length =
  533. (OMAP_VRFB_LINE_LEN * var->bits_per_pixel) >> 2;
  534. break;
  535. default:
  536. fix->line_length =
  537. (OMAP_VRFB_LINE_LEN * var->bits_per_pixel) >> 3;
  538. break;
  539. }
  540. fix->smem_len = var->yres_virtual * fix->line_length;
  541. } else {
  542. fix->line_length =
  543. (var->xres_virtual * var->bits_per_pixel) >> 3;
  544. fix->smem_len = rg->size;
  545. }
  546. fix->smem_start = omapfb_get_region_paddr(ofbi);
  547. fix->type = FB_TYPE_PACKED_PIXELS;
  548. if (var->nonstd)
  549. fix->visual = FB_VISUAL_PSEUDOCOLOR;
  550. else {
  551. switch (var->bits_per_pixel) {
  552. case 32:
  553. case 24:
  554. case 16:
  555. case 12:
  556. fix->visual = FB_VISUAL_TRUECOLOR;
  557. /* 12bpp is stored in 16 bits */
  558. break;
  559. case 1:
  560. case 2:
  561. case 4:
  562. case 8:
  563. fix->visual = FB_VISUAL_PSEUDOCOLOR;
  564. break;
  565. }
  566. }
  567. fix->accel = FB_ACCEL_NONE;
  568. fix->xpanstep = 1;
  569. fix->ypanstep = 1;
  570. }
  571. /* check new var and possibly modify it to be ok */
  572. int check_fb_var(struct fb_info *fbi, struct fb_var_screeninfo *var)
  573. {
  574. struct omapfb_info *ofbi = FB2OFB(fbi);
  575. struct omap_dss_device *display = fb2display(fbi);
  576. enum omap_color_mode mode = 0;
  577. int i;
  578. int r;
  579. DBG("check_fb_var %d\n", ofbi->id);
  580. WARN_ON(!atomic_read(&ofbi->region->lock_count));
  581. r = fb_mode_to_dss_mode(var, &mode);
  582. if (r) {
  583. DBG("cannot convert var to omap dss mode\n");
  584. return r;
  585. }
  586. for (i = 0; i < ofbi->num_overlays; ++i) {
  587. if ((ofbi->overlays[i]->supported_modes & mode) == 0) {
  588. DBG("invalid mode\n");
  589. return -EINVAL;
  590. }
  591. }
  592. if (var->rotate > 3)
  593. return -EINVAL;
  594. if (check_fb_res_bounds(var))
  595. return -EINVAL;
  596. /* When no memory is allocated ignore the size check */
  597. if (ofbi->region->size != 0 && check_fb_size(ofbi, var))
  598. return -EINVAL;
  599. if (var->xres + var->xoffset > var->xres_virtual)
  600. var->xoffset = var->xres_virtual - var->xres;
  601. if (var->yres + var->yoffset > var->yres_virtual)
  602. var->yoffset = var->yres_virtual - var->yres;
  603. DBG("xres = %d, yres = %d, vxres = %d, vyres = %d\n",
  604. var->xres, var->yres,
  605. var->xres_virtual, var->yres_virtual);
  606. if (display && display->driver->get_dimensions) {
  607. u32 w, h;
  608. display->driver->get_dimensions(display, &w, &h);
  609. var->width = DIV_ROUND_CLOSEST(w, 1000);
  610. var->height = DIV_ROUND_CLOSEST(h, 1000);
  611. } else {
  612. var->height = -1;
  613. var->width = -1;
  614. }
  615. var->grayscale = 0;
  616. if (display && display->driver->get_timings) {
  617. struct omap_video_timings timings;
  618. display->driver->get_timings(display, &timings);
  619. /* pixclock in ps, the rest in pixclock */
  620. var->pixclock = timings.pixel_clock != 0 ?
  621. KHZ2PICOS(timings.pixel_clock) :
  622. 0;
  623. var->left_margin = timings.hbp;
  624. var->right_margin = timings.hfp;
  625. var->upper_margin = timings.vbp;
  626. var->lower_margin = timings.vfp;
  627. var->hsync_len = timings.hsw;
  628. var->vsync_len = timings.vsw;
  629. var->sync |= timings.hsync_level == OMAPDSS_SIG_ACTIVE_HIGH ?
  630. FB_SYNC_HOR_HIGH_ACT : 0;
  631. var->sync |= timings.vsync_level == OMAPDSS_SIG_ACTIVE_HIGH ?
  632. FB_SYNC_VERT_HIGH_ACT : 0;
  633. var->vmode = timings.interlace ?
  634. FB_VMODE_INTERLACED : FB_VMODE_NONINTERLACED;
  635. } else {
  636. var->pixclock = 0;
  637. var->left_margin = 0;
  638. var->right_margin = 0;
  639. var->upper_margin = 0;
  640. var->lower_margin = 0;
  641. var->hsync_len = 0;
  642. var->vsync_len = 0;
  643. var->sync = 0;
  644. var->vmode = FB_VMODE_NONINTERLACED;
  645. }
  646. return 0;
  647. }
  648. /*
  649. * ---------------------------------------------------------------------------
  650. * fbdev framework callbacks
  651. * ---------------------------------------------------------------------------
  652. */
  653. static int omapfb_open(struct fb_info *fbi, int user)
  654. {
  655. return 0;
  656. }
  657. static int omapfb_release(struct fb_info *fbi, int user)
  658. {
  659. return 0;
  660. }
  661. static unsigned calc_rotation_offset_dma(const struct fb_var_screeninfo *var,
  662. const struct fb_fix_screeninfo *fix, int rotation)
  663. {
  664. unsigned offset;
  665. offset = var->yoffset * fix->line_length +
  666. var->xoffset * (var->bits_per_pixel >> 3);
  667. return offset;
  668. }
  669. static unsigned calc_rotation_offset_vrfb(const struct fb_var_screeninfo *var,
  670. const struct fb_fix_screeninfo *fix, int rotation)
  671. {
  672. unsigned offset;
  673. if (rotation == FB_ROTATE_UD)
  674. offset = (var->yres_virtual - var->yres) *
  675. fix->line_length;
  676. else if (rotation == FB_ROTATE_CW)
  677. offset = (var->yres_virtual - var->yres) *
  678. (var->bits_per_pixel >> 3);
  679. else
  680. offset = 0;
  681. if (rotation == FB_ROTATE_UR)
  682. offset += var->yoffset * fix->line_length +
  683. var->xoffset * (var->bits_per_pixel >> 3);
  684. else if (rotation == FB_ROTATE_UD)
  685. offset -= var->yoffset * fix->line_length +
  686. var->xoffset * (var->bits_per_pixel >> 3);
  687. else if (rotation == FB_ROTATE_CW)
  688. offset -= var->xoffset * fix->line_length +
  689. var->yoffset * (var->bits_per_pixel >> 3);
  690. else if (rotation == FB_ROTATE_CCW)
  691. offset += var->xoffset * fix->line_length +
  692. var->yoffset * (var->bits_per_pixel >> 3);
  693. return offset;
  694. }
  695. static void omapfb_calc_addr(const struct omapfb_info *ofbi,
  696. const struct fb_var_screeninfo *var,
  697. const struct fb_fix_screeninfo *fix,
  698. int rotation, u32 *paddr)
  699. {
  700. u32 data_start_p;
  701. int offset;
  702. if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB)
  703. data_start_p = omapfb_get_region_rot_paddr(ofbi, rotation);
  704. else
  705. data_start_p = omapfb_get_region_paddr(ofbi);
  706. if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB)
  707. offset = calc_rotation_offset_vrfb(var, fix, rotation);
  708. else
  709. offset = calc_rotation_offset_dma(var, fix, rotation);
  710. data_start_p += offset;
  711. if (offset)
  712. DBG("offset %d, %d = %d\n",
  713. var->xoffset, var->yoffset, offset);
  714. DBG("paddr %x\n", data_start_p);
  715. *paddr = data_start_p;
  716. }
  717. /* setup overlay according to the fb */
  718. int omapfb_setup_overlay(struct fb_info *fbi, struct omap_overlay *ovl,
  719. u16 posx, u16 posy, u16 outw, u16 outh)
  720. {
  721. int r = 0;
  722. struct omapfb_info *ofbi = FB2OFB(fbi);
  723. struct fb_var_screeninfo *var = &fbi->var;
  724. struct fb_fix_screeninfo *fix = &fbi->fix;
  725. enum omap_color_mode mode = 0;
  726. u32 data_start_p = 0;
  727. struct omap_overlay_info info;
  728. int xres, yres;
  729. int screen_width;
  730. int mirror;
  731. int rotation = var->rotate;
  732. int i;
  733. WARN_ON(!atomic_read(&ofbi->region->lock_count));
  734. for (i = 0; i < ofbi->num_overlays; i++) {
  735. if (ovl != ofbi->overlays[i])
  736. continue;
  737. rotation = (rotation + ofbi->rotation[i]) % 4;
  738. break;
  739. }
  740. DBG("setup_overlay %d, posx %d, posy %d, outw %d, outh %d\n", ofbi->id,
  741. posx, posy, outw, outh);
  742. if (rotation == FB_ROTATE_CW || rotation == FB_ROTATE_CCW) {
  743. xres = var->yres;
  744. yres = var->xres;
  745. } else {
  746. xres = var->xres;
  747. yres = var->yres;
  748. }
  749. if (ofbi->region->size)
  750. omapfb_calc_addr(ofbi, var, fix, rotation, &data_start_p);
  751. r = fb_mode_to_dss_mode(var, &mode);
  752. if (r) {
  753. DBG("fb_mode_to_dss_mode failed");
  754. goto err;
  755. }
  756. switch (var->nonstd) {
  757. case OMAPFB_COLOR_YUV422:
  758. case OMAPFB_COLOR_YUY422:
  759. if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) {
  760. screen_width = fix->line_length
  761. / (var->bits_per_pixel >> 2);
  762. break;
  763. }
  764. default:
  765. screen_width = fix->line_length / (var->bits_per_pixel >> 3);
  766. break;
  767. }
  768. ovl->get_overlay_info(ovl, &info);
  769. if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB)
  770. mirror = 0;
  771. else
  772. mirror = ofbi->mirror;
  773. info.paddr = data_start_p;
  774. info.screen_width = screen_width;
  775. info.width = xres;
  776. info.height = yres;
  777. info.color_mode = mode;
  778. info.rotation_type = ofbi->rotation_type;
  779. info.rotation = rotation;
  780. info.mirror = mirror;
  781. info.pos_x = posx;
  782. info.pos_y = posy;
  783. info.out_width = outw;
  784. info.out_height = outh;
  785. r = ovl->set_overlay_info(ovl, &info);
  786. if (r) {
  787. DBG("ovl->setup_overlay_info failed\n");
  788. goto err;
  789. }
  790. return 0;
  791. err:
  792. DBG("setup_overlay failed\n");
  793. return r;
  794. }
  795. /* apply var to the overlay */
  796. int omapfb_apply_changes(struct fb_info *fbi, int init)
  797. {
  798. int r = 0;
  799. struct omapfb_info *ofbi = FB2OFB(fbi);
  800. struct fb_var_screeninfo *var = &fbi->var;
  801. struct omap_overlay *ovl;
  802. u16 posx, posy;
  803. u16 outw, outh;
  804. int i;
  805. #ifdef DEBUG
  806. if (omapfb_test_pattern)
  807. fill_fb(fbi);
  808. #endif
  809. WARN_ON(!atomic_read(&ofbi->region->lock_count));
  810. for (i = 0; i < ofbi->num_overlays; i++) {
  811. ovl = ofbi->overlays[i];
  812. DBG("apply_changes, fb %d, ovl %d\n", ofbi->id, ovl->id);
  813. if (ofbi->region->size == 0) {
  814. /* the fb is not available. disable the overlay */
  815. omapfb_overlay_enable(ovl, 0);
  816. if (!init && ovl->manager)
  817. ovl->manager->apply(ovl->manager);
  818. continue;
  819. }
  820. if (init || (ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
  821. int rotation = (var->rotate + ofbi->rotation[i]) % 4;
  822. if (rotation == FB_ROTATE_CW ||
  823. rotation == FB_ROTATE_CCW) {
  824. outw = var->yres;
  825. outh = var->xres;
  826. } else {
  827. outw = var->xres;
  828. outh = var->yres;
  829. }
  830. } else {
  831. struct omap_overlay_info info;
  832. ovl->get_overlay_info(ovl, &info);
  833. outw = info.out_width;
  834. outh = info.out_height;
  835. }
  836. if (init) {
  837. posx = 0;
  838. posy = 0;
  839. } else {
  840. struct omap_overlay_info info;
  841. ovl->get_overlay_info(ovl, &info);
  842. posx = info.pos_x;
  843. posy = info.pos_y;
  844. }
  845. r = omapfb_setup_overlay(fbi, ovl, posx, posy, outw, outh);
  846. if (r)
  847. goto err;
  848. if (!init && ovl->manager)
  849. ovl->manager->apply(ovl->manager);
  850. }
  851. return 0;
  852. err:
  853. DBG("apply_changes failed\n");
  854. return r;
  855. }
  856. /* checks var and eventually tweaks it to something supported,
  857. * DO NOT MODIFY PAR */
  858. static int omapfb_check_var(struct fb_var_screeninfo *var, struct fb_info *fbi)
  859. {
  860. struct omapfb_info *ofbi = FB2OFB(fbi);
  861. int r;
  862. DBG("check_var(%d)\n", FB2OFB(fbi)->id);
  863. omapfb_get_mem_region(ofbi->region);
  864. r = check_fb_var(fbi, var);
  865. omapfb_put_mem_region(ofbi->region);
  866. return r;
  867. }
  868. /* set the video mode according to info->var */
  869. static int omapfb_set_par(struct fb_info *fbi)
  870. {
  871. struct omapfb_info *ofbi = FB2OFB(fbi);
  872. int r;
  873. DBG("set_par(%d)\n", FB2OFB(fbi)->id);
  874. omapfb_get_mem_region(ofbi->region);
  875. set_fb_fix(fbi);
  876. r = setup_vrfb_rotation(fbi);
  877. if (r)
  878. goto out;
  879. r = omapfb_apply_changes(fbi, 0);
  880. out:
  881. omapfb_put_mem_region(ofbi->region);
  882. return r;
  883. }
  884. static int omapfb_pan_display(struct fb_var_screeninfo *var,
  885. struct fb_info *fbi)
  886. {
  887. struct omapfb_info *ofbi = FB2OFB(fbi);
  888. struct fb_var_screeninfo new_var;
  889. int r;
  890. DBG("pan_display(%d)\n", FB2OFB(fbi)->id);
  891. if (var->xoffset == fbi->var.xoffset &&
  892. var->yoffset == fbi->var.yoffset)
  893. return 0;
  894. new_var = fbi->var;
  895. new_var.xoffset = var->xoffset;
  896. new_var.yoffset = var->yoffset;
  897. fbi->var = new_var;
  898. omapfb_get_mem_region(ofbi->region);
  899. r = omapfb_apply_changes(fbi, 0);
  900. omapfb_put_mem_region(ofbi->region);
  901. return r;
  902. }
  903. static void mmap_user_open(struct vm_area_struct *vma)
  904. {
  905. struct omapfb2_mem_region *rg = vma->vm_private_data;
  906. omapfb_get_mem_region(rg);
  907. atomic_inc(&rg->map_count);
  908. omapfb_put_mem_region(rg);
  909. }
  910. static void mmap_user_close(struct vm_area_struct *vma)
  911. {
  912. struct omapfb2_mem_region *rg = vma->vm_private_data;
  913. omapfb_get_mem_region(rg);
  914. atomic_dec(&rg->map_count);
  915. omapfb_put_mem_region(rg);
  916. }
  917. static struct vm_operations_struct mmap_user_ops = {
  918. .open = mmap_user_open,
  919. .close = mmap_user_close,
  920. };
  921. static int omapfb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)
  922. {
  923. struct omapfb_info *ofbi = FB2OFB(fbi);
  924. struct fb_fix_screeninfo *fix = &fbi->fix;
  925. struct omapfb2_mem_region *rg;
  926. unsigned long off;
  927. unsigned long start;
  928. u32 len;
  929. int r = -EINVAL;
  930. if (vma->vm_end - vma->vm_start == 0)
  931. return 0;
  932. if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
  933. return -EINVAL;
  934. off = vma->vm_pgoff << PAGE_SHIFT;
  935. rg = omapfb_get_mem_region(ofbi->region);
  936. start = omapfb_get_region_paddr(ofbi);
  937. len = fix->smem_len;
  938. if (off >= len)
  939. goto error;
  940. if ((vma->vm_end - vma->vm_start + off) > len)
  941. goto error;
  942. off += start;
  943. DBG("user mmap region start %lx, len %d, off %lx\n", start, len, off);
  944. vma->vm_pgoff = off >> PAGE_SHIFT;
  945. /* VM_IO | VM_DONTEXPAND | VM_DONTDUMP are set by remap_pfn_range() */
  946. vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
  947. vma->vm_ops = &mmap_user_ops;
  948. vma->vm_private_data = rg;
  949. if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
  950. vma->vm_end - vma->vm_start,
  951. vma->vm_page_prot)) {
  952. r = -EAGAIN;
  953. goto error;
  954. }
  955. /* vm_ops.open won't be called for mmap itself. */
  956. atomic_inc(&rg->map_count);
  957. omapfb_put_mem_region(rg);
  958. return 0;
  959. error:
  960. omapfb_put_mem_region(ofbi->region);
  961. return r;
  962. }
  963. /* Store a single color palette entry into a pseudo palette or the hardware
  964. * palette if one is available. For now we support only 16bpp and thus store
  965. * the entry only to the pseudo palette.
  966. */
  967. static int _setcolreg(struct fb_info *fbi, u_int regno, u_int red, u_int green,
  968. u_int blue, u_int transp, int update_hw_pal)
  969. {
  970. /*struct omapfb_info *ofbi = FB2OFB(fbi);*/
  971. /*struct omapfb2_device *fbdev = ofbi->fbdev;*/
  972. struct fb_var_screeninfo *var = &fbi->var;
  973. int r = 0;
  974. enum omapfb_color_format mode = OMAPFB_COLOR_RGB24U; /* XXX */
  975. /*switch (plane->color_mode) {*/
  976. switch (mode) {
  977. case OMAPFB_COLOR_YUV422:
  978. case OMAPFB_COLOR_YUV420:
  979. case OMAPFB_COLOR_YUY422:
  980. r = -EINVAL;
  981. break;
  982. case OMAPFB_COLOR_CLUT_8BPP:
  983. case OMAPFB_COLOR_CLUT_4BPP:
  984. case OMAPFB_COLOR_CLUT_2BPP:
  985. case OMAPFB_COLOR_CLUT_1BPP:
  986. /*
  987. if (fbdev->ctrl->setcolreg)
  988. r = fbdev->ctrl->setcolreg(regno, red, green, blue,
  989. transp, update_hw_pal);
  990. */
  991. /* Fallthrough */
  992. r = -EINVAL;
  993. break;
  994. case OMAPFB_COLOR_RGB565:
  995. case OMAPFB_COLOR_RGB444:
  996. case OMAPFB_COLOR_RGB24P:
  997. case OMAPFB_COLOR_RGB24U:
  998. if (r != 0)
  999. break;
  1000. if (regno < 16) {
  1001. u32 pal;
  1002. pal = ((red >> (16 - var->red.length)) <<
  1003. var->red.offset) |
  1004. ((green >> (16 - var->green.length)) <<
  1005. var->green.offset) |
  1006. (blue >> (16 - var->blue.length));
  1007. ((u32 *)(fbi->pseudo_palette))[regno] = pal;
  1008. }
  1009. break;
  1010. default:
  1011. BUG();
  1012. }
  1013. return r;
  1014. }
  1015. static int omapfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  1016. u_int transp, struct fb_info *info)
  1017. {
  1018. DBG("setcolreg\n");
  1019. return _setcolreg(info, regno, red, green, blue, transp, 1);
  1020. }
  1021. static int omapfb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
  1022. {
  1023. int count, index, r;
  1024. u16 *red, *green, *blue, *transp;
  1025. u16 trans = 0xffff;
  1026. DBG("setcmap\n");
  1027. red = cmap->red;
  1028. green = cmap->green;
  1029. blue = cmap->blue;
  1030. transp = cmap->transp;
  1031. index = cmap->start;
  1032. for (count = 0; count < cmap->len; count++) {
  1033. if (transp)
  1034. trans = *transp++;
  1035. r = _setcolreg(info, index++, *red++, *green++, *blue++, trans,
  1036. count == cmap->len - 1);
  1037. if (r != 0)
  1038. return r;
  1039. }
  1040. return 0;
  1041. }
  1042. static int omapfb_blank(int blank, struct fb_info *fbi)
  1043. {
  1044. struct omapfb_info *ofbi = FB2OFB(fbi);
  1045. struct omapfb2_device *fbdev = ofbi->fbdev;
  1046. struct omap_dss_device *display = fb2display(fbi);
  1047. struct omapfb_display_data *d;
  1048. int r = 0;
  1049. if (!display)
  1050. return -EINVAL;
  1051. omapfb_lock(fbdev);
  1052. d = get_display_data(fbdev, display);
  1053. switch (blank) {
  1054. case FB_BLANK_UNBLANK:
  1055. if (display->state == OMAP_DSS_DISPLAY_ACTIVE)
  1056. goto exit;
  1057. r = display->driver->enable(display);
  1058. if ((display->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) &&
  1059. d->update_mode == OMAPFB_AUTO_UPDATE &&
  1060. !d->auto_update_work_enabled)
  1061. omapfb_start_auto_update(fbdev, display);
  1062. break;
  1063. case FB_BLANK_NORMAL:
  1064. /* FB_BLANK_NORMAL could be implemented.
  1065. * Needs DSS additions. */
  1066. case FB_BLANK_VSYNC_SUSPEND:
  1067. case FB_BLANK_HSYNC_SUSPEND:
  1068. case FB_BLANK_POWERDOWN:
  1069. if (display->state != OMAP_DSS_DISPLAY_ACTIVE)
  1070. goto exit;
  1071. if (d->auto_update_work_enabled)
  1072. omapfb_stop_auto_update(fbdev, display);
  1073. display->driver->disable(display);
  1074. break;
  1075. default:
  1076. r = -EINVAL;
  1077. }
  1078. exit:
  1079. omapfb_unlock(fbdev);
  1080. return r;
  1081. }
  1082. #if 0
  1083. /* XXX fb_read and fb_write are needed for VRFB */
  1084. ssize_t omapfb_write(struct fb_info *info, const char __user *buf,
  1085. size_t count, loff_t *ppos)
  1086. {
  1087. DBG("omapfb_write %d, %lu\n", count, (unsigned long)*ppos);
  1088. /* XXX needed for VRFB */
  1089. return count;
  1090. }
  1091. #endif
  1092. static struct fb_ops omapfb_ops = {
  1093. .owner = THIS_MODULE,
  1094. .fb_open = omapfb_open,
  1095. .fb_release = omapfb_release,
  1096. .fb_fillrect = cfb_fillrect,
  1097. .fb_copyarea = cfb_copyarea,
  1098. .fb_imageblit = cfb_imageblit,
  1099. .fb_blank = omapfb_blank,
  1100. .fb_ioctl = omapfb_ioctl,
  1101. .fb_check_var = omapfb_check_var,
  1102. .fb_set_par = omapfb_set_par,
  1103. .fb_pan_display = omapfb_pan_display,
  1104. .fb_mmap = omapfb_mmap,
  1105. .fb_setcolreg = omapfb_setcolreg,
  1106. .fb_setcmap = omapfb_setcmap,
  1107. /*.fb_write = omapfb_write,*/
  1108. };
  1109. static void omapfb_free_fbmem(struct fb_info *fbi)
  1110. {
  1111. struct omapfb_info *ofbi = FB2OFB(fbi);
  1112. struct omapfb2_device *fbdev = ofbi->fbdev;
  1113. struct omapfb2_mem_region *rg;
  1114. rg = ofbi->region;
  1115. if (rg->token == NULL)
  1116. return;
  1117. WARN_ON(atomic_read(&rg->map_count));
  1118. if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) {
  1119. /* unmap the 0 angle rotation */
  1120. if (rg->vrfb.vaddr[0]) {
  1121. iounmap(rg->vrfb.vaddr[0]);
  1122. rg->vrfb.vaddr[0] = NULL;
  1123. }
  1124. omap_vrfb_release_ctx(&rg->vrfb);
  1125. }
  1126. dma_free_attrs(fbdev->dev, rg->size, rg->token, rg->dma_handle,
  1127. &rg->attrs);
  1128. rg->token = NULL;
  1129. rg->vaddr = NULL;
  1130. rg->paddr = 0;
  1131. rg->alloc = 0;
  1132. rg->size = 0;
  1133. }
  1134. static void clear_fb_info(struct fb_info *fbi)
  1135. {
  1136. memset(&fbi->var, 0, sizeof(fbi->var));
  1137. memset(&fbi->fix, 0, sizeof(fbi->fix));
  1138. strlcpy(fbi->fix.id, MODULE_NAME, sizeof(fbi->fix.id));
  1139. }
  1140. static int omapfb_free_all_fbmem(struct omapfb2_device *fbdev)
  1141. {
  1142. int i;
  1143. DBG("free all fbmem\n");
  1144. for (i = 0; i < fbdev->num_fbs; i++) {
  1145. struct fb_info *fbi = fbdev->fbs[i];
  1146. omapfb_free_fbmem(fbi);
  1147. clear_fb_info(fbi);
  1148. }
  1149. return 0;
  1150. }
  1151. static int omapfb_alloc_fbmem(struct fb_info *fbi, unsigned long size,
  1152. unsigned long paddr)
  1153. {
  1154. struct omapfb_info *ofbi = FB2OFB(fbi);
  1155. struct omapfb2_device *fbdev = ofbi->fbdev;
  1156. struct omapfb2_mem_region *rg;
  1157. void *token;
  1158. DEFINE_DMA_ATTRS(attrs);
  1159. dma_addr_t dma_handle;
  1160. int r;
  1161. rg = ofbi->region;
  1162. rg->paddr = 0;
  1163. rg->vaddr = NULL;
  1164. memset(&rg->vrfb, 0, sizeof rg->vrfb);
  1165. rg->size = 0;
  1166. rg->type = 0;
  1167. rg->alloc = false;
  1168. rg->map = false;
  1169. size = PAGE_ALIGN(size);
  1170. WARN_ONCE(paddr,
  1171. "reserving memory at predefined address not supported\n");
  1172. dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs);
  1173. if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB)
  1174. dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING, &attrs);
  1175. DBG("allocating %lu bytes for fb %d\n", size, ofbi->id);
  1176. token = dma_alloc_attrs(fbdev->dev, size, &dma_handle,
  1177. GFP_KERNEL, &attrs);
  1178. if (token == NULL) {
  1179. dev_err(fbdev->dev, "failed to allocate framebuffer\n");
  1180. return -ENOMEM;
  1181. }
  1182. DBG("allocated VRAM paddr %lx, vaddr %p\n",
  1183. (unsigned long)dma_handle, token);
  1184. if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) {
  1185. r = omap_vrfb_request_ctx(&rg->vrfb);
  1186. if (r) {
  1187. dma_free_attrs(fbdev->dev, size, token, dma_handle,
  1188. &attrs);
  1189. dev_err(fbdev->dev, "vrfb create ctx failed\n");
  1190. return r;
  1191. }
  1192. }
  1193. rg->attrs = attrs;
  1194. rg->token = token;
  1195. rg->dma_handle = dma_handle;
  1196. rg->paddr = (unsigned long)dma_handle;
  1197. rg->vaddr = (void __iomem *)token;
  1198. rg->size = size;
  1199. rg->alloc = 1;
  1200. return 0;
  1201. }
  1202. /* allocate fbmem using display resolution as reference */
  1203. static int omapfb_alloc_fbmem_display(struct fb_info *fbi, unsigned long size,
  1204. unsigned long paddr)
  1205. {
  1206. struct omapfb_info *ofbi = FB2OFB(fbi);
  1207. struct omapfb2_device *fbdev = ofbi->fbdev;
  1208. struct omap_dss_device *display;
  1209. int bytespp;
  1210. display = fb2display(fbi);
  1211. if (!display)
  1212. return 0;
  1213. switch (omapfb_get_recommended_bpp(fbdev, display)) {
  1214. case 16:
  1215. bytespp = 2;
  1216. break;
  1217. case 24:
  1218. bytespp = 4;
  1219. break;
  1220. default:
  1221. bytespp = 4;
  1222. break;
  1223. }
  1224. if (!size) {
  1225. u16 w, h;
  1226. display->driver->get_resolution(display, &w, &h);
  1227. if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB) {
  1228. size = max(omap_vrfb_min_phys_size(w, h, bytespp),
  1229. omap_vrfb_min_phys_size(h, w, bytespp));
  1230. DBG("adjusting fb mem size for VRFB, %u -> %lu\n",
  1231. w * h * bytespp, size);
  1232. } else {
  1233. size = w * h * bytespp;
  1234. }
  1235. }
  1236. if (!size)
  1237. return 0;
  1238. return omapfb_alloc_fbmem(fbi, size, paddr);
  1239. }
  1240. static int omapfb_parse_vram_param(const char *param, int max_entries,
  1241. unsigned long *sizes, unsigned long *paddrs)
  1242. {
  1243. int fbnum;
  1244. unsigned long size;
  1245. unsigned long paddr = 0;
  1246. char *p, *start;
  1247. start = (char *)param;
  1248. while (1) {
  1249. p = start;
  1250. fbnum = simple_strtoul(p, &p, 10);
  1251. if (p == start)
  1252. return -EINVAL;
  1253. if (*p != ':')
  1254. return -EINVAL;
  1255. if (fbnum >= max_entries)
  1256. return -EINVAL;
  1257. size = memparse(p + 1, &p);
  1258. if (!size)
  1259. return -EINVAL;
  1260. paddr = 0;
  1261. if (*p == '@') {
  1262. paddr = simple_strtoul(p + 1, &p, 16);
  1263. if (!paddr)
  1264. return -EINVAL;
  1265. }
  1266. paddrs[fbnum] = paddr;
  1267. sizes[fbnum] = size;
  1268. if (*p == 0)
  1269. break;
  1270. if (*p != ',')
  1271. return -EINVAL;
  1272. ++p;
  1273. start = p;
  1274. }
  1275. return 0;
  1276. }
  1277. static int omapfb_allocate_all_fbs(struct omapfb2_device *fbdev)
  1278. {
  1279. int i, r;
  1280. unsigned long vram_sizes[10];
  1281. unsigned long vram_paddrs[10];
  1282. memset(&vram_sizes, 0, sizeof(vram_sizes));
  1283. memset(&vram_paddrs, 0, sizeof(vram_paddrs));
  1284. if (def_vram && omapfb_parse_vram_param(def_vram, 10,
  1285. vram_sizes, vram_paddrs)) {
  1286. dev_err(fbdev->dev, "failed to parse vram parameter\n");
  1287. memset(&vram_sizes, 0, sizeof(vram_sizes));
  1288. memset(&vram_paddrs, 0, sizeof(vram_paddrs));
  1289. }
  1290. for (i = 0; i < fbdev->num_fbs; i++) {
  1291. /* allocate memory automatically only for fb0, or if
  1292. * excplicitly defined with vram or plat data option */
  1293. if (i == 0 || vram_sizes[i] != 0) {
  1294. r = omapfb_alloc_fbmem_display(fbdev->fbs[i],
  1295. vram_sizes[i], vram_paddrs[i]);
  1296. if (r)
  1297. return r;
  1298. }
  1299. }
  1300. for (i = 0; i < fbdev->num_fbs; i++) {
  1301. struct omapfb_info *ofbi = FB2OFB(fbdev->fbs[i]);
  1302. struct omapfb2_mem_region *rg;
  1303. rg = ofbi->region;
  1304. DBG("region%d phys %08x virt %p size=%lu\n",
  1305. i,
  1306. rg->paddr,
  1307. rg->vaddr,
  1308. rg->size);
  1309. }
  1310. return 0;
  1311. }
  1312. static void omapfb_clear_fb(struct fb_info *fbi)
  1313. {
  1314. const struct fb_fillrect rect = {
  1315. .dx = 0,
  1316. .dy = 0,
  1317. .width = fbi->var.xres_virtual,
  1318. .height = fbi->var.yres_virtual,
  1319. .color = 0,
  1320. .rop = ROP_COPY,
  1321. };
  1322. cfb_fillrect(fbi, &rect);
  1323. }
  1324. int omapfb_realloc_fbmem(struct fb_info *fbi, unsigned long size, int type)
  1325. {
  1326. struct omapfb_info *ofbi = FB2OFB(fbi);
  1327. struct omapfb2_device *fbdev = ofbi->fbdev;
  1328. struct omap_dss_device *display = fb2display(fbi);
  1329. struct omapfb2_mem_region *rg = ofbi->region;
  1330. unsigned long old_size = rg->size;
  1331. unsigned long old_paddr = rg->paddr;
  1332. int old_type = rg->type;
  1333. int r;
  1334. if (type != OMAPFB_MEMTYPE_SDRAM)
  1335. return -EINVAL;
  1336. size = PAGE_ALIGN(size);
  1337. if (old_size == size && old_type == type)
  1338. return 0;
  1339. if (display && display->driver->sync)
  1340. display->driver->sync(display);
  1341. omapfb_free_fbmem(fbi);
  1342. if (size == 0) {
  1343. clear_fb_info(fbi);
  1344. return 0;
  1345. }
  1346. r = omapfb_alloc_fbmem(fbi, size, 0);
  1347. if (r) {
  1348. if (old_size)
  1349. omapfb_alloc_fbmem(fbi, old_size, old_paddr);
  1350. if (rg->size == 0)
  1351. clear_fb_info(fbi);
  1352. return r;
  1353. }
  1354. if (old_size == size)
  1355. return 0;
  1356. if (old_size == 0) {
  1357. DBG("initializing fb %d\n", ofbi->id);
  1358. r = omapfb_fb_init(fbdev, fbi);
  1359. if (r) {
  1360. DBG("omapfb_fb_init failed\n");
  1361. goto err;
  1362. }
  1363. r = omapfb_apply_changes(fbi, 1);
  1364. if (r) {
  1365. DBG("omapfb_apply_changes failed\n");
  1366. goto err;
  1367. }
  1368. } else {
  1369. struct fb_var_screeninfo new_var;
  1370. memcpy(&new_var, &fbi->var, sizeof(new_var));
  1371. r = check_fb_var(fbi, &new_var);
  1372. if (r)
  1373. goto err;
  1374. memcpy(&fbi->var, &new_var, sizeof(fbi->var));
  1375. set_fb_fix(fbi);
  1376. r = setup_vrfb_rotation(fbi);
  1377. if (r)
  1378. goto err;
  1379. }
  1380. omapfb_clear_fb(fbi);
  1381. return 0;
  1382. err:
  1383. omapfb_free_fbmem(fbi);
  1384. clear_fb_info(fbi);
  1385. return r;
  1386. }
  1387. static void omapfb_auto_update_work(struct work_struct *work)
  1388. {
  1389. struct omap_dss_device *dssdev;
  1390. struct omap_dss_driver *dssdrv;
  1391. struct omapfb_display_data *d;
  1392. u16 w, h;
  1393. unsigned int freq;
  1394. struct omapfb2_device *fbdev;
  1395. d = container_of(work, struct omapfb_display_data,
  1396. auto_update_work.work);
  1397. dssdev = d->dssdev;
  1398. dssdrv = dssdev->driver;
  1399. fbdev = d->fbdev;
  1400. if (!dssdrv || !dssdrv->update)
  1401. return;
  1402. if (dssdrv->sync)
  1403. dssdrv->sync(dssdev);
  1404. dssdrv->get_resolution(dssdev, &w, &h);
  1405. dssdrv->update(dssdev, 0, 0, w, h);
  1406. freq = auto_update_freq;
  1407. if (freq == 0)
  1408. freq = 20;
  1409. queue_delayed_work(fbdev->auto_update_wq,
  1410. &d->auto_update_work, HZ / freq);
  1411. }
  1412. void omapfb_start_auto_update(struct omapfb2_device *fbdev,
  1413. struct omap_dss_device *display)
  1414. {
  1415. struct omapfb_display_data *d;
  1416. if (fbdev->auto_update_wq == NULL) {
  1417. struct workqueue_struct *wq;
  1418. wq = create_singlethread_workqueue("omapfb_auto_update");
  1419. if (wq == NULL) {
  1420. dev_err(fbdev->dev, "Failed to create workqueue for "
  1421. "auto-update\n");
  1422. return;
  1423. }
  1424. fbdev->auto_update_wq = wq;
  1425. }
  1426. d = get_display_data(fbdev, display);
  1427. INIT_DELAYED_WORK(&d->auto_update_work, omapfb_auto_update_work);
  1428. d->auto_update_work_enabled = true;
  1429. omapfb_auto_update_work(&d->auto_update_work.work);
  1430. }
  1431. void omapfb_stop_auto_update(struct omapfb2_device *fbdev,
  1432. struct omap_dss_device *display)
  1433. {
  1434. struct omapfb_display_data *d;
  1435. d = get_display_data(fbdev, display);
  1436. cancel_delayed_work_sync(&d->auto_update_work);
  1437. d->auto_update_work_enabled = false;
  1438. }
  1439. /* initialize fb_info, var, fix to something sane based on the display */
  1440. static int omapfb_fb_init(struct omapfb2_device *fbdev, struct fb_info *fbi)
  1441. {
  1442. struct fb_var_screeninfo *var = &fbi->var;
  1443. struct omap_dss_device *display = fb2display(fbi);
  1444. struct omapfb_info *ofbi = FB2OFB(fbi);
  1445. int r = 0;
  1446. fbi->fbops = &omapfb_ops;
  1447. fbi->flags = FBINFO_FLAG_DEFAULT;
  1448. fbi->pseudo_palette = fbdev->pseudo_palette;
  1449. if (ofbi->region->size == 0) {
  1450. clear_fb_info(fbi);
  1451. return 0;
  1452. }
  1453. var->nonstd = 0;
  1454. var->bits_per_pixel = 0;
  1455. var->rotate = def_rotate;
  1456. if (display) {
  1457. u16 w, h;
  1458. int rotation = (var->rotate + ofbi->rotation[0]) % 4;
  1459. display->driver->get_resolution(display, &w, &h);
  1460. if (rotation == FB_ROTATE_CW ||
  1461. rotation == FB_ROTATE_CCW) {
  1462. var->xres = h;
  1463. var->yres = w;
  1464. } else {
  1465. var->xres = w;
  1466. var->yres = h;
  1467. }
  1468. var->xres_virtual = var->xres;
  1469. var->yres_virtual = var->yres;
  1470. if (!var->bits_per_pixel) {
  1471. switch (omapfb_get_recommended_bpp(fbdev, display)) {
  1472. case 16:
  1473. var->bits_per_pixel = 16;
  1474. break;
  1475. case 24:
  1476. var->bits_per_pixel = 32;
  1477. break;
  1478. default:
  1479. dev_err(fbdev->dev, "illegal display "
  1480. "bpp\n");
  1481. return -EINVAL;
  1482. }
  1483. }
  1484. } else {
  1485. /* if there's no display, let's just guess some basic values */
  1486. var->xres = 320;
  1487. var->yres = 240;
  1488. var->xres_virtual = var->xres;
  1489. var->yres_virtual = var->yres;
  1490. if (!var->bits_per_pixel)
  1491. var->bits_per_pixel = 16;
  1492. }
  1493. r = check_fb_var(fbi, var);
  1494. if (r)
  1495. goto err;
  1496. set_fb_fix(fbi);
  1497. r = setup_vrfb_rotation(fbi);
  1498. if (r)
  1499. goto err;
  1500. r = fb_alloc_cmap(&fbi->cmap, 256, 0);
  1501. if (r)
  1502. dev_err(fbdev->dev, "unable to allocate color map memory\n");
  1503. err:
  1504. return r;
  1505. }
  1506. static void fbinfo_cleanup(struct omapfb2_device *fbdev, struct fb_info *fbi)
  1507. {
  1508. fb_dealloc_cmap(&fbi->cmap);
  1509. }
  1510. static void omapfb_free_resources(struct omapfb2_device *fbdev)
  1511. {
  1512. int i;
  1513. DBG("free_resources\n");
  1514. if (fbdev == NULL)
  1515. return;
  1516. for (i = 0; i < fbdev->num_fbs; i++)
  1517. unregister_framebuffer(fbdev->fbs[i]);
  1518. /* free the reserved fbmem */
  1519. omapfb_free_all_fbmem(fbdev);
  1520. for (i = 0; i < fbdev->num_fbs; i++) {
  1521. fbinfo_cleanup(fbdev, fbdev->fbs[i]);
  1522. framebuffer_release(fbdev->fbs[i]);
  1523. }
  1524. for (i = 0; i < fbdev->num_displays; i++) {
  1525. struct omap_dss_device *dssdev = fbdev->displays[i].dssdev;
  1526. if (fbdev->displays[i].auto_update_work_enabled)
  1527. omapfb_stop_auto_update(fbdev, dssdev);
  1528. if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED)
  1529. dssdev->driver->disable(dssdev);
  1530. omap_dss_put_device(dssdev);
  1531. }
  1532. if (fbdev->auto_update_wq != NULL) {
  1533. flush_workqueue(fbdev->auto_update_wq);
  1534. destroy_workqueue(fbdev->auto_update_wq);
  1535. fbdev->auto_update_wq = NULL;
  1536. }
  1537. dev_set_drvdata(fbdev->dev, NULL);
  1538. kfree(fbdev);
  1539. }
  1540. static int omapfb_create_framebuffers(struct omapfb2_device *fbdev)
  1541. {
  1542. int r, i;
  1543. fbdev->num_fbs = 0;
  1544. DBG("create %d framebuffers\n", CONFIG_FB_OMAP2_NUM_FBS);
  1545. /* allocate fb_infos */
  1546. for (i = 0; i < CONFIG_FB_OMAP2_NUM_FBS; i++) {
  1547. struct fb_info *fbi;
  1548. struct omapfb_info *ofbi;
  1549. fbi = framebuffer_alloc(sizeof(struct omapfb_info),
  1550. fbdev->dev);
  1551. if (fbi == NULL) {
  1552. dev_err(fbdev->dev,
  1553. "unable to allocate memory for plane info\n");
  1554. return -ENOMEM;
  1555. }
  1556. clear_fb_info(fbi);
  1557. fbdev->fbs[i] = fbi;
  1558. ofbi = FB2OFB(fbi);
  1559. ofbi->fbdev = fbdev;
  1560. ofbi->id = i;
  1561. ofbi->region = &fbdev->regions[i];
  1562. ofbi->region->id = i;
  1563. init_rwsem(&ofbi->region->lock);
  1564. /* assign these early, so that fb alloc can use them */
  1565. ofbi->rotation_type = def_vrfb ? OMAP_DSS_ROT_VRFB :
  1566. OMAP_DSS_ROT_DMA;
  1567. ofbi->mirror = def_mirror;
  1568. fbdev->num_fbs++;
  1569. }
  1570. DBG("fb_infos allocated\n");
  1571. /* assign overlays for the fbs */
  1572. for (i = 0; i < min(fbdev->num_fbs, fbdev->num_overlays); i++) {
  1573. struct omapfb_info *ofbi = FB2OFB(fbdev->fbs[i]);
  1574. ofbi->overlays[0] = fbdev->overlays[i];
  1575. ofbi->num_overlays = 1;
  1576. }
  1577. /* allocate fb memories */
  1578. r = omapfb_allocate_all_fbs(fbdev);
  1579. if (r) {
  1580. dev_err(fbdev->dev, "failed to allocate fbmem\n");
  1581. return r;
  1582. }
  1583. DBG("fbmems allocated\n");
  1584. /* setup fb_infos */
  1585. for (i = 0; i < fbdev->num_fbs; i++) {
  1586. struct fb_info *fbi = fbdev->fbs[i];
  1587. struct omapfb_info *ofbi = FB2OFB(fbi);
  1588. omapfb_get_mem_region(ofbi->region);
  1589. r = omapfb_fb_init(fbdev, fbi);
  1590. omapfb_put_mem_region(ofbi->region);
  1591. if (r) {
  1592. dev_err(fbdev->dev, "failed to setup fb_info\n");
  1593. return r;
  1594. }
  1595. }
  1596. for (i = 0; i < fbdev->num_fbs; i++) {
  1597. struct fb_info *fbi = fbdev->fbs[i];
  1598. struct omapfb_info *ofbi = FB2OFB(fbi);
  1599. if (ofbi->region->size == 0)
  1600. continue;
  1601. omapfb_clear_fb(fbi);
  1602. }
  1603. DBG("fb_infos initialized\n");
  1604. for (i = 0; i < fbdev->num_fbs; i++) {
  1605. r = register_framebuffer(fbdev->fbs[i]);
  1606. if (r != 0) {
  1607. dev_err(fbdev->dev,
  1608. "registering framebuffer %d failed\n", i);
  1609. return r;
  1610. }
  1611. }
  1612. DBG("framebuffers registered\n");
  1613. for (i = 0; i < fbdev->num_fbs; i++) {
  1614. struct fb_info *fbi = fbdev->fbs[i];
  1615. struct omapfb_info *ofbi = FB2OFB(fbi);
  1616. omapfb_get_mem_region(ofbi->region);
  1617. r = omapfb_apply_changes(fbi, 1);
  1618. omapfb_put_mem_region(ofbi->region);
  1619. if (r) {
  1620. dev_err(fbdev->dev, "failed to change mode\n");
  1621. return r;
  1622. }
  1623. }
  1624. /* Enable fb0 */
  1625. if (fbdev->num_fbs > 0) {
  1626. struct omapfb_info *ofbi = FB2OFB(fbdev->fbs[0]);
  1627. if (ofbi->num_overlays > 0) {
  1628. struct omap_overlay *ovl = ofbi->overlays[0];
  1629. ovl->manager->apply(ovl->manager);
  1630. r = omapfb_overlay_enable(ovl, 1);
  1631. if (r) {
  1632. dev_err(fbdev->dev,
  1633. "failed to enable overlay\n");
  1634. return r;
  1635. }
  1636. }
  1637. }
  1638. DBG("create_framebuffers done\n");
  1639. return 0;
  1640. }
  1641. static int omapfb_mode_to_timings(const char *mode_str,
  1642. struct omap_dss_device *display,
  1643. struct omap_video_timings *timings, u8 *bpp)
  1644. {
  1645. struct fb_info *fbi;
  1646. struct fb_var_screeninfo *var;
  1647. struct fb_ops *fbops;
  1648. int r;
  1649. #ifdef CONFIG_OMAP2_DSS_VENC
  1650. if (strcmp(mode_str, "pal") == 0) {
  1651. *timings = omap_dss_pal_timings;
  1652. *bpp = 24;
  1653. return 0;
  1654. } else if (strcmp(mode_str, "ntsc") == 0) {
  1655. *timings = omap_dss_ntsc_timings;
  1656. *bpp = 24;
  1657. return 0;
  1658. }
  1659. #endif
  1660. /* this is quite a hack, but I wanted to use the modedb and for
  1661. * that we need fb_info and var, so we create dummy ones */
  1662. *bpp = 0;
  1663. fbi = NULL;
  1664. var = NULL;
  1665. fbops = NULL;
  1666. fbi = kzalloc(sizeof(*fbi), GFP_KERNEL);
  1667. if (fbi == NULL) {
  1668. r = -ENOMEM;
  1669. goto err;
  1670. }
  1671. var = kzalloc(sizeof(*var), GFP_KERNEL);
  1672. if (var == NULL) {
  1673. r = -ENOMEM;
  1674. goto err;
  1675. }
  1676. fbops = kzalloc(sizeof(*fbops), GFP_KERNEL);
  1677. if (fbops == NULL) {
  1678. r = -ENOMEM;
  1679. goto err;
  1680. }
  1681. fbi->fbops = fbops;
  1682. r = fb_find_mode(var, fbi, mode_str, NULL, 0, NULL, 24);
  1683. if (r == 0) {
  1684. r = -EINVAL;
  1685. goto err;
  1686. }
  1687. if (display->driver->get_timings) {
  1688. display->driver->get_timings(display, timings);
  1689. } else {
  1690. timings->data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
  1691. timings->de_level = OMAPDSS_SIG_ACTIVE_HIGH;
  1692. timings->sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES;
  1693. }
  1694. timings->pixel_clock = PICOS2KHZ(var->pixclock);
  1695. timings->hbp = var->left_margin;
  1696. timings->hfp = var->right_margin;
  1697. timings->vbp = var->upper_margin;
  1698. timings->vfp = var->lower_margin;
  1699. timings->hsw = var->hsync_len;
  1700. timings->vsw = var->vsync_len;
  1701. timings->x_res = var->xres;
  1702. timings->y_res = var->yres;
  1703. timings->hsync_level = var->sync & FB_SYNC_HOR_HIGH_ACT ?
  1704. OMAPDSS_SIG_ACTIVE_HIGH :
  1705. OMAPDSS_SIG_ACTIVE_LOW;
  1706. timings->vsync_level = var->sync & FB_SYNC_VERT_HIGH_ACT ?
  1707. OMAPDSS_SIG_ACTIVE_HIGH :
  1708. OMAPDSS_SIG_ACTIVE_LOW;
  1709. timings->interlace = var->vmode & FB_VMODE_INTERLACED;
  1710. switch (var->bits_per_pixel) {
  1711. case 16:
  1712. *bpp = 16;
  1713. break;
  1714. case 24:
  1715. case 32:
  1716. default:
  1717. *bpp = 24;
  1718. break;
  1719. }
  1720. r = 0;
  1721. err:
  1722. kfree(fbi);
  1723. kfree(var);
  1724. kfree(fbops);
  1725. return r;
  1726. }
  1727. static int omapfb_set_def_mode(struct omapfb2_device *fbdev,
  1728. struct omap_dss_device *display, char *mode_str)
  1729. {
  1730. int r;
  1731. u8 bpp;
  1732. struct omap_video_timings timings, temp_timings;
  1733. struct omapfb_display_data *d;
  1734. r = omapfb_mode_to_timings(mode_str, display, &timings, &bpp);
  1735. if (r)
  1736. return r;
  1737. d = get_display_data(fbdev, display);
  1738. d->bpp_override = bpp;
  1739. if (display->driver->check_timings) {
  1740. r = display->driver->check_timings(display, &timings);
  1741. if (r)
  1742. return r;
  1743. } else {
  1744. /* If check_timings is not present compare xres and yres */
  1745. if (display->driver->get_timings) {
  1746. display->driver->get_timings(display, &temp_timings);
  1747. if (temp_timings.x_res != timings.x_res ||
  1748. temp_timings.y_res != timings.y_res)
  1749. return -EINVAL;
  1750. }
  1751. }
  1752. if (display->driver->set_timings)
  1753. display->driver->set_timings(display, &timings);
  1754. return 0;
  1755. }
  1756. static int omapfb_get_recommended_bpp(struct omapfb2_device *fbdev,
  1757. struct omap_dss_device *dssdev)
  1758. {
  1759. struct omapfb_display_data *d;
  1760. BUG_ON(dssdev->driver->get_recommended_bpp == NULL);
  1761. d = get_display_data(fbdev, dssdev);
  1762. if (d->bpp_override != 0)
  1763. return d->bpp_override;
  1764. return dssdev->driver->get_recommended_bpp(dssdev);
  1765. }
  1766. static int omapfb_parse_def_modes(struct omapfb2_device *fbdev)
  1767. {
  1768. char *str, *options, *this_opt;
  1769. int r = 0;
  1770. str = kstrdup(def_mode, GFP_KERNEL);
  1771. if (!str)
  1772. return -ENOMEM;
  1773. options = str;
  1774. while (!r && (this_opt = strsep(&options, ",")) != NULL) {
  1775. char *p, *display_str, *mode_str;
  1776. struct omap_dss_device *display;
  1777. int i;
  1778. p = strchr(this_opt, ':');
  1779. if (!p) {
  1780. r = -EINVAL;
  1781. break;
  1782. }
  1783. *p = 0;
  1784. display_str = this_opt;
  1785. mode_str = p + 1;
  1786. display = NULL;
  1787. for (i = 0; i < fbdev->num_displays; ++i) {
  1788. if (strcmp(fbdev->displays[i].dssdev->name,
  1789. display_str) == 0) {
  1790. display = fbdev->displays[i].dssdev;
  1791. break;
  1792. }
  1793. }
  1794. if (!display) {
  1795. r = -EINVAL;
  1796. break;
  1797. }
  1798. r = omapfb_set_def_mode(fbdev, display, mode_str);
  1799. if (r)
  1800. break;
  1801. }
  1802. kfree(str);
  1803. return r;
  1804. }
  1805. static void fb_videomode_to_omap_timings(struct fb_videomode *m,
  1806. struct omap_dss_device *display,
  1807. struct omap_video_timings *t)
  1808. {
  1809. if (display->driver->get_timings) {
  1810. display->driver->get_timings(display, t);
  1811. } else {
  1812. t->data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
  1813. t->de_level = OMAPDSS_SIG_ACTIVE_HIGH;
  1814. t->sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES;
  1815. }
  1816. t->x_res = m->xres;
  1817. t->y_res = m->yres;
  1818. t->pixel_clock = PICOS2KHZ(m->pixclock);
  1819. t->hsw = m->hsync_len;
  1820. t->hfp = m->right_margin;
  1821. t->hbp = m->left_margin;
  1822. t->vsw = m->vsync_len;
  1823. t->vfp = m->lower_margin;
  1824. t->vbp = m->upper_margin;
  1825. t->hsync_level = m->sync & FB_SYNC_HOR_HIGH_ACT ?
  1826. OMAPDSS_SIG_ACTIVE_HIGH :
  1827. OMAPDSS_SIG_ACTIVE_LOW;
  1828. t->vsync_level = m->sync & FB_SYNC_VERT_HIGH_ACT ?
  1829. OMAPDSS_SIG_ACTIVE_HIGH :
  1830. OMAPDSS_SIG_ACTIVE_LOW;
  1831. t->interlace = m->vmode & FB_VMODE_INTERLACED;
  1832. }
  1833. static int omapfb_find_best_mode(struct omap_dss_device *display,
  1834. struct omap_video_timings *timings)
  1835. {
  1836. struct fb_monspecs *specs;
  1837. u8 *edid;
  1838. int r, i, best_idx, len;
  1839. if (!display->driver->read_edid)
  1840. return -ENODEV;
  1841. len = 0x80 * 2;
  1842. edid = kmalloc(len, GFP_KERNEL);
  1843. r = display->driver->read_edid(display, edid, len);
  1844. if (r < 0)
  1845. goto err1;
  1846. specs = kzalloc(sizeof(*specs), GFP_KERNEL);
  1847. fb_edid_to_monspecs(edid, specs);
  1848. best_idx = -1;
  1849. for (i = 0; i < specs->modedb_len; ++i) {
  1850. struct fb_videomode *m;
  1851. struct omap_video_timings t;
  1852. m = &specs->modedb[i];
  1853. if (m->pixclock == 0)
  1854. continue;
  1855. /* skip repeated pixel modes */
  1856. if (m->xres == 2880 || m->xres == 1440)
  1857. continue;
  1858. if (m->vmode & FB_VMODE_INTERLACED ||
  1859. m->vmode & FB_VMODE_DOUBLE)
  1860. continue;
  1861. fb_videomode_to_omap_timings(m, display, &t);
  1862. r = display->driver->check_timings(display, &t);
  1863. if (r == 0) {
  1864. best_idx = i;
  1865. break;
  1866. }
  1867. }
  1868. if (best_idx == -1) {
  1869. r = -ENOENT;
  1870. goto err2;
  1871. }
  1872. fb_videomode_to_omap_timings(&specs->modedb[best_idx], display,
  1873. timings);
  1874. r = 0;
  1875. err2:
  1876. fb_destroy_modedb(specs->modedb);
  1877. kfree(specs);
  1878. err1:
  1879. kfree(edid);
  1880. return r;
  1881. }
  1882. static int omapfb_init_display(struct omapfb2_device *fbdev,
  1883. struct omap_dss_device *dssdev)
  1884. {
  1885. struct omap_dss_driver *dssdrv = dssdev->driver;
  1886. struct omapfb_display_data *d;
  1887. int r;
  1888. r = dssdrv->enable(dssdev);
  1889. if (r) {
  1890. dev_warn(fbdev->dev, "Failed to enable display '%s'\n",
  1891. dssdev->name);
  1892. return r;
  1893. }
  1894. d = get_display_data(fbdev, dssdev);
  1895. d->fbdev = fbdev;
  1896. if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) {
  1897. u16 w, h;
  1898. if (auto_update) {
  1899. omapfb_start_auto_update(fbdev, dssdev);
  1900. d->update_mode = OMAPFB_AUTO_UPDATE;
  1901. } else {
  1902. d->update_mode = OMAPFB_MANUAL_UPDATE;
  1903. }
  1904. if (dssdrv->enable_te) {
  1905. r = dssdrv->enable_te(dssdev, 1);
  1906. if (r) {
  1907. dev_err(fbdev->dev, "Failed to set TE\n");
  1908. return r;
  1909. }
  1910. }
  1911. dssdrv->get_resolution(dssdev, &w, &h);
  1912. r = dssdrv->update(dssdev, 0, 0, w, h);
  1913. if (r) {
  1914. dev_err(fbdev->dev,
  1915. "Failed to update display\n");
  1916. return r;
  1917. }
  1918. } else {
  1919. d->update_mode = OMAPFB_AUTO_UPDATE;
  1920. }
  1921. return 0;
  1922. }
  1923. static int omapfb_init_connections(struct omapfb2_device *fbdev,
  1924. struct omap_dss_device *dssdev)
  1925. {
  1926. int i, r;
  1927. struct omap_overlay_manager *mgr = NULL;
  1928. for (i = 0; i < fbdev->num_managers; i++) {
  1929. mgr = fbdev->managers[i];
  1930. if (dssdev->channel == mgr->id)
  1931. break;
  1932. }
  1933. if (i == fbdev->num_managers)
  1934. return -ENODEV;
  1935. if (mgr->output)
  1936. mgr->unset_output(mgr);
  1937. r = mgr->set_output(mgr, dssdev->output);
  1938. if (r)
  1939. return r;
  1940. for (i = 0; i < fbdev->num_overlays; i++) {
  1941. struct omap_overlay *ovl = fbdev->overlays[i];
  1942. if (ovl->manager)
  1943. ovl->unset_manager(ovl);
  1944. r = ovl->set_manager(ovl, mgr);
  1945. if (r)
  1946. dev_warn(fbdev->dev,
  1947. "failed to connect overlay %s to manager %s\n",
  1948. ovl->name, mgr->name);
  1949. }
  1950. return 0;
  1951. }
  1952. static int __init omapfb_probe(struct platform_device *pdev)
  1953. {
  1954. struct omapfb2_device *fbdev = NULL;
  1955. int r = 0;
  1956. int i;
  1957. struct omap_dss_device *def_display;
  1958. struct omap_dss_device *dssdev;
  1959. DBG("omapfb_probe\n");
  1960. if (pdev->num_resources != 0) {
  1961. dev_err(&pdev->dev, "probed for an unknown device\n");
  1962. r = -ENODEV;
  1963. goto err0;
  1964. }
  1965. fbdev = kzalloc(sizeof(struct omapfb2_device), GFP_KERNEL);
  1966. if (fbdev == NULL) {
  1967. r = -ENOMEM;
  1968. goto err0;
  1969. }
  1970. if (def_vrfb && !omap_vrfb_supported()) {
  1971. def_vrfb = 0;
  1972. dev_warn(&pdev->dev, "VRFB is not supported on this hardware, "
  1973. "ignoring the module parameter vrfb=y\n");
  1974. }
  1975. mutex_init(&fbdev->mtx);
  1976. fbdev->dev = &pdev->dev;
  1977. platform_set_drvdata(pdev, fbdev);
  1978. r = 0;
  1979. fbdev->num_displays = 0;
  1980. dssdev = NULL;
  1981. for_each_dss_dev(dssdev) {
  1982. struct omapfb_display_data *d;
  1983. omap_dss_get_device(dssdev);
  1984. if (!dssdev->driver) {
  1985. dev_warn(&pdev->dev, "no driver for display: %s\n",
  1986. dssdev->name);
  1987. omap_dss_put_device(dssdev);
  1988. continue;
  1989. }
  1990. d = &fbdev->displays[fbdev->num_displays++];
  1991. d->dssdev = dssdev;
  1992. if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE)
  1993. d->update_mode = OMAPFB_MANUAL_UPDATE;
  1994. else
  1995. d->update_mode = OMAPFB_AUTO_UPDATE;
  1996. }
  1997. if (r)
  1998. goto cleanup;
  1999. if (fbdev->num_displays == 0) {
  2000. dev_err(&pdev->dev, "no displays\n");
  2001. r = -EINVAL;
  2002. goto cleanup;
  2003. }
  2004. fbdev->num_overlays = omap_dss_get_num_overlays();
  2005. for (i = 0; i < fbdev->num_overlays; i++)
  2006. fbdev->overlays[i] = omap_dss_get_overlay(i);
  2007. fbdev->num_managers = omap_dss_get_num_overlay_managers();
  2008. for (i = 0; i < fbdev->num_managers; i++)
  2009. fbdev->managers[i] = omap_dss_get_overlay_manager(i);
  2010. def_display = NULL;
  2011. for (i = 0; i < fbdev->num_displays; ++i) {
  2012. struct omap_dss_device *dssdev;
  2013. const char *def_name;
  2014. def_name = omapdss_get_default_display_name();
  2015. dssdev = fbdev->displays[i].dssdev;
  2016. if (def_name == NULL ||
  2017. (dssdev->name && strcmp(def_name, dssdev->name) == 0)) {
  2018. def_display = dssdev;
  2019. break;
  2020. }
  2021. }
  2022. if (def_display == NULL) {
  2023. dev_err(fbdev->dev, "failed to find default display\n");
  2024. r = -EINVAL;
  2025. goto cleanup;
  2026. }
  2027. r = omapfb_init_connections(fbdev, def_display);
  2028. if (r) {
  2029. dev_err(fbdev->dev, "failed to init overlay connections\n");
  2030. goto cleanup;
  2031. }
  2032. if (def_mode && strlen(def_mode) > 0) {
  2033. if (omapfb_parse_def_modes(fbdev))
  2034. dev_warn(&pdev->dev, "cannot parse default modes\n");
  2035. } else if (def_display && def_display->driver->set_timings &&
  2036. def_display->driver->check_timings) {
  2037. struct omap_video_timings t;
  2038. r = omapfb_find_best_mode(def_display, &t);
  2039. if (r == 0)
  2040. def_display->driver->set_timings(def_display, &t);
  2041. }
  2042. r = omapfb_create_framebuffers(fbdev);
  2043. if (r)
  2044. goto cleanup;
  2045. for (i = 0; i < fbdev->num_managers; i++) {
  2046. struct omap_overlay_manager *mgr;
  2047. mgr = fbdev->managers[i];
  2048. r = mgr->apply(mgr);
  2049. if (r)
  2050. dev_warn(fbdev->dev, "failed to apply dispc config\n");
  2051. }
  2052. DBG("mgr->apply'ed\n");
  2053. if (def_display) {
  2054. r = omapfb_init_display(fbdev, def_display);
  2055. if (r) {
  2056. dev_err(fbdev->dev,
  2057. "failed to initialize default "
  2058. "display\n");
  2059. goto cleanup;
  2060. }
  2061. }
  2062. DBG("create sysfs for fbs\n");
  2063. r = omapfb_create_sysfs(fbdev);
  2064. if (r) {
  2065. dev_err(fbdev->dev, "failed to create sysfs entries\n");
  2066. goto cleanup;
  2067. }
  2068. return 0;
  2069. cleanup:
  2070. omapfb_free_resources(fbdev);
  2071. err0:
  2072. dev_err(&pdev->dev, "failed to setup omapfb\n");
  2073. return r;
  2074. }
  2075. static int __exit omapfb_remove(struct platform_device *pdev)
  2076. {
  2077. struct omapfb2_device *fbdev = platform_get_drvdata(pdev);
  2078. /* FIXME: wait till completion of pending events */
  2079. omapfb_remove_sysfs(fbdev);
  2080. omapfb_free_resources(fbdev);
  2081. return 0;
  2082. }
  2083. static struct platform_driver omapfb_driver = {
  2084. .remove = __exit_p(omapfb_remove),
  2085. .driver = {
  2086. .name = "omapfb",
  2087. .owner = THIS_MODULE,
  2088. },
  2089. };
  2090. static int __init omapfb_init(void)
  2091. {
  2092. DBG("omapfb_init\n");
  2093. if (platform_driver_probe(&omapfb_driver, omapfb_probe)) {
  2094. printk(KERN_ERR "failed to register omapfb driver\n");
  2095. return -ENODEV;
  2096. }
  2097. return 0;
  2098. }
  2099. static void __exit omapfb_exit(void)
  2100. {
  2101. DBG("omapfb_exit\n");
  2102. platform_driver_unregister(&omapfb_driver);
  2103. }
  2104. module_param_named(mode, def_mode, charp, 0);
  2105. module_param_named(vram, def_vram, charp, 0);
  2106. module_param_named(rotate, def_rotate, int, 0);
  2107. module_param_named(vrfb, def_vrfb, bool, 0);
  2108. module_param_named(mirror, def_mirror, bool, 0);
  2109. /* late_initcall to let panel/ctrl drivers loaded first.
  2110. * I guess better option would be a more dynamic approach,
  2111. * so that omapfb reacts to new panels when they are loaded */
  2112. late_initcall(omapfb_init);
  2113. /*module_init(omapfb_init);*/
  2114. module_exit(omapfb_exit);
  2115. MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@nokia.com>");
  2116. MODULE_DESCRIPTION("OMAP2/3 Framebuffer");
  2117. MODULE_LICENSE("GPL v2");