omapfb_main.c 48 KB

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