ipu_common.c 32 KB

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