t613.c 27 KB

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