ipu_common.c 31 KB

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