skeletonfb.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /*
  2. * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device
  3. *
  4. * Modified to new api Jan 2001 by James Simmons (jsimmons@transvirtual.com)
  5. *
  6. * Created 28 Dec 1997 by Geert Uytterhoeven
  7. *
  8. *
  9. * I have started rewriting this driver as a example of the upcoming new API
  10. * The primary goal is to remove the console code from fbdev and place it
  11. * into fbcon.c. This reduces the code and makes writing a new fbdev driver
  12. * easy since the author doesn't need to worry about console internals. It
  13. * also allows the ability to run fbdev without a console/tty system on top
  14. * of it.
  15. *
  16. * First the roles of struct fb_info and struct display have changed. Struct
  17. * display will go away. The way the the new framebuffer console code will
  18. * work is that it will act to translate data about the tty/console in
  19. * struct vc_data to data in a device independent way in struct fb_info. Then
  20. * various functions in struct fb_ops will be called to store the device
  21. * dependent state in the par field in struct fb_info and to change the
  22. * hardware to that state. This allows a very clean separation of the fbdev
  23. * layer from the console layer. It also allows one to use fbdev on its own
  24. * which is a bounus for embedded devices. The reason this approach works is
  25. * for each framebuffer device when used as a tty/console device is allocated
  26. * a set of virtual terminals to it. Only one virtual terminal can be active
  27. * per framebuffer device. We already have all the data we need in struct
  28. * vc_data so why store a bunch of colormaps and other fbdev specific data
  29. * per virtual terminal.
  30. *
  31. * As you can see doing this makes the con parameter pretty much useless
  32. * for struct fb_ops functions, as it should be. Also having struct
  33. * fb_var_screeninfo and other data in fb_info pretty much eliminates the
  34. * need for get_fix and get_var. Once all drivers use the fix, var, and cmap
  35. * fbcon can be written around these fields. This will also eliminate the
  36. * need to regenerate struct fb_var_screeninfo, struct fb_fix_screeninfo
  37. * struct fb_cmap every time get_var, get_fix, get_cmap functions are called
  38. * as many drivers do now.
  39. *
  40. * This file is subject to the terms and conditions of the GNU General Public
  41. * License. See the file COPYING in the main directory of this archive for
  42. * more details.
  43. */
  44. #include <linux/module.h>
  45. #include <linux/kernel.h>
  46. #include <linux/errno.h>
  47. #include <linux/string.h>
  48. #include <linux/mm.h>
  49. #include <linux/tty.h>
  50. #include <linux/slab.h>
  51. #include <linux/delay.h>
  52. #include <linux/fb.h>
  53. #include <linux/init.h>
  54. /*
  55. * This is just simple sample code.
  56. *
  57. * No warranty that it actually compiles.
  58. * Even less warranty that it actually works :-)
  59. */
  60. /*
  61. * If your driver supports multiple boards, you should make the
  62. * below data types arrays, or allocate them dynamically (using kmalloc()).
  63. */
  64. /*
  65. * This structure defines the hardware state of the graphics card. Normally
  66. * you place this in a header file in linux/include/video. This file usually
  67. * also includes register information. That allows other driver subsystems
  68. * and userland applications the ability to use the same header file to
  69. * avoid duplicate work and easy porting of software.
  70. */
  71. struct xxx_par;
  72. /*
  73. * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo
  74. * if we don't use modedb. If we do use modedb see xxxfb_init how to use it
  75. * to get a fb_var_screeninfo. Otherwise define a default var as well.
  76. */
  77. static struct fb_fix_screeninfo xxxfb_fix __initdata = {
  78. .id = "FB's name",
  79. .type = FB_TYPE_PACKED_PIXELS,
  80. .visual = FB_VISUAL_PSEUDOCOLOR,
  81. .xpanstep = 1,
  82. .ypanstep = 1,
  83. .ywrapstep = 1,
  84. .accel = FB_ACCEL_NONE,
  85. };
  86. /*
  87. * Modern graphical hardware not only supports pipelines but some
  88. * also support multiple monitors where each display can have its
  89. * its own unique data. In this case each display could be
  90. * represented by a separate framebuffer device thus a separate
  91. * struct fb_info. Now the struct xxx_par represents the graphics
  92. * hardware state thus only one exist per card. In this case the
  93. * struct xxx_par for each graphics card would be shared between
  94. * every struct fb_info that represents a framebuffer on that card.
  95. * This allows when one display changes it video resolution (info->var)
  96. * the other displays know instantly. Each display can always be
  97. * aware of the entire hardware state that affects it because they share
  98. * the same xxx_par struct. The other side of the coin is multiple
  99. * graphics cards that pass data around until it is finally displayed
  100. * on one monitor. Such examples are the voodoo 1 cards and high end
  101. * NUMA graphics servers. For this case we have a bunch of pars, each
  102. * one that represents a graphics state, that belong to one struct
  103. * fb_info. Their you would want to have *par point to a array of device
  104. * states and have each struct fb_ops function deal with all those
  105. * states. I hope this covers every possible hardware design. If not
  106. * feel free to send your ideas at jsimmons@users.sf.net
  107. */
  108. /*
  109. * If your driver supports multiple boards or it supports multiple
  110. * framebuffers, you should make these arrays, or allocate them
  111. * dynamically (using kmalloc()).
  112. */
  113. static struct fb_info info;
  114. /*
  115. * Each one represents the state of the hardware. Most hardware have
  116. * just one hardware state. These here represent the default state(s).
  117. */
  118. static struct xxx_par __initdata current_par;
  119. int xxxfb_init(void);
  120. int xxxfb_setup(char*);
  121. /**
  122. * xxxfb_open - Optional function. Called when the framebuffer is
  123. * first accessed.
  124. * @info: frame buffer structure that represents a single frame buffer
  125. * @user: tell us if the userland (value=1) or the console is accessing
  126. * the framebuffer.
  127. *
  128. * This function is the first function called in the framebuffer api.
  129. * Usually you don't need to provide this function. The case where it
  130. * is used is to change from a text mode hardware state to a graphics
  131. * mode state.
  132. *
  133. * Returns negative errno on error, or zero on success.
  134. */
  135. static int xxxfb_open(const struct fb_info *info, int user)
  136. {
  137. return 0;
  138. }
  139. /**
  140. * xxxfb_release - Optional function. Called when the framebuffer
  141. * device is closed.
  142. * @info: frame buffer structure that represents a single frame buffer
  143. * @user: tell us if the userland (value=1) or the console is accessing
  144. * the framebuffer.
  145. *
  146. * Thus function is called when we close /dev/fb or the framebuffer
  147. * console system is released. Usually you don't need this function.
  148. * The case where it is usually used is to go from a graphics state
  149. * to a text mode state.
  150. *
  151. * Returns negative errno on error, or zero on success.
  152. */
  153. static int xxxfb_release(const struct fb_info *info, int user)
  154. {
  155. return 0;
  156. }
  157. /**
  158. * xxxfb_check_var - Optional function. Validates a var passed in.
  159. * @var: frame buffer variable screen structure
  160. * @info: frame buffer structure that represents a single frame buffer
  161. *
  162. * Checks to see if the hardware supports the state requested by
  163. * var passed in. This function does not alter the hardware state!!!
  164. * This means the data stored in struct fb_info and struct xxx_par do
  165. * not change. This includes the var inside of struct fb_info.
  166. * Do NOT change these. This function can be called on its own if we
  167. * intent to only test a mode and not actually set it. The stuff in
  168. * modedb.c is a example of this. If the var passed in is slightly
  169. * off by what the hardware can support then we alter the var PASSED in
  170. * to what we can do. If the hardware doesn't support mode change
  171. * a -EINVAL will be returned by the upper layers. You don't need to
  172. * implement this function then. If you hardware doesn't support
  173. * changing the resolution then this function is not needed. In this
  174. * case the driver woudl just provide a var that represents the static
  175. * state the screen is in.
  176. *
  177. * Returns negative errno on error, or zero on success.
  178. */
  179. static int xxxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  180. {
  181. const struct xxx_par *par = (const struct xxx_par *) info->par;
  182. /* ... */
  183. return 0;
  184. }
  185. /**
  186. * xxxfb_set_par - Optional function. Alters the hardware state.
  187. * @info: frame buffer structure that represents a single frame buffer
  188. *
  189. * Using the fb_var_screeninfo in fb_info we set the resolution of the
  190. * this particular framebuffer. This function alters the par AND the
  191. * fb_fix_screeninfo stored in fb_info. It doesn't not alter var in
  192. * fb_info since we are using that data. This means we depend on the
  193. * data in var inside fb_info to be supported by the hardware.
  194. * xxxfb_check_var is always called before xxxfb_set_par to ensure this.
  195. * Again if you can't change the resolution you don't need this function.
  196. *
  197. * Returns negative errno on error, or zero on success.
  198. */
  199. static int xxxfb_set_par(struct fb_info *info)
  200. {
  201. struct xxx_par *par = (struct xxx_par *) info->par;
  202. /* ... */
  203. return 0;
  204. }
  205. /**
  206. * xxxfb_setcolreg - Optional function. Sets a color register.
  207. * @regno: Which register in the CLUT we are programming
  208. * @red: The red value which can be up to 16 bits wide
  209. * @green: The green value which can be up to 16 bits wide
  210. * @blue: The blue value which can be up to 16 bits wide.
  211. * @transp: If supported, the alpha value which can be up to 16 bits wide.
  212. * @info: frame buffer info structure
  213. *
  214. * Set a single color register. The values supplied have a 16 bit
  215. * magnitude which needs to be scaled in this function for the hardware.
  216. * Things to take into consideration are how many color registers, if
  217. * any, are supported with the current color visual. With truecolor mode
  218. * no color palettes are supported. Here a pseudo palette is created
  219. * which we store the value in pseudo_palette in struct fb_info. For
  220. * pseudocolor mode we have a limited color palette. To deal with this
  221. * we can program what color is displayed for a particular pixel value.
  222. * DirectColor is similar in that we can program each color field. If
  223. * we have a static colormap we don't need to implement this function.
  224. *
  225. * Returns negative errno on error, or zero on success.
  226. */
  227. static int xxxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
  228. unsigned blue, unsigned transp,
  229. const struct fb_info *info)
  230. {
  231. if (regno >= 256) /* no. of hw registers */
  232. return -EINVAL;
  233. /*
  234. * Program hardware... do anything you want with transp
  235. */
  236. /* grayscale works only partially under directcolor */
  237. if (info->var.grayscale) {
  238. /* grayscale = 0.30*R + 0.59*G + 0.11*B */
  239. red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
  240. }
  241. /* Directcolor:
  242. * var->{color}.offset contains start of bitfield
  243. * var->{color}.length contains length of bitfield
  244. * {hardwarespecific} contains width of DAC
  245. * cmap[X] is programmed to (X << red.offset) | (X << green.offset) | (X << blue.offset)
  246. * RAMDAC[X] is programmed to (red, green, blue)
  247. *
  248. * Pseudocolor:
  249. * uses offset = 0 && length = DAC register width.
  250. * var->{color}.offset is 0
  251. * var->{color}.length contains widht of DAC
  252. * cmap is not used
  253. * DAC[X] is programmed to (red, green, blue)
  254. * Truecolor:
  255. * does not use RAMDAC (usually has 3 of them).
  256. * var->{color}.offset contains start of bitfield
  257. * var->{color}.length contains length of bitfield
  258. * cmap is programmed to (red << red.offset) | (green << green.offset) |
  259. * (blue << blue.offset) | (transp << transp.offset)
  260. * RAMDAC does not exist
  261. */
  262. #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
  263. switch (info->fix.visual) {
  264. case FB_VISUAL_TRUECOLOR:
  265. case FB_VISUAL_PSEUDOCOLOR:
  266. red = CNVT_TOHW(red, info->var.red.length);
  267. green = CNVT_TOHW(green, info->var.green.length);
  268. blue = CNVT_TOHW(blue, info->var.blue.length);
  269. transp = CNVT_TOHW(transp, info->var.transp.length);
  270. break;
  271. case FB_VISUAL_DIRECTCOLOR:
  272. /* example here assumes 8 bit DAC. Might be different
  273. * for your hardware */
  274. red = CNVT_TOHW(red, 8);
  275. green = CNVT_TOHW(green, 8);
  276. blue = CNVT_TOHW(blue, 8);
  277. /* hey, there is bug in transp handling... */
  278. transp = CNVT_TOHW(transp, 8);
  279. break;
  280. }
  281. #undef CNVT_TOHW
  282. /* Truecolor has hardware independent palette */
  283. if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
  284. u32 v;
  285. if (regno >= 16)
  286. return -EINVAL;
  287. v = (red << info->var.red.offset) |
  288. (green << info->var.green.offset) |
  289. (blue << info->var.blue.offset) |
  290. (transp << info->var.transp.offset);
  291. switch (info->var.bits_per_pixel) {
  292. case 8:
  293. /* Yes some hand held devices have this. */
  294. ((u8*)(info->pseudo_palette))[regno] = v;
  295. break;
  296. case 16:
  297. ((u16*)(info->pseudo_palette))[regno] = v;
  298. break;
  299. case 24:
  300. case 32:
  301. ((u32*)(info->pseudo_palette))[regno] = v;
  302. break;
  303. }
  304. return 0;
  305. }
  306. /* ... */
  307. return 0;
  308. }
  309. /**
  310. * xxxfb_pan_display - NOT a required function. Pans the display.
  311. * @var: frame buffer variable screen structure
  312. * @info: frame buffer structure that represents a single frame buffer
  313. *
  314. * Pan (or wrap, depending on the `vmode' field) the display using the
  315. * `xoffset' and `yoffset' fields of the `var' structure.
  316. * If the values don't fit, return -EINVAL.
  317. *
  318. * Returns negative errno on error, or zero on success.
  319. */
  320. static int xxxfb_pan_display(struct fb_var_screeninfo *var,
  321. const struct fb_info *info)
  322. {
  323. /* ... */
  324. return 0;
  325. }
  326. /**
  327. * xxxfb_blank - NOT a required function. Blanks the display.
  328. * @blank_mode: the blank mode we want.
  329. * @info: frame buffer structure that represents a single frame buffer
  330. *
  331. * Blank the screen if blank_mode != 0, else unblank. Return 0 if
  332. * blanking succeeded, != 0 if un-/blanking failed due to e.g. a
  333. * video mode which doesn't support it. Implements VESA suspend
  334. * and powerdown modes on hardware that supports disabling hsync/vsync:
  335. * blank_mode == 2: suspend vsync
  336. * blank_mode == 3: suspend hsync
  337. * blank_mode == 4: powerdown
  338. *
  339. * Returns negative errno on error, or zero on success.
  340. *
  341. */
  342. static int xxxfb_blank(int blank_mode, const struct fb_info *info)
  343. {
  344. /* ... */
  345. return 0;
  346. }
  347. /* ------------ Accelerated Functions --------------------- */
  348. /*
  349. * We provide our own functions if we have hardware acceleration
  350. * or non packed pixel format layouts. If we have no hardware
  351. * acceleration, we can use a generic unaccelerated function. If using
  352. * a pack pixel format just use the functions in cfb_*.c. Each file
  353. * has one of the three different accel functions we support.
  354. */
  355. /**
  356. * xxxfb_fillrect - REQUIRED function. Can use generic routines if
  357. * non acclerated hardware and packed pixel based.
  358. * Draws a rectangle on the screen.
  359. *
  360. * @info: frame buffer structure that represents a single frame buffer
  361. * @region: The structure representing the rectangular region we
  362. * wish to draw to.
  363. *
  364. * This drawing operation places/removes a retangle on the screen
  365. * depending on the rastering operation with the value of color which
  366. * is in the current color depth format.
  367. */
  368. void xxfb_fillrect(struct fb_info *p, const struct fb_fillrect *region)
  369. {
  370. /* Meaning of struct fb_fillrect
  371. *
  372. * @dx: The x and y corrdinates of the upper left hand corner of the
  373. * @dy: area we want to draw to.
  374. * @width: How wide the rectangle is we want to draw.
  375. * @height: How tall the rectangle is we want to draw.
  376. * @color: The color to fill in the rectangle with.
  377. * @rop: The raster operation. We can draw the rectangle with a COPY
  378. * of XOR which provides erasing effect.
  379. */
  380. }
  381. /**
  382. * xxxfb_copyarea - REQUIRED function. Can use generic routines if
  383. * non acclerated hardware and packed pixel based.
  384. * Copies one area of the screen to another area.
  385. *
  386. * @info: frame buffer structure that represents a single frame buffer
  387. * @area: Structure providing the data to copy the framebuffer contents
  388. * from one region to another.
  389. *
  390. * This drawing operation copies a rectangular area from one area of the
  391. * screen to another area.
  392. */
  393. void xxxfb_copyarea(struct fb_info *p, const struct fb_copyarea *area)
  394. {
  395. /*
  396. * @dx: The x and y coordinates of the upper left hand corner of the
  397. * @dy: destination area on the screen.
  398. * @width: How wide the rectangle is we want to copy.
  399. * @height: How tall the rectangle is we want to copy.
  400. * @sx: The x and y coordinates of the upper left hand corner of the
  401. * @sy: source area on the screen.
  402. */
  403. }
  404. /**
  405. * xxxfb_imageblit - REQUIRED function. Can use generic routines if
  406. * non acclerated hardware and packed pixel based.
  407. * Copies a image from system memory to the screen.
  408. *
  409. * @info: frame buffer structure that represents a single frame buffer
  410. * @image: structure defining the image.
  411. *
  412. * This drawing operation draws a image on the screen. It can be a
  413. * mono image (needed for font handling) or a color image (needed for
  414. * tux).
  415. */
  416. void xxxfb_imageblit(struct fb_info *p, const struct fb_image *image)
  417. {
  418. /*
  419. * @dx: The x and y coordinates of the upper left hand corner of the
  420. * @dy: destination area to place the image on the screen.
  421. * @width: How wide the image is we want to copy.
  422. * @height: How tall the image is we want to copy.
  423. * @fg_color: For mono bitmap images this is color data for
  424. * @bg_color: the foreground and background of the image to
  425. * write directly to the frmaebuffer.
  426. * @depth: How many bits represent a single pixel for this image.
  427. * @data: The actual data used to construct the image on the display.
  428. * @cmap: The colormap used for color images.
  429. */
  430. }
  431. /**
  432. * xxxfb_cursor - REQUIRED function. If your hardware lacks support
  433. * for a cursor you can use the default cursor whose
  434. * function is called soft_cursor. It will always
  435. * work since it uses xxxfb_imageblit function which
  436. * is required.
  437. *
  438. * @info: frame buffer structure that represents a single frame buffer
  439. * @cursor: structure defining the cursor to draw.
  440. *
  441. * This operation is used to set or alter the properities of the
  442. * cursor.
  443. *
  444. * Returns negative errno on error, or zero on success.
  445. */
  446. int xxxfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
  447. {
  448. /*
  449. * @set: Which fields we are altering in struct fb_cursor
  450. * @enable: Disable or enable the cursor
  451. * @rop: The bit operation we want to do.
  452. * @mask: This is the cursor mask bitmap.
  453. * @dest: A image of the area we are going to display the cursor.
  454. * Used internally by the driver.
  455. * @hot: The hot spot.
  456. * @image: The actual data for the cursor image.
  457. *
  458. * NOTES ON FLAGS (cursor->set):
  459. *
  460. * FB_CUR_SETIMAGE - the cursor image has changed (cursor->image.data)
  461. * FB_CUR_SETPOS - the cursor position has changed (cursor->image.dx|dy)
  462. * FB_CUR_SETHOT - the cursor hot spot has changed (cursor->hot.dx|dy)
  463. * FB_CUR_SETCMAP - the cursor colors has changed (cursor->fg_color|bg_color)
  464. * FB_CUR_SETSHAPE - the cursor bitmask has changed (cursor->mask)
  465. * FB_CUR_SETSIZE - the cursor size has changed (cursor->width|height)
  466. * FB_CUR_SETALL - everything has changed
  467. *
  468. * NOTES ON ROPs (cursor->rop, Raster Operation)
  469. *
  470. * ROP_XOR - cursor->image.data XOR cursor->mask
  471. * ROP_COPY - curosr->image.data AND cursor->mask
  472. *
  473. * OTHER NOTES:
  474. *
  475. * - fbcon only supports a 2-color cursor (cursor->image.depth = 1)
  476. * - The fb_cursor structure, @cursor, _will_ always contain valid
  477. * fields, whether any particular bitfields in cursor->set is set
  478. * or not.
  479. */
  480. }
  481. /**
  482. * xxxfb_rotate - NOT a required function. If your hardware
  483. * supports rotation the whole screen then
  484. * you would provide a hook for this.
  485. *
  486. * @info: frame buffer structure that represents a single frame buffer
  487. * @angle: The angle we rotate the screen.
  488. *
  489. * This operation is used to set or alter the properities of the
  490. * cursor.
  491. */
  492. void xxxfb_rotate(struct fb_info *info, int angle)
  493. {
  494. }
  495. /**
  496. * xxxfb_poll - NOT a required function. The purpose of this
  497. * function is to provide a way for some process
  498. * to wait until a specific hardware event occurs
  499. * for the framebuffer device.
  500. *
  501. * @info: frame buffer structure that represents a single frame buffer
  502. * @wait: poll table where we store process that await a event.
  503. */
  504. void xxxfb_poll(struct fb_info *info, poll_table *wait)
  505. {
  506. }
  507. /**
  508. * xxxfb_sync - NOT a required function. Normally the accel engine
  509. * for a graphics card take a specific amount of time.
  510. * Often we have to wait for the accelerator to finish
  511. * its operation before we can write to the framebuffer
  512. * so we can have consistent display output.
  513. *
  514. * @info: frame buffer structure that represents a single frame buffer
  515. */
  516. void xxxfb_sync(struct fb_info *info)
  517. {
  518. }
  519. /*
  520. * Initialization
  521. */
  522. int __init xxxfb_init(void)
  523. {
  524. int cmap_len, retval;
  525. /*
  526. * For kernel boot options (in 'video=xxxfb:<options>' format)
  527. */
  528. #ifndef MODULE
  529. char *option = NULL;
  530. if (fb_get_options("xxxfb", &option))
  531. return -ENODEV;
  532. xxxfb_setup(option);
  533. #endif
  534. /*
  535. * Here we set the screen_base to the virtual memory address
  536. * for the framebuffer. Usually we obtain the resource address
  537. * from the bus layer and then translate it to virtual memory
  538. * space via ioremap. Consult ioport.h.
  539. */
  540. info.screen_base = framebuffer_virtual_memory;
  541. info.fbops = &xxxfb_ops;
  542. info.fix = xxxfb_fix;
  543. info.pseudo_palette = pseudo_palette;
  544. /*
  545. * Set up flags to indicate what sort of acceleration your
  546. * driver can provide (pan/wrap/copyarea/etc.) and whether it
  547. * is a module -- see FBINFO_* in include/linux/fb.h
  548. */
  549. info.flags = FBINFO_DEFAULT;
  550. info.par = current_par;
  551. /*
  552. * This should give a reasonable default video mode. The following is
  553. * done when we can set a video mode.
  554. */
  555. if (!mode_option)
  556. mode_option = "640x480@60";
  557. retval = fb_find_mode(&info.var, &info, mode_option, NULL, 0, NULL, 8);
  558. if (!retval || retval == 4)
  559. return -EINVAL;
  560. /* This has to been done !!! */
  561. fb_alloc_cmap(&info.cmap, cmap_len, 0);
  562. /*
  563. * The following is done in the case of having hardware with a static
  564. * mode. If we are setting the mode ourselves we don't call this.
  565. */
  566. info.var = xxxfb_var;
  567. if (register_framebuffer(&info) < 0)
  568. return -EINVAL;
  569. printk(KERN_INFO "fb%d: %s frame buffer device\n", info.node,
  570. info.fix.id);
  571. return 0;
  572. }
  573. /*
  574. * Cleanup
  575. */
  576. static void __exit xxxfb_cleanup(void)
  577. {
  578. /*
  579. * If your driver supports multiple boards, you should unregister and
  580. * clean up all instances.
  581. */
  582. unregister_framebuffer(info);
  583. fb_dealloc_cmap(&info.cmap);
  584. /* ... */
  585. }
  586. /*
  587. * Setup
  588. */
  589. /*
  590. * Only necessary if your driver takes special options,
  591. * otherwise we fall back on the generic fb_setup().
  592. */
  593. int __init xxxfb_setup(char *options)
  594. {
  595. /* Parse user speficied options (`video=xxxfb:') */
  596. }
  597. /* ------------------------------------------------------------------------- */
  598. /*
  599. * Frame buffer operations
  600. */
  601. static struct fb_ops xxxfb_ops = {
  602. .owner = THIS_MODULE,
  603. .fb_open = xxxfb_open,
  604. .fb_read = xxxfb_read,
  605. .fb_write = xxxfb_write,
  606. .fb_release = xxxfb_release,
  607. .fb_check_var = xxxfb_check_var,
  608. .fb_set_par = xxxfb_set_par,
  609. .fb_setcolreg = xxxfb_setcolreg,
  610. .fb_blank = xxxfb_blank,
  611. .fb_pan_display = xxxfb_pan_display,
  612. .fb_fillrect = xxxfb_fillrect, /* Needed !!! */
  613. .fb_copyarea = xxxfb_copyarea, /* Needed !!! */
  614. .fb_imageblit = xxxfb_imageblit, /* Needed !!! */
  615. .fb_cursor = xxxfb_cursor, /* Needed !!! */
  616. .fb_rotate = xxxfb_rotate,
  617. .fb_poll = xxxfb_poll,
  618. .fb_sync = xxxfb_sync,
  619. .fb_ioctl = xxxfb_ioctl,
  620. .fb_mmap = xxxfb_mmap,
  621. };
  622. /* ------------------------------------------------------------------------- */
  623. /*
  624. * Modularization
  625. */
  626. module_init(xxxfb_init);
  627. module_exit(xxxfb_cleanup);
  628. MODULE_LICENSE("GPL");