fb_ddc.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 <linux/slab.h>
  15. #include "edid.h"
  16. #define DDC_ADDR 0x50
  17. static unsigned char *fb_do_probe_ddc_edid(struct i2c_adapter *adapter)
  18. {
  19. unsigned char start = 0x0;
  20. unsigned char *buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
  21. struct i2c_msg msgs[] = {
  22. {
  23. .addr = DDC_ADDR,
  24. .flags = 0,
  25. .len = 1,
  26. .buf = &start,
  27. }, {
  28. .addr = DDC_ADDR,
  29. .flags = I2C_M_RD,
  30. .len = EDID_LENGTH,
  31. .buf = buf,
  32. }
  33. };
  34. if (!buf) {
  35. dev_warn(&adapter->dev, "unable to allocate memory for EDID "
  36. "block.\n");
  37. return NULL;
  38. }
  39. if (i2c_transfer(adapter, msgs, 2) == 2)
  40. return buf;
  41. dev_warn(&adapter->dev, "unable to read EDID block.\n");
  42. kfree(buf);
  43. return NULL;
  44. }
  45. unsigned char *fb_ddc_read(struct i2c_adapter *adapter)
  46. {
  47. struct i2c_algo_bit_data *algo_data = adapter->algo_data;
  48. unsigned char *edid = NULL;
  49. int i, j;
  50. algo_data->setscl(algo_data->data, 1);
  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, 1);
  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. algo_data->setsda(algo_data->data, 0);
  86. if (edid)
  87. break;
  88. }
  89. /* Release the DDC lines when done or the Apple Cinema HD display
  90. * will switch off
  91. */
  92. algo_data->setsda(algo_data->data, 1);
  93. algo_data->setscl(algo_data->data, 1);
  94. adapter->class |= I2C_CLASS_DDC;
  95. return edid;
  96. }
  97. EXPORT_SYMBOL_GPL(fb_ddc_read);
  98. MODULE_AUTHOR("Dennis Munsie <dmunsie@cecropia.com>");
  99. MODULE_DESCRIPTION("DDC/EDID reading support");
  100. MODULE_LICENSE("GPL");