isppreview.c 61 KB

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