fimc-core.c 31.5 KB
Newer Older
1
/*
2
 * Samsung S5P/EXYNOS4 SoC series FIMC (CAMIF) driver
3
 *
4 5
 * Copyright (C) 2010-2012 Samsung Electronics Co., Ltd.
 * Sylwester Nawrocki <s.nawrocki@samsung.com>
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation, either version 2 of the License,
 * or (at your option) any later version.
 */

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/bug.h>
#include <linux/interrupt.h>
#include <linux/device.h>
#include <linux/platform_device.h>
21
#include <linux/pm_runtime.h>
22 23 24 25 26
#include <linux/list.h>
#include <linux/io.h>
#include <linux/slab.h>
#include <linux/clk.h>
#include <media/v4l2-ioctl.h>
27 28
#include <media/videobuf2-core.h>
#include <media/videobuf2-dma-contig.h>
29 30

#include "fimc-core.h"
31
#include "fimc-reg.h"
32
#include "fimc-mdevice.h"
33

34
static char *fimc_clocks[MAX_FIMC_CLOCKS] = {
35
	"sclk_fimc", "fimc"
36
};
37 38 39

static struct fimc_fmt fimc_formats[] = {
	{
40
		.name		= "RGB565",
41
		.fourcc		= V4L2_PIX_FMT_RGB565,
42
		.depth		= { 16 },
43
		.color		= FIMC_FMT_RGB565,
44 45 46
		.memplanes	= 1,
		.colplanes	= 1,
		.flags		= FMT_FLAGS_M2M,
47
	}, {
48 49 50
		.name		= "BGR666",
		.fourcc		= V4L2_PIX_FMT_BGR666,
		.depth		= { 32 },
51
		.color		= FIMC_FMT_RGB666,
52 53 54
		.memplanes	= 1,
		.colplanes	= 1,
		.flags		= FMT_FLAGS_M2M,
55
	}, {
56
		.name		= "ARGB8888, 32 bpp",
57 58
		.fourcc		= V4L2_PIX_FMT_RGB32,
		.depth		= { 32 },
59
		.color		= FIMC_FMT_RGB888,
60 61
		.memplanes	= 1,
		.colplanes	= 1,
62 63 64 65 66
		.flags		= FMT_FLAGS_M2M | FMT_HAS_ALPHA,
	}, {
		.name		= "ARGB1555",
		.fourcc		= V4L2_PIX_FMT_RGB555,
		.depth		= { 16 },
67
		.color		= FIMC_FMT_RGB555,
68 69 70 71 72 73 74
		.memplanes	= 1,
		.colplanes	= 1,
		.flags		= FMT_FLAGS_M2M_OUT | FMT_HAS_ALPHA,
	}, {
		.name		= "ARGB4444",
		.fourcc		= V4L2_PIX_FMT_RGB444,
		.depth		= { 16 },
75
		.color		= FIMC_FMT_RGB444,
76 77 78
		.memplanes	= 1,
		.colplanes	= 1,
		.flags		= FMT_FLAGS_M2M_OUT | FMT_HAS_ALPHA,
79
	}, {
80 81 82
		.name		= "YUV 4:2:2 packed, YCbYCr",
		.fourcc		= V4L2_PIX_FMT_YUYV,
		.depth		= { 16 },
83
		.color		= FIMC_FMT_YCBYCR422,
84 85 86 87
		.memplanes	= 1,
		.colplanes	= 1,
		.mbus_code	= V4L2_MBUS_FMT_YUYV8_2X8,
		.flags		= FMT_FLAGS_M2M | FMT_FLAGS_CAM,
88
	}, {
89 90 91
		.name		= "YUV 4:2:2 packed, CbYCrY",
		.fourcc		= V4L2_PIX_FMT_UYVY,
		.depth		= { 16 },
92
		.color		= FIMC_FMT_CBYCRY422,
93 94 95 96
		.memplanes	= 1,
		.colplanes	= 1,
		.mbus_code	= V4L2_MBUS_FMT_UYVY8_2X8,
		.flags		= FMT_FLAGS_M2M | FMT_FLAGS_CAM,
97
	}, {
98 99 100
		.name		= "YUV 4:2:2 packed, CrYCbY",
		.fourcc		= V4L2_PIX_FMT_VYUY,
		.depth		= { 16 },
101
		.color		= FIMC_FMT_CRYCBY422,
102 103 104 105
		.memplanes	= 1,
		.colplanes	= 1,
		.mbus_code	= V4L2_MBUS_FMT_VYUY8_2X8,
		.flags		= FMT_FLAGS_M2M | FMT_FLAGS_CAM,
106
	}, {
107 108 109
		.name		= "YUV 4:2:2 packed, YCrYCb",
		.fourcc		= V4L2_PIX_FMT_YVYU,
		.depth		= { 16 },
110
		.color		= FIMC_FMT_YCRYCB422,
111 112 113 114
		.memplanes	= 1,
		.colplanes	= 1,
		.mbus_code	= V4L2_MBUS_FMT_YVYU8_2X8,
		.flags		= FMT_FLAGS_M2M | FMT_FLAGS_CAM,
115
	}, {
116 117 118
		.name		= "YUV 4:2:2 planar, Y/Cb/Cr",
		.fourcc		= V4L2_PIX_FMT_YUV422P,
		.depth		= { 12 },
119
		.color		= FIMC_FMT_YCBYCR422,
120 121 122
		.memplanes	= 1,
		.colplanes	= 3,
		.flags		= FMT_FLAGS_M2M,
123
	}, {
124 125 126
		.name		= "YUV 4:2:2 planar, Y/CbCr",
		.fourcc		= V4L2_PIX_FMT_NV16,
		.depth		= { 16 },
127
		.color		= FIMC_FMT_YCBYCR422,
128 129 130
		.memplanes	= 1,
		.colplanes	= 2,
		.flags		= FMT_FLAGS_M2M,
131
	}, {
132 133 134
		.name		= "YUV 4:2:2 planar, Y/CrCb",
		.fourcc		= V4L2_PIX_FMT_NV61,
		.depth		= { 16 },
135
		.color		= FIMC_FMT_YCRYCB422,
136 137 138
		.memplanes	= 1,
		.colplanes	= 2,
		.flags		= FMT_FLAGS_M2M,
139
	}, {
140 141 142
		.name		= "YUV 4:2:0 planar, YCbCr",
		.fourcc		= V4L2_PIX_FMT_YUV420,
		.depth		= { 12 },
143
		.color		= FIMC_FMT_YCBCR420,
144 145 146
		.memplanes	= 1,
		.colplanes	= 3,
		.flags		= FMT_FLAGS_M2M,
147
	}, {
148 149 150
		.name		= "YUV 4:2:0 planar, Y/CbCr",
		.fourcc		= V4L2_PIX_FMT_NV12,
		.depth		= { 12 },
151
		.color		= FIMC_FMT_YCBCR420,
152 153 154 155
		.memplanes	= 1,
		.colplanes	= 2,
		.flags		= FMT_FLAGS_M2M,
	}, {
156
		.name		= "YUV 4:2:0 non-contig. 2p, Y/CbCr",
157
		.fourcc		= V4L2_PIX_FMT_NV12M,
158
		.color		= FIMC_FMT_YCBCR420,
159 160 161 162 163
		.depth		= { 8, 4 },
		.memplanes	= 2,
		.colplanes	= 2,
		.flags		= FMT_FLAGS_M2M,
	}, {
164
		.name		= "YUV 4:2:0 non-contig. 3p, Y/Cb/Cr",
165
		.fourcc		= V4L2_PIX_FMT_YUV420M,
166
		.color		= FIMC_FMT_YCBCR420,
167 168 169 170 171
		.depth		= { 8, 2, 2 },
		.memplanes	= 3,
		.colplanes	= 3,
		.flags		= FMT_FLAGS_M2M,
	}, {
172
		.name		= "YUV 4:2:0 non-contig. 2p, tiled",
173
		.fourcc		= V4L2_PIX_FMT_NV12MT,
174
		.color		= FIMC_FMT_YCBCR420,
175 176 177 178
		.depth		= { 8, 4 },
		.memplanes	= 2,
		.colplanes	= 2,
		.flags		= FMT_FLAGS_M2M,
179 180 181
	}, {
		.name		= "JPEG encoded data",
		.fourcc		= V4L2_PIX_FMT_JPEG,
182
		.color		= FIMC_FMT_JPEG,
183 184 185 186
		.depth		= { 8 },
		.memplanes	= 1,
		.colplanes	= 1,
		.mbus_code	= V4L2_MBUS_FMT_JPEG_1X8,
187 188 189 190 191 192 193 194 195 196 197
		.flags		= FMT_FLAGS_CAM | FMT_FLAGS_COMPRESSED,
	}, {
		.name		= "S5C73MX interleaved UYVY/JPEG",
		.fourcc		= V4L2_PIX_FMT_S5C_UYVY_JPG,
		.color		= FIMC_FMT_YUYV_JPEG,
		.depth		= { 8 },
		.memplanes	= 2,
		.colplanes	= 1,
		.mdataplanes	= 0x2, /* plane 1 holds frame meta data */
		.mbus_code	= V4L2_MBUS_FMT_S5C_UYVY_JPEG_1X8,
		.flags		= FMT_FLAGS_CAM | FMT_FLAGS_COMPRESSED,
198
	},
199
};
200

201
struct fimc_fmt *fimc_get_format(unsigned int index)
202
{
203 204 205 206
	if (index >= ARRAY_SIZE(fimc_formats))
		return NULL;

	return &fimc_formats[index];
207 208
}

209 210
int fimc_check_scaler_ratio(struct fimc_ctx *ctx, int sw, int sh,
			    int dw, int dh, int rotation)
211
{
212 213
	if (rotation == 90 || rotation == 270)
		swap(dw, dh);
214

215 216
	if (!ctx->scaler.enabled)
		return (sw == dw && sh == dh) ? 0 : -EINVAL;
217

218
	if ((sw >= SCALER_MAX_HRATIO * dw) || (sh >= SCALER_MAX_VRATIO * dh))
219 220
		return -EINVAL;

221 222 223 224 225
	return 0;
}

static int fimc_get_scaler_factor(u32 src, u32 tar, u32 *ratio, u32 *shift)
{
226 227 228
	u32 sh = 6;

	if (src >= 64 * tar)
229
		return -EINVAL;
230 231 232 233 234 235 236

	while (sh--) {
		u32 tmp = 1 << sh;
		if (src >= tar * tmp) {
			*shift = sh, *ratio = tmp;
			return 0;
		}
237
	}
238
	*shift = 0, *ratio = 1;
239 240 241
	return 0;
}

242
int fimc_set_scaler_info(struct fimc_ctx *ctx)
243
{
244
	const struct fimc_variant *variant = ctx->fimc_dev->variant;
245
	struct device *dev = &ctx->fimc_dev->pdev->dev;
246 247 248 249 250 251
	struct fimc_scaler *sc = &ctx->scaler;
	struct fimc_frame *s_frame = &ctx->s_frame;
	struct fimc_frame *d_frame = &ctx->d_frame;
	int tx, ty, sx, sy;
	int ret;

252 253 254 255 256 257 258
	if (ctx->rotation == 90 || ctx->rotation == 270) {
		ty = d_frame->width;
		tx = d_frame->height;
	} else {
		tx = d_frame->width;
		ty = d_frame->height;
	}
259
	if (tx <= 0 || ty <= 0) {
260
		dev_err(dev, "Invalid target size: %dx%d\n", tx, ty);
261 262 263 264 265 266
		return -EINVAL;
	}

	sx = s_frame->width;
	sy = s_frame->height;
	if (sx <= 0 || sy <= 0) {
267
		dev_err(dev, "Invalid source size: %dx%d\n", sx, sy);
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
		return -EINVAL;
	}
	sc->real_width = sx;
	sc->real_height = sy;

	ret = fimc_get_scaler_factor(sx, tx, &sc->pre_hratio, &sc->hfactor);
	if (ret)
		return ret;

	ret = fimc_get_scaler_factor(sy, ty,  &sc->pre_vratio, &sc->vfactor);
	if (ret)
		return ret;

	sc->pre_dst_width = sx / sc->pre_hratio;
	sc->pre_dst_height = sy / sc->pre_vratio;

284 285 286 287 288 289 290 291
	if (variant->has_mainscaler_ext) {
		sc->main_hratio = (sx << 14) / (tx << sc->hfactor);
		sc->main_vratio = (sy << 14) / (ty << sc->vfactor);
	} else {
		sc->main_hratio = (sx << 8) / (tx << sc->hfactor);
		sc->main_vratio = (sy << 8) / (ty << sc->vfactor);

	}
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306

	sc->scaleup_h = (tx >= sx) ? 1 : 0;
	sc->scaleup_v = (ty >= sy) ? 1 : 0;

	/* check to see if input and output size/format differ */
	if (s_frame->fmt->color == d_frame->fmt->color
		&& s_frame->width == d_frame->width
		&& s_frame->height == d_frame->height)
		sc->copy_mode = 1;
	else
		sc->copy_mode = 0;

	return 0;
}

307
static irqreturn_t fimc_irq_handler(int irq, void *priv)
308
{
309
	struct fimc_dev *fimc = priv;
310
	struct fimc_ctx *ctx;
311 312 313

	fimc_hw_clear_irq(fimc);

314 315
	spin_lock(&fimc->slock);

316
	if (test_and_clear_bit(ST_M2M_PEND, &fimc->state)) {
317 318 319 320 321
		if (test_and_clear_bit(ST_M2M_SUSPENDING, &fimc->state)) {
			set_bit(ST_M2M_SUSPENDED, &fimc->state);
			wake_up(&fimc->irq_queue);
			goto out;
		}
322 323
		ctx = v4l2_m2m_get_curr_priv(fimc->m2m.m2m_dev);
		if (ctx != NULL) {
324
			spin_unlock(&fimc->slock);
325
			fimc_m2m_job_finish(ctx, VB2_BUF_STATE_DONE);
326

327 328 329 330
			if (ctx->state & FIMC_CTX_SHUT) {
				ctx->state &= ~FIMC_CTX_SHUT;
				wake_up(&fimc->irq_queue);
			}
331
			return IRQ_HANDLED;
332
		}
333
	} else if (test_bit(ST_CAPT_PEND, &fimc->state)) {
334 335 336
		int last_buf = test_bit(ST_CAPT_JPEG, &fimc->state) &&
				fimc->vid_cap.reqbufs_count == 1;
		fimc_capture_irq_handler(fimc, !last_buf);
337
	}
338
out:
339 340 341 342
	spin_unlock(&fimc->slock);
	return IRQ_HANDLED;
}

343
/* The color format (colplanes, memplanes) must be already configured. */
344
int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb,
345
		      struct fimc_frame *frame, struct fimc_addr *paddr)
346 347
{
	int ret = 0;
348
	u32 pix_size;
349

350
	if (vb == NULL || frame == NULL)
351 352 353 354
		return -EINVAL;

	pix_size = frame->width * frame->height;

355 356 357
	dbg("memplanes= %d, colplanes= %d, pix_size= %d",
		frame->fmt->memplanes, frame->fmt->colplanes, pix_size);

358
	paddr->y = vb2_dma_contig_plane_dma_addr(vb, 0);
359

360 361
	if (frame->fmt->memplanes == 1) {
		switch (frame->fmt->colplanes) {
362 363 364 365 366 367 368 369 370 371 372 373
		case 1:
			paddr->cb = 0;
			paddr->cr = 0;
			break;
		case 2:
			/* decompose Y into Y/Cb */
			paddr->cb = (u32)(paddr->y + pix_size);
			paddr->cr = 0;
			break;
		case 3:
			paddr->cb = (u32)(paddr->y + pix_size);
			/* decompose Y into Y/Cb/Cr */
374
			if (FIMC_FMT_YCBCR420 == frame->fmt->color)
375 376 377 378 379 380 381 382 383
				paddr->cr = (u32)(paddr->cb
						+ (pix_size >> 2));
			else /* 422 */
				paddr->cr = (u32)(paddr->cb
						+ (pix_size >> 1));
			break;
		default:
			return -EINVAL;
		}
384
	} else if (!frame->fmt->mdataplanes) {
385
		if (frame->fmt->memplanes >= 2)
386
			paddr->cb = vb2_dma_contig_plane_dma_addr(vb, 1);
387 388

		if (frame->fmt->memplanes == 3)
389
			paddr->cr = vb2_dma_contig_plane_dma_addr(vb, 2);
390 391
	}

392 393
	dbg("PHYS_ADDR: y= 0x%X  cb= 0x%X cr= 0x%X ret= %d",
	    paddr->y, paddr->cb, paddr->cr, ret);
394 395 396 397 398

	return ret;
}

/* Set order for 1 and 2 plane YCBCR 4:2:2 formats. */
399
void fimc_set_yuv_order(struct fimc_ctx *ctx)
400 401
{
	/* The one only mode supported in SoC. */
402 403
	ctx->in_order_2p = FIMC_REG_CIOCTRL_ORDER422_2P_LSB_CRCB;
	ctx->out_order_2p = FIMC_REG_CIOCTRL_ORDER422_2P_LSB_CRCB;
404 405 406

	/* Set order for 1 plane input formats. */
	switch (ctx->s_frame.fmt->color) {
407
	case FIMC_FMT_YCRYCB422:
408
		ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_CBYCRY;
409
		break;
410
	case FIMC_FMT_CBYCRY422:
411
		ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_YCRYCB;
412
		break;
413
	case FIMC_FMT_CRYCBY422:
414
		ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_YCBYCR;
415
		break;
416
	case FIMC_FMT_YCBYCR422:
417
	default:
418
		ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_CRYCBY;
419 420 421 422 423
		break;
	}
	dbg("ctx->in_order_1p= %d", ctx->in_order_1p);

	switch (ctx->d_frame.fmt->color) {
424
	case FIMC_FMT_YCRYCB422:
425
		ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_CBYCRY;
426
		break;
427
	case FIMC_FMT_CBYCRY422:
428
		ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_YCRYCB;
429
		break;
430
	case FIMC_FMT_CRYCBY422:
431
		ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_YCBYCR;
432
		break;
433
	case FIMC_FMT_YCBYCR422:
434
	default:
435
		ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_CRYCBY;
436 437 438 439 440
		break;
	}
	dbg("ctx->out_order_1p= %d", ctx->out_order_1p);
}

441
void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f)
442
{
443
	const struct fimc_variant *variant = ctx->fimc_dev->variant;
444 445 446 447
	u32 i, depth = 0;

	for (i = 0; i < f->fmt->colplanes; i++)
		depth += f->fmt->depth[i];
448 449 450

	f->dma_offset.y_h = f->offs_h;
	if (!variant->pix_hoff)
451
		f->dma_offset.y_h *= (depth >> 3);
452 453 454 455 456 457 458 459 460 461

	f->dma_offset.y_v = f->offs_v;

	f->dma_offset.cb_h = f->offs_h;
	f->dma_offset.cb_v = f->offs_v;

	f->dma_offset.cr_h = f->offs_h;
	f->dma_offset.cr_v = f->offs_v;

	if (!variant->pix_hoff) {
462
		if (f->fmt->colplanes == 3) {
463 464 465
			f->dma_offset.cb_h >>= 1;
			f->dma_offset.cr_h >>= 1;
		}
466
		if (f->fmt->color == FIMC_FMT_YCBCR420) {
467 468 469 470 471 472 473 474 475
			f->dma_offset.cb_v >>= 1;
			f->dma_offset.cr_v >>= 1;
		}
	}

	dbg("in_offset: color= %d, y_h= %d, y_v= %d",
	    f->fmt->color, f->dma_offset.y_h, f->dma_offset.y_v);
}

476
static int fimc_set_color_effect(struct fimc_ctx *ctx, enum v4l2_colorfx colorfx)
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
{
	struct fimc_effect *effect = &ctx->effect;

	switch (colorfx) {
	case V4L2_COLORFX_NONE:
		effect->type = FIMC_REG_CIIMGEFF_FIN_BYPASS;
		break;
	case V4L2_COLORFX_BW:
		effect->type = FIMC_REG_CIIMGEFF_FIN_ARBITRARY;
		effect->pat_cb = 128;
		effect->pat_cr = 128;
		break;
	case V4L2_COLORFX_SEPIA:
		effect->type = FIMC_REG_CIIMGEFF_FIN_ARBITRARY;
		effect->pat_cb = 115;
		effect->pat_cr = 145;
		break;
	case V4L2_COLORFX_NEGATIVE:
		effect->type = FIMC_REG_CIIMGEFF_FIN_NEGATIVE;
		break;
	case V4L2_COLORFX_EMBOSS:
		effect->type = FIMC_REG_CIIMGEFF_FIN_EMBOSSING;
		break;
	case V4L2_COLORFX_ART_FREEZE:
		effect->type = FIMC_REG_CIIMGEFF_FIN_ARTFREEZE;
		break;
	case V4L2_COLORFX_SILHOUETTE:
		effect->type = FIMC_REG_CIIMGEFF_FIN_SILHOUETTE;
		break;
	case V4L2_COLORFX_SET_CBCR:
		effect->type = FIMC_REG_CIIMGEFF_FIN_ARBITRARY;
		effect->pat_cb = ctx->ctrls.colorfx_cbcr->val >> 8;
		effect->pat_cr = ctx->ctrls.colorfx_cbcr->val & 0xff;
		break;
	default:
		return -EINVAL;
	}

	return 0;
}

518 519 520 521
/*
 * V4L2 controls handling
 */
#define ctrl_to_ctx(__ctrl) \
522
	container_of((__ctrl)->handler, struct fimc_ctx, ctrls.handler)
523

524
static int __fimc_s_ctrl(struct fimc_ctx *ctx, struct v4l2_ctrl *ctrl)
525 526
{
	struct fimc_dev *fimc = ctx->fimc_dev;
527
	const struct fimc_variant *variant = fimc->variant;
528
	unsigned int flags = FIMC_DST_FMT | FIMC_SRC_FMT;
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544
	int ret = 0;

	if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE)
		return 0;

	switch (ctrl->id) {
	case V4L2_CID_HFLIP:
		ctx->hflip = ctrl->val;
		break;

	case V4L2_CID_VFLIP:
		ctx->vflip = ctrl->val;
		break;

	case V4L2_CID_ROTATE:
		if (fimc_capture_pending(fimc) ||
545
		    (ctx->state & flags) == flags) {
546
			ret = fimc_check_scaler_ratio(ctx, ctx->s_frame.width,
547 548
					ctx->s_frame.height, ctx->d_frame.width,
					ctx->d_frame.height, ctrl->val);
549 550
			if (ret)
				return -EINVAL;
551 552 553 554
		}
		if ((ctrl->val == 90 || ctrl->val == 270) &&
		    !variant->has_out_rot)
			return -EINVAL;
555

556 557 558
		ctx->rotation = ctrl->val;
		break;

559 560 561
	case V4L2_CID_ALPHA_COMPONENT:
		ctx->d_frame.alpha = ctrl->val;
		break;
562 563 564 565 566 567

	case V4L2_CID_COLORFX:
		ret = fimc_set_color_effect(ctx, ctrl->val);
		if (ret)
			return ret;
		break;
568
	}
569

570 571 572 573 574
	ctx->state |= FIMC_PARAMS;
	set_bit(ST_CAPT_APPLY_CFG, &fimc->state);
	return 0;
}

575 576 577 578 579 580
static int fimc_s_ctrl(struct v4l2_ctrl *ctrl)
{
	struct fimc_ctx *ctx = ctrl_to_ctx(ctrl);
	unsigned long flags;
	int ret;

581
	spin_lock_irqsave(&ctx->fimc_dev->slock, flags);
582
	ret = __fimc_s_ctrl(ctx, ctrl);
583
	spin_unlock_irqrestore(&ctx->fimc_dev->slock, flags);
584 585 586 587

	return ret;
}

588 589 590 591 592 593
static const struct v4l2_ctrl_ops fimc_ctrl_ops = {
	.s_ctrl = fimc_s_ctrl,
};

int fimc_ctrls_create(struct fimc_ctx *ctx)
{
594
	const struct fimc_variant *variant = ctx->fimc_dev->variant;
595
	unsigned int max_alpha = fimc_get_alpha_mask(ctx->d_frame.fmt);
596 597
	struct fimc_ctrls *ctrls = &ctx->ctrls;
	struct v4l2_ctrl_handler *handler = &ctrls->handler;
598

599
	if (ctx->ctrls.ready)
600 601
		return 0;

602 603 604
	v4l2_ctrl_handler_init(handler, 6);

	ctrls->rotate = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
605
					V4L2_CID_ROTATE, 0, 270, 90, 0);
606
	ctrls->hflip = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
607
					V4L2_CID_HFLIP, 0, 1, 1, 0);
608
	ctrls->vflip = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
609
					V4L2_CID_VFLIP, 0, 1, 1, 0);
610

611
	if (variant->has_alpha)
612 613 614
		ctrls->alpha = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
					V4L2_CID_ALPHA_COMPONENT,
					0, max_alpha, 1, 0);
615
	else
616 617 618 619 620 621 622 623
		ctrls->alpha = NULL;

	ctrls->colorfx = v4l2_ctrl_new_std_menu(handler, &fimc_ctrl_ops,
				V4L2_CID_COLORFX, V4L2_COLORFX_SET_CBCR,
				~0x983f, V4L2_COLORFX_NONE);

	ctrls->colorfx_cbcr = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops,
				V4L2_CID_COLORFX_CBCR, 0, 0xffff, 1, 0);
624

625
	ctx->effect.type = FIMC_REG_CIIMGEFF_FIN_BYPASS;
626

627
	if (!handler->error) {
628
		v4l2_ctrl_cluster(2, &ctrls->colorfx);
629 630 631 632
		ctrls->ready = true;
	}

	return handler->error;
633 634 635 636
}

void fimc_ctrls_delete(struct fimc_ctx *ctx)
{
637 638 639 640 641 642
	struct fimc_ctrls *ctrls = &ctx->ctrls;

	if (ctrls->ready) {
		v4l2_ctrl_handler_free(&ctrls->handler);
		ctrls->ready = false;
		ctrls->alpha = NULL;
643 644 645 646 647
	}
}

void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active)
{
648
	unsigned int has_alpha = ctx->d_frame.fmt->flags & FMT_HAS_ALPHA;
649
	struct fimc_ctrls *ctrls = &ctx->ctrls;
650

651
	if (!ctrls->ready)
652 653
		return;

654
	mutex_lock(ctrls->handler.lock);
655 656 657 658 659 660
	v4l2_ctrl_activate(ctrls->rotate, active);
	v4l2_ctrl_activate(ctrls->hflip, active);
	v4l2_ctrl_activate(ctrls->vflip, active);
	v4l2_ctrl_activate(ctrls->colorfx, active);
	if (ctrls->alpha)
		v4l2_ctrl_activate(ctrls->alpha, active && has_alpha);
661 662

	if (active) {
663 664 665 666
		fimc_set_color_effect(ctx, ctrls->colorfx->cur.val);
		ctx->rotation = ctrls->rotate->val;
		ctx->hflip    = ctrls->hflip->val;
		ctx->vflip    = ctrls->vflip->val;
667
	} else {
668
		ctx->effect.type = FIMC_REG_CIIMGEFF_FIN_BYPASS;
669 670 671 672
		ctx->rotation = 0;
		ctx->hflip    = 0;
		ctx->vflip    = 0;
	}
673
	mutex_unlock(ctrls->handler.lock);
674 675
}

676 677 678 679
/* Update maximum value of the alpha color control */
void fimc_alpha_ctrl_update(struct fimc_ctx *ctx)
{
	struct fimc_dev *fimc = ctx->fimc_dev;
680
	struct v4l2_ctrl *ctrl = ctx->ctrls.alpha;
681 682 683 684 685 686 687 688 689 690 691 692 693

	if (ctrl == NULL || !fimc->variant->has_alpha)
		return;

	v4l2_ctrl_lock(ctrl);
	ctrl->maximum = fimc_get_alpha_mask(ctx->d_frame.fmt);

	if (ctrl->cur.val > ctrl->maximum)
		ctrl->cur.val = ctrl->maximum;

	v4l2_ctrl_unlock(ctrl);
}

694
void __fimc_get_format(struct fimc_frame *frame, struct v4l2_format *f)
695
{
696
	struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp;
697
	int i;
698

699 700 701 702 703 704
	pixm->width = frame->o_width;
	pixm->height = frame->o_height;
	pixm->field = V4L2_FIELD_NONE;
	pixm->pixelformat = frame->fmt->fourcc;
	pixm->colorspace = V4L2_COLORSPACE_JPEG;
	pixm->num_planes = frame->fmt->memplanes;
705 706

	for (i = 0; i < pixm->num_planes; ++i) {
707 708
		pixm->plane_fmt[i].bytesperline = frame->bytesperline[i];
		pixm->plane_fmt[i].sizeimage = frame->payload[i];
709
	}
710 711
}

712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
void fimc_fill_frame(struct fimc_frame *frame, struct v4l2_format *f)
{
	struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp;

	frame->f_width  = pixm->plane_fmt[0].bytesperline;
	if (frame->fmt->colplanes == 1)
		frame->f_width = (frame->f_width * 8) / frame->fmt->depth[0];
	frame->f_height	= pixm->height;
	frame->width    = pixm->width;
	frame->height   = pixm->height;
	frame->o_width  = pixm->width;
	frame->o_height = pixm->height;
	frame->offs_h   = 0;
	frame->offs_v   = 0;
}

/**
 * fimc_adjust_mplane_format - adjust bytesperline/sizeimage for each plane
 * @fmt: fimc pixel format description (input)
 * @width: requested pixel width
 * @height: requested pixel height
 * @pix: multi-plane format to adjust
 */
void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height,
			       struct v4l2_pix_format_mplane *pix)
{
	u32 bytesperline = 0;
	int i;

	pix->colorspace	= V4L2_COLORSPACE_JPEG;
	pix->field = V4L2_FIELD_NONE;
	pix->num_planes = fmt->memplanes;
744
	pix->pixelformat = fmt->fourcc;
745 746 747 748
	pix->height = height;
	pix->width = width;

	for (i = 0; i < pix->num_planes; ++i) {
749 750
		struct v4l2_plane_pix_format *plane_fmt = &pix->plane_fmt[i];
		u32 bpl = plane_fmt->bytesperline;
751 752 753 754 755 756 757

		if (fmt->colplanes > 1 && (bpl == 0 || bpl < pix->width))
			bpl = pix->width; /* Planar */

		if (fmt->colplanes == 1 && /* Packed */
		    (bpl == 0 || ((bpl * 8) / fmt->depth[i]) < pix->width))
			bpl = (pix->width * fmt->depth[0]) / 8;
758 759 760 761 762 763 764
		/*
		 * Currently bytesperline for each plane is same, except
		 * V4L2_PIX_FMT_YUV420M format. This calculation may need
		 * to be changed when other multi-planar formats are added
		 * to the fimc_formats[] array.
		 */
		if (i == 0)
765
			bytesperline = bpl;
766 767
		else if (i == 1 && fmt->memplanes == 3)
			bytesperline /= 2;
768

769 770 771
		plane_fmt->bytesperline = bytesperline;
		plane_fmt->sizeimage = max((pix->width * pix->height *
				   fmt->depth[i]) / 8, plane_fmt->sizeimage);
772 773 774
	}
}

775 776 777 778 779 780 781
/**
 * fimc_find_format - lookup fimc color format by fourcc or media bus format
 * @pixelformat: fourcc to match, ignored if null
 * @mbus_code: media bus code to match, ignored if null
 * @mask: the color flags to match
 * @index: offset in the fimc_formats array, ignored if negative
 */
782
struct fimc_fmt *fimc_find_format(const u32 *pixelformat, const u32 *mbus_code,
783
				  unsigned int mask, int index)
784
{
785
	struct fimc_fmt *fmt, *def_fmt = NULL;
786
	unsigned int i;
787
	int id = 0;
788

789
	if (index >= (int)ARRAY_SIZE(fimc_formats))
790
		return NULL;
791 792 793

	for (i = 0; i < ARRAY_SIZE(fimc_formats); ++i) {
		fmt = &fimc_formats[i];
794 795 796 797 798 799 800 801 802
		if (!(fmt->flags & mask))
			continue;
		if (pixelformat && fmt->fourcc == *pixelformat)
			return fmt;
		if (mbus_code && fmt->mbus_code == *mbus_code)
			return fmt;
		if (index == id)
			def_fmt = fmt;
		id++;
803
	}
804
	return def_fmt;
805 806
}

807
static void fimc_clk_put(struct fimc_dev *fimc)
808 809
{
	int i;
810
	for (i = 0; i < MAX_FIMC_CLOCKS; i++) {
811
		if (IS_ERR(fimc->clock[i]))
812 813 814
			continue;
		clk_unprepare(fimc->clock[i]);
		clk_put(fimc->clock[i]);
815
		fimc->clock[i] = ERR_PTR(-EINVAL);
816 817 818 819 820
	}
}

static int fimc_clk_get(struct fimc_dev *fimc)
{
821 822
	int i, ret;

823 824 825
	for (i = 0; i < MAX_FIMC_CLOCKS; i++)
		fimc->clock[i] = ERR_PTR(-EINVAL);

826
	for (i = 0; i < MAX_FIMC_CLOCKS; i++) {
827
		fimc->clock[i] = clk_get(&fimc->pdev->dev, fimc_clocks[i]);
828 829
		if (IS_ERR(fimc->clock[i])) {
			ret = PTR_ERR(fimc->clock[i]);
830
			goto err;
831
		}
832 833 834
		ret = clk_prepare(fimc->clock[i]);
		if (ret < 0) {
			clk_put(fimc->clock[i]);
835
			fimc->clock[i] = ERR_PTR(-EINVAL);
836 837
			goto err;
		}
838
	}
839
	return 0;
840 841 842 843 844
err:
	fimc_clk_put(fimc);
	dev_err(&fimc->pdev->dev, "failed to get clock: %s\n",
		fimc_clocks[i]);
	return -ENXIO;
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880
}

static int fimc_m2m_suspend(struct fimc_dev *fimc)
{
	unsigned long flags;
	int timeout;

	spin_lock_irqsave(&fimc->slock, flags);
	if (!fimc_m2m_pending(fimc)) {
		spin_unlock_irqrestore(&fimc->slock, flags);
		return 0;
	}
	clear_bit(ST_M2M_SUSPENDED, &fimc->state);
	set_bit(ST_M2M_SUSPENDING, &fimc->state);
	spin_unlock_irqrestore(&fimc->slock, flags);

	timeout = wait_event_timeout(fimc->irq_queue,
			     test_bit(ST_M2M_SUSPENDED, &fimc->state),
			     FIMC_SHUTDOWN_TIMEOUT);

	clear_bit(ST_M2M_SUSPENDING, &fimc->state);
	return timeout == 0 ? -EAGAIN : 0;
}

static int fimc_m2m_resume(struct fimc_dev *fimc)
{
	unsigned long flags;

	spin_lock_irqsave(&fimc->slock, flags);
	/* Clear for full H/W setup in first run after resume */
	fimc->m2m.ctx = NULL;
	spin_unlock_irqrestore(&fimc->slock, flags);

	if (test_and_clear_bit(ST_M2M_SUSPENDED, &fimc->state))
		fimc_m2m_job_finish(fimc->m2m.ctx,
				    VB2_BUF_STATE_ERROR);
881 882 883 884 885
	return 0;
}

static int fimc_probe(struct platform_device *pdev)
{
886
	const struct fimc_drvdata *drv_data = fimc_get_drvdata(pdev);
887
	struct s5p_platform_fimc *pdata;
888 889 890 891
	struct fimc_dev *fimc;
	struct resource *res;
	int ret = 0;

892
	if (pdev->id >= drv_data->num_entities) {
893 894 895 896 897
		dev_err(&pdev->dev, "Invalid platform device id: %d\n",
			pdev->id);
		return -EINVAL;
	}

898
	fimc = devm_kzalloc(&pdev->dev, sizeof(*fimc), GFP_KERNEL);
899 900 901 902
	if (!fimc)
		return -ENOMEM;

	fimc->id = pdev->id;
903

904 905
	fimc->variant = drv_data->variant[fimc->id];
	fimc->pdev = pdev;
906 907
	pdata = pdev->dev.platform_data;
	fimc->pdata = pdata;
908

909
	init_waitqueue_head(&fimc->irq_queue);
910 911 912 913
	spin_lock_init(&fimc->slock);
	mutex_init(&fimc->lock);

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
914 915 916 917
	fimc->regs = devm_request_and_ioremap(&pdev->dev, res);
	if (fimc->regs == NULL) {
		dev_err(&pdev->dev, "Failed to obtain io memory\n");
		return -ENOENT;
918 919 920
	}

	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
921 922 923
	if (res == NULL) {
		dev_err(&pdev->dev, "Failed to get IRQ resource\n");
		return -ENXIO;
924 925
	}

926 927
	ret = fimc_clk_get(fimc);
	if (ret)
928
		return ret;
929 930 931 932 933 934 935 936

	ret = clk_set_rate(fimc->clock[CLK_BUS], drv_data->lclk_frequency);
	if (ret < 0)
		return ret;

	ret = clk_enable(fimc->clock[CLK_BUS]);
	if (ret < 0)
		return ret;
937

938
	ret = devm_request_irq(&pdev->dev, res->start, fimc_irq_handler,
939
			       0, dev_name(&pdev->dev), fimc);
940 941 942 943 944
	if (ret) {
		dev_err(&pdev->dev, "failed to install irq (%d)\n", ret);
		goto err_clk;
	}

945 946 947 948 949
	ret = fimc_initialize_capture_subdev(fimc);
	if (ret)
		goto err_clk;

	platform_set_drvdata(pdev, fimc);
950 951 952
	pm_runtime_enable(&pdev->dev);
	ret = pm_runtime_get_sync(&pdev->dev);
	if (ret < 0)
953
		goto err_sd;
954
	/* Initialize contiguous memory allocator */
955
	fimc->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
956 957
	if (IS_ERR(fimc->alloc_ctx)) {
		ret = PTR_ERR(fimc->alloc_ctx);
958
		goto err_pm;
959 960
	}

961
	dev_dbg(&pdev->dev, "FIMC.%d registered successfully\n", fimc->id);
962

963
	pm_runtime_put(&pdev->dev);
964
	return 0;
965 966
err_pm:
	pm_runtime_put(&pdev->dev);
967 968
err_sd:
	fimc_unregister_capture_subdev(fimc);
969
err_clk:
970
	clk_disable(fimc->clock[CLK_BUS]);
971
	fimc_clk_put(fimc);
972 973 974
	return ret;
}

975
static int fimc_runtime_resume(struct device *dev)
976
{
977
	struct fimc_dev *fimc =	dev_get_drvdata(dev);
978

979 980 981 982
	dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);

	/* Enable clocks and perform basic initalization */
	clk_enable(fimc->clock[CLK_GATE]);
983
	fimc_hw_reset(fimc);
984 985 986 987

	/* Resume the capture or mem-to-mem device */
	if (fimc_capture_busy(fimc))
		return fimc_capture_resume(fimc);
988 989

	return fimc_m2m_resume(fimc);
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
}

static int fimc_runtime_suspend(struct device *dev)
{
	struct fimc_dev *fimc =	dev_get_drvdata(dev);
	int ret = 0;

	if (fimc_capture_busy(fimc))
		ret = fimc_capture_suspend(fimc);
	else
		ret = fimc_m2m_suspend(fimc);
	if (!ret)
		clk_disable(fimc->clock[CLK_GATE]);

	dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);
	return ret;
}

#ifdef CONFIG_PM_SLEEP
static int fimc_resume(struct device *dev)
{
	struct fimc_dev *fimc =	dev_get_drvdata(dev);
	unsigned long flags;

	dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);

	/* Do not resume if the device was idle before system suspend */
	spin_lock_irqsave(&fimc->slock, flags);
	if (!test_and_clear_bit(ST_LPM, &fimc->state) ||
	    (!fimc_m2m_active(fimc) && !fimc_capture_busy(fimc))) {
		spin_unlock_irqrestore(&fimc->slock, flags);
		return 0;
	}
	fimc_hw_reset(fimc);
	spin_unlock_irqrestore(&fimc->slock, flags);

	if (fimc_capture_busy(fimc))
		return fimc_capture_resume(fimc);

	return fimc_m2m_resume(fimc);
}

static int fimc_suspend(struct device *dev)
{
	struct fimc_dev *fimc =	dev_get_drvdata(dev);

	dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state);

	if (test_and_set_bit(ST_LPM, &fimc->state))
		return 0;
	if (fimc_capture_busy(fimc))
		return fimc_capture_suspend(fimc);

	return fimc_m2m_suspend(fimc);
}
#endif /* CONFIG_PM_SLEEP */

1047
static int fimc_remove(struct platform_device *pdev)
1048 1049 1050 1051 1052
{
	struct fimc_dev *fimc = platform_get_drvdata(pdev);

	pm_runtime_disable(&pdev->dev);
	pm_runtime_set_suspended(&pdev->dev);
1053

1054
	fimc_unregister_capture_subdev(fimc);
1055 1056
	vb2_dma_contig_cleanup_ctx(fimc->alloc_ctx);

1057 1058
	clk_disable(fimc->clock[CLK_BUS]);
	fimc_clk_put(fimc);
1059

1060
	dev_info(&pdev->dev, "driver unloaded\n");
1061 1062 1063
	return 0;
}

1064
/* Image pixel limits, similar across several FIMC HW revisions. */
1065
static const struct fimc_pix_limit s5p_pix_limit[4] = {
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
	[0] = {
		.scaler_en_w	= 3264,
		.scaler_dis_w	= 8192,
		.in_rot_en_h	= 1920,
		.in_rot_dis_w	= 8192,
		.out_rot_en_w	= 1920,
		.out_rot_dis_w	= 4224,
	},
	[1] = {
		.scaler_en_w	= 4224,
		.scaler_dis_w	= 8192,
		.in_rot_en_h	= 1920,
		.in_rot_dis_w	= 8192,
		.out_rot_en_w	= 1920,
		.out_rot_dis_w	= 4224,
	},
	[2] = {
		.scaler_en_w	= 1920,
		.scaler_dis_w	= 8192,
		.in_rot_en_h	= 1280,
		.in_rot_dis_w	= 8192,
		.out_rot_en_w	= 1280,
		.out_rot_dis_w	= 1920,
	},
1090 1091 1092 1093 1094 1095 1096 1097
	[3] = {
		.scaler_en_w	= 1920,
		.scaler_dis_w	= 8192,
		.in_rot_en_h	= 1366,
		.in_rot_dis_w	= 8192,
		.out_rot_en_w	= 1366,
		.out_rot_dis_w	= 1920,
	},
1098 1099
};

1100
static const struct fimc_variant fimc0_variant_s5p = {
1101 1102
	.has_inp_rot	 = 1,
	.has_out_rot	 = 1,
1103
	.has_cam_if	 = 1,
1104 1105
	.min_inp_pixsize = 16,
	.min_out_pixsize = 16,
1106
	.hor_offs_align	 = 8,
1107
	.min_vsize_align = 16,
1108 1109
	.out_buf_count	 = 4,
	.pix_limit	 = &s5p_pix_limit[0],
1110 1111
};

1112
static const struct fimc_variant fimc2_variant_s5p = {
1113
	.has_cam_if	 = 1,
1114 1115
	.min_inp_pixsize = 16,
	.min_out_pixsize = 16,
1116
	.hor_offs_align	 = 8,
1117
	.min_vsize_align = 16,
1118
	.out_buf_count	 = 4,
1119
	.pix_limit	 = &s5p_pix_limit[1],
1120 1121
};

1122
static const struct fimc_variant fimc0_variant_s5pv210 = {
1123 1124 1125
	.pix_hoff	 = 1,
	.has_inp_rot	 = 1,
	.has_out_rot	 = 1,
1126
	.has_cam_if	 = 1,
1127
	.min_inp_pixsize = 16,
1128
	.min_out_pixsize = 16,
1129
	.hor_offs_align	 = 8,
1130
	.min_vsize_align = 16,
1131 1132 1133
	.out_buf_count	 = 4,
	.pix_limit	 = &s5p_pix_limit[1],
};
1134

1135
static const struct fimc_variant fimc1_variant_s5pv210 = {
1136 1137 1138
	.pix_hoff	 = 1,
	.has_inp_rot	 = 1,
	.has_out_rot	 = 1,
1139
	.has_cam_if	 = 1,
1140
	.has_mainscaler_ext = 1,
1141 1142 1143
	.min_inp_pixsize = 16,
	.min_out_pixsize = 16,
	.hor_offs_align	 = 1,
1144
	.min_vsize_align = 1,
1145 1146
	.out_buf_count	 = 4,
	.pix_limit	 = &s5p_pix_limit[2],
1147 1148
};

1149
static const struct fimc_variant fimc2_variant_s5pv210 = {
1150
	.has_cam_if	 = 1,
1151
	.pix_hoff	 = 1,
1152
	.min_inp_pixsize = 16,
1153
	.min_out_pixsize = 16,
1154
	.hor_offs_align	 = 8,
1155
	.min_vsize_align = 16,
1156 1157 1158
	.out_buf_count	 = 4,
	.pix_limit	 = &s5p_pix_limit[2],
};
1159

1160
static const struct fimc_variant fimc0_variant_exynos4210 = {
1161 1162 1163
	.pix_hoff	 = 1,
	.has_inp_rot	 = 1,
	.has_out_rot	 = 1,
1164
	.has_cam_if	 = 1,
1165
	.has_cistatus2	 = 1,
1166
	.has_mainscaler_ext = 1,
1167
	.has_alpha	 = 1,
1168 1169
	.min_inp_pixsize = 16,
	.min_out_pixsize = 16,
1170
	.hor_offs_align	 = 2,
1171
	.min_vsize_align = 1,
1172 1173 1174 1175
	.out_buf_count	 = 32,
	.pix_limit	 = &s5p_pix_limit[1],
};

1176
static const struct fimc_variant fimc3_variant_exynos4210 = {
1177
	.pix_hoff	 = 1,
1178
	.has_cistatus2	 = 1,
1179
	.has_mainscaler_ext = 1,
1180
	.has_alpha	 = 1,
1181 1182
	.min_inp_pixsize = 16,
	.min_out_pixsize = 16,
1183
	.hor_offs_align	 = 2,
1184
	.min_vsize_align = 1,
1185
	.out_buf_count	 = 32,
1186
	.pix_limit	 = &s5p_pix_limit[3],
1187 1188
};

1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218
static const struct fimc_variant fimc0_variant_exynos4x12 = {
	.pix_hoff		= 1,
	.has_inp_rot		= 1,
	.has_out_rot		= 1,
	.has_cam_if		= 1,
	.has_isp_wb		= 1,
	.has_cistatus2		= 1,
	.has_mainscaler_ext	= 1,
	.has_alpha		= 1,
	.min_inp_pixsize	= 16,
	.min_out_pixsize	= 16,
	.hor_offs_align		= 2,
	.min_vsize_align	= 1,
	.out_buf_count		= 32,
	.pix_limit		= &s5p_pix_limit[1],
};

static const struct fimc_variant fimc3_variant_exynos4x12 = {
	.pix_hoff		= 1,
	.has_cistatus2		= 1,
	.has_mainscaler_ext	= 1,
	.has_alpha		= 1,
	.min_inp_pixsize	= 16,
	.min_out_pixsize	= 16,
	.hor_offs_align		= 2,
	.min_vsize_align	= 1,
	.out_buf_count		= 32,
	.pix_limit		= &s5p_pix_limit[3],
};

1219
/* S5PC100 */
1220
static const struct fimc_drvdata fimc_drvdata_s5p = {
1221
	.variant = {
1222 1223
		[0] = &fimc0_variant_s5p,
		[1] = &fimc0_variant_s5p,
1224 1225
		[2] = &fimc2_variant_s5p,
	},
1226 1227
	.num_entities = 3,
	.lclk_frequency = 133000000UL,
1228 1229
};

1230
/* S5PV210, S5PC110 */
1231
static const struct fimc_drvdata fimc_drvdata_s5pv210 = {
1232
	.variant = {
1233 1234
		[0] = &fimc0_variant_s5pv210,
		[1] = &fimc1_variant_s5pv210,
1235 1236
		[2] = &fimc2_variant_s5pv210,
	},
1237 1238 1239 1240
	.num_entities = 3,
	.lclk_frequency = 166000000UL,
};

1241
/* EXYNOS4210, S5PV310, S5PC210 */
1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254
static const struct fimc_drvdata fimc_drvdata_exynos4210 = {
	.variant = {
		[0] = &fimc0_variant_exynos4210,
		[1] = &fimc0_variant_exynos4210,
		[2] = &fimc0_variant_exynos4210,
		[3] = &fimc3_variant_exynos4210,
	},
	.num_entities = 4,
	.lclk_frequency = 166000000UL,
};

/* EXYNOS4212, EXYNOS4412 */
static const struct fimc_drvdata fimc_drvdata_exynos4x12 = {
1255
	.variant = {
1256 1257 1258 1259
		[0] = &fimc0_variant_exynos4x12,
		[1] = &fimc0_variant_exynos4x12,
		[2] = &fimc0_variant_exynos4x12,
		[3] = &fimc3_variant_exynos4x12,
1260 1261 1262
	},
	.num_entities = 4,
	.lclk_frequency = 166000000UL,
1263 1264
};

1265
static const struct platform_device_id fimc_driver_ids[] = {
1266 1267 1268 1269 1270 1271
	{
		.name		= "s5p-fimc",
		.driver_data	= (unsigned long)&fimc_drvdata_s5p,
	}, {
		.name		= "s5pv210-fimc",
		.driver_data	= (unsigned long)&fimc_drvdata_s5pv210,
1272
	}, {
1273
		.name		= "exynos4-fimc",
1274 1275 1276 1277
		.driver_data	= (unsigned long)&fimc_drvdata_exynos4210,
	}, {
		.name		= "exynos4x12-fimc",
		.driver_data	= (unsigned long)&fimc_drvdata_exynos4x12,
1278 1279 1280 1281 1282
	},
	{},
};
MODULE_DEVICE_TABLE(platform, fimc_driver_ids);

1283 1284 1285 1286 1287
static const struct dev_pm_ops fimc_pm_ops = {
	SET_SYSTEM_SLEEP_PM_OPS(fimc_suspend, fimc_resume)
	SET_RUNTIME_PM_OPS(fimc_runtime_suspend, fimc_runtime_resume, NULL)
};

1288 1289
static struct platform_driver fimc_driver = {
	.probe		= fimc_probe,
1290
	.remove		= fimc_remove,
1291 1292
	.id_table	= fimc_driver_ids,
	.driver = {
1293
		.name	= FIMC_MODULE_NAME,
1294
		.owner	= THIS_MODULE,
1295
		.pm     = &fimc_pm_ops,
1296 1297 1298
	}
};

1299
int __init fimc_register_driver(void)
1300
{
1301
	return platform_driver_register(&fimc_driver);
1302 1303
}

1304
void __exit fimc_unregister_driver(void)
1305 1306 1307
{
	platform_driver_unregister(&fimc_driver);
}