omapfb_main.c 47 KB

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