ispccdc.c 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535
  1. /*
  2. * ispccdc.c
  3. *
  4. * TI OMAP3 ISP - CCDC module
  5. *
  6. * Copyright (C) 2009-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/module.h>
  27. #include <linux/uaccess.h>
  28. #include <linux/delay.h>
  29. #include <linux/device.h>
  30. #include <linux/dma-mapping.h>
  31. #include <linux/mm.h>
  32. #include <linux/sched.h>
  33. #include <linux/slab.h>
  34. #include <media/v4l2-event.h>
  35. #include "isp.h"
  36. #include "ispreg.h"
  37. #include "ispccdc.h"
  38. #define CCDC_MIN_WIDTH 32
  39. #define CCDC_MIN_HEIGHT 32
  40. static struct v4l2_mbus_framefmt *
  41. __ccdc_get_format(struct isp_ccdc_device *ccdc, struct v4l2_subdev_fh *fh,
  42. unsigned int pad, enum v4l2_subdev_format_whence which);
  43. static const unsigned int ccdc_fmts[] = {
  44. V4L2_MBUS_FMT_Y8_1X8,
  45. V4L2_MBUS_FMT_Y10_1X10,
  46. V4L2_MBUS_FMT_Y12_1X12,
  47. V4L2_MBUS_FMT_SGRBG8_1X8,
  48. V4L2_MBUS_FMT_SRGGB8_1X8,
  49. V4L2_MBUS_FMT_SBGGR8_1X8,
  50. V4L2_MBUS_FMT_SGBRG8_1X8,
  51. V4L2_MBUS_FMT_SGRBG10_1X10,
  52. V4L2_MBUS_FMT_SRGGB10_1X10,
  53. V4L2_MBUS_FMT_SBGGR10_1X10,
  54. V4L2_MBUS_FMT_SGBRG10_1X10,
  55. V4L2_MBUS_FMT_SGRBG12_1X12,
  56. V4L2_MBUS_FMT_SRGGB12_1X12,
  57. V4L2_MBUS_FMT_SBGGR12_1X12,
  58. V4L2_MBUS_FMT_SGBRG12_1X12,
  59. };
  60. /*
  61. * ccdc_print_status - Print current CCDC Module register values.
  62. * @ccdc: Pointer to ISP CCDC device.
  63. *
  64. * Also prints other debug information stored in the CCDC module.
  65. */
  66. #define CCDC_PRINT_REGISTER(isp, name)\
  67. dev_dbg(isp->dev, "###CCDC " #name "=0x%08x\n", \
  68. isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_##name))
  69. static void ccdc_print_status(struct isp_ccdc_device *ccdc)
  70. {
  71. struct isp_device *isp = to_isp_device(ccdc);
  72. dev_dbg(isp->dev, "-------------CCDC Register dump-------------\n");
  73. CCDC_PRINT_REGISTER(isp, PCR);
  74. CCDC_PRINT_REGISTER(isp, SYN_MODE);
  75. CCDC_PRINT_REGISTER(isp, HD_VD_WID);
  76. CCDC_PRINT_REGISTER(isp, PIX_LINES);
  77. CCDC_PRINT_REGISTER(isp, HORZ_INFO);
  78. CCDC_PRINT_REGISTER(isp, VERT_START);
  79. CCDC_PRINT_REGISTER(isp, VERT_LINES);
  80. CCDC_PRINT_REGISTER(isp, CULLING);
  81. CCDC_PRINT_REGISTER(isp, HSIZE_OFF);
  82. CCDC_PRINT_REGISTER(isp, SDOFST);
  83. CCDC_PRINT_REGISTER(isp, SDR_ADDR);
  84. CCDC_PRINT_REGISTER(isp, CLAMP);
  85. CCDC_PRINT_REGISTER(isp, DCSUB);
  86. CCDC_PRINT_REGISTER(isp, COLPTN);
  87. CCDC_PRINT_REGISTER(isp, BLKCMP);
  88. CCDC_PRINT_REGISTER(isp, FPC);
  89. CCDC_PRINT_REGISTER(isp, FPC_ADDR);
  90. CCDC_PRINT_REGISTER(isp, VDINT);
  91. CCDC_PRINT_REGISTER(isp, ALAW);
  92. CCDC_PRINT_REGISTER(isp, REC656IF);
  93. CCDC_PRINT_REGISTER(isp, CFG);
  94. CCDC_PRINT_REGISTER(isp, FMTCFG);
  95. CCDC_PRINT_REGISTER(isp, FMT_HORZ);
  96. CCDC_PRINT_REGISTER(isp, FMT_VERT);
  97. CCDC_PRINT_REGISTER(isp, PRGEVEN0);
  98. CCDC_PRINT_REGISTER(isp, PRGEVEN1);
  99. CCDC_PRINT_REGISTER(isp, PRGODD0);
  100. CCDC_PRINT_REGISTER(isp, PRGODD1);
  101. CCDC_PRINT_REGISTER(isp, VP_OUT);
  102. CCDC_PRINT_REGISTER(isp, LSC_CONFIG);
  103. CCDC_PRINT_REGISTER(isp, LSC_INITIAL);
  104. CCDC_PRINT_REGISTER(isp, LSC_TABLE_BASE);
  105. CCDC_PRINT_REGISTER(isp, LSC_TABLE_OFFSET);
  106. dev_dbg(isp->dev, "--------------------------------------------\n");
  107. }
  108. /*
  109. * omap3isp_ccdc_busy - Get busy state of the CCDC.
  110. * @ccdc: Pointer to ISP CCDC device.
  111. */
  112. int omap3isp_ccdc_busy(struct isp_ccdc_device *ccdc)
  113. {
  114. struct isp_device *isp = to_isp_device(ccdc);
  115. return isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_PCR) &
  116. ISPCCDC_PCR_BUSY;
  117. }
  118. /* -----------------------------------------------------------------------------
  119. * Lens Shading Compensation
  120. */
  121. /*
  122. * ccdc_lsc_validate_config - Check that LSC configuration is valid.
  123. * @ccdc: Pointer to ISP CCDC device.
  124. * @lsc_cfg: the LSC configuration to check.
  125. *
  126. * Returns 0 if the LSC configuration is valid, or -EINVAL if invalid.
  127. */
  128. static int ccdc_lsc_validate_config(struct isp_ccdc_device *ccdc,
  129. struct omap3isp_ccdc_lsc_config *lsc_cfg)
  130. {
  131. struct isp_device *isp = to_isp_device(ccdc);
  132. struct v4l2_mbus_framefmt *format;
  133. unsigned int paxel_width, paxel_height;
  134. unsigned int paxel_shift_x, paxel_shift_y;
  135. unsigned int min_width, min_height, min_size;
  136. unsigned int input_width, input_height;
  137. paxel_shift_x = lsc_cfg->gain_mode_m;
  138. paxel_shift_y = lsc_cfg->gain_mode_n;
  139. if ((paxel_shift_x < 2) || (paxel_shift_x > 6) ||
  140. (paxel_shift_y < 2) || (paxel_shift_y > 6)) {
  141. dev_dbg(isp->dev, "CCDC: LSC: Invalid paxel size\n");
  142. return -EINVAL;
  143. }
  144. if (lsc_cfg->offset & 3) {
  145. dev_dbg(isp->dev, "CCDC: LSC: Offset must be a multiple of "
  146. "4\n");
  147. return -EINVAL;
  148. }
  149. if ((lsc_cfg->initial_x & 1) || (lsc_cfg->initial_y & 1)) {
  150. dev_dbg(isp->dev, "CCDC: LSC: initial_x and y must be even\n");
  151. return -EINVAL;
  152. }
  153. format = __ccdc_get_format(ccdc, NULL, CCDC_PAD_SINK,
  154. V4L2_SUBDEV_FORMAT_ACTIVE);
  155. input_width = format->width;
  156. input_height = format->height;
  157. /* Calculate minimum bytesize for validation */
  158. paxel_width = 1 << paxel_shift_x;
  159. min_width = ((input_width + lsc_cfg->initial_x + paxel_width - 1)
  160. >> paxel_shift_x) + 1;
  161. paxel_height = 1 << paxel_shift_y;
  162. min_height = ((input_height + lsc_cfg->initial_y + paxel_height - 1)
  163. >> paxel_shift_y) + 1;
  164. min_size = 4 * min_width * min_height;
  165. if (min_size > lsc_cfg->size) {
  166. dev_dbg(isp->dev, "CCDC: LSC: too small table\n");
  167. return -EINVAL;
  168. }
  169. if (lsc_cfg->offset < (min_width * 4)) {
  170. dev_dbg(isp->dev, "CCDC: LSC: Offset is too small\n");
  171. return -EINVAL;
  172. }
  173. if ((lsc_cfg->size / lsc_cfg->offset) < min_height) {
  174. dev_dbg(isp->dev, "CCDC: LSC: Wrong size/offset combination\n");
  175. return -EINVAL;
  176. }
  177. return 0;
  178. }
  179. /*
  180. * ccdc_lsc_program_table - Program Lens Shading Compensation table address.
  181. * @ccdc: Pointer to ISP CCDC device.
  182. */
  183. static void ccdc_lsc_program_table(struct isp_ccdc_device *ccdc, u32 addr)
  184. {
  185. isp_reg_writel(to_isp_device(ccdc), addr,
  186. OMAP3_ISP_IOMEM_CCDC, ISPCCDC_LSC_TABLE_BASE);
  187. }
  188. /*
  189. * ccdc_lsc_setup_regs - Configures the lens shading compensation module
  190. * @ccdc: Pointer to ISP CCDC device.
  191. */
  192. static void ccdc_lsc_setup_regs(struct isp_ccdc_device *ccdc,
  193. struct omap3isp_ccdc_lsc_config *cfg)
  194. {
  195. struct isp_device *isp = to_isp_device(ccdc);
  196. int reg;
  197. isp_reg_writel(isp, cfg->offset, OMAP3_ISP_IOMEM_CCDC,
  198. ISPCCDC_LSC_TABLE_OFFSET);
  199. reg = 0;
  200. reg |= cfg->gain_mode_n << ISPCCDC_LSC_GAIN_MODE_N_SHIFT;
  201. reg |= cfg->gain_mode_m << ISPCCDC_LSC_GAIN_MODE_M_SHIFT;
  202. reg |= cfg->gain_format << ISPCCDC_LSC_GAIN_FORMAT_SHIFT;
  203. isp_reg_writel(isp, reg, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_LSC_CONFIG);
  204. reg = 0;
  205. reg &= ~ISPCCDC_LSC_INITIAL_X_MASK;
  206. reg |= cfg->initial_x << ISPCCDC_LSC_INITIAL_X_SHIFT;
  207. reg &= ~ISPCCDC_LSC_INITIAL_Y_MASK;
  208. reg |= cfg->initial_y << ISPCCDC_LSC_INITIAL_Y_SHIFT;
  209. isp_reg_writel(isp, reg, OMAP3_ISP_IOMEM_CCDC,
  210. ISPCCDC_LSC_INITIAL);
  211. }
  212. static int ccdc_lsc_wait_prefetch(struct isp_ccdc_device *ccdc)
  213. {
  214. struct isp_device *isp = to_isp_device(ccdc);
  215. unsigned int wait;
  216. isp_reg_writel(isp, IRQ0STATUS_CCDC_LSC_PREF_COMP_IRQ,
  217. OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
  218. /* timeout 1 ms */
  219. for (wait = 0; wait < 1000; wait++) {
  220. if (isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS) &
  221. IRQ0STATUS_CCDC_LSC_PREF_COMP_IRQ) {
  222. isp_reg_writel(isp, IRQ0STATUS_CCDC_LSC_PREF_COMP_IRQ,
  223. OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
  224. return 0;
  225. }
  226. rmb();
  227. udelay(1);
  228. }
  229. return -ETIMEDOUT;
  230. }
  231. /*
  232. * __ccdc_lsc_enable - Enables/Disables the Lens Shading Compensation module.
  233. * @ccdc: Pointer to ISP CCDC device.
  234. * @enable: 0 Disables LSC, 1 Enables LSC.
  235. */
  236. static int __ccdc_lsc_enable(struct isp_ccdc_device *ccdc, int enable)
  237. {
  238. struct isp_device *isp = to_isp_device(ccdc);
  239. const struct v4l2_mbus_framefmt *format =
  240. __ccdc_get_format(ccdc, NULL, CCDC_PAD_SINK,
  241. V4L2_SUBDEV_FORMAT_ACTIVE);
  242. if ((format->code != V4L2_MBUS_FMT_SGRBG10_1X10) &&
  243. (format->code != V4L2_MBUS_FMT_SRGGB10_1X10) &&
  244. (format->code != V4L2_MBUS_FMT_SBGGR10_1X10) &&
  245. (format->code != V4L2_MBUS_FMT_SGBRG10_1X10))
  246. return -EINVAL;
  247. if (enable)
  248. omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_CCDC_LSC_READ);
  249. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_LSC_CONFIG,
  250. ISPCCDC_LSC_ENABLE, enable ? ISPCCDC_LSC_ENABLE : 0);
  251. if (enable) {
  252. if (ccdc_lsc_wait_prefetch(ccdc) < 0) {
  253. isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC,
  254. ISPCCDC_LSC_CONFIG, ISPCCDC_LSC_ENABLE);
  255. ccdc->lsc.state = LSC_STATE_STOPPED;
  256. dev_warn(to_device(ccdc), "LSC prefecth timeout\n");
  257. return -ETIMEDOUT;
  258. }
  259. ccdc->lsc.state = LSC_STATE_RUNNING;
  260. } else {
  261. ccdc->lsc.state = LSC_STATE_STOPPING;
  262. }
  263. return 0;
  264. }
  265. static int ccdc_lsc_busy(struct isp_ccdc_device *ccdc)
  266. {
  267. struct isp_device *isp = to_isp_device(ccdc);
  268. return isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_LSC_CONFIG) &
  269. ISPCCDC_LSC_BUSY;
  270. }
  271. /* __ccdc_lsc_configure - Apply a new configuration to the LSC engine
  272. * @ccdc: Pointer to ISP CCDC device
  273. * @req: New configuration request
  274. *
  275. * context: in_interrupt()
  276. */
  277. static int __ccdc_lsc_configure(struct isp_ccdc_device *ccdc,
  278. struct ispccdc_lsc_config_req *req)
  279. {
  280. if (!req->enable)
  281. return -EINVAL;
  282. if (ccdc_lsc_validate_config(ccdc, &req->config) < 0) {
  283. dev_dbg(to_device(ccdc), "Discard LSC configuration\n");
  284. return -EINVAL;
  285. }
  286. if (ccdc_lsc_busy(ccdc))
  287. return -EBUSY;
  288. ccdc_lsc_setup_regs(ccdc, &req->config);
  289. ccdc_lsc_program_table(ccdc, req->table);
  290. return 0;
  291. }
  292. /*
  293. * ccdc_lsc_error_handler - Handle LSC prefetch error scenario.
  294. * @ccdc: Pointer to ISP CCDC device.
  295. *
  296. * Disables LSC, and defers enablement to shadow registers update time.
  297. */
  298. static void ccdc_lsc_error_handler(struct isp_ccdc_device *ccdc)
  299. {
  300. struct isp_device *isp = to_isp_device(ccdc);
  301. /*
  302. * From OMAP3 TRM: When this event is pending, the module
  303. * goes into transparent mode (output =input). Normal
  304. * operation can be resumed at the start of the next frame
  305. * after:
  306. * 1) Clearing this event
  307. * 2) Disabling the LSC module
  308. * 3) Enabling it
  309. */
  310. isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_LSC_CONFIG,
  311. ISPCCDC_LSC_ENABLE);
  312. ccdc->lsc.state = LSC_STATE_STOPPED;
  313. }
  314. static void ccdc_lsc_free_request(struct isp_ccdc_device *ccdc,
  315. struct ispccdc_lsc_config_req *req)
  316. {
  317. struct isp_device *isp = to_isp_device(ccdc);
  318. if (req == NULL)
  319. return;
  320. if (req->iovm)
  321. dma_unmap_sg(isp->dev, req->iovm->sgt->sgl,
  322. req->iovm->sgt->nents, DMA_TO_DEVICE);
  323. if (req->table)
  324. omap_iommu_vfree(isp->domain, isp->dev, req->table);
  325. kfree(req);
  326. }
  327. static void ccdc_lsc_free_queue(struct isp_ccdc_device *ccdc,
  328. struct list_head *queue)
  329. {
  330. struct ispccdc_lsc_config_req *req, *n;
  331. unsigned long flags;
  332. spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
  333. list_for_each_entry_safe(req, n, queue, list) {
  334. list_del(&req->list);
  335. spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
  336. ccdc_lsc_free_request(ccdc, req);
  337. spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
  338. }
  339. spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
  340. }
  341. static void ccdc_lsc_free_table_work(struct work_struct *work)
  342. {
  343. struct isp_ccdc_device *ccdc;
  344. struct ispccdc_lsc *lsc;
  345. lsc = container_of(work, struct ispccdc_lsc, table_work);
  346. ccdc = container_of(lsc, struct isp_ccdc_device, lsc);
  347. ccdc_lsc_free_queue(ccdc, &lsc->free_queue);
  348. }
  349. /*
  350. * ccdc_lsc_config - Configure the LSC module from a userspace request
  351. *
  352. * Store the request LSC configuration in the LSC engine request pointer. The
  353. * configuration will be applied to the hardware when the CCDC will be enabled,
  354. * or at the next LSC interrupt if the CCDC is already running.
  355. */
  356. static int ccdc_lsc_config(struct isp_ccdc_device *ccdc,
  357. struct omap3isp_ccdc_update_config *config)
  358. {
  359. struct isp_device *isp = to_isp_device(ccdc);
  360. struct ispccdc_lsc_config_req *req;
  361. unsigned long flags;
  362. void *table;
  363. u16 update;
  364. int ret;
  365. update = config->update &
  366. (OMAP3ISP_CCDC_CONFIG_LSC | OMAP3ISP_CCDC_TBL_LSC);
  367. if (!update)
  368. return 0;
  369. if (update != (OMAP3ISP_CCDC_CONFIG_LSC | OMAP3ISP_CCDC_TBL_LSC)) {
  370. dev_dbg(to_device(ccdc), "%s: Both LSC configuration and table "
  371. "need to be supplied\n", __func__);
  372. return -EINVAL;
  373. }
  374. req = kzalloc(sizeof(*req), GFP_KERNEL);
  375. if (req == NULL)
  376. return -ENOMEM;
  377. if (config->flag & OMAP3ISP_CCDC_CONFIG_LSC) {
  378. if (copy_from_user(&req->config, config->lsc_cfg,
  379. sizeof(req->config))) {
  380. ret = -EFAULT;
  381. goto done;
  382. }
  383. req->enable = 1;
  384. req->table = omap_iommu_vmalloc(isp->domain, isp->dev, 0,
  385. req->config.size, IOMMU_FLAG);
  386. if (IS_ERR_VALUE(req->table)) {
  387. req->table = 0;
  388. ret = -ENOMEM;
  389. goto done;
  390. }
  391. req->iovm = omap_find_iovm_area(isp->dev, req->table);
  392. if (req->iovm == NULL) {
  393. ret = -ENOMEM;
  394. goto done;
  395. }
  396. if (!dma_map_sg(isp->dev, req->iovm->sgt->sgl,
  397. req->iovm->sgt->nents, DMA_TO_DEVICE)) {
  398. ret = -ENOMEM;
  399. req->iovm = NULL;
  400. goto done;
  401. }
  402. dma_sync_sg_for_cpu(isp->dev, req->iovm->sgt->sgl,
  403. req->iovm->sgt->nents, DMA_TO_DEVICE);
  404. table = omap_da_to_va(isp->dev, req->table);
  405. if (copy_from_user(table, config->lsc, req->config.size)) {
  406. ret = -EFAULT;
  407. goto done;
  408. }
  409. dma_sync_sg_for_device(isp->dev, req->iovm->sgt->sgl,
  410. req->iovm->sgt->nents, DMA_TO_DEVICE);
  411. }
  412. spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
  413. if (ccdc->lsc.request) {
  414. list_add_tail(&ccdc->lsc.request->list, &ccdc->lsc.free_queue);
  415. schedule_work(&ccdc->lsc.table_work);
  416. }
  417. ccdc->lsc.request = req;
  418. spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
  419. ret = 0;
  420. done:
  421. if (ret < 0)
  422. ccdc_lsc_free_request(ccdc, req);
  423. return ret;
  424. }
  425. static inline int ccdc_lsc_is_configured(struct isp_ccdc_device *ccdc)
  426. {
  427. unsigned long flags;
  428. spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
  429. if (ccdc->lsc.active) {
  430. spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
  431. return 1;
  432. }
  433. spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
  434. return 0;
  435. }
  436. static int ccdc_lsc_enable(struct isp_ccdc_device *ccdc)
  437. {
  438. struct ispccdc_lsc *lsc = &ccdc->lsc;
  439. if (lsc->state != LSC_STATE_STOPPED)
  440. return -EINVAL;
  441. if (lsc->active) {
  442. list_add_tail(&lsc->active->list, &lsc->free_queue);
  443. lsc->active = NULL;
  444. }
  445. if (__ccdc_lsc_configure(ccdc, lsc->request) < 0) {
  446. omap3isp_sbl_disable(to_isp_device(ccdc),
  447. OMAP3_ISP_SBL_CCDC_LSC_READ);
  448. list_add_tail(&lsc->request->list, &lsc->free_queue);
  449. lsc->request = NULL;
  450. goto done;
  451. }
  452. lsc->active = lsc->request;
  453. lsc->request = NULL;
  454. __ccdc_lsc_enable(ccdc, 1);
  455. done:
  456. if (!list_empty(&lsc->free_queue))
  457. schedule_work(&lsc->table_work);
  458. return 0;
  459. }
  460. /* -----------------------------------------------------------------------------
  461. * Parameters configuration
  462. */
  463. /*
  464. * ccdc_configure_clamp - Configure optical-black or digital clamping
  465. * @ccdc: Pointer to ISP CCDC device.
  466. *
  467. * The CCDC performs either optical-black or digital clamp. Configure and enable
  468. * the selected clamp method.
  469. */
  470. static void ccdc_configure_clamp(struct isp_ccdc_device *ccdc)
  471. {
  472. struct isp_device *isp = to_isp_device(ccdc);
  473. u32 clamp;
  474. if (ccdc->obclamp) {
  475. clamp = ccdc->clamp.obgain << ISPCCDC_CLAMP_OBGAIN_SHIFT;
  476. clamp |= ccdc->clamp.oblen << ISPCCDC_CLAMP_OBSLEN_SHIFT;
  477. clamp |= ccdc->clamp.oblines << ISPCCDC_CLAMP_OBSLN_SHIFT;
  478. clamp |= ccdc->clamp.obstpixel << ISPCCDC_CLAMP_OBST_SHIFT;
  479. isp_reg_writel(isp, clamp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CLAMP);
  480. } else {
  481. isp_reg_writel(isp, ccdc->clamp.dcsubval,
  482. OMAP3_ISP_IOMEM_CCDC, ISPCCDC_DCSUB);
  483. }
  484. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CLAMP,
  485. ISPCCDC_CLAMP_CLAMPEN,
  486. ccdc->obclamp ? ISPCCDC_CLAMP_CLAMPEN : 0);
  487. }
  488. /*
  489. * ccdc_configure_fpc - Configure Faulty Pixel Correction
  490. * @ccdc: Pointer to ISP CCDC device.
  491. */
  492. static void ccdc_configure_fpc(struct isp_ccdc_device *ccdc)
  493. {
  494. struct isp_device *isp = to_isp_device(ccdc);
  495. isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FPC, ISPCCDC_FPC_FPCEN);
  496. if (!ccdc->fpc_en)
  497. return;
  498. isp_reg_writel(isp, ccdc->fpc.fpcaddr, OMAP3_ISP_IOMEM_CCDC,
  499. ISPCCDC_FPC_ADDR);
  500. /* The FPNUM field must be set before enabling FPC. */
  501. isp_reg_writel(isp, (ccdc->fpc.fpnum << ISPCCDC_FPC_FPNUM_SHIFT),
  502. OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FPC);
  503. isp_reg_writel(isp, (ccdc->fpc.fpnum << ISPCCDC_FPC_FPNUM_SHIFT) |
  504. ISPCCDC_FPC_FPCEN, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FPC);
  505. }
  506. /*
  507. * ccdc_configure_black_comp - Configure Black Level Compensation.
  508. * @ccdc: Pointer to ISP CCDC device.
  509. */
  510. static void ccdc_configure_black_comp(struct isp_ccdc_device *ccdc)
  511. {
  512. struct isp_device *isp = to_isp_device(ccdc);
  513. u32 blcomp;
  514. blcomp = ccdc->blcomp.b_mg << ISPCCDC_BLKCMP_B_MG_SHIFT;
  515. blcomp |= ccdc->blcomp.gb_g << ISPCCDC_BLKCMP_GB_G_SHIFT;
  516. blcomp |= ccdc->blcomp.gr_cy << ISPCCDC_BLKCMP_GR_CY_SHIFT;
  517. blcomp |= ccdc->blcomp.r_ye << ISPCCDC_BLKCMP_R_YE_SHIFT;
  518. isp_reg_writel(isp, blcomp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_BLKCMP);
  519. }
  520. /*
  521. * ccdc_configure_lpf - Configure Low-Pass Filter (LPF).
  522. * @ccdc: Pointer to ISP CCDC device.
  523. */
  524. static void ccdc_configure_lpf(struct isp_ccdc_device *ccdc)
  525. {
  526. struct isp_device *isp = to_isp_device(ccdc);
  527. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE,
  528. ISPCCDC_SYN_MODE_LPF,
  529. ccdc->lpf ? ISPCCDC_SYN_MODE_LPF : 0);
  530. }
  531. /*
  532. * ccdc_configure_alaw - Configure A-law compression.
  533. * @ccdc: Pointer to ISP CCDC device.
  534. */
  535. static void ccdc_configure_alaw(struct isp_ccdc_device *ccdc)
  536. {
  537. struct isp_device *isp = to_isp_device(ccdc);
  538. u32 alaw = 0;
  539. switch (ccdc->syncif.datsz) {
  540. case 8:
  541. return;
  542. case 10:
  543. alaw = ISPCCDC_ALAW_GWDI_9_0;
  544. break;
  545. case 11:
  546. alaw = ISPCCDC_ALAW_GWDI_10_1;
  547. break;
  548. case 12:
  549. alaw = ISPCCDC_ALAW_GWDI_11_2;
  550. break;
  551. case 13:
  552. alaw = ISPCCDC_ALAW_GWDI_12_3;
  553. break;
  554. }
  555. if (ccdc->alaw)
  556. alaw |= ISPCCDC_ALAW_CCDTBL;
  557. isp_reg_writel(isp, alaw, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_ALAW);
  558. }
  559. /*
  560. * ccdc_config_imgattr - Configure sensor image specific attributes.
  561. * @ccdc: Pointer to ISP CCDC device.
  562. * @colptn: Color pattern of the sensor.
  563. */
  564. static void ccdc_config_imgattr(struct isp_ccdc_device *ccdc, u32 colptn)
  565. {
  566. struct isp_device *isp = to_isp_device(ccdc);
  567. isp_reg_writel(isp, colptn, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_COLPTN);
  568. }
  569. /*
  570. * ccdc_config - Set CCDC configuration from userspace
  571. * @ccdc: Pointer to ISP CCDC device.
  572. * @userspace_add: Structure containing CCDC configuration sent from userspace.
  573. *
  574. * Returns 0 if successful, -EINVAL if the pointer to the configuration
  575. * structure is null, or the copy_from_user function fails to copy user space
  576. * memory to kernel space memory.
  577. */
  578. static int ccdc_config(struct isp_ccdc_device *ccdc,
  579. struct omap3isp_ccdc_update_config *ccdc_struct)
  580. {
  581. struct isp_device *isp = to_isp_device(ccdc);
  582. unsigned long flags;
  583. spin_lock_irqsave(&ccdc->lock, flags);
  584. ccdc->shadow_update = 1;
  585. spin_unlock_irqrestore(&ccdc->lock, flags);
  586. if (OMAP3ISP_CCDC_ALAW & ccdc_struct->update) {
  587. ccdc->alaw = !!(OMAP3ISP_CCDC_ALAW & ccdc_struct->flag);
  588. ccdc->update |= OMAP3ISP_CCDC_ALAW;
  589. }
  590. if (OMAP3ISP_CCDC_LPF & ccdc_struct->update) {
  591. ccdc->lpf = !!(OMAP3ISP_CCDC_LPF & ccdc_struct->flag);
  592. ccdc->update |= OMAP3ISP_CCDC_LPF;
  593. }
  594. if (OMAP3ISP_CCDC_BLCLAMP & ccdc_struct->update) {
  595. if (copy_from_user(&ccdc->clamp, ccdc_struct->bclamp,
  596. sizeof(ccdc->clamp))) {
  597. ccdc->shadow_update = 0;
  598. return -EFAULT;
  599. }
  600. ccdc->obclamp = !!(OMAP3ISP_CCDC_BLCLAMP & ccdc_struct->flag);
  601. ccdc->update |= OMAP3ISP_CCDC_BLCLAMP;
  602. }
  603. if (OMAP3ISP_CCDC_BCOMP & ccdc_struct->update) {
  604. if (copy_from_user(&ccdc->blcomp, ccdc_struct->blcomp,
  605. sizeof(ccdc->blcomp))) {
  606. ccdc->shadow_update = 0;
  607. return -EFAULT;
  608. }
  609. ccdc->update |= OMAP3ISP_CCDC_BCOMP;
  610. }
  611. ccdc->shadow_update = 0;
  612. if (OMAP3ISP_CCDC_FPC & ccdc_struct->update) {
  613. u32 table_old = 0;
  614. u32 table_new;
  615. u32 size;
  616. if (ccdc->state != ISP_PIPELINE_STREAM_STOPPED)
  617. return -EBUSY;
  618. ccdc->fpc_en = !!(OMAP3ISP_CCDC_FPC & ccdc_struct->flag);
  619. if (ccdc->fpc_en) {
  620. if (copy_from_user(&ccdc->fpc, ccdc_struct->fpc,
  621. sizeof(ccdc->fpc)))
  622. return -EFAULT;
  623. /*
  624. * table_new must be 64-bytes aligned, but it's
  625. * already done by omap_iommu_vmalloc().
  626. */
  627. size = ccdc->fpc.fpnum * 4;
  628. table_new = omap_iommu_vmalloc(isp->domain, isp->dev,
  629. 0, size, IOMMU_FLAG);
  630. if (IS_ERR_VALUE(table_new))
  631. return -ENOMEM;
  632. if (copy_from_user(omap_da_to_va(isp->dev, table_new),
  633. (__force void __user *)
  634. ccdc->fpc.fpcaddr, size)) {
  635. omap_iommu_vfree(isp->domain, isp->dev,
  636. table_new);
  637. return -EFAULT;
  638. }
  639. table_old = ccdc->fpc.fpcaddr;
  640. ccdc->fpc.fpcaddr = table_new;
  641. }
  642. ccdc_configure_fpc(ccdc);
  643. if (table_old != 0)
  644. omap_iommu_vfree(isp->domain, isp->dev, table_old);
  645. }
  646. return ccdc_lsc_config(ccdc, ccdc_struct);
  647. }
  648. static void ccdc_apply_controls(struct isp_ccdc_device *ccdc)
  649. {
  650. if (ccdc->update & OMAP3ISP_CCDC_ALAW) {
  651. ccdc_configure_alaw(ccdc);
  652. ccdc->update &= ~OMAP3ISP_CCDC_ALAW;
  653. }
  654. if (ccdc->update & OMAP3ISP_CCDC_LPF) {
  655. ccdc_configure_lpf(ccdc);
  656. ccdc->update &= ~OMAP3ISP_CCDC_LPF;
  657. }
  658. if (ccdc->update & OMAP3ISP_CCDC_BLCLAMP) {
  659. ccdc_configure_clamp(ccdc);
  660. ccdc->update &= ~OMAP3ISP_CCDC_BLCLAMP;
  661. }
  662. if (ccdc->update & OMAP3ISP_CCDC_BCOMP) {
  663. ccdc_configure_black_comp(ccdc);
  664. ccdc->update &= ~OMAP3ISP_CCDC_BCOMP;
  665. }
  666. }
  667. /*
  668. * omap3isp_ccdc_restore_context - Restore values of the CCDC module registers
  669. * @dev: Pointer to ISP device
  670. */
  671. void omap3isp_ccdc_restore_context(struct isp_device *isp)
  672. {
  673. struct isp_ccdc_device *ccdc = &isp->isp_ccdc;
  674. isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CFG, ISPCCDC_CFG_VDLC);
  675. ccdc->update = OMAP3ISP_CCDC_ALAW | OMAP3ISP_CCDC_LPF
  676. | OMAP3ISP_CCDC_BLCLAMP | OMAP3ISP_CCDC_BCOMP;
  677. ccdc_apply_controls(ccdc);
  678. ccdc_configure_fpc(ccdc);
  679. }
  680. /* -----------------------------------------------------------------------------
  681. * Format- and pipeline-related configuration helpers
  682. */
  683. /*
  684. * ccdc_config_vp - Configure the Video Port.
  685. * @ccdc: Pointer to ISP CCDC device.
  686. */
  687. static void ccdc_config_vp(struct isp_ccdc_device *ccdc)
  688. {
  689. struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity);
  690. struct isp_device *isp = to_isp_device(ccdc);
  691. unsigned long l3_ick = pipe->l3_ick;
  692. unsigned int max_div = isp->revision == ISP_REVISION_15_0 ? 64 : 8;
  693. unsigned int div = 0;
  694. u32 fmtcfg_vp;
  695. fmtcfg_vp = isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FMTCFG)
  696. & ~(ISPCCDC_FMTCFG_VPIN_MASK | ISPCCDC_FMTCFG_VPIF_FRQ_MASK);
  697. switch (ccdc->syncif.datsz) {
  698. case 8:
  699. case 10:
  700. fmtcfg_vp |= ISPCCDC_FMTCFG_VPIN_9_0;
  701. break;
  702. case 11:
  703. fmtcfg_vp |= ISPCCDC_FMTCFG_VPIN_10_1;
  704. break;
  705. case 12:
  706. fmtcfg_vp |= ISPCCDC_FMTCFG_VPIN_11_2;
  707. break;
  708. case 13:
  709. fmtcfg_vp |= ISPCCDC_FMTCFG_VPIN_12_3;
  710. break;
  711. };
  712. if (pipe->input)
  713. div = DIV_ROUND_UP(l3_ick, pipe->max_rate);
  714. else if (pipe->external_rate)
  715. div = l3_ick / pipe->external_rate;
  716. div = clamp(div, 2U, max_div);
  717. fmtcfg_vp |= (div - 2) << ISPCCDC_FMTCFG_VPIF_FRQ_SHIFT;
  718. isp_reg_writel(isp, fmtcfg_vp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FMTCFG);
  719. }
  720. /*
  721. * ccdc_enable_vp - Enable Video Port.
  722. * @ccdc: Pointer to ISP CCDC device.
  723. * @enable: 0 Disables VP, 1 Enables VP
  724. *
  725. * This is needed for outputting image to Preview, H3A and HIST ISP submodules.
  726. */
  727. static void ccdc_enable_vp(struct isp_ccdc_device *ccdc, u8 enable)
  728. {
  729. struct isp_device *isp = to_isp_device(ccdc);
  730. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FMTCFG,
  731. ISPCCDC_FMTCFG_VPEN, enable ? ISPCCDC_FMTCFG_VPEN : 0);
  732. }
  733. /*
  734. * ccdc_config_outlineoffset - Configure memory saving output line offset
  735. * @ccdc: Pointer to ISP CCDC device.
  736. * @offset: Address offset to start a new line. Must be twice the
  737. * Output width and aligned on 32 byte boundary
  738. * @oddeven: Specifies the odd/even line pattern to be chosen to store the
  739. * output.
  740. * @numlines: Set the value 0-3 for +1-4lines, 4-7 for -1-4lines.
  741. *
  742. * - Configures the output line offset when stored in memory
  743. * - Sets the odd/even line pattern to store the output
  744. * (EVENEVEN (1), ODDEVEN (2), EVENODD (3), ODDODD (4))
  745. * - Configures the number of even and odd line fields in case of rearranging
  746. * the lines.
  747. */
  748. static void ccdc_config_outlineoffset(struct isp_ccdc_device *ccdc,
  749. u32 offset, u8 oddeven, u8 numlines)
  750. {
  751. struct isp_device *isp = to_isp_device(ccdc);
  752. isp_reg_writel(isp, offset & 0xffff,
  753. OMAP3_ISP_IOMEM_CCDC, ISPCCDC_HSIZE_OFF);
  754. isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SDOFST,
  755. ISPCCDC_SDOFST_FINV);
  756. isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SDOFST,
  757. ISPCCDC_SDOFST_FOFST_4L);
  758. switch (oddeven) {
  759. case EVENEVEN:
  760. isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SDOFST,
  761. (numlines & 0x7) << ISPCCDC_SDOFST_LOFST0_SHIFT);
  762. break;
  763. case ODDEVEN:
  764. isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SDOFST,
  765. (numlines & 0x7) << ISPCCDC_SDOFST_LOFST1_SHIFT);
  766. break;
  767. case EVENODD:
  768. isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SDOFST,
  769. (numlines & 0x7) << ISPCCDC_SDOFST_LOFST2_SHIFT);
  770. break;
  771. case ODDODD:
  772. isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SDOFST,
  773. (numlines & 0x7) << ISPCCDC_SDOFST_LOFST3_SHIFT);
  774. break;
  775. default:
  776. break;
  777. }
  778. }
  779. /*
  780. * ccdc_set_outaddr - Set memory address to save output image
  781. * @ccdc: Pointer to ISP CCDC device.
  782. * @addr: ISP MMU Mapped 32-bit memory address aligned on 32 byte boundary.
  783. *
  784. * Sets the memory address where the output will be saved.
  785. */
  786. static void ccdc_set_outaddr(struct isp_ccdc_device *ccdc, u32 addr)
  787. {
  788. struct isp_device *isp = to_isp_device(ccdc);
  789. isp_reg_writel(isp, addr, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SDR_ADDR);
  790. }
  791. /*
  792. * omap3isp_ccdc_max_rate - Calculate maximum input data rate based on the input
  793. * @ccdc: Pointer to ISP CCDC device.
  794. * @max_rate: Maximum calculated data rate.
  795. *
  796. * Returns in *max_rate less value between calculated and passed
  797. */
  798. void omap3isp_ccdc_max_rate(struct isp_ccdc_device *ccdc,
  799. unsigned int *max_rate)
  800. {
  801. struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity);
  802. unsigned int rate;
  803. if (pipe == NULL)
  804. return;
  805. /*
  806. * TRM says that for parallel sensors the maximum data rate
  807. * should be 90% form L3/2 clock, otherwise just L3/2.
  808. */
  809. if (ccdc->input == CCDC_INPUT_PARALLEL)
  810. rate = pipe->l3_ick / 2 * 9 / 10;
  811. else
  812. rate = pipe->l3_ick / 2;
  813. *max_rate = min(*max_rate, rate);
  814. }
  815. /*
  816. * ccdc_config_sync_if - Set CCDC sync interface configuration
  817. * @ccdc: Pointer to ISP CCDC device.
  818. * @syncif: Structure containing the sync parameters like field state, CCDC in
  819. * master/slave mode, raw/yuv data, polarity of data, field, hs, vs
  820. * signals.
  821. */
  822. static void ccdc_config_sync_if(struct isp_ccdc_device *ccdc,
  823. struct ispccdc_syncif *syncif)
  824. {
  825. struct isp_device *isp = to_isp_device(ccdc);
  826. u32 syn_mode = isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC,
  827. ISPCCDC_SYN_MODE);
  828. syn_mode |= ISPCCDC_SYN_MODE_VDHDEN;
  829. if (syncif->fldstat)
  830. syn_mode |= ISPCCDC_SYN_MODE_FLDSTAT;
  831. else
  832. syn_mode &= ~ISPCCDC_SYN_MODE_FLDSTAT;
  833. syn_mode &= ~ISPCCDC_SYN_MODE_DATSIZ_MASK;
  834. switch (syncif->datsz) {
  835. case 8:
  836. syn_mode |= ISPCCDC_SYN_MODE_DATSIZ_8;
  837. break;
  838. case 10:
  839. syn_mode |= ISPCCDC_SYN_MODE_DATSIZ_10;
  840. break;
  841. case 11:
  842. syn_mode |= ISPCCDC_SYN_MODE_DATSIZ_11;
  843. break;
  844. case 12:
  845. syn_mode |= ISPCCDC_SYN_MODE_DATSIZ_12;
  846. break;
  847. };
  848. if (syncif->fldmode)
  849. syn_mode |= ISPCCDC_SYN_MODE_FLDMODE;
  850. else
  851. syn_mode &= ~ISPCCDC_SYN_MODE_FLDMODE;
  852. if (syncif->datapol)
  853. syn_mode |= ISPCCDC_SYN_MODE_DATAPOL;
  854. else
  855. syn_mode &= ~ISPCCDC_SYN_MODE_DATAPOL;
  856. if (syncif->fldpol)
  857. syn_mode |= ISPCCDC_SYN_MODE_FLDPOL;
  858. else
  859. syn_mode &= ~ISPCCDC_SYN_MODE_FLDPOL;
  860. if (syncif->hdpol)
  861. syn_mode |= ISPCCDC_SYN_MODE_HDPOL;
  862. else
  863. syn_mode &= ~ISPCCDC_SYN_MODE_HDPOL;
  864. if (syncif->vdpol)
  865. syn_mode |= ISPCCDC_SYN_MODE_VDPOL;
  866. else
  867. syn_mode &= ~ISPCCDC_SYN_MODE_VDPOL;
  868. if (syncif->ccdc_mastermode) {
  869. syn_mode |= ISPCCDC_SYN_MODE_FLDOUT | ISPCCDC_SYN_MODE_VDHDOUT;
  870. isp_reg_writel(isp,
  871. syncif->hs_width << ISPCCDC_HD_VD_WID_HDW_SHIFT
  872. | syncif->vs_width << ISPCCDC_HD_VD_WID_VDW_SHIFT,
  873. OMAP3_ISP_IOMEM_CCDC,
  874. ISPCCDC_HD_VD_WID);
  875. isp_reg_writel(isp,
  876. syncif->ppln << ISPCCDC_PIX_LINES_PPLN_SHIFT
  877. | syncif->hlprf << ISPCCDC_PIX_LINES_HLPRF_SHIFT,
  878. OMAP3_ISP_IOMEM_CCDC,
  879. ISPCCDC_PIX_LINES);
  880. } else
  881. syn_mode &= ~(ISPCCDC_SYN_MODE_FLDOUT |
  882. ISPCCDC_SYN_MODE_VDHDOUT);
  883. isp_reg_writel(isp, syn_mode, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE);
  884. if (!syncif->bt_r656_en)
  885. isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_REC656IF,
  886. ISPCCDC_REC656IF_R656ON);
  887. }
  888. /* CCDC formats descriptions */
  889. static const u32 ccdc_sgrbg_pattern =
  890. ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP0PLC0_SHIFT |
  891. ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP0PLC1_SHIFT |
  892. ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP0PLC2_SHIFT |
  893. ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP0PLC3_SHIFT |
  894. ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP1PLC0_SHIFT |
  895. ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP1PLC1_SHIFT |
  896. ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP1PLC2_SHIFT |
  897. ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP1PLC3_SHIFT |
  898. ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP2PLC0_SHIFT |
  899. ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP2PLC1_SHIFT |
  900. ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP2PLC2_SHIFT |
  901. ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP2PLC3_SHIFT |
  902. ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP3PLC0_SHIFT |
  903. ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP3PLC1_SHIFT |
  904. ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP3PLC2_SHIFT |
  905. ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP3PLC3_SHIFT;
  906. static const u32 ccdc_srggb_pattern =
  907. ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP0PLC0_SHIFT |
  908. ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP0PLC1_SHIFT |
  909. ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP0PLC2_SHIFT |
  910. ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP0PLC3_SHIFT |
  911. ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP1PLC0_SHIFT |
  912. ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP1PLC1_SHIFT |
  913. ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP1PLC2_SHIFT |
  914. ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP1PLC3_SHIFT |
  915. ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP2PLC0_SHIFT |
  916. ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP2PLC1_SHIFT |
  917. ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP2PLC2_SHIFT |
  918. ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP2PLC3_SHIFT |
  919. ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP3PLC0_SHIFT |
  920. ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP3PLC1_SHIFT |
  921. ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP3PLC2_SHIFT |
  922. ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP3PLC3_SHIFT;
  923. static const u32 ccdc_sbggr_pattern =
  924. ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP0PLC0_SHIFT |
  925. ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP0PLC1_SHIFT |
  926. ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP0PLC2_SHIFT |
  927. ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP0PLC3_SHIFT |
  928. ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP1PLC0_SHIFT |
  929. ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP1PLC1_SHIFT |
  930. ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP1PLC2_SHIFT |
  931. ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP1PLC3_SHIFT |
  932. ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP2PLC0_SHIFT |
  933. ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP2PLC1_SHIFT |
  934. ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP2PLC2_SHIFT |
  935. ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP2PLC3_SHIFT |
  936. ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP3PLC0_SHIFT |
  937. ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP3PLC1_SHIFT |
  938. ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP3PLC2_SHIFT |
  939. ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP3PLC3_SHIFT;
  940. static const u32 ccdc_sgbrg_pattern =
  941. ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP0PLC0_SHIFT |
  942. ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP0PLC1_SHIFT |
  943. ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP0PLC2_SHIFT |
  944. ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP0PLC3_SHIFT |
  945. ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP1PLC0_SHIFT |
  946. ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP1PLC1_SHIFT |
  947. ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP1PLC2_SHIFT |
  948. ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP1PLC3_SHIFT |
  949. ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP2PLC0_SHIFT |
  950. ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP2PLC1_SHIFT |
  951. ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP2PLC2_SHIFT |
  952. ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP2PLC3_SHIFT |
  953. ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP3PLC0_SHIFT |
  954. ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP3PLC1_SHIFT |
  955. ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP3PLC2_SHIFT |
  956. ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP3PLC3_SHIFT;
  957. static void ccdc_configure(struct isp_ccdc_device *ccdc)
  958. {
  959. struct isp_device *isp = to_isp_device(ccdc);
  960. struct isp_parallel_platform_data *pdata = NULL;
  961. struct v4l2_subdev *sensor;
  962. struct v4l2_mbus_framefmt *format;
  963. const struct v4l2_rect *crop;
  964. const struct isp_format_info *fmt_info;
  965. struct v4l2_subdev_format fmt_src;
  966. unsigned int depth_out;
  967. unsigned int depth_in = 0;
  968. struct media_pad *pad;
  969. unsigned long flags;
  970. unsigned int shift;
  971. u32 syn_mode;
  972. u32 ccdc_pattern;
  973. pad = media_entity_remote_source(&ccdc->pads[CCDC_PAD_SINK]);
  974. sensor = media_entity_to_v4l2_subdev(pad->entity);
  975. if (ccdc->input == CCDC_INPUT_PARALLEL)
  976. pdata = &((struct isp_v4l2_subdevs_group *)sensor->host_priv)
  977. ->bus.parallel;
  978. /* Compute shift value for lane shifter to configure the bridge. */
  979. fmt_src.pad = pad->index;
  980. fmt_src.which = V4L2_SUBDEV_FORMAT_ACTIVE;
  981. if (!v4l2_subdev_call(sensor, pad, get_fmt, NULL, &fmt_src)) {
  982. fmt_info = omap3isp_video_format_info(fmt_src.format.code);
  983. depth_in = fmt_info->bpp;
  984. }
  985. fmt_info = omap3isp_video_format_info
  986. (isp->isp_ccdc.formats[CCDC_PAD_SINK].code);
  987. depth_out = fmt_info->bpp;
  988. shift = depth_in - depth_out;
  989. omap3isp_configure_bridge(isp, ccdc->input, pdata, shift);
  990. ccdc->syncif.datsz = depth_out;
  991. ccdc->syncif.hdpol = pdata ? pdata->hs_pol : 0;
  992. ccdc->syncif.vdpol = pdata ? pdata->vs_pol : 0;
  993. ccdc_config_sync_if(ccdc, &ccdc->syncif);
  994. /* CCDC_PAD_SINK */
  995. format = &ccdc->formats[CCDC_PAD_SINK];
  996. syn_mode = isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE);
  997. /* Use the raw, unprocessed data when writing to memory. The H3A and
  998. * histogram modules are still fed with lens shading corrected data.
  999. */
  1000. syn_mode &= ~ISPCCDC_SYN_MODE_VP2SDR;
  1001. if (ccdc->output & CCDC_OUTPUT_MEMORY)
  1002. syn_mode |= ISPCCDC_SYN_MODE_WEN;
  1003. else
  1004. syn_mode &= ~ISPCCDC_SYN_MODE_WEN;
  1005. if (ccdc->output & CCDC_OUTPUT_RESIZER)
  1006. syn_mode |= ISPCCDC_SYN_MODE_SDR2RSZ;
  1007. else
  1008. syn_mode &= ~ISPCCDC_SYN_MODE_SDR2RSZ;
  1009. /* Use PACK8 mode for 1byte per pixel formats. */
  1010. if (omap3isp_video_format_info(format->code)->bpp <= 8)
  1011. syn_mode |= ISPCCDC_SYN_MODE_PACK8;
  1012. else
  1013. syn_mode &= ~ISPCCDC_SYN_MODE_PACK8;
  1014. isp_reg_writel(isp, syn_mode, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE);
  1015. /* Mosaic filter */
  1016. switch (format->code) {
  1017. case V4L2_MBUS_FMT_SRGGB10_1X10:
  1018. case V4L2_MBUS_FMT_SRGGB12_1X12:
  1019. ccdc_pattern = ccdc_srggb_pattern;
  1020. break;
  1021. case V4L2_MBUS_FMT_SBGGR10_1X10:
  1022. case V4L2_MBUS_FMT_SBGGR12_1X12:
  1023. ccdc_pattern = ccdc_sbggr_pattern;
  1024. break;
  1025. case V4L2_MBUS_FMT_SGBRG10_1X10:
  1026. case V4L2_MBUS_FMT_SGBRG12_1X12:
  1027. ccdc_pattern = ccdc_sgbrg_pattern;
  1028. break;
  1029. default:
  1030. /* Use GRBG */
  1031. ccdc_pattern = ccdc_sgrbg_pattern;
  1032. break;
  1033. }
  1034. ccdc_config_imgattr(ccdc, ccdc_pattern);
  1035. /* Generate VD0 on the last line of the image and VD1 on the
  1036. * 2/3 height line.
  1037. */
  1038. isp_reg_writel(isp, ((format->height - 2) << ISPCCDC_VDINT_0_SHIFT) |
  1039. ((format->height * 2 / 3) << ISPCCDC_VDINT_1_SHIFT),
  1040. OMAP3_ISP_IOMEM_CCDC, ISPCCDC_VDINT);
  1041. /* CCDC_PAD_SOURCE_OF */
  1042. crop = &ccdc->crop;
  1043. isp_reg_writel(isp, (crop->left << ISPCCDC_HORZ_INFO_SPH_SHIFT) |
  1044. ((crop->width - 1) << ISPCCDC_HORZ_INFO_NPH_SHIFT),
  1045. OMAP3_ISP_IOMEM_CCDC, ISPCCDC_HORZ_INFO);
  1046. isp_reg_writel(isp, crop->top << ISPCCDC_VERT_START_SLV0_SHIFT,
  1047. OMAP3_ISP_IOMEM_CCDC, ISPCCDC_VERT_START);
  1048. isp_reg_writel(isp, (crop->height - 1)
  1049. << ISPCCDC_VERT_LINES_NLV_SHIFT,
  1050. OMAP3_ISP_IOMEM_CCDC, ISPCCDC_VERT_LINES);
  1051. ccdc_config_outlineoffset(ccdc, ccdc->video_out.bpl_value, 0, 0);
  1052. /* CCDC_PAD_SOURCE_VP */
  1053. format = &ccdc->formats[CCDC_PAD_SOURCE_VP];
  1054. isp_reg_writel(isp, (0 << ISPCCDC_FMT_HORZ_FMTSPH_SHIFT) |
  1055. (format->width << ISPCCDC_FMT_HORZ_FMTLNH_SHIFT),
  1056. OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FMT_HORZ);
  1057. isp_reg_writel(isp, (0 << ISPCCDC_FMT_VERT_FMTSLV_SHIFT) |
  1058. ((format->height + 1) << ISPCCDC_FMT_VERT_FMTLNV_SHIFT),
  1059. OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FMT_VERT);
  1060. isp_reg_writel(isp, (format->width << ISPCCDC_VP_OUT_HORZ_NUM_SHIFT) |
  1061. (format->height << ISPCCDC_VP_OUT_VERT_NUM_SHIFT),
  1062. OMAP3_ISP_IOMEM_CCDC, ISPCCDC_VP_OUT);
  1063. spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
  1064. if (ccdc->lsc.request == NULL)
  1065. goto unlock;
  1066. WARN_ON(ccdc->lsc.active);
  1067. /* Get last good LSC configuration. If it is not supported for
  1068. * the current active resolution discard it.
  1069. */
  1070. if (ccdc->lsc.active == NULL &&
  1071. __ccdc_lsc_configure(ccdc, ccdc->lsc.request) == 0) {
  1072. ccdc->lsc.active = ccdc->lsc.request;
  1073. } else {
  1074. list_add_tail(&ccdc->lsc.request->list, &ccdc->lsc.free_queue);
  1075. schedule_work(&ccdc->lsc.table_work);
  1076. }
  1077. ccdc->lsc.request = NULL;
  1078. unlock:
  1079. spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
  1080. ccdc_apply_controls(ccdc);
  1081. }
  1082. static void __ccdc_enable(struct isp_ccdc_device *ccdc, int enable)
  1083. {
  1084. struct isp_device *isp = to_isp_device(ccdc);
  1085. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_PCR,
  1086. ISPCCDC_PCR_EN, enable ? ISPCCDC_PCR_EN : 0);
  1087. }
  1088. static int ccdc_disable(struct isp_ccdc_device *ccdc)
  1089. {
  1090. unsigned long flags;
  1091. int ret = 0;
  1092. spin_lock_irqsave(&ccdc->lock, flags);
  1093. if (ccdc->state == ISP_PIPELINE_STREAM_CONTINUOUS)
  1094. ccdc->stopping = CCDC_STOP_REQUEST;
  1095. spin_unlock_irqrestore(&ccdc->lock, flags);
  1096. ret = wait_event_timeout(ccdc->wait,
  1097. ccdc->stopping == CCDC_STOP_FINISHED,
  1098. msecs_to_jiffies(2000));
  1099. if (ret == 0) {
  1100. ret = -ETIMEDOUT;
  1101. dev_warn(to_device(ccdc), "CCDC stop timeout!\n");
  1102. }
  1103. omap3isp_sbl_disable(to_isp_device(ccdc), OMAP3_ISP_SBL_CCDC_LSC_READ);
  1104. mutex_lock(&ccdc->ioctl_lock);
  1105. ccdc_lsc_free_request(ccdc, ccdc->lsc.request);
  1106. ccdc->lsc.request = ccdc->lsc.active;
  1107. ccdc->lsc.active = NULL;
  1108. cancel_work_sync(&ccdc->lsc.table_work);
  1109. ccdc_lsc_free_queue(ccdc, &ccdc->lsc.free_queue);
  1110. mutex_unlock(&ccdc->ioctl_lock);
  1111. ccdc->stopping = CCDC_STOP_NOT_REQUESTED;
  1112. return ret > 0 ? 0 : ret;
  1113. }
  1114. static void ccdc_enable(struct isp_ccdc_device *ccdc)
  1115. {
  1116. if (ccdc_lsc_is_configured(ccdc))
  1117. __ccdc_lsc_enable(ccdc, 1);
  1118. __ccdc_enable(ccdc, 1);
  1119. }
  1120. /* -----------------------------------------------------------------------------
  1121. * Interrupt handling
  1122. */
  1123. /*
  1124. * ccdc_sbl_busy - Poll idle state of CCDC and related SBL memory write bits
  1125. * @ccdc: Pointer to ISP CCDC device.
  1126. *
  1127. * Returns zero if the CCDC is idle and the image has been written to
  1128. * memory, too.
  1129. */
  1130. static int ccdc_sbl_busy(struct isp_ccdc_device *ccdc)
  1131. {
  1132. struct isp_device *isp = to_isp_device(ccdc);
  1133. return omap3isp_ccdc_busy(ccdc)
  1134. | (isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_CCDC_WR_0) &
  1135. ISPSBL_CCDC_WR_0_DATA_READY)
  1136. | (isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_CCDC_WR_1) &
  1137. ISPSBL_CCDC_WR_0_DATA_READY)
  1138. | (isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_CCDC_WR_2) &
  1139. ISPSBL_CCDC_WR_0_DATA_READY)
  1140. | (isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_CCDC_WR_3) &
  1141. ISPSBL_CCDC_WR_0_DATA_READY);
  1142. }
  1143. /*
  1144. * ccdc_sbl_wait_idle - Wait until the CCDC and related SBL are idle
  1145. * @ccdc: Pointer to ISP CCDC device.
  1146. * @max_wait: Max retry count in us for wait for idle/busy transition.
  1147. */
  1148. static int ccdc_sbl_wait_idle(struct isp_ccdc_device *ccdc,
  1149. unsigned int max_wait)
  1150. {
  1151. unsigned int wait = 0;
  1152. if (max_wait == 0)
  1153. max_wait = 10000; /* 10 ms */
  1154. for (wait = 0; wait <= max_wait; wait++) {
  1155. if (!ccdc_sbl_busy(ccdc))
  1156. return 0;
  1157. rmb();
  1158. udelay(1);
  1159. }
  1160. return -EBUSY;
  1161. }
  1162. /* __ccdc_handle_stopping - Handle CCDC and/or LSC stopping sequence
  1163. * @ccdc: Pointer to ISP CCDC device.
  1164. * @event: Pointing which event trigger handler
  1165. *
  1166. * Return 1 when the event and stopping request combination is satisfied,
  1167. * zero otherwise.
  1168. */
  1169. static int __ccdc_handle_stopping(struct isp_ccdc_device *ccdc, u32 event)
  1170. {
  1171. int rval = 0;
  1172. switch ((ccdc->stopping & 3) | event) {
  1173. case CCDC_STOP_REQUEST | CCDC_EVENT_VD1:
  1174. if (ccdc->lsc.state != LSC_STATE_STOPPED)
  1175. __ccdc_lsc_enable(ccdc, 0);
  1176. __ccdc_enable(ccdc, 0);
  1177. ccdc->stopping = CCDC_STOP_EXECUTED;
  1178. return 1;
  1179. case CCDC_STOP_EXECUTED | CCDC_EVENT_VD0:
  1180. ccdc->stopping |= CCDC_STOP_CCDC_FINISHED;
  1181. if (ccdc->lsc.state == LSC_STATE_STOPPED)
  1182. ccdc->stopping |= CCDC_STOP_LSC_FINISHED;
  1183. rval = 1;
  1184. break;
  1185. case CCDC_STOP_EXECUTED | CCDC_EVENT_LSC_DONE:
  1186. ccdc->stopping |= CCDC_STOP_LSC_FINISHED;
  1187. rval = 1;
  1188. break;
  1189. case CCDC_STOP_EXECUTED | CCDC_EVENT_VD1:
  1190. return 1;
  1191. }
  1192. if (ccdc->stopping == CCDC_STOP_FINISHED) {
  1193. wake_up(&ccdc->wait);
  1194. rval = 1;
  1195. }
  1196. return rval;
  1197. }
  1198. static void ccdc_hs_vs_isr(struct isp_ccdc_device *ccdc)
  1199. {
  1200. struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity);
  1201. struct video_device *vdev = ccdc->subdev.devnode;
  1202. struct v4l2_event event;
  1203. /* Frame number propagation */
  1204. atomic_inc(&pipe->frame_number);
  1205. memset(&event, 0, sizeof(event));
  1206. event.type = V4L2_EVENT_FRAME_SYNC;
  1207. event.u.frame_sync.frame_sequence = atomic_read(&pipe->frame_number);
  1208. v4l2_event_queue(vdev, &event);
  1209. }
  1210. /*
  1211. * ccdc_lsc_isr - Handle LSC events
  1212. * @ccdc: Pointer to ISP CCDC device.
  1213. * @events: LSC events
  1214. */
  1215. static void ccdc_lsc_isr(struct isp_ccdc_device *ccdc, u32 events)
  1216. {
  1217. unsigned long flags;
  1218. if (events & IRQ0STATUS_CCDC_LSC_PREF_ERR_IRQ) {
  1219. struct isp_pipeline *pipe =
  1220. to_isp_pipeline(&ccdc->subdev.entity);
  1221. ccdc_lsc_error_handler(ccdc);
  1222. pipe->error = true;
  1223. dev_dbg(to_device(ccdc), "lsc prefetch error\n");
  1224. }
  1225. if (!(events & IRQ0STATUS_CCDC_LSC_DONE_IRQ))
  1226. return;
  1227. /* LSC_DONE interrupt occur, there are two cases
  1228. * 1. stopping for reconfiguration
  1229. * 2. stopping because of STREAM OFF command
  1230. */
  1231. spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
  1232. if (ccdc->lsc.state == LSC_STATE_STOPPING)
  1233. ccdc->lsc.state = LSC_STATE_STOPPED;
  1234. if (__ccdc_handle_stopping(ccdc, CCDC_EVENT_LSC_DONE))
  1235. goto done;
  1236. if (ccdc->lsc.state != LSC_STATE_RECONFIG)
  1237. goto done;
  1238. /* LSC is in STOPPING state, change to the new state */
  1239. ccdc->lsc.state = LSC_STATE_STOPPED;
  1240. /* This is an exception. Start of frame and LSC_DONE interrupt
  1241. * have been received on the same time. Skip this event and wait
  1242. * for better times.
  1243. */
  1244. if (events & IRQ0STATUS_HS_VS_IRQ)
  1245. goto done;
  1246. /* The LSC engine is stopped at this point. Enable it if there's a
  1247. * pending request.
  1248. */
  1249. if (ccdc->lsc.request == NULL)
  1250. goto done;
  1251. ccdc_lsc_enable(ccdc);
  1252. done:
  1253. spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
  1254. }
  1255. static int ccdc_isr_buffer(struct isp_ccdc_device *ccdc)
  1256. {
  1257. struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity);
  1258. struct isp_device *isp = to_isp_device(ccdc);
  1259. struct isp_buffer *buffer;
  1260. int restart = 0;
  1261. /* The CCDC generates VD0 interrupts even when disabled (the datasheet
  1262. * doesn't explicitly state if that's supposed to happen or not, so it
  1263. * can be considered as a hardware bug or as a feature, but we have to
  1264. * deal with it anyway). Disabling the CCDC when no buffer is available
  1265. * would thus not be enough, we need to handle the situation explicitly.
  1266. */
  1267. if (list_empty(&ccdc->video_out.dmaqueue))
  1268. goto done;
  1269. /* We're in continuous mode, and memory writes were disabled due to a
  1270. * buffer underrun. Reenable them now that we have a buffer. The buffer
  1271. * address has been set in ccdc_video_queue.
  1272. */
  1273. if (ccdc->state == ISP_PIPELINE_STREAM_CONTINUOUS && ccdc->underrun) {
  1274. restart = 1;
  1275. ccdc->underrun = 0;
  1276. goto done;
  1277. }
  1278. if (ccdc_sbl_wait_idle(ccdc, 1000)) {
  1279. dev_info(isp->dev, "CCDC won't become idle!\n");
  1280. goto done;
  1281. }
  1282. buffer = omap3isp_video_buffer_next(&ccdc->video_out);
  1283. if (buffer != NULL) {
  1284. ccdc_set_outaddr(ccdc, buffer->isp_addr);
  1285. restart = 1;
  1286. }
  1287. pipe->state |= ISP_PIPELINE_IDLE_OUTPUT;
  1288. if (ccdc->state == ISP_PIPELINE_STREAM_SINGLESHOT &&
  1289. isp_pipeline_ready(pipe))
  1290. omap3isp_pipeline_set_stream(pipe,
  1291. ISP_PIPELINE_STREAM_SINGLESHOT);
  1292. done:
  1293. return restart;
  1294. }
  1295. /*
  1296. * ccdc_vd0_isr - Handle VD0 event
  1297. * @ccdc: Pointer to ISP CCDC device.
  1298. *
  1299. * Executes LSC deferred enablement before next frame starts.
  1300. */
  1301. static void ccdc_vd0_isr(struct isp_ccdc_device *ccdc)
  1302. {
  1303. unsigned long flags;
  1304. int restart = 0;
  1305. if (ccdc->output & CCDC_OUTPUT_MEMORY)
  1306. restart = ccdc_isr_buffer(ccdc);
  1307. spin_lock_irqsave(&ccdc->lock, flags);
  1308. if (__ccdc_handle_stopping(ccdc, CCDC_EVENT_VD0)) {
  1309. spin_unlock_irqrestore(&ccdc->lock, flags);
  1310. return;
  1311. }
  1312. if (!ccdc->shadow_update)
  1313. ccdc_apply_controls(ccdc);
  1314. spin_unlock_irqrestore(&ccdc->lock, flags);
  1315. if (restart)
  1316. ccdc_enable(ccdc);
  1317. }
  1318. /*
  1319. * ccdc_vd1_isr - Handle VD1 event
  1320. * @ccdc: Pointer to ISP CCDC device.
  1321. */
  1322. static void ccdc_vd1_isr(struct isp_ccdc_device *ccdc)
  1323. {
  1324. unsigned long flags;
  1325. spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
  1326. /*
  1327. * Depending on the CCDC pipeline state, CCDC stopping should be
  1328. * handled differently. In SINGLESHOT we emulate an internal CCDC
  1329. * stopping because the CCDC hw works only in continuous mode.
  1330. * When CONTINUOUS pipeline state is used and the CCDC writes it's
  1331. * data to memory the CCDC and LSC are stopped immediately but
  1332. * without change the CCDC stopping state machine. The CCDC
  1333. * stopping state machine should be used only when user request
  1334. * for stopping is received (SINGLESHOT is an exeption).
  1335. */
  1336. switch (ccdc->state) {
  1337. case ISP_PIPELINE_STREAM_SINGLESHOT:
  1338. ccdc->stopping = CCDC_STOP_REQUEST;
  1339. break;
  1340. case ISP_PIPELINE_STREAM_CONTINUOUS:
  1341. if (ccdc->output & CCDC_OUTPUT_MEMORY) {
  1342. if (ccdc->lsc.state != LSC_STATE_STOPPED)
  1343. __ccdc_lsc_enable(ccdc, 0);
  1344. __ccdc_enable(ccdc, 0);
  1345. }
  1346. break;
  1347. case ISP_PIPELINE_STREAM_STOPPED:
  1348. break;
  1349. }
  1350. if (__ccdc_handle_stopping(ccdc, CCDC_EVENT_VD1))
  1351. goto done;
  1352. if (ccdc->lsc.request == NULL)
  1353. goto done;
  1354. /*
  1355. * LSC need to be reconfigured. Stop it here and on next LSC_DONE IRQ
  1356. * do the appropriate changes in registers
  1357. */
  1358. if (ccdc->lsc.state == LSC_STATE_RUNNING) {
  1359. __ccdc_lsc_enable(ccdc, 0);
  1360. ccdc->lsc.state = LSC_STATE_RECONFIG;
  1361. goto done;
  1362. }
  1363. /* LSC has been in STOPPED state, enable it */
  1364. if (ccdc->lsc.state == LSC_STATE_STOPPED)
  1365. ccdc_lsc_enable(ccdc);
  1366. done:
  1367. spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
  1368. }
  1369. /*
  1370. * omap3isp_ccdc_isr - Configure CCDC during interframe time.
  1371. * @ccdc: Pointer to ISP CCDC device.
  1372. * @events: CCDC events
  1373. */
  1374. int omap3isp_ccdc_isr(struct isp_ccdc_device *ccdc, u32 events)
  1375. {
  1376. if (ccdc->state == ISP_PIPELINE_STREAM_STOPPED)
  1377. return 0;
  1378. if (events & IRQ0STATUS_CCDC_VD1_IRQ)
  1379. ccdc_vd1_isr(ccdc);
  1380. ccdc_lsc_isr(ccdc, events);
  1381. if (events & IRQ0STATUS_CCDC_VD0_IRQ)
  1382. ccdc_vd0_isr(ccdc);
  1383. if (events & IRQ0STATUS_HS_VS_IRQ)
  1384. ccdc_hs_vs_isr(ccdc);
  1385. return 0;
  1386. }
  1387. /* -----------------------------------------------------------------------------
  1388. * ISP video operations
  1389. */
  1390. static int ccdc_video_queue(struct isp_video *video, struct isp_buffer *buffer)
  1391. {
  1392. struct isp_ccdc_device *ccdc = &video->isp->isp_ccdc;
  1393. if (!(ccdc->output & CCDC_OUTPUT_MEMORY))
  1394. return -ENODEV;
  1395. ccdc_set_outaddr(ccdc, buffer->isp_addr);
  1396. /* We now have a buffer queued on the output, restart the pipeline
  1397. * on the next CCDC interrupt if running in continuous mode (or when
  1398. * starting the stream).
  1399. */
  1400. ccdc->underrun = 1;
  1401. return 0;
  1402. }
  1403. static const struct isp_video_operations ccdc_video_ops = {
  1404. .queue = ccdc_video_queue,
  1405. };
  1406. /* -----------------------------------------------------------------------------
  1407. * V4L2 subdev operations
  1408. */
  1409. /*
  1410. * ccdc_ioctl - CCDC module private ioctl's
  1411. * @sd: ISP CCDC V4L2 subdevice
  1412. * @cmd: ioctl command
  1413. * @arg: ioctl argument
  1414. *
  1415. * Return 0 on success or a negative error code otherwise.
  1416. */
  1417. static long ccdc_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
  1418. {
  1419. struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
  1420. int ret;
  1421. switch (cmd) {
  1422. case VIDIOC_OMAP3ISP_CCDC_CFG:
  1423. mutex_lock(&ccdc->ioctl_lock);
  1424. ret = ccdc_config(ccdc, arg);
  1425. mutex_unlock(&ccdc->ioctl_lock);
  1426. break;
  1427. default:
  1428. return -ENOIOCTLCMD;
  1429. }
  1430. return ret;
  1431. }
  1432. static int ccdc_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
  1433. struct v4l2_event_subscription *sub)
  1434. {
  1435. if (sub->type != V4L2_EVENT_FRAME_SYNC)
  1436. return -EINVAL;
  1437. /* line number is zero at frame start */
  1438. if (sub->id != 0)
  1439. return -EINVAL;
  1440. return v4l2_event_subscribe(fh, sub, OMAP3ISP_CCDC_NEVENTS, NULL);
  1441. }
  1442. static int ccdc_unsubscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
  1443. struct v4l2_event_subscription *sub)
  1444. {
  1445. return v4l2_event_unsubscribe(fh, sub);
  1446. }
  1447. /*
  1448. * ccdc_set_stream - Enable/Disable streaming on the CCDC module
  1449. * @sd: ISP CCDC V4L2 subdevice
  1450. * @enable: Enable/disable stream
  1451. *
  1452. * When writing to memory, the CCDC hardware can't be enabled without a memory
  1453. * buffer to write to. As the s_stream operation is called in response to a
  1454. * STREAMON call without any buffer queued yet, just update the enabled field
  1455. * and return immediately. The CCDC will be enabled in ccdc_isr_buffer().
  1456. *
  1457. * When not writing to memory enable the CCDC immediately.
  1458. */
  1459. static int ccdc_set_stream(struct v4l2_subdev *sd, int enable)
  1460. {
  1461. struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
  1462. struct isp_device *isp = to_isp_device(ccdc);
  1463. int ret = 0;
  1464. if (ccdc->state == ISP_PIPELINE_STREAM_STOPPED) {
  1465. if (enable == ISP_PIPELINE_STREAM_STOPPED)
  1466. return 0;
  1467. omap3isp_subclk_enable(isp, OMAP3_ISP_SUBCLK_CCDC);
  1468. isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CFG,
  1469. ISPCCDC_CFG_VDLC);
  1470. ccdc_configure(ccdc);
  1471. /* TODO: Don't configure the video port if all of its output
  1472. * links are inactive.
  1473. */
  1474. ccdc_config_vp(ccdc);
  1475. ccdc_enable_vp(ccdc, 1);
  1476. ccdc_print_status(ccdc);
  1477. }
  1478. switch (enable) {
  1479. case ISP_PIPELINE_STREAM_CONTINUOUS:
  1480. if (ccdc->output & CCDC_OUTPUT_MEMORY)
  1481. omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_CCDC_WRITE);
  1482. if (ccdc->underrun || !(ccdc->output & CCDC_OUTPUT_MEMORY))
  1483. ccdc_enable(ccdc);
  1484. ccdc->underrun = 0;
  1485. break;
  1486. case ISP_PIPELINE_STREAM_SINGLESHOT:
  1487. if (ccdc->output & CCDC_OUTPUT_MEMORY &&
  1488. ccdc->state != ISP_PIPELINE_STREAM_SINGLESHOT)
  1489. omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_CCDC_WRITE);
  1490. ccdc_enable(ccdc);
  1491. break;
  1492. case ISP_PIPELINE_STREAM_STOPPED:
  1493. ret = ccdc_disable(ccdc);
  1494. if (ccdc->output & CCDC_OUTPUT_MEMORY)
  1495. omap3isp_sbl_disable(isp, OMAP3_ISP_SBL_CCDC_WRITE);
  1496. omap3isp_subclk_disable(isp, OMAP3_ISP_SUBCLK_CCDC);
  1497. ccdc->underrun = 0;
  1498. break;
  1499. }
  1500. ccdc->state = enable;
  1501. return ret;
  1502. }
  1503. static struct v4l2_mbus_framefmt *
  1504. __ccdc_get_format(struct isp_ccdc_device *ccdc, struct v4l2_subdev_fh *fh,
  1505. unsigned int pad, enum v4l2_subdev_format_whence which)
  1506. {
  1507. if (which == V4L2_SUBDEV_FORMAT_TRY)
  1508. return v4l2_subdev_get_try_format(fh, pad);
  1509. else
  1510. return &ccdc->formats[pad];
  1511. }
  1512. static struct v4l2_rect *
  1513. __ccdc_get_crop(struct isp_ccdc_device *ccdc, struct v4l2_subdev_fh *fh,
  1514. enum v4l2_subdev_format_whence which)
  1515. {
  1516. if (which == V4L2_SUBDEV_FORMAT_TRY)
  1517. return v4l2_subdev_get_try_crop(fh, CCDC_PAD_SOURCE_OF);
  1518. else
  1519. return &ccdc->crop;
  1520. }
  1521. /*
  1522. * ccdc_try_format - Try video format on a pad
  1523. * @ccdc: ISP CCDC device
  1524. * @fh : V4L2 subdev file handle
  1525. * @pad: Pad number
  1526. * @fmt: Format
  1527. */
  1528. static void
  1529. ccdc_try_format(struct isp_ccdc_device *ccdc, struct v4l2_subdev_fh *fh,
  1530. unsigned int pad, struct v4l2_mbus_framefmt *fmt,
  1531. enum v4l2_subdev_format_whence which)
  1532. {
  1533. struct v4l2_mbus_framefmt *format;
  1534. const struct isp_format_info *info;
  1535. unsigned int width = fmt->width;
  1536. unsigned int height = fmt->height;
  1537. struct v4l2_rect *crop;
  1538. unsigned int i;
  1539. switch (pad) {
  1540. case CCDC_PAD_SINK:
  1541. /* TODO: If the CCDC output formatter pad is connected directly
  1542. * to the resizer, only YUV formats can be used.
  1543. */
  1544. for (i = 0; i < ARRAY_SIZE(ccdc_fmts); i++) {
  1545. if (fmt->code == ccdc_fmts[i])
  1546. break;
  1547. }
  1548. /* If not found, use SGRBG10 as default */
  1549. if (i >= ARRAY_SIZE(ccdc_fmts))
  1550. fmt->code = V4L2_MBUS_FMT_SGRBG10_1X10;
  1551. /* Clamp the input size. */
  1552. fmt->width = clamp_t(u32, width, 32, 4096);
  1553. fmt->height = clamp_t(u32, height, 32, 4096);
  1554. break;
  1555. case CCDC_PAD_SOURCE_OF:
  1556. format = __ccdc_get_format(ccdc, fh, CCDC_PAD_SINK, which);
  1557. memcpy(fmt, format, sizeof(*fmt));
  1558. /* Hardcode the output size to the crop rectangle size. */
  1559. crop = __ccdc_get_crop(ccdc, fh, which);
  1560. fmt->width = crop->width;
  1561. fmt->height = crop->height;
  1562. break;
  1563. case CCDC_PAD_SOURCE_VP:
  1564. format = __ccdc_get_format(ccdc, fh, CCDC_PAD_SINK, which);
  1565. memcpy(fmt, format, sizeof(*fmt));
  1566. /* The video port interface truncates the data to 10 bits. */
  1567. info = omap3isp_video_format_info(fmt->code);
  1568. fmt->code = info->truncated;
  1569. /* The number of lines that can be clocked out from the video
  1570. * port output must be at least one line less than the number
  1571. * of input lines.
  1572. */
  1573. fmt->width = clamp_t(u32, width, 32, fmt->width);
  1574. fmt->height = clamp_t(u32, height, 32, fmt->height - 1);
  1575. break;
  1576. }
  1577. /* Data is written to memory unpacked, each 10-bit or 12-bit pixel is
  1578. * stored on 2 bytes.
  1579. */
  1580. fmt->colorspace = V4L2_COLORSPACE_SRGB;
  1581. fmt->field = V4L2_FIELD_NONE;
  1582. }
  1583. /*
  1584. * ccdc_try_crop - Validate a crop rectangle
  1585. * @ccdc: ISP CCDC device
  1586. * @sink: format on the sink pad
  1587. * @crop: crop rectangle to be validated
  1588. */
  1589. static void ccdc_try_crop(struct isp_ccdc_device *ccdc,
  1590. const struct v4l2_mbus_framefmt *sink,
  1591. struct v4l2_rect *crop)
  1592. {
  1593. const struct isp_format_info *info;
  1594. unsigned int max_width;
  1595. /* For Bayer formats, restrict left/top and width/height to even values
  1596. * to keep the Bayer pattern.
  1597. */
  1598. info = omap3isp_video_format_info(sink->code);
  1599. if (info->flavor != V4L2_MBUS_FMT_Y8_1X8) {
  1600. crop->left &= ~1;
  1601. crop->top &= ~1;
  1602. }
  1603. crop->left = clamp_t(u32, crop->left, 0, sink->width - CCDC_MIN_WIDTH);
  1604. crop->top = clamp_t(u32, crop->top, 0, sink->height - CCDC_MIN_HEIGHT);
  1605. /* The data formatter truncates the number of horizontal output pixels
  1606. * to a multiple of 16. To avoid clipping data, allow callers to request
  1607. * an output size bigger than the input size up to the nearest multiple
  1608. * of 16.
  1609. */
  1610. max_width = (sink->width - crop->left + 15) & ~15;
  1611. crop->width = clamp_t(u32, crop->width, CCDC_MIN_WIDTH, max_width)
  1612. & ~15;
  1613. crop->height = clamp_t(u32, crop->height, CCDC_MIN_HEIGHT,
  1614. sink->height - crop->top);
  1615. /* Odd width/height values don't make sense for Bayer formats. */
  1616. if (info->flavor != V4L2_MBUS_FMT_Y8_1X8) {
  1617. crop->width &= ~1;
  1618. crop->height &= ~1;
  1619. }
  1620. }
  1621. /*
  1622. * ccdc_enum_mbus_code - Handle pixel format enumeration
  1623. * @sd : pointer to v4l2 subdev structure
  1624. * @fh : V4L2 subdev file handle
  1625. * @code : pointer to v4l2_subdev_mbus_code_enum structure
  1626. * return -EINVAL or zero on success
  1627. */
  1628. static int ccdc_enum_mbus_code(struct v4l2_subdev *sd,
  1629. struct v4l2_subdev_fh *fh,
  1630. struct v4l2_subdev_mbus_code_enum *code)
  1631. {
  1632. struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
  1633. struct v4l2_mbus_framefmt *format;
  1634. switch (code->pad) {
  1635. case CCDC_PAD_SINK:
  1636. if (code->index >= ARRAY_SIZE(ccdc_fmts))
  1637. return -EINVAL;
  1638. code->code = ccdc_fmts[code->index];
  1639. break;
  1640. case CCDC_PAD_SOURCE_OF:
  1641. case CCDC_PAD_SOURCE_VP:
  1642. /* No format conversion inside CCDC */
  1643. if (code->index != 0)
  1644. return -EINVAL;
  1645. format = __ccdc_get_format(ccdc, fh, CCDC_PAD_SINK,
  1646. V4L2_SUBDEV_FORMAT_TRY);
  1647. code->code = format->code;
  1648. break;
  1649. default:
  1650. return -EINVAL;
  1651. }
  1652. return 0;
  1653. }
  1654. static int ccdc_enum_frame_size(struct v4l2_subdev *sd,
  1655. struct v4l2_subdev_fh *fh,
  1656. struct v4l2_subdev_frame_size_enum *fse)
  1657. {
  1658. struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
  1659. struct v4l2_mbus_framefmt format;
  1660. if (fse->index != 0)
  1661. return -EINVAL;
  1662. format.code = fse->code;
  1663. format.width = 1;
  1664. format.height = 1;
  1665. ccdc_try_format(ccdc, fh, fse->pad, &format, V4L2_SUBDEV_FORMAT_TRY);
  1666. fse->min_width = format.width;
  1667. fse->min_height = format.height;
  1668. if (format.code != fse->code)
  1669. return -EINVAL;
  1670. format.code = fse->code;
  1671. format.width = -1;
  1672. format.height = -1;
  1673. ccdc_try_format(ccdc, fh, fse->pad, &format, V4L2_SUBDEV_FORMAT_TRY);
  1674. fse->max_width = format.width;
  1675. fse->max_height = format.height;
  1676. return 0;
  1677. }
  1678. /*
  1679. * ccdc_get_selection - Retrieve a selection rectangle on a pad
  1680. * @sd: ISP CCDC V4L2 subdevice
  1681. * @fh: V4L2 subdev file handle
  1682. * @sel: Selection rectangle
  1683. *
  1684. * The only supported rectangles are the crop rectangles on the output formatter
  1685. * source pad.
  1686. *
  1687. * Return 0 on success or a negative error code otherwise.
  1688. */
  1689. static int ccdc_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
  1690. struct v4l2_subdev_selection *sel)
  1691. {
  1692. struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
  1693. struct v4l2_mbus_framefmt *format;
  1694. if (sel->pad != CCDC_PAD_SOURCE_OF)
  1695. return -EINVAL;
  1696. switch (sel->target) {
  1697. case V4L2_SEL_TGT_CROP_BOUNDS:
  1698. sel->r.left = 0;
  1699. sel->r.top = 0;
  1700. sel->r.width = INT_MAX;
  1701. sel->r.height = INT_MAX;
  1702. format = __ccdc_get_format(ccdc, fh, CCDC_PAD_SINK, sel->which);
  1703. ccdc_try_crop(ccdc, format, &sel->r);
  1704. break;
  1705. case V4L2_SEL_TGT_CROP:
  1706. sel->r = *__ccdc_get_crop(ccdc, fh, sel->which);
  1707. break;
  1708. default:
  1709. return -EINVAL;
  1710. }
  1711. return 0;
  1712. }
  1713. /*
  1714. * ccdc_set_selection - Set a selection rectangle on a pad
  1715. * @sd: ISP CCDC V4L2 subdevice
  1716. * @fh: V4L2 subdev file handle
  1717. * @sel: Selection rectangle
  1718. *
  1719. * The only supported rectangle is the actual crop rectangle on the output
  1720. * formatter source pad.
  1721. *
  1722. * Return 0 on success or a negative error code otherwise.
  1723. */
  1724. static int ccdc_set_selection(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
  1725. struct v4l2_subdev_selection *sel)
  1726. {
  1727. struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
  1728. struct v4l2_mbus_framefmt *format;
  1729. if (sel->target != V4L2_SEL_TGT_CROP ||
  1730. sel->pad != CCDC_PAD_SOURCE_OF)
  1731. return -EINVAL;
  1732. /* The crop rectangle can't be changed while streaming. */
  1733. if (ccdc->state != ISP_PIPELINE_STREAM_STOPPED)
  1734. return -EBUSY;
  1735. /* Modifying the crop rectangle always changes the format on the source
  1736. * pad. If the KEEP_CONFIG flag is set, just return the current crop
  1737. * rectangle.
  1738. */
  1739. if (sel->flags & V4L2_SEL_FLAG_KEEP_CONFIG) {
  1740. sel->r = *__ccdc_get_crop(ccdc, fh, sel->which);
  1741. return 0;
  1742. }
  1743. format = __ccdc_get_format(ccdc, fh, CCDC_PAD_SINK, sel->which);
  1744. ccdc_try_crop(ccdc, format, &sel->r);
  1745. *__ccdc_get_crop(ccdc, fh, sel->which) = sel->r;
  1746. /* Update the source format. */
  1747. format = __ccdc_get_format(ccdc, fh, CCDC_PAD_SOURCE_OF, sel->which);
  1748. ccdc_try_format(ccdc, fh, CCDC_PAD_SOURCE_OF, format, sel->which);
  1749. return 0;
  1750. }
  1751. /*
  1752. * ccdc_get_format - Retrieve the video format on a pad
  1753. * @sd : ISP CCDC V4L2 subdevice
  1754. * @fh : V4L2 subdev file handle
  1755. * @fmt: Format
  1756. *
  1757. * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond
  1758. * to the format type.
  1759. */
  1760. static int ccdc_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
  1761. struct v4l2_subdev_format *fmt)
  1762. {
  1763. struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
  1764. struct v4l2_mbus_framefmt *format;
  1765. format = __ccdc_get_format(ccdc, fh, fmt->pad, fmt->which);
  1766. if (format == NULL)
  1767. return -EINVAL;
  1768. fmt->format = *format;
  1769. return 0;
  1770. }
  1771. /*
  1772. * ccdc_set_format - Set the video format on a pad
  1773. * @sd : ISP CCDC V4L2 subdevice
  1774. * @fh : V4L2 subdev file handle
  1775. * @fmt: Format
  1776. *
  1777. * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond
  1778. * to the format type.
  1779. */
  1780. static int ccdc_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
  1781. struct v4l2_subdev_format *fmt)
  1782. {
  1783. struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
  1784. struct v4l2_mbus_framefmt *format;
  1785. struct v4l2_rect *crop;
  1786. format = __ccdc_get_format(ccdc, fh, fmt->pad, fmt->which);
  1787. if (format == NULL)
  1788. return -EINVAL;
  1789. ccdc_try_format(ccdc, fh, fmt->pad, &fmt->format, fmt->which);
  1790. *format = fmt->format;
  1791. /* Propagate the format from sink to source */
  1792. if (fmt->pad == CCDC_PAD_SINK) {
  1793. /* Reset the crop rectangle. */
  1794. crop = __ccdc_get_crop(ccdc, fh, fmt->which);
  1795. crop->left = 0;
  1796. crop->top = 0;
  1797. crop->width = fmt->format.width;
  1798. crop->height = fmt->format.height;
  1799. ccdc_try_crop(ccdc, &fmt->format, crop);
  1800. /* Update the source formats. */
  1801. format = __ccdc_get_format(ccdc, fh, CCDC_PAD_SOURCE_OF,
  1802. fmt->which);
  1803. *format = fmt->format;
  1804. ccdc_try_format(ccdc, fh, CCDC_PAD_SOURCE_OF, format,
  1805. fmt->which);
  1806. format = __ccdc_get_format(ccdc, fh, CCDC_PAD_SOURCE_VP,
  1807. fmt->which);
  1808. *format = fmt->format;
  1809. ccdc_try_format(ccdc, fh, CCDC_PAD_SOURCE_VP, format,
  1810. fmt->which);
  1811. }
  1812. return 0;
  1813. }
  1814. /*
  1815. * Decide whether desired output pixel code can be obtained with
  1816. * the lane shifter by shifting the input pixel code.
  1817. * @in: input pixelcode to shifter
  1818. * @out: output pixelcode from shifter
  1819. * @additional_shift: # of bits the sensor's LSB is offset from CAMEXT[0]
  1820. *
  1821. * return true if the combination is possible
  1822. * return false otherwise
  1823. */
  1824. static bool ccdc_is_shiftable(enum v4l2_mbus_pixelcode in,
  1825. enum v4l2_mbus_pixelcode out,
  1826. unsigned int additional_shift)
  1827. {
  1828. const struct isp_format_info *in_info, *out_info;
  1829. if (in == out)
  1830. return true;
  1831. in_info = omap3isp_video_format_info(in);
  1832. out_info = omap3isp_video_format_info(out);
  1833. if ((in_info->flavor == 0) || (out_info->flavor == 0))
  1834. return false;
  1835. if (in_info->flavor != out_info->flavor)
  1836. return false;
  1837. return in_info->bpp - out_info->bpp + additional_shift <= 6;
  1838. }
  1839. static int ccdc_link_validate(struct v4l2_subdev *sd,
  1840. struct media_link *link,
  1841. struct v4l2_subdev_format *source_fmt,
  1842. struct v4l2_subdev_format *sink_fmt)
  1843. {
  1844. struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
  1845. unsigned long parallel_shift;
  1846. /* Check if the two ends match */
  1847. if (source_fmt->format.width != sink_fmt->format.width ||
  1848. source_fmt->format.height != sink_fmt->format.height)
  1849. return -EPIPE;
  1850. /* We've got a parallel sensor here. */
  1851. if (ccdc->input == CCDC_INPUT_PARALLEL) {
  1852. struct isp_parallel_platform_data *pdata =
  1853. &((struct isp_v4l2_subdevs_group *)
  1854. media_entity_to_v4l2_subdev(link->source->entity)
  1855. ->host_priv)->bus.parallel;
  1856. parallel_shift = pdata->data_lane_shift * 2;
  1857. } else {
  1858. parallel_shift = 0;
  1859. }
  1860. /* Lane shifter may be used to drop bits on CCDC sink pad */
  1861. if (!ccdc_is_shiftable(source_fmt->format.code,
  1862. sink_fmt->format.code, parallel_shift))
  1863. return -EPIPE;
  1864. return 0;
  1865. }
  1866. /*
  1867. * ccdc_init_formats - Initialize formats on all pads
  1868. * @sd: ISP CCDC V4L2 subdevice
  1869. * @fh: V4L2 subdev file handle
  1870. *
  1871. * Initialize all pad formats with default values. If fh is not NULL, try
  1872. * formats are initialized on the file handle. Otherwise active formats are
  1873. * initialized on the device.
  1874. */
  1875. static int ccdc_init_formats(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
  1876. {
  1877. struct v4l2_subdev_format format;
  1878. memset(&format, 0, sizeof(format));
  1879. format.pad = CCDC_PAD_SINK;
  1880. format.which = fh ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
  1881. format.format.code = V4L2_MBUS_FMT_SGRBG10_1X10;
  1882. format.format.width = 4096;
  1883. format.format.height = 4096;
  1884. ccdc_set_format(sd, fh, &format);
  1885. return 0;
  1886. }
  1887. /* V4L2 subdev core operations */
  1888. static const struct v4l2_subdev_core_ops ccdc_v4l2_core_ops = {
  1889. .ioctl = ccdc_ioctl,
  1890. .subscribe_event = ccdc_subscribe_event,
  1891. .unsubscribe_event = ccdc_unsubscribe_event,
  1892. };
  1893. /* V4L2 subdev video operations */
  1894. static const struct v4l2_subdev_video_ops ccdc_v4l2_video_ops = {
  1895. .s_stream = ccdc_set_stream,
  1896. };
  1897. /* V4L2 subdev pad operations */
  1898. static const struct v4l2_subdev_pad_ops ccdc_v4l2_pad_ops = {
  1899. .enum_mbus_code = ccdc_enum_mbus_code,
  1900. .enum_frame_size = ccdc_enum_frame_size,
  1901. .get_fmt = ccdc_get_format,
  1902. .set_fmt = ccdc_set_format,
  1903. .get_selection = ccdc_get_selection,
  1904. .set_selection = ccdc_set_selection,
  1905. .link_validate = ccdc_link_validate,
  1906. };
  1907. /* V4L2 subdev operations */
  1908. static const struct v4l2_subdev_ops ccdc_v4l2_ops = {
  1909. .core = &ccdc_v4l2_core_ops,
  1910. .video = &ccdc_v4l2_video_ops,
  1911. .pad = &ccdc_v4l2_pad_ops,
  1912. };
  1913. /* V4L2 subdev internal operations */
  1914. static const struct v4l2_subdev_internal_ops ccdc_v4l2_internal_ops = {
  1915. .open = ccdc_init_formats,
  1916. };
  1917. /* -----------------------------------------------------------------------------
  1918. * Media entity operations
  1919. */
  1920. /*
  1921. * ccdc_link_setup - Setup CCDC connections
  1922. * @entity: CCDC media entity
  1923. * @local: Pad at the local end of the link
  1924. * @remote: Pad at the remote end of the link
  1925. * @flags: Link flags
  1926. *
  1927. * return -EINVAL or zero on success
  1928. */
  1929. static int ccdc_link_setup(struct media_entity *entity,
  1930. const struct media_pad *local,
  1931. const struct media_pad *remote, u32 flags)
  1932. {
  1933. struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
  1934. struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
  1935. struct isp_device *isp = to_isp_device(ccdc);
  1936. switch (local->index | media_entity_type(remote->entity)) {
  1937. case CCDC_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
  1938. /* Read from the sensor (parallel interface), CCP2, CSI2a or
  1939. * CSI2c.
  1940. */
  1941. if (!(flags & MEDIA_LNK_FL_ENABLED)) {
  1942. ccdc->input = CCDC_INPUT_NONE;
  1943. break;
  1944. }
  1945. if (ccdc->input != CCDC_INPUT_NONE)
  1946. return -EBUSY;
  1947. if (remote->entity == &isp->isp_ccp2.subdev.entity)
  1948. ccdc->input = CCDC_INPUT_CCP2B;
  1949. else if (remote->entity == &isp->isp_csi2a.subdev.entity)
  1950. ccdc->input = CCDC_INPUT_CSI2A;
  1951. else if (remote->entity == &isp->isp_csi2c.subdev.entity)
  1952. ccdc->input = CCDC_INPUT_CSI2C;
  1953. else
  1954. ccdc->input = CCDC_INPUT_PARALLEL;
  1955. break;
  1956. /*
  1957. * The ISP core doesn't support pipelines with multiple video outputs.
  1958. * Revisit this when it will be implemented, and return -EBUSY for now.
  1959. */
  1960. case CCDC_PAD_SOURCE_VP | MEDIA_ENT_T_V4L2_SUBDEV:
  1961. /* Write to preview engine, histogram and H3A. When none of
  1962. * those links are active, the video port can be disabled.
  1963. */
  1964. if (flags & MEDIA_LNK_FL_ENABLED) {
  1965. if (ccdc->output & ~CCDC_OUTPUT_PREVIEW)
  1966. return -EBUSY;
  1967. ccdc->output |= CCDC_OUTPUT_PREVIEW;
  1968. } else {
  1969. ccdc->output &= ~CCDC_OUTPUT_PREVIEW;
  1970. }
  1971. break;
  1972. case CCDC_PAD_SOURCE_OF | MEDIA_ENT_T_DEVNODE:
  1973. /* Write to memory */
  1974. if (flags & MEDIA_LNK_FL_ENABLED) {
  1975. if (ccdc->output & ~CCDC_OUTPUT_MEMORY)
  1976. return -EBUSY;
  1977. ccdc->output |= CCDC_OUTPUT_MEMORY;
  1978. } else {
  1979. ccdc->output &= ~CCDC_OUTPUT_MEMORY;
  1980. }
  1981. break;
  1982. case CCDC_PAD_SOURCE_OF | MEDIA_ENT_T_V4L2_SUBDEV:
  1983. /* Write to resizer */
  1984. if (flags & MEDIA_LNK_FL_ENABLED) {
  1985. if (ccdc->output & ~CCDC_OUTPUT_RESIZER)
  1986. return -EBUSY;
  1987. ccdc->output |= CCDC_OUTPUT_RESIZER;
  1988. } else {
  1989. ccdc->output &= ~CCDC_OUTPUT_RESIZER;
  1990. }
  1991. break;
  1992. default:
  1993. return -EINVAL;
  1994. }
  1995. return 0;
  1996. }
  1997. /* media operations */
  1998. static const struct media_entity_operations ccdc_media_ops = {
  1999. .link_setup = ccdc_link_setup,
  2000. .link_validate = v4l2_subdev_link_validate,
  2001. };
  2002. void omap3isp_ccdc_unregister_entities(struct isp_ccdc_device *ccdc)
  2003. {
  2004. v4l2_device_unregister_subdev(&ccdc->subdev);
  2005. omap3isp_video_unregister(&ccdc->video_out);
  2006. }
  2007. int omap3isp_ccdc_register_entities(struct isp_ccdc_device *ccdc,
  2008. struct v4l2_device *vdev)
  2009. {
  2010. int ret;
  2011. /* Register the subdev and video node. */
  2012. ret = v4l2_device_register_subdev(vdev, &ccdc->subdev);
  2013. if (ret < 0)
  2014. goto error;
  2015. ret = omap3isp_video_register(&ccdc->video_out, vdev);
  2016. if (ret < 0)
  2017. goto error;
  2018. return 0;
  2019. error:
  2020. omap3isp_ccdc_unregister_entities(ccdc);
  2021. return ret;
  2022. }
  2023. /* -----------------------------------------------------------------------------
  2024. * ISP CCDC initialisation and cleanup
  2025. */
  2026. /*
  2027. * ccdc_init_entities - Initialize V4L2 subdev and media entity
  2028. * @ccdc: ISP CCDC module
  2029. *
  2030. * Return 0 on success and a negative error code on failure.
  2031. */
  2032. static int ccdc_init_entities(struct isp_ccdc_device *ccdc)
  2033. {
  2034. struct v4l2_subdev *sd = &ccdc->subdev;
  2035. struct media_pad *pads = ccdc->pads;
  2036. struct media_entity *me = &sd->entity;
  2037. int ret;
  2038. ccdc->input = CCDC_INPUT_NONE;
  2039. v4l2_subdev_init(sd, &ccdc_v4l2_ops);
  2040. sd->internal_ops = &ccdc_v4l2_internal_ops;
  2041. strlcpy(sd->name, "OMAP3 ISP CCDC", sizeof(sd->name));
  2042. sd->grp_id = 1 << 16; /* group ID for isp subdevs */
  2043. v4l2_set_subdevdata(sd, ccdc);
  2044. sd->flags |= V4L2_SUBDEV_FL_HAS_EVENTS | V4L2_SUBDEV_FL_HAS_DEVNODE;
  2045. pads[CCDC_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
  2046. pads[CCDC_PAD_SOURCE_VP].flags = MEDIA_PAD_FL_SOURCE;
  2047. pads[CCDC_PAD_SOURCE_OF].flags = MEDIA_PAD_FL_SOURCE;
  2048. me->ops = &ccdc_media_ops;
  2049. ret = media_entity_init(me, CCDC_PADS_NUM, pads, 0);
  2050. if (ret < 0)
  2051. return ret;
  2052. ccdc_init_formats(sd, NULL);
  2053. ccdc->video_out.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  2054. ccdc->video_out.ops = &ccdc_video_ops;
  2055. ccdc->video_out.isp = to_isp_device(ccdc);
  2056. ccdc->video_out.capture_mem = PAGE_ALIGN(4096 * 4096) * 3;
  2057. ccdc->video_out.bpl_alignment = 32;
  2058. ret = omap3isp_video_init(&ccdc->video_out, "CCDC");
  2059. if (ret < 0)
  2060. goto error_video;
  2061. /* Connect the CCDC subdev to the video node. */
  2062. ret = media_entity_create_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
  2063. &ccdc->video_out.video.entity, 0, 0);
  2064. if (ret < 0)
  2065. goto error_link;
  2066. return 0;
  2067. error_link:
  2068. omap3isp_video_cleanup(&ccdc->video_out);
  2069. error_video:
  2070. media_entity_cleanup(me);
  2071. return ret;
  2072. }
  2073. /*
  2074. * omap3isp_ccdc_init - CCDC module initialization.
  2075. * @dev: Device pointer specific to the OMAP3 ISP.
  2076. *
  2077. * TODO: Get the initialisation values from platform data.
  2078. *
  2079. * Return 0 on success or a negative error code otherwise.
  2080. */
  2081. int omap3isp_ccdc_init(struct isp_device *isp)
  2082. {
  2083. struct isp_ccdc_device *ccdc = &isp->isp_ccdc;
  2084. int ret;
  2085. spin_lock_init(&ccdc->lock);
  2086. init_waitqueue_head(&ccdc->wait);
  2087. mutex_init(&ccdc->ioctl_lock);
  2088. ccdc->stopping = CCDC_STOP_NOT_REQUESTED;
  2089. INIT_WORK(&ccdc->lsc.table_work, ccdc_lsc_free_table_work);
  2090. ccdc->lsc.state = LSC_STATE_STOPPED;
  2091. INIT_LIST_HEAD(&ccdc->lsc.free_queue);
  2092. spin_lock_init(&ccdc->lsc.req_lock);
  2093. ccdc->syncif.ccdc_mastermode = 0;
  2094. ccdc->syncif.datapol = 0;
  2095. ccdc->syncif.datsz = 0;
  2096. ccdc->syncif.fldmode = 0;
  2097. ccdc->syncif.fldout = 0;
  2098. ccdc->syncif.fldpol = 0;
  2099. ccdc->syncif.fldstat = 0;
  2100. ccdc->clamp.oblen = 0;
  2101. ccdc->clamp.dcsubval = 0;
  2102. ccdc->update = OMAP3ISP_CCDC_BLCLAMP;
  2103. ccdc_apply_controls(ccdc);
  2104. ret = ccdc_init_entities(ccdc);
  2105. if (ret < 0) {
  2106. mutex_destroy(&ccdc->ioctl_lock);
  2107. return ret;
  2108. }
  2109. return 0;
  2110. }
  2111. /*
  2112. * omap3isp_ccdc_cleanup - CCDC module cleanup.
  2113. * @dev: Device pointer specific to the OMAP3 ISP.
  2114. */
  2115. void omap3isp_ccdc_cleanup(struct isp_device *isp)
  2116. {
  2117. struct isp_ccdc_device *ccdc = &isp->isp_ccdc;
  2118. omap3isp_video_cleanup(&ccdc->video_out);
  2119. media_entity_cleanup(&ccdc->subdev.entity);
  2120. /* Free LSC requests. As the CCDC is stopped there's no active request,
  2121. * so only the pending request and the free queue need to be handled.
  2122. */
  2123. ccdc_lsc_free_request(ccdc, ccdc->lsc.request);
  2124. cancel_work_sync(&ccdc->lsc.table_work);
  2125. ccdc_lsc_free_queue(ccdc, &ccdc->lsc.free_queue);
  2126. if (ccdc->fpc.fpcaddr != 0)
  2127. omap_iommu_vfree(isp->domain, isp->dev, ccdc->fpc.fpcaddr);
  2128. mutex_destroy(&ccdc->ioctl_lock);
  2129. }