isppreview.c 65 KB

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