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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
/* Copyright (c) 2017, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/media.h>
#include <media/v4l2-ioctl.h>
#include <linux/videodev2.h>
#include <media/v4l2-device.h>
#include <media/v4l2-ctrls.h>
#include <linux/platform_device.h>
#include <linux/of_platform.h>
#include <media/msm_ba.h>
#include "tvtuner.h"
#define DRIVER_NAME "tv-tuner"
struct Tvtuner_state {
struct device *dev;
/* V4L2 Data */
struct v4l2_subdev sd;
struct v4l2_ctrl_handler ctrl_hdl;
struct v4l2_dv_timings timings;
/* media entity controls */
struct media_pad pad;
struct mutex mutex;
};
/* Initialize Tvtuner I2C Settings */
static int Tvtuner_dev_init(struct Tvtuner_state *state)
{
int ret = 0;
TUNER_DEBUG("tv_tuner dev init is started\n");
return ret;
}
/* Initialize Tvtuner hardware */
static int Tvtuner_hw_init(struct Tvtuner_state *state)
{
int ret = 0;
TUNER_DEBUG("tv_tuner hw init is started\n");
return ret;
}
static int Tvtuner_s_ctrl(struct v4l2_ctrl *ctrl)
{
int ret = 0;
TUNER_DEBUG("tv_tuner set control is started id = 0x%x\n", ctrl->id);
return ret;
}
static int Tvtuner_get_fmt(struct v4l2_subdev *sd,
struct v4l2_subdev_pad_config *cfg,
struct v4l2_subdev_format *format)
{
int ret = 0;
struct v4l2_mbus_framefmt *fmt = &format->format;
fmt->code = MEDIA_BUS_FMT_UYVY8_2X8;
fmt->width = 1280;
fmt->height = 720;
fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
TUNER_DEBUG("tv_tuner get mbus format is started\n");
return ret;
}
static int Tvtuner_g_frame_interval(struct v4l2_subdev *sd,
struct v4l2_subdev_frame_interval *interval)
{
int ret = 0;
TUNER_DEBUG("tv_tuner get frame interval is started\n");
return ret;
}
static int Tvtuner_s_routing(struct v4l2_subdev *sd, u32 input,
u32 output, u32 config)
{
int ret = 0;
TUNER_DEBUG("tv_tuner s_routing is started\n");
return ret;
}
static int Tvtuner_query_dv_timings(struct v4l2_subdev *sd,
struct v4l2_dv_timings *timings)
{
int ret = 0;
TUNER_DEBUG("tv_tuner query dv timings is started\n");
return ret;
}
static int Tvtuner_query_sd_std(struct v4l2_subdev *sd, v4l2_std_id *std)
{
int ret = 0;
TUNER_DEBUG("tv_tuner query SD input is started\n");
return ret;
}
static int Tvtuner_g_input_status(struct v4l2_subdev *sd, u32 *status)
{
int ret = 0;
*status = 1;
TUNER_DEBUG("tv_tuner get input status is started\n");
return ret;
}
static int Tvtuner_s_stream(struct v4l2_subdev *sd, int on)
{
int ret = 0;
TUNER_DEBUG("tv_tuner start stream is started\n");
return ret;
}
static const struct v4l2_subdev_video_ops Tvtuner_video_ops = {
.s_routing = Tvtuner_s_routing,
.g_frame_interval = Tvtuner_g_frame_interval,
.querystd = Tvtuner_query_sd_std,
.g_dv_timings = Tvtuner_query_dv_timings,
.g_input_status = Tvtuner_g_input_status,
.s_stream = Tvtuner_s_stream,
};
static const struct v4l2_ctrl_ops Tvtuner_ctrl_ops = {
.s_ctrl = Tvtuner_s_ctrl,
};
static const struct v4l2_subdev_pad_ops Tvtuner_pad_ops = {
.get_fmt = Tvtuner_get_fmt,
};
static const struct v4l2_subdev_ops Tvtuner_ops = {
.video = &Tvtuner_video_ops,
.pad = &Tvtuner_pad_ops,
};
static int Tvtuner_init_v4l2_controls(struct Tvtuner_state *state)
{
int ret = 0;
TUNER_DEBUG("%s: Exit with ret: %d\n", __func__, ret);
return ret;
}
static int Tvtuner_parse_dt(struct platform_device *pdev,
struct Tvtuner_state *state)
{
int ret = 0;
TUNER_DEBUG("%s: tvtuner parse dt called\n", __func__);
return ret;
}
static const struct of_device_id Tvtuner_id[] = {
{ .compatible = "qcom,tv-tuner", },
{},
};
MODULE_DEVICE_TABLE(of, Tvtuner_id);
static int Tvtuner_probe(struct platform_device *pdev)
{
struct Tvtuner_state *state;
const struct of_device_id *device_id;
struct v4l2_subdev *sd;
int ret;
device_id = of_match_device(Tvtuner_id, &pdev->dev);
if (!device_id) {
TUNER_DEBUG("%s: device_id is NULL\n", __func__);
ret = -ENODEV;
goto err;
}
/* Create Tvtuner State */
state = devm_kzalloc(&pdev->dev,
sizeof(struct Tvtuner_state), GFP_KERNEL);
if (state == NULL) {
ret = -ENOMEM;
goto err;
}
platform_set_drvdata(pdev, state);
state->dev = &pdev->dev;
mutex_init(&state->mutex);
ret = Tvtuner_parse_dt(pdev, state);
if (ret < 0) {
TUNER_ERROR("Error parsing dt tree\n");
goto err_mem_free;
}
/* Configure and Register V4L2 Sub-device */
sd = &state->sd;
v4l2_subdev_init(sd, &Tvtuner_ops);
sd->owner = pdev->dev.driver->owner;
v4l2_set_subdevdata(sd, state);
strlcpy(sd->name, DRIVER_NAME, sizeof(sd->name));
state->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
state->sd.flags |= V4L2_SUBDEV_FL_HAS_EVENTS;
/* Register as Media Entity */
state->pad.flags = MEDIA_PAD_FL_SOURCE;
state->sd.entity.flags |= (unsigned long)MEDIA_ENT_T_V4L2_SUBDEV;
ret = media_entity_init(&state->sd.entity, 1, &state->pad, 0);
if (ret) {
ret = -EIO;
TUNER_ERROR("%s(%d): Media entity init failed\n",
__func__, __LINE__);
goto err_media_entity;
}
/* Initialize HW Config */
ret = Tvtuner_hw_init(state);
if (ret) {
ret = -EIO;
TUNER_ERROR("%s: HW Initialisation Failed\n", __func__);
goto err_media_entity;
}
ret = Tvtuner_init_v4l2_controls(state);
if (ret) {
TUNER_ERROR("%s: V4L2 Controls Initialisation Failed %d\n",
__func__, ret);
}
/* Initialize SW Init Settings and I2C sub maps */
ret = Tvtuner_dev_init(state);
if (ret) {
ret = -EIO;
TUNER_ERROR("%s(%d): SW Initialisation Failed\n",
__func__, __LINE__);
goto err_media_entity;
}
/* BA registration */
TUNER_DEBUG(" register msm-ba driver to tv_tuner");
ret = msm_ba_register_subdev_node(sd);
if (ret) {
ret = -EIO;
TUNER_DEBUG("%s: BA init failed\n", __func__);
goto err_media_entity;
}
TUNER_DEBUG("Probe of tvtuner successful!\n");
return ret;
err_media_entity:
media_entity_cleanup(&sd->entity);
err_mem_free:
devm_kfree(&pdev->dev, state);
err:
return ret;
}
static int Tvtuner_remove(struct platform_device *pdev)
{
struct Tvtuner_state *state = platform_get_drvdata(pdev);
msm_ba_unregister_subdev_node(&state->sd);
v4l2_device_unregister_subdev(&state->sd);
media_entity_cleanup(&state->sd.entity);
v4l2_ctrl_handler_free(&state->ctrl_hdl);
mutex_destroy(&state->mutex);
devm_kfree(&pdev->dev, state);
return 0;
}
static int Tvtuner_suspend(struct device *dev)
{
TUNER_DEBUG("tv_tuner driver is in suspend state\n");
return 0;
}
static int Tvtuner_resume(struct device *dev)
{
TUNER_DEBUG("tv_tuner driver is in resume state\n");
return 0;
}
static SIMPLE_DEV_PM_OPS(Tvtuner_pm_ops, Tvtuner_suspend, Tvtuner_resume);
#define TVTUNER_PM_OPS (&Tvtuner_pm_ops)
static struct platform_driver Tvtuner_driver = {
.driver = {
.owner = THIS_MODULE,
.name = "tv-tuner",
.of_match_table = Tvtuner_id,
.pm = TVTUNER_PM_OPS,
},
.probe = Tvtuner_probe,
.remove = Tvtuner_remove,
};
module_driver(Tvtuner_driver, platform_driver_register,
platform_driver_unregister);
MODULE_DESCRIPTION(" TV TUNER Test driver");
MODULE_LICENSE("GPL v2");
|