t613.c 27 KB

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