ipu_idmac.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796
  1. /*
  2. * Copyright (C) 2008
  3. * Guennadi Liakhovetski, DENX Software Engineering, <lg@denx.de>
  4. *
  5. * Copyright (C) 2005-2007 Freescale Semiconductor, Inc. All Rights Reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/dma-mapping.h>
  12. #include <linux/init.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/err.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/delay.h>
  17. #include <linux/list.h>
  18. #include <linux/clk.h>
  19. #include <linux/vmalloc.h>
  20. #include <linux/string.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/io.h>
  23. #include <linux/module.h>
  24. #include <linux/dma/ipu-dma.h>
  25. #include "../dmaengine.h"
  26. #include "ipu_intern.h"
  27. #define FS_VF_IN_VALID 0x00000002
  28. #define FS_ENC_IN_VALID 0x00000001
  29. static int ipu_disable_channel(struct idmac *idmac, struct idmac_channel *ichan,
  30. bool wait_for_stop);
  31. /*
  32. * There can be only one, we could allocate it dynamically, but then we'd have
  33. * to add an extra parameter to some functions, and use something as ugly as
  34. * struct ipu *ipu = to_ipu(to_idmac(ichan->dma_chan.device));
  35. * in the ISR
  36. */
  37. static struct ipu ipu_data;
  38. #define to_ipu(id) container_of(id, struct ipu, idmac)
  39. static u32 __idmac_read_icreg(struct ipu *ipu, unsigned long reg)
  40. {
  41. return __raw_readl(ipu->reg_ic + reg);
  42. }
  43. #define idmac_read_icreg(ipu, reg) __idmac_read_icreg(ipu, reg - IC_CONF)
  44. static void __idmac_write_icreg(struct ipu *ipu, u32 value, unsigned long reg)
  45. {
  46. __raw_writel(value, ipu->reg_ic + reg);
  47. }
  48. #define idmac_write_icreg(ipu, v, reg) __idmac_write_icreg(ipu, v, reg - IC_CONF)
  49. static u32 idmac_read_ipureg(struct ipu *ipu, unsigned long reg)
  50. {
  51. return __raw_readl(ipu->reg_ipu + reg);
  52. }
  53. static void idmac_write_ipureg(struct ipu *ipu, u32 value, unsigned long reg)
  54. {
  55. __raw_writel(value, ipu->reg_ipu + reg);
  56. }
  57. /*****************************************************************************
  58. * IPU / IC common functions
  59. */
  60. static void dump_idmac_reg(struct ipu *ipu)
  61. {
  62. dev_dbg(ipu->dev, "IDMAC_CONF 0x%x, IC_CONF 0x%x, IDMAC_CHA_EN 0x%x, "
  63. "IDMAC_CHA_PRI 0x%x, IDMAC_CHA_BUSY 0x%x\n",
  64. idmac_read_icreg(ipu, IDMAC_CONF),
  65. idmac_read_icreg(ipu, IC_CONF),
  66. idmac_read_icreg(ipu, IDMAC_CHA_EN),
  67. idmac_read_icreg(ipu, IDMAC_CHA_PRI),
  68. idmac_read_icreg(ipu, IDMAC_CHA_BUSY));
  69. dev_dbg(ipu->dev, "BUF0_RDY 0x%x, BUF1_RDY 0x%x, CUR_BUF 0x%x, "
  70. "DB_MODE 0x%x, TASKS_STAT 0x%x\n",
  71. idmac_read_ipureg(ipu, IPU_CHA_BUF0_RDY),
  72. idmac_read_ipureg(ipu, IPU_CHA_BUF1_RDY),
  73. idmac_read_ipureg(ipu, IPU_CHA_CUR_BUF),
  74. idmac_read_ipureg(ipu, IPU_CHA_DB_MODE_SEL),
  75. idmac_read_ipureg(ipu, IPU_TASKS_STAT));
  76. }
  77. static uint32_t bytes_per_pixel(enum pixel_fmt fmt)
  78. {
  79. switch (fmt) {
  80. case IPU_PIX_FMT_GENERIC: /* generic data */
  81. case IPU_PIX_FMT_RGB332:
  82. case IPU_PIX_FMT_YUV420P:
  83. case IPU_PIX_FMT_YUV422P:
  84. default:
  85. return 1;
  86. case IPU_PIX_FMT_RGB565:
  87. case IPU_PIX_FMT_YUYV:
  88. case IPU_PIX_FMT_UYVY:
  89. return 2;
  90. case IPU_PIX_FMT_BGR24:
  91. case IPU_PIX_FMT_RGB24:
  92. return 3;
  93. case IPU_PIX_FMT_GENERIC_32: /* generic data */
  94. case IPU_PIX_FMT_BGR32:
  95. case IPU_PIX_FMT_RGB32:
  96. case IPU_PIX_FMT_ABGR32:
  97. return 4;
  98. }
  99. }
  100. /* Enable direct write to memory by the Camera Sensor Interface */
  101. static void ipu_ic_enable_task(struct ipu *ipu, enum ipu_channel channel)
  102. {
  103. uint32_t ic_conf, mask;
  104. switch (channel) {
  105. case IDMAC_IC_0:
  106. mask = IC_CONF_PRPENC_EN;
  107. break;
  108. case IDMAC_IC_7:
  109. mask = IC_CONF_RWS_EN | IC_CONF_PRPENC_EN;
  110. break;
  111. default:
  112. return;
  113. }
  114. ic_conf = idmac_read_icreg(ipu, IC_CONF) | mask;
  115. idmac_write_icreg(ipu, ic_conf, IC_CONF);
  116. }
  117. /* Called under spin_lock_irqsave(&ipu_data.lock) */
  118. static void ipu_ic_disable_task(struct ipu *ipu, enum ipu_channel channel)
  119. {
  120. uint32_t ic_conf, mask;
  121. switch (channel) {
  122. case IDMAC_IC_0:
  123. mask = IC_CONF_PRPENC_EN;
  124. break;
  125. case IDMAC_IC_7:
  126. mask = IC_CONF_RWS_EN | IC_CONF_PRPENC_EN;
  127. break;
  128. default:
  129. return;
  130. }
  131. ic_conf = idmac_read_icreg(ipu, IC_CONF) & ~mask;
  132. idmac_write_icreg(ipu, ic_conf, IC_CONF);
  133. }
  134. static uint32_t ipu_channel_status(struct ipu *ipu, enum ipu_channel channel)
  135. {
  136. uint32_t stat = TASK_STAT_IDLE;
  137. uint32_t task_stat_reg = idmac_read_ipureg(ipu, IPU_TASKS_STAT);
  138. switch (channel) {
  139. case IDMAC_IC_7:
  140. stat = (task_stat_reg & TSTAT_CSI2MEM_MASK) >>
  141. TSTAT_CSI2MEM_OFFSET;
  142. break;
  143. case IDMAC_IC_0:
  144. case IDMAC_SDC_0:
  145. case IDMAC_SDC_1:
  146. default:
  147. break;
  148. }
  149. return stat;
  150. }
  151. struct chan_param_mem_planar {
  152. /* Word 0 */
  153. u32 xv:10;
  154. u32 yv:10;
  155. u32 xb:12;
  156. u32 yb:12;
  157. u32 res1:2;
  158. u32 nsb:1;
  159. u32 lnpb:6;
  160. u32 ubo_l:11;
  161. u32 ubo_h:15;
  162. u32 vbo_l:17;
  163. u32 vbo_h:9;
  164. u32 res2:3;
  165. u32 fw:12;
  166. u32 fh_l:8;
  167. u32 fh_h:4;
  168. u32 res3:28;
  169. /* Word 1 */
  170. u32 eba0;
  171. u32 eba1;
  172. u32 bpp:3;
  173. u32 sl:14;
  174. u32 pfs:3;
  175. u32 bam:3;
  176. u32 res4:2;
  177. u32 npb:6;
  178. u32 res5:1;
  179. u32 sat:2;
  180. u32 res6:30;
  181. } __attribute__ ((packed));
  182. struct chan_param_mem_interleaved {
  183. /* Word 0 */
  184. u32 xv:10;
  185. u32 yv:10;
  186. u32 xb:12;
  187. u32 yb:12;
  188. u32 sce:1;
  189. u32 res1:1;
  190. u32 nsb:1;
  191. u32 lnpb:6;
  192. u32 sx:10;
  193. u32 sy_l:1;
  194. u32 sy_h:9;
  195. u32 ns:10;
  196. u32 sm:10;
  197. u32 sdx_l:3;
  198. u32 sdx_h:2;
  199. u32 sdy:5;
  200. u32 sdrx:1;
  201. u32 sdry:1;
  202. u32 sdr1:1;
  203. u32 res2:2;
  204. u32 fw:12;
  205. u32 fh_l:8;
  206. u32 fh_h:4;
  207. u32 res3:28;
  208. /* Word 1 */
  209. u32 eba0;
  210. u32 eba1;
  211. u32 bpp:3;
  212. u32 sl:14;
  213. u32 pfs:3;
  214. u32 bam:3;
  215. u32 res4:2;
  216. u32 npb:6;
  217. u32 res5:1;
  218. u32 sat:2;
  219. u32 scc:1;
  220. u32 ofs0:5;
  221. u32 ofs1:5;
  222. u32 ofs2:5;
  223. u32 ofs3:5;
  224. u32 wid0:3;
  225. u32 wid1:3;
  226. u32 wid2:3;
  227. u32 wid3:3;
  228. u32 dec_sel:1;
  229. u32 res6:28;
  230. } __attribute__ ((packed));
  231. union chan_param_mem {
  232. struct chan_param_mem_planar pp;
  233. struct chan_param_mem_interleaved ip;
  234. };
  235. static void ipu_ch_param_set_plane_offset(union chan_param_mem *params,
  236. u32 u_offset, u32 v_offset)
  237. {
  238. params->pp.ubo_l = u_offset & 0x7ff;
  239. params->pp.ubo_h = u_offset >> 11;
  240. params->pp.vbo_l = v_offset & 0x1ffff;
  241. params->pp.vbo_h = v_offset >> 17;
  242. }
  243. static void ipu_ch_param_set_size(union chan_param_mem *params,
  244. uint32_t pixel_fmt, uint16_t width,
  245. uint16_t height, uint16_t stride)
  246. {
  247. u32 u_offset;
  248. u32 v_offset;
  249. params->pp.fw = width - 1;
  250. params->pp.fh_l = height - 1;
  251. params->pp.fh_h = (height - 1) >> 8;
  252. params->pp.sl = stride - 1;
  253. switch (pixel_fmt) {
  254. case IPU_PIX_FMT_GENERIC:
  255. /*Represents 8-bit Generic data */
  256. params->pp.bpp = 3;
  257. params->pp.pfs = 7;
  258. params->pp.npb = 31;
  259. params->pp.sat = 2; /* SAT = use 32-bit access */
  260. break;
  261. case IPU_PIX_FMT_GENERIC_32:
  262. /*Represents 32-bit Generic data */
  263. params->pp.bpp = 0;
  264. params->pp.pfs = 7;
  265. params->pp.npb = 7;
  266. params->pp.sat = 2; /* SAT = use 32-bit access */
  267. break;
  268. case IPU_PIX_FMT_RGB565:
  269. params->ip.bpp = 2;
  270. params->ip.pfs = 4;
  271. params->ip.npb = 15;
  272. params->ip.sat = 2; /* SAT = 32-bit access */
  273. params->ip.ofs0 = 0; /* Red bit offset */
  274. params->ip.ofs1 = 5; /* Green bit offset */
  275. params->ip.ofs2 = 11; /* Blue bit offset */
  276. params->ip.ofs3 = 16; /* Alpha bit offset */
  277. params->ip.wid0 = 4; /* Red bit width - 1 */
  278. params->ip.wid1 = 5; /* Green bit width - 1 */
  279. params->ip.wid2 = 4; /* Blue bit width - 1 */
  280. break;
  281. case IPU_PIX_FMT_BGR24:
  282. params->ip.bpp = 1; /* 24 BPP & RGB PFS */
  283. params->ip.pfs = 4;
  284. params->ip.npb = 7;
  285. params->ip.sat = 2; /* SAT = 32-bit access */
  286. params->ip.ofs0 = 0; /* Red bit offset */
  287. params->ip.ofs1 = 8; /* Green bit offset */
  288. params->ip.ofs2 = 16; /* Blue bit offset */
  289. params->ip.ofs3 = 24; /* Alpha bit offset */
  290. params->ip.wid0 = 7; /* Red bit width - 1 */
  291. params->ip.wid1 = 7; /* Green bit width - 1 */
  292. params->ip.wid2 = 7; /* Blue bit width - 1 */
  293. break;
  294. case IPU_PIX_FMT_RGB24:
  295. params->ip.bpp = 1; /* 24 BPP & RGB PFS */
  296. params->ip.pfs = 4;
  297. params->ip.npb = 7;
  298. params->ip.sat = 2; /* SAT = 32-bit access */
  299. params->ip.ofs0 = 16; /* Red bit offset */
  300. params->ip.ofs1 = 8; /* Green bit offset */
  301. params->ip.ofs2 = 0; /* Blue bit offset */
  302. params->ip.ofs3 = 24; /* Alpha bit offset */
  303. params->ip.wid0 = 7; /* Red bit width - 1 */
  304. params->ip.wid1 = 7; /* Green bit width - 1 */
  305. params->ip.wid2 = 7; /* Blue bit width - 1 */
  306. break;
  307. case IPU_PIX_FMT_BGRA32:
  308. case IPU_PIX_FMT_BGR32:
  309. case IPU_PIX_FMT_ABGR32:
  310. params->ip.bpp = 0;
  311. params->ip.pfs = 4;
  312. params->ip.npb = 7;
  313. params->ip.sat = 2; /* SAT = 32-bit access */
  314. params->ip.ofs0 = 8; /* Red bit offset */
  315. params->ip.ofs1 = 16; /* Green bit offset */
  316. params->ip.ofs2 = 24; /* Blue bit offset */
  317. params->ip.ofs3 = 0; /* Alpha bit offset */
  318. params->ip.wid0 = 7; /* Red bit width - 1 */
  319. params->ip.wid1 = 7; /* Green bit width - 1 */
  320. params->ip.wid2 = 7; /* Blue bit width - 1 */
  321. params->ip.wid3 = 7; /* Alpha bit width - 1 */
  322. break;
  323. case IPU_PIX_FMT_RGBA32:
  324. case IPU_PIX_FMT_RGB32:
  325. params->ip.bpp = 0;
  326. params->ip.pfs = 4;
  327. params->ip.npb = 7;
  328. params->ip.sat = 2; /* SAT = 32-bit access */
  329. params->ip.ofs0 = 24; /* Red bit offset */
  330. params->ip.ofs1 = 16; /* Green bit offset */
  331. params->ip.ofs2 = 8; /* Blue bit offset */
  332. params->ip.ofs3 = 0; /* Alpha bit offset */
  333. params->ip.wid0 = 7; /* Red bit width - 1 */
  334. params->ip.wid1 = 7; /* Green bit width - 1 */
  335. params->ip.wid2 = 7; /* Blue bit width - 1 */
  336. params->ip.wid3 = 7; /* Alpha bit width - 1 */
  337. break;
  338. case IPU_PIX_FMT_UYVY:
  339. params->ip.bpp = 2;
  340. params->ip.pfs = 6;
  341. params->ip.npb = 7;
  342. params->ip.sat = 2; /* SAT = 32-bit access */
  343. break;
  344. case IPU_PIX_FMT_YUV420P2:
  345. case IPU_PIX_FMT_YUV420P:
  346. params->ip.bpp = 3;
  347. params->ip.pfs = 3;
  348. params->ip.npb = 7;
  349. params->ip.sat = 2; /* SAT = 32-bit access */
  350. u_offset = stride * height;
  351. v_offset = u_offset + u_offset / 4;
  352. ipu_ch_param_set_plane_offset(params, u_offset, v_offset);
  353. break;
  354. case IPU_PIX_FMT_YVU422P:
  355. params->ip.bpp = 3;
  356. params->ip.pfs = 2;
  357. params->ip.npb = 7;
  358. params->ip.sat = 2; /* SAT = 32-bit access */
  359. v_offset = stride * height;
  360. u_offset = v_offset + v_offset / 2;
  361. ipu_ch_param_set_plane_offset(params, u_offset, v_offset);
  362. break;
  363. case IPU_PIX_FMT_YUV422P:
  364. params->ip.bpp = 3;
  365. params->ip.pfs = 2;
  366. params->ip.npb = 7;
  367. params->ip.sat = 2; /* SAT = 32-bit access */
  368. u_offset = stride * height;
  369. v_offset = u_offset + u_offset / 2;
  370. ipu_ch_param_set_plane_offset(params, u_offset, v_offset);
  371. break;
  372. default:
  373. dev_err(ipu_data.dev,
  374. "mx3 ipu: unimplemented pixel format %d\n", pixel_fmt);
  375. break;
  376. }
  377. params->pp.nsb = 1;
  378. }
  379. static void ipu_ch_param_set_buffer(union chan_param_mem *params,
  380. dma_addr_t buf0, dma_addr_t buf1)
  381. {
  382. params->pp.eba0 = buf0;
  383. params->pp.eba1 = buf1;
  384. }
  385. static void ipu_ch_param_set_rotation(union chan_param_mem *params,
  386. enum ipu_rotate_mode rotate)
  387. {
  388. params->pp.bam = rotate;
  389. }
  390. static void ipu_write_param_mem(uint32_t addr, uint32_t *data,
  391. uint32_t num_words)
  392. {
  393. for (; num_words > 0; num_words--) {
  394. dev_dbg(ipu_data.dev,
  395. "write param mem - addr = 0x%08X, data = 0x%08X\n",
  396. addr, *data);
  397. idmac_write_ipureg(&ipu_data, addr, IPU_IMA_ADDR);
  398. idmac_write_ipureg(&ipu_data, *data++, IPU_IMA_DATA);
  399. addr++;
  400. if ((addr & 0x7) == 5) {
  401. addr &= ~0x7; /* set to word 0 */
  402. addr += 8; /* increment to next row */
  403. }
  404. }
  405. }
  406. static int calc_resize_coeffs(uint32_t in_size, uint32_t out_size,
  407. uint32_t *resize_coeff,
  408. uint32_t *downsize_coeff)
  409. {
  410. uint32_t temp_size;
  411. uint32_t temp_downsize;
  412. *resize_coeff = 1 << 13;
  413. *downsize_coeff = 1 << 13;
  414. /* Cannot downsize more than 8:1 */
  415. if (out_size << 3 < in_size)
  416. return -EINVAL;
  417. /* compute downsizing coefficient */
  418. temp_downsize = 0;
  419. temp_size = in_size;
  420. while (temp_size >= out_size * 2 && temp_downsize < 2) {
  421. temp_size >>= 1;
  422. temp_downsize++;
  423. }
  424. *downsize_coeff = temp_downsize;
  425. /*
  426. * compute resizing coefficient using the following formula:
  427. * resize_coeff = M*(SI -1)/(SO - 1)
  428. * where M = 2^13, SI - input size, SO - output size
  429. */
  430. *resize_coeff = (8192L * (temp_size - 1)) / (out_size - 1);
  431. if (*resize_coeff >= 16384L) {
  432. dev_err(ipu_data.dev, "Warning! Overflow on resize coeff.\n");
  433. *resize_coeff = 0x3FFF;
  434. }
  435. dev_dbg(ipu_data.dev, "resizing from %u -> %u pixels, "
  436. "downsize=%u, resize=%u.%lu (reg=%u)\n", in_size, out_size,
  437. *downsize_coeff, *resize_coeff >= 8192L ? 1 : 0,
  438. ((*resize_coeff & 0x1FFF) * 10000L) / 8192L, *resize_coeff);
  439. return 0;
  440. }
  441. static enum ipu_color_space format_to_colorspace(enum pixel_fmt fmt)
  442. {
  443. switch (fmt) {
  444. case IPU_PIX_FMT_RGB565:
  445. case IPU_PIX_FMT_BGR24:
  446. case IPU_PIX_FMT_RGB24:
  447. case IPU_PIX_FMT_BGR32:
  448. case IPU_PIX_FMT_RGB32:
  449. return IPU_COLORSPACE_RGB;
  450. default:
  451. return IPU_COLORSPACE_YCBCR;
  452. }
  453. }
  454. static int ipu_ic_init_prpenc(struct ipu *ipu,
  455. union ipu_channel_param *params, bool src_is_csi)
  456. {
  457. uint32_t reg, ic_conf;
  458. uint32_t downsize_coeff, resize_coeff;
  459. enum ipu_color_space in_fmt, out_fmt;
  460. /* Setup vertical resizing */
  461. calc_resize_coeffs(params->video.in_height,
  462. params->video.out_height,
  463. &resize_coeff, &downsize_coeff);
  464. reg = (downsize_coeff << 30) | (resize_coeff << 16);
  465. /* Setup horizontal resizing */
  466. calc_resize_coeffs(params->video.in_width,
  467. params->video.out_width,
  468. &resize_coeff, &downsize_coeff);
  469. reg |= (downsize_coeff << 14) | resize_coeff;
  470. /* Setup color space conversion */
  471. in_fmt = format_to_colorspace(params->video.in_pixel_fmt);
  472. out_fmt = format_to_colorspace(params->video.out_pixel_fmt);
  473. /*
  474. * Colourspace conversion unsupported yet - see _init_csc() in
  475. * Freescale sources
  476. */
  477. if (in_fmt != out_fmt) {
  478. dev_err(ipu->dev, "Colourspace conversion unsupported!\n");
  479. return -EOPNOTSUPP;
  480. }
  481. idmac_write_icreg(ipu, reg, IC_PRP_ENC_RSC);
  482. ic_conf = idmac_read_icreg(ipu, IC_CONF);
  483. if (src_is_csi)
  484. ic_conf &= ~IC_CONF_RWS_EN;
  485. else
  486. ic_conf |= IC_CONF_RWS_EN;
  487. idmac_write_icreg(ipu, ic_conf, IC_CONF);
  488. return 0;
  489. }
  490. static uint32_t dma_param_addr(uint32_t dma_ch)
  491. {
  492. /* Channel Parameter Memory */
  493. return 0x10000 | (dma_ch << 4);
  494. }
  495. static void ipu_channel_set_priority(struct ipu *ipu, enum ipu_channel channel,
  496. bool prio)
  497. {
  498. u32 reg = idmac_read_icreg(ipu, IDMAC_CHA_PRI);
  499. if (prio)
  500. reg |= 1UL << channel;
  501. else
  502. reg &= ~(1UL << channel);
  503. idmac_write_icreg(ipu, reg, IDMAC_CHA_PRI);
  504. dump_idmac_reg(ipu);
  505. }
  506. static uint32_t ipu_channel_conf_mask(enum ipu_channel channel)
  507. {
  508. uint32_t mask;
  509. switch (channel) {
  510. case IDMAC_IC_0:
  511. case IDMAC_IC_7:
  512. mask = IPU_CONF_CSI_EN | IPU_CONF_IC_EN;
  513. break;
  514. case IDMAC_SDC_0:
  515. case IDMAC_SDC_1:
  516. mask = IPU_CONF_SDC_EN | IPU_CONF_DI_EN;
  517. break;
  518. default:
  519. mask = 0;
  520. break;
  521. }
  522. return mask;
  523. }
  524. /**
  525. * ipu_enable_channel() - enable an IPU channel.
  526. * @idmac: IPU DMAC context.
  527. * @ichan: IDMAC channel.
  528. * @return: 0 on success or negative error code on failure.
  529. */
  530. static int ipu_enable_channel(struct idmac *idmac, struct idmac_channel *ichan)
  531. {
  532. struct ipu *ipu = to_ipu(idmac);
  533. enum ipu_channel channel = ichan->dma_chan.chan_id;
  534. uint32_t reg;
  535. unsigned long flags;
  536. spin_lock_irqsave(&ipu->lock, flags);
  537. /* Reset to buffer 0 */
  538. idmac_write_ipureg(ipu, 1UL << channel, IPU_CHA_CUR_BUF);
  539. ichan->active_buffer = 0;
  540. ichan->status = IPU_CHANNEL_ENABLED;
  541. switch (channel) {
  542. case IDMAC_SDC_0:
  543. case IDMAC_SDC_1:
  544. case IDMAC_IC_7:
  545. ipu_channel_set_priority(ipu, channel, true);
  546. default:
  547. break;
  548. }
  549. reg = idmac_read_icreg(ipu, IDMAC_CHA_EN);
  550. idmac_write_icreg(ipu, reg | (1UL << channel), IDMAC_CHA_EN);
  551. ipu_ic_enable_task(ipu, channel);
  552. spin_unlock_irqrestore(&ipu->lock, flags);
  553. return 0;
  554. }
  555. /**
  556. * ipu_init_channel_buffer() - initialize a buffer for logical IPU channel.
  557. * @ichan: IDMAC channel.
  558. * @pixel_fmt: pixel format of buffer. Pixel format is a FOURCC ASCII code.
  559. * @width: width of buffer in pixels.
  560. * @height: height of buffer in pixels.
  561. * @stride: stride length of buffer in pixels.
  562. * @rot_mode: rotation mode of buffer. A rotation setting other than
  563. * IPU_ROTATE_VERT_FLIP should only be used for input buffers of
  564. * rotation channels.
  565. * @phyaddr_0: buffer 0 physical address.
  566. * @phyaddr_1: buffer 1 physical address. Setting this to a value other than
  567. * NULL enables double buffering mode.
  568. * @return: 0 on success or negative error code on failure.
  569. */
  570. static int ipu_init_channel_buffer(struct idmac_channel *ichan,
  571. enum pixel_fmt pixel_fmt,
  572. uint16_t width, uint16_t height,
  573. uint32_t stride,
  574. enum ipu_rotate_mode rot_mode,
  575. dma_addr_t phyaddr_0, dma_addr_t phyaddr_1)
  576. {
  577. enum ipu_channel channel = ichan->dma_chan.chan_id;
  578. struct idmac *idmac = to_idmac(ichan->dma_chan.device);
  579. struct ipu *ipu = to_ipu(idmac);
  580. union chan_param_mem params = {};
  581. unsigned long flags;
  582. uint32_t reg;
  583. uint32_t stride_bytes;
  584. stride_bytes = stride * bytes_per_pixel(pixel_fmt);
  585. if (stride_bytes % 4) {
  586. dev_err(ipu->dev,
  587. "Stride length must be 32-bit aligned, stride = %d, bytes = %d\n",
  588. stride, stride_bytes);
  589. return -EINVAL;
  590. }
  591. /* IC channel's stride must be a multiple of 8 pixels */
  592. if ((channel <= IDMAC_IC_13) && (stride % 8)) {
  593. dev_err(ipu->dev, "Stride must be 8 pixel multiple\n");
  594. return -EINVAL;
  595. }
  596. /* Build parameter memory data for DMA channel */
  597. ipu_ch_param_set_size(&params, pixel_fmt, width, height, stride_bytes);
  598. ipu_ch_param_set_buffer(&params, phyaddr_0, phyaddr_1);
  599. ipu_ch_param_set_rotation(&params, rot_mode);
  600. spin_lock_irqsave(&ipu->lock, flags);
  601. ipu_write_param_mem(dma_param_addr(channel), (uint32_t *)&params, 10);
  602. reg = idmac_read_ipureg(ipu, IPU_CHA_DB_MODE_SEL);
  603. if (phyaddr_1)
  604. reg |= 1UL << channel;
  605. else
  606. reg &= ~(1UL << channel);
  607. idmac_write_ipureg(ipu, reg, IPU_CHA_DB_MODE_SEL);
  608. ichan->status = IPU_CHANNEL_READY;
  609. spin_unlock_irqrestore(&ipu->lock, flags);
  610. return 0;
  611. }
  612. /**
  613. * ipu_select_buffer() - mark a channel's buffer as ready.
  614. * @channel: channel ID.
  615. * @buffer_n: buffer number to mark ready.
  616. */
  617. static void ipu_select_buffer(enum ipu_channel channel, int buffer_n)
  618. {
  619. /* No locking - this is a write-one-to-set register, cleared by IPU */
  620. if (buffer_n == 0)
  621. /* Mark buffer 0 as ready. */
  622. idmac_write_ipureg(&ipu_data, 1UL << channel, IPU_CHA_BUF0_RDY);
  623. else
  624. /* Mark buffer 1 as ready. */
  625. idmac_write_ipureg(&ipu_data, 1UL << channel, IPU_CHA_BUF1_RDY);
  626. }
  627. /**
  628. * ipu_update_channel_buffer() - update physical address of a channel buffer.
  629. * @ichan: IDMAC channel.
  630. * @buffer_n: buffer number to update.
  631. * 0 or 1 are the only valid values.
  632. * @phyaddr: buffer physical address.
  633. */
  634. /* Called under spin_lock(_irqsave)(&ichan->lock) */
  635. static void ipu_update_channel_buffer(struct idmac_channel *ichan,
  636. int buffer_n, dma_addr_t phyaddr)
  637. {
  638. enum ipu_channel channel = ichan->dma_chan.chan_id;
  639. uint32_t reg;
  640. unsigned long flags;
  641. spin_lock_irqsave(&ipu_data.lock, flags);
  642. if (buffer_n == 0) {
  643. reg = idmac_read_ipureg(&ipu_data, IPU_CHA_BUF0_RDY);
  644. if (reg & (1UL << channel)) {
  645. ipu_ic_disable_task(&ipu_data, channel);
  646. ichan->status = IPU_CHANNEL_READY;
  647. }
  648. /* 44.3.3.1.9 - Row Number 1 (WORD1, offset 0) */
  649. idmac_write_ipureg(&ipu_data, dma_param_addr(channel) +
  650. 0x0008UL, IPU_IMA_ADDR);
  651. idmac_write_ipureg(&ipu_data, phyaddr, IPU_IMA_DATA);
  652. } else {
  653. reg = idmac_read_ipureg(&ipu_data, IPU_CHA_BUF1_RDY);
  654. if (reg & (1UL << channel)) {
  655. ipu_ic_disable_task(&ipu_data, channel);
  656. ichan->status = IPU_CHANNEL_READY;
  657. }
  658. /* Check if double-buffering is already enabled */
  659. reg = idmac_read_ipureg(&ipu_data, IPU_CHA_DB_MODE_SEL);
  660. if (!(reg & (1UL << channel)))
  661. idmac_write_ipureg(&ipu_data, reg | (1UL << channel),
  662. IPU_CHA_DB_MODE_SEL);
  663. /* 44.3.3.1.9 - Row Number 1 (WORD1, offset 1) */
  664. idmac_write_ipureg(&ipu_data, dma_param_addr(channel) +
  665. 0x0009UL, IPU_IMA_ADDR);
  666. idmac_write_ipureg(&ipu_data, phyaddr, IPU_IMA_DATA);
  667. }
  668. spin_unlock_irqrestore(&ipu_data.lock, flags);
  669. }
  670. /* Called under spin_lock_irqsave(&ichan->lock) */
  671. static int ipu_submit_buffer(struct idmac_channel *ichan,
  672. struct idmac_tx_desc *desc, struct scatterlist *sg, int buf_idx)
  673. {
  674. unsigned int chan_id = ichan->dma_chan.chan_id;
  675. struct device *dev = &ichan->dma_chan.dev->device;
  676. if (async_tx_test_ack(&desc->txd))
  677. return -EINTR;
  678. /*
  679. * On first invocation this shouldn't be necessary, the call to
  680. * ipu_init_channel_buffer() above will set addresses for us, so we
  681. * could make it conditional on status >= IPU_CHANNEL_ENABLED, but
  682. * doing it again shouldn't hurt either.
  683. */
  684. ipu_update_channel_buffer(ichan, buf_idx, sg_dma_address(sg));
  685. ipu_select_buffer(chan_id, buf_idx);
  686. dev_dbg(dev, "Updated sg %p on channel 0x%x buffer %d\n",
  687. sg, chan_id, buf_idx);
  688. return 0;
  689. }
  690. /* Called under spin_lock_irqsave(&ichan->lock) */
  691. static int ipu_submit_channel_buffers(struct idmac_channel *ichan,
  692. struct idmac_tx_desc *desc)
  693. {
  694. struct scatterlist *sg;
  695. int i, ret = 0;
  696. for (i = 0, sg = desc->sg; i < 2 && sg; i++) {
  697. if (!ichan->sg[i]) {
  698. ichan->sg[i] = sg;
  699. ret = ipu_submit_buffer(ichan, desc, sg, i);
  700. if (ret < 0)
  701. return ret;
  702. sg = sg_next(sg);
  703. }
  704. }
  705. return ret;
  706. }
  707. static dma_cookie_t idmac_tx_submit(struct dma_async_tx_descriptor *tx)
  708. {
  709. struct idmac_tx_desc *desc = to_tx_desc(tx);
  710. struct idmac_channel *ichan = to_idmac_chan(tx->chan);
  711. struct idmac *idmac = to_idmac(tx->chan->device);
  712. struct ipu *ipu = to_ipu(idmac);
  713. struct device *dev = &ichan->dma_chan.dev->device;
  714. dma_cookie_t cookie;
  715. unsigned long flags;
  716. int ret;
  717. /* Sanity check */
  718. if (!list_empty(&desc->list)) {
  719. /* The descriptor doesn't belong to client */
  720. dev_err(dev, "Descriptor %p not prepared!\n", tx);
  721. return -EBUSY;
  722. }
  723. mutex_lock(&ichan->chan_mutex);
  724. async_tx_clear_ack(tx);
  725. if (ichan->status < IPU_CHANNEL_READY) {
  726. struct idmac_video_param *video = &ichan->params.video;
  727. /*
  728. * Initial buffer assignment - the first two sg-entries from
  729. * the descriptor will end up in the IDMAC buffers
  730. */
  731. dma_addr_t dma_1 = sg_is_last(desc->sg) ? 0 :
  732. sg_dma_address(&desc->sg[1]);
  733. WARN_ON(ichan->sg[0] || ichan->sg[1]);
  734. cookie = ipu_init_channel_buffer(ichan,
  735. video->out_pixel_fmt,
  736. video->out_width,
  737. video->out_height,
  738. video->out_stride,
  739. IPU_ROTATE_NONE,
  740. sg_dma_address(&desc->sg[0]),
  741. dma_1);
  742. if (cookie < 0)
  743. goto out;
  744. }
  745. dev_dbg(dev, "Submitting sg %p\n", &desc->sg[0]);
  746. cookie = dma_cookie_assign(tx);
  747. /* ipu->lock can be taken under ichan->lock, but not v.v. */
  748. spin_lock_irqsave(&ichan->lock, flags);
  749. list_add_tail(&desc->list, &ichan->queue);
  750. /* submit_buffers() atomically verifies and fills empty sg slots */
  751. ret = ipu_submit_channel_buffers(ichan, desc);
  752. spin_unlock_irqrestore(&ichan->lock, flags);
  753. if (ret < 0) {
  754. cookie = ret;
  755. goto dequeue;
  756. }
  757. if (ichan->status < IPU_CHANNEL_ENABLED) {
  758. ret = ipu_enable_channel(idmac, ichan);
  759. if (ret < 0) {
  760. cookie = ret;
  761. goto dequeue;
  762. }
  763. }
  764. dump_idmac_reg(ipu);
  765. dequeue:
  766. if (cookie < 0) {
  767. spin_lock_irqsave(&ichan->lock, flags);
  768. list_del_init(&desc->list);
  769. spin_unlock_irqrestore(&ichan->lock, flags);
  770. tx->cookie = cookie;
  771. ichan->dma_chan.cookie = cookie;
  772. }
  773. out:
  774. mutex_unlock(&ichan->chan_mutex);
  775. return cookie;
  776. }
  777. /* Called with ichan->chan_mutex held */
  778. static int idmac_desc_alloc(struct idmac_channel *ichan, int n)
  779. {
  780. struct idmac_tx_desc *desc = vmalloc(n * sizeof(struct idmac_tx_desc));
  781. struct idmac *idmac = to_idmac(ichan->dma_chan.device);
  782. if (!desc)
  783. return -ENOMEM;
  784. /* No interrupts, just disable the tasklet for a moment */
  785. tasklet_disable(&to_ipu(idmac)->tasklet);
  786. ichan->n_tx_desc = n;
  787. ichan->desc = desc;
  788. INIT_LIST_HEAD(&ichan->queue);
  789. INIT_LIST_HEAD(&ichan->free_list);
  790. while (n--) {
  791. struct dma_async_tx_descriptor *txd = &desc->txd;
  792. memset(txd, 0, sizeof(*txd));
  793. dma_async_tx_descriptor_init(txd, &ichan->dma_chan);
  794. txd->tx_submit = idmac_tx_submit;
  795. list_add(&desc->list, &ichan->free_list);
  796. desc++;
  797. }
  798. tasklet_enable(&to_ipu(idmac)->tasklet);
  799. return 0;
  800. }
  801. /**
  802. * ipu_init_channel() - initialize an IPU channel.
  803. * @idmac: IPU DMAC context.
  804. * @ichan: pointer to the channel object.
  805. * @return 0 on success or negative error code on failure.
  806. */
  807. static int ipu_init_channel(struct idmac *idmac, struct idmac_channel *ichan)
  808. {
  809. union ipu_channel_param *params = &ichan->params;
  810. uint32_t ipu_conf;
  811. enum ipu_channel channel = ichan->dma_chan.chan_id;
  812. unsigned long flags;
  813. uint32_t reg;
  814. struct ipu *ipu = to_ipu(idmac);
  815. int ret = 0, n_desc = 0;
  816. dev_dbg(ipu->dev, "init channel = %d\n", channel);
  817. if (channel != IDMAC_SDC_0 && channel != IDMAC_SDC_1 &&
  818. channel != IDMAC_IC_7)
  819. return -EINVAL;
  820. spin_lock_irqsave(&ipu->lock, flags);
  821. switch (channel) {
  822. case IDMAC_IC_7:
  823. n_desc = 16;
  824. reg = idmac_read_icreg(ipu, IC_CONF);
  825. idmac_write_icreg(ipu, reg & ~IC_CONF_CSI_MEM_WR_EN, IC_CONF);
  826. break;
  827. case IDMAC_IC_0:
  828. n_desc = 16;
  829. reg = idmac_read_ipureg(ipu, IPU_FS_PROC_FLOW);
  830. idmac_write_ipureg(ipu, reg & ~FS_ENC_IN_VALID, IPU_FS_PROC_FLOW);
  831. ret = ipu_ic_init_prpenc(ipu, params, true);
  832. break;
  833. case IDMAC_SDC_0:
  834. case IDMAC_SDC_1:
  835. n_desc = 4;
  836. default:
  837. break;
  838. }
  839. ipu->channel_init_mask |= 1L << channel;
  840. /* Enable IPU sub module */
  841. ipu_conf = idmac_read_ipureg(ipu, IPU_CONF) |
  842. ipu_channel_conf_mask(channel);
  843. idmac_write_ipureg(ipu, ipu_conf, IPU_CONF);
  844. spin_unlock_irqrestore(&ipu->lock, flags);
  845. if (n_desc && !ichan->desc)
  846. ret = idmac_desc_alloc(ichan, n_desc);
  847. dump_idmac_reg(ipu);
  848. return ret;
  849. }
  850. /**
  851. * ipu_uninit_channel() - uninitialize an IPU channel.
  852. * @idmac: IPU DMAC context.
  853. * @ichan: pointer to the channel object.
  854. */
  855. static void ipu_uninit_channel(struct idmac *idmac, struct idmac_channel *ichan)
  856. {
  857. enum ipu_channel channel = ichan->dma_chan.chan_id;
  858. unsigned long flags;
  859. uint32_t reg;
  860. unsigned long chan_mask = 1UL << channel;
  861. uint32_t ipu_conf;
  862. struct ipu *ipu = to_ipu(idmac);
  863. spin_lock_irqsave(&ipu->lock, flags);
  864. if (!(ipu->channel_init_mask & chan_mask)) {
  865. dev_err(ipu->dev, "Channel already uninitialized %d\n",
  866. channel);
  867. spin_unlock_irqrestore(&ipu->lock, flags);
  868. return;
  869. }
  870. /* Reset the double buffer */
  871. reg = idmac_read_ipureg(ipu, IPU_CHA_DB_MODE_SEL);
  872. idmac_write_ipureg(ipu, reg & ~chan_mask, IPU_CHA_DB_MODE_SEL);
  873. ichan->sec_chan_en = false;
  874. switch (channel) {
  875. case IDMAC_IC_7:
  876. reg = idmac_read_icreg(ipu, IC_CONF);
  877. idmac_write_icreg(ipu, reg & ~(IC_CONF_RWS_EN | IC_CONF_PRPENC_EN),
  878. IC_CONF);
  879. break;
  880. case IDMAC_IC_0:
  881. reg = idmac_read_icreg(ipu, IC_CONF);
  882. idmac_write_icreg(ipu, reg & ~(IC_CONF_PRPENC_EN | IC_CONF_PRPENC_CSC1),
  883. IC_CONF);
  884. break;
  885. case IDMAC_SDC_0:
  886. case IDMAC_SDC_1:
  887. default:
  888. break;
  889. }
  890. ipu->channel_init_mask &= ~(1L << channel);
  891. ipu_conf = idmac_read_ipureg(ipu, IPU_CONF) &
  892. ~ipu_channel_conf_mask(channel);
  893. idmac_write_ipureg(ipu, ipu_conf, IPU_CONF);
  894. spin_unlock_irqrestore(&ipu->lock, flags);
  895. ichan->n_tx_desc = 0;
  896. vfree(ichan->desc);
  897. ichan->desc = NULL;
  898. }
  899. /**
  900. * ipu_disable_channel() - disable an IPU channel.
  901. * @idmac: IPU DMAC context.
  902. * @ichan: channel object pointer.
  903. * @wait_for_stop: flag to set whether to wait for channel end of frame or
  904. * return immediately.
  905. * @return: 0 on success or negative error code on failure.
  906. */
  907. static int ipu_disable_channel(struct idmac *idmac, struct idmac_channel *ichan,
  908. bool wait_for_stop)
  909. {
  910. enum ipu_channel channel = ichan->dma_chan.chan_id;
  911. struct ipu *ipu = to_ipu(idmac);
  912. uint32_t reg;
  913. unsigned long flags;
  914. unsigned long chan_mask = 1UL << channel;
  915. unsigned int timeout;
  916. if (wait_for_stop && channel != IDMAC_SDC_1 && channel != IDMAC_SDC_0) {
  917. timeout = 40;
  918. /* This waiting always fails. Related to spurious irq problem */
  919. while ((idmac_read_icreg(ipu, IDMAC_CHA_BUSY) & chan_mask) ||
  920. (ipu_channel_status(ipu, channel) == TASK_STAT_ACTIVE)) {
  921. timeout--;
  922. msleep(10);
  923. if (!timeout) {
  924. dev_dbg(ipu->dev,
  925. "Warning: timeout waiting for channel %u to "
  926. "stop: buf0_rdy = 0x%08X, buf1_rdy = 0x%08X, "
  927. "busy = 0x%08X, tstat = 0x%08X\n", channel,
  928. idmac_read_ipureg(ipu, IPU_CHA_BUF0_RDY),
  929. idmac_read_ipureg(ipu, IPU_CHA_BUF1_RDY),
  930. idmac_read_icreg(ipu, IDMAC_CHA_BUSY),
  931. idmac_read_ipureg(ipu, IPU_TASKS_STAT));
  932. break;
  933. }
  934. }
  935. dev_dbg(ipu->dev, "timeout = %d * 10ms\n", 40 - timeout);
  936. }
  937. /* SDC BG and FG must be disabled before DMA is disabled */
  938. if (wait_for_stop && (channel == IDMAC_SDC_0 ||
  939. channel == IDMAC_SDC_1)) {
  940. for (timeout = 5;
  941. timeout && !ipu_irq_status(ichan->eof_irq); timeout--)
  942. msleep(5);
  943. }
  944. spin_lock_irqsave(&ipu->lock, flags);
  945. /* Disable IC task */
  946. ipu_ic_disable_task(ipu, channel);
  947. /* Disable DMA channel(s) */
  948. reg = idmac_read_icreg(ipu, IDMAC_CHA_EN);
  949. idmac_write_icreg(ipu, reg & ~chan_mask, IDMAC_CHA_EN);
  950. spin_unlock_irqrestore(&ipu->lock, flags);
  951. return 0;
  952. }
  953. static struct scatterlist *idmac_sg_next(struct idmac_channel *ichan,
  954. struct idmac_tx_desc **desc, struct scatterlist *sg)
  955. {
  956. struct scatterlist *sgnew = sg ? sg_next(sg) : NULL;
  957. if (sgnew)
  958. /* next sg-element in this list */
  959. return sgnew;
  960. if ((*desc)->list.next == &ichan->queue)
  961. /* No more descriptors on the queue */
  962. return NULL;
  963. /* Fetch next descriptor */
  964. *desc = list_entry((*desc)->list.next, struct idmac_tx_desc, list);
  965. return (*desc)->sg;
  966. }
  967. /*
  968. * We have several possibilities here:
  969. * current BUF next BUF
  970. *
  971. * not last sg next not last sg
  972. * not last sg next last sg
  973. * last sg first sg from next descriptor
  974. * last sg NULL
  975. *
  976. * Besides, the descriptor queue might be empty or not. We process all these
  977. * cases carefully.
  978. */
  979. static irqreturn_t idmac_interrupt(int irq, void *dev_id)
  980. {
  981. struct idmac_channel *ichan = dev_id;
  982. struct device *dev = &ichan->dma_chan.dev->device;
  983. unsigned int chan_id = ichan->dma_chan.chan_id;
  984. struct scatterlist **sg, *sgnext, *sgnew = NULL;
  985. /* Next transfer descriptor */
  986. struct idmac_tx_desc *desc, *descnew;
  987. dma_async_tx_callback callback;
  988. void *callback_param;
  989. bool done = false;
  990. u32 ready0, ready1, curbuf, err;
  991. unsigned long flags;
  992. /* IDMAC has cleared the respective BUFx_RDY bit, we manage the buffer */
  993. dev_dbg(dev, "IDMAC irq %d, buf %d\n", irq, ichan->active_buffer);
  994. spin_lock_irqsave(&ipu_data.lock, flags);
  995. ready0 = idmac_read_ipureg(&ipu_data, IPU_CHA_BUF0_RDY);
  996. ready1 = idmac_read_ipureg(&ipu_data, IPU_CHA_BUF1_RDY);
  997. curbuf = idmac_read_ipureg(&ipu_data, IPU_CHA_CUR_BUF);
  998. err = idmac_read_ipureg(&ipu_data, IPU_INT_STAT_4);
  999. if (err & (1 << chan_id)) {
  1000. idmac_write_ipureg(&ipu_data, 1 << chan_id, IPU_INT_STAT_4);
  1001. spin_unlock_irqrestore(&ipu_data.lock, flags);
  1002. /*
  1003. * Doing this
  1004. * ichan->sg[0] = ichan->sg[1] = NULL;
  1005. * you can force channel re-enable on the next tx_submit(), but
  1006. * this is dirty - think about descriptors with multiple
  1007. * sg elements.
  1008. */
  1009. dev_warn(dev, "NFB4EOF on channel %d, ready %x, %x, cur %x\n",
  1010. chan_id, ready0, ready1, curbuf);
  1011. return IRQ_HANDLED;
  1012. }
  1013. spin_unlock_irqrestore(&ipu_data.lock, flags);
  1014. /* Other interrupts do not interfere with this channel */
  1015. spin_lock(&ichan->lock);
  1016. if (unlikely((ichan->active_buffer && (ready1 >> chan_id) & 1) ||
  1017. (!ichan->active_buffer && (ready0 >> chan_id) & 1)
  1018. )) {
  1019. spin_unlock(&ichan->lock);
  1020. dev_dbg(dev,
  1021. "IRQ with active buffer still ready on channel %x, "
  1022. "active %d, ready %x, %x!\n", chan_id,
  1023. ichan->active_buffer, ready0, ready1);
  1024. return IRQ_NONE;
  1025. }
  1026. if (unlikely(list_empty(&ichan->queue))) {
  1027. ichan->sg[ichan->active_buffer] = NULL;
  1028. spin_unlock(&ichan->lock);
  1029. dev_err(dev,
  1030. "IRQ without queued buffers on channel %x, active %d, "
  1031. "ready %x, %x!\n", chan_id,
  1032. ichan->active_buffer, ready0, ready1);
  1033. return IRQ_NONE;
  1034. }
  1035. /*
  1036. * active_buffer is a software flag, it shows which buffer we are
  1037. * currently expecting back from the hardware, IDMAC should be
  1038. * processing the other buffer already
  1039. */
  1040. sg = &ichan->sg[ichan->active_buffer];
  1041. sgnext = ichan->sg[!ichan->active_buffer];
  1042. if (!*sg) {
  1043. spin_unlock(&ichan->lock);
  1044. return IRQ_HANDLED;
  1045. }
  1046. desc = list_entry(ichan->queue.next, struct idmac_tx_desc, list);
  1047. descnew = desc;
  1048. dev_dbg(dev, "IDMAC irq %d, dma 0x%08x, next dma 0x%08x, current %d, curbuf 0x%08x\n",
  1049. irq, sg_dma_address(*sg), sgnext ? sg_dma_address(sgnext) : 0, ichan->active_buffer, curbuf);
  1050. /* Find the descriptor of sgnext */
  1051. sgnew = idmac_sg_next(ichan, &descnew, *sg);
  1052. if (sgnext != sgnew)
  1053. dev_err(dev, "Submitted buffer %p, next buffer %p\n", sgnext, sgnew);
  1054. /*
  1055. * if sgnext == NULL sg must be the last element in a scatterlist and
  1056. * queue must be empty
  1057. */
  1058. if (unlikely(!sgnext)) {
  1059. if (!WARN_ON(sg_next(*sg)))
  1060. dev_dbg(dev, "Underrun on channel %x\n", chan_id);
  1061. ichan->sg[!ichan->active_buffer] = sgnew;
  1062. if (unlikely(sgnew)) {
  1063. ipu_submit_buffer(ichan, descnew, sgnew, !ichan->active_buffer);
  1064. } else {
  1065. spin_lock_irqsave(&ipu_data.lock, flags);
  1066. ipu_ic_disable_task(&ipu_data, chan_id);
  1067. spin_unlock_irqrestore(&ipu_data.lock, flags);
  1068. ichan->status = IPU_CHANNEL_READY;
  1069. /* Continue to check for complete descriptor */
  1070. }
  1071. }
  1072. /* Calculate and submit the next sg element */
  1073. sgnew = idmac_sg_next(ichan, &descnew, sgnew);
  1074. if (unlikely(!sg_next(*sg)) || !sgnext) {
  1075. /*
  1076. * Last element in scatterlist done, remove from the queue,
  1077. * _init for debugging
  1078. */
  1079. list_del_init(&desc->list);
  1080. done = true;
  1081. }
  1082. *sg = sgnew;
  1083. if (likely(sgnew) &&
  1084. ipu_submit_buffer(ichan, descnew, sgnew, ichan->active_buffer) < 0) {
  1085. callback = descnew->txd.callback;
  1086. callback_param = descnew->txd.callback_param;
  1087. list_del_init(&descnew->list);
  1088. spin_unlock(&ichan->lock);
  1089. if (callback)
  1090. callback(callback_param);
  1091. spin_lock(&ichan->lock);
  1092. }
  1093. /* Flip the active buffer - even if update above failed */
  1094. ichan->active_buffer = !ichan->active_buffer;
  1095. if (done)
  1096. dma_cookie_complete(&desc->txd);
  1097. callback = desc->txd.callback;
  1098. callback_param = desc->txd.callback_param;
  1099. spin_unlock(&ichan->lock);
  1100. if (done && (desc->txd.flags & DMA_PREP_INTERRUPT) && callback)
  1101. callback(callback_param);
  1102. return IRQ_HANDLED;
  1103. }
  1104. static void ipu_gc_tasklet(unsigned long arg)
  1105. {
  1106. struct ipu *ipu = (struct ipu *)arg;
  1107. int i;
  1108. for (i = 0; i < IPU_CHANNELS_NUM; i++) {
  1109. struct idmac_channel *ichan = ipu->channel + i;
  1110. struct idmac_tx_desc *desc;
  1111. unsigned long flags;
  1112. struct scatterlist *sg;
  1113. int j, k;
  1114. for (j = 0; j < ichan->n_tx_desc; j++) {
  1115. desc = ichan->desc + j;
  1116. spin_lock_irqsave(&ichan->lock, flags);
  1117. if (async_tx_test_ack(&desc->txd)) {
  1118. list_move(&desc->list, &ichan->free_list);
  1119. for_each_sg(desc->sg, sg, desc->sg_len, k) {
  1120. if (ichan->sg[0] == sg)
  1121. ichan->sg[0] = NULL;
  1122. else if (ichan->sg[1] == sg)
  1123. ichan->sg[1] = NULL;
  1124. }
  1125. async_tx_clear_ack(&desc->txd);
  1126. }
  1127. spin_unlock_irqrestore(&ichan->lock, flags);
  1128. }
  1129. }
  1130. }
  1131. /* Allocate and initialise a transfer descriptor. */
  1132. static struct dma_async_tx_descriptor *idmac_prep_slave_sg(struct dma_chan *chan,
  1133. struct scatterlist *sgl, unsigned int sg_len,
  1134. enum dma_transfer_direction direction, unsigned long tx_flags,
  1135. void *context)
  1136. {
  1137. struct idmac_channel *ichan = to_idmac_chan(chan);
  1138. struct idmac_tx_desc *desc = NULL;
  1139. struct dma_async_tx_descriptor *txd = NULL;
  1140. unsigned long flags;
  1141. /* We only can handle these three channels so far */
  1142. if (chan->chan_id != IDMAC_SDC_0 && chan->chan_id != IDMAC_SDC_1 &&
  1143. chan->chan_id != IDMAC_IC_7)
  1144. return NULL;
  1145. if (!is_slave_direction(direction)) {
  1146. dev_err(chan->device->dev, "Invalid DMA direction %d!\n", direction);
  1147. return NULL;
  1148. }
  1149. mutex_lock(&ichan->chan_mutex);
  1150. spin_lock_irqsave(&ichan->lock, flags);
  1151. if (!list_empty(&ichan->free_list)) {
  1152. desc = list_entry(ichan->free_list.next,
  1153. struct idmac_tx_desc, list);
  1154. list_del_init(&desc->list);
  1155. desc->sg_len = sg_len;
  1156. desc->sg = sgl;
  1157. txd = &desc->txd;
  1158. txd->flags = tx_flags;
  1159. }
  1160. spin_unlock_irqrestore(&ichan->lock, flags);
  1161. mutex_unlock(&ichan->chan_mutex);
  1162. tasklet_schedule(&to_ipu(to_idmac(chan->device))->tasklet);
  1163. return txd;
  1164. }
  1165. /* Re-select the current buffer and re-activate the channel */
  1166. static void idmac_issue_pending(struct dma_chan *chan)
  1167. {
  1168. struct idmac_channel *ichan = to_idmac_chan(chan);
  1169. struct idmac *idmac = to_idmac(chan->device);
  1170. struct ipu *ipu = to_ipu(idmac);
  1171. unsigned long flags;
  1172. /* This is not always needed, but doesn't hurt either */
  1173. spin_lock_irqsave(&ipu->lock, flags);
  1174. ipu_select_buffer(chan->chan_id, ichan->active_buffer);
  1175. spin_unlock_irqrestore(&ipu->lock, flags);
  1176. /*
  1177. * Might need to perform some parts of initialisation from
  1178. * ipu_enable_channel(), but not all, we do not want to reset to buffer
  1179. * 0, don't need to set priority again either, but re-enabling the task
  1180. * and the channel might be a good idea.
  1181. */
  1182. }
  1183. static int __idmac_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  1184. unsigned long arg)
  1185. {
  1186. struct idmac_channel *ichan = to_idmac_chan(chan);
  1187. struct idmac *idmac = to_idmac(chan->device);
  1188. struct ipu *ipu = to_ipu(idmac);
  1189. struct list_head *list, *tmp;
  1190. unsigned long flags;
  1191. int i;
  1192. switch (cmd) {
  1193. case DMA_PAUSE:
  1194. spin_lock_irqsave(&ipu->lock, flags);
  1195. ipu_ic_disable_task(ipu, chan->chan_id);
  1196. /* Return all descriptors into "prepared" state */
  1197. list_for_each_safe(list, tmp, &ichan->queue)
  1198. list_del_init(list);
  1199. ichan->sg[0] = NULL;
  1200. ichan->sg[1] = NULL;
  1201. spin_unlock_irqrestore(&ipu->lock, flags);
  1202. ichan->status = IPU_CHANNEL_INITIALIZED;
  1203. break;
  1204. case DMA_TERMINATE_ALL:
  1205. ipu_disable_channel(idmac, ichan,
  1206. ichan->status >= IPU_CHANNEL_ENABLED);
  1207. tasklet_disable(&ipu->tasklet);
  1208. /* ichan->queue is modified in ISR, have to spinlock */
  1209. spin_lock_irqsave(&ichan->lock, flags);
  1210. list_splice_init(&ichan->queue, &ichan->free_list);
  1211. if (ichan->desc)
  1212. for (i = 0; i < ichan->n_tx_desc; i++) {
  1213. struct idmac_tx_desc *desc = ichan->desc + i;
  1214. if (list_empty(&desc->list))
  1215. /* Descriptor was prepared, but not submitted */
  1216. list_add(&desc->list, &ichan->free_list);
  1217. async_tx_clear_ack(&desc->txd);
  1218. }
  1219. ichan->sg[0] = NULL;
  1220. ichan->sg[1] = NULL;
  1221. spin_unlock_irqrestore(&ichan->lock, flags);
  1222. tasklet_enable(&ipu->tasklet);
  1223. ichan->status = IPU_CHANNEL_INITIALIZED;
  1224. break;
  1225. default:
  1226. return -ENOSYS;
  1227. }
  1228. return 0;
  1229. }
  1230. static int idmac_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  1231. unsigned long arg)
  1232. {
  1233. struct idmac_channel *ichan = to_idmac_chan(chan);
  1234. int ret;
  1235. mutex_lock(&ichan->chan_mutex);
  1236. ret = __idmac_control(chan, cmd, arg);
  1237. mutex_unlock(&ichan->chan_mutex);
  1238. return ret;
  1239. }
  1240. #ifdef DEBUG
  1241. static irqreturn_t ic_sof_irq(int irq, void *dev_id)
  1242. {
  1243. struct idmac_channel *ichan = dev_id;
  1244. printk(KERN_DEBUG "Got SOF IRQ %d on Channel %d\n",
  1245. irq, ichan->dma_chan.chan_id);
  1246. disable_irq_nosync(irq);
  1247. return IRQ_HANDLED;
  1248. }
  1249. static irqreturn_t ic_eof_irq(int irq, void *dev_id)
  1250. {
  1251. struct idmac_channel *ichan = dev_id;
  1252. printk(KERN_DEBUG "Got EOF IRQ %d on Channel %d\n",
  1253. irq, ichan->dma_chan.chan_id);
  1254. disable_irq_nosync(irq);
  1255. return IRQ_HANDLED;
  1256. }
  1257. static int ic_sof = -EINVAL, ic_eof = -EINVAL;
  1258. #endif
  1259. static int idmac_alloc_chan_resources(struct dma_chan *chan)
  1260. {
  1261. struct idmac_channel *ichan = to_idmac_chan(chan);
  1262. struct idmac *idmac = to_idmac(chan->device);
  1263. int ret;
  1264. /* dmaengine.c now guarantees to only offer free channels */
  1265. BUG_ON(chan->client_count > 1);
  1266. WARN_ON(ichan->status != IPU_CHANNEL_FREE);
  1267. dma_cookie_init(chan);
  1268. ret = ipu_irq_map(chan->chan_id);
  1269. if (ret < 0)
  1270. goto eimap;
  1271. ichan->eof_irq = ret;
  1272. /*
  1273. * Important to first disable the channel, because maybe someone
  1274. * used it before us, e.g., the bootloader
  1275. */
  1276. ipu_disable_channel(idmac, ichan, true);
  1277. ret = ipu_init_channel(idmac, ichan);
  1278. if (ret < 0)
  1279. goto eichan;
  1280. ret = request_irq(ichan->eof_irq, idmac_interrupt, 0,
  1281. ichan->eof_name, ichan);
  1282. if (ret < 0)
  1283. goto erirq;
  1284. #ifdef DEBUG
  1285. if (chan->chan_id == IDMAC_IC_7) {
  1286. ic_sof = ipu_irq_map(69);
  1287. if (ic_sof > 0)
  1288. request_irq(ic_sof, ic_sof_irq, 0, "IC SOF", ichan);
  1289. ic_eof = ipu_irq_map(70);
  1290. if (ic_eof > 0)
  1291. request_irq(ic_eof, ic_eof_irq, 0, "IC EOF", ichan);
  1292. }
  1293. #endif
  1294. ichan->status = IPU_CHANNEL_INITIALIZED;
  1295. dev_dbg(&chan->dev->device, "Found channel 0x%x, irq %d\n",
  1296. chan->chan_id, ichan->eof_irq);
  1297. return ret;
  1298. erirq:
  1299. ipu_uninit_channel(idmac, ichan);
  1300. eichan:
  1301. ipu_irq_unmap(chan->chan_id);
  1302. eimap:
  1303. return ret;
  1304. }
  1305. static void idmac_free_chan_resources(struct dma_chan *chan)
  1306. {
  1307. struct idmac_channel *ichan = to_idmac_chan(chan);
  1308. struct idmac *idmac = to_idmac(chan->device);
  1309. mutex_lock(&ichan->chan_mutex);
  1310. __idmac_control(chan, DMA_TERMINATE_ALL, 0);
  1311. if (ichan->status > IPU_CHANNEL_FREE) {
  1312. #ifdef DEBUG
  1313. if (chan->chan_id == IDMAC_IC_7) {
  1314. if (ic_sof > 0) {
  1315. free_irq(ic_sof, ichan);
  1316. ipu_irq_unmap(69);
  1317. ic_sof = -EINVAL;
  1318. }
  1319. if (ic_eof > 0) {
  1320. free_irq(ic_eof, ichan);
  1321. ipu_irq_unmap(70);
  1322. ic_eof = -EINVAL;
  1323. }
  1324. }
  1325. #endif
  1326. free_irq(ichan->eof_irq, ichan);
  1327. ipu_irq_unmap(chan->chan_id);
  1328. }
  1329. ichan->status = IPU_CHANNEL_FREE;
  1330. ipu_uninit_channel(idmac, ichan);
  1331. mutex_unlock(&ichan->chan_mutex);
  1332. tasklet_schedule(&to_ipu(idmac)->tasklet);
  1333. }
  1334. static enum dma_status idmac_tx_status(struct dma_chan *chan,
  1335. dma_cookie_t cookie, struct dma_tx_state *txstate)
  1336. {
  1337. dma_set_tx_state(txstate, chan->completed_cookie, chan->cookie, 0);
  1338. if (cookie != chan->cookie)
  1339. return DMA_ERROR;
  1340. return DMA_SUCCESS;
  1341. }
  1342. static int __init ipu_idmac_init(struct ipu *ipu)
  1343. {
  1344. struct idmac *idmac = &ipu->idmac;
  1345. struct dma_device *dma = &idmac->dma;
  1346. int i;
  1347. dma_cap_set(DMA_SLAVE, dma->cap_mask);
  1348. dma_cap_set(DMA_PRIVATE, dma->cap_mask);
  1349. /* Compulsory common fields */
  1350. dma->dev = ipu->dev;
  1351. dma->device_alloc_chan_resources = idmac_alloc_chan_resources;
  1352. dma->device_free_chan_resources = idmac_free_chan_resources;
  1353. dma->device_tx_status = idmac_tx_status;
  1354. dma->device_issue_pending = idmac_issue_pending;
  1355. /* Compulsory for DMA_SLAVE fields */
  1356. dma->device_prep_slave_sg = idmac_prep_slave_sg;
  1357. dma->device_control = idmac_control;
  1358. INIT_LIST_HEAD(&dma->channels);
  1359. for (i = 0; i < IPU_CHANNELS_NUM; i++) {
  1360. struct idmac_channel *ichan = ipu->channel + i;
  1361. struct dma_chan *dma_chan = &ichan->dma_chan;
  1362. spin_lock_init(&ichan->lock);
  1363. mutex_init(&ichan->chan_mutex);
  1364. ichan->status = IPU_CHANNEL_FREE;
  1365. ichan->sec_chan_en = false;
  1366. snprintf(ichan->eof_name, sizeof(ichan->eof_name), "IDMAC EOF %d", i);
  1367. dma_chan->device = &idmac->dma;
  1368. dma_cookie_init(dma_chan);
  1369. dma_chan->chan_id = i;
  1370. list_add_tail(&dma_chan->device_node, &dma->channels);
  1371. }
  1372. idmac_write_icreg(ipu, 0x00000070, IDMAC_CONF);
  1373. return dma_async_device_register(&idmac->dma);
  1374. }
  1375. static void __exit ipu_idmac_exit(struct ipu *ipu)
  1376. {
  1377. int i;
  1378. struct idmac *idmac = &ipu->idmac;
  1379. for (i = 0; i < IPU_CHANNELS_NUM; i++) {
  1380. struct idmac_channel *ichan = ipu->channel + i;
  1381. idmac_control(&ichan->dma_chan, DMA_TERMINATE_ALL, 0);
  1382. }
  1383. dma_async_device_unregister(&idmac->dma);
  1384. }
  1385. /*****************************************************************************
  1386. * IPU common probe / remove
  1387. */
  1388. static int __init ipu_probe(struct platform_device *pdev)
  1389. {
  1390. struct resource *mem_ipu, *mem_ic;
  1391. int ret;
  1392. spin_lock_init(&ipu_data.lock);
  1393. mem_ipu = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1394. mem_ic = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  1395. if (!mem_ipu || !mem_ic)
  1396. return -EINVAL;
  1397. ipu_data.dev = &pdev->dev;
  1398. platform_set_drvdata(pdev, &ipu_data);
  1399. ret = platform_get_irq(pdev, 0);
  1400. if (ret < 0)
  1401. goto err_noirq;
  1402. ipu_data.irq_fn = ret;
  1403. ret = platform_get_irq(pdev, 1);
  1404. if (ret < 0)
  1405. goto err_noirq;
  1406. ipu_data.irq_err = ret;
  1407. dev_dbg(&pdev->dev, "fn irq %u, err irq %u\n",
  1408. ipu_data.irq_fn, ipu_data.irq_err);
  1409. /* Remap IPU common registers */
  1410. ipu_data.reg_ipu = ioremap(mem_ipu->start, resource_size(mem_ipu));
  1411. if (!ipu_data.reg_ipu) {
  1412. ret = -ENOMEM;
  1413. goto err_ioremap_ipu;
  1414. }
  1415. /* Remap Image Converter and Image DMA Controller registers */
  1416. ipu_data.reg_ic = ioremap(mem_ic->start, resource_size(mem_ic));
  1417. if (!ipu_data.reg_ic) {
  1418. ret = -ENOMEM;
  1419. goto err_ioremap_ic;
  1420. }
  1421. /* Get IPU clock */
  1422. ipu_data.ipu_clk = clk_get(&pdev->dev, NULL);
  1423. if (IS_ERR(ipu_data.ipu_clk)) {
  1424. ret = PTR_ERR(ipu_data.ipu_clk);
  1425. goto err_clk_get;
  1426. }
  1427. /* Make sure IPU HSP clock is running */
  1428. clk_prepare_enable(ipu_data.ipu_clk);
  1429. /* Disable all interrupts */
  1430. idmac_write_ipureg(&ipu_data, 0, IPU_INT_CTRL_1);
  1431. idmac_write_ipureg(&ipu_data, 0, IPU_INT_CTRL_2);
  1432. idmac_write_ipureg(&ipu_data, 0, IPU_INT_CTRL_3);
  1433. idmac_write_ipureg(&ipu_data, 0, IPU_INT_CTRL_4);
  1434. idmac_write_ipureg(&ipu_data, 0, IPU_INT_CTRL_5);
  1435. dev_dbg(&pdev->dev, "%s @ 0x%08lx, fn irq %u, err irq %u\n", pdev->name,
  1436. (unsigned long)mem_ipu->start, ipu_data.irq_fn, ipu_data.irq_err);
  1437. ret = ipu_irq_attach_irq(&ipu_data, pdev);
  1438. if (ret < 0)
  1439. goto err_attach_irq;
  1440. /* Initialize DMA engine */
  1441. ret = ipu_idmac_init(&ipu_data);
  1442. if (ret < 0)
  1443. goto err_idmac_init;
  1444. tasklet_init(&ipu_data.tasklet, ipu_gc_tasklet, (unsigned long)&ipu_data);
  1445. ipu_data.dev = &pdev->dev;
  1446. dev_dbg(ipu_data.dev, "IPU initialized\n");
  1447. return 0;
  1448. err_idmac_init:
  1449. err_attach_irq:
  1450. ipu_irq_detach_irq(&ipu_data, pdev);
  1451. clk_disable_unprepare(ipu_data.ipu_clk);
  1452. clk_put(ipu_data.ipu_clk);
  1453. err_clk_get:
  1454. iounmap(ipu_data.reg_ic);
  1455. err_ioremap_ic:
  1456. iounmap(ipu_data.reg_ipu);
  1457. err_ioremap_ipu:
  1458. err_noirq:
  1459. dev_err(&pdev->dev, "Failed to probe IPU: %d\n", ret);
  1460. return ret;
  1461. }
  1462. static int __exit ipu_remove(struct platform_device *pdev)
  1463. {
  1464. struct ipu *ipu = platform_get_drvdata(pdev);
  1465. ipu_idmac_exit(ipu);
  1466. ipu_irq_detach_irq(ipu, pdev);
  1467. clk_disable_unprepare(ipu->ipu_clk);
  1468. clk_put(ipu->ipu_clk);
  1469. iounmap(ipu->reg_ic);
  1470. iounmap(ipu->reg_ipu);
  1471. tasklet_kill(&ipu->tasklet);
  1472. platform_set_drvdata(pdev, NULL);
  1473. return 0;
  1474. }
  1475. /*
  1476. * We need two MEM resources - with IPU-common and Image Converter registers,
  1477. * including PF_CONF and IDMAC_* registers, and two IRQs - function and error
  1478. */
  1479. static struct platform_driver ipu_platform_driver = {
  1480. .driver = {
  1481. .name = "ipu-core",
  1482. .owner = THIS_MODULE,
  1483. },
  1484. .remove = __exit_p(ipu_remove),
  1485. };
  1486. static int __init ipu_init(void)
  1487. {
  1488. return platform_driver_probe(&ipu_platform_driver, ipu_probe);
  1489. }
  1490. subsys_initcall(ipu_init);
  1491. MODULE_DESCRIPTION("IPU core driver");
  1492. MODULE_LICENSE("GPL v2");
  1493. MODULE_AUTHOR("Guennadi Liakhovetski <lg@denx.de>");
  1494. MODULE_ALIAS("platform:ipu-core");