isp.c 62 KB

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