sq930x.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
  1. /*
  2. * SQ930x subdriver
  3. *
  4. * Copyright (C) 2010 Jean-François Moine <http://moinejf.free.fr>
  5. * Copyright (C) 2006 -2008 Gerard Klaver <gerard at gkall dot hobby dot nl>
  6. * Copyright (C) 2007 Sam Revitch <samr7@cs.washington.edu>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  23. #define MODULE_NAME "sq930x"
  24. #include "gspca.h"
  25. MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>\n"
  26. "Gerard Klaver <gerard at gkall dot hobby dot nl\n"
  27. "Sam Revitch <samr7@cs.washington.edu>");
  28. MODULE_DESCRIPTION("GSPCA/SQ930x USB Camera Driver");
  29. MODULE_LICENSE("GPL");
  30. /* Structure to hold all of our device specific stuff */
  31. struct sd {
  32. struct gspca_dev gspca_dev; /* !! must be the first item */
  33. u16 expo;
  34. u8 gain;
  35. u8 do_ctrl;
  36. u8 gpio[2];
  37. u8 sensor;
  38. u8 type;
  39. #define Generic 0
  40. #define Creative_live_motion 1
  41. };
  42. enum sensors {
  43. SENSOR_ICX098BQ,
  44. SENSOR_LZ24BP,
  45. SENSOR_MI0360,
  46. SENSOR_MT9V111, /* = MI360SOC */
  47. SENSOR_OV7660,
  48. SENSOR_OV9630,
  49. };
  50. static int sd_setexpo(struct gspca_dev *gspca_dev, __s32 val);
  51. static int sd_getexpo(struct gspca_dev *gspca_dev, __s32 *val);
  52. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
  53. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
  54. static const struct ctrl sd_ctrls[] = {
  55. {
  56. {
  57. .id = V4L2_CID_EXPOSURE,
  58. .type = V4L2_CTRL_TYPE_INTEGER,
  59. .name = "Exposure",
  60. .minimum = 0x0001,
  61. .maximum = 0x0fff,
  62. .step = 1,
  63. #define EXPO_DEF 0x0356
  64. .default_value = EXPO_DEF,
  65. },
  66. .set = sd_setexpo,
  67. .get = sd_getexpo,
  68. },
  69. {
  70. {
  71. .id = V4L2_CID_GAIN,
  72. .type = V4L2_CTRL_TYPE_INTEGER,
  73. .name = "Gain",
  74. .minimum = 0x01,
  75. .maximum = 0xff,
  76. .step = 1,
  77. #define GAIN_DEF 0x8d
  78. .default_value = GAIN_DEF,
  79. },
  80. .set = sd_setgain,
  81. .get = sd_getgain,
  82. },
  83. };
  84. static struct v4l2_pix_format vga_mode[] = {
  85. {320, 240, V4L2_PIX_FMT_SRGGB8, V4L2_FIELD_NONE,
  86. .bytesperline = 320,
  87. .sizeimage = 320 * 240,
  88. .colorspace = V4L2_COLORSPACE_SRGB,
  89. .priv = 0},
  90. {640, 480, V4L2_PIX_FMT_SRGGB8, V4L2_FIELD_NONE,
  91. .bytesperline = 640,
  92. .sizeimage = 640 * 480,
  93. .colorspace = V4L2_COLORSPACE_SRGB,
  94. .priv = 1},
  95. };
  96. /* sq930x registers */
  97. #define SQ930_CTRL_UCBUS_IO 0x0001
  98. #define SQ930_CTRL_I2C_IO 0x0002
  99. #define SQ930_CTRL_GPIO 0x0005
  100. #define SQ930_CTRL_CAP_START 0x0010
  101. #define SQ930_CTRL_CAP_STOP 0x0011
  102. #define SQ930_CTRL_SET_EXPOSURE 0x001d
  103. #define SQ930_CTRL_RESET 0x001e
  104. #define SQ930_CTRL_GET_DEV_INFO 0x001f
  105. /* gpio 1 (8..15) */
  106. #define SQ930_GPIO_DFL_I2C_SDA 0x0001
  107. #define SQ930_GPIO_DFL_I2C_SCL 0x0002
  108. #define SQ930_GPIO_RSTBAR 0x0004
  109. #define SQ930_GPIO_EXTRA1 0x0040
  110. #define SQ930_GPIO_EXTRA2 0x0080
  111. /* gpio 3 (24..31) */
  112. #define SQ930_GPIO_POWER 0x0200
  113. #define SQ930_GPIO_DFL_LED 0x1000
  114. struct ucbus_write_cmd {
  115. u16 bw_addr;
  116. u8 bw_data;
  117. };
  118. struct i2c_write_cmd {
  119. u8 reg;
  120. u16 val;
  121. };
  122. static const struct ucbus_write_cmd icx098bq_start_0[] = {
  123. {0x0354, 0x00}, {0x03fa, 0x00}, {0xf800, 0x02}, {0xf801, 0xce},
  124. {0xf802, 0xc1}, {0xf804, 0x00}, {0xf808, 0x00}, {0xf809, 0x0e},
  125. {0xf80a, 0x01}, {0xf80b, 0xee}, {0xf807, 0x60}, {0xf80c, 0x02},
  126. {0xf80d, 0xf0}, {0xf80e, 0x03}, {0xf80f, 0x0a}, {0xf81c, 0x02},
  127. {0xf81d, 0xf0}, {0xf81e, 0x03}, {0xf81f, 0x0a}, {0xf83a, 0x00},
  128. {0xf83b, 0x10}, {0xf83c, 0x00}, {0xf83d, 0x4e}, {0xf810, 0x04},
  129. {0xf811, 0x00}, {0xf812, 0x02}, {0xf813, 0x10}, {0xf803, 0x00},
  130. {0xf814, 0x01}, {0xf815, 0x18}, {0xf816, 0x00}, {0xf817, 0x48},
  131. {0xf818, 0x00}, {0xf819, 0x25}, {0xf81a, 0x00}, {0xf81b, 0x3c},
  132. {0xf82f, 0x03}, {0xf820, 0xff}, {0xf821, 0x0d}, {0xf822, 0xff},
  133. {0xf823, 0x07}, {0xf824, 0xff}, {0xf825, 0x03}, {0xf826, 0xff},
  134. {0xf827, 0x06}, {0xf828, 0xff}, {0xf829, 0x03}, {0xf82a, 0xff},
  135. {0xf82b, 0x0c}, {0xf82c, 0xfd}, {0xf82d, 0x01}, {0xf82e, 0x00},
  136. {0xf830, 0x00}, {0xf831, 0x47}, {0xf832, 0x00}, {0xf833, 0x00},
  137. {0xf850, 0x00}, {0xf851, 0x00}, {0xf852, 0x00}, {0xf853, 0x24},
  138. {0xf854, 0x00}, {0xf855, 0x18}, {0xf856, 0x00}, {0xf857, 0x3c},
  139. {0xf858, 0x00}, {0xf859, 0x0c}, {0xf85a, 0x00}, {0xf85b, 0x30},
  140. {0xf85c, 0x00}, {0xf85d, 0x0c}, {0xf85e, 0x00}, {0xf85f, 0x30},
  141. {0xf860, 0x00}, {0xf861, 0x48}, {0xf862, 0x01}, {0xf863, 0xdc},
  142. {0xf864, 0xff}, {0xf865, 0x98}, {0xf866, 0xff}, {0xf867, 0xc0},
  143. {0xf868, 0xff}, {0xf869, 0x70}, {0xf86c, 0xff}, {0xf86d, 0x00},
  144. {0xf86a, 0xff}, {0xf86b, 0x48}, {0xf86e, 0xff}, {0xf86f, 0x00},
  145. {0xf870, 0x01}, {0xf871, 0xdb}, {0xf872, 0x01}, {0xf873, 0xfa},
  146. {0xf874, 0x01}, {0xf875, 0xdb}, {0xf876, 0x01}, {0xf877, 0xfa},
  147. {0xf878, 0x0f}, {0xf879, 0x0f}, {0xf87a, 0xff}, {0xf87b, 0xff},
  148. {0xf800, 0x03}
  149. };
  150. static const struct ucbus_write_cmd icx098bq_start_1[] = {
  151. {0xf5f0, 0x00}, {0xf5f1, 0xcd}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
  152. {0xf5f4, 0xc0},
  153. {0xf5f0, 0x49}, {0xf5f1, 0xcd}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
  154. {0xf5f4, 0xc0},
  155. {0xf5fa, 0x00}, {0xf5f6, 0x00}, {0xf5f7, 0x00}, {0xf5f8, 0x00},
  156. {0xf5f9, 0x00}
  157. };
  158. static const struct ucbus_write_cmd icx098bq_start_2[] = {
  159. {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x82}, {0xf806, 0x00},
  160. {0xf807, 0x7f}, {0xf800, 0x03},
  161. {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x40}, {0xf806, 0x00},
  162. {0xf807, 0x7f}, {0xf800, 0x03},
  163. {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0xcf}, {0xf806, 0xd0},
  164. {0xf807, 0x7f}, {0xf800, 0x03},
  165. {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x00}, {0xf806, 0x00},
  166. {0xf807, 0x7f}, {0xf800, 0x03}
  167. };
  168. static const struct ucbus_write_cmd lz24bp_start_0[] = {
  169. {0x0354, 0x00}, {0x03fa, 0x00}, {0xf800, 0x02}, {0xf801, 0xbe},
  170. {0xf802, 0xc6}, {0xf804, 0x00}, {0xf808, 0x00}, {0xf809, 0x06},
  171. {0xf80a, 0x01}, {0xf80b, 0xfe}, {0xf807, 0x84}, {0xf80c, 0x02},
  172. {0xf80d, 0xf7}, {0xf80e, 0x03}, {0xf80f, 0x0b}, {0xf81c, 0x00},
  173. {0xf81d, 0x49}, {0xf81e, 0x03}, {0xf81f, 0x0b}, {0xf83a, 0x00},
  174. {0xf83b, 0x01}, {0xf83c, 0x00}, {0xf83d, 0x6b}, {0xf810, 0x03},
  175. {0xf811, 0x10}, {0xf812, 0x02}, {0xf813, 0x6f}, {0xf803, 0x00},
  176. {0xf814, 0x00}, {0xf815, 0x44}, {0xf816, 0x00}, {0xf817, 0x48},
  177. {0xf818, 0x00}, {0xf819, 0x25}, {0xf81a, 0x00}, {0xf81b, 0x3c},
  178. {0xf82f, 0x03}, {0xf820, 0xff}, {0xf821, 0x0d}, {0xf822, 0xff},
  179. {0xf823, 0x07}, {0xf824, 0xfd}, {0xf825, 0x07}, {0xf826, 0xf0},
  180. {0xf827, 0x0c}, {0xf828, 0xff}, {0xf829, 0x03}, {0xf82a, 0xff},
  181. {0xf82b, 0x0c}, {0xf82c, 0xfc}, {0xf82d, 0x01}, {0xf82e, 0x00},
  182. {0xf830, 0x00}, {0xf831, 0x47}, {0xf832, 0x00}, {0xf833, 0x00},
  183. {0xf850, 0x00}, {0xf851, 0x00}, {0xf852, 0x00}, {0xf853, 0x24},
  184. {0xf854, 0x00}, {0xf855, 0x0c}, {0xf856, 0x00}, {0xf857, 0x30},
  185. {0xf858, 0x00}, {0xf859, 0x18}, {0xf85a, 0x00}, {0xf85b, 0x3c},
  186. {0xf85c, 0x00}, {0xf85d, 0x18}, {0xf85e, 0x00}, {0xf85f, 0x3c},
  187. {0xf860, 0xff}, {0xf861, 0x37}, {0xf862, 0xff}, {0xf863, 0x1d},
  188. {0xf864, 0xff}, {0xf865, 0x98}, {0xf866, 0xff}, {0xf867, 0xc0},
  189. {0xf868, 0x00}, {0xf869, 0x37}, {0xf86c, 0x02}, {0xf86d, 0x1d},
  190. {0xf86a, 0x00}, {0xf86b, 0x37}, {0xf86e, 0x02}, {0xf86f, 0x1d},
  191. {0xf870, 0x01}, {0xf871, 0xc6}, {0xf872, 0x02}, {0xf873, 0x04},
  192. {0xf874, 0x01}, {0xf875, 0xc6}, {0xf876, 0x02}, {0xf877, 0x04},
  193. {0xf878, 0x0f}, {0xf879, 0x0f}, {0xf87a, 0xff}, {0xf87b, 0xff},
  194. {0xf800, 0x03}
  195. };
  196. static const struct ucbus_write_cmd lz24bp_start_1_gen[] = {
  197. {0xf5f0, 0x00}, {0xf5f1, 0xff}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
  198. {0xf5f4, 0xb3},
  199. {0xf5f0, 0x40}, {0xf5f1, 0xff}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
  200. {0xf5f4, 0xb3},
  201. {0xf5fa, 0x00}, {0xf5f6, 0x00}, {0xf5f7, 0x00}, {0xf5f8, 0x00},
  202. {0xf5f9, 0x00}
  203. };
  204. static const struct ucbus_write_cmd lz24bp_start_1_clm[] = {
  205. {0xf5f0, 0x00}, {0xf5f1, 0xff}, {0xf5f2, 0x88}, {0xf5f3, 0x88},
  206. {0xf5f4, 0xc0},
  207. {0xf5f0, 0x40}, {0xf5f1, 0xff}, {0xf5f2, 0x88}, {0xf5f3, 0x88},
  208. {0xf5f4, 0xc0},
  209. {0xf5fa, 0x00}, {0xf5f6, 0x00}, {0xf5f7, 0x00}, {0xf5f8, 0x00},
  210. {0xf5f9, 0x00}
  211. };
  212. static const struct ucbus_write_cmd lz24bp_start_2[] = {
  213. {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x80}, {0xf806, 0x00},
  214. {0xf807, 0x7f}, {0xf800, 0x03},
  215. {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x4e}, {0xf806, 0x00},
  216. {0xf807, 0x7f}, {0xf800, 0x03},
  217. {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0xc0}, {0xf806, 0x48},
  218. {0xf807, 0x7f}, {0xf800, 0x03},
  219. {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x00}, {0xf806, 0x00},
  220. {0xf807, 0x7f}, {0xf800, 0x03}
  221. };
  222. static const struct ucbus_write_cmd mi0360_start_0[] = {
  223. {0x0354, 0x00}, {0x03fa, 0x00}, {0xf332, 0xcc}, {0xf333, 0xcc},
  224. {0xf334, 0xcc}, {0xf335, 0xcc}, {0xf33f, 0x00}
  225. };
  226. static const struct i2c_write_cmd mi0360_init_23[] = {
  227. {0x30, 0x0040}, /* reserved - def 0x0005 */
  228. {0x31, 0x0000}, /* reserved - def 0x002a */
  229. {0x34, 0x0100}, /* reserved - def 0x0100 */
  230. {0x3d, 0x068f}, /* reserved - def 0x068f */
  231. };
  232. static const struct i2c_write_cmd mi0360_init_24[] = {
  233. {0x03, 0x01e5}, /* window height */
  234. {0x04, 0x0285}, /* window width */
  235. };
  236. static const struct i2c_write_cmd mi0360_init_25[] = {
  237. {0x35, 0x0020}, /* global gain */
  238. {0x2b, 0x0020}, /* green1 gain */
  239. {0x2c, 0x002a}, /* blue gain */
  240. {0x2d, 0x0028}, /* red gain */
  241. {0x2e, 0x0020}, /* green2 gain */
  242. };
  243. static const struct ucbus_write_cmd mi0360_start_1[] = {
  244. {0xf5f0, 0x11}, {0xf5f1, 0x99}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
  245. {0xf5f4, 0xa6},
  246. {0xf5f0, 0x51}, {0xf5f1, 0x99}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
  247. {0xf5f4, 0xa6},
  248. {0xf5fa, 0x00}, {0xf5f6, 0x00}, {0xf5f7, 0x00}, {0xf5f8, 0x00},
  249. {0xf5f9, 0x00}
  250. };
  251. static const struct i2c_write_cmd mi0360_start_2[] = {
  252. {0x62, 0x041d}, /* reserved - def 0x0418 */
  253. };
  254. static const struct i2c_write_cmd mi0360_start_3[] = {
  255. {0x05, 0x007b}, /* horiz blanking */
  256. };
  257. static const struct i2c_write_cmd mi0360_start_4[] = {
  258. {0x05, 0x03f5}, /* horiz blanking */
  259. };
  260. static const struct i2c_write_cmd mt9v111_init_0[] = {
  261. {0x01, 0x0001}, /* select IFP/SOC registers */
  262. {0x06, 0x300c}, /* operating mode control */
  263. {0x08, 0xcc00}, /* output format control (RGB) */
  264. {0x01, 0x0004}, /* select sensor core registers */
  265. };
  266. static const struct i2c_write_cmd mt9v111_init_1[] = {
  267. {0x03, 0x01e5}, /* window height */
  268. {0x04, 0x0285}, /* window width */
  269. };
  270. static const struct i2c_write_cmd mt9v111_init_2[] = {
  271. {0x30, 0x7800},
  272. {0x31, 0x0000},
  273. {0x07, 0x3002}, /* output control */
  274. {0x35, 0x0020}, /* global gain */
  275. {0x2b, 0x0020}, /* green1 gain */
  276. {0x2c, 0x0020}, /* blue gain */
  277. {0x2d, 0x0020}, /* red gain */
  278. {0x2e, 0x0020}, /* green2 gain */
  279. };
  280. static const struct ucbus_write_cmd mt9v111_start_1[] = {
  281. {0xf5f0, 0x11}, {0xf5f1, 0x96}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
  282. {0xf5f4, 0xaa},
  283. {0xf5f0, 0x51}, {0xf5f1, 0x96}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
  284. {0xf5f4, 0xaa},
  285. {0xf5fa, 0x00}, {0xf5f6, 0x0a}, {0xf5f7, 0x0a}, {0xf5f8, 0x0a},
  286. {0xf5f9, 0x0a}
  287. };
  288. static const struct i2c_write_cmd mt9v111_init_3[] = {
  289. {0x62, 0x0405},
  290. };
  291. static const struct i2c_write_cmd mt9v111_init_4[] = {
  292. /* {0x05, 0x00ce}, */
  293. {0x05, 0x005d}, /* horizontal blanking */
  294. };
  295. static const struct ucbus_write_cmd ov7660_start_0[] = {
  296. {0x0354, 0x00}, {0x03fa, 0x00}, {0xf332, 0x00}, {0xf333, 0xc0},
  297. {0xf334, 0x39}, {0xf335, 0xe7}, {0xf33f, 0x03}
  298. };
  299. static const struct ucbus_write_cmd ov9630_start_0[] = {
  300. {0x0354, 0x00}, {0x03fa, 0x00}, {0xf332, 0x00}, {0xf333, 0x00},
  301. {0xf334, 0x3e}, {0xf335, 0xf8}, {0xf33f, 0x03}
  302. };
  303. /* start parameters indexed by [sensor][mode] */
  304. static const struct cap_s {
  305. u8 cc_sizeid;
  306. u8 cc_bytes[32];
  307. } capconfig[4][2] = {
  308. [SENSOR_ICX098BQ] = {
  309. {2, /* Bayer 320x240 */
  310. {0x05, 0x1f, 0x20, 0x0e, 0x00, 0x9f, 0x02, 0xee,
  311. 0x01, 0x01, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
  312. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0,
  313. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} },
  314. {4, /* Bayer 640x480 */
  315. {0x01, 0x1f, 0x20, 0x0e, 0x00, 0x9f, 0x02, 0xee,
  316. 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
  317. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  318. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} },
  319. },
  320. [SENSOR_LZ24BP] = {
  321. {2, /* Bayer 320x240 */
  322. {0x05, 0x22, 0x20, 0x0e, 0x00, 0xa2, 0x02, 0xee,
  323. 0x01, 0x01, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
  324. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  325. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} },
  326. {4, /* Bayer 640x480 */
  327. {0x01, 0x22, 0x20, 0x0e, 0x00, 0xa2, 0x02, 0xee,
  328. 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
  329. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  330. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} },
  331. },
  332. [SENSOR_MI0360] = {
  333. {2, /* Bayer 320x240 */
  334. {0x05, 0x02, 0x20, 0x01, 0x20, 0x82, 0x02, 0xe1,
  335. 0x01, 0x01, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
  336. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  337. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} },
  338. {4, /* Bayer 640x480 */
  339. {0x01, 0x02, 0x20, 0x01, 0x20, 0x82, 0x02, 0xe1,
  340. 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
  341. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  342. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} },
  343. },
  344. [SENSOR_MT9V111] = {
  345. {2, /* Bayer 320x240 */
  346. {0x05, 0x02, 0x20, 0x01, 0x20, 0x82, 0x02, 0xe1,
  347. 0x01, 0x01, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
  348. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  349. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} },
  350. {4, /* Bayer 640x480 */
  351. {0x01, 0x02, 0x20, 0x01, 0x20, 0x82, 0x02, 0xe1,
  352. 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
  353. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  354. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} },
  355. },
  356. };
  357. struct sensor_s {
  358. const char *name;
  359. u8 i2c_addr;
  360. u8 i2c_dum;
  361. u8 gpio[5];
  362. u8 cmd_len;
  363. const struct ucbus_write_cmd *cmd;
  364. };
  365. static const struct sensor_s sensor_tb[] = {
  366. [SENSOR_ICX098BQ] = {
  367. "icx098bp",
  368. 0x00, 0x00,
  369. {0,
  370. SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL,
  371. SQ930_GPIO_DFL_I2C_SDA,
  372. 0,
  373. SQ930_GPIO_RSTBAR
  374. },
  375. 8, icx098bq_start_0
  376. },
  377. [SENSOR_LZ24BP] = {
  378. "lz24bp",
  379. 0x00, 0x00,
  380. {0,
  381. SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL,
  382. SQ930_GPIO_DFL_I2C_SDA,
  383. 0,
  384. SQ930_GPIO_RSTBAR
  385. },
  386. 8, lz24bp_start_0
  387. },
  388. [SENSOR_MI0360] = {
  389. "mi0360",
  390. 0x5d, 0x80,
  391. {SQ930_GPIO_RSTBAR,
  392. SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL,
  393. SQ930_GPIO_DFL_I2C_SDA,
  394. 0,
  395. 0
  396. },
  397. 7, mi0360_start_0
  398. },
  399. [SENSOR_MT9V111] = {
  400. "mt9v111",
  401. 0x5c, 0x7f,
  402. {SQ930_GPIO_RSTBAR,
  403. SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL,
  404. SQ930_GPIO_DFL_I2C_SDA,
  405. 0,
  406. 0
  407. },
  408. 7, mi0360_start_0
  409. },
  410. [SENSOR_OV7660] = {
  411. "ov7660",
  412. 0x21, 0x00,
  413. {0,
  414. SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL,
  415. SQ930_GPIO_DFL_I2C_SDA,
  416. 0,
  417. SQ930_GPIO_RSTBAR
  418. },
  419. 7, ov7660_start_0
  420. },
  421. [SENSOR_OV9630] = {
  422. "ov9630",
  423. 0x30, 0x00,
  424. {0,
  425. SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL,
  426. SQ930_GPIO_DFL_I2C_SDA,
  427. 0,
  428. SQ930_GPIO_RSTBAR
  429. },
  430. 7, ov9630_start_0
  431. },
  432. };
  433. static void reg_r(struct gspca_dev *gspca_dev,
  434. u16 value, int len)
  435. {
  436. int ret;
  437. if (gspca_dev->usb_err < 0)
  438. return;
  439. ret = usb_control_msg(gspca_dev->dev,
  440. usb_rcvctrlpipe(gspca_dev->dev, 0),
  441. 0x0c,
  442. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  443. value, 0, gspca_dev->usb_buf, len,
  444. 500);
  445. if (ret < 0) {
  446. pr_err("reg_r %04x failed %d\n", value, ret);
  447. gspca_dev->usb_err = ret;
  448. }
  449. }
  450. static void reg_w(struct gspca_dev *gspca_dev, u16 value, u16 index)
  451. {
  452. int ret;
  453. if (gspca_dev->usb_err < 0)
  454. return;
  455. PDEBUG(D_USBO, "reg_w v: %04x i: %04x", value, index);
  456. ret = usb_control_msg(gspca_dev->dev,
  457. usb_sndctrlpipe(gspca_dev->dev, 0),
  458. 0x0c, /* request */
  459. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  460. value, index, NULL, 0,
  461. 500);
  462. msleep(30);
  463. if (ret < 0) {
  464. pr_err("reg_w %04x %04x failed %d\n", value, index, ret);
  465. gspca_dev->usb_err = ret;
  466. }
  467. }
  468. static void reg_wb(struct gspca_dev *gspca_dev, u16 value, u16 index,
  469. const u8 *data, int len)
  470. {
  471. int ret;
  472. if (gspca_dev->usb_err < 0)
  473. return;
  474. PDEBUG(D_USBO, "reg_wb v: %04x i: %04x %02x...%02x",
  475. value, index, *data, data[len - 1]);
  476. memcpy(gspca_dev->usb_buf, data, len);
  477. ret = usb_control_msg(gspca_dev->dev,
  478. usb_sndctrlpipe(gspca_dev->dev, 0),
  479. 0x0c, /* request */
  480. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  481. value, index, gspca_dev->usb_buf, len,
  482. 1000);
  483. msleep(30);
  484. if (ret < 0) {
  485. pr_err("reg_wb %04x %04x failed %d\n", value, index, ret);
  486. gspca_dev->usb_err = ret;
  487. }
  488. }
  489. static void i2c_write(struct sd *sd,
  490. const struct i2c_write_cmd *cmd,
  491. int ncmds)
  492. {
  493. struct gspca_dev *gspca_dev = &sd->gspca_dev;
  494. const struct sensor_s *sensor;
  495. u16 val, idx;
  496. u8 *buf;
  497. int ret;
  498. if (gspca_dev->usb_err < 0)
  499. return;
  500. sensor = &sensor_tb[sd->sensor];
  501. val = (sensor->i2c_addr << 8) | SQ930_CTRL_I2C_IO;
  502. idx = (cmd->val & 0xff00) | cmd->reg;
  503. buf = gspca_dev->usb_buf;
  504. *buf++ = sensor->i2c_dum;
  505. *buf++ = cmd->val;
  506. while (--ncmds > 0) {
  507. cmd++;
  508. *buf++ = cmd->reg;
  509. *buf++ = cmd->val >> 8;
  510. *buf++ = sensor->i2c_dum;
  511. *buf++ = cmd->val;
  512. }
  513. PDEBUG(D_USBO, "i2c_w v: %04x i: %04x %02x...%02x",
  514. val, idx, gspca_dev->usb_buf[0], buf[-1]);
  515. ret = usb_control_msg(gspca_dev->dev,
  516. usb_sndctrlpipe(gspca_dev->dev, 0),
  517. 0x0c, /* request */
  518. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  519. val, idx,
  520. gspca_dev->usb_buf, buf - gspca_dev->usb_buf,
  521. 500);
  522. if (ret < 0) {
  523. pr_err("i2c_write failed %d\n", ret);
  524. gspca_dev->usb_err = ret;
  525. }
  526. }
  527. static void ucbus_write(struct gspca_dev *gspca_dev,
  528. const struct ucbus_write_cmd *cmd,
  529. int ncmds,
  530. int batchsize)
  531. {
  532. u8 *buf;
  533. u16 val, idx;
  534. int len, ret;
  535. if (gspca_dev->usb_err < 0)
  536. return;
  537. #ifdef GSPCA_DEBUG
  538. if ((batchsize - 1) * 3 > USB_BUF_SZ) {
  539. pr_err("Bug: usb_buf overflow\n");
  540. gspca_dev->usb_err = -ENOMEM;
  541. return;
  542. }
  543. #endif
  544. for (;;) {
  545. len = ncmds;
  546. if (len > batchsize)
  547. len = batchsize;
  548. ncmds -= len;
  549. val = (cmd->bw_addr << 8) | SQ930_CTRL_UCBUS_IO;
  550. idx = (cmd->bw_data << 8) | (cmd->bw_addr >> 8);
  551. buf = gspca_dev->usb_buf;
  552. while (--len > 0) {
  553. cmd++;
  554. *buf++ = cmd->bw_addr;
  555. *buf++ = cmd->bw_addr >> 8;
  556. *buf++ = cmd->bw_data;
  557. }
  558. if (buf != gspca_dev->usb_buf)
  559. PDEBUG(D_USBO, "ucbus v: %04x i: %04x %02x...%02x",
  560. val, idx,
  561. gspca_dev->usb_buf[0], buf[-1]);
  562. else
  563. PDEBUG(D_USBO, "ucbus v: %04x i: %04x",
  564. val, idx);
  565. ret = usb_control_msg(gspca_dev->dev,
  566. usb_sndctrlpipe(gspca_dev->dev, 0),
  567. 0x0c, /* request */
  568. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
  569. val, idx,
  570. gspca_dev->usb_buf, buf - gspca_dev->usb_buf,
  571. 500);
  572. if (ret < 0) {
  573. pr_err("ucbus_write failed %d\n", ret);
  574. gspca_dev->usb_err = ret;
  575. return;
  576. }
  577. msleep(30);
  578. if (ncmds <= 0)
  579. break;
  580. cmd++;
  581. }
  582. }
  583. static void gpio_set(struct sd *sd, u16 val, u16 mask)
  584. {
  585. struct gspca_dev *gspca_dev = &sd->gspca_dev;
  586. if (mask & 0x00ff) {
  587. sd->gpio[0] &= ~mask;
  588. sd->gpio[0] |= val;
  589. reg_w(gspca_dev, 0x0100 | SQ930_CTRL_GPIO,
  590. ~sd->gpio[0] << 8);
  591. }
  592. mask >>= 8;
  593. val >>= 8;
  594. if (mask) {
  595. sd->gpio[1] &= ~mask;
  596. sd->gpio[1] |= val;
  597. reg_w(gspca_dev, 0x0300 | SQ930_CTRL_GPIO,
  598. ~sd->gpio[1] << 8);
  599. }
  600. }
  601. static void gpio_init(struct sd *sd,
  602. const u8 *gpio)
  603. {
  604. gpio_set(sd, *gpio++, 0x000f);
  605. gpio_set(sd, *gpio++, 0x000f);
  606. gpio_set(sd, *gpio++, 0x000f);
  607. gpio_set(sd, *gpio++, 0x000f);
  608. gpio_set(sd, *gpio, 0x000f);
  609. }
  610. static void bridge_init(struct sd *sd)
  611. {
  612. static const struct ucbus_write_cmd clkfreq_cmd = {
  613. 0xf031, 0 /* SQ930_CLKFREQ_60MHZ */
  614. };
  615. ucbus_write(&sd->gspca_dev, &clkfreq_cmd, 1, 1);
  616. gpio_set(sd, SQ930_GPIO_POWER, 0xff00);
  617. }
  618. static void cmos_probe(struct gspca_dev *gspca_dev)
  619. {
  620. struct sd *sd = (struct sd *) gspca_dev;
  621. int i;
  622. const struct sensor_s *sensor;
  623. static const u8 probe_order[] = {
  624. /* SENSOR_LZ24BP, (tested as ccd) */
  625. SENSOR_OV9630,
  626. SENSOR_MI0360,
  627. SENSOR_OV7660,
  628. SENSOR_MT9V111,
  629. };
  630. for (i = 0; i < ARRAY_SIZE(probe_order); i++) {
  631. sensor = &sensor_tb[probe_order[i]];
  632. ucbus_write(&sd->gspca_dev, sensor->cmd, sensor->cmd_len, 8);
  633. gpio_init(sd, sensor->gpio);
  634. msleep(100);
  635. reg_r(gspca_dev, (sensor->i2c_addr << 8) | 0x001c, 1);
  636. msleep(100);
  637. if (gspca_dev->usb_buf[0] != 0)
  638. break;
  639. }
  640. if (i >= ARRAY_SIZE(probe_order)) {
  641. pr_err("Unknown sensor\n");
  642. gspca_dev->usb_err = -EINVAL;
  643. return;
  644. }
  645. sd->sensor = probe_order[i];
  646. switch (sd->sensor) {
  647. case SENSOR_OV7660:
  648. case SENSOR_OV9630:
  649. pr_err("Sensor %s not yet treated\n",
  650. sensor_tb[sd->sensor].name);
  651. gspca_dev->usb_err = -EINVAL;
  652. break;
  653. }
  654. }
  655. static void mt9v111_init(struct gspca_dev *gspca_dev)
  656. {
  657. int i, nwait;
  658. static const u8 cmd_001b[] = {
  659. 0x00, 0x3b, 0xf6, 0x01, 0x03, 0x02, 0x00, 0x00,
  660. 0x00, 0x00, 0x00
  661. };
  662. static const u8 cmd_011b[][7] = {
  663. {0x10, 0x01, 0x66, 0x08, 0x00, 0x00, 0x00},
  664. {0x01, 0x00, 0x1a, 0x04, 0x00, 0x00, 0x00},
  665. {0x20, 0x00, 0x10, 0x04, 0x00, 0x00, 0x00},
  666. {0x02, 0x01, 0xae, 0x01, 0x00, 0x00, 0x00},
  667. };
  668. reg_wb(gspca_dev, 0x001b, 0x0000, cmd_001b, sizeof cmd_001b);
  669. for (i = 0; i < ARRAY_SIZE(cmd_011b); i++) {
  670. reg_wb(gspca_dev, 0x001b, 0x0000, cmd_011b[i],
  671. ARRAY_SIZE(cmd_011b[0]));
  672. msleep(400);
  673. nwait = 20;
  674. for (;;) {
  675. reg_r(gspca_dev, 0x031b, 1);
  676. if (gspca_dev->usb_buf[0] == 0
  677. || gspca_dev->usb_err != 0)
  678. break;
  679. if (--nwait < 0) {
  680. PDEBUG(D_PROBE, "mt9v111_init timeout");
  681. gspca_dev->usb_err = -ETIME;
  682. return;
  683. }
  684. msleep(50);
  685. }
  686. }
  687. }
  688. static void global_init(struct sd *sd, int first_time)
  689. {
  690. switch (sd->sensor) {
  691. case SENSOR_ICX098BQ:
  692. if (first_time)
  693. ucbus_write(&sd->gspca_dev,
  694. icx098bq_start_0,
  695. 8, 8);
  696. gpio_init(sd, sensor_tb[sd->sensor].gpio);
  697. break;
  698. case SENSOR_LZ24BP:
  699. if (sd->type != Creative_live_motion)
  700. gpio_set(sd, SQ930_GPIO_EXTRA1, 0x00ff);
  701. else
  702. gpio_set(sd, 0, 0x00ff);
  703. msleep(50);
  704. if (first_time)
  705. ucbus_write(&sd->gspca_dev,
  706. lz24bp_start_0,
  707. 8, 8);
  708. gpio_init(sd, sensor_tb[sd->sensor].gpio);
  709. break;
  710. case SENSOR_MI0360:
  711. if (first_time)
  712. ucbus_write(&sd->gspca_dev,
  713. mi0360_start_0,
  714. ARRAY_SIZE(mi0360_start_0),
  715. 8);
  716. gpio_init(sd, sensor_tb[sd->sensor].gpio);
  717. gpio_set(sd, SQ930_GPIO_EXTRA2, SQ930_GPIO_EXTRA2);
  718. break;
  719. default:
  720. /* case SENSOR_MT9V111: */
  721. if (first_time)
  722. mt9v111_init(&sd->gspca_dev);
  723. else
  724. gpio_init(sd, sensor_tb[sd->sensor].gpio);
  725. break;
  726. }
  727. }
  728. static void lz24bp_ppl(struct sd *sd, u16 ppl)
  729. {
  730. struct ucbus_write_cmd cmds[2] = {
  731. {0xf810, ppl >> 8},
  732. {0xf811, ppl}
  733. };
  734. ucbus_write(&sd->gspca_dev, cmds, ARRAY_SIZE(cmds), 2);
  735. }
  736. static void setexposure(struct gspca_dev *gspca_dev)
  737. {
  738. struct sd *sd = (struct sd *) gspca_dev;
  739. int i, integclks, intstartclk, frameclks, min_frclk;
  740. const struct sensor_s *sensor;
  741. u16 cmd;
  742. u8 buf[15];
  743. integclks = sd->expo;
  744. i = 0;
  745. cmd = SQ930_CTRL_SET_EXPOSURE;
  746. switch (sd->sensor) {
  747. case SENSOR_ICX098BQ: /* ccd */
  748. case SENSOR_LZ24BP:
  749. min_frclk = sd->sensor == SENSOR_ICX098BQ ? 0x210 : 0x26f;
  750. if (integclks >= min_frclk) {
  751. intstartclk = 0;
  752. frameclks = integclks;
  753. } else {
  754. intstartclk = min_frclk - integclks;
  755. frameclks = min_frclk;
  756. }
  757. buf[i++] = intstartclk >> 8;
  758. buf[i++] = intstartclk;
  759. buf[i++] = frameclks >> 8;
  760. buf[i++] = frameclks;
  761. buf[i++] = sd->gain;
  762. break;
  763. default: /* cmos */
  764. /* case SENSOR_MI0360: */
  765. /* case SENSOR_MT9V111: */
  766. cmd |= 0x0100;
  767. sensor = &sensor_tb[sd->sensor];
  768. buf[i++] = sensor->i2c_addr; /* i2c_slave_addr */
  769. buf[i++] = 0x08; /* 2 * ni2c */
  770. buf[i++] = 0x09; /* reg = shutter width */
  771. buf[i++] = integclks >> 8; /* val H */
  772. buf[i++] = sensor->i2c_dum;
  773. buf[i++] = integclks; /* val L */
  774. buf[i++] = 0x35; /* reg = global gain */
  775. buf[i++] = 0x00; /* val H */
  776. buf[i++] = sensor->i2c_dum;
  777. buf[i++] = 0x80 + sd->gain / 2; /* val L */
  778. buf[i++] = 0x00;
  779. buf[i++] = 0x00;
  780. buf[i++] = 0x00;
  781. buf[i++] = 0x00;
  782. buf[i++] = 0x83;
  783. break;
  784. }
  785. reg_wb(gspca_dev, cmd, 0, buf, i);
  786. }
  787. /* This function is called at probe time just before sd_init */
  788. static int sd_config(struct gspca_dev *gspca_dev,
  789. const struct usb_device_id *id)
  790. {
  791. struct sd *sd = (struct sd *) gspca_dev;
  792. struct cam *cam = &gspca_dev->cam;
  793. sd->sensor = id->driver_info >> 8;
  794. sd->type = id->driver_info;
  795. cam->cam_mode = vga_mode;
  796. cam->nmodes = ARRAY_SIZE(vga_mode);
  797. cam->bulk = 1;
  798. sd->gain = GAIN_DEF;
  799. sd->expo = EXPO_DEF;
  800. return 0;
  801. }
  802. /* this function is called at probe and resume time */
  803. static int sd_init(struct gspca_dev *gspca_dev)
  804. {
  805. struct sd *sd = (struct sd *) gspca_dev;
  806. sd->gpio[0] = sd->gpio[1] = 0xff; /* force gpio rewrite */
  807. /*fixme: is this needed for icx098bp and mi0360?
  808. if (sd->sensor != SENSOR_LZ24BP)
  809. reg_w(gspca_dev, SQ930_CTRL_RESET, 0x0000);
  810. */
  811. reg_r(gspca_dev, SQ930_CTRL_GET_DEV_INFO, 8);
  812. if (gspca_dev->usb_err < 0)
  813. return gspca_dev->usb_err;
  814. /* it returns:
  815. * 03 00 12 93 0b f6 c9 00 live! ultra
  816. * 03 00 07 93 0b f6 ca 00 live! ultra for notebook
  817. * 03 00 12 93 0b fe c8 00 Trust WB-3500T
  818. * 02 00 06 93 0b fe c8 00 Joy-IT 318S
  819. * 03 00 12 93 0b f6 cf 00 icam tracer - sensor icx098bq
  820. * 02 00 12 93 0b fe cf 00 ProQ Motion Webcam
  821. *
  822. * byte
  823. * 0: 02 = usb 1.0 (12Mbit) / 03 = usb2.0 (480Mbit)
  824. * 1: 00
  825. * 2: 06 / 07 / 12 = mode webcam? firmware??
  826. * 3: 93 chip = 930b (930b or 930c)
  827. * 4: 0b
  828. * 5: f6 = cdd (icx098bq, lz24bp) / fe or de = cmos (i2c) (other sensors)
  829. * 6: c8 / c9 / ca / cf = mode webcam?, sensor? webcam?
  830. * 7: 00
  831. */
  832. PDEBUG(D_PROBE, "info: %02x %02x %02x %02x %02x %02x %02x %02x",
  833. gspca_dev->usb_buf[0],
  834. gspca_dev->usb_buf[1],
  835. gspca_dev->usb_buf[2],
  836. gspca_dev->usb_buf[3],
  837. gspca_dev->usb_buf[4],
  838. gspca_dev->usb_buf[5],
  839. gspca_dev->usb_buf[6],
  840. gspca_dev->usb_buf[7]);
  841. bridge_init(sd);
  842. if (sd->sensor == SENSOR_MI0360) {
  843. /* no sensor probe for icam tracer */
  844. if (gspca_dev->usb_buf[5] == 0xf6) /* if ccd */
  845. sd->sensor = SENSOR_ICX098BQ;
  846. else
  847. cmos_probe(gspca_dev);
  848. }
  849. if (gspca_dev->usb_err >= 0) {
  850. PDEBUG(D_PROBE, "Sensor %s", sensor_tb[sd->sensor].name);
  851. global_init(sd, 1);
  852. }
  853. return gspca_dev->usb_err;
  854. }
  855. /* send the start/stop commands to the webcam */
  856. static void send_start(struct gspca_dev *gspca_dev)
  857. {
  858. struct sd *sd = (struct sd *) gspca_dev;
  859. const struct cap_s *cap;
  860. int mode;
  861. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  862. cap = &capconfig[sd->sensor][mode];
  863. reg_wb(gspca_dev, 0x0900 | SQ930_CTRL_CAP_START,
  864. 0x0a00 | cap->cc_sizeid,
  865. cap->cc_bytes, 32);
  866. }
  867. static void send_stop(struct gspca_dev *gspca_dev)
  868. {
  869. reg_w(gspca_dev, SQ930_CTRL_CAP_STOP, 0);
  870. }
  871. /* function called at start time before URB creation */
  872. static int sd_isoc_init(struct gspca_dev *gspca_dev)
  873. {
  874. struct sd *sd = (struct sd *) gspca_dev;
  875. gspca_dev->cam.bulk_nurbs = 1; /* there must be one URB only */
  876. sd->do_ctrl = 0;
  877. gspca_dev->cam.bulk_size = gspca_dev->width * gspca_dev->height + 8;
  878. return 0;
  879. }
  880. /* start the capture */
  881. static int sd_start(struct gspca_dev *gspca_dev)
  882. {
  883. struct sd *sd = (struct sd *) gspca_dev;
  884. int mode;
  885. bridge_init(sd);
  886. global_init(sd, 0);
  887. msleep(100);
  888. switch (sd->sensor) {
  889. case SENSOR_ICX098BQ:
  890. ucbus_write(gspca_dev, icx098bq_start_0,
  891. ARRAY_SIZE(icx098bq_start_0),
  892. 8);
  893. ucbus_write(gspca_dev, icx098bq_start_1,
  894. ARRAY_SIZE(icx098bq_start_1),
  895. 5);
  896. ucbus_write(gspca_dev, icx098bq_start_2,
  897. ARRAY_SIZE(icx098bq_start_2),
  898. 6);
  899. msleep(50);
  900. /* 1st start */
  901. send_start(gspca_dev);
  902. gpio_set(sd, SQ930_GPIO_EXTRA2 | SQ930_GPIO_RSTBAR, 0x00ff);
  903. msleep(70);
  904. reg_w(gspca_dev, SQ930_CTRL_CAP_STOP, 0x0000);
  905. gpio_set(sd, 0x7f, 0x00ff);
  906. /* 2nd start */
  907. send_start(gspca_dev);
  908. gpio_set(sd, SQ930_GPIO_EXTRA2 | SQ930_GPIO_RSTBAR, 0x00ff);
  909. goto out;
  910. case SENSOR_LZ24BP:
  911. ucbus_write(gspca_dev, lz24bp_start_0,
  912. ARRAY_SIZE(lz24bp_start_0),
  913. 8);
  914. if (sd->type != Creative_live_motion)
  915. ucbus_write(gspca_dev, lz24bp_start_1_gen,
  916. ARRAY_SIZE(lz24bp_start_1_gen),
  917. 5);
  918. else
  919. ucbus_write(gspca_dev, lz24bp_start_1_clm,
  920. ARRAY_SIZE(lz24bp_start_1_clm),
  921. 5);
  922. ucbus_write(gspca_dev, lz24bp_start_2,
  923. ARRAY_SIZE(lz24bp_start_2),
  924. 6);
  925. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  926. lz24bp_ppl(sd, mode == 1 ? 0x0564 : 0x0310);
  927. msleep(10);
  928. break;
  929. case SENSOR_MI0360:
  930. ucbus_write(gspca_dev, mi0360_start_0,
  931. ARRAY_SIZE(mi0360_start_0),
  932. 8);
  933. i2c_write(sd, mi0360_init_23,
  934. ARRAY_SIZE(mi0360_init_23));
  935. i2c_write(sd, mi0360_init_24,
  936. ARRAY_SIZE(mi0360_init_24));
  937. i2c_write(sd, mi0360_init_25,
  938. ARRAY_SIZE(mi0360_init_25));
  939. ucbus_write(gspca_dev, mi0360_start_1,
  940. ARRAY_SIZE(mi0360_start_1),
  941. 5);
  942. i2c_write(sd, mi0360_start_2,
  943. ARRAY_SIZE(mi0360_start_2));
  944. i2c_write(sd, mi0360_start_3,
  945. ARRAY_SIZE(mi0360_start_3));
  946. /* 1st start */
  947. send_start(gspca_dev);
  948. msleep(60);
  949. send_stop(gspca_dev);
  950. i2c_write(sd,
  951. mi0360_start_4, ARRAY_SIZE(mi0360_start_4));
  952. break;
  953. default:
  954. /* case SENSOR_MT9V111: */
  955. ucbus_write(gspca_dev, mi0360_start_0,
  956. ARRAY_SIZE(mi0360_start_0),
  957. 8);
  958. i2c_write(sd, mt9v111_init_0,
  959. ARRAY_SIZE(mt9v111_init_0));
  960. i2c_write(sd, mt9v111_init_1,
  961. ARRAY_SIZE(mt9v111_init_1));
  962. i2c_write(sd, mt9v111_init_2,
  963. ARRAY_SIZE(mt9v111_init_2));
  964. ucbus_write(gspca_dev, mt9v111_start_1,
  965. ARRAY_SIZE(mt9v111_start_1),
  966. 5);
  967. i2c_write(sd, mt9v111_init_3,
  968. ARRAY_SIZE(mt9v111_init_3));
  969. i2c_write(sd, mt9v111_init_4,
  970. ARRAY_SIZE(mt9v111_init_4));
  971. break;
  972. }
  973. send_start(gspca_dev);
  974. out:
  975. msleep(1000);
  976. if (sd->sensor == SENSOR_MT9V111)
  977. gpio_set(sd, SQ930_GPIO_DFL_LED, SQ930_GPIO_DFL_LED);
  978. sd->do_ctrl = 1; /* set the exposure */
  979. return gspca_dev->usb_err;
  980. }
  981. static void sd_stopN(struct gspca_dev *gspca_dev)
  982. {
  983. struct sd *sd = (struct sd *) gspca_dev;
  984. if (sd->sensor == SENSOR_MT9V111)
  985. gpio_set(sd, 0, SQ930_GPIO_DFL_LED);
  986. send_stop(gspca_dev);
  987. }
  988. /* function called when the application gets a new frame */
  989. /* It sets the exposure if required and restart the bulk transfer. */
  990. static void sd_dq_callback(struct gspca_dev *gspca_dev)
  991. {
  992. struct sd *sd = (struct sd *) gspca_dev;
  993. int ret;
  994. if (!sd->do_ctrl || gspca_dev->cam.bulk_nurbs != 0)
  995. return;
  996. sd->do_ctrl = 0;
  997. setexposure(gspca_dev);
  998. gspca_dev->cam.bulk_nurbs = 1;
  999. ret = usb_submit_urb(gspca_dev->urb[0], GFP_ATOMIC);
  1000. if (ret < 0)
  1001. pr_err("sd_dq_callback() err %d\n", ret);
  1002. /* wait a little time, otherwise the webcam crashes */
  1003. msleep(100);
  1004. }
  1005. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  1006. u8 *data, /* isoc packet */
  1007. int len) /* iso packet length */
  1008. {
  1009. struct sd *sd = (struct sd *) gspca_dev;
  1010. if (sd->do_ctrl)
  1011. gspca_dev->cam.bulk_nurbs = 0;
  1012. gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
  1013. gspca_frame_add(gspca_dev, INTER_PACKET, data, len - 8);
  1014. gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
  1015. }
  1016. static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
  1017. {
  1018. struct sd *sd = (struct sd *) gspca_dev;
  1019. sd->gain = val;
  1020. if (gspca_dev->streaming)
  1021. sd->do_ctrl = 1;
  1022. return 0;
  1023. }
  1024. static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
  1025. {
  1026. struct sd *sd = (struct sd *) gspca_dev;
  1027. *val = sd->gain;
  1028. return 0;
  1029. }
  1030. static int sd_setexpo(struct gspca_dev *gspca_dev, __s32 val)
  1031. {
  1032. struct sd *sd = (struct sd *) gspca_dev;
  1033. sd->expo = val;
  1034. if (gspca_dev->streaming)
  1035. sd->do_ctrl = 1;
  1036. return 0;
  1037. }
  1038. static int sd_getexpo(struct gspca_dev *gspca_dev, __s32 *val)
  1039. {
  1040. struct sd *sd = (struct sd *) gspca_dev;
  1041. *val = sd->expo;
  1042. return 0;
  1043. }
  1044. /* sub-driver description */
  1045. static const struct sd_desc sd_desc = {
  1046. .name = MODULE_NAME,
  1047. .ctrls = sd_ctrls,
  1048. .nctrls = ARRAY_SIZE(sd_ctrls),
  1049. .config = sd_config,
  1050. .init = sd_init,
  1051. .isoc_init = sd_isoc_init,
  1052. .start = sd_start,
  1053. .stopN = sd_stopN,
  1054. .pkt_scan = sd_pkt_scan,
  1055. .dq_callback = sd_dq_callback,
  1056. };
  1057. /* Table of supported USB devices */
  1058. #define ST(sensor, type) \
  1059. .driver_info = (SENSOR_ ## sensor << 8) \
  1060. | (type)
  1061. static const struct usb_device_id device_table[] = {
  1062. {USB_DEVICE(0x041e, 0x4038), ST(MI0360, 0)},
  1063. {USB_DEVICE(0x041e, 0x403c), ST(LZ24BP, 0)},
  1064. {USB_DEVICE(0x041e, 0x403d), ST(LZ24BP, 0)},
  1065. {USB_DEVICE(0x041e, 0x4041), ST(LZ24BP, Creative_live_motion)},
  1066. {USB_DEVICE(0x2770, 0x930b), ST(MI0360, 0)},
  1067. {USB_DEVICE(0x2770, 0x930c), ST(MI0360, 0)},
  1068. {}
  1069. };
  1070. MODULE_DEVICE_TABLE(usb, device_table);
  1071. /* -- device connect -- */
  1072. static int sd_probe(struct usb_interface *intf,
  1073. const struct usb_device_id *id)
  1074. {
  1075. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  1076. THIS_MODULE);
  1077. }
  1078. static struct usb_driver sd_driver = {
  1079. .name = MODULE_NAME,
  1080. .id_table = device_table,
  1081. .probe = sd_probe,
  1082. .disconnect = gspca_disconnect,
  1083. #ifdef CONFIG_PM
  1084. .suspend = gspca_suspend,
  1085. .resume = gspca_resume,
  1086. #endif
  1087. };
  1088. module_usb_driver(sd_driver);