via_aux_edid.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. spec->version = spec->revision = 0;
  38. if (via_aux_read(drv, 0x00, edid, EDID_LENGTH)) {
  39. fb_edid_to_monspecs(edid, spec);
  40. valid = spec->version || spec->revision;
  41. }
  42. if (!valid) {
  43. kfree(spec);
  44. spec = NULL;
  45. } else
  46. printk(KERN_DEBUG "EDID: %s %s\n", spec->manufacturer, spec->monitor);
  47. drv->data = spec;
  48. }
  49. static const struct fb_videomode *get_preferred_mode(struct via_aux_drv *drv)
  50. {
  51. struct fb_monspecs *spec = drv->data;
  52. int i;
  53. if (!spec || !spec->modedb || !(spec->misc & FB_MISC_1ST_DETAIL))
  54. return NULL;
  55. for (i = 0; i < spec->modedb_len; i++) {
  56. if (spec->modedb[i].flag & FB_MODE_IS_FIRST &&
  57. spec->modedb[i].flag & FB_MODE_IS_DETAILED)
  58. return &spec->modedb[i];
  59. }
  60. return NULL;
  61. }
  62. static void cleanup(struct via_aux_drv *drv)
  63. {
  64. struct fb_monspecs *spec = drv->data;
  65. if (spec)
  66. fb_destroy_modedb(spec->modedb);
  67. }
  68. void via_aux_edid_probe(struct via_aux_bus *bus)
  69. {
  70. struct via_aux_drv drv = {
  71. .bus = bus,
  72. .addr = 0x50,
  73. .name = name,
  74. .cleanup = cleanup,
  75. .get_preferred_mode = get_preferred_mode};
  76. query_edid(&drv);
  77. /* as EDID devices can be connected/disconnected just add the driver */
  78. via_aux_add(&drv);
  79. }