linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2.6.17-1] fbmon: add generic ddc read functionality
@ 2006-06-21 19:57 Dennis Munsie
  2006-07-13 20:26 ` Dennis Munsie
  0 siblings, 1 reply; 9+ messages in thread
From: Dennis Munsie @ 2006-06-21 19:57 UTC (permalink / raw)
  To: linux-fbdev-devel; +Cc: Luca, Eric Hustvedt

hello,

another day, another patch... this one adds generic ddc/edid read  
functionality to fbmon.c.

I'm not convinced that this is the final version of this patch -- it  
works for me, but I would like to see it get some heavier testing.   
It's based on the radeon code, but that code twiddled some of the  
registers directly, where this patch uses the existing setsda,  
getsda, setscl, and getscl functions to do it's dirty work.  One  
possible side effect is that the original code could set both sda and  
scl at the same time, where this code can only set one after the  
other.  I don't know if this will be a factor or not.

Another minor issue is that the stubbed out function still requires  
the i2c.h file to be included since I use struct i2c_adapter as the  
parameter.  I thought of a few possible ways around this, but I left  
it the way it is right now because I figured that nothing was to be  
gained by not having that struct... if anyone feels otherwise, please  
let me know.

I'll put together a patch for the radeon driver today so that it will  
be easier to test.  I haven't worked out everything in the intelfb  
driver yet to post up a patch.

dennis

---

From: Dennis Munsie <dmunsie@cecropia.com>

Adds functionality to read the EDID information over the DDC bus in a
generic way.  This code is based on the DDC implementation in the radeon
driver.

Signed-off-by: Dennis Munsie <dmunsie@cecropia.com>

---

drivers/video/fbmon.c |  110 +++++++++++++++++++++++++++++++++++++++++ 
+++++++++
include/linux/fb.h    |    2
2 files changed, 112 insertions(+)

diff -Naurp -X linux-2.6.17.1-patched/Documentation/dontdiff  
linux-2.6.17.1-patched/drivers/video/fbmon.c linux/drivers/video/fbmon.c
--- linux-2.6.17.1-patched/drivers/video/fbmon.c	2006-06-21  
12:03:41.000000000 -0500
+++ linux/drivers/video/fbmon.c	2006-06-21 14:45:43.000000000 -0500
@@ -1314,6 +1314,116 @@ const unsigned char *fb_firmware_edid(st
#endif
EXPORT_SYMBOL(fb_firmware_edid);
+/*
+ * DDC/EDID read support.
+ *
+ * You must pass in an i2c_adapter that uses the bit algorithm, or
+ * there will be a panic.
+ */
+#if defined(CONFIG_I2C) && defined(CONFIG_I2C_ALGOBIT)
+#include <linux/i2c-algo-bit.h>
+#include <linux/delay.h>
+
+#define DDC_ADDR	0x50
+
+static unsigned char *fb_do_probe_ddc_edid(struct i2c_adapter *adapter)
+{
+	unsigned char start = 0x0;
+	struct i2c_msg msgs[] = {
+		{
+			.addr	= DDC_ADDR,
+			.len	= 1,
+			.buf	= &start,
+		}, {
+			.addr	= DDC_ADDR,
+			.flags	= I2C_M_RD,
+			.len	= EDID_LENGTH,
+		}
+	};
+	unsigned char *buf;
+
+	buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
+	if (!buf) {
+		printk(KERN_ERR "fbmon: unable to allocate memory for EDID block. 
\n");
+		return NULL;		
+	}
+	msgs[1].buf = buf;
+
+	if (i2c_transfer(adapter, msgs, 2) == 2)
+		return buf;
+
+	printk(KERN_WARNING "fbmon: unable to read EDID block.\n");
+	kfree(buf);
+	return NULL;
+}
+
+unsigned char *fb_ddc_read(struct i2c_adapter *adapter)
+{
+	struct i2c_algo_bit_data *algo_data = adapter->algo_data;
+	unsigned char *edid = NULL;
+	int i, j;
+	
+	algo_data->setscl(algo_data->data, 1);
+	algo_data->setscl(algo_data->data, 0);
+
+	for (i = 0; i < 3; i++) {
+		/* For some old monitors we need the
+		 * following process to initialize/stop DDC
+		 */
+		algo_data->setsda(algo_data->data, 0);
+		msleep(13);
+
+		algo_data->setscl(algo_data->data, 1);
+		for (j = 0; j < 5; j++) {
+			msleep(10);
+			if (algo_data->getscl(algo_data->data))
+				break;
+		}
+		if (j == 5)
+			continue;
+
+		algo_data->setsda(algo_data->data, 0);
+		msleep(15);
+		algo_data->setscl(algo_data->data, 0);
+		msleep(15);
+		algo_data->setsda(algo_data->data, 1);
+		msleep(15);
+
+		/* Do the real work */
+		edid = fb_do_probe_ddc_edid(adapter);
+		algo_data->setsda(algo_data->data, 0);
+		algo_data->setscl(algo_data->data, 0);
+		msleep(15);
+
+		algo_data->setscl(algo_data->data, 1);
+		for (j = 0; j < 10; j++) {
+			msleep(10);
+			if (algo_data->getscl(algo_data->data))
+				break;
+		}
+
+		algo_data->setsda(algo_data->data, 1);
+		msleep(15);
+		algo_data->setscl(algo_data->data, 0);
+		if (edid)
+			break;
+	}
+	/* Release the DDC lines when done or the Apple Cinema HD display
+	 * will switch off
+	 */
+	algo_data->setsda(algo_data->data, 0);
+	algo_data->setscl(algo_data->data, 0);
+
+	return edid;
+}
+#else
+unsigned char *fb_ddc_read(struct i2c_adapter *adapter)
+{
+	return NULL;
+}
+#endif
+EXPORT_SYMBOL(fb_ddc_read);
+
EXPORT_SYMBOL(fb_parse_edid);
EXPORT_SYMBOL(fb_edid_to_monspecs);
EXPORT_SYMBOL(fb_get_mode);
diff -Naurp -X linux-2.6.17.1-patched/Documentation/dontdiff  
linux-2.6.17.1-patched/include/linux/fb.h linux/include/linux/fb.h
--- linux-2.6.17.1-patched/include/linux/fb.h	2006-06-21  
12:03:42.000000000 -0500
+++ linux/include/linux/fb.h	2006-06-21 14:46:06.000000000 -0500
@@ -2,6 +2,7 @@
#define _LINUX_FB_H
#include <asm/types.h>
+#include <linux/i2c.h>
/* Definitions of frame buffers						*/
@@ -924,6 +925,7 @@ extern void fb_edid_to_monspecs(unsigned
				struct fb_monspecs *specs);
extern void fb_destroy_modedb(struct fb_videomode *modedb);
extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins,  
int rb);
+extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
/* drivers/video/modedb.c */
#define VESA_MODEDB_SIZE 34


All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2.6.17-1] fbmon: add generic ddc read functionality
  2006-06-21 19:57 [PATCH 2.6.17-1] fbmon: add generic ddc read functionality Dennis Munsie
@ 2006-07-13 20:26 ` Dennis Munsie
  2006-07-15 13:15   ` Antonino A. Daplas
  0 siblings, 1 reply; 9+ messages in thread
From: Dennis Munsie @ 2006-07-13 20:26 UTC (permalink / raw)
  To: linux-fbdev-devel

did anyone have any problems with this patch?  Just wondering if it  
was going to be flipped upstream or if I need to make some changes to  
it.

dennis

On Jun 21, 2006, at 3:57 PM, Dennis Munsie wrote:

> hello,
>
> another day, another patch... this one adds generic ddc/edid read
> functionality to fbmon.c.
>



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2.6.17-1] fbmon: add generic ddc read functionality
  2006-07-13 20:26 ` Dennis Munsie
@ 2006-07-15 13:15   ` Antonino A. Daplas
  2006-07-15 13:29     ` Dennis Munsie
  0 siblings, 1 reply; 9+ messages in thread
From: Antonino A. Daplas @ 2006-07-15 13:15 UTC (permalink / raw)
  To: linux-fbdev-devel; +Cc: Dennis Munsie

Dennis Munsie wrote:
> did anyone have any problems with this patch?  Just wondering if it  
> was going to be flipped upstream or if I need to make some changes to  
> it.

Can you resend? I'm getting "malformed patch". An attachment is fine.

Tony


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2.6.17-1] fbmon: add generic ddc read functionality
  2006-07-15 13:15   ` Antonino A. Daplas
@ 2006-07-15 13:29     ` Dennis Munsie
  2006-07-16  3:23       ` Antonino A. Daplas
  2006-07-16  3:25       ` Antonino A. Daplas
  0 siblings, 2 replies; 9+ messages in thread
From: Dennis Munsie @ 2006-07-15 13:29 UTC (permalink / raw)
  To: Antonino A. Daplas; +Cc: linux-fbdev-devel

[-- Attachment #1: Type: text/plain, Size: 419 bytes --]

I've attached both patches -- the fb-ddc-read.patch adds the generic  
ddc functionality, and the other patches the radeonfb driver to use  
the generic functionality instead.

There are other drivers that should be patched to use the generic  
functionality as well, but since I didn't have any other cards to  
test with, I just did the patch for the radeon (and intelfb as well,  
but that's not ready yet).

dennis

[-- Attachment #2: fb-ddc-read.patch --]
[-- Type: application/octet-stream, Size: 4123 bytes --]

From: Dennis Munsie <dmunsie@cecropia.com>

Adds functionality to read the EDID information over the DDC bus in a
generic way.  This code is based on the DDC implementation in the radeon
driver.

Signed-off-by: Dennis Munsie <dmunsie@cecropia.com>

---

 drivers/video/fbmon.c |  110 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fb.h    |    2 
 2 files changed, 112 insertions(+)

diff -Naurp -X linux-2.6.17.1-patched/Documentation/dontdiff linux-2.6.17.1-patched/drivers/video/fbmon.c linux/drivers/video/fbmon.c
--- linux-2.6.17.1-patched/drivers/video/fbmon.c	2006-06-21 12:03:41.000000000 -0500
+++ linux/drivers/video/fbmon.c	2006-06-21 14:45:43.000000000 -0500
@@ -1314,6 +1314,116 @@ const unsigned char *fb_firmware_edid(st
 #endif
 EXPORT_SYMBOL(fb_firmware_edid);
 
+/*
+ * DDC/EDID read support.
+ *
+ * You must pass in an i2c_adapter that uses the bit algorithm, or
+ * there will be a panic.
+ */
+#if defined(CONFIG_I2C) && defined(CONFIG_I2C_ALGOBIT)
+#include <linux/i2c-algo-bit.h>
+#include <linux/delay.h>
+
+#define DDC_ADDR	0x50
+
+static unsigned char *fb_do_probe_ddc_edid(struct i2c_adapter *adapter)
+{
+	unsigned char start = 0x0;
+	struct i2c_msg msgs[] = {
+		{
+			.addr	= DDC_ADDR,
+			.len	= 1,
+			.buf	= &start,
+		}, {
+			.addr	= DDC_ADDR,
+			.flags	= I2C_M_RD,
+			.len	= EDID_LENGTH,
+		}
+	};
+	unsigned char *buf;
+
+	buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
+	if (!buf) {
+		printk(KERN_ERR "fbmon: unable to allocate memory for EDID block.\n");
+		return NULL;		
+	}
+	msgs[1].buf = buf;
+
+	if (i2c_transfer(adapter, msgs, 2) == 2)
+		return buf;
+
+	printk(KERN_WARNING "fbmon: unable to read EDID block.\n");
+	kfree(buf);
+	return NULL;
+}
+
+unsigned char *fb_ddc_read(struct i2c_adapter *adapter)
+{
+	struct i2c_algo_bit_data *algo_data = adapter->algo_data;
+	unsigned char *edid = NULL;
+	int i, j;
+	
+	algo_data->setscl(algo_data->data, 1);
+	algo_data->setscl(algo_data->data, 0);
+
+	for (i = 0; i < 3; i++) {
+		/* For some old monitors we need the
+		 * following process to initialize/stop DDC
+		 */
+		algo_data->setsda(algo_data->data, 0);
+		msleep(13);
+
+		algo_data->setscl(algo_data->data, 1);
+		for (j = 0; j < 5; j++) {
+			msleep(10);
+			if (algo_data->getscl(algo_data->data))
+				break;
+		}
+		if (j == 5)
+			continue;
+
+		algo_data->setsda(algo_data->data, 0);
+		msleep(15);
+		algo_data->setscl(algo_data->data, 0);
+		msleep(15);
+		algo_data->setsda(algo_data->data, 1);
+		msleep(15);
+
+		/* Do the real work */
+		edid = fb_do_probe_ddc_edid(adapter);
+		algo_data->setsda(algo_data->data, 0);
+		algo_data->setscl(algo_data->data, 0);
+		msleep(15);
+
+		algo_data->setscl(algo_data->data, 1);
+		for (j = 0; j < 10; j++) {
+			msleep(10);
+			if (algo_data->getscl(algo_data->data))
+				break;
+		}
+
+		algo_data->setsda(algo_data->data, 1);
+		msleep(15);
+		algo_data->setscl(algo_data->data, 0);
+		if (edid)
+			break;
+	}
+	/* Release the DDC lines when done or the Apple Cinema HD display
+	 * will switch off
+	 */
+	algo_data->setsda(algo_data->data, 0);
+	algo_data->setscl(algo_data->data, 0);
+
+	return edid;
+}
+#else
+unsigned char *fb_ddc_read(struct i2c_adapter *adapter)
+{
+	return NULL;
+}
+#endif
+EXPORT_SYMBOL(fb_ddc_read);
+
 EXPORT_SYMBOL(fb_parse_edid);
 EXPORT_SYMBOL(fb_edid_to_monspecs);
 EXPORT_SYMBOL(fb_get_mode);
diff -Naurp -X linux-2.6.17.1-patched/Documentation/dontdiff linux-2.6.17.1-patched/include/linux/fb.h linux/include/linux/fb.h
--- linux-2.6.17.1-patched/include/linux/fb.h	2006-06-21 12:03:42.000000000 -0500
+++ linux/include/linux/fb.h	2006-06-21 14:46:06.000000000 -0500
@@ -2,6 +2,7 @@
 #define _LINUX_FB_H
 
 #include <asm/types.h>
+#include <linux/i2c.h>
 
 /* Definitions of frame buffers						*/
 
@@ -924,6 +925,7 @@ extern void fb_edid_to_monspecs(unsigned
 				struct fb_monspecs *specs);
 extern void fb_destroy_modedb(struct fb_videomode *modedb);
 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
+extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
 /* drivers/video/modedb.c */
 #define VESA_MODEDB_SIZE 34

[-- Attachment #3: radeonfb-use-generic-ddc-read.patch --]
[-- Type: application/octet-stream, Size: 3437 bytes --]

From: Dennis Munsie <dmunsie@cecropia.com>

Uses the generic ddc read functionality in fbmon.c instead of the
previous functionality.

Signed-off-by: Dennis Munsie <dmunsie@cecropia.com>

---

 drivers/video/aty/radeon_i2c.c |  104 -----------------------------------------
 1 file changed, 1 insertion(+), 103 deletions(-)

diff -Naurp -X linux-2.6.17.1-patched/Documentation/dontdiff linux-2.6.17.1-patched/drivers/video/aty/radeon_i2c.c linux/drivers/video/aty/radeon_i2c.c
--- linux-2.6.17.1-patched/drivers/video/aty/radeon_i2c.c	2006-03-20 00:53:29.000000000 -0500
+++ linux/drivers/video/aty/radeon_i2c.c	2006-06-21 15:45:53.000000000 -0500
@@ -17,8 +17,6 @@
 #include "radeonfb.h"
 #include "../edid.h"
 
-#define RADEON_DDC 	0x50
-
 static void radeon_gpio_setscl(void* data, int state)
 {
 	struct radeon_i2c_chan 	*chan = data;
@@ -139,109 +137,9 @@ void radeon_delete_i2c_busses(struct rad
 	rinfo->i2c[3].rinfo = NULL;
 }
 
-
-static u8 *radeon_do_probe_i2c_edid(struct radeon_i2c_chan *chan)
-{
-	u8 start = 0x0;
-	struct i2c_msg msgs[] = {
-		{
-			.addr	= RADEON_DDC,
-			.len	= 1,
-			.buf	= &start,
-		}, {
-			.addr	= RADEON_DDC,
-			.flags	= I2C_M_RD,
-			.len	= EDID_LENGTH,
-		},
-	};
-	u8 *buf;
-
-	buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
-	if (!buf) {
-		dev_warn(&chan->rinfo->pdev->dev, "Out of memory!\n");
-		return NULL;
-	}
-	msgs[1].buf = buf;
-
-	if (i2c_transfer(&chan->adapter, msgs, 2) == 2)
-		return buf;
-	dev_dbg(&chan->rinfo->pdev->dev, "Unable to read EDID block.\n");
-	kfree(buf);
-	return NULL;
-}
-
-
 int radeon_probe_i2c_connector(struct radeonfb_info *rinfo, int conn, u8 **out_edid)
 {
-	u32 reg = rinfo->i2c[conn-1].ddc_reg;
-	u8 *edid = NULL;
-	int i, j;
-
-	OUTREG(reg, INREG(reg) & 
-			~(VGA_DDC_DATA_OUTPUT | VGA_DDC_CLK_OUTPUT));
-
-	OUTREG(reg, INREG(reg) & ~(VGA_DDC_CLK_OUT_EN));
-	(void)INREG(reg);
-
-	for (i = 0; i < 3; i++) {
-		/* For some old monitors we need the
-		 * following process to initialize/stop DDC
-		 */
-		OUTREG(reg, INREG(reg) & ~(VGA_DDC_DATA_OUT_EN));
-		(void)INREG(reg);
-		msleep(13);
-
-		OUTREG(reg, INREG(reg) & ~(VGA_DDC_CLK_OUT_EN));
-		(void)INREG(reg);
-		for (j = 0; j < 5; j++) {
-			msleep(10);
-			if (INREG(reg) & VGA_DDC_CLK_INPUT)
-				break;
-		}
-		if (j == 5)
-			continue;
-
-		OUTREG(reg, INREG(reg) | VGA_DDC_DATA_OUT_EN);
-		(void)INREG(reg);
-		msleep(15);
-		OUTREG(reg, INREG(reg) | VGA_DDC_CLK_OUT_EN);
-		(void)INREG(reg);
-		msleep(15);
-		OUTREG(reg, INREG(reg) & ~(VGA_DDC_DATA_OUT_EN));
-		(void)INREG(reg);
-		msleep(15);
-
-		/* Do the real work */
-		edid = radeon_do_probe_i2c_edid(&rinfo->i2c[conn-1]);
-
-		OUTREG(reg, INREG(reg) | 
-				(VGA_DDC_DATA_OUT_EN | VGA_DDC_CLK_OUT_EN));
-		(void)INREG(reg);
-		msleep(15);
-		
-		OUTREG(reg, INREG(reg) & ~(VGA_DDC_CLK_OUT_EN));
-		(void)INREG(reg);
-		for (j = 0; j < 10; j++) {
-			msleep(10);
-			if (INREG(reg) & VGA_DDC_CLK_INPUT)
-				break;
-		}
-
-		OUTREG(reg, INREG(reg) & ~(VGA_DDC_DATA_OUT_EN));
-		(void)INREG(reg);
-		msleep(15);
-		OUTREG(reg, INREG(reg) |
-				(VGA_DDC_DATA_OUT_EN | VGA_DDC_CLK_OUT_EN));
-		(void)INREG(reg);
-		if (edid)
-			break;
-	}
-	/* Release the DDC lines when done or the Apple Cinema HD display
-	 * will switch off
-	 */
-	OUTREG(reg, INREG(reg) & ~(VGA_DDC_CLK_OUT_EN | VGA_DDC_DATA_OUT_EN));
-	(void)INREG(reg);
-
+	u8 *edid = fb_ddc_read(&rinfo->i2c[conn-1].adapter);
 	if (out_edid)
 		*out_edid = edid;
 	if (!edid) {

[-- Attachment #4: Type: text/plain, Size: 315 bytes --]


On Jul 15, 2006, at 9:15 AM, Antonino A. Daplas wrote:

> Dennis Munsie wrote:
>> did anyone have any problems with this patch?  Just wondering if it
>> was going to be flipped upstream or if I need to make some changes to
>> it.
>
> Can you resend? I'm getting "malformed patch". An attachment is fine.
>
> Tony


[-- Attachment #5: Type: text/plain, Size: 375 bytes --]


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

[-- Attachment #6: Type: text/plain, Size: 182 bytes --]

_______________________________________________
Linux-fbdev-devel mailing list
Linux-fbdev-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-fbdev-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2.6.17-1] fbmon: add generic ddc read functionality
  2006-07-15 13:29     ` Dennis Munsie
@ 2006-07-16  3:23       ` Antonino A. Daplas
  2006-07-17 14:27         ` Dennis Munsie
  2006-07-16  3:25       ` Antonino A. Daplas
  1 sibling, 1 reply; 9+ messages in thread
From: Antonino A. Daplas @ 2006-07-16  3:23 UTC (permalink / raw)
  To: Dennis Munsie; +Cc: linux-fbdev-devel

Dennis Munsie wrote:
> I've attached both patches -- the fb-ddc-read.patch adds the generic ddc
> functionality, and the other patches the radeonfb driver to use the
> generic functionality instead.
> 
> There are other drivers that should be patched to use the generic
> functionality as well, but since I didn't have any other cards to test
> with, I just did the patch for the radeon (and intelfb as well, but
> that's not ready yet).
> 
> dennis
> 
> On Jul 15, 2006, at 9:15 AM, Antonino A. Daplas wrote:
> 
>> Dennis Munsie wrote:
>>> did anyone have any problems with this patch?  Just wondering if it
>>> was going to be flipped upstream or if I need to make some changes to
>>> it.

Okay, just tested it. At least fb_ddc_read works() also with nvidiafb, and I'm
assuming it would also work with savage and i810, so I'll begin converting
them to that.

A few problems:

This:

+#if defined(CONFIG_I2C) && defined(CONFIG_I2C_ALGOBIT)

will compile the dummy version fb_ddc_read() if i2c support is enabled as
a module (CONFIG_I2C will not be defined, CONFIG_I2C_MODULE will be defined
instead).

So, I removed this particular line from the code. Also, I created a new file
for it (fb_ddc.c) instead of placing it in fbmon.c. I also created a Kconfig
option for it, so drivers that need it will need to have a 'select FB_DDC'
line in Kconfig.

I'm attaching an update patch. The authorship will be in your name (so people
can hunt you down when they have problems :-)). Anyway, check the version,
and let me know of any changes you want.

Now for a wishlist. Perhaps we can make the creation and deletion of the
i2c bus generic also, so we can maximize the size reduction and make it much
simpler for driver writers to add i2c support.

Tony 


fbdev: Add generic ddc read functionality

From: Dennis Munsie <dmunsie@cecropia.com>

Adds functionality to read the EDID information over the DDC bus in a
generic way.  This code is based on the DDC implementation in the radeon
driver.

[adaplas]
- separate from fbmon.c and place in new file fb_ddc.c
- remove dependency to CONFIG_I2C and CONFIG_I2C_ALGOBIT, otherwise, feature
  will not compile if i2c support is compiled as a module
- feature is selectable only by drivers needing it. It must have a
  'select FB_DDC if xxx' in Kconfig
- change printk's to dev_*, the i2c people prefers it

Signed-off-by: Dennis Munsie <dmunsie@cecropia.com>
Signed-off-by: Antonino Daplas <adaplas@pol.net>
---

 drivers/video/Kconfig  |    5 ++
 drivers/video/Makefile |    1 
 drivers/video/fb_ddc.c |  116 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fb.h     |    2 +
 4 files changed, 124 insertions(+), 0 deletions(-)

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index be4b50a..8846262 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -53,6 +53,11 @@ config FB
 	  (e.g. an accelerated X server) and that are not frame buffer
 	  device-aware may cause unexpected results. If unsure, say N.
 
+config FB_DDC
+       tristate
+       depends on FB && I2C && I2C_ALGOBIT
+       default n
+
 config FB_CFB_FILLRECT
 	tristate
 	depends on FB
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 481c6c9..a6980e9 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_FB_CFB_FILLRECT)  += cfbfil
 obj-$(CONFIG_FB_CFB_COPYAREA)  += cfbcopyarea.o
 obj-$(CONFIG_FB_CFB_IMAGEBLIT) += cfbimgblt.o
 obj-$(CONFIG_FB_MACMODES)      += macmodes.o
+obj-$(CONFIG_FB_DDC)           += fb_ddc.o
 
 # Hardware specific drivers go first
 obj-$(CONFIG_FB_RETINAZ3)         += retz3fb.o
diff --git a/drivers/video/fb_ddc.c b/drivers/video/fb_ddc.c
new file mode 100644
index 0000000..3aa6ebf
--- /dev/null
+++ b/drivers/video/fb_ddc.c
@@ -0,0 +1,116 @@
+/*
+ * driver/vide/fb_ddc.c - DDC/EDID read support.
+ *
+ *  Copyright (C) 2006 Dennis Munsie <dmunsie@cecropia.com>
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file COPYING in the main directory of this archive
+ * for more details.
+ */
+
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/fb.h>
+#include <linux/i2c-algo-bit.h>
+
+#include "edid.h"
+
+#define DDC_ADDR	0x50
+
+static unsigned char *fb_do_probe_ddc_edid(struct i2c_adapter *adapter)
+{
+	unsigned char start = 0x0;
+	struct i2c_msg msgs[] = {
+		{
+			.addr	= DDC_ADDR,
+			.len	= 1,
+			.buf	= &start,
+		}, {
+			.addr	= DDC_ADDR,
+			.flags	= I2C_M_RD,
+			.len	= EDID_LENGTH,
+		}
+	};
+	unsigned char *buf;
+
+	buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
+	if (!buf) {
+		dev_warn(&adapter->dev, "unable to allocate memory for EDID "
+			 "block.\n");
+		return NULL;
+	}
+	msgs[1].buf = buf;
+
+	if (i2c_transfer(adapter, msgs, 2) == 2)
+		return buf;
+
+	dev_warn(&adapter->dev, "unable to read EDID block.\n");
+	kfree(buf);
+	return NULL;
+}
+
+unsigned char *fb_ddc_read(struct i2c_adapter *adapter)
+{
+	struct i2c_algo_bit_data *algo_data = adapter->algo_data;
+	unsigned char *edid = NULL;
+	int i, j;
+
+	algo_data->setscl(algo_data->data, 1);
+	algo_data->setscl(algo_data->data, 0);
+
+	for (i = 0; i < 3; i++) {
+		/* For some old monitors we need the
+		 * following process to initialize/stop DDC
+		 */
+		algo_data->setsda(algo_data->data, 0);
+		msleep(13);
+
+		algo_data->setscl(algo_data->data, 1);
+		for (j = 0; j < 5; j++) {
+			msleep(10);
+			if (algo_data->getscl(algo_data->data))
+				break;
+		}
+		if (j == 5)
+			continue;
+
+		algo_data->setsda(algo_data->data, 0);
+		msleep(15);
+		algo_data->setscl(algo_data->data, 0);
+		msleep(15);
+		algo_data->setsda(algo_data->data, 1);
+		msleep(15);
+
+		/* Do the real work */
+		edid = fb_do_probe_ddc_edid(adapter);
+		algo_data->setsda(algo_data->data, 0);
+		algo_data->setscl(algo_data->data, 0);
+		msleep(15);
+
+		algo_data->setscl(algo_data->data, 1);
+		for (j = 0; j < 10; j++) {
+			msleep(10);
+			if (algo_data->getscl(algo_data->data))
+				break;
+		}
+
+		algo_data->setsda(algo_data->data, 1);
+		msleep(15);
+		algo_data->setscl(algo_data->data, 0);
+		if (edid)
+			break;
+	}
+	/* Release the DDC lines when done or the Apple Cinema HD display
+	 * will switch off
+	 */
+	algo_data->setsda(algo_data->data, 0);
+	algo_data->setscl(algo_data->data, 0);
+
+	return edid;
+}
+
+EXPORT_SYMBOL_GPL(fb_ddc_read);
+
+MODULE_AUTHOR("Dennis Munsie <dmunsie@cecropia.com>");
+MODULE_DESCRIPTION("DDC/EDID reading support");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/fb.h b/include/linux/fb.h
index 4ad0673..a49ba06 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -3,6 +3,7 @@ #define _LINUX_FB_H
 
 #include <linux/backlight.h>
 #include <asm/types.h>
+#include <linux/i2c.h>
 
 /* Definitions of frame buffers						*/
 
@@ -940,6 +941,7 @@ extern void fb_edid_to_monspecs(unsigned
 				struct fb_monspecs *specs);
 extern void fb_destroy_modedb(struct fb_videomode *modedb);
 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
+extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
 /* drivers/video/modedb.c */
 #define VESA_MODEDB_SIZE 34


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 2.6.17-1] fbmon: add generic ddc read functionality
  2006-07-15 13:29     ` Dennis Munsie
  2006-07-16  3:23       ` Antonino A. Daplas
@ 2006-07-16  3:25       ` Antonino A. Daplas
  1 sibling, 0 replies; 9+ messages in thread
From: Antonino A. Daplas @ 2006-07-16  3:25 UTC (permalink / raw)
  To: Dennis Munsie; +Cc: linux-fbdev-devel

Dennis Munsie wrote:
> I've attached both patches -- the fb-ddc-read.patch adds the generic ddc
> functionality, and the other patches the radeonfb driver to use the
> generic functionality instead.
> 
> There are other drivers that should be patched to use the generic
> functionality as well, but since I didn't have any other cards to test
> with, I just did the patch for the radeon (and intelfb as well, but
> that's not ready yet).
> 
> dennis
> 
> On Jul 15, 2006, at 9:15 AM, Antonino A. Daplas wrote:
> 
>> Dennis Munsie wrote:
>>> did anyone have any problems with this patch?  Just wondering if it
>>> was going to be flipped upstream or if I need to make some changes to
>>> it.

And here's the updated nvidiafb driver...

Tony

nvidiafb: Use generic DDC reading

Update driver to use generic DDC reading

Signed-off-by: Antonino Daplas <adaplas@pol.net>
---

 drivers/video/Kconfig         |    1 +
 drivers/video/nvidia/nv_i2c.c |   45 +++--------------------------------------
 2 files changed, 4 insertions(+), 42 deletions(-)

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 8846262..215ad28 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -699,6 +699,7 @@ config FB_NVIDIA
 	depends on FB && PCI
 	select I2C_ALGOBIT if FB_NVIDIA_I2C
 	select I2C if FB_NVIDIA_I2C
+	select FB_DDC if FB_NVIDIA_I2C
 	select FB_MODE_HELPERS
 	select FB_CFB_FILLRECT
 	select FB_CFB_COPYAREA
diff --git a/drivers/video/nvidia/nv_i2c.c b/drivers/video/nvidia/nv_i2c.c
index 19eef3a..e48de3c 100644
--- a/drivers/video/nvidia/nv_i2c.c
+++ b/drivers/video/nvidia/nv_i2c.c
@@ -160,51 +160,12 @@ void nvidia_delete_i2c_busses(struct nvi
 
 }
 
-static u8 *nvidia_do_probe_i2c_edid(struct nvidia_i2c_chan *chan)
-{
-	u8 start = 0x0;
-	struct i2c_msg msgs[] = {
-		{
-		 .addr = 0x50,
-		 .len = 1,
-		 .buf = &start,
-		 }, {
-		     .addr = 0x50,
-		     .flags = I2C_M_RD,
-		     .len = EDID_LENGTH,
-		     },
-	};
-	u8 *buf;
-
-	if (!chan->par)
-		return NULL;
-
-	buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
-	if (!buf) {
-		dev_warn(&chan->par->pci_dev->dev, "Out of memory!\n");
-		return NULL;
-	}
-	msgs[1].buf = buf;
-
-	if (i2c_transfer(&chan->adapter, msgs, 2) == 2)
-		return buf;
-	dev_dbg(&chan->par->pci_dev->dev, "Unable to read EDID block.\n");
-	kfree(buf);
-	return NULL;
-}
-
 int nvidia_probe_i2c_connector(struct fb_info *info, int conn, u8 **out_edid)
 {
 	struct nvidia_par *par = info->par;
-	u8 *edid = NULL;
-	int i;
-
-	for (i = 0; i < 3; i++) {
-		/* Do the real work */
-		edid = nvidia_do_probe_i2c_edid(&par->chan[conn - 1]);
-		if (edid)
-			break;
-	}
+	u8 *edid;
+
+	edid = fb_ddc_read(&par->chan[conn - 1].adapter);
 
 	if (!edid && conn == 1) {
 		/* try to get from firmware */


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 2.6.17-1] fbmon: add generic ddc read functionality
  2006-07-16  3:23       ` Antonino A. Daplas
@ 2006-07-17 14:27         ` Dennis Munsie
  2006-07-17 23:01           ` Antonino A. Daplas
  0 siblings, 1 reply; 9+ messages in thread
From: Dennis Munsie @ 2006-07-17 14:27 UTC (permalink / raw)
  To: Antonino A.Daplas; +Cc: linux-fbdev-devel

It looks good, but the copyright should be in my company's name, not  
mine -- Cecropia, Inc.  My name and email can still be there, though,  
for contact purposes.

Also, I looked on the original file in the radeon driver for a  
copyright, but there wasn't one there -- whoever wrote that original  
code should also be listed in the copyright.

BTW -- are you going to modify the radeon patch to account for the  
Kconfig change or should I send up a new version?

dennis

On Jul 15, 2006, at 11:23 PM, Antonino A. Daplas wrote:
> I'm attaching an update patch. The authorship will be in your name  
> (so people
> can hunt you down when they have problems :-)). Anyway, check the  
> version,
> and let me know of any changes you want.



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2.6.17-1] fbmon: add generic ddc read functionality
  2006-07-17 14:27         ` Dennis Munsie
@ 2006-07-17 23:01           ` Antonino A. Daplas
  2006-07-18 19:36             ` Luca
  0 siblings, 1 reply; 9+ messages in thread
From: Antonino A. Daplas @ 2006-07-17 23:01 UTC (permalink / raw)
  To: Dennis Munsie; +Cc: Luca, linux-fbdev-devel

Dennis Munsie wrote:
> It looks good, but the copyright should be in my company's name, not
> mine -- Cecropia, Inc.  My name and email can still be there, though,
> for contact purposes.

Okay.
> 
> Also, I looked on the original file in the radeon driver for a
> copyright, but there wasn't one there -- whoever wrote that original
> code should also be listed in the copyright.
> 

I guess that would be Luca.

> BTW -- are you going to modify the radeon patch to account for the
> Kconfig change or should I send up a new version?
> 

I'll do it, it should be simple enough.

Tony


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2.6.17-1] fbmon: add generic ddc read functionality
  2006-07-17 23:01           ` Antonino A. Daplas
@ 2006-07-18 19:36             ` Luca
  0 siblings, 0 replies; 9+ messages in thread
From: Luca @ 2006-07-18 19:36 UTC (permalink / raw)
  To: Antonino A. Daplas; +Cc: Dennis Munsie, linux-fbdev-devel

Il Tue, Jul 18, 2006 at 07:01:06AM +0800, Antonino A. Daplas ha scritto: 
> > Also, I looked on the original file in the radeon driver for a
> > copyright, but there wasn't one there -- whoever wrote that original
> > code should also be listed in the copyright.
> > 
> 
> I guess that would be Luca.

Ah yes, I started writing that code back when James Simmons was still
around ;) There's a notice in radeon_base.c.

Anyway BenH put a great deal of work in it too.

Luca
-- 
Home: http://kronoz.cjb.net
Il dottore mi ha detto di smettere di fare cene intime per quattro.
A meno che non ci siamo altre tre persone.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2006-07-18 19:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-21 19:57 [PATCH 2.6.17-1] fbmon: add generic ddc read functionality Dennis Munsie
2006-07-13 20:26 ` Dennis Munsie
2006-07-15 13:15   ` Antonino A. Daplas
2006-07-15 13:29     ` Dennis Munsie
2006-07-16  3:23       ` Antonino A. Daplas
2006-07-17 14:27         ` Dennis Munsie
2006-07-17 23:01           ` Antonino A. Daplas
2006-07-18 19:36             ` Luca
2006-07-16  3:25       ` Antonino A. Daplas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).