ispresizer.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693
  1. /*
  2. * ispresizer.c
  3. *
  4. * TI OMAP3 ISP - Resizer 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 "isp.h"
  30. #include "ispreg.h"
  31. #include "ispresizer.h"
  32. /*
  33. * Resizer Constants
  34. */
  35. #define MIN_RESIZE_VALUE 64
  36. #define MID_RESIZE_VALUE 512
  37. #define MAX_RESIZE_VALUE 1024
  38. #define MIN_IN_WIDTH 32
  39. #define MIN_IN_HEIGHT 32
  40. #define MAX_IN_WIDTH_MEMORY_MODE 4095
  41. #define MAX_IN_WIDTH_ONTHEFLY_MODE_ES1 1280
  42. #define MAX_IN_WIDTH_ONTHEFLY_MODE_ES2 4095
  43. #define MAX_IN_HEIGHT 4095
  44. #define MIN_OUT_WIDTH 16
  45. #define MIN_OUT_HEIGHT 2
  46. #define MAX_OUT_HEIGHT 4095
  47. /*
  48. * Resizer Use Constraints
  49. * "TRM ES3.1, table 12-46"
  50. */
  51. #define MAX_4TAP_OUT_WIDTH_ES1 1280
  52. #define MAX_7TAP_OUT_WIDTH_ES1 640
  53. #define MAX_4TAP_OUT_WIDTH_ES2 3312
  54. #define MAX_7TAP_OUT_WIDTH_ES2 1650
  55. #define MAX_4TAP_OUT_WIDTH_3630 4096
  56. #define MAX_7TAP_OUT_WIDTH_3630 2048
  57. /*
  58. * Constants for ratio calculation
  59. */
  60. #define RESIZE_DIVISOR 256
  61. #define DEFAULT_PHASE 1
  62. /*
  63. * Default (and only) configuration of filter coefficients.
  64. * 7-tap mode is for scale factors 0.25x to 0.5x.
  65. * 4-tap mode is for scale factors 0.5x to 4.0x.
  66. * There shouldn't be any reason to recalculate these, EVER.
  67. */
  68. static const struct isprsz_coef filter_coefs = {
  69. /* For 8-phase 4-tap horizontal filter: */
  70. {
  71. 0x0000, 0x0100, 0x0000, 0x0000,
  72. 0x03FA, 0x00F6, 0x0010, 0x0000,
  73. 0x03F9, 0x00DB, 0x002C, 0x0000,
  74. 0x03FB, 0x00B3, 0x0053, 0x03FF,
  75. 0x03FD, 0x0082, 0x0084, 0x03FD,
  76. 0x03FF, 0x0053, 0x00B3, 0x03FB,
  77. 0x0000, 0x002C, 0x00DB, 0x03F9,
  78. 0x0000, 0x0010, 0x00F6, 0x03FA
  79. },
  80. /* For 8-phase 4-tap vertical filter: */
  81. {
  82. 0x0000, 0x0100, 0x0000, 0x0000,
  83. 0x03FA, 0x00F6, 0x0010, 0x0000,
  84. 0x03F9, 0x00DB, 0x002C, 0x0000,
  85. 0x03FB, 0x00B3, 0x0053, 0x03FF,
  86. 0x03FD, 0x0082, 0x0084, 0x03FD,
  87. 0x03FF, 0x0053, 0x00B3, 0x03FB,
  88. 0x0000, 0x002C, 0x00DB, 0x03F9,
  89. 0x0000, 0x0010, 0x00F6, 0x03FA
  90. },
  91. /* For 4-phase 7-tap horizontal filter: */
  92. #define DUMMY 0
  93. {
  94. 0x0004, 0x0023, 0x005A, 0x0058, 0x0023, 0x0004, 0x0000, DUMMY,
  95. 0x0002, 0x0018, 0x004d, 0x0060, 0x0031, 0x0008, 0x0000, DUMMY,
  96. 0x0001, 0x000f, 0x003f, 0x0062, 0x003f, 0x000f, 0x0001, DUMMY,
  97. 0x0000, 0x0008, 0x0031, 0x0060, 0x004d, 0x0018, 0x0002, DUMMY
  98. },
  99. /* For 4-phase 7-tap vertical filter: */
  100. {
  101. 0x0004, 0x0023, 0x005A, 0x0058, 0x0023, 0x0004, 0x0000, DUMMY,
  102. 0x0002, 0x0018, 0x004d, 0x0060, 0x0031, 0x0008, 0x0000, DUMMY,
  103. 0x0001, 0x000f, 0x003f, 0x0062, 0x003f, 0x000f, 0x0001, DUMMY,
  104. 0x0000, 0x0008, 0x0031, 0x0060, 0x004d, 0x0018, 0x0002, DUMMY
  105. }
  106. /*
  107. * The dummy padding is required in 7-tap mode because of how the
  108. * registers are arranged physically.
  109. */
  110. #undef DUMMY
  111. };
  112. /*
  113. * __resizer_get_format - helper function for getting resizer format
  114. * @res : pointer to resizer private structure
  115. * @pad : pad number
  116. * @fh : V4L2 subdev file handle
  117. * @which : wanted subdev format
  118. * return zero
  119. */
  120. static struct v4l2_mbus_framefmt *
  121. __resizer_get_format(struct isp_res_device *res, struct v4l2_subdev_fh *fh,
  122. unsigned int pad, enum v4l2_subdev_format_whence which)
  123. {
  124. if (which == V4L2_SUBDEV_FORMAT_TRY)
  125. return v4l2_subdev_get_try_format(fh, pad);
  126. else
  127. return &res->formats[pad];
  128. }
  129. /*
  130. * __resizer_get_crop - helper function for getting resizer crop rectangle
  131. * @res : pointer to resizer private structure
  132. * @fh : V4L2 subdev file handle
  133. * @which : wanted subdev crop rectangle
  134. */
  135. static struct v4l2_rect *
  136. __resizer_get_crop(struct isp_res_device *res, struct v4l2_subdev_fh *fh,
  137. enum v4l2_subdev_format_whence which)
  138. {
  139. if (which == V4L2_SUBDEV_FORMAT_TRY)
  140. return v4l2_subdev_get_try_crop(fh, RESZ_PAD_SINK);
  141. else
  142. return &res->crop.request;
  143. }
  144. /*
  145. * resizer_set_filters - Set resizer filters
  146. * @res: Device context.
  147. * @h_coeff: horizontal coefficient
  148. * @v_coeff: vertical coefficient
  149. * Return none
  150. */
  151. static void resizer_set_filters(struct isp_res_device *res, const u16 *h_coeff,
  152. const u16 *v_coeff)
  153. {
  154. struct isp_device *isp = to_isp_device(res);
  155. u32 startaddr_h, startaddr_v, tmp_h, tmp_v;
  156. int i;
  157. startaddr_h = ISPRSZ_HFILT10;
  158. startaddr_v = ISPRSZ_VFILT10;
  159. for (i = 0; i < COEFF_CNT; i += 2) {
  160. tmp_h = h_coeff[i] |
  161. (h_coeff[i + 1] << ISPRSZ_HFILT_COEF1_SHIFT);
  162. tmp_v = v_coeff[i] |
  163. (v_coeff[i + 1] << ISPRSZ_VFILT_COEF1_SHIFT);
  164. isp_reg_writel(isp, tmp_h, OMAP3_ISP_IOMEM_RESZ, startaddr_h);
  165. isp_reg_writel(isp, tmp_v, OMAP3_ISP_IOMEM_RESZ, startaddr_v);
  166. startaddr_h += 4;
  167. startaddr_v += 4;
  168. }
  169. }
  170. /*
  171. * resizer_set_bilinear - Chrominance horizontal algorithm select
  172. * @res: Device context.
  173. * @type: Filtering interpolation type.
  174. *
  175. * Filtering that is same as luminance processing is
  176. * intended only for downsampling, and bilinear interpolation
  177. * is intended only for upsampling.
  178. */
  179. static void resizer_set_bilinear(struct isp_res_device *res,
  180. enum resizer_chroma_algo type)
  181. {
  182. struct isp_device *isp = to_isp_device(res);
  183. if (type == RSZ_BILINEAR)
  184. isp_reg_set(isp, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_CNT,
  185. ISPRSZ_CNT_CBILIN);
  186. else
  187. isp_reg_clr(isp, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_CNT,
  188. ISPRSZ_CNT_CBILIN);
  189. }
  190. /*
  191. * resizer_set_ycpos - Luminance and chrominance order
  192. * @res: Device context.
  193. * @order: order type.
  194. */
  195. static void resizer_set_ycpos(struct isp_res_device *res,
  196. enum v4l2_mbus_pixelcode pixelcode)
  197. {
  198. struct isp_device *isp = to_isp_device(res);
  199. switch (pixelcode) {
  200. case V4L2_MBUS_FMT_YUYV8_1X16:
  201. isp_reg_set(isp, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_CNT,
  202. ISPRSZ_CNT_YCPOS);
  203. break;
  204. case V4L2_MBUS_FMT_UYVY8_1X16:
  205. isp_reg_clr(isp, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_CNT,
  206. ISPRSZ_CNT_YCPOS);
  207. break;
  208. default:
  209. return;
  210. }
  211. }
  212. /*
  213. * resizer_set_phase - Setup horizontal and vertical starting phase
  214. * @res: Device context.
  215. * @h_phase: horizontal phase parameters.
  216. * @v_phase: vertical phase parameters.
  217. *
  218. * Horizontal and vertical phase range is 0 to 7
  219. */
  220. static void resizer_set_phase(struct isp_res_device *res, u32 h_phase,
  221. u32 v_phase)
  222. {
  223. struct isp_device *isp = to_isp_device(res);
  224. u32 rgval = 0;
  225. rgval = isp_reg_readl(isp, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_CNT) &
  226. ~(ISPRSZ_CNT_HSTPH_MASK | ISPRSZ_CNT_VSTPH_MASK);
  227. rgval |= (h_phase << ISPRSZ_CNT_HSTPH_SHIFT) & ISPRSZ_CNT_HSTPH_MASK;
  228. rgval |= (v_phase << ISPRSZ_CNT_VSTPH_SHIFT) & ISPRSZ_CNT_VSTPH_MASK;
  229. isp_reg_writel(isp, rgval, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_CNT);
  230. }
  231. /*
  232. * resizer_set_luma - Setup luminance enhancer parameters
  233. * @res: Device context.
  234. * @luma: Structure for luminance enhancer parameters.
  235. *
  236. * Algorithm select:
  237. * 0x0: Disable
  238. * 0x1: [-1 2 -1]/2 high-pass filter
  239. * 0x2: [-1 -2 6 -2 -1]/4 high-pass filter
  240. *
  241. * Maximum gain:
  242. * The data is coded in U4Q4 representation.
  243. *
  244. * Slope:
  245. * The data is coded in U4Q4 representation.
  246. *
  247. * Coring offset:
  248. * The data is coded in U8Q0 representation.
  249. *
  250. * The new luminance value is computed as:
  251. * Y += HPF(Y) x max(GAIN, (HPF(Y) - CORE) x SLOP + 8) >> 4.
  252. */
  253. static void resizer_set_luma(struct isp_res_device *res,
  254. struct resizer_luma_yenh *luma)
  255. {
  256. struct isp_device *isp = to_isp_device(res);
  257. u32 rgval = 0;
  258. rgval = (luma->algo << ISPRSZ_YENH_ALGO_SHIFT)
  259. & ISPRSZ_YENH_ALGO_MASK;
  260. rgval |= (luma->gain << ISPRSZ_YENH_GAIN_SHIFT)
  261. & ISPRSZ_YENH_GAIN_MASK;
  262. rgval |= (luma->slope << ISPRSZ_YENH_SLOP_SHIFT)
  263. & ISPRSZ_YENH_SLOP_MASK;
  264. rgval |= (luma->core << ISPRSZ_YENH_CORE_SHIFT)
  265. & ISPRSZ_YENH_CORE_MASK;
  266. isp_reg_writel(isp, rgval, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_YENH);
  267. }
  268. /*
  269. * resizer_set_source - Input source select
  270. * @res: Device context.
  271. * @source: Input source type
  272. *
  273. * If this field is set to RESIZER_INPUT_VP, the resizer input is fed from
  274. * Preview/CCDC engine, otherwise from memory.
  275. */
  276. static void resizer_set_source(struct isp_res_device *res,
  277. enum resizer_input_entity source)
  278. {
  279. struct isp_device *isp = to_isp_device(res);
  280. if (source == RESIZER_INPUT_MEMORY)
  281. isp_reg_set(isp, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_CNT,
  282. ISPRSZ_CNT_INPSRC);
  283. else
  284. isp_reg_clr(isp, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_CNT,
  285. ISPRSZ_CNT_INPSRC);
  286. }
  287. /*
  288. * resizer_set_ratio - Setup horizontal and vertical resizing value
  289. * @res: Device context.
  290. * @ratio: Structure for ratio parameters.
  291. *
  292. * Resizing range from 64 to 1024
  293. */
  294. static void resizer_set_ratio(struct isp_res_device *res,
  295. const struct resizer_ratio *ratio)
  296. {
  297. struct isp_device *isp = to_isp_device(res);
  298. const u16 *h_filter, *v_filter;
  299. u32 rgval = 0;
  300. rgval = isp_reg_readl(isp, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_CNT) &
  301. ~(ISPRSZ_CNT_HRSZ_MASK | ISPRSZ_CNT_VRSZ_MASK);
  302. rgval |= ((ratio->horz - 1) << ISPRSZ_CNT_HRSZ_SHIFT)
  303. & ISPRSZ_CNT_HRSZ_MASK;
  304. rgval |= ((ratio->vert - 1) << ISPRSZ_CNT_VRSZ_SHIFT)
  305. & ISPRSZ_CNT_VRSZ_MASK;
  306. isp_reg_writel(isp, rgval, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_CNT);
  307. /* prepare horizontal filter coefficients */
  308. if (ratio->horz > MID_RESIZE_VALUE)
  309. h_filter = &filter_coefs.h_filter_coef_7tap[0];
  310. else
  311. h_filter = &filter_coefs.h_filter_coef_4tap[0];
  312. /* prepare vertical filter coefficients */
  313. if (ratio->vert > MID_RESIZE_VALUE)
  314. v_filter = &filter_coefs.v_filter_coef_7tap[0];
  315. else
  316. v_filter = &filter_coefs.v_filter_coef_4tap[0];
  317. resizer_set_filters(res, h_filter, v_filter);
  318. }
  319. /*
  320. * resizer_set_dst_size - Setup the output height and width
  321. * @res: Device context.
  322. * @width: Output width.
  323. * @height: Output height.
  324. *
  325. * Width :
  326. * The value must be EVEN.
  327. *
  328. * Height:
  329. * The number of bytes written to SDRAM must be
  330. * a multiple of 16-bytes if the vertical resizing factor
  331. * is greater than 1x (upsizing)
  332. */
  333. static void resizer_set_output_size(struct isp_res_device *res,
  334. u32 width, u32 height)
  335. {
  336. struct isp_device *isp = to_isp_device(res);
  337. u32 rgval = 0;
  338. dev_dbg(isp->dev, "Output size[w/h]: %dx%d\n", width, height);
  339. rgval = (width << ISPRSZ_OUT_SIZE_HORZ_SHIFT)
  340. & ISPRSZ_OUT_SIZE_HORZ_MASK;
  341. rgval |= (height << ISPRSZ_OUT_SIZE_VERT_SHIFT)
  342. & ISPRSZ_OUT_SIZE_VERT_MASK;
  343. isp_reg_writel(isp, rgval, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_OUT_SIZE);
  344. }
  345. /*
  346. * resizer_set_output_offset - Setup memory offset for the output lines.
  347. * @res: Device context.
  348. * @offset: Memory offset.
  349. *
  350. * The 5 LSBs are forced to be zeros by the hardware to align on a 32-byte
  351. * boundary; the 5 LSBs are read-only. For optimal use of SDRAM bandwidth,
  352. * the SDRAM line offset must be set on a 256-byte boundary
  353. */
  354. static void resizer_set_output_offset(struct isp_res_device *res, u32 offset)
  355. {
  356. struct isp_device *isp = to_isp_device(res);
  357. isp_reg_writel(isp, offset, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_SDR_OUTOFF);
  358. }
  359. /*
  360. * resizer_set_start - Setup vertical and horizontal start position
  361. * @res: Device context.
  362. * @left: Horizontal start position.
  363. * @top: Vertical start position.
  364. *
  365. * Vertical start line:
  366. * This field makes sense only when the resizer obtains its input
  367. * from the preview engine/CCDC
  368. *
  369. * Horizontal start pixel:
  370. * Pixels are coded on 16 bits for YUV and 8 bits for color separate data.
  371. * When the resizer gets its input from SDRAM, this field must be set
  372. * to <= 15 for YUV 16-bit data and <= 31 for 8-bit color separate data
  373. */
  374. static void resizer_set_start(struct isp_res_device *res, u32 left, u32 top)
  375. {
  376. struct isp_device *isp = to_isp_device(res);
  377. u32 rgval = 0;
  378. rgval = (left << ISPRSZ_IN_START_HORZ_ST_SHIFT)
  379. & ISPRSZ_IN_START_HORZ_ST_MASK;
  380. rgval |= (top << ISPRSZ_IN_START_VERT_ST_SHIFT)
  381. & ISPRSZ_IN_START_VERT_ST_MASK;
  382. isp_reg_writel(isp, rgval, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_IN_START);
  383. }
  384. /*
  385. * resizer_set_input_size - Setup the input size
  386. * @res: Device context.
  387. * @width: The range is 0 to 4095 pixels
  388. * @height: The range is 0 to 4095 lines
  389. */
  390. static void resizer_set_input_size(struct isp_res_device *res,
  391. u32 width, u32 height)
  392. {
  393. struct isp_device *isp = to_isp_device(res);
  394. u32 rgval = 0;
  395. dev_dbg(isp->dev, "Input size[w/h]: %dx%d\n", width, height);
  396. rgval = (width << ISPRSZ_IN_SIZE_HORZ_SHIFT)
  397. & ISPRSZ_IN_SIZE_HORZ_MASK;
  398. rgval |= (height << ISPRSZ_IN_SIZE_VERT_SHIFT)
  399. & ISPRSZ_IN_SIZE_VERT_MASK;
  400. isp_reg_writel(isp, rgval, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_IN_SIZE);
  401. }
  402. /*
  403. * resizer_set_src_offs - Setup the memory offset for the input lines
  404. * @res: Device context.
  405. * @offset: Memory offset.
  406. *
  407. * The 5 LSBs are forced to be zeros by the hardware to align on a 32-byte
  408. * boundary; the 5 LSBs are read-only. This field must be programmed to be
  409. * 0x0 if the resizer input is from preview engine/CCDC.
  410. */
  411. static void resizer_set_input_offset(struct isp_res_device *res, u32 offset)
  412. {
  413. struct isp_device *isp = to_isp_device(res);
  414. isp_reg_writel(isp, offset, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_SDR_INOFF);
  415. }
  416. /*
  417. * resizer_set_intype - Input type select
  418. * @res: Device context.
  419. * @type: Pixel format type.
  420. */
  421. static void resizer_set_intype(struct isp_res_device *res,
  422. enum resizer_colors_type type)
  423. {
  424. struct isp_device *isp = to_isp_device(res);
  425. if (type == RSZ_COLOR8)
  426. isp_reg_set(isp, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_CNT,
  427. ISPRSZ_CNT_INPTYP);
  428. else
  429. isp_reg_clr(isp, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_CNT,
  430. ISPRSZ_CNT_INPTYP);
  431. }
  432. /*
  433. * __resizer_set_inaddr - Helper function for set input address
  434. * @res : pointer to resizer private data structure
  435. * @addr: input address
  436. * return none
  437. */
  438. static void __resizer_set_inaddr(struct isp_res_device *res, u32 addr)
  439. {
  440. struct isp_device *isp = to_isp_device(res);
  441. isp_reg_writel(isp, addr, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_SDR_INADD);
  442. }
  443. /*
  444. * The data rate at the horizontal resizer output must not exceed half the
  445. * functional clock or 100 MP/s, whichever is lower. According to the TRM
  446. * there's no similar requirement for the vertical resizer output. However
  447. * experience showed that vertical upscaling by 4 leads to SBL overflows (with
  448. * data rates at the resizer output exceeding 300 MP/s). Limiting the resizer
  449. * output data rate to the functional clock or 200 MP/s, whichever is lower,
  450. * seems to get rid of SBL overflows.
  451. *
  452. * The maximum data rate at the output of the horizontal resizer can thus be
  453. * computed with
  454. *
  455. * max intermediate rate <= L3 clock * input height / output height
  456. * max intermediate rate <= L3 clock / 2
  457. *
  458. * The maximum data rate at the resizer input is then
  459. *
  460. * max input rate <= max intermediate rate * input width / output width
  461. *
  462. * where the input width and height are the resizer input crop rectangle size.
  463. * The TRM doesn't clearly explain if that's a maximum instant data rate or a
  464. * maximum average data rate.
  465. */
  466. void omap3isp_resizer_max_rate(struct isp_res_device *res,
  467. unsigned int *max_rate)
  468. {
  469. struct isp_pipeline *pipe = to_isp_pipeline(&res->subdev.entity);
  470. const struct v4l2_mbus_framefmt *ofmt = &res->formats[RESZ_PAD_SOURCE];
  471. unsigned long limit = min(pipe->l3_ick, 200000000UL);
  472. unsigned long clock;
  473. clock = div_u64((u64)limit * res->crop.active.height, ofmt->height);
  474. clock = min(clock, limit / 2);
  475. *max_rate = div_u64((u64)clock * res->crop.active.width, ofmt->width);
  476. }
  477. /*
  478. * When the resizer processes images from memory, the driver must slow down read
  479. * requests on the input to at least comply with the internal data rate
  480. * requirements. If the application real-time requirements can cope with slower
  481. * processing, the resizer can be slowed down even more to put less pressure on
  482. * the overall system.
  483. *
  484. * When the resizer processes images on the fly (either from the CCDC or the
  485. * preview module), the same data rate requirements apply but they can't be
  486. * enforced at the resizer level. The image input module (sensor, CCP2 or
  487. * preview module) must not provide image data faster than the resizer can
  488. * process.
  489. *
  490. * For live image pipelines, the data rate is set by the frame format, size and
  491. * rate. The sensor output frame rate must not exceed the maximum resizer data
  492. * rate.
  493. *
  494. * The resizer slows down read requests by inserting wait cycles in the SBL
  495. * requests. The maximum number of 256-byte requests per second can be computed
  496. * as (the data rate is multiplied by 2 to convert from pixels per second to
  497. * bytes per second)
  498. *
  499. * request per second = data rate * 2 / 256
  500. * cycles per request = cycles per second / requests per second
  501. *
  502. * The number of cycles per second is controlled by the L3 clock, leading to
  503. *
  504. * cycles per request = L3 frequency / 2 * 256 / data rate
  505. */
  506. static void resizer_adjust_bandwidth(struct isp_res_device *res)
  507. {
  508. struct isp_pipeline *pipe = to_isp_pipeline(&res->subdev.entity);
  509. struct isp_device *isp = to_isp_device(res);
  510. unsigned long l3_ick = pipe->l3_ick;
  511. struct v4l2_fract *timeperframe;
  512. unsigned int cycles_per_frame;
  513. unsigned int requests_per_frame;
  514. unsigned int cycles_per_request;
  515. unsigned int granularity;
  516. unsigned int minimum;
  517. unsigned int maximum;
  518. unsigned int value;
  519. if (res->input != RESIZER_INPUT_MEMORY) {
  520. isp_reg_clr(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_SDR_REQ_EXP,
  521. ISPSBL_SDR_REQ_RSZ_EXP_MASK);
  522. return;
  523. }
  524. switch (isp->revision) {
  525. case ISP_REVISION_1_0:
  526. case ISP_REVISION_2_0:
  527. default:
  528. granularity = 1024;
  529. break;
  530. case ISP_REVISION_15_0:
  531. granularity = 32;
  532. break;
  533. }
  534. /* Compute the minimum number of cycles per request, based on the
  535. * pipeline maximum data rate. This is an absolute lower bound if we
  536. * don't want SBL overflows, so round the value up.
  537. */
  538. cycles_per_request = div_u64((u64)l3_ick / 2 * 256 + pipe->max_rate - 1,
  539. pipe->max_rate);
  540. minimum = DIV_ROUND_UP(cycles_per_request, granularity);
  541. /* Compute the maximum number of cycles per request, based on the
  542. * requested frame rate. This is a soft upper bound to achieve a frame
  543. * rate equal or higher than the requested value, so round the value
  544. * down.
  545. */
  546. timeperframe = &pipe->max_timeperframe;
  547. requests_per_frame = DIV_ROUND_UP(res->crop.active.width * 2, 256)
  548. * res->crop.active.height;
  549. cycles_per_frame = div_u64((u64)l3_ick * timeperframe->numerator,
  550. timeperframe->denominator);
  551. cycles_per_request = cycles_per_frame / requests_per_frame;
  552. maximum = cycles_per_request / granularity;
  553. value = max(minimum, maximum);
  554. dev_dbg(isp->dev, "%s: cycles per request = %u\n", __func__, value);
  555. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_SDR_REQ_EXP,
  556. ISPSBL_SDR_REQ_RSZ_EXP_MASK,
  557. value << ISPSBL_SDR_REQ_RSZ_EXP_SHIFT);
  558. }
  559. /*
  560. * omap3isp_resizer_busy - Checks if ISP resizer is busy.
  561. *
  562. * Returns busy field from ISPRSZ_PCR register.
  563. */
  564. int omap3isp_resizer_busy(struct isp_res_device *res)
  565. {
  566. struct isp_device *isp = to_isp_device(res);
  567. return isp_reg_readl(isp, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_PCR) &
  568. ISPRSZ_PCR_BUSY;
  569. }
  570. /*
  571. * resizer_set_inaddr - Sets the memory address of the input frame.
  572. * @addr: 32bit memory address aligned on 32byte boundary.
  573. */
  574. static void resizer_set_inaddr(struct isp_res_device *res, u32 addr)
  575. {
  576. res->addr_base = addr;
  577. /* This will handle crop settings in stream off state */
  578. if (res->crop_offset)
  579. addr += res->crop_offset & ~0x1f;
  580. __resizer_set_inaddr(res, addr);
  581. }
  582. /*
  583. * Configures the memory address to which the output frame is written.
  584. * @addr: 32bit memory address aligned on 32byte boundary.
  585. * Note: For SBL efficiency reasons the address should be on a 256-byte
  586. * boundary.
  587. */
  588. static void resizer_set_outaddr(struct isp_res_device *res, u32 addr)
  589. {
  590. struct isp_device *isp = to_isp_device(res);
  591. /*
  592. * Set output address. This needs to be in its own function
  593. * because it changes often.
  594. */
  595. isp_reg_writel(isp, addr << ISPRSZ_SDR_OUTADD_ADDR_SHIFT,
  596. OMAP3_ISP_IOMEM_RESZ, ISPRSZ_SDR_OUTADD);
  597. }
  598. /*
  599. * resizer_print_status - Prints the values of the resizer module registers.
  600. */
  601. #define RSZ_PRINT_REGISTER(isp, name)\
  602. dev_dbg(isp->dev, "###RSZ " #name "=0x%08x\n", \
  603. isp_reg_readl(isp, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_##name))
  604. static void resizer_print_status(struct isp_res_device *res)
  605. {
  606. struct isp_device *isp = to_isp_device(res);
  607. dev_dbg(isp->dev, "-------------Resizer Register dump----------\n");
  608. RSZ_PRINT_REGISTER(isp, PCR);
  609. RSZ_PRINT_REGISTER(isp, CNT);
  610. RSZ_PRINT_REGISTER(isp, OUT_SIZE);
  611. RSZ_PRINT_REGISTER(isp, IN_START);
  612. RSZ_PRINT_REGISTER(isp, IN_SIZE);
  613. RSZ_PRINT_REGISTER(isp, SDR_INADD);
  614. RSZ_PRINT_REGISTER(isp, SDR_INOFF);
  615. RSZ_PRINT_REGISTER(isp, SDR_OUTADD);
  616. RSZ_PRINT_REGISTER(isp, SDR_OUTOFF);
  617. RSZ_PRINT_REGISTER(isp, YENH);
  618. dev_dbg(isp->dev, "--------------------------------------------\n");
  619. }
  620. /*
  621. * resizer_calc_ratios - Helper function for calculate resizer ratios
  622. * @res: pointer to resizer private data structure
  623. * @input: input frame size
  624. * @output: output frame size
  625. * @ratio : return calculated ratios
  626. * return none
  627. *
  628. * The resizer uses a polyphase sample rate converter. The upsampling filter
  629. * has a fixed number of phases that depend on the resizing ratio. As the ratio
  630. * computation depends on the number of phases, we need to compute a first
  631. * approximation and then refine it.
  632. *
  633. * The input/output/ratio relationship is given by the OMAP34xx TRM:
  634. *
  635. * - 8-phase, 4-tap mode (RSZ = 64 ~ 512)
  636. * iw = (32 * sph + (ow - 1) * hrsz + 16) >> 8 + 7
  637. * ih = (32 * spv + (oh - 1) * vrsz + 16) >> 8 + 4
  638. * - 4-phase, 7-tap mode (RSZ = 513 ~ 1024)
  639. * iw = (64 * sph + (ow - 1) * hrsz + 32) >> 8 + 7
  640. * ih = (64 * spv + (oh - 1) * vrsz + 32) >> 8 + 7
  641. *
  642. * iw and ih are the input width and height after cropping. Those equations need
  643. * to be satisfied exactly for the resizer to work correctly.
  644. *
  645. * Reverting the equations, we can compute the resizing ratios with
  646. *
  647. * - 8-phase, 4-tap mode
  648. * hrsz = ((iw - 7) * 256 - 16 - 32 * sph) / (ow - 1)
  649. * vrsz = ((ih - 4) * 256 - 16 - 32 * spv) / (oh - 1)
  650. * - 4-phase, 7-tap mode
  651. * hrsz = ((iw - 7) * 256 - 32 - 64 * sph) / (ow - 1)
  652. * vrsz = ((ih - 7) * 256 - 32 - 64 * spv) / (oh - 1)
  653. *
  654. * The ratios are integer values, and must be rounded down to ensure that the
  655. * cropped input size is not bigger than the uncropped input size. As the ratio
  656. * in 7-tap mode is always smaller than the ratio in 4-tap mode, we can use the
  657. * 7-tap mode equations to compute a ratio approximation.
  658. *
  659. * We first clamp the output size according to the hardware capabilitie to avoid
  660. * auto-cropping the input more than required to satisfy the TRM equations. The
  661. * minimum output size is achieved with a scaling factor of 1024. It is thus
  662. * computed using the 7-tap equations.
  663. *
  664. * min ow = ((iw - 7) * 256 - 32 - 64 * sph) / 1024 + 1
  665. * min oh = ((ih - 7) * 256 - 32 - 64 * spv) / 1024 + 1
  666. *
  667. * Similarly, the maximum output size is achieved with a scaling factor of 64
  668. * and computed using the 4-tap equations.
  669. *
  670. * max ow = ((iw - 7) * 256 + 255 - 16 - 32 * sph) / 64 + 1
  671. * max oh = ((ih - 4) * 256 + 255 - 16 - 32 * spv) / 64 + 1
  672. *
  673. * The additional +255 term compensates for the round down operation performed
  674. * by the TRM equations when shifting the value right by 8 bits.
  675. *
  676. * We then compute and clamp the ratios (x1/4 ~ x4). Clamping the output size to
  677. * the maximum value guarantees that the ratio value will never be smaller than
  678. * the minimum, but it could still slightly exceed the maximum. Clamping the
  679. * ratio will thus result in a resizing factor slightly larger than the
  680. * requested value.
  681. *
  682. * To accomodate that, and make sure the TRM equations are satisfied exactly, we
  683. * compute the input crop rectangle as the last step.
  684. *
  685. * As if the situation wasn't complex enough, the maximum output width depends
  686. * on the vertical resizing ratio. Fortunately, the output height doesn't
  687. * depend on the horizontal resizing ratio. We can then start by computing the
  688. * output height and the vertical ratio, and then move to computing the output
  689. * width and the horizontal ratio.
  690. */
  691. static void resizer_calc_ratios(struct isp_res_device *res,
  692. struct v4l2_rect *input,
  693. struct v4l2_mbus_framefmt *output,
  694. struct resizer_ratio *ratio)
  695. {
  696. struct isp_device *isp = to_isp_device(res);
  697. const unsigned int spv = DEFAULT_PHASE;
  698. const unsigned int sph = DEFAULT_PHASE;
  699. unsigned int upscaled_width;
  700. unsigned int upscaled_height;
  701. unsigned int min_width;
  702. unsigned int min_height;
  703. unsigned int max_width;
  704. unsigned int max_height;
  705. unsigned int width_alignment;
  706. /*
  707. * Clamp the output height based on the hardware capabilities and
  708. * compute the vertical resizing ratio.
  709. */
  710. min_height = ((input->height - 7) * 256 - 32 - 64 * spv) / 1024 + 1;
  711. min_height = max_t(unsigned int, min_height, MIN_OUT_HEIGHT);
  712. max_height = ((input->height - 4) * 256 + 255 - 16 - 32 * spv) / 64 + 1;
  713. max_height = min_t(unsigned int, max_height, MAX_OUT_HEIGHT);
  714. output->height = clamp(output->height, min_height, max_height);
  715. ratio->vert = ((input->height - 7) * 256 - 32 - 64 * spv)
  716. / (output->height - 1);
  717. ratio->vert = clamp_t(unsigned int, ratio->vert,
  718. MIN_RESIZE_VALUE, MAX_RESIZE_VALUE);
  719. if (ratio->vert <= MID_RESIZE_VALUE) {
  720. upscaled_height = (output->height - 1) * ratio->vert
  721. + 32 * spv + 16;
  722. input->height = (upscaled_height >> 8) + 4;
  723. } else {
  724. upscaled_height = (output->height - 1) * ratio->vert
  725. + 64 * spv + 32;
  726. input->height = (upscaled_height >> 8) + 7;
  727. }
  728. /*
  729. * Compute the minimum and maximum output widths based on the hardware
  730. * capabilities. The maximum depends on the vertical resizing ratio.
  731. */
  732. min_width = ((input->width - 7) * 256 - 32 - 64 * sph) / 1024 + 1;
  733. min_width = max_t(unsigned int, min_width, MIN_OUT_WIDTH);
  734. if (ratio->vert <= MID_RESIZE_VALUE) {
  735. switch (isp->revision) {
  736. case ISP_REVISION_1_0:
  737. max_width = MAX_4TAP_OUT_WIDTH_ES1;
  738. break;
  739. case ISP_REVISION_2_0:
  740. default:
  741. max_width = MAX_4TAP_OUT_WIDTH_ES2;
  742. break;
  743. case ISP_REVISION_15_0:
  744. max_width = MAX_4TAP_OUT_WIDTH_3630;
  745. break;
  746. }
  747. } else {
  748. switch (isp->revision) {
  749. case ISP_REVISION_1_0:
  750. max_width = MAX_7TAP_OUT_WIDTH_ES1;
  751. break;
  752. case ISP_REVISION_2_0:
  753. default:
  754. max_width = MAX_7TAP_OUT_WIDTH_ES2;
  755. break;
  756. case ISP_REVISION_15_0:
  757. max_width = MAX_7TAP_OUT_WIDTH_3630;
  758. break;
  759. }
  760. }
  761. max_width = min(((input->width - 7) * 256 + 255 - 16 - 32 * sph) / 64
  762. + 1, max_width);
  763. /*
  764. * The output width must be even, and must be a multiple of 16 bytes
  765. * when upscaling vertically. Clamp the output width to the valid range.
  766. * Take the alignment into account (the maximum width in 7-tap mode on
  767. * ES2 isn't a multiple of 8) and align the result up to make sure it
  768. * won't be smaller than the minimum.
  769. */
  770. width_alignment = ratio->vert < 256 ? 8 : 2;
  771. output->width = clamp(output->width, min_width,
  772. max_width & ~(width_alignment - 1));
  773. output->width = ALIGN(output->width, width_alignment);
  774. ratio->horz = ((input->width - 7) * 256 - 32 - 64 * sph)
  775. / (output->width - 1);
  776. ratio->horz = clamp_t(unsigned int, ratio->horz,
  777. MIN_RESIZE_VALUE, MAX_RESIZE_VALUE);
  778. if (ratio->horz <= MID_RESIZE_VALUE) {
  779. upscaled_width = (output->width - 1) * ratio->horz
  780. + 32 * sph + 16;
  781. input->width = (upscaled_width >> 8) + 7;
  782. } else {
  783. upscaled_width = (output->width - 1) * ratio->horz
  784. + 64 * sph + 32;
  785. input->width = (upscaled_width >> 8) + 7;
  786. }
  787. }
  788. /*
  789. * resizer_set_crop_params - Setup hardware with cropping parameters
  790. * @res : resizer private structure
  791. * @crop_rect : current crop rectangle
  792. * @ratio : resizer ratios
  793. * return none
  794. */
  795. static void resizer_set_crop_params(struct isp_res_device *res,
  796. const struct v4l2_mbus_framefmt *input,
  797. const struct v4l2_mbus_framefmt *output)
  798. {
  799. resizer_set_ratio(res, &res->ratio);
  800. /* Set chrominance horizontal algorithm */
  801. if (res->ratio.horz >= RESIZE_DIVISOR)
  802. resizer_set_bilinear(res, RSZ_THE_SAME);
  803. else
  804. resizer_set_bilinear(res, RSZ_BILINEAR);
  805. resizer_adjust_bandwidth(res);
  806. if (res->input == RESIZER_INPUT_MEMORY) {
  807. /* Calculate additional offset for crop */
  808. res->crop_offset = (res->crop.active.top * input->width +
  809. res->crop.active.left) * 2;
  810. /*
  811. * Write lowest 4 bits of horizontal pixel offset (in pixels),
  812. * vertical start must be 0.
  813. */
  814. resizer_set_start(res, (res->crop_offset / 2) & 0xf, 0);
  815. /*
  816. * Set start (read) address for cropping, in bytes.
  817. * Lowest 5 bits must be zero.
  818. */
  819. __resizer_set_inaddr(res,
  820. res->addr_base + (res->crop_offset & ~0x1f));
  821. } else {
  822. /*
  823. * Set vertical start line and horizontal starting pixel.
  824. * If the input is from CCDC/PREV, horizontal start field is
  825. * in bytes (twice number of pixels).
  826. */
  827. resizer_set_start(res, res->crop.active.left * 2,
  828. res->crop.active.top);
  829. /* Input address and offset must be 0 for preview/ccdc input */
  830. __resizer_set_inaddr(res, 0);
  831. resizer_set_input_offset(res, 0);
  832. }
  833. /* Set the input size */
  834. resizer_set_input_size(res, res->crop.active.width,
  835. res->crop.active.height);
  836. }
  837. static void resizer_configure(struct isp_res_device *res)
  838. {
  839. struct v4l2_mbus_framefmt *informat, *outformat;
  840. struct resizer_luma_yenh luma = {0, 0, 0, 0};
  841. resizer_set_source(res, res->input);
  842. informat = &res->formats[RESZ_PAD_SINK];
  843. outformat = &res->formats[RESZ_PAD_SOURCE];
  844. /* RESZ_PAD_SINK */
  845. if (res->input == RESIZER_INPUT_VP)
  846. resizer_set_input_offset(res, 0);
  847. else
  848. resizer_set_input_offset(res, ALIGN(informat->width, 0x10) * 2);
  849. /* YUV422 interleaved, default phase, no luma enhancement */
  850. resizer_set_intype(res, RSZ_YUV422);
  851. resizer_set_ycpos(res, informat->code);
  852. resizer_set_phase(res, DEFAULT_PHASE, DEFAULT_PHASE);
  853. resizer_set_luma(res, &luma);
  854. /* RESZ_PAD_SOURCE */
  855. resizer_set_output_offset(res, ALIGN(outformat->width * 2, 32));
  856. resizer_set_output_size(res, outformat->width, outformat->height);
  857. resizer_set_crop_params(res, informat, outformat);
  858. }
  859. /* -----------------------------------------------------------------------------
  860. * Interrupt handling
  861. */
  862. static void resizer_enable_oneshot(struct isp_res_device *res)
  863. {
  864. struct isp_device *isp = to_isp_device(res);
  865. isp_reg_set(isp, OMAP3_ISP_IOMEM_RESZ, ISPRSZ_PCR,
  866. ISPRSZ_PCR_ENABLE | ISPRSZ_PCR_ONESHOT);
  867. }
  868. void omap3isp_resizer_isr_frame_sync(struct isp_res_device *res)
  869. {
  870. /*
  871. * If ISP_VIDEO_DMAQUEUE_QUEUED is set, DMA queue had an underrun
  872. * condition, the module was paused and now we have a buffer queued
  873. * on the output again. Restart the pipeline if running in continuous
  874. * mode.
  875. */
  876. if (res->state == ISP_PIPELINE_STREAM_CONTINUOUS &&
  877. res->video_out.dmaqueue_flags & ISP_VIDEO_DMAQUEUE_QUEUED) {
  878. resizer_enable_oneshot(res);
  879. isp_video_dmaqueue_flags_clr(&res->video_out);
  880. }
  881. }
  882. static void resizer_isr_buffer(struct isp_res_device *res)
  883. {
  884. struct isp_pipeline *pipe = to_isp_pipeline(&res->subdev.entity);
  885. struct isp_buffer *buffer;
  886. int restart = 0;
  887. if (res->state == ISP_PIPELINE_STREAM_STOPPED)
  888. return;
  889. /* Complete the output buffer and, if reading from memory, the input
  890. * buffer.
  891. */
  892. buffer = omap3isp_video_buffer_next(&res->video_out, res->error);
  893. if (buffer != NULL) {
  894. resizer_set_outaddr(res, buffer->isp_addr);
  895. restart = 1;
  896. }
  897. pipe->state |= ISP_PIPELINE_IDLE_OUTPUT;
  898. if (res->input == RESIZER_INPUT_MEMORY) {
  899. buffer = omap3isp_video_buffer_next(&res->video_in, 0);
  900. if (buffer != NULL)
  901. resizer_set_inaddr(res, buffer->isp_addr);
  902. pipe->state |= ISP_PIPELINE_IDLE_INPUT;
  903. }
  904. if (res->state == ISP_PIPELINE_STREAM_SINGLESHOT) {
  905. if (isp_pipeline_ready(pipe))
  906. omap3isp_pipeline_set_stream(pipe,
  907. ISP_PIPELINE_STREAM_SINGLESHOT);
  908. } else {
  909. /* If an underrun occurs, the video queue operation handler will
  910. * restart the resizer. Otherwise restart it immediately.
  911. */
  912. if (restart)
  913. resizer_enable_oneshot(res);
  914. }
  915. res->error = 0;
  916. }
  917. /*
  918. * omap3isp_resizer_isr - ISP resizer interrupt handler
  919. *
  920. * Manage the resizer video buffers and configure shadowed and busy-locked
  921. * registers.
  922. */
  923. void omap3isp_resizer_isr(struct isp_res_device *res)
  924. {
  925. struct v4l2_mbus_framefmt *informat, *outformat;
  926. if (omap3isp_module_sync_is_stopping(&res->wait, &res->stopping))
  927. return;
  928. if (res->applycrop) {
  929. outformat = __resizer_get_format(res, NULL, RESZ_PAD_SOURCE,
  930. V4L2_SUBDEV_FORMAT_ACTIVE);
  931. informat = __resizer_get_format(res, NULL, RESZ_PAD_SINK,
  932. V4L2_SUBDEV_FORMAT_ACTIVE);
  933. resizer_set_crop_params(res, informat, outformat);
  934. res->applycrop = 0;
  935. }
  936. resizer_isr_buffer(res);
  937. }
  938. /* -----------------------------------------------------------------------------
  939. * ISP video operations
  940. */
  941. static int resizer_video_queue(struct isp_video *video,
  942. struct isp_buffer *buffer)
  943. {
  944. struct isp_res_device *res = &video->isp->isp_res;
  945. if (video->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
  946. resizer_set_inaddr(res, buffer->isp_addr);
  947. /*
  948. * We now have a buffer queued on the output. Despite what the
  949. * TRM says, the resizer can't be restarted immediately.
  950. * Enabling it in one shot mode in the middle of a frame (or at
  951. * least asynchronously to the frame) results in the output
  952. * being shifted randomly left/right and up/down, as if the
  953. * hardware didn't synchronize itself to the beginning of the
  954. * frame correctly.
  955. *
  956. * Restart the resizer on the next sync interrupt if running in
  957. * continuous mode or when starting the stream.
  958. */
  959. if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
  960. resizer_set_outaddr(res, buffer->isp_addr);
  961. return 0;
  962. }
  963. static const struct isp_video_operations resizer_video_ops = {
  964. .queue = resizer_video_queue,
  965. };
  966. /* -----------------------------------------------------------------------------
  967. * V4L2 subdev operations
  968. */
  969. /*
  970. * resizer_set_stream - Enable/Disable streaming on resizer subdev
  971. * @sd: ISP resizer V4L2 subdev
  972. * @enable: 1 == Enable, 0 == Disable
  973. *
  974. * The resizer hardware can't be enabled without a memory buffer to write to.
  975. * As the s_stream operation is called in response to a STREAMON call without
  976. * any buffer queued yet, just update the state field and return immediately.
  977. * The resizer will be enabled in resizer_video_queue().
  978. */
  979. static int resizer_set_stream(struct v4l2_subdev *sd, int enable)
  980. {
  981. struct isp_res_device *res = v4l2_get_subdevdata(sd);
  982. struct isp_video *video_out = &res->video_out;
  983. struct isp_device *isp = to_isp_device(res);
  984. struct device *dev = to_device(res);
  985. if (res->state == ISP_PIPELINE_STREAM_STOPPED) {
  986. if (enable == ISP_PIPELINE_STREAM_STOPPED)
  987. return 0;
  988. omap3isp_subclk_enable(isp, OMAP3_ISP_SUBCLK_RESIZER);
  989. resizer_configure(res);
  990. res->error = 0;
  991. resizer_print_status(res);
  992. }
  993. switch (enable) {
  994. case ISP_PIPELINE_STREAM_CONTINUOUS:
  995. omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_RESIZER_WRITE);
  996. if (video_out->dmaqueue_flags & ISP_VIDEO_DMAQUEUE_QUEUED) {
  997. resizer_enable_oneshot(res);
  998. isp_video_dmaqueue_flags_clr(video_out);
  999. }
  1000. break;
  1001. case ISP_PIPELINE_STREAM_SINGLESHOT:
  1002. if (res->input == RESIZER_INPUT_MEMORY)
  1003. omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_RESIZER_READ);
  1004. omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_RESIZER_WRITE);
  1005. resizer_enable_oneshot(res);
  1006. break;
  1007. case ISP_PIPELINE_STREAM_STOPPED:
  1008. if (omap3isp_module_sync_idle(&sd->entity, &res->wait,
  1009. &res->stopping))
  1010. dev_dbg(dev, "%s: module stop timeout.\n", sd->name);
  1011. omap3isp_sbl_disable(isp, OMAP3_ISP_SBL_RESIZER_READ |
  1012. OMAP3_ISP_SBL_RESIZER_WRITE);
  1013. omap3isp_subclk_disable(isp, OMAP3_ISP_SUBCLK_RESIZER);
  1014. isp_video_dmaqueue_flags_clr(video_out);
  1015. break;
  1016. }
  1017. res->state = enable;
  1018. return 0;
  1019. }
  1020. /*
  1021. * resizer_g_crop - handle get crop subdev operation
  1022. * @sd : pointer to v4l2 subdev structure
  1023. * @pad : subdev pad
  1024. * @crop : pointer to crop structure
  1025. * @which : active or try format
  1026. * return zero
  1027. */
  1028. static int resizer_g_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
  1029. struct v4l2_subdev_crop *crop)
  1030. {
  1031. struct isp_res_device *res = v4l2_get_subdevdata(sd);
  1032. struct v4l2_mbus_framefmt *format;
  1033. struct resizer_ratio ratio;
  1034. /* Only sink pad has crop capability */
  1035. if (crop->pad != RESZ_PAD_SINK)
  1036. return -EINVAL;
  1037. format = __resizer_get_format(res, fh, RESZ_PAD_SOURCE, crop->which);
  1038. crop->rect = *__resizer_get_crop(res, fh, crop->which);
  1039. resizer_calc_ratios(res, &crop->rect, format, &ratio);
  1040. return 0;
  1041. }
  1042. /*
  1043. * resizer_try_crop - mangles crop parameters.
  1044. */
  1045. static void resizer_try_crop(const struct v4l2_mbus_framefmt *sink,
  1046. const struct v4l2_mbus_framefmt *source,
  1047. struct v4l2_rect *crop)
  1048. {
  1049. const unsigned int spv = DEFAULT_PHASE;
  1050. const unsigned int sph = DEFAULT_PHASE;
  1051. /* Crop rectangle is constrained to the output size so that zoom ratio
  1052. * cannot exceed +/-4.0.
  1053. */
  1054. unsigned int min_width =
  1055. ((32 * sph + (source->width - 1) * 64 + 16) >> 8) + 7;
  1056. unsigned int min_height =
  1057. ((32 * spv + (source->height - 1) * 64 + 16) >> 8) + 4;
  1058. unsigned int max_width =
  1059. ((64 * sph + (source->width - 1) * 1024 + 32) >> 8) + 7;
  1060. unsigned int max_height =
  1061. ((64 * spv + (source->height - 1) * 1024 + 32) >> 8) + 7;
  1062. crop->width = clamp_t(u32, crop->width, min_width, max_width);
  1063. crop->height = clamp_t(u32, crop->height, min_height, max_height);
  1064. /* Crop can not go beyond of the input rectangle */
  1065. crop->left = clamp_t(u32, crop->left, 0, sink->width - MIN_IN_WIDTH);
  1066. crop->width = clamp_t(u32, crop->width, MIN_IN_WIDTH,
  1067. sink->width - crop->left);
  1068. crop->top = clamp_t(u32, crop->top, 0, sink->height - MIN_IN_HEIGHT);
  1069. crop->height = clamp_t(u32, crop->height, MIN_IN_HEIGHT,
  1070. sink->height - crop->top);
  1071. }
  1072. /*
  1073. * resizer_s_crop - handle set crop subdev operation
  1074. * @sd : pointer to v4l2 subdev structure
  1075. * @pad : subdev pad
  1076. * @crop : pointer to crop structure
  1077. * @which : active or try format
  1078. * return -EINVAL or zero when succeed
  1079. */
  1080. static int resizer_s_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
  1081. struct v4l2_subdev_crop *crop)
  1082. {
  1083. struct isp_res_device *res = v4l2_get_subdevdata(sd);
  1084. struct isp_device *isp = to_isp_device(res);
  1085. struct v4l2_mbus_framefmt *format_sink, *format_source;
  1086. struct resizer_ratio ratio;
  1087. /* Only sink pad has crop capability */
  1088. if (crop->pad != RESZ_PAD_SINK)
  1089. return -EINVAL;
  1090. format_sink = __resizer_get_format(res, fh, RESZ_PAD_SINK,
  1091. crop->which);
  1092. format_source = __resizer_get_format(res, fh, RESZ_PAD_SOURCE,
  1093. crop->which);
  1094. dev_dbg(isp->dev, "%s: L=%d,T=%d,W=%d,H=%d,which=%d\n", __func__,
  1095. crop->rect.left, crop->rect.top, crop->rect.width,
  1096. crop->rect.height, crop->which);
  1097. dev_dbg(isp->dev, "%s: input=%dx%d, output=%dx%d\n", __func__,
  1098. format_sink->width, format_sink->height,
  1099. format_source->width, format_source->height);
  1100. resizer_try_crop(format_sink, format_source, &crop->rect);
  1101. *__resizer_get_crop(res, fh, crop->which) = crop->rect;
  1102. resizer_calc_ratios(res, &crop->rect, format_source, &ratio);
  1103. if (crop->which == V4L2_SUBDEV_FORMAT_TRY)
  1104. return 0;
  1105. res->ratio = ratio;
  1106. res->crop.active = crop->rect;
  1107. /*
  1108. * s_crop can be called while streaming is on. In this case
  1109. * the crop values will be set in the next IRQ.
  1110. */
  1111. if (res->state != ISP_PIPELINE_STREAM_STOPPED)
  1112. res->applycrop = 1;
  1113. return 0;
  1114. }
  1115. /* resizer pixel formats */
  1116. static const unsigned int resizer_formats[] = {
  1117. V4L2_MBUS_FMT_UYVY8_1X16,
  1118. V4L2_MBUS_FMT_YUYV8_1X16,
  1119. };
  1120. static unsigned int resizer_max_in_width(struct isp_res_device *res)
  1121. {
  1122. struct isp_device *isp = to_isp_device(res);
  1123. if (res->input == RESIZER_INPUT_MEMORY) {
  1124. return MAX_IN_WIDTH_MEMORY_MODE;
  1125. } else {
  1126. if (isp->revision == ISP_REVISION_1_0)
  1127. return MAX_IN_WIDTH_ONTHEFLY_MODE_ES1;
  1128. else
  1129. return MAX_IN_WIDTH_ONTHEFLY_MODE_ES2;
  1130. }
  1131. }
  1132. /*
  1133. * resizer_try_format - Handle try format by pad subdev method
  1134. * @res : ISP resizer device
  1135. * @fh : V4L2 subdev file handle
  1136. * @pad : pad num
  1137. * @fmt : pointer to v4l2 format structure
  1138. * @which : wanted subdev format
  1139. */
  1140. static void resizer_try_format(struct isp_res_device *res,
  1141. struct v4l2_subdev_fh *fh, unsigned int pad,
  1142. struct v4l2_mbus_framefmt *fmt,
  1143. enum v4l2_subdev_format_whence which)
  1144. {
  1145. struct v4l2_mbus_framefmt *format;
  1146. struct resizer_ratio ratio;
  1147. struct v4l2_rect crop;
  1148. switch (pad) {
  1149. case RESZ_PAD_SINK:
  1150. if (fmt->code != V4L2_MBUS_FMT_YUYV8_1X16 &&
  1151. fmt->code != V4L2_MBUS_FMT_UYVY8_1X16)
  1152. fmt->code = V4L2_MBUS_FMT_YUYV8_1X16;
  1153. fmt->width = clamp_t(u32, fmt->width, MIN_IN_WIDTH,
  1154. resizer_max_in_width(res));
  1155. fmt->height = clamp_t(u32, fmt->height, MIN_IN_HEIGHT,
  1156. MAX_IN_HEIGHT);
  1157. break;
  1158. case RESZ_PAD_SOURCE:
  1159. format = __resizer_get_format(res, fh, RESZ_PAD_SINK, which);
  1160. fmt->code = format->code;
  1161. crop = *__resizer_get_crop(res, fh, which);
  1162. resizer_calc_ratios(res, &crop, fmt, &ratio);
  1163. break;
  1164. }
  1165. fmt->colorspace = V4L2_COLORSPACE_JPEG;
  1166. fmt->field = V4L2_FIELD_NONE;
  1167. }
  1168. /*
  1169. * resizer_enum_mbus_code - Handle pixel format enumeration
  1170. * @sd : pointer to v4l2 subdev structure
  1171. * @fh : V4L2 subdev file handle
  1172. * @code : pointer to v4l2_subdev_mbus_code_enum structure
  1173. * return -EINVAL or zero on success
  1174. */
  1175. static int resizer_enum_mbus_code(struct v4l2_subdev *sd,
  1176. struct v4l2_subdev_fh *fh,
  1177. struct v4l2_subdev_mbus_code_enum *code)
  1178. {
  1179. struct isp_res_device *res = v4l2_get_subdevdata(sd);
  1180. struct v4l2_mbus_framefmt *format;
  1181. if (code->pad == RESZ_PAD_SINK) {
  1182. if (code->index >= ARRAY_SIZE(resizer_formats))
  1183. return -EINVAL;
  1184. code->code = resizer_formats[code->index];
  1185. } else {
  1186. if (code->index != 0)
  1187. return -EINVAL;
  1188. format = __resizer_get_format(res, fh, RESZ_PAD_SINK,
  1189. V4L2_SUBDEV_FORMAT_TRY);
  1190. code->code = format->code;
  1191. }
  1192. return 0;
  1193. }
  1194. static int resizer_enum_frame_size(struct v4l2_subdev *sd,
  1195. struct v4l2_subdev_fh *fh,
  1196. struct v4l2_subdev_frame_size_enum *fse)
  1197. {
  1198. struct isp_res_device *res = v4l2_get_subdevdata(sd);
  1199. struct v4l2_mbus_framefmt format;
  1200. if (fse->index != 0)
  1201. return -EINVAL;
  1202. format.code = fse->code;
  1203. format.width = 1;
  1204. format.height = 1;
  1205. resizer_try_format(res, fh, fse->pad, &format, V4L2_SUBDEV_FORMAT_TRY);
  1206. fse->min_width = format.width;
  1207. fse->min_height = format.height;
  1208. if (format.code != fse->code)
  1209. return -EINVAL;
  1210. format.code = fse->code;
  1211. format.width = -1;
  1212. format.height = -1;
  1213. resizer_try_format(res, fh, fse->pad, &format, V4L2_SUBDEV_FORMAT_TRY);
  1214. fse->max_width = format.width;
  1215. fse->max_height = format.height;
  1216. return 0;
  1217. }
  1218. /*
  1219. * resizer_get_format - Handle get format by pads subdev method
  1220. * @sd : pointer to v4l2 subdev structure
  1221. * @fh : V4L2 subdev file handle
  1222. * @fmt : pointer to v4l2 subdev format structure
  1223. * return -EINVAL or zero on sucess
  1224. */
  1225. static int resizer_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
  1226. struct v4l2_subdev_format *fmt)
  1227. {
  1228. struct isp_res_device *res = v4l2_get_subdevdata(sd);
  1229. struct v4l2_mbus_framefmt *format;
  1230. format = __resizer_get_format(res, fh, fmt->pad, fmt->which);
  1231. if (format == NULL)
  1232. return -EINVAL;
  1233. fmt->format = *format;
  1234. return 0;
  1235. }
  1236. /*
  1237. * resizer_set_format - Handle set format by pads subdev method
  1238. * @sd : pointer to v4l2 subdev structure
  1239. * @fh : V4L2 subdev file handle
  1240. * @fmt : pointer to v4l2 subdev format structure
  1241. * return -EINVAL or zero on success
  1242. */
  1243. static int resizer_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
  1244. struct v4l2_subdev_format *fmt)
  1245. {
  1246. struct isp_res_device *res = v4l2_get_subdevdata(sd);
  1247. struct v4l2_mbus_framefmt *format;
  1248. struct v4l2_rect *crop;
  1249. format = __resizer_get_format(res, fh, fmt->pad, fmt->which);
  1250. if (format == NULL)
  1251. return -EINVAL;
  1252. resizer_try_format(res, fh, fmt->pad, &fmt->format, fmt->which);
  1253. *format = fmt->format;
  1254. if (fmt->pad == RESZ_PAD_SINK) {
  1255. /* reset crop rectangle */
  1256. crop = __resizer_get_crop(res, fh, fmt->which);
  1257. crop->left = 0;
  1258. crop->top = 0;
  1259. crop->width = fmt->format.width;
  1260. crop->height = fmt->format.height;
  1261. /* Propagate the format from sink to source */
  1262. format = __resizer_get_format(res, fh, RESZ_PAD_SOURCE,
  1263. fmt->which);
  1264. *format = fmt->format;
  1265. resizer_try_format(res, fh, RESZ_PAD_SOURCE, format,
  1266. fmt->which);
  1267. }
  1268. if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
  1269. /* Compute and store the active crop rectangle and resizer
  1270. * ratios. format already points to the source pad active
  1271. * format.
  1272. */
  1273. res->crop.active = res->crop.request;
  1274. resizer_calc_ratios(res, &res->crop.active, format,
  1275. &res->ratio);
  1276. }
  1277. return 0;
  1278. }
  1279. /*
  1280. * resizer_init_formats - Initialize formats on all pads
  1281. * @sd: ISP resizer V4L2 subdevice
  1282. * @fh: V4L2 subdev file handle
  1283. *
  1284. * Initialize all pad formats with default values. If fh is not NULL, try
  1285. * formats are initialized on the file handle. Otherwise active formats are
  1286. * initialized on the device.
  1287. */
  1288. static int resizer_init_formats(struct v4l2_subdev *sd,
  1289. struct v4l2_subdev_fh *fh)
  1290. {
  1291. struct v4l2_subdev_format format;
  1292. memset(&format, 0, sizeof(format));
  1293. format.pad = RESZ_PAD_SINK;
  1294. format.which = fh ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
  1295. format.format.code = V4L2_MBUS_FMT_YUYV8_1X16;
  1296. format.format.width = 4096;
  1297. format.format.height = 4096;
  1298. resizer_set_format(sd, fh, &format);
  1299. return 0;
  1300. }
  1301. /* subdev video operations */
  1302. static const struct v4l2_subdev_video_ops resizer_v4l2_video_ops = {
  1303. .s_stream = resizer_set_stream,
  1304. };
  1305. /* subdev pad operations */
  1306. static const struct v4l2_subdev_pad_ops resizer_v4l2_pad_ops = {
  1307. .enum_mbus_code = resizer_enum_mbus_code,
  1308. .enum_frame_size = resizer_enum_frame_size,
  1309. .get_fmt = resizer_get_format,
  1310. .set_fmt = resizer_set_format,
  1311. .get_crop = resizer_g_crop,
  1312. .set_crop = resizer_s_crop,
  1313. };
  1314. /* subdev operations */
  1315. static const struct v4l2_subdev_ops resizer_v4l2_ops = {
  1316. .video = &resizer_v4l2_video_ops,
  1317. .pad = &resizer_v4l2_pad_ops,
  1318. };
  1319. /* subdev internal operations */
  1320. static const struct v4l2_subdev_internal_ops resizer_v4l2_internal_ops = {
  1321. .open = resizer_init_formats,
  1322. };
  1323. /* -----------------------------------------------------------------------------
  1324. * Media entity operations
  1325. */
  1326. /*
  1327. * resizer_link_setup - Setup resizer connections.
  1328. * @entity : Pointer to media entity structure
  1329. * @local : Pointer to local pad array
  1330. * @remote : Pointer to remote pad array
  1331. * @flags : Link flags
  1332. * return -EINVAL or zero on success
  1333. */
  1334. static int resizer_link_setup(struct media_entity *entity,
  1335. const struct media_pad *local,
  1336. const struct media_pad *remote, u32 flags)
  1337. {
  1338. struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
  1339. struct isp_res_device *res = v4l2_get_subdevdata(sd);
  1340. switch (local->index | media_entity_type(remote->entity)) {
  1341. case RESZ_PAD_SINK | MEDIA_ENT_T_DEVNODE:
  1342. /* read from memory */
  1343. if (flags & MEDIA_LNK_FL_ENABLED) {
  1344. if (res->input == RESIZER_INPUT_VP)
  1345. return -EBUSY;
  1346. res->input = RESIZER_INPUT_MEMORY;
  1347. } else {
  1348. if (res->input == RESIZER_INPUT_MEMORY)
  1349. res->input = RESIZER_INPUT_NONE;
  1350. }
  1351. break;
  1352. case RESZ_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
  1353. /* read from ccdc or previewer */
  1354. if (flags & MEDIA_LNK_FL_ENABLED) {
  1355. if (res->input == RESIZER_INPUT_MEMORY)
  1356. return -EBUSY;
  1357. res->input = RESIZER_INPUT_VP;
  1358. } else {
  1359. if (res->input == RESIZER_INPUT_VP)
  1360. res->input = RESIZER_INPUT_NONE;
  1361. }
  1362. break;
  1363. case RESZ_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
  1364. /* resizer always write to memory */
  1365. break;
  1366. default:
  1367. return -EINVAL;
  1368. }
  1369. return 0;
  1370. }
  1371. /* media operations */
  1372. static const struct media_entity_operations resizer_media_ops = {
  1373. .link_setup = resizer_link_setup,
  1374. };
  1375. /*
  1376. * resizer_init_entities - Initialize resizer subdev and media entity.
  1377. * @res : Pointer to resizer device structure
  1378. * return -ENOMEM or zero on success
  1379. */
  1380. static int resizer_init_entities(struct isp_res_device *res)
  1381. {
  1382. struct v4l2_subdev *sd = &res->subdev;
  1383. struct media_pad *pads = res->pads;
  1384. struct media_entity *me = &sd->entity;
  1385. int ret;
  1386. res->input = RESIZER_INPUT_NONE;
  1387. v4l2_subdev_init(sd, &resizer_v4l2_ops);
  1388. sd->internal_ops = &resizer_v4l2_internal_ops;
  1389. strlcpy(sd->name, "OMAP3 ISP resizer", sizeof(sd->name));
  1390. sd->grp_id = 1 << 16; /* group ID for isp subdevs */
  1391. v4l2_set_subdevdata(sd, res);
  1392. sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
  1393. pads[RESZ_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
  1394. pads[RESZ_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
  1395. me->ops = &resizer_media_ops;
  1396. ret = media_entity_init(me, RESZ_PADS_NUM, pads, 0);
  1397. if (ret < 0)
  1398. return ret;
  1399. resizer_init_formats(sd, NULL);
  1400. res->video_in.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
  1401. res->video_in.ops = &resizer_video_ops;
  1402. res->video_in.isp = to_isp_device(res);
  1403. res->video_in.capture_mem = PAGE_ALIGN(4096 * 4096) * 2 * 3;
  1404. res->video_in.bpl_alignment = 32;
  1405. res->video_out.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  1406. res->video_out.ops = &resizer_video_ops;
  1407. res->video_out.isp = to_isp_device(res);
  1408. res->video_out.capture_mem = PAGE_ALIGN(4096 * 4096) * 2 * 3;
  1409. res->video_out.bpl_alignment = 32;
  1410. ret = omap3isp_video_init(&res->video_in, "resizer");
  1411. if (ret < 0)
  1412. return ret;
  1413. ret = omap3isp_video_init(&res->video_out, "resizer");
  1414. if (ret < 0)
  1415. return ret;
  1416. /* Connect the video nodes to the resizer subdev. */
  1417. ret = media_entity_create_link(&res->video_in.video.entity, 0,
  1418. &res->subdev.entity, RESZ_PAD_SINK, 0);
  1419. if (ret < 0)
  1420. return ret;
  1421. ret = media_entity_create_link(&res->subdev.entity, RESZ_PAD_SOURCE,
  1422. &res->video_out.video.entity, 0, 0);
  1423. if (ret < 0)
  1424. return ret;
  1425. return 0;
  1426. }
  1427. void omap3isp_resizer_unregister_entities(struct isp_res_device *res)
  1428. {
  1429. media_entity_cleanup(&res->subdev.entity);
  1430. v4l2_device_unregister_subdev(&res->subdev);
  1431. omap3isp_video_unregister(&res->video_in);
  1432. omap3isp_video_unregister(&res->video_out);
  1433. }
  1434. int omap3isp_resizer_register_entities(struct isp_res_device *res,
  1435. struct v4l2_device *vdev)
  1436. {
  1437. int ret;
  1438. /* Register the subdev and video nodes. */
  1439. ret = v4l2_device_register_subdev(vdev, &res->subdev);
  1440. if (ret < 0)
  1441. goto error;
  1442. ret = omap3isp_video_register(&res->video_in, vdev);
  1443. if (ret < 0)
  1444. goto error;
  1445. ret = omap3isp_video_register(&res->video_out, vdev);
  1446. if (ret < 0)
  1447. goto error;
  1448. return 0;
  1449. error:
  1450. omap3isp_resizer_unregister_entities(res);
  1451. return ret;
  1452. }
  1453. /* -----------------------------------------------------------------------------
  1454. * ISP resizer initialization and cleanup
  1455. */
  1456. void omap3isp_resizer_cleanup(struct isp_device *isp)
  1457. {
  1458. }
  1459. /*
  1460. * isp_resizer_init - Resizer initialization.
  1461. * @isp : Pointer to ISP device
  1462. * return -ENOMEM or zero on success
  1463. */
  1464. int omap3isp_resizer_init(struct isp_device *isp)
  1465. {
  1466. struct isp_res_device *res = &isp->isp_res;
  1467. int ret;
  1468. init_waitqueue_head(&res->wait);
  1469. atomic_set(&res->stopping, 0);
  1470. ret = resizer_init_entities(res);
  1471. if (ret < 0)
  1472. goto out;
  1473. out:
  1474. if (ret)
  1475. omap3isp_resizer_cleanup(isp);
  1476. return ret;
  1477. }