sonixj.c 93 KB

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