public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: malattia@linux.it
To: lenb@kernel.org
Cc: linux-acpi@vger.kernel.org, Stelian Pop <stelian@popies.net>,
	Mattia Dongili <malattia@linux.it>
Subject: [patch 1/9 v2] sony-laptop: add camera enable/disable parameter, better handle possible infinite loop
Date: Sat, 28 Apr 2007 23:18:45 +0900	[thread overview]
Message-ID: <20070428141845.GA5293@inferi.kami.home> (raw)
In-Reply-To: 20070428141557.GA4764@inferi.kami.home

[-- Attachment #1: 0006-add-SNY6001-platform-attributes-fix-camera-opts.patch --]
[-- Type: text/plain, Size: 3257 bytes --]

Use a parameter to enable/disable motion eye camera (for C1VE/C1VN models)
controls and avoid entering an infinite loop if the camera is not present
and the HW doesn't answer as we expect on io commands.

Signed-off-by: Mattia Dongili <malattia@linux.it>
---
Index: linux-2.6/drivers/misc/sony-laptop.c
===================================================================
--- linux-2.6.orig/drivers/misc/sony-laptop.c	2007-04-23 00:20:19.586798352 +0900
+++ linux-2.6/drivers/misc/sony-laptop.c	2007-04-23 00:26:25.107628197 +0900
@@ -107,6 +107,12 @@ module_param(mask, ulong, 0644);
 MODULE_PARM_DESC(mask,
 		 "set this to the mask of event you want to enable (see doc)");
 
+static int camera;		/* = 0 */
+module_param(camera, int, 0444);
+MODULE_PARM_DESC(camera,
+		 "set this to 1 to enable Motion Eye camera controls "
+		 "(only use it if you have a C1VE or C1VN model)");
+
 #ifdef CONFIG_SONY_LAPTOP_OLD
 static int minor = -1;
 module_param(minor, int, 0);
@@ -1226,29 +1232,39 @@ static int sony_pic_camera_ready(void)
 	return (v != 0xff && (v & SONYPI_CAMERA_STATUS_READY));
 }
 
-static void sony_pic_camera_off(void)
+static int sony_pic_camera_off(void)
 {
+	if (!camera) {
+		printk(KERN_WARNING DRV_PFX "camera control not enabled\n");
+		return -ENODEV;
+	}
+
 	wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE,
 				SONYPI_CAMERA_MUTE_MASK),
 			ITERATIONS_SHORT);
 
-	if (!spic_dev.camera_power)
-		return;
-
-	sony_pic_call2(0x91, 0);
-	spic_dev.camera_power = 0;
+	if (spic_dev.camera_power) {
+		sony_pic_call2(0x91, 0);
+		spic_dev.camera_power = 0;
+	}
+	return 0;
 }
 
-static void sony_pic_camera_on(void)
+static int sony_pic_camera_on(void)
 {
-	int i, j;
+	int i, j, x;
+
+	if (!camera) {
+		printk(KERN_WARNING DRV_PFX "camera control not enabled\n");
+		return -ENODEV;
+	}
 
 	if (spic_dev.camera_power)
-		return;
+		return 0;
 
 	for (j = 5; j > 0; j--) {
 
-		while (sony_pic_call2(0x91, 0x1))
+		for (x = 0; x < 100 && sony_pic_call2(0x91, 0x1); x++)
 			msleep(10);
 		sony_pic_call1(0x93);
 
@@ -1262,8 +1278,8 @@ static void sony_pic_camera_on(void)
 	}
 
 	if (j == 0) {
-		printk(KERN_WARNING "sonypi: failed to power on camera\n");
-		return;
+		printk(KERN_WARNING DRV_PFX "failed to power on camera\n");
+		return -ENODEV;
 	}
 
 	wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTROL,
@@ -1271,6 +1287,7 @@ static void sony_pic_camera_on(void)
 			ITERATIONS_SHORT);
 
 	spic_dev.camera_power = 1;
+	return 0;
 }
 
 static ssize_t sony_pic_camerapower_store(struct device *dev,
@@ -1278,14 +1295,18 @@ static ssize_t sony_pic_camerapower_stor
 		const char *buffer, size_t count)
 {
 	unsigned long value;
+	int result;
 	if (count > 31)
 		return -EINVAL;
 
 	value = simple_strtoul(buffer, NULL, 10);
 	if (value)
-		sony_pic_camera_on();
+		result = sony_pic_camera_on();
 	else
-		sony_pic_camera_off();
+		result = sony_pic_camera_off();
+
+	if (result)
+		return result;
 
 	return count;
 }
@@ -1662,7 +1683,7 @@ static int sonypi_compat_init(void)
 		goto err_free_kfifo;
 	}
 	if (minor == -1)
-		printk(KERN_INFO "sonypi: device allocated minor is %d\n",
+		printk(KERN_INFO DRV_PFX "device allocated minor is %d\n",
 		       sonypi_misc_device.minor);
 
 	return 0;

--
mattia
:wq!

  reply	other threads:[~2007-04-28 14:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-28 14:15 [patch 0/9 v2] sony drivers: finish rewriting sonypi and updates malattia
2007-04-28 14:18 ` malattia [this message]
2007-04-28 14:19 ` [patch 2/9 v2] sony-laptop: add locking on accesses to the ioport and global vars malattia
2007-04-28 14:21 ` [patch 3/9 v2] sony-laptop: add edge modem support (also called WWAN) malattia
2007-04-28 14:22 ` [patch 4/9 v2] sonypi: suggest sonypi users to try sony-laptop instead malattia
2007-04-28 14:34 ` [patch 5/9 v2] sonypi: try to detect if sony-laptop has already taken one of the known ioports malattia
2007-04-28 14:34 ` [patch 6/9 v2] sony-laptop: complete the motion eye camera support in sony-laptop malattia
2007-04-28 14:34 ` [patch 7/9 v2] sony-laptop: add a meye-usable include file for camera ops malattia
2007-04-28 14:36 ` [patch 8/9 v2] meye: make meye use sony-laptop instead of sonypi malattia
2007-04-28 14:36 ` [patch 9/9 v2] sony-laptop: remove user visible camera controls as platform attributes malattia
2007-04-29  4:42 ` [patch 0/9 v2] sony drivers: finish rewriting sonypi and updates Len Brown

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=20070428141845.GA5293@inferi.kami.home \
    --to=malattia@linux.it \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=stelian@popies.net \
    /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