PageRenderTime 162ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/video/sunxvr1000.c

https://bitbucket.org/abioy/linux
C | 227 lines | 170 code | 51 blank | 6 comment | 14 complexity | 91fea0b4c645e191e593f37cbb1026dd MD5 | raw file
Possible License(s): CC-BY-SA-3.0, GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /* sunxvr1000.c: Sun XVR-1000 driver for sparc64 systems
  2. *
  3. * Copyright (C) 2010 David S. Miller (davem@davemloft.net)
  4. */
  5. #include <linux/module.h>
  6. #include <linux/kernel.h>
  7. #include <linux/fb.h>
  8. #include <linux/init.h>
  9. #include <linux/of_device.h>
  10. struct gfb_info {
  11. struct fb_info *info;
  12. char __iomem *fb_base;
  13. unsigned long fb_base_phys;
  14. struct device_node *of_node;
  15. unsigned int width;
  16. unsigned int height;
  17. unsigned int depth;
  18. unsigned int fb_size;
  19. u32 pseudo_palette[16];
  20. };
  21. static int __devinit gfb_get_props(struct gfb_info *gp)
  22. {
  23. gp->width = of_getintprop_default(gp->of_node, "width", 0);
  24. gp->height = of_getintprop_default(gp->of_node, "height", 0);
  25. gp->depth = of_getintprop_default(gp->of_node, "depth", 32);
  26. if (!gp->width || !gp->height) {
  27. printk(KERN_ERR "gfb: Critical properties missing for %s\n",
  28. gp->of_node->full_name);
  29. return -EINVAL;
  30. }
  31. return 0;
  32. }
  33. static int gfb_setcolreg(unsigned regno,
  34. unsigned red, unsigned green, unsigned blue,
  35. unsigned transp, struct fb_info *info)
  36. {
  37. u32 value;
  38. if (regno < 16) {
  39. red >>= 8;
  40. green >>= 8;
  41. blue >>= 8;
  42. value = (blue << 16) | (green << 8) | red;
  43. ((u32 *)info->pseudo_palette)[regno] = value;
  44. }
  45. return 0;
  46. }
  47. static struct fb_ops gfb_ops = {
  48. .owner = THIS_MODULE,
  49. .fb_setcolreg = gfb_setcolreg,
  50. .fb_fillrect = cfb_fillrect,
  51. .fb_copyarea = cfb_copyarea,
  52. .fb_imageblit = cfb_imageblit,
  53. };
  54. static int __devinit gfb_set_fbinfo(struct gfb_info *gp)
  55. {
  56. struct fb_info *info = gp->info;
  57. struct fb_var_screeninfo *var = &info->var;
  58. info->flags = FBINFO_DEFAULT;
  59. info->fbops = &gfb_ops;
  60. info->screen_base = gp->fb_base;
  61. info->screen_size = gp->fb_size;
  62. info->pseudo_palette = gp->pseudo_palette;
  63. /* Fill fix common fields */
  64. strlcpy(info->fix.id, "gfb", sizeof(info->fix.id));
  65. info->fix.smem_start = gp->fb_base_phys;
  66. info->fix.smem_len = gp->fb_size;
  67. info->fix.type = FB_TYPE_PACKED_PIXELS;
  68. if (gp->depth == 32 || gp->depth == 24)
  69. info->fix.visual = FB_VISUAL_TRUECOLOR;
  70. else
  71. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  72. var->xres = gp->width;
  73. var->yres = gp->height;
  74. var->xres_virtual = var->xres;
  75. var->yres_virtual = var->yres;
  76. var->bits_per_pixel = gp->depth;
  77. var->red.offset = 0;
  78. var->red.length = 8;
  79. var->green.offset = 8;
  80. var->green.length = 8;
  81. var->blue.offset = 16;
  82. var->blue.length = 8;
  83. var->transp.offset = 0;
  84. var->transp.length = 0;
  85. if (fb_alloc_cmap(&info->cmap, 256, 0)) {
  86. printk(KERN_ERR "gfb: Cannot allocate color map.\n");
  87. return -ENOMEM;
  88. }
  89. return 0;
  90. }
  91. static int __devinit gfb_probe(struct of_device *op,
  92. const struct of_device_id *match)
  93. {
  94. struct device_node *dp = op->node;
  95. struct fb_info *info;
  96. struct gfb_info *gp;
  97. int err;
  98. info = framebuffer_alloc(sizeof(struct gfb_info), &op->dev);
  99. if (!info) {
  100. printk(KERN_ERR "gfb: Cannot allocate fb_info\n");
  101. err = -ENOMEM;
  102. goto err_out;
  103. }
  104. gp = info->par;
  105. gp->info = info;
  106. gp->of_node = dp;
  107. gp->fb_base_phys = op->resource[6].start;
  108. err = gfb_get_props(gp);
  109. if (err)
  110. goto err_release_fb;
  111. /* Framebuffer length is the same regardless of resolution. */
  112. info->fix.line_length = 16384;
  113. gp->fb_size = info->fix.line_length * gp->height;
  114. gp->fb_base = of_ioremap(&op->resource[6], 0,
  115. gp->fb_size, "gfb fb");
  116. if (!gp->fb_base)
  117. goto err_release_fb;
  118. err = gfb_set_fbinfo(gp);
  119. if (err)
  120. goto err_unmap_fb;
  121. printk("gfb: Found device at %s\n", dp->full_name);
  122. err = register_framebuffer(info);
  123. if (err < 0) {
  124. printk(KERN_ERR "gfb: Could not register framebuffer %s\n",
  125. dp->full_name);
  126. goto err_unmap_fb;
  127. }
  128. dev_set_drvdata(&op->dev, info);
  129. return 0;
  130. err_unmap_fb:
  131. of_iounmap(&op->resource[6], gp->fb_base, gp->fb_size);
  132. err_release_fb:
  133. framebuffer_release(info);
  134. err_out:
  135. return err;
  136. }
  137. static int __devexit gfb_remove(struct of_device *op)
  138. {
  139. struct fb_info *info = dev_get_drvdata(&op->dev);
  140. struct gfb_info *gp = info->par;
  141. unregister_framebuffer(info);
  142. iounmap(gp->fb_base);
  143. of_iounmap(&op->resource[6], gp->fb_base, gp->fb_size);
  144. framebuffer_release(info);
  145. dev_set_drvdata(&op->dev, NULL);
  146. return 0;
  147. }
  148. static const struct of_device_id gfb_match[] = {
  149. {
  150. .name = "SUNW,gfb",
  151. },
  152. {},
  153. };
  154. MODULE_DEVICE_TABLE(of, ffb_match);
  155. static struct of_platform_driver gfb_driver = {
  156. .name = "gfb",
  157. .match_table = gfb_match,
  158. .probe = gfb_probe,
  159. .remove = __devexit_p(gfb_remove),
  160. };
  161. static int __init gfb_init(void)
  162. {
  163. if (fb_get_options("gfb", NULL))
  164. return -ENODEV;
  165. return of_register_driver(&gfb_driver, &of_bus_type);
  166. }
  167. static void __exit gfb_exit(void)
  168. {
  169. of_unregister_driver(&gfb_driver);
  170. }
  171. module_init(gfb_init);
  172. module_exit(gfb_exit);
  173. MODULE_DESCRIPTION("framebuffer driver for Sun XVR-1000 graphics");
  174. MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
  175. MODULE_VERSION("1.0");
  176. MODULE_LICENSE("GPL");