pnxrgbfb.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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/vmalloc.h>
  21. #include <linux/delay.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/fb.h>
  24. #include <linux/init.h>
  25. #include <linux/platform_device.h>
  26. #include "sdum.h"
  27. #include "fbcommon.h"
  28. static u32 colreg[16];
  29. static struct fb_var_screeninfo rgbfb_var __initdata = {
  30. .xres = LCD_X_RES,
  31. .yres = LCD_Y_RES,
  32. .xres_virtual = LCD_X_RES,
  33. .yres_virtual = LCD_Y_RES,
  34. .bits_per_pixel = 32,
  35. .red.offset = 16,
  36. .red.length = 8,
  37. .green.offset = 8,
  38. .green.length = 8,
  39. .blue.offset = 0,
  40. .blue.length = 8,
  41. .left_margin = 0,
  42. .right_margin = 0,
  43. .upper_margin = 0,
  44. .lower_margin = 0,
  45. .vmode = FB_VMODE_NONINTERLACED,
  46. };
  47. static struct fb_fix_screeninfo rgbfb_fix __initdata = {
  48. .id = "RGBFB",
  49. .line_length = LCD_X_RES * LCD_BBP,
  50. .type = FB_TYPE_PACKED_PIXELS,
  51. .visual = FB_VISUAL_TRUECOLOR,
  52. .xpanstep = 0,
  53. .ypanstep = 0,
  54. .ywrapstep = 0,
  55. .accel = FB_ACCEL_NONE,
  56. };
  57. static int channel_owned;
  58. static int no_cursor(struct fb_info *info, struct fb_cursor *cursor)
  59. {
  60. return 0;
  61. }
  62. static int rgbfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  63. u_int transp, struct fb_info *info)
  64. {
  65. if (regno > 15)
  66. return 1;
  67. colreg[regno] = ((red & 0xff00) << 8) | (green & 0xff00) |
  68. ((blue & 0xff00) >> 8);
  69. return 0;
  70. }
  71. static int rgbfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
  72. {
  73. return pnx4008_sdum_mmap(info, vma, NULL);
  74. }
  75. static struct fb_ops rgbfb_ops = {
  76. .fb_mmap = rgbfb_mmap,
  77. .fb_setcolreg = rgbfb_setcolreg,
  78. .fb_fillrect = cfb_fillrect,
  79. .fb_copyarea = cfb_copyarea,
  80. .fb_imageblit = cfb_imageblit,
  81. };
  82. static int rgbfb_remove(struct platform_device *pdev)
  83. {
  84. struct fb_info *info = platform_get_drvdata(pdev);
  85. if (info) {
  86. unregister_framebuffer(info);
  87. fb_dealloc_cmap(&info->cmap);
  88. framebuffer_release(info);
  89. platform_set_drvdata(pdev, NULL);
  90. }
  91. pnx4008_free_dum_channel(channel_owned, pdev->id);
  92. pnx4008_set_dum_exit_notification(pdev->id);
  93. return 0;
  94. }
  95. static int __devinit rgbfb_probe(struct platform_device *pdev)
  96. {
  97. struct fb_info *info;
  98. struct dumchannel_uf chan_uf;
  99. int ret;
  100. char *option;
  101. info = framebuffer_alloc(sizeof(u32) * 16, &pdev->dev);
  102. if (!info) {
  103. ret = -ENOMEM;
  104. goto err;
  105. }
  106. pnx4008_get_fb_addresses(FB_TYPE_RGB, (void **)&info->screen_base,
  107. (dma_addr_t *) &rgbfb_fix.smem_start,
  108. &rgbfb_fix.smem_len);
  109. if ((ret = pnx4008_alloc_dum_channel(pdev->id)) < 0)
  110. goto err0;
  111. else {
  112. channel_owned = ret;
  113. chan_uf.channelnr = channel_owned;
  114. chan_uf.dirty = (u32 *) NULL;
  115. chan_uf.source = (u32 *) rgbfb_fix.smem_start;
  116. chan_uf.x_offset = 0;
  117. chan_uf.y_offset = 0;
  118. chan_uf.width = LCD_X_RES;
  119. chan_uf.height = LCD_Y_RES;
  120. if ((ret = pnx4008_put_dum_channel_uf(chan_uf, pdev->id))< 0)
  121. goto err1;
  122. if ((ret =
  123. pnx4008_set_dum_channel_sync(channel_owned, CONF_SYNC_ON,
  124. pdev->id)) < 0)
  125. goto err1;
  126. if ((ret =
  127. pnx4008_set_dum_channel_dirty_detect(channel_owned,
  128. CONF_DIRTYDETECTION_ON,
  129. pdev->id)) < 0)
  130. goto err1;
  131. }
  132. if (!fb_get_options("pnxrgbfb", &option) && option &&
  133. !strcmp(option, "nocursor"))
  134. rgbfb_ops.fb_cursor = no_cursor;
  135. info->node = -1;
  136. info->flags = FBINFO_FLAG_DEFAULT;
  137. info->fbops = &rgbfb_ops;
  138. info->fix = rgbfb_fix;
  139. info->var = rgbfb_var;
  140. info->screen_size = rgbfb_fix.smem_len;
  141. info->pseudo_palette = info->par;
  142. info->par = NULL;
  143. ret = fb_alloc_cmap(&info->cmap, 256, 0);
  144. if (ret < 0)
  145. goto err1;
  146. ret = register_framebuffer(info);
  147. if (ret < 0)
  148. goto err2;
  149. platform_set_drvdata(pdev, info);
  150. return 0;
  151. err2:
  152. fb_dealloc_cmap(&info->cmap);
  153. err1:
  154. pnx4008_free_dum_channel(channel_owned, pdev->id);
  155. err0:
  156. framebuffer_release(info);
  157. err:
  158. return ret;
  159. }
  160. static struct platform_driver rgbfb_driver = {
  161. .driver = {
  162. .name = "pnx4008-rgbfb",
  163. },
  164. .probe = rgbfb_probe,
  165. .remove = rgbfb_remove,
  166. };
  167. module_platform_driver(rgbfb_driver);
  168. MODULE_LICENSE("GPL");