sunxvr1000.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /* sunxvr1000.c: Sun XVR-1000 fb driver for sparc64 systems
  2. *
  3. * License: GPL
  4. *
  5. * Copyright (C) 2010 David S. Miller ([email protected])
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/fb.h>
  9. #include <linux/init.h>
  10. #include <linux/of_device.h>
  11. struct gfb_info {
  12. struct fb_info *info;
  13. char __iomem *fb_base;
  14. unsigned long fb_base_phys;
  15. struct device_node *of_node;
  16. unsigned int width;
  17. unsigned int height;
  18. unsigned int depth;
  19. unsigned int fb_size;
  20. u32 pseudo_palette[16];
  21. };
  22. static int gfb_get_props(struct gfb_info *gp)
  23. {
  24. gp->width = of_getintprop_default(gp->of_node, "width", 0);
  25. gp->height = of_getintprop_default(gp->of_node, "height", 0);
  26. gp->depth = of_getintprop_default(gp->of_node, "depth", 32);
  27. if (!gp->width || !gp->height) {
  28. printk(KERN_ERR "gfb: Critical properties missing for %pOF\n",
  29. gp->of_node);
  30. return -EINVAL;
  31. }
  32. return 0;
  33. }
  34. static int gfb_setcolreg(unsigned regno,
  35. unsigned red, unsigned green, unsigned blue,
  36. unsigned transp, struct fb_info *info)
  37. {
  38. u32 value;
  39. if (regno < 16) {
  40. red >>= 8;
  41. green >>= 8;
  42. blue >>= 8;
  43. value = (blue << 16) | (green << 8) | red;
  44. ((u32 *)info->pseudo_palette)[regno] = value;
  45. }
  46. return 0;
  47. }
  48. static const struct fb_ops gfb_ops = {
  49. .owner = THIS_MODULE,
  50. .fb_setcolreg = gfb_setcolreg,
  51. .fb_fillrect = cfb_fillrect,
  52. .fb_copyarea = cfb_copyarea,
  53. .fb_imageblit = cfb_imageblit,
  54. };
  55. static int gfb_set_fbinfo(struct gfb_info *gp)
  56. {
  57. struct fb_info *info = gp->info;
  58. struct fb_var_screeninfo *var = &info->var;
  59. info->flags = FBINFO_DEFAULT;
  60. info->fbops = &gfb_ops;
  61. info->screen_base = gp->fb_base;
  62. info->screen_size = gp->fb_size;
  63. info->pseudo_palette = gp->pseudo_palette;
  64. /* Fill fix common fields */
  65. strscpy(info->fix.id, "gfb", sizeof(info->fix.id));
  66. info->fix.smem_start = gp->fb_base_phys;
  67. info->fix.smem_len = gp->fb_size;
  68. info->fix.type = FB_TYPE_PACKED_PIXELS;
  69. if (gp->depth == 32 || gp->depth == 24)
  70. info->fix.visual = FB_VISUAL_TRUECOLOR;
  71. else
  72. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  73. var->xres = gp->width;
  74. var->yres = gp->height;
  75. var->xres_virtual = var->xres;
  76. var->yres_virtual = var->yres;
  77. var->bits_per_pixel = gp->depth;
  78. var->red.offset = 0;
  79. var->red.length = 8;
  80. var->green.offset = 8;
  81. var->green.length = 8;
  82. var->blue.offset = 16;
  83. var->blue.length = 8;
  84. var->transp.offset = 0;
  85. var->transp.length = 0;
  86. if (fb_alloc_cmap(&info->cmap, 256, 0)) {
  87. printk(KERN_ERR "gfb: Cannot allocate color map.\n");
  88. return -ENOMEM;
  89. }
  90. return 0;
  91. }
  92. static int gfb_probe(struct platform_device *op)
  93. {
  94. struct device_node *dp = op->dev.of_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. 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 %pOF\n", dp);
  123. err = register_framebuffer(info);
  124. if (err < 0) {
  125. printk(KERN_ERR "gfb: Could not register framebuffer %pOF\n",
  126. dp);
  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 const struct of_device_id gfb_match[] = {
  139. {
  140. .name = "SUNW,gfb",
  141. },
  142. {},
  143. };
  144. static struct platform_driver gfb_driver = {
  145. .probe = gfb_probe,
  146. .driver = {
  147. .name = "gfb",
  148. .of_match_table = gfb_match,
  149. .suppress_bind_attrs = true,
  150. },
  151. };
  152. static int __init gfb_init(void)
  153. {
  154. if (fb_get_options("gfb", NULL))
  155. return -ENODEV;
  156. return platform_driver_register(&gfb_driver);
  157. }
  158. device_initcall(gfb_init);