via_aux_edid.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright 2011 Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public
  6. * License as published by the Free Software Foundation;
  7. * either version 2, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
  11. * the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. * A PARTICULAR PURPOSE.See the GNU General Public License
  13. * for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc.,
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. /*
  21. * generic EDID driver
  22. */
  23. #include <linux/slab.h>
  24. #include <linux/fb.h>
  25. #include "via_aux.h"
  26. #include "../edid.h"
  27. static const char *name = "EDID";
  28. static void query_edid(struct via_aux_drv *drv)
  29. {
  30. struct fb_monspecs *spec = drv->data;
  31. unsigned char edid[EDID_LENGTH];
  32. bool valid = false;
  33. if (spec) {
  34. fb_destroy_modedb(spec->modedb);
  35. } else {
  36. spec = kmalloc(sizeof(*spec), GFP_KERNEL);
  37. if (!spec)
  38. return;
  39. }
  40. spec->version = spec->revision = 0;
  41. if (via_aux_read(drv, 0x00, edid, EDID_LENGTH)) {
  42. fb_edid_to_monspecs(edid, spec);
  43. valid = spec->version || spec->revision;
  44. }
  45. if (!valid) {
  46. kfree(spec);
  47. spec = NULL;
  48. } else
  49. printk(KERN_DEBUG "EDID: %s %s\n", spec->manufacturer, spec->monitor);
  50. drv->data = spec;
  51. }
  52. static const struct fb_videomode *get_preferred_mode(struct via_aux_drv *drv)
  53. {
  54. struct fb_monspecs *spec = drv->data;
  55. int i;
  56. if (!spec || !spec->modedb || !(spec->misc & FB_MISC_1ST_DETAIL))
  57. return NULL;
  58. for (i = 0; i < spec->modedb_len; i++) {
  59. if (spec->modedb[i].flag & FB_MODE_IS_FIRST &&
  60. spec->modedb[i].flag & FB_MODE_IS_DETAILED)
  61. return &spec->modedb[i];
  62. }
  63. return NULL;
  64. }
  65. static void cleanup(struct via_aux_drv *drv)
  66. {
  67. struct fb_monspecs *spec = drv->data;
  68. if (spec)
  69. fb_destroy_modedb(spec->modedb);
  70. }
  71. void via_aux_edid_probe(struct via_aux_bus *bus)
  72. {
  73. struct via_aux_drv drv = {
  74. .bus = bus,
  75. .addr = 0x50,
  76. .name = name,
  77. .cleanup = cleanup,
  78. .get_preferred_mode = get_preferred_mode};
  79. query_edid(&drv);
  80. /* as EDID devices can be connected/disconnected just add the driver */
  81. via_aux_add(&drv);
  82. }