ACPI: thinkpad-acpi: use bitfields to hold subdriver flags
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / video / fb_ddc.c
blobf836137a0edac366b1d814c4230d7517e88a6b9d
1 /*
2 * driver/vide/fb_ddc.c - DDC/EDID read support.
4 * Copyright (C) 2006 Dennis Munsie <dmunsie@cecropia.com>
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 */
11 #include <linux/delay.h>
12 #include <linux/device.h>
13 #include <linux/fb.h>
14 #include <linux/i2c-algo-bit.h>
16 #include "edid.h"
18 #define DDC_ADDR 0x50
20 static unsigned char *fb_do_probe_ddc_edid(struct i2c_adapter *adapter)
22 unsigned char start = 0x0;
23 unsigned char *buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
24 struct i2c_msg msgs[] = {
26 .addr = DDC_ADDR,
27 .flags = 0,
28 .len = 1,
29 .buf = &start,
30 }, {
31 .addr = DDC_ADDR,
32 .flags = I2C_M_RD,
33 .len = EDID_LENGTH,
34 .buf = buf,
38 if (!buf) {
39 dev_warn(&adapter->dev, "unable to allocate memory for EDID "
40 "block.\n");
41 return NULL;
44 if (i2c_transfer(adapter, msgs, 2) == 2)
45 return buf;
47 dev_warn(&adapter->dev, "unable to read EDID block.\n");
48 kfree(buf);
49 return NULL;
52 unsigned char *fb_ddc_read(struct i2c_adapter *adapter)
54 struct i2c_algo_bit_data *algo_data = adapter->algo_data;
55 unsigned char *edid = NULL;
56 int i, j;
58 algo_data->setscl(algo_data->data, 1);
59 algo_data->setscl(algo_data->data, 0);
61 for (i = 0; i < 3; i++) {
62 /* For some old monitors we need the
63 * following process to initialize/stop DDC
65 algo_data->setsda(algo_data->data, 0);
66 msleep(13);
68 algo_data->setscl(algo_data->data, 1);
69 for (j = 0; j < 5; j++) {
70 msleep(10);
71 if (algo_data->getscl(algo_data->data))
72 break;
74 if (j == 5)
75 continue;
77 algo_data->setsda(algo_data->data, 0);
78 msleep(15);
79 algo_data->setscl(algo_data->data, 0);
80 msleep(15);
81 algo_data->setsda(algo_data->data, 1);
82 msleep(15);
84 /* Do the real work */
85 edid = fb_do_probe_ddc_edid(adapter);
86 algo_data->setsda(algo_data->data, 0);
87 algo_data->setscl(algo_data->data, 0);
88 msleep(15);
90 algo_data->setscl(algo_data->data, 1);
91 for (j = 0; j < 10; j++) {
92 msleep(10);
93 if (algo_data->getscl(algo_data->data))
94 break;
97 algo_data->setsda(algo_data->data, 1);
98 msleep(15);
99 algo_data->setscl(algo_data->data, 0);
100 if (edid)
101 break;
103 /* Release the DDC lines when done or the Apple Cinema HD display
104 * will switch off
106 algo_data->setsda(algo_data->data, 0);
107 algo_data->setscl(algo_data->data, 0);
109 return edid;
112 EXPORT_SYMBOL_GPL(fb_ddc_read);
114 MODULE_AUTHOR("Dennis Munsie <dmunsie@cecropia.com>");
115 MODULE_DESCRIPTION("DDC/EDID reading support");
116 MODULE_LICENSE("GPL");