From patchwork Thu Mar 3 19:03:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Drake X-Patchwork-Id: 607461 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 p23LTwjg010128 for ; Thu, 3 Mar 2011 21:29:58 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758718Ab1CCV34 (ORCPT ); Thu, 3 Mar 2011 16:29:56 -0500 Received: from queueout04-winn.ispmail.ntl.com ([81.103.221.58]:58516 "EHLO queueout04-winn.ispmail.ntl.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758263Ab1CCV34 (ORCPT ); Thu, 3 Mar 2011 16:29:56 -0500 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 03 Mar 2011 21:29:58 +0000 (UTC) X-Greylist: delayed 2423 seconds by postgrey-1.27 at vger.kernel.org; Thu, 03 Mar 2011 16:29:55 EST Received: from aamtaout04-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout01-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20110303190335.KDQH18231.mtaout01-winn.ispmail.ntl.com@aamtaout04-winn.ispmail.ntl.com>; Thu, 3 Mar 2011 19:03:35 +0000 Received: from zog.reactivated.net ([86.14.215.141]) by aamtaout04-winn.ispmail.ntl.com (InterMail vG.3.00.04.00 201-2196-133-20080908) with ESMTP id <20110303190334.LGFI25656.aamtaout04-winn.ispmail.ntl.com@zog.reactivated.net>; Thu, 3 Mar 2011 19:03:34 +0000 Received: by zog.reactivated.net (Postfix, from userid 1000) id E8ED79D401D; Thu, 3 Mar 2011 19:03:31 +0000 (GMT) From: Daniel Drake To: mchehab@infradead.org Cc: linux-media@vger.kernel.org Cc: corbet@lwn.net Cc: dilinger@queued.net Subject: [PATCH] via-camera: Fix OLPC serial check Message-Id: <20110303190331.E8ED79D401D@zog.reactivated.net> Date: Thu, 3 Mar 2011 19:03:31 +0000 (GMT) X-Cloudmark-Analysis: v=1.1 cv=R50lirqlHffDPPkwUlkuVa99MrvKdVWo//yz83qex8g= c=1 sm=0 a=54JAOo5n_PwA:10 a=Op-mwl0xAAAA:8 a=Yv50c-Wc3aP7rPtT9qMA:9 a=oXlSP3OYaiQy6L1wMnsA:7 a=jDERWB7OqfoCQMN_Fp2YELl3TZMA:4 a=d4CUUju0HPYA:10 a=iFDLTJ3UA3f8Zx9v:21 a=kChabVvrxKApPnL9:21 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org diff --git a/drivers/media/video/via-camera.c b/drivers/media/video/via-camera.c index 2f973cd..4f19edc 100644 --- a/drivers/media/video/via-camera.c +++ b/drivers/media/video/via-camera.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "via-camera.h" @@ -38,14 +39,12 @@ MODULE_PARM_DESC(flip_image, "If set, the sensor will be instructed to flip the image " "vertically."); -#ifdef CONFIG_OLPC_XO_1_5 static int override_serial; module_param(override_serial, bool, 0444); MODULE_PARM_DESC(override_serial, "The camera driver will normally refuse to load if " "the XO 1.5 serial port is enabled. Set this option " - "to force the issue."); -#endif + "to force-enable the camera."); /* * Basic window sizes. @@ -1261,6 +1260,37 @@ static struct video_device viacam_v4l_template = { .release = video_device_release_empty, /* Check this */ }; +/* + * The OLPC folks put the serial port on the same pin as + * the camera. They also get grumpy if we break the + * serial port and keep them from using it. So we have + * to check the serial enable bit and not step on it. + */ +#define VIACAM_SERIAL_DEVFN 0x88 +#define VIACAM_SERIAL_CREG 0x46 +#define VIACAM_SERIAL_BIT 0x40 + +static __devinit bool viacam_serial_is_enabled(void) +{ + struct pci_bus *pbus = pci_find_bus(0, 0); + u8 cbyte; + + pci_bus_read_config_byte(pbus, VIACAM_SERIAL_DEVFN, + VIACAM_SERIAL_CREG, &cbyte); + if ((cbyte & VIACAM_SERIAL_BIT) == 0) + return false; /* Not enabled */ + if (override_serial == 0) { + printk(KERN_NOTICE "Via camera: serial port is enabled, " \ + "refusing to load.\n"); + printk(KERN_NOTICE "Specify override_serial=1 to force " \ + "module loading.\n"); + return true; + } + printk(KERN_NOTICE "Via camera: overriding serial port\n"); + pci_bus_write_config_byte(pbus, VIACAM_SERIAL_DEVFN, + VIACAM_SERIAL_CREG, cbyte & ~VIACAM_SERIAL_BIT); + return false; +} static __devinit int viacam_probe(struct platform_device *pdev) { @@ -1292,6 +1322,10 @@ static __devinit int viacam_probe(struct platform_device *pdev) printk(KERN_ERR "viacam: No I/O memory, so no pictures\n"); return -ENOMEM; } + + if (machine_is_olpc() && viacam_serial_is_enabled()) + return -EBUSY; + /* * Basic structure initialization. */ @@ -1395,7 +1429,6 @@ static __devexit int viacam_remove(struct platform_device *pdev) return 0; } - static struct platform_driver viacam_driver = { .driver = { .name = "viafb-camera", @@ -1404,50 +1437,8 @@ static struct platform_driver viacam_driver = { .remove = viacam_remove, }; - -#ifdef CONFIG_OLPC_XO_1_5 -/* - * The OLPC folks put the serial port on the same pin as - * the camera. They also get grumpy if we break the - * serial port and keep them from using it. So we have - * to check the serial enable bit and not step on it. - */ -#define VIACAM_SERIAL_DEVFN 0x88 -#define VIACAM_SERIAL_CREG 0x46 -#define VIACAM_SERIAL_BIT 0x40 - -static __devinit int viacam_check_serial_port(void) -{ - struct pci_bus *pbus = pci_find_bus(0, 0); - u8 cbyte; - - pci_bus_read_config_byte(pbus, VIACAM_SERIAL_DEVFN, - VIACAM_SERIAL_CREG, &cbyte); - if ((cbyte & VIACAM_SERIAL_BIT) == 0) - return 0; /* Not enabled */ - if (override_serial == 0) { - printk(KERN_NOTICE "Via camera: serial port is enabled, " \ - "refusing to load.\n"); - printk(KERN_NOTICE "Specify override_serial=1 to force " \ - "module loading.\n"); - return -EBUSY; - } - printk(KERN_NOTICE "Via camera: overriding serial port\n"); - pci_bus_write_config_byte(pbus, VIACAM_SERIAL_DEVFN, - VIACAM_SERIAL_CREG, cbyte & ~VIACAM_SERIAL_BIT); - return 0; -} -#endif - - - - static int viacam_init(void) { -#ifdef CONFIG_OLPC_XO_1_5 - if (viacam_check_serial_port()) - return -EBUSY; -#endif return platform_driver_register(&viacam_driver); } module_init(viacam_init);