q40fb.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * linux/drivers/video/q40fb.c -- Q40 frame buffer device
  3. *
  4. * Copyright (C) 2001
  5. *
  6. * Richard Zidlicky <rz@linux-m68k.org>
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file COPYING in the main directory of this archive for
  10. * more details.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/errno.h>
  14. #include <linux/string.h>
  15. #include <linux/mm.h>
  16. #include <linux/delay.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/uaccess.h>
  20. #include <asm/setup.h>
  21. #include <asm/q40_master.h>
  22. #include <linux/fb.h>
  23. #include <linux/module.h>
  24. #define Q40_PHYS_SCREEN_ADDR 0xFE800000
  25. static struct fb_fix_screeninfo q40fb_fix = {
  26. .id = "Q40",
  27. .smem_len = 1024*1024,
  28. .type = FB_TYPE_PACKED_PIXELS,
  29. .visual = FB_VISUAL_TRUECOLOR,
  30. .line_length = 1024*2,
  31. .accel = FB_ACCEL_NONE,
  32. };
  33. static const struct fb_var_screeninfo q40fb_var = {
  34. .xres = 1024,
  35. .yres = 512,
  36. .xres_virtual = 1024,
  37. .yres_virtual = 512,
  38. .bits_per_pixel = 16,
  39. .red = {6, 5, 0},
  40. .green = {11, 5, 0},
  41. .blue = {0, 6, 0},
  42. .activate = FB_ACTIVATE_NOW,
  43. .height = 230,
  44. .width = 300,
  45. .vmode = FB_VMODE_NONINTERLACED,
  46. };
  47. static int q40fb_setcolreg(unsigned regno, unsigned red, unsigned green,
  48. unsigned blue, unsigned transp,
  49. struct fb_info *info)
  50. {
  51. /*
  52. * Set a single color register. The values supplied have a 16 bit
  53. * magnitude.
  54. * Return != 0 for invalid regno.
  55. */
  56. if (regno > 255)
  57. return 1;
  58. red>>=11;
  59. green>>=11;
  60. blue>>=10;
  61. if (regno < 16) {
  62. ((u32 *)info->pseudo_palette)[regno] = ((red & 31) <<6) |
  63. ((green & 31) << 11) |
  64. (blue & 63);
  65. }
  66. return 0;
  67. }
  68. static const struct fb_ops q40fb_ops = {
  69. .owner = THIS_MODULE,
  70. FB_DEFAULT_IOMEM_OPS,
  71. .fb_setcolreg = q40fb_setcolreg,
  72. };
  73. static int q40fb_probe(struct platform_device *dev)
  74. {
  75. struct fb_info *info;
  76. if (!MACH_IS_Q40)
  77. return -ENXIO;
  78. /* mapped in q40/config.c */
  79. q40fb_fix.smem_start = Q40_PHYS_SCREEN_ADDR;
  80. info = framebuffer_alloc(sizeof(u32) * 16, &dev->dev);
  81. if (!info)
  82. return -ENOMEM;
  83. info->var = q40fb_var;
  84. info->fix = q40fb_fix;
  85. info->fbops = &q40fb_ops;
  86. info->pseudo_palette = info->par;
  87. info->par = NULL;
  88. info->screen_base = (char *) q40fb_fix.smem_start;
  89. if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
  90. framebuffer_release(info);
  91. return -ENOMEM;
  92. }
  93. master_outb(3, DISPLAY_CONTROL_REG);
  94. if (register_framebuffer(info) < 0) {
  95. printk(KERN_ERR "Unable to register Q40 frame buffer\n");
  96. fb_dealloc_cmap(&info->cmap);
  97. framebuffer_release(info);
  98. return -EINVAL;
  99. }
  100. fb_info(info, "Q40 frame buffer alive and kicking !\n");
  101. return 0;
  102. }
  103. static struct platform_driver q40fb_driver = {
  104. .probe = q40fb_probe,
  105. .driver = {
  106. .name = "q40fb",
  107. },
  108. };
  109. static struct platform_device q40fb_device = {
  110. .name = "q40fb",
  111. };
  112. static int __init q40fb_init(void)
  113. {
  114. int ret = 0;
  115. if (fb_get_options("q40fb", NULL))
  116. return -ENODEV;
  117. ret = platform_driver_register(&q40fb_driver);
  118. if (!ret) {
  119. ret = platform_device_register(&q40fb_device);
  120. if (ret)
  121. platform_driver_unregister(&q40fb_driver);
  122. }
  123. return ret;
  124. }
  125. module_init(q40fb_init);
  126. MODULE_LICENSE("GPL");