diff options
| author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
|---|---|---|
| committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
| commit | fcc9d2e5a6c89d22b8b773a64fb4ad21ac318446 (patch) | |
| tree | a57612d1888735a2ec7972891b68c1ac5ec8faea /drivers/media/video/gspca/mars.c | |
| parent | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (diff) | |
Diffstat (limited to 'drivers/media/video/gspca/mars.c')
| -rw-r--r-- | drivers/media/video/gspca/mars.c | 529 |
1 files changed, 529 insertions, 0 deletions
diff --git a/drivers/media/video/gspca/mars.c b/drivers/media/video/gspca/mars.c new file mode 100644 index 00000000000..0196209a948 --- /dev/null +++ b/drivers/media/video/gspca/mars.c | |||
| @@ -0,0 +1,529 @@ | |||
| 1 | /* | ||
| 2 | * Mars-Semi MR97311A library | ||
| 3 | * Copyright (C) 2005 <bradlch@hotmail.com> | ||
| 4 | * | ||
| 5 | * V4L2 by Jean-Francois Moine <http://moinejf.free.fr> | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License as published by | ||
| 9 | * the Free Software Foundation; either version 2 of the License, or | ||
| 10 | * any later version. | ||
| 11 | * | ||
| 12 | * This program is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | * GNU General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License | ||
| 18 | * along with this program; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #define MODULE_NAME "mars" | ||
| 23 | |||
| 24 | #include "gspca.h" | ||
| 25 | #include "jpeg.h" | ||
| 26 | |||
| 27 | MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); | ||
| 28 | MODULE_DESCRIPTION("GSPCA/Mars USB Camera Driver"); | ||
| 29 | MODULE_LICENSE("GPL"); | ||
| 30 | |||
| 31 | /* controls */ | ||
| 32 | enum e_ctrl { | ||
| 33 | BRIGHTNESS, | ||
| 34 | COLORS, | ||
| 35 | GAMMA, | ||
| 36 | SHARPNESS, | ||
| 37 | ILLUM_TOP, | ||
| 38 | ILLUM_BOT, | ||
| 39 | NCTRLS /* number of controls */ | ||
| 40 | }; | ||
| 41 | |||
| 42 | /* specific webcam descriptor */ | ||
| 43 | struct sd { | ||
| 44 | struct gspca_dev gspca_dev; /* !! must be the first item */ | ||
| 45 | |||
| 46 | struct gspca_ctrl ctrls[NCTRLS]; | ||
| 47 | |||
| 48 | u8 quality; | ||
| 49 | #define QUALITY_MIN 40 | ||
| 50 | #define QUALITY_MAX 70 | ||
| 51 | #define QUALITY_DEF 50 | ||
| 52 | |||
| 53 | u8 jpeg_hdr[JPEG_HDR_SZ]; | ||
| 54 | }; | ||
| 55 | |||
| 56 | /* V4L2 controls supported by the driver */ | ||
| 57 | static void setbrightness(struct gspca_dev *gspca_dev); | ||
| 58 | static void setcolors(struct gspca_dev *gspca_dev); | ||
| 59 | static void setgamma(struct gspca_dev *gspca_dev); | ||
| 60 | static void setsharpness(struct gspca_dev *gspca_dev); | ||
| 61 | static int sd_setilluminator1(struct gspca_dev *gspca_dev, __s32 val); | ||
| 62 | static int sd_setilluminator2(struct gspca_dev *gspca_dev, __s32 val); | ||
| 63 | |||
| 64 | static const struct ctrl sd_ctrls[NCTRLS] = { | ||
| 65 | [BRIGHTNESS] = { | ||
| 66 | { | ||
| 67 | .id = V4L2_CID_BRIGHTNESS, | ||
| 68 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
| 69 | .name = "Brightness", | ||
| 70 | .minimum = 0, | ||
| 71 | .maximum = 30, | ||
| 72 | .step = 1, | ||
| 73 | .default_value = 15, | ||
| 74 | }, | ||
| 75 | .set_control = setbrightness | ||
| 76 | }, | ||
| 77 | [COLORS] = { | ||
| 78 | { | ||
| 79 | .id = V4L2_CID_SATURATION, | ||
| 80 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
| 81 | .name = "Color", | ||
| 82 | .minimum = 1, | ||
| 83 | .maximum = 255, | ||
| 84 | .step = 1, | ||
| 85 | .default_value = 200, | ||
| 86 | }, | ||
| 87 | .set_control = setcolors | ||
| 88 | }, | ||
| 89 | [GAMMA] = { | ||
| 90 | { | ||
| 91 | .id = V4L2_CID_GAMMA, | ||
| 92 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
| 93 | .name = "Gamma", | ||
| 94 | .minimum = 0, | ||
| 95 | .maximum = 3, | ||
| 96 | .step = 1, | ||
| 97 | .default_value = 1, | ||
| 98 | }, | ||
| 99 | .set_control = setgamma | ||
| 100 | }, | ||
| 101 | [SHARPNESS] = { | ||
| 102 | { | ||
| 103 | .id = V4L2_CID_SHARPNESS, | ||
| 104 | .type = V4L2_CTRL_TYPE_INTEGER, | ||
| 105 | .name = "Sharpness", | ||
| 106 | .minimum = 0, | ||
| 107 | .maximum = 2, | ||
| 108 | .step = 1, | ||
| 109 | .default_value = 1, | ||
| 110 | }, | ||
| 111 | .set_control = setsharpness | ||
| 112 | }, | ||
| 113 | [ILLUM_TOP] = { | ||
| 114 | { | ||
| 115 | .id = V4L2_CID_ILLUMINATORS_1, | ||
| 116 | .type = V4L2_CTRL_TYPE_BOOLEAN, | ||
| 117 | .name = "Top illuminator", | ||
| 118 | .minimum = 0, | ||
| 119 | .maximum = 1, | ||
| 120 | .step = 1, | ||
| 121 | .default_value = 0, | ||
| 122 | .flags = V4L2_CTRL_FLAG_UPDATE, | ||
| 123 | }, | ||
| 124 | .set = sd_setilluminator1 | ||
| 125 | }, | ||
| 126 | [ILLUM_BOT] = { | ||
| 127 | { | ||
| 128 | .id = V4L2_CID_ILLUMINATORS_2, | ||
| 129 | .type = V4L2_CTRL_TYPE_BOOLEAN, | ||
| 130 | .name = "Bottom illuminator", | ||
| 131 | .minimum = 0, | ||
| 132 | .maximum = 1, | ||
| 133 | .step = 1, | ||
| 134 | .default_value = 0, | ||
| 135 | .flags = V4L2_CTRL_FLAG_UPDATE, | ||
| 136 | }, | ||
| 137 | .set = sd_setilluminator2 | ||
| 138 | }, | ||
| 139 | }; | ||
| 140 | |||
| 141 | static const struct v4l2_pix_format vga_mode[] = { | ||
| 142 | {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, | ||
| 143 | .bytesperline = 320, | ||
| 144 | .sizeimage = 320 * 240 * 3 / 8 + 590, | ||
| 145 | .colorspace = V4L2_COLORSPACE_JPEG, | ||
| 146 | .priv = 2}, | ||
| 147 | {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, | ||
| 148 | .bytesperline = 640, | ||
| 149 | .sizeimage = 640 * 480 * 3 / 8 + 590, | ||
| 150 | .colorspace = V4L2_COLORSPACE_JPEG, | ||
| 151 | .priv = 1}, | ||
| 152 | }; | ||
| 153 | |||
| 154 | static const __u8 mi_data[0x20] = { | ||
| 155 | /* 01 02 03 04 05 06 07 08 */ | ||
| 156 | 0x48, 0x22, 0x01, 0x47, 0x10, 0x00, 0x00, 0x00, | ||
| 157 | /* 09 0a 0b 0c 0d 0e 0f 10 */ | ||
| 158 | 0x00, 0x01, 0x30, 0x01, 0x30, 0x01, 0x30, 0x01, | ||
| 159 | /* 11 12 13 14 15 16 17 18 */ | ||
| 160 | 0x30, 0x00, 0x04, 0x00, 0x06, 0x01, 0xe2, 0x02, | ||
| 161 | /* 19 1a 1b 1c 1d 1e 1f 20 */ | ||
| 162 | 0x82, 0x00, 0x20, 0x17, 0x80, 0x08, 0x0c, 0x00 | ||
| 163 | }; | ||
| 164 | |||
| 165 | /* write <len> bytes from gspca_dev->usb_buf */ | ||
| 166 | static void reg_w(struct gspca_dev *gspca_dev, | ||
| 167 | int len) | ||
| 168 | { | ||
| 169 | int alen, ret; | ||
| 170 | |||
| 171 | if (gspca_dev->usb_err < 0) | ||
| 172 | return; | ||
| 173 | |||
| 174 | ret = usb_bulk_msg(gspca_dev->dev, | ||
| 175 | usb_sndbulkpipe(gspca_dev->dev, 4), | ||
| 176 | gspca_dev->usb_buf, | ||
| 177 | len, | ||
| 178 | &alen, | ||
| 179 | 500); /* timeout in milliseconds */ | ||
| 180 | if (ret < 0) { | ||
| 181 | err("reg write [%02x] error %d", | ||
| 182 | gspca_dev->usb_buf[0], ret); | ||
| 183 | gspca_dev->usb_err = ret; | ||
| 184 | } | ||
| 185 | } | ||
| 186 | |||
| 187 | static void mi_w(struct gspca_dev *gspca_dev, | ||
| 188 | u8 addr, | ||
| 189 | u8 value) | ||
| 190 | { | ||
| 191 | gspca_dev->usb_buf[0] = 0x1f; | ||
| 192 | gspca_dev->usb_buf[1] = 0; /* control byte */ | ||
| 193 | gspca_dev->usb_buf[2] = addr; | ||
| 194 | gspca_dev->usb_buf[3] = value; | ||
| 195 | |||
| 196 | reg_w(gspca_dev, 4); | ||
| 197 | } | ||
| 198 | |||
| 199 | static void setbrightness(struct gspca_dev *gspca_dev) | ||
| 200 | { | ||
| 201 | struct sd *sd = (struct sd *) gspca_dev; | ||
| 202 | |||
| 203 | gspca_dev->usb_buf[0] = 0x61; | ||
| 204 | gspca_dev->usb_buf[1] = sd->ctrls[BRIGHTNESS].val; | ||
| 205 | reg_w(gspca_dev, 2); | ||
| 206 | } | ||
| 207 | |||
| 208 | static void setcolors(struct gspca_dev *gspca_dev) | ||
| 209 | { | ||
| 210 | struct sd *sd = (struct sd *) gspca_dev; | ||
