Linux Framebuffer Layer development
 help / color / mirror / Atom feed
From: Dzianis Kahanovich <mahatma@bspu.unibel.by>
To: linux-fbdev@vger.kernel.org
Subject: [PATCH v5] viafb: I2C/DDC legacy & detect output device if viafb_active_dev
Date: Tue, 04 Jan 2011 11:22:01 +0000	[thread overview]
Message-ID: <4D2302D9.4060404@bspu.unibel.by> (raw)

Adding output device detection. Including legacy I2C/DDC code, currently safe
mostly for LCD, think "unknown" device as forced CRT. Detect whole output config
if "viafb_active_dev" unset, or undetected else LCDs in other cases. Also early
viafb_crt_enable if CRT ON - to force CRT DDC detection and multi-out in
textmode as positive side-effect.

v5 - check adapter->algo_data (against multiple viafb_find_i2c_adapter()
behaviours).

Signed-off-by: Dzianis Kahanovich <mahatma@eu.by>
---
--- a/drivers/video/via/viafbdev.c	2011-01-04 13:10:20.000000000 +0200
+++ b/drivers/video/via/viafbdev.c	2011-01-04 13:12:34.000000000 +0200
@@ -1670,6 +1670,119 @@ static int parse_mode(const char *str, u
 	return 0;
 }

+/* Add devices, detected only via i2c legacy.
+   Really there may be CRT too, but unless I got no CRT DDC - LCD only.
+   Possible CRT may be found as "unknown" to keep CRT ON.
+   Set LCD/DVI/CRT if viafb_active_dev unset. */
+static void viafb_detect_dev(struct viafb_dev *vdev)
+{
+	u8 *edid;
+	struct fb_var_screeninfo var;
+	int i, t, ndev = 0, nlcd = 0, unknown = 0;
+	struct i2c_adapter *adapter;
+	struct lvds_setting_information *inf;
+
+	/* FIXME: viaparinfo1->chip_info looks equal to viaparinfo */
+	if (viaparinfo->chip_info->tmds_chip_info.tmds_chip_name) {
+		ndev++;
+		if (!viafb_active_dev)
+			viafb_DVI_ON = STATE_ON;
+	}
+	if (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
+		ndev++;
+		nlcd = 1;
+		if (!viafb_active_dev)
+			viafb_LCD_ON = STATE_ON;
+	}
+	if (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
+		ndev++;
+		nlcd = 2;
+		if (!viafb_active_dev)
+			viafb_LCD2_ON = STATE_ON;
+	}
+	/* enabling CRT in textmode is at least no bad */
+	if (viafb_CRT_ON) {
+		ndev++;
+		viafb_crt_enable();
+	}
+	for (i = 0; i < VIAFB_NUM_PORTS; i++) {
+		t = vdev->port_cfg[i].type;
+		/* detect only i2c ports, undetected in other places */
+		if ((viaparinfo && viaparinfo->chip_info && (
+		    (viaparinfo->chip_info->tmds_chip_info.tmds_chip_name &&
+		    viaparinfo->chip_info->tmds_chip_info.i2c_port = t) ||
+		    (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name &&
+		    viaparinfo->chip_info->lvds_chip_info.i2c_port = t) ||
+		    (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name &&
+		    viaparinfo->chip_info->lvds_chip_info2.i2c_port = t)
+		    )) || (viaparinfo1 && viaparinfo1->chip_info && (
+		    (viaparinfo1->chip_info->tmds_chip_info.tmds_chip_name &&
+		    viaparinfo1->chip_info->tmds_chip_info.i2c_port = t) ||
+		    (viaparinfo1->chip_info->lvds_chip_info.lvds_chip_name &&
+		    viaparinfo1->chip_info->lvds_chip_info.i2c_port = t) ||
+		    (viaparinfo1->chip_info->lvds_chip_info2.lvds_chip_name &&
+		    viaparinfo1->chip_info->lvds_chip_info2.i2c_port = t)
+		    )) || !(adapter = viafb_find_i2c_adapter(i)) ||
+		    !adapter->algo_data || !(edid = fb_ddc_read(adapter)))
+			continue;
+		memset(&var, 0, sizeof(var));
+		if (fb_parse_edid(edid, &var))
+			goto free_edid;
+		printk(KERN_INFO "viafb: %48s\n", adapter->name);
+		inf = NULL;
+		if (!nlcd) {
+			fb_edid_to_monspecs(edid, &viafbinfo->monspecs);
+			if (viafbinfo->monspecs.input & FB_DISP_DDI)
+				inf = viaparinfo->lvds_setting_info;
+			else
+				unknown++;
+		} else if (nlcd > 1) {
+			printk(KERN_ERR "viafb: too many LCD\n");
+			unknown++;
+		} else if (viafb_dual_fb) {
+			fb_edid_to_monspecs(edid, &viafbinfo1->monspecs);
+			if (viafbinfo1->monspecs.input & FB_DISP_DDI)
+				inf = viaparinfo1->lvds_setting_info;
+			else
+				unknown++;
+		} else {
+			fb_edid_to_monspecs(edid, &viafbinfo->monspecs);
+			if (viafbinfo->monspecs.input & FB_DISP_DDI)
+				inf = viaparinfo->lvds_setting_info2;
+			else
+				unknown++;
+		}
+		if (inf) {
+			if (!viafb_active_dev) {
+				if (nlcd)
+					viafb_LCD2_ON = STATE_ON;
+				else
+					viafb_LCD_ON = STATE_ON;
+			}
+			nlcd++;
+			if (var.xres)
+				inf->lcd_panel_hres = var.xres;
+			if (var.yres)
+				inf->lcd_panel_vres = var.yres;
+		}
+		ndev++;
+free_edid:
+		kfree(edid);
+	}
+	if (!viafb_active_dev) {
+		/* prefer CRT OFF if other devices */
+		if (!unknown && ndev > 1) {
+			viafb_CRT_ON = STATE_OFF;
+			viafb_crt_disable();
+		}
+		viafb_DeviceStatus = viafb_primary_dev +		    viafb_CRT_ON ? CRT_Device :
+		    viafb_DVI_ON ? DVI_Device :
+		    viafb_LCD_ON ? LCD_Device : None_Device;
+		viafb_set_iga_path();
+	}
+}
+

 #ifdef CONFIG_PM
 static int viafb_suspend(void *unused)
@@ -1891,6 +2004,7 @@ int __devinit via_fb_pci_probe(struct vi

 	viafb_init_proc(viaparinfo->shared);
 	viafb_init_dac(IGA2);
+	viafb_detect_dev(vdev);

 #ifdef CONFIG_PM
 	viafb_pm_register(&viafb_fb_pm_hooks);
--

                 reply	other threads:[~2011-01-04 11:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D2302D9.4060404@bspu.unibel.by \
    --to=mahatma@bspu.unibel.by \
    --cc=linux-fbdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox