ipu_common.c 32 KB

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