ipu-ic.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. /*
  2. * Copyright (C) 2012-2014 Mentor Graphics Inc.
  3. * Copyright 2005-2012 Freescale Semiconductor, Inc. All Rights Reserved.
  4. *
  5. * The code contained herein is licensed under the GNU General Public
  6. * License. You may obtain a copy of the GNU General Public License
  7. * Version 2 or later at the following locations:
  8. *
  9. * http://www.opensource.org/licenses/gpl-license.html
  10. * http://www.gnu.org/copyleft/gpl.html
  11. */
  12. #include <linux/types.h>
  13. #include <linux/init.h>
  14. #include <linux/errno.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/bitrev.h>
  17. #include <linux/io.h>
  18. #include <linux/err.h>
  19. #include "ipu-prv.h"
  20. /* IC Register Offsets */
  21. #define IC_CONF 0x0000
  22. #define IC_PRP_ENC_RSC 0x0004
  23. #define IC_PRP_VF_RSC 0x0008
  24. #define IC_PP_RSC 0x000C
  25. #define IC_CMBP_1 0x0010
  26. #define IC_CMBP_2 0x0014
  27. #define IC_IDMAC_1 0x0018
  28. #define IC_IDMAC_2 0x001C
  29. #define IC_IDMAC_3 0x0020
  30. #define IC_IDMAC_4 0x0024
  31. /* IC Register Fields */
  32. #define IC_CONF_PRPENC_EN (1 << 0)
  33. #define IC_CONF_PRPENC_CSC1 (1 << 1)
  34. #define IC_CONF_PRPENC_ROT_EN (1 << 2)
  35. #define IC_CONF_PRPVF_EN (1 << 8)
  36. #define IC_CONF_PRPVF_CSC1 (1 << 9)
  37. #define IC_CONF_PRPVF_CSC2 (1 << 10)
  38. #define IC_CONF_PRPVF_CMB (1 << 11)
  39. #define IC_CONF_PRPVF_ROT_EN (1 << 12)
  40. #define IC_CONF_PP_EN (1 << 16)
  41. #define IC_CONF_PP_CSC1 (1 << 17)
  42. #define IC_CONF_PP_CSC2 (1 << 18)
  43. #define IC_CONF_PP_CMB (1 << 19)
  44. #define IC_CONF_PP_ROT_EN (1 << 20)
  45. #define IC_CONF_IC_GLB_LOC_A (1 << 28)
  46. #define IC_CONF_KEY_COLOR_EN (1 << 29)
  47. #define IC_CONF_RWS_EN (1 << 30)
  48. #define IC_CONF_CSI_MEM_WR_EN (1 << 31)
  49. #define IC_IDMAC_1_CB0_BURST_16 (1 << 0)
  50. #define IC_IDMAC_1_CB1_BURST_16 (1 << 1)
  51. #define IC_IDMAC_1_CB2_BURST_16 (1 << 2)
  52. #define IC_IDMAC_1_CB3_BURST_16 (1 << 3)
  53. #define IC_IDMAC_1_CB4_BURST_16 (1 << 4)
  54. #define IC_IDMAC_1_CB5_BURST_16 (1 << 5)
  55. #define IC_IDMAC_1_CB6_BURST_16 (1 << 6)
  56. #define IC_IDMAC_1_CB7_BURST_16 (1 << 7)
  57. #define IC_IDMAC_1_PRPENC_ROT_MASK (0x7 << 11)
  58. #define IC_IDMAC_1_PRPENC_ROT_OFFSET 11
  59. #define IC_IDMAC_1_PRPVF_ROT_MASK (0x7 << 14)
  60. #define IC_IDMAC_1_PRPVF_ROT_OFFSET 14
  61. #define IC_IDMAC_1_PP_ROT_MASK (0x7 << 17)
  62. #define IC_IDMAC_1_PP_ROT_OFFSET 17
  63. #define IC_IDMAC_1_PP_FLIP_RS (1 << 22)
  64. #define IC_IDMAC_1_PRPVF_FLIP_RS (1 << 21)
  65. #define IC_IDMAC_1_PRPENC_FLIP_RS (1 << 20)
  66. #define IC_IDMAC_2_PRPENC_HEIGHT_MASK (0x3ff << 0)
  67. #define IC_IDMAC_2_PRPENC_HEIGHT_OFFSET 0
  68. #define IC_IDMAC_2_PRPVF_HEIGHT_MASK (0x3ff << 10)
  69. #define IC_IDMAC_2_PRPVF_HEIGHT_OFFSET 10
  70. #define IC_IDMAC_2_PP_HEIGHT_MASK (0x3ff << 20)
  71. #define IC_IDMAC_2_PP_HEIGHT_OFFSET 20
  72. #define IC_IDMAC_3_PRPENC_WIDTH_MASK (0x3ff << 0)
  73. #define IC_IDMAC_3_PRPENC_WIDTH_OFFSET 0
  74. #define IC_IDMAC_3_PRPVF_WIDTH_MASK (0x3ff << 10)
  75. #define IC_IDMAC_3_PRPVF_WIDTH_OFFSET 10
  76. #define IC_IDMAC_3_PP_WIDTH_MASK (0x3ff << 20)
  77. #define IC_IDMAC_3_PP_WIDTH_OFFSET 20
  78. struct ic_task_regoffs {
  79. u32 rsc;
  80. u32 tpmem_csc[2];
  81. };
  82. struct ic_task_bitfields {
  83. u32 ic_conf_en;
  84. u32 ic_conf_rot_en;
  85. u32 ic_conf_cmb_en;
  86. u32 ic_conf_csc1_en;
  87. u32 ic_conf_csc2_en;
  88. u32 ic_cmb_galpha_bit;
  89. };
  90. static const struct ic_task_regoffs ic_task_reg[IC_NUM_TASKS] = {
  91. [IC_TASK_ENCODER] = {
  92. .rsc = IC_PRP_ENC_RSC,
  93. .tpmem_csc = {0x2008, 0},
  94. },
  95. [IC_TASK_VIEWFINDER] = {
  96. .rsc = IC_PRP_VF_RSC,
  97. .tpmem_csc = {0x4028, 0x4040},
  98. },
  99. [IC_TASK_POST_PROCESSOR] = {
  100. .rsc = IC_PP_RSC,
  101. .tpmem_csc = {0x6060, 0x6078},
  102. },
  103. };
  104. static const struct ic_task_bitfields ic_task_bit[IC_NUM_TASKS] = {
  105. [IC_TASK_ENCODER] = {
  106. .ic_conf_en = IC_CONF_PRPENC_EN,
  107. .ic_conf_rot_en = IC_CONF_PRPENC_ROT_EN,
  108. .ic_conf_cmb_en = 0, /* NA */
  109. .ic_conf_csc1_en = IC_CONF_PRPENC_CSC1,
  110. .ic_conf_csc2_en = 0, /* NA */
  111. .ic_cmb_galpha_bit = 0, /* NA */
  112. },
  113. [IC_TASK_VIEWFINDER] = {
  114. .ic_conf_en = IC_CONF_PRPVF_EN,
  115. .ic_conf_rot_en = IC_CONF_PRPVF_ROT_EN,
  116. .ic_conf_cmb_en = IC_CONF_PRPVF_CMB,
  117. .ic_conf_csc1_en = IC_CONF_PRPVF_CSC1,
  118. .ic_conf_csc2_en = IC_CONF_PRPVF_CSC2,
  119. .ic_cmb_galpha_bit = 0,
  120. },
  121. [IC_TASK_POST_PROCESSOR] = {
  122. .ic_conf_en = IC_CONF_PP_EN,
  123. .ic_conf_rot_en = IC_CONF_PP_ROT_EN,
  124. .ic_conf_cmb_en = IC_CONF_PP_CMB,
  125. .ic_conf_csc1_en = IC_CONF_PP_CSC1,
  126. .ic_conf_csc2_en = IC_CONF_PP_CSC2,
  127. .ic_cmb_galpha_bit = 8,
  128. },
  129. };
  130. struct ipu_ic_priv;
  131. struct ipu_ic {
  132. enum ipu_ic_task task;
  133. const struct ic_task_regoffs *reg;
  134. const struct ic_task_bitfields *bit;
  135. enum ipu_color_space in_cs, g_in_cs;
  136. enum ipu_color_space out_cs;
  137. bool graphics;
  138. bool rotation;
  139. bool in_use;
  140. struct ipu_ic_priv *priv;
  141. };
  142. struct ipu_ic_priv {
  143. void __iomem *base;
  144. void __iomem *tpmem_base;
  145. spinlock_t lock;
  146. struct ipu_soc *ipu;
  147. int use_count;
  148. struct ipu_ic task[IC_NUM_TASKS];
  149. };
  150. static inline u32 ipu_ic_read(struct ipu_ic *ic, unsigned offset)
  151. {
  152. return readl(ic->priv->base + offset);
  153. }
  154. static inline void ipu_ic_write(struct ipu_ic *ic, u32 value, unsigned offset)
  155. {
  156. writel(value, ic->priv->base + offset);
  157. }
  158. struct ic_csc_params {
  159. s16 coeff[3][3]; /* signed 9-bit integer coefficients */
  160. s16 offset[3]; /* signed 11+2-bit fixed point offset */
  161. u8 scale:2; /* scale coefficients * 2^(scale-1) */
  162. bool sat:1; /* saturate to (16, 235(Y) / 240(U, V)) */
  163. };
  164. /*
  165. * Y = R * .299 + G * .587 + B * .114;
  166. * U = R * -.169 + G * -.332 + B * .500 + 128.;
  167. * V = R * .500 + G * -.419 + B * -.0813 + 128.;
  168. */
  169. static const struct ic_csc_params ic_csc_rgb2ycbcr = {
  170. .coeff = {
  171. { 77, 150, 29 },
  172. { 469, 427, 128 },
  173. { 128, 405, 491 },
  174. },
  175. .offset = { 0, 512, 512 },
  176. .scale = 1,
  177. };
  178. /* transparent RGB->RGB matrix for graphics combining */
  179. static const struct ic_csc_params ic_csc_rgb2rgb = {
  180. .coeff = {
  181. { 128, 0, 0 },
  182. { 0, 128, 0 },
  183. { 0, 0, 128 },
  184. },
  185. .scale = 2,
  186. };
  187. /*
  188. * R = (1.164 * (Y - 16)) + (1.596 * (Cr - 128));
  189. * G = (1.164 * (Y - 16)) - (0.392 * (Cb - 128)) - (0.813 * (Cr - 128));
  190. * B = (1.164 * (Y - 16)) + (2.017 * (Cb - 128);
  191. */
  192. static const struct ic_csc_params ic_csc_ycbcr2rgb = {
  193. .coeff = {
  194. { 149, 0, 204 },
  195. { 149, 462, 408 },
  196. { 149, 255, 0 },
  197. },
  198. .offset = { -446, 266, -554 },
  199. .scale = 2,
  200. };
  201. static int init_csc(struct ipu_ic *ic,
  202. enum ipu_color_space inf,
  203. enum ipu_color_space outf,
  204. int csc_index)
  205. {
  206. struct ipu_ic_priv *priv = ic->priv;
  207. const struct ic_csc_params *params;
  208. u32 __iomem *base;
  209. const u16 (*c)[3];
  210. const u16 *a;
  211. u32 param;
  212. base = (u32 __iomem *)
  213. (priv->tpmem_base + ic->reg->tpmem_csc[csc_index]);
  214. if (inf == IPUV3_COLORSPACE_YUV && outf == IPUV3_COLORSPACE_RGB)
  215. params = &ic_csc_ycbcr2rgb;
  216. else if (inf == IPUV3_COLORSPACE_RGB && outf == IPUV3_COLORSPACE_YUV)
  217. params = &ic_csc_rgb2ycbcr;
  218. else if (inf == IPUV3_COLORSPACE_RGB && outf == IPUV3_COLORSPACE_RGB)
  219. params = &ic_csc_rgb2rgb;
  220. else {
  221. dev_err(priv->ipu->dev, "Unsupported color space conversion\n");
  222. return -EINVAL;
  223. }
  224. /* Cast to unsigned */
  225. c = (const u16 (*)[3])params->coeff;
  226. a = (const u16 *)params->offset;
  227. param = ((a[0] & 0x1f) << 27) | ((c[0][0] & 0x1ff) << 18) |
  228. ((c[1][1] & 0x1ff) << 9) | (c[2][2] & 0x1ff);
  229. writel(param, base++);
  230. param = ((a[0] & 0x1fe0) >> 5) | (params->scale << 8) |
  231. (params->sat << 9);
  232. writel(param, base++);
  233. param = ((a[1] & 0x1f) << 27) | ((c[0][1] & 0x1ff) << 18) |
  234. ((c[1][0] & 0x1ff) << 9) | (c[2][0] & 0x1ff);
  235. writel(param, base++);
  236. param = ((a[1] & 0x1fe0) >> 5);
  237. writel(param, base++);
  238. param = ((a[2] & 0x1f) << 27) | ((c[0][2] & 0x1ff) << 18) |
  239. ((c[1][2] & 0x1ff) << 9) | (c[2][1] & 0x1ff);
  240. writel(param, base++);
  241. param = ((a[2] & 0x1fe0) >> 5);
  242. writel(param, base++);
  243. return 0;
  244. }
  245. static int calc_resize_coeffs(struct ipu_ic *ic,
  246. u32 in_size, u32 out_size,
  247. u32 *resize_coeff,
  248. u32 *downsize_coeff)
  249. {
  250. struct ipu_ic_priv *priv = ic->priv;
  251. struct ipu_soc *ipu = priv->ipu;
  252. u32 temp_size, temp_downsize;
  253. /*
  254. * Input size cannot be more than 4096, and output size cannot
  255. * be more than 1024
  256. */
  257. if (in_size > 4096) {
  258. dev_err(ipu->dev, "Unsupported resize (in_size > 4096)\n");
  259. return -EINVAL;
  260. }
  261. if (out_size > 1024) {
  262. dev_err(ipu->dev, "Unsupported resize (out_size > 1024)\n");
  263. return -EINVAL;
  264. }
  265. /* Cannot downsize more than 4:1 */
  266. if ((out_size << 2) < in_size) {
  267. dev_err(ipu->dev, "Unsupported downsize\n");
  268. return -EINVAL;
  269. }
  270. /* Compute downsizing coefficient */
  271. temp_downsize = 0;
  272. temp_size = in_size;
  273. while (((temp_size > 1024) || (temp_size >= out_size * 2)) &&
  274. (temp_downsize < 2)) {
  275. temp_size >>= 1;
  276. temp_downsize++;
  277. }
  278. *downsize_coeff = temp_downsize;
  279. /*
  280. * compute resizing coefficient using the following equation:
  281. * resize_coeff = M * (SI - 1) / (SO - 1)
  282. * where M = 2^13, SI = input size, SO = output size
  283. */
  284. *resize_coeff = (8192L * (temp_size - 1)) / (out_size - 1);
  285. if (*resize_coeff >= 16384L) {
  286. dev_err(ipu->dev, "Warning! Overflow on resize coeff.\n");
  287. *resize_coeff = 0x3FFF;
  288. }
  289. return 0;
  290. }
  291. void ipu_ic_task_enable(struct ipu_ic *ic)
  292. {
  293. struct ipu_ic_priv *priv = ic->priv;
  294. unsigned long flags;
  295. u32 ic_conf;
  296. spin_lock_irqsave(&priv->lock, flags);
  297. ic_conf = ipu_ic_read(ic, IC_CONF);
  298. ic_conf |= ic->bit->ic_conf_en;
  299. if (ic->rotation)
  300. ic_conf |= ic->bit->ic_conf_rot_en;
  301. if (ic->in_cs != ic->out_cs)
  302. ic_conf |= ic->bit->ic_conf_csc1_en;
  303. if (ic->graphics) {
  304. ic_conf |= ic->bit->ic_conf_cmb_en;
  305. ic_conf |= ic->bit->ic_conf_csc1_en;
  306. if (ic->g_in_cs != ic->out_cs)
  307. ic_conf |= ic->bit->ic_conf_csc2_en;
  308. }
  309. ipu_ic_write(ic, ic_conf, IC_CONF);
  310. spin_unlock_irqrestore(&priv->lock, flags);
  311. }
  312. EXPORT_SYMBOL_GPL(ipu_ic_task_enable);
  313. void ipu_ic_task_disable(struct ipu_ic *ic)
  314. {
  315. struct ipu_ic_priv *priv = ic->priv;
  316. unsigned long flags;
  317. u32 ic_conf;
  318. spin_lock_irqsave(&priv->lock, flags);
  319. ic_conf = ipu_ic_read(ic, IC_CONF);
  320. ic_conf &= ~(ic->bit->ic_conf_en |
  321. ic->bit->ic_conf_csc1_en |
  322. ic->bit->ic_conf_rot_en);
  323. if (ic->bit->ic_conf_csc2_en)
  324. ic_conf &= ~ic->bit->ic_conf_csc2_en;
  325. if (ic->bit->ic_conf_cmb_en)
  326. ic_conf &= ~ic->bit->ic_conf_cmb_en;
  327. ipu_ic_write(ic, ic_conf, IC_CONF);
  328. ic->rotation = ic->graphics = false;
  329. spin_unlock_irqrestore(&priv->lock, flags);
  330. }
  331. EXPORT_SYMBOL_GPL(ipu_ic_task_disable);
  332. int ipu_ic_task_graphics_init(struct ipu_ic *ic,
  333. enum ipu_color_space in_g_cs,
  334. bool galpha_en, u32 galpha,
  335. bool colorkey_en, u32 colorkey)
  336. {
  337. struct ipu_ic_priv *priv = ic->priv;
  338. unsigned long flags;
  339. u32 reg, ic_conf;
  340. int ret = 0;
  341. if (ic->task == IC_TASK_ENCODER)
  342. return -EINVAL;
  343. spin_lock_irqsave(&priv->lock, flags);
  344. ic_conf = ipu_ic_read(ic, IC_CONF);
  345. if (!(ic_conf & ic->bit->ic_conf_csc1_en)) {
  346. /* need transparent CSC1 conversion */
  347. ret = init_csc(ic, IPUV3_COLORSPACE_RGB,
  348. IPUV3_COLORSPACE_RGB, 0);
  349. if (ret)
  350. goto unlock;
  351. }
  352. ic->g_in_cs = in_g_cs;
  353. if (ic->g_in_cs != ic->out_cs) {
  354. ret = init_csc(ic, ic->g_in_cs, ic->out_cs, 1);
  355. if (ret)
  356. goto unlock;
  357. }
  358. if (galpha_en) {
  359. ic_conf |= IC_CONF_IC_GLB_LOC_A;
  360. reg = ipu_ic_read(ic, IC_CMBP_1);
  361. reg &= ~(0xff << ic->bit->ic_cmb_galpha_bit);
  362. reg |= (galpha << ic->bit->ic_cmb_galpha_bit);
  363. ipu_ic_write(ic, reg, IC_CMBP_1);
  364. } else
  365. ic_conf &= ~IC_CONF_IC_GLB_LOC_A;
  366. if (colorkey_en) {
  367. ic_conf |= IC_CONF_KEY_COLOR_EN;
  368. ipu_ic_write(ic, colorkey, IC_CMBP_2);
  369. } else
  370. ic_conf &= ~IC_CONF_KEY_COLOR_EN;
  371. ipu_ic_write(ic, ic_conf, IC_CONF);
  372. ic->graphics = true;
  373. unlock:
  374. spin_unlock_irqrestore(&priv->lock, flags);
  375. return ret;
  376. }
  377. EXPORT_SYMBOL_GPL(ipu_ic_task_graphics_init);
  378. int ipu_ic_task_init(struct ipu_ic *ic,
  379. int in_width, int in_height,
  380. int out_width, int out_height,
  381. enum ipu_color_space in_cs,
  382. enum ipu_color_space out_cs)
  383. {
  384. struct ipu_ic_priv *priv = ic->priv;
  385. u32 reg, downsize_coeff, resize_coeff;
  386. unsigned long flags;
  387. int ret = 0;
  388. /* Setup vertical resizing */
  389. ret = calc_resize_coeffs(ic, in_height, out_height,
  390. &resize_coeff, &downsize_coeff);
  391. if (ret)
  392. return ret;
  393. reg = (downsize_coeff << 30) | (resize_coeff << 16);
  394. /* Setup horizontal resizing */
  395. ret = calc_resize_coeffs(ic, in_width, out_width,
  396. &resize_coeff, &downsize_coeff);
  397. if (ret)
  398. return ret;
  399. reg |= (downsize_coeff << 14) | resize_coeff;
  400. spin_lock_irqsave(&priv->lock, flags);
  401. ipu_ic_write(ic, reg, ic->reg->rsc);
  402. /* Setup color space conversion */
  403. ic->in_cs = in_cs;
  404. ic->out_cs = out_cs;
  405. if (ic->in_cs != ic->out_cs) {
  406. ret = init_csc(ic, ic->in_cs, ic->out_cs, 0);
  407. if (ret)
  408. goto unlock;
  409. }
  410. unlock:
  411. spin_unlock_irqrestore(&priv->lock, flags);
  412. return ret;
  413. }
  414. EXPORT_SYMBOL_GPL(ipu_ic_task_init);
  415. int ipu_ic_task_idma_init(struct ipu_ic *ic, struct ipuv3_channel *channel,
  416. u32 width, u32 height, int burst_size,
  417. enum ipu_rotate_mode rot)
  418. {
  419. struct ipu_ic_priv *priv = ic->priv;
  420. struct ipu_soc *ipu = priv->ipu;
  421. u32 ic_idmac_1, ic_idmac_2, ic_idmac_3;
  422. u32 temp_rot = bitrev8(rot) >> 5;
  423. bool need_hor_flip = false;
  424. unsigned long flags;
  425. int ret = 0;
  426. if ((burst_size != 8) && (burst_size != 16)) {
  427. dev_err(ipu->dev, "Illegal burst length for IC\n");
  428. return -EINVAL;
  429. }
  430. width--;
  431. height--;
  432. if (temp_rot & 0x2) /* Need horizontal flip */
  433. need_hor_flip = true;
  434. spin_lock_irqsave(&priv->lock, flags);
  435. ic_idmac_1 = ipu_ic_read(ic, IC_IDMAC_1);
  436. ic_idmac_2 = ipu_ic_read(ic, IC_IDMAC_2);
  437. ic_idmac_3 = ipu_ic_read(ic, IC_IDMAC_3);
  438. switch (channel->num) {
  439. case IPUV3_CHANNEL_IC_PP_MEM:
  440. if (burst_size == 16)
  441. ic_idmac_1 |= IC_IDMAC_1_CB2_BURST_16;
  442. else
  443. ic_idmac_1 &= ~IC_IDMAC_1_CB2_BURST_16;
  444. if (need_hor_flip)
  445. ic_idmac_1 |= IC_IDMAC_1_PP_FLIP_RS;
  446. else
  447. ic_idmac_1 &= ~IC_IDMAC_1_PP_FLIP_RS;
  448. ic_idmac_2 &= ~IC_IDMAC_2_PP_HEIGHT_MASK;
  449. ic_idmac_2 |= height << IC_IDMAC_2_PP_HEIGHT_OFFSET;
  450. ic_idmac_3 &= ~IC_IDMAC_3_PP_WIDTH_MASK;
  451. ic_idmac_3 |= width << IC_IDMAC_3_PP_WIDTH_OFFSET;
  452. break;
  453. case IPUV3_CHANNEL_MEM_IC_PP:
  454. if (burst_size == 16)
  455. ic_idmac_1 |= IC_IDMAC_1_CB5_BURST_16;
  456. else
  457. ic_idmac_1 &= ~IC_IDMAC_1_CB5_BURST_16;
  458. break;
  459. case IPUV3_CHANNEL_MEM_ROT_PP:
  460. ic_idmac_1 &= ~IC_IDMAC_1_PP_ROT_MASK;
  461. ic_idmac_1 |= temp_rot << IC_IDMAC_1_PP_ROT_OFFSET;
  462. break;
  463. case IPUV3_CHANNEL_MEM_IC_PRP_VF:
  464. if (burst_size == 16)
  465. ic_idmac_1 |= IC_IDMAC_1_CB6_BURST_16;
  466. else
  467. ic_idmac_1 &= ~IC_IDMAC_1_CB6_BURST_16;
  468. break;
  469. case IPUV3_CHANNEL_IC_PRP_ENC_MEM:
  470. if (burst_size == 16)
  471. ic_idmac_1 |= IC_IDMAC_1_CB0_BURST_16;
  472. else
  473. ic_idmac_1 &= ~IC_IDMAC_1_CB0_BURST_16;
  474. if (need_hor_flip)
  475. ic_idmac_1 |= IC_IDMAC_1_PRPENC_FLIP_RS;
  476. else
  477. ic_idmac_1 &= ~IC_IDMAC_1_PRPENC_FLIP_RS;
  478. ic_idmac_2 &= ~IC_IDMAC_2_PRPENC_HEIGHT_MASK;
  479. ic_idmac_2 |= height << IC_IDMAC_2_PRPENC_HEIGHT_OFFSET;
  480. ic_idmac_3 &= ~IC_IDMAC_3_PRPENC_WIDTH_MASK;
  481. ic_idmac_3 |= width << IC_IDMAC_3_PRPENC_WIDTH_OFFSET;
  482. break;
  483. case IPUV3_CHANNEL_MEM_ROT_ENC:
  484. ic_idmac_1 &= ~IC_IDMAC_1_PRPENC_ROT_MASK;
  485. ic_idmac_1 |= temp_rot << IC_IDMAC_1_PRPENC_ROT_OFFSET;
  486. break;
  487. case IPUV3_CHANNEL_IC_PRP_VF_MEM:
  488. if (burst_size == 16)
  489. ic_idmac_1 |= IC_IDMAC_1_CB1_BURST_16;
  490. else
  491. ic_idmac_1 &= ~IC_IDMAC_1_CB1_BURST_16;
  492. if (need_hor_flip)
  493. ic_idmac_1 |= IC_IDMAC_1_PRPVF_FLIP_RS;
  494. else
  495. ic_idmac_1 &= ~IC_IDMAC_1_PRPVF_FLIP_RS;
  496. ic_idmac_2 &= ~IC_IDMAC_2_PRPVF_HEIGHT_MASK;
  497. ic_idmac_2 |= height << IC_IDMAC_2_PRPVF_HEIGHT_OFFSET;
  498. ic_idmac_3 &= ~IC_IDMAC_3_PRPVF_WIDTH_MASK;
  499. ic_idmac_3 |= width << IC_IDMAC_3_PRPVF_WIDTH_OFFSET;
  500. break;
  501. case IPUV3_CHANNEL_MEM_ROT_VF:
  502. ic_idmac_1 &= ~IC_IDMAC_1_PRPVF_ROT_MASK;
  503. ic_idmac_1 |= temp_rot << IC_IDMAC_1_PRPVF_ROT_OFFSET;
  504. break;
  505. case IPUV3_CHANNEL_G_MEM_IC_PRP_VF:
  506. if (burst_size == 16)
  507. ic_idmac_1 |= IC_IDMAC_1_CB3_BURST_16;
  508. else
  509. ic_idmac_1 &= ~IC_IDMAC_1_CB3_BURST_16;
  510. break;
  511. case IPUV3_CHANNEL_G_MEM_IC_PP:
  512. if (burst_size == 16)
  513. ic_idmac_1 |= IC_IDMAC_1_CB4_BURST_16;
  514. else
  515. ic_idmac_1 &= ~IC_IDMAC_1_CB4_BURST_16;
  516. break;
  517. case IPUV3_CHANNEL_VDI_MEM_IC_VF:
  518. if (burst_size == 16)
  519. ic_idmac_1 |= IC_IDMAC_1_CB7_BURST_16;
  520. else
  521. ic_idmac_1 &= ~IC_IDMAC_1_CB7_BURST_16;
  522. break;
  523. default:
  524. goto unlock;
  525. }
  526. ipu_ic_write(ic, ic_idmac_1, IC_IDMAC_1);
  527. ipu_ic_write(ic, ic_idmac_2, IC_IDMAC_2);
  528. ipu_ic_write(ic, ic_idmac_3, IC_IDMAC_3);
  529. if (rot >= IPU_ROTATE_90_RIGHT)
  530. ic->rotation = true;
  531. unlock:
  532. spin_unlock_irqrestore(&priv->lock, flags);
  533. return ret;
  534. }
  535. EXPORT_SYMBOL_GPL(ipu_ic_task_idma_init);
  536. int ipu_ic_enable(struct ipu_ic *ic)
  537. {
  538. struct ipu_ic_priv *priv = ic->priv;
  539. unsigned long flags;
  540. u32 module = IPU_CONF_IC_EN;
  541. spin_lock_irqsave(&priv->lock, flags);
  542. if (ic->rotation)
  543. module |= IPU_CONF_ROT_EN;
  544. if (!priv->use_count)
  545. ipu_module_enable(priv->ipu, module);
  546. priv->use_count++;
  547. spin_unlock_irqrestore(&priv->lock, flags);
  548. return 0;
  549. }
  550. EXPORT_SYMBOL_GPL(ipu_ic_enable);
  551. int ipu_ic_disable(struct ipu_ic *ic)
  552. {
  553. struct ipu_ic_priv *priv = ic->priv;
  554. unsigned long flags;
  555. u32 module = IPU_CONF_IC_EN | IPU_CONF_ROT_EN;
  556. spin_lock_irqsave(&priv->lock, flags);
  557. priv->use_count--;
  558. if (!priv->use_count)
  559. ipu_module_disable(priv->ipu, module);
  560. if (priv->use_count < 0)
  561. priv->use_count = 0;
  562. spin_unlock_irqrestore(&priv->lock, flags);
  563. return 0;
  564. }
  565. EXPORT_SYMBOL_GPL(ipu_ic_disable);
  566. struct ipu_ic *ipu_ic_get(struct ipu_soc *ipu, enum ipu_ic_task task)
  567. {
  568. struct ipu_ic_priv *priv = ipu->ic_priv;
  569. unsigned long flags;
  570. struct ipu_ic *ic, *ret;
  571. if (task >= IC_NUM_TASKS)
  572. return ERR_PTR(-EINVAL);
  573. ic = &priv->task[task];
  574. spin_lock_irqsave(&priv->lock, flags);
  575. if (ic->in_use) {
  576. ret = ERR_PTR(-EBUSY);
  577. goto unlock;
  578. }
  579. ic->in_use = true;
  580. ret = ic;
  581. unlock:
  582. spin_unlock_irqrestore(&priv->lock, flags);
  583. return ret;
  584. }
  585. EXPORT_SYMBOL_GPL(ipu_ic_get);
  586. void ipu_ic_put(struct ipu_ic *ic)
  587. {
  588. struct ipu_ic_priv *priv = ic->priv;
  589. unsigned long flags;
  590. spin_lock_irqsave(&priv->lock, flags);
  591. ic->in_use = false;
  592. spin_unlock_irqrestore(&priv->lock, flags);
  593. }
  594. EXPORT_SYMBOL_GPL(ipu_ic_put);
  595. int ipu_ic_init(struct ipu_soc *ipu, struct device *dev,
  596. unsigned long base, unsigned long tpmem_base)
  597. {
  598. struct ipu_ic_priv *priv;
  599. int i;
  600. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  601. if (!priv)
  602. return -ENOMEM;
  603. ipu->ic_priv = priv;
  604. spin_lock_init(&priv->lock);
  605. priv->base = devm_ioremap(dev, base, PAGE_SIZE);
  606. if (!priv->base)
  607. return -ENOMEM;
  608. priv->tpmem_base = devm_ioremap(dev, tpmem_base, SZ_64K);
  609. if (!priv->tpmem_base)
  610. return -ENOMEM;
  611. dev_dbg(dev, "IC base: 0x%08lx remapped to %p\n", base, priv->base);
  612. priv->ipu = ipu;
  613. for (i = 0; i < IC_NUM_TASKS; i++) {
  614. priv->task[i].task = i;
  615. priv->task[i].priv = priv;
  616. priv->task[i].reg = &ic_task_reg[i];
  617. priv->task[i].bit = &ic_task_bit[i];
  618. }
  619. return 0;
  620. }
  621. void ipu_ic_exit(struct ipu_soc *ipu)
  622. {
  623. }
  624. void ipu_ic_dump(struct ipu_ic *ic)
  625. {
  626. struct ipu_ic_priv *priv = ic->priv;
  627. struct ipu_soc *ipu = priv->ipu;
  628. dev_dbg(ipu->dev, "IC_CONF = \t0x%08X\n",
  629. ipu_ic_read(ic, IC_CONF));
  630. dev_dbg(ipu->dev, "IC_PRP_ENC_RSC = \t0x%08X\n",
  631. ipu_ic_read(ic, IC_PRP_ENC_RSC));
  632. dev_dbg(ipu->dev, "IC_PRP_VF_RSC = \t0x%08X\n",
  633. ipu_ic_read(ic, IC_PRP_VF_RSC));
  634. dev_dbg(ipu->dev, "IC_PP_RSC = \t0x%08X\n",
  635. ipu_ic_read(ic, IC_PP_RSC));
  636. dev_dbg(ipu->dev, "IC_CMBP_1 = \t0x%08X\n",
  637. ipu_ic_read(ic, IC_CMBP_1));
  638. dev_dbg(ipu->dev, "IC_CMBP_2 = \t0x%08X\n",
  639. ipu_ic_read(ic, IC_CMBP_2));
  640. dev_dbg(ipu->dev, "IC_IDMAC_1 = \t0x%08X\n",
  641. ipu_ic_read(ic, IC_IDMAC_1));
  642. dev_dbg(ipu->dev, "IC_IDMAC_2 = \t0x%08X\n",
  643. ipu_ic_read(ic, IC_IDMAC_2));
  644. dev_dbg(ipu->dev, "IC_IDMAC_3 = \t0x%08X\n",
  645. ipu_ic_read(ic, IC_IDMAC_3));
  646. dev_dbg(ipu->dev, "IC_IDMAC_4 = \t0x%08X\n",
  647. ipu_ic_read(ic, IC_IDMAC_4));
  648. }
  649. EXPORT_SYMBOL_GPL(ipu_ic_dump);