pnxrgbfb.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * drivers/video/pnx4008/pnxrgbfb.c
  3. *
  4. * PNX4008's framebuffer support
  5. *
  6. * Author: Grigory Tolstolytkin <gtolstolytkin@ru.mvista.com>
  7. * Based on Philips Semiconductors's code
  8. *
  9. * Copyrght (c) 2005 MontaVista Software, Inc.
  10. * Copyright (c) 2005 Philips Semiconductors
  11. * This file is licensed under the terms of the GNU General Public License
  12. * version 2. This program is licensed "as is" without any warranty of any
  13. * kind, whether express or implied.
  14. */
  15. #include <linux/module.h>
  16. #include <linux/kernel.h>
  17. #include <linux/errno.h>
  18. #include <linux/string.h>
  19. #include <linux/mm.h>
  20. #include <linux/slab.h>
  21. #include <linux/vmalloc.h>
  22. #include <linux/delay.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/fb.h>
  25. #include <linux/init.h>
  26. #include <linux/platform_device.h>
  27. #include <asm/uaccess.h>
  28. #include "sdum.h"
  29. #include "fbcommon.h"
  30. static u32 colreg[16];
  31. static struct fb_var_screeninfo rgbfb_var __initdata = {
  32. .xres = LCD_X_RES,
  33. .yres = LCD_Y_RES,
  34. .xres_virtual = LCD_X_RES,
  35. .yres_virtual = LCD_Y_RES,
  36. .bits_per_pixel = 32,
  37. .red.offset = 16,
  38. .red.length = 8,
  39. .green.offset = 8,
  40. .green.length = 8,
  41. .blue.offset = 0,
  42. .blue.length = 8,
  43. .left_margin = 0,
  44. .right_margin = 0,
  45. .upper_margin = 0,
  46. .lower_margin = 0,
  47. .vmode = FB_VMODE_NONINTERLACED,
  48. };
  49. static struct fb_fix_screeninfo rgbfb_fix __initdata = {
  50. .id = "RGBFB",
  51. .line_length = LCD_X_RES * LCD_BBP,
  52. .type = FB_TYPE_PACKED_PIXELS,
  53. .visual = FB_VISUAL_TRUECOLOR,
  54. .xpanstep = 0,
  55. .ypanstep = 0,
  56. .ywrapstep = 0,
  57. .accel = FB_ACCEL_NONE,
  58. };
  59. static int channel_owned;
  60. static int no_cursor(struct fb_info *info, struct fb_cursor *cursor)
  61. {
  62. return 0;
  63. }
  64. static int rgbfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  65. u_int transp, struct fb_info *info)
  66. {
  67. if (regno > 15)
  68. return 1;
  69. colreg[regno] = ((red & 0xff00) << 8) | (green & 0xff00) |
  70. ((blue & 0xff00) >> 8);
  71. return 0;
  72. }
  73. static int rgbfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
  74. {
  75. return pnx4008_sdum_mmap(info, vma, NULL);
  76. }
  77. static struct fb_ops rgbfb_ops = {
  78. .fb_mmap = rgbfb_mmap,
  79. .fb_setcolreg = rgbfb_setcolreg,
  80. .fb_fillrect = cfb_fillrect,
  81. .fb_copyarea = cfb_copyarea,
  82. .fb_imageblit = cfb_imageblit,
  83. };
  84. static int rgbfb_remove(struct platform_device *pdev)
  85. {
  86. struct fb_info *info = platform_get_drvdata(pdev);
  87. if (info) {
  88. unregister_framebuffer(info);
  89. fb_dealloc_cmap(&info->cmap);
  90. framebuffer_release(info);
  91. platform_set_drvdata(pdev, NULL);
  92. kfree(info);
  93. }
  94. pnx4008_free_dum_channel(channel_owned, pdev->id);
  95. pnx4008_set_dum_exit_notification(pdev->id);
  96. return 0;
  97. }
  98. static int __devinit rgbfb_probe(struct platform_device *pdev)
  99. {
  100. struct fb_info *info;
  101. struct dumchannel_uf chan_uf;
  102. int ret;
  103. char *option;
  104. info = framebuffer_alloc(sizeof(u32) * 16, &pdev->dev);
  105. if (!info) {
  106. ret = -ENOMEM;
  107. goto err;
  108. }
  109. pnx4008_get_fb_addresses(FB_TYPE_RGB, (void **)&info->screen_base,
  110. (dma_addr_t *) &rgbfb_fix.smem_start,
  111. &rgbfb_fix.smem_len);
  112. if ((ret = pnx4008_alloc_dum_channel(pdev->id)) < 0)
  113. goto err0;
  114. else {
  115. channel_owned = ret;
  116. chan_uf.channelnr = channel_owned;
  117. chan_uf.dirty = (u32 *) NULL;
  118. chan_uf.source = (u32 *) rgbfb_fix.smem_start;
  119. chan_uf.x_offset = 0;
  120. chan_uf.y_offset = 0;
  121. chan_uf.width = LCD_X_RES;
  122. chan_uf.height = LCD_Y_RES;
  123. if ((ret = pnx4008_put_dum_channel_uf(chan_uf, pdev->id))< 0)
  124. goto err1;
  125. if ((ret =
  126. pnx4008_set_dum_channel_sync(channel_owned, CONF_SYNC_ON,
  127. pdev->id)) < 0)
  128. goto err1;
  129. if ((ret =
  130. pnx4008_set_dum_channel_dirty_detect(channel_owned,
  131. CONF_DIRTYDETECTION_ON,
  132. pdev->id)) < 0)
  133. goto err1;
  134. }
  135. if (!fb_get_options("pnxrgbfb", &option) && !strcmp(option, "nocursor"))
  136. rgbfb_ops.fb_cursor = no_cursor;
  137. info->node = -1;
  138. info->flags = FBINFO_FLAG_DEFAULT;
  139. info->fbops = &rgbfb_ops;
  140. info->fix = rgbfb_fix;
  141. info->var = rgbfb_var;
  142. info->screen_size = rgbfb_fix.smem_len;
  143. info->pseudo_palette = info->par;
  144. info->par = NULL;
  145. ret = fb_alloc_cmap(&info->cmap, 256, 0);
  146. if (ret < 0)
  147. goto err2;
  148. ret = register_framebuffer(info);
  149. if (ret < 0)
  150. goto err3;
  151. platform_set_drvdata(pdev, info);
  152. return 0;
  153. err3:
  154. fb_dealloc_cmap(&info->cmap);
  155. err2:
  156. framebuffer_release(info);
  157. err1:
  158. pnx4008_free_dum_channel(channel_owned, pdev->id);
  159. err0:
  160. kfree(info);
  161. err:
  162. return ret;
  163. }
  164. static struct platform_driver rgbfb_driver = {
  165. .driver = {
  166. .name = "rgbfb",
  167. },
  168. .probe = rgbfb_probe,
  169. .remove = rgbfb_remove,
  170. };
  171. static int __init rgbfb_init(void)
  172. {
  173. return platform_driver_register(&rgbfb_driver);
  174. }
  175. static void __exit rgbfb_exit(void)
  176. {
  177. platform_driver_unregister(&rgbfb_driver);
  178. }
  179. module_init(rgbfb_init);
  180. module_exit(rgbfb_exit);
  181. MODULE_LICENSE("GPL");