sunxvr1000.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /* sunxvr1000.c: Sun XVR-1000 fb driver for sparc64 systems
  2. *
  3. * License: GPL
  4. *
  5. * Copyright (C) 2010 David S. Miller (davem@davemloft.net)
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/fb.h>
  9. #include <linux/init.h>
  10. #include <linux/of.h>
  11. #include <linux/platform_device.h>
  12. struct gfb_info {
  13. struct fb_info *info;
  14. char __iomem *fb_base;
  15. unsigned long fb_base_phys;
  16. struct device_node *of_node;
  17. unsigned int width;
  18. unsigned int height;
  19. unsigned int depth;
  20. unsigned int fb_size;
  21. u32 pseudo_palette[16];
  22. };
  23. static int gfb_get_props(struct gfb_info *gp)
  24. {
  25. gp->width = of_getintprop_default(gp->of_node, "width", 0);
  26. gp->height = of_getintprop_default(gp->of_node, "height", 0);
  27. gp->depth = of_getintprop_default(gp->of_node, "depth", 32);
  28. if (!gp->width || !gp->height) {
  29. printk(KERN_ERR "gfb: Critical properties missing for %pOF\n",
  30. gp->of_node);
  31. return -EINVAL;
  32. }
  33. return 0;
  34. }
  35. static int gfb_setcolreg(unsigned regno,
  36. unsigned red, unsigned green, unsigned blue,
  37. unsigned transp, struct fb_info *info)
  38. {
  39. u32 value;
  40. if (regno < 16) {
  41. red >>= 8;
  42. green >>= 8;
  43. blue >>= 8;
  44. value = (blue << 16) | (green << 8) | red;
  45. ((u32 *)info->pseudo_palette)[regno] = value;
  46. }
  47. return 0;
  48. }
  49. static const struct fb_ops gfb_ops = {
  50. .owner = THIS_MODULE,
  51. FB_DEFAULT_IOMEM_OPS,
  52. .fb_setcolreg = gfb_setcolreg,
  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->fbops = &gfb_ops;
  59. info->screen_base = gp->fb_base;
  60. info->screen_size = gp->fb_size;
  61. info->pseudo_palette = gp->pseudo_palette;
  62. /* Fill fix common fields */
  63. strscpy(info->fix.id, "gfb", sizeof(info->fix.id));
  64. info->fix.smem_start = gp->fb_base_phys;
  65. info->fix.smem_len = gp->fb_size;
  66. info->fix.type = FB_TYPE_PACKED_PIXELS;
  67. if (gp->depth == 32 || gp->depth == 24)
  68. info->fix.visual = FB_VISUAL_TRUECOLOR;
  69. else
  70. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  71. var->xres = gp->width;
  72. var->yres = gp->height;
  73. var->xres_virtual = var->xres;
  74. var->yres_virtual = var->yres;
  75. var->bits_per_pixel = gp->depth;
  76. var->red.offset = 0;
  77. var->red.length = 8;
  78. var->green.offset = 8;
  79. var->green.length = 8;
  80. var->blue.offset = 16;
  81. var->blue.length = 8;
  82. var->transp.offset = 0;
  83. var->transp.length = 0;
  84. if (fb_alloc_cmap(&info->cmap, 256, 0)) {
  85. printk(KERN_ERR "gfb: Cannot allocate color map.\n");
  86. return -ENOMEM;
  87. }
  88. return 0;
  89. }
  90. static int gfb_probe(struct platform_device *op)
  91. {
  92. struct device_node *dp = op->dev.of_node;
  93. struct fb_info *info;
  94. struct gfb_info *gp;
  95. int err;
  96. info = framebuffer_alloc(sizeof(struct gfb_info), &op->dev);
  97. if (!info) {
  98. err = -ENOMEM;
  99. goto err_out;
  100. }
  101. gp = info->par;
  102. gp->info = info;
  103. gp->of_node = dp;
  104. gp->fb_base_phys = op->resource[6].start;
  105. err = gfb_get_props(gp);
  106. if (err)
  107. goto err_release_fb;
  108. /* Framebuffer length is the same regardless of resolution. */
  109. info->fix.line_length = 16384;
  110. gp->fb_size = info->fix.line_length * gp->height;
  111. gp->fb_base = of_ioremap(&op->resource[6], 0,
  112. gp->fb_size, "gfb fb");
  113. if (!gp->fb_base) {
  114. err = -ENOMEM;
  115. goto err_release_fb;
  116. }
  117. err = gfb_set_fbinfo(gp);
  118. if (err)
  119. goto err_unmap_fb;
  120. printk("gfb: Found device at %pOF\n", dp);
  121. err = register_framebuffer(info);
  122. if (err < 0) {
  123. printk(KERN_ERR "gfb: Could not register framebuffer %pOF\n",
  124. dp);
  125. goto err_unmap_fb;
  126. }
  127. dev_set_drvdata(&op->dev, info);
  128. return 0;
  129. err_unmap_fb:
  130. of_iounmap(&op->resource[6], gp->fb_base, gp->fb_size);
  131. err_release_fb:
  132. framebuffer_release(info);
  133. err_out:
  134. return err;
  135. }
  136. static const struct of_device_id gfb_match[] = {
  137. {
  138. .name = "SUNW,gfb",
  139. },
  140. {},
  141. };
  142. static struct platform_driver gfb_driver = {
  143. .probe = gfb_probe,
  144. .driver = {
  145. .name = "gfb",
  146. .of_match_table = gfb_match,
  147. .suppress_bind_attrs = true,
  148. },
  149. };
  150. static int __init gfb_init(void)
  151. {
  152. if (fb_get_options("gfb", NULL))
  153. return -ENODEV;
  154. return platform_driver_register(&gfb_driver);
  155. }
  156. device_initcall(gfb_init);