From patchwork Fri Dec 3 11:32:16 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dzianis Kahanovich X-Patchwork-Id: 377371 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oB3BW9f2023202 for ; Fri, 3 Dec 2010 11:32:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758423Ab0LCLcY (ORCPT ); Fri, 3 Dec 2010 06:32:24 -0500 Received: from mail.bspu.unibel.by ([195.50.2.21]:55238 "EHLO mail.bspu.local" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758416Ab0LCLcX (ORCPT ); Fri, 3 Dec 2010 06:32:23 -0500 Received: from [10.200.200.1] ([10.200.200.1]) by mail.bspu.local (8.14.4/8.14.4) with ESMTP id oB3BW9Mb028206; Fri, 3 Dec 2010 13:32:14 +0200 Message-ID: <4CF8D540.5080405@bspu.unibel.by> Date: Fri, 03 Dec 2010 13:32:16 +0200 From: Dzianis Kahanovich Reply-To: mahatma@eu.by User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:2.0b7pre) Gecko/20101123 Firefox/4.0b7pre SeaMonkey/2.1b1 MIME-Version: 1.0 To: Paul Mundt CC: mahatma@eu.by, Joseph Chan , Florian Tobias Schandinat , linux-fbdev@vger.kernel.org Subject: [PATCH v5] viafb: I2C/DDC LCD detection for VIA framebuffer References: <4CED3DD5.5080405@bspu.unibel.by> <20101130061357.GE17114@linux-sh.org> In-Reply-To: <20101130061357.GE17114@linux-sh.org> X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.bspu.local Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Fri, 03 Dec 2010 11:32:24 +0000 (UTC) diff -pruN a/drivers/video/via/via-core.c b/drivers/video/via/via-core.c --- a/drivers/video/via/via-core.c 2010-12-03 13:06:06.000000000 +0200 +++ b/drivers/video/via/via-core.c 2010-12-03 13:16:14.000000000 +0200 @@ -559,6 +560,69 @@ static void via_teardown_subdevs(void) } } +static void via_i2c_detect(int stage) +{ + u8 *edid; + struct fb_var_screeninfo var; + int i, n = 0; + struct i2c_adapter *adapter; + struct lvds_setting_information *inf; + + for (i = 0; i < VIAFB_NUM_PORTS; i++) { + adapter = viafb_find_i2c_adapter(i); + if (!adapter || !adapter->algo_data || + !(edid = fb_ddc_read(adapter))) + continue; + memset(&var, 0, sizeof(var)); + if (fb_parse_edid(edid, &var)) + goto free_edid; + if (!stage) { + if (n && !viafb_active_dev) + viafb_dual_fb = STATE_ON; + inf = NULL; + } else if (!n || !viafb_LCD_ON) { + fb_edid_to_monspecs(edid, &viafbinfo->monspecs); + inf = viaparinfo->lvds_setting_info; + if (!viafb_active_dev) { + viafb_DVI_ON = + viaparinfo->tmds_setting_info->max_hres ? + STATE_ON : STATE_OFF; + if (viafbinfo->monspecs.input & FB_DISP_DDI) { + viafb_LCD_ON = STATE_ON; + viafb_DeviceStatus = LCD_Device; + if (!n) + viafb_primary_dev = LCD_Device; + } + } + } else if (viafb_dual_fb) { + fb_edid_to_monspecs(edid, &viafbinfo1->monspecs); + inf = viaparinfo1->lvds_setting_info; + if (!viafb_active_dev && + (viafbinfo1->monspecs.input & FB_DISP_DDI)) + viafb_LCD2_ON = STATE_ON; + } else { + fb_edid_to_monspecs(edid, &viafbinfo->monspecs); + inf = viaparinfo->lvds_setting_info2; + if (!viafb_active_dev && + (viafbinfo->monspecs.input & FB_DISP_DDI)) + viafb_LCD2_ON = STATE_ON; + } + if (inf) { + if (var.xres) + inf->lcd_panel_hres = var.xres; + if (var.yres) + inf->lcd_panel_vres = var.yres; + } + n++; +free_edid: + kfree(edid); + if (n > 1) + break; + } + if (stage && n && !viafb_active_dev) + viafb_set_iga_path(); +} + static int __devinit via_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) @@ -585,12 +649,16 @@ static int __devinit via_pci_probe(struc */ viafb_int_init(); via_setup_subdevs(&global_dev); + /* dual? */ + via_i2c_detect(0); /* * Set up the framebuffer device */ ret = via_fb_pci_probe(&global_dev); if (ret) goto out_subdevs; + /* LCD size & present */ + via_i2c_detect(1); return 0; out_subdevs: diff -pruN a/drivers/video/via/viafbdev.h b/drivers/video/via/viafbdev.h --- a/drivers/video/via/viafbdev.h 2010-08-02 01:11:14.000000000 +0300 +++ b/drivers/video/via/viafbdev.h 2010-12-03 13:13:50.000000000 +0200 @@ -88,6 +88,7 @@ extern int viafb_LCD2_ON; extern int viafb_LCD_ON; extern int viafb_DVI_ON; extern int viafb_hotplug; +extern char *viafb_active_dev; extern int strict_strtoul(const char *cp, unsigned int base, unsigned long *res); diff -pruN a/drivers/video/via/via_i2c.c b/drivers/video/via/via_i2c.c --- a/drivers/video/via/via_i2c.c 2010-12-03 13:06:06.000000000 +0200 +++ b/drivers/video/via/via_i2c.c 2010-12-03 13:10:26.000000000 +0200 @@ -167,7 +167,7 @@ struct i2c_adapter *viafb_find_i2c_adapt { struct via_i2c_stuff *stuff = &via_i2c_par[which]; - return &stuff->adapter; + return stuff->is_active ? &stuff->adapter : NULL; } EXPORT_SYMBOL_GPL(viafb_find_i2c_adapter);