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