isp.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255
  1. /*
  2. * isp.c
  3. *
  4. * TI OMAP3 ISP - Core
  5. *
  6. * Copyright (C) 2006-2010 Nokia Corporation
  7. * Copyright (C) 2007-2009 Texas Instruments, Inc.
  8. *
  9. * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  10. * Sakari Ailus <sakari.ailus@iki.fi>
  11. *
  12. * Contributors:
  13. * Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  14. * Sakari Ailus <sakari.ailus@iki.fi>
  15. * David Cohen <dacohen@gmail.com>
  16. * Stanimir Varbanov <svarbanov@mm-sol.com>
  17. * Vimarsh Zutshi <vimarsh.zutshi@gmail.com>
  18. * Tuukka Toivonen <tuukkat76@gmail.com>
  19. * Sergio Aguirre <saaguirre@ti.com>
  20. * Antti Koskipaa <akoskipa@gmail.com>
  21. * Ivan T. Ivanov <iivanov@mm-sol.com>
  22. * RaniSuneela <r-m@ti.com>
  23. * Atanas Filipov <afilipov@mm-sol.com>
  24. * Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
  25. * Hiroshi DOYU <hiroshi.doyu@nokia.com>
  26. * Nayden Kanchev <nkanchev@mm-sol.com>
  27. * Phil Carmody <ext-phil.2.carmody@nokia.com>
  28. * Artem Bityutskiy <artem.bityutskiy@nokia.com>
  29. * Dominic Curran <dcurran@ti.com>
  30. * Ilkka Myllyperkio <ilkka.myllyperkio@sofica.fi>
  31. * Pallavi Kulkarni <p-kulkarni@ti.com>
  32. * Vaibhav Hiremath <hvaibhav@ti.com>
  33. * Mohit Jalori <mjalori@ti.com>
  34. * Sameer Venkatraman <sameerv@ti.com>
  35. * Senthilvadivu Guruswamy <svadivu@ti.com>
  36. * Thara Gopinath <thara@ti.com>
  37. * Toni Leinonen <toni.leinonen@nokia.com>
  38. * Troy Laramy <t-laramy@ti.com>
  39. *
  40. * This program is free software; you can redistribute it and/or modify
  41. * it under the terms of the GNU General Public License version 2 as
  42. * published by the Free Software Foundation.
  43. *
  44. * This program is distributed in the hope that it will be useful, but
  45. * WITHOUT ANY WARRANTY; without even the implied warranty of
  46. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  47. * General Public License for more details.
  48. *
  49. * You should have received a copy of the GNU General Public License
  50. * along with this program; if not, write to the Free Software
  51. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  52. * 02110-1301 USA
  53. */
  54. #include <asm/cacheflush.h>
  55. #include <linux/clk.h>
  56. #include <linux/delay.h>
  57. #include <linux/device.h>
  58. #include <linux/dma-mapping.h>
  59. #include <linux/i2c.h>
  60. #include <linux/interrupt.h>
  61. #include <linux/module.h>
  62. #include <linux/platform_device.h>
  63. #include <linux/regulator/consumer.h>
  64. #include <linux/slab.h>
  65. #include <linux/sched.h>
  66. #include <linux/vmalloc.h>
  67. #include <media/v4l2-common.h>
  68. #include <media/v4l2-device.h>
  69. #include "isp.h"
  70. #include "ispreg.h"
  71. #include "ispccdc.h"
  72. #include "isppreview.h"
  73. #include "ispresizer.h"
  74. #include "ispcsi2.h"
  75. #include "ispccp2.h"
  76. #include "isph3a.h"
  77. #include "isphist.h"
  78. /*
  79. * this is provided as an interim solution until omap3isp doesn't need
  80. * any omap-specific iommu API
  81. */
  82. #define to_iommu(dev) \
  83. (struct omap_iommu *)platform_get_drvdata(to_platform_device(dev))
  84. static unsigned int autoidle;
  85. module_param(autoidle, int, 0444);
  86. MODULE_PARM_DESC(autoidle, "Enable OMAP3ISP AUTOIDLE support");
  87. static void isp_save_ctx(struct isp_device *isp);
  88. static void isp_restore_ctx(struct isp_device *isp);
  89. static const struct isp_res_mapping isp_res_maps[] = {
  90. {
  91. .isp_rev = ISP_REVISION_2_0,
  92. .map = 1 << OMAP3_ISP_IOMEM_MAIN |
  93. 1 << OMAP3_ISP_IOMEM_CCP2 |
  94. 1 << OMAP3_ISP_IOMEM_CCDC |
  95. 1 << OMAP3_ISP_IOMEM_HIST |
  96. 1 << OMAP3_ISP_IOMEM_H3A |
  97. 1 << OMAP3_ISP_IOMEM_PREV |
  98. 1 << OMAP3_ISP_IOMEM_RESZ |
  99. 1 << OMAP3_ISP_IOMEM_SBL |
  100. 1 << OMAP3_ISP_IOMEM_CSI2A_REGS1 |
  101. 1 << OMAP3_ISP_IOMEM_CSIPHY2,
  102. },
  103. {
  104. .isp_rev = ISP_REVISION_15_0,
  105. .map = 1 << OMAP3_ISP_IOMEM_MAIN |
  106. 1 << OMAP3_ISP_IOMEM_CCP2 |
  107. 1 << OMAP3_ISP_IOMEM_CCDC |
  108. 1 << OMAP3_ISP_IOMEM_HIST |
  109. 1 << OMAP3_ISP_IOMEM_H3A |
  110. 1 << OMAP3_ISP_IOMEM_PREV |
  111. 1 << OMAP3_ISP_IOMEM_RESZ |
  112. 1 << OMAP3_ISP_IOMEM_SBL |
  113. 1 << OMAP3_ISP_IOMEM_CSI2A_REGS1 |
  114. 1 << OMAP3_ISP_IOMEM_CSIPHY2 |
  115. 1 << OMAP3_ISP_IOMEM_CSI2A_REGS2 |
  116. 1 << OMAP3_ISP_IOMEM_CSI2C_REGS1 |
  117. 1 << OMAP3_ISP_IOMEM_CSIPHY1 |
  118. 1 << OMAP3_ISP_IOMEM_CSI2C_REGS2,
  119. },
  120. };
  121. /* Structure for saving/restoring ISP module registers */
  122. static struct isp_reg isp_reg_list[] = {
  123. {OMAP3_ISP_IOMEM_MAIN, ISP_SYSCONFIG, 0},
  124. {OMAP3_ISP_IOMEM_MAIN, ISP_CTRL, 0},
  125. {OMAP3_ISP_IOMEM_MAIN, ISP_TCTRL_CTRL, 0},
  126. {0, ISP_TOK_TERM, 0}
  127. };
  128. /*
  129. * omap3isp_flush - Post pending L3 bus writes by doing a register readback
  130. * @isp: OMAP3 ISP device
  131. *
  132. * In order to force posting of pending writes, we need to write and
  133. * readback the same register, in this case the revision register.
  134. *
  135. * See this link for reference:
  136. * http://www.mail-archive.com/linux-omap@vger.kernel.org/msg08149.html
  137. */
  138. void omap3isp_flush(struct isp_device *isp)
  139. {
  140. isp_reg_writel(isp, 0, OMAP3_ISP_IOMEM_MAIN, ISP_REVISION);
  141. isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_REVISION);
  142. }
  143. /*
  144. * isp_enable_interrupts - Enable ISP interrupts.
  145. * @isp: OMAP3 ISP device
  146. */
  147. static void isp_enable_interrupts(struct isp_device *isp)
  148. {
  149. static const u32 irq = IRQ0ENABLE_CSIA_IRQ
  150. | IRQ0ENABLE_CSIB_IRQ
  151. | IRQ0ENABLE_CCDC_LSC_PREF_ERR_IRQ
  152. | IRQ0ENABLE_CCDC_LSC_DONE_IRQ
  153. | IRQ0ENABLE_CCDC_VD0_IRQ
  154. | IRQ0ENABLE_CCDC_VD1_IRQ
  155. | IRQ0ENABLE_HS_VS_IRQ
  156. | IRQ0ENABLE_HIST_DONE_IRQ
  157. | IRQ0ENABLE_H3A_AWB_DONE_IRQ
  158. | IRQ0ENABLE_H3A_AF_DONE_IRQ
  159. | IRQ0ENABLE_PRV_DONE_IRQ
  160. | IRQ0ENABLE_RSZ_DONE_IRQ;
  161. isp_reg_writel(isp, irq, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
  162. isp_reg_writel(isp, irq, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0ENABLE);
  163. }
  164. /*
  165. * isp_disable_interrupts - Disable ISP interrupts.
  166. * @isp: OMAP3 ISP device
  167. */
  168. static void isp_disable_interrupts(struct isp_device *isp)
  169. {
  170. isp_reg_writel(isp, 0, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0ENABLE);
  171. }
  172. /**
  173. * isp_set_xclk - Configures the specified cam_xclk to the desired frequency.
  174. * @isp: OMAP3 ISP device
  175. * @xclk: Desired frequency of the clock in Hz. 0 = stable low, 1 is stable high
  176. * @xclksel: XCLK to configure (0 = A, 1 = B).
  177. *
  178. * Configures the specified MCLK divisor in the ISP timing control register
  179. * (TCTRL_CTRL) to generate the desired xclk clock value.
  180. *
  181. * Divisor = cam_mclk_hz / xclk
  182. *
  183. * Returns the final frequency that is actually being generated
  184. **/
  185. static u32 isp_set_xclk(struct isp_device *isp, u32 xclk, u8 xclksel)
  186. {
  187. u32 divisor;
  188. u32 currentxclk;
  189. unsigned long mclk_hz;
  190. if (!omap3isp_get(isp))
  191. return 0;
  192. mclk_hz = clk_get_rate(isp->clock[ISP_CLK_CAM_MCLK]);
  193. if (xclk >= mclk_hz) {
  194. divisor = ISPTCTRL_CTRL_DIV_BYPASS;
  195. currentxclk = mclk_hz;
  196. } else if (xclk >= 2) {
  197. divisor = mclk_hz / xclk;
  198. if (divisor >= ISPTCTRL_CTRL_DIV_BYPASS)
  199. divisor = ISPTCTRL_CTRL_DIV_BYPASS - 1;
  200. currentxclk = mclk_hz / divisor;
  201. } else {
  202. divisor = xclk;
  203. currentxclk = 0;
  204. }
  205. switch (xclksel) {
  206. case ISP_XCLK_A:
  207. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_MAIN, ISP_TCTRL_CTRL,
  208. ISPTCTRL_CTRL_DIVA_MASK,
  209. divisor << ISPTCTRL_CTRL_DIVA_SHIFT);
  210. dev_dbg(isp->dev, "isp_set_xclk(): cam_xclka set to %d Hz\n",
  211. currentxclk);
  212. break;
  213. case ISP_XCLK_B:
  214. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_MAIN, ISP_TCTRL_CTRL,
  215. ISPTCTRL_CTRL_DIVB_MASK,
  216. divisor << ISPTCTRL_CTRL_DIVB_SHIFT);
  217. dev_dbg(isp->dev, "isp_set_xclk(): cam_xclkb set to %d Hz\n",
  218. currentxclk);
  219. break;
  220. case ISP_XCLK_NONE:
  221. default:
  222. omap3isp_put(isp);
  223. dev_dbg(isp->dev, "ISP_ERR: isp_set_xclk(): Invalid requested "
  224. "xclk. Must be 0 (A) or 1 (B).\n");
  225. return -EINVAL;
  226. }
  227. /* Do we go from stable whatever to clock? */
  228. if (divisor >= 2 && isp->xclk_divisor[xclksel - 1] < 2)
  229. omap3isp_get(isp);
  230. /* Stopping the clock. */
  231. else if (divisor < 2 && isp->xclk_divisor[xclksel - 1] >= 2)
  232. omap3isp_put(isp);
  233. isp->xclk_divisor[xclksel - 1] = divisor;
  234. omap3isp_put(isp);
  235. return currentxclk;
  236. }
  237. /*
  238. * isp_power_settings - Sysconfig settings, for Power Management.
  239. * @isp: OMAP3 ISP device
  240. * @idle: Consider idle state.
  241. *
  242. * Sets the power settings for the ISP, and SBL bus.
  243. */
  244. static void isp_power_settings(struct isp_device *isp, int idle)
  245. {
  246. isp_reg_writel(isp,
  247. ((idle ? ISP_SYSCONFIG_MIDLEMODE_SMARTSTANDBY :
  248. ISP_SYSCONFIG_MIDLEMODE_FORCESTANDBY) <<
  249. ISP_SYSCONFIG_MIDLEMODE_SHIFT) |
  250. ((isp->revision == ISP_REVISION_15_0) ?
  251. ISP_SYSCONFIG_AUTOIDLE : 0),
  252. OMAP3_ISP_IOMEM_MAIN, ISP_SYSCONFIG);
  253. if (isp->autoidle)
  254. isp_reg_writel(isp, ISPCTRL_SBL_AUTOIDLE, OMAP3_ISP_IOMEM_MAIN,
  255. ISP_CTRL);
  256. }
  257. /*
  258. * Configure the bridge and lane shifter. Valid inputs are
  259. *
  260. * CCDC_INPUT_PARALLEL: Parallel interface
  261. * CCDC_INPUT_CSI2A: CSI2a receiver
  262. * CCDC_INPUT_CCP2B: CCP2b receiver
  263. * CCDC_INPUT_CSI2C: CSI2c receiver
  264. *
  265. * The bridge and lane shifter are configured according to the selected input
  266. * and the ISP platform data.
  267. */
  268. void omap3isp_configure_bridge(struct isp_device *isp,
  269. enum ccdc_input_entity input,
  270. const struct isp_parallel_platform_data *pdata,
  271. unsigned int shift)
  272. {
  273. u32 ispctrl_val;
  274. ispctrl_val = isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL);
  275. ispctrl_val &= ~ISPCTRL_SHIFT_MASK;
  276. ispctrl_val &= ~ISPCTRL_PAR_CLK_POL_INV;
  277. ispctrl_val &= ~ISPCTRL_PAR_SER_CLK_SEL_MASK;
  278. ispctrl_val &= ~ISPCTRL_PAR_BRIDGE_MASK;
  279. switch (input) {
  280. case CCDC_INPUT_PARALLEL:
  281. ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_PARALLEL;
  282. ispctrl_val |= pdata->clk_pol << ISPCTRL_PAR_CLK_POL_SHIFT;
  283. ispctrl_val |= pdata->bridge << ISPCTRL_PAR_BRIDGE_SHIFT;
  284. shift += pdata->data_lane_shift * 2;
  285. break;
  286. case CCDC_INPUT_CSI2A:
  287. ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_CSIA;
  288. break;
  289. case CCDC_INPUT_CCP2B:
  290. ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_CSIB;
  291. break;
  292. case CCDC_INPUT_CSI2C:
  293. ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_CSIC;
  294. break;
  295. default:
  296. return;
  297. }
  298. ispctrl_val |= ((shift/2) << ISPCTRL_SHIFT_SHIFT) & ISPCTRL_SHIFT_MASK;
  299. ispctrl_val &= ~ISPCTRL_SYNC_DETECT_MASK;
  300. ispctrl_val |= ISPCTRL_SYNC_DETECT_VSRISE;
  301. isp_reg_writel(isp, ispctrl_val, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL);
  302. }
  303. /**
  304. * isp_set_pixel_clock - Configures the ISP pixel clock
  305. * @isp: OMAP3 ISP device
  306. * @pixelclk: Average pixel clock in Hz
  307. *
  308. * Set the average pixel clock required by the sensor. The ISP will use the
  309. * lowest possible memory bandwidth settings compatible with the clock.
  310. **/
  311. static void isp_set_pixel_clock(struct isp_device *isp, unsigned int pixelclk)
  312. {
  313. isp->isp_ccdc.vpcfg.pixelclk = pixelclk;
  314. }
  315. void omap3isp_hist_dma_done(struct isp_device *isp)
  316. {
  317. if (omap3isp_ccdc_busy(&isp->isp_ccdc) ||
  318. omap3isp_stat_pcr_busy(&isp->isp_hist)) {
  319. /* Histogram cannot be enabled in this frame anymore */
  320. atomic_set(&isp->isp_hist.buf_err, 1);
  321. dev_dbg(isp->dev, "hist: Out of synchronization with "
  322. "CCDC. Ignoring next buffer.\n");
  323. }
  324. }
  325. static inline void isp_isr_dbg(struct isp_device *isp, u32 irqstatus)
  326. {
  327. static const char *name[] = {
  328. "CSIA_IRQ",
  329. "res1",
  330. "res2",
  331. "CSIB_LCM_IRQ",
  332. "CSIB_IRQ",
  333. "res5",
  334. "res6",
  335. "res7",
  336. "CCDC_VD0_IRQ",
  337. "CCDC_VD1_IRQ",
  338. "CCDC_VD2_IRQ",
  339. "CCDC_ERR_IRQ",
  340. "H3A_AF_DONE_IRQ",
  341. "H3A_AWB_DONE_IRQ",
  342. "res14",
  343. "res15",
  344. "HIST_DONE_IRQ",
  345. "CCDC_LSC_DONE",
  346. "CCDC_LSC_PREFETCH_COMPLETED",
  347. "CCDC_LSC_PREFETCH_ERROR",
  348. "PRV_DONE_IRQ",
  349. "CBUFF_IRQ",
  350. "res22",
  351. "res23",
  352. "RSZ_DONE_IRQ",
  353. "OVF_IRQ",
  354. "res26",
  355. "res27",
  356. "MMU_ERR_IRQ",
  357. "OCP_ERR_IRQ",
  358. "SEC_ERR_IRQ",
  359. "HS_VS_IRQ",
  360. };
  361. int i;
  362. dev_dbg(isp->dev, "ISP IRQ: ");
  363. for (i = 0; i < ARRAY_SIZE(name); i++) {
  364. if ((1 << i) & irqstatus)
  365. printk(KERN_CONT "%s ", name[i]);
  366. }
  367. printk(KERN_CONT "\n");
  368. }
  369. static void isp_isr_sbl(struct isp_device *isp)
  370. {
  371. struct device *dev = isp->dev;
  372. struct isp_pipeline *pipe;
  373. u32 sbl_pcr;
  374. /*
  375. * Handle shared buffer logic overflows for video buffers.
  376. * ISPSBL_PCR_CCDCPRV_2_RSZ_OVF can be safely ignored.
  377. */
  378. sbl_pcr = isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_PCR);
  379. isp_reg_writel(isp, sbl_pcr, OMAP3_ISP_IOMEM_SBL, ISPSBL_PCR);
  380. sbl_pcr &= ~ISPSBL_PCR_CCDCPRV_2_RSZ_OVF;
  381. if (sbl_pcr)
  382. dev_dbg(dev, "SBL overflow (PCR = 0x%08x)\n", sbl_pcr);
  383. if (sbl_pcr & ISPSBL_PCR_CSIB_WBL_OVF) {
  384. pipe = to_isp_pipeline(&isp->isp_ccp2.subdev.entity);
  385. if (pipe != NULL)
  386. pipe->error = true;
  387. }
  388. if (sbl_pcr & ISPSBL_PCR_CSIA_WBL_OVF) {
  389. pipe = to_isp_pipeline(&isp->isp_csi2a.subdev.entity);
  390. if (pipe != NULL)
  391. pipe->error = true;
  392. }
  393. if (sbl_pcr & ISPSBL_PCR_CCDC_WBL_OVF) {
  394. pipe = to_isp_pipeline(&isp->isp_ccdc.subdev.entity);
  395. if (pipe != NULL)
  396. pipe->error = true;
  397. }
  398. if (sbl_pcr & ISPSBL_PCR_PRV_WBL_OVF) {
  399. pipe = to_isp_pipeline(&isp->isp_prev.subdev.entity);
  400. if (pipe != NULL)
  401. pipe->error = true;
  402. }
  403. if (sbl_pcr & (ISPSBL_PCR_RSZ1_WBL_OVF
  404. | ISPSBL_PCR_RSZ2_WBL_OVF
  405. | ISPSBL_PCR_RSZ3_WBL_OVF
  406. | ISPSBL_PCR_RSZ4_WBL_OVF)) {
  407. pipe = to_isp_pipeline(&isp->isp_res.subdev.entity);
  408. if (pipe != NULL)
  409. pipe->error = true;
  410. }
  411. if (sbl_pcr & ISPSBL_PCR_H3A_AF_WBL_OVF)
  412. omap3isp_stat_sbl_overflow(&isp->isp_af);
  413. if (sbl_pcr & ISPSBL_PCR_H3A_AEAWB_WBL_OVF)
  414. omap3isp_stat_sbl_overflow(&isp->isp_aewb);
  415. }
  416. /*
  417. * isp_isr - Interrupt Service Routine for Camera ISP module.
  418. * @irq: Not used currently.
  419. * @_isp: Pointer to the OMAP3 ISP device
  420. *
  421. * Handles the corresponding callback if plugged in.
  422. *
  423. * Returns IRQ_HANDLED when IRQ was correctly handled, or IRQ_NONE when the
  424. * IRQ wasn't handled.
  425. */
  426. static irqreturn_t isp_isr(int irq, void *_isp)
  427. {
  428. static const u32 ccdc_events = IRQ0STATUS_CCDC_LSC_PREF_ERR_IRQ |
  429. IRQ0STATUS_CCDC_LSC_DONE_IRQ |
  430. IRQ0STATUS_CCDC_VD0_IRQ |
  431. IRQ0STATUS_CCDC_VD1_IRQ |
  432. IRQ0STATUS_HS_VS_IRQ;
  433. struct isp_device *isp = _isp;
  434. u32 irqstatus;
  435. irqstatus = isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
  436. isp_reg_writel(isp, irqstatus, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
  437. isp_isr_sbl(isp);
  438. if (irqstatus & IRQ0STATUS_CSIA_IRQ)
  439. omap3isp_csi2_isr(&isp->isp_csi2a);
  440. if (irqstatus & IRQ0STATUS_CSIB_IRQ)
  441. omap3isp_ccp2_isr(&isp->isp_ccp2);
  442. if (irqstatus & IRQ0STATUS_CCDC_VD0_IRQ) {
  443. if (isp->isp_ccdc.output & CCDC_OUTPUT_PREVIEW)
  444. omap3isp_preview_isr_frame_sync(&isp->isp_prev);
  445. if (isp->isp_ccdc.output & CCDC_OUTPUT_RESIZER)
  446. omap3isp_resizer_isr_frame_sync(&isp->isp_res);
  447. omap3isp_stat_isr_frame_sync(&isp->isp_aewb);
  448. omap3isp_stat_isr_frame_sync(&isp->isp_af);
  449. omap3isp_stat_isr_frame_sync(&isp->isp_hist);
  450. }
  451. if (irqstatus & ccdc_events)
  452. omap3isp_ccdc_isr(&isp->isp_ccdc, irqstatus & ccdc_events);
  453. if (irqstatus & IRQ0STATUS_PRV_DONE_IRQ) {
  454. if (isp->isp_prev.output & PREVIEW_OUTPUT_RESIZER)
  455. omap3isp_resizer_isr_frame_sync(&isp->isp_res);
  456. omap3isp_preview_isr(&isp->isp_prev);
  457. }
  458. if (irqstatus & IRQ0STATUS_RSZ_DONE_IRQ)
  459. omap3isp_resizer_isr(&isp->isp_res);
  460. if (irqstatus & IRQ0STATUS_H3A_AWB_DONE_IRQ)
  461. omap3isp_stat_isr(&isp->isp_aewb);
  462. if (irqstatus & IRQ0STATUS_H3A_AF_DONE_IRQ)
  463. omap3isp_stat_isr(&isp->isp_af);
  464. if (irqstatus & IRQ0STATUS_HIST_DONE_IRQ)
  465. omap3isp_stat_isr(&isp->isp_hist);
  466. omap3isp_flush(isp);
  467. #if defined(DEBUG) && defined(ISP_ISR_DEBUG)
  468. isp_isr_dbg(isp, irqstatus);
  469. #endif
  470. return IRQ_HANDLED;
  471. }
  472. /* -----------------------------------------------------------------------------
  473. * Pipeline power management
  474. *
  475. * Entities must be powered up when part of a pipeline that contains at least
  476. * one open video device node.
  477. *
  478. * To achieve this use the entity use_count field to track the number of users.
  479. * For entities corresponding to video device nodes the use_count field stores
  480. * the users count of the node. For entities corresponding to subdevs the
  481. * use_count field stores the total number of users of all video device nodes
  482. * in the pipeline.
  483. *
  484. * The omap3isp_pipeline_pm_use() function must be called in the open() and
  485. * close() handlers of video device nodes. It increments or decrements the use
  486. * count of all subdev entities in the pipeline.
  487. *
  488. * To react to link management on powered pipelines, the link setup notification
  489. * callback updates the use count of all entities in the source and sink sides
  490. * of the link.
  491. */
  492. /*
  493. * isp_pipeline_pm_use_count - Count the number of users of a pipeline
  494. * @entity: The entity
  495. *
  496. * Return the total number of users of all video device nodes in the pipeline.
  497. */
  498. static int isp_pipeline_pm_use_count(struct media_entity *entity)
  499. {
  500. struct media_entity_graph graph;
  501. int use = 0;
  502. media_entity_graph_walk_start(&graph, entity);
  503. while ((entity = media_entity_graph_walk_next(&graph))) {
  504. if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
  505. use += entity->use_count;
  506. }
  507. return use;
  508. }
  509. /*
  510. * isp_pipeline_pm_power_one - Apply power change to an entity
  511. * @entity: The entity
  512. * @change: Use count change
  513. *
  514. * Change the entity use count by @change. If the entity is a subdev update its
  515. * power state by calling the core::s_power operation when the use count goes
  516. * from 0 to != 0 or from != 0 to 0.
  517. *
  518. * Return 0 on success or a negative error code on failure.
  519. */
  520. static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
  521. {
  522. struct v4l2_subdev *subdev;
  523. int ret;
  524. subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
  525. ? media_entity_to_v4l2_subdev(entity) : NULL;
  526. if (entity->use_count == 0 && change > 0 && subdev != NULL) {
  527. ret = v4l2_subdev_call(subdev, core, s_power, 1);
  528. if (ret < 0 && ret != -ENOIOCTLCMD)
  529. return ret;
  530. }
  531. entity->use_count += change;
  532. WARN_ON(entity->use_count < 0);
  533. if (entity->use_count == 0 && change < 0 && subdev != NULL)
  534. v4l2_subdev_call(subdev, core, s_power, 0);
  535. return 0;
  536. }
  537. /*
  538. * isp_pipeline_pm_power - Apply power change to all entities in a pipeline
  539. * @entity: The entity
  540. * @change: Use count change
  541. *
  542. * Walk the pipeline to update the use count and the power state of all non-node
  543. * entities.
  544. *
  545. * Return 0 on success or a negative error code on failure.
  546. */
  547. static int isp_pipeline_pm_power(struct media_entity *entity, int change)
  548. {
  549. struct media_entity_graph graph;
  550. struct media_entity *first = entity;
  551. int ret = 0;
  552. if (!change)
  553. return 0;
  554. media_entity_graph_walk_start(&graph, entity);
  555. while (!ret && (entity = media_entity_graph_walk_next(&graph)))
  556. if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
  557. ret = isp_pipeline_pm_power_one(entity, change);
  558. if (!ret)
  559. return 0;
  560. media_entity_graph_walk_start(&graph, first);
  561. while ((first = media_entity_graph_walk_next(&graph))
  562. && first != entity)
  563. if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
  564. isp_pipeline_pm_power_one(first, -change);
  565. return ret;
  566. }
  567. /*
  568. * omap3isp_pipeline_pm_use - Update the use count of an entity
  569. * @entity: The entity
  570. * @use: Use (1) or stop using (0) the entity
  571. *
  572. * Update the use count of all entities in the pipeline and power entities on or
  573. * off accordingly.
  574. *
  575. * Return 0 on success or a negative error code on failure. Powering entities
  576. * off is assumed to never fail. No failure can occur when the use parameter is
  577. * set to 0.
  578. */
  579. int omap3isp_pipeline_pm_use(struct media_entity *entity, int use)
  580. {
  581. int change = use ? 1 : -1;
  582. int ret;
  583. mutex_lock(&entity->parent->graph_mutex);
  584. /* Apply use count to node. */
  585. entity->use_count += change;
  586. WARN_ON(entity->use_count < 0);
  587. /* Apply power change to connected non-nodes. */
  588. ret = isp_pipeline_pm_power(entity, change);
  589. if (ret < 0)
  590. entity->use_count -= change;
  591. mutex_unlock(&entity->parent->graph_mutex);
  592. return ret;
  593. }
  594. /*
  595. * isp_pipeline_link_notify - Link management notification callback
  596. * @source: Pad at the start of the link
  597. * @sink: Pad at the end of the link
  598. * @flags: New link flags that will be applied
  599. *
  600. * React to link management on powered pipelines by updating the use count of
  601. * all entities in the source and sink sides of the link. Entities are powered
  602. * on or off accordingly.
  603. *
  604. * Return 0 on success or a negative error code on failure. Powering entities
  605. * off is assumed to never fail. This function will not fail for disconnection
  606. * events.
  607. */
  608. static int isp_pipeline_link_notify(struct media_pad *source,
  609. struct media_pad *sink, u32 flags)
  610. {
  611. int source_use = isp_pipeline_pm_use_count(source->entity);
  612. int sink_use = isp_pipeline_pm_use_count(sink->entity);
  613. int ret;
  614. if (!(flags & MEDIA_LNK_FL_ENABLED)) {
  615. /* Powering off entities is assumed to never fail. */
  616. isp_pipeline_pm_power(source->entity, -sink_use);
  617. isp_pipeline_pm_power(sink->entity, -source_use);
  618. return 0;
  619. }
  620. ret = isp_pipeline_pm_power(source->entity, sink_use);
  621. if (ret < 0)
  622. return ret;
  623. ret = isp_pipeline_pm_power(sink->entity, source_use);
  624. if (ret < 0)
  625. isp_pipeline_pm_power(source->entity, -sink_use);
  626. return ret;
  627. }
  628. /* -----------------------------------------------------------------------------
  629. * Pipeline stream management
  630. */
  631. /*
  632. * isp_pipeline_enable - Enable streaming on a pipeline
  633. * @pipe: ISP pipeline
  634. * @mode: Stream mode (single shot or continuous)
  635. *
  636. * Walk the entities chain starting at the pipeline output video node and start
  637. * all modules in the chain in the given mode.
  638. *
  639. * Return 0 if successful, or the return value of the failed video::s_stream
  640. * operation otherwise.
  641. */
  642. static int isp_pipeline_enable(struct isp_pipeline *pipe,
  643. enum isp_pipeline_stream_state mode)
  644. {
  645. struct isp_device *isp = pipe->output->isp;
  646. struct media_entity *entity;
  647. struct media_pad *pad;
  648. struct v4l2_subdev *subdev;
  649. unsigned long flags;
  650. int ret;
  651. spin_lock_irqsave(&pipe->lock, flags);
  652. pipe->state &= ~(ISP_PIPELINE_IDLE_INPUT | ISP_PIPELINE_IDLE_OUTPUT);
  653. spin_unlock_irqrestore(&pipe->lock, flags);
  654. pipe->do_propagation = false;
  655. entity = &pipe->output->video.entity;
  656. while (1) {
  657. pad = &entity->pads[0];
  658. if (!(pad->flags & MEDIA_PAD_FL_SINK))
  659. break;
  660. pad = media_entity_remote_source(pad);
  661. if (pad == NULL ||
  662. media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
  663. break;
  664. entity = pad->entity;
  665. subdev = media_entity_to_v4l2_subdev(entity);
  666. ret = v4l2_subdev_call(subdev, video, s_stream, mode);
  667. if (ret < 0 && ret != -ENOIOCTLCMD)
  668. return ret;
  669. if (subdev == &isp->isp_ccdc.subdev) {
  670. v4l2_subdev_call(&isp->isp_aewb.subdev, video,
  671. s_stream, mode);
  672. v4l2_subdev_call(&isp->isp_af.subdev, video,
  673. s_stream, mode);
  674. v4l2_subdev_call(&isp->isp_hist.subdev, video,
  675. s_stream, mode);
  676. pipe->do_propagation = true;
  677. }
  678. }
  679. /* Frame number propagation. In continuous streaming mode the number
  680. * is incremented in the frame start ISR. In mem-to-mem mode
  681. * singleshot is used and frame start IRQs are not available.
  682. * Thus we have to increment the number here.
  683. */
  684. if (pipe->do_propagation && mode == ISP_PIPELINE_STREAM_SINGLESHOT)
  685. atomic_inc(&pipe->frame_number);
  686. return 0;
  687. }
  688. static int isp_pipeline_wait_resizer(struct isp_device *isp)
  689. {
  690. return omap3isp_resizer_busy(&isp->isp_res);
  691. }
  692. static int isp_pipeline_wait_preview(struct isp_device *isp)
  693. {
  694. return omap3isp_preview_busy(&isp->isp_prev);
  695. }
  696. static int isp_pipeline_wait_ccdc(struct isp_device *isp)
  697. {
  698. return omap3isp_stat_busy(&isp->isp_af)
  699. || omap3isp_stat_busy(&isp->isp_aewb)
  700. || omap3isp_stat_busy(&isp->isp_hist)
  701. || omap3isp_ccdc_busy(&isp->isp_ccdc);
  702. }
  703. #define ISP_STOP_TIMEOUT msecs_to_jiffies(1000)
  704. static int isp_pipeline_wait(struct isp_device *isp,
  705. int(*busy)(struct isp_device *isp))
  706. {
  707. unsigned long timeout = jiffies + ISP_STOP_TIMEOUT;
  708. while (!time_after(jiffies, timeout)) {
  709. if (!busy(isp))
  710. return 0;
  711. }
  712. return 1;
  713. }
  714. /*
  715. * isp_pipeline_disable - Disable streaming on a pipeline
  716. * @pipe: ISP pipeline
  717. *
  718. * Walk the entities chain starting at the pipeline output video node and stop
  719. * all modules in the chain. Wait synchronously for the modules to be stopped if
  720. * necessary.
  721. *
  722. * Return 0 if all modules have been properly stopped, or -ETIMEDOUT if a module
  723. * can't be stopped (in which case a software reset of the ISP is probably
  724. * necessary).
  725. */
  726. static int isp_pipeline_disable(struct isp_pipeline *pipe)
  727. {
  728. struct isp_device *isp = pipe->output->isp;
  729. struct media_entity *entity;
  730. struct media_pad *pad;
  731. struct v4l2_subdev *subdev;
  732. int failure = 0;
  733. int ret;
  734. /*
  735. * We need to stop all the modules after CCDC first or they'll
  736. * never stop since they may not get a full frame from CCDC.
  737. */
  738. entity = &pipe->output->video.entity;
  739. while (1) {
  740. pad = &entity->pads[0];
  741. if (!(pad->flags & MEDIA_PAD_FL_SINK))
  742. break;
  743. pad = media_entity_remote_source(pad);
  744. if (pad == NULL ||
  745. media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
  746. break;
  747. entity = pad->entity;
  748. subdev = media_entity_to_v4l2_subdev(entity);
  749. if (subdev == &isp->isp_ccdc.subdev) {
  750. v4l2_subdev_call(&isp->isp_aewb.subdev,
  751. video, s_stream, 0);
  752. v4l2_subdev_call(&isp->isp_af.subdev,
  753. video, s_stream, 0);
  754. v4l2_subdev_call(&isp->isp_hist.subdev,
  755. video, s_stream, 0);
  756. }
  757. v4l2_subdev_call(subdev, video, s_stream, 0);
  758. if (subdev == &isp->isp_res.subdev)
  759. ret = isp_pipeline_wait(isp, isp_pipeline_wait_resizer);
  760. else if (subdev == &isp->isp_prev.subdev)
  761. ret = isp_pipeline_wait(isp, isp_pipeline_wait_preview);
  762. else if (subdev == &isp->isp_ccdc.subdev)
  763. ret = isp_pipeline_wait(isp, isp_pipeline_wait_ccdc);
  764. else
  765. ret = 0;
  766. if (ret) {
  767. dev_info(isp->dev, "Unable to stop %s\n", subdev->name);
  768. failure = -ETIMEDOUT;
  769. }
  770. }
  771. if (failure < 0)
  772. isp->needs_reset = true;
  773. return failure;
  774. }
  775. /*
  776. * omap3isp_pipeline_set_stream - Enable/disable streaming on a pipeline
  777. * @pipe: ISP pipeline
  778. * @state: Stream state (stopped, single shot or continuous)
  779. *
  780. * Set the pipeline to the given stream state. Pipelines can be started in
  781. * single-shot or continuous mode.
  782. *
  783. * Return 0 if successful, or the return value of the failed video::s_stream
  784. * operation otherwise. The pipeline state is not updated when the operation
  785. * fails, except when stopping the pipeline.
  786. */
  787. int omap3isp_pipeline_set_stream(struct isp_pipeline *pipe,
  788. enum isp_pipeline_stream_state state)
  789. {
  790. int ret;
  791. if (state == ISP_PIPELINE_STREAM_STOPPED)
  792. ret = isp_pipeline_disable(pipe);
  793. else
  794. ret = isp_pipeline_enable(pipe, state);
  795. if (ret == 0 || state == ISP_PIPELINE_STREAM_STOPPED)
  796. pipe->stream_state = state;
  797. return ret;
  798. }
  799. /*
  800. * isp_pipeline_resume - Resume streaming on a pipeline
  801. * @pipe: ISP pipeline
  802. *
  803. * Resume video output and input and re-enable pipeline.
  804. */
  805. static void isp_pipeline_resume(struct isp_pipeline *pipe)
  806. {
  807. int singleshot = pipe->stream_state == ISP_PIPELINE_STREAM_SINGLESHOT;
  808. omap3isp_video_resume(pipe->output, !singleshot);
  809. if (singleshot)
  810. omap3isp_video_resume(pipe->input, 0);
  811. isp_pipeline_enable(pipe, pipe->stream_state);
  812. }
  813. /*
  814. * isp_pipeline_suspend - Suspend streaming on a pipeline
  815. * @pipe: ISP pipeline
  816. *
  817. * Suspend pipeline.
  818. */
  819. static void isp_pipeline_suspend(struct isp_pipeline *pipe)
  820. {
  821. isp_pipeline_disable(pipe);
  822. }
  823. /*
  824. * isp_pipeline_is_last - Verify if entity has an enabled link to the output
  825. * video node
  826. * @me: ISP module's media entity
  827. *
  828. * Returns 1 if the entity has an enabled link to the output video node or 0
  829. * otherwise. It's true only while pipeline can have no more than one output
  830. * node.
  831. */
  832. static int isp_pipeline_is_last(struct media_entity *me)
  833. {
  834. struct isp_pipeline *pipe;
  835. struct media_pad *pad;
  836. if (!me->pipe)
  837. return 0;
  838. pipe = to_isp_pipeline(me);
  839. if (pipe->stream_state == ISP_PIPELINE_STREAM_STOPPED)
  840. return 0;
  841. pad = media_entity_remote_source(&pipe->output->pad);
  842. return pad->entity == me;
  843. }
  844. /*
  845. * isp_suspend_module_pipeline - Suspend pipeline to which belongs the module
  846. * @me: ISP module's media entity
  847. *
  848. * Suspend the whole pipeline if module's entity has an enabled link to the
  849. * output video node. It works only while pipeline can have no more than one
  850. * output node.
  851. */
  852. static void isp_suspend_module_pipeline(struct media_entity *me)
  853. {
  854. if (isp_pipeline_is_last(me))
  855. isp_pipeline_suspend(to_isp_pipeline(me));
  856. }
  857. /*
  858. * isp_resume_module_pipeline - Resume pipeline to which belongs the module
  859. * @me: ISP module's media entity
  860. *
  861. * Resume the whole pipeline if module's entity has an enabled link to the
  862. * output video node. It works only while pipeline can have no more than one
  863. * output node.
  864. */
  865. static void isp_resume_module_pipeline(struct media_entity *me)
  866. {
  867. if (isp_pipeline_is_last(me))
  868. isp_pipeline_resume(to_isp_pipeline(me));
  869. }
  870. /*
  871. * isp_suspend_modules - Suspend ISP submodules.
  872. * @isp: OMAP3 ISP device
  873. *
  874. * Returns 0 if suspend left in idle state all the submodules properly,
  875. * or returns 1 if a general Reset is required to suspend the submodules.
  876. */
  877. static int isp_suspend_modules(struct isp_device *isp)
  878. {
  879. unsigned long timeout;
  880. omap3isp_stat_suspend(&isp->isp_aewb);
  881. omap3isp_stat_suspend(&isp->isp_af);
  882. omap3isp_stat_suspend(&isp->isp_hist);
  883. isp_suspend_module_pipeline(&isp->isp_res.subdev.entity);
  884. isp_suspend_module_pipeline(&isp->isp_prev.subdev.entity);
  885. isp_suspend_module_pipeline(&isp->isp_ccdc.subdev.entity);
  886. isp_suspend_module_pipeline(&isp->isp_csi2a.subdev.entity);
  887. isp_suspend_module_pipeline(&isp->isp_ccp2.subdev.entity);
  888. timeout = jiffies + ISP_STOP_TIMEOUT;
  889. while (omap3isp_stat_busy(&isp->isp_af)
  890. || omap3isp_stat_busy(&isp->isp_aewb)
  891. || omap3isp_stat_busy(&isp->isp_hist)
  892. || omap3isp_preview_busy(&isp->isp_prev)
  893. || omap3isp_resizer_busy(&isp->isp_res)
  894. || omap3isp_ccdc_busy(&isp->isp_ccdc)) {
  895. if (time_after(jiffies, timeout)) {
  896. dev_info(isp->dev, "can't stop modules.\n");
  897. return 1;
  898. }
  899. msleep(1);
  900. }
  901. return 0;
  902. }
  903. /*
  904. * isp_resume_modules - Resume ISP submodules.
  905. * @isp: OMAP3 ISP device
  906. */
  907. static void isp_resume_modules(struct isp_device *isp)
  908. {
  909. omap3isp_stat_resume(&isp->isp_aewb);
  910. omap3isp_stat_resume(&isp->isp_af);
  911. omap3isp_stat_resume(&isp->isp_hist);
  912. isp_resume_module_pipeline(&isp->isp_res.subdev.entity);
  913. isp_resume_module_pipeline(&isp->isp_prev.subdev.entity);
  914. isp_resume_module_pipeline(&isp->isp_ccdc.subdev.entity);
  915. isp_resume_module_pipeline(&isp->isp_csi2a.subdev.entity);
  916. isp_resume_module_pipeline(&isp->isp_ccp2.subdev.entity);
  917. }
  918. /*
  919. * isp_reset - Reset ISP with a timeout wait for idle.
  920. * @isp: OMAP3 ISP device
  921. */
  922. static int isp_reset(struct isp_device *isp)
  923. {
  924. unsigned long timeout = 0;
  925. isp_reg_writel(isp,
  926. isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_SYSCONFIG)
  927. | ISP_SYSCONFIG_SOFTRESET,
  928. OMAP3_ISP_IOMEM_MAIN, ISP_SYSCONFIG);
  929. while (!(isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN,
  930. ISP_SYSSTATUS) & 0x1)) {
  931. if (timeout++ > 10000) {
  932. dev_alert(isp->dev, "cannot reset ISP\n");
  933. return -ETIMEDOUT;
  934. }
  935. udelay(1);
  936. }
  937. return 0;
  938. }
  939. /*
  940. * isp_save_context - Saves the values of the ISP module registers.
  941. * @isp: OMAP3 ISP device
  942. * @reg_list: Structure containing pairs of register address and value to
  943. * modify on OMAP.
  944. */
  945. static void
  946. isp_save_context(struct isp_device *isp, struct isp_reg *reg_list)
  947. {
  948. struct isp_reg *next = reg_list;
  949. for (; next->reg != ISP_TOK_TERM; next++)
  950. next->val = isp_reg_readl(isp, next->mmio_range, next->reg);
  951. }
  952. /*
  953. * isp_restore_context - Restores the values of the ISP module registers.
  954. * @isp: OMAP3 ISP device
  955. * @reg_list: Structure containing pairs of register address and value to
  956. * modify on OMAP.
  957. */
  958. static void
  959. isp_restore_context(struct isp_device *isp, struct isp_reg *reg_list)
  960. {
  961. struct isp_reg *next = reg_list;
  962. for (; next->reg != ISP_TOK_TERM; next++)
  963. isp_reg_writel(isp, next->val, next->mmio_range, next->reg);
  964. }
  965. /*
  966. * isp_save_ctx - Saves ISP, CCDC, HIST, H3A, PREV, RESZ & MMU context.
  967. * @isp: OMAP3 ISP device
  968. *
  969. * Routine for saving the context of each module in the ISP.
  970. * CCDC, HIST, H3A, PREV, RESZ and MMU.
  971. */
  972. static void isp_save_ctx(struct isp_device *isp)
  973. {
  974. isp_save_context(isp, isp_reg_list);
  975. if (isp->iommu)
  976. omap_iommu_save_ctx(isp->iommu);
  977. }
  978. /*
  979. * isp_restore_ctx - Restores ISP, CCDC, HIST, H3A, PREV, RESZ & MMU context.
  980. * @isp: OMAP3 ISP device
  981. *
  982. * Routine for restoring the context of each module in the ISP.
  983. * CCDC, HIST, H3A, PREV, RESZ and MMU.
  984. */
  985. static void isp_restore_ctx(struct isp_device *isp)
  986. {
  987. isp_restore_context(isp, isp_reg_list);
  988. if (isp->iommu)
  989. omap_iommu_restore_ctx(isp->iommu);
  990. omap3isp_ccdc_restore_context(isp);
  991. omap3isp_preview_restore_context(isp);
  992. }
  993. /* -----------------------------------------------------------------------------
  994. * SBL resources management
  995. */
  996. #define OMAP3_ISP_SBL_READ (OMAP3_ISP_SBL_CSI1_READ | \
  997. OMAP3_ISP_SBL_CCDC_LSC_READ | \
  998. OMAP3_ISP_SBL_PREVIEW_READ | \
  999. OMAP3_ISP_SBL_RESIZER_READ)
  1000. #define OMAP3_ISP_SBL_WRITE (OMAP3_ISP_SBL_CSI1_WRITE | \
  1001. OMAP3_ISP_SBL_CSI2A_WRITE | \
  1002. OMAP3_ISP_SBL_CSI2C_WRITE | \
  1003. OMAP3_ISP_SBL_CCDC_WRITE | \
  1004. OMAP3_ISP_SBL_PREVIEW_WRITE)
  1005. void omap3isp_sbl_enable(struct isp_device *isp, enum isp_sbl_resource res)
  1006. {
  1007. u32 sbl = 0;
  1008. isp->sbl_resources |= res;
  1009. if (isp->sbl_resources & OMAP3_ISP_SBL_CSI1_READ)
  1010. sbl |= ISPCTRL_SBL_SHARED_RPORTA;
  1011. if (isp->sbl_resources & OMAP3_ISP_SBL_CCDC_LSC_READ)
  1012. sbl |= ISPCTRL_SBL_SHARED_RPORTB;
  1013. if (isp->sbl_resources & OMAP3_ISP_SBL_CSI2C_WRITE)
  1014. sbl |= ISPCTRL_SBL_SHARED_WPORTC;
  1015. if (isp->sbl_resources & OMAP3_ISP_SBL_RESIZER_WRITE)
  1016. sbl |= ISPCTRL_SBL_WR0_RAM_EN;
  1017. if (isp->sbl_resources & OMAP3_ISP_SBL_WRITE)
  1018. sbl |= ISPCTRL_SBL_WR1_RAM_EN;
  1019. if (isp->sbl_resources & OMAP3_ISP_SBL_READ)
  1020. sbl |= ISPCTRL_SBL_RD_RAM_EN;
  1021. isp_reg_set(isp, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL, sbl);
  1022. }
  1023. void omap3isp_sbl_disable(struct isp_device *isp, enum isp_sbl_resource res)
  1024. {
  1025. u32 sbl = 0;
  1026. isp->sbl_resources &= ~res;
  1027. if (!(isp->sbl_resources & OMAP3_ISP_SBL_CSI1_READ))
  1028. sbl |= ISPCTRL_SBL_SHARED_RPORTA;
  1029. if (!(isp->sbl_resources & OMAP3_ISP_SBL_CCDC_LSC_READ))
  1030. sbl |= ISPCTRL_SBL_SHARED_RPORTB;
  1031. if (!(isp->sbl_resources & OMAP3_ISP_SBL_CSI2C_WRITE))
  1032. sbl |= ISPCTRL_SBL_SHARED_WPORTC;
  1033. if (!(isp->sbl_resources & OMAP3_ISP_SBL_RESIZER_WRITE))
  1034. sbl |= ISPCTRL_SBL_WR0_RAM_EN;
  1035. if (!(isp->sbl_resources & OMAP3_ISP_SBL_WRITE))
  1036. sbl |= ISPCTRL_SBL_WR1_RAM_EN;
  1037. if (!(isp->sbl_resources & OMAP3_ISP_SBL_READ))
  1038. sbl |= ISPCTRL_SBL_RD_RAM_EN;
  1039. isp_reg_clr(isp, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL, sbl);
  1040. }
  1041. /*
  1042. * isp_module_sync_idle - Helper to sync module with its idle state
  1043. * @me: ISP submodule's media entity
  1044. * @wait: ISP submodule's wait queue for streamoff/interrupt synchronization
  1045. * @stopping: flag which tells module wants to stop
  1046. *
  1047. * This function checks if ISP submodule needs to wait for next interrupt. If
  1048. * yes, makes the caller to sleep while waiting for such event.
  1049. */
  1050. int omap3isp_module_sync_idle(struct media_entity *me, wait_queue_head_t *wait,
  1051. atomic_t *stopping)
  1052. {
  1053. struct isp_pipeline *pipe = to_isp_pipeline(me);
  1054. if (pipe->stream_state == ISP_PIPELINE_STREAM_STOPPED ||
  1055. (pipe->stream_state == ISP_PIPELINE_STREAM_SINGLESHOT &&
  1056. !isp_pipeline_ready(pipe)))
  1057. return 0;
  1058. /*
  1059. * atomic_set() doesn't include memory barrier on ARM platform for SMP
  1060. * scenario. We'll call it here to avoid race conditions.
  1061. */
  1062. atomic_set(stopping, 1);
  1063. smp_mb();
  1064. /*
  1065. * If module is the last one, it's writing to memory. In this case,
  1066. * it's necessary to check if the module is already paused due to
  1067. * DMA queue underrun or if it has to wait for next interrupt to be
  1068. * idle.
  1069. * If it isn't the last one, the function won't sleep but *stopping
  1070. * will still be set to warn next submodule caller's interrupt the
  1071. * module wants to be idle.
  1072. */
  1073. if (isp_pipeline_is_last(me)) {
  1074. struct isp_video *video = pipe->output;
  1075. unsigned long flags;
  1076. spin_lock_irqsave(&video->queue->irqlock, flags);
  1077. if (video->dmaqueue_flags & ISP_VIDEO_DMAQUEUE_UNDERRUN) {
  1078. spin_unlock_irqrestore(&video->queue->irqlock, flags);
  1079. atomic_set(stopping, 0);
  1080. smp_mb();
  1081. return 0;
  1082. }
  1083. spin_unlock_irqrestore(&video->queue->irqlock, flags);
  1084. if (!wait_event_timeout(*wait, !atomic_read(stopping),
  1085. msecs_to_jiffies(1000))) {
  1086. atomic_set(stopping, 0);
  1087. smp_mb();
  1088. return -ETIMEDOUT;
  1089. }
  1090. }
  1091. return 0;
  1092. }
  1093. /*
  1094. * omap3isp_module_sync_is_stopped - Helper to verify if module was stopping
  1095. * @wait: ISP submodule's wait queue for streamoff/interrupt synchronization
  1096. * @stopping: flag which tells module wants to stop
  1097. *
  1098. * This function checks if ISP submodule was stopping. In case of yes, it
  1099. * notices the caller by setting stopping to 0 and waking up the wait queue.
  1100. * Returns 1 if it was stopping or 0 otherwise.
  1101. */
  1102. int omap3isp_module_sync_is_stopping(wait_queue_head_t *wait,
  1103. atomic_t *stopping)
  1104. {
  1105. if (atomic_cmpxchg(stopping, 1, 0)) {
  1106. wake_up(wait);
  1107. return 1;
  1108. }
  1109. return 0;
  1110. }
  1111. /* --------------------------------------------------------------------------
  1112. * Clock management
  1113. */
  1114. #define ISPCTRL_CLKS_MASK (ISPCTRL_H3A_CLK_EN | \
  1115. ISPCTRL_HIST_CLK_EN | \
  1116. ISPCTRL_RSZ_CLK_EN | \
  1117. (ISPCTRL_CCDC_CLK_EN | ISPCTRL_CCDC_RAM_EN) | \
  1118. (ISPCTRL_PREV_CLK_EN | ISPCTRL_PREV_RAM_EN))
  1119. static void __isp_subclk_update(struct isp_device *isp)
  1120. {
  1121. u32 clk = 0;
  1122. if (isp->subclk_resources & OMAP3_ISP_SUBCLK_H3A)
  1123. clk |= ISPCTRL_H3A_CLK_EN;
  1124. if (isp->subclk_resources & OMAP3_ISP_SUBCLK_HIST)
  1125. clk |= ISPCTRL_HIST_CLK_EN;
  1126. if (isp->subclk_resources & OMAP3_ISP_SUBCLK_RESIZER)
  1127. clk |= ISPCTRL_RSZ_CLK_EN;
  1128. /* NOTE: For CCDC & Preview submodules, we need to affect internal
  1129. * RAM as well.
  1130. */
  1131. if (isp->subclk_resources & OMAP3_ISP_SUBCLK_CCDC)
  1132. clk |= ISPCTRL_CCDC_CLK_EN | ISPCTRL_CCDC_RAM_EN;
  1133. if (isp->subclk_resources & OMAP3_ISP_SUBCLK_PREVIEW)
  1134. clk |= ISPCTRL_PREV_CLK_EN | ISPCTRL_PREV_RAM_EN;
  1135. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL,
  1136. ISPCTRL_CLKS_MASK, clk);
  1137. }
  1138. void omap3isp_subclk_enable(struct isp_device *isp,
  1139. enum isp_subclk_resource res)
  1140. {
  1141. isp->subclk_resources |= res;
  1142. __isp_subclk_update(isp);
  1143. }
  1144. void omap3isp_subclk_disable(struct isp_device *isp,
  1145. enum isp_subclk_resource res)
  1146. {
  1147. isp->subclk_resources &= ~res;
  1148. __isp_subclk_update(isp);
  1149. }
  1150. /*
  1151. * isp_enable_clocks - Enable ISP clocks
  1152. * @isp: OMAP3 ISP device
  1153. *
  1154. * Return 0 if successful, or clk_enable return value if any of tthem fails.
  1155. */
  1156. static int isp_enable_clocks(struct isp_device *isp)
  1157. {
  1158. int r;
  1159. unsigned long rate;
  1160. int divisor;
  1161. /*
  1162. * cam_mclk clock chain:
  1163. * dpll4 -> dpll4_m5 -> dpll4_m5x2 -> cam_mclk
  1164. *
  1165. * In OMAP3630 dpll4_m5x2 != 2 x dpll4_m5 but both are
  1166. * set to the same value. Hence the rate set for dpll4_m5
  1167. * has to be twice of what is set on OMAP3430 to get
  1168. * the required value for cam_mclk
  1169. */
  1170. if (cpu_is_omap3630())
  1171. divisor = 1;
  1172. else
  1173. divisor = 2;
  1174. r = clk_enable(isp->clock[ISP_CLK_CAM_ICK]);
  1175. if (r) {
  1176. dev_err(isp->dev, "clk_enable cam_ick failed\n");
  1177. goto out_clk_enable_ick;
  1178. }
  1179. r = clk_set_rate(isp->clock[ISP_CLK_DPLL4_M5_CK],
  1180. CM_CAM_MCLK_HZ/divisor);
  1181. if (r) {
  1182. dev_err(isp->dev, "clk_set_rate for dpll4_m5_ck failed\n");
  1183. goto out_clk_enable_mclk;
  1184. }
  1185. r = clk_enable(isp->clock[ISP_CLK_CAM_MCLK]);
  1186. if (r) {
  1187. dev_err(isp->dev, "clk_enable cam_mclk failed\n");
  1188. goto out_clk_enable_mclk;
  1189. }
  1190. rate = clk_get_rate(isp->clock[ISP_CLK_CAM_MCLK]);
  1191. if (rate != CM_CAM_MCLK_HZ)
  1192. dev_warn(isp->dev, "unexpected cam_mclk rate:\n"
  1193. " expected : %d\n"
  1194. " actual : %ld\n", CM_CAM_MCLK_HZ, rate);
  1195. r = clk_enable(isp->clock[ISP_CLK_CSI2_FCK]);
  1196. if (r) {
  1197. dev_err(isp->dev, "clk_enable csi2_fck failed\n");
  1198. goto out_clk_enable_csi2_fclk;
  1199. }
  1200. return 0;
  1201. out_clk_enable_csi2_fclk:
  1202. clk_disable(isp->clock[ISP_CLK_CAM_MCLK]);
  1203. out_clk_enable_mclk:
  1204. clk_disable(isp->clock[ISP_CLK_CAM_ICK]);
  1205. out_clk_enable_ick:
  1206. return r;
  1207. }
  1208. /*
  1209. * isp_disable_clocks - Disable ISP clocks
  1210. * @isp: OMAP3 ISP device
  1211. */
  1212. static void isp_disable_clocks(struct isp_device *isp)
  1213. {
  1214. clk_disable(isp->clock[ISP_CLK_CAM_ICK]);
  1215. clk_disable(isp->clock[ISP_CLK_CAM_MCLK]);
  1216. clk_disable(isp->clock[ISP_CLK_CSI2_FCK]);
  1217. }
  1218. static const char *isp_clocks[] = {
  1219. "cam_ick",
  1220. "cam_mclk",
  1221. "dpll4_m5_ck",
  1222. "csi2_96m_fck",
  1223. "l3_ick",
  1224. };
  1225. static void isp_put_clocks(struct isp_device *isp)
  1226. {
  1227. unsigned int i;
  1228. for (i = 0; i < ARRAY_SIZE(isp_clocks); ++i) {
  1229. if (isp->clock[i]) {
  1230. clk_put(isp->clock[i]);
  1231. isp->clock[i] = NULL;
  1232. }
  1233. }
  1234. }
  1235. static int isp_get_clocks(struct isp_device *isp)
  1236. {
  1237. struct clk *clk;
  1238. unsigned int i;
  1239. for (i = 0; i < ARRAY_SIZE(isp_clocks); ++i) {
  1240. clk = clk_get(isp->dev, isp_clocks[i]);
  1241. if (IS_ERR(clk)) {
  1242. dev_err(isp->dev, "clk_get %s failed\n", isp_clocks[i]);
  1243. isp_put_clocks(isp);
  1244. return PTR_ERR(clk);
  1245. }
  1246. isp->clock[i] = clk;
  1247. }
  1248. return 0;
  1249. }
  1250. /*
  1251. * omap3isp_get - Acquire the ISP resource.
  1252. *
  1253. * Initializes the clocks for the first acquire.
  1254. *
  1255. * Increment the reference count on the ISP. If the first reference is taken,
  1256. * enable clocks and power-up all submodules.
  1257. *
  1258. * Return a pointer to the ISP device structure, or NULL if an error occurred.
  1259. */
  1260. struct isp_device *omap3isp_get(struct isp_device *isp)
  1261. {
  1262. struct isp_device *__isp = isp;
  1263. if (isp == NULL)
  1264. return NULL;
  1265. mutex_lock(&isp->isp_mutex);
  1266. if (isp->ref_count > 0)
  1267. goto out;
  1268. if (isp_enable_clocks(isp) < 0) {
  1269. __isp = NULL;
  1270. goto out;
  1271. }
  1272. /* We don't want to restore context before saving it! */
  1273. if (isp->has_context)
  1274. isp_restore_ctx(isp);
  1275. else
  1276. isp->has_context = 1;
  1277. isp_enable_interrupts(isp);
  1278. out:
  1279. if (__isp != NULL)
  1280. isp->ref_count++;
  1281. mutex_unlock(&isp->isp_mutex);
  1282. return __isp;
  1283. }
  1284. /*
  1285. * omap3isp_put - Release the ISP
  1286. *
  1287. * Decrement the reference count on the ISP. If the last reference is released,
  1288. * power-down all submodules, disable clocks and free temporary buffers.
  1289. */
  1290. void omap3isp_put(struct isp_device *isp)
  1291. {
  1292. if (isp == NULL)
  1293. return;
  1294. mutex_lock(&isp->isp_mutex);
  1295. BUG_ON(isp->ref_count == 0);
  1296. if (--isp->ref_count == 0) {
  1297. isp_disable_interrupts(isp);
  1298. isp_save_ctx(isp);
  1299. if (isp->needs_reset) {
  1300. isp_reset(isp);
  1301. isp->needs_reset = false;
  1302. }
  1303. isp_disable_clocks(isp);
  1304. }
  1305. mutex_unlock(&isp->isp_mutex);
  1306. }
  1307. /* --------------------------------------------------------------------------
  1308. * Platform device driver
  1309. */
  1310. /*
  1311. * omap3isp_print_status - Prints the values of the ISP Control Module registers
  1312. * @isp: OMAP3 ISP device
  1313. */
  1314. #define ISP_PRINT_REGISTER(isp, name)\
  1315. dev_dbg(isp->dev, "###ISP " #name "=0x%08x\n", \
  1316. isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_##name))
  1317. #define SBL_PRINT_REGISTER(isp, name)\
  1318. dev_dbg(isp->dev, "###SBL " #name "=0x%08x\n", \
  1319. isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_##name))
  1320. void omap3isp_print_status(struct isp_device *isp)
  1321. {
  1322. dev_dbg(isp->dev, "-------------ISP Register dump--------------\n");
  1323. ISP_PRINT_REGISTER(isp, SYSCONFIG);
  1324. ISP_PRINT_REGISTER(isp, SYSSTATUS);
  1325. ISP_PRINT_REGISTER(isp, IRQ0ENABLE);
  1326. ISP_PRINT_REGISTER(isp, IRQ0STATUS);
  1327. ISP_PRINT_REGISTER(isp, TCTRL_GRESET_LENGTH);
  1328. ISP_PRINT_REGISTER(isp, TCTRL_PSTRB_REPLAY);
  1329. ISP_PRINT_REGISTER(isp, CTRL);
  1330. ISP_PRINT_REGISTER(isp, TCTRL_CTRL);
  1331. ISP_PRINT_REGISTER(isp, TCTRL_FRAME);
  1332. ISP_PRINT_REGISTER(isp, TCTRL_PSTRB_DELAY);
  1333. ISP_PRINT_REGISTER(isp, TCTRL_STRB_DELAY);
  1334. ISP_PRINT_REGISTER(isp, TCTRL_SHUT_DELAY);
  1335. ISP_PRINT_REGISTER(isp, TCTRL_PSTRB_LENGTH);
  1336. ISP_PRINT_REGISTER(isp, TCTRL_STRB_LENGTH);
  1337. ISP_PRINT_REGISTER(isp, TCTRL_SHUT_LENGTH);
  1338. SBL_PRINT_REGISTER(isp, PCR);
  1339. SBL_PRINT_REGISTER(isp, SDR_REQ_EXP);
  1340. dev_dbg(isp->dev, "--------------------------------------------\n");
  1341. }
  1342. #ifdef CONFIG_PM
  1343. /*
  1344. * Power management support.
  1345. *
  1346. * As the ISP can't properly handle an input video stream interruption on a non
  1347. * frame boundary, the ISP pipelines need to be stopped before sensors get
  1348. * suspended. However, as suspending the sensors can require a running clock,
  1349. * which can be provided by the ISP, the ISP can't be completely suspended
  1350. * before the sensor.
  1351. *
  1352. * To solve this problem power management support is split into prepare/complete
  1353. * and suspend/resume operations. The pipelines are stopped in prepare() and the
  1354. * ISP clocks get disabled in suspend(). Similarly, the clocks are reenabled in
  1355. * resume(), and the the pipelines are restarted in complete().
  1356. *
  1357. * TODO: PM dependencies between the ISP and sensors are not modeled explicitly
  1358. * yet.
  1359. */
  1360. static int isp_pm_prepare(struct device *dev)
  1361. {
  1362. struct isp_device *isp = dev_get_drvdata(dev);
  1363. int reset;
  1364. WARN_ON(mutex_is_locked(&isp->isp_mutex));
  1365. if (isp->ref_count == 0)
  1366. return 0;
  1367. reset = isp_suspend_modules(isp);
  1368. isp_disable_interrupts(isp);
  1369. isp_save_ctx(isp);
  1370. if (reset)
  1371. isp_reset(isp);
  1372. return 0;
  1373. }
  1374. static int isp_pm_suspend(struct device *dev)
  1375. {
  1376. struct isp_device *isp = dev_get_drvdata(dev);
  1377. WARN_ON(mutex_is_locked(&isp->isp_mutex));
  1378. if (isp->ref_count)
  1379. isp_disable_clocks(isp);
  1380. return 0;
  1381. }
  1382. static int isp_pm_resume(struct device *dev)
  1383. {
  1384. struct isp_device *isp = dev_get_drvdata(dev);
  1385. if (isp->ref_count == 0)
  1386. return 0;
  1387. return isp_enable_clocks(isp);
  1388. }
  1389. static void isp_pm_complete(struct device *dev)
  1390. {
  1391. struct isp_device *isp = dev_get_drvdata(dev);
  1392. if (isp->ref_count == 0)
  1393. return;
  1394. isp_restore_ctx(isp);
  1395. isp_enable_interrupts(isp);
  1396. isp_resume_modules(isp);
  1397. }
  1398. #else
  1399. #define isp_pm_prepare NULL
  1400. #define isp_pm_suspend NULL
  1401. #define isp_pm_resume NULL
  1402. #define isp_pm_complete NULL
  1403. #endif /* CONFIG_PM */
  1404. static void isp_unregister_entities(struct isp_device *isp)
  1405. {
  1406. omap3isp_csi2_unregister_entities(&isp->isp_csi2a);
  1407. omap3isp_ccp2_unregister_entities(&isp->isp_ccp2);
  1408. omap3isp_ccdc_unregister_entities(&isp->isp_ccdc);
  1409. omap3isp_preview_unregister_entities(&isp->isp_prev);
  1410. omap3isp_resizer_unregister_entities(&isp->isp_res);
  1411. omap3isp_stat_unregister_entities(&isp->isp_aewb);
  1412. omap3isp_stat_unregister_entities(&isp->isp_af);
  1413. omap3isp_stat_unregister_entities(&isp->isp_hist);
  1414. v4l2_device_unregister(&isp->v4l2_dev);
  1415. media_device_unregister(&isp->media_dev);
  1416. }
  1417. /*
  1418. * isp_register_subdev_group - Register a group of subdevices
  1419. * @isp: OMAP3 ISP device
  1420. * @board_info: I2C subdevs board information array
  1421. *
  1422. * Register all I2C subdevices in the board_info array. The array must be
  1423. * terminated by a NULL entry, and the first entry must be the sensor.
  1424. *
  1425. * Return a pointer to the sensor media entity if it has been successfully
  1426. * registered, or NULL otherwise.
  1427. */
  1428. static struct v4l2_subdev *
  1429. isp_register_subdev_group(struct isp_device *isp,
  1430. struct isp_subdev_i2c_board_info *board_info)
  1431. {
  1432. struct v4l2_subdev *sensor = NULL;
  1433. unsigned int first;
  1434. if (board_info->board_info == NULL)
  1435. return NULL;
  1436. for (first = 1; board_info->board_info; ++board_info, first = 0) {
  1437. struct v4l2_subdev *subdev;
  1438. struct i2c_adapter *adapter;
  1439. adapter = i2c_get_adapter(board_info->i2c_adapter_id);
  1440. if (adapter == NULL) {
  1441. printk(KERN_ERR "%s: Unable to get I2C adapter %d for "
  1442. "device %s\n", __func__,
  1443. board_info->i2c_adapter_id,
  1444. board_info->board_info->type);
  1445. continue;
  1446. }
  1447. subdev = v4l2_i2c_new_subdev_board(&isp->v4l2_dev, adapter,
  1448. board_info->board_info, NULL);
  1449. if (subdev == NULL) {
  1450. printk(KERN_ERR "%s: Unable to register subdev %s\n",
  1451. __func__, board_info->board_info->type);
  1452. continue;
  1453. }
  1454. if (first)
  1455. sensor = subdev;
  1456. }
  1457. return sensor;
  1458. }
  1459. static int isp_register_entities(struct isp_device *isp)
  1460. {
  1461. struct isp_platform_data *pdata = isp->pdata;
  1462. struct isp_v4l2_subdevs_group *subdevs;
  1463. int ret;
  1464. isp->media_dev.dev = isp->dev;
  1465. strlcpy(isp->media_dev.model, "TI OMAP3 ISP",
  1466. sizeof(isp->media_dev.model));
  1467. isp->media_dev.hw_revision = isp->revision;
  1468. isp->media_dev.link_notify = isp_pipeline_link_notify;
  1469. ret = media_device_register(&isp->media_dev);
  1470. if (ret < 0) {
  1471. printk(KERN_ERR "%s: Media device registration failed (%d)\n",
  1472. __func__, ret);
  1473. return ret;
  1474. }
  1475. isp->v4l2_dev.mdev = &isp->media_dev;
  1476. ret = v4l2_device_register(isp->dev, &isp->v4l2_dev);
  1477. if (ret < 0) {
  1478. printk(KERN_ERR "%s: V4L2 device registration failed (%d)\n",
  1479. __func__, ret);
  1480. goto done;
  1481. }
  1482. /* Register internal entities */
  1483. ret = omap3isp_ccp2_register_entities(&isp->isp_ccp2, &isp->v4l2_dev);
  1484. if (ret < 0)
  1485. goto done;
  1486. ret = omap3isp_csi2_register_entities(&isp->isp_csi2a, &isp->v4l2_dev);
  1487. if (ret < 0)
  1488. goto done;
  1489. ret = omap3isp_ccdc_register_entities(&isp->isp_ccdc, &isp->v4l2_dev);
  1490. if (ret < 0)
  1491. goto done;
  1492. ret = omap3isp_preview_register_entities(&isp->isp_prev,
  1493. &isp->v4l2_dev);
  1494. if (ret < 0)
  1495. goto done;
  1496. ret = omap3isp_resizer_register_entities(&isp->isp_res, &isp->v4l2_dev);
  1497. if (ret < 0)
  1498. goto done;
  1499. ret = omap3isp_stat_register_entities(&isp->isp_aewb, &isp->v4l2_dev);
  1500. if (ret < 0)
  1501. goto done;
  1502. ret = omap3isp_stat_register_entities(&isp->isp_af, &isp->v4l2_dev);
  1503. if (ret < 0)
  1504. goto done;
  1505. ret = omap3isp_stat_register_entities(&isp->isp_hist, &isp->v4l2_dev);
  1506. if (ret < 0)
  1507. goto done;
  1508. /* Register external entities */
  1509. for (subdevs = pdata->subdevs; subdevs && subdevs->subdevs; ++subdevs) {
  1510. struct v4l2_subdev *sensor;
  1511. struct media_entity *input;
  1512. unsigned int flags;
  1513. unsigned int pad;
  1514. sensor = isp_register_subdev_group(isp, subdevs->subdevs);
  1515. if (sensor == NULL)
  1516. continue;
  1517. sensor->host_priv = subdevs;
  1518. /* Connect the sensor to the correct interface module. Parallel
  1519. * sensors are connected directly to the CCDC, while serial
  1520. * sensors are connected to the CSI2a, CCP2b or CSI2c receiver
  1521. * through CSIPHY1 or CSIPHY2.
  1522. */
  1523. switch (subdevs->interface) {
  1524. case ISP_INTERFACE_PARALLEL:
  1525. input = &isp->isp_ccdc.subdev.entity;
  1526. pad = CCDC_PAD_SINK;
  1527. flags = 0;
  1528. break;
  1529. case ISP_INTERFACE_CSI2A_PHY2:
  1530. input = &isp->isp_csi2a.subdev.entity;
  1531. pad = CSI2_PAD_SINK;
  1532. flags = MEDIA_LNK_FL_IMMUTABLE
  1533. | MEDIA_LNK_FL_ENABLED;
  1534. break;
  1535. case ISP_INTERFACE_CCP2B_PHY1:
  1536. case ISP_INTERFACE_CCP2B_PHY2:
  1537. input = &isp->isp_ccp2.subdev.entity;
  1538. pad = CCP2_PAD_SINK;
  1539. flags = 0;
  1540. break;
  1541. case ISP_INTERFACE_CSI2C_PHY1:
  1542. input = &isp->isp_csi2c.subdev.entity;
  1543. pad = CSI2_PAD_SINK;
  1544. flags = MEDIA_LNK_FL_IMMUTABLE
  1545. | MEDIA_LNK_FL_ENABLED;
  1546. break;
  1547. default:
  1548. printk(KERN_ERR "%s: invalid interface type %u\n",
  1549. __func__, subdevs->interface);
  1550. ret = -EINVAL;
  1551. goto done;
  1552. }
  1553. ret = media_entity_create_link(&sensor->entity, 0, input, pad,
  1554. flags);
  1555. if (ret < 0)
  1556. goto done;
  1557. }
  1558. ret = v4l2_device_register_subdev_nodes(&isp->v4l2_dev);
  1559. done:
  1560. if (ret < 0)
  1561. isp_unregister_entities(isp);
  1562. return ret;
  1563. }
  1564. static void isp_cleanup_modules(struct isp_device *isp)
  1565. {
  1566. omap3isp_h3a_aewb_cleanup(isp);
  1567. omap3isp_h3a_af_cleanup(isp);
  1568. omap3isp_hist_cleanup(isp);
  1569. omap3isp_resizer_cleanup(isp);
  1570. omap3isp_preview_cleanup(isp);
  1571. omap3isp_ccdc_cleanup(isp);
  1572. omap3isp_ccp2_cleanup(isp);
  1573. omap3isp_csi2_cleanup(isp);
  1574. }
  1575. static int isp_initialize_modules(struct isp_device *isp)
  1576. {
  1577. int ret;
  1578. ret = omap3isp_csiphy_init(isp);
  1579. if (ret < 0) {
  1580. dev_err(isp->dev, "CSI PHY initialization failed\n");
  1581. goto error_csiphy;
  1582. }
  1583. ret = omap3isp_csi2_init(isp);
  1584. if (ret < 0) {
  1585. dev_err(isp->dev, "CSI2 initialization failed\n");
  1586. goto error_csi2;
  1587. }
  1588. ret = omap3isp_ccp2_init(isp);
  1589. if (ret < 0) {
  1590. dev_err(isp->dev, "CCP2 initialization failed\n");
  1591. goto error_ccp2;
  1592. }
  1593. ret = omap3isp_ccdc_init(isp);
  1594. if (ret < 0) {
  1595. dev_err(isp->dev, "CCDC initialization failed\n");
  1596. goto error_ccdc;
  1597. }
  1598. ret = omap3isp_preview_init(isp);
  1599. if (ret < 0) {
  1600. dev_err(isp->dev, "Preview initialization failed\n");
  1601. goto error_preview;
  1602. }
  1603. ret = omap3isp_resizer_init(isp);
  1604. if (ret < 0) {
  1605. dev_err(isp->dev, "Resizer initialization failed\n");
  1606. goto error_resizer;
  1607. }
  1608. ret = omap3isp_hist_init(isp);
  1609. if (ret < 0) {
  1610. dev_err(isp->dev, "Histogram initialization failed\n");
  1611. goto error_hist;
  1612. }
  1613. ret = omap3isp_h3a_aewb_init(isp);
  1614. if (ret < 0) {
  1615. dev_err(isp->dev, "H3A AEWB initialization failed\n");
  1616. goto error_h3a_aewb;
  1617. }
  1618. ret = omap3isp_h3a_af_init(isp);
  1619. if (ret < 0) {
  1620. dev_err(isp->dev, "H3A AF initialization failed\n");
  1621. goto error_h3a_af;
  1622. }
  1623. /* Connect the submodules. */
  1624. ret = media_entity_create_link(
  1625. &isp->isp_csi2a.subdev.entity, CSI2_PAD_SOURCE,
  1626. &isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
  1627. if (ret < 0)
  1628. goto error_link;
  1629. ret = media_entity_create_link(
  1630. &isp->isp_ccp2.subdev.entity, CCP2_PAD_SOURCE,
  1631. &isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
  1632. if (ret < 0)
  1633. goto error_link;
  1634. ret = media_entity_create_link(
  1635. &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
  1636. &isp->isp_prev.subdev.entity, PREV_PAD_SINK, 0);
  1637. if (ret < 0)
  1638. goto error_link;
  1639. ret = media_entity_create_link(
  1640. &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_OF,
  1641. &isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
  1642. if (ret < 0)
  1643. goto error_link;
  1644. ret = media_entity_create_link(
  1645. &isp->isp_prev.subdev.entity, PREV_PAD_SOURCE,
  1646. &isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
  1647. if (ret < 0)
  1648. goto error_link;
  1649. ret = media_entity_create_link(
  1650. &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
  1651. &isp->isp_aewb.subdev.entity, 0,
  1652. MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
  1653. if (ret < 0)
  1654. goto error_link;
  1655. ret = media_entity_create_link(
  1656. &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
  1657. &isp->isp_af.subdev.entity, 0,
  1658. MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
  1659. if (ret < 0)
  1660. goto error_link;
  1661. ret = media_entity_create_link(
  1662. &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
  1663. &isp->isp_hist.subdev.entity, 0,
  1664. MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
  1665. if (ret < 0)
  1666. goto error_link;
  1667. return 0;
  1668. error_link:
  1669. omap3isp_h3a_af_cleanup(isp);
  1670. error_h3a_af:
  1671. omap3isp_h3a_aewb_cleanup(isp);
  1672. error_h3a_aewb:
  1673. omap3isp_hist_cleanup(isp);
  1674. error_hist:
  1675. omap3isp_resizer_cleanup(isp);
  1676. error_resizer:
  1677. omap3isp_preview_cleanup(isp);
  1678. error_preview:
  1679. omap3isp_ccdc_cleanup(isp);
  1680. error_ccdc:
  1681. omap3isp_ccp2_cleanup(isp);
  1682. error_ccp2:
  1683. omap3isp_csi2_cleanup(isp);
  1684. error_csi2:
  1685. error_csiphy:
  1686. return ret;
  1687. }
  1688. /*
  1689. * isp_remove - Remove ISP platform device
  1690. * @pdev: Pointer to ISP platform device
  1691. *
  1692. * Always returns 0.
  1693. */
  1694. static int isp_remove(struct platform_device *pdev)
  1695. {
  1696. struct isp_device *isp = platform_get_drvdata(pdev);
  1697. int i;
  1698. isp_unregister_entities(isp);
  1699. isp_cleanup_modules(isp);
  1700. omap3isp_get(isp);
  1701. iommu_detach_device(isp->domain, isp->iommu_dev);
  1702. iommu_domain_free(isp->domain);
  1703. omap3isp_put(isp);
  1704. free_irq(isp->irq_num, isp);
  1705. isp_put_clocks(isp);
  1706. for (i = 0; i < OMAP3_ISP_IOMEM_LAST; i++) {
  1707. if (isp->mmio_base[i]) {
  1708. iounmap(isp->mmio_base[i]);
  1709. isp->mmio_base[i] = NULL;
  1710. }
  1711. if (isp->mmio_base_phys[i]) {
  1712. release_mem_region(isp->mmio_base_phys[i],
  1713. isp->mmio_size[i]);
  1714. isp->mmio_base_phys[i] = 0;
  1715. }
  1716. }
  1717. regulator_put(isp->isp_csiphy1.vdd);
  1718. regulator_put(isp->isp_csiphy2.vdd);
  1719. kfree(isp);
  1720. return 0;
  1721. }
  1722. static int isp_map_mem_resource(struct platform_device *pdev,
  1723. struct isp_device *isp,
  1724. enum isp_mem_resources res)
  1725. {
  1726. struct resource *mem;
  1727. /* request the mem region for the camera registers */
  1728. mem = platform_get_resource(pdev, IORESOURCE_MEM, res);
  1729. if (!mem) {
  1730. dev_err(isp->dev, "no mem resource?\n");
  1731. return -ENODEV;
  1732. }
  1733. if (!request_mem_region(mem->start, resource_size(mem), pdev->name)) {
  1734. dev_err(isp->dev,
  1735. "cannot reserve camera register I/O region\n");
  1736. return -ENODEV;
  1737. }
  1738. isp->mmio_base_phys[res] = mem->start;
  1739. isp->mmio_size[res] = resource_size(mem);
  1740. /* map the region */
  1741. isp->mmio_base[res] = ioremap_nocache(isp->mmio_base_phys[res],
  1742. isp->mmio_size[res]);
  1743. if (!isp->mmio_base[res]) {
  1744. dev_err(isp->dev, "cannot map camera register I/O region\n");
  1745. return -ENODEV;
  1746. }
  1747. return 0;
  1748. }
  1749. /*
  1750. * isp_probe - Probe ISP platform device
  1751. * @pdev: Pointer to ISP platform device
  1752. *
  1753. * Returns 0 if successful,
  1754. * -ENOMEM if no memory available,
  1755. * -ENODEV if no platform device resources found
  1756. * or no space for remapping registers,
  1757. * -EINVAL if couldn't install ISR,
  1758. * or clk_get return error value.
  1759. */
  1760. static int isp_probe(struct platform_device *pdev)
  1761. {
  1762. struct isp_platform_data *pdata = pdev->dev.platform_data;
  1763. struct isp_device *isp;
  1764. int ret;
  1765. int i, m;
  1766. if (pdata == NULL)
  1767. return -EINVAL;
  1768. isp = kzalloc(sizeof(*isp), GFP_KERNEL);
  1769. if (!isp) {
  1770. dev_err(&pdev->dev, "could not allocate memory\n");
  1771. return -ENOMEM;
  1772. }
  1773. isp->autoidle = autoidle;
  1774. isp->platform_cb.set_xclk = isp_set_xclk;
  1775. isp->platform_cb.set_pixel_clock = isp_set_pixel_clock;
  1776. mutex_init(&isp->isp_mutex);
  1777. spin_lock_init(&isp->stat_lock);
  1778. isp->dev = &pdev->dev;
  1779. isp->pdata = pdata;
  1780. isp->ref_count = 0;
  1781. isp->raw_dmamask = DMA_BIT_MASK(32);
  1782. isp->dev->dma_mask = &isp->raw_dmamask;
  1783. isp->dev->coherent_dma_mask = DMA_BIT_MASK(32);
  1784. platform_set_drvdata(pdev, isp);
  1785. /* Regulators */
  1786. isp->isp_csiphy1.vdd = regulator_get(&pdev->dev, "VDD_CSIPHY1");
  1787. isp->isp_csiphy2.vdd = regulator_get(&pdev->dev, "VDD_CSIPHY2");
  1788. /* Clocks */
  1789. ret = isp_map_mem_resource(pdev, isp, OMAP3_ISP_IOMEM_MAIN);
  1790. if (ret < 0)
  1791. goto error;
  1792. ret = isp_get_clocks(isp);
  1793. if (ret < 0)
  1794. goto error;
  1795. if (omap3isp_get(isp) == NULL)
  1796. goto error;
  1797. ret = isp_reset(isp);
  1798. if (ret < 0)
  1799. goto error_isp;
  1800. /* Memory resources */
  1801. isp->revision = isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_REVISION);
  1802. dev_info(isp->dev, "Revision %d.%d found\n",
  1803. (isp->revision & 0xf0) >> 4, isp->revision & 0x0f);
  1804. for (m = 0; m < ARRAY_SIZE(isp_res_maps); m++)
  1805. if (isp->revision == isp_res_maps[m].isp_rev)
  1806. break;
  1807. if (m == ARRAY_SIZE(isp_res_maps)) {
  1808. dev_err(isp->dev, "No resource map found for ISP rev %d.%d\n",
  1809. (isp->revision & 0xf0) >> 4, isp->revision & 0xf);
  1810. ret = -ENODEV;
  1811. goto error_isp;
  1812. }
  1813. for (i = 1; i < OMAP3_ISP_IOMEM_LAST; i++) {
  1814. if (isp_res_maps[m].map & 1 << i) {
  1815. ret = isp_map_mem_resource(pdev, isp, i);
  1816. if (ret)
  1817. goto error_isp;
  1818. }
  1819. }
  1820. /* IOMMU */
  1821. isp->iommu_dev = omap_find_iommu_device("isp");
  1822. if (!isp->iommu_dev) {
  1823. dev_err(isp->dev, "omap_find_iommu_device failed\n");
  1824. ret = -ENODEV;
  1825. goto error_isp;
  1826. }
  1827. /* to be removed once iommu migration is complete */
  1828. isp->iommu = to_iommu(isp->iommu_dev);
  1829. isp->domain = iommu_domain_alloc(pdev->dev.bus);
  1830. if (!isp->domain) {
  1831. dev_err(isp->dev, "can't alloc iommu domain\n");
  1832. ret = -ENOMEM;
  1833. goto error_isp;
  1834. }
  1835. ret = iommu_attach_device(isp->domain, isp->iommu_dev);
  1836. if (ret) {
  1837. dev_err(&pdev->dev, "can't attach iommu device: %d\n", ret);
  1838. goto free_domain;
  1839. }
  1840. /* Interrupt */
  1841. isp->irq_num = platform_get_irq(pdev, 0);
  1842. if (isp->irq_num <= 0) {
  1843. dev_err(isp->dev, "No IRQ resource\n");
  1844. ret = -ENODEV;
  1845. goto detach_dev;
  1846. }
  1847. if (request_irq(isp->irq_num, isp_isr, IRQF_SHARED, "OMAP3 ISP", isp)) {
  1848. dev_err(isp->dev, "Unable to request IRQ\n");
  1849. ret = -EINVAL;
  1850. goto detach_dev;
  1851. }
  1852. /* Entities */
  1853. ret = isp_initialize_modules(isp);
  1854. if (ret < 0)
  1855. goto error_irq;
  1856. ret = isp_register_entities(isp);
  1857. if (ret < 0)
  1858. goto error_modules;
  1859. isp_power_settings(isp, 1);
  1860. omap3isp_put(isp);
  1861. return 0;
  1862. error_modules:
  1863. isp_cleanup_modules(isp);
  1864. error_irq:
  1865. free_irq(isp->irq_num, isp);
  1866. detach_dev:
  1867. iommu_detach_device(isp->domain, isp->iommu_dev);
  1868. free_domain:
  1869. iommu_domain_free(isp->domain);
  1870. error_isp:
  1871. omap3isp_put(isp);
  1872. error:
  1873. isp_put_clocks(isp);
  1874. for (i = 0; i < OMAP3_ISP_IOMEM_LAST; i++) {
  1875. if (isp->mmio_base[i]) {
  1876. iounmap(isp->mmio_base[i]);
  1877. isp->mmio_base[i] = NULL;
  1878. }
  1879. if (isp->mmio_base_phys[i]) {
  1880. release_mem_region(isp->mmio_base_phys[i],
  1881. isp->mmio_size[i]);
  1882. isp->mmio_base_phys[i] = 0;
  1883. }
  1884. }
  1885. regulator_put(isp->isp_csiphy2.vdd);
  1886. regulator_put(isp->isp_csiphy1.vdd);
  1887. platform_set_drvdata(pdev, NULL);
  1888. mutex_destroy(&isp->isp_mutex);
  1889. kfree(isp);
  1890. return ret;
  1891. }
  1892. static const struct dev_pm_ops omap3isp_pm_ops = {
  1893. .prepare = isp_pm_prepare,
  1894. .suspend = isp_pm_suspend,
  1895. .resume = isp_pm_resume,
  1896. .complete = isp_pm_complete,
  1897. };
  1898. static struct platform_device_id omap3isp_id_table[] = {
  1899. { "omap3isp", 0 },
  1900. { },
  1901. };
  1902. MODULE_DEVICE_TABLE(platform, omap3isp_id_table);
  1903. static struct platform_driver omap3isp_driver = {
  1904. .probe = isp_probe,
  1905. .remove = isp_remove,
  1906. .id_table = omap3isp_id_table,
  1907. .driver = {
  1908. .owner = THIS_MODULE,
  1909. .name = "omap3isp",
  1910. .pm = &omap3isp_pm_ops,
  1911. },
  1912. };
  1913. module_platform_driver(omap3isp_driver);
  1914. MODULE_AUTHOR("Nokia Corporation");
  1915. MODULE_DESCRIPTION("TI OMAP3 ISP driver");
  1916. MODULE_LICENSE("GPL");
  1917. MODULE_VERSION(ISP_VIDEO_DRIVER_VERSION);