isppreview.c 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326
  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;
  573. unsigned long flags;
  574. spin_lock_irqsave(&prev->params.lock, flags);
  575. params = (prev->params.active & OMAP3ISP_PREV_CONTRAST)
  576. ? &prev->params.params[0] : &prev->params.params[1];
  577. if (params->contrast != (contrast * ISPPRV_CONTRAST_UNITS)) {
  578. params->contrast = contrast * ISPPRV_CONTRAST_UNITS;
  579. params->update |= OMAP3ISP_PREV_CONTRAST;
  580. }
  581. spin_unlock_irqrestore(&prev->params.lock, flags);
  582. }
  583. /*
  584. * preview_config_contrast - Configures the Contrast.
  585. * @params: Contrast value (u8 pointer, U8Q0 format).
  586. *
  587. * Value should be programmed before enabling the module.
  588. */
  589. static void
  590. preview_config_contrast(struct isp_prev_device *prev, const void *params)
  591. {
  592. struct isp_device *isp = to_isp_device(prev);
  593. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_CNT_BRT,
  594. 0xff << ISPPRV_CNT_BRT_CNT_SHIFT,
  595. *(u8 *)params << ISPPRV_CNT_BRT_CNT_SHIFT);
  596. }
  597. /*
  598. * preview_update_brightness - Updates the brightness in preview module.
  599. * @brightness: Pointer to hold the current programmed brightness value.
  600. *
  601. */
  602. static void
  603. preview_update_brightness(struct isp_prev_device *prev, u8 brightness)
  604. {
  605. struct prev_params *params;
  606. unsigned long flags;
  607. spin_lock_irqsave(&prev->params.lock, flags);
  608. params = (prev->params.active & OMAP3ISP_PREV_BRIGHTNESS)
  609. ? &prev->params.params[0] : &prev->params.params[1];
  610. if (params->brightness != (brightness * ISPPRV_BRIGHT_UNITS)) {
  611. params->brightness = brightness * ISPPRV_BRIGHT_UNITS;
  612. params->update |= OMAP3ISP_PREV_BRIGHTNESS;
  613. }
  614. spin_unlock_irqrestore(&prev->params.lock, flags);
  615. }
  616. /*
  617. * preview_config_brightness - Configures the brightness.
  618. * @params: Brightness value (u8 pointer, U8Q0 format).
  619. */
  620. static void
  621. preview_config_brightness(struct isp_prev_device *prev, const void *params)
  622. {
  623. struct isp_device *isp = to_isp_device(prev);
  624. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_CNT_BRT,
  625. 0xff << ISPPRV_CNT_BRT_BRT_SHIFT,
  626. *(u8 *)params << ISPPRV_CNT_BRT_BRT_SHIFT);
  627. }
  628. /*
  629. * preview_config_yc_range - Configures the max and min Y and C values.
  630. * @yclimit: Structure containing the range of Y and C values.
  631. */
  632. static void
  633. preview_config_yc_range(struct isp_prev_device *prev, const void *yclimit)
  634. {
  635. struct isp_device *isp = to_isp_device(prev);
  636. const struct omap3isp_prev_yclimit *yc = yclimit;
  637. isp_reg_writel(isp,
  638. yc->maxC << ISPPRV_SETUP_YC_MAXC_SHIFT |
  639. yc->maxY << ISPPRV_SETUP_YC_MAXY_SHIFT |
  640. yc->minC << ISPPRV_SETUP_YC_MINC_SHIFT |
  641. yc->minY << ISPPRV_SETUP_YC_MINY_SHIFT,
  642. OMAP3_ISP_IOMEM_PREV, ISPPRV_SETUP_YC);
  643. }
  644. static u32
  645. preview_params_lock(struct isp_prev_device *prev, u32 update, bool shadow)
  646. {
  647. u32 active = prev->params.active;
  648. if (shadow) {
  649. /* Mark all shadow parameters we are going to touch as busy. */
  650. prev->params.params[0].busy |= ~active & update;
  651. prev->params.params[1].busy |= active & update;
  652. } else {
  653. /* Mark all active parameters we are going to touch as busy. */
  654. update = (prev->params.params[0].update & active)
  655. | (prev->params.params[1].update & ~active);
  656. prev->params.params[0].busy |= active & update;
  657. prev->params.params[1].busy |= ~active & update;
  658. }
  659. return update;
  660. }
  661. static void
  662. preview_params_unlock(struct isp_prev_device *prev, u32 update, bool shadow)
  663. {
  664. u32 active = prev->params.active;
  665. if (shadow) {
  666. /* Set the update flag for shadow parameters that have been
  667. * updated and clear the busy flag for all shadow parameters.
  668. */
  669. prev->params.params[0].update |= (~active & update);
  670. prev->params.params[1].update |= (active & update);
  671. prev->params.params[0].busy &= active;
  672. prev->params.params[1].busy &= ~active;
  673. } else {
  674. /* Clear the update flag for active parameters that have been
  675. * applied and the busy flag for all active parameters.
  676. */
  677. prev->params.params[0].update &= ~(active & update);
  678. prev->params.params[1].update &= ~(~active & update);
  679. prev->params.params[0].busy &= ~active;
  680. prev->params.params[1].busy &= active;
  681. }
  682. }
  683. static void preview_params_switch(struct isp_prev_device *prev)
  684. {
  685. u32 to_switch;
  686. /* Switch active parameters with updated shadow parameters when the
  687. * shadow parameter has been updated and neither the active not the
  688. * shadow parameter is busy.
  689. */
  690. to_switch = (prev->params.params[0].update & ~prev->params.active)
  691. | (prev->params.params[1].update & prev->params.active);
  692. to_switch &= ~(prev->params.params[0].busy |
  693. prev->params.params[1].busy);
  694. if (to_switch == 0)
  695. return;
  696. prev->params.active ^= to_switch;
  697. /* Remove the update flag for the shadow copy of parameters we have
  698. * switched.
  699. */
  700. prev->params.params[0].update &= ~(~prev->params.active & to_switch);
  701. prev->params.params[1].update &= ~(prev->params.active & to_switch);
  702. }
  703. /* preview parameters update structure */
  704. struct preview_update {
  705. void (*config)(struct isp_prev_device *, const void *);
  706. void (*enable)(struct isp_prev_device *, u8);
  707. unsigned int param_offset;
  708. unsigned int param_size;
  709. unsigned int config_offset;
  710. bool skip;
  711. };
  712. /* Keep the array indexed by the OMAP3ISP_PREV_* bit number. */
  713. static const struct preview_update update_attrs[] = {
  714. /* OMAP3ISP_PREV_LUMAENH */ {
  715. preview_config_luma_enhancement,
  716. preview_enable_luma_enhancement,
  717. offsetof(struct prev_params, luma),
  718. FIELD_SIZEOF(struct prev_params, luma),
  719. offsetof(struct omap3isp_prev_update_config, luma),
  720. }, /* OMAP3ISP_PREV_INVALAW */ {
  721. NULL,
  722. preview_enable_invalaw,
  723. }, /* OMAP3ISP_PREV_HRZ_MED */ {
  724. preview_config_hmed,
  725. preview_enable_hmed,
  726. offsetof(struct prev_params, hmed),
  727. FIELD_SIZEOF(struct prev_params, hmed),
  728. offsetof(struct omap3isp_prev_update_config, hmed),
  729. }, /* OMAP3ISP_PREV_CFA */ {
  730. preview_config_cfa,
  731. preview_enable_cfa,
  732. offsetof(struct prev_params, cfa),
  733. FIELD_SIZEOF(struct prev_params, cfa),
  734. offsetof(struct omap3isp_prev_update_config, cfa),
  735. }, /* OMAP3ISP_PREV_CHROMA_SUPP */ {
  736. preview_config_chroma_suppression,
  737. preview_enable_chroma_suppression,
  738. offsetof(struct prev_params, csup),
  739. FIELD_SIZEOF(struct prev_params, csup),
  740. offsetof(struct omap3isp_prev_update_config, csup),
  741. }, /* OMAP3ISP_PREV_WB */ {
  742. preview_config_whitebalance,
  743. NULL,
  744. offsetof(struct prev_params, wbal),
  745. FIELD_SIZEOF(struct prev_params, wbal),
  746. offsetof(struct omap3isp_prev_update_config, wbal),
  747. }, /* OMAP3ISP_PREV_BLKADJ */ {
  748. preview_config_blkadj,
  749. NULL,
  750. offsetof(struct prev_params, blkadj),
  751. FIELD_SIZEOF(struct prev_params, blkadj),
  752. offsetof(struct omap3isp_prev_update_config, blkadj),
  753. }, /* OMAP3ISP_PREV_RGB2RGB */ {
  754. preview_config_rgb_blending,
  755. NULL,
  756. offsetof(struct prev_params, rgb2rgb),
  757. FIELD_SIZEOF(struct prev_params, rgb2rgb),
  758. offsetof(struct omap3isp_prev_update_config, rgb2rgb),
  759. }, /* OMAP3ISP_PREV_COLOR_CONV */ {
  760. preview_config_rgb_to_ycbcr,
  761. NULL,
  762. offsetof(struct prev_params, csc),
  763. FIELD_SIZEOF(struct prev_params, csc),
  764. offsetof(struct omap3isp_prev_update_config, csc),
  765. }, /* OMAP3ISP_PREV_YC_LIMIT */ {
  766. preview_config_yc_range,
  767. NULL,
  768. offsetof(struct prev_params, yclimit),
  769. FIELD_SIZEOF(struct prev_params, yclimit),
  770. offsetof(struct omap3isp_prev_update_config, yclimit),
  771. }, /* OMAP3ISP_PREV_DEFECT_COR */ {
  772. preview_config_dcor,
  773. preview_enable_dcor,
  774. offsetof(struct prev_params, dcor),
  775. FIELD_SIZEOF(struct prev_params, dcor),
  776. offsetof(struct omap3isp_prev_update_config, dcor),
  777. }, /* OMAP3ISP_PREV_GAMMABYPASS */ {
  778. NULL,
  779. preview_enable_gammabypass,
  780. }, /* OMAP3ISP_PREV_DRK_FRM_CAPTURE */ {
  781. NULL,
  782. preview_enable_drkframe_capture,
  783. }, /* OMAP3ISP_PREV_DRK_FRM_SUBTRACT */ {
  784. NULL,
  785. preview_enable_drkframe,
  786. }, /* OMAP3ISP_PREV_LENS_SHADING */ {
  787. preview_config_drkf_shadcomp,
  788. preview_enable_drkframe,
  789. }, /* OMAP3ISP_PREV_NF */ {
  790. preview_config_noisefilter,
  791. preview_enable_noisefilter,
  792. offsetof(struct prev_params, nf),
  793. FIELD_SIZEOF(struct prev_params, nf),
  794. offsetof(struct omap3isp_prev_update_config, nf),
  795. }, /* OMAP3ISP_PREV_GAMMA */ {
  796. preview_config_gammacorrn,
  797. NULL,
  798. offsetof(struct prev_params, gamma),
  799. FIELD_SIZEOF(struct prev_params, gamma),
  800. offsetof(struct omap3isp_prev_update_config, gamma),
  801. }, /* OMAP3ISP_PREV_CONTRAST */ {
  802. preview_config_contrast,
  803. NULL,
  804. offsetof(struct prev_params, contrast),
  805. 0, true,
  806. }, /* OMAP3ISP_PREV_BRIGHTNESS */ {
  807. preview_config_brightness,
  808. NULL,
  809. offsetof(struct prev_params, brightness),
  810. 0, true,
  811. },
  812. };
  813. /*
  814. * preview_config - Copy and update local structure with userspace preview
  815. * configuration.
  816. * @prev: ISP preview engine
  817. * @cfg: Configuration
  818. *
  819. * Return zero if success or -EFAULT if the configuration can't be copied from
  820. * userspace.
  821. */
  822. static int preview_config(struct isp_prev_device *prev,
  823. struct omap3isp_prev_update_config *cfg)
  824. {
  825. unsigned long flags;
  826. unsigned int i;
  827. int rval = 0;
  828. u32 update;
  829. u32 active;
  830. if (cfg->update == 0)
  831. return 0;
  832. /* Mark the shadow parameters we're going to update as busy. */
  833. spin_lock_irqsave(&prev->params.lock, flags);
  834. preview_params_lock(prev, cfg->update, true);
  835. active = prev->params.active;
  836. spin_unlock_irqrestore(&prev->params.lock, flags);
  837. update = 0;
  838. for (i = 0; i < ARRAY_SIZE(update_attrs); i++) {
  839. const struct preview_update *attr = &update_attrs[i];
  840. struct prev_params *params;
  841. unsigned int bit = 1 << i;
  842. if (attr->skip || !(cfg->update & bit))
  843. continue;
  844. params = &prev->params.params[!!(active & bit)];
  845. if (cfg->flag & bit) {
  846. void __user *from = *(void * __user *)
  847. ((void *)cfg + attr->config_offset);
  848. void *to = (void *)params + attr->param_offset;
  849. size_t size = attr->param_size;
  850. if (to && from && size) {
  851. if (copy_from_user(to, from, size)) {
  852. rval = -EFAULT;
  853. break;
  854. }
  855. }
  856. params->features |= bit;
  857. } else {
  858. params->features &= ~bit;
  859. }
  860. update |= bit;
  861. }
  862. spin_lock_irqsave(&prev->params.lock, flags);
  863. preview_params_unlock(prev, update, true);
  864. preview_params_switch(prev);
  865. spin_unlock_irqrestore(&prev->params.lock, flags);
  866. return rval;
  867. }
  868. /*
  869. * preview_setup_hw - Setup preview registers and/or internal memory
  870. * @prev: pointer to preview private structure
  871. * @update: Bitmask of parameters to setup
  872. * @active: Bitmask of parameters active in set 0
  873. * Note: can be called from interrupt context
  874. * Return none
  875. */
  876. static void preview_setup_hw(struct isp_prev_device *prev, u32 update,
  877. u32 active)
  878. {
  879. unsigned int i;
  880. u32 features;
  881. if (update == 0)
  882. return;
  883. features = (prev->params.params[0].features & active)
  884. | (prev->params.params[1].features & ~active);
  885. for (i = 0; i < ARRAY_SIZE(update_attrs); i++) {
  886. const struct preview_update *attr = &update_attrs[i];
  887. struct prev_params *params;
  888. unsigned int bit = 1 << i;
  889. void *param_ptr;
  890. if (!(update & bit))
  891. continue;
  892. params = &prev->params.params[!(active & bit)];
  893. if (params->features & bit) {
  894. if (attr->config) {
  895. param_ptr = (void *)params + attr->param_offset;
  896. attr->config(prev, param_ptr);
  897. }
  898. if (attr->enable)
  899. attr->enable(prev, 1);
  900. } else {
  901. if (attr->enable)
  902. attr->enable(prev, 0);
  903. }
  904. }
  905. }
  906. /*
  907. * preview_config_ycpos - Configure byte layout of YUV image.
  908. * @mode: Indicates the required byte layout.
  909. */
  910. static void
  911. preview_config_ycpos(struct isp_prev_device *prev,
  912. enum v4l2_mbus_pixelcode pixelcode)
  913. {
  914. struct isp_device *isp = to_isp_device(prev);
  915. enum preview_ycpos_mode mode;
  916. switch (pixelcode) {
  917. case V4L2_MBUS_FMT_YUYV8_1X16:
  918. mode = YCPOS_CrYCbY;
  919. break;
  920. case V4L2_MBUS_FMT_UYVY8_1X16:
  921. mode = YCPOS_YCrYCb;
  922. break;
  923. default:
  924. return;
  925. }
  926. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  927. ISPPRV_PCR_YCPOS_CrYCbY,
  928. mode << ISPPRV_PCR_YCPOS_SHIFT);
  929. }
  930. /*
  931. * preview_config_averager - Enable / disable / configure averager
  932. * @average: Average value to be configured.
  933. */
  934. static void preview_config_averager(struct isp_prev_device *prev, u8 average)
  935. {
  936. struct isp_device *isp = to_isp_device(prev);
  937. struct prev_params *params;
  938. int reg = 0;
  939. params = (prev->params.active & OMAP3ISP_PREV_CFA)
  940. ? &prev->params.params[0] : &prev->params.params[1];
  941. if (params->cfa.format == OMAP3ISP_CFAFMT_BAYER)
  942. reg = ISPPRV_AVE_EVENDIST_2 << ISPPRV_AVE_EVENDIST_SHIFT |
  943. ISPPRV_AVE_ODDDIST_2 << ISPPRV_AVE_ODDDIST_SHIFT |
  944. average;
  945. else if (params->cfa.format == OMAP3ISP_CFAFMT_RGBFOVEON)
  946. reg = ISPPRV_AVE_EVENDIST_3 << ISPPRV_AVE_EVENDIST_SHIFT |
  947. ISPPRV_AVE_ODDDIST_3 << ISPPRV_AVE_ODDDIST_SHIFT |
  948. average;
  949. isp_reg_writel(isp, reg, OMAP3_ISP_IOMEM_PREV, ISPPRV_AVE);
  950. }
  951. /*
  952. * preview_config_input_size - Configure the input frame size
  953. *
  954. * The preview engine crops several rows and columns internally depending on
  955. * which processing blocks are enabled. The driver assumes all those blocks are
  956. * enabled when reporting source pad formats to userspace. If this assumption is
  957. * not true, rows and columns must be manually cropped at the preview engine
  958. * input to avoid overflows at the end of lines and frames.
  959. *
  960. * See the explanation at the PREV_MARGIN_* definitions for more details.
  961. */
  962. static void preview_config_input_size(struct isp_prev_device *prev, u32 active)
  963. {
  964. struct isp_device *isp = to_isp_device(prev);
  965. unsigned int sph = prev->crop.left;
  966. unsigned int eph = prev->crop.left + prev->crop.width - 1;
  967. unsigned int slv = prev->crop.top;
  968. unsigned int elv = prev->crop.top + prev->crop.height - 1;
  969. u32 features;
  970. features = (prev->params.params[0].features & active)
  971. | (prev->params.params[1].features & ~active);
  972. if (features & OMAP3ISP_PREV_CFA) {
  973. sph -= 2;
  974. eph += 2;
  975. slv -= 2;
  976. elv += 2;
  977. }
  978. if (features & (OMAP3ISP_PREV_DEFECT_COR | OMAP3ISP_PREV_NF)) {
  979. sph -= 2;
  980. eph += 2;
  981. slv -= 2;
  982. elv += 2;
  983. }
  984. if (features & OMAP3ISP_PREV_HRZ_MED) {
  985. sph -= 2;
  986. eph += 2;
  987. }
  988. if (features & (OMAP3ISP_PREV_CHROMA_SUPP | OMAP3ISP_PREV_LUMAENH))
  989. sph -= 2;
  990. isp_reg_writel(isp, (sph << ISPPRV_HORZ_INFO_SPH_SHIFT) | eph,
  991. OMAP3_ISP_IOMEM_PREV, ISPPRV_HORZ_INFO);
  992. isp_reg_writel(isp, (slv << ISPPRV_VERT_INFO_SLV_SHIFT) | elv,
  993. OMAP3_ISP_IOMEM_PREV, ISPPRV_VERT_INFO);
  994. }
  995. /*
  996. * preview_config_inlineoffset - Configures the Read address line offset.
  997. * @prev: Preview module
  998. * @offset: Line offset
  999. *
  1000. * According to the TRM, the line offset must be aligned on a 32 bytes boundary.
  1001. * However, a hardware bug requires the memory start address to be aligned on a
  1002. * 64 bytes boundary, so the offset probably should be aligned on 64 bytes as
  1003. * well.
  1004. */
  1005. static void
  1006. preview_config_inlineoffset(struct isp_prev_device *prev, u32 offset)
  1007. {
  1008. struct isp_device *isp = to_isp_device(prev);
  1009. isp_reg_writel(isp, offset & 0xffff, OMAP3_ISP_IOMEM_PREV,
  1010. ISPPRV_RADR_OFFSET);
  1011. }
  1012. /*
  1013. * preview_set_inaddr - Sets memory address of input frame.
  1014. * @addr: 32bit memory address aligned on 32byte boundary.
  1015. *
  1016. * Configures the memory address from which the input frame is to be read.
  1017. */
  1018. static void preview_set_inaddr(struct isp_prev_device *prev, u32 addr)
  1019. {
  1020. struct isp_device *isp = to_isp_device(prev);
  1021. isp_reg_writel(isp, addr, OMAP3_ISP_IOMEM_PREV, ISPPRV_RSDR_ADDR);
  1022. }
  1023. /*
  1024. * preview_config_outlineoffset - Configures the Write address line offset.
  1025. * @offset: Line Offset for the preview output.
  1026. *
  1027. * The offset must be a multiple of 32 bytes.
  1028. */
  1029. static void preview_config_outlineoffset(struct isp_prev_device *prev,
  1030. u32 offset)
  1031. {
  1032. struct isp_device *isp = to_isp_device(prev);
  1033. isp_reg_writel(isp, offset & 0xffff, OMAP3_ISP_IOMEM_PREV,
  1034. ISPPRV_WADD_OFFSET);
  1035. }
  1036. /*
  1037. * preview_set_outaddr - Sets the memory address to store output frame
  1038. * @addr: 32bit memory address aligned on 32byte boundary.
  1039. *
  1040. * Configures the memory address to which the output frame is written.
  1041. */
  1042. static void preview_set_outaddr(struct isp_prev_device *prev, u32 addr)
  1043. {
  1044. struct isp_device *isp = to_isp_device(prev);
  1045. isp_reg_writel(isp, addr, OMAP3_ISP_IOMEM_PREV, ISPPRV_WSDR_ADDR);
  1046. }
  1047. static void preview_adjust_bandwidth(struct isp_prev_device *prev)
  1048. {
  1049. struct isp_pipeline *pipe = to_isp_pipeline(&prev->subdev.entity);
  1050. struct isp_device *isp = to_isp_device(prev);
  1051. const struct v4l2_mbus_framefmt *ifmt = &prev->formats[PREV_PAD_SINK];
  1052. unsigned long l3_ick = pipe->l3_ick;
  1053. struct v4l2_fract *timeperframe;
  1054. unsigned int cycles_per_frame;
  1055. unsigned int requests_per_frame;
  1056. unsigned int cycles_per_request;
  1057. unsigned int minimum;
  1058. unsigned int maximum;
  1059. unsigned int value;
  1060. if (prev->input != PREVIEW_INPUT_MEMORY) {
  1061. isp_reg_clr(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_SDR_REQ_EXP,
  1062. ISPSBL_SDR_REQ_PRV_EXP_MASK);
  1063. return;
  1064. }
  1065. /* Compute the minimum number of cycles per request, based on the
  1066. * pipeline maximum data rate. This is an absolute lower bound if we
  1067. * don't want SBL overflows, so round the value up.
  1068. */
  1069. cycles_per_request = div_u64((u64)l3_ick / 2 * 256 + pipe->max_rate - 1,
  1070. pipe->max_rate);
  1071. minimum = DIV_ROUND_UP(cycles_per_request, 32);
  1072. /* Compute the maximum number of cycles per request, based on the
  1073. * requested frame rate. This is a soft upper bound to achieve a frame
  1074. * rate equal or higher than the requested value, so round the value
  1075. * down.
  1076. */
  1077. timeperframe = &pipe->max_timeperframe;
  1078. requests_per_frame = DIV_ROUND_UP(ifmt->width * 2, 256) * ifmt->height;
  1079. cycles_per_frame = div_u64((u64)l3_ick * timeperframe->numerator,
  1080. timeperframe->denominator);
  1081. cycles_per_request = cycles_per_frame / requests_per_frame;
  1082. maximum = cycles_per_request / 32;
  1083. value = max(minimum, maximum);
  1084. dev_dbg(isp->dev, "%s: cycles per request = %u\n", __func__, value);
  1085. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_SDR_REQ_EXP,
  1086. ISPSBL_SDR_REQ_PRV_EXP_MASK,
  1087. value << ISPSBL_SDR_REQ_PRV_EXP_SHIFT);
  1088. }
  1089. /*
  1090. * omap3isp_preview_busy - Gets busy state of preview module.
  1091. */
  1092. int omap3isp_preview_busy(struct isp_prev_device *prev)
  1093. {
  1094. struct isp_device *isp = to_isp_device(prev);
  1095. return isp_reg_readl(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR)
  1096. & ISPPRV_PCR_BUSY;
  1097. }
  1098. /*
  1099. * omap3isp_preview_restore_context - Restores the values of preview registers
  1100. */
  1101. void omap3isp_preview_restore_context(struct isp_device *isp)
  1102. {
  1103. struct isp_prev_device *prev = &isp->isp_prev;
  1104. const u32 update = OMAP3ISP_PREV_FEATURES_END - 1;
  1105. prev->params.params[0].update = prev->params.active & update;
  1106. prev->params.params[1].update = ~prev->params.active & update;
  1107. preview_setup_hw(prev, update, prev->params.active);
  1108. prev->params.params[0].update = 0;
  1109. prev->params.params[1].update = 0;
  1110. }
  1111. /*
  1112. * preview_print_status - Dump preview module registers to the kernel log
  1113. */
  1114. #define PREV_PRINT_REGISTER(isp, name)\
  1115. dev_dbg(isp->dev, "###PRV " #name "=0x%08x\n", \
  1116. isp_reg_readl(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_##name))
  1117. static void preview_print_status(struct isp_prev_device *prev)
  1118. {
  1119. struct isp_device *isp = to_isp_device(prev);
  1120. dev_dbg(isp->dev, "-------------Preview Register dump----------\n");
  1121. PREV_PRINT_REGISTER(isp, PCR);
  1122. PREV_PRINT_REGISTER(isp, HORZ_INFO);
  1123. PREV_PRINT_REGISTER(isp, VERT_INFO);
  1124. PREV_PRINT_REGISTER(isp, RSDR_ADDR);
  1125. PREV_PRINT_REGISTER(isp, RADR_OFFSET);
  1126. PREV_PRINT_REGISTER(isp, DSDR_ADDR);
  1127. PREV_PRINT_REGISTER(isp, DRKF_OFFSET);
  1128. PREV_PRINT_REGISTER(isp, WSDR_ADDR);
  1129. PREV_PRINT_REGISTER(isp, WADD_OFFSET);
  1130. PREV_PRINT_REGISTER(isp, AVE);
  1131. PREV_PRINT_REGISTER(isp, HMED);
  1132. PREV_PRINT_REGISTER(isp, NF);
  1133. PREV_PRINT_REGISTER(isp, WB_DGAIN);
  1134. PREV_PRINT_REGISTER(isp, WBGAIN);
  1135. PREV_PRINT_REGISTER(isp, WBSEL);
  1136. PREV_PRINT_REGISTER(isp, CFA);
  1137. PREV_PRINT_REGISTER(isp, BLKADJOFF);
  1138. PREV_PRINT_REGISTER(isp, RGB_MAT1);
  1139. PREV_PRINT_REGISTER(isp, RGB_MAT2);
  1140. PREV_PRINT_REGISTER(isp, RGB_MAT3);
  1141. PREV_PRINT_REGISTER(isp, RGB_MAT4);
  1142. PREV_PRINT_REGISTER(isp, RGB_MAT5);
  1143. PREV_PRINT_REGISTER(isp, RGB_OFF1);
  1144. PREV_PRINT_REGISTER(isp, RGB_OFF2);
  1145. PREV_PRINT_REGISTER(isp, CSC0);
  1146. PREV_PRINT_REGISTER(isp, CSC1);
  1147. PREV_PRINT_REGISTER(isp, CSC2);
  1148. PREV_PRINT_REGISTER(isp, CSC_OFFSET);
  1149. PREV_PRINT_REGISTER(isp, CNT_BRT);
  1150. PREV_PRINT_REGISTER(isp, CSUP);
  1151. PREV_PRINT_REGISTER(isp, SETUP_YC);
  1152. PREV_PRINT_REGISTER(isp, SET_TBL_ADDR);
  1153. PREV_PRINT_REGISTER(isp, CDC_THR0);
  1154. PREV_PRINT_REGISTER(isp, CDC_THR1);
  1155. PREV_PRINT_REGISTER(isp, CDC_THR2);
  1156. PREV_PRINT_REGISTER(isp, CDC_THR3);
  1157. dev_dbg(isp->dev, "--------------------------------------------\n");
  1158. }
  1159. /*
  1160. * preview_init_params - init image processing parameters.
  1161. * @prev: pointer to previewer private structure
  1162. */
  1163. static void preview_init_params(struct isp_prev_device *prev)
  1164. {
  1165. struct prev_params *params;
  1166. unsigned int i;
  1167. spin_lock_init(&prev->params.lock);
  1168. prev->params.active = ~0;
  1169. prev->params.params[0].busy = 0;
  1170. prev->params.params[0].update = OMAP3ISP_PREV_FEATURES_END - 1;
  1171. prev->params.params[1].busy = 0;
  1172. prev->params.params[1].update = 0;
  1173. params = &prev->params.params[0];
  1174. /* Init values */
  1175. params->contrast = ISPPRV_CONTRAST_DEF * ISPPRV_CONTRAST_UNITS;
  1176. params->brightness = ISPPRV_BRIGHT_DEF * ISPPRV_BRIGHT_UNITS;
  1177. params->cfa.format = OMAP3ISP_CFAFMT_BAYER;
  1178. memcpy(params->cfa.table, cfa_coef_table,
  1179. sizeof(params->cfa.table));
  1180. params->cfa.gradthrs_horz = FLR_CFA_GRADTHRS_HORZ;
  1181. params->cfa.gradthrs_vert = FLR_CFA_GRADTHRS_VERT;
  1182. params->csup.gain = FLR_CSUP_GAIN;
  1183. params->csup.thres = FLR_CSUP_THRES;
  1184. params->csup.hypf_en = 0;
  1185. memcpy(params->luma.table, luma_enhance_table,
  1186. sizeof(params->luma.table));
  1187. params->nf.spread = FLR_NF_STRGTH;
  1188. memcpy(params->nf.table, noise_filter_table, sizeof(params->nf.table));
  1189. params->dcor.couplet_mode_en = 1;
  1190. for (i = 0; i < OMAP3ISP_PREV_DETECT_CORRECT_CHANNELS; i++)
  1191. params->dcor.detect_correct[i] = DEF_DETECT_CORRECT_VAL;
  1192. memcpy(params->gamma.blue, gamma_table, sizeof(params->gamma.blue));
  1193. memcpy(params->gamma.green, gamma_table, sizeof(params->gamma.green));
  1194. memcpy(params->gamma.red, gamma_table, sizeof(params->gamma.red));
  1195. params->wbal.dgain = FLR_WBAL_DGAIN;
  1196. params->wbal.coef0 = FLR_WBAL_COEF;
  1197. params->wbal.coef1 = FLR_WBAL_COEF;
  1198. params->wbal.coef2 = FLR_WBAL_COEF;
  1199. params->wbal.coef3 = FLR_WBAL_COEF;
  1200. params->blkadj.red = FLR_BLKADJ_RED;
  1201. params->blkadj.green = FLR_BLKADJ_GREEN;
  1202. params->blkadj.blue = FLR_BLKADJ_BLUE;
  1203. params->rgb2rgb = flr_rgb2rgb;
  1204. params->csc = flr_prev_csc;
  1205. params->yclimit.minC = ISPPRV_YC_MIN;
  1206. params->yclimit.maxC = ISPPRV_YC_MAX;
  1207. params->yclimit.minY = ISPPRV_YC_MIN;
  1208. params->yclimit.maxY = ISPPRV_YC_MAX;
  1209. params->features = OMAP3ISP_PREV_CFA | OMAP3ISP_PREV_DEFECT_COR
  1210. | OMAP3ISP_PREV_NF | OMAP3ISP_PREV_GAMMA
  1211. | OMAP3ISP_PREV_BLKADJ | OMAP3ISP_PREV_YC_LIMIT
  1212. | OMAP3ISP_PREV_RGB2RGB | OMAP3ISP_PREV_COLOR_CONV
  1213. | OMAP3ISP_PREV_WB | OMAP3ISP_PREV_BRIGHTNESS
  1214. | OMAP3ISP_PREV_CONTRAST;
  1215. }
  1216. /*
  1217. * preview_max_out_width - Handle previewer hardware ouput limitations
  1218. * @isp_revision : ISP revision
  1219. * returns maximum width output for current isp revision
  1220. */
  1221. static unsigned int preview_max_out_width(struct isp_prev_device *prev)
  1222. {
  1223. struct isp_device *isp = to_isp_device(prev);
  1224. switch (isp->revision) {
  1225. case ISP_REVISION_1_0:
  1226. return PREV_MAX_OUT_WIDTH_REV_1;
  1227. case ISP_REVISION_2_0:
  1228. default:
  1229. return PREV_MAX_OUT_WIDTH_REV_2;
  1230. case ISP_REVISION_15_0:
  1231. return PREV_MAX_OUT_WIDTH_REV_15;
  1232. }
  1233. }
  1234. static void preview_configure(struct isp_prev_device *prev)
  1235. {
  1236. struct isp_device *isp = to_isp_device(prev);
  1237. struct v4l2_mbus_framefmt *format;
  1238. unsigned long flags;
  1239. u32 update;
  1240. u32 active;
  1241. spin_lock_irqsave(&prev->params.lock, flags);
  1242. /* Mark all active parameters we are going to touch as busy. */
  1243. update = preview_params_lock(prev, 0, false);
  1244. active = prev->params.active;
  1245. spin_unlock_irqrestore(&prev->params.lock, flags);
  1246. preview_setup_hw(prev, update, active);
  1247. if (prev->output & PREVIEW_OUTPUT_MEMORY)
  1248. isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  1249. ISPPRV_PCR_SDRPORT);
  1250. else
  1251. isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  1252. ISPPRV_PCR_SDRPORT);
  1253. if (prev->output & PREVIEW_OUTPUT_RESIZER)
  1254. isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  1255. ISPPRV_PCR_RSZPORT);
  1256. else
  1257. isp_reg_clr(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  1258. ISPPRV_PCR_RSZPORT);
  1259. /* PREV_PAD_SINK */
  1260. format = &prev->formats[PREV_PAD_SINK];
  1261. preview_adjust_bandwidth(prev);
  1262. preview_config_input_size(prev, active);
  1263. if (prev->input == PREVIEW_INPUT_CCDC)
  1264. preview_config_inlineoffset(prev, 0);
  1265. else
  1266. preview_config_inlineoffset(prev,
  1267. ALIGN(format->width, 0x20) * 2);
  1268. /* PREV_PAD_SOURCE */
  1269. format = &prev->formats[PREV_PAD_SOURCE];
  1270. if (prev->output & PREVIEW_OUTPUT_MEMORY)
  1271. preview_config_outlineoffset(prev,
  1272. ALIGN(format->width, 0x10) * 2);
  1273. preview_config_averager(prev, 0);
  1274. preview_config_ycpos(prev, format->code);
  1275. spin_lock_irqsave(&prev->params.lock, flags);
  1276. preview_params_unlock(prev, update, false);
  1277. spin_unlock_irqrestore(&prev->params.lock, flags);
  1278. }
  1279. /* -----------------------------------------------------------------------------
  1280. * Interrupt handling
  1281. */
  1282. static void preview_enable_oneshot(struct isp_prev_device *prev)
  1283. {
  1284. struct isp_device *isp = to_isp_device(prev);
  1285. /* The PCR.SOURCE bit is automatically reset to 0 when the PCR.ENABLE
  1286. * bit is set. As the preview engine is used in single-shot mode, we
  1287. * need to set PCR.SOURCE before enabling the preview engine.
  1288. */
  1289. if (prev->input == PREVIEW_INPUT_MEMORY)
  1290. isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  1291. ISPPRV_PCR_SOURCE);
  1292. isp_reg_set(isp, OMAP3_ISP_IOMEM_PREV, ISPPRV_PCR,
  1293. ISPPRV_PCR_EN | ISPPRV_PCR_ONESHOT);
  1294. }
  1295. void omap3isp_preview_isr_frame_sync(struct isp_prev_device *prev)
  1296. {
  1297. /*
  1298. * If ISP_VIDEO_DMAQUEUE_QUEUED is set, DMA queue had an underrun
  1299. * condition, the module was paused and now we have a buffer queued
  1300. * on the output again. Restart the pipeline if running in continuous
  1301. * mode.
  1302. */
  1303. if (prev->state == ISP_PIPELINE_STREAM_CONTINUOUS &&
  1304. prev->video_out.dmaqueue_flags & ISP_VIDEO_DMAQUEUE_QUEUED) {
  1305. preview_enable_oneshot(prev);
  1306. isp_video_dmaqueue_flags_clr(&prev->video_out);
  1307. }
  1308. }
  1309. static void preview_isr_buffer(struct isp_prev_device *prev)
  1310. {
  1311. struct isp_pipeline *pipe = to_isp_pipeline(&prev->subdev.entity);
  1312. struct isp_buffer *buffer;
  1313. int restart = 0;
  1314. if (prev->input == PREVIEW_INPUT_MEMORY) {
  1315. buffer = omap3isp_video_buffer_next(&prev->video_in);
  1316. if (buffer != NULL)
  1317. preview_set_inaddr(prev, buffer->isp_addr);
  1318. pipe->state |= ISP_PIPELINE_IDLE_INPUT;
  1319. }
  1320. if (prev->output & PREVIEW_OUTPUT_MEMORY) {
  1321. buffer = omap3isp_video_buffer_next(&prev->video_out);
  1322. if (buffer != NULL) {
  1323. preview_set_outaddr(prev, buffer->isp_addr);
  1324. restart = 1;
  1325. }
  1326. pipe->state |= ISP_PIPELINE_IDLE_OUTPUT;
  1327. }
  1328. switch (prev->state) {
  1329. case ISP_PIPELINE_STREAM_SINGLESHOT:
  1330. if (isp_pipeline_ready(pipe))
  1331. omap3isp_pipeline_set_stream(pipe,
  1332. ISP_PIPELINE_STREAM_SINGLESHOT);
  1333. break;
  1334. case ISP_PIPELINE_STREAM_CONTINUOUS:
  1335. /* If an underrun occurs, the video queue operation handler will
  1336. * restart the preview engine. Otherwise restart it immediately.
  1337. */
  1338. if (restart)
  1339. preview_enable_oneshot(prev);
  1340. break;
  1341. case ISP_PIPELINE_STREAM_STOPPED:
  1342. default:
  1343. return;
  1344. }
  1345. }
  1346. /*
  1347. * omap3isp_preview_isr - ISP preview engine interrupt handler
  1348. *
  1349. * Manage the preview engine video buffers and configure shadowed registers.
  1350. */
  1351. void omap3isp_preview_isr(struct isp_prev_device *prev)
  1352. {
  1353. unsigned long flags;
  1354. u32 update;
  1355. u32 active;
  1356. if (omap3isp_module_sync_is_stopping(&prev->wait, &prev->stopping))
  1357. return;
  1358. spin_lock_irqsave(&prev->params.lock, flags);
  1359. preview_params_switch(prev);
  1360. update = preview_params_lock(prev, 0, false);
  1361. active = prev->params.active;
  1362. spin_unlock_irqrestore(&prev->params.lock, flags);
  1363. preview_setup_hw(prev, update, active);
  1364. preview_config_input_size(prev, active);
  1365. if (prev->input == PREVIEW_INPUT_MEMORY ||
  1366. prev->output & PREVIEW_OUTPUT_MEMORY)
  1367. preview_isr_buffer(prev);
  1368. else if (prev->state == ISP_PIPELINE_STREAM_CONTINUOUS)
  1369. preview_enable_oneshot(prev);
  1370. spin_lock_irqsave(&prev->params.lock, flags);
  1371. preview_params_unlock(prev, update, false);
  1372. spin_unlock_irqrestore(&prev->params.lock, flags);
  1373. }
  1374. /* -----------------------------------------------------------------------------
  1375. * ISP video operations
  1376. */
  1377. static int preview_video_queue(struct isp_video *video,
  1378. struct isp_buffer *buffer)
  1379. {
  1380. struct isp_prev_device *prev = &video->isp->isp_prev;
  1381. if (video->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
  1382. preview_set_inaddr(prev, buffer->isp_addr);
  1383. if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  1384. preview_set_outaddr(prev, buffer->isp_addr);
  1385. return 0;
  1386. }
  1387. static const struct isp_video_operations preview_video_ops = {
  1388. .queue = preview_video_queue,
  1389. };
  1390. /* -----------------------------------------------------------------------------
  1391. * V4L2 subdev operations
  1392. */
  1393. /*
  1394. * preview_s_ctrl - Handle set control subdev method
  1395. * @ctrl: pointer to v4l2 control structure
  1396. */
  1397. static int preview_s_ctrl(struct v4l2_ctrl *ctrl)
  1398. {
  1399. struct isp_prev_device *prev =
  1400. container_of(ctrl->handler, struct isp_prev_device, ctrls);
  1401. switch (ctrl->id) {
  1402. case V4L2_CID_BRIGHTNESS:
  1403. preview_update_brightness(prev, ctrl->val);
  1404. break;
  1405. case V4L2_CID_CONTRAST:
  1406. preview_update_contrast(prev, ctrl->val);
  1407. break;
  1408. }
  1409. return 0;
  1410. }
  1411. static const struct v4l2_ctrl_ops preview_ctrl_ops = {
  1412. .s_ctrl = preview_s_ctrl,
  1413. };
  1414. /*
  1415. * preview_ioctl - Handle preview module private ioctl's
  1416. * @prev: pointer to preview context structure
  1417. * @cmd: configuration command
  1418. * @arg: configuration argument
  1419. * return -EINVAL or zero on success
  1420. */
  1421. static long preview_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
  1422. {
  1423. struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
  1424. switch (cmd) {
  1425. case VIDIOC_OMAP3ISP_PRV_CFG:
  1426. return preview_config(prev, arg);
  1427. default:
  1428. return -ENOIOCTLCMD;
  1429. }
  1430. }
  1431. /*
  1432. * preview_set_stream - Enable/Disable streaming on preview subdev
  1433. * @sd : pointer to v4l2 subdev structure
  1434. * @enable: 1 == Enable, 0 == Disable
  1435. * return -EINVAL or zero on success
  1436. */
  1437. static int preview_set_stream(struct v4l2_subdev *sd, int enable)
  1438. {
  1439. struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
  1440. struct isp_video *video_out = &prev->video_out;
  1441. struct isp_device *isp = to_isp_device(prev);
  1442. struct device *dev = to_device(prev);
  1443. if (prev->state == ISP_PIPELINE_STREAM_STOPPED) {
  1444. if (enable == ISP_PIPELINE_STREAM_STOPPED)
  1445. return 0;
  1446. omap3isp_subclk_enable(isp, OMAP3_ISP_SUBCLK_PREVIEW);
  1447. preview_configure(prev);
  1448. atomic_set(&prev->stopping, 0);
  1449. preview_print_status(prev);
  1450. }
  1451. switch (enable) {
  1452. case ISP_PIPELINE_STREAM_CONTINUOUS:
  1453. if (prev->output & PREVIEW_OUTPUT_MEMORY)
  1454. omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_PREVIEW_WRITE);
  1455. if (video_out->dmaqueue_flags & ISP_VIDEO_DMAQUEUE_QUEUED ||
  1456. !(prev->output & PREVIEW_OUTPUT_MEMORY))
  1457. preview_enable_oneshot(prev);
  1458. isp_video_dmaqueue_flags_clr(video_out);
  1459. break;
  1460. case ISP_PIPELINE_STREAM_SINGLESHOT:
  1461. if (prev->input == PREVIEW_INPUT_MEMORY)
  1462. omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_PREVIEW_READ);
  1463. if (prev->output & PREVIEW_OUTPUT_MEMORY)
  1464. omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_PREVIEW_WRITE);
  1465. preview_enable_oneshot(prev);
  1466. break;
  1467. case ISP_PIPELINE_STREAM_STOPPED:
  1468. if (omap3isp_module_sync_idle(&sd->entity, &prev->wait,
  1469. &prev->stopping))
  1470. dev_dbg(dev, "%s: stop timeout.\n", sd->name);
  1471. omap3isp_sbl_disable(isp, OMAP3_ISP_SBL_PREVIEW_READ);
  1472. omap3isp_sbl_disable(isp, OMAP3_ISP_SBL_PREVIEW_WRITE);
  1473. omap3isp_subclk_disable(isp, OMAP3_ISP_SUBCLK_PREVIEW);
  1474. isp_video_dmaqueue_flags_clr(video_out);
  1475. break;
  1476. }
  1477. prev->state = enable;
  1478. return 0;
  1479. }
  1480. static struct v4l2_mbus_framefmt *
  1481. __preview_get_format(struct isp_prev_device *prev, struct v4l2_subdev_fh *fh,
  1482. unsigned int pad, enum v4l2_subdev_format_whence which)
  1483. {
  1484. if (which == V4L2_SUBDEV_FORMAT_TRY)
  1485. return v4l2_subdev_get_try_format(fh, pad);
  1486. else
  1487. return &prev->formats[pad];
  1488. }
  1489. static struct v4l2_rect *
  1490. __preview_get_crop(struct isp_prev_device *prev, struct v4l2_subdev_fh *fh,
  1491. enum v4l2_subdev_format_whence which)
  1492. {
  1493. if (which == V4L2_SUBDEV_FORMAT_TRY)
  1494. return v4l2_subdev_get_try_crop(fh, PREV_PAD_SINK);
  1495. else
  1496. return &prev->crop;
  1497. }
  1498. /* previewer format descriptions */
  1499. static const unsigned int preview_input_fmts[] = {
  1500. V4L2_MBUS_FMT_SGRBG10_1X10,
  1501. V4L2_MBUS_FMT_SRGGB10_1X10,
  1502. V4L2_MBUS_FMT_SBGGR10_1X10,
  1503. V4L2_MBUS_FMT_SGBRG10_1X10,
  1504. };
  1505. static const unsigned int preview_output_fmts[] = {
  1506. V4L2_MBUS_FMT_UYVY8_1X16,
  1507. V4L2_MBUS_FMT_YUYV8_1X16,
  1508. };
  1509. /*
  1510. * preview_try_format - Validate a format
  1511. * @prev: ISP preview engine
  1512. * @fh: V4L2 subdev file handle
  1513. * @pad: pad number
  1514. * @fmt: format to be validated
  1515. * @which: try/active format selector
  1516. *
  1517. * Validate and adjust the given format for the given pad based on the preview
  1518. * engine limits and the format and crop rectangles on other pads.
  1519. */
  1520. static void preview_try_format(struct isp_prev_device *prev,
  1521. struct v4l2_subdev_fh *fh, unsigned int pad,
  1522. struct v4l2_mbus_framefmt *fmt,
  1523. enum v4l2_subdev_format_whence which)
  1524. {
  1525. enum v4l2_mbus_pixelcode pixelcode;
  1526. struct v4l2_rect *crop;
  1527. unsigned int i;
  1528. switch (pad) {
  1529. case PREV_PAD_SINK:
  1530. /* When reading data from the CCDC, the input size has already
  1531. * been mangled by the CCDC output pad so it can be accepted
  1532. * as-is.
  1533. *
  1534. * When reading data from memory, clamp the requested width and
  1535. * height. The TRM doesn't specify a minimum input height, make
  1536. * sure we got enough lines to enable the noise filter and color
  1537. * filter array interpolation.
  1538. */
  1539. if (prev->input == PREVIEW_INPUT_MEMORY) {
  1540. fmt->width = clamp_t(u32, fmt->width, PREV_MIN_IN_WIDTH,
  1541. preview_max_out_width(prev));
  1542. fmt->height = clamp_t(u32, fmt->height,
  1543. PREV_MIN_IN_HEIGHT,
  1544. PREV_MAX_IN_HEIGHT);
  1545. }
  1546. fmt->colorspace = V4L2_COLORSPACE_SRGB;
  1547. for (i = 0; i < ARRAY_SIZE(preview_input_fmts); i++) {
  1548. if (fmt->code == preview_input_fmts[i])
  1549. break;
  1550. }
  1551. /* If not found, use SGRBG10 as default */
  1552. if (i >= ARRAY_SIZE(preview_input_fmts))
  1553. fmt->code = V4L2_MBUS_FMT_SGRBG10_1X10;
  1554. break;
  1555. case PREV_PAD_SOURCE:
  1556. pixelcode = fmt->code;
  1557. *fmt = *__preview_get_format(prev, fh, PREV_PAD_SINK, which);
  1558. switch (pixelcode) {
  1559. case V4L2_MBUS_FMT_YUYV8_1X16:
  1560. case V4L2_MBUS_FMT_UYVY8_1X16:
  1561. fmt->code = pixelcode;
  1562. break;
  1563. default:
  1564. fmt->code = V4L2_MBUS_FMT_YUYV8_1X16;
  1565. break;
  1566. }
  1567. /* The preview module output size is configurable through the
  1568. * averager (horizontal scaling by 1/1, 1/2, 1/4 or 1/8). This
  1569. * is not supported yet, hardcode the output size to the crop
  1570. * rectangle size.
  1571. */
  1572. crop = __preview_get_crop(prev, fh, which);
  1573. fmt->width = crop->width;
  1574. fmt->height = crop->height;
  1575. fmt->colorspace = V4L2_COLORSPACE_JPEG;
  1576. break;
  1577. }
  1578. fmt->field = V4L2_FIELD_NONE;
  1579. }
  1580. /*
  1581. * preview_try_crop - Validate a crop rectangle
  1582. * @prev: ISP preview engine
  1583. * @sink: format on the sink pad
  1584. * @crop: crop rectangle to be validated
  1585. *
  1586. * The preview engine crops lines and columns for its internal operation,
  1587. * depending on which filters are enabled. Enforce minimum crop margins to
  1588. * handle that transparently for userspace.
  1589. *
  1590. * See the explanation at the PREV_MARGIN_* definitions for more details.
  1591. */
  1592. static void preview_try_crop(struct isp_prev_device *prev,
  1593. const struct v4l2_mbus_framefmt *sink,
  1594. struct v4l2_rect *crop)
  1595. {
  1596. unsigned int left = PREV_MARGIN_LEFT;
  1597. unsigned int right = sink->width - PREV_MARGIN_RIGHT;
  1598. unsigned int top = PREV_MARGIN_TOP;
  1599. unsigned int bottom = sink->height - PREV_MARGIN_BOTTOM;
  1600. /* When processing data on-the-fly from the CCDC, at least 2 pixels must
  1601. * be cropped from the left and right sides of the image. As we don't
  1602. * know which filters will be enabled, increase the left and right
  1603. * margins by two.
  1604. */
  1605. if (prev->input == PREVIEW_INPUT_CCDC) {
  1606. left += 2;
  1607. right -= 2;
  1608. }
  1609. /* Restrict left/top to even values to keep the Bayer pattern. */
  1610. crop->left &= ~1;
  1611. crop->top &= ~1;
  1612. crop->left = clamp_t(u32, crop->left, left, right - PREV_MIN_OUT_WIDTH);
  1613. crop->top = clamp_t(u32, crop->top, top, bottom - PREV_MIN_OUT_HEIGHT);
  1614. crop->width = clamp_t(u32, crop->width, PREV_MIN_OUT_WIDTH,
  1615. right - crop->left);
  1616. crop->height = clamp_t(u32, crop->height, PREV_MIN_OUT_HEIGHT,
  1617. bottom - crop->top);
  1618. }
  1619. /*
  1620. * preview_enum_mbus_code - Handle pixel format enumeration
  1621. * @sd : pointer to v4l2 subdev structure
  1622. * @fh : V4L2 subdev file handle
  1623. * @code : pointer to v4l2_subdev_mbus_code_enum structure
  1624. * return -EINVAL or zero on success
  1625. */
  1626. static int preview_enum_mbus_code(struct v4l2_subdev *sd,
  1627. struct v4l2_subdev_fh *fh,
  1628. struct v4l2_subdev_mbus_code_enum *code)
  1629. {
  1630. switch (code->pad) {
  1631. case PREV_PAD_SINK:
  1632. if (code->index >= ARRAY_SIZE(preview_input_fmts))
  1633. return -EINVAL;
  1634. code->code = preview_input_fmts[code->index];
  1635. break;
  1636. case PREV_PAD_SOURCE:
  1637. if (code->index >= ARRAY_SIZE(preview_output_fmts))
  1638. return -EINVAL;
  1639. code->code = preview_output_fmts[code->index];
  1640. break;
  1641. default:
  1642. return -EINVAL;
  1643. }
  1644. return 0;
  1645. }
  1646. static int preview_enum_frame_size(struct v4l2_subdev *sd,
  1647. struct v4l2_subdev_fh *fh,
  1648. struct v4l2_subdev_frame_size_enum *fse)
  1649. {
  1650. struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
  1651. struct v4l2_mbus_framefmt format;
  1652. if (fse->index != 0)
  1653. return -EINVAL;
  1654. format.code = fse->code;
  1655. format.width = 1;
  1656. format.height = 1;
  1657. preview_try_format(prev, fh, fse->pad, &format, V4L2_SUBDEV_FORMAT_TRY);
  1658. fse->min_width = format.width;
  1659. fse->min_height = format.height;
  1660. if (format.code != fse->code)
  1661. return -EINVAL;
  1662. format.code = fse->code;
  1663. format.width = -1;
  1664. format.height = -1;
  1665. preview_try_format(prev, fh, fse->pad, &format, V4L2_SUBDEV_FORMAT_TRY);
  1666. fse->max_width = format.width;
  1667. fse->max_height = format.height;
  1668. return 0;
  1669. }
  1670. /*
  1671. * preview_get_crop - Retrieve the crop rectangle on a pad
  1672. * @sd: ISP preview V4L2 subdevice
  1673. * @fh: V4L2 subdev file handle
  1674. * @crop: crop rectangle
  1675. *
  1676. * Return 0 on success or a negative error code otherwise.
  1677. */
  1678. static int preview_get_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
  1679. struct v4l2_subdev_crop *crop)
  1680. {
  1681. struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
  1682. /* Cropping is only supported on the sink pad. */
  1683. if (crop->pad != PREV_PAD_SINK)
  1684. return -EINVAL;
  1685. crop->rect = *__preview_get_crop(prev, fh, crop->which);
  1686. return 0;
  1687. }
  1688. /*
  1689. * preview_set_crop - Retrieve the crop rectangle on a pad
  1690. * @sd: ISP preview V4L2 subdevice
  1691. * @fh: V4L2 subdev file handle
  1692. * @crop: crop rectangle
  1693. *
  1694. * Return 0 on success or a negative error code otherwise.
  1695. */
  1696. static int preview_set_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
  1697. struct v4l2_subdev_crop *crop)
  1698. {
  1699. struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
  1700. struct v4l2_mbus_framefmt *format;
  1701. /* Cropping is only supported on the sink pad. */
  1702. if (crop->pad != PREV_PAD_SINK)
  1703. return -EINVAL;
  1704. /* The crop rectangle can't be changed while streaming. */
  1705. if (prev->state != ISP_PIPELINE_STREAM_STOPPED)
  1706. return -EBUSY;
  1707. format = __preview_get_format(prev, fh, PREV_PAD_SINK, crop->which);
  1708. preview_try_crop(prev, format, &crop->rect);
  1709. *__preview_get_crop(prev, fh, crop->which) = crop->rect;
  1710. /* Update the source format. */
  1711. format = __preview_get_format(prev, fh, PREV_PAD_SOURCE, crop->which);
  1712. preview_try_format(prev, fh, PREV_PAD_SOURCE, format, crop->which);
  1713. return 0;
  1714. }
  1715. /*
  1716. * preview_get_format - Handle get format by pads subdev method
  1717. * @sd : pointer to v4l2 subdev structure
  1718. * @fh : V4L2 subdev file handle
  1719. * @fmt: pointer to v4l2 subdev format structure
  1720. * return -EINVAL or zero on success
  1721. */
  1722. static int preview_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
  1723. struct v4l2_subdev_format *fmt)
  1724. {
  1725. struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
  1726. struct v4l2_mbus_framefmt *format;
  1727. format = __preview_get_format(prev, fh, fmt->pad, fmt->which);
  1728. if (format == NULL)
  1729. return -EINVAL;
  1730. fmt->format = *format;
  1731. return 0;
  1732. }
  1733. /*
  1734. * preview_set_format - Handle set format by pads subdev method
  1735. * @sd : pointer to v4l2 subdev structure
  1736. * @fh : V4L2 subdev file handle
  1737. * @fmt: pointer to v4l2 subdev format structure
  1738. * return -EINVAL or zero on success
  1739. */
  1740. static int preview_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
  1741. struct v4l2_subdev_format *fmt)
  1742. {
  1743. struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
  1744. struct v4l2_mbus_framefmt *format;
  1745. struct v4l2_rect *crop;
  1746. format = __preview_get_format(prev, fh, fmt->pad, fmt->which);
  1747. if (format == NULL)
  1748. return -EINVAL;
  1749. preview_try_format(prev, fh, fmt->pad, &fmt->format, fmt->which);
  1750. *format = fmt->format;
  1751. /* Propagate the format from sink to source */
  1752. if (fmt->pad == PREV_PAD_SINK) {
  1753. /* Reset the crop rectangle. */
  1754. crop = __preview_get_crop(prev, fh, fmt->which);
  1755. crop->left = 0;
  1756. crop->top = 0;
  1757. crop->width = fmt->format.width;
  1758. crop->height = fmt->format.height;
  1759. preview_try_crop(prev, &fmt->format, crop);
  1760. /* Update the source format. */
  1761. format = __preview_get_format(prev, fh, PREV_PAD_SOURCE,
  1762. fmt->which);
  1763. preview_try_format(prev, fh, PREV_PAD_SOURCE, format,
  1764. fmt->which);
  1765. }
  1766. return 0;
  1767. }
  1768. /*
  1769. * preview_init_formats - Initialize formats on all pads
  1770. * @sd: ISP preview V4L2 subdevice
  1771. * @fh: V4L2 subdev file handle
  1772. *
  1773. * Initialize all pad formats with default values. If fh is not NULL, try
  1774. * formats are initialized on the file handle. Otherwise active formats are
  1775. * initialized on the device.
  1776. */
  1777. static int preview_init_formats(struct v4l2_subdev *sd,
  1778. struct v4l2_subdev_fh *fh)
  1779. {
  1780. struct v4l2_subdev_format format;
  1781. memset(&format, 0, sizeof(format));
  1782. format.pad = PREV_PAD_SINK;
  1783. format.which = fh ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
  1784. format.format.code = V4L2_MBUS_FMT_SGRBG10_1X10;
  1785. format.format.width = 4096;
  1786. format.format.height = 4096;
  1787. preview_set_format(sd, fh, &format);
  1788. return 0;
  1789. }
  1790. /* subdev core operations */
  1791. static const struct v4l2_subdev_core_ops preview_v4l2_core_ops = {
  1792. .ioctl = preview_ioctl,
  1793. };
  1794. /* subdev video operations */
  1795. static const struct v4l2_subdev_video_ops preview_v4l2_video_ops = {
  1796. .s_stream = preview_set_stream,
  1797. };
  1798. /* subdev pad operations */
  1799. static const struct v4l2_subdev_pad_ops preview_v4l2_pad_ops = {
  1800. .enum_mbus_code = preview_enum_mbus_code,
  1801. .enum_frame_size = preview_enum_frame_size,
  1802. .get_fmt = preview_get_format,
  1803. .set_fmt = preview_set_format,
  1804. .get_crop = preview_get_crop,
  1805. .set_crop = preview_set_crop,
  1806. };
  1807. /* subdev operations */
  1808. static const struct v4l2_subdev_ops preview_v4l2_ops = {
  1809. .core = &preview_v4l2_core_ops,
  1810. .video = &preview_v4l2_video_ops,
  1811. .pad = &preview_v4l2_pad_ops,
  1812. };
  1813. /* subdev internal operations */
  1814. static const struct v4l2_subdev_internal_ops preview_v4l2_internal_ops = {
  1815. .open = preview_init_formats,
  1816. };
  1817. /* -----------------------------------------------------------------------------
  1818. * Media entity operations
  1819. */
  1820. /*
  1821. * preview_link_setup - Setup previewer connections.
  1822. * @entity : Pointer to media entity structure
  1823. * @local : Pointer to local pad array
  1824. * @remote : Pointer to remote pad array
  1825. * @flags : Link flags
  1826. * return -EINVAL or zero on success
  1827. */
  1828. static int preview_link_setup(struct media_entity *entity,
  1829. const struct media_pad *local,
  1830. const struct media_pad *remote, u32 flags)
  1831. {
  1832. struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
  1833. struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
  1834. switch (local->index | media_entity_type(remote->entity)) {
  1835. case PREV_PAD_SINK | MEDIA_ENT_T_DEVNODE:
  1836. /* read from memory */
  1837. if (flags & MEDIA_LNK_FL_ENABLED) {
  1838. if (prev->input == PREVIEW_INPUT_CCDC)
  1839. return -EBUSY;
  1840. prev->input = PREVIEW_INPUT_MEMORY;
  1841. } else {
  1842. if (prev->input == PREVIEW_INPUT_MEMORY)
  1843. prev->input = PREVIEW_INPUT_NONE;
  1844. }
  1845. break;
  1846. case PREV_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
  1847. /* read from ccdc */
  1848. if (flags & MEDIA_LNK_FL_ENABLED) {
  1849. if (prev->input == PREVIEW_INPUT_MEMORY)
  1850. return -EBUSY;
  1851. prev->input = PREVIEW_INPUT_CCDC;
  1852. } else {
  1853. if (prev->input == PREVIEW_INPUT_CCDC)
  1854. prev->input = PREVIEW_INPUT_NONE;
  1855. }
  1856. break;
  1857. /*
  1858. * The ISP core doesn't support pipelines with multiple video outputs.
  1859. * Revisit this when it will be implemented, and return -EBUSY for now.
  1860. */
  1861. case PREV_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
  1862. /* write to memory */
  1863. if (flags & MEDIA_LNK_FL_ENABLED) {
  1864. if (prev->output & ~PREVIEW_OUTPUT_MEMORY)
  1865. return -EBUSY;
  1866. prev->output |= PREVIEW_OUTPUT_MEMORY;
  1867. } else {
  1868. prev->output &= ~PREVIEW_OUTPUT_MEMORY;
  1869. }
  1870. break;
  1871. case PREV_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
  1872. /* write to resizer */
  1873. if (flags & MEDIA_LNK_FL_ENABLED) {
  1874. if (prev->output & ~PREVIEW_OUTPUT_RESIZER)
  1875. return -EBUSY;
  1876. prev->output |= PREVIEW_OUTPUT_RESIZER;
  1877. } else {
  1878. prev->output &= ~PREVIEW_OUTPUT_RESIZER;
  1879. }
  1880. break;
  1881. default:
  1882. return -EINVAL;
  1883. }
  1884. return 0;
  1885. }
  1886. /* media operations */
  1887. static const struct media_entity_operations preview_media_ops = {
  1888. .link_setup = preview_link_setup,
  1889. };
  1890. void omap3isp_preview_unregister_entities(struct isp_prev_device *prev)
  1891. {
  1892. v4l2_device_unregister_subdev(&prev->subdev);
  1893. omap3isp_video_unregister(&prev->video_in);
  1894. omap3isp_video_unregister(&prev->video_out);
  1895. }
  1896. int omap3isp_preview_register_entities(struct isp_prev_device *prev,
  1897. struct v4l2_device *vdev)
  1898. {
  1899. int ret;
  1900. /* Register the subdev and video nodes. */
  1901. ret = v4l2_device_register_subdev(vdev, &prev->subdev);
  1902. if (ret < 0)
  1903. goto error;
  1904. ret = omap3isp_video_register(&prev->video_in, vdev);
  1905. if (ret < 0)
  1906. goto error;
  1907. ret = omap3isp_video_register(&prev->video_out, vdev);
  1908. if (ret < 0)
  1909. goto error;
  1910. return 0;
  1911. error:
  1912. omap3isp_preview_unregister_entities(prev);
  1913. return ret;
  1914. }
  1915. /* -----------------------------------------------------------------------------
  1916. * ISP previewer initialisation and cleanup
  1917. */
  1918. /*
  1919. * preview_init_entities - Initialize subdev and media entity.
  1920. * @prev : Pointer to preview structure
  1921. * return -ENOMEM or zero on success
  1922. */
  1923. static int preview_init_entities(struct isp_prev_device *prev)
  1924. {
  1925. struct v4l2_subdev *sd = &prev->subdev;
  1926. struct media_pad *pads = prev->pads;
  1927. struct media_entity *me = &sd->entity;
  1928. int ret;
  1929. prev->input = PREVIEW_INPUT_NONE;
  1930. v4l2_subdev_init(sd, &preview_v4l2_ops);
  1931. sd->internal_ops = &preview_v4l2_internal_ops;
  1932. strlcpy(sd->name, "OMAP3 ISP preview", sizeof(sd->name));
  1933. sd->grp_id = 1 << 16; /* group ID for isp subdevs */
  1934. v4l2_set_subdevdata(sd, prev);
  1935. sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
  1936. v4l2_ctrl_handler_init(&prev->ctrls, 2);
  1937. v4l2_ctrl_new_std(&prev->ctrls, &preview_ctrl_ops, V4L2_CID_BRIGHTNESS,
  1938. ISPPRV_BRIGHT_LOW, ISPPRV_BRIGHT_HIGH,
  1939. ISPPRV_BRIGHT_STEP, ISPPRV_BRIGHT_DEF);
  1940. v4l2_ctrl_new_std(&prev->ctrls, &preview_ctrl_ops, V4L2_CID_CONTRAST,
  1941. ISPPRV_CONTRAST_LOW, ISPPRV_CONTRAST_HIGH,
  1942. ISPPRV_CONTRAST_STEP, ISPPRV_CONTRAST_DEF);
  1943. v4l2_ctrl_handler_setup(&prev->ctrls);
  1944. sd->ctrl_handler = &prev->ctrls;
  1945. pads[PREV_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
  1946. pads[PREV_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
  1947. me->ops = &preview_media_ops;
  1948. ret = media_entity_init(me, PREV_PADS_NUM, pads, 0);
  1949. if (ret < 0)
  1950. return ret;
  1951. preview_init_formats(sd, NULL);
  1952. /* According to the OMAP34xx TRM, video buffers need to be aligned on a
  1953. * 32 bytes boundary. However, an undocumented hardware bug requires a
  1954. * 64 bytes boundary at the preview engine input.
  1955. */
  1956. prev->video_in.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
  1957. prev->video_in.ops = &preview_video_ops;
  1958. prev->video_in.isp = to_isp_device(prev);
  1959. prev->video_in.capture_mem = PAGE_ALIGN(4096 * 4096) * 2 * 3;
  1960. prev->video_in.bpl_alignment = 64;
  1961. prev->video_out.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1962. prev->video_out.ops = &preview_video_ops;
  1963. prev->video_out.isp = to_isp_device(prev);
  1964. prev->video_out.capture_mem = PAGE_ALIGN(4096 * 4096) * 2 * 3;
  1965. prev->video_out.bpl_alignment = 32;
  1966. ret = omap3isp_video_init(&prev->video_in, "preview");
  1967. if (ret < 0)
  1968. goto error_video_in;
  1969. ret = omap3isp_video_init(&prev->video_out, "preview");
  1970. if (ret < 0)
  1971. goto error_video_out;
  1972. /* Connect the video nodes to the previewer subdev. */
  1973. ret = media_entity_create_link(&prev->video_in.video.entity, 0,
  1974. &prev->subdev.entity, PREV_PAD_SINK, 0);
  1975. if (ret < 0)
  1976. goto error_link;
  1977. ret = media_entity_create_link(&prev->subdev.entity, PREV_PAD_SOURCE,
  1978. &prev->video_out.video.entity, 0, 0);
  1979. if (ret < 0)
  1980. goto error_link;
  1981. return 0;
  1982. error_link:
  1983. omap3isp_video_cleanup(&prev->video_out);
  1984. error_video_out:
  1985. omap3isp_video_cleanup(&prev->video_in);
  1986. error_video_in:
  1987. media_entity_cleanup(&prev->subdev.entity);
  1988. return ret;
  1989. }
  1990. /*
  1991. * omap3isp_preview_init - Previewer initialization.
  1992. * @dev : Pointer to ISP device
  1993. * return -ENOMEM or zero on success
  1994. */
  1995. int omap3isp_preview_init(struct isp_device *isp)
  1996. {
  1997. struct isp_prev_device *prev = &isp->isp_prev;
  1998. init_waitqueue_head(&prev->wait);
  1999. preview_init_params(prev);
  2000. return preview_init_entities(prev);
  2001. }
  2002. void omap3isp_preview_cleanup(struct isp_device *isp)
  2003. {
  2004. struct isp_prev_device *prev = &isp->isp_prev;
  2005. v4l2_ctrl_handler_free(&prev->ctrls);
  2006. omap3isp_video_cleanup(&prev->video_in);
  2007. omap3isp_video_cleanup(&prev->video_out);
  2008. media_entity_cleanup(&prev->subdev.entity);
  2009. }