omapfb_main.c 48 KB

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