sonixj.c 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121
  1. /*
  2. * Sonix sn9c102p sn9c105 sn9c120 (jpeg) subdriver
  3. *
  4. * Copyright (C) 2009-2010 Jean-François Moine <http://moinejf.free.fr>
  5. * Copyright (C) 2005 Michel Xhaard mxhaard@magic.fr
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  22. #define MODULE_NAME "sonixj"
  23. #include <linux/input.h>
  24. #include "gspca.h"
  25. #include "jpeg.h"
  26. MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
  27. MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
  28. MODULE_LICENSE("GPL");
  29. /* controls */
  30. enum e_ctrl {
  31. BRIGHTNESS,
  32. CONTRAST,
  33. COLORS,
  34. BLUE,
  35. RED,
  36. GAMMA,
  37. AUTOGAIN,
  38. HFLIP,
  39. VFLIP,
  40. SHARPNESS,
  41. ILLUM,
  42. FREQ,
  43. NCTRLS /* number of controls */
  44. };
  45. /* specific webcam descriptor */
  46. struct sd {
  47. struct gspca_dev gspca_dev; /* !! must be the first item */
  48. struct gspca_ctrl ctrls[NCTRLS];
  49. atomic_t avg_lum;
  50. u32 exposure;
  51. struct work_struct work;
  52. struct workqueue_struct *work_thread;
  53. u32 pktsz; /* (used by pkt_scan) */
  54. u16 npkt;
  55. s8 nchg;
  56. s8 short_mark;
  57. u8 quality; /* image quality */
  58. #define QUALITY_MIN 25
  59. #define QUALITY_MAX 90
  60. #define QUALITY_DEF 70
  61. u8 reg01;
  62. u8 reg17;
  63. u8 reg18;
  64. u8 flags;
  65. s8 ag_cnt;
  66. #define AG_CNT_START 13
  67. u8 bridge;
  68. #define BRIDGE_SN9C102P 0
  69. #define BRIDGE_SN9C105 1
  70. #define BRIDGE_SN9C110 2
  71. #define BRIDGE_SN9C120 3
  72. u8 sensor; /* Type of image sensor chip */
  73. u8 i2c_addr;
  74. u8 jpeg_hdr[JPEG_HDR_SZ];
  75. };
  76. enum sensors {
  77. SENSOR_ADCM1700,
  78. SENSOR_GC0307,
  79. SENSOR_HV7131R,
  80. SENSOR_MI0360,
  81. SENSOR_MI0360B,
  82. SENSOR_MO4000,
  83. SENSOR_MT9V111,
  84. SENSOR_OM6802,
  85. SENSOR_OV7630,
  86. SENSOR_OV7648,
  87. SENSOR_OV7660,
  88. SENSOR_PO1030,
  89. SENSOR_PO2030N,
  90. SENSOR_SOI768,
  91. SENSOR_SP80708,
  92. };
  93. static void qual_upd(struct work_struct *work);
  94. /* device flags */
  95. #define F_PDN_INV 0x01 /* inverse pin S_PWR_DN / sn_xxx tables */
  96. #define F_ILLUM 0x02 /* presence of illuminator */
  97. /* sn9c1xx definitions */
  98. /* register 0x01 */
  99. #define S_PWR_DN 0x01 /* sensor power down */
  100. #define S_PDN_INV 0x02 /* inverse pin S_PWR_DN */
  101. #define V_TX_EN 0x04 /* video transfer enable */
  102. #define LED 0x08 /* output to pin LED */
  103. #define SCL_SEL_OD 0x20 /* open-drain mode */
  104. #define SYS_SEL_48M 0x40 /* system clock 0: 24MHz, 1: 48MHz */
  105. /* register 0x17 */
  106. #define MCK_SIZE_MASK 0x1f /* sensor master clock */
  107. #define SEN_CLK_EN 0x20 /* enable sensor clock */
  108. #define DEF_EN 0x80 /* defect pixel by 0: soft, 1: hard */
  109. /* V4L2 controls supported by the driver */
  110. static void setbrightness(struct gspca_dev *gspca_dev);
  111. static void setcontrast(struct gspca_dev *gspca_dev);
  112. static void setcolors(struct gspca_dev *gspca_dev);
  113. static void setredblue(struct gspca_dev *gspca_dev);
  114. static void setgamma(struct gspca_dev *gspca_dev);
  115. static void setautogain(struct gspca_dev *gspca_dev);
  116. static void sethvflip(struct gspca_dev *gspca_dev);
  117. static void setsharpness(struct gspca_dev *gspca_dev);
  118. static void setillum(struct gspca_dev *gspca_dev);
  119. static void setfreq(struct gspca_dev *gspca_dev);
  120. static const struct ctrl sd_ctrls[NCTRLS] = {
  121. [BRIGHTNESS] = {
  122. {
  123. .id = V4L2_CID_BRIGHTNESS,
  124. .type = V4L2_CTRL_TYPE_INTEGER,
  125. .name = "Brightness",
  126. .minimum = 0,
  127. .maximum = 0xff,
  128. .step = 1,
  129. .default_value = 0x80,
  130. },
  131. .set_control = setbrightness
  132. },
  133. [CONTRAST] = {
  134. {
  135. .id = V4L2_CID_CONTRAST,
  136. .type = V4L2_CTRL_TYPE_INTEGER,
  137. .name = "Contrast",
  138. .minimum = 0,
  139. #define CONTRAST_MAX 127
  140. .maximum = CONTRAST_MAX,
  141. .step = 1,
  142. .default_value = 63,
  143. },
  144. .set_control = setcontrast
  145. },
  146. [COLORS] = {
  147. {
  148. .id = V4L2_CID_SATURATION,
  149. .type = V4L2_CTRL_TYPE_INTEGER,
  150. .name = "Saturation",
  151. .minimum = 0,
  152. .maximum = 40,
  153. .step = 1,
  154. #define COLORS_DEF 25
  155. .default_value = COLORS_DEF,
  156. },
  157. .set_control = setcolors
  158. },
  159. [BLUE] = {
  160. {
  161. .id = V4L2_CID_BLUE_BALANCE,
  162. .type = V4L2_CTRL_TYPE_INTEGER,
  163. .name = "Blue Balance",
  164. .minimum = 24,
  165. .maximum = 40,
  166. .step = 1,
  167. .default_value = 32,
  168. },
  169. .set_control = setredblue
  170. },
  171. [RED] = {
  172. {
  173. .id = V4L2_CID_RED_BALANCE,
  174. .type = V4L2_CTRL_TYPE_INTEGER,
  175. .name = "Red Balance",
  176. .minimum = 24,
  177. .maximum = 40,
  178. .step = 1,
  179. .default_value = 32,
  180. },
  181. .set_control = setredblue
  182. },
  183. [GAMMA] = {
  184. {
  185. .id = V4L2_CID_GAMMA,
  186. .type = V4L2_CTRL_TYPE_INTEGER,
  187. .name = "Gamma",
  188. .minimum = 0,
  189. .maximum = 40,
  190. .step = 1,
  191. #define GAMMA_DEF 20
  192. .default_value = GAMMA_DEF,
  193. },
  194. .set_control = setgamma
  195. },
  196. [AUTOGAIN] = {
  197. {
  198. .id = V4L2_CID_AUTOGAIN,
  199. .type = V4L2_CTRL_TYPE_BOOLEAN,
  200. .name = "Auto Gain",
  201. .minimum = 0,
  202. .maximum = 1,
  203. .step = 1,
  204. .default_value = 1
  205. },
  206. .set_control = setautogain
  207. },
  208. [HFLIP] = {
  209. {
  210. .id = V4L2_CID_HFLIP,
  211. .type = V4L2_CTRL_TYPE_BOOLEAN,
  212. .name = "Mirror",
  213. .minimum = 0,
  214. .maximum = 1,
  215. .step = 1,
  216. .default_value = 0,
  217. },
  218. .set_control = sethvflip
  219. },
  220. [VFLIP] = {
  221. {
  222. .id = V4L2_CID_VFLIP,
  223. .type = V4L2_CTRL_TYPE_BOOLEAN,
  224. .name = "Vflip",
  225. .minimum = 0,
  226. .maximum = 1,
  227. .step = 1,
  228. .default_value = 0,
  229. },
  230. .set_control = sethvflip
  231. },
  232. [SHARPNESS] = {
  233. {
  234. .id = V4L2_CID_SHARPNESS,
  235. .type = V4L2_CTRL_TYPE_INTEGER,
  236. .name = "Sharpness",
  237. .minimum = 0,
  238. .maximum = 255,
  239. .step = 1,
  240. .default_value = 90,
  241. },
  242. .set_control = setsharpness
  243. },
  244. [ILLUM] = {
  245. {
  246. .id = V4L2_CID_ILLUMINATORS_1,
  247. .type = V4L2_CTRL_TYPE_BOOLEAN,
  248. .name = "Illuminator / infrared",
  249. .minimum = 0,
  250. .maximum = 1,
  251. .step = 1,
  252. .default_value = 0,
  253. },
  254. .set_control = setillum
  255. },
  256. /* ov7630/ov7648/ov7660 only */
  257. [FREQ] = {
  258. {
  259. .id = V4L2_CID_POWER_LINE_FREQUENCY,
  260. .type = V4L2_CTRL_TYPE_MENU,
  261. .name = "Light frequency filter",
  262. .minimum = 0,
  263. .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
  264. .step = 1,
  265. .default_value = 1,
  266. },
  267. .set_control = setfreq
  268. },
  269. };
  270. /* table of the disabled controls */
  271. static const __u32 ctrl_dis[] = {
  272. [SENSOR_ADCM1700] = (1 << AUTOGAIN) |
  273. (1 << HFLIP) |
  274. (1 << VFLIP) |
  275. (1 << FREQ),
  276. [SENSOR_GC0307] = (1 << HFLIP) |
  277. (1 << VFLIP) |
  278. (1 << FREQ),
  279. [SENSOR_HV7131R] = (1 << HFLIP) |
  280. (1 << FREQ),
  281. [SENSOR_MI0360] = (1 << HFLIP) |
  282. (1 << VFLIP) |
  283. (1 << FREQ),
  284. [SENSOR_MI0360B] = (1 << HFLIP) |
  285. (1 << VFLIP) |
  286. (1 << FREQ),
  287. [SENSOR_MO4000] = (1 << HFLIP) |
  288. (1 << VFLIP) |
  289. (1 << FREQ),
  290. [SENSOR_MT9V111] = (1 << HFLIP) |
  291. (1 << VFLIP) |
  292. (1 << FREQ),
  293. [SENSOR_OM6802] = (1 << HFLIP) |
  294. (1 << VFLIP) |
  295. (1 << FREQ),
  296. [SENSOR_OV7630] = (1 << HFLIP),
  297. [SENSOR_OV7648] = (1 << HFLIP),
  298. [SENSOR_OV7660] = (1 << AUTOGAIN) |
  299. (1 << HFLIP) |
  300. (1 << VFLIP),
  301. [SENSOR_PO1030] = (1 << AUTOGAIN) |
  302. (1 << HFLIP) |
  303. (1 << VFLIP) |
  304. (1 << FREQ),
  305. [SENSOR_PO2030N] = (1 << AUTOGAIN) |
  306. (1 << FREQ),
  307. [SENSOR_SOI768] = (1 << AUTOGAIN) |
  308. (1 << HFLIP) |
  309. (1 << VFLIP) |
  310. (1 << FREQ),
  311. [SENSOR_SP80708] = (1 << AUTOGAIN) |
  312. (1 << HFLIP) |
  313. (1 << VFLIP) |
  314. (1 << FREQ),
  315. };
  316. static const struct v4l2_pix_format cif_mode[] = {
  317. {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  318. .bytesperline = 352,
  319. .sizeimage = 352 * 288 * 4 / 8 + 590,
  320. .colorspace = V4L2_COLORSPACE_JPEG,
  321. .priv = 0},
  322. };
  323. static const struct v4l2_pix_format vga_mode[] = {
  324. {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  325. .bytesperline = 160,
  326. .sizeimage = 160 * 120 * 4 / 8 + 590,
  327. .colorspace = V4L2_COLORSPACE_JPEG,
  328. .priv = 2},
  329. {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  330. .bytesperline = 320,
  331. .sizeimage = 320 * 240 * 3 / 8 + 590,
  332. .colorspace = V4L2_COLORSPACE_JPEG,
  333. .priv = 1},
  334. {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
  335. .bytesperline = 640,
  336. /* Note 3 / 8 is not large enough, not even 5 / 8 is ?! */
  337. .sizeimage = 640 * 480 * 3 / 4 + 590,
  338. .colorspace = V4L2_COLORSPACE_JPEG,
  339. .priv = 0},
  340. };
  341. static const u8 sn_adcm1700[0x1c] = {
  342. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  343. 0x00, 0x43, 0x60, 0x00, 0x1a, 0x00, 0x00, 0x00,
  344. /* reg8 reg9 rega regb regc regd rege regf */
  345. 0x80, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  346. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  347. 0x03, 0x00, 0x05, 0x01, 0x05, 0x16, 0x12, 0x42,
  348. /* reg18 reg19 reg1a reg1b */
  349. 0x06, 0x00, 0x00, 0x00
  350. };
  351. static const u8 sn_gc0307[0x1c] = {
  352. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  353. 0x00, 0x61, 0x62, 0x00, 0x1a, 0x00, 0x00, 0x00,
  354. /* reg8 reg9 rega regb regc regd rege regf */
  355. 0x80, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  356. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  357. 0x03, 0x00, 0x03, 0x01, 0x08, 0x28, 0x1e, 0x02,
  358. /* reg18 reg19 reg1a reg1b */
  359. 0x06, 0x00, 0x00, 0x00
  360. };
  361. static const u8 sn_hv7131[0x1c] = {
  362. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  363. 0x00, 0x03, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
  364. /* reg8 reg9 rega regb regc regd rege regf */
  365. 0x81, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  366. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  367. 0x03, 0x00, 0x00, 0x01, 0x03, 0x28, 0x1e, 0x41,
  368. /* reg18 reg19 reg1a reg1b */
  369. 0x0a, 0x00, 0x00, 0x00
  370. };
  371. static const u8 sn_mi0360[0x1c] = {
  372. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  373. 0x00, 0x63, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  374. /* reg8 reg9 rega regb regc regd rege regf */
  375. 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  376. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  377. 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x61,
  378. /* reg18 reg19 reg1a reg1b */
  379. 0x06, 0x00, 0x00, 0x00
  380. };
  381. static const u8 sn_mi0360b[0x1c] = {
  382. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  383. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  384. /* reg8 reg9 rega regb regc regd rege regf */
  385. 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  386. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  387. 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x40,
  388. /* reg18 reg19 reg1a reg1b */
  389. 0x06, 0x00, 0x00, 0x00
  390. };
  391. static const u8 sn_mo4000[0x1c] = {
  392. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  393. 0x00, 0x23, 0x60, 0x00, 0x1a, 0x00, 0x20, 0x18,
  394. /* reg8 reg9 rega regb regc regd rege regf */
  395. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  396. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  397. 0x03, 0x00, 0x0b, 0x0f, 0x14, 0x28, 0x1e, 0x40,
  398. /* reg18 reg19 reg1a reg1b */
  399. 0x08, 0x00, 0x00, 0x00
  400. };
  401. static const u8 sn_mt9v111[0x1c] = {
  402. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  403. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  404. /* reg8 reg9 rega regb regc regd rege regf */
  405. 0x81, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  406. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  407. 0x03, 0x00, 0x00, 0x02, 0x1c, 0x28, 0x1e, 0x40,
  408. /* reg18 reg19 reg1a reg1b */
  409. 0x06, 0x00, 0x00, 0x00
  410. };
  411. static const u8 sn_om6802[0x1c] = {
  412. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  413. 0x00, 0x23, 0x72, 0x00, 0x1a, 0x20, 0x20, 0x19,
  414. /* reg8 reg9 rega regb regc regd rege regf */
  415. 0x80, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  416. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  417. 0x03, 0x00, 0x51, 0x01, 0x00, 0x28, 0x1e, 0x40,
  418. /* reg18 reg19 reg1a reg1b */
  419. 0x05, 0x00, 0x00, 0x00
  420. };
  421. static const u8 sn_ov7630[0x1c] = {
  422. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  423. 0x00, 0x21, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  424. /* reg8 reg9 rega regb regc regd rege regf */
  425. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  426. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  427. 0x03, 0x00, 0x04, 0x01, 0x0a, 0x28, 0x1e, 0xc2,
  428. /* reg18 reg19 reg1a reg1b */
  429. 0x0b, 0x00, 0x00, 0x00
  430. };
  431. static const u8 sn_ov7648[0x1c] = {
  432. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  433. 0x00, 0x63, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
  434. /* reg8 reg9 rega regb regc regd rege regf */
  435. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  436. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  437. 0x03, 0x00, 0x00, 0x01, 0x00, 0x28, 0x1e, 0x00,
  438. /* reg18 reg19 reg1a reg1b */
  439. 0x0b, 0x00, 0x00, 0x00
  440. };
  441. static const u8 sn_ov7660[0x1c] = {
  442. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  443. 0x00, 0x61, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  444. /* reg8 reg9 rega regb regc regd rege regf */
  445. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  446. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  447. 0x03, 0x00, 0x01, 0x01, 0x08, 0x28, 0x1e, 0x20,
  448. /* reg18 reg19 reg1a reg1b */
  449. 0x07, 0x00, 0x00, 0x00
  450. };
  451. static const u8 sn_po1030[0x1c] = {
  452. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  453. 0x00, 0x21, 0x62, 0x00, 0x1a, 0x20, 0x20, 0x20,
  454. /* reg8 reg9 rega regb regc regd rege regf */
  455. 0x81, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  456. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  457. 0x03, 0x00, 0x00, 0x06, 0x06, 0x28, 0x1e, 0x00,
  458. /* reg18 reg19 reg1a reg1b */
  459. 0x07, 0x00, 0x00, 0x00
  460. };
  461. static const u8 sn_po2030n[0x1c] = {
  462. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  463. 0x00, 0x63, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  464. /* reg8 reg9 rega regb regc regd rege regf */
  465. 0x81, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  466. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  467. 0x03, 0x00, 0x00, 0x01, 0x14, 0x28, 0x1e, 0x00,
  468. /* reg18 reg19 reg1a reg1b */
  469. 0x07, 0x00, 0x00, 0x00
  470. };
  471. static const u8 sn_soi768[0x1c] = {
  472. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  473. 0x00, 0x21, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
  474. /* reg8 reg9 rega regb regc regd rege regf */
  475. 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  476. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  477. 0x03, 0x00, 0x00, 0x01, 0x08, 0x28, 0x1e, 0x00,
  478. /* reg18 reg19 reg1a reg1b */
  479. 0x07, 0x00, 0x00, 0x00
  480. };
  481. static const u8 sn_sp80708[0x1c] = {
  482. /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
  483. 0x00, 0x63, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
  484. /* reg8 reg9 rega regb regc regd rege regf */
  485. 0x81, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  486. /* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
  487. 0x03, 0x00, 0x00, 0x03, 0x04, 0x28, 0x1e, 0x00,
  488. /* reg18 reg19 reg1a reg1b */
  489. 0x07, 0x00, 0x00, 0x00
  490. };
  491. /* sequence specific to the sensors - !! index = SENSOR_xxx */
  492. static const u8 *sn_tb[] = {
  493. [SENSOR_ADCM1700] = sn_adcm1700,
  494. [SENSOR_GC0307] = sn_gc0307,
  495. [SENSOR_HV7131R] = sn_hv7131,
  496. [SENSOR_MI0360] = sn_mi0360,
  497. [SENSOR_MI0360B] = sn_mi0360b,
  498. [SENSOR_MO4000] = sn_mo4000,
  499. [SENSOR_MT9V111] = sn_mt9v111,
  500. [SENSOR_OM6802] = sn_om6802,
  501. [SENSOR_OV7630] = sn_ov7630,
  502. [SENSOR_OV7648] = sn_ov7648,
  503. [SENSOR_OV7660] = sn_ov7660,
  504. [SENSOR_PO1030] = sn_po1030,
  505. [SENSOR_PO2030N] = sn_po2030n,
  506. [SENSOR_SOI768] = sn_soi768,
  507. [SENSOR_SP80708] = sn_sp80708,
  508. };
  509. /* default gamma table */
  510. static const u8 gamma_def[17] = {
  511. 0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99,
  512. 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
  513. };
  514. /* gamma for sensor ADCM1700 */
  515. static const u8 gamma_spec_0[17] = {
  516. 0x0f, 0x39, 0x5a, 0x74, 0x86, 0x95, 0xa6, 0xb4,
  517. 0xbd, 0xc4, 0xcc, 0xd4, 0xd5, 0xde, 0xe4, 0xed, 0xf5
  518. };
  519. /* gamma for sensors HV7131R and MT9V111 */
  520. static const u8 gamma_spec_1[17] = {
  521. 0x08, 0x3a, 0x52, 0x65, 0x75, 0x83, 0x91, 0x9d,
  522. 0xa9, 0xb4, 0xbe, 0xc8, 0xd2, 0xdb, 0xe4, 0xed, 0xf5
  523. };
  524. /* gamma for sensor GC0307 */
  525. static const u8 gamma_spec_2[17] = {
  526. 0x14, 0x37, 0x50, 0x6a, 0x7c, 0x8d, 0x9d, 0xab,
  527. 0xb5, 0xbf, 0xc2, 0xcb, 0xd1, 0xd6, 0xdb, 0xe1, 0xeb
  528. };
  529. /* gamma for sensor SP80708 */
  530. static const u8 gamma_spec_3[17] = {
  531. 0x0a, 0x2d, 0x4e, 0x68, 0x7d, 0x8f, 0x9f, 0xab,
  532. 0xb7, 0xc2, 0xcc, 0xd3, 0xd8, 0xde, 0xe2, 0xe5, 0xe6
  533. };
  534. /* color matrix and offsets */
  535. static const u8 reg84[] = {
  536. 0x14, 0x00, 0x27, 0x00, 0x07, 0x00, /* YR YG YB gains */
  537. 0xe8, 0x0f, 0xda, 0x0f, 0x40, 0x00, /* UR UG UB */
  538. 0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f, /* VR VG VB */
  539. 0x00, 0x00, 0x00 /* YUV offsets */
  540. };
  541. #define DELAY 0xdd
  542. static const u8 adcm1700_sensor_init[][8] = {
  543. {0xa0, 0x51, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x10},
  544. {0xb0, 0x51, 0x04, 0x08, 0x00, 0x00, 0x00, 0x10}, /* reset */
  545. {DELAY, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  546. {0xb0, 0x51, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
  547. {DELAY, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  548. {0xb0, 0x51, 0x0c, 0xe0, 0x2e, 0x00, 0x00, 0x10},
  549. {0xb0, 0x51, 0x10, 0x02, 0x02, 0x00, 0x00, 0x10},
  550. {0xb0, 0x51, 0x14, 0x0e, 0x0e, 0x00, 0x00, 0x10},
  551. {0xb0, 0x51, 0x1c, 0x00, 0x80, 0x00, 0x00, 0x10},
  552. {0xb0, 0x51, 0x20, 0x01, 0x00, 0x00, 0x00, 0x10},
  553. {DELAY, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  554. {0xb0, 0x51, 0x04, 0x04, 0x00, 0x00, 0x00, 0x10},
  555. {DELAY, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  556. {0xb0, 0x51, 0x04, 0x01, 0x00, 0x00, 0x00, 0x10},
  557. {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
  558. {0xb0, 0x51, 0x14, 0x01, 0x00, 0x00, 0x00, 0x10},
  559. {0xb0, 0x51, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
  560. {}
  561. };
  562. static const u8 adcm1700_sensor_param1[][8] = {
  563. {0xb0, 0x51, 0x26, 0xf9, 0x01, 0x00, 0x00, 0x10}, /* exposure? */
  564. {0xd0, 0x51, 0x1e, 0x8e, 0x8e, 0x8e, 0x8e, 0x10},
  565. {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10},
  566. {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10},
  567. {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
  568. {0xb0, 0x51, 0x32, 0x00, 0x72, 0x00, 0x00, 0x10},
  569. {0xd0, 0x51, 0x1e, 0xbe, 0xd7, 0xe8, 0xbe, 0x10}, /* exposure? */
  570. {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10},
  571. {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10},
  572. {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
  573. {0xb0, 0x51, 0x32, 0x00, 0xa2, 0x00, 0x00, 0x10},
  574. {}
  575. };
  576. static const u8 gc0307_sensor_init[][8] = {
  577. {0xa0, 0x21, 0x43, 0x00, 0x00, 0x00, 0x00, 0x10},
  578. {0xa0, 0x21, 0x44, 0xa2, 0x00, 0x00, 0x00, 0x10},
  579. {0xa0, 0x21, 0x01, 0x6a, 0x00, 0x00, 0x00, 0x10},
  580. {0xa0, 0x21, 0x02, 0x70, 0x00, 0x00, 0x00, 0x10},
  581. {0xa0, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  582. {0xa0, 0x21, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
  583. {0xa0, 0x21, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x10},
  584. {0xa0, 0x21, 0x11, 0x05, 0x00, 0x00, 0x00, 0x10},
  585. {0xa0, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
  586. {0xa0, 0x21, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10},
  587. {0xa0, 0x21, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10},
  588. {0xa0, 0x21, 0x08, 0x02, 0x00, 0x00, 0x00, 0x10},
  589. {0xa0, 0x21, 0x09, 0x01, 0x00, 0x00, 0x00, 0x10},
  590. {0xa0, 0x21, 0x0a, 0xe8, 0x00, 0x00, 0x00, 0x10},
  591. {0xa0, 0x21, 0x0b, 0x02, 0x00, 0x00, 0x00, 0x10},
  592. {0xa0, 0x21, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x10},
  593. {0xa0, 0x21, 0x0d, 0x22, 0x00, 0x00, 0x00, 0x10},
  594. {0xa0, 0x21, 0x0e, 0x02, 0x00, 0x00, 0x00, 0x10},
  595. {0xa0, 0x21, 0x0f, 0xb2, 0x00, 0x00, 0x00, 0x10},
  596. {0xa0, 0x21, 0x12, 0x70, 0x00, 0x00, 0x00, 0x10},
  597. {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 10ms*/
  598. {0xa0, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10},
  599. {0xa0, 0x21, 0x15, 0xb8, 0x00, 0x00, 0x00, 0x10},
  600. {0xa0, 0x21, 0x16, 0x13, 0x00, 0x00, 0x00, 0x10},
  601. {0xa0, 0x21, 0x17, 0x52, 0x00, 0x00, 0x00, 0x10},
  602. {0xa0, 0x21, 0x18, 0x50, 0x00, 0x00, 0x00, 0x10},
  603. {0xa0, 0x21, 0x1e, 0x0d, 0x00, 0x00, 0x00, 0x10},
  604. {0xa0, 0x21, 0x1f, 0x32, 0x00, 0x00, 0x00, 0x10},
  605. {0xa0, 0x21, 0x61, 0x90, 0x00, 0x00, 0x00, 0x10},
  606. {0xa0, 0x21, 0x63, 0x70, 0x00, 0x00, 0x00, 0x10},
  607. {0xa0, 0x21, 0x65, 0x98, 0x00, 0x00, 0x00, 0x10},
  608. {0xa0, 0x21, 0x67, 0x90, 0x00, 0x00, 0x00, 0x10},
  609. {0xa0, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  610. {0xa0, 0x21, 0x04, 0x96, 0x00, 0x00, 0x00, 0x10},
  611. {0xa0, 0x21, 0x45, 0x27, 0x00, 0x00, 0x00, 0x10},
  612. {0xa0, 0x21, 0x47, 0x2c, 0x00, 0x00, 0x00, 0x10},
  613. {0xa0, 0x21, 0x43, 0x47, 0x00, 0x00, 0x00, 0x10},
  614. {0xa0, 0x21, 0x44, 0xd8, 0x00, 0x00, 0x00, 0x10},
  615. {}
  616. };
  617. static const u8 gc0307_sensor_param1[][8] = {
  618. {0xa0, 0x21, 0x68, 0x13, 0x00, 0x00, 0x00, 0x10},
  619. {0xd0, 0x21, 0x61, 0x80, 0x00, 0x80, 0x00, 0x10},
  620. {0xc0, 0x21, 0x65, 0x80, 0x00, 0x80, 0x00, 0x10},
  621. {0xc0, 0x21, 0x63, 0xa0, 0x00, 0xa6, 0x00, 0x10},
  622. /*param3*/
  623. {0xa0, 0x21, 0x01, 0x6e, 0x00, 0x00, 0x00, 0x10},
  624. {0xa0, 0x21, 0x02, 0x88, 0x00, 0x00, 0x00, 0x10},
  625. {}
  626. };
  627. static const u8 hv7131r_sensor_init[][8] = {
  628. {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
  629. {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10},
  630. {0xd1, 0x11, 0x40, 0xff, 0x7f, 0x7f, 0x7f, 0x10},
  631. /* {0x91, 0x11, 0x44, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  632. {0xd1, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  633. {0xd1, 0x11, 0x14, 0x01, 0xe2, 0x02, 0x82, 0x10},
  634. /* {0x91, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  635. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  636. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  637. {0xc1, 0x11, 0x25, 0x00, 0x61, 0xa8, 0x00, 0x10},
  638. {0xa1, 0x11, 0x30, 0x22, 0x00, 0x00, 0x00, 0x10},
  639. {0xc1, 0x11, 0x31, 0x20, 0x2e, 0x20, 0x00, 0x10},
  640. {0xc1, 0x11, 0x25, 0x00, 0xc3, 0x50, 0x00, 0x10},
  641. {0xa1, 0x11, 0x30, 0x07, 0x00, 0x00, 0x00, 0x10}, /* gain14 */
  642. {0xc1, 0x11, 0x31, 0x10, 0x10, 0x10, 0x00, 0x10}, /* r g b 101a10 */
  643. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  644. {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  645. {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
  646. {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  647. {0xa1, 0x11, 0x23, 0x09, 0x00, 0x00, 0x00, 0x10},
  648. {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
  649. {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  650. {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
  651. {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  652. {0xa1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10},
  653. {0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10},
  654. /* set sensor clock */
  655. {}
  656. };
  657. static const u8 mi0360_sensor_init[][8] = {
  658. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  659. {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
  660. {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
  661. {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
  662. {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
  663. {0xd1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x53, 0x10},
  664. {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
  665. {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  666. {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
  667. {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  668. {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  669. {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  670. {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
  671. {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
  672. {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
  673. {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
  674. {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
  675. {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
  676. {0xd1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
  677. {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  678. {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
  679. {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
  680. {0xd1, 0x5d, 0x2f, 0xf7, 0xB0, 0x00, 0x04, 0x10},
  681. {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
  682. {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
  683. {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
  684. {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
  685. {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
  686. {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
  687. {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
  688. {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
  689. {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
  690. {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
  691. {0xb1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
  692. {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  693. {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
  694. {0xd1, 0x5d, 0x2b, 0x00, 0xa0, 0x00, 0xb0, 0x10},
  695. {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0xa0, 0x10},
  696. {0xb1, 0x5d, 0x0a, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor clck ?2 */
  697. {0xb1, 0x5d, 0x06, 0x00, 0x30, 0x00, 0x00, 0x10},
  698. {0xb1, 0x5d, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10},
  699. {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
  700. {0xd1, 0x5d, 0x2b, 0x00, 0xb9, 0x00, 0xe3, 0x10},
  701. {0xd1, 0x5d, 0x2d, 0x00, 0x5f, 0x00, 0xb9, 0x10}, /* 42 */
  702. /* {0xb1, 0x5d, 0x35, 0x00, 0x67, 0x00, 0x00, 0x10}, * gain orig */
  703. /* {0xb1, 0x5d, 0x35, 0x00, 0x20, 0x00, 0x00, 0x10}, * gain */
  704. {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
  705. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
  706. {}
  707. };
  708. static const u8 mi0360b_sensor_init[][8] = {
  709. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  710. {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
  711. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 20ms*/
  712. {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
  713. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 20ms*/
  714. {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
  715. {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
  716. {0xd1, 0x5d, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
  717. {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
  718. {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  719. {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
  720. {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  721. {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  722. {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  723. {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
  724. {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
  725. {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
  726. {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
  727. {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
  728. {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
  729. {0xd1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  730. {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  731. {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
  732. {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
  733. {0xd1, 0x5d, 0x2f, 0xf7, 0xb0, 0x00, 0x04, 0x10},
  734. {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
  735. {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
  736. {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
  737. {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
  738. {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
  739. {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
  740. {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
  741. {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
  742. {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
  743. {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
  744. {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  745. {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
  746. {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
  747. {0xd1, 0x5d, 0x2b, 0x00, 0x33, 0x00, 0xa0, 0x10},
  748. {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0x33, 0x10},
  749. {}
  750. };
  751. static const u8 mi0360b_sensor_param1[][8] = {
  752. {0xb1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  753. {0xb1, 0x5d, 0x06, 0x00, 0x53, 0x00, 0x00, 0x10},
  754. {0xb1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x00, 0x10},
  755. {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
  756. {0xd1, 0x5d, 0x2b, 0x00, 0xd1, 0x01, 0xc9, 0x10},
  757. {0xd1, 0x5d, 0x2d, 0x00, 0xed, 0x00, 0xd1, 0x10},
  758. {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
  759. {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
  760. {}
  761. };
  762. static const u8 mo4000_sensor_init[][8] = {
  763. {0xa1, 0x21, 0x01, 0x02, 0x00, 0x00, 0x00, 0x10},
  764. {0xa1, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10},
  765. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  766. {0xa1, 0x21, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
  767. {0xa1, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
  768. {0xa1, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x10},
  769. {0xa1, 0x21, 0x06, 0x80, 0x00, 0x00, 0x00, 0x10},
  770. {0xa1, 0x21, 0x06, 0x81, 0x00, 0x00, 0x00, 0x10},
  771. {0xa1, 0x21, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
  772. {0xa1, 0x21, 0x11, 0x00, 0x00, 0x00, 0x00, 0x10},
  773. {0xa1, 0x21, 0x11, 0x20, 0x00, 0x00, 0x00, 0x10},
  774. {0xa1, 0x21, 0x11, 0x30, 0x00, 0x00, 0x00, 0x10},
  775. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  776. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  777. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  778. {0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
  779. {0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10},
  780. {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10},
  781. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  782. {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
  783. {}
  784. };
  785. static const u8 mt9v111_sensor_init[][8] = {
  786. {0xb1, 0x5c, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10}, /* reset? */
  787. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  788. {0xb1, 0x5c, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
  789. {0xb1, 0x5c, 0x01, 0x00, 0x01, 0x00, 0x00, 0x10}, /* IFP select */
  790. {0xb1, 0x5c, 0x08, 0x04, 0x80, 0x00, 0x00, 0x10}, /* output fmt ctrl */
  791. {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10}, /* op mode ctrl */
  792. {0xb1, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10}, /* sensor select */
  793. {0xb1, 0x5c, 0x08, 0x00, 0x08, 0x00, 0x00, 0x10}, /* row start */
  794. {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10}, /* col start */
  795. {0xb1, 0x5c, 0x03, 0x01, 0xe7, 0x00, 0x00, 0x10}, /* window height */
  796. {0xb1, 0x5c, 0x04, 0x02, 0x87, 0x00, 0x00, 0x10}, /* window width */
  797. {0xb1, 0x5c, 0x07, 0x30, 0x02, 0x00, 0x00, 0x10}, /* output ctrl */
  798. {0xb1, 0x5c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10}, /* shutter delay */
  799. {0xb1, 0x5c, 0x12, 0x00, 0xb0, 0x00, 0x00, 0x10}, /* zoom col start */
  800. {0xb1, 0x5c, 0x13, 0x00, 0x7c, 0x00, 0x00, 0x10}, /* zoom row start */
  801. {0xb1, 0x5c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* digital zoom */
  802. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10}, /* read mode */
  803. {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
  804. {}
  805. };
  806. static const u8 mt9v111_sensor_param1[][8] = {
  807. {0xd1, 0x5c, 0x2b, 0x00, 0x33, 0x00, 0xad, 0x10}, /* G1 and B gains */
  808. {0xd1, 0x5c, 0x2d, 0x00, 0xad, 0x00, 0x33, 0x10}, /* R and G2 gains */
  809. {0xb1, 0x5c, 0x06, 0x00, 0x40, 0x00, 0x00, 0x10}, /* vert blanking */
  810. {0xb1, 0x5c, 0x05, 0x00, 0x09, 0x00, 0x00, 0x10}, /* horiz blanking */
  811. {0xb1, 0x5c, 0x35, 0x01, 0xc0, 0x00, 0x00, 0x10}, /* global gain */
  812. {}
  813. };
  814. static const u8 om6802_init0[2][8] = {
  815. /*fixme: variable*/
  816. {0xa0, 0x34, 0x29, 0x0e, 0x00, 0x00, 0x00, 0x10},
  817. {0xa0, 0x34, 0x23, 0xb0, 0x00, 0x00, 0x00, 0x10},
  818. };
  819. static const u8 om6802_sensor_init[][8] = {
  820. {0xa0, 0x34, 0xdf, 0x6d, 0x00, 0x00, 0x00, 0x10},
  821. /* factory mode */
  822. {0xa0, 0x34, 0xdd, 0x18, 0x00, 0x00, 0x00, 0x10},
  823. /* output raw RGB */
  824. {0xa0, 0x34, 0x5a, 0xc0, 0x00, 0x00, 0x00, 0x10},
  825. /* {0xa0, 0x34, 0xfb, 0x11, 0x00, 0x00, 0x00, 0x10}, */
  826. {0xa0, 0x34, 0xf0, 0x04, 0x00, 0x00, 0x00, 0x10},
  827. /* auto-exposure speed (0) / white balance mode (auto RGB) */
  828. /* {0xa0, 0x34, 0xf1, 0x02, 0x00, 0x00, 0x00, 0x10},
  829. * set color mode */
  830. /* {0xa0, 0x34, 0xfe, 0x5b, 0x00, 0x00, 0x00, 0x10},
  831. * max AGC value in AE */
  832. /* {0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10},
  833. * preset AGC */
  834. /* {0xa0, 0x34, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x10},
  835. * preset brightness */
  836. /* {0xa0, 0x34, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x10},
  837. * preset contrast */
  838. /* {0xa0, 0x34, 0xe8, 0x31, 0x00, 0x00, 0x00, 0x10},
  839. * preset gamma */
  840. {0xa0, 0x34, 0xe9, 0x0f, 0x00, 0x00, 0x00, 0x10},
  841. /* luminance mode (0x4f -> AutoExpo on) */
  842. {0xa0, 0x34, 0xe4, 0xff, 0x00, 0x00, 0x00, 0x10},
  843. /* preset shutter */
  844. /* {0xa0, 0x34, 0xef, 0x00, 0x00, 0x00, 0x00, 0x10},
  845. * auto frame rate */
  846. /* {0xa0, 0x34, 0xfb, 0xee, 0x00, 0x00, 0x00, 0x10}, */
  847. {0xa0, 0x34, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
  848. {}
  849. };
  850. static const u8 om6802_sensor_param1[][8] = {
  851. {0xa0, 0x34, 0x71, 0x84, 0x00, 0x00, 0x00, 0x10},
  852. {0xa0, 0x34, 0x72, 0x05, 0x00, 0x00, 0x00, 0x10},
  853. {0xa0, 0x34, 0x68, 0x80, 0x00, 0x00, 0x00, 0x10},
  854. {0xa0, 0x34, 0x69, 0x01, 0x00, 0x00, 0x00, 0x10},
  855. {}
  856. };
  857. static const u8 ov7630_sensor_init[][8] = {
  858. {0xa1, 0x21, 0x76, 0x01, 0x00, 0x00, 0x00, 0x10},
  859. {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
  860. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  861. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  862. {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
  863. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  864. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  865. /* win: i2c_r from 00 to 80 */
  866. {0xd1, 0x21, 0x03, 0x80, 0x10, 0x20, 0x80, 0x10},
  867. {0xb1, 0x21, 0x0c, 0x20, 0x20, 0x00, 0x00, 0x10},
  868. /* HDG: 0x11 was 0x00 change to 0x01 for better exposure (15 fps instead of 30)
  869. 0x13 was 0xc0 change to 0xc3 for auto gain and exposure */
  870. {0xd1, 0x21, 0x11, 0x01, 0x48, 0xc3, 0x00, 0x10},
  871. {0xb1, 0x21, 0x15, 0x80, 0x03, 0x00, 0x00, 0x10},
  872. {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
  873. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  874. {0xd1, 0x21, 0x1f, 0x00, 0x80, 0x80, 0x80, 0x10},
  875. {0xd1, 0x21, 0x23, 0xde, 0x10, 0x8a, 0xa0, 0x10},
  876. {0xc1, 0x21, 0x27, 0xca, 0xa2, 0x74, 0x00, 0x10},
  877. {0xd1, 0x21, 0x2a, 0x88, 0x00, 0x88, 0x01, 0x10},
  878. {0xc1, 0x21, 0x2e, 0x80, 0x00, 0x18, 0x00, 0x10},
  879. {0xa1, 0x21, 0x21, 0x08, 0x00, 0x00, 0x00, 0x10},
  880. {0xa1, 0x21, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
  881. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
  882. {0xb1, 0x21, 0x32, 0xc2, 0x08, 0x00, 0x00, 0x10},
  883. {0xb1, 0x21, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x10},
  884. {0xd1, 0x21, 0x60, 0x05, 0x40, 0x12, 0x57, 0x10},
  885. {0xa1, 0x21, 0x64, 0x73, 0x00, 0x00, 0x00, 0x10},
  886. {0xd1, 0x21, 0x65, 0x00, 0x55, 0x01, 0xac, 0x10},
  887. {0xa1, 0x21, 0x69, 0x38, 0x00, 0x00, 0x00, 0x10},
  888. {0xd1, 0x21, 0x6f, 0x1f, 0x01, 0x00, 0x10, 0x10},
  889. {0xd1, 0x21, 0x73, 0x50, 0x20, 0x02, 0x01, 0x10},
  890. {0xd1, 0x21, 0x77, 0xf3, 0x90, 0x98, 0x98, 0x10},
  891. {0xc1, 0x21, 0x7b, 0x00, 0x4c, 0xf7, 0x00, 0x10},
  892. {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
  893. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  894. {}
  895. };
  896. static const u8 ov7630_sensor_param1[][8] = {
  897. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  898. {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
  899. /*fixme: + 0x12, 0x04*/
  900. /* {0xa1, 0x21, 0x75, 0x82, 0x00, 0x00, 0x00, 0x10}, * COMN
  901. * set by setvflip */
  902. {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
  903. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  904. {0xb1, 0x21, 0x01, 0x80, 0x80, 0x00, 0x00, 0x10},
  905. /* */
  906. /* {0xa1, 0x21, 0x2a, 0x88, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
  907. /* {0xa1, 0x21, 0x2b, 0x34, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
  908. /* */
  909. {0xa1, 0x21, 0x10, 0x83, 0x00, 0x00, 0x00, 0x10},
  910. /* {0xb1, 0x21, 0x01, 0x88, 0x70, 0x00, 0x00, 0x10}, */
  911. {}
  912. };
  913. static const u8 ov7648_sensor_init[][8] = {
  914. {0xa1, 0x21, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10},
  915. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
  916. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  917. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  918. {0xd1, 0x21, 0x03, 0xa4, 0x30, 0x88, 0x00, 0x10},
  919. {0xb1, 0x21, 0x11, 0x80, 0x08, 0x00, 0x00, 0x10},
  920. {0xc1, 0x21, 0x13, 0xa0, 0x04, 0x84, 0x00, 0x10},
  921. {0xd1, 0x21, 0x17, 0x1a, 0x02, 0xba, 0xf4, 0x10},
  922. {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
  923. {0xd1, 0x21, 0x1f, 0x41, 0xc0, 0x80, 0x80, 0x10},
  924. {0xd1, 0x21, 0x23, 0xde, 0xa0, 0x80, 0x32, 0x10},
  925. {0xd1, 0x21, 0x27, 0xfe, 0xa0, 0x00, 0x91, 0x10},
  926. {0xd1, 0x21, 0x2b, 0x00, 0x88, 0x85, 0x80, 0x10},
  927. {0xc1, 0x21, 0x2f, 0x9c, 0x00, 0xc4, 0x00, 0x10},
  928. {0xd1, 0x21, 0x60, 0xa6, 0x60, 0x88, 0x12, 0x10},
  929. {0xd1, 0x21, 0x64, 0x88, 0x00, 0x00, 0x94, 0x10},
  930. {0xd1, 0x21, 0x68, 0x7a, 0x0c, 0x00, 0x00, 0x10},
  931. {0xd1, 0x21, 0x6c, 0x11, 0x33, 0x22, 0x00, 0x10},
  932. {0xd1, 0x21, 0x70, 0x11, 0x00, 0x10, 0x50, 0x10},
  933. {0xd1, 0x21, 0x74, 0x20, 0x06, 0x00, 0xb5, 0x10},
  934. {0xd1, 0x21, 0x78, 0x8a, 0x00, 0x00, 0x00, 0x10},
  935. {0xb1, 0x21, 0x7c, 0x00, 0x43, 0x00, 0x00, 0x10},
  936. {0xd1, 0x21, 0x21, 0x86, 0x00, 0xde, 0xa0, 0x10},
  937. /* {0xd1, 0x21, 0x25, 0x80, 0x32, 0xfe, 0xa0, 0x10}, jfm done */
  938. /* {0xd1, 0x21, 0x29, 0x00, 0x91, 0x00, 0x88, 0x10}, jfm done */
  939. /* {0xb1, 0x21, 0x2d, 0x85, 0x00, 0x00, 0x00, 0x10}, set by setfreq */
  940. {}
  941. };
  942. static const u8 ov7648_sensor_param1[][8] = {
  943. /* {0xa1, 0x21, 0x12, 0x08, 0x00, 0x00, 0x00, 0x10}, jfm done */
  944. /* {0xa1, 0x21, 0x75, 0x06, 0x00, 0x00, 0x00, 0x10}, * COMN
  945. * set by setvflip */
  946. {0xa1, 0x21, 0x19, 0x02, 0x00, 0x00, 0x00, 0x10},
  947. {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
  948. /* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  949. /* {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}, * GAIN - def */
  950. /* {0xb1, 0x21, 0x01, 0x6c, 0x6c, 0x00, 0x00, 0x10}, * B R - def: 80 */
  951. /*...*/
  952. {0xa1, 0x21, 0x11, 0x81, 0x00, 0x00, 0x00, 0x10}, /* CLKRC */
  953. /* {0xa1, 0x21, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  954. /* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  955. /* {0xa1, 0x21, 0x2a, 0x91, 0x00, 0x00, 0x00, 0x10}, jfm done */
  956. /* {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
  957. /* {0xb1, 0x21, 0x01, 0x64, 0x84, 0x00, 0x00, 0x10}, * B R - def: 80 */
  958. {}
  959. };
  960. static const u8 ov7660_sensor_init[][8] = {
  961. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */
  962. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  963. {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
  964. /* Outformat = rawRGB */
  965. {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */
  966. {0xd1, 0x21, 0x00, 0x01, 0x74, 0x92, 0x00, 0x10},
  967. /* GAIN BLUE RED VREF */
  968. {0xd1, 0x21, 0x04, 0x00, 0x7d, 0x62, 0x00, 0x10},
  969. /* COM 1 BAVE GEAVE AECHH */
  970. {0xb1, 0x21, 0x08, 0x83, 0x01, 0x00, 0x00, 0x10}, /* RAVE COM2 */
  971. {0xd1, 0x21, 0x0c, 0x00, 0x08, 0x04, 0x4f, 0x10}, /* COM 3 4 5 6 */
  972. {0xd1, 0x21, 0x10, 0x7f, 0x40, 0x05, 0xff, 0x10},
  973. /* AECH CLKRC COM7 COM8 */
  974. {0xc1, 0x21, 0x14, 0x2c, 0x00, 0x02, 0x00, 0x10}, /* COM9 COM10 */
  975. {0xd1, 0x21, 0x17, 0x10, 0x60, 0x02, 0x7b, 0x10},
  976. /* HSTART HSTOP VSTRT VSTOP */
  977. {0xa1, 0x21, 0x1b, 0x02, 0x00, 0x00, 0x00, 0x10}, /* PSHFT */
  978. {0xb1, 0x21, 0x1e, 0x01, 0x0e, 0x00, 0x00, 0x10}, /* MVFP LAEC */
  979. {0xd1, 0x21, 0x20, 0x07, 0x07, 0x07, 0x07, 0x10},
  980. /* BOS GBOS GROS ROS (BGGR offset) */
  981. /* {0xd1, 0x21, 0x24, 0x68, 0x58, 0xd4, 0x80, 0x10}, */
  982. {0xd1, 0x21, 0x24, 0x78, 0x68, 0xd4, 0x80, 0x10},
  983. /* AEW AEB VPT BBIAS */
  984. {0xd1, 0x21, 0x28, 0x80, 0x30, 0x00, 0x00, 0x10},
  985. /* GbBIAS RSVD EXHCH EXHCL */
  986. {0xd1, 0x21, 0x2c, 0x80, 0x00, 0x00, 0x62, 0x10},
  987. /* RBIAS ADVFL ASDVFH YAVE */
  988. {0xc1, 0x21, 0x30, 0x08, 0x30, 0xb4, 0x00, 0x10},
  989. /* HSYST HSYEN HREF */
  990. {0xd1, 0x21, 0x33, 0x00, 0x07, 0x84, 0x00, 0x10}, /* reserved */
  991. {0xd1, 0x21, 0x37, 0x0c, 0x02, 0x43, 0x00, 0x10},
  992. /* ADC ACOM OFON TSLB */
  993. {0xd1, 0x21, 0x3b, 0x02, 0x6c, 0x19, 0x0e, 0x10},
  994. /* COM11 COM12 COM13 COM14 */
  995. {0xd1, 0x21, 0x3f, 0x41, 0xc1, 0x22, 0x08, 0x10},
  996. /* EDGE COM15 COM16 COM17 */
  997. {0xd1, 0x21, 0x43, 0xf0, 0x10, 0x78, 0xa8, 0x10}, /* reserved */
  998. {0xd1, 0x21, 0x47, 0x60, 0x80, 0x00, 0x00, 0x10}, /* reserved */
  999. {0xd1, 0x21, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* reserved */
  1000. {0xd1, 0x21, 0x4f, 0x46, 0x36, 0x0f, 0x17, 0x10}, /* MTX 1 2 3 4 */
  1001. {0xd1, 0x21, 0x53, 0x7f, 0x96, 0x40, 0x40, 0x10}, /* MTX 5 6 7 8 */
  1002. {0xb1, 0x21, 0x57, 0x40, 0x0f, 0x00, 0x00, 0x10}, /* MTX9 MTXS */
  1003. {0xd1, 0x21, 0x59, 0xba, 0x9a, 0x22, 0xb9, 0x10}, /* reserved */
  1004. {0xd1, 0x21, 0x5d, 0x9b, 0x10, 0xf0, 0x05, 0x10}, /* reserved */
  1005. {0xa1, 0x21, 0x61, 0x60, 0x00, 0x00, 0x00, 0x10}, /* reserved */
  1006. {0xd1, 0x21, 0x62, 0x00, 0x00, 0x50, 0x30, 0x10},
  1007. /* LCC1 LCC2 LCC3 LCC4 */
  1008. {0xa1, 0x21, 0x66, 0x00, 0x00, 0x00, 0x00, 0x10}, /* LCC5 */
  1009. {0xd1, 0x21, 0x67, 0x80, 0x7a, 0x90, 0x80, 0x10}, /* MANU */
  1010. {0xa1, 0x21, 0x6b, 0x0a, 0x00, 0x00, 0x00, 0x10},
  1011. /* band gap reference [0:3] DBLV */
  1012. {0xd1, 0x21, 0x6c, 0x30, 0x48, 0x80, 0x74, 0x10}, /* gamma curve */
  1013. {0xd1, 0x21, 0x70, 0x64, 0x60, 0x5c, 0x58, 0x10}, /* gamma curve */
  1014. {0xd1, 0x21, 0x74, 0x54, 0x4c, 0x40, 0x38, 0x10}, /* gamma curve */
  1015. {0xd1, 0x21, 0x78, 0x34, 0x30, 0x2f, 0x2b, 0x10}, /* gamma curve */
  1016. {0xd1, 0x21, 0x7c, 0x03, 0x07, 0x17, 0x34, 0x10}, /* gamma curve */
  1017. {0xd1, 0x21, 0x80, 0x41, 0x4d, 0x58, 0x63, 0x10}, /* gamma curve */
  1018. {0xd1, 0x21, 0x84, 0x6e, 0x77, 0x87, 0x95, 0x10}, /* gamma curve */
  1019. {0xc1, 0x21, 0x88, 0xaf, 0xc7, 0xdf, 0x00, 0x10}, /* gamma curve */
  1020. {0xc1, 0x21, 0x8b, 0x99, 0x99, 0xcf, 0x00, 0x10}, /* reserved */
  1021. {0xb1, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x10}, /* DM_LNL/H */
  1022. /* not in all ms-win traces*/
  1023. {0xa1, 0x21, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x10},
  1024. {}
  1025. };
  1026. static const u8 ov7660_sensor_param1[][8] = {
  1027. {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10}, /* MVFP */
  1028. /* bits[3..0]reserved */
  1029. {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10},
  1030. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  1031. /* VREF vertical frame ctrl */
  1032. {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
  1033. {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10}, /* AECH 0x20 */
  1034. {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFL */
  1035. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFH */
  1036. {0xa1, 0x21, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x10}, /* GAIN */
  1037. /* {0xb1, 0x21, 0x01, 0x78, 0x78, 0x00, 0x00, 0x10}, * BLUE */
  1038. /****** (some exchanges in the win trace) ******/
  1039. /*fixme:param2*/
  1040. {0xa1, 0x21, 0x93, 0x00, 0x00, 0x00, 0x00, 0x10},/* dummy line hight */
  1041. {0xa1, 0x21, 0x92, 0x25, 0x00, 0x00, 0x00, 0x10}, /* dummy line low */
  1042. {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCH */
  1043. {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCL */
  1044. /* {0xa1, 0x21, 0x02, 0x90, 0x00, 0x00, 0x00, 0x10}, * RED */
  1045. /****** (some exchanges in the win trace) ******/
  1046. /******!! startsensor KO if changed !!****/
  1047. /*fixme: param3*/
  1048. {0xa1, 0x21, 0x93, 0x01, 0x00, 0x00, 0x00, 0x10},
  1049. {0xa1, 0x21, 0x92, 0xff, 0x00, 0x00, 0x00, 0x10},
  1050. {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10},
  1051. {0xa1, 0x21, 0x2b, 0xc3, 0x00, 0x00, 0x00, 0x10},
  1052. {}
  1053. };
  1054. static const u8 po1030_sensor_init[][8] = {
  1055. /* the sensor registers are described in m5602/m5602_po1030.h */
  1056. {0xa1, 0x6e, 0x3f, 0x20, 0x00, 0x00, 0x00, 0x10}, /* sensor reset */
  1057. {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
  1058. {0xa1, 0x6e, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x10},
  1059. {0xa1, 0x6e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x10},
  1060. {0xd1, 0x6e, 0x04, 0x02, 0xb1, 0x02, 0x39, 0x10},
  1061. {0xd1, 0x6e, 0x08, 0x00, 0x01, 0x00, 0x00, 0x10},
  1062. {0xd1, 0x6e, 0x0c, 0x02, 0x7f, 0x01, 0xe0, 0x10},
  1063. {0xd1, 0x6e, 0x12, 0x03, 0x02, 0x00, 0x03, 0x10},
  1064. {0xd1, 0x6e, 0x16, 0x85, 0x40, 0x4a, 0x40, 0x10}, /* r/g1/b/g2 gains */
  1065. {0xc1, 0x6e, 0x1a, 0x00, 0x80, 0x00, 0x00, 0x10},
  1066. {0xd1, 0x6e, 0x1d, 0x08, 0x03, 0x00, 0x00, 0x10},
  1067. {0xd1, 0x6e, 0x23, 0x00, 0xb0, 0x00, 0x94, 0x10},
  1068. {0xd1, 0x6e, 0x27, 0x58, 0x00, 0x00, 0x00, 0x10},
  1069. {0xb1, 0x6e, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10},
  1070. {0xd1, 0x6e, 0x2d, 0x14, 0x35, 0x61, 0x84, 0x10}, /* gamma corr */
  1071. {0xd1, 0x6e, 0x31, 0xa2, 0xbd, 0xd8, 0xff, 0x10},
  1072. {0xd1, 0x6e, 0x35, 0x06, 0x1e, 0x12, 0x02, 0x10}, /* color matrix */
  1073. {0xd1, 0x6e, 0x39, 0xaa, 0x53, 0x37, 0xd5, 0x10},
  1074. {0xa1, 0x6e, 0x3d, 0xf2, 0x00, 0x00, 0x00, 0x10},
  1075. {0xd1, 0x6e, 0x3e, 0x00, 0x00, 0x80, 0x03, 0x10},
  1076. {0xd1, 0x6e, 0x42, 0x03, 0x00, 0x00, 0x00, 0x10},
  1077. {0xc1, 0x6e, 0x46, 0x00, 0x80, 0x80, 0x00, 0x10},
  1078. {0xd1, 0x6e, 0x4b, 0x02, 0xef, 0x08, 0xcd, 0x10},
  1079. {0xd1, 0x6e, 0x4f, 0x00, 0xd0, 0x00, 0xa0, 0x10},
  1080. {0xd1, 0x6e, 0x53, 0x01, 0xaa, 0x01, 0x40, 0x10},
  1081. {0xd1, 0x6e, 0x5a, 0x50, 0x04, 0x30, 0x03, 0x10}, /* raw rgb bayer */
  1082. {0xa1, 0x6e, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x10},
  1083. {0xd1, 0x6e, 0x5f, 0x10, 0x40, 0xff, 0x00, 0x10},
  1084. {0xd1, 0x6e, 0x63, 0x40, 0x40, 0x00, 0x00, 0x10},
  1085. {0xd1, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x00, 0x10},
  1086. {0xd1, 0x6e, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x10},
  1087. {0xd1, 0x6e, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x10},
  1088. {0xc1, 0x6e, 0x73, 0x10, 0x80, 0xeb, 0x00, 0x10},
  1089. {}
  1090. };
  1091. static const u8 po1030_sensor_param1[][8] = {
  1092. /* from ms-win traces - these values change with auto gain/expo/wb.. */
  1093. {0xa1, 0x6e, 0x1e, 0x03, 0x00, 0x00, 0x00, 0x10},
  1094. {0xa1, 0x6e, 0x1e, 0x03, 0x00, 0x00, 0x00, 0x10},
  1095. /* mean values */
  1096. {0xc1, 0x6e, 0x1a, 0x02, 0xd4, 0xa4, 0x00, 0x10}, /* integlines */
  1097. {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10}, /* global gain */
  1098. {0xc1, 0x6e, 0x16, 0x40, 0x40, 0x40, 0x00, 0x10}, /* r/g1/b gains */
  1099. {0xa1, 0x6e, 0x1d, 0x08, 0x00, 0x00, 0x00, 0x10}, /* control1 */
  1100. {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10}, /* frameheight */
  1101. {0xa1, 0x6e, 0x07, 0xd5, 0x00, 0x00, 0x00, 0x10},
  1102. /* {0xc1, 0x6e, 0x16, 0x49, 0x40, 0x45, 0x00, 0x10}, */
  1103. {}
  1104. };
  1105. static const u8 po2030n_sensor_init[][8] = {
  1106. {0xa1, 0x6e, 0x1e, 0x1a, 0x00, 0x00, 0x00, 0x10},
  1107. {0xa1, 0x6e, 0x1f, 0x99, 0x00, 0x00, 0x00, 0x10},
  1108. {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 10ms */
  1109. {0xa1, 0x6e, 0x1e, 0x0a, 0x00, 0x00, 0x00, 0x10},
  1110. {0xa1, 0x6e, 0x1f, 0x19, 0x00, 0x00, 0x00, 0x10},
  1111. {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 10ms */
  1112. {0xa1, 0x6e, 0x20, 0x44, 0x00, 0x00, 0x00, 0x10},
  1113. {0xa1, 0x6e, 0x04, 0x03, 0x00, 0x00, 0x00, 0x10},
  1114. {0xa1, 0x6e, 0x05, 0x70, 0x00, 0x00, 0x00, 0x10},
  1115. {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10},
  1116. {0xa1, 0x6e, 0x07, 0x25, 0x00, 0x00, 0x00, 0x10},
  1117. {0xd1, 0x6e, 0x08, 0x00, 0xd0, 0x00, 0x08, 0x10},
  1118. {0xd1, 0x6e, 0x0c, 0x03, 0x50, 0x01, 0xe8, 0x10},
  1119. {0xd1, 0x6e, 0x1d, 0x20, 0x0a, 0x19, 0x44, 0x10},
  1120. {0xd1, 0x6e, 0x21, 0x00, 0x00, 0x00, 0x00, 0x10},
  1121. {0xd1, 0x6e, 0x25, 0x00, 0x00, 0x00, 0x00, 0x10},
  1122. {0xd1, 0x6e, 0x29, 0x00, 0x00, 0x00, 0x00, 0x10},
  1123. {0xd1, 0x6e, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1124. {0xd1, 0x6e, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
  1125. {0xd1, 0x6e, 0x35, 0x00, 0x00, 0x00, 0x00, 0x10},
  1126. {0xd1, 0x6e, 0x39, 0x00, 0x00, 0x00, 0x00, 0x10},
  1127. {0xd1, 0x6e, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1128. {0xd1, 0x6e, 0x41, 0x00, 0x00, 0x00, 0x00, 0x10},
  1129. {0xd1, 0x6e, 0x45, 0x00, 0x00, 0x00, 0x00, 0x10},
  1130. {0xd1, 0x6e, 0x49, 0x00, 0x00, 0x00, 0x00, 0x10},
  1131. {0xd1, 0x6e, 0x4d, 0x00, 0x00, 0x00, 0xed, 0x10},
  1132. {0xd1, 0x6e, 0x51, 0x17, 0x4a, 0x2f, 0xc0, 0x10},
  1133. {0xd1, 0x6e, 0x55, 0x00, 0x00, 0x00, 0x00, 0x10},
  1134. {0xd1, 0x6e, 0x59, 0x00, 0x00, 0x00, 0x00, 0x10},
  1135. {0xd1, 0x6e, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1136. {0xd1, 0x6e, 0x61, 0x00, 0x00, 0x00, 0x00, 0x10},
  1137. {0xd1, 0x6e, 0x65, 0x00, 0x00, 0x00, 0x00, 0x10},
  1138. {0xd1, 0x6e, 0x69, 0x00, 0x00, 0x00, 0x00, 0x10},
  1139. {0xd1, 0x6e, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1140. {0xd1, 0x6e, 0x71, 0x00, 0x00, 0x00, 0x00, 0x10},
  1141. {0xd1, 0x6e, 0x75, 0x00, 0x00, 0x00, 0x00, 0x10},
  1142. {0xd1, 0x6e, 0x79, 0x00, 0x00, 0x00, 0x00, 0x10},
  1143. {0xd1, 0x6e, 0x7d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1144. {0xd1, 0x6e, 0x81, 0x00, 0x00, 0x00, 0x00, 0x10},
  1145. {0xd1, 0x6e, 0x85, 0x00, 0x00, 0x00, 0x08, 0x10},
  1146. {0xd1, 0x6e, 0x89, 0x01, 0xe8, 0x00, 0x01, 0x10},
  1147. {0xa1, 0x6e, 0x8d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1148. {0xd1, 0x6e, 0x21, 0x00, 0x00, 0x00, 0x00, 0x10},
  1149. {0xd1, 0x6e, 0x25, 0x00, 0x00, 0x00, 0x01, 0x10},
  1150. {0xd1, 0x6e, 0x29, 0xe6, 0x00, 0xbd, 0x03, 0x10},
  1151. {0xd1, 0x6e, 0x2d, 0x41, 0x38, 0x68, 0x40, 0x10},
  1152. {0xd1, 0x6e, 0x31, 0x2b, 0x00, 0x36, 0x00, 0x10},
  1153. {0xd1, 0x6e, 0x35, 0x30, 0x30, 0x08, 0x00, 0x10},
  1154. {0xd1, 0x6e, 0x39, 0x00, 0x00, 0x33, 0x06, 0x10},
  1155. {0xb1, 0x6e, 0x3d, 0x06, 0x02, 0x00, 0x00, 0x10},
  1156. {}
  1157. };
  1158. static const u8 po2030n_sensor_param1[][8] = {
  1159. {0xa1, 0x6e, 0x1a, 0x01, 0x00, 0x00, 0x00, 0x10},
  1160. {DELAY, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 8ms */
  1161. {0xa1, 0x6e, 0x1b, 0xf4, 0x00, 0x00, 0x00, 0x10},
  1162. {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10},
  1163. {0xd1, 0x6e, 0x16, 0x50, 0x40, 0x49, 0x40, 0x10},
  1164. /*param2*/
  1165. {0xa1, 0x6e, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1166. {0xa1, 0x6e, 0x04, 0x03, 0x00, 0x00, 0x00, 0x10},
  1167. {0xa1, 0x6e, 0x05, 0x6f, 0x00, 0x00, 0x00, 0x10},
  1168. {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10},
  1169. {0xa1, 0x6e, 0x07, 0x25, 0x00, 0x00, 0x00, 0x10},
  1170. {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10},
  1171. {0xc1, 0x6e, 0x16, 0x52, 0x40, 0x48, 0x00, 0x10},
  1172. /*after start*/
  1173. {0xa1, 0x6e, 0x15, 0x0f, 0x00, 0x00, 0x00, 0x10},
  1174. {DELAY, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 5ms */
  1175. {0xa1, 0x6e, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x10},
  1176. {DELAY, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 5ms */
  1177. {0xa1, 0x6e, 0x1b, 0x53, 0x00, 0x00, 0x00, 0x10},
  1178. {}
  1179. };
  1180. static const u8 soi768_sensor_init[][8] = {
  1181. {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
  1182. {DELAY, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 96ms */
  1183. {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
  1184. {0xa1, 0x21, 0x13, 0x80, 0x00, 0x00, 0x00, 0x10},
  1185. {0xa1, 0x21, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x10},
  1186. {0xa1, 0x21, 0x19, 0x00, 0x00, 0x00, 0x00, 0x10},
  1187. {}
  1188. };
  1189. static const u8 soi768_sensor_param1[][8] = {
  1190. {0xa1, 0x21, 0x10, 0x10, 0x00, 0x00, 0x00, 0x10},
  1191. {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10},
  1192. {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
  1193. {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1194. {0xb1, 0x21, 0x01, 0x7f, 0x7f, 0x00, 0x00, 0x10},
  1195. /* */
  1196. /* {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  1197. /* {0xa1, 0x21, 0x2d, 0x25, 0x00, 0x00, 0x00, 0x10}, */
  1198. {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10},
  1199. /* {0xb1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, */
  1200. {0xa1, 0x21, 0x02, 0x8d, 0x00, 0x00, 0x00, 0x10},
  1201. /* the next sequence should be used for auto gain */
  1202. {0xa1, 0x21, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10},
  1203. /* global gain ? : 07 - change with 0x15 at the end */
  1204. {0xa1, 0x21, 0x10, 0x3f, 0x00, 0x00, 0x00, 0x10}, /* ???? : 063f */
  1205. {0xa1, 0x21, 0x04, 0x06, 0x00, 0x00, 0x00, 0x10},
  1206. {0xb1, 0x21, 0x2d, 0x00, 0x02, 0x00, 0x00, 0x10},
  1207. /* exposure ? : 0200 - change with 0x1e at the end */
  1208. {}
  1209. };
  1210. static const u8 sp80708_sensor_init[][8] = {
  1211. {0xa1, 0x18, 0x06, 0xf9, 0x00, 0x00, 0x00, 0x10},
  1212. {0xa1, 0x18, 0x09, 0x1f, 0x00, 0x00, 0x00, 0x10},
  1213. {0xa1, 0x18, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
  1214. {0xa1, 0x18, 0x0d, 0xc0, 0x00, 0x00, 0x00, 0x10},
  1215. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  1216. {0xa1, 0x18, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x10},
  1217. {0xa1, 0x18, 0x10, 0x40, 0x00, 0x00, 0x00, 0x10},
  1218. {0xa1, 0x18, 0x11, 0x4e, 0x00, 0x00, 0x00, 0x10},
  1219. {0xa1, 0x18, 0x12, 0x53, 0x00, 0x00, 0x00, 0x10},
  1220. {0xa1, 0x18, 0x15, 0x80, 0x00, 0x00, 0x00, 0x10},
  1221. {0xa1, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10},
  1222. {0xa1, 0x18, 0x19, 0x18, 0x00, 0x00, 0x00, 0x10},
  1223. {0xa1, 0x18, 0x1a, 0x10, 0x00, 0x00, 0x00, 0x10},
  1224. {0xa1, 0x18, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x10},
  1225. {0xa1, 0x18, 0x1c, 0x28, 0x00, 0x00, 0x00, 0x10},
  1226. {0xa1, 0x18, 0x1d, 0x02, 0x00, 0x00, 0x00, 0x10},
  1227. {0xa1, 0x18, 0x1e, 0x10, 0x00, 0x00, 0x00, 0x10},
  1228. {0xa1, 0x18, 0x26, 0x04, 0x00, 0x00, 0x00, 0x10},
  1229. {0xa1, 0x18, 0x27, 0x1e, 0x00, 0x00, 0x00, 0x10},
  1230. {0xa1, 0x18, 0x28, 0x5a, 0x00, 0x00, 0x00, 0x10},
  1231. {0xa1, 0x18, 0x29, 0x28, 0x00, 0x00, 0x00, 0x10},
  1232. {0xa1, 0x18, 0x2a, 0x78, 0x00, 0x00, 0x00, 0x10},
  1233. {0xa1, 0x18, 0x2b, 0x01, 0x00, 0x00, 0x00, 0x10},
  1234. {0xa1, 0x18, 0x2c, 0xf7, 0x00, 0x00, 0x00, 0x10},
  1235. {0xa1, 0x18, 0x2d, 0x2d, 0x00, 0x00, 0x00, 0x10},
  1236. {0xa1, 0x18, 0x2e, 0xd5, 0x00, 0x00, 0x00, 0x10},
  1237. {0xa1, 0x18, 0x39, 0x42, 0x00, 0x00, 0x00, 0x10},
  1238. {0xa1, 0x18, 0x3a, 0x67, 0x00, 0x00, 0x00, 0x10},
  1239. {0xa1, 0x18, 0x3b, 0x87, 0x00, 0x00, 0x00, 0x10},
  1240. {0xa1, 0x18, 0x3c, 0xa3, 0x00, 0x00, 0x00, 0x10},
  1241. {0xa1, 0x18, 0x3d, 0xb0, 0x00, 0x00, 0x00, 0x10},
  1242. {0xa1, 0x18, 0x3e, 0xbc, 0x00, 0x00, 0x00, 0x10},
  1243. {0xa1, 0x18, 0x3f, 0xc8, 0x00, 0x00, 0x00, 0x10},
  1244. {0xa1, 0x18, 0x40, 0xd4, 0x00, 0x00, 0x00, 0x10},
  1245. {0xa1, 0x18, 0x41, 0xdf, 0x00, 0x00, 0x00, 0x10},
  1246. {0xa1, 0x18, 0x42, 0xea, 0x00, 0x00, 0x00, 0x10},
  1247. {0xa1, 0x18, 0x43, 0xf5, 0x00, 0x00, 0x00, 0x10},
  1248. {0xa1, 0x18, 0x45, 0x80, 0x00, 0x00, 0x00, 0x10},
  1249. {0xa1, 0x18, 0x46, 0x60, 0x00, 0x00, 0x00, 0x10},
  1250. {0xa1, 0x18, 0x47, 0x50, 0x00, 0x00, 0x00, 0x10},
  1251. {0xa1, 0x18, 0x48, 0x30, 0x00, 0x00, 0x00, 0x10},
  1252. {0xa1, 0x18, 0x49, 0x01, 0x00, 0x00, 0x00, 0x10},
  1253. {0xa1, 0x18, 0x4d, 0xae, 0x00, 0x00, 0x00, 0x10},
  1254. {0xa1, 0x18, 0x4e, 0x03, 0x00, 0x00, 0x00, 0x10},
  1255. {0xa1, 0x18, 0x4f, 0x66, 0x00, 0x00, 0x00, 0x10},
  1256. {0xa1, 0x18, 0x50, 0x1c, 0x00, 0x00, 0x00, 0x10},
  1257. {0xa1, 0x18, 0x44, 0x10, 0x00, 0x00, 0x00, 0x10},
  1258. {0xa1, 0x18, 0x4a, 0x30, 0x00, 0x00, 0x00, 0x10},
  1259. {0xa1, 0x18, 0x51, 0x80, 0x00, 0x00, 0x00, 0x10},
  1260. {0xa1, 0x18, 0x52, 0x80, 0x00, 0x00, 0x00, 0x10},
  1261. {0xa1, 0x18, 0x53, 0x80, 0x00, 0x00, 0x00, 0x10},
  1262. {0xa1, 0x18, 0x54, 0x80, 0x00, 0x00, 0x00, 0x10},
  1263. {0xa1, 0x18, 0x55, 0x80, 0x00, 0x00, 0x00, 0x10},
  1264. {0xa1, 0x18, 0x56, 0x80, 0x00, 0x00, 0x00, 0x10},
  1265. {0xa1, 0x18, 0x57, 0xe0, 0x00, 0x00, 0x00, 0x10},
  1266. {0xa1, 0x18, 0x58, 0xc0, 0x00, 0x00, 0x00, 0x10},
  1267. {0xa1, 0x18, 0x59, 0xab, 0x00, 0x00, 0x00, 0x10},
  1268. {0xa1, 0x18, 0x5a, 0xa0, 0x00, 0x00, 0x00, 0x10},
  1269. {0xa1, 0x18, 0x5b, 0x99, 0x00, 0x00, 0x00, 0x10},
  1270. {0xa1, 0x18, 0x5c, 0x90, 0x00, 0x00, 0x00, 0x10},
  1271. {0xa1, 0x18, 0x5e, 0x24, 0x00, 0x00, 0x00, 0x10},
  1272. {0xa1, 0x18, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x10},
  1273. {0xa1, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00, 0x10},
  1274. {0xa1, 0x18, 0x61, 0x73, 0x00, 0x00, 0x00, 0x10},
  1275. {0xa1, 0x18, 0x63, 0x42, 0x00, 0x00, 0x00, 0x10},
  1276. {0xa1, 0x18, 0x64, 0x42, 0x00, 0x00, 0x00, 0x10},
  1277. {0xa1, 0x18, 0x65, 0x42, 0x00, 0x00, 0x00, 0x10},
  1278. {0xa1, 0x18, 0x66, 0x24, 0x00, 0x00, 0x00, 0x10},
  1279. {0xa1, 0x18, 0x67, 0x24, 0x00, 0x00, 0x00, 0x10},
  1280. {0xa1, 0x18, 0x68, 0x08, 0x00, 0x00, 0x00, 0x10},
  1281. {0xa1, 0x18, 0x2f, 0xc9, 0x00, 0x00, 0x00, 0x10},
  1282. {}
  1283. };
  1284. static const u8 sp80708_sensor_param1[][8] = {
  1285. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  1286. {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
  1287. {0xa1, 0x18, 0x03, 0x01, 0x00, 0x00, 0x00, 0x10},
  1288. {0xa1, 0x18, 0x04, 0xa4, 0x00, 0x00, 0x00, 0x10},
  1289. {0xa1, 0x18, 0x14, 0x3f, 0x00, 0x00, 0x00, 0x10},
  1290. {0xa1, 0x18, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
  1291. {0xb1, 0x18, 0x11, 0x40, 0x40, 0x00, 0x00, 0x10},
  1292. {}
  1293. };
  1294. static const u8 (*sensor_init[])[8] = {
  1295. [SENSOR_ADCM1700] = adcm1700_sensor_init,
  1296. [SENSOR_GC0307] = gc0307_sensor_init,
  1297. [SENSOR_HV7131R] = hv7131r_sensor_init,
  1298. [SENSOR_MI0360] = mi0360_sensor_init,
  1299. [SENSOR_MI0360B] = mi0360b_sensor_init,
  1300. [SENSOR_MO4000] = mo4000_sensor_init,
  1301. [SENSOR_MT9V111] = mt9v111_sensor_init,
  1302. [SENSOR_OM6802] = om6802_sensor_init,
  1303. [SENSOR_OV7630] = ov7630_sensor_init,
  1304. [SENSOR_OV7648] = ov7648_sensor_init,
  1305. [SENSOR_OV7660] = ov7660_sensor_init,
  1306. [SENSOR_PO1030] = po1030_sensor_init,
  1307. [SENSOR_PO2030N] = po2030n_sensor_init,
  1308. [SENSOR_SOI768] = soi768_sensor_init,
  1309. [SENSOR_SP80708] = sp80708_sensor_init,
  1310. };
  1311. /* read <len> bytes to gspca_dev->usb_buf */
  1312. static void reg_r(struct gspca_dev *gspca_dev,
  1313. u16 value, int len)
  1314. {
  1315. int ret;
  1316. if (gspca_dev->usb_err < 0)
  1317. return;
  1318. #ifdef GSPCA_DEBUG
  1319. if (len > USB_BUF_SZ) {
  1320. pr_err("reg_r: buffer overflow\n");
  1321. return;
  1322. }
  1323. #endif
  1324. ret = usb_control_msg(gspca_dev->dev,
  1325. usb_rcvctrlpipe(gspca_dev->dev, 0),
  1326. 0,
  1327. USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1328. value, 0,
  1329. gspca_dev->usb_buf, len,
  1330. 500);
  1331. PDEBUG(D_USBI, "reg_r [%02x] -> %02x", value, gspca_dev->usb_buf[0]);
  1332. if (ret < 0) {
  1333. pr_err("reg_r err %d\n", ret);
  1334. gspca_dev->usb_err = ret;
  1335. }
  1336. }
  1337. static void reg_w1(struct gspca_dev *gspca_dev,
  1338. u16 value,
  1339. u8 data)
  1340. {
  1341. int ret;
  1342. if (gspca_dev->usb_err < 0)
  1343. return;
  1344. PDEBUG(D_USBO, "reg_w1 [%04x] = %02x", value, data);
  1345. gspca_dev->usb_buf[0] = data;
  1346. ret = usb_control_msg(gspca_dev->dev,
  1347. usb_sndctrlpipe(gspca_dev->dev, 0),
  1348. 0x08,
  1349. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1350. value,
  1351. 0,
  1352. gspca_dev->usb_buf, 1,
  1353. 500);
  1354. if (ret < 0) {
  1355. pr_err("reg_w1 err %d\n", ret);
  1356. gspca_dev->usb_err = ret;
  1357. }
  1358. }
  1359. static void reg_w(struct gspca_dev *gspca_dev,
  1360. u16 value,
  1361. const u8 *buffer,
  1362. int len)
  1363. {
  1364. int ret;
  1365. if (gspca_dev->usb_err < 0)
  1366. return;
  1367. PDEBUG(D_USBO, "reg_w [%04x] = %02x %02x ..",
  1368. value, buffer[0], buffer[1]);
  1369. #ifdef GSPCA_DEBUG
  1370. if (len > USB_BUF_SZ) {
  1371. pr_err("reg_w: buffer overflow\n");
  1372. return;
  1373. }
  1374. #endif
  1375. memcpy(gspca_dev->usb_buf, buffer, len);
  1376. ret = usb_control_msg(gspca_dev->dev,
  1377. usb_sndctrlpipe(gspca_dev->dev, 0),
  1378. 0x08,
  1379. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1380. value, 0,
  1381. gspca_dev->usb_buf, len,
  1382. 500);
  1383. if (ret < 0) {
  1384. pr_err("reg_w err %d\n", ret);
  1385. gspca_dev->usb_err = ret;
  1386. }
  1387. }
  1388. /* I2C write 1 byte */
  1389. static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
  1390. {
  1391. struct sd *sd = (struct sd *) gspca_dev;
  1392. int ret;
  1393. if (gspca_dev->usb_err < 0)
  1394. return;
  1395. PDEBUG(D_USBO, "i2c_w1 [%02x] = %02x", reg, val);
  1396. switch (sd->sensor) {
  1397. case SENSOR_ADCM1700:
  1398. case SENSOR_OM6802:
  1399. case SENSOR_GC0307: /* i2c command = a0 (100 kHz) */
  1400. gspca_dev->usb_buf[0] = 0x80 | (2 << 4);
  1401. break;
  1402. default: /* i2c command = a1 (400 kHz) */
  1403. gspca_dev->usb_buf[0] = 0x81 | (2 << 4);
  1404. break;
  1405. }
  1406. gspca_dev->usb_buf[1] = sd->i2c_addr;
  1407. gspca_dev->usb_buf[2] = reg;
  1408. gspca_dev->usb_buf[3] = val;
  1409. gspca_dev->usb_buf[4] = 0;
  1410. gspca_dev->usb_buf[5] = 0;
  1411. gspca_dev->usb_buf[6] = 0;
  1412. gspca_dev->usb_buf[7] = 0x10;
  1413. ret = usb_control_msg(gspca_dev->dev,
  1414. usb_sndctrlpipe(gspca_dev->dev, 0),
  1415. 0x08,
  1416. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1417. 0x08, /* value = i2c */
  1418. 0,
  1419. gspca_dev->usb_buf, 8,
  1420. 500);
  1421. if (ret < 0) {
  1422. pr_err("i2c_w1 err %d\n", ret);
  1423. gspca_dev->usb_err = ret;
  1424. }
  1425. }
  1426. /* I2C write 8 bytes */
  1427. static void i2c_w8(struct gspca_dev *gspca_dev,
  1428. const u8 *buffer)
  1429. {
  1430. int ret;
  1431. if (gspca_dev->usb_err < 0)
  1432. return;
  1433. PDEBUG(D_USBO, "i2c_w8 [%02x] = %02x ..",
  1434. buffer[2], buffer[3]);
  1435. memcpy(gspca_dev->usb_buf, buffer, 8);
  1436. ret = usb_control_msg(gspca_dev->dev,
  1437. usb_sndctrlpipe(gspca_dev->dev, 0),
  1438. 0x08,
  1439. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  1440. 0x08, 0, /* value, index */
  1441. gspca_dev->usb_buf, 8,
  1442. 500);
  1443. msleep(2);
  1444. if (ret < 0) {
  1445. pr_err("i2c_w8 err %d\n", ret);
  1446. gspca_dev->usb_err = ret;
  1447. }
  1448. }
  1449. /* sensor read 'len' (1..5) bytes in gspca_dev->usb_buf */
  1450. static void i2c_r(struct gspca_dev *gspca_dev, u8 reg, int len)
  1451. {
  1452. struct sd *sd = (struct sd *) gspca_dev;
  1453. u8 mode[8];
  1454. switch (sd->sensor) {
  1455. case SENSOR_ADCM1700:
  1456. case SENSOR_OM6802:
  1457. case SENSOR_GC0307: /* i2c command = a0 (100 kHz) */
  1458. mode[0] = 0x80 | 0x10;
  1459. break;
  1460. default: /* i2c command = 91 (400 kHz) */
  1461. mode[0] = 0x81 | 0x10;
  1462. break;
  1463. }
  1464. mode[1] = sd->i2c_addr;
  1465. mode[2] = reg;
  1466. mode[3] = 0;
  1467. mode[4] = 0;
  1468. mode[5] = 0;
  1469. mode[6] = 0;
  1470. mode[7] = 0x10;
  1471. i2c_w8(gspca_dev, mode);
  1472. msleep(2);
  1473. mode[0] = (mode[0] & 0x81) | (len << 4) | 0x02;
  1474. mode[2] = 0;
  1475. i2c_w8(gspca_dev, mode);
  1476. msleep(2);
  1477. reg_r(gspca_dev, 0x0a, 5);
  1478. }
  1479. static void i2c_w_seq(struct gspca_dev *gspca_dev,
  1480. const u8 (*data)[8])
  1481. {
  1482. while ((*data)[0] != 0) {
  1483. if ((*data)[0] != DELAY)
  1484. i2c_w8(gspca_dev, *data);
  1485. else
  1486. msleep((*data)[1]);
  1487. data++;
  1488. }
  1489. }
  1490. /* check the ID of the hv7131 sensor */
  1491. /* this sequence is needed because it activates the sensor */
  1492. static void hv7131r_probe(struct gspca_dev *gspca_dev)
  1493. {
  1494. i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */
  1495. msleep(10);
  1496. reg_w1(gspca_dev, 0x02, 0x66); /* Gpio on */
  1497. msleep(10);
  1498. i2c_r(gspca_dev, 0, 5); /* read sensor id */
  1499. if (gspca_dev->usb_buf[0] == 0x02 /* chip ID (02 is R) */
  1500. && gspca_dev->usb_buf[1] == 0x09
  1501. && gspca_dev->usb_buf[2] == 0x01) {
  1502. PDEBUG(D_PROBE, "Sensor HV7131R found");
  1503. return;
  1504. }
  1505. pr_warn("Erroneous HV7131R ID 0x%02x 0x%02x 0x%02x\n",
  1506. gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
  1507. gspca_dev->usb_buf[2]);
  1508. }
  1509. static void mi0360_probe(struct gspca_dev *gspca_dev)
  1510. {
  1511. struct sd *sd = (struct sd *) gspca_dev;
  1512. int i, j;
  1513. u16 val = 0;
  1514. static const u8 probe_tb[][4][8] = {
  1515. { /* mi0360 */
  1516. {0xb0, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
  1517. {0x90, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1518. {0xa2, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1519. {0xb0, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10}
  1520. },
  1521. { /* mt9v111 */
  1522. {0xb0, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10},
  1523. {0x90, 0x5c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x10},
  1524. {0xa2, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
  1525. {}
  1526. },
  1527. };
  1528. for (i = 0; i < ARRAY_SIZE(probe_tb); i++) {
  1529. reg_w1(gspca_dev, 0x17, 0x62);
  1530. reg_w1(gspca_dev, 0x01, 0x08);
  1531. for (j = 0; j < 3; j++)
  1532. i2c_w8(gspca_dev, probe_tb[i][j]);
  1533. msleep(2);
  1534. reg_r(gspca_dev, 0x0a, 5);
  1535. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1536. if (probe_tb[i][3][0] != 0)
  1537. i2c_w8(gspca_dev, probe_tb[i][3]);
  1538. reg_w1(gspca_dev, 0x01, 0x29);
  1539. reg_w1(gspca_dev, 0x17, 0x42);
  1540. if (val != 0xffff)
  1541. break;
  1542. }
  1543. if (gspca_dev->usb_err < 0)
  1544. return;
  1545. switch (val) {
  1546. case 0x8221:
  1547. PDEBUG(D_PROBE, "Sensor mi0360b");
  1548. sd->sensor = SENSOR_MI0360B;
  1549. break;
  1550. case 0x823a:
  1551. PDEBUG(D_PROBE, "Sensor mt9v111");
  1552. sd->sensor = SENSOR_MT9V111;
  1553. break;
  1554. case 0x8243:
  1555. PDEBUG(D_PROBE, "Sensor mi0360");
  1556. break;
  1557. default:
  1558. PDEBUG(D_PROBE, "Unknown sensor %04x - forced to mi0360", val);
  1559. break;
  1560. }
  1561. }
  1562. static void ov7630_probe(struct gspca_dev *gspca_dev)
  1563. {
  1564. struct sd *sd = (struct sd *) gspca_dev;
  1565. u16 val;
  1566. /* check ov76xx */
  1567. reg_w1(gspca_dev, 0x17, 0x62);
  1568. reg_w1(gspca_dev, 0x01, 0x08);
  1569. sd->i2c_addr = 0x21;
  1570. i2c_r(gspca_dev, 0x0a, 2);
  1571. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1572. reg_w1(gspca_dev, 0x01, 0x29);
  1573. reg_w1(gspca_dev, 0x17, 0x42);
  1574. if (gspca_dev->usb_err < 0)
  1575. return;
  1576. if (val == 0x7628) { /* soi768 */
  1577. sd->sensor = SENSOR_SOI768;
  1578. /*fixme: only valid for 0c45:613e?*/
  1579. gspca_dev->cam.input_flags =
  1580. V4L2_IN_ST_VFLIP | V4L2_IN_ST_HFLIP;
  1581. PDEBUG(D_PROBE, "Sensor soi768");
  1582. return;
  1583. }
  1584. PDEBUG(D_PROBE, "Sensor ov%04x", val);
  1585. }
  1586. static void ov7648_probe(struct gspca_dev *gspca_dev)
  1587. {
  1588. struct sd *sd = (struct sd *) gspca_dev;
  1589. u16 val;
  1590. /* check ov76xx */
  1591. reg_w1(gspca_dev, 0x17, 0x62);
  1592. reg_w1(gspca_dev, 0x01, 0x08);
  1593. sd->i2c_addr = 0x21;
  1594. i2c_r(gspca_dev, 0x0a, 2);
  1595. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1596. reg_w1(gspca_dev, 0x01, 0x29);
  1597. reg_w1(gspca_dev, 0x17, 0x42);
  1598. if ((val & 0xff00) == 0x7600) { /* ov76xx */
  1599. PDEBUG(D_PROBE, "Sensor ov%04x", val);
  1600. return;
  1601. }
  1602. /* check po1030 */
  1603. reg_w1(gspca_dev, 0x17, 0x62);
  1604. reg_w1(gspca_dev, 0x01, 0x08);
  1605. sd->i2c_addr = 0x6e;
  1606. i2c_r(gspca_dev, 0x00, 2);
  1607. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1608. reg_w1(gspca_dev, 0x01, 0x29);
  1609. reg_w1(gspca_dev, 0x17, 0x42);
  1610. if (gspca_dev->usb_err < 0)
  1611. return;
  1612. if (val == 0x1030) { /* po1030 */
  1613. PDEBUG(D_PROBE, "Sensor po1030");
  1614. sd->sensor = SENSOR_PO1030;
  1615. return;
  1616. }
  1617. pr_err("Unknown sensor %04x\n", val);
  1618. }
  1619. /* 0c45:6142 sensor may be po2030n, gc0305 or gc0307 */
  1620. static void po2030n_probe(struct gspca_dev *gspca_dev)
  1621. {
  1622. struct sd *sd = (struct sd *) gspca_dev;
  1623. u16 val;
  1624. /* check gc0307 */
  1625. reg_w1(gspca_dev, 0x17, 0x62);
  1626. reg_w1(gspca_dev, 0x01, 0x08);
  1627. reg_w1(gspca_dev, 0x02, 0x22);
  1628. sd->i2c_addr = 0x21;
  1629. i2c_r(gspca_dev, 0x00, 1);
  1630. val = gspca_dev->usb_buf[4];
  1631. reg_w1(gspca_dev, 0x01, 0x29); /* reset */
  1632. reg_w1(gspca_dev, 0x17, 0x42);
  1633. if (val == 0x99) { /* gc0307 (?) */
  1634. PDEBUG(D_PROBE, "Sensor gc0307");
  1635. sd->sensor = SENSOR_GC0307;
  1636. return;
  1637. }
  1638. /* check po2030n */
  1639. reg_w1(gspca_dev, 0x17, 0x62);
  1640. reg_w1(gspca_dev, 0x01, 0x0a);
  1641. sd->i2c_addr = 0x6e;
  1642. i2c_r(gspca_dev, 0x00, 2);
  1643. val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
  1644. reg_w1(gspca_dev, 0x01, 0x29);
  1645. reg_w1(gspca_dev, 0x17, 0x42);
  1646. if (gspca_dev->usb_err < 0)
  1647. return;
  1648. if (val == 0x2030) {
  1649. PDEBUG(D_PROBE, "Sensor po2030n");
  1650. /* sd->sensor = SENSOR_PO2030N; */
  1651. } else {
  1652. pr_err("Unknown sensor ID %04x\n", val);
  1653. }
  1654. }
  1655. /* this function is called at probe time */
  1656. static int sd_config(struct gspca_dev *gspca_dev,
  1657. const struct usb_device_id *id)
  1658. {
  1659. struct sd *sd = (struct sd *) gspca_dev;
  1660. struct cam *cam;
  1661. sd->bridge = id->driver_info >> 16;
  1662. sd->sensor = id->driver_info >> 8;
  1663. sd->flags = id->driver_info;
  1664. cam = &gspca_dev->cam;
  1665. if (sd->sensor == SENSOR_ADCM1700) {
  1666. cam->cam_mode = cif_mode;
  1667. cam->nmodes = ARRAY_SIZE(cif_mode);
  1668. } else {
  1669. cam->cam_mode = vga_mode;
  1670. cam->nmodes = ARRAY_SIZE(vga_mode);
  1671. }
  1672. cam->npkt = 24; /* 24 packets per ISOC message */
  1673. cam->ctrls = sd->ctrls;
  1674. sd->ag_cnt = -1;
  1675. sd->quality = QUALITY_DEF;
  1676. /* if USB 1.1, let some bandwidth for the audio device */
  1677. if (gspca_dev->audio && gspca_dev->dev->speed < USB_SPEED_HIGH)
  1678. gspca_dev->nbalt--;
  1679. INIT_WORK(&sd->work, qual_upd);
  1680. return 0;
  1681. }
  1682. /* this function is called at probe and resume time */
  1683. static int sd_init(struct gspca_dev *gspca_dev)
  1684. {
  1685. struct sd *sd = (struct sd *) gspca_dev;
  1686. const u8 *sn9c1xx;
  1687. u8 regGpio[] = { 0x29, 0x70 }; /* no audio */
  1688. u8 regF1;
  1689. /* setup a selector by bridge */
  1690. reg_w1(gspca_dev, 0xf1, 0x01);
  1691. reg_r(gspca_dev, 0x00, 1);
  1692. reg_w1(gspca_dev, 0xf1, 0x00);
  1693. reg_r(gspca_dev, 0x00, 1); /* get sonix chip id */
  1694. regF1 = gspca_dev->usb_buf[0];
  1695. if (gspca_dev->usb_err < 0)
  1696. return gspca_dev->usb_err;
  1697. PDEBUG(D_PROBE, "Sonix chip id: %02x", regF1);
  1698. if (gspca_dev->audio)
  1699. regGpio[1] |= 0x04; /* with audio */
  1700. switch (sd->bridge) {
  1701. case BRIDGE_SN9C102P:
  1702. case BRIDGE_SN9C105:
  1703. if (regF1 != 0x11)
  1704. return -ENODEV;
  1705. break;
  1706. default:
  1707. /* case BRIDGE_SN9C110: */
  1708. /* case BRIDGE_SN9C120: */
  1709. if (regF1 != 0x12)
  1710. return -ENODEV;
  1711. }
  1712. switch (sd->sensor) {
  1713. case SENSOR_MI0360:
  1714. mi0360_probe(gspca_dev);
  1715. break;
  1716. case SENSOR_OV7630:
  1717. ov7630_probe(gspca_dev);
  1718. break;
  1719. case SENSOR_OV7648:
  1720. ov7648_probe(gspca_dev);
  1721. break;
  1722. case SENSOR_PO2030N:
  1723. po2030n_probe(gspca_dev);
  1724. break;
  1725. }
  1726. switch (sd->bridge) {
  1727. case BRIDGE_SN9C102P:
  1728. reg_w1(gspca_dev, 0x02, regGpio[1]);
  1729. break;
  1730. default:
  1731. reg_w(gspca_dev, 0x01, regGpio, 2);
  1732. break;
  1733. }
  1734. if (sd->sensor == SENSOR_OM6802)
  1735. sd->ctrls[SHARPNESS].def = 0x10;
  1736. /* Note we do not disable the sensor clock here (power saving mode),
  1737. as that also disables the button on the cam. */
  1738. reg_w1(gspca_dev, 0xf1, 0x00);
  1739. /* set the i2c address */
  1740. sn9c1xx = sn_tb[sd->sensor];
  1741. sd->i2c_addr = sn9c1xx[9];
  1742. gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
  1743. if (!(sd->flags & F_ILLUM))
  1744. gspca_dev->ctrl_dis |= (1 << ILLUM);
  1745. return gspca_dev->usb_err;
  1746. }
  1747. static u32 setexposure(struct gspca_dev *gspca_dev,
  1748. u32 expo)
  1749. {
  1750. struct sd *sd = (struct sd *) gspca_dev;
  1751. switch (sd->sensor) {
  1752. case SENSOR_GC0307: {
  1753. int a, b;
  1754. /* expo = 0..255 -> a = 19..43 */
  1755. a = 19 + expo * 25 / 256;
  1756. i2c_w1(gspca_dev, 0x68, a);
  1757. a -= 12;
  1758. b = a * a * 4; /* heuristic */
  1759. i2c_w1(gspca_dev, 0x03, b >> 8);
  1760. i2c_w1(gspca_dev, 0x04, b);
  1761. break;
  1762. }
  1763. case SENSOR_HV7131R: {
  1764. u8 Expodoit[] =
  1765. { 0xc1, 0x11, 0x25, 0x00, 0x00, 0x00, 0x00, 0x16 };
  1766. Expodoit[3] = expo >> 16;
  1767. Expodoit[4] = expo >> 8;
  1768. Expodoit[5] = expo;
  1769. i2c_w8(gspca_dev, Expodoit);
  1770. break;
  1771. }
  1772. case SENSOR_MI0360:
  1773. case SENSOR_MI0360B: {
  1774. u8 expoMi[] = /* exposure 0x0635 -> 4 fp/s 0x10 */
  1775. { 0xb1, 0x5d, 0x09, 0x00, 0x00, 0x00, 0x00, 0x16 };
  1776. static const u8 doit[] = /* update sensor */
  1777. { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
  1778. static const u8 sensorgo[] = /* sensor on */
  1779. { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
  1780. if (expo > 0x0635)
  1781. expo = 0x0635;
  1782. else if (expo < 0x0001)
  1783. expo = 0x0001;
  1784. expoMi[3] = expo >> 8;
  1785. expoMi[4] = expo;
  1786. i2c_w8(gspca_dev, expoMi);
  1787. i2c_w8(gspca_dev, doit);
  1788. i2c_w8(gspca_dev, sensorgo);
  1789. break;
  1790. }
  1791. case SENSOR_MO4000: {
  1792. u8 expoMof[] =
  1793. { 0xa1, 0x21, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1794. u8 expoMo10[] =
  1795. { 0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1796. static const u8 gainMo[] =
  1797. { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
  1798. if (expo > 0x1fff)
  1799. expo = 0x1fff;
  1800. else if (expo < 0x0001)
  1801. expo = 0x0001;
  1802. expoMof[3] = (expo & 0x03fc) >> 2;
  1803. i2c_w8(gspca_dev, expoMof);
  1804. expoMo10[3] = ((expo & 0x1c00) >> 10)
  1805. | ((expo & 0x0003) << 4);
  1806. i2c_w8(gspca_dev, expoMo10);
  1807. i2c_w8(gspca_dev, gainMo);
  1808. PDEBUG(D_FRAM, "set exposure %d",
  1809. ((expoMo10[3] & 0x07) << 10)
  1810. | (expoMof[3] << 2)
  1811. | ((expoMo10[3] & 0x30) >> 4));
  1812. break;
  1813. }
  1814. case SENSOR_MT9V111: {
  1815. u8 expo_c1[] =
  1816. { 0xb1, 0x5c, 0x09, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1817. if (expo > 0x0390)
  1818. expo = 0x0390;
  1819. else if (expo < 0x0060)
  1820. expo = 0x0060;
  1821. expo_c1[3] = expo >> 8;
  1822. expo_c1[4] = expo;
  1823. i2c_w8(gspca_dev, expo_c1);
  1824. break;
  1825. }
  1826. case SENSOR_OM6802: {
  1827. u8 gainOm[] =
  1828. { 0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10 };
  1829. /* preset AGC - works when AutoExpo = off */
  1830. if (expo > 0x03ff)
  1831. expo = 0x03ff;
  1832. if (expo < 0x0001)
  1833. expo = 0x0001;
  1834. gainOm[3] = expo >> 2;
  1835. i2c_w8(gspca_dev, gainOm);
  1836. reg_w1(gspca_dev, 0x96, expo >> 5);
  1837. PDEBUG(D_FRAM, "set exposure %d", gainOm[3]);
  1838. break;
  1839. }
  1840. }
  1841. return expo;
  1842. }
  1843. static void setbrightness(struct gspca_dev *gspca_dev)
  1844. {
  1845. struct sd *sd = (struct sd *) gspca_dev;
  1846. unsigned int expo;
  1847. int brightness;
  1848. u8 k2;
  1849. brightness = sd->ctrls[BRIGHTNESS].val;
  1850. k2 = (brightness - 0x80) >> 2;
  1851. switch (sd->sensor) {
  1852. case SENSOR_ADCM1700:
  1853. if (k2 > 0x1f)
  1854. k2 = 0; /* only positive Y offset */
  1855. break;
  1856. case SENSOR_HV7131R:
  1857. expo = brightness << 12;
  1858. if (expo > 0x002dc6c0)
  1859. expo = 0x002dc6c0;
  1860. else if (expo < 0x02a0)
  1861. expo = 0x02a0;
  1862. sd->exposure = setexposure(gspca_dev, expo);
  1863. break;
  1864. case SENSOR_MI0360:
  1865. case SENSOR_MO4000:
  1866. expo = brightness << 4;
  1867. sd->exposure = setexposure(gspca_dev, expo);
  1868. break;
  1869. case SENSOR_MI0360B:
  1870. expo = brightness << 2;
  1871. sd->exposure = setexposure(gspca_dev, expo);
  1872. break;
  1873. case SENSOR_GC0307:
  1874. expo = brightness;
  1875. sd->exposure = setexposure(gspca_dev, expo);
  1876. return; /* don't set the Y offset */
  1877. case SENSOR_MT9V111:
  1878. expo = brightness << 2;
  1879. sd->exposure = setexposure(gspca_dev, expo);
  1880. return; /* don't set the Y offset */
  1881. case SENSOR_OM6802:
  1882. expo = brightness << 2;
  1883. sd->exposure = setexposure(gspca_dev, expo);
  1884. k2 = brightness >> 3;
  1885. break;
  1886. }
  1887. reg_w1(gspca_dev, 0x96, k2); /* color matrix Y offset */
  1888. }
  1889. static void setcontrast(struct gspca_dev *gspca_dev)
  1890. {
  1891. struct sd *sd = (struct sd *) gspca_dev;
  1892. u8 k2;
  1893. u8 contrast[6];
  1894. k2 = sd->ctrls[CONTRAST].val * 0x30 / (CONTRAST_MAX + 1)
  1895. + 0x10; /* 10..40 */
  1896. contrast[0] = (k2 + 1) / 2; /* red */
  1897. contrast[1] = 0;
  1898. contrast[2] = k2; /* green */
  1899. contrast[3] = 0;
  1900. contrast[4] = (k2 + 1) / 5; /* blue */
  1901. contrast[5] = 0;
  1902. reg_w(gspca_dev, 0x84, contrast, sizeof contrast);
  1903. }
  1904. static void setcolors(struct gspca_dev *gspca_dev)
  1905. {
  1906. struct sd *sd = (struct sd *) gspca_dev;
  1907. int i, v, colors;
  1908. const s16 *uv;
  1909. u8 reg8a[12]; /* U & V gains */
  1910. static const s16 uv_com[6] = { /* same as reg84 in signed decimal */
  1911. -24, -38, 64, /* UR UG UB */
  1912. 62, -51, -9 /* VR VG VB */
  1913. };
  1914. static const s16 uv_mi0360b[6] = {
  1915. -20, -38, 64, /* UR UG UB */
  1916. 60, -51, -9 /* VR VG VB */
  1917. };
  1918. colors = sd->ctrls[COLORS].val;
  1919. if (sd->sensor == SENSOR_MI0360B)
  1920. uv = uv_mi0360b;
  1921. else
  1922. uv = uv_com;
  1923. for (i = 0; i < 6; i++) {
  1924. v = uv[i] * colors / COLORS_DEF;
  1925. reg8a[i * 2] = v;
  1926. reg8a[i * 2 + 1] = (v >> 8) & 0x0f;
  1927. }
  1928. reg_w(gspca_dev, 0x8a, reg8a, sizeof reg8a);
  1929. }
  1930. static void setredblue(struct gspca_dev *gspca_dev)
  1931. {
  1932. struct sd *sd = (struct sd *) gspca_dev;
  1933. reg_w1(gspca_dev, 0x05, sd->ctrls[RED].val);
  1934. /* reg_w1(gspca_dev, 0x07, 32); */
  1935. reg_w1(gspca_dev, 0x06, sd->ctrls[BLUE].val);
  1936. }
  1937. static void setgamma(struct gspca_dev *gspca_dev)
  1938. {
  1939. struct sd *sd = (struct sd *) gspca_dev;
  1940. int i, val;
  1941. u8 gamma[17];
  1942. const u8 *gamma_base;
  1943. static const u8 delta[17] = {
  1944. 0x00, 0x14, 0x1c, 0x1c, 0x1c, 0x1c, 0x1b, 0x1a,
  1945. 0x18, 0x13, 0x10, 0x0e, 0x08, 0x07, 0x04, 0x02, 0x00
  1946. };
  1947. switch (sd->sensor) {
  1948. case SENSOR_ADCM1700:
  1949. gamma_base = gamma_spec_0;
  1950. break;
  1951. case SENSOR_HV7131R:
  1952. case SENSOR_MI0360B:
  1953. case SENSOR_MT9V111:
  1954. gamma_base = gamma_spec_1;
  1955. break;
  1956. case SENSOR_GC0307:
  1957. gamma_base = gamma_spec_2;
  1958. break;
  1959. case SENSOR_SP80708:
  1960. gamma_base = gamma_spec_3;
  1961. break;
  1962. default:
  1963. gamma_base = gamma_def;
  1964. break;
  1965. }
  1966. val = sd->ctrls[GAMMA].val;
  1967. for (i = 0; i < sizeof gamma; i++)
  1968. gamma[i] = gamma_base[i]
  1969. + delta[i] * (val - GAMMA_DEF) / 32;
  1970. reg_w(gspca_dev, 0x20, gamma, sizeof gamma);
  1971. }
  1972. static void setautogain(struct gspca_dev *gspca_dev)
  1973. {
  1974. struct sd *sd = (struct sd *) gspca_dev;
  1975. if (gspca_dev->ctrl_dis & (1 << AUTOGAIN))
  1976. return;
  1977. switch (sd->sensor) {
  1978. case SENSOR_OV7630:
  1979. case SENSOR_OV7648: {
  1980. u8 comb;
  1981. if (sd->sensor == SENSOR_OV7630)
  1982. comb = 0xc0;
  1983. else
  1984. comb = 0xa0;
  1985. if (sd->ctrls[AUTOGAIN].val)
  1986. comb |= 0x03;
  1987. i2c_w1(&sd->gspca_dev, 0x13, comb);
  1988. return;
  1989. }
  1990. }
  1991. if (sd->ctrls[AUTOGAIN].val)
  1992. sd->ag_cnt = AG_CNT_START;
  1993. else
  1994. sd->ag_cnt = -1;
  1995. }
  1996. static void sethvflip(struct gspca_dev *gspca_dev)
  1997. {
  1998. struct sd *sd = (struct sd *) gspca_dev;
  1999. u8 comn;
  2000. switch (sd->sensor) {
  2001. case SENSOR_HV7131R:
  2002. comn = 0x18; /* clkdiv = 1, ablcen = 1 */
  2003. if (sd->ctrls[VFLIP].val)
  2004. comn |= 0x01;
  2005. i2c_w1(gspca_dev, 0x01, comn); /* sctra */
  2006. break;
  2007. case SENSOR_OV7630:
  2008. comn = 0x02;
  2009. if (!sd->ctrls[VFLIP].val)
  2010. comn |= 0x80;
  2011. i2c_w1(gspca_dev, 0x75, comn);
  2012. break;
  2013. case SENSOR_OV7648:
  2014. comn = 0x06;
  2015. if (sd->ctrls[VFLIP].val)
  2016. comn |= 0x80;
  2017. i2c_w1(gspca_dev, 0x75, comn);
  2018. break;
  2019. case SENSOR_PO2030N:
  2020. /* Reg. 0x1E: Timing Generator Control Register 2 (Tgcontrol2)
  2021. * (reset value: 0x0A)
  2022. * bit7: HM: Horizontal Mirror: 0: disable, 1: enable
  2023. * bit6: VM: Vertical Mirror: 0: disable, 1: enable
  2024. * bit5: ST: Shutter Selection: 0: electrical, 1: mechanical
  2025. * bit4: FT: Single Frame Transfer: 0: disable, 1: enable
  2026. * bit3-0: X
  2027. */
  2028. comn = 0x0a;
  2029. if (sd->ctrls[HFLIP].val)
  2030. comn |= 0x80;
  2031. if (sd->ctrls[VFLIP].val)
  2032. comn |= 0x40;
  2033. i2c_w1(&sd->gspca_dev, 0x1e, comn);
  2034. break;
  2035. }
  2036. }
  2037. static void setsharpness(struct gspca_dev *gspca_dev)
  2038. {
  2039. struct sd *sd = (struct sd *) gspca_dev;
  2040. reg_w1(gspca_dev, 0x99, sd->ctrls[SHARPNESS].val);
  2041. }
  2042. static void setillum(struct gspca_dev *gspca_dev)
  2043. {
  2044. struct sd *sd = (struct sd *) gspca_dev;
  2045. if (gspca_dev->ctrl_dis & (1 << ILLUM))
  2046. return;
  2047. switch (sd->sensor) {
  2048. case SENSOR_ADCM1700:
  2049. reg_w1(gspca_dev, 0x02, /* gpio */
  2050. sd->ctrls[ILLUM].val ? 0x64 : 0x60);
  2051. break;
  2052. case SENSOR_MT9V111:
  2053. reg_w1(gspca_dev, 0x02,
  2054. sd->ctrls[ILLUM].val ? 0x77 : 0x74);
  2055. /* should have been: */
  2056. /* 0x55 : 0x54); * 370i */
  2057. /* 0x66 : 0x64); * Clip */
  2058. break;
  2059. }
  2060. }
  2061. static void setfreq(struct gspca_dev *gspca_dev)
  2062. {
  2063. struct sd *sd = (struct sd *) gspca_dev;
  2064. if (gspca_dev->ctrl_dis & (1 << FREQ))
  2065. return;
  2066. if (sd->sensor == SENSOR_OV7660) {
  2067. u8 com8;
  2068. com8 = 0xdf; /* auto gain/wb/expo */
  2069. switch (sd->ctrls[FREQ].val) {
  2070. case 0: /* Banding filter disabled */
  2071. i2c_w1(gspca_dev, 0x13, com8 | 0x20);
  2072. break;
  2073. case 1: /* 50 hz */
  2074. i2c_w1(gspca_dev, 0x13, com8);
  2075. i2c_w1(gspca_dev, 0x3b, 0x0a);
  2076. break;
  2077. case 2: /* 60 hz */
  2078. i2c_w1(gspca_dev, 0x13, com8);
  2079. i2c_w1(gspca_dev, 0x3b, 0x02);
  2080. break;
  2081. }
  2082. } else {
  2083. u8 reg2a = 0, reg2b = 0, reg2d = 0;
  2084. /* Get reg2a / reg2d base values */
  2085. switch (sd->sensor) {
  2086. case SENSOR_OV7630:
  2087. reg2a = 0x08;
  2088. reg2d = 0x01;
  2089. break;
  2090. case SENSOR_OV7648:
  2091. reg2a = 0x11;
  2092. reg2d = 0x81;
  2093. break;
  2094. }
  2095. switch (sd->ctrls[FREQ].val) {
  2096. case 0: /* Banding filter disabled */
  2097. break;
  2098. case 1: /* 50 hz (filter on and framerate adj) */
  2099. reg2a |= 0x80;
  2100. reg2b = 0xac;
  2101. reg2d |= 0x04;
  2102. break;
  2103. case 2: /* 60 hz (filter on, no framerate adj) */
  2104. reg2a |= 0x80;
  2105. reg2d |= 0x04;
  2106. break;
  2107. }
  2108. i2c_w1(gspca_dev, 0x2a, reg2a);
  2109. i2c_w1(gspca_dev, 0x2b, reg2b);
  2110. i2c_w1(gspca_dev, 0x2d, reg2d);
  2111. }
  2112. }
  2113. static void setjpegqual(struct gspca_dev *gspca_dev)
  2114. {
  2115. struct sd *sd = (struct sd *) gspca_dev;
  2116. jpeg_set_qual(sd->jpeg_hdr, sd->quality);
  2117. #if USB_BUF_SZ < 64
  2118. #error "No room enough in usb_buf for quantization table"
  2119. #endif
  2120. memcpy(gspca_dev->usb_buf, &sd->jpeg_hdr[JPEG_QT0_OFFSET], 64);
  2121. usb_control_msg(gspca_dev->dev,
  2122. usb_sndctrlpipe(gspca_dev->dev, 0),
  2123. 0x08,
  2124. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  2125. 0x0100, 0,
  2126. gspca_dev->usb_buf, 64,
  2127. 500);
  2128. memcpy(gspca_dev->usb_buf, &sd->jpeg_hdr[JPEG_QT1_OFFSET], 64);
  2129. usb_control_msg(gspca_dev->dev,
  2130. usb_sndctrlpipe(gspca_dev->dev, 0),
  2131. 0x08,
  2132. USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  2133. 0x0140, 0,
  2134. gspca_dev->usb_buf, 64,
  2135. 500);
  2136. sd->reg18 ^= 0x40;
  2137. reg_w1(gspca_dev, 0x18, sd->reg18);
  2138. }
  2139. /* JPEG quality update */
  2140. /* This function is executed from a work queue. */
  2141. static void qual_upd(struct work_struct *work)
  2142. {
  2143. struct sd *sd = container_of(work, struct sd, work);
  2144. struct gspca_dev *gspca_dev = &sd->gspca_dev;
  2145. mutex_lock(&gspca_dev->usb_lock);
  2146. PDEBUG(D_STREAM, "qual_upd %d%%", sd->quality);
  2147. setjpegqual(gspca_dev);
  2148. mutex_unlock(&gspca_dev->usb_lock);
  2149. }
  2150. /* -- start the camera -- */
  2151. static int sd_start(struct gspca_dev *gspca_dev)
  2152. {
  2153. struct sd *sd = (struct sd *) gspca_dev;
  2154. int i;
  2155. u8 reg01, reg17;
  2156. u8 reg0102[2];
  2157. const u8 *sn9c1xx;
  2158. const u8 (*init)[8];
  2159. const u8 *reg9a;
  2160. int mode;
  2161. static const u8 reg9a_def[] =
  2162. {0x00, 0x40, 0x20, 0x00, 0x00, 0x00};
  2163. static const u8 reg9a_spec[] =
  2164. {0x00, 0x40, 0x38, 0x30, 0x00, 0x20};
  2165. static const u8 regd4[] = {0x60, 0x00, 0x00};
  2166. static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
  2167. static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
  2168. static const u8 CA_adcm1700[] =
  2169. { 0x14, 0xec, 0x0a, 0xf6 };
  2170. static const u8 CA_po2030n[] =
  2171. { 0x1e, 0xe2, 0x14, 0xec };
  2172. static const u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */
  2173. static const u8 CE_gc0307[] =
  2174. { 0x32, 0xce, 0x2d, 0xd3 };
  2175. static const u8 CE_ov76xx[] =
  2176. { 0x32, 0xdd, 0x32, 0xdd };
  2177. static const u8 CE_po2030n[] =
  2178. { 0x14, 0xe7, 0x1e, 0xdd };
  2179. /* create the JPEG header */
  2180. jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
  2181. 0x21); /* JPEG 422 */
  2182. /* initialize the bridge */
  2183. sn9c1xx = sn_tb[sd->sensor];
  2184. /* sensor clock already enabled in sd_init */
  2185. /* reg_w1(gspca_dev, 0xf1, 0x00); */
  2186. reg01 = sn9c1xx[1];
  2187. if (sd->flags & F_PDN_INV)
  2188. reg01 ^= S_PDN_INV; /* power down inverted */
  2189. reg_w1(gspca_dev, 0x01, reg01);
  2190. /* configure gpio */
  2191. reg0102[0] = reg01;
  2192. reg0102[1] = sn9c1xx[2];
  2193. if (gspca_dev->audio)
  2194. reg0102[1] |= 0x04; /* keep the audio connection */
  2195. reg_w(gspca_dev, 0x01, reg0102, 2);
  2196. reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
  2197. reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5);
  2198. switch (sd->sensor) {
  2199. case SENSOR_GC0307:
  2200. case SENSOR_OV7660:
  2201. case SENSOR_PO1030:
  2202. case SENSOR_PO2030N:
  2203. case SENSOR_SOI768:
  2204. case SENSOR_SP80708:
  2205. reg9a = reg9a_spec;
  2206. break;
  2207. default:
  2208. reg9a = reg9a_def;
  2209. break;
  2210. }
  2211. reg_w(gspca_dev, 0x9a, reg9a, 6);
  2212. reg_w(gspca_dev, 0xd4, regd4, sizeof regd4);
  2213. reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
  2214. reg17 = sn9c1xx[0x17];
  2215. switch (sd->sensor) {
  2216. case SENSOR_GC0307:
  2217. msleep(50); /*fixme: is it useful? */
  2218. break;
  2219. case SENSOR_OM6802:
  2220. msleep(10);
  2221. reg_w1(gspca_dev, 0x02, 0x73);
  2222. reg17 |= SEN_CLK_EN;
  2223. reg_w1(gspca_dev, 0x17, reg17);
  2224. reg_w1(gspca_dev, 0x01, 0x22);
  2225. msleep(100);
  2226. reg01 = SCL_SEL_OD | S_PDN_INV;
  2227. reg17 &= ~MCK_SIZE_MASK;
  2228. reg17 |= 0x04; /* clock / 4 */
  2229. break;
  2230. }
  2231. reg01 |= SYS_SEL_48M;
  2232. reg_w1(gspca_dev, 0x01, reg01);
  2233. reg17 |= SEN_CLK_EN;
  2234. reg_w1(gspca_dev, 0x17, reg17);
  2235. reg01 &= ~S_PWR_DN; /* sensor power on */
  2236. reg_w1(gspca_dev, 0x01, reg01);
  2237. reg01 &= ~SYS_SEL_48M;
  2238. reg_w1(gspca_dev, 0x01, reg01);
  2239. switch (sd->sensor) {
  2240. case SENSOR_HV7131R:
  2241. hv7131r_probe(gspca_dev); /*fixme: is it useful? */
  2242. break;
  2243. case SENSOR_OM6802:
  2244. msleep(10);
  2245. reg_w1(gspca_dev, 0x01, reg01);
  2246. i2c_w8(gspca_dev, om6802_init0[0]);
  2247. i2c_w8(gspca_dev, om6802_init0[1]);
  2248. msleep(15);
  2249. reg_w1(gspca_dev, 0x02, 0x71);
  2250. msleep(150);
  2251. break;
  2252. case SENSOR_SP80708:
  2253. msleep(100);
  2254. reg_w1(gspca_dev, 0x02, 0x62);
  2255. break;
  2256. }
  2257. /* initialize the sensor */
  2258. i2c_w_seq(gspca_dev, sensor_init[sd->sensor]);
  2259. reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]);
  2260. reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]);
  2261. reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
  2262. reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]);
  2263. reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
  2264. if (sd->sensor == SENSOR_ADCM1700) {
  2265. reg_w1(gspca_dev, 0xd2, 0x3a); /* AE_H_SIZE = 116 */
  2266. reg_w1(gspca_dev, 0xd3, 0x30); /* AE_V_SIZE = 96 */
  2267. } else {
  2268. reg_w1(gspca_dev, 0xd2, 0x6a); /* AE_H_SIZE = 212 */
  2269. reg_w1(gspca_dev, 0xd3, 0x50); /* AE_V_SIZE = 160 */
  2270. }
  2271. reg_w1(gspca_dev, 0xc6, 0x00);
  2272. reg_w1(gspca_dev, 0xc7, 0x00);
  2273. if (sd->sensor == SENSOR_ADCM1700) {
  2274. reg_w1(gspca_dev, 0xc8, 0x2c); /* AW_H_STOP = 352 */
  2275. reg_w1(gspca_dev, 0xc9, 0x24); /* AW_V_STOP = 288 */
  2276. } else {
  2277. reg_w1(gspca_dev, 0xc8, 0x50); /* AW_H_STOP = 640 */
  2278. reg_w1(gspca_dev, 0xc9, 0x3c); /* AW_V_STOP = 480 */
  2279. }
  2280. reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
  2281. switch (sd->sensor) {
  2282. case SENSOR_OM6802:
  2283. /* case SENSOR_OV7648: * fixme: sometimes */
  2284. break;
  2285. default:
  2286. reg17 |= DEF_EN;
  2287. break;
  2288. }
  2289. reg_w1(gspca_dev, 0x17, reg17);
  2290. reg_w1(gspca_dev, 0x05, 0x00); /* red */
  2291. reg_w1(gspca_dev, 0x07, 0x00); /* green */
  2292. reg_w1(gspca_dev, 0x06, 0x00); /* blue */
  2293. reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
  2294. setgamma(gspca_dev);
  2295. /*fixme: 8 times with all zeroes and 1 or 2 times with normal values */
  2296. for (i = 0; i < 8; i++)
  2297. reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
  2298. switch (sd->sensor) {
  2299. case SENSOR_ADCM1700:
  2300. case SENSOR_OV7660:
  2301. case SENSOR_SP80708:
  2302. reg_w1(gspca_dev, 0x9a, 0x05);
  2303. break;
  2304. case SENSOR_GC0307:
  2305. case SENSOR_MT9V111:
  2306. case SENSOR_MI0360B:
  2307. reg_w1(gspca_dev, 0x9a, 0x07);
  2308. break;
  2309. case SENSOR_OV7630:
  2310. case SENSOR_OV7648:
  2311. reg_w1(gspca_dev, 0x9a, 0x0a);
  2312. break;
  2313. case SENSOR_PO2030N:
  2314. case SENSOR_SOI768:
  2315. reg_w1(gspca_dev, 0x9a, 0x06);
  2316. break;
  2317. default:
  2318. reg_w1(gspca_dev, 0x9a, 0x08);
  2319. break;
  2320. }
  2321. setsharpness(gspca_dev);
  2322. reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
  2323. reg_w1(gspca_dev, 0x05, 0x20); /* red */
  2324. reg_w1(gspca_dev, 0x07, 0x20); /* green */
  2325. reg_w1(gspca_dev, 0x06, 0x20); /* blue */
  2326. init = NULL;
  2327. mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
  2328. reg01 |= SYS_SEL_48M | V_TX_EN;
  2329. reg17 &= ~MCK_SIZE_MASK;
  2330. reg17 |= 0x02; /* clock / 2 */
  2331. switch (sd->sensor) {
  2332. case SENSOR_ADCM1700:
  2333. init = adcm1700_sensor_param1;
  2334. break;
  2335. case SENSOR_GC0307:
  2336. init = gc0307_sensor_param1;
  2337. break;
  2338. case SENSOR_HV7131R:
  2339. case SENSOR_MI0360:
  2340. if (mode)
  2341. reg01 |= SYS_SEL_48M; /* 320x240: clk 48Mhz */
  2342. else
  2343. reg01 &= ~SYS_SEL_48M; /* 640x480: clk 24Mhz */
  2344. reg17 &= ~MCK_SIZE_MASK;
  2345. reg17 |= 0x01; /* clock / 1 */
  2346. break;
  2347. case SENSOR_MI0360B:
  2348. init = mi0360b_sensor_param1;
  2349. break;
  2350. case SENSOR_MO4000:
  2351. if (mode) { /* if 320x240 */
  2352. reg01 &= ~SYS_SEL_48M; /* clk 24Mz */
  2353. reg17 &= ~MCK_SIZE_MASK;
  2354. reg17 |= 0x01; /* clock / 1 */
  2355. }
  2356. break;
  2357. case SENSOR_MT9V111:
  2358. init = mt9v111_sensor_param1;
  2359. break;
  2360. case SENSOR_OM6802:
  2361. init = om6802_sensor_param1;
  2362. if (!mode) { /* if 640x480 */
  2363. reg17 &= ~MCK_SIZE_MASK;
  2364. reg17 |= 0x04; /* clock / 4 */
  2365. } else {
  2366. reg01 &= ~SYS_SEL_48M; /* clk 24Mz */
  2367. reg17 &= ~MCK_SIZE_MASK;
  2368. reg17 |= 0x02; /* clock / 2 */
  2369. }
  2370. break;
  2371. case SENSOR_OV7630:
  2372. init = ov7630_sensor_param1;
  2373. break;
  2374. case SENSOR_OV7648:
  2375. init = ov7648_sensor_param1;
  2376. reg17 &= ~MCK_SIZE_MASK;
  2377. reg17 |= 0x01; /* clock / 1 */
  2378. break;
  2379. case SENSOR_OV7660:
  2380. init = ov7660_sensor_param1;
  2381. break;
  2382. case SENSOR_PO1030:
  2383. init = po1030_sensor_param1;
  2384. break;
  2385. case SENSOR_PO2030N:
  2386. init = po2030n_sensor_param1;
  2387. break;
  2388. case SENSOR_SOI768:
  2389. init = soi768_sensor_param1;
  2390. break;
  2391. case SENSOR_SP80708:
  2392. init = sp80708_sensor_param1;
  2393. break;
  2394. }
  2395. /* more sensor initialization - param1 */
  2396. if (init != NULL) {
  2397. i2c_w_seq(gspca_dev, init);
  2398. /* init = NULL; */
  2399. }
  2400. reg_w(gspca_dev, 0xc0, C0, 6);
  2401. switch (sd->sensor) {
  2402. case SENSOR_ADCM1700:
  2403. case SENSOR_GC0307:
  2404. case SENSOR_SOI768:
  2405. reg_w(gspca_dev, 0xca, CA_adcm1700, 4);
  2406. break;
  2407. case SENSOR_PO2030N:
  2408. reg_w(gspca_dev, 0xca, CA_po2030n, 4);
  2409. break;
  2410. default:
  2411. reg_w(gspca_dev, 0xca, CA, 4);
  2412. break;
  2413. }
  2414. switch (sd->sensor) {
  2415. case SENSOR_ADCM1700:
  2416. case SENSOR_OV7630:
  2417. case SENSOR_OV7648:
  2418. case SENSOR_OV7660:
  2419. case SENSOR_SOI768:
  2420. reg_w(gspca_dev, 0xce, CE_ov76xx, 4);
  2421. break;
  2422. case SENSOR_GC0307:
  2423. reg_w(gspca_dev, 0xce, CE_gc0307, 4);
  2424. break;
  2425. case SENSOR_PO2030N:
  2426. reg_w(gspca_dev, 0xce, CE_po2030n, 4);
  2427. break;
  2428. default:
  2429. reg_w(gspca_dev, 0xce, CE, 4);
  2430. /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */
  2431. break;
  2432. }
  2433. /* here change size mode 0 -> VGA; 1 -> CIF */
  2434. sd->reg18 = sn9c1xx[0x18] | (mode << 4) | 0x40;
  2435. reg_w1(gspca_dev, 0x18, sd->reg18);
  2436. setjpegqual(gspca_dev);
  2437. reg_w1(gspca_dev, 0x17, reg17);
  2438. reg_w1(gspca_dev, 0x01, reg01);
  2439. sd->reg01 = reg01;
  2440. sd->reg17 = reg17;
  2441. sethvflip(gspca_dev);
  2442. setbrightness(gspca_dev);
  2443. setcontrast(gspca_dev);
  2444. setcolors(gspca_dev);
  2445. setautogain(gspca_dev);
  2446. setfreq(gspca_dev);
  2447. sd->pktsz = sd->npkt = 0;
  2448. sd->nchg = sd->short_mark = 0;
  2449. sd->work_thread = create_singlethread_workqueue(MODULE_NAME);
  2450. return gspca_dev->usb_err;
  2451. }
  2452. static void sd_stopN(struct gspca_dev *gspca_dev)
  2453. {
  2454. struct sd *sd = (struct sd *) gspca_dev;
  2455. static const u8 stophv7131[] =
  2456. { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
  2457. static const u8 stopmi0360[] =
  2458. { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
  2459. static const u8 stopov7648[] =
  2460. { 0xa1, 0x21, 0x76, 0x20, 0x00, 0x00, 0x00, 0x10 };
  2461. static const u8 stopsoi768[] =
  2462. { 0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10 };
  2463. u8 reg01;
  2464. u8 reg17;
  2465. reg01 = sd->reg01;
  2466. reg17 = sd->reg17 & ~SEN_CLK_EN;
  2467. switch (sd->sensor) {
  2468. case SENSOR_ADCM1700:
  2469. case SENSOR_GC0307:
  2470. case SENSOR_PO2030N:
  2471. case SENSOR_SP80708:
  2472. reg01 |= LED;
  2473. reg_w1(gspca_dev, 0x01, reg01);
  2474. reg01 &= ~(LED | V_TX_EN);
  2475. reg_w1(gspca_dev, 0x01, reg01);
  2476. /* reg_w1(gspca_dev, 0x02, 0x??); * LED off ? */
  2477. break;
  2478. case SENSOR_HV7131R:
  2479. reg01 &= ~V_TX_EN;
  2480. reg_w1(gspca_dev, 0x01, reg01);
  2481. i2c_w8(gspca_dev, stophv7131);
  2482. break;
  2483. case SENSOR_MI0360:
  2484. case SENSOR_MI0360B:
  2485. reg01 &= ~V_TX_EN;
  2486. reg_w1(gspca_dev, 0x01, reg01);
  2487. /* reg_w1(gspca_dev, 0x02, 0x40); * LED off ? */
  2488. i2c_w8(gspca_dev, stopmi0360);
  2489. break;
  2490. case SENSOR_MT9V111:
  2491. case SENSOR_OM6802:
  2492. case SENSOR_PO1030:
  2493. reg01 &= ~V_TX_EN;
  2494. reg_w1(gspca_dev, 0x01, reg01);
  2495. break;
  2496. case SENSOR_OV7630:
  2497. case SENSOR_OV7648:
  2498. reg01 &= ~V_TX_EN;
  2499. reg_w1(gspca_dev, 0x01, reg01);
  2500. i2c_w8(gspca_dev, stopov7648);
  2501. break;
  2502. case SENSOR_OV7660:
  2503. reg01 &= ~V_TX_EN;
  2504. reg_w1(gspca_dev, 0x01, reg01);
  2505. break;
  2506. case SENSOR_SOI768:
  2507. i2c_w8(gspca_dev, stopsoi768);
  2508. break;
  2509. }
  2510. reg01 |= SCL_SEL_OD;
  2511. reg_w1(gspca_dev, 0x01, reg01);
  2512. reg01 |= S_PWR_DN; /* sensor power down */
  2513. reg_w1(gspca_dev, 0x01, reg01);
  2514. reg_w1(gspca_dev, 0x17, reg17);
  2515. reg01 &= ~SYS_SEL_48M; /* clock 24MHz */
  2516. reg_w1(gspca_dev, 0x01, reg01);
  2517. reg01 |= LED;
  2518. reg_w1(gspca_dev, 0x01, reg01);
  2519. /* Don't disable sensor clock as that disables the button on the cam */
  2520. /* reg_w1(gspca_dev, 0xf1, 0x01); */
  2521. }
  2522. /* called on streamoff with alt==0 and on disconnect */
  2523. /* the usb_lock is held at entry - restore on exit */
  2524. static void sd_stop0(struct gspca_dev *gspca_dev)
  2525. {
  2526. struct sd *sd = (struct sd *) gspca_dev;
  2527. if (sd->work_thread != NULL) {
  2528. mutex_unlock(&gspca_dev->usb_lock);
  2529. destroy_workqueue(sd->work_thread);
  2530. mutex_lock(&gspca_dev->usb_lock);
  2531. sd->work_thread = NULL;
  2532. }
  2533. }
  2534. static void do_autogain(struct gspca_dev *gspca_dev)
  2535. {
  2536. struct sd *sd = (struct sd *) gspca_dev;
  2537. int delta;
  2538. int expotimes;
  2539. u8 luma_mean = 130;
  2540. u8 luma_delta = 20;
  2541. /* Thanks S., without your advice, autobright should not work :) */
  2542. if (sd->ag_cnt < 0)
  2543. return;
  2544. if (--sd->ag_cnt >= 0)
  2545. return;
  2546. sd->ag_cnt = AG_CNT_START;
  2547. delta = atomic_read(&sd->avg_lum);
  2548. PDEBUG(D_FRAM, "mean lum %d", delta);
  2549. if (delta < luma_mean - luma_delta ||
  2550. delta > luma_mean + luma_delta) {
  2551. switch (sd->sensor) {
  2552. case SENSOR_GC0307:
  2553. expotimes = sd->exposure;
  2554. expotimes += (luma_mean - delta) >> 6;
  2555. if (expotimes < 0)
  2556. expotimes = 0;
  2557. sd->exposure = setexposure(gspca_dev,
  2558. (unsigned int) expotimes);
  2559. break;
  2560. case SENSOR_HV7131R:
  2561. expotimes = sd->exposure >> 8;
  2562. expotimes += (luma_mean - delta) >> 4;
  2563. if (expotimes < 0)
  2564. expotimes = 0;
  2565. sd->exposure = setexposure(gspca_dev,
  2566. (unsigned int) (expotimes << 8));
  2567. break;
  2568. case SENSOR_OM6802:
  2569. case SENSOR_MT9V111:
  2570. expotimes = sd->exposure;
  2571. expotimes += (luma_mean - delta) >> 2;
  2572. if (expotimes < 0)
  2573. expotimes = 0;
  2574. sd->exposure = setexposure(gspca_dev,
  2575. (unsigned int) expotimes);
  2576. setredblue(gspca_dev);
  2577. break;
  2578. default:
  2579. /* case SENSOR_MO4000: */
  2580. /* case SENSOR_MI0360: */
  2581. /* case SENSOR_MI0360B: */
  2582. expotimes = sd->exposure;
  2583. expotimes += (luma_mean - delta) >> 6;
  2584. if (expotimes < 0)
  2585. expotimes = 0;
  2586. sd->exposure = setexposure(gspca_dev,
  2587. (unsigned int) expotimes);
  2588. setredblue(gspca_dev);
  2589. break;
  2590. }
  2591. }
  2592. }
  2593. /* set the average luminosity from an isoc marker */
  2594. static void set_lum(struct sd *sd,
  2595. u8 *data)
  2596. {
  2597. int avg_lum;
  2598. /* w0 w1 w2
  2599. * w3 w4 w5
  2600. * w6 w7 w8
  2601. */
  2602. avg_lum = (data[27] << 8) + data[28] /* w3 */
  2603. + (data[31] << 8) + data[32] /* w5 */
  2604. + (data[23] << 8) + data[24] /* w1 */
  2605. + (data[35] << 8) + data[36] /* w7 */
  2606. + (data[29] << 10) + (data[30] << 2); /* w4 * 4 */
  2607. avg_lum >>= 10;
  2608. atomic_set(&sd->avg_lum, avg_lum);
  2609. }
  2610. /* scan the URB packets */
  2611. /* This function is run at interrupt level. */
  2612. static void sd_pkt_scan(struct gspca_dev *gspca_dev,
  2613. u8 *data, /* isoc packet */
  2614. int len) /* iso packet length */
  2615. {
  2616. struct sd *sd = (struct sd *) gspca_dev;
  2617. int i, new_qual;
  2618. /*
  2619. * A frame ends on the marker
  2620. * ff ff 00 c4 c4 96 ..
  2621. * which is 62 bytes long and is followed by various information
  2622. * including statuses and luminosity.
  2623. *
  2624. * A marker may be splitted on two packets.
  2625. *
  2626. * The 6th byte of a marker contains the bits:
  2627. * 0x08: USB full
  2628. * 0xc0: frame sequence
  2629. * When the bit 'USB full' is set, the frame must be discarded;
  2630. * this is also the case when the 2 bytes before the marker are
  2631. * not the JPEG end of frame ('ff d9').
  2632. */
  2633. /*fixme: assumption about the following code:
  2634. * - there can be only one marker in a packet
  2635. */
  2636. /* skip the remaining bytes of a short marker */
  2637. i = sd->short_mark;
  2638. if (i != 0) {
  2639. sd->short_mark = 0;
  2640. if (i < 0 /* if 'ff' at end of previous packet */
  2641. && data[0] == 0xff
  2642. && data[1] == 0x00)
  2643. goto marker_found;
  2644. if (data[0] == 0xff && data[1] == 0xff) {
  2645. i = 0;
  2646. goto marker_found;
  2647. }
  2648. len -= i;
  2649. if (len <= 0)
  2650. return;
  2651. data += i;
  2652. }
  2653. /* count the packets and their size */
  2654. sd->npkt++;
  2655. sd->pktsz += len;
  2656. /* search backwards if there is a marker in the packet */
  2657. for (i = len - 1; --i >= 0; ) {
  2658. if (data[i] != 0xff) {
  2659. i--;
  2660. continue;
  2661. }
  2662. if (data[i + 1] == 0xff) {
  2663. /* (there may be 'ff ff' inside a marker) */
  2664. if (i + 2 >= len || data[i + 2] == 0x00)
  2665. goto marker_found;
  2666. }
  2667. }
  2668. /* no marker found */
  2669. /* add the JPEG header if first fragment */
  2670. if (data[len - 1] == 0xff)
  2671. sd->short_mark = -1;
  2672. if (gspca_dev->last_packet_type == LAST_PACKET)
  2673. gspca_frame_add(gspca_dev, FIRST_PACKET,
  2674. sd->jpeg_hdr, JPEG_HDR_SZ);
  2675. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  2676. return;
  2677. /* marker found */
  2678. /* if some error, discard the frame and decrease the quality */
  2679. marker_found:
  2680. new_qual = 0;
  2681. if (i > 2) {
  2682. if (data[i - 2] != 0xff || data[i - 1] != 0xd9) {
  2683. gspca_dev->last_packet_type = DISCARD_PACKET;
  2684. new_qual = -3;
  2685. }
  2686. } else if (i + 6 < len) {
  2687. if (data[i + 6] & 0x08) {
  2688. gspca_dev->last_packet_type = DISCARD_PACKET;
  2689. new_qual = -5;
  2690. }
  2691. }
  2692. gspca_frame_add(gspca_dev, LAST_PACKET, data, i);
  2693. /* compute the filling rate and a new JPEG quality */
  2694. if (new_qual == 0) {
  2695. int r;
  2696. r = (sd->pktsz * 100) /
  2697. (sd->npkt *
  2698. gspca_dev->urb[0]->iso_frame_desc[0].length);
  2699. if (r >= 85)
  2700. new_qual = -3;
  2701. else if (r < 75)
  2702. new_qual = 2;
  2703. }
  2704. if (new_qual != 0) {
  2705. sd->nchg += new_qual;
  2706. if (sd->nchg < -6 || sd->nchg >= 12) {
  2707. sd->nchg = 0;
  2708. new_qual += sd->quality;
  2709. if (new_qual < QUALITY_MIN)
  2710. new_qual = QUALITY_MIN;
  2711. else if (new_qual > QUALITY_MAX)
  2712. new_qual = QUALITY_MAX;
  2713. if (new_qual != sd->quality) {
  2714. sd->quality = new_qual;
  2715. queue_work(sd->work_thread, &sd->work);
  2716. }
  2717. }
  2718. } else {
  2719. sd->nchg = 0;
  2720. }
  2721. sd->pktsz = sd->npkt = 0;
  2722. /* if the marker is smaller than 62 bytes,
  2723. * memorize the number of bytes to skip in the next packet */
  2724. if (i + 62 > len) { /* no more usable data */
  2725. sd->short_mark = i + 62 - len;
  2726. return;
  2727. }
  2728. if (sd->ag_cnt >= 0)
  2729. set_lum(sd, data + i);
  2730. /* if more data, start a new frame */
  2731. i += 62;
  2732. if (i < len) {
  2733. data += i;
  2734. len -= i;
  2735. gspca_frame_add(gspca_dev, FIRST_PACKET,
  2736. sd->jpeg_hdr, JPEG_HDR_SZ);
  2737. gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
  2738. }
  2739. }
  2740. static int sd_get_jcomp(struct gspca_dev *gspca_dev,
  2741. struct v4l2_jpegcompression *jcomp)
  2742. {
  2743. struct sd *sd = (struct sd *) gspca_dev;
  2744. memset(jcomp, 0, sizeof *jcomp);
  2745. jcomp->quality = sd->quality;
  2746. jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
  2747. | V4L2_JPEG_MARKER_DQT;
  2748. return 0;
  2749. }
  2750. static int sd_querymenu(struct gspca_dev *gspca_dev,
  2751. struct v4l2_querymenu *menu)
  2752. {
  2753. switch (menu->id) {
  2754. case V4L2_CID_POWER_LINE_FREQUENCY:
  2755. switch (menu->index) {
  2756. case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
  2757. strcpy((char *) menu->name, "NoFliker");
  2758. return 0;
  2759. case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
  2760. strcpy((char *) menu->name, "50 Hz");
  2761. return 0;
  2762. case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
  2763. strcpy((char *) menu->name, "60 Hz");
  2764. return 0;
  2765. }
  2766. break;
  2767. }
  2768. return -EINVAL;
  2769. }
  2770. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  2771. static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
  2772. u8 *data, /* interrupt packet data */
  2773. int len) /* interrupt packet length */
  2774. {
  2775. int ret = -EINVAL;
  2776. if (len == 1 && data[0] == 1) {
  2777. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
  2778. input_sync(gspca_dev->input_dev);
  2779. input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
  2780. input_sync(gspca_dev->input_dev);
  2781. ret = 0;
  2782. }
  2783. return ret;
  2784. }
  2785. #endif
  2786. /* sub-driver description */
  2787. static const struct sd_desc sd_desc = {
  2788. .name = MODULE_NAME,
  2789. .ctrls = sd_ctrls,
  2790. .nctrls = NCTRLS,
  2791. .config = sd_config,
  2792. .init = sd_init,
  2793. .start = sd_start,
  2794. .stopN = sd_stopN,
  2795. .stop0 = sd_stop0,
  2796. .pkt_scan = sd_pkt_scan,
  2797. .dq_callback = do_autogain,
  2798. .get_jcomp = sd_get_jcomp,
  2799. .querymenu = sd_querymenu,
  2800. #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
  2801. .int_pkt_scan = sd_int_pkt_scan,
  2802. #endif
  2803. };
  2804. /* -- module initialisation -- */
  2805. #define BS(bridge, sensor) \
  2806. .driver_info = (BRIDGE_ ## bridge << 16) \
  2807. | (SENSOR_ ## sensor << 8)
  2808. #define BSF(bridge, sensor, flags) \
  2809. .driver_info = (BRIDGE_ ## bridge << 16) \
  2810. | (SENSOR_ ## sensor << 8) \
  2811. | (flags)
  2812. static const struct usb_device_id device_table[] = {
  2813. {USB_DEVICE(0x0458, 0x7025), BS(SN9C120, MI0360)},
  2814. {USB_DEVICE(0x0458, 0x702e), BS(SN9C120, OV7660)},
  2815. {USB_DEVICE(0x045e, 0x00f5), BSF(SN9C105, OV7660, F_PDN_INV)},
  2816. {USB_DEVICE(0x045e, 0x00f7), BSF(SN9C105, OV7660, F_PDN_INV)},
  2817. {USB_DEVICE(0x0471, 0x0327), BS(SN9C105, MI0360)},
  2818. {USB_DEVICE(0x0471, 0x0328), BS(SN9C105, MI0360)},
  2819. {USB_DEVICE(0x0471, 0x0330), BS(SN9C105, MI0360)},
  2820. {USB_DEVICE(0x06f8, 0x3004), BS(SN9C105, OV7660)},
  2821. {USB_DEVICE(0x06f8, 0x3008), BS(SN9C105, OV7660)},
  2822. /* {USB_DEVICE(0x0c45, 0x603a), BS(SN9C102P, OV7648)}, */
  2823. {USB_DEVICE(0x0c45, 0x6040), BS(SN9C102P, HV7131R)},
  2824. /* {USB_DEVICE(0x0c45, 0x607a), BS(SN9C102P, OV7648)}, */
  2825. /* {USB_DEVICE(0x0c45, 0x607b), BS(SN9C102P, OV7660)}, */
  2826. {USB_DEVICE(0x0c45, 0x607c), BS(SN9C102P, HV7131R)},
  2827. /* {USB_DEVICE(0x0c45, 0x607e), BS(SN9C102P, OV7630)}, */
  2828. {USB_DEVICE(0x0c45, 0x60c0), BSF(SN9C105, MI0360, F_ILLUM)},
  2829. /* or MT9V111 */
  2830. /* {USB_DEVICE(0x0c45, 0x60c2), BS(SN9C105, P1030xC)}, */
  2831. /* {USB_DEVICE(0x0c45, 0x60c8), BS(SN9C105, OM6802)}, */
  2832. /* {USB_DEVICE(0x0c45, 0x60cc), BS(SN9C105, HV7131GP)}, */
  2833. {USB_DEVICE(0x0c45, 0x60ce), BS(SN9C105, SP80708)},
  2834. {USB_DEVICE(0x0c45, 0x60ec), BS(SN9C105, MO4000)},
  2835. /* {USB_DEVICE(0x0c45, 0x60ef), BS(SN9C105, ICM105C)}, */
  2836. /* {USB_DEVICE(0x0c45, 0x60fa), BS(SN9C105, OV7648)}, */
  2837. /* {USB_DEVICE(0x0c45, 0x60f2), BS(SN9C105, OV7660)}, */
  2838. {USB_DEVICE(0x0c45, 0x60fb), BS(SN9C105, OV7660)},
  2839. {USB_DEVICE(0x0c45, 0x60fc), BS(SN9C105, HV7131R)},
  2840. {USB_DEVICE(0x0c45, 0x60fe), BS(SN9C105, OV7630)},
  2841. {USB_DEVICE(0x0c45, 0x6100), BS(SN9C120, MI0360)}, /*sn9c128*/
  2842. {USB_DEVICE(0x0c45, 0x6102), BS(SN9C120, PO2030N)}, /* /GC0305*/
  2843. /* {USB_DEVICE(0x0c45, 0x6108), BS(SN9C120, OM6802)}, */
  2844. {USB_DEVICE(0x0c45, 0x610a), BS(SN9C120, OV7648)}, /*sn9c128*/
  2845. {USB_DEVICE(0x0c45, 0x610b), BS(SN9C120, OV7660)}, /*sn9c128*/
  2846. {USB_DEVICE(0x0c45, 0x610c), BS(SN9C120, HV7131R)}, /*sn9c128*/
  2847. {USB_DEVICE(0x0c45, 0x610e), BS(SN9C120, OV7630)}, /*sn9c128*/
  2848. /* {USB_DEVICE(0x0c45, 0x610f), BS(SN9C120, S5K53BEB)}, */
  2849. /* {USB_DEVICE(0x0c45, 0x6122), BS(SN9C110, ICM105C)}, */
  2850. /* {USB_DEVICE(0x0c45, 0x6123), BS(SN9C110, SanyoCCD)}, */
  2851. {USB_DEVICE(0x0c45, 0x6128), BS(SN9C120, OM6802)}, /*sn9c325?*/
  2852. /*bw600.inf:*/
  2853. {USB_DEVICE(0x0c45, 0x612a), BS(SN9C120, OV7648)}, /*sn9c325?*/
  2854. {USB_DEVICE(0x0c45, 0x612b), BS(SN9C110, ADCM1700)},
  2855. {USB_DEVICE(0x0c45, 0x612c), BS(SN9C110, MO4000)},
  2856. {USB_DEVICE(0x0c45, 0x612e), BS(SN9C110, OV7630)},
  2857. /* {USB_DEVICE(0x0c45, 0x612f), BS(SN9C110, ICM105C)}, */
  2858. {USB_DEVICE(0x0c45, 0x6130), BS(SN9C120, MI0360)},
  2859. /* or MT9V111 / MI0360B */
  2860. /* {USB_DEVICE(0x0c45, 0x6132), BS(SN9C120, OV7670)}, */
  2861. {USB_DEVICE(0x0c45, 0x6138), BS(SN9C120, MO4000)},
  2862. {USB_DEVICE(0x0c45, 0x613a), BS(SN9C120, OV7648)},
  2863. {USB_DEVICE(0x0c45, 0x613b), BS(SN9C120, OV7660)},
  2864. {USB_DEVICE(0x0c45, 0x613c), BS(SN9C120, HV7131R)},
  2865. {USB_DEVICE(0x0c45, 0x613e), BS(SN9C120, OV7630)},
  2866. {USB_DEVICE(0x0c45, 0x6142), BS(SN9C120, PO2030N)}, /*sn9c120b*/
  2867. /* or GC0305 / GC0307 */
  2868. {USB_DEVICE(0x0c45, 0x6143), BS(SN9C120, SP80708)}, /*sn9c120b*/
  2869. {USB_DEVICE(0x0c45, 0x6148), BS(SN9C120, OM6802)}, /*sn9c120b*/
  2870. {USB_DEVICE(0x0c45, 0x614a), BSF(SN9C120, ADCM1700, F_ILLUM)},
  2871. /* {USB_DEVICE(0x0c45, 0x614c), BS(SN9C120, GC0306)}, */ /*sn9c120b*/
  2872. {}
  2873. };
  2874. MODULE_DEVICE_TABLE(usb, device_table);
  2875. /* -- device connect -- */
  2876. static int sd_probe(struct usb_interface *intf,
  2877. const struct usb_device_id *id)
  2878. {
  2879. return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
  2880. THIS_MODULE);
  2881. }
  2882. static struct usb_driver sd_driver = {
  2883. .name = MODULE_NAME,
  2884. .id_table = device_table,
  2885. .probe = sd_probe,
  2886. .disconnect = gspca_disconnect,
  2887. #ifdef CONFIG_PM
  2888. .suspend = gspca_suspend,
  2889. .resume = gspca_resume,
  2890. #endif
  2891. };
  2892. /* -- module insert / remove -- */
  2893. static int __init sd_mod_init(void)
  2894. {
  2895. return usb_register(&sd_driver);
  2896. }
  2897. static void __exit sd_mod_exit(void)
  2898. {
  2899. usb_deregister(&sd_driver);
  2900. }
  2901. module_init(sd_mod_init);
  2902. module_exit(sd_mod_exit);