2 * Copyright (c) 2010 Sascha Hauer <s.hauer@pengutronix.de>
3 * Copyright (C) 2005-2009 Freescale Semiconductor, Inc.
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.
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
15 #include <linux/export.h>
16 #include <linux/types.h>
17 #include <linux/errno.h>
20 #include <video/imx-ipu-v3.h>
23 #define DMFC_RD_CHAN 0x0000
24 #define DMFC_WR_CHAN 0x0004
25 #define DMFC_WR_CHAN_DEF 0x0008
26 #define DMFC_DP_CHAN 0x000c
27 #define DMFC_DP_CHAN_DEF 0x0010
28 #define DMFC_GENERAL1 0x0014
29 #define DMFC_GENERAL2 0x0018
30 #define DMFC_IC_CTRL 0x001c
31 #define DMFC_WR_CHAN_ALT 0x0020
32 #define DMFC_WR_CHAN_DEF_ALT 0x0024
33 #define DMFC_DP_CHAN_ALT 0x0028
34 #define DMFC_DP_CHAN_DEF_ALT 0x002c
35 #define DMFC_GENERAL1_ALT 0x0030
36 #define DMFC_STAT 0x0034
38 #define DMFC_WR_CHAN_1_28 0
39 #define DMFC_WR_CHAN_2_41 8
40 #define DMFC_WR_CHAN_1C_42 16
41 #define DMFC_WR_CHAN_2C_43 24
43 #define DMFC_DP_CHAN_5B_23 0
44 #define DMFC_DP_CHAN_5F_27 8
45 #define DMFC_DP_CHAN_6B_24 16
46 #define DMFC_DP_CHAN_6F_29 24
48 struct dmfc_channel_data
{
50 unsigned long channel_reg
;
53 unsigned max_fifo_lines
;
56 static const struct dmfc_channel_data dmfcdata
[] = {
58 .ipu_channel
= IPUV3_CHANNEL_MEM_BG_SYNC
,
59 .channel_reg
= DMFC_DP_CHAN
,
60 .shift
= DMFC_DP_CHAN_5B_23
,
65 .channel_reg
= DMFC_DP_CHAN
,
66 .shift
= DMFC_DP_CHAN_6B_24
,
70 .ipu_channel
= IPUV3_CHANNEL_MEM_FG_SYNC
,
71 .channel_reg
= DMFC_DP_CHAN
,
72 .shift
= DMFC_DP_CHAN_5F_27
,
76 .ipu_channel
= IPUV3_CHANNEL_MEM_DC_SYNC
,
77 .channel_reg
= DMFC_WR_CHAN
,
78 .shift
= DMFC_WR_CHAN_1_28
,
83 .channel_reg
= DMFC_DP_CHAN
,
84 .shift
= DMFC_DP_CHAN_6F_29
,
90 #define DMFC_NUM_CHANNELS ARRAY_SIZE(dmfcdata)
97 struct ipu_dmfc_priv
*priv
;
98 const struct dmfc_channel_data
*data
;
101 struct ipu_dmfc_priv
{
104 struct dmfc_channel channels
[DMFC_NUM_CHANNELS
];
110 int ipu_dmfc_enable_channel(struct dmfc_channel
*dmfc
)
112 struct ipu_dmfc_priv
*priv
= dmfc
->priv
;
113 mutex_lock(&priv
->mutex
);
115 if (!priv
->use_count
)
116 ipu_module_enable(priv
->ipu
, IPU_CONF_DMFC_EN
);
120 mutex_unlock(&priv
->mutex
);
124 EXPORT_SYMBOL_GPL(ipu_dmfc_enable_channel
);
126 void ipu_dmfc_disable_channel(struct dmfc_channel
*dmfc
)
128 struct ipu_dmfc_priv
*priv
= dmfc
->priv
;
130 mutex_lock(&priv
->mutex
);
134 if (!priv
->use_count
)
135 ipu_module_disable(priv
->ipu
, IPU_CONF_DMFC_EN
);
137 if (priv
->use_count
< 0)
140 mutex_unlock(&priv
->mutex
);
142 EXPORT_SYMBOL_GPL(ipu_dmfc_disable_channel
);
144 void ipu_dmfc_config_wait4eot(struct dmfc_channel
*dmfc
, int width
)
146 struct ipu_dmfc_priv
*priv
= dmfc
->priv
;
149 mutex_lock(&priv
->mutex
);
151 dmfc_gen1
= readl(priv
->base
+ DMFC_GENERAL1
);
153 if ((dmfc
->slots
* 64 * 4) / width
> dmfc
->data
->max_fifo_lines
)
154 dmfc_gen1
|= 1 << dmfc
->data
->eot_shift
;
156 dmfc_gen1
&= ~(1 << dmfc
->data
->eot_shift
);
158 writel(dmfc_gen1
, priv
->base
+ DMFC_GENERAL1
);
160 mutex_unlock(&priv
->mutex
);
162 EXPORT_SYMBOL_GPL(ipu_dmfc_config_wait4eot
);
164 struct dmfc_channel
*ipu_dmfc_get(struct ipu_soc
*ipu
, int ipu_channel
)
166 struct ipu_dmfc_priv
*priv
= ipu
->dmfc_priv
;
169 for (i
= 0; i
< DMFC_NUM_CHANNELS
; i
++)
170 if (dmfcdata
[i
].ipu_channel
== ipu_channel
)
171 return &priv
->channels
[i
];
172 return ERR_PTR(-ENODEV
);
174 EXPORT_SYMBOL_GPL(ipu_dmfc_get
);
176 void ipu_dmfc_put(struct dmfc_channel
*dmfc
)
179 EXPORT_SYMBOL_GPL(ipu_dmfc_put
);
181 int ipu_dmfc_init(struct ipu_soc
*ipu
, struct device
*dev
, unsigned long base
,
184 struct ipu_dmfc_priv
*priv
;
187 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
191 priv
->base
= devm_ioremap(dev
, base
, PAGE_SIZE
);
197 mutex_init(&priv
->mutex
);
199 ipu
->dmfc_priv
= priv
;
201 for (i
= 0; i
< DMFC_NUM_CHANNELS
; i
++) {
202 priv
->channels
[i
].priv
= priv
;
203 priv
->channels
[i
].ipu
= ipu
;
204 priv
->channels
[i
].data
= &dmfcdata
[i
];
206 if (dmfcdata
[i
].ipu_channel
== IPUV3_CHANNEL_MEM_BG_SYNC
||
207 dmfcdata
[i
].ipu_channel
== IPUV3_CHANNEL_MEM_FG_SYNC
||
208 dmfcdata
[i
].ipu_channel
== IPUV3_CHANNEL_MEM_DC_SYNC
)
209 priv
->channels
[i
].slots
= 2;
212 writel(0x00000050, priv
->base
+ DMFC_WR_CHAN
);
213 writel(0x00005654, priv
->base
+ DMFC_DP_CHAN
);
214 writel(0x202020f6, priv
->base
+ DMFC_WR_CHAN_DEF
);
215 writel(0x2020f6f6, priv
->base
+ DMFC_DP_CHAN_DEF
);
216 writel(0x00000003, priv
->base
+ DMFC_GENERAL1
);
221 void ipu_dmfc_exit(struct ipu_soc
*ipu
)