sunxvr1000.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 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 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 gfb_probe(struct platform_device *op)
  92. {
  93. struct device_node *dp = op->dev.of_node;
  94. struct fb_info *info;
  95. struct gfb_info *gp;
  96. int err;
  97. info = framebuffer_alloc(sizeof(struct gfb_info), &op->dev);
  98. if (!info) {
  99. printk(KERN_ERR "gfb: Cannot allocate fb_info\n");
  100. err = -ENOMEM;
  101. goto err_out;
  102. }
  103. gp = info->par;
  104. gp->info = info;
  105. gp->of_node = dp;
  106. gp->fb_base_phys = op->resource[6].start;
  107. err = gfb_get_props(gp);
  108. if (err)
  109. goto err_release_fb;
  110. /* Framebuffer length is the same regardless of resolution. */
  111. info->fix.line_length = 16384;
  112. gp->fb_size = info->fix.line_length * gp->height;
  113. gp->fb_base = of_ioremap(&op->resource[6], 0,
  114. gp->fb_size, "gfb fb");
  115. if (!gp->fb_base) {
  116. err = -ENOMEM;
  117. goto err_release_fb;
  118. }
  119. err = gfb_set_fbinfo(gp);
  120. if (err)
  121. goto err_unmap_fb;
  122. printk("gfb: Found device at %s\n", dp->full_name);
  123. err = register_framebuffer(info);
  124. if (err < 0) {
  125. printk(KERN_ERR "gfb: Could not register framebuffer %s\n",
  126. dp->full_name);
  127. goto err_unmap_fb;
  128. }
  129. dev_set_drvdata(&op->dev, info);
  130. return 0;
  131. err_unmap_fb:
  132. of_iounmap(&op->resource[6], gp->fb_base, gp->fb_size);
  133. err_release_fb:
  134. framebuffer_release(info);
  135. err_out:
  136. return err;
  137. }
  138. static int gfb_remove(struct platform_device *op)
  139. {
  140. struct fb_info *info = dev_get_drvdata(&op->dev);
  141. struct gfb_info *gp = info->par;
  142. unregister_framebuffer(info);
  143. iounmap(gp->fb_base);
  144. of_iounmap(&op->resource[6], gp->fb_base, gp->fb_size);
  145. framebuffer_release(info);
  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 platform_driver gfb_driver = {
  156. .probe = gfb_probe,
  157. .remove = gfb_remove,
  158. .driver = {
  159. .name = "gfb",
  160. .of_match_table = gfb_match,
  161. },
  162. };
  163. static int __init gfb_init(void)
  164. {
  165. if (fb_get_options("gfb", NULL))
  166. return -ENODEV;
  167. return platform_driver_register(&gfb_driver);
  168. }
  169. static void __exit gfb_exit(void)
  170. {
  171. platform_driver_unregister(&gfb_driver);
  172. }
  173. module_init(gfb_init);
  174. module_exit(gfb_exit);
  175. MODULE_DESCRIPTION("framebuffer driver for Sun XVR-1000 graphics");
  176. MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
  177. MODULE_VERSION("1.0");
  178. MODULE_LICENSE("GPL");