pwc-v4l.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135
  1. /* Linux driver for Philips webcam
  2. USB and Video4Linux interface part.
  3. (C) 1999-2004 Nemosoft Unv.
  4. (C) 2004-2006 Luc Saillard (luc@saillard.org)
  5. (C) 2011 Hans de Goede <hdegoede@redhat.com>
  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. The decompression routines have been implemented by reverse-engineering the
  10. Nemosoft binary pwcx module. Caveat emptor.
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #include <linux/errno.h>
  24. #include <linux/init.h>
  25. #include <linux/mm.h>
  26. #include <linux/module.h>
  27. #include <linux/poll.h>
  28. #include <linux/vmalloc.h>
  29. #include <linux/jiffies.h>
  30. #include <asm/io.h>
  31. #include "pwc.h"
  32. #define PWC_CID_CUSTOM(ctrl) ((V4L2_CID_USER_BASE | 0xf000) + custom_ ## ctrl)
  33. static int pwc_g_volatile_ctrl(struct v4l2_ctrl *ctrl);
  34. static int pwc_s_ctrl(struct v4l2_ctrl *ctrl);
  35. static const struct v4l2_ctrl_ops pwc_ctrl_ops = {
  36. .g_volatile_ctrl = pwc_g_volatile_ctrl,
  37. .s_ctrl = pwc_s_ctrl,
  38. };
  39. enum { awb_indoor, awb_outdoor, awb_fl, awb_manual, awb_auto };
  40. enum { custom_autocontour, custom_contour, custom_noise_reduction,
  41. custom_awb_speed, custom_awb_delay,
  42. custom_save_user, custom_restore_user, custom_restore_factory };
  43. const char * const pwc_auto_whitebal_qmenu[] = {
  44. "Indoor (Incandescant Lighting) Mode",
  45. "Outdoor (Sunlight) Mode",
  46. "Indoor (Fluorescent Lighting) Mode",
  47. "Manual Mode",
  48. "Auto Mode",
  49. NULL
  50. };
  51. static const struct v4l2_ctrl_config pwc_auto_white_balance_cfg = {
  52. .ops = &pwc_ctrl_ops,
  53. .id = V4L2_CID_AUTO_WHITE_BALANCE,
  54. .type = V4L2_CTRL_TYPE_MENU,
  55. .max = awb_auto,
  56. .qmenu = pwc_auto_whitebal_qmenu,
  57. };
  58. static const struct v4l2_ctrl_config pwc_autocontour_cfg = {
  59. .ops = &pwc_ctrl_ops,
  60. .id = PWC_CID_CUSTOM(autocontour),
  61. .type = V4L2_CTRL_TYPE_BOOLEAN,
  62. .name = "Auto contour",
  63. .min = 0,
  64. .max = 1,
  65. .step = 1,
  66. };
  67. static const struct v4l2_ctrl_config pwc_contour_cfg = {
  68. .ops = &pwc_ctrl_ops,
  69. .id = PWC_CID_CUSTOM(contour),
  70. .type = V4L2_CTRL_TYPE_INTEGER,
  71. .name = "Contour",
  72. .flags = V4L2_CTRL_FLAG_SLIDER,
  73. .min = 0,
  74. .max = 63,
  75. .step = 1,
  76. };
  77. static const struct v4l2_ctrl_config pwc_backlight_cfg = {
  78. .ops = &pwc_ctrl_ops,
  79. .id = V4L2_CID_BACKLIGHT_COMPENSATION,
  80. .type = V4L2_CTRL_TYPE_BOOLEAN,
  81. .min = 0,
  82. .max = 1,
  83. .step = 1,
  84. };
  85. static const struct v4l2_ctrl_config pwc_flicker_cfg = {
  86. .ops = &pwc_ctrl_ops,
  87. .id = V4L2_CID_BAND_STOP_FILTER,
  88. .type = V4L2_CTRL_TYPE_BOOLEAN,
  89. .min = 0,
  90. .max = 1,
  91. .step = 1,
  92. };
  93. static const struct v4l2_ctrl_config pwc_noise_reduction_cfg = {
  94. .ops = &pwc_ctrl_ops,
  95. .id = PWC_CID_CUSTOM(noise_reduction),
  96. .type = V4L2_CTRL_TYPE_INTEGER,
  97. .name = "Dynamic Noise Reduction",
  98. .min = 0,
  99. .max = 3,
  100. .step = 1,
  101. };
  102. static const struct v4l2_ctrl_config pwc_save_user_cfg = {
  103. .ops = &pwc_ctrl_ops,
  104. .id = PWC_CID_CUSTOM(save_user),
  105. .type = V4L2_CTRL_TYPE_BUTTON,
  106. .name = "Save User Settings",
  107. };
  108. static const struct v4l2_ctrl_config pwc_restore_user_cfg = {
  109. .ops = &pwc_ctrl_ops,
  110. .id = PWC_CID_CUSTOM(restore_user),
  111. .type = V4L2_CTRL_TYPE_BUTTON,
  112. .name = "Restore User Settings",
  113. };
  114. static const struct v4l2_ctrl_config pwc_restore_factory_cfg = {
  115. .ops = &pwc_ctrl_ops,
  116. .id = PWC_CID_CUSTOM(restore_factory),
  117. .type = V4L2_CTRL_TYPE_BUTTON,
  118. .name = "Restore Factory Settings",
  119. };
  120. static const struct v4l2_ctrl_config pwc_awb_speed_cfg = {
  121. .ops = &pwc_ctrl_ops,
  122. .id = PWC_CID_CUSTOM(awb_speed),
  123. .type = V4L2_CTRL_TYPE_INTEGER,
  124. .name = "Auto White Balance Speed",
  125. .min = 1,
  126. .max = 32,
  127. .step = 1,
  128. };
  129. static const struct v4l2_ctrl_config pwc_awb_delay_cfg = {
  130. .ops = &pwc_ctrl_ops,
  131. .id = PWC_CID_CUSTOM(awb_delay),
  132. .type = V4L2_CTRL_TYPE_INTEGER,
  133. .name = "Auto White Balance Delay",
  134. .min = 0,
  135. .max = 63,
  136. .step = 1,
  137. };
  138. int pwc_init_controls(struct pwc_device *pdev)
  139. {
  140. struct v4l2_ctrl_handler *hdl;
  141. struct v4l2_ctrl_config cfg;
  142. int r, def;
  143. hdl = &pdev->ctrl_handler;
  144. r = v4l2_ctrl_handler_init(hdl, 20);
  145. if (r)
  146. return r;
  147. /* Brightness, contrast, saturation, gamma */
  148. r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL, BRIGHTNESS_FORMATTER, &def);
  149. if (r || def > 127)
  150. def = 63;
  151. pdev->brightness = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops,
  152. V4L2_CID_BRIGHTNESS, 0, 127, 1, def);
  153. r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL, CONTRAST_FORMATTER, &def);
  154. if (r || def > 63)
  155. def = 31;
  156. pdev->contrast = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops,
  157. V4L2_CID_CONTRAST, 0, 63, 1, def);
  158. if (pdev->type >= 675) {
  159. if (pdev->type < 730)
  160. pdev->saturation_fmt = SATURATION_MODE_FORMATTER2;
  161. else
  162. pdev->saturation_fmt = SATURATION_MODE_FORMATTER1;
  163. r = pwc_get_s8_ctrl(pdev, GET_CHROM_CTL, pdev->saturation_fmt,
  164. &def);
  165. if (r || def < -100 || def > 100)
  166. def = 0;
  167. pdev->saturation = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops,
  168. V4L2_CID_SATURATION, -100, 100, 1, def);
  169. }
  170. r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL, GAMMA_FORMATTER, &def);
  171. if (r || def > 31)
  172. def = 15;
  173. pdev->gamma = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops,
  174. V4L2_CID_GAMMA, 0, 31, 1, def);
  175. /* auto white balance, red gain, blue gain */
  176. r = pwc_get_u8_ctrl(pdev, GET_CHROM_CTL, WB_MODE_FORMATTER, &def);
  177. if (r || def > awb_auto)
  178. def = awb_auto;
  179. cfg = pwc_auto_white_balance_cfg;
  180. cfg.name = v4l2_ctrl_get_name(cfg.id);
  181. cfg.def = def;
  182. pdev->auto_white_balance = v4l2_ctrl_new_custom(hdl, &cfg, NULL);
  183. /* check auto controls to avoid NULL deref in v4l2_ctrl_auto_cluster */
  184. if (!pdev->auto_white_balance)
  185. return hdl->error;
  186. r = pwc_get_u8_ctrl(pdev, GET_CHROM_CTL,
  187. PRESET_MANUAL_RED_GAIN_FORMATTER, &def);
  188. if (r)
  189. def = 127;
  190. pdev->red_balance = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops,
  191. V4L2_CID_RED_BALANCE, 0, 255, 1, def);
  192. r = pwc_get_u8_ctrl(pdev, GET_CHROM_CTL,
  193. PRESET_MANUAL_BLUE_GAIN_FORMATTER, &def);
  194. if (r)
  195. def = 127;
  196. pdev->blue_balance = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops,
  197. V4L2_CID_BLUE_BALANCE, 0, 255, 1, def);
  198. v4l2_ctrl_auto_cluster(3, &pdev->auto_white_balance, awb_manual, true);
  199. /* autogain, gain */
  200. r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL, AGC_MODE_FORMATTER, &def);
  201. if (r || (def != 0 && def != 0xff))
  202. def = 0;
  203. /* Note a register value if 0 means auto gain is on */
  204. pdev->autogain = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops,
  205. V4L2_CID_AUTOGAIN, 0, 1, 1, def == 0);
  206. if (!pdev->autogain)
  207. return hdl->error;
  208. r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL, PRESET_AGC_FORMATTER, &def);
  209. if (r || def > 63)
  210. def = 31;
  211. pdev->gain = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops,
  212. V4L2_CID_GAIN, 0, 63, 1, def);
  213. /* auto exposure, exposure */
  214. if (DEVICE_USE_CODEC2(pdev->type)) {
  215. r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL, SHUTTER_MODE_FORMATTER,
  216. &def);
  217. if (r || (def != 0 && def != 0xff))
  218. def = 0;
  219. /*
  220. * def = 0 auto, def = ff manual
  221. * menu idx 0 = auto, idx 1 = manual
  222. */
  223. pdev->exposure_auto = v4l2_ctrl_new_std_menu(hdl,
  224. &pwc_ctrl_ops,
  225. V4L2_CID_EXPOSURE_AUTO,
  226. 1, 0, def != 0);
  227. if (!pdev->exposure_auto)
  228. return hdl->error;
  229. /* GET_LUM_CTL, PRESET_SHUTTER_FORMATTER is unreliable */
  230. r = pwc_get_u16_ctrl(pdev, GET_STATUS_CTL,
  231. READ_SHUTTER_FORMATTER, &def);
  232. if (r || def > 655)
  233. def = 655;
  234. pdev->exposure = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops,
  235. V4L2_CID_EXPOSURE, 0, 655, 1, def);
  236. /* CODEC2: separate auto gain & auto exposure */
  237. v4l2_ctrl_auto_cluster(2, &pdev->autogain, 0, true);
  238. v4l2_ctrl_auto_cluster(2, &pdev->exposure_auto,
  239. V4L2_EXPOSURE_MANUAL, true);
  240. } else if (DEVICE_USE_CODEC3(pdev->type)) {
  241. /* GET_LUM_CTL, PRESET_SHUTTER_FORMATTER is unreliable */
  242. r = pwc_get_u16_ctrl(pdev, GET_STATUS_CTL,
  243. READ_SHUTTER_FORMATTER, &def);
  244. if (r || def > 255)
  245. def = 255;
  246. pdev->exposure = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops,
  247. V4L2_CID_EXPOSURE, 0, 255, 1, def);
  248. /* CODEC3: both gain and exposure controlled by autogain */
  249. pdev->autogain_expo_cluster[0] = pdev->autogain;
  250. pdev->autogain_expo_cluster[1] = pdev->gain;
  251. pdev->autogain_expo_cluster[2] = pdev->exposure;
  252. v4l2_ctrl_auto_cluster(3, pdev->autogain_expo_cluster,
  253. 0, true);
  254. }
  255. /* color / bw setting */
  256. r = pwc_get_u8_ctrl(pdev, GET_CHROM_CTL, COLOUR_MODE_FORMATTER,
  257. &def);
  258. if (r || (def != 0 && def != 0xff))
  259. def = 0xff;
  260. /* def = 0 bw, def = ff color, menu idx 0 = color, idx 1 = bw */
  261. pdev->colorfx = v4l2_ctrl_new_std_menu(hdl, &pwc_ctrl_ops,
  262. V4L2_CID_COLORFX, 1, 0, def == 0);
  263. /* autocontour, contour */
  264. r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL, AUTO_CONTOUR_FORMATTER, &def);
  265. if (r || (def != 0 && def != 0xff))
  266. def = 0;
  267. cfg = pwc_autocontour_cfg;
  268. cfg.def = def == 0;
  269. pdev->autocontour = v4l2_ctrl_new_custom(hdl, &cfg, NULL);
  270. if (!pdev->autocontour)
  271. return hdl->error;
  272. r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL, PRESET_CONTOUR_FORMATTER, &def);
  273. if (r || def > 63)
  274. def = 31;
  275. cfg = pwc_contour_cfg;
  276. cfg.def = def;
  277. pdev->contour = v4l2_ctrl_new_custom(hdl, &cfg, NULL);
  278. v4l2_ctrl_auto_cluster(2, &pdev->autocontour, 0, false);
  279. /* backlight */
  280. r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL,
  281. BACK_LIGHT_COMPENSATION_FORMATTER, &def);
  282. if (r || (def != 0 && def != 0xff))
  283. def = 0;
  284. cfg = pwc_backlight_cfg;
  285. cfg.name = v4l2_ctrl_get_name(cfg.id);
  286. cfg.def = def == 0;
  287. pdev->backlight = v4l2_ctrl_new_custom(hdl, &cfg, NULL);
  288. /* flikker rediction */
  289. r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL,
  290. FLICKERLESS_MODE_FORMATTER, &def);
  291. if (r || (def != 0 && def != 0xff))
  292. def = 0;
  293. cfg = pwc_flicker_cfg;
  294. cfg.name = v4l2_ctrl_get_name(cfg.id);
  295. cfg.def = def == 0;
  296. pdev->flicker = v4l2_ctrl_new_custom(hdl, &cfg, NULL);
  297. /* Dynamic noise reduction */
  298. r = pwc_get_u8_ctrl(pdev, GET_LUM_CTL,
  299. DYNAMIC_NOISE_CONTROL_FORMATTER, &def);
  300. if (r || def > 3)
  301. def = 2;
  302. cfg = pwc_noise_reduction_cfg;
  303. cfg.def = def;
  304. pdev->noise_reduction = v4l2_ctrl_new_custom(hdl, &cfg, NULL);
  305. /* Save / Restore User / Factory Settings */
  306. pdev->save_user = v4l2_ctrl_new_custom(hdl, &pwc_save_user_cfg, NULL);
  307. pdev->restore_user = v4l2_ctrl_new_custom(hdl, &pwc_restore_user_cfg,
  308. NULL);
  309. if (pdev->restore_user)
  310. pdev->restore_user->flags |= V4L2_CTRL_FLAG_UPDATE;
  311. pdev->restore_factory = v4l2_ctrl_new_custom(hdl,
  312. &pwc_restore_factory_cfg,
  313. NULL);
  314. if (pdev->restore_factory)
  315. pdev->restore_factory->flags |= V4L2_CTRL_FLAG_UPDATE;
  316. /* Auto White Balance speed & delay */
  317. r = pwc_get_u8_ctrl(pdev, GET_CHROM_CTL,
  318. AWB_CONTROL_SPEED_FORMATTER, &def);
  319. if (r || def < 1 || def > 32)
  320. def = 1;
  321. cfg = pwc_awb_speed_cfg;
  322. cfg.def = def;
  323. pdev->awb_speed = v4l2_ctrl_new_custom(hdl, &cfg, NULL);
  324. r = pwc_get_u8_ctrl(pdev, GET_CHROM_CTL,
  325. AWB_CONTROL_DELAY_FORMATTER, &def);
  326. if (r || def > 63)
  327. def = 0;
  328. cfg = pwc_awb_delay_cfg;
  329. cfg.def = def;
  330. pdev->awb_delay = v4l2_ctrl_new_custom(hdl, &cfg, NULL);
  331. if (!(pdev->features & FEATURE_MOTOR_PANTILT))
  332. return hdl->error;
  333. /* Motor pan / tilt / reset */
  334. pdev->motor_pan = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops,
  335. V4L2_CID_PAN_RELATIVE, -4480, 4480, 64, 0);
  336. if (!pdev->motor_pan)
  337. return hdl->error;
  338. pdev->motor_tilt = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops,
  339. V4L2_CID_TILT_RELATIVE, -1920, 1920, 64, 0);
  340. pdev->motor_pan_reset = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops,
  341. V4L2_CID_PAN_RESET, 0, 0, 0, 0);
  342. pdev->motor_tilt_reset = v4l2_ctrl_new_std(hdl, &pwc_ctrl_ops,
  343. V4L2_CID_TILT_RESET, 0, 0, 0, 0);
  344. v4l2_ctrl_cluster(4, &pdev->motor_pan);
  345. return hdl->error;
  346. }
  347. static void pwc_vidioc_fill_fmt(const struct pwc_device *pdev, struct v4l2_format *f)
  348. {
  349. memset(&f->fmt.pix, 0, sizeof(struct v4l2_pix_format));
  350. f->fmt.pix.width = pdev->width;
  351. f->fmt.pix.height = pdev->height;
  352. f->fmt.pix.field = V4L2_FIELD_NONE;
  353. if (pdev->pixfmt == V4L2_PIX_FMT_YUV420) {
  354. f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420;
  355. f->fmt.pix.bytesperline = (f->fmt.pix.width * 3)/2;
  356. f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
  357. } else {
  358. /* vbandlength contains 4 lines ... */
  359. f->fmt.pix.bytesperline = pdev->vbandlength/4;
  360. f->fmt.pix.sizeimage = pdev->frame_size + sizeof(struct pwc_raw_frame);
  361. if (DEVICE_USE_CODEC1(pdev->type))
  362. f->fmt.pix.pixelformat = V4L2_PIX_FMT_PWC1;
  363. else
  364. f->fmt.pix.pixelformat = V4L2_PIX_FMT_PWC2;
  365. }
  366. PWC_DEBUG_IOCTL("pwc_vidioc_fill_fmt() "
  367. "width=%d, height=%d, bytesperline=%d, sizeimage=%d, pixelformat=%c%c%c%c\n",
  368. f->fmt.pix.width,
  369. f->fmt.pix.height,
  370. f->fmt.pix.bytesperline,
  371. f->fmt.pix.sizeimage,
  372. (f->fmt.pix.pixelformat)&255,
  373. (f->fmt.pix.pixelformat>>8)&255,
  374. (f->fmt.pix.pixelformat>>16)&255,
  375. (f->fmt.pix.pixelformat>>24)&255);
  376. }
  377. /* ioctl(VIDIOC_TRY_FMT) */
  378. static int pwc_vidioc_try_fmt(struct pwc_device *pdev, struct v4l2_format *f)
  379. {
  380. int size;
  381. if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
  382. PWC_DEBUG_IOCTL("Bad video type must be V4L2_BUF_TYPE_VIDEO_CAPTURE\n");
  383. return -EINVAL;
  384. }
  385. switch (f->fmt.pix.pixelformat) {
  386. case V4L2_PIX_FMT_YUV420:
  387. break;
  388. case V4L2_PIX_FMT_PWC1:
  389. if (DEVICE_USE_CODEC23(pdev->type)) {
  390. PWC_DEBUG_IOCTL("codec1 is only supported for old pwc webcam\n");
  391. return -EINVAL;
  392. }
  393. break;
  394. case V4L2_PIX_FMT_PWC2:
  395. if (DEVICE_USE_CODEC1(pdev->type)) {
  396. PWC_DEBUG_IOCTL("codec23 is only supported for new pwc webcam\n");
  397. return -EINVAL;
  398. }
  399. break;
  400. default:
  401. PWC_DEBUG_IOCTL("Unsupported pixel format\n");
  402. return -EINVAL;
  403. }
  404. size = pwc_get_size(pdev, f->fmt.pix.width, f->fmt.pix.height);
  405. f->fmt.pix.width = pwc_image_sizes[size][0];
  406. f->fmt.pix.height = pwc_image_sizes[size][1];
  407. return 0;
  408. }
  409. /* ioctl(VIDIOC_SET_FMT) */
  410. static int pwc_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f)
  411. {
  412. struct pwc_device *pdev = video_drvdata(file);
  413. int ret, pixelformat;
  414. if (pwc_test_n_set_capt_file(pdev, file))
  415. return -EBUSY;
  416. ret = pwc_vidioc_try_fmt(pdev, f);
  417. if (ret < 0)
  418. return ret;
  419. pixelformat = f->fmt.pix.pixelformat;
  420. if (pixelformat != V4L2_PIX_FMT_YUV420 &&
  421. pixelformat != V4L2_PIX_FMT_PWC1 &&
  422. pixelformat != V4L2_PIX_FMT_PWC2)
  423. return -EINVAL;
  424. mutex_lock(&pdev->udevlock);
  425. if (!pdev->udev) {
  426. ret = -ENODEV;
  427. goto leave;
  428. }
  429. if (pdev->iso_init) {
  430. ret = -EBUSY;
  431. goto leave;
  432. }
  433. PWC_DEBUG_IOCTL("Trying to set format to: width=%d height=%d fps=%d "
  434. "compression=%d format=%c%c%c%c\n",
  435. f->fmt.pix.width, f->fmt.pix.height, pdev->vframes,
  436. pdev->vcompression,
  437. (pixelformat)&255,
  438. (pixelformat>>8)&255,
  439. (pixelformat>>16)&255,
  440. (pixelformat>>24)&255);
  441. ret = pwc_set_video_mode(pdev,
  442. f->fmt.pix.width,
  443. f->fmt.pix.height,
  444. pdev->vframes,
  445. pdev->vcompression);
  446. PWC_DEBUG_IOCTL("pwc_set_video_mode(), return=%d\n", ret);
  447. if (ret == 0) {
  448. pdev->pixfmt = pixelformat;
  449. pwc_vidioc_fill_fmt(pdev, f);
  450. }
  451. leave:
  452. mutex_unlock(&pdev->udevlock);
  453. return ret;
  454. }
  455. static int pwc_querycap(struct file *file, void *fh, struct v4l2_capability *cap)
  456. {
  457. struct pwc_device *pdev = video_drvdata(file);
  458. if (!pdev->udev)
  459. return -ENODEV;
  460. strcpy(cap->driver, PWC_NAME);
  461. strlcpy(cap->card, pdev->vdev.name, sizeof(cap->card));
  462. usb_make_path(pdev->udev, cap->bus_info, sizeof(cap->bus_info));
  463. cap->capabilities =
  464. V4L2_CAP_VIDEO_CAPTURE |
  465. V4L2_CAP_STREAMING |
  466. V4L2_CAP_READWRITE;
  467. return 0;
  468. }
  469. static int pwc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
  470. {
  471. if (i->index) /* Only one INPUT is supported */
  472. return -EINVAL;
  473. strcpy(i->name, "usb");
  474. return 0;
  475. }
  476. static int pwc_g_input(struct file *file, void *fh, unsigned int *i)
  477. {
  478. *i = 0;
  479. return 0;
  480. }
  481. static int pwc_s_input(struct file *file, void *fh, unsigned int i)
  482. {
  483. return i ? -EINVAL : 0;
  484. }
  485. static int pwc_g_volatile_ctrl_unlocked(struct v4l2_ctrl *ctrl)
  486. {
  487. struct pwc_device *pdev =
  488. container_of(ctrl->handler, struct pwc_device, ctrl_handler);
  489. int ret = 0;
  490. if (!pdev->udev)
  491. return -ENODEV;
  492. switch (ctrl->id) {
  493. case V4L2_CID_AUTO_WHITE_BALANCE:
  494. if (pdev->color_bal_valid &&
  495. (pdev->auto_white_balance->val != awb_auto ||
  496. time_before(jiffies,
  497. pdev->last_color_bal_update + HZ / 4))) {
  498. pdev->red_balance->val = pdev->last_red_balance;
  499. pdev->blue_balance->val = pdev->last_blue_balance;
  500. break;
  501. }
  502. ret = pwc_get_u8_ctrl(pdev, GET_STATUS_CTL,
  503. READ_RED_GAIN_FORMATTER,
  504. &pdev->red_balance->val);
  505. if (ret)
  506. break;
  507. ret = pwc_get_u8_ctrl(pdev, GET_STATUS_CTL,
  508. READ_BLUE_GAIN_FORMATTER,
  509. &pdev->blue_balance->val);
  510. if (ret)
  511. break;
  512. pdev->last_red_balance = pdev->red_balance->val;
  513. pdev->last_blue_balance = pdev->blue_balance->val;
  514. pdev->last_color_bal_update = jiffies;
  515. pdev->color_bal_valid = true;
  516. break;
  517. case V4L2_CID_AUTOGAIN:
  518. if (pdev->gain_valid && time_before(jiffies,
  519. pdev->last_gain_update + HZ / 4)) {
  520. pdev->gain->val = pdev->last_gain;
  521. break;
  522. }
  523. ret = pwc_get_u8_ctrl(pdev, GET_STATUS_CTL,
  524. READ_AGC_FORMATTER, &pdev->gain->val);
  525. if (ret)
  526. break;
  527. pdev->last_gain = pdev->gain->val;
  528. pdev->last_gain_update = jiffies;
  529. pdev->gain_valid = true;
  530. if (!DEVICE_USE_CODEC3(pdev->type))
  531. break;
  532. /* Fall through for CODEC3 where autogain also controls expo */
  533. case V4L2_CID_EXPOSURE_AUTO:
  534. if (pdev->exposure_valid && time_before(jiffies,
  535. pdev->last_exposure_update + HZ / 4)) {
  536. pdev->exposure->val = pdev->last_exposure;
  537. break;
  538. }
  539. ret = pwc_get_u16_ctrl(pdev, GET_STATUS_CTL,
  540. READ_SHUTTER_FORMATTER,
  541. &pdev->exposure->val);
  542. if (ret)
  543. break;
  544. pdev->last_exposure = pdev->exposure->val;
  545. pdev->last_exposure_update = jiffies;
  546. pdev->exposure_valid = true;
  547. break;
  548. default:
  549. ret = -EINVAL;
  550. }
  551. if (ret)
  552. PWC_ERROR("g_ctrl %s error %d\n", ctrl->name, ret);
  553. return ret;
  554. }
  555. static int pwc_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
  556. {
  557. struct pwc_device *pdev =
  558. container_of(ctrl->handler, struct pwc_device, ctrl_handler);
  559. int ret;
  560. mutex_lock(&pdev->udevlock);
  561. ret = pwc_g_volatile_ctrl_unlocked(ctrl);
  562. mutex_unlock(&pdev->udevlock);
  563. return ret;
  564. }
  565. static int pwc_set_awb(struct pwc_device *pdev)
  566. {
  567. int ret;
  568. if (pdev->auto_white_balance->is_new) {
  569. ret = pwc_set_u8_ctrl(pdev, SET_CHROM_CTL,
  570. WB_MODE_FORMATTER,
  571. pdev->auto_white_balance->val);
  572. if (ret)
  573. return ret;
  574. if (pdev->auto_white_balance->val != awb_manual)
  575. pdev->color_bal_valid = false; /* Force cache update */
  576. /*
  577. * If this is a preset, update our red / blue balance values
  578. * so that events get generated for the new preset values
  579. */
  580. if (pdev->auto_white_balance->val == awb_indoor ||
  581. pdev->auto_white_balance->val == awb_outdoor ||
  582. pdev->auto_white_balance->val == awb_fl)
  583. pwc_g_volatile_ctrl_unlocked(pdev->auto_white_balance);
  584. }
  585. if (pdev->auto_white_balance->val != awb_manual)
  586. return 0;
  587. if (pdev->red_balance->is_new) {
  588. ret = pwc_set_u8_ctrl(pdev, SET_CHROM_CTL,
  589. PRESET_MANUAL_RED_GAIN_FORMATTER,
  590. pdev->red_balance->val);
  591. if (ret)
  592. return ret;
  593. }
  594. if (pdev->blue_balance->is_new) {
  595. ret = pwc_set_u8_ctrl(pdev, SET_CHROM_CTL,
  596. PRESET_MANUAL_BLUE_GAIN_FORMATTER,
  597. pdev->blue_balance->val);
  598. if (ret)
  599. return ret;
  600. }
  601. return 0;
  602. }
  603. /* For CODEC2 models which have separate autogain and auto exposure */
  604. static int pwc_set_autogain(struct pwc_device *pdev)
  605. {
  606. int ret;
  607. if (pdev->autogain->is_new) {
  608. ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL,
  609. AGC_MODE_FORMATTER,
  610. pdev->autogain->val ? 0 : 0xff);
  611. if (ret)
  612. return ret;
  613. if (pdev->autogain->val)
  614. pdev->gain_valid = false; /* Force cache update */
  615. }
  616. if (pdev->autogain->val)
  617. return 0;
  618. if (pdev->gain->is_new) {
  619. ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL,
  620. PRESET_AGC_FORMATTER,
  621. pdev->gain->val);
  622. if (ret)
  623. return ret;
  624. }
  625. return 0;
  626. }
  627. /* For CODEC2 models which have separate autogain and auto exposure */
  628. static int pwc_set_exposure_auto(struct pwc_device *pdev)
  629. {
  630. int ret;
  631. int is_auto = pdev->exposure_auto->val == V4L2_EXPOSURE_AUTO;
  632. if (pdev->exposure_auto->is_new) {
  633. ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL,
  634. SHUTTER_MODE_FORMATTER,
  635. is_auto ? 0 : 0xff);
  636. if (ret)
  637. return ret;
  638. if (is_auto)
  639. pdev->exposure_valid = false; /* Force cache update */
  640. }
  641. if (is_auto)
  642. return 0;
  643. if (pdev->exposure->is_new) {
  644. ret = pwc_set_u16_ctrl(pdev, SET_LUM_CTL,
  645. PRESET_SHUTTER_FORMATTER,
  646. pdev->exposure->val);
  647. if (ret)
  648. return ret;
  649. }
  650. return 0;
  651. }
  652. /* For CODEC3 models which have autogain controlling both gain and exposure */
  653. static int pwc_set_autogain_expo(struct pwc_device *pdev)
  654. {
  655. int ret;
  656. if (pdev->autogain->is_new) {
  657. ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL,
  658. AGC_MODE_FORMATTER,
  659. pdev->autogain->val ? 0 : 0xff);
  660. if (ret)
  661. return ret;
  662. if (pdev->autogain->val) {
  663. pdev->gain_valid = false; /* Force cache update */
  664. pdev->exposure_valid = false; /* Force cache update */
  665. }
  666. }
  667. if (pdev->autogain->val)
  668. return 0;
  669. if (pdev->gain->is_new) {
  670. ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL,
  671. PRESET_AGC_FORMATTER,
  672. pdev->gain->val);
  673. if (ret)
  674. return ret;
  675. }
  676. if (pdev->exposure->is_new) {
  677. ret = pwc_set_u16_ctrl(pdev, SET_LUM_CTL,
  678. PRESET_SHUTTER_FORMATTER,
  679. pdev->exposure->val);
  680. if (ret)
  681. return ret;
  682. }
  683. return 0;
  684. }
  685. static int pwc_set_motor(struct pwc_device *pdev)
  686. {
  687. int ret;
  688. u8 buf[4];
  689. buf[0] = 0;
  690. if (pdev->motor_pan_reset->is_new)
  691. buf[0] |= 0x01;
  692. if (pdev->motor_tilt_reset->is_new)
  693. buf[0] |= 0x02;
  694. if (pdev->motor_pan_reset->is_new || pdev->motor_tilt_reset->is_new) {
  695. ret = send_control_msg(pdev, SET_MPT_CTL,
  696. PT_RESET_CONTROL_FORMATTER, buf, 1);
  697. if (ret < 0)
  698. return ret;
  699. }
  700. memset(buf, 0, sizeof(buf));
  701. if (pdev->motor_pan->is_new) {
  702. buf[0] = pdev->motor_pan->val & 0xFF;
  703. buf[1] = (pdev->motor_pan->val >> 8);
  704. }
  705. if (pdev->motor_tilt->is_new) {
  706. buf[2] = pdev->motor_tilt->val & 0xFF;
  707. buf[3] = (pdev->motor_tilt->val >> 8);
  708. }
  709. if (pdev->motor_pan->is_new || pdev->motor_tilt->is_new) {
  710. ret = send_control_msg(pdev, SET_MPT_CTL,
  711. PT_RELATIVE_CONTROL_FORMATTER,
  712. buf, sizeof(buf));
  713. if (ret < 0)
  714. return ret;
  715. }
  716. return 0;
  717. }
  718. static int pwc_s_ctrl(struct v4l2_ctrl *ctrl)
  719. {
  720. struct pwc_device *pdev =
  721. container_of(ctrl->handler, struct pwc_device, ctrl_handler);
  722. int ret = 0;
  723. mutex_lock(&pdev->udevlock);
  724. if (!pdev->udev) {
  725. ret = -ENODEV;
  726. goto leave;
  727. }
  728. switch (ctrl->id) {
  729. case V4L2_CID_BRIGHTNESS:
  730. ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL,
  731. BRIGHTNESS_FORMATTER, ctrl->val);
  732. break;
  733. case V4L2_CID_CONTRAST:
  734. ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL,
  735. CONTRAST_FORMATTER, ctrl->val);
  736. break;
  737. case V4L2_CID_SATURATION:
  738. ret = pwc_set_s8_ctrl(pdev, SET_CHROM_CTL,
  739. pdev->saturation_fmt, ctrl->val);
  740. break;
  741. case V4L2_CID_GAMMA:
  742. ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL,
  743. GAMMA_FORMATTER, ctrl->val);
  744. break;
  745. case V4L2_CID_AUTO_WHITE_BALANCE:
  746. ret = pwc_set_awb(pdev);
  747. break;
  748. case V4L2_CID_AUTOGAIN:
  749. if (DEVICE_USE_CODEC2(pdev->type))
  750. ret = pwc_set_autogain(pdev);
  751. else if (DEVICE_USE_CODEC3(pdev->type))
  752. ret = pwc_set_autogain_expo(pdev);
  753. else
  754. ret = -EINVAL;
  755. break;
  756. case V4L2_CID_EXPOSURE_AUTO:
  757. if (DEVICE_USE_CODEC2(pdev->type))
  758. ret = pwc_set_exposure_auto(pdev);
  759. else
  760. ret = -EINVAL;
  761. break;
  762. case V4L2_CID_COLORFX:
  763. ret = pwc_set_u8_ctrl(pdev, SET_CHROM_CTL,
  764. COLOUR_MODE_FORMATTER,
  765. ctrl->val ? 0 : 0xff);
  766. break;
  767. case PWC_CID_CUSTOM(autocontour):
  768. if (pdev->autocontour->is_new) {
  769. ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL,
  770. AUTO_CONTOUR_FORMATTER,
  771. pdev->autocontour->val ? 0 : 0xff);
  772. }
  773. if (ret == 0 && pdev->contour->is_new) {
  774. ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL,
  775. PRESET_CONTOUR_FORMATTER,
  776. pdev->contour->val);
  777. }
  778. break;
  779. case V4L2_CID_BACKLIGHT_COMPENSATION:
  780. ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL,
  781. BACK_LIGHT_COMPENSATION_FORMATTER,
  782. ctrl->val ? 0 : 0xff);
  783. break;
  784. case V4L2_CID_BAND_STOP_FILTER:
  785. ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL,
  786. FLICKERLESS_MODE_FORMATTER,
  787. ctrl->val ? 0 : 0xff);
  788. break;
  789. case PWC_CID_CUSTOM(noise_reduction):
  790. ret = pwc_set_u8_ctrl(pdev, SET_LUM_CTL,
  791. DYNAMIC_NOISE_CONTROL_FORMATTER,
  792. ctrl->val);
  793. break;
  794. case PWC_CID_CUSTOM(save_user):
  795. ret = pwc_button_ctrl(pdev, SAVE_USER_DEFAULTS_FORMATTER);
  796. break;
  797. case PWC_CID_CUSTOM(restore_user):
  798. ret = pwc_button_ctrl(pdev, RESTORE_USER_DEFAULTS_FORMATTER);
  799. break;
  800. case PWC_CID_CUSTOM(restore_factory):
  801. ret = pwc_button_ctrl(pdev,
  802. RESTORE_FACTORY_DEFAULTS_FORMATTER);
  803. break;
  804. case PWC_CID_CUSTOM(awb_speed):
  805. ret = pwc_set_u8_ctrl(pdev, SET_CHROM_CTL,
  806. AWB_CONTROL_SPEED_FORMATTER,
  807. ctrl->val);
  808. break;
  809. case PWC_CID_CUSTOM(awb_delay):
  810. ret = pwc_set_u8_ctrl(pdev, SET_CHROM_CTL,
  811. AWB_CONTROL_DELAY_FORMATTER,
  812. ctrl->val);
  813. break;
  814. case V4L2_CID_PAN_RELATIVE:
  815. ret = pwc_set_motor(pdev);
  816. break;
  817. default:
  818. ret = -EINVAL;
  819. }
  820. if (ret)
  821. PWC_ERROR("s_ctrl %s error %d\n", ctrl->name, ret);
  822. leave:
  823. mutex_unlock(&pdev->udevlock);
  824. return ret;
  825. }
  826. static int pwc_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *f)
  827. {
  828. struct pwc_device *pdev = video_drvdata(file);
  829. /* We only support two format: the raw format, and YUV */
  830. switch (f->index) {
  831. case 0:
  832. /* RAW format */
  833. f->pixelformat = pdev->type <= 646 ? V4L2_PIX_FMT_PWC1 : V4L2_PIX_FMT_PWC2;
  834. f->flags = V4L2_FMT_FLAG_COMPRESSED;
  835. strlcpy(f->description, "Raw Philips Webcam", sizeof(f->description));
  836. break;
  837. case 1:
  838. f->pixelformat = V4L2_PIX_FMT_YUV420;
  839. strlcpy(f->description, "4:2:0, planar, Y-Cb-Cr", sizeof(f->description));
  840. break;
  841. default:
  842. return -EINVAL;
  843. }
  844. return 0;
  845. }
  846. static int pwc_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f)
  847. {
  848. struct pwc_device *pdev = video_drvdata(file);
  849. mutex_lock(&pdev->udevlock); /* To avoid race with s_fmt */
  850. PWC_DEBUG_IOCTL("ioctl(VIDIOC_G_FMT) return size %dx%d\n",
  851. pdev->width, pdev->height);
  852. pwc_vidioc_fill_fmt(pdev, f);
  853. mutex_unlock(&pdev->udevlock);
  854. return 0;
  855. }
  856. static int pwc_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f)
  857. {
  858. struct pwc_device *pdev = video_drvdata(file);
  859. return pwc_vidioc_try_fmt(pdev, f);
  860. }
  861. static int pwc_reqbufs(struct file *file, void *fh,
  862. struct v4l2_requestbuffers *rb)
  863. {
  864. struct pwc_device *pdev = video_drvdata(file);
  865. if (pwc_test_n_set_capt_file(pdev, file))
  866. return -EBUSY;
  867. return vb2_reqbufs(&pdev->vb_queue, rb);
  868. }
  869. static int pwc_querybuf(struct file *file, void *fh, struct v4l2_buffer *buf)
  870. {
  871. struct pwc_device *pdev = video_drvdata(file);
  872. return vb2_querybuf(&pdev->vb_queue, buf);
  873. }
  874. static int pwc_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
  875. {
  876. struct pwc_device *pdev = video_drvdata(file);
  877. if (!pdev->udev)
  878. return -ENODEV;
  879. if (pdev->capt_file != file)
  880. return -EBUSY;
  881. return vb2_qbuf(&pdev->vb_queue, buf);
  882. }
  883. static int pwc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
  884. {
  885. struct pwc_device *pdev = video_drvdata(file);
  886. if (!pdev->udev)
  887. return -ENODEV;
  888. if (pdev->capt_file != file)
  889. return -EBUSY;
  890. return vb2_dqbuf(&pdev->vb_queue, buf, file->f_flags & O_NONBLOCK);
  891. }
  892. static int pwc_streamon(struct file *file, void *fh, enum v4l2_buf_type i)
  893. {
  894. struct pwc_device *pdev = video_drvdata(file);
  895. if (!pdev->udev)
  896. return -ENODEV;
  897. if (pdev->capt_file != file)
  898. return -EBUSY;
  899. return vb2_streamon(&pdev->vb_queue, i);
  900. }
  901. static int pwc_streamoff(struct file *file, void *fh, enum v4l2_buf_type i)
  902. {
  903. struct pwc_device *pdev = video_drvdata(file);
  904. if (!pdev->udev)
  905. return -ENODEV;
  906. if (pdev->capt_file != file)
  907. return -EBUSY;
  908. return vb2_streamoff(&pdev->vb_queue, i);
  909. }
  910. static int pwc_enum_framesizes(struct file *file, void *fh,
  911. struct v4l2_frmsizeenum *fsize)
  912. {
  913. struct pwc_device *pdev = video_drvdata(file);
  914. unsigned int i = 0, index = fsize->index;
  915. if (fsize->pixel_format == V4L2_PIX_FMT_YUV420 ||
  916. (fsize->pixel_format == V4L2_PIX_FMT_PWC1 &&
  917. DEVICE_USE_CODEC1(pdev->type)) ||
  918. (fsize->pixel_format == V4L2_PIX_FMT_PWC2 &&
  919. DEVICE_USE_CODEC23(pdev->type))) {
  920. for (i = 0; i < PSZ_MAX; i++) {
  921. if (!(pdev->image_mask & (1UL << i)))
  922. continue;
  923. if (!index--) {
  924. fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
  925. fsize->discrete.width = pwc_image_sizes[i][0];
  926. fsize->discrete.height = pwc_image_sizes[i][1];
  927. return 0;
  928. }
  929. }
  930. }
  931. return -EINVAL;
  932. }
  933. static int pwc_enum_frameintervals(struct file *file, void *fh,
  934. struct v4l2_frmivalenum *fival)
  935. {
  936. struct pwc_device *pdev = video_drvdata(file);
  937. int size = -1;
  938. unsigned int i;
  939. for (i = 0; i < PSZ_MAX; i++) {
  940. if (pwc_image_sizes[i][0] == fival->width &&
  941. pwc_image_sizes[i][1] == fival->height) {
  942. size = i;
  943. break;
  944. }
  945. }
  946. /* TODO: Support raw format */
  947. if (size < 0 || fival->pixel_format != V4L2_PIX_FMT_YUV420)
  948. return -EINVAL;
  949. i = pwc_get_fps(pdev, fival->index, size);
  950. if (!i)
  951. return -EINVAL;
  952. fival->type = V4L2_FRMIVAL_TYPE_DISCRETE;
  953. fival->discrete.numerator = 1;
  954. fival->discrete.denominator = i;
  955. return 0;
  956. }
  957. static int pwc_log_status(struct file *file, void *priv)
  958. {
  959. struct pwc_device *pdev = video_drvdata(file);
  960. v4l2_ctrl_handler_log_status(&pdev->ctrl_handler, PWC_NAME);
  961. return 0;
  962. }
  963. const struct v4l2_ioctl_ops pwc_ioctl_ops = {
  964. .vidioc_querycap = pwc_querycap,
  965. .vidioc_enum_input = pwc_enum_input,
  966. .vidioc_g_input = pwc_g_input,
  967. .vidioc_s_input = pwc_s_input,
  968. .vidioc_enum_fmt_vid_cap = pwc_enum_fmt_vid_cap,
  969. .vidioc_g_fmt_vid_cap = pwc_g_fmt_vid_cap,
  970. .vidioc_s_fmt_vid_cap = pwc_s_fmt_vid_cap,
  971. .vidioc_try_fmt_vid_cap = pwc_try_fmt_vid_cap,
  972. .vidioc_reqbufs = pwc_reqbufs,
  973. .vidioc_querybuf = pwc_querybuf,
  974. .vidioc_qbuf = pwc_qbuf,
  975. .vidioc_dqbuf = pwc_dqbuf,
  976. .vidioc_streamon = pwc_streamon,
  977. .vidioc_streamoff = pwc_streamoff,
  978. .vidioc_log_status = pwc_log_status,
  979. .vidioc_enum_framesizes = pwc_enum_framesizes,
  980. .vidioc_enum_frameintervals = pwc_enum_frameintervals,
  981. };