sonixj.c 93 KB

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