ipu_common.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196
  1. /*
  2. * Porting to u-boot:
  3. *
  4. * (C) Copyright 2010
  5. * Stefano Babic, DENX Software Engineering, sbabic@denx.de
  6. *
  7. * Linux IPU driver for MX51:
  8. *
  9. * (C) Copyright 2005-2010 Freescale Semiconductor, Inc.
  10. *
  11. * SPDX-License-Identifier: GPL-2.0+
  12. */
  13. /* #define DEBUG */
  14. #include <common.h>
  15. #include <linux/types.h>
  16. #include <linux/err.h>
  17. #include <asm/io.h>
  18. #include <asm/errno.h>
  19. #include <asm/arch/imx-regs.h>
  20. #include <asm/arch/crm_regs.h>
  21. #include "ipu.h"
  22. #include "ipu_regs.h"
  23. extern struct mxc_ccm_reg *mxc_ccm;
  24. extern u32 *ipu_cpmem_base;
  25. struct ipu_ch_param_word {
  26. uint32_t data[5];
  27. uint32_t res[3];
  28. };
  29. struct ipu_ch_param {
  30. struct ipu_ch_param_word word[2];
  31. };
  32. #define ipu_ch_param_addr(ch) (((struct ipu_ch_param *)ipu_cpmem_base) + (ch))
  33. #define _param_word(base, w) \
  34. (((struct ipu_ch_param *)(base))->word[(w)].data)
  35. #define ipu_ch_param_set_field(base, w, bit, size, v) { \
  36. int i = (bit) / 32; \
  37. int off = (bit) % 32; \
  38. _param_word(base, w)[i] |= (v) << off; \
  39. if (((bit) + (size) - 1) / 32 > i) { \
  40. _param_word(base, w)[i + 1] |= (v) >> (off ? (32 - off) : 0); \
  41. } \
  42. }
  43. #define ipu_ch_param_mod_field(base, w, bit, size, v) { \
  44. int i = (bit) / 32; \
  45. int off = (bit) % 32; \
  46. u32 mask = (1UL << size) - 1; \
  47. u32 temp = _param_word(base, w)[i]; \
  48. temp &= ~(mask << off); \
  49. _param_word(base, w)[i] = temp | (v) << off; \
  50. if (((bit) + (size) - 1) / 32 > i) { \
  51. temp = _param_word(base, w)[i + 1]; \
  52. temp &= ~(mask >> (32 - off)); \
  53. _param_word(base, w)[i + 1] = \
  54. temp | ((v) >> (off ? (32 - off) : 0)); \
  55. } \
  56. }
  57. #define ipu_ch_param_read_field(base, w, bit, size) ({ \
  58. u32 temp2; \
  59. int i = (bit) / 32; \
  60. int off = (bit) % 32; \
  61. u32 mask = (1UL << size) - 1; \
  62. u32 temp1 = _param_word(base, w)[i]; \
  63. temp1 = mask & (temp1 >> off); \
  64. if (((bit)+(size) - 1) / 32 > i) { \
  65. temp2 = _param_word(base, w)[i + 1]; \
  66. temp2 &= mask >> (off ? (32 - off) : 0); \
  67. temp1 |= temp2 << (off ? (32 - off) : 0); \
  68. } \
  69. temp1; \
  70. })
  71. #define IPU_SW_RST_TOUT_USEC (10000)
  72. void clk_enable(struct clk *clk)
  73. {
  74. if (clk) {
  75. if (clk->usecount++ == 0) {
  76. clk->enable(clk);
  77. }
  78. }
  79. }
  80. void clk_disable(struct clk *clk)
  81. {
  82. if (clk) {
  83. if (!(--clk->usecount)) {
  84. if (clk->disable)
  85. clk->disable(clk);
  86. }
  87. }
  88. }
  89. int clk_get_usecount(struct clk *clk)
  90. {
  91. if (clk == NULL)
  92. return 0;
  93. return clk->usecount;
  94. }
  95. u32 clk_get_rate(struct clk *clk)
  96. {
  97. if (!clk)
  98. return 0;
  99. return clk->rate;
  100. }
  101. struct clk *clk_get_parent(struct clk *clk)
  102. {
  103. if (!clk)
  104. return 0;
  105. return clk->parent;
  106. }
  107. int clk_set_rate(struct clk *clk, unsigned long rate)
  108. {
  109. if (clk && clk->set_rate)
  110. clk->set_rate(clk, rate);
  111. return clk->rate;
  112. }
  113. long clk_round_rate(struct clk *clk, unsigned long rate)
  114. {
  115. if (clk == NULL || !clk->round_rate)
  116. return 0;
  117. return clk->round_rate(clk, rate);
  118. }
  119. int clk_set_parent(struct clk *clk, struct clk *parent)
  120. {
  121. clk->parent = parent;
  122. if (clk->set_parent)
  123. return clk->set_parent(clk, parent);
  124. return 0;
  125. }
  126. static int clk_ipu_enable(struct clk *clk)
  127. {
  128. u32 reg;
  129. reg = __raw_readl(clk->enable_reg);
  130. reg |= MXC_CCM_CCGR_CG_MASK << clk->enable_shift;
  131. __raw_writel(reg, clk->enable_reg);
  132. #if defined(CONFIG_MX51) || defined(CONFIG_MX53)
  133. /* Handshake with IPU when certain clock rates are changed. */
  134. reg = __raw_readl(&mxc_ccm->ccdr);
  135. reg &= ~MXC_CCM_CCDR_IPU_HS_MASK;
  136. __raw_writel(reg, &mxc_ccm->ccdr);
  137. /* Handshake with IPU when LPM is entered as its enabled. */
  138. reg = __raw_readl(&mxc_ccm->clpcr);
  139. reg &= ~MXC_CCM_CLPCR_BYPASS_IPU_LPM_HS;
  140. __raw_writel(reg, &mxc_ccm->clpcr);
  141. #endif
  142. return 0;
  143. }
  144. static void clk_ipu_disable(struct clk *clk)
  145. {
  146. u32 reg;
  147. reg = __raw_readl(clk->enable_reg);
  148. reg &= ~(MXC_CCM_CCGR_CG_MASK << clk->enable_shift);
  149. __raw_writel(reg, clk->enable_reg);
  150. #if defined(CONFIG_MX51) || defined(CONFIG_MX53)
  151. /*
  152. * No handshake with IPU whe dividers are changed
  153. * as its not enabled.
  154. */
  155. reg = __raw_readl(&mxc_ccm->ccdr);
  156. reg |= MXC_CCM_CCDR_IPU_HS_MASK;
  157. __raw_writel(reg, &mxc_ccm->ccdr);
  158. /* No handshake with IPU when LPM is entered as its not enabled. */
  159. reg = __raw_readl(&mxc_ccm->clpcr);
  160. reg |= MXC_CCM_CLPCR_BYPASS_IPU_LPM_HS;
  161. __raw_writel(reg, &mxc_ccm->clpcr);
  162. #endif
  163. }
  164. static struct clk ipu_clk = {
  165. .name = "ipu_clk",
  166. .rate = CONFIG_IPUV3_CLK,
  167. #if defined(CONFIG_MX51) || defined(CONFIG_MX53)
  168. .enable_reg = (u32 *)(CCM_BASE_ADDR +
  169. offsetof(struct mxc_ccm_reg, CCGR5)),
  170. .enable_shift = MXC_CCM_CCGR5_IPU_OFFSET,
  171. #else
  172. .enable_reg = (u32 *)(CCM_BASE_ADDR +
  173. offsetof(struct mxc_ccm_reg, CCGR3)),
  174. .enable_shift = MXC_CCM_CCGR3_IPU1_IPU_DI0_OFFSET,
  175. #endif
  176. .enable = clk_ipu_enable,
  177. .disable = clk_ipu_disable,
  178. .usecount = 0,
  179. };
  180. static struct clk ldb_clk = {
  181. .name = "ldb_clk",
  182. .rate = 65000000,
  183. .usecount = 0,
  184. };
  185. /* Globals */
  186. struct clk *g_ipu_clk;
  187. struct clk *g_ldb_clk;
  188. unsigned char g_ipu_clk_enabled;
  189. struct clk *g_di_clk[2];
  190. struct clk *g_pixel_clk[2];
  191. unsigned char g_dc_di_assignment[10];
  192. uint32_t g_channel_init_mask;
  193. uint32_t g_channel_enable_mask;
  194. static int ipu_dc_use_count;
  195. static int ipu_dp_use_count;
  196. static int ipu_dmfc_use_count;
  197. static int ipu_di_use_count[2];
  198. u32 *ipu_cpmem_base;
  199. u32 *ipu_dc_tmpl_reg;
  200. /* Static functions */
  201. static inline void ipu_ch_param_set_high_priority(uint32_t ch)
  202. {
  203. ipu_ch_param_mod_field(ipu_ch_param_addr(ch), 1, 93, 2, 1);
  204. };
  205. static inline uint32_t channel_2_dma(ipu_channel_t ch, ipu_buffer_t type)
  206. {
  207. return ((uint32_t) ch >> (6 * type)) & 0x3F;
  208. };
  209. /* Either DP BG or DP FG can be graphic window */
  210. static inline int ipu_is_dp_graphic_chan(uint32_t dma_chan)
  211. {
  212. return (dma_chan == 23 || dma_chan == 27);
  213. }
  214. static inline int ipu_is_dmfc_chan(uint32_t dma_chan)
  215. {
  216. return ((dma_chan >= 23) && (dma_chan <= 29));
  217. }
  218. static inline void ipu_ch_param_set_buffer(uint32_t ch, int bufNum,
  219. dma_addr_t phyaddr)
  220. {
  221. ipu_ch_param_mod_field(ipu_ch_param_addr(ch), 1, 29 * bufNum, 29,
  222. phyaddr / 8);
  223. };
  224. #define idma_is_valid(ch) (ch != NO_DMA)
  225. #define idma_mask(ch) (idma_is_valid(ch) ? (1UL << (ch & 0x1F)) : 0)
  226. #define idma_is_set(reg, dma) (__raw_readl(reg(dma)) & idma_mask(dma))
  227. static void ipu_pixel_clk_recalc(struct clk *clk)
  228. {
  229. u32 div = __raw_readl(DI_BS_CLKGEN0(clk->id));
  230. if (div == 0)
  231. clk->rate = 0;
  232. else
  233. clk->rate = (clk->parent->rate * 16) / div;
  234. }
  235. static unsigned long ipu_pixel_clk_round_rate(struct clk *clk,
  236. unsigned long rate)
  237. {
  238. u32 div, div1;
  239. u32 tmp;
  240. /*
  241. * Calculate divider
  242. * Fractional part is 4 bits,
  243. * so simply multiply by 2^4 to get fractional part.
  244. */
  245. tmp = (clk->parent->rate * 16);
  246. div = tmp / rate;
  247. if (div < 0x10) /* Min DI disp clock divider is 1 */
  248. div = 0x10;
  249. if (div & ~0xFEF)
  250. div &= 0xFF8;
  251. else {
  252. div1 = div & 0xFE0;
  253. if ((tmp/div1 - tmp/div) < rate / 4)
  254. div = div1;
  255. else
  256. div &= 0xFF8;
  257. }
  258. return (clk->parent->rate * 16) / div;
  259. }
  260. static int ipu_pixel_clk_set_rate(struct clk *clk, unsigned long rate)
  261. {
  262. u32 div = (clk->parent->rate * 16) / rate;
  263. __raw_writel(div, DI_BS_CLKGEN0(clk->id));
  264. /* Setup pixel clock timing */
  265. __raw_writel((div / 16) << 16, DI_BS_CLKGEN1(clk->id));
  266. clk->rate = (clk->parent->rate * 16) / div;
  267. return 0;
  268. }
  269. static int ipu_pixel_clk_enable(struct clk *clk)
  270. {
  271. u32 disp_gen = __raw_readl(IPU_DISP_GEN);
  272. disp_gen |= clk->id ? DI1_COUNTER_RELEASE : DI0_COUNTER_RELEASE;
  273. __raw_writel(disp_gen, IPU_DISP_GEN);
  274. return 0;
  275. }
  276. static void ipu_pixel_clk_disable(struct clk *clk)
  277. {
  278. u32 disp_gen = __raw_readl(IPU_DISP_GEN);
  279. disp_gen &= clk->id ? ~DI1_COUNTER_RELEASE : ~DI0_COUNTER_RELEASE;
  280. __raw_writel(disp_gen, IPU_DISP_GEN);
  281. }
  282. static int ipu_pixel_clk_set_parent(struct clk *clk, struct clk *parent)
  283. {
  284. u32 di_gen = __raw_readl(DI_GENERAL(clk->id));
  285. if (parent == g_ipu_clk)
  286. di_gen &= ~DI_GEN_DI_CLK_EXT;
  287. else if (!IS_ERR(g_di_clk[clk->id]) && parent == g_ldb_clk)
  288. di_gen |= DI_GEN_DI_CLK_EXT;
  289. else
  290. return -EINVAL;
  291. __raw_writel(di_gen, DI_GENERAL(clk->id));
  292. ipu_pixel_clk_recalc(clk);
  293. return 0;
  294. }
  295. static struct clk pixel_clk[] = {
  296. {
  297. .name = "pixel_clk",
  298. .id = 0,
  299. .recalc = ipu_pixel_clk_recalc,
  300. .set_rate = ipu_pixel_clk_set_rate,
  301. .round_rate = ipu_pixel_clk_round_rate,
  302. .set_parent = ipu_pixel_clk_set_parent,
  303. .enable = ipu_pixel_clk_enable,
  304. .disable = ipu_pixel_clk_disable,
  305. .usecount = 0,
  306. },
  307. {
  308. .name = "pixel_clk",
  309. .id = 1,
  310. .recalc = ipu_pixel_clk_recalc,
  311. .set_rate = ipu_pixel_clk_set_rate,
  312. .round_rate = ipu_pixel_clk_round_rate,
  313. .set_parent = ipu_pixel_clk_set_parent,
  314. .enable = ipu_pixel_clk_enable,
  315. .disable = ipu_pixel_clk_disable,
  316. .usecount = 0,
  317. },
  318. };
  319. /*
  320. * This function resets IPU
  321. */
  322. static void ipu_reset(void)
  323. {
  324. u32 *reg;
  325. u32 value;
  326. int timeout = IPU_SW_RST_TOUT_USEC;
  327. reg = (u32 *)SRC_BASE_ADDR;
  328. value = __raw_readl(reg);
  329. value = value | SW_IPU_RST;
  330. __raw_writel(value, reg);
  331. while (__raw_readl(reg) & SW_IPU_RST) {
  332. udelay(1);
  333. if (!(timeout--)) {
  334. printf("ipu software reset timeout\n");
  335. break;
  336. }
  337. };
  338. }
  339. /*
  340. * This function is called by the driver framework to initialize the IPU
  341. * hardware.
  342. *
  343. * @param dev The device structure for the IPU passed in by the
  344. * driver framework.
  345. *
  346. * @return Returns 0 on success or negative error code on error
  347. */
  348. int ipu_probe(void)
  349. {
  350. unsigned long ipu_base;
  351. #if defined CONFIG_MX51
  352. u32 temp;
  353. u32 *reg_hsc_mcd = (u32 *)MIPI_HSC_BASE_ADDR;
  354. u32 *reg_hsc_mxt_conf = (u32 *)(MIPI_HSC_BASE_ADDR + 0x800);
  355. __raw_writel(0xF00, reg_hsc_mcd);
  356. /* CSI mode reserved*/
  357. temp = __raw_readl(reg_hsc_mxt_conf);
  358. __raw_writel(temp | 0x0FF, reg_hsc_mxt_conf);
  359. temp = __raw_readl(reg_hsc_mxt_conf);
  360. __raw_writel(temp | 0x10000, reg_hsc_mxt_conf);
  361. #endif
  362. ipu_base = IPU_CTRL_BASE_ADDR;
  363. ipu_cpmem_base = (u32 *)(ipu_base + IPU_CPMEM_REG_BASE);
  364. ipu_dc_tmpl_reg = (u32 *)(ipu_base + IPU_DC_TMPL_REG_BASE);
  365. g_pixel_clk[0] = &pixel_clk[0];
  366. g_pixel_clk[1] = &pixel_clk[1];
  367. g_ipu_clk = &ipu_clk;
  368. debug("ipu_clk = %u\n", clk_get_rate(g_ipu_clk));
  369. g_ldb_clk = &ldb_clk;
  370. debug("ldb_clk = %u\n", clk_get_rate(g_ldb_clk));
  371. ipu_reset();
  372. clk_set_parent(g_pixel_clk[0], g_ipu_clk);
  373. clk_set_parent(g_pixel_clk[1], g_ipu_clk);
  374. clk_enable(g_ipu_clk);
  375. g_di_clk[0] = NULL;
  376. g_di_clk[1] = NULL;
  377. __raw_writel(0x807FFFFF, IPU_MEM_RST);
  378. while (__raw_readl(IPU_MEM_RST) & 0x80000000)
  379. ;
  380. ipu_init_dc_mappings();
  381. __raw_writel(0, IPU_INT_CTRL(5));
  382. __raw_writel(0, IPU_INT_CTRL(6));
  383. __raw_writel(0, IPU_INT_CTRL(9));
  384. __raw_writel(0, IPU_INT_CTRL(10));
  385. /* DMFC Init */
  386. ipu_dmfc_init(DMFC_NORMAL, 1);
  387. /* Set sync refresh channels as high priority */
  388. __raw_writel(0x18800000L, IDMAC_CHA_PRI(0));
  389. /* Set MCU_T to divide MCU access window into 2 */
  390. __raw_writel(0x00400000L | (IPU_MCU_T_DEFAULT << 18), IPU_DISP_GEN);
  391. clk_disable(g_ipu_clk);
  392. return 0;
  393. }
  394. void ipu_dump_registers(void)
  395. {
  396. debug("IPU_CONF = \t0x%08X\n", __raw_readl(IPU_CONF));
  397. debug("IDMAC_CONF = \t0x%08X\n", __raw_readl(IDMAC_CONF));
  398. debug("IDMAC_CHA_EN1 = \t0x%08X\n",
  399. __raw_readl(IDMAC_CHA_EN(0)));
  400. debug("IDMAC_CHA_EN2 = \t0x%08X\n",
  401. __raw_readl(IDMAC_CHA_EN(32)));
  402. debug("IDMAC_CHA_PRI1 = \t0x%08X\n",
  403. __raw_readl(IDMAC_CHA_PRI(0)));
  404. debug("IDMAC_CHA_PRI2 = \t0x%08X\n",
  405. __raw_readl(IDMAC_CHA_PRI(32)));
  406. debug("IPU_CHA_DB_MODE_SEL0 = \t0x%08X\n",
  407. __raw_readl(IPU_CHA_DB_MODE_SEL(0)));
  408. debug("IPU_CHA_DB_MODE_SEL1 = \t0x%08X\n",
  409. __raw_readl(IPU_CHA_DB_MODE_SEL(32)));
  410. debug("DMFC_WR_CHAN = \t0x%08X\n",
  411. __raw_readl(DMFC_WR_CHAN));
  412. debug("DMFC_WR_CHAN_DEF = \t0x%08X\n",
  413. __raw_readl(DMFC_WR_CHAN_DEF));
  414. debug("DMFC_DP_CHAN = \t0x%08X\n",
  415. __raw_readl(DMFC_DP_CHAN));
  416. debug("DMFC_DP_CHAN_DEF = \t0x%08X\n",
  417. __raw_readl(DMFC_DP_CHAN_DEF));
  418. debug("DMFC_IC_CTRL = \t0x%08X\n",
  419. __raw_readl(DMFC_IC_CTRL));
  420. debug("IPU_FS_PROC_FLOW1 = \t0x%08X\n",
  421. __raw_readl(IPU_FS_PROC_FLOW1));
  422. debug("IPU_FS_PROC_FLOW2 = \t0x%08X\n",
  423. __raw_readl(IPU_FS_PROC_FLOW2));
  424. debug("IPU_FS_PROC_FLOW3 = \t0x%08X\n",
  425. __raw_readl(IPU_FS_PROC_FLOW3));
  426. debug("IPU_FS_DISP_FLOW1 = \t0x%08X\n",
  427. __raw_readl(IPU_FS_DISP_FLOW1));
  428. }
  429. /*
  430. * This function is called to initialize a logical IPU channel.
  431. *
  432. * @param channel Input parameter for the logical channel ID to init.
  433. *
  434. * @param params Input parameter containing union of channel
  435. * initialization parameters.
  436. *
  437. * @return Returns 0 on success or negative error code on fail
  438. */
  439. int32_t ipu_init_channel(ipu_channel_t channel, ipu_channel_params_t *params)
  440. {
  441. int ret = 0;
  442. uint32_t ipu_conf;
  443. debug("init channel = %d\n", IPU_CHAN_ID(channel));
  444. if (g_ipu_clk_enabled == 0) {
  445. g_ipu_clk_enabled = 1;
  446. clk_enable(g_ipu_clk);
  447. }
  448. if (g_channel_init_mask & (1L << IPU_CHAN_ID(channel))) {
  449. printf("Warning: channel already initialized %d\n",
  450. IPU_CHAN_ID(channel));
  451. }
  452. ipu_conf = __raw_readl(IPU_CONF);
  453. switch (channel) {
  454. case MEM_DC_SYNC:
  455. if (params->mem_dc_sync.di > 1) {
  456. ret = -EINVAL;
  457. goto err;
  458. }
  459. g_dc_di_assignment[1] = params->mem_dc_sync.di;
  460. ipu_dc_init(1, params->mem_dc_sync.di,
  461. params->mem_dc_sync.interlaced);
  462. ipu_di_use_count[params->mem_dc_sync.di]++;
  463. ipu_dc_use_count++;
  464. ipu_dmfc_use_count++;
  465. break;
  466. case MEM_BG_SYNC:
  467. if (params->mem_dp_bg_sync.di > 1) {
  468. ret = -EINVAL;
  469. goto err;
  470. }
  471. g_dc_di_assignment[5] = params->mem_dp_bg_sync.di;
  472. ipu_dp_init(channel, params->mem_dp_bg_sync.in_pixel_fmt,
  473. params->mem_dp_bg_sync.out_pixel_fmt);
  474. ipu_dc_init(5, params->mem_dp_bg_sync.di,
  475. params->mem_dp_bg_sync.interlaced);
  476. ipu_di_use_count[params->mem_dp_bg_sync.di]++;
  477. ipu_dc_use_count++;
  478. ipu_dp_use_count++;
  479. ipu_dmfc_use_count++;
  480. break;
  481. case MEM_FG_SYNC:
  482. ipu_dp_init(channel, params->mem_dp_fg_sync.in_pixel_fmt,
  483. params->mem_dp_fg_sync.out_pixel_fmt);
  484. ipu_dc_use_count++;
  485. ipu_dp_use_count++;
  486. ipu_dmfc_use_count++;
  487. break;
  488. default:
  489. printf("Missing channel initialization\n");
  490. break;
  491. }
  492. /* Enable IPU sub module */
  493. g_channel_init_mask |= 1L << IPU_CHAN_ID(channel);
  494. if (ipu_dc_use_count == 1)
  495. ipu_conf |= IPU_CONF_DC_EN;
  496. if (ipu_dp_use_count == 1)
  497. ipu_conf |= IPU_CONF_DP_EN;
  498. if (ipu_dmfc_use_count == 1)
  499. ipu_conf |= IPU_CONF_DMFC_EN;
  500. if (ipu_di_use_count[0] == 1) {
  501. ipu_conf |= IPU_CONF_DI0_EN;
  502. }
  503. if (ipu_di_use_count[1] == 1) {
  504. ipu_conf |= IPU_CONF_DI1_EN;
  505. }
  506. __raw_writel(ipu_conf, IPU_CONF);
  507. err:
  508. return ret;
  509. }
  510. /*
  511. * This function is called to uninitialize a logical IPU channel.
  512. *
  513. * @param channel Input parameter for the logical channel ID to uninit.
  514. */
  515. void ipu_uninit_channel(ipu_channel_t channel)
  516. {
  517. uint32_t reg;
  518. uint32_t in_dma, out_dma = 0;
  519. uint32_t ipu_conf;
  520. if ((g_channel_init_mask & (1L << IPU_CHAN_ID(channel))) == 0) {
  521. debug("Channel already uninitialized %d\n",
  522. IPU_CHAN_ID(channel));
  523. return;
  524. }
  525. /*
  526. * Make sure channel is disabled
  527. * Get input and output dma channels
  528. */
  529. in_dma = channel_2_dma(channel, IPU_OUTPUT_BUFFER);
  530. out_dma = channel_2_dma(channel, IPU_VIDEO_IN_BUFFER);
  531. if (idma_is_set(IDMAC_CHA_EN, in_dma) ||
  532. idma_is_set(IDMAC_CHA_EN, out_dma)) {
  533. printf(
  534. "Channel %d is not disabled, disable first\n",
  535. IPU_CHAN_ID(channel));
  536. return;
  537. }
  538. ipu_conf = __raw_readl(IPU_CONF);
  539. /* Reset the double buffer */
  540. reg = __raw_readl(IPU_CHA_DB_MODE_SEL(in_dma));
  541. __raw_writel(reg & ~idma_mask(in_dma), IPU_CHA_DB_MODE_SEL(in_dma));
  542. reg = __raw_readl(IPU_CHA_DB_MODE_SEL(out_dma));
  543. __raw_writel(reg & ~idma_mask(out_dma), IPU_CHA_DB_MODE_SEL(out_dma));
  544. switch (channel) {
  545. case MEM_DC_SYNC:
  546. ipu_dc_uninit(1);
  547. ipu_di_use_count[g_dc_di_assignment[1]]--;
  548. ipu_dc_use_count--;
  549. ipu_dmfc_use_count--;
  550. break;
  551. case MEM_BG_SYNC:
  552. ipu_dp_uninit(channel);
  553. ipu_dc_uninit(5);
  554. ipu_di_use_count[g_dc_di_assignment[5]]--;
  555. ipu_dc_use_count--;
  556. ipu_dp_use_count--;
  557. ipu_dmfc_use_count--;
  558. break;
  559. case MEM_FG_SYNC:
  560. ipu_dp_uninit(channel);
  561. ipu_dc_use_count--;
  562. ipu_dp_use_count--;
  563. ipu_dmfc_use_count--;
  564. break;
  565. default:
  566. break;
  567. }
  568. g_channel_init_mask &= ~(1L << IPU_CHAN_ID(channel));
  569. if (ipu_dc_use_count == 0)
  570. ipu_conf &= ~IPU_CONF_DC_EN;
  571. if (ipu_dp_use_count == 0)
  572. ipu_conf &= ~IPU_CONF_DP_EN;
  573. if (ipu_dmfc_use_count == 0)
  574. ipu_conf &= ~IPU_CONF_DMFC_EN;
  575. if (ipu_di_use_count[0] == 0) {
  576. ipu_conf &= ~IPU_CONF_DI0_EN;
  577. }
  578. if (ipu_di_use_count[1] == 0) {
  579. ipu_conf &= ~IPU_CONF_DI1_EN;
  580. }
  581. __raw_writel(ipu_conf, IPU_CONF);
  582. if (ipu_conf == 0) {
  583. clk_disable(g_ipu_clk);
  584. g_ipu_clk_enabled = 0;
  585. }
  586. }
  587. static inline void ipu_ch_param_dump(int ch)
  588. {
  589. #ifdef DEBUG
  590. struct ipu_ch_param *p = ipu_ch_param_addr(ch);
  591. debug("ch %d word 0 - %08X %08X %08X %08X %08X\n", ch,
  592. p->word[0].data[0], p->word[0].data[1], p->word[0].data[2],
  593. p->word[0].data[3], p->word[0].data[4]);
  594. debug("ch %d word 1 - %08X %08X %08X %08X %08X\n", ch,
  595. p->word[1].data[0], p->word[1].data[1], p->word[1].data[2],
  596. p->word[1].data[3], p->word[1].data[4]);
  597. debug("PFS 0x%x, ",
  598. ipu_ch_param_read_field(ipu_ch_param_addr(ch), 1, 85, 4));
  599. debug("BPP 0x%x, ",
  600. ipu_ch_param_read_field(ipu_ch_param_addr(ch), 0, 107, 3));
  601. debug("NPB 0x%x\n",
  602. ipu_ch_param_read_field(ipu_ch_param_addr(ch), 1, 78, 7));
  603. debug("FW %d, ",
  604. ipu_ch_param_read_field(ipu_ch_param_addr(ch), 0, 125, 13));
  605. debug("FH %d, ",
  606. ipu_ch_param_read_field(ipu_ch_param_addr(ch), 0, 138, 12));
  607. debug("Stride %d\n",
  608. ipu_ch_param_read_field(ipu_ch_param_addr(ch), 1, 102, 14));
  609. debug("Width0 %d+1, ",
  610. ipu_ch_param_read_field(ipu_ch_param_addr(ch), 1, 116, 3));
  611. debug("Width1 %d+1, ",
  612. ipu_ch_param_read_field(ipu_ch_param_addr(ch), 1, 119, 3));
  613. debug("Width2 %d+1, ",
  614. ipu_ch_param_read_field(ipu_ch_param_addr(ch), 1, 122, 3));
  615. debug("Width3 %d+1, ",
  616. ipu_ch_param_read_field(ipu_ch_param_addr(ch), 1, 125, 3));
  617. debug("Offset0 %d, ",
  618. ipu_ch_param_read_field(ipu_ch_param_addr(ch), 1, 128, 5));
  619. debug("Offset1 %d, ",
  620. ipu_ch_param_read_field(ipu_ch_param_addr(ch), 1, 133, 5));
  621. debug("Offset2 %d, ",
  622. ipu_ch_param_read_field(ipu_ch_param_addr(ch), 1, 138, 5));
  623. debug("Offset3 %d\n",
  624. ipu_ch_param_read_field(ipu_ch_param_addr(ch), 1, 143, 5));
  625. #endif
  626. }
  627. static inline void ipu_ch_params_set_packing(struct ipu_ch_param *p,
  628. int red_width, int red_offset,
  629. int green_width, int green_offset,
  630. int blue_width, int blue_offset,
  631. int alpha_width, int alpha_offset)
  632. {
  633. /* Setup red width and offset */
  634. ipu_ch_param_set_field(p, 1, 116, 3, red_width - 1);
  635. ipu_ch_param_set_field(p, 1, 128, 5, red_offset);
  636. /* Setup green width and offset */
  637. ipu_ch_param_set_field(p, 1, 119, 3, green_width - 1);
  638. ipu_ch_param_set_field(p, 1, 133, 5, green_offset);
  639. /* Setup blue width and offset */
  640. ipu_ch_param_set_field(p, 1, 122, 3, blue_width - 1);
  641. ipu_ch_param_set_field(p, 1, 138, 5, blue_offset);
  642. /* Setup alpha width and offset */
  643. ipu_ch_param_set_field(p, 1, 125, 3, alpha_width - 1);
  644. ipu_ch_param_set_field(p, 1, 143, 5, alpha_offset);
  645. }
  646. static void ipu_ch_param_init(int ch,
  647. uint32_t pixel_fmt, uint32_t width,
  648. uint32_t height, uint32_t stride,
  649. uint32_t u, uint32_t v,
  650. uint32_t uv_stride, dma_addr_t addr0,
  651. dma_addr_t addr1)
  652. {
  653. uint32_t u_offset = 0;
  654. uint32_t v_offset = 0;
  655. struct ipu_ch_param params;
  656. memset(&params, 0, sizeof(params));
  657. ipu_ch_param_set_field(&params, 0, 125, 13, width - 1);
  658. if ((ch == 8) || (ch == 9) || (ch == 10)) {
  659. ipu_ch_param_set_field(&params, 0, 138, 12, (height / 2) - 1);
  660. ipu_ch_param_set_field(&params, 1, 102, 14, (stride * 2) - 1);
  661. } else {
  662. ipu_ch_param_set_field(&params, 0, 138, 12, height - 1);
  663. ipu_ch_param_set_field(&params, 1, 102, 14, stride - 1);
  664. }
  665. ipu_ch_param_set_field(&params, 1, 0, 29, addr0 >> 3);
  666. ipu_ch_param_set_field(&params, 1, 29, 29, addr1 >> 3);
  667. switch (pixel_fmt) {
  668. case IPU_PIX_FMT_GENERIC:
  669. /*Represents 8-bit Generic data */
  670. ipu_ch_param_set_field(&params, 0, 107, 3, 5); /* bits/pixel */
  671. ipu_ch_param_set_field(&params, 1, 85, 4, 6); /* pix format */
  672. ipu_ch_param_set_field(&params, 1, 78, 7, 63); /* burst size */
  673. break;
  674. case IPU_PIX_FMT_GENERIC_32:
  675. /*Represents 32-bit Generic data */
  676. break;
  677. case IPU_PIX_FMT_RGB565:
  678. ipu_ch_param_set_field(&params, 0, 107, 3, 3); /* bits/pixel */
  679. ipu_ch_param_set_field(&params, 1, 85, 4, 7); /* pix format */
  680. ipu_ch_param_set_field(&params, 1, 78, 7, 15); /* burst size */
  681. ipu_ch_params_set_packing(&params, 5, 0, 6, 5, 5, 11, 8, 16);
  682. break;
  683. case IPU_PIX_FMT_BGR24:
  684. ipu_ch_param_set_field(&params, 0, 107, 3, 1); /* bits/pixel */
  685. ipu_ch_param_set_field(&params, 1, 85, 4, 7); /* pix format */
  686. ipu_ch_param_set_field(&params, 1, 78, 7, 19); /* burst size */
  687. ipu_ch_params_set_packing(&params, 8, 0, 8, 8, 8, 16, 8, 24);
  688. break;
  689. case IPU_PIX_FMT_RGB24:
  690. case IPU_PIX_FMT_YUV444:
  691. ipu_ch_param_set_field(&params, 0, 107, 3, 1); /* bits/pixel */
  692. ipu_ch_param_set_field(&params, 1, 85, 4, 7); /* pix format */
  693. ipu_ch_param_set_field(&params, 1, 78, 7, 19); /* burst size */
  694. ipu_ch_params_set_packing(&params, 8, 16, 8, 8, 8, 0, 8, 24);
  695. break;
  696. case IPU_PIX_FMT_BGRA32:
  697. case IPU_PIX_FMT_BGR32:
  698. ipu_ch_param_set_field(&params, 0, 107, 3, 0); /* bits/pixel */
  699. ipu_ch_param_set_field(&params, 1, 85, 4, 7); /* pix format */
  700. ipu_ch_param_set_field(&params, 1, 78, 7, 15); /* burst size */
  701. ipu_ch_params_set_packing(&params, 8, 8, 8, 16, 8, 24, 8, 0);
  702. break;
  703. case IPU_PIX_FMT_RGBA32:
  704. case IPU_PIX_FMT_RGB32:
  705. ipu_ch_param_set_field(&params, 0, 107, 3, 0); /* bits/pixel */
  706. ipu_ch_param_set_field(&params, 1, 85, 4, 7); /* pix format */
  707. ipu_ch_param_set_field(&params, 1, 78, 7, 15); /* burst size */
  708. ipu_ch_params_set_packing(&params, 8, 24, 8, 16, 8, 8, 8, 0);
  709. break;
  710. case IPU_PIX_FMT_ABGR32:
  711. ipu_ch_param_set_field(&params, 0, 107, 3, 0); /* bits/pixel */
  712. ipu_ch_param_set_field(&params, 1, 85, 4, 7); /* pix format */
  713. ipu_ch_params_set_packing(&params, 8, 0, 8, 8, 8, 16, 8, 24);
  714. break;
  715. case IPU_PIX_FMT_UYVY:
  716. ipu_ch_param_set_field(&params, 0, 107, 3, 3); /* bits/pixel */
  717. ipu_ch_param_set_field(&params, 1, 85, 4, 0xA); /* pix format */
  718. ipu_ch_param_set_field(&params, 1, 78, 7, 15); /* burst size */
  719. break;
  720. case IPU_PIX_FMT_YUYV:
  721. ipu_ch_param_set_field(&params, 0, 107, 3, 3); /* bits/pixel */
  722. ipu_ch_param_set_field(&params, 1, 85, 4, 0x8); /* pix format */
  723. ipu_ch_param_set_field(&params, 1, 78, 7, 31); /* burst size */
  724. break;
  725. case IPU_PIX_FMT_YUV420P2:
  726. case IPU_PIX_FMT_YUV420P:
  727. ipu_ch_param_set_field(&params, 1, 85, 4, 2); /* pix format */
  728. if (uv_stride < stride / 2)
  729. uv_stride = stride / 2;
  730. u_offset = stride * height;
  731. v_offset = u_offset + (uv_stride * height / 2);
  732. /* burst size */
  733. if ((ch == 8) || (ch == 9) || (ch == 10)) {
  734. ipu_ch_param_set_field(&params, 1, 78, 7, 15);
  735. uv_stride = uv_stride*2;
  736. } else {
  737. ipu_ch_param_set_field(&params, 1, 78, 7, 31);
  738. }
  739. break;
  740. case IPU_PIX_FMT_YVU422P:
  741. /* BPP & pixel format */
  742. ipu_ch_param_set_field(&params, 1, 85, 4, 1); /* pix format */
  743. ipu_ch_param_set_field(&params, 1, 78, 7, 31); /* burst size */
  744. if (uv_stride < stride / 2)
  745. uv_stride = stride / 2;
  746. v_offset = (v == 0) ? stride * height : v;
  747. u_offset = (u == 0) ? v_offset + v_offset / 2 : u;
  748. break;
  749. case IPU_PIX_FMT_YUV422P:
  750. /* BPP & pixel format */
  751. ipu_ch_param_set_field(&params, 1, 85, 4, 1); /* pix format */
  752. ipu_ch_param_set_field(&params, 1, 78, 7, 31); /* burst size */
  753. if (uv_stride < stride / 2)
  754. uv_stride = stride / 2;
  755. u_offset = (u == 0) ? stride * height : u;
  756. v_offset = (v == 0) ? u_offset + u_offset / 2 : v;
  757. break;
  758. case IPU_PIX_FMT_NV12:
  759. /* BPP & pixel format */
  760. ipu_ch_param_set_field(&params, 1, 85, 4, 4); /* pix format */
  761. ipu_ch_param_set_field(&params, 1, 78, 7, 31); /* burst size */
  762. uv_stride = stride;
  763. u_offset = (u == 0) ? stride * height : u;
  764. break;
  765. default:
  766. puts("mxc ipu: unimplemented pixel format\n");
  767. break;
  768. }
  769. if (uv_stride)
  770. ipu_ch_param_set_field(&params, 1, 128, 14, uv_stride - 1);
  771. /* Get the uv offset from user when need cropping */
  772. if (u || v) {
  773. u_offset = u;
  774. v_offset = v;
  775. }
  776. /* UBO and VBO are 22-bit */
  777. if (u_offset/8 > 0x3fffff)
  778. puts("The value of U offset exceeds IPU limitation\n");
  779. if (v_offset/8 > 0x3fffff)
  780. puts("The value of V offset exceeds IPU limitation\n");
  781. ipu_ch_param_set_field(&params, 0, 46, 22, u_offset / 8);
  782. ipu_ch_param_set_field(&params, 0, 68, 22, v_offset / 8);
  783. debug("initializing idma ch %d @ %p\n", ch, ipu_ch_param_addr(ch));
  784. memcpy(ipu_ch_param_addr(ch), &params, sizeof(params));
  785. };
  786. /*
  787. * This function is called to initialize a buffer for logical IPU channel.
  788. *
  789. * @param channel Input parameter for the logical channel ID.
  790. *
  791. * @param type Input parameter which buffer to initialize.
  792. *
  793. * @param pixel_fmt Input parameter for pixel format of buffer.
  794. * Pixel format is a FOURCC ASCII code.
  795. *
  796. * @param width Input parameter for width of buffer in pixels.
  797. *
  798. * @param height Input parameter for height of buffer in pixels.
  799. *
  800. * @param stride Input parameter for stride length of buffer
  801. * in pixels.
  802. *
  803. * @param phyaddr_0 Input parameter buffer 0 physical address.
  804. *
  805. * @param phyaddr_1 Input parameter buffer 1 physical address.
  806. * Setting this to a value other than NULL enables
  807. * double buffering mode.
  808. *
  809. * @param u private u offset for additional cropping,
  810. * zero if not used.
  811. *
  812. * @param v private v offset for additional cropping,
  813. * zero if not used.
  814. *
  815. * @return Returns 0 on success or negative error code on fail
  816. */
  817. int32_t ipu_init_channel_buffer(ipu_channel_t channel, ipu_buffer_t type,
  818. uint32_t pixel_fmt,
  819. uint16_t width, uint16_t height,
  820. uint32_t stride,
  821. dma_addr_t phyaddr_0, dma_addr_t phyaddr_1,
  822. uint32_t u, uint32_t v)
  823. {
  824. uint32_t reg;
  825. uint32_t dma_chan;
  826. dma_chan = channel_2_dma(channel, type);
  827. if (!idma_is_valid(dma_chan))
  828. return -EINVAL;
  829. if (stride < width * bytes_per_pixel(pixel_fmt))
  830. stride = width * bytes_per_pixel(pixel_fmt);
  831. if (stride % 4) {
  832. printf(
  833. "Stride not 32-bit aligned, stride = %d\n", stride);
  834. return -EINVAL;
  835. }
  836. /* Build parameter memory data for DMA channel */
  837. ipu_ch_param_init(dma_chan, pixel_fmt, width, height, stride, u, v, 0,
  838. phyaddr_0, phyaddr_1);
  839. if (ipu_is_dmfc_chan(dma_chan)) {
  840. ipu_dmfc_set_wait4eot(dma_chan, width);
  841. }
  842. if (idma_is_set(IDMAC_CHA_PRI, dma_chan))
  843. ipu_ch_param_set_high_priority(dma_chan);
  844. ipu_ch_param_dump(dma_chan);
  845. reg = __raw_readl(IPU_CHA_DB_MODE_SEL(dma_chan));
  846. if (phyaddr_1)
  847. reg |= idma_mask(dma_chan);
  848. else
  849. reg &= ~idma_mask(dma_chan);
  850. __raw_writel(reg, IPU_CHA_DB_MODE_SEL(dma_chan));
  851. /* Reset to buffer 0 */
  852. __raw_writel(idma_mask(dma_chan), IPU_CHA_CUR_BUF(dma_chan));
  853. return 0;
  854. }
  855. /*
  856. * This function enables a logical channel.
  857. *
  858. * @param channel Input parameter for the logical channel ID.
  859. *
  860. * @return This function returns 0 on success or negative error code on
  861. * fail.
  862. */
  863. int32_t ipu_enable_channel(ipu_channel_t channel)
  864. {
  865. uint32_t reg;
  866. uint32_t in_dma;
  867. uint32_t out_dma;
  868. if (g_channel_enable_mask & (1L << IPU_CHAN_ID(channel))) {
  869. printf("Warning: channel already enabled %d\n",
  870. IPU_CHAN_ID(channel));
  871. }
  872. /* Get input and output dma channels */
  873. out_dma = channel_2_dma(channel, IPU_OUTPUT_BUFFER);
  874. in_dma = channel_2_dma(channel, IPU_VIDEO_IN_BUFFER);
  875. if (idma_is_valid(in_dma)) {
  876. reg = __raw_readl(IDMAC_CHA_EN(in_dma));
  877. __raw_writel(reg | idma_mask(in_dma), IDMAC_CHA_EN(in_dma));
  878. }
  879. if (idma_is_valid(out_dma)) {
  880. reg = __raw_readl(IDMAC_CHA_EN(out_dma));
  881. __raw_writel(reg | idma_mask(out_dma), IDMAC_CHA_EN(out_dma));
  882. }
  883. if ((channel == MEM_DC_SYNC) || (channel == MEM_BG_SYNC) ||
  884. (channel == MEM_FG_SYNC))
  885. ipu_dp_dc_enable(channel);
  886. g_channel_enable_mask |= 1L << IPU_CHAN_ID(channel);
  887. return 0;
  888. }
  889. /*
  890. * This function clear buffer ready for a logical channel.
  891. *
  892. * @param channel Input parameter for the logical channel ID.
  893. *
  894. * @param type Input parameter which buffer to clear.
  895. *
  896. * @param bufNum Input parameter for which buffer number clear
  897. * ready state.
  898. *
  899. */
  900. void ipu_clear_buffer_ready(ipu_channel_t channel, ipu_buffer_t type,
  901. uint32_t bufNum)
  902. {
  903. uint32_t dma_ch = channel_2_dma(channel, type);
  904. if (!idma_is_valid(dma_ch))
  905. return;
  906. __raw_writel(0xF0000000, IPU_GPR); /* write one to clear */
  907. if (bufNum == 0) {
  908. if (idma_is_set(IPU_CHA_BUF0_RDY, dma_ch)) {
  909. __raw_writel(idma_mask(dma_ch),
  910. IPU_CHA_BUF0_RDY(dma_ch));
  911. }
  912. } else {
  913. if (idma_is_set(IPU_CHA_BUF1_RDY, dma_ch)) {
  914. __raw_writel(idma_mask(dma_ch),
  915. IPU_CHA_BUF1_RDY(dma_ch));
  916. }
  917. }
  918. __raw_writel(0x0, IPU_GPR); /* write one to set */
  919. }
  920. /*
  921. * This function disables a logical channel.
  922. *
  923. * @param channel Input parameter for the logical channel ID.
  924. *
  925. * @param wait_for_stop Flag to set whether to wait for channel end
  926. * of frame or return immediately.
  927. *
  928. * @return This function returns 0 on success or negative error code on
  929. * fail.
  930. */
  931. int32_t ipu_disable_channel(ipu_channel_t channel)
  932. {
  933. uint32_t reg;
  934. uint32_t in_dma;
  935. uint32_t out_dma;
  936. if ((g_channel_enable_mask & (1L << IPU_CHAN_ID(channel))) == 0) {
  937. debug("Channel already disabled %d\n",
  938. IPU_CHAN_ID(channel));
  939. return 0;
  940. }
  941. /* Get input and output dma channels */
  942. out_dma = channel_2_dma(channel, IPU_OUTPUT_BUFFER);
  943. in_dma = channel_2_dma(channel, IPU_VIDEO_IN_BUFFER);
  944. if ((idma_is_valid(in_dma) &&
  945. !idma_is_set(IDMAC_CHA_EN, in_dma))
  946. && (idma_is_valid(out_dma) &&
  947. !idma_is_set(IDMAC_CHA_EN, out_dma)))
  948. return -EINVAL;
  949. if ((channel == MEM_BG_SYNC) || (channel == MEM_FG_SYNC) ||
  950. (channel == MEM_DC_SYNC)) {
  951. ipu_dp_dc_disable(channel, 0);
  952. }
  953. /* Disable DMA channel(s) */
  954. if (idma_is_valid(in_dma)) {
  955. reg = __raw_readl(IDMAC_CHA_EN(in_dma));
  956. __raw_writel(reg & ~idma_mask(in_dma), IDMAC_CHA_EN(in_dma));
  957. __raw_writel(idma_mask(in_dma), IPU_CHA_CUR_BUF(in_dma));
  958. }
  959. if (idma_is_valid(out_dma)) {
  960. reg = __raw_readl(IDMAC_CHA_EN(out_dma));
  961. __raw_writel(reg & ~idma_mask(out_dma), IDMAC_CHA_EN(out_dma));
  962. __raw_writel(idma_mask(out_dma), IPU_CHA_CUR_BUF(out_dma));
  963. }
  964. g_channel_enable_mask &= ~(1L << IPU_CHAN_ID(channel));
  965. /* Set channel buffers NOT to be ready */
  966. if (idma_is_valid(in_dma)) {
  967. ipu_clear_buffer_ready(channel, IPU_VIDEO_IN_BUFFER, 0);
  968. ipu_clear_buffer_ready(channel, IPU_VIDEO_IN_BUFFER, 1);
  969. }
  970. if (idma_is_valid(out_dma)) {
  971. ipu_clear_buffer_ready(channel, IPU_OUTPUT_BUFFER, 0);
  972. ipu_clear_buffer_ready(channel, IPU_OUTPUT_BUFFER, 1);
  973. }
  974. return 0;
  975. }
  976. uint32_t bytes_per_pixel(uint32_t fmt)
  977. {
  978. switch (fmt) {
  979. case IPU_PIX_FMT_GENERIC: /*generic data */
  980. case IPU_PIX_FMT_RGB332:
  981. case IPU_PIX_FMT_YUV420P:
  982. case IPU_PIX_FMT_YUV422P:
  983. return 1;
  984. break;
  985. case IPU_PIX_FMT_RGB565:
  986. case IPU_PIX_FMT_YUYV:
  987. case IPU_PIX_FMT_UYVY:
  988. return 2;
  989. break;
  990. case IPU_PIX_FMT_BGR24:
  991. case IPU_PIX_FMT_RGB24:
  992. return 3;
  993. break;
  994. case IPU_PIX_FMT_GENERIC_32: /*generic data */
  995. case IPU_PIX_FMT_BGR32:
  996. case IPU_PIX_FMT_BGRA32:
  997. case IPU_PIX_FMT_RGB32:
  998. case IPU_PIX_FMT_RGBA32:
  999. case IPU_PIX_FMT_ABGR32:
  1000. return 4;
  1001. break;
  1002. default:
  1003. return 1;
  1004. break;
  1005. }
  1006. return 0;
  1007. }
  1008. ipu_color_space_t format_to_colorspace(uint32_t fmt)
  1009. {
  1010. switch (fmt) {
  1011. case IPU_PIX_FMT_RGB666:
  1012. case IPU_PIX_FMT_RGB565:
  1013. case IPU_PIX_FMT_BGR24:
  1014. case IPU_PIX_FMT_RGB24:
  1015. case IPU_PIX_FMT_BGR32:
  1016. case IPU_PIX_FMT_BGRA32:
  1017. case IPU_PIX_FMT_RGB32:
  1018. case IPU_PIX_FMT_RGBA32:
  1019. case IPU_PIX_FMT_ABGR32:
  1020. case IPU_PIX_FMT_LVDS666:
  1021. case IPU_PIX_FMT_LVDS888:
  1022. return RGB;
  1023. break;
  1024. default:
  1025. return YCbCr;
  1026. break;
  1027. }
  1028. return RGB;
  1029. }