omapfb_main.c 48 KB

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