2 * Copyright 2003, Thomas Kurschel. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 /*! DDC communication */
13 #include <KernelExport.h>
19 #define READ_RETRIES 4 // number of retries to read ddc data
23 extern void _sPrintf(const char* format
, ...);
24 # define TRACE(x...) _sPrintf("DDC: " x)
26 # define TRACE(x...) ;
30 //! Verify checksum of DDC data.
32 verify_checksum(const uint8
*data
, size_t len
)
38 for (index
= 0; index
< len
; ++index
, ++data
) {
44 TRACE("%s: DDC information contains zeros only\n", __func__
);
49 TRACE("%s: Checksum error in DDC information\n", __func__
);
57 //! Read ddc2 data from monitor
59 ddc2_read(const i2c_bus
*bus
, int start
, uint8
*buffer
, size_t length
)
61 status_t status
= B_OK
;
65 writeBuffer
[0] = start
& 0xff;
66 writeBuffer
[1] = (start
>> 8) & 0xff;
68 for (i
= 0; i
< READ_RETRIES
; ++i
) {
69 status
= i2c_send_receive(bus
, 0xa0, writeBuffer
,
70 start
< 0x100 ? 1 : 2, buffer
, length
);
73 TRACE("%s: DDC information read failure\n", __func__
);
76 status
= verify_checksum(buffer
, length
);
80 dprintf("%s: DDC checksum incorrect!\n", __func__
);
89 Reading VDIF has not been tested.
90 it seems that almost noone supports VDIF which makes testing hard,
91 but what's the point anyway?
95 ddc2_read_vdif(const i2c_bus
*bus
, int start
,
96 void **vdif
, size_t *vdif_len
)
99 uint8
*data
, *cur_data
;
106 res
= ddc2_read(bus
, start
, buffer
, 64);
107 SHOW_INFO(2, "%x", buffer
[0]);
108 if (res
!= B_OK
|| buffer
[0] == 0)
111 // each block is 63 bytes plus 1 checksum long
112 // we strip the checksum but store data directly into
113 // buffer, so we need an extra byte for checksum of the last block
114 data
= malloc(buffer
[0] * 63 + 1);
119 for (i
= 0; i
< buffer
[0]; ++i
) {
120 ddc2_read(bus
, start
+ i
* 64, cur_data
, 64);
121 // strip checksum byte
125 *vdif_len
= buffer
[0] * 63;
136 ddc2_init_timing(i2c_bus
*bus
)
138 i2c_get100k_timing(&bus
->timing
);
141 bus
->timing
.start_timeout
= 550;
142 bus
->timing
.byte_timeout
= 2200;
143 bus
->timing
.bit_timeout
= 40;
144 bus
->timing
.ack_start_timeout
= 40;
145 bus
->timing
.ack_timeout
= 40;
149 //! Read EDID and VDIF from monitor via ddc2
151 ddc2_read_edid1(const i2c_bus
*bus
, edid1_info
*edid
,
152 void **vdif
, size_t *vdifLength
)
155 status_t status
= ddc2_read(bus
, 0, (uint8
*)&raw
, sizeof(raw
));
159 if (raw
.version
.version
!= 1 || raw
.version
.revision
> 4) {
160 TRACE("%s: EDID version or revision out of range\n", __func__
);
164 edid_decode(edid
, &raw
);
168 if (vdifLength
!= NULL
)
171 // skip vdif as long as it's not tested
173 status
= ddc2_read_vdif(bus
, sizeof(raw
) * (edid
->num_sections
+ 1),