linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] gspca_pac7302: correct register documentation
@ 2012-09-16 16:00 Frank Schäfer
  0 siblings, 0 replies; 4+ messages in thread
From: Frank Schäfer @ 2012-09-16 16:00 UTC (permalink / raw)
  To: hdegoede; +Cc: linux-media, Frank Schäfer

R,G,B balance registers are 0x01-0x03 instead of 0x02-0x04,
which lead to the wrong conclusion that values are inverted.
Exposure is controlled via page 3 registers and this is already documented.
Also fix a whitespace issue.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
---
 drivers/media/usb/gspca/pac7302.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/media/usb/gspca/pac7302.c b/drivers/media/usb/gspca/pac7302.c
index 2d5c6d83..4894ac1 100644
--- a/drivers/media/usb/gspca/pac7302.c
+++ b/drivers/media/usb/gspca/pac7302.c
@@ -29,14 +29,13 @@
  * Register page 0:
  *
  * Address	Description
- * 0x02		Red balance control
- * 0x03		Green balance control
- * 0x04 	Blue balance control
- *		     Valus are inverted (0=max, 255=min).
+ * 0x01		Red balance control
+ * 0x02		Green balance control
+ * 0x03		Blue balance control
  *		     The Windows driver uses a quadratic approach to map
  *		     the settable values (0-200) on register values:
- *		     min=0x80, default=0x40, max=0x20
- * 0x0f-0x20	Colors, saturation and exposure control
+ *		     min=0x20, default=0x40, max=0x80
+ * 0x0f-0x20	Color and saturation control
  * 0xa2-0xab	Brightness, contrast and gamma control
  * 0xb6		Sharpness control (bits 0-4)
  *
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 1/4] gspca_pac7302: correct register documentation
@ 2012-09-23 13:29 Frank Schäfer
  2012-09-23 13:29 ` [PATCH 2/4] gspca_pac7302: use registers 0x01 and 0x03 for red and blue balance controls Frank Schäfer
  2012-09-24 14:17 ` [PATCH 1/4] gspca_pac7302: correct register documentation Hans de Goede
  0 siblings, 2 replies; 4+ messages in thread
From: Frank Schäfer @ 2012-09-23 13:29 UTC (permalink / raw)
  To: hdegoede; +Cc: linux-media, Frank Schäfer

R,G,B balance registers are 0x01-0x03 instead of 0x02-0x04,
which lead to the wrong conclusion that values are inverted.
Exposure is controlled via page 3 registers and this is already documented.
Also fix a whitespace issue.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
---
 drivers/media/usb/gspca/pac7302.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/media/usb/gspca/pac7302.c b/drivers/media/usb/gspca/pac7302.c
index 2d5c6d83..4894ac1 100644
--- a/drivers/media/usb/gspca/pac7302.c
+++ b/drivers/media/usb/gspca/pac7302.c
@@ -29,14 +29,13 @@
  * Register page 0:
  *
  * Address	Description
- * 0x02		Red balance control
- * 0x03		Green balance control
- * 0x04 	Blue balance control
- *		     Valus are inverted (0=max, 255=min).
+ * 0x01		Red balance control
+ * 0x02		Green balance control
+ * 0x03		Blue balance control
  *		     The Windows driver uses a quadratic approach to map
  *		     the settable values (0-200) on register values:
- *		     min=0x80, default=0x40, max=0x20
- * 0x0f-0x20	Colors, saturation and exposure control
+ *		     min=0x20, default=0x40, max=0x80
+ * 0x0f-0x20	Color and saturation control
  * 0xa2-0xab	Brightness, contrast and gamma control
  * 0xb6		Sharpness control (bits 0-4)
  *
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/4] gspca_pac7302: use registers 0x01 and 0x03 for red and blue balance controls
  2012-09-23 13:29 [PATCH 1/4] gspca_pac7302: correct register documentation Frank Schäfer
@ 2012-09-23 13:29 ` Frank Schäfer
  2012-09-24 14:17 ` [PATCH 1/4] gspca_pac7302: correct register documentation Hans de Goede
  1 sibling, 0 replies; 4+ messages in thread
From: Frank Schäfer @ 2012-09-23 13:29 UTC (permalink / raw)
  To: hdegoede; +Cc: linux-media, Frank Schäfer

Currently used registers 0xc5 and 0xc7 provide only a very coarse
adjustment possibility within a very small value range (0-3).
With registers 0x01 and 0x03, a fine grained adjustment with
255 steps is possible. This is also what the Windows driver does.

Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>
---
 drivers/media/usb/gspca/pac7302.c |   51 +++++++++++++++++++++++++++++--------
 1 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/drivers/media/usb/gspca/pac7302.c b/drivers/media/usb/gspca/pac7302.c
index 4894ac1..8a0f4d6 100644
--- a/drivers/media/usb/gspca/pac7302.c
+++ b/drivers/media/usb/gspca/pac7302.c
@@ -77,12 +77,12 @@
  *
  * Page | Register   | Function
  * -----+------------+---------------------------------------------------
+ *  0   | 0x01       | setredbalance()
+ *  0   | 0x03       | setbluebalance()
  *  0   | 0x0f..0x20 | setcolors()
  *  0   | 0xa2..0xab | setbrightcont()
  *  0   | 0xb6       | setsharpness()
- *  0   | 0xc5       | setredbalance()
  *  0   | 0xc6       | setwhitebalance()
- *  0   | 0xc7       | setbluebalance()
  *  0   | 0xdc       | setbrightcont(), setcolors()
  *  3   | 0x02       | setexposure()
  *  3   | 0x10, 0x12 | setgain()
@@ -98,10 +98,13 @@
 /* Include pac common sof detection functions */
 #include "pac_common.h"
 
-#define PAC7302_GAIN_DEFAULT      15
-#define PAC7302_GAIN_KNEE         42
-#define PAC7302_EXPOSURE_DEFAULT  66 /* 33 ms / 30 fps */
-#define PAC7302_EXPOSURE_KNEE    133 /* 66 ms / 15 fps */
+#define PAC7302_RGB_BALANCE_MIN		  0
+#define PAC7302_RGB_BALANCE_MAX		200
+#define PAC7302_RGB_BALANCE_DEFAULT	100
+#define PAC7302_GAIN_DEFAULT		 15
+#define PAC7302_GAIN_KNEE 		 42
+#define PAC7302_EXPOSURE_DEFAULT	 66 /* 33 ms / 30 fps */
+#define PAC7302_EXPOSURE_KNEE		133 /* 66 ms / 15 fps */
 
 MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>, "
 		"Thomas Kaiser thomas@kaiser-linux.li");
@@ -438,12 +441,31 @@ static void setwhitebalance(struct gspca_dev *gspca_dev)
 	reg_w(gspca_dev, 0xdc, 0x01);
 }
 
+static u8 rgbbalance_ctrl_to_reg_value(s32 rgb_ctrl_val)
+{
+	const unsigned int k = 1000;	/* precision factor */
+	unsigned int norm;
+
+	/* Normed value [0...k] */
+	norm = k * (rgb_ctrl_val - PAC7302_RGB_BALANCE_MIN)
+		    / (PAC7302_RGB_BALANCE_MAX - PAC7302_RGB_BALANCE_MIN);
+	/* Qudratic apporach improves control at small (register) values: */
+	return 64 * norm * norm / (k*k)  +  32 * norm / k  +  32;
+	/* Y = 64*X*X + 32*X + 32
+	 * => register values 0x20-0x80; Windows driver uses these limits */
+
+	/* NOTE: for full value range (0x00-0xff) use
+	 *         Y = 254*X*X + X
+	 *         => 254 * norm * norm / (k*k)  +  1 * norm / k	*/
+}
+
 static void setredbalance(struct gspca_dev *gspca_dev)
 {
 	struct sd *sd = (struct sd *) gspca_dev;
 
-	reg_w(gspca_dev, 0xff, 0x00);		/* page 0 */
-	reg_w(gspca_dev, 0xc5, sd->red_balance->val);
+	reg_w(gspca_dev, 0xff, 0x00);			/* page 0 */
+	reg_w(gspca_dev, 0x01,
+	      rgbbalance_ctrl_to_reg_value(sd->red_balance->val));
 
 	reg_w(gspca_dev, 0xdc, 0x01);
 }
@@ -453,7 +475,8 @@ static void setbluebalance(struct gspca_dev *gspca_dev)
 	struct sd *sd = (struct sd *) gspca_dev;
 
 	reg_w(gspca_dev, 0xff, 0x00);			/* page 0 */
-	reg_w(gspca_dev, 0xc7, sd->blue_balance->val);
+	reg_w(gspca_dev, 0x03,
+	      rgbbalance_ctrl_to_reg_value(sd->blue_balance->val));
 
 	reg_w(gspca_dev, 0xdc, 0x01);
 }
@@ -642,9 +665,15 @@ static int sd_init_controls(struct gspca_dev *gspca_dev)
 					V4L2_CID_WHITE_BALANCE_TEMPERATURE,
 					0, 255, 1, 55);
 	sd->red_balance = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
-					V4L2_CID_RED_BALANCE, 0, 3, 1, 1);
+					V4L2_CID_RED_BALANCE,
+					PAC7302_RGB_BALANCE_MIN,
+					PAC7302_RGB_BALANCE_MAX,
+					1, PAC7302_RGB_BALANCE_DEFAULT);
 	sd->blue_balance = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
-					V4L2_CID_BLUE_BALANCE, 0, 3, 1, 1);
+					V4L2_CID_BLUE_BALANCE,
+					PAC7302_RGB_BALANCE_MIN,
+					PAC7302_RGB_BALANCE_MAX,
+					1, PAC7302_RGB_BALANCE_DEFAULT);
 
 	gspca_dev->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
 					V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/4] gspca_pac7302: correct register documentation
  2012-09-23 13:29 [PATCH 1/4] gspca_pac7302: correct register documentation Frank Schäfer
  2012-09-23 13:29 ` [PATCH 2/4] gspca_pac7302: use registers 0x01 and 0x03 for red and blue balance controls Frank Schäfer
@ 2012-09-24 14:17 ` Hans de Goede
  1 sibling, 0 replies; 4+ messages in thread
From: Hans de Goede @ 2012-09-24 14:17 UTC (permalink / raw)
  To: Frank Schäfer; +Cc: linux-media

Hi,

On 09/23/2012 03:29 PM, Frank Schäfer wrote:
> R,G,B balance registers are 0x01-0x03 instead of 0x02-0x04,
> which lead to the wrong conclusion that values are inverted.
> Exposure is controlled via page 3 registers and this is already documented.
> Also fix a whitespace issue.
>
> Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com>

Thanks, as discussed I've added the first 2 patches to my media tree and
they will be included in my next pull-req to Mauro.

Regards,

Hans



> ---
>   drivers/media/usb/gspca/pac7302.c |   11 +++++------
>   1 files changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/media/usb/gspca/pac7302.c b/drivers/media/usb/gspca/pac7302.c
> index 2d5c6d83..4894ac1 100644
> --- a/drivers/media/usb/gspca/pac7302.c
> +++ b/drivers/media/usb/gspca/pac7302.c
> @@ -29,14 +29,13 @@
>    * Register page 0:
>    *
>    * Address	Description
> - * 0x02		Red balance control
> - * 0x03		Green balance control
> - * 0x04 	Blue balance control
> - *		     Valus are inverted (0=max, 255=min).
> + * 0x01		Red balance control
> + * 0x02		Green balance control
> + * 0x03		Blue balance control
>    *		     The Windows driver uses a quadratic approach to map
>    *		     the settable values (0-200) on register values:
> - *		     min=0x80, default=0x40, max=0x20
> - * 0x0f-0x20	Colors, saturation and exposure control
> + *		     min=0x20, default=0x40, max=0x80
> + * 0x0f-0x20	Color and saturation control
>    * 0xa2-0xab	Brightness, contrast and gamma control
>    * 0xb6		Sharpness control (bits 0-4)
>    *
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-09-24 14:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-23 13:29 [PATCH 1/4] gspca_pac7302: correct register documentation Frank Schäfer
2012-09-23 13:29 ` [PATCH 2/4] gspca_pac7302: use registers 0x01 and 0x03 for red and blue balance controls Frank Schäfer
2012-09-24 14:17 ` [PATCH 1/4] gspca_pac7302: correct register documentation Hans de Goede
  -- strict thread matches above, loose matches on Subject: below --
2012-09-16 16:00 Frank Schäfer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).