isppreview.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102
  1. /*
  2. * isppreview.c
  3. *
  4. * TI OMAP3 ISP driver - Preview module
  5. *
  6. * Copyright (C) 2010 Nokia Corporation
  7. * Copyright (C) 2009 Texas Instruments, Inc.
  8. *
  9. * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  10. * Sakari Ailus <sakari.ailus@iki.fi>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  24. * 02110-1301 USA
  25. */
  26. #include <linux/device.h>
  27. #include <linux/mm.h>
  28. #include <linux/module.h>
  29. #include <linux/mutex.h>
  30. #include <linux/uaccess.h>
  31. #include "isp.h"
  32. #include "ispreg.h"
  33. #include "isppreview.h"
  34. /* Default values in Office Fluorescent Light for RGBtoRGB Blending */
  35. static struct omap3isp_prev_rgbtorgb flr_rgb2rgb = {
  36. { /* RGB-RGB Matrix */
  37. {0x01E2, 0x0F30, 0x0FEE},
  38. {0x0F9B, 0x01AC, 0x0FB9},
  39. {0x0FE0, 0x0EC0, 0x0260}
  40. }, /* RGB Offset */
  41. {0x0000, 0x0000, 0x0000}
  42. };
  43. /* Default values in Office Fluorescent Light for RGB to YUV Conversion*/
  44. static struct omap3isp_prev_csc flr_prev_csc = {
  45. { /* CSC Coef Matrix */
  46. {66, 129, 25},
  47. {-38, -75, 112},
  48. {112, -94 , -18}
  49. }, /* CSC Offset */
  50. {0x0, 0x0, 0x0}
  51. };
  52. /* Default values in Office Fluorescent Light for CFA Gradient*/
  53. #define FLR_CFA_GRADTHRS_HORZ 0x28
  54. #define FLR_CFA_GRADTHRS_VERT 0x28
  55. /* Default values in Office Fluorescent Light for Chroma Suppression*/
  56. #define FLR_CSUP_GAIN 0x0D
  57. #define FLR_CSUP_THRES 0xEB
  58. /* Default values in Office Fluorescent Light for Noise Filter*/
  59. #define FLR_NF_STRGTH 0x03
  60. /* Default values for White Balance */
  61. #define FLR_WBAL_DGAIN 0x100
  62. #define FLR_WBAL_COEF 0x20
  63. /* Default values in Office Fluorescent Light for Black Adjustment*/
  64. #define FLR_BLKADJ_BLUE 0x0
  65. #define FLR_BLKADJ_GREEN 0x0
  66. #define FLR_BLKADJ_RED 0x0
  67. #define DEF_DETECT_CORRECT_VAL 0xe
  68. #define PREV_MIN_IN_WIDTH 64
  69. #define PREV_MIN_IN_HEIGHT 8
  70. #define PREV_MAX_IN_HEIGHT 16384
  71. #define PREV_MIN_OUT_WIDTH 0
  72. #define PREV_MIN_OUT_HEIGHT 0
  73. #define PREV_MAX_OUT_WIDTH 1280
  74. #define PREV_MAX_OUT_WIDTH_ES2 3300
  75. #define PREV_MAX_OUT_WIDTH_3630 4096
  76. /*
  77. * Coeficient Tables for the submodules in Preview.
  78. * Array is initialised with the values from.the tables text file.
  79. */
  80. /*
  81. * CFA Filter Coefficient Table
  82. *
  83. */
  84. static u32 cfa_coef_table[] = {
  85. #include "cfa_coef_table.h"
  86. };
  87. /*
  88. * Default Gamma Correction Table - All components
  89. */
  90. static u32 gamma_table[] = {
  91. #include "gamma_table.h"
  92. };
  93. /*
  94. * Noise Filter Threshold table
  95. */
  96. static u32 noise_filter_table[] = {
  97. #include "noise_filter_table.h"
  98. };
  99. /*
  100. * Luminance Enhancement Table
  101. */
  102. static u32 luma_enhance_table[] = {
  103. #include "luma_enhance_table.h"
  104. };
  105. /*
  106. * preview_enable_invalaw - Enable/Disable Inverse A-Law module in Preview.
  107. * @enable: 1 - Reverse the A-Law done in CCDC.
  108. */
  109. static void
  110. preview_enable_invalaw(struct isp_prev_device *prev, u8 enable)
  111. {
  112. struct isp_device *isp = to_isp_device(prev);
  113. if (enable)
  114. isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  115. ISPPRV_PCR_WIDTH | ISPPRV_PCR_INVALAW);
  116. else
  117. isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  118. ISPPRV_PCR_WIDTH | ISPPRV_PCR_INVALAW);
  119. }
  120. /*
  121. * preview_enable_drkframe_capture - Enable/Disable of the darkframe capture.
  122. * @prev -
  123. * @enable: 1 - Enable, 0 - Disable
  124. *
  125. * NOTE: PRV_WSDR_ADDR and PRV_WADD_OFFSET must be set also
  126. * The process is applied for each captured frame.
  127. */
  128. static void
  129. preview_enable_drkframe_capture(struct isp_prev_device *prev, u8 enable)
  130. {
  131. struct isp_device *isp = to_isp_device(prev);
  132. if (enable)
  133. isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  134. ISPPRV_PCR_DRKFCAP);
  135. else
  136. isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  137. ISPPRV_PCR_DRKFCAP);
  138. }
  139. /*
  140. * preview_enable_drkframe - Enable/Disable of the darkframe subtract.
  141. * @enable: 1 - Acquires memory bandwidth since the pixels in each frame is
  142. * subtracted with the pixels in the current frame.
  143. *
  144. * The process is applied for each captured frame.
  145. */
  146. static void
  147. preview_enable_drkframe(struct isp_prev_device *prev, u8 enable)
  148. {
  149. struct isp_device *isp = to_isp_device(prev);
  150. if (enable)
  151. isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  152. ISPPRV_PCR_DRKFEN);
  153. else
  154. isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  155. ISPPRV_PCR_DRKFEN);
  156. }
  157. /*
  158. * preview_config_drkf_shadcomp - Configures shift value in shading comp.
  159. * @scomp_shtval: 3bit value of shift used in shading compensation.
  160. */
  161. static void
  162. preview_config_drkf_shadcomp(struct isp_prev_device *prev,
  163. const void *scomp_shtval)
  164. {
  165. struct isp_device *isp = to_isp_device(prev);
  166. const u32 *shtval = scomp_shtval;
  167. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  168. ISPPRV_PCR_SCOMP_SFT_MASK,
  169. *shtval << ISPPRV_PCR_SCOMP_SFT_SHIFT);
  170. }
  171. /*
  172. * preview_enable_hmed - Enables/Disables of the Horizontal Median Filter.
  173. * @enable: 1 - Enables Horizontal Median Filter.
  174. */
  175. static void
  176. preview_enable_hmed(struct isp_prev_device *prev, u8 enable)
  177. {
  178. struct isp_device *isp = to_isp_device(prev);
  179. if (enable)
  180. isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  181. ISPPRV_PCR_HMEDEN);
  182. else
  183. isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  184. ISPPRV_PCR_HMEDEN);
  185. }
  186. /*
  187. * preview_config_hmed - Configures the Horizontal Median Filter.
  188. * @prev_hmed: Structure containing the odd and even distance between the
  189. * pixels in the image along with the filter threshold.
  190. */
  191. static void
  192. preview_config_hmed(struct isp_prev_device *prev, const void *prev_hmed)
  193. {
  194. struct isp_device *isp = to_isp_device(prev);
  195. const struct omap3isp_prev_hmed *hmed = prev_hmed;
  196. isp_reg_writel(isp, (hmed->odddist == 1 ? 0 : ISPPRV_HMED_ODDDIST) |
  197. (hmed->evendist == 1 ? 0 : ISPPRV_HMED_EVENDIST) |
  198. (hmed->thres << ISPPRV_HMED_THRESHOLD_SHIFT),
  199. OMAP3_ISP_IOMEM_PREV, ISPPRV_HMED);
  200. }
  201. /*
  202. * preview_config_noisefilter - Configures the Noise Filter.
  203. * @prev_nf: Structure containing the noisefilter table, strength to be used
  204. * for the noise filter and the defect correction enable flag.
  205. */
  206. static void
  207. preview_config_noisefilter(struct isp_prev_device *prev, const void *prev_nf)
  208. {
  209. struct isp_device *isp = to_isp_device(prev);
  210. const struct omap3isp_prev_nf *nf = prev_nf;
  211. unsigned int i;
  212. isp_reg_writel(isp, nf->spread, OMAP3_ISP_IOMEM_PREV, ISPPRV_NF);
  213. isp_reg_writel(isp, ISPPRV_NF_TABLE_ADDR,
  214. OMAP3_ISP_IOMEM_PREV, ISPPRV_SET_TBL_ADDR);
  215. for (i = 0; i < OMAP3ISP_PREV_NF_TBL_SIZE; i++) {
  216. isp_reg_writel(isp, nf->table[i],
  217. OMAP3_ISP_IOMEM_PREV, ISPPRV_SET_TBL_DATA);
  218. }
  219. }
  220. /*
  221. * preview_config_dcor - Configures the defect correction
  222. * @prev_dcor: Structure containing the defect correct thresholds
  223. */
  224. static void
  225. preview_config_dcor(struct isp_prev_device *prev, const void *prev_dcor)
  226. {
  227. struct isp_device *isp = to_isp_device(prev);
  228. const struct omap3isp_prev_dcor *dcor = prev_dcor;
  229. isp_reg_writel(isp, dcor->detect_correct[0],
  230. OMAP3_ISP_IOMEM_PREV, ISPPRV_CDC_THR0);
  231. isp_reg_writel(isp, dcor->detect_correct[1],
  232. OMAP3_ISP_IOMEM_PREV, ISPPRV_CDC_THR1);
  233. isp_reg_writel(isp, dcor->detect_correct[2],
  234. OMAP3_ISP_IOMEM_PREV, ISPPRV_CDC_THR2);
  235. isp_reg_writel(isp, dcor->detect_correct[3],
  236. OMAP3_ISP_IOMEM_PREV, ISPPRV_CDC_THR3);
  237. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  238. ISPPRV_PCR_DCCOUP,
  239. dcor->couplet_mode_en ? ISPPRV_PCR_DCCOUP : 0);
  240. }
  241. /*
  242. * preview_config_cfa - Configures the CFA Interpolation parameters.
  243. * @prev_cfa: Structure containing the CFA interpolation table, CFA format
  244. * in the image, vertical and horizontal gradient threshold.
  245. */
  246. static void
  247. preview_config_cfa(struct isp_prev_device *prev, const void *prev_cfa)
  248. {
  249. struct isp_device *isp = to_isp_device(prev);
  250. const struct omap3isp_prev_cfa *cfa = prev_cfa;
  251. unsigned int i;
  252. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  253. ISPPRV_PCR_CFAFMT_MASK,
  254. cfa->format << ISPPRV_PCR_CFAFMT_SHIFT);
  255. isp_reg_writel(isp,
  256. (cfa->gradthrs_vert << ISPPRV_CFA_GRADTH_VER_SHIFT) |
  257. (cfa->gradthrs_horz << ISPPRV_CFA_GRADTH_HOR_SHIFT),
  258. OMAP3_ISP_IOMEM_PREV, ISPPRV_CFA);
  259. isp_reg_writel(isp, ISPPRV_CFA_TABLE_ADDR,
  260. OMAP3_ISP_IOMEM_PREV, ISPPRV_SET_TBL_ADDR);
  261. for (i = 0; i < OMAP3ISP_PREV_CFA_TBL_SIZE; i++) {
  262. isp_reg_writel(isp, cfa->table[i],
  263. OMAP3_ISP_IOMEM_PREV, ISPPRV_SET_TBL_DATA);
  264. }
  265. }
  266. /*
  267. * preview_config_gammacorrn - Configures the Gamma Correction table values
  268. * @gtable: Structure containing the table for red, blue, green gamma table.
  269. */
  270. static void
  271. preview_config_gammacorrn(struct isp_prev_device *prev, const void *gtable)
  272. {
  273. struct isp_device *isp = to_isp_device(prev);
  274. const struct omap3isp_prev_gtables *gt = gtable;
  275. unsigned int i;
  276. isp_reg_writel(isp, ISPPRV_REDGAMMA_TABLE_ADDR,
  277. OMAP3_ISP_IOMEM_PREV, ISPPRV_SET_TBL_ADDR);
  278. for (i = 0; i < OMAP3ISP_PREV_GAMMA_TBL_SIZE; i++)
  279. isp_reg_writel(isp, gt->red[i], OMAP3_ISP_IOMEM_PREV,
  280. ISPPRV_SET_TBL_DATA);
  281. isp_reg_writel(isp, ISPPRV_GREENGAMMA_TABLE_ADDR,
  282. OMAP3_ISP_IOMEM_PREV, ISPPRV_SET_TBL_ADDR);
  283. for (i = 0; i < OMAP3ISP_PREV_GAMMA_TBL_SIZE; i++)
  284. isp_reg_writel(isp, gt->green[i], OMAP3_ISP_IOMEM_PREV,
  285. ISPPRV_SET_TBL_DATA);
  286. isp_reg_writel(isp, ISPPRV_BLUEGAMMA_TABLE_ADDR,
  287. OMAP3_ISP_IOMEM_PREV, ISPPRV_SET_TBL_ADDR);
  288. for (i = 0; i < OMAP3ISP_PREV_GAMMA_TBL_SIZE; i++)
  289. isp_reg_writel(isp, gt->blue[i], OMAP3_ISP_IOMEM_PREV,
  290. ISPPRV_SET_TBL_DATA);
  291. }
  292. /*
  293. * preview_config_luma_enhancement - Sets the Luminance Enhancement table.
  294. * @ytable: Structure containing the table for Luminance Enhancement table.
  295. */
  296. static void
  297. preview_config_luma_enhancement(struct isp_prev_device *prev,
  298. const void *ytable)
  299. {
  300. struct isp_device *isp = to_isp_device(prev);
  301. const struct omap3isp_prev_luma *yt = ytable;
  302. unsigned int i;
  303. isp_reg_writel(isp, ISPPRV_YENH_TABLE_ADDR,
  304. OMAP3_ISP_IOMEM_PREV, ISPPRV_SET_TBL_ADDR);
  305. for (i = 0; i < OMAP3ISP_PREV_YENH_TBL_SIZE; i++) {
  306. isp_reg_writel(isp, yt->table[i],
  307. OMAP3_ISP_IOMEM_PREV, ISPPRV_SET_TBL_DATA);
  308. }
  309. }
  310. /*
  311. * preview_config_chroma_suppression - Configures the Chroma Suppression.
  312. * @csup: Structure containing the threshold value for suppression
  313. * and the hypass filter enable flag.
  314. */
  315. static void
  316. preview_config_chroma_suppression(struct isp_prev_device *prev,
  317. const void *csup)
  318. {
  319. struct isp_device *isp = to_isp_device(prev);
  320. const struct omap3isp_prev_csup *cs = csup;
  321. isp_reg_writel(isp,
  322. cs->gain | (cs->thres << ISPPRV_CSUP_THRES_SHIFT) |
  323. (cs->hypf_en << ISPPRV_CSUP_HPYF_SHIFT),
  324. OMAP3_ISP_IOMEM_PREV, ISPPRV_CSUP);
  325. }
  326. /*
  327. * preview_enable_noisefilter - Enables/Disables the Noise Filter.
  328. * @enable: 1 - Enables the Noise Filter.
  329. */
  330. static void
  331. preview_enable_noisefilter(struct isp_prev_device *prev, u8 enable)
  332. {
  333. struct isp_device *isp = to_isp_device(prev);
  334. if (enable)
  335. isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  336. ISPPRV_PCR_NFEN);
  337. else
  338. isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  339. ISPPRV_PCR_NFEN);
  340. }
  341. /*
  342. * preview_enable_dcor - Enables/Disables the defect correction.
  343. * @enable: 1 - Enables the defect correction.
  344. */
  345. static void
  346. preview_enable_dcor(struct isp_prev_device *prev, u8 enable)
  347. {
  348. struct isp_device *isp = to_isp_device(prev);
  349. if (enable)
  350. isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  351. ISPPRV_PCR_DCOREN);
  352. else
  353. isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  354. ISPPRV_PCR_DCOREN);
  355. }
  356. /*
  357. * preview_enable_cfa - Enable/Disable the CFA Interpolation.
  358. * @enable: 1 - Enables the CFA.
  359. */
  360. static void
  361. preview_enable_cfa(struct isp_prev_device *prev, u8 enable)
  362. {
  363. struct isp_device *isp = to_isp_device(prev);
  364. if (enable)
  365. isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  366. ISPPRV_PCR_CFAEN);
  367. else
  368. isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  369. ISPPRV_PCR_CFAEN);
  370. }
  371. /*
  372. * preview_enable_gammabypass - Enables/Disables the GammaByPass
  373. * @enable: 1 - Bypasses Gamma - 10bit input is cropped to 8MSB.
  374. * 0 - Goes through Gamma Correction. input and output is 10bit.
  375. */
  376. static void
  377. preview_enable_gammabypass(struct isp_prev_device *prev, u8 enable)
  378. {
  379. struct isp_device *isp = to_isp_device(prev);
  380. if (enable)
  381. isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  382. ISPPRV_PCR_GAMMA_BYPASS);
  383. else
  384. isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  385. ISPPRV_PCR_GAMMA_BYPASS);
  386. }
  387. /*
  388. * preview_enable_luma_enhancement - Enables/Disables Luminance Enhancement
  389. * @enable: 1 - Enable the Luminance Enhancement.
  390. */
  391. static void
  392. preview_enable_luma_enhancement(struct isp_prev_device *prev, u8 enable)
  393. {
  394. struct isp_device *isp = to_isp_device(prev);
  395. if (enable)
  396. isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  397. ISPPRV_PCR_YNENHEN);
  398. else
  399. isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  400. ISPPRV_PCR_YNENHEN);
  401. }
  402. /*
  403. * preview_enable_chroma_suppression - Enables/Disables Chrominance Suppr.
  404. * @enable: 1 - Enable the Chrominance Suppression.
  405. */
  406. static void
  407. preview_enable_chroma_suppression(struct isp_prev_device *prev, u8 enable)
  408. {
  409. struct isp_device *isp = to_isp_device(prev);
  410. if (enable)
  411. isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  412. ISPPRV_PCR_SUPEN);
  413. else
  414. isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  415. ISPPRV_PCR_SUPEN);
  416. }
  417. /*
  418. * preview_config_whitebalance - Configures the White Balance parameters.
  419. * @prev_wbal: Structure containing the digital gain and white balance
  420. * coefficient.
  421. *
  422. * Coefficient matrix always with default values.
  423. */
  424. static void
  425. preview_config_whitebalance(struct isp_prev_device *prev, const void *prev_wbal)
  426. {
  427. struct isp_device *isp = to_isp_device(prev);
  428. const struct omap3isp_prev_wbal *wbal = prev_wbal;
  429. u32 val;
  430. isp_reg_writel(isp, wbal->dgain, OMAP3_ISP_IOMEM_PREV, ISPPRV_WB_DGAIN);
  431. val = wbal->coef0 << ISPPRV_WBGAIN_COEF0_SHIFT;
  432. val |= wbal->coef1 << ISPPRV_WBGAIN_COEF1_SHIFT;
  433. val |= wbal->coef2 << ISPPRV_WBGAIN_COEF2_SHIFT;
  434. val |= wbal->coef3 << ISPPRV_WBGAIN_COEF3_SHIFT;
  435. isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_WBGAIN);
  436. isp_reg_writel(isp,
  437. ISPPRV_WBSEL_COEF0 << ISPPRV_WBSEL_N0_0_SHIFT |
  438. ISPPRV_WBSEL_COEF1 << ISPPRV_WBSEL_N0_1_SHIFT |
  439. ISPPRV_WBSEL_COEF0 << ISPPRV_WBSEL_N0_2_SHIFT |
  440. ISPPRV_WBSEL_COEF1 << ISPPRV_WBSEL_N0_3_SHIFT |
  441. ISPPRV_WBSEL_COEF2 << ISPPRV_WBSEL_N1_0_SHIFT |
  442. ISPPRV_WBSEL_COEF3 << ISPPRV_WBSEL_N1_1_SHIFT |
  443. ISPPRV_WBSEL_COEF2 << ISPPRV_WBSEL_N1_2_SHIFT |
  444. ISPPRV_WBSEL_COEF3 << ISPPRV_WBSEL_N1_3_SHIFT |
  445. ISPPRV_WBSEL_COEF0 << ISPPRV_WBSEL_N2_0_SHIFT |
  446. ISPPRV_WBSEL_COEF1 << ISPPRV_WBSEL_N2_1_SHIFT |
  447. ISPPRV_WBSEL_COEF0 << ISPPRV_WBSEL_N2_2_SHIFT |
  448. ISPPRV_WBSEL_COEF1 << ISPPRV_WBSEL_N2_3_SHIFT |
  449. ISPPRV_WBSEL_COEF2 << ISPPRV_WBSEL_N3_0_SHIFT |
  450. ISPPRV_WBSEL_COEF3 << ISPPRV_WBSEL_N3_1_SHIFT |
  451. ISPPRV_WBSEL_COEF2 << ISPPRV_WBSEL_N3_2_SHIFT |
  452. ISPPRV_WBSEL_COEF3 << ISPPRV_WBSEL_N3_3_SHIFT,
  453. OMAP3_ISP_IOMEM_PREV, ISPPRV_WBSEL);
  454. }
  455. /*
  456. * preview_config_blkadj - Configures the Black Adjustment parameters.
  457. * @prev_blkadj: Structure containing the black adjustment towards red, green,
  458. * blue.
  459. */
  460. static void
  461. preview_config_blkadj(struct isp_prev_device *prev, const void *prev_blkadj)
  462. {
  463. struct isp_device *isp = to_isp_device(prev);
  464. const struct omap3isp_prev_blkadj *blkadj = prev_blkadj;
  465. isp_reg_writel(isp, (blkadj->blue << ISPPRV_BLKADJOFF_B_SHIFT) |
  466. (blkadj->green << ISPPRV_BLKADJOFF_G_SHIFT) |
  467. (blkadj->red << ISPPRV_BLKADJOFF_R_SHIFT),
  468. OMAP3_ISP_IOMEM_PREV, ISPPRV_BLKADJOFF);
  469. }
  470. /*
  471. * preview_config_rgb_blending - Configures the RGB-RGB Blending matrix.
  472. * @rgb2rgb: Structure containing the rgb to rgb blending matrix and the rgb
  473. * offset.
  474. */
  475. static void
  476. preview_config_rgb_blending(struct isp_prev_device *prev, const void *rgb2rgb)
  477. {
  478. struct isp_device *isp = to_isp_device(prev);
  479. const struct omap3isp_prev_rgbtorgb *rgbrgb = rgb2rgb;
  480. u32 val;
  481. val = (rgbrgb->matrix[0][0] & 0xfff) << ISPPRV_RGB_MAT1_MTX_RR_SHIFT;
  482. val |= (rgbrgb->matrix[0][1] & 0xfff) << ISPPRV_RGB_MAT1_MTX_GR_SHIFT;
  483. isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_MAT1);
  484. val = (rgbrgb->matrix[0][2] & 0xfff) << ISPPRV_RGB_MAT2_MTX_BR_SHIFT;
  485. val |= (rgbrgb->matrix[1][0] & 0xfff) << ISPPRV_RGB_MAT2_MTX_RG_SHIFT;
  486. isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_MAT2);
  487. val = (rgbrgb->matrix[1][1] & 0xfff) << ISPPRV_RGB_MAT3_MTX_GG_SHIFT;
  488. val |= (rgbrgb->matrix[1][2] & 0xfff) << ISPPRV_RGB_MAT3_MTX_BG_SHIFT;
  489. isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_MAT3);
  490. val = (rgbrgb->matrix[2][0] & 0xfff) << ISPPRV_RGB_MAT4_MTX_RB_SHIFT;
  491. val |= (rgbrgb->matrix[2][1] & 0xfff) << ISPPRV_RGB_MAT4_MTX_GB_SHIFT;
  492. isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_MAT4);
  493. val = (rgbrgb->matrix[2][2] & 0xfff) << ISPPRV_RGB_MAT5_MTX_BB_SHIFT;
  494. isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_MAT5);
  495. val = (rgbrgb->offset[0] & 0x3ff) << ISPPRV_RGB_OFF1_MTX_OFFR_SHIFT;
  496. val |= (rgbrgb->offset[1] & 0x3ff) << ISPPRV_RGB_OFF1_MTX_OFFG_SHIFT;
  497. isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_OFF1);
  498. val = (rgbrgb->offset[2] & 0x3ff) << ISPPRV_RGB_OFF2_MTX_OFFB_SHIFT;
  499. isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_RGB_OFF2);
  500. }
  501. /*
  502. * Configures the RGB-YCbYCr conversion matrix
  503. * @prev_csc: Structure containing the RGB to YCbYCr matrix and the
  504. * YCbCr offset.
  505. */
  506. static void
  507. preview_config_rgb_to_ycbcr(struct isp_prev_device *prev, const void *prev_csc)
  508. {
  509. struct isp_device *isp = to_isp_device(prev);
  510. const struct omap3isp_prev_csc *csc = prev_csc;
  511. u32 val;
  512. val = (csc->matrix[0][0] & 0x3ff) << ISPPRV_CSC0_RY_SHIFT;
  513. val |= (csc->matrix[0][1] & 0x3ff) << ISPPRV_CSC0_GY_SHIFT;
  514. val |= (csc->matrix[0][2] & 0x3ff) << ISPPRV_CSC0_BY_SHIFT;
  515. isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_CSC0);
  516. val = (csc->matrix[1][0] & 0x3ff) << ISPPRV_CSC1_RCB_SHIFT;
  517. val |= (csc->matrix[1][1] & 0x3ff) << ISPPRV_CSC1_GCB_SHIFT;
  518. val |= (csc->matrix[1][2] & 0x3ff) << ISPPRV_CSC1_BCB_SHIFT;
  519. isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_CSC1);
  520. val = (csc->matrix[2][0] & 0x3ff) << ISPPRV_CSC2_RCR_SHIFT;
  521. val |= (csc->matrix[2][1] & 0x3ff) << ISPPRV_CSC2_GCR_SHIFT;
  522. val |= (csc->matrix[2][2] & 0x3ff) << ISPPRV_CSC2_BCR_SHIFT;
  523. isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_CSC2);
  524. val = (csc->offset[0] & 0xff) << ISPPRV_CSC_OFFSET_Y_SHIFT;
  525. val |= (csc->offset[1] & 0xff) << ISPPRV_CSC_OFFSET_CB_SHIFT;
  526. val |= (csc->offset[2] & 0xff) << ISPPRV_CSC_OFFSET_CR_SHIFT;
  527. isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_PREV, ISPPRV_CSC_OFFSET);
  528. }
  529. /*
  530. * preview_update_contrast - Updates the contrast.
  531. * @contrast: Pointer to hold the current programmed contrast value.
  532. *
  533. * Value should be programmed before enabling the module.
  534. */
  535. static void
  536. preview_update_contrast(struct isp_prev_device *prev, u8 contrast)
  537. {
  538. struct prev_params *params = &prev->params;
  539. if (params->contrast != (contrast * ISPPRV_CONTRAST_UNITS)) {
  540. params->contrast = contrast * ISPPRV_CONTRAST_UNITS;
  541. prev->update |= PREV_CONTRAST;
  542. }
  543. }
  544. /*
  545. * preview_config_contrast - Configures the Contrast.
  546. * @params: Contrast value (u8 pointer, U8Q0 format).
  547. *
  548. * Value should be programmed before enabling the module.
  549. */
  550. static void
  551. preview_config_contrast(struct isp_prev_device *prev, const void *params)
  552. {
  553. struct isp_device *isp = to_isp_device(prev);
  554. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_CNT_BRT,
  555. 0xff << ISPPRV_CNT_BRT_CNT_SHIFT,
  556. *(u8 *)params << ISPPRV_CNT_BRT_CNT_SHIFT);
  557. }
  558. /*
  559. * preview_update_brightness - Updates the brightness in preview module.
  560. * @brightness: Pointer to hold the current programmed brightness value.
  561. *
  562. */
  563. static void
  564. preview_update_brightness(struct isp_prev_device *prev, u8 brightness)
  565. {
  566. struct prev_params *params = &prev->params;
  567. if (params->brightness != (brightness * ISPPRV_BRIGHT_UNITS)) {
  568. params->brightness = brightness * ISPPRV_BRIGHT_UNITS;
  569. prev->update |= PREV_BRIGHTNESS;
  570. }
  571. }
  572. /*
  573. * preview_config_brightness - Configures the brightness.
  574. * @params: Brightness value (u8 pointer, U8Q0 format).
  575. */
  576. static void
  577. preview_config_brightness(struct isp_prev_device *prev, const void *params)
  578. {
  579. struct isp_device *isp = to_isp_device(prev);
  580. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_CNT_BRT,
  581. 0xff << ISPPRV_CNT_BRT_BRT_SHIFT,
  582. *(u8 *)params << ISPPRV_CNT_BRT_BRT_SHIFT);
  583. }
  584. /*
  585. * preview_config_yc_range - Configures the max and min Y and C values.
  586. * @yclimit: Structure containing the range of Y and C values.
  587. */
  588. static void
  589. preview_config_yc_range(struct isp_prev_device *prev, const void *yclimit)
  590. {
  591. struct isp_device *isp = to_isp_device(prev);
  592. const struct omap3isp_prev_yclimit *yc = yclimit;
  593. isp_reg_writel(isp,
  594. yc->maxC << ISPPRV_SETUP_YC_MAXC_SHIFT |
  595. yc->maxY << ISPPRV_SETUP_YC_MAXY_SHIFT |
  596. yc->minC << ISPPRV_SETUP_YC_MINC_SHIFT |
  597. yc->minY << ISPPRV_SETUP_YC_MINY_SHIFT,
  598. OMAP3_ISP_IOMEM_PREV, ISPPRV_SETUP_YC);
  599. }
  600. /* preview parameters update structure */
  601. struct preview_update {
  602. int cfg_bit;
  603. int feature_bit;
  604. void (*config)(struct isp_prev_device *, const void *);
  605. void (*enable)(struct isp_prev_device *, u8);
  606. };
  607. static struct preview_update update_attrs[] = {
  608. {OMAP3ISP_PREV_LUMAENH, PREV_LUMA_ENHANCE,
  609. preview_config_luma_enhancement,
  610. preview_enable_luma_enhancement},
  611. {OMAP3ISP_PREV_INVALAW, PREV_INVERSE_ALAW,
  612. NULL,
  613. preview_enable_invalaw},
  614. {OMAP3ISP_PREV_HRZ_MED, PREV_HORZ_MEDIAN_FILTER,
  615. preview_config_hmed,
  616. preview_enable_hmed},
  617. {OMAP3ISP_PREV_CFA, PREV_CFA,
  618. preview_config_cfa,
  619. preview_enable_cfa},
  620. {OMAP3ISP_PREV_CHROMA_SUPP, PREV_CHROMA_SUPPRESS,
  621. preview_config_chroma_suppression,
  622. preview_enable_chroma_suppression},
  623. {OMAP3ISP_PREV_WB, PREV_WB,
  624. preview_config_whitebalance,
  625. NULL},
  626. {OMAP3ISP_PREV_BLKADJ, PREV_BLKADJ,
  627. preview_config_blkadj,
  628. NULL},
  629. {OMAP3ISP_PREV_RGB2RGB, PREV_RGB2RGB,
  630. preview_config_rgb_blending,
  631. NULL},
  632. {OMAP3ISP_PREV_COLOR_CONV, PREV_COLOR_CONV,
  633. preview_config_rgb_to_ycbcr,
  634. NULL},
  635. {OMAP3ISP_PREV_YC_LIMIT, PREV_YCLIMITS,
  636. preview_config_yc_range,
  637. NULL},
  638. {OMAP3ISP_PREV_DEFECT_COR, PREV_DEFECT_COR,
  639. preview_config_dcor,
  640. preview_enable_dcor},
  641. {OMAP3ISP_PREV_GAMMABYPASS, PREV_GAMMA_BYPASS,
  642. NULL,
  643. preview_enable_gammabypass},
  644. {OMAP3ISP_PREV_DRK_FRM_CAPTURE, PREV_DARK_FRAME_CAPTURE,
  645. NULL,
  646. preview_enable_drkframe_capture},
  647. {OMAP3ISP_PREV_DRK_FRM_SUBTRACT, PREV_DARK_FRAME_SUBTRACT,
  648. NULL,
  649. preview_enable_drkframe},
  650. {OMAP3ISP_PREV_LENS_SHADING, PREV_LENS_SHADING,
  651. preview_config_drkf_shadcomp,
  652. preview_enable_drkframe},
  653. {OMAP3ISP_PREV_NF, PREV_NOISE_FILTER,
  654. preview_config_noisefilter,
  655. preview_enable_noisefilter},
  656. {OMAP3ISP_PREV_GAMMA, PREV_GAMMA,
  657. preview_config_gammacorrn,
  658. NULL},
  659. {-1, PREV_CONTRAST,
  660. preview_config_contrast,
  661. NULL},
  662. {-1, PREV_BRIGHTNESS,
  663. preview_config_brightness,
  664. NULL},
  665. };
  666. /*
  667. * __preview_get_ptrs - helper function which return pointers to members
  668. * of params and config structures.
  669. * @params - pointer to preview_params structure.
  670. * @param - return pointer to appropriate structure field.
  671. * @configs - pointer to update config structure.
  672. * @config - return pointer to appropriate structure field.
  673. * @bit - for which feature to return pointers.
  674. * Return size of corresponding prev_params member
  675. */
  676. static u32
  677. __preview_get_ptrs(struct prev_params *params, void **param,
  678. struct omap3isp_prev_update_config *configs,
  679. void __user **config, u32 bit)
  680. {
  681. #define CHKARG(cfgs, cfg, field) \
  682. if (cfgs && cfg) { \
  683. *(cfg) = (cfgs)->field; \
  684. }
  685. switch (bit) {
  686. case PREV_HORZ_MEDIAN_FILTER:
  687. *param = &params->hmed;
  688. CHKARG(configs, config, hmed)
  689. return sizeof(params->hmed);
  690. case PREV_NOISE_FILTER:
  691. *param = &params->nf;
  692. CHKARG(configs, config, nf)
  693. return sizeof(params->nf);
  694. break;
  695. case PREV_CFA:
  696. *param = &params->cfa;
  697. CHKARG(configs, config, cfa)
  698. return sizeof(params->cfa);
  699. case PREV_LUMA_ENHANCE:
  700. *param = &params->luma;
  701. CHKARG(configs, config, luma)
  702. return sizeof(params->luma);
  703. case PREV_CHROMA_SUPPRESS:
  704. *param = &params->csup;
  705. CHKARG(configs, config, csup)
  706. return sizeof(params->csup);
  707. case PREV_DEFECT_COR:
  708. *param = &params->dcor;
  709. CHKARG(configs, config, dcor)
  710. return sizeof(params->dcor);
  711. case PREV_BLKADJ:
  712. *param = &params->blk_adj;
  713. CHKARG(configs, config, blkadj)
  714. return sizeof(params->blk_adj);
  715. case PREV_YCLIMITS:
  716. *param = &params->yclimit;
  717. CHKARG(configs, config, yclimit)
  718. return sizeof(params->yclimit);
  719. case PREV_RGB2RGB:
  720. *param = &params->rgb2rgb;
  721. CHKARG(configs, config, rgb2rgb)
  722. return sizeof(params->rgb2rgb);
  723. case PREV_COLOR_CONV:
  724. *param = &params->rgb2ycbcr;
  725. CHKARG(configs, config, csc)
  726. return sizeof(params->rgb2ycbcr);
  727. case PREV_WB:
  728. *param = &params->wbal;
  729. CHKARG(configs, config, wbal)
  730. return sizeof(params->wbal);
  731. case PREV_GAMMA:
  732. *param = &params->gamma;
  733. CHKARG(configs, config, gamma)
  734. return sizeof(params->gamma);
  735. case PREV_CONTRAST:
  736. *param = &params->contrast;
  737. return 0;
  738. case PREV_BRIGHTNESS:
  739. *param = &params->brightness;
  740. return 0;
  741. default:
  742. *param = NULL;
  743. *config = NULL;
  744. break;
  745. }
  746. return 0;
  747. }
  748. /*
  749. * preview_config - Copy and update local structure with userspace preview
  750. * configuration.
  751. * @prev: ISP preview engine
  752. * @cfg: Configuration
  753. *
  754. * Return zero if success or -EFAULT if the configuration can't be copied from
  755. * userspace.
  756. */
  757. static int preview_config(struct isp_prev_device *prev,
  758. struct omap3isp_prev_update_config *cfg)
  759. {
  760. struct prev_params *params;
  761. struct preview_update *attr;
  762. int i, bit, rval = 0;
  763. params = &prev->params;
  764. if (prev->state != ISP_PIPELINE_STREAM_STOPPED) {
  765. unsigned long flags;
  766. spin_lock_irqsave(&prev->lock, flags);
  767. prev->shadow_update = 1;
  768. spin_unlock_irqrestore(&prev->lock, flags);
  769. }
  770. for (i = 0; i < ARRAY_SIZE(update_attrs); i++) {
  771. attr = &update_attrs[i];
  772. bit = 0;
  773. if (!(cfg->update & attr->cfg_bit))
  774. continue;
  775. bit = cfg->flag & attr->cfg_bit;
  776. if (bit) {
  777. void *to = NULL, __user *from = NULL;
  778. unsigned long sz = 0;
  779. sz = __preview_get_ptrs(params, &to, cfg, &from,
  780. bit);
  781. if (to && from && sz) {
  782. if (copy_from_user(to, from, sz)) {
  783. rval = -EFAULT;
  784. break;
  785. }
  786. }
  787. params->features |= attr->feature_bit;
  788. } else {
  789. params->features &= ~attr->feature_bit;
  790. }
  791. prev->update |= attr->feature_bit;
  792. }
  793. prev->shadow_update = 0;
  794. return rval;
  795. }
  796. /*
  797. * preview_setup_hw - Setup preview registers and/or internal memory
  798. * @prev: pointer to preview private structure
  799. * Note: can be called from interrupt context
  800. * Return none
  801. */
  802. static void preview_setup_hw(struct isp_prev_device *prev)
  803. {
  804. struct prev_params *params = &prev->params;
  805. struct preview_update *attr;
  806. int i, bit;
  807. void *param_ptr;
  808. for (i = 0; i < ARRAY_SIZE(update_attrs); i++) {
  809. attr = &update_attrs[i];
  810. if (!(prev->update & attr->feature_bit))
  811. continue;
  812. bit = params->features & attr->feature_bit;
  813. if (bit) {
  814. if (attr->config) {
  815. __preview_get_ptrs(params, &param_ptr, NULL,
  816. NULL, bit);
  817. attr->config(prev, param_ptr);
  818. }
  819. if (attr->enable)
  820. attr->enable(prev, 1);
  821. } else
  822. if (attr->enable)
  823. attr->enable(prev, 0);
  824. prev->update &= ~attr->feature_bit;
  825. }
  826. }
  827. /*
  828. * preview_config_ycpos - Configure byte layout of YUV image.
  829. * @mode: Indicates the required byte layout.
  830. */
  831. static void
  832. preview_config_ycpos(struct isp_prev_device *prev,
  833. enum v4l2_mbus_pixelcode pixelcode)
  834. {
  835. struct isp_device *isp = to_isp_device(prev);
  836. enum preview_ycpos_mode mode;
  837. switch (pixelcode) {
  838. case V4L2_MBUS_FMT_YUYV8_1X16:
  839. mode = YCPOS_CrYCbY;
  840. break;
  841. case V4L2_MBUS_FMT_UYVY8_1X16:
  842. mode = YCPOS_YCrYCb;
  843. break;
  844. default:
  845. return;
  846. }
  847. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  848. ISPPRV_PCR_YCPOS_CrYCbY,
  849. mode << ISPPRV_PCR_YCPOS_SHIFT);
  850. }
  851. /*
  852. * preview_config_averager - Enable / disable / configure averager
  853. * @average: Average value to be configured.
  854. */
  855. static void preview_config_averager(struct isp_prev_device *prev, u8 average)
  856. {
  857. struct isp_device *isp = to_isp_device(prev);
  858. int reg = 0;
  859. if (prev->params.cfa.format == OMAP3ISP_CFAFMT_BAYER)
  860. reg = ISPPRV_AVE_EVENDIST_2 << ISPPRV_AVE_EVENDIST_SHIFT |
  861. ISPPRV_AVE_ODDDIST_2 << ISPPRV_AVE_ODDDIST_SHIFT |
  862. average;
  863. else if (prev->params.cfa.format == OMAP3ISP_CFAFMT_RGBFOVEON)
  864. reg = ISPPRV_AVE_EVENDIST_3 << ISPPRV_AVE_EVENDIST_SHIFT |
  865. ISPPRV_AVE_ODDDIST_3 << ISPPRV_AVE_ODDDIST_SHIFT |
  866. average;
  867. isp_reg_writel(isp, reg, OMAP3_ISP_IOMEM_PREV, ISPPRV_AVE);
  868. }
  869. /*
  870. * preview_config_input_size - Configure the input frame size
  871. *
  872. * The preview engine crops several rows and columns internally depending on
  873. * which processing blocks are enabled. The driver assumes all those blocks are
  874. * enabled when reporting source pad formats to userspace. If this assumption is
  875. * not true, rows and columns must be manually cropped at the preview engine
  876. * input to avoid overflows at the end of lines and frames.
  877. */
  878. static void preview_config_input_size(struct isp_prev_device *prev)
  879. {
  880. struct isp_device *isp = to_isp_device(prev);
  881. struct prev_params *params = &prev->params;
  882. struct v4l2_mbus_framefmt *format = &prev->formats[PREV_PAD_SINK];
  883. unsigned int sph = 0;
  884. unsigned int eph = format->width - 1;
  885. unsigned int slv = 0;
  886. unsigned int elv = format->height - 1;
  887. if (prev->input == PREVIEW_INPUT_CCDC) {
  888. sph += 2;
  889. eph -= 2;
  890. }
  891. /*
  892. * Median filter 4 pixels
  893. * Noise filter 4 pixels, 4 lines
  894. * or faulty pixels correction
  895. * CFA filter 4 pixels, 4 lines in Bayer mode
  896. * 2 lines in other modes
  897. * Color suppression 2 pixels
  898. * or luma enhancement
  899. * -------------------------------------------------------------
  900. * Maximum total 14 pixels, 8 lines
  901. */
  902. if (!(params->features & PREV_CFA)) {
  903. sph += 2;
  904. eph -= 2;
  905. slv += 2;
  906. elv -= 2;
  907. }
  908. if (!(params->features & (PREV_DEFECT_COR | PREV_NOISE_FILTER))) {
  909. sph += 2;
  910. eph -= 2;
  911. slv += 2;
  912. elv -= 2;
  913. }
  914. if (!(params->features & PREV_HORZ_MEDIAN_FILTER)) {
  915. sph += 2;
  916. eph -= 2;
  917. }
  918. if (!(params->features & (PREV_CHROMA_SUPPRESS | PREV_LUMA_ENHANCE)))
  919. sph += 2;
  920. isp_reg_writel(isp, (sph << ISPPRV_HORZ_INFO_SPH_SHIFT) | eph,
  921. OMAP3_ISP_IOMEM_PREV, ISPPRV_HORZ_INFO);
  922. isp_reg_writel(isp, (slv << ISPPRV_VERT_INFO_SLV_SHIFT) | elv,
  923. OMAP3_ISP_IOMEM_PREV, ISPPRV_VERT_INFO);
  924. }
  925. /*
  926. * preview_config_inlineoffset - Configures the Read address line offset.
  927. * @prev: Preview module
  928. * @offset: Line offset
  929. *
  930. * According to the TRM, the line offset must be aligned on a 32 bytes boundary.
  931. * However, a hardware bug requires the memory start address to be aligned on a
  932. * 64 bytes boundary, so the offset probably should be aligned on 64 bytes as
  933. * well.
  934. */
  935. static void
  936. preview_config_inlineoffset(struct isp_prev_device *prev, u32 offset)
  937. {
  938. struct isp_device *isp = to_isp_device(prev);
  939. isp_reg_writel(isp, offset & 0xffff, OMAP3_ISP_IOMEM_PREV,
  940. ISPPRV_RADR_OFFSET);
  941. }
  942. /*
  943. * preview_set_inaddr - Sets memory address of input frame.
  944. * @addr: 32bit memory address aligned on 32byte boundary.
  945. *
  946. * Configures the memory address from which the input frame is to be read.
  947. */
  948. static void preview_set_inaddr(struct isp_prev_device *prev, u32 addr)
  949. {
  950. struct isp_device *isp = to_isp_device(prev);
  951. isp_reg_writel(isp, addr, OMAP3_ISP_IOMEM_PREV, ISPPRV_RSDR_ADDR);
  952. }
  953. /*
  954. * preview_config_outlineoffset - Configures the Write address line offset.
  955. * @offset: Line Offset for the preview output.
  956. *
  957. * The offset must be a multiple of 32 bytes.
  958. */
  959. static void preview_config_outlineoffset(struct isp_prev_device *prev,
  960. u32 offset)
  961. {
  962. struct isp_device *isp = to_isp_device(prev);
  963. isp_reg_writel(isp, offset & 0xffff, OMAP3_ISP_IOMEM_PREV,
  964. ISPPRV_WADD_OFFSET);
  965. }
  966. /*
  967. * preview_set_outaddr - Sets the memory address to store output frame
  968. * @addr: 32bit memory address aligned on 32byte boundary.
  969. *
  970. * Configures the memory address to which the output frame is written.
  971. */
  972. static void preview_set_outaddr(struct isp_prev_device *prev, u32 addr)
  973. {
  974. struct isp_device *isp = to_isp_device(prev);
  975. isp_reg_writel(isp, addr, OMAP3_ISP_IOMEM_PREV, ISPPRV_WSDR_ADDR);
  976. }
  977. static void preview_adjust_bandwidth(struct isp_prev_device *prev)
  978. {
  979. struct isp_pipeline *pipe = to_isp_pipeline(&prev->subdev.entity);
  980. struct isp_device *isp = to_isp_device(prev);
  981. const struct v4l2_mbus_framefmt *ifmt = &prev->formats[PREV_PAD_SINK];
  982. unsigned long l3_ick = pipe->l3_ick;
  983. struct v4l2_fract *timeperframe;
  984. unsigned int cycles_per_frame;
  985. unsigned int requests_per_frame;
  986. unsigned int cycles_per_request;
  987. unsigned int minimum;
  988. unsigned int maximum;
  989. unsigned int value;
  990. if (prev->input != PREVIEW_INPUT_MEMORY) {
  991. isp_reg_clr(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_SDR_REQ_EXP,
  992. ISPSBL_SDR_REQ_PRV_EXP_MASK);
  993. return;
  994. }
  995. /* Compute the minimum number of cycles per request, based on the
  996. * pipeline maximum data rate. This is an absolute lower bound if we
  997. * don't want SBL overflows, so round the value up.
  998. */
  999. cycles_per_request = div_u64((u64)l3_ick / 2 * 256 + pipe->max_rate - 1,
  1000. pipe->max_rate);
  1001. minimum = DIV_ROUND_UP(cycles_per_request, 32);
  1002. /* Compute the maximum number of cycles per request, based on the
  1003. * requested frame rate. This is a soft upper bound to achieve a frame
  1004. * rate equal or higher than the requested value, so round the value
  1005. * down.
  1006. */
  1007. timeperframe = &pipe->max_timeperframe;
  1008. requests_per_frame = DIV_ROUND_UP(ifmt->width * 2, 256) * ifmt->height;
  1009. cycles_per_frame = div_u64((u64)l3_ick * timeperframe->numerator,
  1010. timeperframe->denominator);
  1011. cycles_per_request = cycles_per_frame / requests_per_frame;
  1012. maximum = cycles_per_request / 32;
  1013. value = max(minimum, maximum);
  1014. dev_dbg(isp->dev, "%s: cycles per request = %u\n", __func__, value);
  1015. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_SDR_REQ_EXP,
  1016. ISPSBL_SDR_REQ_PRV_EXP_MASK,
  1017. value << ISPSBL_SDR_REQ_PRV_EXP_SHIFT);
  1018. }
  1019. /*
  1020. * omap3isp_preview_busy - Gets busy state of preview module.
  1021. */
  1022. int omap3isp_preview_busy(struct isp_prev_device *prev)
  1023. {
  1024. struct isp_device *isp = to_isp_device(prev);
  1025. return isp_reg_readl(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR)
  1026. & ISPPRV_PCR_BUSY;
  1027. }
  1028. /*
  1029. * omap3isp_preview_restore_context - Restores the values of preview registers
  1030. */
  1031. void omap3isp_preview_restore_context(struct isp_device *isp)
  1032. {
  1033. isp->isp_prev.update = PREV_FEATURES_END - 1;
  1034. preview_setup_hw(&isp->isp_prev);
  1035. }
  1036. /*
  1037. * preview_print_status - Dump preview module registers to the kernel log
  1038. */
  1039. #define PREV_PRINT_REGISTER(isp, name)\
  1040. dev_dbg(isp->dev, "###PRV " #name "=0x%08x\n", \
  1041. isp_reg_readl(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_##name))
  1042. static void preview_print_status(struct isp_prev_device *prev)
  1043. {
  1044. struct isp_device *isp = to_isp_device(prev);
  1045. dev_dbg(isp->dev, "-------------Preview Register dump----------\n");
  1046. PREV_PRINT_REGISTER(isp, PCR);
  1047. PREV_PRINT_REGISTER(isp, HORZ_INFO);
  1048. PREV_PRINT_REGISTER(isp, VERT_INFO);
  1049. PREV_PRINT_REGISTER(isp, RSDR_ADDR);
  1050. PREV_PRINT_REGISTER(isp, RADR_OFFSET);
  1051. PREV_PRINT_REGISTER(isp, DSDR_ADDR);
  1052. PREV_PRINT_REGISTER(isp, DRKF_OFFSET);
  1053. PREV_PRINT_REGISTER(isp, WSDR_ADDR);
  1054. PREV_PRINT_REGISTER(isp, WADD_OFFSET);
  1055. PREV_PRINT_REGISTER(isp, AVE);
  1056. PREV_PRINT_REGISTER(isp, HMED);
  1057. PREV_PRINT_REGISTER(isp, NF);
  1058. PREV_PRINT_REGISTER(isp, WB_DGAIN);
  1059. PREV_PRINT_REGISTER(isp, WBGAIN);
  1060. PREV_PRINT_REGISTER(isp, WBSEL);
  1061. PREV_PRINT_REGISTER(isp, CFA);
  1062. PREV_PRINT_REGISTER(isp, BLKADJOFF);
  1063. PREV_PRINT_REGISTER(isp, RGB_MAT1);
  1064. PREV_PRINT_REGISTER(isp, RGB_MAT2);
  1065. PREV_PRINT_REGISTER(isp, RGB_MAT3);
  1066. PREV_PRINT_REGISTER(isp, RGB_MAT4);
  1067. PREV_PRINT_REGISTER(isp, RGB_MAT5);
  1068. PREV_PRINT_REGISTER(isp, RGB_OFF1);
  1069. PREV_PRINT_REGISTER(isp, RGB_OFF2);
  1070. PREV_PRINT_REGISTER(isp, CSC0);
  1071. PREV_PRINT_REGISTER(isp, CSC1);
  1072. PREV_PRINT_REGISTER(isp, CSC2);
  1073. PREV_PRINT_REGISTER(isp, CSC_OFFSET);
  1074. PREV_PRINT_REGISTER(isp, CNT_BRT);
  1075. PREV_PRINT_REGISTER(isp, CSUP);
  1076. PREV_PRINT_REGISTER(isp, SETUP_YC);
  1077. PREV_PRINT_REGISTER(isp, SET_TBL_ADDR);
  1078. PREV_PRINT_REGISTER(isp, CDC_THR0);
  1079. PREV_PRINT_REGISTER(isp, CDC_THR1);
  1080. PREV_PRINT_REGISTER(isp, CDC_THR2);
  1081. PREV_PRINT_REGISTER(isp, CDC_THR3);
  1082. dev_dbg(isp->dev, "--------------------------------------------\n");
  1083. }
  1084. /*
  1085. * preview_init_params - init image processing parameters.
  1086. * @prev: pointer to previewer private structure
  1087. * return none
  1088. */
  1089. static void preview_init_params(struct isp_prev_device *prev)
  1090. {
  1091. struct prev_params *params = &prev->params;
  1092. int i = 0;
  1093. /* Init values */
  1094. params->contrast = ISPPRV_CONTRAST_DEF * ISPPRV_CONTRAST_UNITS;
  1095. params->brightness = ISPPRV_BRIGHT_DEF * ISPPRV_BRIGHT_UNITS;
  1096. params->cfa.format = OMAP3ISP_CFAFMT_BAYER;
  1097. memcpy(params->cfa.table, cfa_coef_table,
  1098. sizeof(params->cfa.table));
  1099. params->cfa.gradthrs_horz = FLR_CFA_GRADTHRS_HORZ;
  1100. params->cfa.gradthrs_vert = FLR_CFA_GRADTHRS_VERT;
  1101. params->csup.gain = FLR_CSUP_GAIN;
  1102. params->csup.thres = FLR_CSUP_THRES;
  1103. params->csup.hypf_en = 0;
  1104. memcpy(params->luma.table, luma_enhance_table,
  1105. sizeof(params->luma.table));
  1106. params->nf.spread = FLR_NF_STRGTH;
  1107. memcpy(params->nf.table, noise_filter_table, sizeof(params->nf.table));
  1108. params->dcor.couplet_mode_en = 1;
  1109. for (i = 0; i < OMAP3ISP_PREV_DETECT_CORRECT_CHANNELS; i++)
  1110. params->dcor.detect_correct[i] = DEF_DETECT_CORRECT_VAL;
  1111. memcpy(params->gamma.blue, gamma_table, sizeof(params->gamma.blue));
  1112. memcpy(params->gamma.green, gamma_table, sizeof(params->gamma.green));
  1113. memcpy(params->gamma.red, gamma_table, sizeof(params->gamma.red));
  1114. params->wbal.dgain = FLR_WBAL_DGAIN;
  1115. params->wbal.coef0 = FLR_WBAL_COEF;
  1116. params->wbal.coef1 = FLR_WBAL_COEF;
  1117. params->wbal.coef2 = FLR_WBAL_COEF;
  1118. params->wbal.coef3 = FLR_WBAL_COEF;
  1119. params->blk_adj.red = FLR_BLKADJ_RED;
  1120. params->blk_adj.green = FLR_BLKADJ_GREEN;
  1121. params->blk_adj.blue = FLR_BLKADJ_BLUE;
  1122. params->rgb2rgb = flr_rgb2rgb;
  1123. params->rgb2ycbcr = flr_prev_csc;
  1124. params->yclimit.minC = ISPPRV_YC_MIN;
  1125. params->yclimit.maxC = ISPPRV_YC_MAX;
  1126. params->yclimit.minY = ISPPRV_YC_MIN;
  1127. params->yclimit.maxY = ISPPRV_YC_MAX;
  1128. params->features = PREV_CFA | PREV_DEFECT_COR | PREV_NOISE_FILTER
  1129. | PREV_GAMMA | PREV_BLKADJ | PREV_YCLIMITS
  1130. | PREV_RGB2RGB | PREV_COLOR_CONV | PREV_WB
  1131. | PREV_BRIGHTNESS | PREV_CONTRAST;
  1132. prev->update = PREV_FEATURES_END - 1;
  1133. }
  1134. /*
  1135. * preview_max_out_width - Handle previewer hardware ouput limitations
  1136. * @isp_revision : ISP revision
  1137. * returns maximum width output for current isp revision
  1138. */
  1139. static unsigned int preview_max_out_width(struct isp_prev_device *prev)
  1140. {
  1141. struct isp_device *isp = to_isp_device(prev);
  1142. switch (isp->revision) {
  1143. case ISP_REVISION_1_0:
  1144. return PREV_MAX_OUT_WIDTH;
  1145. case ISP_REVISION_2_0:
  1146. default:
  1147. return PREV_MAX_OUT_WIDTH_ES2;
  1148. case ISP_REVISION_15_0:
  1149. return PREV_MAX_OUT_WIDTH_3630;
  1150. }
  1151. }
  1152. static void preview_configure(struct isp_prev_device *prev)
  1153. {
  1154. struct isp_device *isp = to_isp_device(prev);
  1155. struct v4l2_mbus_framefmt *format;
  1156. preview_setup_hw(prev);
  1157. if (prev->output & PREVIEW_OUTPUT_MEMORY)
  1158. isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  1159. ISPPRV_PCR_SDRPORT);
  1160. else
  1161. isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  1162. ISPPRV_PCR_SDRPORT);
  1163. if (prev->output & PREVIEW_OUTPUT_RESIZER)
  1164. isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  1165. ISPPRV_PCR_RSZPORT);
  1166. else
  1167. isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  1168. ISPPRV_PCR_RSZPORT);
  1169. /* PREV_PAD_SINK */
  1170. format = &prev->formats[PREV_PAD_SINK];
  1171. preview_adjust_bandwidth(prev);
  1172. preview_config_input_size(prev);
  1173. if (prev->input == PREVIEW_INPUT_CCDC)
  1174. preview_config_inlineoffset(prev, 0);
  1175. else
  1176. preview_config_inlineoffset(prev,
  1177. ALIGN(format->width, 0x20) * 2);
  1178. /* PREV_PAD_SOURCE */
  1179. format = &prev->formats[PREV_PAD_SOURCE];
  1180. if (prev->output & PREVIEW_OUTPUT_MEMORY)
  1181. preview_config_outlineoffset(prev,
  1182. ALIGN(format->width, 0x10) * 2);
  1183. preview_config_averager(prev, 0);
  1184. preview_config_ycpos(prev, format->code);
  1185. }
  1186. /* -----------------------------------------------------------------------------
  1187. * Interrupt handling
  1188. */
  1189. static void preview_enable_oneshot(struct isp_prev_device *prev)
  1190. {
  1191. struct isp_device *isp = to_isp_device(prev);
  1192. /* The PCR.SOURCE bit is automatically reset to 0 when the PCR.ENABLE
  1193. * bit is set. As the preview engine is used in single-shot mode, we
  1194. * need to set PCR.SOURCE before enabling the preview engine.
  1195. */
  1196. if (prev->input == PREVIEW_INPUT_MEMORY)
  1197. isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  1198. ISPPRV_PCR_SOURCE);
  1199. isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  1200. ISPPRV_PCR_EN | ISPPRV_PCR_ONESHOT);
  1201. }
  1202. void omap3isp_preview_isr_frame_sync(struct isp_prev_device *prev)
  1203. {
  1204. /*
  1205. * If ISP_VIDEO_DMAQUEUE_QUEUED is set, DMA queue had an underrun
  1206. * condition, the module was paused and now we have a buffer queued
  1207. * on the output again. Restart the pipeline if running in continuous
  1208. * mode.
  1209. */
  1210. if (prev->state == ISP_PIPELINE_STREAM_CONTINUOUS &&
  1211. prev->video_out.dmaqueue_flags & ISP_VIDEO_DMAQUEUE_QUEUED) {
  1212. preview_enable_oneshot(prev);
  1213. isp_video_dmaqueue_flags_clr(&prev->video_out);
  1214. }
  1215. }
  1216. static void preview_isr_buffer(struct isp_prev_device *prev)
  1217. {
  1218. struct isp_pipeline *pipe = to_isp_pipeline(&prev->subdev.entity);
  1219. struct isp_buffer *buffer;
  1220. int restart = 0;
  1221. if (prev->input == PREVIEW_INPUT_MEMORY) {
  1222. buffer = omap3isp_video_buffer_next(&prev->video_in,
  1223. prev->error);
  1224. if (buffer != NULL)
  1225. preview_set_inaddr(prev, buffer->isp_addr);
  1226. pipe->state |= ISP_PIPELINE_IDLE_INPUT;
  1227. }
  1228. if (prev->output & PREVIEW_OUTPUT_MEMORY) {
  1229. buffer = omap3isp_video_buffer_next(&prev->video_out,
  1230. prev->error);
  1231. if (buffer != NULL) {
  1232. preview_set_outaddr(prev, buffer->isp_addr);
  1233. restart = 1;
  1234. }
  1235. pipe->state |= ISP_PIPELINE_IDLE_OUTPUT;
  1236. }
  1237. switch (prev->state) {
  1238. case ISP_PIPELINE_STREAM_SINGLESHOT:
  1239. if (isp_pipeline_ready(pipe))
  1240. omap3isp_pipeline_set_stream(pipe,
  1241. ISP_PIPELINE_STREAM_SINGLESHOT);
  1242. break;
  1243. case ISP_PIPELINE_STREAM_CONTINUOUS:
  1244. /* If an underrun occurs, the video queue operation handler will
  1245. * restart the preview engine. Otherwise restart it immediately.
  1246. */
  1247. if (restart)
  1248. preview_enable_oneshot(prev);
  1249. break;
  1250. case ISP_PIPELINE_STREAM_STOPPED:
  1251. default:
  1252. return;
  1253. }
  1254. prev->error = 0;
  1255. }
  1256. /*
  1257. * omap3isp_preview_isr - ISP preview engine interrupt handler
  1258. *
  1259. * Manage the preview engine video buffers and configure shadowed registers.
  1260. */
  1261. void omap3isp_preview_isr(struct isp_prev_device *prev)
  1262. {
  1263. unsigned long flags;
  1264. if (omap3isp_module_sync_is_stopping(&prev->wait, &prev->stopping))
  1265. return;
  1266. spin_lock_irqsave(&prev->lock, flags);
  1267. if (prev->shadow_update)
  1268. goto done;
  1269. preview_setup_hw(prev);
  1270. preview_config_input_size(prev);
  1271. done:
  1272. spin_unlock_irqrestore(&prev->lock, flags);
  1273. if (prev->input == PREVIEW_INPUT_MEMORY ||
  1274. prev->output & PREVIEW_OUTPUT_MEMORY)
  1275. preview_isr_buffer(prev);
  1276. else if (prev->state == ISP_PIPELINE_STREAM_CONTINUOUS)
  1277. preview_enable_oneshot(prev);
  1278. }
  1279. /* -----------------------------------------------------------------------------
  1280. * ISP video operations
  1281. */
  1282. static int preview_video_queue(struct isp_video *video,
  1283. struct isp_buffer *buffer)
  1284. {
  1285. struct isp_prev_device *prev = &video->isp->isp_prev;
  1286. if (video->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
  1287. preview_set_inaddr(prev, buffer->isp_addr);
  1288. if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1289. preview_set_outaddr(prev, buffer->isp_addr);
  1290. return 0;
  1291. }
  1292. static const struct isp_video_operations preview_video_ops = {
  1293. .queue = preview_video_queue,
  1294. };
  1295. /* -----------------------------------------------------------------------------
  1296. * V4L2 subdev operations
  1297. */
  1298. /*
  1299. * preview_s_ctrl - Handle set control subdev method
  1300. * @ctrl: pointer to v4l2 control structure
  1301. */
  1302. static int preview_s_ctrl(struct v4l2_ctrl *ctrl)
  1303. {
  1304. struct isp_prev_device *prev =
  1305. container_of(ctrl->handler, struct isp_prev_device, ctrls);
  1306. switch (ctrl->id) {
  1307. case V4L2_CID_BRIGHTNESS:
  1308. preview_update_brightness(prev, ctrl->val);
  1309. break;
  1310. case V4L2_CID_CONTRAST:
  1311. preview_update_contrast(prev, ctrl->val);
  1312. break;
  1313. }
  1314. return 0;
  1315. }
  1316. static const struct v4l2_ctrl_ops preview_ctrl_ops = {
  1317. .s_ctrl = preview_s_ctrl,
  1318. };
  1319. /*
  1320. * preview_ioctl - Handle preview module private ioctl's
  1321. * @prev: pointer to preview context structure
  1322. * @cmd: configuration command
  1323. * @arg: configuration argument
  1324. * return -EINVAL or zero on success
  1325. */
  1326. static long preview_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
  1327. {
  1328. struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
  1329. switch (cmd) {
  1330. case VIDIOC_OMAP3ISP_PRV_CFG:
  1331. return preview_config(prev, arg);
  1332. default:
  1333. return -ENOIOCTLCMD;
  1334. }
  1335. }
  1336. /*
  1337. * preview_set_stream - Enable/Disable streaming on preview subdev
  1338. * @sd : pointer to v4l2 subdev structure
  1339. * @enable: 1 == Enable, 0 == Disable
  1340. * return -EINVAL or zero on success
  1341. */
  1342. static int preview_set_stream(struct v4l2_subdev *sd, int enable)
  1343. {
  1344. struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
  1345. struct isp_video *video_out = &prev->video_out;
  1346. struct isp_device *isp = to_isp_device(prev);
  1347. struct device *dev = to_device(prev);
  1348. unsigned long flags;
  1349. if (prev->state == ISP_PIPELINE_STREAM_STOPPED) {
  1350. if (enable == ISP_PIPELINE_STREAM_STOPPED)
  1351. return 0;
  1352. omap3isp_subclk_enable(isp, OMAP3_ISP_SUBCLK_PREVIEW);
  1353. preview_configure(prev);
  1354. atomic_set(&prev->stopping, 0);
  1355. prev->error = 0;
  1356. preview_print_status(prev);
  1357. }
  1358. switch (enable) {
  1359. case ISP_PIPELINE_STREAM_CONTINUOUS:
  1360. if (prev->output & PREVIEW_OUTPUT_MEMORY)
  1361. omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_PREVIEW_WRITE);
  1362. if (video_out->dmaqueue_flags & ISP_VIDEO_DMAQUEUE_QUEUED ||
  1363. !(prev->output & PREVIEW_OUTPUT_MEMORY))
  1364. preview_enable_oneshot(prev);
  1365. isp_video_dmaqueue_flags_clr(video_out);
  1366. break;
  1367. case ISP_PIPELINE_STREAM_SINGLESHOT:
  1368. if (prev->input == PREVIEW_INPUT_MEMORY)
  1369. omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_PREVIEW_READ);
  1370. if (prev->output & PREVIEW_OUTPUT_MEMORY)
  1371. omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_PREVIEW_WRITE);
  1372. preview_enable_oneshot(prev);
  1373. break;
  1374. case ISP_PIPELINE_STREAM_STOPPED:
  1375. if (omap3isp_module_sync_idle(&sd->entity, &prev->wait,
  1376. &prev->stopping))
  1377. dev_dbg(dev, "%s: stop timeout.\n", sd->name);
  1378. spin_lock_irqsave(&prev->lock, flags);
  1379. omap3isp_sbl_disable(isp, OMAP3_ISP_SBL_PREVIEW_READ);
  1380. omap3isp_sbl_disable(isp, OMAP3_ISP_SBL_PREVIEW_WRITE);
  1381. omap3isp_subclk_disable(isp, OMAP3_ISP_SUBCLK_PREVIEW);
  1382. spin_unlock_irqrestore(&prev->lock, flags);
  1383. isp_video_dmaqueue_flags_clr(video_out);
  1384. break;
  1385. }
  1386. prev->state = enable;
  1387. return 0;
  1388. }
  1389. static struct v4l2_mbus_framefmt *
  1390. __preview_get_format(struct isp_prev_device *prev, struct v4l2_subdev_fh *fh,
  1391. unsigned int pad, enum v4l2_subdev_format_whence which)
  1392. {
  1393. if (which == V4L2_SUBDEV_FORMAT_TRY)
  1394. return v4l2_subdev_get_try_format(fh, pad);
  1395. else
  1396. return &prev->formats[pad];
  1397. }
  1398. /* previewer format descriptions */
  1399. static const unsigned int preview_input_fmts[] = {
  1400. V4L2_MBUS_FMT_SGRBG10_1X10,
  1401. V4L2_MBUS_FMT_SRGGB10_1X10,
  1402. V4L2_MBUS_FMT_SBGGR10_1X10,
  1403. V4L2_MBUS_FMT_SGBRG10_1X10,
  1404. };
  1405. static const unsigned int preview_output_fmts[] = {
  1406. V4L2_MBUS_FMT_UYVY8_1X16,
  1407. V4L2_MBUS_FMT_YUYV8_1X16,
  1408. };
  1409. /*
  1410. * preview_try_format - Handle try format by pad subdev method
  1411. * @prev: ISP preview device
  1412. * @fh : V4L2 subdev file handle
  1413. * @pad: pad num
  1414. * @fmt: pointer to v4l2 format structure
  1415. */
  1416. static void preview_try_format(struct isp_prev_device *prev,
  1417. struct v4l2_subdev_fh *fh, unsigned int pad,
  1418. struct v4l2_mbus_framefmt *fmt,
  1419. enum v4l2_subdev_format_whence which)
  1420. {
  1421. struct v4l2_mbus_framefmt *format;
  1422. enum v4l2_mbus_pixelcode pixelcode;
  1423. unsigned int i;
  1424. switch (pad) {
  1425. case PREV_PAD_SINK:
  1426. /* When reading data from the CCDC, the input size has already
  1427. * been mangled by the CCDC output pad so it can be accepted
  1428. * as-is.
  1429. *
  1430. * When reading data from memory, clamp the requested width and
  1431. * height. The TRM doesn't specify a minimum input height, make
  1432. * sure we got enough lines to enable the noise filter and color
  1433. * filter array interpolation.
  1434. */
  1435. if (prev->input == PREVIEW_INPUT_MEMORY) {
  1436. fmt->width = clamp_t(u32, fmt->width, PREV_MIN_IN_WIDTH,
  1437. preview_max_out_width(prev));
  1438. fmt->height = clamp_t(u32, fmt->height,
  1439. PREV_MIN_IN_HEIGHT,
  1440. PREV_MAX_IN_HEIGHT);
  1441. }
  1442. fmt->colorspace = V4L2_COLORSPACE_SRGB;
  1443. for (i = 0; i < ARRAY_SIZE(preview_input_fmts); i++) {
  1444. if (fmt->code == preview_input_fmts[i])
  1445. break;
  1446. }
  1447. /* If not found, use SGRBG10 as default */
  1448. if (i >= ARRAY_SIZE(preview_input_fmts))
  1449. fmt->code = V4L2_MBUS_FMT_SGRBG10_1X10;
  1450. break;
  1451. case PREV_PAD_SOURCE:
  1452. pixelcode = fmt->code;
  1453. format = __preview_get_format(prev, fh, PREV_PAD_SINK, which);
  1454. memcpy(fmt, format, sizeof(*fmt));
  1455. /* The preview module output size is configurable through the
  1456. * input interface (horizontal and vertical cropping) and the
  1457. * averager (horizontal scaling by 1/1, 1/2, 1/4 or 1/8). In
  1458. * spite of this, hardcode the output size to the biggest
  1459. * possible value for simplicity reasons.
  1460. */
  1461. switch (pixelcode) {
  1462. case V4L2_MBUS_FMT_YUYV8_1X16:
  1463. case V4L2_MBUS_FMT_UYVY8_1X16:
  1464. fmt->code = pixelcode;
  1465. break;
  1466. default:
  1467. fmt->code = V4L2_MBUS_FMT_YUYV8_1X16;
  1468. break;
  1469. }
  1470. /* The TRM states (12.1.4.7.1.2) that 2 pixels must be cropped
  1471. * from the left and right sides when the input source is the
  1472. * CCDC. This seems not to be needed in practice, investigation
  1473. * is required.
  1474. */
  1475. if (prev->input == PREVIEW_INPUT_CCDC)
  1476. fmt->width -= 4;
  1477. /* Assume that all blocks are enabled and crop pixels and lines
  1478. * accordingly. See preview_config_input_size() for more
  1479. * information.
  1480. */
  1481. fmt->width -= 14;
  1482. fmt->height -= 8;
  1483. fmt->colorspace = V4L2_COLORSPACE_JPEG;
  1484. break;
  1485. }
  1486. fmt->field = V4L2_FIELD_NONE;
  1487. }
  1488. /*
  1489. * preview_enum_mbus_code - Handle pixel format enumeration
  1490. * @sd : pointer to v4l2 subdev structure
  1491. * @fh : V4L2 subdev file handle
  1492. * @code : pointer to v4l2_subdev_mbus_code_enum structure
  1493. * return -EINVAL or zero on success
  1494. */
  1495. static int preview_enum_mbus_code(struct v4l2_subdev *sd,
  1496. struct v4l2_subdev_fh *fh,
  1497. struct v4l2_subdev_mbus_code_enum *code)
  1498. {
  1499. switch (code->pad) {
  1500. case PREV_PAD_SINK:
  1501. if (code->index >= ARRAY_SIZE(preview_input_fmts))
  1502. return -EINVAL;
  1503. code->code = preview_input_fmts[code->index];
  1504. break;
  1505. case PREV_PAD_SOURCE:
  1506. if (code->index >= ARRAY_SIZE(preview_output_fmts))
  1507. return -EINVAL;
  1508. code->code = preview_output_fmts[code->index];
  1509. break;
  1510. default:
  1511. return -EINVAL;
  1512. }
  1513. return 0;
  1514. }
  1515. static int preview_enum_frame_size(struct v4l2_subdev *sd,
  1516. struct v4l2_subdev_fh *fh,
  1517. struct v4l2_subdev_frame_size_enum *fse)
  1518. {
  1519. struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
  1520. struct v4l2_mbus_framefmt format;
  1521. if (fse->index != 0)
  1522. return -EINVAL;
  1523. format.code = fse->code;
  1524. format.width = 1;
  1525. format.height = 1;
  1526. preview_try_format(prev, fh, fse->pad, &format, V4L2_SUBDEV_FORMAT_TRY);
  1527. fse->min_width = format.width;
  1528. fse->min_height = format.height;
  1529. if (format.code != fse->code)
  1530. return -EINVAL;
  1531. format.code = fse->code;
  1532. format.width = -1;
  1533. format.height = -1;
  1534. preview_try_format(prev, fh, fse->pad, &format, V4L2_SUBDEV_FORMAT_TRY);
  1535. fse->max_width = format.width;
  1536. fse->max_height = format.height;
  1537. return 0;
  1538. }
  1539. /*
  1540. * preview_get_format - Handle get format by pads subdev method
  1541. * @sd : pointer to v4l2 subdev structure
  1542. * @fh : V4L2 subdev file handle
  1543. * @fmt: pointer to v4l2 subdev format structure
  1544. * return -EINVAL or zero on success
  1545. */
  1546. static int preview_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
  1547. struct v4l2_subdev_format *fmt)
  1548. {
  1549. struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
  1550. struct v4l2_mbus_framefmt *format;
  1551. format = __preview_get_format(prev, fh, fmt->pad, fmt->which);
  1552. if (format == NULL)
  1553. return -EINVAL;
  1554. fmt->format = *format;
  1555. return 0;
  1556. }
  1557. /*
  1558. * preview_set_format - Handle set format by pads subdev method
  1559. * @sd : pointer to v4l2 subdev structure
  1560. * @fh : V4L2 subdev file handle
  1561. * @fmt: pointer to v4l2 subdev format structure
  1562. * return -EINVAL or zero on success
  1563. */
  1564. static int preview_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
  1565. struct v4l2_subdev_format *fmt)
  1566. {
  1567. struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
  1568. struct v4l2_mbus_framefmt *format;
  1569. format = __preview_get_format(prev, fh, fmt->pad, fmt->which);
  1570. if (format == NULL)
  1571. return -EINVAL;
  1572. preview_try_format(prev, fh, fmt->pad, &fmt->format, fmt->which);
  1573. *format = fmt->format;
  1574. /* Propagate the format from sink to source */
  1575. if (fmt->pad == PREV_PAD_SINK) {
  1576. format = __preview_get_format(prev, fh, PREV_PAD_SOURCE,
  1577. fmt->which);
  1578. *format = fmt->format;
  1579. preview_try_format(prev, fh, PREV_PAD_SOURCE, format,
  1580. fmt->which);
  1581. }
  1582. return 0;
  1583. }
  1584. /*
  1585. * preview_init_formats - Initialize formats on all pads
  1586. * @sd: ISP preview V4L2 subdevice
  1587. * @fh: V4L2 subdev file handle
  1588. *
  1589. * Initialize all pad formats with default values. If fh is not NULL, try
  1590. * formats are initialized on the file handle. Otherwise active formats are
  1591. * initialized on the device.
  1592. */
  1593. static int preview_init_formats(struct v4l2_subdev *sd,
  1594. struct v4l2_subdev_fh *fh)
  1595. {
  1596. struct v4l2_subdev_format format;
  1597. memset(&format, 0, sizeof(format));
  1598. format.pad = PREV_PAD_SINK;
  1599. format.which = fh ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
  1600. format.format.code = V4L2_MBUS_FMT_SGRBG10_1X10;
  1601. format.format.width = 4096;
  1602. format.format.height = 4096;
  1603. preview_set_format(sd, fh, &format);
  1604. return 0;
  1605. }
  1606. /* subdev core operations */
  1607. static const struct v4l2_subdev_core_ops preview_v4l2_core_ops = {
  1608. .ioctl = preview_ioctl,
  1609. };
  1610. /* subdev video operations */
  1611. static const struct v4l2_subdev_video_ops preview_v4l2_video_ops = {
  1612. .s_stream = preview_set_stream,
  1613. };
  1614. /* subdev pad operations */
  1615. static const struct v4l2_subdev_pad_ops preview_v4l2_pad_ops = {
  1616. .enum_mbus_code = preview_enum_mbus_code,
  1617. .enum_frame_size = preview_enum_frame_size,
  1618. .get_fmt = preview_get_format,
  1619. .set_fmt = preview_set_format,
  1620. };
  1621. /* subdev operations */
  1622. static const struct v4l2_subdev_ops preview_v4l2_ops = {
  1623. .core = &preview_v4l2_core_ops,
  1624. .video = &preview_v4l2_video_ops,
  1625. .pad = &preview_v4l2_pad_ops,
  1626. };
  1627. /* subdev internal operations */
  1628. static const struct v4l2_subdev_internal_ops preview_v4l2_internal_ops = {
  1629. .open = preview_init_formats,
  1630. };
  1631. /* -----------------------------------------------------------------------------
  1632. * Media entity operations
  1633. */
  1634. /*
  1635. * preview_link_setup - Setup previewer connections.
  1636. * @entity : Pointer to media entity structure
  1637. * @local : Pointer to local pad array
  1638. * @remote : Pointer to remote pad array
  1639. * @flags : Link flags
  1640. * return -EINVAL or zero on success
  1641. */
  1642. static int preview_link_setup(struct media_entity *entity,
  1643. const struct media_pad *local,
  1644. const struct media_pad *remote, u32 flags)
  1645. {
  1646. struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
  1647. struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
  1648. switch (local->index | media_entity_type(remote->entity)) {
  1649. case PREV_PAD_SINK | MEDIA_ENT_T_DEVNODE:
  1650. /* read from memory */
  1651. if (flags & MEDIA_LNK_FL_ENABLED) {
  1652. if (prev->input == PREVIEW_INPUT_CCDC)
  1653. return -EBUSY;
  1654. prev->input = PREVIEW_INPUT_MEMORY;
  1655. } else {
  1656. if (prev->input == PREVIEW_INPUT_MEMORY)
  1657. prev->input = PREVIEW_INPUT_NONE;
  1658. }
  1659. break;
  1660. case PREV_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
  1661. /* read from ccdc */
  1662. if (flags & MEDIA_LNK_FL_ENABLED) {
  1663. if (prev->input == PREVIEW_INPUT_MEMORY)
  1664. return -EBUSY;
  1665. prev->input = PREVIEW_INPUT_CCDC;
  1666. } else {
  1667. if (prev->input == PREVIEW_INPUT_CCDC)
  1668. prev->input = PREVIEW_INPUT_NONE;
  1669. }
  1670. break;
  1671. /*
  1672. * The ISP core doesn't support pipelines with multiple video outputs.
  1673. * Revisit this when it will be implemented, and return -EBUSY for now.
  1674. */
  1675. case PREV_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
  1676. /* write to memory */
  1677. if (flags & MEDIA_LNK_FL_ENABLED) {
  1678. if (prev->output & ~PREVIEW_OUTPUT_MEMORY)
  1679. return -EBUSY;
  1680. prev->output |= PREVIEW_OUTPUT_MEMORY;
  1681. } else {
  1682. prev->output &= ~PREVIEW_OUTPUT_MEMORY;
  1683. }
  1684. break;
  1685. case PREV_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
  1686. /* write to resizer */
  1687. if (flags & MEDIA_LNK_FL_ENABLED) {
  1688. if (prev->output & ~PREVIEW_OUTPUT_RESIZER)
  1689. return -EBUSY;
  1690. prev->output |= PREVIEW_OUTPUT_RESIZER;
  1691. } else {
  1692. prev->output &= ~PREVIEW_OUTPUT_RESIZER;
  1693. }
  1694. break;
  1695. default:
  1696. return -EINVAL;
  1697. }
  1698. return 0;
  1699. }
  1700. /* media operations */
  1701. static const struct media_entity_operations preview_media_ops = {
  1702. .link_setup = preview_link_setup,
  1703. };
  1704. void omap3isp_preview_unregister_entities(struct isp_prev_device *prev)
  1705. {
  1706. v4l2_device_unregister_subdev(&prev->subdev);
  1707. omap3isp_video_unregister(&prev->video_in);
  1708. omap3isp_video_unregister(&prev->video_out);
  1709. }
  1710. int omap3isp_preview_register_entities(struct isp_prev_device *prev,
  1711. struct v4l2_device *vdev)
  1712. {
  1713. int ret;
  1714. /* Register the subdev and video nodes. */
  1715. ret = v4l2_device_register_subdev(vdev, &prev->subdev);
  1716. if (ret < 0)
  1717. goto error;
  1718. ret = omap3isp_video_register(&prev->video_in, vdev);
  1719. if (ret < 0)
  1720. goto error;
  1721. ret = omap3isp_video_register(&prev->video_out, vdev);
  1722. if (ret < 0)
  1723. goto error;
  1724. return 0;
  1725. error:
  1726. omap3isp_preview_unregister_entities(prev);
  1727. return ret;
  1728. }
  1729. /* -----------------------------------------------------------------------------
  1730. * ISP previewer initialisation and cleanup
  1731. */
  1732. /*
  1733. * preview_init_entities - Initialize subdev and media entity.
  1734. * @prev : Pointer to preview structure
  1735. * return -ENOMEM or zero on success
  1736. */
  1737. static int preview_init_entities(struct isp_prev_device *prev)
  1738. {
  1739. struct v4l2_subdev *sd = &prev->subdev;
  1740. struct media_pad *pads = prev->pads;
  1741. struct media_entity *me = &sd->entity;
  1742. int ret;
  1743. prev->input = PREVIEW_INPUT_NONE;
  1744. v4l2_subdev_init(sd, &preview_v4l2_ops);
  1745. sd->internal_ops = &preview_v4l2_internal_ops;
  1746. strlcpy(sd->name, "OMAP3 ISP preview", sizeof(sd->name));
  1747. sd->grp_id = 1 << 16; /* group ID for isp subdevs */
  1748. v4l2_set_subdevdata(sd, prev);
  1749. sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
  1750. v4l2_ctrl_handler_init(&prev->ctrls, 2);
  1751. v4l2_ctrl_new_std(&prev->ctrls, &preview_ctrl_ops, V4L2_CID_BRIGHTNESS,
  1752. ISPPRV_BRIGHT_LOW, ISPPRV_BRIGHT_HIGH,
  1753. ISPPRV_BRIGHT_STEP, ISPPRV_BRIGHT_DEF);
  1754. v4l2_ctrl_new_std(&prev->ctrls, &preview_ctrl_ops, V4L2_CID_CONTRAST,
  1755. ISPPRV_CONTRAST_LOW, ISPPRV_CONTRAST_HIGH,
  1756. ISPPRV_CONTRAST_STEP, ISPPRV_CONTRAST_DEF);
  1757. v4l2_ctrl_handler_setup(&prev->ctrls);
  1758. sd->ctrl_handler = &prev->ctrls;
  1759. pads[PREV_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
  1760. pads[PREV_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
  1761. me->ops = &preview_media_ops;
  1762. ret = media_entity_init(me, PREV_PADS_NUM, pads, 0);
  1763. if (ret < 0)
  1764. return ret;
  1765. preview_init_formats(sd, NULL);
  1766. /* According to the OMAP34xx TRM, video buffers need to be aligned on a
  1767. * 32 bytes boundary. However, an undocumented hardware bug requires a
  1768. * 64 bytes boundary at the preview engine input.
  1769. */
  1770. prev->video_in.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
  1771. prev->video_in.ops = &preview_video_ops;
  1772. prev->video_in.isp = to_isp_device(prev);
  1773. prev->video_in.capture_mem = PAGE_ALIGN(4096 * 4096) * 2 * 3;
  1774. prev->video_in.bpl_alignment = 64;
  1775. prev->video_out.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1776. prev->video_out.ops = &preview_video_ops;
  1777. prev->video_out.isp = to_isp_device(prev);
  1778. prev->video_out.capture_mem = PAGE_ALIGN(4096 * 4096) * 2 * 3;
  1779. prev->video_out.bpl_alignment = 32;
  1780. ret = omap3isp_video_init(&prev->video_in, "preview");
  1781. if (ret < 0)
  1782. goto error_video_in;
  1783. ret = omap3isp_video_init(&prev->video_out, "preview");
  1784. if (ret < 0)
  1785. goto error_video_out;
  1786. /* Connect the video nodes to the previewer subdev. */
  1787. ret = media_entity_create_link(&prev->video_in.video.entity, 0,
  1788. &prev->subdev.entity, PREV_PAD_SINK, 0);
  1789. if (ret < 0)
  1790. goto error_link;
  1791. ret = media_entity_create_link(&prev->subdev.entity, PREV_PAD_SOURCE,
  1792. &prev->video_out.video.entity, 0, 0);
  1793. if (ret < 0)
  1794. goto error_link;
  1795. return 0;
  1796. error_link:
  1797. omap3isp_video_cleanup(&prev->video_out);
  1798. error_video_out:
  1799. omap3isp_video_cleanup(&prev->video_in);
  1800. error_video_in:
  1801. media_entity_cleanup(&prev->subdev.entity);
  1802. return ret;
  1803. }
  1804. /*
  1805. * isp_preview_init - Previewer initialization.
  1806. * @dev : Pointer to ISP device
  1807. * return -ENOMEM or zero on success
  1808. */
  1809. int omap3isp_preview_init(struct isp_device *isp)
  1810. {
  1811. struct isp_prev_device *prev = &isp->isp_prev;
  1812. spin_lock_init(&prev->lock);
  1813. init_waitqueue_head(&prev->wait);
  1814. preview_init_params(prev);
  1815. return preview_init_entities(prev);
  1816. }
  1817. void omap3isp_preview_cleanup(struct isp_device *isp)
  1818. {
  1819. struct isp_prev_device *prev = &isp->isp_prev;
  1820. v4l2_ctrl_handler_free(&prev->ctrls);
  1821. omap3isp_video_cleanup(&prev->video_in);
  1822. omap3isp_video_cleanup(&prev->video_out);
  1823. media_entity_cleanup(&prev->subdev.entity);
  1824. }