Patch by Vasilis Kaoutsis - thanks!:
* Fixed some warnings. * Style cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21774 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,32 +1,40 @@
|
||||
/*
|
||||
Copyright (c) 2003, Thomas Kurschel
|
||||
* Copyright 2003, Thomas Kurschel. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
Part of DDC driver
|
||||
|
||||
Main DDC communication
|
||||
*/
|
||||
|
||||
#include <OS.h>
|
||||
#include <KernelExport.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "ddc_int.h"
|
||||
#include "ddc.h"
|
||||
|
||||
#include "i2c.h"
|
||||
|
||||
// number of retries to read ddc data
|
||||
#define READ_RETRIES 4
|
||||
#include <KernelExport.h>
|
||||
#include <OS.h>
|
||||
|
||||
// verify checksum of ddc data
|
||||
// (some monitors have a broken checksum - bad luck for them)
|
||||
static status_t verify_checksum( const uint8 *data, size_t len )
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#define READ_RETRIES 4
|
||||
// number of retries to read ddc data
|
||||
|
||||
#if 0
|
||||
/*! Verify checksum of ddc data
|
||||
(some monitors have a broken checksum - bad luck for them)
|
||||
*/
|
||||
static status_t
|
||||
verify_checksum(const uint8 *data, size_t len)
|
||||
{
|
||||
int i;
|
||||
uint32 index;
|
||||
uint8 sum = 0;
|
||||
uint8 all_or = 0;
|
||||
|
||||
for( i = 0; i < len; ++i, ++data ) {
|
||||
for (index = 0; index < len; ++index, ++data) {
|
||||
sum += *data;
|
||||
all_or |= *data;
|
||||
}
|
||||
@@ -43,14 +51,17 @@ static status_t verify_checksum( const uint8 *data, size_t len )
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
// read ddc2 data from monitor
|
||||
static status_t ddc2_read( const i2c_bus *bus, int start, uint8 *buffer, size_t len )
|
||||
|
||||
//! Read ddc2 data from monitor
|
||||
static status_t
|
||||
ddc2_read(const i2c_bus *bus, int start, uint8 *buffer, size_t len)
|
||||
{
|
||||
uint8 write_buffer[2];
|
||||
i2c_timing timing;
|
||||
int i;
|
||||
status_t res;
|
||||
status_t res = B_OK;
|
||||
|
||||
write_buffer[0] = start & 0xff;
|
||||
write_buffer[1] = (start >> 8) & 0xff;
|
||||
@@ -78,11 +89,14 @@ static status_t ddc2_read( const i2c_bus *bus, int start, uint8 *buffer, size_t
|
||||
}
|
||||
|
||||
|
||||
// reading VDIF has not been tested.
|
||||
// it seems that almost noone supports VDIF which makes testing hard,
|
||||
// but what's the point anyway?
|
||||
/*!
|
||||
Reading VDIF has not been tested.
|
||||
it seems that almost noone supports VDIF which makes testing hard,
|
||||
but what's the point anyway?
|
||||
*/
|
||||
#if 0
|
||||
static status_t ddc2_read_vdif( const i2c_bus *bus, int start,
|
||||
static status_t
|
||||
ddc2_read_vdif(const i2c_bus *bus, int start,
|
||||
void **vdif, size_t *vdif_len)
|
||||
{
|
||||
status_t res;
|
||||
@@ -118,8 +132,10 @@ static status_t ddc2_read_vdif( const i2c_bus *bus, int start,
|
||||
}
|
||||
#endif
|
||||
|
||||
// read EDID and VDIF from monitor via ddc2
|
||||
status_t ddc2_read_edid1( const i2c_bus *bus, edid1_info *edid,
|
||||
|
||||
//! Read EDID and VDIF from monitor via ddc2
|
||||
status_t
|
||||
ddc2_read_edid1(const i2c_bus *bus, edid1_info *edid,
|
||||
void **vdif, size_t *vdif_len)
|
||||
{
|
||||
status_t res;
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
/*
|
||||
Copyright (c) 2003, Thomas Kurschel
|
||||
* Copyright 2003, Thomas Kurschel. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef DDC_INT_H
|
||||
#define DDC_INT_H
|
||||
|
||||
|
||||
/*!
|
||||
Part of DDC driver
|
||||
|
||||
Internal header
|
||||
*/
|
||||
|
||||
// no dprintf in user space, but if you know the trick ;)
|
||||
|
||||
void _sPrintf(const char *format, ...);
|
||||
// no dprintf in user space, but if you know the trick ;)
|
||||
|
||||
//bool set_dprintf_enabled(bool); /* returns old enable flag */
|
||||
|
||||
#define dprintf _sPrintf
|
||||
@@ -21,3 +27,5 @@ void _sPrintf(const char *format, ...);
|
||||
#define DEBUG_MSG_PREFIX "DDC "
|
||||
|
||||
#include "debug_ext.h"
|
||||
|
||||
#endif // DDC_INT_H
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Thomas Kurschel. All Rights Reserved.
|
||||
* Copyright 2003, Thomas Kurschel. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
Part of DDC driver
|
||||
|
||||
@@ -16,6 +17,7 @@
|
||||
#include "edid.h"
|
||||
|
||||
#include <KernelExport.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
@@ -89,12 +91,15 @@ decode_std_timing(edid1_std_timing *timing, const edid1_std_timing_raw *raw)
|
||||
case 0:
|
||||
timing->v_size = timing->h_size;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
timing->v_size = timing->h_size * 3 / 4;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
timing->v_size = timing->h_size * 4 / 5;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
timing->v_size = timing->h_size * 9 / 16;
|
||||
break;
|
||||
@@ -191,21 +196,26 @@ decode_detailed_monitor( edid1_detailed_monitor *monitor,
|
||||
copy_str( monitor->data.serial_number,
|
||||
raw->extra.data.serial_number, EDID1_EXTRA_STRING_LEN );
|
||||
break;
|
||||
|
||||
case edid1_ascii_data:
|
||||
copy_str( monitor->data.ascii_data,
|
||||
raw->extra.data.ascii_data, EDID1_EXTRA_STRING_LEN );
|
||||
break;
|
||||
|
||||
case edid1_monitor_ranges:
|
||||
monitor->data.monitor_range = raw->extra.data.monitor_range;
|
||||
break;
|
||||
|
||||
case edid1_monitor_name:
|
||||
copy_str( monitor->data.monitor_name,
|
||||
raw->extra.data.monitor_name, EDID1_EXTRA_STRING_LEN );
|
||||
break;
|
||||
|
||||
case edid1_add_colour_pointer:
|
||||
decode_whitepoint( monitor->data.whitepoint,
|
||||
&raw->extra.data.whitepoint );
|
||||
break;
|
||||
|
||||
case edid1_add_std_timing:
|
||||
for (j = 0; j < EDID1_NUM_EXTRA_STD_TIMING; ++j) {
|
||||
decode_std_timing(&monitor->data.std_timing[j],
|
||||
@@ -224,7 +234,7 @@ decode_detailed_monitor( edid1_detailed_monitor *monitor,
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
//! main function to decode edid data
|
||||
//! Main function to decode edid data
|
||||
void
|
||||
edid_decode(edid1_info *edid, const edid1_raw *raw)
|
||||
{
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
Part of DDC driver
|
||||
Dumps EDID content
|
||||
*/
|
||||
|
||||
|
||||
#include "edid.h"
|
||||
#if !defined(_KERNEL_MODE) && !defined(_BOOT_MODE)
|
||||
# include "ddc_int.h"
|
||||
@@ -91,10 +93,13 @@ edid_dump(edid1_info *edid)
|
||||
case edid1_serial_number:
|
||||
dprintf("Serial Number: %s\n", monitor->data.serial_number);
|
||||
break;
|
||||
|
||||
case edid1_ascii_data:
|
||||
dprintf(" %s\n", monitor->data.serial_number);
|
||||
break;
|
||||
case edid1_monitor_ranges: {
|
||||
|
||||
case edid1_monitor_ranges:
|
||||
{
|
||||
edid1_monitor_range monitor_range = monitor->data.monitor_range;
|
||||
|
||||
dprintf("Horizontal frequency range = %d..%d kHz\n",
|
||||
@@ -104,10 +109,13 @@ edid_dump(edid1_info *edid)
|
||||
dprintf("Maximum pixel clock = %d MHz\n", (uint16)monitor_range.max_clock * 10);
|
||||
break;
|
||||
}
|
||||
|
||||
case edid1_monitor_name:
|
||||
dprintf("Monitor Name: %s\n", monitor->data.serial_number);
|
||||
break;
|
||||
case edid1_add_colour_pointer: {
|
||||
|
||||
case edid1_add_colour_pointer:
|
||||
{
|
||||
for (j = 0; j < EDID1_NUM_EXTRA_WHITEPOINTS; ++j) {
|
||||
edid1_whitepoint *whitepoint = &monitor->data.whitepoint[j];
|
||||
|
||||
@@ -122,7 +130,9 @@ edid_dump(edid1_info *edid)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case edid1_add_std_timing: {
|
||||
|
||||
case edid1_add_std_timing:
|
||||
{
|
||||
for (j = 0; j < EDID1_NUM_EXTRA_STD_TIMING; ++j) {
|
||||
edid1_std_timing *timing = &monitor->data.std_timing[j];
|
||||
|
||||
@@ -135,7 +145,9 @@ edid_dump(edid1_info *edid)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case edid1_is_detailed_timing: {
|
||||
|
||||
case edid1_is_detailed_timing:
|
||||
{
|
||||
edid1_detailed_timing *timing = &monitor->data.detailed_timing;
|
||||
|
||||
dprintf("Additional Video Mode:\n");
|
||||
|
||||
@@ -1,24 +1,28 @@
|
||||
/*
|
||||
Copyright (c) 2003, Thomas Kurschel
|
||||
* Copyright 2003, Thomas Kurschel. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
Part of DDC driver
|
||||
|
||||
I2C protocoll
|
||||
*/
|
||||
|
||||
#include <OS.h>
|
||||
#include <KernelExport.h>
|
||||
|
||||
#include "ddc_int.h"
|
||||
#include "i2c.h"
|
||||
|
||||
#include "ddc_int.h"
|
||||
#include <KernelExport.h>
|
||||
#include <OS.h>
|
||||
|
||||
|
||||
// there's no spin in user space, but we need it to wait a couple
|
||||
// of microseconds only
|
||||
// (in this case, snooze has much too much overhead)
|
||||
void spin( bigtime_t delay )
|
||||
/*!
|
||||
There's no spin in user space, but we need it to wait a couple
|
||||
of microseconds only
|
||||
(in this case, snooze has much too much overhead)
|
||||
*/
|
||||
void
|
||||
spin(bigtime_t delay)
|
||||
{
|
||||
bigtime_t start_time = system_time();
|
||||
|
||||
@@ -27,8 +31,9 @@ void spin( bigtime_t delay )
|
||||
}
|
||||
|
||||
|
||||
// wait until slave releases clock signal ("clock stretching")
|
||||
static status_t wait_for_clk( const i2c_bus *bus, const i2c_timing *timing,
|
||||
//! Wait until slave releases clock signal ("clock stretching")
|
||||
static status_t
|
||||
wait_for_clk(const i2c_bus *bus, const i2c_timing *timing,
|
||||
bigtime_t timeout)
|
||||
{
|
||||
bigtime_t start_time;
|
||||
@@ -53,8 +58,9 @@ static status_t wait_for_clk( const i2c_bus *bus, const i2c_timing *timing,
|
||||
}
|
||||
|
||||
|
||||
// send start or repeated start condition
|
||||
static status_t send_start_condition( const i2c_bus *bus, const i2c_timing *timing )
|
||||
//! Send start or repeated start condition
|
||||
static status_t
|
||||
send_start_condition(const i2c_bus *bus, const i2c_timing *timing)
|
||||
{
|
||||
status_t res;
|
||||
|
||||
@@ -76,8 +82,9 @@ static status_t send_start_condition( const i2c_bus *bus, const i2c_timing *timi
|
||||
}
|
||||
|
||||
|
||||
// send stop condition
|
||||
static status_t send_stop_condition( const i2c_bus *bus, const i2c_timing *timing )
|
||||
//! Send stop condition
|
||||
static status_t
|
||||
send_stop_condition(const i2c_bus *bus, const i2c_timing *timing)
|
||||
{
|
||||
status_t res;
|
||||
|
||||
@@ -103,8 +110,9 @@ static status_t send_stop_condition( const i2c_bus *bus, const i2c_timing *timin
|
||||
}
|
||||
|
||||
|
||||
// send one bit
|
||||
static status_t send_bit( const i2c_bus *bus, const i2c_timing *timing, bool bit, int timeout )
|
||||
//! Send one bit
|
||||
static status_t
|
||||
send_bit(const i2c_bus *bus, const i2c_timing *timing, bool bit, int timeout)
|
||||
{
|
||||
status_t res;
|
||||
|
||||
@@ -128,8 +136,9 @@ static status_t send_bit( const i2c_bus *bus, const i2c_timing *timing, bool bit
|
||||
}
|
||||
|
||||
|
||||
// send acknowledge and wait for reply
|
||||
static status_t send_acknowledge( const i2c_bus *bus, const i2c_timing *timing )
|
||||
//! Send acknowledge and wait for reply
|
||||
static status_t
|
||||
send_acknowledge(const i2c_bus *bus, const i2c_timing *timing)
|
||||
{
|
||||
status_t res;
|
||||
bigtime_t start_time;
|
||||
@@ -177,8 +186,9 @@ static status_t send_acknowledge( const i2c_bus *bus, const i2c_timing *timing )
|
||||
}
|
||||
|
||||
|
||||
// send byte and wait for acknowledge if <ackowledge> is true
|
||||
static status_t send_byte( const i2c_bus *bus, const i2c_timing *timing,
|
||||
//! Send byte and wait for acknowledge if <ackowledge> is true
|
||||
static status_t
|
||||
send_byte(const i2c_bus *bus, const i2c_timing *timing,
|
||||
uint8 byte, bool acknowledge)
|
||||
{
|
||||
int i;
|
||||
@@ -200,9 +210,11 @@ static status_t send_byte( const i2c_bus *bus, const i2c_timing *timing,
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
// send slave address, obeying 10-bit addresses and general call addresses
|
||||
static status_t send_slave_address( const i2c_bus *bus,
|
||||
const i2c_timing *timing, int slave_address, bool is_write )
|
||||
|
||||
//! Send slave address, obeying 10-bit addresses and general call addresses
|
||||
static status_t
|
||||
send_slave_address( const i2c_bus *bus, const i2c_timing *timing,
|
||||
int slave_address, bool is_write )
|
||||
{
|
||||
status_t res;
|
||||
|
||||
@@ -221,24 +233,24 @@ static status_t send_slave_address( const i2c_bus *bus,
|
||||
// - 1111 0xxx - 10 bit address (second byte contains remaining 8 bits)
|
||||
|
||||
// the lsb is 0 for write and 1 for read (except for general call address)
|
||||
if( (slave_address & 0xff) != 0 &&
|
||||
(slave_address & 0xf8) != 0xf0 )
|
||||
if ((slave_address & 0xff) != 0 && (slave_address & 0xf8) != 0xf0)
|
||||
return B_OK;
|
||||
|
||||
// send second byte if required
|
||||
return send_byte(bus, timing, slave_address >> 8, true);
|
||||
// send second byte if required
|
||||
}
|
||||
|
||||
|
||||
// receive one bit
|
||||
static status_t receive_bit( const i2c_bus *bus, const i2c_timing *timing,
|
||||
//! Receive one bit
|
||||
static status_t
|
||||
receive_bit(const i2c_bus *bus, const i2c_timing *timing,
|
||||
bool *bit, int timeout)
|
||||
{
|
||||
status_t res;
|
||||
int clk, data;
|
||||
|
||||
// release clock
|
||||
bus->set_signals(bus->cookie, 1, 1);
|
||||
// release clock
|
||||
|
||||
// wait for slave to raise clock
|
||||
res = wait_for_clk(bus, timing, timeout);
|
||||
@@ -247,23 +259,30 @@ static status_t receive_bit( const i2c_bus *bus, const i2c_timing *timing,
|
||||
return res;
|
||||
}
|
||||
|
||||
// sample data
|
||||
bus->get_signals(bus->cookie, &clk, &data);
|
||||
// leave clock high for minimal time
|
||||
// sample data
|
||||
|
||||
spin(timing->high);
|
||||
// pull clock low so slave waits for us before next bit
|
||||
// leave clock high for minimal time
|
||||
|
||||
bus->set_signals(bus->cookie, 0, 1);
|
||||
// pull clock low so slave waits for us before next bit
|
||||
|
||||
spin(timing->f + timing->low);
|
||||
// let it settle and leave it low for minimal time
|
||||
// to make sure slave has finished bit transmission too
|
||||
spin( timing->f + timing->low);
|
||||
|
||||
*bit = data;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
// receive byte
|
||||
// send positive acknowledge afterwards if <acknowledge> is true, else send negative one
|
||||
static status_t receive_byte( const i2c_bus *bus, const i2c_timing *timing,
|
||||
|
||||
/*! receive byte
|
||||
Send positive acknowledge afterwards if <acknowledge> is true,
|
||||
else send negative one
|
||||
*/
|
||||
static status_t
|
||||
receive_byte(const i2c_bus *bus, const i2c_timing *timing,
|
||||
uint8 *res_byte, bool acknowledge)
|
||||
{
|
||||
uint8 byte = 0;
|
||||
@@ -291,8 +310,10 @@ static status_t receive_byte( const i2c_bus *bus, const i2c_timing *timing,
|
||||
return send_bit(bus, timing, acknowledge ? 0 : 1, timing->bit_timeout);
|
||||
}
|
||||
|
||||
// send multiple bytes
|
||||
static status_t send_bytes( const i2c_bus *bus, const i2c_timing *timing,
|
||||
|
||||
//! Send multiple bytes
|
||||
static status_t
|
||||
send_bytes(const i2c_bus *bus, const i2c_timing *timing,
|
||||
const uint8 *write_buffer, ssize_t write_len)
|
||||
{
|
||||
SHOW_FLOW( 3, "len=%ld", write_len );
|
||||
@@ -308,8 +329,10 @@ static status_t send_bytes( const i2c_bus *bus, const i2c_timing *timing,
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
// receive multiple bytes
|
||||
static status_t receive_bytes( const i2c_bus *bus, const i2c_timing *timing,
|
||||
|
||||
//! Receive multiple bytes
|
||||
static status_t
|
||||
receive_bytes(const i2c_bus *bus, const i2c_timing *timing,
|
||||
uint8 *read_buffer, ssize_t read_len)
|
||||
{
|
||||
SHOW_FLOW(3, "len=%ld", read_len);
|
||||
@@ -325,10 +348,11 @@ static status_t receive_bytes( const i2c_bus *bus, const i2c_timing *timing,
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
// combined i2c send+receive format
|
||||
status_t i2c_send_receive( const i2c_bus *bus, const i2c_timing *timing,
|
||||
int slave_address,
|
||||
const uint8 *write_buffer, size_t write_len,
|
||||
|
||||
//! Combined i2c send+receive format
|
||||
status_t
|
||||
i2c_send_receive(const i2c_bus *bus, const i2c_timing *timing,
|
||||
int slave_address, const uint8 *write_buffer, size_t write_len,
|
||||
uint8 *read_buffer, size_t read_len)
|
||||
{
|
||||
status_t res;
|
||||
@@ -366,9 +390,9 @@ err:
|
||||
return res;
|
||||
}
|
||||
|
||||
// timining for 100kHz bus (fractional parts are rounded up)
|
||||
i2c_timing i2c_timing_100k =
|
||||
{
|
||||
|
||||
//! Timining for 100kHz bus (fractional parts are rounded up)
|
||||
i2c_timing i2c_timing_100k = {
|
||||
buf : 5,
|
||||
hd_sta : 4,
|
||||
low : 5,
|
||||
@@ -390,8 +414,7 @@ i2c_timing i2c_timing_100k =
|
||||
|
||||
// timing for 400 kHz bus
|
||||
// (argh! heavy up-rounding here)
|
||||
i2c_timing i2c_timing_400k =
|
||||
{
|
||||
i2c_timing i2c_timing_400k = {
|
||||
buf : 2,
|
||||
hd_sta : 1,
|
||||
low : 2,
|
||||
@@ -411,12 +434,16 @@ i2c_timing i2c_timing_400k =
|
||||
ack_timeout : 2
|
||||
};
|
||||
|
||||
void i2c_get100k_timing( i2c_timing *timing )
|
||||
|
||||
void
|
||||
i2c_get100k_timing(i2c_timing *timing)
|
||||
{
|
||||
*timing = i2c_timing_100k;
|
||||
}
|
||||
|
||||
void i2c_get400k_timing( i2c_timing *timing )
|
||||
|
||||
void
|
||||
i2c_get400k_timing(i2c_timing *timing)
|
||||
{
|
||||
*timing = i2c_timing_400k;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user