1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2008-2010 Freescale Semiconductor, Inc. All Rights Reserved.
5 #include <linux/export.h>
6 #include <linux/types.h>
7 #include <linux/init.h>
9 #include <linux/errno.h>
10 #include <linux/spinlock.h>
11 #include <linux/delay.h>
12 #include <linux/clk.h>
13 #include <video/imx-ipu-v3.h>
18 struct ipu_smfc_priv
*priv
;
23 struct ipu_smfc_priv
{
27 struct ipu_smfc channel
[4];
32 #define SMFC_MAP 0x0000
33 #define SMFC_WMC 0x0004
34 #define SMFC_BS 0x0008
36 int ipu_smfc_set_burstsize(struct ipu_smfc
*smfc
, int burstsize
)
38 struct ipu_smfc_priv
*priv
= smfc
->priv
;
42 spin_lock_irqsave(&priv
->lock
, flags
);
44 shift
= smfc
->chno
* 4;
45 val
= readl(priv
->base
+ SMFC_BS
);
46 val
&= ~(0xf << shift
);
47 val
|= burstsize
<< shift
;
48 writel(val
, priv
->base
+ SMFC_BS
);
50 spin_unlock_irqrestore(&priv
->lock
, flags
);
54 EXPORT_SYMBOL_GPL(ipu_smfc_set_burstsize
);
56 int ipu_smfc_map_channel(struct ipu_smfc
*smfc
, int csi_id
, int mipi_id
)
58 struct ipu_smfc_priv
*priv
= smfc
->priv
;
62 spin_lock_irqsave(&priv
->lock
, flags
);
64 shift
= smfc
->chno
* 3;
65 val
= readl(priv
->base
+ SMFC_MAP
);
66 val
&= ~(0x7 << shift
);
67 val
|= ((csi_id
<< 2) | mipi_id
) << shift
;
68 writel(val
, priv
->base
+ SMFC_MAP
);
70 spin_unlock_irqrestore(&priv
->lock
, flags
);
74 EXPORT_SYMBOL_GPL(ipu_smfc_map_channel
);
76 int ipu_smfc_set_watermark(struct ipu_smfc
*smfc
, u32 set_level
, u32 clr_level
)
78 struct ipu_smfc_priv
*priv
= smfc
->priv
;
82 spin_lock_irqsave(&priv
->lock
, flags
);
84 shift
= smfc
->chno
* 6 + (smfc
->chno
> 1 ? 4 : 0);
85 val
= readl(priv
->base
+ SMFC_WMC
);
86 val
&= ~(0x3f << shift
);
87 val
|= ((clr_level
<< 3) | set_level
) << shift
;
88 writel(val
, priv
->base
+ SMFC_WMC
);
90 spin_unlock_irqrestore(&priv
->lock
, flags
);
94 EXPORT_SYMBOL_GPL(ipu_smfc_set_watermark
);
96 int ipu_smfc_enable(struct ipu_smfc
*smfc
)
98 struct ipu_smfc_priv
*priv
= smfc
->priv
;
101 spin_lock_irqsave(&priv
->lock
, flags
);
103 if (!priv
->use_count
)
104 ipu_module_enable(priv
->ipu
, IPU_CONF_SMFC_EN
);
108 spin_unlock_irqrestore(&priv
->lock
, flags
);
112 EXPORT_SYMBOL_GPL(ipu_smfc_enable
);
114 int ipu_smfc_disable(struct ipu_smfc
*smfc
)
116 struct ipu_smfc_priv
*priv
= smfc
->priv
;
119 spin_lock_irqsave(&priv
->lock
, flags
);
123 if (!priv
->use_count
)
124 ipu_module_disable(priv
->ipu
, IPU_CONF_SMFC_EN
);
126 if (priv
->use_count
< 0)
129 spin_unlock_irqrestore(&priv
->lock
, flags
);
133 EXPORT_SYMBOL_GPL(ipu_smfc_disable
);
135 struct ipu_smfc
*ipu_smfc_get(struct ipu_soc
*ipu
, unsigned int chno
)
137 struct ipu_smfc_priv
*priv
= ipu
->smfc_priv
;
138 struct ipu_smfc
*smfc
, *ret
;
142 return ERR_PTR(-EINVAL
);
144 smfc
= &priv
->channel
[chno
];
147 spin_lock_irqsave(&priv
->lock
, flags
);
150 ret
= ERR_PTR(-EBUSY
);
156 spin_unlock_irqrestore(&priv
->lock
, flags
);
159 EXPORT_SYMBOL_GPL(ipu_smfc_get
);
161 void ipu_smfc_put(struct ipu_smfc
*smfc
)
163 struct ipu_smfc_priv
*priv
= smfc
->priv
;
166 spin_lock_irqsave(&priv
->lock
, flags
);
168 spin_unlock_irqrestore(&priv
->lock
, flags
);
170 EXPORT_SYMBOL_GPL(ipu_smfc_put
);
172 int ipu_smfc_init(struct ipu_soc
*ipu
, struct device
*dev
,
175 struct ipu_smfc_priv
*priv
;
178 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
182 ipu
->smfc_priv
= priv
;
183 spin_lock_init(&priv
->lock
);
186 priv
->base
= devm_ioremap(dev
, base
, PAGE_SIZE
);
190 for (i
= 0; i
< 4; i
++) {
191 priv
->channel
[i
].priv
= priv
;
192 priv
->channel
[i
].chno
= i
;
195 pr_debug("%s: ioremap 0x%08lx -> %p\n", __func__
, base
, priv
->base
);
200 void ipu_smfc_exit(struct ipu_soc
*ipu
)