I2C DDC display
I just ported monddc from 2.4 to 2.6 and I attached the source. It implemented a few DDC decodings but to implement them all you need to add about thirty attributes.
I'm trying to figure out if a generic DDC module can probe for older DDC monitors. The radeon framebuffer driver (2.6, drivers/video/aty/radeon_i2c.c) contains the following code for discovering old DDC chips.
I see that I can replace the probe function in the monddc driver with this probe function. But I don't know enough about DDC and I2C to really under what it's trying to do to the I2C bus. Can this probe function be turned into a generic form where it uses something like i2c_smbus_xfer() instead of directly playing with the bus ioports? Does anyone have one of these old monitors that needs this probe?
I'd like to build one universal DDC module instead of reimplementing this in every video driver.
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);
wait_ms(13);
OUTREG(reg, INREG(reg) & ~(VGA_DDC_CLK_OUT_EN));
(void)INREG(reg);
for (j = 0; j < 5; j++) {
wait_ms(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);
wait_ms(15);
OUTREG(reg, INREG(reg) | VGA_DDC_CLK_OUT_EN);
(void)INREG(reg);
wait_ms(15);
OUTREG(reg, INREG(reg) & ~(VGA_DDC_DATA_OUT_EN));
(void)INREG(reg);
wait_ms(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);
wait_ms(15);
OUTREG(reg, INREG(reg) & ~(VGA_DDC_CLK_OUT_EN));
(void)INREG(reg);
for (j = 0; j < 10; j++) {
wait_ms(10);
if (INREG(reg) & VGA_DDC_CLK_INPUT)
break;
}
OUTREG(reg, INREG(reg) & ~(VGA_DDC_DATA_OUT_EN));
(void)INREG(reg);
wait_ms(15);
OUTREG(reg, INREG(reg) |
(VGA_DDC_DATA_OUT_EN | VGA_DDC_CLK_OUT_EN));
(void)INREG(reg);
if (edid)
break;
}
if (out_edid)
*out_edid = edid;
if (!edid) {
RTRACE("radeonfb: I2C (port %d) ... not found\n", conn);
return MT_NONE;
}
if (edid[0x14] & 0x80) {
/* Fix detection using BIOS tables */
if (rinfo->is_mobility /*&& conn = ddc_dvi*/ &&
(INREG(LVDS_GEN_CNTL) & LVDS_ON)) {
RTRACE("radeonfb: I2C (port %d) ... found LVDS panel\n", conn);
return MT_LCD;
} else {
RTRACE("radeonfb: I2C (port %d) ... found TMDS panel\n", conn);
return MT_DFP;
}
}
RTRACE("radeonfb: I2C (port %d) ... found CRT display\n", conn);
return MT_CRT;
}==Jon Smirl
[email protected]
__________________________________
Do you Yahoo!?
Get better spam protection with Yahoo! Mail.
http://antispam.yahoo.com/tools
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ddcmon.patch
Type: text/x-patch
Size: 11486 bytes
Desc: ddcmon.patch
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20040227/e647ba33/ddcmon.bin
Quoted 3 lines
I just ported monddc from 2.4 to 2.6 and I attached the source. It implemented a few DDC decodings but to implement them all you need to add about thirty attributes.
Ehe, I was thinking of doing the same. Just that the sysfs interface change that I have been working on these days postponed it. My comments on your code below.
Quoted 10 lines
I'm trying to figure out if a generic DDC module can probe for older DDC monitors. The radeon framebuffer driver (2.6,
drivers/video/aty/radeon_i2c.c) contains the following code for discovering old DDC chips.I see that I can replace the probe function in the monddc driver with this probe function. But I don't know enough about DDC and I2C to really under what it's trying to do to the I2C bus. Can this probe function be turned into a generic form where it uses something like
i2c_smbus_xfer()instead of directly playing with the bus ioports?
In fact I don't think you can do anything at all at the chip driver level. I guess that the strange procedure in radeonfb_i2c.c is there to "activate" the DDC eeprom, i.e. make it appear on the bus. As long as nothing appears on the bus, the chip driver's detect function won't be called at all! This is due to the i2c subsystem architecture we have in the Linux kernel. So you cannot hope to be able to reproduce the trick in the chip driver. It belongs to the bus driver (unless we change the architecture).
That said, there are not that many bus drivers for DDC. There must be 6 or 7. What's more, two of them (radeonfb and matroxfb) do need the DDC information for themselves, so they *have* to do the trick themselves anyway.
Quoted 1 line
Does anyone have one of these old monitors that needs this probe?
I don't think I do (anymore). The older monitor I have here does already support DDC without the particular probe.
Quoted 2 lines
I'd like to build one universal DDC module instead of reimplementing this in every video driver.
Noble intention, but sadly not achievable if I understand it correctly.
To your code now:
obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o
+obj-$(CONFIG_SENSORS_DDCMON) += ddcmon.o
obj-$(CONFIG_SENSORS_FSCHER) += fscher.o
Respect the alphabetical order please.
+ Copyright (c) 1998, 1999, 2000 Frodo Looijaard <[email protected]>, + Philip Edelbrock <[email protected]>, + and Mark Studebaker <[email protected]>
Which version of the driver have you been starting from? In the more recent ones, my name should be there too. So I guess you have based your work on an old version, which is no good :(
+#include <linux/module.h>
+#include <linux/version.h>
You don't need that one, do you?
+#include <linux/slab.h>
+#include <linux/i2c.h>
+#include <linux/i2c.h>
And including this one twice doesn't give you any extra points ;)
+#include <linux/i2c-sensor.h>
+#include <linux/init.h>
Oh, BTW, please see the other drivers (e.g. lm83) for the prefered inclusion order.
+#define LM_VERSION "1.0"
+#define LM_DATE "2/26/04"
We don't want to use such defines in the 2.6 kernel versions of the i2c drivers.
+/* DDCMON registers */
+#define DDCMON_REG_ID 0x08
+#define DDCMON_REG_SERIAL 0x0C
Please align the values, using tabs (tabstop=8).
+ unsigned long last_updated; /* In jiffies */
+
+};
No empty line here.
+ .owner = THIS_MODULE,
+ .name = "monitor_ddc",
Correct name is "ddcmon". Quoting the porting guide (which BTW you did not use?): "all lowercase, as simple as the driver name itself".
More general comments now:
1* Sysfs files should only contain one single value. Multivalue files are not allowed.
2* You seem to export almost all values as hexadecimal. Decimal is prefered.
3* Sysfs file names should be all lowercase (so "ID" is not OK). BTW, the whole interface names choice should be discussed on this list. We try to establish a common standard for all drivers. Since the ddcmon driver isn't a hardware monitor driver, it's obviously less important, but still worth discussing. For example, it would be better if the eeprom, ddcmon and bt869 drivers were to use a common naming scheme.
If you're interested in having a ddcmon driver in Linux 2.6 soon and want to help, here is the proposed plan:
1* List the values we want to export to sysfs. The latest lm_sensors ddcmon driver should be used as the base. Discuss the names here.
2* Update your code so as to take my comments above into account, and make it comply with the interface decided in step 1.
3* Test and send to Greg KH.
Thanks.
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
Quoted 6 lines · --- Jean Delvare
Quoted 5 lines
I see that I can replace the probe function in the monddc driver with this probe function. But I don't know enough about DDC and I2C to really under what it's trying to do to the I2C bus. Can this probe function be turned into a generic form where it uses something like
i2c_smbus_xfer()instead of directly playing with the bus ioports?
Quoted 8 lines
In fact I don't think you can do anything at all at the chip driver level. I guess that the strange procedure in
radeonfb_i2c.cis there to "activate" the DDC eeprom, i.e. make it appear on the bus. As long as nothing appears on the bus, the chip driver's detect function won't be called at all! This is due to the i2c subsystem architecture we have in the Linux kernel. So you cannot hope to be able to reproduce the trick in the chip driver. It belongs to the bus driver (unless we change the architecture).
The wake up should go in the chip driver not the bus driver. It's not a problem with the bus, it a problem with the chip on the bus. Putting it in the bus driver means we need to add it to the bus driver for every video card instead if just once in the chip driver.
This gets called once per bus so the code to wake up the chip could be put here.
int ddcmon_attach_adapter(struct i2c_adapter *adapter)
{
return i2c_detect(adapter, &addr_data, ddcmon_detect);
}But now I don't know enough about i2c to rewrite the following code in generic terms using the i2c_adapter operations instead of direct IO port actions.
int ddcmon_attach_adapter(struct i2c_adapter *adapter)
{
.......//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);
wait_ms(13);
OUTREG(reg, INREG(reg) & ~(VGA_DDC_CLK_OUT_EN));
(void)INREG(reg);
for (j = 0; j < 5; j++) {
wait_ms(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);
wait_ms(15);
OUTREG(reg, INREG(reg) | VGA_DDC_CLK_OUT_EN);
(void)INREG(reg);
wait_ms(15);
OUTREG(reg, INREG(reg) & ~(VGA_DDC_DATA_OUT_EN));
(void)INREG(reg);
wait_ms(15);
/* Do the real work */
ret = i2c_detect(adapter, &addr_data, ddcmon_detect);
OUTREG(reg, INREG(reg) |
(VGA_DDC_DATA_OUT_EN | VGA_DDC_CLK_OUT_EN));
(void)INREG(reg);
wait_ms(15);
OUTREG(reg, INREG(reg) & ~(VGA_DDC_CLK_OUT_EN));
(void)INREG(reg);
for (j = 0; j < 10; j++) {
wait_ms(10);
if (INREG(reg) & VGA_DDC_CLK_INPUT)
break;
}
OUTREG(reg, INREG(reg) & ~(VGA_DDC_DATA_OUT_EN));
(void)INREG(reg);
wait_ms(15);
OUTREG(reg, INREG(reg) |
(VGA_DDC_DATA_OUT_EN | VGA_DDC_CLK_OUT_EN));
(void)INREG(reg);
if (ret)
break;
}
return ret;
}==Jon Smirl
[email protected]
__________________________________
Do you Yahoo!?
Get better spam protection with Yahoo! Mail.
http://antispam.yahoo.com/tools
Il Sat, Feb 28, 2004 at 08:02:00AM -0800, Jon Smirl ha scritto:
Quoted 24 lines
Quoted 6 lines · --- Jean Delvare
Quoted 5 lines
I see that I can replace the probe function in the monddc driver with this probe function. But I don't know enough about DDC and I2C to really under what it's trying to do to the I2C bus. Can this probe function be turned into a generic form where it uses something like
i2c_smbus_xfer()instead of directly playing with the bus ioports?Quoted 8 lines
In fact I don't think you can do anything at all at the chip driver level. I guess that the strange procedure in
radeonfb_i2c.cis there to "activate" the DDC eeprom, i.e. make it appear on the bus. As long as nothing appears on the bus, the chip driver's detect function won't be called at all! This is due to the i2c subsystem architecture we have in the Linux kernel. So you cannot hope to be able to reproduce the trick in the chip driver. It belongs to the bus driver (unless we change the architecture).The wake up should go in the chip driver not the bus driver. It's not a problem with the bus, it a problem with the chip on the bus. Putting it in the bus driver means we need to add it to the bus driver for every video card instead if just once in the chip driver.
This gets called once per bus so the code to wake up the chip could be put here.
Quoted 8 lines
int
ddcmon_attach_adapter(struct i2c_adapter *adapter){ return i2c_detect(adapter, &addr_data, ddcmon_detect); }But now I don't know enough about i2c to rewrite the following code in generic terms using the
i2c_adapteroperations instead of direct IO port actions.
Hum, I can rewrite it using sda/scl operation, it's quite simple. But I don't think that the code is generic. When I wrote the adapter I decided to leave that stuff around just to be sure, but it does work without that black magic (ie. with only radeon_do_probe_i2c_edid), al least on my setup (R300 + analog LCD).
Also, I don't think that is safe to attach a client to radeon DDC busses (yet). During probe I fiddle directly with the adapter (without any locking), if another client kicks in I fear that it will blow up. radeonfb should register its own clients for probing EDID, it's in my TODO list.
Luca
Signature · 3 lines
Home: http://kronoz.cjb.net La differenza fra l'intelligenza e la stupidita`? All'intelligenza c'e` un limite.
Il Sat, Feb 28, 2004 at 06:54:08PM +0100, Jean Delvare ha scritto:
Quoted 2 lines
According to Jon, it's required only for some old monitors. BTW, Jon, where did you get this information from?
XFree driver.
Quoted 3 lines
Frankly, I don't see the point in handling these old monitors. At least, I wouldn't support them unless someone specifically asks for it and provides enough information for us to do the right thing.
Agreed, I'll talk to Benh about this issue.
Quoted 4 lines
As for where the code should be, I still think it is *not* possible to put it in the chip driver. If I understand it correctly, before the special sequence is send on the bus, the EDID does *not* respond to any I2C address. This means that the ddcmon driver will *never* be called.
That's not correct. You can remove the code that touches SDA/SCL but you need to activate i2c bus first:
OUTREG(reg, INREG(reg) & ~(VGA_DDC_DATA_OUTPUT | VGA_DDC_CLK_OUTPUT));
Btw, the voodoo code is the following:
radeon_gpio_setscl(chan, 1);radeon_gpio_setsda(chan, 1);
/* Looks like a start */radeon_gpio_setscl(chan, 1);
wait for radeon_gpio_getscl(chan); /* ack ? */radeon_gpio_setsda(chan, 0);radeon_gpio_setscl(chan, 0);
/* Stop ? */radeon_gpio_setsda(chan, 1);
read EDID
radeon_gpio_setsda(chan, 0);radeon_gpio_setscl(chan, 0);
/* Stop ? */radeon_gpio_setscl(chan, 1);
wait for radeon_gpio_getscl(chan); /* ack ? */radeon_gpio_setsda(chan, 1);
/* Start */radeon_gpio_setsda(chan, 0);radeon_gpio_setscl(chan, 0);
/* Stop again */
It seems pointeless to me, but it comes from XFree radeon driver. Can you make any sense out of it?
Quoted 9 lines
Quoted 5 lines
Also, I don't think that is safe to attach a client to radeon DDC busses (yet). During probe I fiddle directly with the adapter (without any locking), if another client kicks in I fear that it will blow up. radeonfb should register its own clients for probing EDID, it's in my TODO list.
I have been trying it :) And it worked correctly. Anyway, the radeonfb driver only probes the EDID at startup, right? So accessing it later sounds safe.
radeonfb can be build as a module, and we have a preemptible kernel... doh!
Quoted 2 lines
Thanks Kronos for entering the thread. I hadn't even realized you were subscribed to the list.
I'm not, but Jon put me on CC.
Luca
Signature · 3 lines
Home: http://kronoz.cjb.net Let me make your mind, leave yourself behind Be not afraid
Hi Kronos,
Quoted 5 lines
Hum, I can rewrite it using sda/scl operation, it's quite simple. But I don't think that the code is generic. When I wrote the adapter I decided to leave that stuff around just to be sure, but it does work without that black magic (ie. with only
radeon_do_probe_i2c_edid), al least on my setup (R300 + analog LCD).
According to Jon, it's required only for some old monitors. BTW, Jon, where did you get this information from?
I too have been having success with reading DDC information on various graphics adapters (Matrox and nVidia) on recent enough monitors.
Frankly, I don't see the point in handling these old monitors. At least, I wouldn't support them unless someone specifically asks for it and provides enough information for us to do the right thing.
As for where the code should be, I still think it is *not* possible to put it in the chip driver. If I understand it correctly, before the special sequence is send on the bus, the EDID does *not* respond to any I2C address. This means that the ddcmon driver will *never* be called.
Quoted 5 lines
Also, I don't think that is safe to attach a client to radeon DDC busses (yet). During probe I fiddle directly with the adapter (without any locking), if another client kicks in I fear that it will blow up. radeonfb should register its own clients for probing EDID, it's in my TODO list.
I have been trying it :) And it worked correctly. Anyway, the radeonfb driver only probes the EDID at startup, right? So accessing it later sounds safe.
Thanks Kronos for entering the thread. I hadn't even realized you were subscribed to the list.
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
benh and I have been talking about moving all of the EDID processing and mode computations up into user space. This is about 100K of code that is used in frequently and really has no need to be in a device driver. After the mode is computed the appropriate register values are passed in to the video driver. None of the user space code touches registers directly. The new klibc and initramfs support allow the mode to be set from userspace very early in the boot process via a hotplug event when the adapter is first detected.
It would be preferable if the user space code for retrieving EDID was the same for all cards. One way to achive this is for the cards to implement I2C bus drivers and then we have a univeral DDC chip implementation. For example right now if you load benh's radeon driver the standard i2c eeprom chip module will pick up the EDID. Waking up the DDC chip is a monitor issue so all video cards will need to deal with it. That why I wanted to fix it in the chip driver instead of implementing it in each video driver.
Finally, after we get a working version of an EDID driver, it would probably be best to go back and rework the eeprom driver to load decoder functions instead of having different drivers for each chip type. Right now there would be three
implementations: EDID, RAM, generic.
The user space code will use the eeprom image and decode the edid itself, but I need the wake-up DDC code in the kernel. The decoder functions will just be for optional fun so that the user can directly view the EDID or RAM contents.
==Jon Smirl
[email protected]
__________________________________
Do you Yahoo!?
Get better spam protection with Yahoo! Mail.
http://antispam.yahoo.com/tools
Quoted 5 lines · --- Jean Delvare
As for where the code should be, I still think it is *not* possible to put it in the chip driver. If I understand it correctly, before the special sequence is send on the bus, the EDID does *not* respond to any I2C address. This means that the ddcmon driver will *never* be called.
Am I reading this wrong? It looks to me like driver.attach_adapter, int ddcmon_attach_adapter(struct i2c_adapter *adapter) is always called when a bus is going to be probed.
Most of the drivers implement it like this:
int ddcmon_attach_adapter(struct i2c_adapter *adapter)
{
return i2c_detect(adapter, &addr_data, ddcmon_detect);
}It's then i2c_detect() that goes and looks for the devices and decides to call ddcmon_detect(); I see that ddcmon_detect() will not be called if none of the devices are present.
So the wakeup function can be added to the attach_adapter code. Isn't the whole point of the attach_adapter function to allow the implementation of a custom probing function?
==Jon Smirl
[email protected]
__________________________________
Do you Yahoo!?
Get better spam protection with Yahoo! Mail.
http://antispam.yahoo.com/tools
Il Sat, Feb 28, 2004 at 11:27:35AM -0800, Jon Smirl ha scritto:
Quoted 10 lines
Am I reading this wrong? It looks to me like driver.attach_adapter, int
ddcmon_attach_adapter(struct i2c_adapter *adapter)is always called when a bus is going to be probed.Most of the drivers implement it like this:
intddcmon_attach_adapter(struct i2c_adapter *adapter){ return i2c_detect(adapter, &addr_data, ddcmon_detect); }
Quoted 7 lines
It's then
i2c_detect()that goes and looks for the devices and decides to callddcmon_detect(); I see thatddcmon_detect()will not be called if none of the devices are present.So the wakeup function can be added to the
attach_adaptercode. Isn't the whole point of theattach_adapterfunction to allow the implementation of a custom probing function?
Yeah, but I need to access mmio space of the board, I need to touch registers to enable the bus. The strange start/stop sequence can be remove without any harm (well, I hope so...).
Before probing I need to enable data and clock lines. Now, in theory this operation can be done once at driver load time, but it's just a *guess*. I don't have any official doc that says that the bus will be left enabled.
Also, XFree is touching the same bus and I'm not sure that it will leave the bus enabled.... currently this is a non-issue because radeonfb uses it only on init. Don't know what will happen if a client can read from that bus at any time.
Luca
Signature · 3 lines
Home: http://kronoz.cjb.net Recursion n.: See Recursion.
Quoted 10 lines
Am I reading this wrong? It looks to me like driver.attach_adapter, int
ddcmon_attach_adapter(struct i2c_adapter *adapter)is always called when a bus is going to be probed.Most of the drivers implement it like this:
intddcmon_attach_adapter(struct i2c_adapter *adapter){ return i2c_detect(adapter, &addr_data, ddcmon_detect); }
Quoted 7 lines
It's then
i2c_detect()that goes and looks for the devices and decides to callddcmon_detect(); I see thatddcmon_detect()will not be called if none of the devices are present.So the wakeup function can be added to the
attach_adaptercode. Isn't the whole point of theattach_adapterfunction to allow the implementation of a custom probing function?
Hm, you have to be right here. It has become so usual that these function don't contain real code that I forgot that one could put something there, sorry.
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/