isppreview.c 65 KB

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