omapfb_main.c 47 KB

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