pwc-ctrl.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542
  1. /* Driver for Philips webcam
  2. Functions that send various control messages to the webcam, including
  3. video modes.
  4. (C) 1999-2003 Nemosoft Unv.
  5. (C) 2004 Luc Saillard (luc@saillard.org)
  6. NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
  7. driver and thus may have bugs that are not present in the original version.
  8. Please send bug reports and support requests to <luc@saillard.org>.
  9. NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
  10. driver and thus may have bugs that are not present in the original version.
  11. Please send bug reports and support requests to <luc@saillard.org>.
  12. The decompression routines have been implemented by reverse-engineering the
  13. Nemosoft binary pwcx module. Caveat emptor.
  14. This program is free software; you can redistribute it and/or modify
  15. it under the terms of the GNU General Public License as published by
  16. the Free Software Foundation; either version 2 of the License, or
  17. (at your option) any later version.
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. GNU General Public License for more details.
  22. You should have received a copy of the GNU General Public License
  23. along with this program; if not, write to the Free Software
  24. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. */
  26. /*
  27. Changes
  28. 2001/08/03 Alvarado Added methods for changing white balance and
  29. red/green gains
  30. */
  31. /* Control functions for the cam; brightness, contrast, video mode, etc. */
  32. #ifdef __KERNEL__
  33. #include <asm/uaccess.h>
  34. #endif
  35. #include <asm/errno.h>
  36. #include <linux/version.h>
  37. #include "pwc.h"
  38. #include "pwc-ioctl.h"
  39. #include "pwc-uncompress.h"
  40. #include "pwc-kiara.h"
  41. #include "pwc-timon.h"
  42. /* Request types: video */
  43. #define SET_LUM_CTL 0x01
  44. #define GET_LUM_CTL 0x02
  45. #define SET_CHROM_CTL 0x03
  46. #define GET_CHROM_CTL 0x04
  47. #define SET_STATUS_CTL 0x05
  48. #define GET_STATUS_CTL 0x06
  49. #define SET_EP_STREAM_CTL 0x07
  50. #define GET_EP_STREAM_CTL 0x08
  51. #define SET_MPT_CTL 0x0D
  52. #define GET_MPT_CTL 0x0E
  53. /* Selectors for the Luminance controls [GS]ET_LUM_CTL */
  54. #define AGC_MODE_FORMATTER 0x2000
  55. #define PRESET_AGC_FORMATTER 0x2100
  56. #define SHUTTER_MODE_FORMATTER 0x2200
  57. #define PRESET_SHUTTER_FORMATTER 0x2300
  58. #define PRESET_CONTOUR_FORMATTER 0x2400
  59. #define AUTO_CONTOUR_FORMATTER 0x2500
  60. #define BACK_LIGHT_COMPENSATION_FORMATTER 0x2600
  61. #define CONTRAST_FORMATTER 0x2700
  62. #define DYNAMIC_NOISE_CONTROL_FORMATTER 0x2800
  63. #define FLICKERLESS_MODE_FORMATTER 0x2900
  64. #define AE_CONTROL_SPEED 0x2A00
  65. #define BRIGHTNESS_FORMATTER 0x2B00
  66. #define GAMMA_FORMATTER 0x2C00
  67. /* Selectors for the Chrominance controls [GS]ET_CHROM_CTL */
  68. #define WB_MODE_FORMATTER 0x1000
  69. #define AWB_CONTROL_SPEED_FORMATTER 0x1100
  70. #define AWB_CONTROL_DELAY_FORMATTER 0x1200
  71. #define PRESET_MANUAL_RED_GAIN_FORMATTER 0x1300
  72. #define PRESET_MANUAL_BLUE_GAIN_FORMATTER 0x1400
  73. #define COLOUR_MODE_FORMATTER 0x1500
  74. #define SATURATION_MODE_FORMATTER1 0x1600
  75. #define SATURATION_MODE_FORMATTER2 0x1700
  76. /* Selectors for the Status controls [GS]ET_STATUS_CTL */
  77. #define SAVE_USER_DEFAULTS_FORMATTER 0x0200
  78. #define RESTORE_USER_DEFAULTS_FORMATTER 0x0300
  79. #define RESTORE_FACTORY_DEFAULTS_FORMATTER 0x0400
  80. #define READ_AGC_FORMATTER 0x0500
  81. #define READ_SHUTTER_FORMATTER 0x0600
  82. #define READ_RED_GAIN_FORMATTER 0x0700
  83. #define READ_BLUE_GAIN_FORMATTER 0x0800
  84. #define SENSOR_TYPE_FORMATTER1 0x0C00
  85. #define READ_RAW_Y_MEAN_FORMATTER 0x3100
  86. #define SET_POWER_SAVE_MODE_FORMATTER 0x3200
  87. #define MIRROR_IMAGE_FORMATTER 0x3300
  88. #define LED_FORMATTER 0x3400
  89. #define SENSOR_TYPE_FORMATTER2 0x3700
  90. /* Formatters for the Video Endpoint controls [GS]ET_EP_STREAM_CTL */
  91. #define VIDEO_OUTPUT_CONTROL_FORMATTER 0x0100
  92. /* Formatters for the motorized pan & tilt [GS]ET_MPT_CTL */
  93. #define PT_RELATIVE_CONTROL_FORMATTER 0x01
  94. #define PT_RESET_CONTROL_FORMATTER 0x02
  95. #define PT_STATUS_FORMATTER 0x03
  96. static const char *size2name[PSZ_MAX] =
  97. {
  98. "subQCIF",
  99. "QSIF",
  100. "QCIF",
  101. "SIF",
  102. "CIF",
  103. "VGA",
  104. };
  105. /********/
  106. /* Entries for the Nala (645/646) camera; the Nala doesn't have compression
  107. preferences, so you either get compressed or non-compressed streams.
  108. An alternate value of 0 means this mode is not available at all.
  109. */
  110. struct Nala_table_entry {
  111. char alternate; /* USB alternate setting */
  112. int compressed; /* Compressed yes/no */
  113. unsigned char mode[3]; /* precomputed mode table */
  114. };
  115. static struct Nala_table_entry Nala_table[PSZ_MAX][8] =
  116. {
  117. #include "pwc-nala.h"
  118. };
  119. /****************************************************************************/
  120. #define SendControlMsg(request, value, buflen) \
  121. usb_control_msg(pdev->udev, usb_sndctrlpipe(pdev->udev, 0), \
  122. request, \
  123. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, \
  124. value, \
  125. pdev->vcinterface, \
  126. &buf, buflen, 500)
  127. #define RecvControlMsg(request, value, buflen) \
  128. usb_control_msg(pdev->udev, usb_rcvctrlpipe(pdev->udev, 0), \
  129. request, \
  130. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, \
  131. value, \
  132. pdev->vcinterface, \
  133. &buf, buflen, 500)
  134. #if PWC_DEBUG
  135. void pwc_hexdump(void *p, int len)
  136. {
  137. int i;
  138. unsigned char *s;
  139. char buf[100], *d;
  140. s = (unsigned char *)p;
  141. d = buf;
  142. *d = '\0';
  143. Debug("Doing hexdump @ %p, %d bytes.\n", p, len);
  144. for (i = 0; i < len; i++) {
  145. d += sprintf(d, "%02X ", *s++);
  146. if ((i & 0xF) == 0xF) {
  147. Debug("%s\n", buf);
  148. d = buf;
  149. *d = '\0';
  150. }
  151. }
  152. if ((i & 0xF) != 0)
  153. Debug("%s\n", buf);
  154. }
  155. #endif
  156. static inline int send_video_command(struct usb_device *udev, int index, void *buf, int buflen)
  157. {
  158. return usb_control_msg(udev,
  159. usb_sndctrlpipe(udev, 0),
  160. SET_EP_STREAM_CTL,
  161. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  162. VIDEO_OUTPUT_CONTROL_FORMATTER,
  163. index,
  164. buf, buflen, 1000);
  165. }
  166. static inline int set_video_mode_Nala(struct pwc_device *pdev, int size, int frames)
  167. {
  168. unsigned char buf[3];
  169. int ret, fps;
  170. struct Nala_table_entry *pEntry;
  171. int frames2frames[31] =
  172. { /* closest match of framerate */
  173. 0, 0, 0, 0, 4, /* 0-4 */
  174. 5, 5, 7, 7, 10, /* 5-9 */
  175. 10, 10, 12, 12, 15, /* 10-14 */
  176. 15, 15, 15, 20, 20, /* 15-19 */
  177. 20, 20, 20, 24, 24, /* 20-24 */
  178. 24, 24, 24, 24, 24, /* 25-29 */
  179. 24 /* 30 */
  180. };
  181. int frames2table[31] =
  182. { 0, 0, 0, 0, 0, /* 0-4 */
  183. 1, 1, 1, 2, 2, /* 5-9 */
  184. 3, 3, 4, 4, 4, /* 10-14 */
  185. 5, 5, 5, 5, 5, /* 15-19 */
  186. 6, 6, 6, 6, 7, /* 20-24 */
  187. 7, 7, 7, 7, 7, /* 25-29 */
  188. 7 /* 30 */
  189. };
  190. if (size < 0 || size > PSZ_CIF || frames < 4 || frames > 25)
  191. return -EINVAL;
  192. frames = frames2frames[frames];
  193. fps = frames2table[frames];
  194. pEntry = &Nala_table[size][fps];
  195. if (pEntry->alternate == 0)
  196. return -EINVAL;
  197. if (pEntry->compressed)
  198. return -ENOENT; /* Not supported. */
  199. memcpy(buf, pEntry->mode, 3);
  200. ret = send_video_command(pdev->udev, pdev->vendpoint, buf, 3);
  201. if (ret < 0) {
  202. Debug("Failed to send video command... %d\n", ret);
  203. return ret;
  204. }
  205. if (pEntry->compressed && pdev->vpalette != VIDEO_PALETTE_RAW)
  206. {
  207. switch(pdev->type) {
  208. case 645:
  209. case 646:
  210. /* pwc_dec1_init(pdev->type, pdev->release, buf, pdev->decompress_data); */
  211. break;
  212. case 675:
  213. case 680:
  214. case 690:
  215. case 720:
  216. case 730:
  217. case 740:
  218. case 750:
  219. /* pwc_dec23_init(pdev->type, pdev->release, buf, pdev->decompress_data); */
  220. break;
  221. }
  222. }
  223. pdev->cmd_len = 3;
  224. memcpy(pdev->cmd_buf, buf, 3);
  225. /* Set various parameters */
  226. pdev->vframes = frames;
  227. pdev->vsize = size;
  228. pdev->valternate = pEntry->alternate;
  229. pdev->image = pwc_image_sizes[size];
  230. pdev->frame_size = (pdev->image.x * pdev->image.y * 3) / 2;
  231. if (pEntry->compressed) {
  232. if (pdev->release < 5) { /* 4 fold compression */
  233. pdev->vbandlength = 528;
  234. pdev->frame_size /= 4;
  235. }
  236. else {
  237. pdev->vbandlength = 704;
  238. pdev->frame_size /= 3;
  239. }
  240. }
  241. else
  242. pdev->vbandlength = 0;
  243. return 0;
  244. }
  245. static inline int set_video_mode_Timon(struct pwc_device *pdev, int size, int frames, int compression, int snapshot)
  246. {
  247. unsigned char buf[13];
  248. const struct Timon_table_entry *pChoose;
  249. int ret, fps;
  250. if (size >= PSZ_MAX || frames < 5 || frames > 30 || compression < 0 || compression > 3)
  251. return -EINVAL;
  252. if (size == PSZ_VGA && frames > 15)
  253. return -EINVAL;
  254. fps = (frames / 5) - 1;
  255. /* Find a supported framerate with progressively higher compression ratios
  256. if the preferred ratio is not available.
  257. */
  258. pChoose = NULL;
  259. while (compression <= 3) {
  260. pChoose = &Timon_table[size][fps][compression];
  261. if (pChoose->alternate != 0)
  262. break;
  263. compression++;
  264. }
  265. if (pChoose == NULL || pChoose->alternate == 0)
  266. return -ENOENT; /* Not supported. */
  267. memcpy(buf, pChoose->mode, 13);
  268. if (snapshot)
  269. buf[0] |= 0x80;
  270. ret = send_video_command(pdev->udev, pdev->vendpoint, buf, 13);
  271. if (ret < 0)
  272. return ret;
  273. /* if (pChoose->bandlength > 0 && pdev->vpalette != VIDEO_PALETTE_RAW)
  274. pwc_dec23_init(pdev->type, pdev->release, buf, pdev->decompress_data); */
  275. pdev->cmd_len = 13;
  276. memcpy(pdev->cmd_buf, buf, 13);
  277. /* Set various parameters */
  278. pdev->vframes = frames;
  279. pdev->vsize = size;
  280. pdev->vsnapshot = snapshot;
  281. pdev->valternate = pChoose->alternate;
  282. pdev->image = pwc_image_sizes[size];
  283. pdev->vbandlength = pChoose->bandlength;
  284. if (pChoose->bandlength > 0)
  285. pdev->frame_size = (pChoose->bandlength * pdev->image.y) / 4;
  286. else
  287. pdev->frame_size = (pdev->image.x * pdev->image.y * 12) / 8;
  288. return 0;
  289. }
  290. static inline int set_video_mode_Kiara(struct pwc_device *pdev, int size, int frames, int compression, int snapshot)
  291. {
  292. const struct Kiara_table_entry *pChoose = NULL;
  293. int fps, ret;
  294. unsigned char buf[12];
  295. struct Kiara_table_entry RawEntry = {6, 773, 1272, {0xAD, 0xF4, 0x10, 0x27, 0xB6, 0x24, 0x96, 0x02, 0x30, 0x05, 0x03, 0x80}};
  296. if (size >= PSZ_MAX || frames < 5 || frames > 30 || compression < 0 || compression > 3)
  297. return -EINVAL;
  298. if (size == PSZ_VGA && frames > 15)
  299. return -EINVAL;
  300. fps = (frames / 5) - 1;
  301. /* special case: VGA @ 5 fps and snapshot is raw bayer mode */
  302. if (size == PSZ_VGA && frames == 5 && snapshot)
  303. {
  304. /* Only available in case the raw palette is selected or
  305. we have the decompressor available. This mode is
  306. only available in compressed form
  307. */
  308. if (pdev->vpalette == VIDEO_PALETTE_RAW)
  309. {
  310. Info("Choosing VGA/5 BAYER mode (%d).\n", pdev->vpalette);
  311. pChoose = &RawEntry;
  312. }
  313. else
  314. {
  315. Info("VGA/5 BAYER mode _must_ have a decompressor available, or use RAW palette.\n");
  316. }
  317. }
  318. else
  319. {
  320. /* Find a supported framerate with progressively higher compression ratios
  321. if the preferred ratio is not available.
  322. Skip this step when using RAW modes.
  323. */
  324. while (compression <= 3) {
  325. pChoose = &Kiara_table[size][fps][compression];
  326. if (pChoose->alternate != 0)
  327. break;
  328. compression++;
  329. }
  330. }
  331. if (pChoose == NULL || pChoose->alternate == 0)
  332. return -ENOENT; /* Not supported. */
  333. Debug("Using alternate setting %d.\n", pChoose->alternate);
  334. /* usb_control_msg won't take staticly allocated arrays as argument?? */
  335. memcpy(buf, pChoose->mode, 12);
  336. if (snapshot)
  337. buf[0] |= 0x80;
  338. /* Firmware bug: video endpoint is 5, but commands are sent to endpoint 4 */
  339. ret = send_video_command(pdev->udev, 4 /* pdev->vendpoint */, buf, 12);
  340. if (ret < 0)
  341. return ret;
  342. /* if (pChoose->bandlength > 0 && pdev->vpalette != VIDEO_PALETTE_RAW)
  343. pwc_dec23_init(pdev->type, pdev->release, buf, pdev->decompress_data); */
  344. pdev->cmd_len = 12;
  345. memcpy(pdev->cmd_buf, buf, 12);
  346. /* All set and go */
  347. pdev->vframes = frames;
  348. pdev->vsize = size;
  349. pdev->vsnapshot = snapshot;
  350. pdev->valternate = pChoose->alternate;
  351. pdev->image = pwc_image_sizes[size];
  352. pdev->vbandlength = pChoose->bandlength;
  353. if (pdev->vbandlength > 0)
  354. pdev->frame_size = (pdev->vbandlength * pdev->image.y) / 4;
  355. else
  356. pdev->frame_size = (pdev->image.x * pdev->image.y * 12) / 8;
  357. return 0;
  358. }
  359. static void pwc_set_image_buffer_size(struct pwc_device *pdev)
  360. {
  361. int i, factor = 0, filler = 0;
  362. /* for PALETTE_YUV420P */
  363. switch(pdev->vpalette)
  364. {
  365. case VIDEO_PALETTE_YUV420P:
  366. factor = 6;
  367. filler = 128;
  368. break;
  369. case VIDEO_PALETTE_RAW:
  370. factor = 6; /* can be uncompressed YUV420P */
  371. filler = 0;
  372. break;
  373. }
  374. /* Set sizes in bytes */
  375. pdev->image.size = pdev->image.x * pdev->image.y * factor / 4;
  376. pdev->view.size = pdev->view.x * pdev->view.y * factor / 4;
  377. /* Align offset, or you'll get some very weird results in
  378. YUV420 mode... x must be multiple of 4 (to get the Y's in
  379. place), and y even (or you'll mixup U & V). This is less of a
  380. problem for YUV420P.
  381. */
  382. pdev->offset.x = ((pdev->view.x - pdev->image.x) / 2) & 0xFFFC;
  383. pdev->offset.y = ((pdev->view.y - pdev->image.y) / 2) & 0xFFFE;
  384. /* Fill buffers with gray or black */
  385. for (i = 0; i < MAX_IMAGES; i++) {
  386. if (pdev->image_ptr[i] != NULL)
  387. memset(pdev->image_ptr[i], filler, pdev->view.size);
  388. }
  389. }
  390. /**
  391. @pdev: device structure
  392. @width: viewport width
  393. @height: viewport height
  394. @frame: framerate, in fps
  395. @compression: preferred compression ratio
  396. @snapshot: snapshot mode or streaming
  397. */
  398. int pwc_set_video_mode(struct pwc_device *pdev, int width, int height, int frames, int compression, int snapshot)
  399. {
  400. int ret, size;
  401. Trace(TRACE_FLOW, "set_video_mode(%dx%d @ %d, palette %d).\n", width, height, frames, pdev->vpalette);
  402. size = pwc_decode_size(pdev, width, height);
  403. if (size < 0) {
  404. Debug("Could not find suitable size.\n");
  405. return -ERANGE;
  406. }
  407. Debug("decode_size = %d.\n", size);
  408. ret = -EINVAL;
  409. switch(pdev->type) {
  410. case 645:
  411. case 646:
  412. ret = set_video_mode_Nala(pdev, size, frames);
  413. break;
  414. case 675:
  415. case 680:
  416. case 690:
  417. ret = set_video_mode_Timon(pdev, size, frames, compression, snapshot);
  418. break;
  419. case 720:
  420. case 730:
  421. case 740:
  422. case 750:
  423. ret = set_video_mode_Kiara(pdev, size, frames, compression, snapshot);
  424. break;
  425. }
  426. if (ret < 0) {
  427. if (ret == -ENOENT)
  428. Info("Video mode %s@%d fps is only supported with the decompressor module (pwcx).\n", size2name[size], frames);
  429. else {
  430. Err("Failed to set video mode %s@%d fps; return code = %d\n", size2name[size], frames, ret);
  431. }
  432. return ret;
  433. }
  434. pdev->view.x = width;
  435. pdev->view.y = height;
  436. pdev->frame_total_size = pdev->frame_size + pdev->frame_header_size + pdev->frame_trailer_size;
  437. pwc_set_image_buffer_size(pdev);
  438. Trace(TRACE_SIZE, "Set viewport to %dx%d, image size is %dx%d.\n", width, height, pwc_image_sizes[size].x, pwc_image_sizes[size].y);
  439. return 0;
  440. }
  441. /* BRIGHTNESS */
  442. int pwc_get_brightness(struct pwc_device *pdev)
  443. {
  444. char buf;
  445. int ret;
  446. ret = RecvControlMsg(GET_LUM_CTL, BRIGHTNESS_FORMATTER, 1);
  447. if (ret < 0)
  448. return ret;
  449. return buf << 9;
  450. }
  451. int pwc_set_brightness(struct pwc_device *pdev, int value)
  452. {
  453. char buf;
  454. if (value < 0)
  455. value = 0;
  456. if (value > 0xffff)
  457. value = 0xffff;
  458. buf = (value >> 9) & 0x7f;
  459. return SendControlMsg(SET_LUM_CTL, BRIGHTNESS_FORMATTER, 1);
  460. }
  461. /* CONTRAST */
  462. int pwc_get_contrast(struct pwc_device *pdev)
  463. {
  464. char buf;
  465. int ret;
  466. ret = RecvControlMsg(GET_LUM_CTL, CONTRAST_FORMATTER, 1);
  467. if (ret < 0)
  468. return ret;
  469. return buf << 10;
  470. }
  471. int pwc_set_contrast(struct pwc_device *pdev, int value)
  472. {
  473. char buf;
  474. if (value < 0)
  475. value = 0;
  476. if (value > 0xffff)
  477. value = 0xffff;
  478. buf = (value >> 10) & 0x3f;
  479. return SendControlMsg(SET_LUM_CTL, CONTRAST_FORMATTER, 1);
  480. }
  481. /* GAMMA */
  482. int pwc_get_gamma(struct pwc_device *pdev)
  483. {
  484. char buf;
  485. int ret;
  486. ret = RecvControlMsg(GET_LUM_CTL, GAMMA_FORMATTER, 1);
  487. if (ret < 0)
  488. return ret;
  489. return buf << 11;
  490. }
  491. int pwc_set_gamma(struct pwc_device *pdev, int value)
  492. {
  493. char buf;
  494. if (value < 0)
  495. value = 0;
  496. if (value > 0xffff)
  497. value = 0xffff;
  498. buf = (value >> 11) & 0x1f;
  499. return SendControlMsg(SET_LUM_CTL, GAMMA_FORMATTER, 1);
  500. }
  501. /* SATURATION */
  502. int pwc_get_saturation(struct pwc_device *pdev)
  503. {
  504. char buf;
  505. int ret;
  506. if (pdev->type < 675)
  507. return -1;
  508. ret = RecvControlMsg(GET_CHROM_CTL, pdev->type < 730 ? SATURATION_MODE_FORMATTER2 : SATURATION_MODE_FORMATTER1, 1);
  509. if (ret < 0)
  510. return ret;
  511. return 32768 + buf * 327;
  512. }
  513. int pwc_set_saturation(struct pwc_device *pdev, int value)
  514. {
  515. char buf;
  516. if (pdev->type < 675)
  517. return -EINVAL;
  518. if (value < 0)
  519. value = 0;
  520. if (value > 0xffff)
  521. value = 0xffff;
  522. /* saturation ranges from -100 to +100 */
  523. buf = (value - 32768) / 327;
  524. return SendControlMsg(SET_CHROM_CTL, pdev->type < 730 ? SATURATION_MODE_FORMATTER2 : SATURATION_MODE_FORMATTER1, 1);
  525. }
  526. /* AGC */
  527. static inline int pwc_set_agc(struct pwc_device *pdev, int mode, int value)
  528. {
  529. char buf;
  530. int ret;
  531. if (mode)
  532. buf = 0x0; /* auto */
  533. else
  534. buf = 0xff; /* fixed */
  535. ret = SendControlMsg(SET_LUM_CTL, AGC_MODE_FORMATTER, 1);
  536. if (!mode && ret >= 0) {
  537. if (value < 0)
  538. value = 0;
  539. if (value > 0xffff)
  540. value = 0xffff;
  541. buf = (value >> 10) & 0x3F;
  542. ret = SendControlMsg(SET_LUM_CTL, PRESET_AGC_FORMATTER, 1);
  543. }
  544. if (ret < 0)
  545. return ret;
  546. return 0;
  547. }
  548. static inline int pwc_get_agc(struct pwc_device *pdev, int *value)
  549. {
  550. unsigned char buf;
  551. int ret;
  552. ret = RecvControlMsg(GET_LUM_CTL, AGC_MODE_FORMATTER, 1);
  553. if (ret < 0)
  554. return ret;
  555. if (buf != 0) { /* fixed */
  556. ret = RecvControlMsg(GET_LUM_CTL, PRESET_AGC_FORMATTER, 1);
  557. if (ret < 0)
  558. return ret;
  559. if (buf > 0x3F)
  560. buf = 0x3F;
  561. *value = (buf << 10);
  562. }
  563. else { /* auto */
  564. ret = RecvControlMsg(GET_STATUS_CTL, READ_AGC_FORMATTER, 1);
  565. if (ret < 0)
  566. return ret;
  567. /* Gah... this value ranges from 0x00 ... 0x9F */
  568. if (buf > 0x9F)
  569. buf = 0x9F;
  570. *value = -(48 + buf * 409);
  571. }
  572. return 0;
  573. }
  574. static inline int pwc_set_shutter_speed(struct pwc_device *pdev, int mode, int value)
  575. {
  576. char buf[2];
  577. int speed, ret;
  578. if (mode)
  579. buf[0] = 0x0; /* auto */
  580. else
  581. buf[0] = 0xff; /* fixed */
  582. ret = SendControlMsg(SET_LUM_CTL, SHUTTER_MODE_FORMATTER, 1);
  583. if (!mode && ret >= 0) {
  584. if (value < 0)
  585. value = 0;
  586. if (value > 0xffff)
  587. value = 0xffff;
  588. switch(pdev->type) {
  589. case 675:
  590. case 680:
  591. case 690:
  592. /* speed ranges from 0x0 to 0x290 (656) */
  593. speed = (value / 100);
  594. buf[1] = speed >> 8;
  595. buf[0] = speed & 0xff;
  596. break;
  597. case 720:
  598. case 730:
  599. case 740:
  600. case 750:
  601. /* speed seems to range from 0x0 to 0xff */
  602. buf[1] = 0;
  603. buf[0] = value >> 8;
  604. break;
  605. }
  606. ret = SendControlMsg(SET_LUM_CTL, PRESET_SHUTTER_FORMATTER, 2);
  607. }
  608. return ret;
  609. }
  610. /* POWER */
  611. int pwc_camera_power(struct pwc_device *pdev, int power)
  612. {
  613. char buf;
  614. if (pdev->type < 675 || (pdev->type < 730 && pdev->release < 6))
  615. return 0; /* Not supported by Nala or Timon < release 6 */
  616. if (power)
  617. buf = 0x00; /* active */
  618. else
  619. buf = 0xFF; /* power save */
  620. return SendControlMsg(SET_STATUS_CTL, SET_POWER_SAVE_MODE_FORMATTER, 1);
  621. }
  622. /* private calls */
  623. static inline int pwc_restore_user(struct pwc_device *pdev)
  624. {
  625. char buf; /* dummy */
  626. return SendControlMsg(SET_STATUS_CTL, RESTORE_USER_DEFAULTS_FORMATTER, 0);
  627. }
  628. static inline int pwc_save_user(struct pwc_device *pdev)
  629. {
  630. char buf; /* dummy */
  631. return SendControlMsg(SET_STATUS_CTL, SAVE_USER_DEFAULTS_FORMATTER, 0);
  632. }
  633. static inline int pwc_restore_factory(struct pwc_device *pdev)
  634. {
  635. char buf; /* dummy */
  636. return SendControlMsg(SET_STATUS_CTL, RESTORE_FACTORY_DEFAULTS_FORMATTER, 0);
  637. }
  638. /* ************************************************* */
  639. /* Patch by Alvarado: (not in the original version */
  640. /*
  641. * the camera recognizes modes from 0 to 4:
  642. *
  643. * 00: indoor (incandescant lighting)
  644. * 01: outdoor (sunlight)
  645. * 02: fluorescent lighting
  646. * 03: manual
  647. * 04: auto
  648. */
  649. static inline int pwc_set_awb(struct pwc_device *pdev, int mode)
  650. {
  651. char buf;
  652. int ret;
  653. if (mode < 0)
  654. mode = 0;
  655. if (mode > 4)
  656. mode = 4;
  657. buf = mode & 0x07; /* just the lowest three bits */
  658. ret = SendControlMsg(SET_CHROM_CTL, WB_MODE_FORMATTER, 1);
  659. if (ret < 0)
  660. return ret;
  661. return 0;
  662. }
  663. static inline int pwc_get_awb(struct pwc_device *pdev)
  664. {
  665. unsigned char buf;
  666. int ret;
  667. ret = RecvControlMsg(GET_CHROM_CTL, WB_MODE_FORMATTER, 1);
  668. if (ret < 0)
  669. return ret;
  670. return buf;
  671. }
  672. static inline int pwc_set_red_gain(struct pwc_device *pdev, int value)
  673. {
  674. unsigned char buf;
  675. if (value < 0)
  676. value = 0;
  677. if (value > 0xffff)
  678. value = 0xffff;
  679. /* only the msb is considered */
  680. buf = value >> 8;
  681. return SendControlMsg(SET_CHROM_CTL, PRESET_MANUAL_RED_GAIN_FORMATTER, 1);
  682. }
  683. static inline int pwc_get_red_gain(struct pwc_device *pdev, int *value)
  684. {
  685. unsigned char buf;
  686. int ret;
  687. ret = RecvControlMsg(GET_CHROM_CTL, PRESET_MANUAL_RED_GAIN_FORMATTER, 1);
  688. if (ret < 0)
  689. return ret;
  690. *value = buf << 8;
  691. return 0;
  692. }
  693. static inline int pwc_set_blue_gain(struct pwc_device *pdev, int value)
  694. {
  695. unsigned char buf;
  696. if (value < 0)
  697. value = 0;
  698. if (value > 0xffff)
  699. value = 0xffff;
  700. /* only the msb is considered */
  701. buf = value >> 8;
  702. return SendControlMsg(SET_CHROM_CTL, PRESET_MANUAL_BLUE_GAIN_FORMATTER, 1);
  703. }
  704. static inline int pwc_get_blue_gain(struct pwc_device *pdev, int *value)
  705. {
  706. unsigned char buf;
  707. int ret;
  708. ret = RecvControlMsg(GET_CHROM_CTL, PRESET_MANUAL_BLUE_GAIN_FORMATTER, 1);
  709. if (ret < 0)
  710. return ret;
  711. *value = buf << 8;
  712. return 0;
  713. }
  714. /* The following two functions are different, since they only read the
  715. internal red/blue gains, which may be different from the manual
  716. gains set or read above.
  717. */
  718. static inline int pwc_read_red_gain(struct pwc_device *pdev, int *value)
  719. {
  720. unsigned char buf;
  721. int ret;
  722. ret = RecvControlMsg(GET_STATUS_CTL, READ_RED_GAIN_FORMATTER, 1);
  723. if (ret < 0)
  724. return ret;
  725. *value = buf << 8;
  726. return 0;
  727. }
  728. static inline int pwc_read_blue_gain(struct pwc_device *pdev, int *value)
  729. {
  730. unsigned char buf;
  731. int ret;
  732. ret = RecvControlMsg(GET_STATUS_CTL, READ_BLUE_GAIN_FORMATTER, 1);
  733. if (ret < 0)
  734. return ret;
  735. *value = buf << 8;
  736. return 0;
  737. }
  738. static inline int pwc_set_wb_speed(struct pwc_device *pdev, int speed)
  739. {
  740. unsigned char buf;
  741. /* useful range is 0x01..0x20 */
  742. buf = speed / 0x7f0;
  743. return SendControlMsg(SET_CHROM_CTL, AWB_CONTROL_SPEED_FORMATTER, 1);
  744. }
  745. static inline int pwc_get_wb_speed(struct pwc_device *pdev, int *value)
  746. {
  747. unsigned char buf;
  748. int ret;
  749. ret = RecvControlMsg(GET_CHROM_CTL, AWB_CONTROL_SPEED_FORMATTER, 1);
  750. if (ret < 0)
  751. return ret;
  752. *value = buf * 0x7f0;
  753. return 0;
  754. }
  755. static inline int pwc_set_wb_delay(struct pwc_device *pdev, int delay)
  756. {
  757. unsigned char buf;
  758. /* useful range is 0x01..0x3F */
  759. buf = (delay >> 10);
  760. return SendControlMsg(SET_CHROM_CTL, AWB_CONTROL_DELAY_FORMATTER, 1);
  761. }
  762. static inline int pwc_get_wb_delay(struct pwc_device *pdev, int *value)
  763. {
  764. unsigned char buf;
  765. int ret;
  766. ret = RecvControlMsg(GET_CHROM_CTL, AWB_CONTROL_DELAY_FORMATTER, 1);
  767. if (ret < 0)
  768. return ret;
  769. *value = buf << 10;
  770. return 0;
  771. }
  772. int pwc_set_leds(struct pwc_device *pdev, int on_value, int off_value)
  773. {
  774. unsigned char buf[2];
  775. if (pdev->type < 730)
  776. return 0;
  777. on_value /= 100;
  778. off_value /= 100;
  779. if (on_value < 0)
  780. on_value = 0;
  781. if (on_value > 0xff)
  782. on_value = 0xff;
  783. if (off_value < 0)
  784. off_value = 0;
  785. if (off_value > 0xff)
  786. off_value = 0xff;
  787. buf[0] = on_value;
  788. buf[1] = off_value;
  789. return SendControlMsg(SET_STATUS_CTL, LED_FORMATTER, 2);
  790. }
  791. static int pwc_get_leds(struct pwc_device *pdev, int *on_value, int *off_value)
  792. {
  793. unsigned char buf[2];
  794. int ret;
  795. if (pdev->type < 730) {
  796. *on_value = -1;
  797. *off_value = -1;
  798. return 0;
  799. }
  800. ret = RecvControlMsg(GET_STATUS_CTL, LED_FORMATTER, 2);
  801. if (ret < 0)
  802. return ret;
  803. *on_value = buf[0] * 100;
  804. *off_value = buf[1] * 100;
  805. return 0;
  806. }
  807. static inline int pwc_set_contour(struct pwc_device *pdev, int contour)
  808. {
  809. unsigned char buf;
  810. int ret;
  811. if (contour < 0)
  812. buf = 0xff; /* auto contour on */
  813. else
  814. buf = 0x0; /* auto contour off */
  815. ret = SendControlMsg(SET_LUM_CTL, AUTO_CONTOUR_FORMATTER, 1);
  816. if (ret < 0)
  817. return ret;
  818. if (contour < 0)
  819. return 0;
  820. if (contour > 0xffff)
  821. contour = 0xffff;
  822. buf = (contour >> 10); /* contour preset is [0..3f] */
  823. ret = SendControlMsg(SET_LUM_CTL, PRESET_CONTOUR_FORMATTER, 1);
  824. if (ret < 0)
  825. return ret;
  826. return 0;
  827. }
  828. static inline int pwc_get_contour(struct pwc_device *pdev, int *contour)
  829. {
  830. unsigned char buf;
  831. int ret;
  832. ret = RecvControlMsg(GET_LUM_CTL, AUTO_CONTOUR_FORMATTER, 1);
  833. if (ret < 0)
  834. return ret;
  835. if (buf == 0) {
  836. /* auto mode off, query current preset value */
  837. ret = RecvControlMsg(GET_LUM_CTL, PRESET_CONTOUR_FORMATTER, 1);
  838. if (ret < 0)
  839. return ret;
  840. *contour = buf << 10;
  841. }
  842. else
  843. *contour = -1;
  844. return 0;
  845. }
  846. static inline int pwc_set_backlight(struct pwc_device *pdev, int backlight)
  847. {
  848. unsigned char buf;
  849. if (backlight)
  850. buf = 0xff;
  851. else
  852. buf = 0x0;
  853. return SendControlMsg(SET_LUM_CTL, BACK_LIGHT_COMPENSATION_FORMATTER, 1);
  854. }
  855. static inline int pwc_get_backlight(struct pwc_device *pdev, int *backlight)
  856. {
  857. int ret;
  858. unsigned char buf;
  859. ret = RecvControlMsg(GET_LUM_CTL, BACK_LIGHT_COMPENSATION_FORMATTER, 1);
  860. if (ret < 0)
  861. return ret;
  862. *backlight = buf;
  863. return 0;
  864. }
  865. static inline int pwc_set_flicker(struct pwc_device *pdev, int flicker)
  866. {
  867. unsigned char buf;
  868. if (flicker)
  869. buf = 0xff;
  870. else
  871. buf = 0x0;
  872. return SendControlMsg(SET_LUM_CTL, FLICKERLESS_MODE_FORMATTER, 1);
  873. }
  874. static inline int pwc_get_flicker(struct pwc_device *pdev, int *flicker)
  875. {
  876. int ret;
  877. unsigned char buf;
  878. ret = RecvControlMsg(GET_LUM_CTL, FLICKERLESS_MODE_FORMATTER, 1);
  879. if (ret < 0)
  880. return ret;
  881. *flicker = buf;
  882. return 0;
  883. }
  884. static inline int pwc_set_dynamic_noise(struct pwc_device *pdev, int noise)
  885. {
  886. unsigned char buf;
  887. if (noise < 0)
  888. noise = 0;
  889. if (noise > 3)
  890. noise = 3;
  891. buf = noise;
  892. return SendControlMsg(SET_LUM_CTL, DYNAMIC_NOISE_CONTROL_FORMATTER, 1);
  893. }
  894. static inline int pwc_get_dynamic_noise(struct pwc_device *pdev, int *noise)
  895. {
  896. int ret;
  897. unsigned char buf;
  898. ret = RecvControlMsg(GET_LUM_CTL, DYNAMIC_NOISE_CONTROL_FORMATTER, 1);
  899. if (ret < 0)
  900. return ret;
  901. *noise = buf;
  902. return 0;
  903. }
  904. static int pwc_mpt_reset(struct pwc_device *pdev, int flags)
  905. {
  906. unsigned char buf;
  907. buf = flags & 0x03; // only lower two bits are currently used
  908. return SendControlMsg(SET_MPT_CTL, PT_RESET_CONTROL_FORMATTER, 1);
  909. }
  910. static inline int pwc_mpt_set_angle(struct pwc_device *pdev, int pan, int tilt)
  911. {
  912. unsigned char buf[4];
  913. /* set new relative angle; angles are expressed in degrees * 100,
  914. but cam as .5 degree resolution, hence divide by 200. Also
  915. the angle must be multiplied by 64 before it's send to
  916. the cam (??)
  917. */
  918. pan = 64 * pan / 100;
  919. tilt = -64 * tilt / 100; /* positive tilt is down, which is not what the user would expect */
  920. buf[0] = pan & 0xFF;
  921. buf[1] = (pan >> 8) & 0xFF;
  922. buf[2] = tilt & 0xFF;
  923. buf[3] = (tilt >> 8) & 0xFF;
  924. return SendControlMsg(SET_MPT_CTL, PT_RELATIVE_CONTROL_FORMATTER, 4);
  925. }
  926. static inline int pwc_mpt_get_status(struct pwc_device *pdev, struct pwc_mpt_status *status)
  927. {
  928. int ret;
  929. unsigned char buf[5];
  930. ret = RecvControlMsg(GET_MPT_CTL, PT_STATUS_FORMATTER, 5);
  931. if (ret < 0)
  932. return ret;
  933. status->status = buf[0] & 0x7; // 3 bits are used for reporting
  934. status->time_pan = (buf[1] << 8) + buf[2];
  935. status->time_tilt = (buf[3] << 8) + buf[4];
  936. return 0;
  937. }
  938. int pwc_get_cmos_sensor(struct pwc_device *pdev, int *sensor)
  939. {
  940. unsigned char buf;
  941. int ret = -1, request;
  942. if (pdev->type < 675)
  943. request = SENSOR_TYPE_FORMATTER1;
  944. else if (pdev->type < 730)
  945. return -1; /* The Vesta series doesn't have this call */
  946. else
  947. request = SENSOR_TYPE_FORMATTER2;
  948. ret = RecvControlMsg(GET_STATUS_CTL, request, 1);
  949. if (ret < 0)
  950. return ret;
  951. if (pdev->type < 675)
  952. *sensor = buf | 0x100;
  953. else
  954. *sensor = buf;
  955. return 0;
  956. }
  957. /* End of Add-Ons */
  958. /* ************************************************* */
  959. int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
  960. {
  961. int ret = 0;
  962. switch(cmd) {
  963. case VIDIOCPWCRUSER:
  964. {
  965. if (pwc_restore_user(pdev))
  966. ret = -EINVAL;
  967. break;
  968. }
  969. case VIDIOCPWCSUSER:
  970. {
  971. if (pwc_save_user(pdev))
  972. ret = -EINVAL;
  973. break;
  974. }
  975. case VIDIOCPWCFACTORY:
  976. {
  977. if (pwc_restore_factory(pdev))
  978. ret = -EINVAL;
  979. break;
  980. }
  981. case VIDIOCPWCSCQUAL:
  982. {
  983. int *qual = arg;
  984. if (*qual < 0 || *qual > 3)
  985. ret = -EINVAL;
  986. else
  987. ret = pwc_try_video_mode(pdev, pdev->view.x, pdev->view.y, pdev->vframes, *qual, pdev->vsnapshot);
  988. if (ret >= 0)
  989. pdev->vcompression = *qual;
  990. break;
  991. }
  992. case VIDIOCPWCGCQUAL:
  993. {
  994. int *qual = arg;
  995. *qual = pdev->vcompression;
  996. break;
  997. }
  998. case VIDIOCPWCPROBE:
  999. {
  1000. struct pwc_probe *probe = arg;
  1001. strcpy(probe->name, pdev->vdev->name);
  1002. probe->type = pdev->type;
  1003. break;
  1004. }
  1005. case VIDIOCPWCGSERIAL:
  1006. {
  1007. struct pwc_serial *serial = arg;
  1008. strcpy(serial->serial, pdev->serial);
  1009. break;
  1010. }
  1011. case VIDIOCPWCSAGC:
  1012. {
  1013. int *agc = arg;
  1014. if (pwc_set_agc(pdev, *agc < 0 ? 1 : 0, *agc))
  1015. ret = -EINVAL;
  1016. break;
  1017. }
  1018. case VIDIOCPWCGAGC:
  1019. {
  1020. int *agc = arg;
  1021. if (pwc_get_agc(pdev, agc))
  1022. ret = -EINVAL;
  1023. break;
  1024. }
  1025. case VIDIOCPWCSSHUTTER:
  1026. {
  1027. int *shutter_speed = arg;
  1028. ret = pwc_set_shutter_speed(pdev, *shutter_speed < 0 ? 1 : 0, *shutter_speed);
  1029. break;
  1030. }
  1031. case VIDIOCPWCSAWB:
  1032. {
  1033. struct pwc_whitebalance *wb = arg;
  1034. ret = pwc_set_awb(pdev, wb->mode);
  1035. if (ret >= 0 && wb->mode == PWC_WB_MANUAL) {
  1036. pwc_set_red_gain(pdev, wb->manual_red);
  1037. pwc_set_blue_gain(pdev, wb->manual_blue);
  1038. }
  1039. break;
  1040. }
  1041. case VIDIOCPWCGAWB:
  1042. {
  1043. struct pwc_whitebalance *wb = arg;
  1044. memset(wb, 0, sizeof(struct pwc_whitebalance));
  1045. wb->mode = pwc_get_awb(pdev);
  1046. if (wb->mode < 0)
  1047. ret = -EINVAL;
  1048. else {
  1049. if (wb->mode == PWC_WB_MANUAL) {
  1050. ret = pwc_get_red_gain(pdev, &wb->manual_red);
  1051. if (ret < 0)
  1052. break;
  1053. ret = pwc_get_blue_gain(pdev, &wb->manual_blue);
  1054. if (ret < 0)
  1055. break;
  1056. }
  1057. if (wb->mode == PWC_WB_AUTO) {
  1058. ret = pwc_read_red_gain(pdev, &wb->read_red);
  1059. if (ret < 0)
  1060. break;
  1061. ret = pwc_read_blue_gain(pdev, &wb->read_blue);
  1062. if (ret < 0)
  1063. break;
  1064. }
  1065. }
  1066. break;
  1067. }
  1068. case VIDIOCPWCSAWBSPEED:
  1069. {
  1070. struct pwc_wb_speed *wbs = arg;
  1071. if (wbs->control_speed > 0) {
  1072. ret = pwc_set_wb_speed(pdev, wbs->control_speed);
  1073. }
  1074. if (wbs->control_delay > 0) {
  1075. ret = pwc_set_wb_delay(pdev, wbs->control_delay);
  1076. }
  1077. break;
  1078. }
  1079. case VIDIOCPWCGAWBSPEED:
  1080. {
  1081. struct pwc_wb_speed *wbs = arg;
  1082. ret = pwc_get_wb_speed(pdev, &wbs->control_speed);
  1083. if (ret < 0)
  1084. break;
  1085. ret = pwc_get_wb_delay(pdev, &wbs->control_delay);
  1086. if (ret < 0)
  1087. break;
  1088. break;
  1089. }
  1090. case VIDIOCPWCSLED:
  1091. {
  1092. struct pwc_leds *leds = arg;
  1093. ret = pwc_set_leds(pdev, leds->led_on, leds->led_off);
  1094. break;
  1095. }
  1096. case VIDIOCPWCGLED:
  1097. {
  1098. struct pwc_leds *leds = arg;
  1099. ret = pwc_get_leds(pdev, &leds->led_on, &leds->led_off);
  1100. break;
  1101. }
  1102. case VIDIOCPWCSCONTOUR:
  1103. {
  1104. int *contour = arg;
  1105. ret = pwc_set_contour(pdev, *contour);
  1106. break;
  1107. }
  1108. case VIDIOCPWCGCONTOUR:
  1109. {
  1110. int *contour = arg;
  1111. ret = pwc_get_contour(pdev, contour);
  1112. break;
  1113. }
  1114. case VIDIOCPWCSBACKLIGHT:
  1115. {
  1116. int *backlight = arg;
  1117. ret = pwc_set_backlight(pdev, *backlight);
  1118. break;
  1119. }
  1120. case VIDIOCPWCGBACKLIGHT:
  1121. {
  1122. int *backlight = arg;
  1123. ret = pwc_get_backlight(pdev, backlight);
  1124. break;
  1125. }
  1126. case VIDIOCPWCSFLICKER:
  1127. {
  1128. int *flicker = arg;
  1129. ret = pwc_set_flicker(pdev, *flicker);
  1130. break;
  1131. }
  1132. case VIDIOCPWCGFLICKER:
  1133. {
  1134. int *flicker = arg;
  1135. ret = pwc_get_flicker(pdev, flicker);
  1136. break;
  1137. }
  1138. case VIDIOCPWCSDYNNOISE:
  1139. {
  1140. int *dynnoise = arg;
  1141. ret = pwc_set_dynamic_noise(pdev, *dynnoise);
  1142. break;
  1143. }
  1144. case VIDIOCPWCGDYNNOISE:
  1145. {
  1146. int *dynnoise = arg;
  1147. ret = pwc_get_dynamic_noise(pdev, dynnoise);
  1148. break;
  1149. }
  1150. case VIDIOCPWCGREALSIZE:
  1151. {
  1152. struct pwc_imagesize *size = arg;
  1153. size->width = pdev->image.x;
  1154. size->height = pdev->image.y;
  1155. break;
  1156. }
  1157. case VIDIOCPWCMPTRESET:
  1158. {
  1159. if (pdev->features & FEATURE_MOTOR_PANTILT)
  1160. {
  1161. int *flags = arg;
  1162. ret = pwc_mpt_reset(pdev, *flags);
  1163. if (ret >= 0)
  1164. {
  1165. pdev->pan_angle = 0;
  1166. pdev->tilt_angle = 0;
  1167. }
  1168. }
  1169. else
  1170. {
  1171. ret = -ENXIO;
  1172. }
  1173. break;
  1174. }
  1175. case VIDIOCPWCMPTGRANGE:
  1176. {
  1177. if (pdev->features & FEATURE_MOTOR_PANTILT)
  1178. {
  1179. struct pwc_mpt_range *range = arg;
  1180. *range = pdev->angle_range;
  1181. }
  1182. else
  1183. {
  1184. ret = -ENXIO;
  1185. }
  1186. break;
  1187. }
  1188. case VIDIOCPWCMPTSANGLE:
  1189. {
  1190. int new_pan, new_tilt;
  1191. if (pdev->features & FEATURE_MOTOR_PANTILT)
  1192. {
  1193. struct pwc_mpt_angles *angles = arg;
  1194. /* The camera can only set relative angles, so
  1195. do some calculations when getting an absolute angle .
  1196. */
  1197. if (angles->absolute)
  1198. {
  1199. new_pan = angles->pan;
  1200. new_tilt = angles->tilt;
  1201. }
  1202. else
  1203. {
  1204. new_pan = pdev->pan_angle + angles->pan;
  1205. new_tilt = pdev->tilt_angle + angles->tilt;
  1206. }
  1207. /* check absolute ranges */
  1208. if (new_pan < pdev->angle_range.pan_min ||
  1209. new_pan > pdev->angle_range.pan_max ||
  1210. new_tilt < pdev->angle_range.tilt_min ||
  1211. new_tilt > pdev->angle_range.tilt_max)
  1212. {
  1213. ret = -ERANGE;
  1214. }
  1215. else
  1216. {
  1217. /* go to relative range, check again */
  1218. new_pan -= pdev->pan_angle;
  1219. new_tilt -= pdev->tilt_angle;
  1220. /* angles are specified in degrees * 100, thus the limit = 36000 */
  1221. if (new_pan < -36000 || new_pan > 36000 || new_tilt < -36000 || new_tilt > 36000)
  1222. ret = -ERANGE;
  1223. }
  1224. if (ret == 0) /* no errors so far */
  1225. {
  1226. ret = pwc_mpt_set_angle(pdev, new_pan, new_tilt);
  1227. if (ret >= 0)
  1228. {
  1229. pdev->pan_angle += new_pan;
  1230. pdev->tilt_angle += new_tilt;
  1231. }
  1232. if (ret == -EPIPE) /* stall -> out of range */
  1233. ret = -ERANGE;
  1234. }
  1235. }
  1236. else
  1237. {
  1238. ret = -ENXIO;
  1239. }
  1240. break;
  1241. }
  1242. case VIDIOCPWCMPTGANGLE:
  1243. {
  1244. if (pdev->features & FEATURE_MOTOR_PANTILT)
  1245. {
  1246. struct pwc_mpt_angles *angles = arg;
  1247. angles->absolute = 1;
  1248. angles->pan = pdev->pan_angle;
  1249. angles->tilt = pdev->tilt_angle;
  1250. }
  1251. else
  1252. {
  1253. ret = -ENXIO;
  1254. }
  1255. break;
  1256. }
  1257. case VIDIOCPWCMPTSTATUS:
  1258. {
  1259. if (pdev->features & FEATURE_MOTOR_PANTILT)
  1260. {
  1261. struct pwc_mpt_status *status = arg;
  1262. ret = pwc_mpt_get_status(pdev, status);
  1263. }
  1264. else
  1265. {
  1266. ret = -ENXIO;
  1267. }
  1268. break;
  1269. }
  1270. case VIDIOCPWCGVIDCMD:
  1271. {
  1272. struct pwc_video_command *cmd = arg;
  1273. cmd->type = pdev->type;
  1274. cmd->release = pdev->release;
  1275. cmd->command_len = pdev->cmd_len;
  1276. memcpy(&cmd->command_buf, pdev->cmd_buf, pdev->cmd_len);
  1277. cmd->bandlength = pdev->vbandlength;
  1278. cmd->frame_size = pdev->frame_size;
  1279. break;
  1280. }
  1281. /*
  1282. case VIDIOCPWCGVIDTABLE:
  1283. {
  1284. struct pwc_table_init_buffer *table = arg;
  1285. table->len = pdev->cmd_len;
  1286. memcpy(&table->buffer, pdev->decompress_data, pdev->decompressor->table_size);
  1287. break;
  1288. }
  1289. */
  1290. default:
  1291. ret = -ENOIOCTLCMD;
  1292. break;
  1293. }
  1294. if (ret > 0)
  1295. return 0;
  1296. return ret;
  1297. }