ipu-dmfc.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * Copyright (c) 2010 Sascha Hauer <s.hauer@pengutronix.de>
  3. * Copyright (C) 2005-2009 Freescale Semiconductor, Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. * for more details.
  14. */
  15. #include <linux/export.h>
  16. #include <linux/types.h>
  17. #include <linux/errno.h>
  18. #include <linux/io.h>
  19. #include <video/imx-ipu-v3.h>
  20. #include "ipu-prv.h"
  21. #define DMFC_RD_CHAN 0x0000
  22. #define DMFC_WR_CHAN 0x0004
  23. #define DMFC_WR_CHAN_DEF 0x0008
  24. #define DMFC_DP_CHAN 0x000c
  25. #define DMFC_DP_CHAN_DEF 0x0010
  26. #define DMFC_GENERAL1 0x0014
  27. #define DMFC_GENERAL2 0x0018
  28. #define DMFC_IC_CTRL 0x001c
  29. #define DMFC_WR_CHAN_ALT 0x0020
  30. #define DMFC_WR_CHAN_DEF_ALT 0x0024
  31. #define DMFC_DP_CHAN_ALT 0x0028
  32. #define DMFC_DP_CHAN_DEF_ALT 0x002c
  33. #define DMFC_GENERAL1_ALT 0x0030
  34. #define DMFC_STAT 0x0034
  35. #define DMFC_WR_CHAN_1_28 0
  36. #define DMFC_WR_CHAN_2_41 8
  37. #define DMFC_WR_CHAN_1C_42 16
  38. #define DMFC_WR_CHAN_2C_43 24
  39. #define DMFC_DP_CHAN_5B_23 0
  40. #define DMFC_DP_CHAN_5F_27 8
  41. #define DMFC_DP_CHAN_6B_24 16
  42. #define DMFC_DP_CHAN_6F_29 24
  43. struct dmfc_channel_data {
  44. int ipu_channel;
  45. unsigned long channel_reg;
  46. unsigned long shift;
  47. unsigned eot_shift;
  48. unsigned max_fifo_lines;
  49. };
  50. static const struct dmfc_channel_data dmfcdata[] = {
  51. {
  52. .ipu_channel = IPUV3_CHANNEL_MEM_BG_SYNC,
  53. .channel_reg = DMFC_DP_CHAN,
  54. .shift = DMFC_DP_CHAN_5B_23,
  55. .eot_shift = 20,
  56. .max_fifo_lines = 3,
  57. }, {
  58. .ipu_channel = 24,
  59. .channel_reg = DMFC_DP_CHAN,
  60. .shift = DMFC_DP_CHAN_6B_24,
  61. .eot_shift = 22,
  62. .max_fifo_lines = 1,
  63. }, {
  64. .ipu_channel = IPUV3_CHANNEL_MEM_FG_SYNC,
  65. .channel_reg = DMFC_DP_CHAN,
  66. .shift = DMFC_DP_CHAN_5F_27,
  67. .eot_shift = 21,
  68. .max_fifo_lines = 2,
  69. }, {
  70. .ipu_channel = IPUV3_CHANNEL_MEM_DC_SYNC,
  71. .channel_reg = DMFC_WR_CHAN,
  72. .shift = DMFC_WR_CHAN_1_28,
  73. .eot_shift = 16,
  74. .max_fifo_lines = 2,
  75. }, {
  76. .ipu_channel = 29,
  77. .channel_reg = DMFC_DP_CHAN,
  78. .shift = DMFC_DP_CHAN_6F_29,
  79. .eot_shift = 23,
  80. .max_fifo_lines = 1,
  81. },
  82. };
  83. #define DMFC_NUM_CHANNELS ARRAY_SIZE(dmfcdata)
  84. struct ipu_dmfc_priv;
  85. struct dmfc_channel {
  86. unsigned slots;
  87. struct ipu_soc *ipu;
  88. struct ipu_dmfc_priv *priv;
  89. const struct dmfc_channel_data *data;
  90. };
  91. struct ipu_dmfc_priv {
  92. struct ipu_soc *ipu;
  93. struct device *dev;
  94. struct dmfc_channel channels[DMFC_NUM_CHANNELS];
  95. struct mutex mutex;
  96. void __iomem *base;
  97. int use_count;
  98. };
  99. int ipu_dmfc_enable_channel(struct dmfc_channel *dmfc)
  100. {
  101. struct ipu_dmfc_priv *priv = dmfc->priv;
  102. mutex_lock(&priv->mutex);
  103. if (!priv->use_count)
  104. ipu_module_enable(priv->ipu, IPU_CONF_DMFC_EN);
  105. priv->use_count++;
  106. mutex_unlock(&priv->mutex);
  107. return 0;
  108. }
  109. EXPORT_SYMBOL_GPL(ipu_dmfc_enable_channel);
  110. void ipu_dmfc_disable_channel(struct dmfc_channel *dmfc)
  111. {
  112. struct ipu_dmfc_priv *priv = dmfc->priv;
  113. mutex_lock(&priv->mutex);
  114. priv->use_count--;
  115. if (!priv->use_count)
  116. ipu_module_disable(priv->ipu, IPU_CONF_DMFC_EN);
  117. if (priv->use_count < 0)
  118. priv->use_count = 0;
  119. mutex_unlock(&priv->mutex);
  120. }
  121. EXPORT_SYMBOL_GPL(ipu_dmfc_disable_channel);
  122. void ipu_dmfc_config_wait4eot(struct dmfc_channel *dmfc, int width)
  123. {
  124. struct ipu_dmfc_priv *priv = dmfc->priv;
  125. u32 dmfc_gen1;
  126. mutex_lock(&priv->mutex);
  127. dmfc_gen1 = readl(priv->base + DMFC_GENERAL1);
  128. if ((dmfc->slots * 64 * 4) / width > dmfc->data->max_fifo_lines)
  129. dmfc_gen1 |= 1 << dmfc->data->eot_shift;
  130. else
  131. dmfc_gen1 &= ~(1 << dmfc->data->eot_shift);
  132. writel(dmfc_gen1, priv->base + DMFC_GENERAL1);
  133. mutex_unlock(&priv->mutex);
  134. }
  135. EXPORT_SYMBOL_GPL(ipu_dmfc_config_wait4eot);
  136. struct dmfc_channel *ipu_dmfc_get(struct ipu_soc *ipu, int ipu_channel)
  137. {
  138. struct ipu_dmfc_priv *priv = ipu->dmfc_priv;
  139. int i;
  140. for (i = 0; i < DMFC_NUM_CHANNELS; i++)
  141. if (dmfcdata[i].ipu_channel == ipu_channel)
  142. return &priv->channels[i];
  143. return ERR_PTR(-ENODEV);
  144. }
  145. EXPORT_SYMBOL_GPL(ipu_dmfc_get);
  146. void ipu_dmfc_put(struct dmfc_channel *dmfc)
  147. {
  148. }
  149. EXPORT_SYMBOL_GPL(ipu_dmfc_put);
  150. int ipu_dmfc_init(struct ipu_soc *ipu, struct device *dev, unsigned long base,
  151. struct clk *ipu_clk)
  152. {
  153. struct ipu_dmfc_priv *priv;
  154. int i;
  155. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  156. if (!priv)
  157. return -ENOMEM;
  158. priv->base = devm_ioremap(dev, base, PAGE_SIZE);
  159. if (!priv->base)
  160. return -ENOMEM;
  161. priv->dev = dev;
  162. priv->ipu = ipu;
  163. mutex_init(&priv->mutex);
  164. ipu->dmfc_priv = priv;
  165. for (i = 0; i < DMFC_NUM_CHANNELS; i++) {
  166. priv->channels[i].priv = priv;
  167. priv->channels[i].ipu = ipu;
  168. priv->channels[i].data = &dmfcdata[i];
  169. if (dmfcdata[i].ipu_channel == IPUV3_CHANNEL_MEM_BG_SYNC ||
  170. dmfcdata[i].ipu_channel == IPUV3_CHANNEL_MEM_FG_SYNC ||
  171. dmfcdata[i].ipu_channel == IPUV3_CHANNEL_MEM_DC_SYNC)
  172. priv->channels[i].slots = 2;
  173. }
  174. writel(0x00000050, priv->base + DMFC_WR_CHAN);
  175. writel(0x00005654, priv->base + DMFC_DP_CHAN);
  176. writel(0x202020f6, priv->base + DMFC_WR_CHAN_DEF);
  177. writel(0x2020f6f6, priv->base + DMFC_DP_CHAN_DEF);
  178. writel(0x00000003, priv->base + DMFC_GENERAL1);
  179. return 0;
  180. }
  181. void ipu_dmfc_exit(struct ipu_soc *ipu)
  182. {
  183. }