fb_ddc.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * drivers/video/fb_ddc.c - DDC/EDID read support.
  3. *
  4. * Copyright (C) 2006 Dennis Munsie <dmunsie@cecropia.com>
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file COPYING in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/delay.h>
  11. #include <linux/device.h>
  12. #include <linux/module.h>
  13. #include <linux/fb.h>
  14. #include <linux/i2c-algo-bit.h>
  15. #include <linux/slab.h>
  16. #include "edid.h"
  17. #define DDC_ADDR 0x50
  18. static unsigned char *fb_do_probe_ddc_edid(struct i2c_adapter *adapter)
  19. {
  20. unsigned char start = 0x0;
  21. unsigned char *buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
  22. struct i2c_msg msgs[] = {
  23. {
  24. .addr = DDC_ADDR,
  25. .flags = 0,
  26. .len = 1,
  27. .buf = &start,
  28. }, {
  29. .addr = DDC_ADDR,
  30. .flags = I2C_M_RD,
  31. .len = EDID_LENGTH,
  32. .buf = buf,
  33. }
  34. };
  35. if (!buf) {
  36. dev_warn(&adapter->dev, "unable to allocate memory for EDID "
  37. "block.\n");
  38. return NULL;
  39. }
  40. if (i2c_transfer(adapter, msgs, 2) == 2)
  41. return buf;
  42. dev_warn(&adapter->dev, "unable to read EDID block.\n");
  43. kfree(buf);
  44. return NULL;
  45. }
  46. unsigned char *fb_ddc_read(struct i2c_adapter *adapter)
  47. {
  48. struct i2c_algo_bit_data *algo_data = adapter->algo_data;
  49. unsigned char *edid = NULL;
  50. int i, j;
  51. algo_data->setscl(algo_data->data, 1);
  52. for (i = 0; i < 3; i++) {
  53. /* For some old monitors we need the
  54. * following process to initialize/stop DDC
  55. */
  56. algo_data->setsda(algo_data->data, 1);
  57. msleep(13);
  58. algo_data->setscl(algo_data->data, 1);
  59. for (j = 0; j < 5; j++) {
  60. msleep(10);
  61. if (algo_data->getscl(algo_data->data))
  62. break;
  63. }
  64. if (j == 5)
  65. continue;
  66. algo_data->setsda(algo_data->data, 0);
  67. msleep(15);
  68. algo_data->setscl(algo_data->data, 0);
  69. msleep(15);
  70. algo_data->setsda(algo_data->data, 1);
  71. msleep(15);
  72. /* Do the real work */
  73. edid = fb_do_probe_ddc_edid(adapter);
  74. algo_data->setsda(algo_data->data, 0);
  75. algo_data->setscl(algo_data->data, 0);
  76. msleep(15);
  77. algo_data->setscl(algo_data->data, 1);
  78. for (j = 0; j < 10; j++) {
  79. msleep(10);
  80. if (algo_data->getscl(algo_data->data))
  81. break;
  82. }
  83. algo_data->setsda(algo_data->data, 1);
  84. msleep(15);
  85. algo_data->setscl(algo_data->data, 0);
  86. algo_data->setsda(algo_data->data, 0);
  87. if (edid)
  88. break;
  89. }
  90. /* Release the DDC lines when done or the Apple Cinema HD display
  91. * will switch off
  92. */
  93. algo_data->setsda(algo_data->data, 1);
  94. algo_data->setscl(algo_data->data, 1);
  95. adapter->class |= I2C_CLASS_DDC;
  96. return edid;
  97. }
  98. EXPORT_SYMBOL_GPL(fb_ddc_read);
  99. MODULE_AUTHOR("Dennis Munsie <dmunsie@cecropia.com>");
  100. MODULE_DESCRIPTION("DDC/EDID reading support");
  101. MODULE_LICENSE("GPL");