From c2f644aeeba3a5178767e757e93151959f037db1 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Sun, 13 Mar 2011 12:26:14 -0300 Subject: [PATCH] [media] gspca_cpia1: Add support for button Not only the qx3 microscope has a button, but some cameras too. Tested with the Trust sp@cecam 100 (and with a creative and ezcam without button). Signed-off-by: Hans de Goede Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/gspca/cpia1.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/drivers/media/video/gspca/cpia1.c b/drivers/media/video/gspca/cpia1.c index 2a4a428f2018..9ddbac680663 100644 --- a/drivers/media/video/gspca/cpia1.c +++ b/drivers/media/video/gspca/cpia1.c @@ -28,6 +28,7 @@ #define MODULE_NAME "cpia1" +#include #include "gspca.h" MODULE_AUTHOR("Hans de Goede "); @@ -653,10 +654,15 @@ static int do_command(struct gspca_dev *gspca_dev, u16 command, break; case CPIA_COMMAND_ReadMCPorts: - if (!sd->params.qx3.qx3_detected) - break; /* test button press */ - sd->params.qx3.button = ((gspca_dev->usb_buf[1] & 0x02) == 0); + a = ((gspca_dev->usb_buf[1] & 0x02) == 0); + if (a != sd->params.qx3.button) { +#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) + input_report_key(gspca_dev->input_dev, KEY_CAMERA, a); + input_sync(gspca_dev->input_dev); +#endif + sd->params.qx3.button = a; + } if (sd->params.qx3.button) { /* button pressed - unlock the latch */ do_command(gspca_dev, CPIA_COMMAND_WriteMCPort, @@ -1738,6 +1744,8 @@ static int sd_start(struct gspca_dev *gspca_dev) static void sd_stopN(struct gspca_dev *gspca_dev) { + struct sd *sd = (struct sd *) gspca_dev; + command_pause(gspca_dev); /* save camera state for later open (developers guide ch 3.5.3) */ @@ -1748,6 +1756,17 @@ static void sd_stopN(struct gspca_dev *gspca_dev) /* Update the camera status */ do_command(gspca_dev, CPIA_COMMAND_GetCameraStatus, 0, 0, 0, 0); + +#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) + /* If the last button state is pressed, release it now! */ + if (sd->params.qx3.button) { + /* The camera latch will hold the pressed state until we reset + the latch, so we do not reset sd->params.qx3.button now, to + avoid a false keypress being reported the next sd_start */ + input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); + input_sync(gspca_dev->input_dev); + } +#endif } /* this function is called at probe and resume time */ @@ -1852,8 +1871,7 @@ static void sd_dq_callback(struct gspca_dev *gspca_dev) /* Update our knowledge of the camera state */ do_command(gspca_dev, CPIA_COMMAND_GetExposure, 0, 0, 0, 0); - if (sd->params.qx3.qx3_detected) - do_command(gspca_dev, CPIA_COMMAND_ReadMCPorts, 0, 0, 0, 0); + do_command(gspca_dev, CPIA_COMMAND_ReadMCPorts, 0, 0, 0, 0); } static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) @@ -2085,6 +2103,9 @@ static const struct sd_desc sd_desc = { .dq_callback = sd_dq_callback, .pkt_scan = sd_pkt_scan, .querymenu = sd_querymenu, +#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) + .other_input = 1, +#endif }; /* -- module initialisation -- */ -- 2.20.1