t613.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  1. /*
  2. * T613 subdriver
  3. *
  4. * Copyright (C) 2010 Jean-Francois Moine (http://moinejf.free.fr)
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. *Notes: * t613 + tas5130A
  21. * * Focus to light do not balance well as in win.
  22. * Quality in win is not good, but its kinda better.
  23. * * Fix some "extraneous bytes", most of apps will show the image anyway
  24. * * Gamma table, is there, but its really doing something?
  25. * * 7~8 Fps, its ok, max on win its 10.
  26. * Costantino Leandro
  27. */
  28. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  29. #define MODULE_NAME "t613"
  30. #include <linux/input.h>
  31. #include <linux/slab.h>
  32. #include "gspca.h"
  33. MODULE_AUTHOR("Leandro Costantino <le_costantino@pixartargentina.com.ar>");
  34. MODULE_DESCRIPTION("GSPCA/T613 (JPEG Compliance) USB Camera Driver");
  35. MODULE_LICENSE("GPL");
  36. struct sd {
  37. struct gspca_dev gspca_dev; /* !! must be the first item */
  38. struct v4l2_ctrl *freq;
  39. struct { /* awb / color gains control cluster */
  40. struct v4l2_ctrl *awb;
  41. struct v4l2_ctrl *gain;
  42. struct v4l2_ctrl *red_balance;
  43. struct v4l2_ctrl *blue_balance;
  44. };
  45. u8 sensor;
  46. u8 button_pressed;
  47. };
  48. enum sensors {
  49. SENSOR_OM6802,
  50. SENSOR_OTHER,
  51. SENSOR_TAS5130A,
  52. SENSOR_LT168G, /* must verify if this is the actual model */
  53. };
  54. static const struct v4l2_pix_format vga_mode_t16[] = {
  55. {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  56. .bytesperline = 160,
  57. .sizeimage = 160 * 120 * 4 / 8 + 590,
  58. .colorspace = V4L2_COLORSPACE_JPEG,
  59. .priv = 4},
  60. #if 0 /* HDG: broken with my test cam, so lets disable it */
  61. {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  62. .bytesperline = 176,
  63. .sizeimage = 176 * 144 * 3 / 8 + 590,
  64. .colorspace = V4L2_COLORSPACE_JPEG,
  65. .priv = 3},
  66. #endif
  67. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  68. .bytesperline = 320,
  69. .sizeimage = 320 * 240 * 3 / 8 + 590,
  70. .colorspace = V4L2_COLORSPACE_JPEG,
  71. .priv = 2},
  72. #if 0 /* HDG: broken with my test cam, so lets disable it */
  73. {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  74. .bytesperline = 352,
  75. .sizeimage = 352 * 288 * 3 / 8 + 590,
  76. .colorspace = V4L2_COLORSPACE_JPEG,
  77. .priv = 1},
  78. #endif
  79. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  80. .bytesperline = 640,
  81. .sizeimage = 640 * 480 * 3 / 8 + 590,
  82. .colorspace = V4L2_COLORSPACE_JPEG,
  83. .priv = 0},
  84. };
  85. /* sensor specific data */
  86. struct additional_sensor_data {
  87. const u8 n3[6];
  88. const u8 *n4, n4sz;
  89. const u8 reg80, reg8e;
  90. const u8 nset8[6];
  91. const u8 data1[10];
  92. const u8 data2[9];
  93. const u8 data3[9];
  94. const u8 data5[6];
  95. const u8 stream[4];
  96. };
  97. static const u8 n4_om6802[] = {
  98. 0x09, 0x01, 0x12, 0x04, 0x66, 0x8a, 0x80, 0x3c,
  99. 0x81, 0x22, 0x84, 0x50, 0x8a, 0x78, 0x8b, 0x68,
  100. 0x8c, 0x88, 0x8e, 0x33, 0x8f, 0x24, 0xaa, 0xb1,
  101. 0xa2, 0x60, 0xa5, 0x30, 0xa6, 0x3a, 0xa8, 0xe8,
  102. 0xae, 0x05, 0xb1, 0x00, 0xbb, 0x04, 0xbc, 0x48,
  103. 0xbe, 0x36, 0xc6, 0x88, 0xe9, 0x00, 0xc5, 0xc0,
  104. 0x65, 0x0a, 0xbb, 0x86, 0xaf, 0x58, 0xb0, 0x68,
  105. 0x87, 0x40, 0x89, 0x2b, 0x8d, 0xff, 0x83, 0x40,
  106. 0xac, 0x84, 0xad, 0x86, 0xaf, 0x46
  107. };
  108. static const u8 n4_other[] = {
  109. 0x66, 0x00, 0x7f, 0x00, 0x80, 0xac, 0x81, 0x69,
  110. 0x84, 0x40, 0x85, 0x70, 0x86, 0x20, 0x8a, 0x68,
  111. 0x8b, 0x58, 0x8c, 0x88, 0x8d, 0xff, 0x8e, 0xb8,
  112. 0x8f, 0x28, 0xa2, 0x60, 0xa5, 0x40, 0xa8, 0xa8,
  113. 0xac, 0x84, 0xad, 0x84, 0xae, 0x24, 0xaf, 0x56,
  114. 0xb0, 0x68, 0xb1, 0x00, 0xb2, 0x88, 0xbb, 0xc5,
  115. 0xbc, 0x4a, 0xbe, 0x36, 0xc2, 0x88, 0xc5, 0xc0,
  116. 0xc6, 0xda, 0xe9, 0x26, 0xeb, 0x00
  117. };
  118. static const u8 n4_tas5130a[] = {
  119. 0x80, 0x3c, 0x81, 0x68, 0x83, 0xa0, 0x84, 0x20,
  120. 0x8a, 0x68, 0x8b, 0x58, 0x8c, 0x88, 0x8e, 0xb4,
  121. 0x8f, 0x24, 0xa1, 0xb1, 0xa2, 0x30, 0xa5, 0x10,
  122. 0xa6, 0x4a, 0xae, 0x03, 0xb1, 0x44, 0xb2, 0x08,
  123. 0xb7, 0x06, 0xb9, 0xe7, 0xbb, 0xc4, 0xbc, 0x4a,
  124. 0xbe, 0x36, 0xbf, 0xff, 0xc2, 0x88, 0xc5, 0xc8,
  125. 0xc6, 0xda
  126. };
  127. static const u8 n4_lt168g[] = {
  128. 0x66, 0x01, 0x7f, 0x00, 0x80, 0x7c, 0x81, 0x28,
  129. 0x83, 0x44, 0x84, 0x20, 0x86, 0x20, 0x8a, 0x70,
  130. 0x8b, 0x58, 0x8c, 0x88, 0x8d, 0xa0, 0x8e, 0xb3,
  131. 0x8f, 0x24, 0xa1, 0xb0, 0xa2, 0x38, 0xa5, 0x20,
  132. 0xa6, 0x4a, 0xa8, 0xe8, 0xaf, 0x38, 0xb0, 0x68,
  133. 0xb1, 0x44, 0xb2, 0x88, 0xbb, 0x86, 0xbd, 0x40,
  134. 0xbe, 0x26, 0xc1, 0x05, 0xc2, 0x88, 0xc5, 0xc0,
  135. 0xda, 0x8e, 0xdb, 0xca, 0xdc, 0xa8, 0xdd, 0x8c,
  136. 0xde, 0x44, 0xdf, 0x0c, 0xe9, 0x80
  137. };
  138. static const struct additional_sensor_data sensor_data[] = {
  139. [SENSOR_OM6802] = {
  140. .n3 =
  141. {0x61, 0x68, 0x65, 0x0a, 0x60, 0x04},
  142. .n4 = n4_om6802,
  143. .n4sz = sizeof n4_om6802,
  144. .reg80 = 0x3c,
  145. .reg8e = 0x33,
  146. .nset8 = {0xa8, 0xf0, 0xc6, 0x88, 0xc0, 0x00},
  147. .data1 =
  148. {0xc2, 0x28, 0x0f, 0x22, 0xcd, 0x27, 0x2c, 0x06,
  149. 0xb3, 0xfc},
  150. .data2 =
  151. {0x80, 0xff, 0xff, 0x80, 0xff, 0xff, 0x80, 0xff,
  152. 0xff},
  153. .data3 =
  154. {0x80, 0xff, 0xff, 0x80, 0xff, 0xff, 0x80, 0xff,
  155. 0xff},
  156. .data5 = /* this could be removed later */
  157. {0x0c, 0x03, 0xab, 0x13, 0x81, 0x23},
  158. .stream =
  159. {0x0b, 0x04, 0x0a, 0x78},
  160. },
  161. [SENSOR_OTHER] = {
  162. .n3 =
  163. {0x61, 0xc2, 0x65, 0x88, 0x60, 0x00},
  164. .n4 = n4_other,
  165. .n4sz = sizeof n4_other,
  166. .reg80 = 0xac,
  167. .reg8e = 0xb8,
  168. .nset8 = {0xa8, 0xa8, 0xc6, 0xda, 0xc0, 0x00},
  169. .data1 =
  170. {0xc1, 0x48, 0x04, 0x1b, 0xca, 0x2e, 0x33, 0x3a,
  171. 0xe8, 0xfc},
  172. .data2 =
  173. {0x4e, 0x9c, 0xec, 0x40, 0x80, 0xc0, 0x48, 0x96,
  174. 0xd9},
  175. .data3 =
  176. {0x4e, 0x9c, 0xec, 0x40, 0x80, 0xc0, 0x48, 0x96,
  177. 0xd9},
  178. .data5 =
  179. {0x0c, 0x03, 0xab, 0x29, 0x81, 0x69},
  180. .stream =
  181. {0x0b, 0x04, 0x0a, 0x00},
  182. },
  183. [SENSOR_TAS5130A] = {
  184. .n3 =
  185. {0x61, 0xc2, 0x65, 0x0d, 0x60, 0x08},
  186. .n4 = n4_tas5130a,
  187. .n4sz = sizeof n4_tas5130a,
  188. .reg80 = 0x3c,
  189. .reg8e = 0xb4,
  190. .nset8 = {0xa8, 0xf0, 0xc6, 0xda, 0xc0, 0x00},
  191. .data1 =
  192. {0xbb, 0x28, 0x10, 0x10, 0xbb, 0x28, 0x1e, 0x27,
  193. 0xc8, 0xfc},
  194. .data2 =
  195. {0x60, 0xa8, 0xe0, 0x60, 0xa8, 0xe0, 0x60, 0xa8,
  196. 0xe0},
  197. .data3 =
  198. {0x60, 0xa8, 0xe0, 0x60, 0xa8, 0xe0, 0x60, 0xa8,
  199. 0xe0},
  200. .data5 =
  201. {0x0c, 0x03, 0xab, 0x10, 0x81, 0x20},
  202. .stream =
  203. {0x0b, 0x04, 0x0a, 0x40},
  204. },
  205. [SENSOR_LT168G] = {
  206. .n3 = {0x61, 0xc2, 0x65, 0x68, 0x60, 0x00},
  207. .n4 = n4_lt168g,
  208. .n4sz = sizeof n4_lt168g,
  209. .reg80 = 0x7c,
  210. .reg8e = 0xb3,
  211. .nset8 = {0xa8, 0xf0, 0xc6, 0xba, 0xc0, 0x00},
  212. .data1 = {0xc0, 0x38, 0x08, 0x10, 0xc0, 0x30, 0x10, 0x40,
  213. 0xb0, 0xf4},
  214. .data2 = {0x40, 0x80, 0xc0, 0x50, 0xa0, 0xf0, 0x53, 0xa6,
  215. 0xff},
  216. .data3 = {0x40, 0x80, 0xc0, 0x50, 0xa0, 0xf0, 0x53, 0xa6,
  217. 0xff},
  218. .data5 = {0x0c, 0x03, 0xab, 0x4b, 0x81, 0x2b},
  219. .stream = {0x0b, 0x04, 0x0a, 0x28},
  220. },
  221. };
  222. #define MAX_EFFECTS 7
  223. static const u8 effects_table[MAX_EFFECTS][6] = {
  224. {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x00}, /* Normal */
  225. {0xa8, 0xc8, 0xc6, 0x52, 0xc0, 0x04}, /* Repujar */
  226. {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x20}, /* Monochrome */
  227. {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x80}, /* Sepia */
  228. {0xa8, 0xc8, 0xc6, 0x52, 0xc0, 0x02}, /* Croquis */
  229. {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x10}, /* Sun Effect */
  230. {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x40}, /* Negative */
  231. };
  232. #define GAMMA_MAX (15)
  233. static const u8 gamma_table[GAMMA_MAX+1][17] = {
  234. /* gamma table from cam1690.ini */
  235. {0x00, 0x00, 0x01, 0x04, 0x08, 0x0e, 0x16, 0x21, /* 0 */
  236. 0x2e, 0x3d, 0x50, 0x65, 0x7d, 0x99, 0xb8, 0xdb,
  237. 0xff},
  238. {0x00, 0x01, 0x03, 0x08, 0x0e, 0x16, 0x21, 0x2d, /* 1 */
  239. 0x3c, 0x4d, 0x60, 0x75, 0x8d, 0xa6, 0xc2, 0xe1,
  240. 0xff},
  241. {0x00, 0x01, 0x05, 0x0b, 0x12, 0x1c, 0x28, 0x35, /* 2 */
  242. 0x45, 0x56, 0x69, 0x7e, 0x95, 0xad, 0xc7, 0xe3,
  243. 0xff},
  244. {0x00, 0x02, 0x07, 0x0f, 0x18, 0x24, 0x30, 0x3f, /* 3 */
  245. 0x4f, 0x61, 0x73, 0x88, 0x9d, 0xb4, 0xcd, 0xe6,
  246. 0xff},
  247. {0x00, 0x04, 0x0b, 0x15, 0x20, 0x2d, 0x3b, 0x4a, /* 4 */
  248. 0x5b, 0x6c, 0x7f, 0x92, 0xa7, 0xbc, 0xd2, 0xe9,
  249. 0xff},
  250. {0x00, 0x07, 0x11, 0x15, 0x20, 0x2d, 0x48, 0x58, /* 5 */
  251. 0x68, 0x79, 0x8b, 0x9d, 0xb0, 0xc4, 0xd7, 0xec,
  252. 0xff},
  253. {0x00, 0x0c, 0x1a, 0x29, 0x38, 0x47, 0x57, 0x67, /* 6 */
  254. 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
  255. 0xff},
  256. {0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, /* 7 */
  257. 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0,
  258. 0xff},
  259. {0x00, 0x15, 0x27, 0x38, 0x49, 0x59, 0x69, 0x79, /* 8 */
  260. 0x88, 0x97, 0xa7, 0xb6, 0xc4, 0xd3, 0xe2, 0xf0,
  261. 0xff},
  262. {0x00, 0x1c, 0x30, 0x43, 0x54, 0x65, 0x75, 0x84, /* 9 */
  263. 0x93, 0xa1, 0xb0, 0xbd, 0xca, 0xd8, 0xe5, 0xf2,
  264. 0xff},
  265. {0x00, 0x24, 0x3b, 0x4f, 0x60, 0x70, 0x80, 0x8e, /* 10 */
  266. 0x9c, 0xaa, 0xb7, 0xc4, 0xd0, 0xdc, 0xe8, 0xf3,
  267. 0xff},
  268. {0x00, 0x2a, 0x3c, 0x5d, 0x6e, 0x7e, 0x8d, 0x9b, /* 11 */
  269. 0xa8, 0xb4, 0xc0, 0xcb, 0xd6, 0xe1, 0xeb, 0xf5,
  270. 0xff},
  271. {0x00, 0x3f, 0x5a, 0x6e, 0x7f, 0x8e, 0x9c, 0xa8, /* 12 */
  272. 0xb4, 0xbf, 0xc9, 0xd3, 0xdc, 0xe5, 0xee, 0xf6,
  273. 0xff},
  274. {0x00, 0x54, 0x6f, 0x83, 0x93, 0xa0, 0xad, 0xb7, /* 13 */
  275. 0xc2, 0xcb, 0xd4, 0xdc, 0xe4, 0xeb, 0xf2, 0xf9,
  276. 0xff},
  277. {0x00, 0x6e, 0x88, 0x9a, 0xa8, 0xb3, 0xbd, 0xc6, /* 14 */
  278. 0xcf, 0xd6, 0xdd, 0xe3, 0xe9, 0xef, 0xf4, 0xfa,
  279. 0xff},
  280. {0x00, 0x93, 0xa8, 0xb7, 0xc1, 0xca, 0xd2, 0xd8, /* 15 */
  281. 0xde, 0xe3, 0xe8, 0xed, 0xf1, 0xf5, 0xf8, 0xfc,
  282. 0xff}
  283. };
  284. static const u8 tas5130a_sensor_init[][8] = {
  285. {0x62, 0x08, 0x63, 0x70, 0x64, 0x1d, 0x60, 0x09},
  286. {0x62, 0x20, 0x63, 0x01, 0x64, 0x02, 0x60, 0x09},
  287. {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09},
  288. };
  289. static u8 sensor_reset[] = {0x61, 0x68, 0x62, 0xff, 0x60, 0x07};
  290. /* read 1 byte */
  291. static u8 reg_r(struct gspca_dev *gspca_dev,
  292. u16 index)
  293. {
  294. usb_control_msg(gspca_dev->dev,
  295. usb_rcvctrlpipe(gspca_dev->dev, 0),
  296. 0, /* request */
  297. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  298. 0, /* value */
  299. index,
  300. gspca_dev->usb_buf, 1, 500);
  301. return gspca_dev->usb_buf[0];
  302. }
  303. static void reg_w(struct gspca_dev *gspca_dev,
  304. u16 index)
  305. {
  306. usb_control_msg(gspca_dev->dev,
  307. usb_sndctrlpipe(gspca_dev->dev, 0),
  308. 0,
  309. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  310. 0, index,
  311. NULL, 0, 500);
  312. }
  313. static void reg_w_buf(struct gspca_dev *gspca_dev,
  314. const u8 *buffer, u16 len)
  315. {
  316. if (len <= USB_BUF_SZ) {
  317. memcpy(gspca_dev->usb_buf, buffer, len);
  318. usb_control_msg(gspca_dev->dev,
  319. usb_sndctrlpipe(gspca_dev->dev, 0),
  320. 0,
  321. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  322. 0x01, 0,
  323. gspca_dev->usb_buf, len, 500);
  324. } else {
  325. u8 *tmpbuf;
  326. tmpbuf = kmemdup(buffer, len, GFP_KERNEL);
  327. if (!tmpbuf) {
  328. pr_err("Out of memory\n");
  329. return;
  330. }
  331. usb_control_msg(gspca_dev->dev,
  332. usb_sndctrlpipe(gspca_dev->dev, 0),
  333. 0,
  334. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  335. 0x01, 0,
  336. tmpbuf, len, 500);
  337. kfree(tmpbuf);
  338. }
  339. }
  340. /* write values to consecutive registers */
  341. static void reg_w_ixbuf(struct gspca_dev *gspca_dev,
  342. u8 reg,
  343. const u8 *buffer, u16 len)
  344. {
  345. int i;
  346. u8 *p, *tmpbuf;
  347. if (len * 2 <= USB_BUF_SZ) {
  348. p = tmpbuf = gspca_dev->usb_buf;
  349. } else {
  350. p = tmpbuf = kmalloc(len * 2, GFP_KERNEL);
  351. if (!tmpbuf) {
  352. pr_err("Out of memory\n");
  353. return;
  354. }
  355. }
  356. i = len;
  357. while (--i >= 0) {
  358. *p++ = reg++;
  359. *p++ = *buffer++;
  360. }
  361. usb_control_msg(gspca_dev->dev,
  362. usb_sndctrlpipe(gspca_dev->dev, 0),
  363. 0,
  364. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  365. 0x01, 0,
  366. tmpbuf, len * 2, 500);
  367. if (len * 2 > USB_BUF_SZ)
  368. kfree(tmpbuf);
  369. }
  370. static void om6802_sensor_init(struct gspca_dev *gspca_dev)
  371. {
  372. int i;
  373. const u8 *p;
  374. u8 byte;
  375. u8 val[6] = {0x62, 0, 0x64, 0, 0x60, 0x05};
  376. static const u8 sensor_init[] = {
  377. 0xdf, 0x6d,
  378. 0xdd, 0x18,
  379. 0x5a, 0xe0,
  380. 0x5c, 0x07,
  381. 0x5d, 0xb0,
  382. 0x5e, 0x1e,
  383. 0x60, 0x71,
  384. 0xef, 0x00,
  385. 0xe9, 0x00,
  386. 0xea, 0x00,
  387. 0x90, 0x24,
  388. 0x91, 0xb2,
  389. 0x82, 0x32,
  390. 0xfd, 0x41,
  391. 0x00 /* table end */
  392. };
  393. reg_w_buf(gspca_dev, sensor_reset, sizeof sensor_reset);
  394. msleep(100);
  395. i = 4;
  396. while (--i > 0) {
  397. byte = reg_r(gspca_dev, 0x0060);
  398. if (!(byte & 0x01))
  399. break;
  400. msleep(100);
  401. }
  402. byte = reg_r(gspca_dev, 0x0063);
  403. if (byte != 0x17) {
  404. pr_err("Bad sensor reset %02x\n", byte);
  405. /* continue? */
  406. }
  407. p = sensor_init;
  408. while (*p != 0) {
  409. val[1] = *p++;
  410. val[3] = *p++;
  411. if (*p == 0)
  412. reg_w(gspca_dev, 0x3c80);
  413. reg_w_buf(gspca_dev, val, sizeof val);
  414. i = 4;
  415. while (--i >= 0) {
  416. msleep(15);
  417. byte = reg_r(gspca_dev, 0x60);
  418. if (!(byte & 0x01))
  419. break;
  420. }
  421. }
  422. msleep(15);
  423. reg_w(gspca_dev, 0x3c80);
  424. }
  425. /* this function is called at probe time */
  426. static int sd_config(struct gspca_dev *gspca_dev,
  427. const struct usb_device_id *id)
  428. {
  429. struct cam *cam = &gspca_dev->cam;
  430. cam->cam_mode = vga_mode_t16;
  431. cam->nmodes = ARRAY_SIZE(vga_mode_t16);
  432. return 0;
  433. }
  434. static void setbrightness(struct gspca_dev *gspca_dev, s32 brightness)
  435. {
  436. u8 set6[4] = { 0x8f, 0x24, 0xc3, 0x00 };
  437. if (brightness < 7) {
  438. set6[1] = 0x26;
  439. set6[3] = 0x70 - brightness * 0x10;
  440. } else {
  441. set6[3] = 0x00 + ((brightness - 7) * 0x10);
  442. }
  443. reg_w_buf(gspca_dev, set6, sizeof set6);
  444. }
  445. static void setcontrast(struct gspca_dev *gspca_dev, s32 contrast)
  446. {
  447. u16 reg_to_write;
  448. if (contrast < 7)
  449. reg_to_write = 0x8ea9 - contrast * 0x200;
  450. else
  451. reg_to_write = 0x00a9 + (contrast - 7) * 0x200;
  452. reg_w(gspca_dev, reg_to_write);
  453. }
  454. static void setcolors(struct gspca_dev *gspca_dev, s32 val)
  455. {
  456. u16 reg_to_write;
  457. reg_to_write = 0x80bb + val * 0x100; /* was 0xc0 */
  458. reg_w(gspca_dev, reg_to_write);
  459. }
  460. static void setgamma(struct gspca_dev *gspca_dev, s32 val)
  461. {
  462. PDEBUG(D_CONF, "Gamma: %d", val);
  463. reg_w_ixbuf(gspca_dev, 0x90,
  464. gamma_table[val], sizeof gamma_table[0]);
  465. }
  466. static void setawb_n_RGB(struct gspca_dev *gspca_dev)
  467. {
  468. struct sd *sd = (struct sd *) gspca_dev;
  469. u8 all_gain_reg[8] = {
  470. 0x87, 0x00, 0x88, 0x00, 0x89, 0x00, 0x80, 0x00 };
  471. s32 red_gain, blue_gain, green_gain;
  472. green_gain = sd->gain->val;
  473. red_gain = green_gain + sd->red_balance->val;
  474. if (red_gain > 0x40)
  475. red_gain = 0x40;
  476. else if (red_gain < 0x10)
  477. red_gain = 0x10;
  478. blue_gain = green_gain + sd->blue_balance->val;
  479. if (blue_gain > 0x40)
  480. blue_gain = 0x40;
  481. else if (blue_gain < 0x10)
  482. blue_gain = 0x10;
  483. all_gain_reg[1] = red_gain;
  484. all_gain_reg[3] = blue_gain;
  485. all_gain_reg[5] = green_gain;
  486. all_gain_reg[7] = sensor_data[sd->sensor].reg80;
  487. if (!sd->awb->val)
  488. all_gain_reg[7] &= ~0x04; /* AWB off */
  489. reg_w_buf(gspca_dev, all_gain_reg, sizeof all_gain_reg);
  490. }
  491. static void setsharpness(struct gspca_dev *gspca_dev, s32 val)
  492. {
  493. u16 reg_to_write;
  494. reg_to_write = 0x0aa6 + 0x1000 * val;
  495. reg_w(gspca_dev, reg_to_write);
  496. }
  497. static void setfreq(struct gspca_dev *gspca_dev, s32 val)
  498. {
  499. struct sd *sd = (struct sd *) gspca_dev;
  500. u8 reg66;
  501. u8 freq[4] = { 0x66, 0x00, 0xa8, 0xe8 };
  502. switch (sd->sensor) {
  503. case SENSOR_LT168G:
  504. if (val != 0)
  505. freq[3] = 0xa8;
  506. reg66 = 0x41;
  507. break;
  508. case SENSOR_OM6802:
  509. reg66 = 0xca;
  510. break;
  511. default:
  512. reg66 = 0x40;
  513. break;
  514. }
  515. switch (val) {
  516. case 0: /* no flicker */
  517. freq[3] = 0xf0;
  518. break;
  519. case 2: /* 60Hz */
  520. reg66 &= ~0x40;
  521. break;
  522. }
  523. freq[1] = reg66;
  524. reg_w_buf(gspca_dev, freq, sizeof freq);
  525. }
  526. /* this function is called at probe and resume time */
  527. static int sd_init(struct gspca_dev *gspca_dev)
  528. {
  529. /* some of this registers are not really neded, because
  530. * they are overriden by setbrigthness, setcontrast, etc,
  531. * but wont hurt anyway, and can help someone with similar webcam
  532. * to see the initial parameters.*/
  533. struct sd *sd = (struct sd *) gspca_dev;
  534. const struct additional_sensor_data *sensor;
  535. int i;
  536. u16 sensor_id;
  537. u8 test_byte = 0;
  538. static const u8 read_indexs[] =
  539. { 0x0a, 0x0b, 0x66, 0x80, 0x81, 0x8e, 0x8f, 0xa5,
  540. 0xa6, 0xa8, 0xbb, 0xbc, 0xc6, 0x00 };
  541. static const u8 n1[] =
  542. {0x08, 0x03, 0x09, 0x03, 0x12, 0x04};
  543. static const u8 n2[] =
  544. {0x08, 0x00};
  545. sensor_id = (reg_r(gspca_dev, 0x06) << 8)
  546. | reg_r(gspca_dev, 0x07);
  547. switch (sensor_id & 0xff0f) {
  548. case 0x0801:
  549. PDEBUG(D_PROBE, "sensor tas5130a");
  550. sd->sensor = SENSOR_TAS5130A;
  551. break;
  552. case 0x0802:
  553. PDEBUG(D_PROBE, "sensor lt168g");
  554. sd->sensor = SENSOR_LT168G;
  555. break;
  556. case 0x0803:
  557. PDEBUG(D_PROBE, "sensor 'other'");
  558. sd->sensor = SENSOR_OTHER;
  559. break;
  560. case 0x0807:
  561. PDEBUG(D_PROBE, "sensor om6802");
  562. sd->sensor = SENSOR_OM6802;
  563. break;
  564. default:
  565. pr_err("unknown sensor %04x\n", sensor_id);
  566. return -EINVAL;
  567. }
  568. if (sd->sensor == SENSOR_OM6802) {
  569. reg_w_buf(gspca_dev, n1, sizeof n1);
  570. i = 5;
  571. while (--i >= 0) {
  572. reg_w_buf(gspca_dev, sensor_reset, sizeof sensor_reset);
  573. test_byte = reg_r(gspca_dev, 0x0063);
  574. msleep(100);
  575. if (test_byte == 0x17)
  576. break; /* OK */
  577. }
  578. if (i < 0) {
  579. pr_err("Bad sensor reset %02x\n", test_byte);
  580. return -EIO;
  581. }
  582. reg_w_buf(gspca_dev, n2, sizeof n2);
  583. }
  584. i = 0;
  585. while (read_indexs[i] != 0x00) {
  586. test_byte = reg_r(gspca_dev, read_indexs[i]);
  587. PDEBUG(D_STREAM, "Reg 0x%02x = 0x%02x", read_indexs[i],
  588. test_byte);
  589. i++;
  590. }
  591. sensor = &sensor_data[sd->sensor];
  592. reg_w_buf(gspca_dev, sensor->n3, sizeof sensor->n3);
  593. reg_w_buf(gspca_dev, sensor->n4, sensor->n4sz);
  594. if (sd->sensor == SENSOR_LT168G) {
  595. test_byte = reg_r(gspca_dev, 0x80);
  596. PDEBUG(D_STREAM, "Reg 0x%02x = 0x%02x", 0x80,
  597. test_byte);
  598. reg_w(gspca_dev, 0x6c80);
  599. }
  600. reg_w_ixbuf(gspca_dev, 0xd0, sensor->data1, sizeof sensor->data1);
  601. reg_w_ixbuf(gspca_dev, 0xc7, sensor->data2, sizeof sensor->data2);
  602. reg_w_ixbuf(gspca_dev, 0xe0, sensor->data3, sizeof sensor->data3);
  603. reg_w(gspca_dev, (sensor->reg80 << 8) + 0x80);
  604. reg_w(gspca_dev, (sensor->reg80 << 8) + 0x80);
  605. reg_w(gspca_dev, (sensor->reg8e << 8) + 0x8e);
  606. reg_w(gspca_dev, (0x20 << 8) + 0x87);
  607. reg_w(gspca_dev, (0x20 << 8) + 0x88);
  608. reg_w(gspca_dev, (0x20 << 8) + 0x89);
  609. reg_w_buf(gspca_dev, sensor->data5, sizeof sensor->data5);
  610. reg_w_buf(gspca_dev, sensor->nset8, sizeof sensor->nset8);
  611. reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream);
  612. if (sd->sensor == SENSOR_LT168G) {
  613. test_byte = reg_r(gspca_dev, 0x80);
  614. PDEBUG(D_STREAM, "Reg 0x%02x = 0x%02x", 0x80,
  615. test_byte);
  616. reg_w(gspca_dev, 0x6c80);
  617. }
  618. reg_w_ixbuf(gspca_dev, 0xd0, sensor->data1, sizeof sensor->data1);
  619. reg_w_ixbuf(gspca_dev, 0xc7, sensor->data2, sizeof sensor->data2);
  620. reg_w_ixbuf(gspca_dev, 0xe0, sensor->data3, sizeof sensor->data3);
  621. return 0;
  622. }
  623. static void setmirror(struct gspca_dev *gspca_dev, s32 val)
  624. {
  625. u8 hflipcmd[8] =
  626. {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09};
  627. if (val)
  628. hflipcmd[3] = 0x01;
  629. reg_w_buf(gspca_dev, hflipcmd, sizeof hflipcmd);
  630. }
  631. static void seteffect(struct gspca_dev *gspca_dev, s32 val)
  632. {
  633. int idx = 0;
  634. switch (val) {
  635. case V4L2_COLORFX_NONE:
  636. break;
  637. case V4L2_COLORFX_BW:
  638. idx = 2;
  639. break;
  640. case V4L2_COLORFX_SEPIA:
  641. idx = 3;
  642. break;
  643. case V4L2_COLORFX_SKETCH:
  644. idx = 4;
  645. break;
  646. case V4L2_COLORFX_NEGATIVE:
  647. idx = 6;
  648. break;
  649. default:
  650. break;
  651. }
  652. reg_w_buf(gspca_dev, effects_table[idx],
  653. sizeof effects_table[0]);
  654. if (val == V4L2_COLORFX_SKETCH)
  655. reg_w(gspca_dev, 0x4aa6);
  656. else
  657. reg_w(gspca_dev, 0xfaa6);
  658. }
  659. /* Is this really needed?
  660. * i added some module parameters for test with some users */
  661. static void poll_sensor(struct gspca_dev *gspca_dev)
  662. {
  663. static const u8 poll1[] =
  664. {0x67, 0x05, 0x68, 0x81, 0x69, 0x80, 0x6a, 0x82,
  665. 0x6b, 0x68, 0x6c, 0x69, 0x72, 0xd9, 0x73, 0x34,
  666. 0x74, 0x32, 0x75, 0x92, 0x76, 0x00, 0x09, 0x01,
  667. 0x60, 0x14};
  668. static const u8 poll2[] =
  669. {0x67, 0x02, 0x68, 0x71, 0x69, 0x72, 0x72, 0xa9,
  670. 0x73, 0x02, 0x73, 0x02, 0x60, 0x14};
  671. static const u8 noise03[] = /* (some differences / ms-drv) */
  672. {0xa6, 0x0a, 0xea, 0xcf, 0xbe, 0x26, 0xb1, 0x5f,
  673. 0xa1, 0xb1, 0xda, 0x6b, 0xdb, 0x98, 0xdf, 0x0c,
  674. 0xc2, 0x80, 0xc3, 0x10};
  675. PDEBUG(D_STREAM, "[Sensor requires polling]");
  676. reg_w_buf(gspca_dev, poll1, sizeof poll1);
  677. reg_w_buf(gspca_dev, poll2, sizeof poll2);
  678. reg_w_buf(gspca_dev, noise03, sizeof noise03);
  679. }
  680. static int sd_start(struct gspca_dev *gspca_dev)
  681. {
  682. struct sd *sd = (struct sd *) gspca_dev;
  683. const struct additional_sensor_data *sensor;
  684. int i, mode;
  685. u8 t2[] = { 0x07, 0x00, 0x0d, 0x60, 0x0e, 0x80 };
  686. static const u8 t3[] =
  687. { 0x07, 0x00, 0x88, 0x02, 0x06, 0x00, 0xe7, 0x01 };
  688. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  689. switch (mode) {
  690. case 0: /* 640x480 (0x00) */
  691. break;
  692. case 1: /* 352x288 */
  693. t2[1] = 0x40;
  694. break;
  695. case 2: /* 320x240 */
  696. t2[1] = 0x10;
  697. break;
  698. case 3: /* 176x144 */
  699. t2[1] = 0x50;
  700. break;
  701. default:
  702. /* case 4: * 160x120 */
  703. t2[1] = 0x20;
  704. break;
  705. }
  706. switch (sd->sensor) {
  707. case SENSOR_OM6802:
  708. om6802_sensor_init(gspca_dev);
  709. break;
  710. case SENSOR_TAS5130A:
  711. i = 0;
  712. for (;;) {
  713. reg_w_buf(gspca_dev, tas5130a_sensor_init[i],
  714. sizeof tas5130a_sensor_init[0]);
  715. if (i >= ARRAY_SIZE(tas5130a_sensor_init) - 1)
  716. break;
  717. i++;
  718. }
  719. reg_w(gspca_dev, 0x3c80);
  720. /* just in case and to keep sync with logs (for mine) */
  721. reg_w_buf(gspca_dev, tas5130a_sensor_init[i],
  722. sizeof tas5130a_sensor_init[0]);
  723. reg_w(gspca_dev, 0x3c80);
  724. break;
  725. }
  726. sensor = &sensor_data[sd->sensor];
  727. setfreq(gspca_dev, v4l2_ctrl_g_ctrl(sd->freq));
  728. reg_r(gspca_dev, 0x0012);
  729. reg_w_buf(gspca_dev, t2, sizeof t2);
  730. reg_w_ixbuf(gspca_dev, 0xb3, t3, sizeof t3);
  731. reg_w(gspca_dev, 0x0013);
  732. msleep(15);
  733. reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream);
  734. reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream);
  735. if (sd->sensor == SENSOR_OM6802)
  736. poll_sensor(gspca_dev);
  737. return 0;
  738. }
  739. static void sd_stopN(struct gspca_dev *gspca_dev)
  740. {
  741. struct sd *sd = (struct sd *) gspca_dev;
  742. reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream,
  743. sizeof sensor_data[sd->sensor].stream);
  744. reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream,
  745. sizeof sensor_data[sd->sensor].stream);
  746. if (sd->sensor == SENSOR_OM6802) {
  747. msleep(20);
  748. reg_w(gspca_dev, 0x0309);
  749. }
  750. #if IS_ENABLED(CONFIG_INPUT)
  751. /* If the last button state is pressed, release it now! */
  752. if (sd->button_pressed) {
  753. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
  754. input_sync(gspca_dev->input_dev);
  755. sd->button_pressed = 0;
  756. }
  757. #endif
  758. }
  759. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  760. u8 *data, /* isoc packet */
  761. int len) /* iso packet length */
  762. {
  763. struct sd *sd __maybe_unused = (struct sd *) gspca_dev;
  764. int pkt_type;
  765. if (data[0] == 0x5a) {
  766. #if IS_ENABLED(CONFIG_INPUT)
  767. if (len > 20) {
  768. u8 state = (data[20] & 0x80) ? 1 : 0;
  769. if (sd->button_pressed != state) {
  770. input_report_key(gspca_dev->input_dev,
  771. KEY_CAMERA, state);
  772. input_sync(gspca_dev->input_dev);
  773. sd->button_pressed = state;
  774. }
  775. }
  776. #endif
  777. /* Control Packet, after this came the header again,
  778. * but extra bytes came in the packet before this,
  779. * sometimes an EOF arrives, sometimes not... */
  780. return;
  781. }
  782. data += 2;
  783. len -= 2;
  784. if (data[0] == 0xff && data[1] == 0xd8)
  785. pkt_type = FIRST_PACKET;
  786. else if (data[len - 2] == 0xff && data[len - 1] == 0xd9)
  787. pkt_type = LAST_PACKET;
  788. else
  789. pkt_type = INTER_PACKET;
  790. gspca_frame_add(gspca_dev, pkt_type, data, len);
  791. }
  792. static int sd_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
  793. {
  794. struct gspca_dev *gspca_dev =
  795. container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
  796. struct sd *sd = (struct sd *)gspca_dev;
  797. s32 red_gain, blue_gain, green_gain;
  798. gspca_dev->usb_err = 0;
  799. switch (ctrl->id) {
  800. case V4L2_CID_AUTO_WHITE_BALANCE:
  801. red_gain = reg_r(gspca_dev, 0x0087);
  802. if (red_gain > 0x40)
  803. red_gain = 0x40;
  804. else if (red_gain < 0x10)
  805. red_gain = 0x10;
  806. blue_gain = reg_r(gspca_dev, 0x0088);
  807. if (blue_gain > 0x40)
  808. blue_gain = 0x40;
  809. else if (blue_gain < 0x10)
  810. blue_gain = 0x10;
  811. green_gain = reg_r(gspca_dev, 0x0089);
  812. if (green_gain > 0x40)
  813. green_gain = 0x40;
  814. else if (green_gain < 0x10)
  815. green_gain = 0x10;
  816. sd->gain->val = green_gain;
  817. sd->red_balance->val = red_gain - green_gain;
  818. sd->blue_balance->val = blue_gain - green_gain;
  819. break;
  820. }
  821. return 0;
  822. }
  823. static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
  824. {
  825. struct gspca_dev *gspca_dev =
  826. container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
  827. gspca_dev->usb_err = 0;
  828. if (!gspca_dev->streaming)
  829. return 0;
  830. switch (ctrl->id) {
  831. case V4L2_CID_BRIGHTNESS:
  832. setbrightness(gspca_dev, ctrl->val);
  833. break;
  834. case V4L2_CID_CONTRAST:
  835. setcontrast(gspca_dev, ctrl->val);
  836. break;
  837. case V4L2_CID_SATURATION:
  838. setcolors(gspca_dev, ctrl->val);
  839. break;
  840. case V4L2_CID_GAMMA:
  841. setgamma(gspca_dev, ctrl->val);
  842. break;
  843. case V4L2_CID_HFLIP:
  844. setmirror(gspca_dev, ctrl->val);
  845. break;
  846. case V4L2_CID_SHARPNESS:
  847. setsharpness(gspca_dev, ctrl->val);
  848. break;
  849. case V4L2_CID_POWER_LINE_FREQUENCY:
  850. setfreq(gspca_dev, ctrl->val);
  851. break;
  852. case V4L2_CID_BACKLIGHT_COMPENSATION:
  853. reg_w(gspca_dev, ctrl->val ? 0xf48e : 0xb48e);
  854. break;
  855. case V4L2_CID_AUTO_WHITE_BALANCE:
  856. setawb_n_RGB(gspca_dev);
  857. break;
  858. case V4L2_CID_COLORFX:
  859. seteffect(gspca_dev, ctrl->val);
  860. break;
  861. }
  862. return gspca_dev->usb_err;
  863. }
  864. static const struct v4l2_ctrl_ops sd_ctrl_ops = {
  865. .g_volatile_ctrl = sd_g_volatile_ctrl,
  866. .s_ctrl = sd_s_ctrl,
  867. };
  868. static int sd_init_controls(struct gspca_dev *gspca_dev)
  869. {
  870. struct sd *sd = (struct sd *)gspca_dev;
  871. struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
  872. gspca_dev->vdev.ctrl_handler = hdl;
  873. v4l2_ctrl_handler_init(hdl, 12);
  874. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  875. V4L2_CID_BRIGHTNESS, 0, 14, 1, 8);
  876. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  877. V4L2_CID_CONTRAST, 0, 0x0d, 1, 7);
  878. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  879. V4L2_CID_SATURATION, 0, 0xf, 1, 5);
  880. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  881. V4L2_CID_GAMMA, 0, GAMMA_MAX, 1, 10);
  882. /* Activate lowlight, some apps dont bring up the
  883. backlight_compensation control) */
  884. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  885. V4L2_CID_BACKLIGHT_COMPENSATION, 0, 1, 1, 1);
  886. if (sd->sensor == SENSOR_TAS5130A)
  887. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  888. V4L2_CID_HFLIP, 0, 1, 1, 0);
  889. sd->awb = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  890. V4L2_CID_AUTO_WHITE_BALANCE, 0, 1, 1, 1);
  891. sd->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  892. V4L2_CID_GAIN, 0x10, 0x40, 1, 0x20);
  893. sd->blue_balance = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  894. V4L2_CID_BLUE_BALANCE, -0x30, 0x30, 1, 0);
  895. sd->red_balance = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  896. V4L2_CID_RED_BALANCE, -0x30, 0x30, 1, 0);
  897. v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
  898. V4L2_CID_SHARPNESS, 0, 15, 1, 6);
  899. v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops,
  900. V4L2_CID_COLORFX, V4L2_COLORFX_SKETCH,
  901. ~((1 << V4L2_COLORFX_NONE) |
  902. (1 << V4L2_COLORFX_BW) |
  903. (1 << V4L2_COLORFX_SEPIA) |
  904. (1 << V4L2_COLORFX_SKETCH) |
  905. (1 << V4L2_COLORFX_NEGATIVE)),
  906. V4L2_COLORFX_NONE);
  907. sd->freq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops,
  908. V4L2_CID_POWER_LINE_FREQUENCY,
  909. V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 1,
  910. V4L2_CID_POWER_LINE_FREQUENCY_50HZ);
  911. if (hdl->error) {
  912. pr_err("Could not initialize controls\n");
  913. return hdl->error;
  914. }
  915. v4l2_ctrl_auto_cluster(4, &sd->awb, 0, true);
  916. return 0;
  917. }
  918. /* sub-driver description */
  919. static const struct sd_desc sd_desc = {
  920. .name = MODULE_NAME,
  921. .config = sd_config,
  922. .init = sd_init,
  923. .init_controls = sd_init_controls,
  924. .start = sd_start,
  925. .stopN = sd_stopN,
  926. .pkt_scan = sd_pkt_scan,
  927. #if IS_ENABLED(CONFIG_INPUT)
  928. .other_input = 1,
  929. #endif
  930. };
  931. /* -- module initialisation -- */
  932. static const struct usb_device_id device_table[] = {
  933. {USB_DEVICE(0x17a1, 0x0128)},
  934. {}
  935. };
  936. MODULE_DEVICE_TABLE(usb, device_table);
  937. /* -- device connect -- */
  938. static int sd_probe(struct usb_interface *intf,
  939. const struct usb_device_id *id)
  940. {
  941. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  942. THIS_MODULE);
  943. }
  944. static struct usb_driver sd_driver = {
  945. .name = MODULE_NAME,
  946. .id_table = device_table,
  947. .probe = sd_probe,
  948. .disconnect = gspca_disconnect,
  949. #ifdef CONFIG_PM
  950. .suspend = gspca_suspend,
  951. .resume = gspca_resume,
  952. .reset_resume = gspca_resume,
  953. #endif
  954. };
  955. module_usb_driver(sd_driver);