ipu_common.c 31 KB

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