xref: /linux/drivers/gpu/ipu-v3/ipu-pre.c (revision c795f3052b60b01e80485fad98c53e5e67d093c9)
1d2a34232SLucas Stach /*
2d2a34232SLucas Stach  * Copyright (c) 2017 Lucas Stach, Pengutronix
3d2a34232SLucas Stach  *
4d2a34232SLucas Stach  * This program is free software; you can redistribute it and/or modify it
5d2a34232SLucas Stach  * under the terms and conditions of the GNU General Public License,
6d2a34232SLucas Stach  * version 2, as published by the Free Software Foundation.
7d2a34232SLucas Stach  *
8d2a34232SLucas Stach  * This program is distributed in the hope it will be useful, but WITHOUT
9d2a34232SLucas Stach  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10d2a34232SLucas Stach  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11d2a34232SLucas Stach  * more details.
12d2a34232SLucas Stach  */
13d2a34232SLucas Stach 
14d2a34232SLucas Stach #include <drm/drm_fourcc.h>
15d2a34232SLucas Stach #include <linux/clk.h>
16d2a34232SLucas Stach #include <linux/err.h>
17d2a34232SLucas Stach #include <linux/genalloc.h>
18d2a34232SLucas Stach #include <linux/module.h>
19d2a34232SLucas Stach #include <linux/of.h>
20d2a34232SLucas Stach #include <linux/platform_device.h>
21d2a34232SLucas Stach #include <video/imx-ipu-v3.h>
22d2a34232SLucas Stach 
23d2a34232SLucas Stach #include "ipu-prv.h"
24d2a34232SLucas Stach 
25d2a34232SLucas Stach #define IPU_PRE_MAX_WIDTH	2048
26d2a34232SLucas Stach #define IPU_PRE_NUM_SCANLINES	8
27d2a34232SLucas Stach 
28d2a34232SLucas Stach #define IPU_PRE_CTRL					0x000
29d2a34232SLucas Stach #define IPU_PRE_CTRL_SET				0x004
30d2a34232SLucas Stach #define  IPU_PRE_CTRL_ENABLE				(1 << 0)
31d2a34232SLucas Stach #define  IPU_PRE_CTRL_BLOCK_EN				(1 << 1)
32d2a34232SLucas Stach #define  IPU_PRE_CTRL_BLOCK_16				(1 << 2)
33d2a34232SLucas Stach #define  IPU_PRE_CTRL_SDW_UPDATE			(1 << 4)
34d2a34232SLucas Stach #define  IPU_PRE_CTRL_VFLIP				(1 << 5)
35d2a34232SLucas Stach #define  IPU_PRE_CTRL_SO				(1 << 6)
36d2a34232SLucas Stach #define  IPU_PRE_CTRL_INTERLACED_FIELD			(1 << 7)
37d2a34232SLucas Stach #define  IPU_PRE_CTRL_HANDSHAKE_EN			(1 << 8)
38d2a34232SLucas Stach #define  IPU_PRE_CTRL_HANDSHAKE_LINE_NUM(v)		((v & 0x3) << 9)
39d2a34232SLucas Stach #define  IPU_PRE_CTRL_HANDSHAKE_ABORT_SKIP_EN		(1 << 11)
40d2a34232SLucas Stach #define  IPU_PRE_CTRL_EN_REPEAT				(1 << 28)
41d2a34232SLucas Stach #define  IPU_PRE_CTRL_TPR_REST_SEL			(1 << 29)
42d2a34232SLucas Stach #define  IPU_PRE_CTRL_CLKGATE				(1 << 30)
43d2a34232SLucas Stach #define  IPU_PRE_CTRL_SFTRST				(1 << 31)
44d2a34232SLucas Stach 
45d2a34232SLucas Stach #define IPU_PRE_CUR_BUF					0x030
46d2a34232SLucas Stach 
47d2a34232SLucas Stach #define IPU_PRE_NEXT_BUF				0x040
48d2a34232SLucas Stach 
49d2a34232SLucas Stach #define IPU_PRE_TPR_CTRL				0x070
50d2a34232SLucas Stach #define  IPU_PRE_TPR_CTRL_TILE_FORMAT(v)		((v & 0xff) << 0)
51d2a34232SLucas Stach #define  IPU_PRE_TPR_CTRL_TILE_FORMAT_MASK		0xff
522f64a554SLucas Stach #define  IPU_PRE_TPR_CTRL_TILE_FORMAT_16_BIT		(1 << 0)
532f64a554SLucas Stach #define  IPU_PRE_TPR_CTRL_TILE_FORMAT_SPLIT_BUF		(1 << 4)
542f64a554SLucas Stach #define  IPU_PRE_TPR_CTRL_TILE_FORMAT_SINGLE_BUF	(1 << 5)
552f64a554SLucas Stach #define  IPU_PRE_TPR_CTRL_TILE_FORMAT_SUPER_TILED	(1 << 6)
56d2a34232SLucas Stach 
57d2a34232SLucas Stach #define IPU_PRE_PREFETCH_ENG_CTRL			0x080
58d2a34232SLucas Stach #define  IPU_PRE_PREF_ENG_CTRL_PREFETCH_EN		(1 << 0)
59d2a34232SLucas Stach #define  IPU_PRE_PREF_ENG_CTRL_RD_NUM_BYTES(v)		((v & 0x7) << 1)
60d2a34232SLucas Stach #define  IPU_PRE_PREF_ENG_CTRL_INPUT_ACTIVE_BPP(v)	((v & 0x3) << 4)
61d2a34232SLucas Stach #define  IPU_PRE_PREF_ENG_CTRL_INPUT_PIXEL_FORMAT(v)	((v & 0x7) << 8)
62d2a34232SLucas Stach #define  IPU_PRE_PREF_ENG_CTRL_SHIFT_BYPASS		(1 << 11)
63d2a34232SLucas Stach #define  IPU_PRE_PREF_ENG_CTRL_FIELD_INVERSE		(1 << 12)
64d2a34232SLucas Stach #define  IPU_PRE_PREF_ENG_CTRL_PARTIAL_UV_SWAP		(1 << 14)
65d2a34232SLucas Stach #define  IPU_PRE_PREF_ENG_CTRL_TPR_COOR_OFFSET_EN	(1 << 15)
66d2a34232SLucas Stach 
67d2a34232SLucas Stach #define IPU_PRE_PREFETCH_ENG_INPUT_SIZE			0x0a0
68d2a34232SLucas Stach #define  IPU_PRE_PREFETCH_ENG_INPUT_SIZE_WIDTH(v)	((v & 0xffff) << 0)
69d2a34232SLucas Stach #define  IPU_PRE_PREFETCH_ENG_INPUT_SIZE_HEIGHT(v)	((v & 0xffff) << 16)
70d2a34232SLucas Stach 
71d2a34232SLucas Stach #define IPU_PRE_PREFETCH_ENG_PITCH			0x0d0
72d2a34232SLucas Stach #define  IPU_PRE_PREFETCH_ENG_PITCH_Y(v)		((v & 0xffff) << 0)
73d2a34232SLucas Stach #define  IPU_PRE_PREFETCH_ENG_PITCH_UV(v)		((v & 0xffff) << 16)
74d2a34232SLucas Stach 
75d2a34232SLucas Stach #define IPU_PRE_STORE_ENG_CTRL				0x110
76d2a34232SLucas Stach #define  IPU_PRE_STORE_ENG_CTRL_STORE_EN		(1 << 0)
77d2a34232SLucas Stach #define  IPU_PRE_STORE_ENG_CTRL_WR_NUM_BYTES(v)		((v & 0x7) << 1)
78d2a34232SLucas Stach #define  IPU_PRE_STORE_ENG_CTRL_OUTPUT_ACTIVE_BPP(v)	((v & 0x3) << 4)
79d2a34232SLucas Stach 
8011aff4b4SLucas Stach #define IPU_PRE_STORE_ENG_STATUS			0x120
8111aff4b4SLucas Stach #define  IPU_PRE_STORE_ENG_STATUS_STORE_BLOCK_X_MASK	0xffff
8211aff4b4SLucas Stach #define  IPU_PRE_STORE_ENG_STATUS_STORE_BLOCK_X_SHIFT	0
8311aff4b4SLucas Stach #define  IPU_PRE_STORE_ENG_STATUS_STORE_BLOCK_Y_MASK	0x3fff
8411aff4b4SLucas Stach #define  IPU_PRE_STORE_ENG_STATUS_STORE_BLOCK_Y_SHIFT	16
8511aff4b4SLucas Stach #define  IPU_PRE_STORE_ENG_STATUS_STORE_FIFO_FULL	(1 << 30)
8611aff4b4SLucas Stach #define  IPU_PRE_STORE_ENG_STATUS_STORE_FIELD		(1 << 31)
8711aff4b4SLucas Stach 
88d2a34232SLucas Stach #define IPU_PRE_STORE_ENG_SIZE				0x130
89d2a34232SLucas Stach #define  IPU_PRE_STORE_ENG_SIZE_INPUT_WIDTH(v)		((v & 0xffff) << 0)
90d2a34232SLucas Stach #define  IPU_PRE_STORE_ENG_SIZE_INPUT_HEIGHT(v)		((v & 0xffff) << 16)
91d2a34232SLucas Stach 
92d2a34232SLucas Stach #define IPU_PRE_STORE_ENG_PITCH				0x140
93d2a34232SLucas Stach #define  IPU_PRE_STORE_ENG_PITCH_OUT_PITCH(v)		((v & 0xffff) << 0)
94d2a34232SLucas Stach 
95d2a34232SLucas Stach #define IPU_PRE_STORE_ENG_ADDR				0x150
96d2a34232SLucas Stach 
97d2a34232SLucas Stach struct ipu_pre {
98d2a34232SLucas Stach 	struct list_head	list;
99d2a34232SLucas Stach 	struct device		*dev;
100d2a34232SLucas Stach 
101d2a34232SLucas Stach 	void __iomem		*regs;
102d2a34232SLucas Stach 	struct clk		*clk_axi;
103d2a34232SLucas Stach 	struct gen_pool		*iram;
104d2a34232SLucas Stach 
105d2a34232SLucas Stach 	dma_addr_t		buffer_paddr;
106d2a34232SLucas Stach 	void			*buffer_virt;
107d2a34232SLucas Stach 	bool			in_use;
10811aff4b4SLucas Stach 	unsigned int		safe_window_end;
109d2a34232SLucas Stach };
110d2a34232SLucas Stach 
111d2a34232SLucas Stach static DEFINE_MUTEX(ipu_pre_list_mutex);
112d2a34232SLucas Stach static LIST_HEAD(ipu_pre_list);
113d2a34232SLucas Stach static int available_pres;
114d2a34232SLucas Stach 
115d2a34232SLucas Stach int ipu_pre_get_available_count(void)
116d2a34232SLucas Stach {
117d2a34232SLucas Stach 	return available_pres;
118d2a34232SLucas Stach }
119d2a34232SLucas Stach 
120d2a34232SLucas Stach struct ipu_pre *
121d2a34232SLucas Stach ipu_pre_lookup_by_phandle(struct device *dev, const char *name, int index)
122d2a34232SLucas Stach {
123d2a34232SLucas Stach 	struct device_node *pre_node = of_parse_phandle(dev->of_node,
124d2a34232SLucas Stach 							name, index);
125d2a34232SLucas Stach 	struct ipu_pre *pre;
126d2a34232SLucas Stach 
127d2a34232SLucas Stach 	mutex_lock(&ipu_pre_list_mutex);
128d2a34232SLucas Stach 	list_for_each_entry(pre, &ipu_pre_list, list) {
129d2a34232SLucas Stach 		if (pre_node == pre->dev->of_node) {
130d2a34232SLucas Stach 			mutex_unlock(&ipu_pre_list_mutex);
131d2a34232SLucas Stach 			device_link_add(dev, pre->dev, DL_FLAG_AUTOREMOVE);
132*c795f305STobias Jordan 			of_node_put(pre_node);
133d2a34232SLucas Stach 			return pre;
134d2a34232SLucas Stach 		}
135d2a34232SLucas Stach 	}
136d2a34232SLucas Stach 	mutex_unlock(&ipu_pre_list_mutex);
137d2a34232SLucas Stach 
138*c795f305STobias Jordan 	of_node_put(pre_node);
139*c795f305STobias Jordan 
140d2a34232SLucas Stach 	return NULL;
141d2a34232SLucas Stach }
142d2a34232SLucas Stach 
143d2a34232SLucas Stach int ipu_pre_get(struct ipu_pre *pre)
144d2a34232SLucas Stach {
145d2a34232SLucas Stach 	u32 val;
146d2a34232SLucas Stach 
147d2a34232SLucas Stach 	if (pre->in_use)
148d2a34232SLucas Stach 		return -EBUSY;
149d2a34232SLucas Stach 
150d2a34232SLucas Stach 	/* first get the engine out of reset and remove clock gating */
151d2a34232SLucas Stach 	writel(0, pre->regs + IPU_PRE_CTRL);
152d2a34232SLucas Stach 
153d2a34232SLucas Stach 	/* init defaults that should be applied to all streams */
154d2a34232SLucas Stach 	val = IPU_PRE_CTRL_HANDSHAKE_ABORT_SKIP_EN |
155d2a34232SLucas Stach 	      IPU_PRE_CTRL_HANDSHAKE_EN |
156d2a34232SLucas Stach 	      IPU_PRE_CTRL_TPR_REST_SEL |
1572f64a554SLucas Stach 	      IPU_PRE_CTRL_SDW_UPDATE;
158d2a34232SLucas Stach 	writel(val, pre->regs + IPU_PRE_CTRL);
159d2a34232SLucas Stach 
160d2a34232SLucas Stach 	pre->in_use = true;
161d2a34232SLucas Stach 	return 0;
162d2a34232SLucas Stach }
163d2a34232SLucas Stach 
164d2a34232SLucas Stach void ipu_pre_put(struct ipu_pre *pre)
165d2a34232SLucas Stach {
16647c298f7SLucas Stach 	writel(IPU_PRE_CTRL_SFTRST, pre->regs + IPU_PRE_CTRL);
167d2a34232SLucas Stach 
168d2a34232SLucas Stach 	pre->in_use = false;
169d2a34232SLucas Stach }
170d2a34232SLucas Stach 
171d2a34232SLucas Stach void ipu_pre_configure(struct ipu_pre *pre, unsigned int width,
172d2a34232SLucas Stach 		       unsigned int height, unsigned int stride, u32 format,
1732f64a554SLucas Stach 		       uint64_t modifier, unsigned int bufaddr)
174d2a34232SLucas Stach {
175d2a34232SLucas Stach 	const struct drm_format_info *info = drm_format_info(format);
176d2a34232SLucas Stach 	u32 active_bpp = info->cpp[0] >> 1;
177d2a34232SLucas Stach 	u32 val;
178d2a34232SLucas Stach 
17911aff4b4SLucas Stach 	/* calculate safe window for ctrl register updates */
1802f64a554SLucas Stach 	if (modifier == DRM_FORMAT_MOD_LINEAR)
18111aff4b4SLucas Stach 		pre->safe_window_end = height - 2;
1822f64a554SLucas Stach 	else
1832f64a554SLucas Stach 		pre->safe_window_end = DIV_ROUND_UP(height, 4) - 1;
18411aff4b4SLucas Stach 
185d2a34232SLucas Stach 	writel(bufaddr, pre->regs + IPU_PRE_CUR_BUF);
186d2a34232SLucas Stach 	writel(bufaddr, pre->regs + IPU_PRE_NEXT_BUF);
187d2a34232SLucas Stach 
188d2a34232SLucas Stach 	val = IPU_PRE_PREF_ENG_CTRL_INPUT_PIXEL_FORMAT(0) |
189d2a34232SLucas Stach 	      IPU_PRE_PREF_ENG_CTRL_INPUT_ACTIVE_BPP(active_bpp) |
190d2a34232SLucas Stach 	      IPU_PRE_PREF_ENG_CTRL_RD_NUM_BYTES(4) |
191d2a34232SLucas Stach 	      IPU_PRE_PREF_ENG_CTRL_SHIFT_BYPASS |
192d2a34232SLucas Stach 	      IPU_PRE_PREF_ENG_CTRL_PREFETCH_EN;
193d2a34232SLucas Stach 	writel(val, pre->regs + IPU_PRE_PREFETCH_ENG_CTRL);
194d2a34232SLucas Stach 
195d2a34232SLucas Stach 	val = IPU_PRE_PREFETCH_ENG_INPUT_SIZE_WIDTH(width) |
196d2a34232SLucas Stach 	      IPU_PRE_PREFETCH_ENG_INPUT_SIZE_HEIGHT(height);
197d2a34232SLucas Stach 	writel(val, pre->regs + IPU_PRE_PREFETCH_ENG_INPUT_SIZE);
198d2a34232SLucas Stach 
199d2a34232SLucas Stach 	val = IPU_PRE_PREFETCH_ENG_PITCH_Y(stride);
200d2a34232SLucas Stach 	writel(val, pre->regs + IPU_PRE_PREFETCH_ENG_PITCH);
201d2a34232SLucas Stach 
202d2a34232SLucas Stach 	val = IPU_PRE_STORE_ENG_CTRL_OUTPUT_ACTIVE_BPP(active_bpp) |
203d2a34232SLucas Stach 	      IPU_PRE_STORE_ENG_CTRL_WR_NUM_BYTES(4) |
204d2a34232SLucas Stach 	      IPU_PRE_STORE_ENG_CTRL_STORE_EN;
205d2a34232SLucas Stach 	writel(val, pre->regs + IPU_PRE_STORE_ENG_CTRL);
206d2a34232SLucas Stach 
207d2a34232SLucas Stach 	val = IPU_PRE_STORE_ENG_SIZE_INPUT_WIDTH(width) |
208d2a34232SLucas Stach 	      IPU_PRE_STORE_ENG_SIZE_INPUT_HEIGHT(height);
209d2a34232SLucas Stach 	writel(val, pre->regs + IPU_PRE_STORE_ENG_SIZE);
210d2a34232SLucas Stach 
211d2a34232SLucas Stach 	val = IPU_PRE_STORE_ENG_PITCH_OUT_PITCH(stride);
212d2a34232SLucas Stach 	writel(val, pre->regs + IPU_PRE_STORE_ENG_PITCH);
213d2a34232SLucas Stach 
214d2a34232SLucas Stach 	writel(pre->buffer_paddr, pre->regs + IPU_PRE_STORE_ENG_ADDR);
215d2a34232SLucas Stach 
2162f64a554SLucas Stach 	val = readl(pre->regs + IPU_PRE_TPR_CTRL);
2172f64a554SLucas Stach 	val &= ~IPU_PRE_TPR_CTRL_TILE_FORMAT_MASK;
2182f64a554SLucas Stach 	if (modifier != DRM_FORMAT_MOD_LINEAR) {
2192f64a554SLucas Stach 		/* only support single buffer formats for now */
2202f64a554SLucas Stach 		val |= IPU_PRE_TPR_CTRL_TILE_FORMAT_SINGLE_BUF;
2212f64a554SLucas Stach 		if (modifier == DRM_FORMAT_MOD_VIVANTE_SUPER_TILED)
2222f64a554SLucas Stach 			val |= IPU_PRE_TPR_CTRL_TILE_FORMAT_SUPER_TILED;
2232f64a554SLucas Stach 		if (info->cpp[0] == 2)
2242f64a554SLucas Stach 			val |= IPU_PRE_TPR_CTRL_TILE_FORMAT_16_BIT;
2252f64a554SLucas Stach 	}
2262f64a554SLucas Stach 	writel(val, pre->regs + IPU_PRE_TPR_CTRL);
2272f64a554SLucas Stach 
228d2a34232SLucas Stach 	val = readl(pre->regs + IPU_PRE_CTRL);
229d2a34232SLucas Stach 	val |= IPU_PRE_CTRL_EN_REPEAT | IPU_PRE_CTRL_ENABLE |
230d2a34232SLucas Stach 	       IPU_PRE_CTRL_SDW_UPDATE;
2312f64a554SLucas Stach 	if (modifier == DRM_FORMAT_MOD_LINEAR)
2322f64a554SLucas Stach 		val &= ~IPU_PRE_CTRL_BLOCK_EN;
2332f64a554SLucas Stach 	else
2342f64a554SLucas Stach 		val |= IPU_PRE_CTRL_BLOCK_EN;
235d2a34232SLucas Stach 	writel(val, pre->regs + IPU_PRE_CTRL);
236d2a34232SLucas Stach }
237d2a34232SLucas Stach 
238d2a34232SLucas Stach void ipu_pre_update(struct ipu_pre *pre, unsigned int bufaddr)
239d2a34232SLucas Stach {
24011aff4b4SLucas Stach 	unsigned long timeout = jiffies + msecs_to_jiffies(5);
24111aff4b4SLucas Stach 	unsigned short current_yblock;
24211aff4b4SLucas Stach 	u32 val;
24311aff4b4SLucas Stach 
244d2a34232SLucas Stach 	writel(bufaddr, pre->regs + IPU_PRE_NEXT_BUF);
24511aff4b4SLucas Stach 
24611aff4b4SLucas Stach 	do {
24711aff4b4SLucas Stach 		if (time_after(jiffies, timeout)) {
24811aff4b4SLucas Stach 			dev_warn(pre->dev, "timeout waiting for PRE safe window\n");
24911aff4b4SLucas Stach 			return;
25011aff4b4SLucas Stach 		}
25111aff4b4SLucas Stach 
25211aff4b4SLucas Stach 		val = readl(pre->regs + IPU_PRE_STORE_ENG_STATUS);
25311aff4b4SLucas Stach 		current_yblock =
25411aff4b4SLucas Stach 			(val >> IPU_PRE_STORE_ENG_STATUS_STORE_BLOCK_Y_SHIFT) &
25511aff4b4SLucas Stach 			IPU_PRE_STORE_ENG_STATUS_STORE_BLOCK_Y_MASK;
25611aff4b4SLucas Stach 	} while (current_yblock == 0 || current_yblock >= pre->safe_window_end);
25711aff4b4SLucas Stach 
258d2a34232SLucas Stach 	writel(IPU_PRE_CTRL_SDW_UPDATE, pre->regs + IPU_PRE_CTRL_SET);
259d2a34232SLucas Stach }
260d2a34232SLucas Stach 
261d2a34232SLucas Stach u32 ipu_pre_get_baddr(struct ipu_pre *pre)
262d2a34232SLucas Stach {
263d2a34232SLucas Stach 	return (u32)pre->buffer_paddr;
264d2a34232SLucas Stach }
265d2a34232SLucas Stach 
266d2a34232SLucas Stach static int ipu_pre_probe(struct platform_device *pdev)
267d2a34232SLucas Stach {
268d2a34232SLucas Stach 	struct device *dev = &pdev->dev;
269d2a34232SLucas Stach 	struct resource *res;
270d2a34232SLucas Stach 	struct ipu_pre *pre;
271d2a34232SLucas Stach 
272d2a34232SLucas Stach 	pre = devm_kzalloc(dev, sizeof(*pre), GFP_KERNEL);
273d2a34232SLucas Stach 	if (!pre)
274d2a34232SLucas Stach 		return -ENOMEM;
275d2a34232SLucas Stach 
276d2a34232SLucas Stach 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
277d2a34232SLucas Stach 	pre->regs = devm_ioremap_resource(&pdev->dev, res);
278d2a34232SLucas Stach 	if (IS_ERR(pre->regs))
279d2a34232SLucas Stach 		return PTR_ERR(pre->regs);
280d2a34232SLucas Stach 
281d2a34232SLucas Stach 	pre->clk_axi = devm_clk_get(dev, "axi");
282d2a34232SLucas Stach 	if (IS_ERR(pre->clk_axi))
283d2a34232SLucas Stach 		return PTR_ERR(pre->clk_axi);
284d2a34232SLucas Stach 
285d2a34232SLucas Stach 	pre->iram = of_gen_pool_get(dev->of_node, "fsl,iram", 0);
286d2a34232SLucas Stach 	if (!pre->iram)
287d2a34232SLucas Stach 		return -EPROBE_DEFER;
288d2a34232SLucas Stach 
289d2a34232SLucas Stach 	/*
290d2a34232SLucas Stach 	 * Allocate IRAM buffer with maximum size. This could be made dynamic,
291d2a34232SLucas Stach 	 * but as there is no other user of this IRAM region and we can fit all
292d2a34232SLucas Stach 	 * max sized buffers into it, there is no need yet.
293d2a34232SLucas Stach 	 */
294d2a34232SLucas Stach 	pre->buffer_virt = gen_pool_dma_alloc(pre->iram, IPU_PRE_MAX_WIDTH *
295d2a34232SLucas Stach 					      IPU_PRE_NUM_SCANLINES * 4,
296d2a34232SLucas Stach 					      &pre->buffer_paddr);
297d2a34232SLucas Stach 	if (!pre->buffer_virt)
298d2a34232SLucas Stach 		return -ENOMEM;
299d2a34232SLucas Stach 
30047c298f7SLucas Stach 	clk_prepare_enable(pre->clk_axi);
30147c298f7SLucas Stach 
302d2a34232SLucas Stach 	pre->dev = dev;
303d2a34232SLucas Stach 	platform_set_drvdata(pdev, pre);
304d2a34232SLucas Stach 	mutex_lock(&ipu_pre_list_mutex);
305d2a34232SLucas Stach 	list_add(&pre->list, &ipu_pre_list);
306d2a34232SLucas Stach 	available_pres++;
307d2a34232SLucas Stach 	mutex_unlock(&ipu_pre_list_mutex);
308d2a34232SLucas Stach 
309d2a34232SLucas Stach 	return 0;
310d2a34232SLucas Stach }
311d2a34232SLucas Stach 
312d2a34232SLucas Stach static int ipu_pre_remove(struct platform_device *pdev)
313d2a34232SLucas Stach {
314d2a34232SLucas Stach 	struct ipu_pre *pre = platform_get_drvdata(pdev);
315d2a34232SLucas Stach 
316d2a34232SLucas Stach 	mutex_lock(&ipu_pre_list_mutex);
317d2a34232SLucas Stach 	list_del(&pre->list);
318d2a34232SLucas Stach 	available_pres--;
319d2a34232SLucas Stach 	mutex_unlock(&ipu_pre_list_mutex);
320d2a34232SLucas Stach 
32147c298f7SLucas Stach 	clk_disable_unprepare(pre->clk_axi);
32247c298f7SLucas Stach 
323d2a34232SLucas Stach 	if (pre->buffer_virt)
324d2a34232SLucas Stach 		gen_pool_free(pre->iram, (unsigned long)pre->buffer_virt,
325d2a34232SLucas Stach 			      IPU_PRE_MAX_WIDTH * IPU_PRE_NUM_SCANLINES * 4);
326d2a34232SLucas Stach 	return 0;
327d2a34232SLucas Stach }
328d2a34232SLucas Stach 
329d2a34232SLucas Stach static const struct of_device_id ipu_pre_dt_ids[] = {
330d2a34232SLucas Stach 	{ .compatible = "fsl,imx6qp-pre", },
331d2a34232SLucas Stach 	{ /* sentinel */ },
332d2a34232SLucas Stach };
333d2a34232SLucas Stach 
334d2a34232SLucas Stach struct platform_driver ipu_pre_drv = {
335d2a34232SLucas Stach 	.probe		= ipu_pre_probe,
336d2a34232SLucas Stach 	.remove		= ipu_pre_remove,
337d2a34232SLucas Stach 	.driver		= {
338d2a34232SLucas Stach 		.name	= "imx-ipu-pre",
339d2a34232SLucas Stach 		.of_match_table = ipu_pre_dt_ids,
340d2a34232SLucas Stach 	},
341d2a34232SLucas Stach };
342