skeletonfb.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  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 framebuffer_alloc() and free them with
  112. * framebuffer_release().
  113. */
  114. static struct fb_info info;
  115. /*
  116. * Each one represents the state of the hardware. Most hardware have
  117. * just one hardware state. These here represent the default state(s).
  118. */
  119. static struct xxx_par __initdata current_par;
  120. int xxxfb_init(void);
  121. int xxxfb_setup(char*);
  122. /**
  123. * xxxfb_open - Optional function. Called when the framebuffer is
  124. * first accessed.
  125. * @info: frame buffer structure that represents a single frame buffer
  126. * @user: tell us if the userland (value=1) or the console is accessing
  127. * the framebuffer.
  128. *
  129. * This function is the first function called in the framebuffer api.
  130. * Usually you don't need to provide this function. The case where it
  131. * is used is to change from a text mode hardware state to a graphics
  132. * mode state.
  133. *
  134. * Returns negative errno on error, or zero on success.
  135. */
  136. static int xxxfb_open(const struct fb_info *info, int user)
  137. {
  138. return 0;
  139. }
  140. /**
  141. * xxxfb_release - Optional function. Called when the framebuffer
  142. * device is closed.
  143. * @info: frame buffer structure that represents a single frame buffer
  144. * @user: tell us if the userland (value=1) or the console is accessing
  145. * the framebuffer.
  146. *
  147. * Thus function is called when we close /dev/fb or the framebuffer
  148. * console system is released. Usually you don't need this function.
  149. * The case where it is usually used is to go from a graphics state
  150. * to a text mode state.
  151. *
  152. * Returns negative errno on error, or zero on success.
  153. */
  154. static int xxxfb_release(const struct fb_info *info, int user)
  155. {
  156. return 0;
  157. }
  158. /**
  159. * xxxfb_check_var - Optional function. Validates a var passed in.
  160. * @var: frame buffer variable screen structure
  161. * @info: frame buffer structure that represents a single frame buffer
  162. *
  163. * Checks to see if the hardware supports the state requested by
  164. * var passed in. This function does not alter the hardware state!!!
  165. * This means the data stored in struct fb_info and struct xxx_par do
  166. * not change. This includes the var inside of struct fb_info.
  167. * Do NOT change these. This function can be called on its own if we
  168. * intent to only test a mode and not actually set it. The stuff in
  169. * modedb.c is a example of this. If the var passed in is slightly
  170. * off by what the hardware can support then we alter the var PASSED in
  171. * to what we can do.
  172. *
  173. * For values that are off, this function must round them _up_ to the
  174. * next value that is supported by the hardware. If the value is
  175. * greater than the highest value supported by the hardware, then this
  176. * function must return -EINVAL.
  177. *
  178. * Exception to the above rule: Some drivers have a fixed mode, ie,
  179. * the hardware is already set at boot up, and cannot be changed. In
  180. * this case, it is more acceptable that this function just return
  181. * a copy of the currently working var (info->var). Better is to not
  182. * implement this function, as the upper layer will do the copying
  183. * of the current var for you.
  184. *
  185. * Note: This is the only function where the contents of var can be
  186. * freely adjusted after the driver has been registered. If you find
  187. * that you have code outside of this function that alters the content
  188. * of var, then you are doing something wrong. Note also that the
  189. * contents of info->var must be left untouched at all times after
  190. * driver registration.
  191. *
  192. * Returns negative errno on error, or zero on success.
  193. */
  194. static int xxxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  195. {
  196. /* ... */
  197. return 0;
  198. }
  199. /**
  200. * xxxfb_set_par - Optional function. Alters the hardware state.
  201. * @info: frame buffer structure that represents a single frame buffer
  202. *
  203. * Using the fb_var_screeninfo in fb_info we set the resolution of the
  204. * this particular framebuffer. This function alters the par AND the
  205. * fb_fix_screeninfo stored in fb_info. It doesn't not alter var in
  206. * fb_info since we are using that data. This means we depend on the
  207. * data in var inside fb_info to be supported by the hardware.
  208. *
  209. * This function is also used to recover/restore the hardware to a
  210. * known working state.
  211. *
  212. * xxxfb_check_var is always called before xxxfb_set_par to ensure that
  213. * the contents of var is always valid.
  214. *
  215. * Again if you can't change the resolution you don't need this function.
  216. *
  217. * However, even if your hardware does not support mode changing,
  218. * a set_par might be needed to at least initialize the hardware to
  219. * a known working state, especially if it came back from another
  220. * process that also modifies the same hardware, such as X.
  221. *
  222. * If this is the case, a combination such as the following should work:
  223. *
  224. * static int xxxfb_check_var(struct fb_var_screeninfo *var,
  225. * struct fb_info *info)
  226. * {
  227. * *var = info->var;
  228. * return 0;
  229. * }
  230. *
  231. * static int xxxfb_set_par(struct fb_info *info)
  232. * {
  233. * init your hardware here
  234. * }
  235. *
  236. * Returns negative errno on error, or zero on success.
  237. */
  238. static int xxxfb_set_par(struct fb_info *info)
  239. {
  240. struct xxx_par *par = info->par;
  241. /* ... */
  242. return 0;
  243. }
  244. /**
  245. * xxxfb_setcolreg - Optional function. Sets a color register.
  246. * @regno: Which register in the CLUT we are programming
  247. * @red: The red value which can be up to 16 bits wide
  248. * @green: The green value which can be up to 16 bits wide
  249. * @blue: The blue value which can be up to 16 bits wide.
  250. * @transp: If supported, the alpha value which can be up to 16 bits wide.
  251. * @info: frame buffer info structure
  252. *
  253. * Set a single color register. The values supplied have a 16 bit
  254. * magnitude which needs to be scaled in this function for the hardware.
  255. * Things to take into consideration are how many color registers, if
  256. * any, are supported with the current color visual. With truecolor mode
  257. * no color palettes are supported. Here a pseudo palette is created
  258. * which we store the value in pseudo_palette in struct fb_info. For
  259. * pseudocolor mode we have a limited color palette. To deal with this
  260. * we can program what color is displayed for a particular pixel value.
  261. * DirectColor is similar in that we can program each color field. If
  262. * we have a static colormap we don't need to implement this function.
  263. *
  264. * Returns negative errno on error, or zero on success.
  265. */
  266. static int xxxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
  267. unsigned blue, unsigned transp,
  268. const struct fb_info *info)
  269. {
  270. if (regno >= 256) /* no. of hw registers */
  271. return -EINVAL;
  272. /*
  273. * Program hardware... do anything you want with transp
  274. */
  275. /* grayscale works only partially under directcolor */
  276. if (info->var.grayscale) {
  277. /* grayscale = 0.30*R + 0.59*G + 0.11*B */
  278. red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
  279. }
  280. /* Directcolor:
  281. * var->{color}.offset contains start of bitfield
  282. * var->{color}.length contains length of bitfield
  283. * {hardwarespecific} contains width of DAC
  284. * pseudo_palette[X] is programmed to (X << red.offset) |
  285. * (X << green.offset) |
  286. * (X << blue.offset)
  287. * RAMDAC[X] is programmed to (red, green, blue)
  288. * color depth = SUM(var->{color}.length)
  289. *
  290. * Pseudocolor:
  291. * var->{color}.offset is 0
  292. * var->{color}.length contains width of DAC or the number of unique
  293. * colors available (color depth)
  294. * pseudo_palette is not used
  295. * RAMDAC[X] is programmed to (red, green, blue)
  296. * color depth = var->{color}.length
  297. *
  298. * Static pseudocolor:
  299. * same as Pseudocolor, but the RAMDAC is not programmed (read-only)
  300. *
  301. * Mono01/Mono10:
  302. * Has only 2 values, black on white or white on black (fg on bg),
  303. * var->{color}.offset is 0
  304. * white = (1 << var->{color}.length) - 1, black = 0
  305. * pseudo_palette is not used
  306. * RAMDAC does not exist
  307. * color depth is always 2
  308. *
  309. * Truecolor:
  310. * does not use RAMDAC (usually has 3 of them).
  311. * var->{color}.offset contains start of bitfield
  312. * var->{color}.length contains length of bitfield
  313. * pseudo_palette is programmed to (red << red.offset) |
  314. * (green << green.offset) |
  315. * (blue << blue.offset) |
  316. * (transp << transp.offset)
  317. * RAMDAC does not exist
  318. * color depth = SUM(var->{color}.length})
  319. *
  320. * The color depth is used by fbcon for choosing the logo and also
  321. * for color palette transformation if color depth < 4
  322. *
  323. * As can be seen from the above, the field bits_per_pixel is _NOT_
  324. * a criteria for describing the color visual.
  325. *
  326. * A common mistake is assuming that bits_per_pixel <= 8 is pseudocolor,
  327. * and higher than that, true/directcolor. This is incorrect, one needs
  328. * to look at the fix->visual.
  329. *
  330. * Another common mistake is using bits_per_pixel to calculate the color
  331. * depth. The bits_per_pixel field does not directly translate to color
  332. * depth. You have to compute for the color depth (using the color
  333. * bitfields) and fix->visual as seen above.
  334. */
  335. /*
  336. * This is the point where the color is converted to something that
  337. * is acceptable by the hardware.
  338. */
  339. #define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
  340. red = CNVT_TOHW(red, info->var.red.length);
  341. green = CNVT_TOHW(green, info->var.green.length);
  342. blue = CNVT_TOHW(blue, info->var.blue.length);
  343. transp = CNVT_TOHW(transp, info->var.transp.length);
  344. #undef CNVT_TOHW
  345. /*
  346. * This is the point where the function feeds the color to the hardware
  347. * palette after converting the colors to something acceptable by
  348. * the hardware. Note, only FB_VISUAL_DIRECTCOLOR and
  349. * FB_VISUAL_PSEUDOCOLOR visuals need to write to the hardware palette.
  350. * If you have code that writes to the hardware CLUT, and it's not
  351. * any of the above visuals, then you are doing something wrong.
  352. */
  353. if (info->fix.visual == FB_VISUAL_DIRECTCOLOR ||
  354. info->fix.visual == FB_VISUAL_TRUECOLOR)
  355. write_{red|green|blue|transp}_to_clut();
  356. /* This is the point were you need to fill up the contents of
  357. * info->pseudo_palette. This structure is used _only_ by fbcon, thus
  358. * it only contains 16 entries to match the number of colors supported
  359. * by the console. The pseudo_palette is used only if the visual is
  360. * in directcolor or truecolor mode. With other visuals, the
  361. * pseudo_palette is not used. (This might change in the future.)
  362. *
  363. * The contents of the pseudo_palette is in raw pixel format. Ie, each
  364. * entry can be written directly to the framebuffer without any conversion.
  365. * The pseudo_palette is (void *). However, if using the generic
  366. * drawing functions (cfb_imageblit, cfb_fillrect), the pseudo_palette
  367. * must be casted to (u32 *) _regardless_ of the bits per pixel. If the
  368. * driver is using its own drawing functions, then it can use whatever
  369. * size it wants.
  370. */
  371. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  372. info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  373. u32 v;
  374. if (regno >= 16)
  375. return -EINVAL;
  376. v = (red << info->var.red.offset) |
  377. (green << info->var.green.offset) |
  378. (blue << info->var.blue.offset) |
  379. (transp << info->var.transp.offset);
  380. ((u32*)(info->pseudo_palette))[regno] = v;
  381. }
  382. /* ... */
  383. return 0;
  384. }
  385. /**
  386. * xxxfb_pan_display - NOT a required function. Pans the display.
  387. * @var: frame buffer variable screen structure
  388. * @info: frame buffer structure that represents a single frame buffer
  389. *
  390. * Pan (or wrap, depending on the `vmode' field) the display using the
  391. * `xoffset' and `yoffset' fields of the `var' structure.
  392. * If the values don't fit, return -EINVAL.
  393. *
  394. * Returns negative errno on error, or zero on success.
  395. */
  396. static int xxxfb_pan_display(struct fb_var_screeninfo *var,
  397. const struct fb_info *info)
  398. {
  399. /*
  400. * If your hardware does not support panning, _do_ _not_ implement this
  401. * function. Creating a dummy function will just confuse user apps.
  402. */
  403. /*
  404. * Note that even if this function is fully functional, a setting of
  405. * 0 in both xpanstep and ypanstep means that this function will never
  406. * get called.
  407. */
  408. /* ... */
  409. return 0;
  410. }
  411. /**
  412. * xxxfb_blank - NOT a required function. Blanks the display.
  413. * @blank_mode: the blank mode we want.
  414. * @info: frame buffer structure that represents a single frame buffer
  415. *
  416. * Blank the screen if blank_mode != FB_BLANK_UNBLANK, else unblank.
  417. * Return 0 if blanking succeeded, != 0 if un-/blanking failed due to
  418. * e.g. a video mode which doesn't support it.
  419. *
  420. * Implements VESA suspend and powerdown modes on hardware that supports
  421. * disabling hsync/vsync:
  422. *
  423. * FB_BLANK_NORMAL = display is blanked, syncs are on.
  424. * FB_BLANK_HSYNC_SUSPEND = hsync off
  425. * FB_BLANK_VSYNC_SUSPEND = vsync off
  426. * FB_BLANK_POWERDOWN = hsync and vsync off
  427. *
  428. * If implementing this function, at least support FB_BLANK_UNBLANK.
  429. * Return !0 for any modes that are unimplemented.
  430. *
  431. */
  432. static int xxxfb_blank(int blank_mode, const struct fb_info *info)
  433. {
  434. /* ... */
  435. return 0;
  436. }
  437. /* ------------ Accelerated Functions --------------------- */
  438. /*
  439. * We provide our own functions if we have hardware acceleration
  440. * or non packed pixel format layouts. If we have no hardware
  441. * acceleration, we can use a generic unaccelerated function. If using
  442. * a pack pixel format just use the functions in cfb_*.c. Each file
  443. * has one of the three different accel functions we support.
  444. */
  445. /**
  446. * xxxfb_fillrect - REQUIRED function. Can use generic routines if
  447. * non acclerated hardware and packed pixel based.
  448. * Draws a rectangle on the screen.
  449. *
  450. * @info: frame buffer structure that represents a single frame buffer
  451. * @region: The structure representing the rectangular region we
  452. * wish to draw to.
  453. *
  454. * This drawing operation places/removes a retangle on the screen
  455. * depending on the rastering operation with the value of color which
  456. * is in the current color depth format.
  457. */
  458. void xxfb_fillrect(struct fb_info *p, const struct fb_fillrect *region)
  459. {
  460. /* Meaning of struct fb_fillrect
  461. *
  462. * @dx: The x and y corrdinates of the upper left hand corner of the
  463. * @dy: area we want to draw to.
  464. * @width: How wide the rectangle is we want to draw.
  465. * @height: How tall the rectangle is we want to draw.
  466. * @color: The color to fill in the rectangle with.
  467. * @rop: The raster operation. We can draw the rectangle with a COPY
  468. * of XOR which provides erasing effect.
  469. */
  470. }
  471. /**
  472. * xxxfb_copyarea - REQUIRED function. Can use generic routines if
  473. * non acclerated hardware and packed pixel based.
  474. * Copies one area of the screen to another area.
  475. *
  476. * @info: frame buffer structure that represents a single frame buffer
  477. * @area: Structure providing the data to copy the framebuffer contents
  478. * from one region to another.
  479. *
  480. * This drawing operation copies a rectangular area from one area of the
  481. * screen to another area.
  482. */
  483. void xxxfb_copyarea(struct fb_info *p, const struct fb_copyarea *area)
  484. {
  485. /*
  486. * @dx: The x and y coordinates of the upper left hand corner of the
  487. * @dy: destination area on the screen.
  488. * @width: How wide the rectangle is we want to copy.
  489. * @height: How tall the rectangle is we want to copy.
  490. * @sx: The x and y coordinates of the upper left hand corner of the
  491. * @sy: source area on the screen.
  492. */
  493. }
  494. /**
  495. * xxxfb_imageblit - REQUIRED function. Can use generic routines if
  496. * non acclerated hardware and packed pixel based.
  497. * Copies a image from system memory to the screen.
  498. *
  499. * @info: frame buffer structure that represents a single frame buffer
  500. * @image: structure defining the image.
  501. *
  502. * This drawing operation draws a image on the screen. It can be a
  503. * mono image (needed for font handling) or a color image (needed for
  504. * tux).
  505. */
  506. void xxxfb_imageblit(struct fb_info *p, const struct fb_image *image)
  507. {
  508. /*
  509. * @dx: The x and y coordinates of the upper left hand corner of the
  510. * @dy: destination area to place the image on the screen.
  511. * @width: How wide the image is we want to copy.
  512. * @height: How tall the image is we want to copy.
  513. * @fg_color: For mono bitmap images this is color data for
  514. * @bg_color: the foreground and background of the image to
  515. * write directly to the frmaebuffer.
  516. * @depth: How many bits represent a single pixel for this image.
  517. * @data: The actual data used to construct the image on the display.
  518. * @cmap: The colormap used for color images.
  519. */
  520. /*
  521. * The generic function, cfb_imageblit, expects that the bitmap scanlines are
  522. * padded to the next byte. Most hardware accelerators may require padding to
  523. * the next u16 or the next u32. If that is the case, the driver can specify
  524. * this by setting info->pixmap.scan_align = 2 or 4. See a more
  525. * comprehensive description of the pixmap below.
  526. */
  527. }
  528. /**
  529. * xxxfb_cursor - OPTIONAL. If your hardware lacks support
  530. * for a cursor, leave this field NULL.
  531. *
  532. * @info: frame buffer structure that represents a single frame buffer
  533. * @cursor: structure defining the cursor to draw.
  534. *
  535. * This operation is used to set or alter the properities of the
  536. * cursor.
  537. *
  538. * Returns negative errno on error, or zero on success.
  539. */
  540. int xxxfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
  541. {
  542. /*
  543. * @set: Which fields we are altering in struct fb_cursor
  544. * @enable: Disable or enable the cursor
  545. * @rop: The bit operation we want to do.
  546. * @mask: This is the cursor mask bitmap.
  547. * @dest: A image of the area we are going to display the cursor.
  548. * Used internally by the driver.
  549. * @hot: The hot spot.
  550. * @image: The actual data for the cursor image.
  551. *
  552. * NOTES ON FLAGS (cursor->set):
  553. *
  554. * FB_CUR_SETIMAGE - the cursor image has changed (cursor->image.data)
  555. * FB_CUR_SETPOS - the cursor position has changed (cursor->image.dx|dy)
  556. * FB_CUR_SETHOT - the cursor hot spot has changed (cursor->hot.dx|dy)
  557. * FB_CUR_SETCMAP - the cursor colors has changed (cursor->fg_color|bg_color)
  558. * FB_CUR_SETSHAPE - the cursor bitmask has changed (cursor->mask)
  559. * FB_CUR_SETSIZE - the cursor size has changed (cursor->width|height)
  560. * FB_CUR_SETALL - everything has changed
  561. *
  562. * NOTES ON ROPs (cursor->rop, Raster Operation)
  563. *
  564. * ROP_XOR - cursor->image.data XOR cursor->mask
  565. * ROP_COPY - curosr->image.data AND cursor->mask
  566. *
  567. * OTHER NOTES:
  568. *
  569. * - fbcon only supports a 2-color cursor (cursor->image.depth = 1)
  570. * - The fb_cursor structure, @cursor, _will_ always contain valid
  571. * fields, whether any particular bitfields in cursor->set is set
  572. * or not.
  573. */
  574. }
  575. /**
  576. * xxxfb_rotate - NOT a required function. If your hardware
  577. * supports rotation the whole screen then
  578. * you would provide a hook for this.
  579. *
  580. * @info: frame buffer structure that represents a single frame buffer
  581. * @angle: The angle we rotate the screen.
  582. *
  583. * This operation is used to set or alter the properities of the
  584. * cursor.
  585. */
  586. void xxxfb_rotate(struct fb_info *info, int angle)
  587. {
  588. /* Will be deprecated */
  589. }
  590. /**
  591. * xxxfb_poll - NOT a required function. The purpose of this
  592. * function is to provide a way for some process
  593. * to wait until a specific hardware event occurs
  594. * for the framebuffer device.
  595. *
  596. * @info: frame buffer structure that represents a single frame buffer
  597. * @wait: poll table where we store process that await a event.
  598. */
  599. void xxxfb_poll(struct fb_info *info, poll_table *wait)
  600. {
  601. }
  602. /**
  603. * xxxfb_sync - NOT a required function. Normally the accel engine
  604. * for a graphics card take a specific amount of time.
  605. * Often we have to wait for the accelerator to finish
  606. * its operation before we can write to the framebuffer
  607. * so we can have consistent display output.
  608. *
  609. * @info: frame buffer structure that represents a single frame buffer
  610. *
  611. * If the driver has implemented its own hardware-based drawing function,
  612. * implementing this function is highly recommended.
  613. */
  614. void xxxfb_sync(struct fb_info *info)
  615. {
  616. }
  617. /*
  618. * Initialization
  619. */
  620. /* static int __init xxfb_probe (struct device *device) -- for platform devs */
  621. static int __init xxxfb_probe(struct pci_dev *dev,
  622. const_struct pci_device_id *ent)
  623. {
  624. struct fb_info *info;
  625. struct xxx_par *par;
  626. struct device = &dev->dev; /* for pci drivers */
  627. int cmap_len, retval;
  628. /*
  629. * Dynamically allocate info and par
  630. */
  631. info = framebuffer_alloc(sizeof(struct xxx_par), device);
  632. if (!info) {
  633. /* goto error path */
  634. }
  635. par = info->par;
  636. /*
  637. * Here we set the screen_base to the virtual memory address
  638. * for the framebuffer. Usually we obtain the resource address
  639. * from the bus layer and then translate it to virtual memory
  640. * space via ioremap. Consult ioport.h.
  641. */
  642. info->screen_base = framebuffer_virtual_memory;
  643. info->fbops = &xxxfb_ops;
  644. info->fix = xxxfb_fix; /* this will be the only time xxxfb_fix will be
  645. * used, so mark it as __initdata
  646. */
  647. info->pseudo_palette = pseudo_palette; /* The pseudopalette is an
  648. * 16-member array
  649. */
  650. /*
  651. * Set up flags to indicate what sort of acceleration your
  652. * driver can provide (pan/wrap/copyarea/etc.) and whether it
  653. * is a module -- see FBINFO_* in include/linux/fb.h
  654. *
  655. * If your hardware can support any of the hardware accelerated functions
  656. * fbcon performance will improve if info->flags is set properly.
  657. *
  658. * FBINFO_HWACCEL_COPYAREA - hardware moves
  659. * FBINFO_HWACCEL_FILLRECT - hardware fills
  660. * FBINFO_HWACCEL_IMAGEBLIT - hardware mono->color expansion
  661. * FBINFO_HWACCEL_YPAN - hardware can pan display in y-axis
  662. * FBINFO_HWACCEL_YWRAP - hardware can wrap display in y-axis
  663. * FBINFO_HWACCEL_DISABLED - supports hardware accels, but disabled
  664. * FBINFO_READS_FAST - if set, prefer moves over mono->color expansion
  665. * FBINFO_MISC_TILEBLITTING - hardware can do tile blits
  666. *
  667. * NOTE: These are for fbcon use only.
  668. */
  669. info->flags = FBINFO_DEFAULT;
  670. /********************* This stage is optional ******************************/
  671. /*
  672. * The struct pixmap is a scratch pad for the drawing functions. This
  673. * is where the monochrome bitmap is constructed by the higher layers
  674. * and then passed to the accelerator. For drivers that uses
  675. * cfb_imageblit, you can skip this part. For those that have a more
  676. * rigorous requirement, this stage is needed
  677. */
  678. /* PIXMAP_SIZE should be small enough to optimize drawing, but not
  679. * large enough that memory is wasted. A safe size is
  680. * (max_xres * max_font_height/8). max_xres is driver dependent,
  681. * max_font_height is 32.
  682. */
  683. info->pixmap.addr = kmalloc(PIXMAP_SIZE, GFP_KERNEL);
  684. if (!info->pixmap.addr) {
  685. /* goto error */
  686. }
  687. info->pixmap.size = PIXMAP_SIZE;
  688. /*
  689. * FB_PIXMAP_SYSTEM - memory is in system ram
  690. * FB_PIXMAP_IO - memory is iomapped
  691. * FB_PIXMAP_SYNC - if set, will call fb_sync() per access to pixmap,
  692. * usually if FB_PIXMAP_IO is set.
  693. *
  694. * Currently, FB_PIXMAP_IO is unimplemented.
  695. */
  696. info->pixmap.flags = FB_PIXMAP_SYSTEM;
  697. /*
  698. * scan_align is the number of padding for each scanline. It is in bytes.
  699. * Thus for accelerators that need padding to the next u32, put 4 here.
  700. */
  701. info->pixmap.scan_align = 4;
  702. /*
  703. * buf_align is the amount to be padded for the buffer. For example,
  704. * the i810fb needs a scan_align of 2 but expects it to be fed with
  705. * dwords, so a buf_align = 4 is required.
  706. */
  707. info->pixmap.buf_align = 4;
  708. /* access_align is how many bits can be accessed from the framebuffer
  709. * ie. some epson cards allow 16-bit access only. Most drivers will
  710. * be safe with u32 here.
  711. *
  712. * NOTE: This field is currently unused.
  713. */
  714. info->pixmap.scan_align = 32
  715. /***************************** End optional stage ***************************/
  716. /*
  717. * This should give a reasonable default video mode. The following is
  718. * done when we can set a video mode.
  719. */
  720. if (!mode_option)
  721. mode_option = "640x480@60";
  722. retval = fb_find_mode(info->var, info, mode_option, NULL, 0, NULL, 8);
  723. if (!retval || retval == 4)
  724. return -EINVAL;
  725. /* This has to been done !!! */
  726. fb_alloc_cmap(info->cmap, cmap_len, 0);
  727. /*
  728. * The following is done in the case of having hardware with a static
  729. * mode. If we are setting the mode ourselves we don't call this.
  730. */
  731. info->var = xxxfb_var;
  732. /*
  733. * For drivers that can...
  734. */
  735. xxxfb_check_var(&info->var, info);
  736. /*
  737. * Does a call to fb_set_par() before register_framebuffer needed? This
  738. * will depend on you and the hardware. If you are sure that your driver
  739. * is the only device in the system, a call to fb_set_par() is safe.
  740. *
  741. * Hardware in x86 systems has a VGA core. Calling set_par() at this
  742. * point will corrupt the VGA console, so it might be safer to skip a
  743. * call to set_par here and just allow fbcon to do it for you.
  744. */
  745. /* xxxfb_set_par(info); */
  746. if (register_framebuffer(info) < 0)
  747. return -EINVAL;
  748. printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
  749. info->fix.id);
  750. pci_set_drvdata(dev, info); /* or dev_set_drvdata(device, info) */
  751. return 0;
  752. }
  753. /*
  754. * Cleanup
  755. */
  756. /* static void __exit xxxfb_remove(struct device *device) */
  757. static void __exit xxxfb_remove(struct pci_dev *dev)
  758. {
  759. struct fb_info *info = pci_get_drv_data(dev);
  760. /* or dev_get_drv_data(device); */
  761. if (info) {
  762. unregister_framebuffer(info);
  763. fb_dealloc_cmap(&info.cmap);
  764. /* ... */
  765. framebuffer_release(info);
  766. }
  767. return 0;
  768. }
  769. #if CONFIG_PCI
  770. /* For PCI drivers */
  771. static struct pci_driver xxxfb_driver = {
  772. .name = "xxxfb",
  773. .id_table = xxxfb_devices,
  774. .probe = xxxfb_probe,
  775. .remove = __devexit_p(xxxfb_remove),
  776. .suspend = xxxfb_suspend, /* optional */
  777. .resume = xxxfb_resume, /* optional */
  778. };
  779. static int __init xxxfb_init(void)
  780. {
  781. /*
  782. * For kernel boot options (in 'video=xxxfb:<options>' format)
  783. */
  784. #ifndef MODULE
  785. char *option = NULL;
  786. if (fb_get_options("xxxfb", &option))
  787. return -ENODEV;
  788. xxxfb_setup(option);
  789. #endif
  790. return pci_register_driver(&xxxfb_driver);
  791. }
  792. static void __exit xxxfb_exit(void)
  793. {
  794. pci_unregister_driver(&xxxfb_driver);
  795. }
  796. #else
  797. #include <linux/platform_device.h>
  798. /* for platform devices */
  799. static struct device_driver xxxfb_driver = {
  800. .name = "xxxfb",
  801. .bus = &platform_bus_type,
  802. .probe = xxxfb_probe,
  803. .remove = xxxfb_remove,
  804. .suspend = xxxfb_suspend, /* optional */
  805. .resume = xxxfb_resume, /* optional */
  806. };
  807. static struct platform_device xxxfb_device = {
  808. .name = "xxxfb",
  809. };
  810. static int __init xxxfb_init(void)
  811. {
  812. int ret;
  813. /*
  814. * For kernel boot options (in 'video=xxxfb:<options>' format)
  815. */
  816. #ifndef MODULE
  817. char *option = NULL;
  818. if (fb_get_options("xxxfb", &option))
  819. return -ENODEV;
  820. xxxfb_setup(option);
  821. #endif
  822. ret = driver_register(&xxxfb_driver);
  823. if (!ret) {
  824. ret = platform_device_register(&xxxfb_device);
  825. if (ret)
  826. driver_unregister(&xxxfb_driver);
  827. }
  828. return ret;
  829. }
  830. static void __exit xxxfb_exit(void)
  831. {
  832. platform_device_unregister(&xxxfb_device);
  833. driver_unregister(&xxxfb_driver);
  834. }
  835. #endif
  836. MODULE_LICENSE("GPL");
  837. module_init(xxxfb_init);
  838. module_exit(xxxfb_exit);
  839. /*
  840. * Setup
  841. */
  842. /*
  843. * Only necessary if your driver takes special options,
  844. * otherwise we fall back on the generic fb_setup().
  845. */
  846. int __init xxxfb_setup(char *options)
  847. {
  848. /* Parse user speficied options (`video=xxxfb:') */
  849. }
  850. /* ------------------------------------------------------------------------- */
  851. /*
  852. * Frame buffer operations
  853. */
  854. static struct fb_ops xxxfb_ops = {
  855. .owner = THIS_MODULE,
  856. .fb_open = xxxfb_open,
  857. .fb_read = xxxfb_read,
  858. .fb_write = xxxfb_write,
  859. .fb_release = xxxfb_release,
  860. .fb_check_var = xxxfb_check_var,
  861. .fb_set_par = xxxfb_set_par,
  862. .fb_setcolreg = xxxfb_setcolreg,
  863. .fb_blank = xxxfb_blank,
  864. .fb_pan_display = xxxfb_pan_display,
  865. .fb_fillrect = xxxfb_fillrect, /* Needed !!! */
  866. .fb_copyarea = xxxfb_copyarea, /* Needed !!! */
  867. .fb_imageblit = xxxfb_imageblit, /* Needed !!! */
  868. .fb_cursor = xxxfb_cursor, /* Optional !!! */
  869. .fb_rotate = xxxfb_rotate,
  870. .fb_poll = xxxfb_poll,
  871. .fb_sync = xxxfb_sync,
  872. .fb_ioctl = xxxfb_ioctl,
  873. .fb_mmap = xxxfb_mmap,
  874. };
  875. /* ------------------------------------------------------------------------- */
  876. /*
  877. * Modularization
  878. */
  879. module_init(xxxfb_init);
  880. module_exit(xxxfb_cleanup);
  881. MODULE_LICENSE("GPL");