From patchwork Wed Oct 27 19:02:28 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Drake X-Patchwork-Id: 286492 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 o9RJ2blW001355 for ; Wed, 27 Oct 2010 19:02:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753452Ab0J0TCg (ORCPT ); Wed, 27 Oct 2010 15:02:36 -0400 Received: from mtaout01-winn.ispmail.ntl.com ([81.103.221.47]:46131 "EHLO mtaout01-winn.ispmail.ntl.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751541Ab0J0TCf (ORCPT ); Wed, 27 Oct 2010 15:02:35 -0400 Received: from aamtaout03-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 <20101027190230.IWKA25742.mtaout01-winn.ispmail.ntl.com@aamtaout03-winn.ispmail.ntl.com>; Wed, 27 Oct 2010 20:02:30 +0100 Received: from zog.reactivated.net ([86.14.215.141]) by aamtaout03-winn.ispmail.ntl.com (InterMail vG.3.00.04.00 201-2196-133-20080908) with ESMTP id <20101027190230.RTNF28282.aamtaout03-winn.ispmail.ntl.com@zog.reactivated.net>; Wed, 27 Oct 2010 20:02:30 +0100 Received: by zog.reactivated.net (Postfix, from userid 1000) id 3C87D9D401B; Wed, 27 Oct 2010 20:02:28 +0100 (BST) From: Daniel Drake To: corbet@lwn.net Cc: linux-media@vger.kernel.org Subject: [PATCH] via-camera: fix OLPC serial port check Message-Id: <20101027190228.3C87D9D401B@zog.reactivated.net> Date: Wed, 27 Oct 2010 20:02:28 +0100 (BST) X-Cloudmark-Analysis: v=1.1 cv=DhNl2YeytwJssBBGe49HJX82LNDFEEVkpVB34RXKaPo= c=1 sm=0 a=3gUis1OcyyYA:10 a=Op-mwl0xAAAA:8 a=07d9gI8wAAAA:8 a=1rO_PT73_hPhHh5cx1oA:9 a=z0HsKdpTtHR-1dFSgDglBjDNcW8A:4 a=d4CUUju0HPYA:10 a=6fZZb_PjwVMA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@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]); Wed, 27 Oct 2010 19:02:38 +0000 (UTC) diff --git a/drivers/media/video/via-camera.c b/drivers/media/video/via-camera.c index 02a21bc..118c26b 100644 --- a/drivers/media/video/via-camera.c +++ b/drivers/media/video/via-camera.c @@ -28,6 +28,8 @@ #include #include +#include + #include "via-camera.h" MODULE_AUTHOR("Jonathan Corbet "); @@ -40,14 +42,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 /* * Basic window sizes. @@ -1276,6 +1276,40 @@ 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 int viacam_check_serial_port(void) +{ + struct pci_bus *pbus = pci_find_bus(0, 0); + u8 cbyte; + + if (!machine_is_olpc()) + return 0; + + 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; +} static __devinit int viacam_probe(struct platform_device *pdev) { @@ -1291,6 +1325,9 @@ static __devinit int viacam_probe(struct platform_device *pdev) */ struct via_camera *cam; + if (viacam_check_serial_port()) + return -EBUSY; + /* * Ensure that frame buffer memory has been set aside for * this purpose. As an arbitrary limit, refuse to work @@ -1420,49 +1457,8 @@ static struct platform_driver viacam_driver = { }; -#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);