gc2015.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813
  1. /*
  2. *gc2015 - This code emulates a real video device with v4l2 api
  3. *
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the BSD Licence, GNU General Public License
  7. * as published by the Free Software Foundation; either version 2 of the
  8. * License, or (at your option) any later version
  9. */
  10. #include <linux/module.h>
  11. #include <linux/delay.h>
  12. #include <linux/errno.h>
  13. #include <linux/fs.h>
  14. #include <linux/kernel.h>
  15. #include <linux/wait.h>
  16. #include <linux/slab.h>
  17. #include <linux/mm.h>
  18. #include <linux/ioport.h>
  19. #include <linux/init.h>
  20. #include <linux/sched.h>
  21. #include <linux/pci.h>
  22. #include <linux/random.h>
  23. #include <linux/version.h>
  24. #include <linux/mutex.h>
  25. #include <linux/videodev2.h>
  26. #include <linux/dma-mapping.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/kthread.h>
  29. #include <linux/highmem.h>
  30. #include <linux/freezer.h>
  31. #include <media/videobuf-vmalloc.h>
  32. #include <media/v4l2-device.h>
  33. #include <media/v4l2-ioctl.h>
  34. #include <linux/i2c.h>
  35. #include <media/v4l2-chip-ident.h>
  36. #include <media/v4l2-i2c-drv.h>
  37. #include <media/amlogic/aml_camera.h>
  38. #include <mach/am_regs.h>
  39. #include <mach/pinmux.h>
  40. #include <media/amlogic/656in.h>
  41. #include "common/plat_ctrl.h"
  42. #include "common/vmapi.h"
  43. #ifdef CONFIG_ARCH_MESON6
  44. #include <mach/mod_gate.h>
  45. #endif
  46. #ifdef CONFIG_HAS_EARLYSUSPEND
  47. #include <linux/earlysuspend.h>
  48. static struct early_suspend gc2015_early_suspend;
  49. #endif
  50. #define gc2015_CAMERA_MODULE_NAME "gc2015"
  51. #ifdef CONFIG_VIDEO_AMLOGIC_FLASHLIGHT
  52. #include <media/amlogic/flashlight.h>
  53. extern aml_plat_flashlight_status_t get_flashlightflag(void);
  54. extern int set_flashlight(bool mode);
  55. #endif
  56. /* Wake up at about 30 fps */
  57. #define WAKE_NUMERATOR 30
  58. #define WAKE_DENOMINATOR 1001
  59. #define BUFFER_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */
  60. #define gc2015_CAMERA_MAJOR_VERSION 0
  61. #define gc2015_CAMERA_MINOR_VERSION 7
  62. #define gc2015_CAMERA_RELEASE 0
  63. #define gc2015_CAMERA_VERSION \
  64. KERNEL_VERSION(gc2015_CAMERA_MAJOR_VERSION, gc2015_CAMERA_MINOR_VERSION, gc2015_CAMERA_RELEASE)
  65. MODULE_DESCRIPTION("gc2015 On Board");
  66. MODULE_AUTHOR("amlogic-sh");
  67. MODULE_LICENSE("GPL v2");
  68. static unsigned video_nr = -1; /* videoX start number, -1 is autodetect. */
  69. static unsigned debug;
  70. //module_param(debug, uint, 0644);
  71. //MODULE_PARM_DESC(debug, "activates debug info");
  72. static unsigned int vid_limit = 16;
  73. //module_param(vid_limit, uint, 0644);
  74. //MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
  75. static int vidio_set_fmt_ticks=0;
  76. extern int disable_gt2005;
  77. static int gc2015_h_active=800;
  78. static int gc2015_v_active=600;
  79. /* supported controls */
  80. static struct v4l2_queryctrl gc2015_qctrl[] = {
  81. {
  82. .id = V4L2_CID_DO_WHITE_BALANCE,
  83. .type = V4L2_CTRL_TYPE_INTEGER,
  84. .name = "white balance",
  85. .minimum = 0,
  86. .maximum = 6,
  87. .step = 0x1,
  88. .default_value = 0,
  89. .flags = V4L2_CTRL_FLAG_SLIDER,
  90. },{
  91. .id = V4L2_CID_EXPOSURE,
  92. .type = V4L2_CTRL_TYPE_INTEGER,
  93. .name = "exposure",
  94. .minimum = 0,
  95. .maximum = 8,
  96. .step = 0x1,
  97. .default_value = 4,
  98. .flags = V4L2_CTRL_FLAG_SLIDER,
  99. },{
  100. .id = V4L2_CID_COLORFX,
  101. .type = V4L2_CTRL_TYPE_INTEGER,
  102. .name = "effect",
  103. .minimum = 0,
  104. .maximum = 6,
  105. .step = 0x1,
  106. .default_value = 0,
  107. .flags = V4L2_CTRL_FLAG_SLIDER,
  108. },{
  109. .id = V4L2_CID_WHITENESS,
  110. .type = V4L2_CTRL_TYPE_INTEGER,
  111. .name = "banding",
  112. .minimum = 0,
  113. .maximum = 1,
  114. .step = 0x1,
  115. .default_value = 0,
  116. .flags = V4L2_CTRL_FLAG_SLIDER,
  117. },{
  118. .id = V4L2_CID_BLUE_BALANCE,
  119. .type = V4L2_CTRL_TYPE_INTEGER,
  120. .name = "scene mode",
  121. .minimum = 0,
  122. .maximum = 1,
  123. .step = 0x1,
  124. .default_value = 0,
  125. .flags = V4L2_CTRL_FLAG_SLIDER,
  126. }
  127. };
  128. #define dprintk(dev, level, fmt, arg...) \
  129. v4l2_dbg(level, debug, &dev->v4l2_dev, fmt, ## arg)
  130. /* ------------------------------------------------------------------
  131. Basic structures
  132. ------------------------------------------------------------------*/
  133. struct gc2015_fmt {
  134. char *name;
  135. u32 fourcc; /* v4l2 format id */
  136. int depth;
  137. };
  138. static struct gc2015_fmt formats[] = {
  139. {
  140. .name = "RGB565 (BE)",
  141. .fourcc = V4L2_PIX_FMT_RGB565X, /* rrrrrggg gggbbbbb */
  142. .depth = 16,
  143. },
  144. {
  145. .name = "RGB888 (24)",
  146. .fourcc = V4L2_PIX_FMT_RGB24, /* 24 RGB-8-8-8 */
  147. .depth = 24,
  148. },
  149. {
  150. .name = "BGR888 (24)",
  151. .fourcc = V4L2_PIX_FMT_BGR24, /* 24 BGR-8-8-8 */
  152. .depth = 24,
  153. },
  154. {
  155. .name = "12 Y/CbCr 4:2:0",
  156. .fourcc = V4L2_PIX_FMT_NV12,
  157. .depth = 12,
  158. },
  159. {
  160. .name = "12 Y/CbCr 4:2:0",
  161. .fourcc = V4L2_PIX_FMT_NV21,
  162. .depth = 12,
  163. },
  164. {
  165. .name = "YUV420P",
  166. .fourcc = V4L2_PIX_FMT_YUV420,
  167. .depth = 12,
  168. }
  169. };
  170. static struct gc2015_fmt *get_format(struct v4l2_format *f)
  171. {
  172. struct gc2015_fmt *fmt;
  173. unsigned int k;
  174. for (k = 0; k < ARRAY_SIZE(formats); k++) {
  175. fmt = &formats[k];
  176. if (fmt->fourcc == f->fmt.pix.pixelformat)
  177. break;
  178. }
  179. if (k == ARRAY_SIZE(formats))
  180. return NULL;
  181. return &formats[k];
  182. }
  183. struct sg_to_addr {
  184. int pos;
  185. struct scatterlist *sg;
  186. };
  187. /* buffer for one video frame */
  188. struct gc2015_buffer {
  189. /* common v4l buffer stuff -- must be first */
  190. struct videobuf_buffer vb;
  191. struct gc2015_fmt *fmt;
  192. };
  193. struct gc2015_dmaqueue {
  194. struct list_head active;
  195. /* thread for generating video stream*/
  196. struct task_struct *kthread;
  197. wait_queue_head_t wq;
  198. /* Counters to control fps rate */
  199. int frame;
  200. int ini_jiffies;
  201. };
  202. static LIST_HEAD(gc2015_devicelist);
  203. struct gc2015_device {
  204. struct list_head gc2015_devicelist;
  205. struct v4l2_subdev sd;
  206. struct v4l2_device v4l2_dev;
  207. spinlock_t slock;
  208. struct mutex mutex;
  209. int users;
  210. /* various device info */
  211. struct video_device *vdev;
  212. struct gc2015_dmaqueue vidq;
  213. /* Several counters */
  214. unsigned long jiffies;
  215. /* Input Number */
  216. int input;
  217. /* platform device data from board initting. */
  218. aml_plat_cam_data_t platform_dev_data;
  219. /* Control 'registers' */
  220. int qctl_regs[ARRAY_SIZE(gc2015_qctrl)];
  221. };
  222. static inline struct gc2015_device *to_dev(struct v4l2_subdev *sd)
  223. {
  224. return container_of(sd, struct gc2015_device, sd);
  225. }
  226. struct gc2015_fh {
  227. struct gc2015_device *dev;
  228. /* video capture */
  229. struct gc2015_fmt *fmt;
  230. unsigned int width, height;
  231. struct videobuf_queue vb_vidq;
  232. enum v4l2_buf_type type;
  233. int input; /* Input Number on bars */
  234. int stream_on;
  235. };
  236. static inline struct gc2015_fh *to_fh(struct gc2015_device *dev)
  237. {
  238. return container_of(dev, struct gc2015_fh, dev);
  239. }
  240. static struct v4l2_frmsize_discrete gc2015_prev_resolution[2]= //should include 352x288 and 640x480, those two size are used for recording
  241. {
  242. {352,288},
  243. {640,480},
  244. };
  245. static struct v4l2_frmsize_discrete gc2015_pic_resolution[2]=
  246. {
  247. {1600,1200},
  248. {800,600}
  249. };
  250. /* ------------------------------------------------------------------
  251. reg spec of gc2015
  252. ------------------------------------------------------------------*/
  253. struct aml_camera_i2c_fig_s gc2015_script[] = {
  254. {0xfe,0x80}, //soft reset
  255. {0xfe,0x80}, //soft reset
  256. {0xfe,0x80}, //soft reset
  257. {0xfe,0x00}, //page0
  258. {0x45,0x00}, //output_disable
  259. //////////////////////////////////////////////////////////////////////////////////////
  260. //////////////////////////preview capture switch /////////////////////////////////////
  261. //////////////////////////////////////////////////////////////////////////////////////
  262. //preview
  263. {0x02,0x01}, //preview mode
  264. {0x2a,0xca}, //[7]col_binning,0x[6]even skip
  265. {0x48,0x58}, //manual_gain
  266. {0x09, 0x00}, //
  267. {0x0a, 0x01}, //row start
  268. {0x0d, 0x04}, //
  269. {0x0e, 0xd0}, //Preview Window height
  270. ////////////////////////////////////////////////////////////////////////
  271. ////////////////////////// preview LSC /////////////////////////////////
  272. ////////////////////////////////////////////////////////////////////////
  273. #if 0
  274. {0xfe,0x01}, //page1
  275. {0xb0,0x03}, //[4]Y_LSC_en [3]lsc_compensate [2]signed_b4 [1:0]pixel array select
  276. {0xb1,0x23}, //P_LSC_red_b2
  277. {0xb2,0x20}, //P_LSC_green_b2
  278. {0xb3,0x20}, //P_LSC_blue_b2
  279. {0xb4,0x24}, //P_LSC_red_b4
  280. {0xb5,0x20}, //P_LSC_green_b4
  281. {0xb6,0x22}, //P_LSC_blue_b4
  282. {0xb7,0x00}, //P_LSC_compensate_b2
  283. {0xb8,0x80}, //P_LSC_row_center,0x344,0x (1200/2-344)/2=128,0x,0x
  284. {0xb9,0x80}, //P_LSC_col_center,0x544,0x (1600/2-544)/2=128
  285. ////////////////////////////////////////////////////////////////////////
  286. ////////////////////////// capture LSC /////////////////////////////////
  287. ////////////////////////////////////////////////////////////////////////
  288. {0xba,0x03}, //[4]Y_LSC_en [3]lsc_compensate [2]signed_b4 [1:0]pixel array select
  289. {0xbb,0x23}, //C_LSC_red_b2
  290. {0xbc,0x20}, //C_LSC_green_b2
  291. {0xbd,0x20}, //C_LSC_blue_b2
  292. {0xbe,0x24}, //C_LSC_red_b4
  293. {0xbf,0x20}, //C_LSC_green_b4
  294. {0xc0,0x22}, //C_LSC_blue_b4
  295. {0xc1,0x00}, //C_Lsc_compensate_b2
  296. {0xc2,0x80}, //C_LSC_row_center,0x344,0x (1200/2-344)/2=128
  297. {0xc3,0x80}, //C_LSC_col_center,0x544,0x (1600/2-544)/2=128
  298. {0xfe,0x00}, //page0
  299. #endif
  300. {0xfe,0x01}, //page1
  301. {0xb0,0x03}, //[4]Y_LSC_en [3]lsc_compensate [2]signed_b4 [1:0]pixel array select
  302. {0xb1,0x3e}, //P_LSC_red_b2
  303. {0xb2,0x3a}, //P_LSC_green_b2
  304. {0xb3,0x3a}, //P_LSC_blue_b2
  305. {0xb4,0x20}, //P_LSC_red_b4
  306. {0xb5,0x20}, //P_LSC_green_b4
  307. {0xb6,0x20}, //P_LSC_blue_b4
  308. {0xb7,0x00}, //P_LSC_compensate_b2
  309. {0xb8,0x80}, //P_LSC_row_center 344 (600/2-100)/2=100
  310. {0xb9,0x60}, //P_LSC_col_center 544 (800/2-200)/2=100
  311. {0xba,0x03}, //[4]Y_LSC_en [3]lsc_compensate [2]signed_b4 [1:0]pixel array select
  312. {0xbb,0x3e}, //C_LSC_red_b2 // 20
  313. {0xbc,0x3a}, //C_LSC_green_b2 // 20
  314. {0xbd,0x3a}, //C_LSC_blue_b2 // 20
  315. {0xbe,0x20}, //C_LSC_red_b4
  316. {0xbf,0x20}, //C_LSC_green_b4
  317. {0xc0,0x20}, //C_LSC_blue_b4
  318. {0xc1,0x00}, //C_Lsc_compensate_b2
  319. {0xc2,0x80}, //C_LSC_row_center 344 (0x1200/2-344)/2=128
  320. {0xc3,0x60}, //C_LSC_col_center 544 (0x1600/2-544)/2=128
  321. {0xfe,0x60}, //page0
  322. ////////////////////////////////////////////////////////////////////////
  323. ////////////////////////// analog configure ///////////////////////////
  324. ////////////////////////////////////////////////////////////////////////
  325. {0xfe,0x00}, //page0
  326. {0x29,0x00}, //cisctl mode 1,orientation mirror.
  327. {0x2b,0x06}, //cisctl mode 3
  328. {0x32,0x1c}, //analog mode 1
  329. {0x33,0x0f}, //analog mode 2
  330. {0x34,0x30}, //[6:4]da_rsg
  331. {0x35,0x88}, //Vref_A25
  332. {0x37,0x13}, //0x16 Drive Current
  333. /////////////////////////////////////////////////////////////////////
  334. /////////////////////////// ISP Related /////////////////////////////
  335. /////////////////////////////////////////////////////////////////////
  336. {0x40,0xff},
  337. {0x41,0x20}, //[5]skin_detectionenable[2]auto_gray,0x[1]y_gamma
  338. {0x42,0xf6}, //[7]auto_sa[6]auto_ee[5]auto_dndd[4]auto_lsc[3]na[2]abs,0x[1]awb
  339. {0x4b,0xe8}, //[1]AWB_gain_mode,0x1:atpregain0:atpostgain
  340. {0x4d,0x03}, //[1]inbf_en
  341. {0x4f,0x01}, //AEC enable
  342. ////////////////////////////////////////////////////////////////////
  343. /////////////////////////// BLK //////////////////////////////////
  344. ////////////////////////////////////////////////////////////////////
  345. {0x63,0x77}, //BLK mode 1
  346. {0x66,0x00}, //BLK global offset
  347. {0x6d,0x00},
  348. {0x6e,0x1a}, //BLK offset submode},offset R
  349. {0x6f,0x20},
  350. {0x70,0x1a},
  351. {0x71,0x20},
  352. {0x73,0x00},
  353. {0x77,0x80}, //0x80 r gain
  354. {0x78,0x80},// 0x80 g gain
  355. {0x79,0x90},//0x90 b gain
  356. ////////////////////////////////////////////////////////////////////
  357. /////////////////////////// DNDD ///////////////////////////////////
  358. ////////////////////////////////////////////////////////////////////
  359. {0x80,0x07}, //[7]dn_inc_or_dec [4]zero_weight_mode[3]share [2]c_weight_adap [1]dn_lsc_mode [0]dn_b
  360. {0x82,0x0c}, //DN lilat b base
  361. {0x83,0x03},
  362. {0x7d,0x80},//0x80 r _ratio
  363. {0x7e,0x80},//0x80 g_ratio
  364. {0x7f,0x80},//0x80 b_ratio
  365. ////////////////////////////////////////////////////////////////////
  366. /////////////////////////// EEINTP ////////////////////////////////
  367. ////////////////////////////////////////////////////////////////////
  368. {0x8a,0x7c},
  369. {0x8c,0x02},
  370. {0x8e,0x02},
  371. {0x8f,0x45},
  372. /////////////////////////////////////////////////////////////////////
  373. /////////////////////////// CC_t ////////////////////////////////////
  374. /////////////////////////////////////////////////////////////////////
  375. #if 0
  376. {0xb0,0x48}, //0x48 r
  377. {0xb1,0x02},//0xfe
  378. {0xb2,0x00},
  379. {0xb3,0xf4},//0xf0
  380. {0xb4,0x54}, //0x50 g
  381. {0xb5,0xf8},
  382. {0xb6,0x00}, // r offset
  383. {0xb7,0x00}, // g offset
  384. {0xb8,0x00}, // b offset
  385. #endif
  386. {0xb0,0x40},
  387. {0xb1,0xfe}, // 00
  388. {0xb2,0x00}, // 04
  389. {0xb3,0xf8},
  390. {0xb4,0x48},
  391. {0xb5,0xf8},
  392. {0xb6,0x00},
  393. {0xb7,0x04},
  394. {0xb8,0x00},
  395. /////////////////////////////////////////////////////////////////////
  396. /////////////////////////// GAMMA ///////////////////////////////////
  397. /////////////////////////////////////////////////////////////////////
  398. //RGB_GAMMA
  399. /***********************
  400. {0xbf,0x08},
  401. {0xc0,0x1e},
  402. {0xc1,0x33},
  403. {0xc2,0x47},
  404. {0xc3,0x59},
  405. {0xc4,0x68},
  406. {0xc5,0x74},
  407. {0xc6,0x86},
  408. {0xc7,0x97},
  409. {0xc8,0xA5},
  410. {0xc9,0xB1},
  411. {0xca,0xBd},
  412. {0xcb,0xC8},
  413. {0xcc,0xD3},
  414. {0xcd,0xE4},
  415. {0xce,0xF4},
  416. {0xcf,0xff},
  417. {0xbF,0x0B}, //case Gamma_dm_3:
  418. {0xc0,0x16},
  419. {0xc1,0x29},
  420. {0xc2,0x3C},
  421. {0xc3,0x4F},
  422. {0xc4,0x5F},
  423. {0xc5,0x6F},
  424. {0xc6,0x8A},
  425. {0xc7,0x9F},
  426. {0xc8,0xB4},
  427. {0xc9,0xC6},
  428. {0xcA,0xD3},
  429. {0xcB,0xDD},
  430. {0xcC,0xE5},
  431. {0xcD,0xF1},
  432. {0xcE,0xFA},
  433. {0xcF,0xFF},
  434. ********************/
  435. {0xbf, 0x04}, //gamma dm 8
  436. {0xc0, 0x19},
  437. {0xc1, 0x2e},
  438. {0xc2, 0x40},
  439. {0xc3, 0x54},
  440. {0xc4, 0x64},
  441. {0xc5, 0x6e},
  442. {0xc6, 0x7f},
  443. {0xc7, 0x8e},
  444. {0xc8, 0x9c},
  445. {0xc9, 0xa8},
  446. {0xca, 0xb4},
  447. {0xcb, 0xbf},
  448. {0xcc, 0xc9},
  449. {0xcd, 0xdd},
  450. {0xce, 0xee},
  451. {0xcf, 0xff},
  452. //////gamma//////
  453. /////////////////////////////////////////////////////////////////////
  454. /////////////////////////// YCP_t ///////////////////////////////////
  455. /////////////////////////////////////////////////////////////////////
  456. {0xd1,0x44}, //saturation 0x38
  457. {0xd2,0x44}, //saturation
  458. {0xdd,0x38}, //edge_dec
  459. {0xd3,0x47},// 0x40 contrast
  460. {0xde,0x21}, //auto_gray
  461. ////////////////////////////////////////////////////////////////////
  462. /////////////////////////// ASDE ///////////////////////////////////
  463. ////////////////////////////////////////////////////////////////////
  464. {0x98,0x3a},
  465. {0x99,0x60},
  466. {0x9b,0x00},
  467. {0x9f,0x12},
  468. {0xa1,0x80},
  469. {0xa2,0x21},
  470. {0xfe,0x01}, //page1
  471. {0xc5,0x10},
  472. {0xc6,0xff},
  473. {0xc7,0xff},
  474. {0xc8,0xff},
  475. #if 0 // 2015 A
  476. ////////////////////////////////////////////////////////////////////
  477. /////////////////////////// AEC ////////////////////////////////////
  478. ////////////////////////////////////////////////////////////////////
  479. {0x10,0x09}, //AEC mode 1
  480. {0x11,0xb2}, //[7]fix target
  481. {0x12,0x20},
  482. {0x13,0x78},
  483. {0x17,0x00},
  484. {0x1c,0x96},
  485. {0x1d,0x04}, // sunlight step
  486. {0x1e,0x11},
  487. {0x21,0xc0}, //max_post_gain
  488. {0x22,0x60}, //max_pre_gain
  489. {0x2d,0x06}, //P_N_AEC_exp_level_1[12:8]
  490. {0x2e,0x00}, //P_N_AEC_exp_level_1[7:0]
  491. {0x1e,0x32},
  492. {0x33,0x00}, //[6:5]max_exp_level [4:0]min_exp_level
  493. {0x34,0x04}, // min exp
  494. ////////////////////////////////////////////////////////////////////
  495. /////////////////////////// Measure Window /////////////////////////
  496. ////////////////////////////////////////////////////////////////////
  497. {0x06,0x07},
  498. {0x07,0x03},
  499. {0x08,0x64},
  500. {0x09,0x4a},
  501. ////////////////////////////////////////////////////////////////////
  502. /////////////////////////// AWB ////////////////////////////////////
  503. ////////////////////////////////////////////////////////////////////
  504. {0x50,0xf5},
  505. {0x51,0x18},
  506. {0x53,0x10},
  507. {0x54,0x20},
  508. {0x55,0x60},
  509. {0x57,0x33}, //number limit }, 33 half }, must <0x65 base on measure wnd now
  510. {0x5d,0x52}, //44
  511. {0x5c,0x25}, //show mode},close dark_mode
  512. {0x5e,0x19}, //close color temp
  513. {0x5f,0x50}, //50
  514. {0x60,0x57}, //50
  515. {0x61,0xdf},
  516. {0x62,0x80}, //7b
  517. {0x63,0x08}, //20
  518. {0x64,0x5B},
  519. {0x65,0x90},
  520. {0x66,0xd0},
  521. {0x67,0x80}, //5a
  522. {0x68,0x68}, //68
  523. {0x69,0x90}, //80
  524. ////////////////////////////////////////////////////////////////////
  525. /////////////////////////// ABS ////////////////////////////////////
  526. ////////////////////////////////////////////////////////////////////
  527. {0x80,0x82},
  528. {0x81,0x00},
  529. {0x83,0x10}, //ABS Y stretch limit
  530. {0xfe,0x00},
  531. ////////////////////////////////////////////////////////////////////
  532. /////////////////////////// OUT ////////////////////////////////////
  533. ////////////////////////////////////////////////////////////////////
  534. {0xfe,0x00},
  535. #endif
  536. {0xfe,0x01}, //2015
  537. ////////////////////////////////////////////////////////////////////
  538. /////////////////////////// AEC ////////////////////////////////
  539. ////////////////////////////////////////////////////////////////////
  540. {0x10 , 0x45}, //AEC mode 1
  541. {0x11 , 0x32}, //[7]fix target
  542. {0x13 , 0x68}, //0x60
  543. {0x17 , 0x00},
  544. {0x1c , 0x96},
  545. {0x1e , 0x11},
  546. {0x21 , 0xc0}, //max_post_gain
  547. {0x22 , 0x40}, //max_pre_gain
  548. {0x2d , 0x06}, //P_N_AEC_exp_level_1[12:8]
  549. {0x2e , 0x00}, //P_N_AEC_exp_level_1[7:0]
  550. {0x1e , 0x32},
  551. {0x33 , 0x00}, //[6:5]max_exp_level [4:0]min_exp_level
  552. ////////////////////////////////////////////////////////////////////
  553. /////////////////////////// AWB ////////////////////////////////
  554. ////////////////////////////////////////////////////////////////////
  555. {0x57 , 0x40}, //number limit
  556. {0x5d , 0x44}, //
  557. {0x5c , 0x35}, //show mode,close dark_mode
  558. {0x5e , 0x29}, //close color temp
  559. {0x5f , 0x50},
  560. {0x60 , 0x50},
  561. {0x65 , 0xc0},
  562. ////////////////////////////////////////////////////////////////////
  563. /////////////////////////// ABS ////////////////////////////////
  564. ////////////////////////////////////////////////////////////////////
  565. {0x80 , 0x82},
  566. {0x81 , 0x00},
  567. {0x83 , 0x00}, //ABS Y stretch limit
  568. {0xfe,0x00},
  569. //crop
  570. {0x50,0x01},
  571. {0x51,0x00},
  572. {0x52,0x00},
  573. {0x53,0x00},
  574. {0x54,0x00},
  575. {0x55,0x02},
  576. {0x56,0x5c},
  577. {0x57,0x03},
  578. {0x58,0x20},
  579. {0x44,0xa3}, //YUV sequence
  580. {0x45,0x0f}, //output enable
  581. {0x46,0x03}, //sync mode
  582. /////write more registers
  583. {0xfe,0x00},
  584. {0x32,0x34},
  585. {0x34,0x00},
  586. /////pv_setting},even_skip(default_preview) start/////
  587. {0x02,0x01},
  588. {0x2a,0xca},
  589. {0x55,0x02},
  590. {0x56,0x5c}, //604
  591. {0x57,0x03},
  592. {0x58,0x20},//800
  593. {0x48,0x58}, //global_gain
  594. {0x63,0x77}, //BLK mode
  595. {0x6e,0x1a},
  596. {0x70,0x1a},
  597. /////pv_setting},even_skip(default_preview) end/////
  598. //////////banding////////////
  599. #ifdef GC2015_48MHz_MCLK
  600. {0x05 ,0x01},//HB
  601. {0x06 ,0xc1},
  602. {0x07 ,0x00},//VB
  603. {0x08 ,0x40},
  604. {0xfe ,0x01},
  605. {0x29 ,0x01},//Anti Step
  606. {0x2a ,0x00},
  607. {0x2b ,0x05},//Level_0 20fps
  608. {0x2c ,0x00},
  609. {0x2d ,0x08},//Level_1 12.5fps
  610. {0x2e ,0x00},
  611. {0x2f ,0x0c},//Level_2 8.33fps
  612. {0x30 ,0x00},
  613. {0x31 ,0x10},//Level_3 6.25fps
  614. {0x32 ,0x00},
  615. {0xfe ,0x00},
  616. #else
  617. {0x05 ,0x01},//HB
  618. {0x06 ,0xc1},
  619. {0x07 ,0x00},//VB
  620. {0x08 ,0x40},
  621. {0xfe ,0x01},
  622. {0x29 ,0x00},//Anti Step 128
  623. {0x2a ,0x80},
  624. {0x2b ,0x05},//Level_0 10.00fps
  625. {0x2c ,0x00},
  626. {0x2d ,0x06},//Level_1 8.33fps
  627. {0x2e ,0x00},
  628. {0x2f ,0x08},//Level_2 6.25fps
  629. {0x30 ,0x00},
  630. {0x31 ,0x09},//Level_3 5.55fps
  631. {0x32 ,0x00},
  632. {0xfe ,0x00},
  633. #endif
  634. {0x43 ,0x00}, //effect normal
  635. {0x42 ,0xf6}, // wb normal
  636. {0xff,0xff},
  637. };
  638. //load gc2015 parameters
  639. void gc2015_init_regs(struct gc2015_device *dev)
  640. {
  641. int i=0;//,j;
  642. unsigned char buf[2];
  643. struct i2c_client *client = v4l2_get_subdevdata(&dev->sd);
  644. while(1)
  645. {
  646. buf[0] = gc2015_script[i].addr;//(unsigned char)((gc2015_script[i].addr >> 8) & 0xff);
  647. //buf[1] = (unsigned char)(gc2015_script[i].addr & 0xff);
  648. buf[1] = gc2015_script[i].val;
  649. i++;
  650. if (gc2015_script[i].val==0xff&&gc2015_script[i].addr==0xff)
  651. {
  652. printk("gc2015_write_regs success in initial gc2015.\n");
  653. break;
  654. }
  655. if((i2c_put_byte_add8(client,buf, 2)) < 0)
  656. {
  657. printk("fail in initial gc2015. \n");
  658. return;
  659. }
  660. }
  661. aml_plat_cam_data_t* plat_dat= (aml_plat_cam_data_t*)client->dev.platform_data;
  662. if (plat_dat&&plat_dat->custom_init_script) {
  663. i=0;
  664. aml_camera_i2c_fig1_t* custom_script = (aml_camera_i2c_fig1_t*)plat_dat->custom_init_script;
  665. while(1)
  666. {
  667. buf[0] = custom_script[i].addr;
  668. buf[1] = custom_script[i].val;
  669. if (custom_script[i].val==0xff&&custom_script[i].addr==0xff)
  670. {
  671. printk("gc2015_write_custom_regs success in initial gc2015.\n");
  672. break;
  673. }
  674. if((i2c_put_byte_add8(client,buf, 2)) < 0)
  675. {
  676. printk("fail in initial gc2015 custom_regs. \n");
  677. return;
  678. }
  679. i++;
  680. }
  681. }
  682. return;
  683. }
  684. /*************************************************************************
  685. * FUNCTION
  686. * gc2015_set_param_wb
  687. *
  688. * DESCRIPTION
  689. * wb setting.
  690. *
  691. * PARAMETERS
  692. * none
  693. *
  694. * RETURNS
  695. * None
  696. *
  697. * GLOBALS AFFECTED
  698. *
  699. *************************************************************************/
  700. void gc2015_set_param_wb(struct gc2015_device *dev,enum camera_wb_flip_e para)//white balance
  701. {
  702. struct i2c_client *client = v4l2_get_subdevdata(&dev->sd);
  703. unsigned char buf[4];
  704. switch (para)
  705. {
  706. case CAM_WB_AUTO://auto
  707. printk("CAM_WB_AUTO \n");
  708. buf[0]=0x42;
  709. buf[1]=0x76;
  710. i2c_put_byte_add8(client,buf,2);
  711. break;
  712. case CAM_WB_CLOUD: //cloud
  713. printk("CAM_WB_CLOUD \n");
  714. buf[0]=0x42;
  715. buf[1]=0x74;
  716. i2c_put_byte_add8(client,buf,2);
  717. buf[0]=0x7a;
  718. buf[1]=0x8c;
  719. i2c_put_byte_add8(client,buf,2);
  720. buf[0]=0x7b;
  721. buf[1]=0x50;
  722. i2c_put_byte_add8(client,buf,2);
  723. buf[0]=0x7c;
  724. buf[1]=0x40;
  725. i2c_put_byte_add8(client,buf,2);
  726. break;
  727. case CAM_WB_DAYLIGHT: //
  728. printk("CAM_WB_DAYLIGHT \n");
  729. buf[0]=0x42;
  730. buf[1]=0x74;
  731. i2c_put_byte_add8(client,buf,2);
  732. buf[0]=0x7a;
  733. buf[1]=0x74;
  734. i2c_put_byte_add8(client,buf,2);
  735. buf[0]=0x7b;
  736. buf[1]=0x52;
  737. i2c_put_byte_add8(client,buf,2);
  738. buf[0]=0x7c;
  739. buf[1]=0x40;
  740. i2c_put_byte_add8(client,buf,2);
  741. break;
  742. case CAM_WB_INCANDESCENCE:
  743. printk("CAM_WB_INCANDESCENCE \n");
  744. buf[0]=0x42;
  745. buf[1]=0x74;
  746. i2c_put_byte_add8(client,buf,2);
  747. buf[0]=0x7a;
  748. buf[1]=0x48;
  749. i2c_put_byte_add8(client,buf,2);
  750. buf[0]=0x7b;
  751. buf[1]=0x40;
  752. i2c_put_byte_add8(client,buf,2);
  753. buf[0]=0x7c;
  754. buf[1]=0x5c;
  755. i2c_put_byte_add8(client,buf,2);
  756. break;
  757. case CAM_WB_TUNGSTEN:
  758. printk("CAM_WB_TUNGSTEN \n");
  759. buf[0]=0x42;
  760. buf[1]=0x74;
  761. i2c_put_byte_add8(client,buf,2);
  762. buf[0]=0x7a;
  763. buf[1]=0x40;
  764. i2c_put_byte_add8(client,buf,2);
  765. buf[0]=0x7b;
  766. buf[1]=0x54;
  767. i2c_put_byte_add8(client,buf,2);
  768. buf[0]=0x7c;
  769. buf[1]=0x70;
  770. i2c_put_byte_add8(client,buf,2);
  771. break;
  772. case CAM_WB_FLUORESCENT:
  773. printk("CAM_WB_FLUORESCENT \n");
  774. buf[0]=0x42;
  775. buf[1]=0x74;
  776. i2c_put_byte_add8(client,buf,2);
  777. buf[0]=0x7a;
  778. buf[1]=0x40;
  779. i2c_put_byte_add8(client,buf,2);
  780. buf[0]=0x7b;
  781. buf[1]=0x42;
  782. i2c_put_byte_add8(client,buf,2);
  783. buf[0]=0x7c;
  784. buf[1]=0x50;
  785. i2c_put_byte_add8(client,buf,2);
  786. break;
  787. case CAM_WB_MANUAL:
  788. // TODO
  789. break;
  790. }
  791. } /* gc2015_set_param_wb */
  792. /*************************************************************************
  793. * FUNCTION
  794. * gc2015_set_param_exposure
  795. *
  796. * DESCRIPTION
  797. * exposure setting.
  798. *
  799. * PARAMETERS
  800. * none
  801. *
  802. * RETURNS
  803. * None
  804. *
  805. * GLOBALS AFFECTED
  806. *
  807. *************************************************************************/
  808. void gc2015_set_param_exposure(struct gc2015_device *dev,enum camera_exposure_e para)
  809. {
  810. struct i2c_client *client = v4l2_get_subdevdata(&dev->sd);
  811. unsigned char buf[4];
  812. switch (para)
  813. {
  814. case EXPOSURE_N4_STEP:
  815. buf[0]=0xfe;
  816. buf[1]=0x01;
  817. i2c_put_byte_add8(client,buf,2);
  818. buf[0]=0x13;
  819. buf[1]=0x40;
  820. i2c_put_byte_add8(client,buf,2);
  821. buf[0]=0xfe;
  822. buf[1]=0x00;
  823. i2c_put_byte_add8(client,buf,2);
  824. buf[0]=0xd5;
  825. buf[1]=0xc0;
  826. i2c_put_byte_add8(client,buf,2);
  827. break;
  828. case EXPOSURE_N3_STEP:
  829. buf[0]=0xfe;
  830. buf[1]=0x01;
  831. i2c_put_byte_add8(client,buf,2);
  832. buf[0]=0x13;
  833. buf[1]=0x48;
  834. i2c_put_byte_add8(client,buf,2);
  835. buf[0]=0xfe;
  836. buf[1]=0x00;
  837. i2c_put_byte_add8(client,buf,2);
  838. buf[0]=0xd5;
  839. buf[1]=0xd0;
  840. i2c_put_byte_add8(client,buf,2);
  841. break;
  842. case EXPOSURE_N2_STEP:
  843. buf[0]=0xfe;
  844. buf[1]=0x01;
  845. i2c_put_byte_add8(client,buf,2);
  846. buf[0]=0x13;
  847. buf[1]=0x50;
  848. i2c_put_byte_add8(client,buf,2);
  849. buf[0]=0xfe;
  850. buf[1]=0x00;
  851. i2c_put_byte_add8(client,buf,2);
  852. buf[0]=0xd5;
  853. buf[1]=0xe0;
  854. i2c_put_byte_add8(client,buf,2);
  855. break;
  856. case EXPOSURE_N1_STEP:
  857. printk("EXPOSURE_N1_STEP \n");
  858. buf[0]=0xfe;
  859. buf[1]=0x01;
  860. i2c_put_byte_add8(client,buf,2);
  861. buf[0]=0x13;
  862. buf[1]=0x58;
  863. i2c_put_byte_add8(client,buf,2);
  864. buf[0]=0xfe;
  865. buf[1]=0x00;
  866. i2c_put_byte_add8(client,buf,2);
  867. buf[0]=0xd5;
  868. buf[1]=0xf0;
  869. i2c_put_byte_add8(client,buf,2);
  870. break;
  871. case EXPOSURE_0_STEP:
  872. printk("EXPOSURE_0_STEP \n");
  873. buf[0]=0xfe;
  874. buf[1]=0x01;
  875. i2c_put_byte_add8(client,buf,2);
  876. buf[0]=0x13;
  877. buf[1]=0x68;//0x60
  878. i2c_put_byte_add8(client,buf,2);
  879. buf[0]=0xfe;
  880. buf[1]=0x00;
  881. i2c_put_byte_add8(client,buf,2);
  882. buf[0]=0xd5;
  883. buf[1]=0x00;
  884. i2c_put_byte_add8(client,buf,2);
  885. break;
  886. case EXPOSURE_P1_STEP:
  887. printk("EXPOSURE_P1_STEP \n");
  888. buf[0]=0xfe;
  889. buf[1]=0x01;
  890. i2c_put_byte_add8(client,buf,2);
  891. buf[0]=0x13;
  892. buf[1]=0x68;
  893. i2c_put_byte_add8(client,buf,2);
  894. buf[0]=0xfe;
  895. buf[1]=0x00;
  896. i2c_put_byte_add8(client,buf,2);
  897. buf[0]=0xd5;
  898. buf[1]=0x10;
  899. i2c_put_byte_add8(client,buf,2);
  900. break;
  901. case EXPOSURE_P2_STEP:
  902. buf[0]=0xfe;
  903. buf[1]=0x01;
  904. i2c_put_byte_add8(client,buf,2);
  905. buf[0]=0x13;
  906. buf[1]=0x70;
  907. i2c_put_byte_add8(client,buf,2);
  908. buf[0]=0xfe;
  909. buf[1]=0x00;
  910. i2c_put_byte_add8(client,buf,2);
  911. buf[0]=0xd5;
  912. buf[1]=0x20;
  913. i2c_put_byte_add8(client,buf,2);
  914. break;
  915. case EXPOSURE_P3_STEP:
  916. buf[0]=0xfe;
  917. buf[1]=0x01;
  918. i2c_put_byte_add8(client,buf,2);
  919. buf[0]=0x13;
  920. buf[1]=0x78;
  921. i2c_put_byte_add8(client,buf,2);
  922. buf[0]=0xfe;
  923. buf[1]=0x00;
  924. i2c_put_byte_add8(client,buf,2);
  925. buf[0]=0xd5;
  926. buf[1]=0x30;
  927. i2c_put_byte_add8(client,buf,2);
  928. break;
  929. case EXPOSURE_P4_STEP:
  930. buf[0]=0xfe;
  931. buf[1]=0x01;
  932. i2c_put_byte_add8(client,buf,2);
  933. buf[0]=0x13;
  934. buf[1]=0x80;
  935. i2c_put_byte_add8(client,buf,2);
  936. buf[0]=0xfe;
  937. buf[1]=0x00;
  938. i2c_put_byte_add8(client,buf,2);
  939. buf[0]=0xd5;
  940. buf[1]=0x40;
  941. i2c_put_byte_add8(client,buf,2);
  942. break;
  943. default:
  944. buf[0]=0xfe;
  945. buf[1]=0x01;
  946. i2c_put_byte_add8(client,buf,2);
  947. buf[0]=0x13;
  948. buf[1]=0x60;
  949. i2c_put_byte_add8(client,buf,2);
  950. buf[0]=0xfe;
  951. buf[1]=0x00;
  952. i2c_put_byte_add8(client,buf,2);
  953. buf[0]=0xd5;
  954. buf[1]=0x00;
  955. i2c_put_byte_add8(client,buf,2);
  956. break;
  957. break;
  958. }
  959. mdelay(150);
  960. } /* gc2015_set_param_exposure */
  961. /*************************************************************************
  962. * FUNCTION
  963. * gc2015_set_param_effect
  964. *
  965. * DESCRIPTION
  966. * effect setting.
  967. *
  968. * PARAMETERS
  969. * none
  970. *
  971. * RETURNS
  972. * None
  973. *
  974. * GLOBALS AFFECTED
  975. *
  976. *************************************************************************/
  977. void gc2015_set_param_effect(struct gc2015_device *dev,enum camera_effect_flip_e para)
  978. {
  979. struct i2c_client *client = v4l2_get_subdevdata(&dev->sd);
  980. unsigned char buf[4];
  981. /*
  982. switch (para)
  983. {
  984. case CAM_EFFECT_ENC_NORMAL:
  985. buf[0]=0xfe;
  986. buf[1]=0x00;
  987. i2c_put_byte_add8(client,buf,2);
  988. buf[0]=0x43;
  989. buf[1]=0x00;
  990. i2c_put_byte_add8(client,buf,2);
  991. break;
  992. case CAM_EFFECT_ENC_GRAYSCALE:
  993. buf[0]=0xfe;
  994. buf[1]=0x00;
  995. i2c_put_byte_add8(client,buf,2);
  996. buf[0]=0x43;
  997. buf[1]=0x02;
  998. i2c_put_byte_add8(client,buf,2);
  999. buf[0]=0xda;
  1000. buf[1]=0x00;
  1001. i2c_put_byte_add8(client,buf,2);
  1002. buf[0]=0xdb;
  1003. buf[1]=0x00;
  1004. i2c_put_byte_add8(client,buf,2);
  1005. break;
  1006. case CAM_EFFECT_ENC_SEPIA:
  1007. buf[0]=0xfe;
  1008. buf[1]=0x00;
  1009. i2c_put_byte_add8(client,buf,2);
  1010. buf[0]=0x43;
  1011. buf[1]=0x02;
  1012. i2c_put_byte_add8(client,buf,2);
  1013. buf[0]=0xda;
  1014. buf[1]=0xd0;
  1015. i2c_put_byte_add8(client,buf,2);
  1016. buf[0]=0xdb;
  1017. buf[1]=0x28;
  1018. i2c_put_byte_add8(client,buf,2);
  1019. break;
  1020. case CAM_EFFECT_ENC_SEPIAGREEN:
  1021. buf[0]=0xfe;
  1022. buf[1]=0x00;
  1023. i2c_put_byte_add8(client,buf,2);
  1024. buf[0]=0x43;
  1025. buf[1]=0x02;
  1026. i2c_put_byte_add8(client,buf,2);
  1027. buf[0]=0xda;
  1028. buf[1]=0xc0;
  1029. i2c_put_byte_add8(client,buf,2);
  1030. buf[0]=0xdb;
  1031. buf[1]=0xc0;
  1032. i2c_put_byte_add8(client,buf,2);
  1033. break;
  1034. case CAM_EFFECT_ENC_SEPIABLUE:
  1035. buf[0]=0xfe;
  1036. buf[1]=0x00;
  1037. i2c_put_byte_add8(client,buf,2);
  1038. buf[0]=0x43;
  1039. buf[1]=0x02;
  1040. i2c_put_byte_add8(client,buf,2);
  1041. buf[0]=0xda;
  1042. buf[1]=0x50;
  1043. i2c_put_byte_add8(client,buf,2);
  1044. buf[0]=0xdb;
  1045. buf[1]=0xe0;
  1046. i2c_put_byte_add8(client,buf,2);
  1047. break;
  1048. case CAM_EFFECT_ENC_COLORINV:
  1049. buf[0]=0xfe;
  1050. buf[1]=0x00;
  1051. i2c_put_byte_add8(client,buf,2);
  1052. buf[0]=0x43;
  1053. buf[1]=0x01;
  1054. i2c_put_byte_add8(client,buf,2);
  1055. break;
  1056. default:
  1057. buf[0]=0xfe;
  1058. buf[1]=0x00;
  1059. i2c_put_byte_add8(client,buf,2);
  1060. buf[0]=0x43;
  1061. buf[1]=0x00;
  1062. i2c_put_byte_add8(client,buf,2);
  1063. break;
  1064. }
  1065. */
  1066. } /* gc2015_set_param_effect */
  1067. /*************************************************************************
  1068. * FUNCTION
  1069. * gc2015_NightMode
  1070. *
  1071. * DESCRIPTION
  1072. * This function night mode of gc2015.
  1073. *
  1074. * PARAMETERS
  1075. * none
  1076. *
  1077. * RETURNS
  1078. * None
  1079. *
  1080. * GLOBALS AFFECTED
  1081. *
  1082. *************************************************************************/
  1083. void gc2015_set_night_mode(struct gc2015_device *dev,enum camera_night_mode_flip_e enable)
  1084. {
  1085. struct i2c_client *client = v4l2_get_subdevdata(&dev->sd);
  1086. unsigned char buf[4];
  1087. /*
  1088. if (enable)
  1089. {
  1090. buf[0]=0xfe;
  1091. buf[1]=0x01;
  1092. i2c_put_byte_add8(client,buf,2);
  1093. buf[0]=0x33;
  1094. buf[1]=0x60;
  1095. i2c_put_byte_add8(client,buf,2);
  1096. buf[0]=0xfe;
  1097. buf[1]=0x00;
  1098. i2c_put_byte_add8(client,buf,2);
  1099. }
  1100. else
  1101. {
  1102. buf[0]=0xfe;
  1103. buf[1]=0x01;
  1104. i2c_put_byte_add8(client,buf,2);
  1105. buf[0]=0x33;
  1106. buf[1]=0x00;
  1107. i2c_put_byte_add8(client,buf,2);
  1108. buf[0]=0xfe;
  1109. buf[1]=0x00;
  1110. i2c_put_byte_add8(client,buf,2);
  1111. }
  1112. */
  1113. } /* gc2015_NightMode */
  1114. void gc2015_set_param_banding(struct gc2015_device *dev,enum camera_night_mode_flip_e banding)
  1115. {
  1116. struct i2c_client *client = v4l2_get_subdevdata(&dev->sd);
  1117. unsigned char buf[4];
  1118. #if 1
  1119. switch(banding)
  1120. {
  1121. case CAM_BANDING_50HZ:
  1122. buf[0]=0xfe;
  1123. buf[1]=0x00;
  1124. i2c_put_byte_add8(client,buf,2);
  1125. buf[0]=0x05;
  1126. buf[1]=0x01;
  1127. i2c_put_byte_add8(client,buf,2);
  1128. buf[0]=0x06;
  1129. buf[1]=0xc1;
  1130. i2c_put_byte_add8(client,buf,2);
  1131. buf[0]=0x07;
  1132. buf[1]=0x00;
  1133. i2c_put_byte_add8(client,buf,2);
  1134. buf[0]=0x08;
  1135. buf[1]=0x40;
  1136. i2c_put_byte_add8(client,buf,2);
  1137. buf[0]=0xfe;
  1138. buf[1]=0x01;
  1139. i2c_put_byte_add8(client,buf,2);
  1140. buf[0]=0x29;
  1141. buf[1]=0x00;
  1142. i2c_put_byte_add8(client,buf,2);
  1143. buf[0]=0x2a;
  1144. buf[1]=0x80; //step
  1145. i2c_put_byte_add8(client,buf,2);
  1146. buf[0]=0x2b;
  1147. buf[1]=0x05;
  1148. i2c_put_byte_add8(client,buf,2);
  1149. buf[0]=0x2c;
  1150. buf[1]=0x00;
  1151. i2c_put_byte_add8(client,buf,2);
  1152. buf[0]=0x2d;
  1153. buf[1]=0x06;
  1154. i2c_put_byte_add8(client,buf,2);
  1155. buf[0]=0x2e;
  1156. buf[1]=0x00;
  1157. i2c_put_byte_add8(client,buf,2);
  1158. buf[0]=0x2f;
  1159. buf[1]=0x08;
  1160. i2c_put_byte_add8(client,buf,2);
  1161. buf[0]=0x30;
  1162. buf[1]=0x00;
  1163. i2c_put_byte_add8(client,buf,2);
  1164. buf[0]=0x31;
  1165. buf[1]=0x09;
  1166. i2c_put_byte_add8(client,buf,2);
  1167. buf[0]=0x32;
  1168. buf[1]=0x00;
  1169. i2c_put_byte_add8(client,buf,2);
  1170. buf[0]=0xfe;
  1171. buf[1]=0x00;
  1172. i2c_put_byte_add8(client,buf,2);
  1173. break;
  1174. case CAM_BANDING_60HZ:
  1175. buf[0]=0xfe;
  1176. buf[1]=0x00;
  1177. i2c_put_byte_add8(client,buf,2);
  1178. buf[0]=0x05;
  1179. buf[1]=0x01;
  1180. i2c_put_byte_add8(client,buf,2);
  1181. buf[0]=0x06;
  1182. buf[1]=0xd9;
  1183. i2c_put_byte_add8(client,buf,2);
  1184. buf[0]=0x07;
  1185. buf[1]=0x00;
  1186. i2c_put_byte_add8(client,buf,2);
  1187. buf[0]=0x08;
  1188. buf[1]=0x20;
  1189. i2c_put_byte_add8(client,buf,2);
  1190. buf[0]=0xfe;
  1191. buf[1]=0x01;
  1192. i2c_put_byte_add8(client,buf,2);
  1193. buf[0]=0x29;
  1194. buf[1]=0x00;
  1195. i2c_put_byte_add8(client,buf,2);
  1196. buf[0]=0x2a;
  1197. buf[1]=0x68; //step
  1198. i2c_put_byte_add8(client,buf,2);
  1199. buf[0]=0x2b;
  1200. buf[1]=0x04;
  1201. i2c_put_byte_add8(client,buf,2);
  1202. buf[0]=0x2c;
  1203. buf[1]=0xe0;
  1204. i2c_put_byte_add8(client,buf,2);
  1205. buf[0]=0x2d;
  1206. buf[1]=0x05;
  1207. i2c_put_byte_add8(client,buf,2);
  1208. buf[0]=0x2e;
  1209. buf[1]=0xb0;
  1210. i2c_put_byte_add8(client,buf,2);
  1211. buf[0]=0x2f;
  1212. buf[1]=0x06;
  1213. i2c_put_byte_add8(client,buf,2);
  1214. buf[0]=0x30;
  1215. buf[1]=0xe8;
  1216. i2c_put_byte_add8(client,buf,2);
  1217. buf[0]=0x31;
  1218. buf[1]=0x08;
  1219. i2c_put_byte_add8(client,buf,2);
  1220. buf[0]=0x32;
  1221. buf[1]=0x20;
  1222. i2c_put_byte_add8(client,buf,2);
  1223. buf[0]=0xfe;
  1224. buf[1]=0x00;
  1225. i2c_put_byte_add8(client,buf,2);
  1226. break;
  1227. }
  1228. #endif
  1229. }
  1230. void gc2015_set_resolution(struct gc2015_device *dev,int height,int width)
  1231. {
  1232. #if 1
  1233. int ret;
  1234. unsigned char buf[4];
  1235. int ret1=0;
  1236. unsigned int value;
  1237. unsigned int pid=0,shutter;
  1238. unsigned int hb_ori, hb_total=298;
  1239. unsigned int temp_reg;
  1240. static unsigned int shutter_l = 0;
  1241. static unsigned int shutter_h = 0;
  1242. struct i2c_client *client = v4l2_get_subdevdata(&dev->sd);
  1243. if((width<1600)&&(height<1200))
  1244. {
  1245. //800*600
  1246. buf[0]=0xfe;
  1247. buf[1]=0x00;
  1248. i2c_put_byte_add8(client,buf,2);
  1249. /* rewrite shutter : 0x03, 0x04*/
  1250. #if 1
  1251. buf[0]=0x03;
  1252. buf[1]=(unsigned char)shutter_l;
  1253. i2c_put_byte_add8(client,buf,2);
  1254. buf[0]=0x04;
  1255. buf[1]=(unsigned char)shutter_h;
  1256. i2c_put_byte_add8(client,buf,2);
  1257. #endif
  1258. buf[0]=0x02;
  1259. buf[1]=0x01;
  1260. i2c_put_byte_add8(client,buf,2);
  1261. buf[0]=0x2a;
  1262. buf[1]=0xca;
  1263. i2c_put_byte_add8(client,buf,2);
  1264. buf[0]=0x55;
  1265. buf[1]=0x02;
  1266. i2c_put_byte_add8(client,buf,2);
  1267. buf[0]=0x56;
  1268. buf[1]=0x5c; //604
  1269. i2c_put_byte_add8(client,buf,2);
  1270. buf[0]=0x57;
  1271. buf[1]=0x03;
  1272. i2c_put_byte_add8(client,buf,2);
  1273. buf[0]=0x58;
  1274. buf[1]=0x20; // 800
  1275. i2c_put_byte_add8(client,buf,2);
  1276. buf[0]=0x48;
  1277. buf[1]=0x58;
  1278. i2c_put_byte_add8(client,buf,2);
  1279. mdelay(250);
  1280. buf[0]=0x4f;
  1281. buf[1]=0x01;
  1282. i2c_put_byte_add8(client,buf,2);
  1283. gc2015_h_active=800;
  1284. gc2015_v_active=600;
  1285. mdelay(50);
  1286. }
  1287. else if(width>=1600&&height>=1200 )
  1288. {
  1289. #if 1
  1290. buf[0]=0x4f;
  1291. buf[1]=0x00; //aec off
  1292. i2c_put_byte_add8(client,buf,2);
  1293. buf[0]=0x03; //0x00
  1294. //value=i2c_get_byte(client, 0x03);
  1295. value=i2c_get_byte_add8(client, 0x03);
  1296. shutter_l = value;
  1297. printk( KERN_INFO" set camera GC2015_set_resolution=0x03=0x%x \n ",value);
  1298. pid |= (value << 8);
  1299. buf[0]=0x04; //0x00
  1300. //value=i2c_get_byte(client, 0x04);
  1301. value=i2c_get_byte_add8(client, 0x04);
  1302. shutter_h = value;
  1303. printk( KERN_INFO" set camera GC2015_set_resolution=0x04=0x%x \n ",value);
  1304. pid |= (value & 0xff);
  1305. shutter=pid;
  1306. printk( KERN_INFO" set camera GC2015_set_resolution=shutter=0x%x \n ",shutter);
  1307. #endif
  1308. buf[0]=0xfe;
  1309. buf[1]=0x00;
  1310. i2c_put_byte_add8(client,buf,2);
  1311. buf[0]=0x02;
  1312. buf[1]=0x00;
  1313. i2c_put_byte_add8(client,buf,2);
  1314. buf[0]=0x2a;
  1315. buf[1]=0x0a;
  1316. i2c_put_byte_add8(client,buf,2);
  1317. buf[0]=0x59;
  1318. buf[1]=0x11;
  1319. i2c_put_byte_add8(client,buf,2);
  1320. buf[0]=0x5a;
  1321. buf[1]=0x06;
  1322. i2c_put_byte_add8(client,buf,2);
  1323. buf[0]=0x5b;
  1324. buf[1]=0x00;
  1325. i2c_put_byte_add8(client,buf,2);
  1326. buf[0]=0x5c;
  1327. buf[1]=0x00;
  1328. i2c_put_byte_add8(client,buf,2);
  1329. buf[0]=0x5d;
  1330. buf[1]=0x00;
  1331. i2c_put_byte_add8(client,buf,2);
  1332. buf[0]=0x5e;
  1333. buf[1]=0x00;
  1334. i2c_put_byte_add8(client,buf,2);
  1335. buf[0]=0x5f;
  1336. buf[1]=0x00;
  1337. i2c_put_byte_add8(client,buf,2);
  1338. buf[0]=0x60;
  1339. buf[1]=0x00;
  1340. i2c_put_byte_add8(client,buf,2);
  1341. buf[0]=0x61;
  1342. buf[1]=0x00;
  1343. i2c_put_byte_add8(client,buf,2);
  1344. buf[0]=0x62;
  1345. buf[1]=0x00;
  1346. i2c_put_byte_add8(client,buf,2);
  1347. buf[0]=0x50;
  1348. buf[1]=0x01;
  1349. i2c_put_byte_add8(client,buf,2);
  1350. buf[0]=0x51;
  1351. buf[1]=0x00;
  1352. i2c_put_byte_add8(client,buf,2);
  1353. buf[0]=0x52;
  1354. buf[1]=0x00;
  1355. i2c_put_byte_add8(client,buf,2);
  1356. buf[0]=0x53;
  1357. buf[1]=0x00;
  1358. i2c_put_byte_add8(client,buf,2);
  1359. buf[0]=0x54;
  1360. buf[1]=0x00;
  1361. i2c_put_byte_add8(client,buf,2);
  1362. buf[0]=0x55;
  1363. buf[1]=0x04;
  1364. i2c_put_byte_add8(client,buf,2);
  1365. buf[0]=0x56;
  1366. buf[1]=0xb2; //1202
  1367. i2c_put_byte_add8(client,buf,2);
  1368. buf[0]=0x57;
  1369. buf[1]=0x06;
  1370. i2c_put_byte_add8(client,buf,2);
  1371. buf[0]=0x58;
  1372. buf[1]=0x40; // 1600
  1373. i2c_put_byte_add8(client,buf,2);
  1374. buf[0]=0x48;
  1375. buf[1]=0x78; //global gain
  1376. i2c_put_byte_add8(client,buf,2);
  1377. mdelay(50);
  1378. #if 1
  1379. buf[0]=0x12;
  1380. buf[1]= ((hb_total>>8)&0xff);
  1381. i2c_put_byte_add8(client,buf,2);
  1382. buf[0]=0x13;
  1383. buf[1]= (hb_total&0xff);
  1384. i2c_put_byte_add8(client,buf,2);
  1385. temp_reg = shutter * 10 / 16 ;
  1386. if(temp_reg < 1) temp_reg = 1;
  1387. printk( KERN_INFO" set camera GC2015_set_resolution=temp_ret=0x%x \n ",temp_reg);
  1388. buf[0]=0x03;
  1389. buf[1]= ((temp_reg>>8)&0xff);
  1390. i2c_put_byte_add8(client,buf,2);
  1391. buf[0]=0x04;
  1392. buf[1]= (temp_reg&0xff);
  1393. i2c_put_byte_add8(client,buf,2);
  1394. #if 0
  1395. buf[0]=0x6e;
  1396. buf[1]= 0x1b;
  1397. i2c_put_byte_add8(client,buf,2);
  1398. buf[0]=0x6f;
  1399. buf[1]= 0x20;
  1400. i2c_put_byte_add8(client,buf,2);
  1401. buf[0]=0x70;
  1402. buf[1]= 0x1b;
  1403. i2c_put_byte_add8(client,buf,2);
  1404. buf[0]=0x71;
  1405. buf[1]= 0x20;
  1406. i2c_put_byte_add8(client,buf,2);
  1407. #endif
  1408. #endif
  1409. gc2015_h_active=1600;
  1410. gc2015_v_active=1200;
  1411. mdelay(150);
  1412. }
  1413. printk(KERN_INFO " set camera GC2015_set_resolution=w=%d,h=%d. \n ",width,height);
  1414. #endif
  1415. } /* gc2015_set_resolution */
  1416. unsigned char v4l_2_gc2015(int val)
  1417. {
  1418. int ret=val/0x20;
  1419. if(ret<4) return ret*0x20+0x80;
  1420. else if(ret<8) return ret*0x20+0x20;
  1421. else return 0;
  1422. }
  1423. static int gc2015_setting(struct gc2015_device *dev,int PROP_ID,int value )
  1424. {
  1425. int ret=0;
  1426. unsigned char cur_val;
  1427. struct i2c_client *client = v4l2_get_subdevdata(&dev->sd);
  1428. switch(PROP_ID) {
  1429. case V4L2_CID_BRIGHTNESS:
  1430. dprintk(dev, 1, "setting brightned:%d\n",v4l_2_gc2015(value));
  1431. // ret=i2c_put_byte(client,0x0201,v4l_2_gc2015(value));
  1432. break;
  1433. case V4L2_CID_CONTRAST:
  1434. // ret=i2c_put_byte(client,0x0200, value);
  1435. break;
  1436. case V4L2_CID_SATURATION:
  1437. // ret=i2c_put_byte(client,0x0202, value);
  1438. break;
  1439. #if 0
  1440. case V4L2_CID_EXPOSURE:
  1441. ret=i2c_put_byte(client,0x0201, value);
  1442. break;
  1443. #endif
  1444. case V4L2_CID_HFLIP: /* set flip on H. */
  1445. break;
  1446. case V4L2_CID_VFLIP: /* set flip on V. */
  1447. break;
  1448. case V4L2_CID_DO_WHITE_BALANCE:
  1449. if(gc2015_qctrl[0].default_value!=value){
  1450. gc2015_qctrl[0].default_value=value;
  1451. gc2015_set_param_wb(dev,value);
  1452. printk(KERN_INFO " set camera white_balance=%d. \n ",value);
  1453. }
  1454. break;
  1455. case V4L2_CID_EXPOSURE:
  1456. if(gc2015_qctrl[1].default_value!=value){
  1457. gc2015_qctrl[1].default_value=value;
  1458. gc2015_set_param_exposure(dev,value);
  1459. printk(KERN_INFO " set camera exposure=%d. \n ",value);
  1460. }
  1461. break;
  1462. case V4L2_CID_COLORFX:
  1463. if(gc2015_qctrl[2].default_value!=value){
  1464. gc2015_qctrl[2].default_value=value;
  1465. gc2015_set_param_effect(dev,value);
  1466. printk(KERN_INFO " set camera effect=%d. \n ",value);
  1467. }
  1468. break;
  1469. case V4L2_CID_WHITENESS:
  1470. if(gc2015_qctrl[3].default_value!=value){
  1471. gc2015_qctrl[3].default_value=value;
  1472. gc2015_set_param_banding(dev,value);
  1473. printk(KERN_INFO " set camera banding=%d. \n ",value);
  1474. }
  1475. break;
  1476. case V4L2_CID_BLUE_BALANCE:
  1477. if(gc2015_qctrl[4].default_value!=value){
  1478. gc2015_qctrl[4].default_value=value;
  1479. gc2015_set_night_mode(dev,value);
  1480. printk(KERN_INFO " set camera scene mode=%d. \n ",value);
  1481. }
  1482. break;
  1483. default:
  1484. ret=-1;
  1485. break;
  1486. }
  1487. return ret;
  1488. }
  1489. static void power_down_gc2015(struct gc2015_device *dev)
  1490. {
  1491. struct i2c_client *client = v4l2_get_subdevdata(&dev->sd);
  1492. unsigned char buf[4];
  1493. buf[0]=0x45;
  1494. buf[1]=0x00;
  1495. i2c_put_byte_add8(client,buf,2);
  1496. }
  1497. /* ------------------------------------------------------------------
  1498. DMA and thread functions
  1499. ------------------------------------------------------------------*/
  1500. extern int vm_fill_buffer(struct videobuf_buffer* vb , int v4l2_format , int magic,void* vaddr);
  1501. #define TSTAMP_MIN_Y 24
  1502. #define TSTAMP_MAX_Y (TSTAMP_MIN_Y + 15)
  1503. #define TSTAMP_INPUT_X 10
  1504. #define TSTAMP_MIN_X (54 + TSTAMP_INPUT_X)
  1505. static void gc2015_fillbuff(struct gc2015_fh *fh, struct gc2015_buffer *buf)
  1506. {
  1507. struct gc2015_device *dev = fh->dev;
  1508. void *vbuf = videobuf_to_vmalloc(&buf->vb);
  1509. dprintk(dev,1,"%s\n", __func__);
  1510. if (!vbuf)
  1511. return;
  1512. /* 0x18221223 indicate the memory type is MAGIC_VMAL_MEM*/
  1513. vm_fill_buffer(&buf->vb,fh->fmt->fourcc ,0x18221223,vbuf);
  1514. buf->vb.state = VIDEOBUF_DONE;
  1515. }
  1516. static void gc2015_thread_tick(struct gc2015_fh *fh)
  1517. {
  1518. struct gc2015_buffer *buf;
  1519. struct gc2015_device *dev = fh->dev;
  1520. struct gc2015_dmaqueue *dma_q = &dev->vidq;
  1521. unsigned long flags = 0;
  1522. dprintk(dev, 1, "Thread tick\n");
  1523. spin_lock_irqsave(&dev->slock, flags);
  1524. if (list_empty(&dma_q->active)) {
  1525. dprintk(dev, 1, "No active queue to serve\n");
  1526. goto unlock;
  1527. }
  1528. buf = list_entry(dma_q->active.next,
  1529. struct gc2015_buffer, vb.queue);
  1530. dprintk(dev, 1, "%s\n", __func__);
  1531. dprintk(dev, 1, "list entry get buf is %x\n",(unsigned)buf);
  1532. /* Nobody is waiting on this buffer, return */
  1533. if (!waitqueue_active(&buf->vb.done))
  1534. goto unlock;
  1535. list_del(&buf->vb.queue);
  1536. do_gettimeofday(&buf->vb.ts);
  1537. /* Fill buffer */
  1538. spin_unlock_irqrestore(&dev->slock, flags);
  1539. gc2015_fillbuff(fh, buf);
  1540. dprintk(dev, 1, "filled buffer %p\n", buf);
  1541. wake_up(&buf->vb.done);
  1542. dprintk(dev, 2, "[%p/%d] wakeup\n", buf, buf->vb. i);
  1543. return;
  1544. unlock:
  1545. spin_unlock_irqrestore(&dev->slock, flags);
  1546. return;
  1547. }
  1548. #define frames_to_ms(frames) \
  1549. ((frames * WAKE_NUMERATOR * 1000) / WAKE_DENOMINATOR)
  1550. static void gc2015_sleep(struct gc2015_fh *fh)
  1551. {
  1552. struct gc2015_device *dev = fh->dev;
  1553. struct gc2015_dmaqueue *dma_q = &dev->vidq;
  1554. DECLARE_WAITQUEUE(wait, current);
  1555. dprintk(dev, 1, "%s dma_q=0x%08lx\n", __func__,
  1556. (unsigned long)dma_q);
  1557. add_wait_queue(&dma_q->wq, &wait);
  1558. if (kthread_should_stop())
  1559. goto stop_task;
  1560. /* Calculate time to wake up */
  1561. //timeout = msecs_to_jiffies(frames_to_ms(1));
  1562. gc2015_thread_tick(fh);
  1563. schedule_timeout_interruptible(2);
  1564. stop_task:
  1565. remove_wait_queue(&dma_q->wq, &wait);
  1566. try_to_freeze();
  1567. }
  1568. static int gc2015_thread(void *data)
  1569. {
  1570. struct gc2015_fh *fh = data;
  1571. struct gc2015_device *dev = fh->dev;
  1572. dprintk(dev, 1, "thread started\n");
  1573. set_freezable();
  1574. for (;;) {
  1575. gc2015_sleep(fh);
  1576. if (kthread_should_stop())
  1577. break;
  1578. }
  1579. dprintk(dev, 1, "thread: exit\n");
  1580. return 0;
  1581. }
  1582. static int gc2015_start_thread(struct gc2015_fh *fh)
  1583. {
  1584. struct gc2015_device *dev = fh->dev;
  1585. struct gc2015_dmaqueue *dma_q = &dev->vidq;
  1586. dma_q->frame = 0;
  1587. dma_q->ini_jiffies = jiffies;
  1588. dprintk(dev, 1, "%s\n", __func__);
  1589. dma_q->kthread = kthread_run(gc2015_thread, fh, "gc2015");
  1590. if (IS_ERR(dma_q->kthread)) {
  1591. v4l2_err(&dev->v4l2_dev, "kernel_thread() failed\n");
  1592. return PTR_ERR(dma_q->kthread);
  1593. }
  1594. /* Wakes thread */
  1595. wake_up_interruptible(&dma_q->wq);
  1596. dprintk(dev, 1, "returning from %s\n", __func__);
  1597. return 0;
  1598. }
  1599. static void gc2015_stop_thread(struct gc2015_dmaqueue *dma_q)
  1600. {
  1601. struct gc2015_device *dev = container_of(dma_q, struct gc2015_device, vidq);
  1602. dprintk(dev, 1, "%s\n", __func__);
  1603. /* shutdown control thread */
  1604. if (dma_q->kthread) {
  1605. kthread_stop(dma_q->kthread);
  1606. dma_q->kthread = NULL;
  1607. }
  1608. }
  1609. /* ------------------------------------------------------------------
  1610. Videobuf operations
  1611. ------------------------------------------------------------------*/
  1612. static int
  1613. buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
  1614. {
  1615. struct gc2015_fh *fh = vq->priv_data;
  1616. struct gc2015_device *dev = fh->dev;
  1617. //int bytes = fh->fmt->depth >> 3 ;
  1618. *size = (fh->width*fh->height*fh->fmt->depth)>>3;
  1619. if (0 == *count)
  1620. *count = 32;
  1621. while (*size * *count > vid_limit * 1024 * 1024)
  1622. (*count)--;
  1623. dprintk(dev, 1, "%s, count=%d, size=%d\n", __func__,
  1624. *count, *size);
  1625. return 0;
  1626. }
  1627. static void free_buffer(struct videobuf_queue *vq, struct gc2015_buffer *buf)
  1628. {
  1629. struct gc2015_fh *fh = vq->priv_data;
  1630. struct gc2015_device *dev = fh->dev;
  1631. dprintk(dev, 1, "%s, state: %i\n", __func__, buf->vb.state);
  1632. if (in_interrupt())
  1633. BUG();
  1634. videobuf_vmalloc_free(&buf->vb);
  1635. dprintk(dev, 1, "free_buffer: freed\n");
  1636. buf->vb.state = VIDEOBUF_NEEDS_INIT;
  1637. }
  1638. #define norm_maxw() 1920
  1639. #define norm_maxh() 1200
  1640. static int
  1641. buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
  1642. enum v4l2_field field)
  1643. {
  1644. struct gc2015_fh *fh = vq->priv_data;
  1645. struct gc2015_device *dev = fh->dev;
  1646. struct gc2015_buffer *buf = container_of(vb, struct gc2015_buffer, vb);
  1647. int rc;
  1648. //int bytes = fh->fmt->depth >> 3 ;
  1649. dprintk(dev, 1, "%s, field=%d\n", __func__, field);
  1650. BUG_ON(NULL == fh->fmt);
  1651. if (fh->width < 48 || fh->width > norm_maxw() ||
  1652. fh->height < 32 || fh->height > norm_maxh())
  1653. return -EINVAL;
  1654. buf->vb.size = (fh->width*fh->height*fh->fmt->depth)>>3;
  1655. if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
  1656. return -EINVAL;
  1657. /* These properties only change when queue is idle, see s_fmt */
  1658. buf->fmt = fh->fmt;
  1659. buf->vb.width = fh->width;
  1660. buf->vb.height = fh->height;
  1661. buf->vb.field = field;
  1662. //precalculate_bars(fh);
  1663. if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
  1664. rc = videobuf_iolock(vq, &buf->vb, NULL);
  1665. if (rc < 0)
  1666. goto fail;
  1667. }
  1668. buf->vb.state = VIDEOBUF_PREPARED;
  1669. return 0;
  1670. fail:
  1671. free_buffer(vq, buf);
  1672. return rc;
  1673. }
  1674. static void
  1675. buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
  1676. {
  1677. struct gc2015_buffer *buf = container_of(vb, struct gc2015_buffer, vb);
  1678. struct gc2015_fh *fh = vq->priv_data;
  1679. struct gc2015_device *dev = fh->dev;
  1680. struct gc2015_dmaqueue *vidq = &dev->vidq;
  1681. dprintk(dev, 1, "%s\n", __func__);
  1682. buf->vb.state = VIDEOBUF_QUEUED;
  1683. list_add_tail(&buf->vb.queue, &vidq->active);
  1684. }
  1685. static void buffer_release(struct videobuf_queue *vq,
  1686. struct videobuf_buffer *vb)
  1687. {
  1688. struct gc2015_buffer *buf = container_of(vb, struct gc2015_buffer, vb);
  1689. struct gc2015_fh *fh = vq->priv_data;
  1690. struct gc2015_device *dev = (struct gc2015_device *)fh->dev;
  1691. dprintk(dev, 1, "%s\n", __func__);
  1692. free_buffer(vq, buf);
  1693. }
  1694. static struct videobuf_queue_ops gc2015_video_qops = {
  1695. .buf_setup = buffer_setup,
  1696. .buf_prepare = buffer_prepare,
  1697. .buf_queue = buffer_queue,
  1698. .buf_release = buffer_release,
  1699. };
  1700. /* ------------------------------------------------------------------
  1701. IOCTL vidioc handling
  1702. ------------------------------------------------------------------*/
  1703. static int vidioc_querycap(struct file *file, void *priv,
  1704. struct v4l2_capability *cap)
  1705. {
  1706. struct gc2015_fh *fh = priv;
  1707. struct gc2015_device *dev = fh->dev;
  1708. strcpy(cap->driver, "gc2015");
  1709. strcpy(cap->card, "gc2015");
  1710. strlcpy(cap->bus_info, dev->v4l2_dev.name, sizeof(cap->bus_info));
  1711. cap->version = gc2015_CAMERA_VERSION;
  1712. cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
  1713. V4L2_CAP_STREAMING |
  1714. V4L2_CAP_READWRITE;
  1715. return 0;
  1716. }
  1717. static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
  1718. struct v4l2_fmtdesc *f)
  1719. {
  1720. struct gc2015_fmt *fmt;
  1721. if (f->index >= ARRAY_SIZE(formats))
  1722. return -EINVAL;
  1723. fmt = &formats[f->index];
  1724. strlcpy(f->description, fmt->name, sizeof(f->description));
  1725. f->pixelformat = fmt->fourcc;
  1726. return 0;
  1727. }
  1728. static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
  1729. struct v4l2_format *f)
  1730. {
  1731. struct gc2015_fh *fh = priv;
  1732. f->fmt.pix.width = fh->width;
  1733. f->fmt.pix.height = fh->height;
  1734. f->fmt.pix.field = fh->vb_vidq.field;
  1735. f->fmt.pix.pixelformat = fh->fmt->fourcc;
  1736. f->fmt.pix.bytesperline =
  1737. (f->fmt.pix.width * fh->fmt->depth) >> 3;
  1738. f->fmt.pix.sizeimage =
  1739. f->fmt.pix.height * f->fmt.pix.bytesperline;
  1740. return (0);
  1741. }
  1742. static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
  1743. struct v4l2_format *f)
  1744. {
  1745. struct gc2015_fh *fh = priv;
  1746. struct gc2015_device *dev = fh->dev;
  1747. struct gc2015_fmt *fmt;
  1748. enum v4l2_field field;
  1749. unsigned int maxw, maxh;
  1750. fmt = get_format(f);
  1751. if (!fmt) {
  1752. dprintk(dev, 1, "Fourcc format (0x%08x) invalid.\n",
  1753. f->fmt.pix.pixelformat);
  1754. return -EINVAL;
  1755. }
  1756. field = f->fmt.pix.field;
  1757. if (field == V4L2_FIELD_ANY) {
  1758. field = V4L2_FIELD_INTERLACED;
  1759. } else if (V4L2_FIELD_INTERLACED != field) {
  1760. dprintk(dev, 1, "Field type invalid.\n");
  1761. return -EINVAL;
  1762. }
  1763. maxw = norm_maxw();
  1764. maxh = norm_maxh();
  1765. f->fmt.pix.field = field;
  1766. v4l_bound_align_image(&f->fmt.pix.width, 48, maxw, 2,
  1767. &f->fmt.pix.height, 32, maxh, 0, 0);
  1768. f->fmt.pix.bytesperline =
  1769. (f->fmt.pix.width * fmt->depth) >> 3;
  1770. f->fmt.pix.sizeimage =
  1771. f->fmt.pix.height * f->fmt.pix.bytesperline;
  1772. return 0;
  1773. }
  1774. /*FIXME: This seems to be generic enough to be at videodev2 */
  1775. static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
  1776. struct v4l2_format *f)
  1777. {
  1778. struct gc2015_fh *fh = priv;
  1779. struct videobuf_queue *q = &fh->vb_vidq;
  1780. struct gc2015_device *dev = fh->dev;
  1781. int ret = vidioc_try_fmt_vid_cap(file, fh, f);
  1782. if (ret < 0)
  1783. return ret;
  1784. mutex_lock(&q->vb_lock);
  1785. if (videobuf_queue_is_busy(&fh->vb_vidq)) {
  1786. dprintk(fh->dev, 1, "%s queue busy\n", __func__);
  1787. ret = -EBUSY;
  1788. goto out;
  1789. }
  1790. fh->fmt = get_format(f);
  1791. fh->width = f->fmt.pix.width;
  1792. fh->height = f->fmt.pix.height;
  1793. fh->vb_vidq.field = f->fmt.pix.field;
  1794. fh->type = f->type;
  1795. #if 1
  1796. if(f->fmt.pix.pixelformat==V4L2_PIX_FMT_RGB24){
  1797. vidio_set_fmt_ticks=1;
  1798. gc2015_set_resolution(dev,fh->height,fh->width);
  1799. }
  1800. else if(vidio_set_fmt_ticks==1){
  1801. gc2015_set_resolution(dev,fh->height,fh->width);
  1802. }
  1803. #endif
  1804. #ifdef CONFIG_VIDEO_AMLOGIC_FLASHLIGHT
  1805. if (dev->platform_dev_data.flash_support) {
  1806. if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_RGB24) {
  1807. if (get_flashlightflag() == FLASHLIGHT_ON) {
  1808. set_flashlight(true);
  1809. }
  1810. } else if(f->fmt.pix.pixelformat == V4L2_PIX_FMT_NV21){
  1811. if (get_flashlightflag() != FLASHLIGHT_TORCH) {
  1812. set_flashlight(false);
  1813. }
  1814. }
  1815. }
  1816. #endif
  1817. ret = 0;
  1818. out:
  1819. mutex_unlock(&q->vb_lock);
  1820. return ret;
  1821. }
  1822. static int vidioc_reqbufs(struct file *file, void *priv,
  1823. struct v4l2_requestbuffers *p)
  1824. {
  1825. struct gc2015_fh *fh = priv;
  1826. return (videobuf_reqbufs(&fh->vb_vidq, p));
  1827. }
  1828. static int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
  1829. {
  1830. struct gc2015_fh *fh = priv;
  1831. return (videobuf_querybuf(&fh->vb_vidq, p));
  1832. }
  1833. static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
  1834. {
  1835. struct gc2015_fh *fh = priv;
  1836. return (videobuf_qbuf(&fh->vb_vidq, p));
  1837. }
  1838. static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
  1839. {
  1840. struct gc2015_fh *fh = priv;
  1841. return (videobuf_dqbuf(&fh->vb_vidq, p,
  1842. file->f_flags & O_NONBLOCK));
  1843. }
  1844. #ifdef CONFIG_VIDEO_V4L1_COMPAT
  1845. static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
  1846. {
  1847. struct gc2015_fh *fh = priv;
  1848. return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8);
  1849. }
  1850. #endif
  1851. static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
  1852. {
  1853. struct gc2015_fh *fh = priv;
  1854. tvin_parm_t para;
  1855. int ret = 0 ;
  1856. if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1857. return -EINVAL;
  1858. if (i != fh->type)
  1859. return -EINVAL;
  1860. para.port = TVIN_PORT_CAMERA;
  1861. para.fmt_info.fmt = TVIN_SIG_FMT_MAX+1;//TVIN_SIG_FMT_MAX+1;;TVIN_SIG_FMT_CAMERA_1280X720P_30Hz
  1862. para.fmt_info.frame_rate = 236;
  1863. para.fmt_info.h_active = gc2015_h_active;
  1864. para.fmt_info.v_active = gc2015_v_active;
  1865. para.fmt_info.hsync_phase = 1;
  1866. para.fmt_info.vsync_phase = 1;
  1867. ret = videobuf_streamon(&fh->vb_vidq);
  1868. if(ret == 0){
  1869. start_tvin_service(0,&para);
  1870. fh->stream_on = 1;
  1871. }
  1872. return ret;
  1873. }
  1874. static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
  1875. {
  1876. struct gc2015_fh *fh = priv;
  1877. int ret = 0 ;
  1878. printk(KERN_INFO " vidioc_streamoff+++ \n ");
  1879. if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1880. return -EINVAL;
  1881. if (i != fh->type)
  1882. return -EINVAL;
  1883. ret = videobuf_streamoff(&fh->vb_vidq);
  1884. if(ret == 0 ){
  1885. stop_tvin_service(0);
  1886. fh->stream_on = 0;
  1887. }
  1888. return ret;
  1889. }
  1890. static int vidioc_enum_framesizes(struct file *file, void *fh,struct v4l2_frmsizeenum *fsize)
  1891. {
  1892. int ret = 0,i=0;
  1893. struct gc2015_fmt *fmt = NULL;
  1894. struct v4l2_frmsize_discrete *frmsize = NULL;
  1895. for (i = 0; i < ARRAY_SIZE(formats); i++) {
  1896. if (formats[i].fourcc == fsize->pixel_format){
  1897. fmt = &formats[i];
  1898. break;
  1899. }
  1900. }
  1901. if (fmt == NULL)
  1902. return -EINVAL;
  1903. if (fmt->fourcc == V4L2_PIX_FMT_NV21){
  1904. if (fsize->index >= ARRAY_SIZE(gc2015_prev_resolution))
  1905. return -EINVAL;
  1906. frmsize = &gc2015_prev_resolution[fsize->index];
  1907. fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
  1908. fsize->discrete.width = frmsize->width;
  1909. fsize->discrete.height = frmsize->height;
  1910. }
  1911. else if(fmt->fourcc == V4L2_PIX_FMT_RGB24){
  1912. if (fsize->index >= ARRAY_SIZE(gc2015_pic_resolution))
  1913. return -EINVAL;
  1914. frmsize = &gc2015_pic_resolution[fsize->index];
  1915. fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
  1916. fsize->discrete.width = frmsize->width;
  1917. fsize->discrete.height = frmsize->height;
  1918. }
  1919. return ret;
  1920. }
  1921. static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i)
  1922. {
  1923. return 0;
  1924. }
  1925. /* only one input in this sample driver */
  1926. static int vidioc_enum_input(struct file *file, void *priv,
  1927. struct v4l2_input *inp)
  1928. {
  1929. //if (inp->index >= NUM_INPUTS)
  1930. //return -EINVAL;
  1931. inp->type = V4L2_INPUT_TYPE_CAMERA;
  1932. inp->std = V4L2_STD_525_60;
  1933. sprintf(inp->name, "Camera %u", inp->index);
  1934. return (0);
  1935. }
  1936. static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  1937. {
  1938. struct gc2015_fh *fh = priv;
  1939. struct gc2015_device *dev = fh->dev;
  1940. *i = dev->input;
  1941. return (0);
  1942. }
  1943. static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
  1944. {
  1945. struct gc2015_fh *fh = priv;
  1946. struct gc2015_device *dev = fh->dev;
  1947. //if (i >= NUM_INPUTS)
  1948. //return -EINVAL;
  1949. dev->input = i;
  1950. //precalculate_bars(fh);
  1951. return (0);
  1952. }
  1953. /* --- controls ---------------------------------------------- */
  1954. static int vidioc_queryctrl(struct file *file, void *priv,
  1955. struct v4l2_queryctrl *qc)
  1956. {
  1957. int i;
  1958. for (i = 0; i < ARRAY_SIZE(gc2015_qctrl); i++)
  1959. if (qc->id && qc->id == gc2015_qctrl[i].id) {
  1960. memcpy(qc, &(gc2015_qctrl[i]),
  1961. sizeof(*qc));
  1962. return (0);
  1963. }
  1964. return -EINVAL;
  1965. }
  1966. static int vidioc_g_ctrl(struct file *file, void *priv,
  1967. struct v4l2_control *ctrl)
  1968. {
  1969. struct gc2015_fh *fh = priv;
  1970. struct gc2015_device *dev = fh->dev;
  1971. int i;
  1972. for (i = 0; i < ARRAY_SIZE(gc2015_qctrl); i++)
  1973. if (ctrl->id == gc2015_qctrl[i].id) {
  1974. ctrl->value = dev->qctl_regs[i];
  1975. return 0;
  1976. }
  1977. return -EINVAL;
  1978. }
  1979. static int vidioc_s_ctrl(struct file *file, void *priv,
  1980. struct v4l2_control *ctrl)
  1981. {
  1982. struct gc2015_fh *fh = priv;
  1983. struct gc2015_device *dev = fh->dev;
  1984. int i;
  1985. for (i = 0; i < ARRAY_SIZE(gc2015_qctrl); i++)
  1986. if (ctrl->id == gc2015_qctrl[i].id) {
  1987. if (ctrl->value < gc2015_qctrl[i].minimum ||
  1988. ctrl->value > gc2015_qctrl[i].maximum ||
  1989. gc2015_setting(dev,ctrl->id,ctrl->value)<0) {
  1990. return -ERANGE;
  1991. }
  1992. dev->qctl_regs[i] = ctrl->value;
  1993. return 0;
  1994. }
  1995. return -EINVAL;
  1996. }
  1997. /* ------------------------------------------------------------------
  1998. File operations for the device
  1999. ------------------------------------------------------------------*/
  2000. static int gc2015_open(struct file *file)
  2001. {
  2002. struct gc2015_device *dev = video_drvdata(file);
  2003. struct gc2015_fh *fh = NULL;
  2004. int retval = 0;
  2005. #ifdef CONFIG_ARCH_MESON6
  2006. switch_mod_gate_by_name("ge2d", 1);
  2007. #endif
  2008. if(dev->platform_dev_data.device_init) {
  2009. dev->platform_dev_data.device_init();
  2010. printk("+++found a init function, and run it..\n");
  2011. }
  2012. gc2015_init_regs(dev);
  2013. msleep(40);
  2014. mutex_lock(&dev->mutex);
  2015. dev->users++;
  2016. if (dev->users > 1) {
  2017. dev->users--;
  2018. mutex_unlock(&dev->mutex);
  2019. return -EBUSY;
  2020. }
  2021. dprintk(dev, 1, "open %s type=%s users=%d\n",
  2022. video_device_node_name(dev->vdev),
  2023. v4l2_type_names[V4L2_BUF_TYPE_VIDEO_CAPTURE], dev->users);
  2024. /* init video dma queues */
  2025. INIT_LIST_HEAD(&dev->vidq.active);
  2026. init_waitqueue_head(&dev->vidq.wq);
  2027. spin_lock_init(&dev->slock);
  2028. /* allocate + initialize per filehandle data */
  2029. fh = kzalloc(sizeof(*fh), GFP_KERNEL);
  2030. if (NULL == fh) {
  2031. dev->users--;
  2032. retval = -ENOMEM;
  2033. }
  2034. mutex_unlock(&dev->mutex);
  2035. if (retval)
  2036. return retval;
  2037. file->private_data = fh;
  2038. fh->dev = dev;
  2039. fh->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  2040. fh->fmt = &formats[0];
  2041. fh->width = 800;
  2042. fh->height = 600;
  2043. fh->stream_on = 0 ;
  2044. /* Resets frame counters */
  2045. dev->jiffies = jiffies;
  2046. // TVIN_SIG_FMT_CAMERA_640X480P_30Hz,
  2047. // TVIN_SIG_FMT_CAMERA_800X600P_30Hz,
  2048. // TVIN_SIG_FMT_CAMERA_1024X768P_30Hz, // 190
  2049. // TVIN_SIG_FMT_CAMERA_1920X1080P_30Hz,
  2050. // TVIN_SIG_FMT_CAMERA_1280X720P_30Hz,
  2051. videobuf_queue_vmalloc_init(&fh->vb_vidq, &gc2015_video_qops,
  2052. NULL, &dev->slock, fh->type, V4L2_FIELD_INTERLACED,
  2053. sizeof(struct gc2015_buffer), fh,NULL);
  2054. gc2015_start_thread(fh);
  2055. return 0;
  2056. }
  2057. static ssize_t
  2058. gc2015_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
  2059. {
  2060. struct gc2015_fh *fh = file->private_data;
  2061. if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
  2062. return videobuf_read_stream(&fh->vb_vidq, data, count, ppos, 0,
  2063. file->f_flags & O_NONBLOCK);
  2064. }
  2065. return 0;
  2066. }
  2067. static unsigned int
  2068. gc2015_poll(struct file *file, struct poll_table_struct *wait)
  2069. {
  2070. struct gc2015_fh *fh = file->private_data;
  2071. struct gc2015_device *dev = fh->dev;
  2072. struct videobuf_queue *q = &fh->vb_vidq;
  2073. dprintk(dev, 1, "%s\n", __func__);
  2074. if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
  2075. return POLLERR;
  2076. return videobuf_poll_stream(file, q, wait);
  2077. }
  2078. static int gc2015_close(struct file *file)
  2079. {
  2080. struct gc2015_fh *fh = file->private_data;
  2081. struct gc2015_device *dev = fh->dev;
  2082. struct gc2015_dmaqueue *vidq = &dev->vidq;
  2083. struct video_device *vdev = video_devdata(file);
  2084. gc2015_stop_thread(vidq);
  2085. videobuf_stop(&fh->vb_vidq);
  2086. if(fh->stream_on){
  2087. stop_tvin_service(0);
  2088. }
  2089. videobuf_mmap_free(&fh->vb_vidq);
  2090. kfree(fh);
  2091. mutex_lock(&dev->mutex);
  2092. dev->users--;
  2093. mutex_unlock(&dev->mutex);
  2094. dprintk(dev, 1, "close called (dev=%s, users=%d)\n",
  2095. video_device_node_name(vdev), dev->users);
  2096. #if 1
  2097. gc2015_h_active=800;
  2098. gc2015_v_active=600;
  2099. gc2015_qctrl[0].default_value=0;
  2100. gc2015_qctrl[1].default_value=4;
  2101. gc2015_qctrl[2].default_value=0;
  2102. gc2015_qctrl[3].default_value=0;
  2103. gc2015_qctrl[4].default_value=0;
  2104. power_down_gc2015(dev);
  2105. #endif
  2106. msleep(10);
  2107. if(disable_gt2005>0){
  2108. disable_gt2005=0;
  2109. //printk("+++device_disable, and run it..\n");
  2110. if(dev->platform_dev_data.device_disable) {
  2111. dev->platform_dev_data.device_disable();
  2112. printk("+++found a disable function, and run it..\n");
  2113. }
  2114. }
  2115. else{
  2116. disable_gt2005=0;
  2117. if(dev->platform_dev_data.device_uninit) {
  2118. dev->platform_dev_data.device_uninit();
  2119. printk("+++found a uninit function, and run it..\n");
  2120. }
  2121. }
  2122. msleep(10);
  2123. #ifdef CONFIG_ARCH_MESON6
  2124. switch_mod_gate_by_name("ge2d", 0);
  2125. #endif
  2126. return 0;
  2127. }
  2128. static int gc2015_mmap(struct file *file, struct vm_area_struct *vma)
  2129. {
  2130. struct gc2015_fh *fh = file->private_data;
  2131. struct gc2015_device *dev = fh->dev;
  2132. int ret;
  2133. dprintk(dev, 1, "mmap called, vma=0x%08lx\n", (unsigned long)vma);
  2134. ret = videobuf_mmap_mapper(&fh->vb_vidq, vma);
  2135. dprintk(dev, 1, "vma start=0x%08lx, size=%ld, ret=%d\n",
  2136. (unsigned long)vma->vm_start,
  2137. (unsigned long)vma->vm_end-(unsigned long)vma->vm_start,
  2138. ret);
  2139. return ret;
  2140. }
  2141. static const struct v4l2_file_operations gc2015_fops = {
  2142. .owner = THIS_MODULE,
  2143. .open = gc2015_open,
  2144. .release = gc2015_close,
  2145. .read = gc2015_read,
  2146. .poll = gc2015_poll,
  2147. .ioctl = video_ioctl2, /* V4L2 ioctl handler */
  2148. .mmap = gc2015_mmap,
  2149. };
  2150. static const struct v4l2_ioctl_ops gc2015_ioctl_ops = {
  2151. .vidioc_querycap = vidioc_querycap,
  2152. .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  2153. .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  2154. .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  2155. .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  2156. .vidioc_reqbufs = vidioc_reqbufs,
  2157. .vidioc_querybuf = vidioc_querybuf,
  2158. .vidioc_qbuf = vidioc_qbuf,
  2159. .vidioc_dqbuf = vidioc_dqbuf,
  2160. .vidioc_s_std = vidioc_s_std,
  2161. .vidioc_enum_input = vidioc_enum_input,
  2162. .vidioc_g_input = vidioc_g_input,
  2163. .vidioc_s_input = vidioc_s_input,
  2164. .vidioc_queryctrl = vidioc_queryctrl,
  2165. .vidioc_g_ctrl = vidioc_g_ctrl,
  2166. .vidioc_s_ctrl = vidioc_s_ctrl,
  2167. .vidioc_streamon = vidioc_streamon,
  2168. .vidioc_streamoff = vidioc_streamoff,
  2169. .vidioc_enum_framesizes = vidioc_enum_framesizes,
  2170. #ifdef CONFIG_VIDEO_V4L1_COMPAT
  2171. .vidiocgmbuf = vidiocgmbuf,
  2172. #endif
  2173. };
  2174. static struct video_device gc2015_template = {
  2175. .name = "gc2015_v4l",
  2176. .fops = &gc2015_fops,
  2177. .ioctl_ops = &gc2015_ioctl_ops,
  2178. .release = video_device_release,
  2179. .tvnorms = V4L2_STD_525_60,
  2180. .current_norm = V4L2_STD_NTSC_M,
  2181. };
  2182. static int gc2015_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
  2183. {
  2184. struct i2c_client *client = v4l2_get_subdevdata(sd);
  2185. return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_GT2005, 0);
  2186. }
  2187. static const struct v4l2_subdev_core_ops gc2015_core_ops = {
  2188. .g_chip_ident = gc2015_g_chip_ident,
  2189. };
  2190. static const struct v4l2_subdev_ops gc2015_ops = {
  2191. .core = &gc2015_core_ops,
  2192. };
  2193. #ifdef CONFIG_HAS_EARLYSUSPEND
  2194. static void aml_gc2015_early_suspend(struct early_suspend *h)
  2195. {
  2196. printk("enter -----> %s \n",__FUNCTION__);
  2197. if(h && h->param) {
  2198. aml_plat_cam_data_t* plat_dat= (aml_plat_cam_data_t*)h->param;
  2199. if (plat_dat && plat_dat->early_suspend) {
  2200. plat_dat->early_suspend();
  2201. }
  2202. }
  2203. }
  2204. static void aml_gc2015_late_resume(struct early_suspend *h)
  2205. {
  2206. printk("enter -----> %s \n",__FUNCTION__);
  2207. if(h && h->param) {
  2208. aml_plat_cam_data_t* plat_dat= (aml_plat_cam_data_t*)h->param;
  2209. if (plat_dat && plat_dat->late_resume) {
  2210. plat_dat->late_resume();
  2211. }
  2212. }
  2213. }
  2214. #endif
  2215. static int gc2015_probe(struct i2c_client *client,
  2216. const struct i2c_device_id *id)
  2217. {
  2218. int err;
  2219. struct gc2015_device *t;
  2220. struct v4l2_subdev *sd;
  2221. aml_plat_cam_data_t* plat_dat;
  2222. v4l_info(client, "chip found @ 0x%x (%s)\n",
  2223. client->addr << 1, client->adapter->name);
  2224. t = kzalloc(sizeof(*t), GFP_KERNEL);
  2225. if (t == NULL)
  2226. return -ENOMEM;
  2227. sd = &t->sd;
  2228. v4l2_i2c_subdev_init(sd, client, &gc2015_ops);
  2229. mutex_init(&t->mutex);
  2230. /* Now create a video4linux device */
  2231. t->vdev = video_device_alloc();
  2232. if (t->vdev == NULL) {
  2233. kfree(t);
  2234. kfree(client);
  2235. return -ENOMEM;
  2236. }
  2237. memcpy(t->vdev, &gc2015_template, sizeof(*t->vdev));
  2238. video_set_drvdata(t->vdev, t);
  2239. /* Register it */
  2240. plat_dat= (aml_plat_cam_data_t*)client->dev.platform_data;
  2241. if (plat_dat) {
  2242. t->platform_dev_data.device_init=plat_dat->device_init;
  2243. t->platform_dev_data.device_uninit=plat_dat->device_uninit;
  2244. t->platform_dev_data.device_disable=plat_dat->device_disable;
  2245. t->platform_dev_data.flash_support=plat_dat->flash_support;
  2246. if(plat_dat->video_nr>=0) video_nr=plat_dat->video_nr;
  2247. }
  2248. err = video_register_device(t->vdev, VFL_TYPE_GRABBER, video_nr);
  2249. if (err < 0) {
  2250. video_device_release(t->vdev);
  2251. kfree(t);
  2252. return err;
  2253. }
  2254. #ifdef CONFIG_HAS_EARLYSUSPEND
  2255. printk("******* enter itk early suspend register *******\n");
  2256. gc2015_early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN;
  2257. gc2015_early_suspend.suspend = aml_gc2015_early_suspend;
  2258. gc2015_early_suspend.resume = aml_gc2015_late_resume;
  2259. gc2015_early_suspend.param = plat_dat;
  2260. register_early_suspend(&gc2015_early_suspend);
  2261. #endif
  2262. return 0;
  2263. }
  2264. static int gc2015_remove(struct i2c_client *client)
  2265. {
  2266. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  2267. struct gc2015_device *t = to_dev(sd);
  2268. video_unregister_device(t->vdev);
  2269. v4l2_device_unregister_subdev(sd);
  2270. kfree(t);
  2271. return 0;
  2272. }
  2273. static int gc2015_suspend(struct i2c_client *client, pm_message_t state)
  2274. {
  2275. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  2276. struct gc2015_device *t = to_dev(sd);
  2277. struct gc2015_fh *fh = to_fh(t);
  2278. if(fh->stream_on == 1){
  2279. stop_tvin_service(0);
  2280. }
  2281. power_down_gc2015(t);
  2282. return 0;
  2283. }
  2284. static int gc2015_resume(struct i2c_client *client)
  2285. {
  2286. struct v4l2_subdev *sd = i2c_get_clientdata(client);
  2287. struct gc2015_device *t = to_dev(sd);
  2288. struct gc2015_fh *fh = to_fh(t);
  2289. tvin_parm_t para;
  2290. para.port = TVIN_PORT_CAMERA;
  2291. para.fmt_info.fmt = TVIN_SIG_FMT_CAMERA_1280X720P_30Hz;
  2292. gc2015_init_regs(t);
  2293. if(fh->stream_on == 1){
  2294. start_tvin_service(0,&para);
  2295. }
  2296. return 0;
  2297. }
  2298. static const struct i2c_device_id gc2015_id[] = {
  2299. { "gc2015_i2c", 0 },
  2300. { }
  2301. };
  2302. MODULE_DEVICE_TABLE(i2c, gc2015_id);
  2303. static struct v4l2_i2c_driver_data v4l2_i2c_data = {
  2304. .name = "gc2015_i2c",
  2305. .probe = gc2015_probe,
  2306. .remove = gc2015_remove,
  2307. .suspend = gc2015_suspend,
  2308. .resume = gc2015_resume,
  2309. .id_table = gc2015_id,
  2310. };