skeletonfb.c 36 KB

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