fb_ddc.c 2.5 KB

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