summaryrefslogtreecommitdiff
path: root/drivers/media/platform/exynos/fimc-is/fimc-is-video-companion.c
blob: a1ed1e65e877b9440fe286b278b737a6c60111c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
 * Samsung Exynos5 SoC series FIMC-IS driver
 *
 * exynos5 fimc-is video functions
 *
 * Copyright (c) 2014 Samsung Electronics Co., Ltd
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/module.h>
#include <linux/delay.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/interrupt.h>
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/videodev2.h>
#include <asm/cacheflush.h>
#include <asm/pgtable.h>
#include <linux/firmware.h>
#include <linux/dma-mapping.h>
#include <linux/scatterlist.h>
#include <linux/videodev2_exynos_camera.h>
#include <linux/v4l2-mediabus.h>
#include <linux/bug.h>

#include "fimc-is-device-companion.h"
#include "fimc-is-video.h"

const struct v4l2_file_operations fimc_is_comp_video_fops;
const struct v4l2_ioctl_ops fimc_is_comp_video_ioctl_ops;
const struct vb2_ops fimc_is_comp_qops;

int fimc_is_comp_video_probe(void *data)
{
	int ret = 0;
	char name[255];
	u32 number;
	struct fimc_is_device_companion *device;
	struct fimc_is_video *video;

	BUG_ON(!data);

	device = data;
	video = &device->video;
	snprintf(name, sizeof(name), "%s%d", FIMC_IS_VIDEO_SENSOR_NAME, 9);
	number = FIMC_IS_VIDEO_SS0_NUM + 9;

	if (!device->pdev) {
		err("pdev is NULL");
		ret = -EINVAL;
		goto p_err;
	}

	ret = fimc_is_video_probe(video,
		name,
		number,
		VFL_DIR_RX,
		&device->mem,
		&device->v4l2_dev,
		&video->lock,
		&fimc_is_comp_video_fops,
		&fimc_is_comp_video_ioctl_ops);
	if (ret)
		dev_err(&device->pdev->dev, "%s is fail(%d)\n", __func__, ret);

p_err:
	info("[CP%d:V:X] %s(%d)\n", number, __func__, ret);
	return ret;
}

extern int fimc_is_ois_sine_mode(struct fimc_is_core *core, int mode);

static int fimc_is_comp_video_s_ctrl(struct file *file, void *priv,
	struct v4l2_control *ctrl)
{
	int ret = 0;
	struct fimc_is_video *video;
	struct fimc_is_device_companion *device;

	dbg_isp("%s\n", __func__);

	video = video_drvdata(file);
	device = container_of(video, struct fimc_is_device_companion, video);

	if (!device->pdev) {
		err("pdev is NULL");
		ret = -EINVAL;
		goto p_err;
	}

	switch (ctrl->id) {
	case V4L2_CID_CAMERA_OIS_SINE_MODE:
		if (fimc_is_ois_sine_mode(device->private_data, ctrl->value)) {
			err("failed to set ois sine mode : %d\n - %d",
			ctrl->value, ret);
			ret = -EINVAL;
		}
		break;

	default:
		info("unsupported ioctl(%d, sine id = %d)\n", ctrl->id, V4L2_CID_CAMERA_OIS_SINE_MODE);
		ret = -EINVAL;
		break;
	}

p_err:
	return ret;
}

/*
 * =============================================================================
 * Video File Opertation
 * =============================================================================
 */

static int fimc_is_comp_video_open(struct file *file)
{
	int ret = 0;
	struct fimc_is_video *video;
	struct fimc_is_video_ctx *vctx;
	struct fimc_is_device_companion *device;
	struct platform_device *fimc_is_pdev;

	fimc_is_pdev = to_platform_device(fimc_is_dev);
	exynos_fimc_is_cfg_cam_clk(fimc_is_pdev);

	vctx = NULL;
	video = video_drvdata(file);
	device = container_of(video, struct fimc_is_device_companion, video);

	ret = open_vctx(file, video, &vctx, FRAMEMGR_ID_INVALID, FRAMEMGR_ID_INVALID);
	if (ret) {
		err("open_vctx is fail(%d)", ret);
		goto p_err;
	}

	info("[CP%d:V:%d] %s\n", video->id, vctx->instance, __func__);

	ret = fimc_is_companion_open(device);
	if (ret) {
		merr("fimc_is_comp_open is fail(%d)", vctx, ret);
		close_vctx(file, video, vctx);
		goto p_err;
	}

p_err:
	return ret;
}

static int fimc_is_comp_video_close(struct file *file)
{
	int ret = 0;
	struct fimc_is_video *video = NULL;
	struct fimc_is_video_ctx *vctx = NULL;
	struct fimc_is_device_companion *device = NULL;

	BUG_ON(!file);

	video = video_drvdata(file);
	device = container_of(video, struct fimc_is_device_companion, video);

	vctx = file->private_data;
	if (!vctx) {
		err("vctx is NULL");
		ret = -EINVAL;
		goto p_err;
	}

	info("[CP:V:%d] %s\n", vctx->instance, __func__);

	ret = fimc_is_companion_close(device);
	if (ret)
		err("fimc_is_companion_close is fail(%d)", ret);

	ret = close_vctx(file, video, vctx);
	if (ret)
		err("close_vctx is fail(%d)", ret);

p_err:
	return ret;
}

const struct v4l2_file_operations fimc_is_comp_video_fops = {
	.owner		= THIS_MODULE,
	.open		= fimc_is_comp_video_open,
	.release	= fimc_is_comp_video_close,
	.unlocked_ioctl	= video_ioctl2,
};

/*
 * =============================================================================
 * Video Ioctl Opertation
 * =============================================================================
 */

const struct v4l2_ioctl_ops fimc_is_comp_video_ioctl_ops = {
	.vidioc_s_ctrl			= fimc_is_comp_video_s_ctrl,
};

const struct vb2_ops fimc_is_comp_qops = {
};