Re: [PATCH] [media] gspca_touptek: Add support for ToupTek UCMOS series USB cameras

2015-01-05 Thread Hans de Goede

Hi John,

On 01-12-14 03:27, John McMaster wrote:

Adds support for AmScope MU800 / ToupTek UCMOS08000KPB USB microscope camera.

Signed-off-by: John McMaster johndmcmas...@gmail.com


Thanks, I've added this driver to my gspca tree, and asked Mauro to
queue it up for 3.20.

Regards,

Hans


---
  drivers/media/usb/gspca/Kconfig   |   10 +
  drivers/media/usb/gspca/Makefile  |2 +
  drivers/media/usb/gspca/touptek.c |  729 +
  3 files changed, 741 insertions(+)
  create mode 100644 drivers/media/usb/gspca/touptek.c

diff --git a/drivers/media/usb/gspca/Kconfig b/drivers/media/usb/gspca/Kconfig
index eed10d7..60af3b1 100644
--- a/drivers/media/usb/gspca/Kconfig
+++ b/drivers/media/usb/gspca/Kconfig
@@ -395,6 +395,16 @@ config USB_GSPCA_TOPRO
  To compile this driver as a module, choose M here: the
  module will be called gspca_topro.

+config USB_GSPCA_TOUPTEK
+   tristate Touptek USB Camera Driver
+   depends on VIDEO_V4L2  USB_GSPCA
+   help
+ Say Y here if you want support for cameras based on the ToupTek UCMOS
+ / AmScope MU series camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called gspca_touptek.
+
  config USB_GSPCA_TV8532
tristate TV8532 USB Camera Driver
depends on VIDEO_V4L2  USB_GSPCA
diff --git a/drivers/media/usb/gspca/Makefile b/drivers/media/usb/gspca/Makefile
index f46975e..9f5ccec 100644
--- a/drivers/media/usb/gspca/Makefile
+++ b/drivers/media/usb/gspca/Makefile
@@ -39,6 +39,7 @@ obj-$(CONFIG_USB_GSPCA_STK1135)  += gspca_stk1135.o
  obj-$(CONFIG_USB_GSPCA_STV0680)  += gspca_stv0680.o
  obj-$(CONFIG_USB_GSPCA_T613) += gspca_t613.o
  obj-$(CONFIG_USB_GSPCA_TOPRO)+= gspca_topro.o
+obj-$(CONFIG_USB_GSPCA_TOUPTEK)  += gspca_touptek.o
  obj-$(CONFIG_USB_GSPCA_TV8532)   += gspca_tv8532.o
  obj-$(CONFIG_USB_GSPCA_VC032X)   += gspca_vc032x.o
  obj-$(CONFIG_USB_GSPCA_VICAM)+= gspca_vicam.o
@@ -86,6 +87,7 @@ gspca_stv0680-objs  := stv0680.o
  gspca_sunplus-objs  := sunplus.o
  gspca_t613-objs := t613.o
  gspca_topro-objs:= topro.o
+gspca_touptek-objs  := touptek.o
  gspca_tv8532-objs   := tv8532.o
  gspca_vc032x-objs   := vc032x.o
  gspca_vicam-objs:= vicam.o
diff --git a/drivers/media/usb/gspca/touptek.c 
b/drivers/media/usb/gspca/touptek.c
new file mode 100644
index 000..2fd876c
--- /dev/null
+++ b/drivers/media/usb/gspca/touptek.c
@@ -0,0 +1,729 @@
+/*
+ * ToupTek UCMOS / AmScope MU series camera driver
+ * TODO: contrast with ScopeTek / AmScope MDC cameras
+ *
+ * Copyright (C) 2012-2014 John McMaster johndmcmas...@gmail.com
+ *
+ * Special thanks to Bushing for helping with the decrypt algorithm and
+ * Sean O'Sullivan / the Rensselaer Center for Open Source
+ * Software (RCOS) for helping me learn kernel development
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include gspca.h
+
+#define MODULE_NAME touptek
+
+MODULE_AUTHOR(John McMaster);
+MODULE_DESCRIPTION(ToupTek UCMOS / Amscope MU microscope camera driver);
+MODULE_LICENSE(GPL);
+
+/*
+Exposure reg is linear with exposure time
+Exposure (sec), E (reg)
+0.000400, 0x0002
+0.001000, 0x0005
+0.005000, 0x0019
+0.02, 0x0064
+0.08, 0x0190
+0.40, 0x07D0
+1.00, 0x1388
+2.00, 0x2710
+
+Three gain stages
+0x1000: master channel enable bit
+0x007F: low gain bits
+0x0080: medium gain bit
+0x0100: high gain bit
+gain = enable * (1 + regH) * (1 + regM) * z * regL
+
+Gain implementation
+Want to do something similar to mt9v011.c's set_balance
+
+Gain does not vary with resolution (checked 640x480 vs 1600x1200)
+
+Constant derivation:
+
+Raw data:
+Gain,   GTOP,   B,   R,  GBOT
+1.00,   0x105C, 0x1068, 0x10C8, 0x105C
+1.20,   0x106E, 0x107E, 0x10D6, 0x106E
+1.40,   0x10C0, 0x10CA, 0x10E5, 0x10C0
+1.60,   0x10C9, 0x10D4, 0x10F3, 0x10C9
+1.80,   0x10D2, 0x10DE, 0x11C1, 0x10D2
+2.00,   0x10DC, 0x10E9, 0x11C8, 0x10DC
+2.20,   0x10E5, 0x10F3, 0x11CF, 0x10E5
+2.40,   0x10EE, 0x10FE, 0x11D7, 0x10EE
+2.60,   0x10F7, 0x11C4, 0x11DE, 0x10F7
+2.80,   0x11C0, 0x11CA, 0x11E5, 0x11C0
+3.00,   0x11C5, 0x11CF, 0x11ED, 0x11C5
+
+zR = 0.0069605943152454778
+   about 3/431 = 0.0069605568445475635
+zB = 0.0095695970695970703
+   about 6/627 = 0.0095693779904306216
+zG = 0.010889328063241107
+   

[PATCH] [media] gspca_touptek: Add support for ToupTek UCMOS series USB cameras

2014-11-30 Thread John McMaster
Adds support for AmScope MU800 / ToupTek UCMOS08000KPB USB microscope camera.

Signed-off-by: John McMaster johndmcmas...@gmail.com
---
 drivers/media/usb/gspca/Kconfig   |   10 +
 drivers/media/usb/gspca/Makefile  |2 +
 drivers/media/usb/gspca/touptek.c |  729 +
 3 files changed, 741 insertions(+)
 create mode 100644 drivers/media/usb/gspca/touptek.c

diff --git a/drivers/media/usb/gspca/Kconfig b/drivers/media/usb/gspca/Kconfig
index eed10d7..60af3b1 100644
--- a/drivers/media/usb/gspca/Kconfig
+++ b/drivers/media/usb/gspca/Kconfig
@@ -395,6 +395,16 @@ config USB_GSPCA_TOPRO
  To compile this driver as a module, choose M here: the
  module will be called gspca_topro.
 
+config USB_GSPCA_TOUPTEK
+   tristate Touptek USB Camera Driver
+   depends on VIDEO_V4L2  USB_GSPCA
+   help
+ Say Y here if you want support for cameras based on the ToupTek UCMOS
+ / AmScope MU series camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called gspca_touptek.
+
 config USB_GSPCA_TV8532
tristate TV8532 USB Camera Driver
depends on VIDEO_V4L2  USB_GSPCA
diff --git a/drivers/media/usb/gspca/Makefile b/drivers/media/usb/gspca/Makefile
index f46975e..9f5ccec 100644
--- a/drivers/media/usb/gspca/Makefile
+++ b/drivers/media/usb/gspca/Makefile
@@ -39,6 +39,7 @@ obj-$(CONFIG_USB_GSPCA_STK1135)  += gspca_stk1135.o
 obj-$(CONFIG_USB_GSPCA_STV0680)  += gspca_stv0680.o
 obj-$(CONFIG_USB_GSPCA_T613) += gspca_t613.o
 obj-$(CONFIG_USB_GSPCA_TOPRO)+= gspca_topro.o
+obj-$(CONFIG_USB_GSPCA_TOUPTEK)  += gspca_touptek.o
 obj-$(CONFIG_USB_GSPCA_TV8532)   += gspca_tv8532.o
 obj-$(CONFIG_USB_GSPCA_VC032X)   += gspca_vc032x.o
 obj-$(CONFIG_USB_GSPCA_VICAM)+= gspca_vicam.o
@@ -86,6 +87,7 @@ gspca_stv0680-objs  := stv0680.o
 gspca_sunplus-objs  := sunplus.o
 gspca_t613-objs := t613.o
 gspca_topro-objs:= topro.o
+gspca_touptek-objs  := touptek.o
 gspca_tv8532-objs   := tv8532.o
 gspca_vc032x-objs   := vc032x.o
 gspca_vicam-objs:= vicam.o
diff --git a/drivers/media/usb/gspca/touptek.c 
b/drivers/media/usb/gspca/touptek.c
new file mode 100644
index 000..2fd876c
--- /dev/null
+++ b/drivers/media/usb/gspca/touptek.c
@@ -0,0 +1,729 @@
+/*
+ * ToupTek UCMOS / AmScope MU series camera driver
+ * TODO: contrast with ScopeTek / AmScope MDC cameras
+ *
+ * Copyright (C) 2012-2014 John McMaster johndmcmas...@gmail.com
+ *
+ * Special thanks to Bushing for helping with the decrypt algorithm and
+ * Sean O'Sullivan / the Rensselaer Center for Open Source
+ * Software (RCOS) for helping me learn kernel development
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include gspca.h
+
+#define MODULE_NAME touptek
+
+MODULE_AUTHOR(John McMaster);
+MODULE_DESCRIPTION(ToupTek UCMOS / Amscope MU microscope camera driver);
+MODULE_LICENSE(GPL);
+
+/*
+Exposure reg is linear with exposure time
+Exposure (sec), E (reg)
+0.000400, 0x0002
+0.001000, 0x0005
+0.005000, 0x0019
+0.02, 0x0064
+0.08, 0x0190
+0.40, 0x07D0
+1.00, 0x1388
+2.00, 0x2710
+
+Three gain stages
+0x1000: master channel enable bit
+0x007F: low gain bits
+0x0080: medium gain bit
+0x0100: high gain bit
+gain = enable * (1 + regH) * (1 + regM) * z * regL
+
+Gain implementation
+Want to do something similar to mt9v011.c's set_balance
+
+Gain does not vary with resolution (checked 640x480 vs 1600x1200)
+
+Constant derivation:
+
+Raw data:
+Gain,   GTOP,   B,   R,  GBOT
+1.00,   0x105C, 0x1068, 0x10C8, 0x105C
+1.20,   0x106E, 0x107E, 0x10D6, 0x106E
+1.40,   0x10C0, 0x10CA, 0x10E5, 0x10C0
+1.60,   0x10C9, 0x10D4, 0x10F3, 0x10C9
+1.80,   0x10D2, 0x10DE, 0x11C1, 0x10D2
+2.00,   0x10DC, 0x10E9, 0x11C8, 0x10DC
+2.20,   0x10E5, 0x10F3, 0x11CF, 0x10E5
+2.40,   0x10EE, 0x10FE, 0x11D7, 0x10EE
+2.60,   0x10F7, 0x11C4, 0x11DE, 0x10F7
+2.80,   0x11C0, 0x11CA, 0x11E5, 0x11C0
+3.00,   0x11C5, 0x11CF, 0x11ED, 0x11C5
+
+zR = 0.0069605943152454778
+   about 3/431 = 0.0069605568445475635
+zB = 0.0095695970695970703
+   about 6/627 = 0.0095693779904306216
+zG = 0.010889328063241107
+   about 6/551 = 0.010889292196007259
+about 10 bits for constant + 7 bits for value = at least 17 bit intermediate
+with 32 bit ints should be fine for overflow etc
+Essentially 

Re: [PATCH] [media] gspca_touptek: Add support for ToupTek UCMOS series USB cameras

2014-11-30 Thread John McMaster
On 10/23/2014 06:09 AM, Hans de Goede wrote:
 Hi,

 On 10/05/2014 08:43 AM, John McMaster wrote:
 Adds support for AmScope MU800 / ToupTek UCMOS08000KPB USB microscope camera.
 First of all many thanks for writing this driver, and also for submitting it
 upstream. We always appreciate it a lot when people put in the effort to
 write a driver to support new webcams, and it is also greatly appreciated
 when people go the extra mile to make the driver clean enough to submit it
 upstream!

 Overall the driver looks fine, you've clearly spend a lot of time on this!

 3 small remarks though:

 1) Please replace all the pr_foo calls with calls to the gspca specific
 PERR (v4l2_err wrapper) and PDEBUG (v4l2_dbg) macros. using PDEBUG will
 allow you to specify one of the D_foo values as debug level and then at
 runtime select which messages to log. The following levels are available:

 #define D_PROBE  1

 Use this for probing info, e.g. print which type of sensors / extra
 features you've detected.

 #define D_CONF   2

 This is used to log configuration info, e.g. for format negotation,
 typically this is used by the gspca core and not by your driver

 #define D_STREAM 3

 Use this to log debug messages at stream start / stop

 #define D_FRAM   4

 Use this to log debug messages occuring once each frame

 #define D_PACK   5

 Use this to log debug messages occuring once each video packet

 #define D_USBI   6

 Use this to log ctrl register reads

 #define D_USBO   7

 Use this to log ctrl register writes

 When you use this, you can use the gspca_main.debug module parameter
 to select a log level between 0 - 7.

Done
 2) As for the XXX: seems done automaticly, should rmeove bit, yes
 controls are set automatically at the start of streaming, so please
 remove this (and double check things still work with it removed).

Done, seems to still work
 3) In some places you do:

   rc = reg_w(gspca_dev, 0x, REG_SCALING_MODE);
   if (rc)
   return rc;
   rc = reg_w(gspca_dev, 0x0010, REG_SCALE_M);
   if (rc)
   return rc;
   rc = reg_w(gspca_dev, w, REG_X_OUTPUT_SIZE);
   if (rc)
   return rc;
   rc = reg_w(gspca_dev, gspca_dev-pixfmt.height, REG_Y_OUTPUT_SIZE);
   if (rc)
   return rc;

 The way we typically handle this in gspca is through gspca_dev-usb_err
 which you use in sd_s_ctrl but never set, here is an example of another reg_w
 function indicating how this is typically used:

 static void pac207_write_reg(struct gspca_dev *gspca_dev, u16 index, u16 
 value)
 {
 struct usb_device *udev = gspca_dev-dev;
 int err;

 if (gspca_dev-usb_err  0)
 return;

 err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00,
 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
 value, index, NULL, 0, PAC207_CTRL_TIMEOUT);
 if (err) {
 pr_err(Failed to write a register (index 0x%04X, value 
 0x%02X,
index, value, err);
 gspca_dev-usb_err = err;
 }
 }

 And the above code would be changed into:

   gspca_dev-usb_err = 0;

   reg_w(gspca_dev, 0x, REG_SCALING_MODE);
   reg_w(gspca_dev, 0x0010, REG_SCALE_M);
   reg_w(gspca_dev, w, REG_X_OUTPUT_SIZE);
   reg_w(gspca_dev, gspca_dev-pixfmt.height, REG_Y_OUTPUT_SIZE);

   return gspca_dev-usb_err;

 The idea being that we can simply chain as many reg_w calls as we need,
 and the first one failing turns all the next ones into nops, and at the
 end we simply return gspca_dev-usb_err which on success is still 0.

 If you make this change then the return of gspca_dev-usb_err at the end
 of sd_s_ctrl also actually starts making sense :)
Changed.  This does change the error handing though: you continue to
send commands in some cases even if a previous one failed.  I guess it
shouldn't really matter though.

 If you can fix these 3 issues then I'll happily merge this driver for
 3.19.

 Regards,

 Hans
Busy with work, took a while longer to get back to this than I hoped. 
Posted new version, let me know if this looks better.  No worries if it
doesn't make 3.19.

I found that depending on the microscope filters I use I cannot get the
full color range.  At some point in the future I'd like to tweak the
gain model.

John

 Signed-off-by: John McMaster johndmcmas...@gmail.com
 ---
  drivers/media/usb/gspca/Kconfig   |   10 +
  drivers/media/usb/gspca/Makefile  |2 +
  drivers/media/usb/gspca/touptek.c |  859 
 +
  3 files changed, 871 insertions(+)
  create mode 100644 drivers/media/usb/gspca/touptek.c

 diff --git a/drivers/media/usb/gspca/Kconfig 
 b/drivers/media/usb/gspca/Kconfig
 index eed10d7..60af3b1 100644
 --- a/drivers/media/usb/gspca/Kconfig
 +++ b/drivers/media/usb/gspca/Kconfig
 @@ -395,6 +395,16 @@ config USB_GSPCA_TOPRO
To compile this driver as a module, choose 

Re: [PATCH] [media] gspca_touptek: Add support for ToupTek UCMOS series USB cameras

2014-10-23 Thread Hans de Goede
Hi,

On 10/05/2014 08:43 AM, John McMaster wrote:
 Adds support for AmScope MU800 / ToupTek UCMOS08000KPB USB microscope camera.

First of all many thanks for writing this driver, and also for submitting it
upstream. We always appreciate it a lot when people put in the effort to
write a driver to support new webcams, and it is also greatly appreciated
when people go the extra mile to make the driver clean enough to submit it
upstream!

Overall the driver looks fine, you've clearly spend a lot of time on this!

3 small remarks though:

1) Please replace all the pr_foo calls with calls to the gspca specific
PERR (v4l2_err wrapper) and PDEBUG (v4l2_dbg) macros. using PDEBUG will
allow you to specify one of the D_foo values as debug level and then at
runtime select which messages to log. The following levels are available:

#define D_PROBE  1

Use this for probing info, e.g. print which type of sensors / extra
features you've detected.

#define D_CONF   2

This is used to log configuration info, e.g. for format negotation,
typically this is used by the gspca core and not by your driver

#define D_STREAM 3

Use this to log debug messages at stream start / stop

#define D_FRAM   4

Use this to log debug messages occuring once each frame

#define D_PACK   5

Use this to log debug messages occuring once each video packet

#define D_USBI   6

Use this to log ctrl register reads

#define D_USBO   7

Use this to log ctrl register writes

When you use this, you can use the gspca_main.debug module parameter
to select a log level between 0 - 7.


2) As for the XXX: seems done automaticly, should rmeove bit, yes
controls are set automatically at the start of streaming, so please
remove this (and double check things still work with it removed).


3) In some places you do:

rc = reg_w(gspca_dev, 0x, REG_SCALING_MODE);
if (rc)
return rc;
rc = reg_w(gspca_dev, 0x0010, REG_SCALE_M);
if (rc)
return rc;
rc = reg_w(gspca_dev, w, REG_X_OUTPUT_SIZE);
if (rc)
return rc;
rc = reg_w(gspca_dev, gspca_dev-pixfmt.height, REG_Y_OUTPUT_SIZE);
if (rc)
return rc;

The way we typically handle this in gspca is through gspca_dev-usb_err
which you use in sd_s_ctrl but never set, here is an example of another reg_w
function indicating how this is typically used:

static void pac207_write_reg(struct gspca_dev *gspca_dev, u16 index, u16 value)
{
struct usb_device *udev = gspca_dev-dev;
int err;

if (gspca_dev-usb_err  0)
return;

err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00,
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
value, index, NULL, 0, PAC207_CTRL_TIMEOUT);
if (err) {
pr_err(Failed to write a register (index 0x%04X, value 0x%02X,
   index, value, err);
gspca_dev-usb_err = err;
}
}

And the above code would be changed into:

gspca_dev-usb_err = 0;

reg_w(gspca_dev, 0x, REG_SCALING_MODE);
reg_w(gspca_dev, 0x0010, REG_SCALE_M);
reg_w(gspca_dev, w, REG_X_OUTPUT_SIZE);
reg_w(gspca_dev, gspca_dev-pixfmt.height, REG_Y_OUTPUT_SIZE);

return gspca_dev-usb_err;

The idea being that we can simply chain as many reg_w calls as we need,
and the first one failing turns all the next ones into nops, and at the
end we simply return gspca_dev-usb_err which on success is still 0.

If you make this change then the return of gspca_dev-usb_err at the end
of sd_s_ctrl also actually starts making sense :)

If you can fix these 3 issues then I'll happily merge this driver for
3.19.

Regards,

Hans


 
 Signed-off-by: John McMaster johndmcmas...@gmail.com
 ---
  drivers/media/usb/gspca/Kconfig   |   10 +
  drivers/media/usb/gspca/Makefile  |2 +
  drivers/media/usb/gspca/touptek.c |  859 
 +
  3 files changed, 871 insertions(+)
  create mode 100644 drivers/media/usb/gspca/touptek.c
 
 diff --git a/drivers/media/usb/gspca/Kconfig b/drivers/media/usb/gspca/Kconfig
 index eed10d7..60af3b1 100644
 --- a/drivers/media/usb/gspca/Kconfig
 +++ b/drivers/media/usb/gspca/Kconfig
 @@ -395,6 +395,16 @@ config USB_GSPCA_TOPRO
 To compile this driver as a module, choose M here: the
 module will be called gspca_topro.
  
 +config USB_GSPCA_TOUPTEK
 + tristate Touptek USB Camera Driver
 + depends on VIDEO_V4L2  USB_GSPCA
 + help
 +   Say Y here if you want support for cameras based on the ToupTek UCMOS
 +   / AmScope MU series camera.
 +
 +   To compile this driver as a module, choose M here: the
 +   module will be called gspca_touptek.
 +
  config USB_GSPCA_TV8532
   tristate TV8532 USB Camera Driver
   depends on VIDEO_V4L2  USB_GSPCA
 diff --git a/drivers/media/usb/gspca/Makefile 
 b/drivers/media/usb/gspca/Makefile
 index 

[PATCH] [media] gspca_touptek: Add support for ToupTek UCMOS series USB cameras

2014-10-05 Thread John McMaster
Adds support for AmScope MU800 / ToupTek UCMOS08000KPB USB microscope camera.

Signed-off-by: John McMaster johndmcmas...@gmail.com
---
 drivers/media/usb/gspca/Kconfig   |   10 +
 drivers/media/usb/gspca/Makefile  |2 +
 drivers/media/usb/gspca/touptek.c |  859 +
 3 files changed, 871 insertions(+)
 create mode 100644 drivers/media/usb/gspca/touptek.c

diff --git a/drivers/media/usb/gspca/Kconfig b/drivers/media/usb/gspca/Kconfig
index eed10d7..60af3b1 100644
--- a/drivers/media/usb/gspca/Kconfig
+++ b/drivers/media/usb/gspca/Kconfig
@@ -395,6 +395,16 @@ config USB_GSPCA_TOPRO
  To compile this driver as a module, choose M here: the
  module will be called gspca_topro.
 
+config USB_GSPCA_TOUPTEK
+   tristate Touptek USB Camera Driver
+   depends on VIDEO_V4L2  USB_GSPCA
+   help
+ Say Y here if you want support for cameras based on the ToupTek UCMOS
+ / AmScope MU series camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called gspca_touptek.
+
 config USB_GSPCA_TV8532
tristate TV8532 USB Camera Driver
depends on VIDEO_V4L2  USB_GSPCA
diff --git a/drivers/media/usb/gspca/Makefile b/drivers/media/usb/gspca/Makefile
index f46975e..9f5ccec 100644
--- a/drivers/media/usb/gspca/Makefile
+++ b/drivers/media/usb/gspca/Makefile
@@ -39,6 +39,7 @@ obj-$(CONFIG_USB_GSPCA_STK1135)  += gspca_stk1135.o
 obj-$(CONFIG_USB_GSPCA_STV0680)  += gspca_stv0680.o
 obj-$(CONFIG_USB_GSPCA_T613) += gspca_t613.o
 obj-$(CONFIG_USB_GSPCA_TOPRO)+= gspca_topro.o
+obj-$(CONFIG_USB_GSPCA_TOUPTEK)  += gspca_touptek.o
 obj-$(CONFIG_USB_GSPCA_TV8532)   += gspca_tv8532.o
 obj-$(CONFIG_USB_GSPCA_VC032X)   += gspca_vc032x.o
 obj-$(CONFIG_USB_GSPCA_VICAM)+= gspca_vicam.o
@@ -86,6 +87,7 @@ gspca_stv0680-objs  := stv0680.o
 gspca_sunplus-objs  := sunplus.o
 gspca_t613-objs := t613.o
 gspca_topro-objs:= topro.o
+gspca_touptek-objs  := touptek.o
 gspca_tv8532-objs   := tv8532.o
 gspca_vc032x-objs   := vc032x.o
 gspca_vicam-objs:= vicam.o
diff --git a/drivers/media/usb/gspca/touptek.c 
b/drivers/media/usb/gspca/touptek.c
new file mode 100644
index 000..a379f5f
--- /dev/null
+++ b/drivers/media/usb/gspca/touptek.c
@@ -0,0 +1,859 @@
+/*
+ * ToupTek UCMOS / AmScope MU series camera driver
+ * TODO: contrast with ScopeTek / AmScope MDC cameras
+ *
+ * Copyright (C) 2012-2014 John McMaster johndmcmas...@gmail.com
+ *
+ * Special thanks to Bushing for helping with the decrypt algorithm and
+ * Sean O'Sullivan / the Rensselaer Center for Open Source
+ * Software (RCOS) for helping me learn kernel development
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include gspca.h
+
+#define MODULE_NAME touptek
+
+MODULE_AUTHOR(John McMaster);
+MODULE_DESCRIPTION(ToupTek UCMOS / Amscope MU microscope camera driver);
+MODULE_LICENSE(GPL);
+
+/*
+Exposure reg is linear with exposure time
+Exposure (sec), E (reg)
+0.000400, 0x0002
+0.001000, 0x0005
+0.005000, 0x0019
+0.02, 0x0064
+0.08, 0x0190
+0.40, 0x07D0
+1.00, 0x1388
+2.00, 0x2710
+*/
+
+/*
+Three gain stages
+0x1000: master channel enable bit
+0x007F: low gain bits
+0x0080: medium gain bit
+0x0100: high gain bit
+gain = enable * (1 + regH) * (1 + regM) * z * regL
+
+Gain implementation
+Goal: simple conversion for default gain at 1.00
+Want to do something similar to mt9v011.c's set_balance
+Problem: can lead to gains higher than possible
+When this happens the gain is clipped and a debug warning is emitted
+
+green_gain = sd-global_gain
+blue_gain = sd-global_gain +
+   ((uint32_t)sd-global_gain) * sd-blue_bal / GAIN_MAX;
+red_gain = sd-global_gain +
+   ((uint32_t)sd-global_gain) * sd-blue_bal / GAIN_MAX;
+
+Want initial gain of 1.4 (since it works well for me ;) ):
+-G: 128 = global_gain = 128
+-B: 148 = blue_bal = 80
+148 = 128 + 128 * blue_bal / 511
+-R: 202 = red_bal = 295
+202 = 128 + 128 * red_bal / 511
+
+Gain does not vary with resolution (checked 640x480 vs 1600x1200)
+
+
+Constant derivation:
+
+Raw data:
+Gain,   GTOP,   B,   R,  GBOT
+1.00,   0x105C, 0x1068, 0x10C8, 0x105C
+1.20,   0x106E, 0x107E, 0x10D6, 0x106E
+1.40,   0x10C0, 0x10CA, 0x10E5, 0x10C0
+1.60,   0x10C9, 0x10D4, 0x10F3, 0x10C9
+1.80,   0x10D2, 0x10DE, 0x11C1, 

[PATCH] [media] gspca_touptek: Add support for ToupTek UCMOS series USB cameras

2014-09-28 Thread John McMaster
Adds support for AmScope MU800 / ToupTek UCMOS08000KPB USB microscope camera.

Signed-off-by: John McMaster johndmcmas...@gmail.com
---
 drivers/media/usb/gspca/Kconfig   |   10 +
 drivers/media/usb/gspca/Makefile  |2 +
 drivers/media/usb/gspca/touptek.c |  829 +
 3 files changed, 841 insertions(+)
 create mode 100644 drivers/media/usb/gspca/touptek.c

diff --git a/drivers/media/usb/gspca/Kconfig b/drivers/media/usb/gspca/Kconfig
index eed10d7..60af3b1 100644
--- a/drivers/media/usb/gspca/Kconfig
+++ b/drivers/media/usb/gspca/Kconfig
@@ -395,6 +395,16 @@ config USB_GSPCA_TOPRO
  To compile this driver as a module, choose M here: the
  module will be called gspca_topro.
 
+config USB_GSPCA_TOUPTEK
+   tristate Touptek USB Camera Driver
+   depends on VIDEO_V4L2  USB_GSPCA
+   help
+ Say Y here if you want support for cameras based on the ToupTek UCMOS
+ / AmScope MU series camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called gspca_touptek.
+
 config USB_GSPCA_TV8532
tristate TV8532 USB Camera Driver
depends on VIDEO_V4L2  USB_GSPCA
diff --git a/drivers/media/usb/gspca/Makefile b/drivers/media/usb/gspca/Makefile
index f46975e..9f5ccec 100644
--- a/drivers/media/usb/gspca/Makefile
+++ b/drivers/media/usb/gspca/Makefile
@@ -39,6 +39,7 @@ obj-$(CONFIG_USB_GSPCA_STK1135)  += gspca_stk1135.o
 obj-$(CONFIG_USB_GSPCA_STV0680)  += gspca_stv0680.o
 obj-$(CONFIG_USB_GSPCA_T613) += gspca_t613.o
 obj-$(CONFIG_USB_GSPCA_TOPRO)+= gspca_topro.o
+obj-$(CONFIG_USB_GSPCA_TOUPTEK)  += gspca_touptek.o
 obj-$(CONFIG_USB_GSPCA_TV8532)   += gspca_tv8532.o
 obj-$(CONFIG_USB_GSPCA_VC032X)   += gspca_vc032x.o
 obj-$(CONFIG_USB_GSPCA_VICAM)+= gspca_vicam.o
@@ -86,6 +87,7 @@ gspca_stv0680-objs  := stv0680.o
 gspca_sunplus-objs  := sunplus.o
 gspca_t613-objs := t613.o
 gspca_topro-objs:= topro.o
+gspca_touptek-objs  := touptek.o
 gspca_tv8532-objs   := tv8532.o
 gspca_vc032x-objs   := vc032x.o
 gspca_vicam-objs:= vicam.o
diff --git a/drivers/media/usb/gspca/touptek.c 
b/drivers/media/usb/gspca/touptek.c
new file mode 100644
index 000..91458d5
--- /dev/null
+++ b/drivers/media/usb/gspca/touptek.c
@@ -0,0 +1,829 @@
+/*
+ * ToupTek UCMOS / AmScope MU series camera driver
+ * TODO: contrast with ScopeTek / AmScope MDC cameras
+ *
+ * Copyright (C) 2012-2014 John McMaster johndmcmas...@gmail.com
+ *
+ * Special thanks to Bushing for helping with the decrypt algorithm and
+ * Sean O'Sullivan / the Rensselaer Center for Open Source
+ * Software (RCOS) for helping me learn kernel development
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include gspca.h
+
+#define MODULE_NAME touptek
+
+MODULE_AUTHOR(John McMaster);
+MODULE_DESCRIPTION(ToupTek UCMOS / Amscope MU microscope camera driver);
+MODULE_LICENSE(GPL);
+
+/*
+Exposure reg is linear with exposure time
+Exposure (sec), E (reg)
+0.000400, 0x0002
+0.001000, 0x0005
+0.005000, 0x0019
+0.02, 0x0064
+0.08, 0x0190
+0.40, 0x07D0
+1.00, 0x1388
+2.00, 0x2710
+*/
+
+/*
+Three gain stages
+0x1000: master channel enable bit
+0x007F: low gain bits
+0x0080: medium gain bit
+0x0100: high gain bit
+gain = enable * (1 + regH) * (1 + regM) * z * regL
+
+Gain implementation
+Goal: simple conversion for default gain at 1.00
+Want to do something similar to mt9v011.c's set_balance
+Problem: can lead to gains higher than possible
+When this happens the gain is clipped and a debug warning is emitted
+
+green_gain = sd-global_gain
+blue_gain = sd-global_gain +
+   ((uint32_t)sd-global_gain) * sd-blue_bal / GAIN_MAX;
+red_gain = sd-global_gain +
+   ((uint32_t)sd-global_gain) * sd-blue_bal / GAIN_MAX;
+
+Want initial gain of 1.4 (since it works well for me ;) ):
+-G: 128 = global_gain = 128
+-B: 148 = blue_bal = 80
+148 = 128 + 128 * blue_bal / 511
+-R: 202 = red_bal = 295
+202 = 128 + 128 * red_bal / 511
+
+Gain does not vary with resolution (checked 640x480 vs 1600x1200)
+
+
+Constant derivation:
+
+Raw data:
+Gain,   GTOP,   B,   R,  GBOT
+1.00,   0x105C, 0x1068, 0x10C8, 0x105C
+1.20,   0x106E, 0x107E, 0x10D6, 0x106E
+1.40,   0x10C0, 0x10CA, 0x10E5, 0x10C0
+1.60,   0x10C9, 0x10D4, 0x10F3, 0x10C9
+1.80,   0x10D2, 0x10DE, 0x11C1, 

Re: [PATCH] [media] gspca_touptek: Add support for ToupTek UCMOS series USB cameras

2013-04-01 Thread Hans de Goede

Hi John,

Thanks for the new driver! Unfortunately the driver is still
using gspca's own/deprecated control mechanism rather then
the new v4l2-control framework which all drivers now a days
use.

And we've just finished converting all the gspca sub-drivers
to using this new control framework, and removing gspca's
own custom control code.

Can you please convert the driver to use the new control code
(see other gspca drivers for examples how to do that, ie:
http://git.linuxtv.org/hgoede/gspca.git/commitdiff/4e02a3cd647940be6a9b4b71dfa88dbcb6fe1af9
http://git.linuxtv.org/hgoede/gspca.git/commitdiff/77f509f09754f46bcad35e13f1e6c95c1b8defdc
http://git.linuxtv.org/hgoede/gspca.git/commitdiff/c535784016480ef17778c285915492b581fa6a5f

And then resubmit the converted driver?

Thanks  Regards,

Hans


On 04/01/2013 02:53 AM, John McMaster wrote:

Adds support for AmScope MU800 / ToupTek UCMOS08000KPB USB microscope camera.

Signed-off-by: John McMaster johndmcmas...@gmail.com
---
  drivers/media/usb/gspca/Kconfig   |   10 +
  drivers/media/usb/gspca/Makefile  |2 +
  drivers/media/usb/gspca/touptek.c |  857 +
  3 files changed, 869 insertions(+)
  create mode 100644 drivers/media/usb/gspca/touptek.c

diff --git a/drivers/media/usb/gspca/Kconfig b/drivers/media/usb/gspca/Kconfig
index 6345f93..113f181 100644
--- a/drivers/media/usb/gspca/Kconfig
+++ b/drivers/media/usb/gspca/Kconfig
@@ -376,6 +376,16 @@ config USB_GSPCA_TOPRO
  To compile this driver as a module, choose M here: the
  module will be called gspca_topro.

+config USB_GSPCA_TOUPTEK
+   tristate Touptek USB Camera Driver
+   depends on VIDEO_V4L2  USB_GSPCA
+   help
+ Say Y here if you want support for cameras based on the ToupTek UCMOS
+ / AmScope MU series camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called gspca_touptek.
+
  config USB_GSPCA_TV8532
tristate TV8532 USB Camera Driver
depends on VIDEO_V4L2  USB_GSPCA
diff --git a/drivers/media/usb/gspca/Makefile b/drivers/media/usb/gspca/Makefile
index c901da0..5f18e7f 100644
--- a/drivers/media/usb/gspca/Makefile
+++ b/drivers/media/usb/gspca/Makefile
@@ -37,6 +37,7 @@ obj-$(CONFIG_USB_GSPCA_STK014)   += gspca_stk014.o
  obj-$(CONFIG_USB_GSPCA_STV0680)  += gspca_stv0680.o
  obj-$(CONFIG_USB_GSPCA_T613) += gspca_t613.o
  obj-$(CONFIG_USB_GSPCA_TOPRO)+= gspca_topro.o
+obj-$(CONFIG_USB_GSPCA_TOUPTEK)  += gspca_touptek.o
  obj-$(CONFIG_USB_GSPCA_TV8532)   += gspca_tv8532.o
  obj-$(CONFIG_USB_GSPCA_VC032X)   += gspca_vc032x.o
  obj-$(CONFIG_USB_GSPCA_VICAM)+= gspca_vicam.o
@@ -82,6 +83,7 @@ gspca_stv0680-objs  := stv0680.o
  gspca_sunplus-objs  := sunplus.o
  gspca_t613-objs := t613.o
  gspca_topro-objs:= topro.o
+gspca_touptek-objs  := touptek.o
  gspca_tv8532-objs   := tv8532.o
  gspca_vc032x-objs   := vc032x.o
  gspca_vicam-objs:= vicam.o
diff --git a/drivers/media/usb/gspca/touptek.c 
b/drivers/media/usb/gspca/touptek.c
new file mode 100644
index 000..9ce31f0
--- /dev/null
+++ b/drivers/media/usb/gspca/touptek.c
@@ -0,0 +1,857 @@
+/*
+ * ToupTek UCMOS / AmScope MU series camera driver
+ * TODO: contrast with ScopeTek / AmScope MDC cameras
+ *
+ * Copyright (C) 2012 John McMaster johndmcmas...@gmail.com
+ *
+ * Special thanks to Bushing for helping with the decrypt algorithm and
+ * Sean O'Sullivan / the Rensselaer Center for Open Source
+ * Software (RCOS) for helping me learn kernel development
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include gspca.h
+
+#define MODULE_NAME touptek
+
+MODULE_AUTHOR(John McMaster);
+MODULE_DESCRIPTION(ToupTek UCMOS / Amscope MU microscope camera driver);
+MODULE_LICENSE(GPL);
+
+/*
+Register value is linear with exposure time
+Exposure (sec), E (reg)
+0.000400, 0x0002
+0.001000, 0x0005
+0.005000, 0x0019
+0.02, 0x0064
+0.08, 0x0190
+0.40, 0x07D0
+1.00, 0x1388
+2.00, 0x2710
+*/
+#define INDEX_EXPOSURE 0x3012
+#define INDEX_WIDTH0x034C
+#define INDEX_HEIGHT   0x034E
+
+/*
+Gain does not vary with resolution (checked 640x480 vs 1600x1200)
+Range 0x1000 (nothing) to 0x11FF (highest)
+However, there appear to be gaps
+
+Suspect three gain stages
+0x1000: master channel enable bit

[PATCH] [media] gspca_touptek: Add support for ToupTek UCMOS series USB cameras

2013-03-31 Thread John McMaster
Adds support for AmScope MU800 / ToupTek UCMOS08000KPB USB microscope camera.

Signed-off-by: John McMaster johndmcmas...@gmail.com
---
 drivers/media/usb/gspca/Kconfig   |   10 +
 drivers/media/usb/gspca/Makefile  |2 +
 drivers/media/usb/gspca/touptek.c |  857 +
 3 files changed, 869 insertions(+)
 create mode 100644 drivers/media/usb/gspca/touptek.c

diff --git a/drivers/media/usb/gspca/Kconfig b/drivers/media/usb/gspca/Kconfig
index 6345f93..113f181 100644
--- a/drivers/media/usb/gspca/Kconfig
+++ b/drivers/media/usb/gspca/Kconfig
@@ -376,6 +376,16 @@ config USB_GSPCA_TOPRO
  To compile this driver as a module, choose M here: the
  module will be called gspca_topro.
 
+config USB_GSPCA_TOUPTEK
+   tristate Touptek USB Camera Driver
+   depends on VIDEO_V4L2  USB_GSPCA
+   help
+ Say Y here if you want support for cameras based on the ToupTek UCMOS
+ / AmScope MU series camera.
+
+ To compile this driver as a module, choose M here: the
+ module will be called gspca_touptek.
+
 config USB_GSPCA_TV8532
tristate TV8532 USB Camera Driver
depends on VIDEO_V4L2  USB_GSPCA
diff --git a/drivers/media/usb/gspca/Makefile b/drivers/media/usb/gspca/Makefile
index c901da0..5f18e7f 100644
--- a/drivers/media/usb/gspca/Makefile
+++ b/drivers/media/usb/gspca/Makefile
@@ -37,6 +37,7 @@ obj-$(CONFIG_USB_GSPCA_STK014)   += gspca_stk014.o
 obj-$(CONFIG_USB_GSPCA_STV0680)  += gspca_stv0680.o
 obj-$(CONFIG_USB_GSPCA_T613) += gspca_t613.o
 obj-$(CONFIG_USB_GSPCA_TOPRO)+= gspca_topro.o
+obj-$(CONFIG_USB_GSPCA_TOUPTEK)  += gspca_touptek.o
 obj-$(CONFIG_USB_GSPCA_TV8532)   += gspca_tv8532.o
 obj-$(CONFIG_USB_GSPCA_VC032X)   += gspca_vc032x.o
 obj-$(CONFIG_USB_GSPCA_VICAM)+= gspca_vicam.o
@@ -82,6 +83,7 @@ gspca_stv0680-objs  := stv0680.o
 gspca_sunplus-objs  := sunplus.o
 gspca_t613-objs := t613.o
 gspca_topro-objs:= topro.o
+gspca_touptek-objs  := touptek.o
 gspca_tv8532-objs   := tv8532.o
 gspca_vc032x-objs   := vc032x.o
 gspca_vicam-objs:= vicam.o
diff --git a/drivers/media/usb/gspca/touptek.c 
b/drivers/media/usb/gspca/touptek.c
new file mode 100644
index 000..9ce31f0
--- /dev/null
+++ b/drivers/media/usb/gspca/touptek.c
@@ -0,0 +1,857 @@
+/*
+ * ToupTek UCMOS / AmScope MU series camera driver
+ * TODO: contrast with ScopeTek / AmScope MDC cameras
+ *
+ * Copyright (C) 2012 John McMaster johndmcmas...@gmail.com
+ *
+ * Special thanks to Bushing for helping with the decrypt algorithm and
+ * Sean O'Sullivan / the Rensselaer Center for Open Source
+ * Software (RCOS) for helping me learn kernel development
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include gspca.h
+
+#define MODULE_NAME touptek
+
+MODULE_AUTHOR(John McMaster);
+MODULE_DESCRIPTION(ToupTek UCMOS / Amscope MU microscope camera driver);
+MODULE_LICENSE(GPL);
+
+/*
+Register value is linear with exposure time
+Exposure (sec), E (reg)
+0.000400, 0x0002
+0.001000, 0x0005
+0.005000, 0x0019
+0.02, 0x0064
+0.08, 0x0190
+0.40, 0x07D0
+1.00, 0x1388
+2.00, 0x2710
+*/
+#define INDEX_EXPOSURE 0x3012
+#define INDEX_WIDTH0x034C
+#define INDEX_HEIGHT   0x034E
+
+/*
+Gain does not vary with resolution (checked 640x480 vs 1600x1200)
+Range 0x1000 (nothing) to 0x11FF (highest)
+However, there appear to be gaps
+
+Suspect three gain stages
+0x1000: master channel enable bit
+0x007F: low gain bits
+0x0080: medium gain bit
+0x0100: high gain bit
+
+gain = enable * (1 + regH) * (1 + regM) * z * regL
+
+zR = 0.0069605943152454778
+   about 3/431 = 0.0069605568445475635
+zB = 0.0095695970695970703
+   about 6/627 = 0.0095693779904306216
+zG = 0.010889328063241107
+   about 6/551 = 0.010889292196007259
+about 10 bits for constant + 7 bits for value = at least 17 bit intermediate
+with 32 bit ints should be fine for overflow etc
+Essentially gains are in range 0-0x001FF
+
+However, V4L expects a main gain channel + R and B balance
+To keep things simple for now saturate the values of balance is too high/low
+This isn't really ideal but easy way to fit the Linux model
+
+Raw data:
+Gain,   GTOP,   B,   R,  GBOT
+1.00,   0x105C, 0x1068, 0x10C8, 0x105C
+1.20,   0x106E, 0x107E, 0x10D6, 0x106E
+1.40,   0x10C0, 0x10CA,