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 6/9 v2] sony-laptop: complete the motion eye camera support in sony-laptop
Date: Sat, 28 Apr 2007 23:34:22 +0900	[thread overview]
Message-ID: <20070428143422.GF5293@inferi.kami.home> (raw)
In-Reply-To: 20070428141557.GA4764@inferi.kami.home

[-- Attachment #1: 0013-complete-motion-eye-camera-support-from-sonypi.patch --]
[-- Type: text/plain, Size: 5205 bytes --]

Add the exported sony_pic_camera_command() function to make the MEYE
driver happy.

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-25 18:52:34.353553446 +0900
+++ linux-2.6/drivers/misc/sony-laptop.c	2007-04-25 18:52:37.353724416 +0900
@@ -1220,11 +1220,35 @@ static u8 sony_pic_call3(u8 dev, u8 fn, 
 
 /* camera tests and poweron/poweroff */
 #define SONYPI_CAMERA_PICTURE		5
-#define SONYPI_CAMERA_MUTE_MASK		0x40
 #define SONYPI_CAMERA_CONTROL		0x10
-#define SONYPI_CAMERA_STATUS 		7
-#define SONYPI_CAMERA_STATUS_READY 	0x2
-#define SONYPI_CAMERA_STATUS_POSITION	0x4
+
+#define SONYPI_CAMERA_BRIGHTNESS		0
+#define SONYPI_CAMERA_CONTRAST			1
+#define SONYPI_CAMERA_HUE			2
+#define SONYPI_CAMERA_COLOR			3
+#define SONYPI_CAMERA_SHARPNESS			4
+
+#define SONYPI_CAMERA_EXPOSURE_MASK		0xC
+#define SONYPI_CAMERA_WHITE_BALANCE_MASK	0x3
+#define SONYPI_CAMERA_PICTURE_MODE_MASK		0x30
+#define SONYPI_CAMERA_MUTE_MASK			0x40
+
+/* the rest don't need a loop until not 0xff */
+#define SONYPI_CAMERA_AGC			6
+#define SONYPI_CAMERA_AGC_MASK			0x30
+#define SONYPI_CAMERA_SHUTTER_MASK 		0x7
+
+#define SONYPI_CAMERA_SHUTDOWN_REQUEST		7
+#define SONYPI_CAMERA_CONTROL			0x10
+
+#define SONYPI_CAMERA_STATUS 			7
+#define SONYPI_CAMERA_STATUS_READY 		0x2
+#define SONYPI_CAMERA_STATUS_POSITION		0x4
+
+#define SONYPI_DIRECTION_BACKWARDS 		0x4
+
+#define SONYPI_CAMERA_REVISION 			8
+#define SONYPI_CAMERA_ROMVERSION 		9
 
 static int __sony_pic_camera_ready(void)
 {
@@ -1234,14 +1258,13 @@ static int __sony_pic_camera_ready(void)
 	return (v != 0xff && (v & SONYPI_CAMERA_STATUS_READY));
 }
 
-static int 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;
 	}
 
-	mutex_lock(&spic_dev.lock);
 	wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE,
 				SONYPI_CAMERA_MUTE_MASK),
 			ITERATIONS_SHORT);
@@ -1250,23 +1273,20 @@ static int sony_pic_camera_off(void)
 		sony_pic_call2(0x91, 0);
 		spic_dev.camera_power = 0;
 	}
-	mutex_unlock(&spic_dev.lock);
 	return 0;
 }
 
-static int sony_pic_camera_on(void)
+static int __sony_pic_camera_on(void)
 {
 	int i, j, x;
-	int result = 0;
 
 	if (!camera) {
 		printk(KERN_WARNING DRV_PFX "camera control not enabled\n");
 		return -ENODEV;
 	}
 
-	mutex_lock(&spic_dev.lock);
 	if (spic_dev.camera_power)
-		goto out_unlock;
+		return 0;
 
 	for (j = 5; j > 0; j--) {
 
@@ -1285,8 +1305,7 @@ static int sony_pic_camera_on(void)
 
 	if (j == 0) {
 		printk(KERN_WARNING DRV_PFX "failed to power on camera\n");
-		result = -ENODEV;
-		goto out_unlock;
+		return -ENODEV;
 	}
 
 	wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTROL,
@@ -1294,9 +1313,6 @@ static int sony_pic_camera_on(void)
 			ITERATIONS_SHORT);
 
 	spic_dev.camera_power = 1;
-
-out_unlock:
-	mutex_unlock(&spic_dev.lock);
 	return 0;
 }
 
@@ -1310,10 +1326,13 @@ static ssize_t sony_pic_camerapower_stor
 		return -EINVAL;
 
 	value = simple_strtoul(buffer, NULL, 10);
+
+	mutex_lock(&spic_dev.lock);
 	if (value)
-		result = sony_pic_camera_on();
+		result = __sony_pic_camera_on();
 	else
-		result = sony_pic_camera_off();
+		result = __sony_pic_camera_off();
+	mutex_unlock(&spic_dev.lock);
 
 	if (result)
 		return result;
@@ -1331,6 +1350,59 @@ static ssize_t sony_pic_camerapower_show
 	return count;
 }
 
+/* External camera command (exported to the motion eye v4l driver) */
+int sony_pic_camera_command(int command, u8 value)
+{
+	if (!camera)
+		return -EIO;
+
+	mutex_lock(&spic_dev.lock);
+
+	switch (command) {
+	case SONYPI_COMMAND_SETCAMERA:
+		if (value)
+			__sony_pic_camera_on();
+		else
+			__sony_pic_camera_off();
+		break;
+	case SONYPI_COMMAND_SETCAMERABRIGHTNESS:
+		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_BRIGHTNESS, value),
+				ITERATIONS_SHORT);
+		break;
+	case SONYPI_COMMAND_SETCAMERACONTRAST:
+		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTRAST, value),
+				ITERATIONS_SHORT);
+		break;
+	case SONYPI_COMMAND_SETCAMERAHUE:
+		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_HUE, value),
+				ITERATIONS_SHORT);
+		break;
+	case SONYPI_COMMAND_SETCAMERACOLOR:
+		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_COLOR, value),
+				ITERATIONS_SHORT);
+		break;
+	case SONYPI_COMMAND_SETCAMERASHARPNESS:
+		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_SHARPNESS, value),
+				ITERATIONS_SHORT);
+		break;
+	case SONYPI_COMMAND_SETCAMERAPICTURE:
+		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE, value),
+				ITERATIONS_SHORT);
+		break;
+	case SONYPI_COMMAND_SETCAMERAAGC:
+		wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_AGC, value),
+				ITERATIONS_SHORT);
+		break;
+	default:
+		printk(KERN_ERR DRV_PFX "sony_pic_camera_command invalid: %d\n",
+		       command);
+		break;
+	}
+	mutex_unlock(&spic_dev.lock);
+	return 0;
+}
+EXPORT_SYMBOL(sony_pic_camera_command);
+
 /* gprs/edge modem (SZ460N and SZ210P), thanks to Joshua Wise */
 static void sony_pic_set_wwanpower(u8 state)
 {

--
mattia
:wq!

  parent reply	other threads:[~2007-04-28 14:35 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 ` [patch 1/9 v2] sony-laptop: add camera enable/disable parameter, better handle possible infinite loop malattia
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 ` malattia [this message]
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=20070428143422.GF5293@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