skeletonfb.c 36 KB

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