GNU Linux-libre 4.14.290-gnu1
[releases.git] / drivers / staging / media / atomisp / pci / atomisp2 / atomisp_tpg.c
1 /*
2  * Support for Medifield PNW Camera Imaging ISP subsystem.
3  *
4  * Copyright (c) 2010 Intel Corporation. All Rights Reserved.
5  *
6  * Copyright (c) 2010 Silicon Hive www.siliconhive.com.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License version
10  * 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301, USA.
21  *
22  */
23
24 #include <media/v4l2-event.h>
25 #include <media/v4l2-mediabus.h>
26 #include "atomisp_internal.h"
27 #include "atomisp_tpg.h"
28
29 static int tpg_s_stream(struct v4l2_subdev *sd, int enable)
30 {
31         return 0;
32 }
33
34 static int tpg_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *param)
35 {
36         /*to fake*/
37         return 0;
38 }
39
40 static int tpg_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *param)
41 {
42         /*to fake*/
43         return 0;
44 }
45
46 static int tpg_get_fmt(struct v4l2_subdev *sd,
47                        struct v4l2_subdev_pad_config *cfg,
48                        struct v4l2_subdev_format *format)
49 {
50         /*to fake*/
51         return 0;
52 }
53
54 static int tpg_set_fmt(struct v4l2_subdev *sd,
55                        struct v4l2_subdev_pad_config *cfg,
56                        struct v4l2_subdev_format *format)
57 {
58         struct v4l2_mbus_framefmt *fmt = &format->format;
59
60         if (format->pad)
61                 return -EINVAL;
62         /* only raw8 grbg is supported by TPG */
63         fmt->code = MEDIA_BUS_FMT_SGRBG8_1X8;
64         if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
65                 cfg->try_fmt = *fmt;
66                 return 0;
67         }
68         return 0;
69 }
70
71 static int tpg_log_status(struct v4l2_subdev *sd)
72 {
73         /*to fake*/
74         return 0;
75 }
76
77 static int tpg_s_power(struct v4l2_subdev *sd, int on)
78 {
79         return 0;
80 }
81
82 static int tpg_enum_mbus_code(struct v4l2_subdev *sd,
83                               struct v4l2_subdev_pad_config *cfg,
84                               struct v4l2_subdev_mbus_code_enum *code)
85 {
86         /*to fake*/
87         return 0;
88 }
89
90 static int tpg_enum_frame_size(struct v4l2_subdev *sd,
91                                struct v4l2_subdev_pad_config *cfg,
92                                struct v4l2_subdev_frame_size_enum *fse)
93 {
94         /*to fake*/
95         return 0;
96 }
97
98 static int tpg_enum_frame_ival(struct v4l2_subdev *sd,
99                                struct v4l2_subdev_pad_config *cfg,
100                                struct v4l2_subdev_frame_interval_enum *fie)
101 {
102         /*to fake*/
103         return 0;
104 }
105
106 static const struct v4l2_subdev_video_ops tpg_video_ops = {
107         .s_stream = tpg_s_stream,
108         .g_parm = tpg_g_parm,
109         .s_parm = tpg_s_parm,
110 };
111
112 static const struct v4l2_subdev_core_ops tpg_core_ops = {
113         .log_status = tpg_log_status,
114         .s_power = tpg_s_power,
115 };
116
117 static const struct v4l2_subdev_pad_ops tpg_pad_ops = {
118         .enum_mbus_code = tpg_enum_mbus_code,
119         .enum_frame_size = tpg_enum_frame_size,
120         .enum_frame_interval = tpg_enum_frame_ival,
121         .get_fmt = tpg_get_fmt,
122         .set_fmt = tpg_set_fmt,
123 };
124
125 static const struct v4l2_subdev_ops tpg_ops = {
126         .core = &tpg_core_ops,
127         .video = &tpg_video_ops,
128         .pad = &tpg_pad_ops,
129 };
130
131 void atomisp_tpg_unregister_entities(struct atomisp_tpg_device *tpg)
132 {
133         media_entity_cleanup(&tpg->sd.entity);
134         v4l2_device_unregister_subdev(&tpg->sd);
135 }
136
137 int atomisp_tpg_register_entities(struct atomisp_tpg_device *tpg,
138                         struct v4l2_device *vdev)
139 {
140         int ret;
141         /* Register the subdev and video nodes. */
142         ret = v4l2_device_register_subdev(vdev, &tpg->sd);
143         if (ret < 0)
144                 goto error;
145
146         return 0;
147
148 error:
149         atomisp_tpg_unregister_entities(tpg);
150         return ret;
151 }
152
153 void atomisp_tpg_cleanup(struct atomisp_device *isp)
154 {
155
156 }
157
158 int atomisp_tpg_init(struct atomisp_device *isp)
159 {
160         struct atomisp_tpg_device *tpg = &isp->tpg;
161         struct v4l2_subdev *sd = &tpg->sd;
162         struct media_pad *pads = tpg->pads;
163         struct media_entity *me = &sd->entity;
164         int ret;
165
166         tpg->isp = isp;
167         v4l2_subdev_init(sd, &tpg_ops);
168         sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
169         strcpy(sd->name, "tpg_subdev");
170         v4l2_set_subdevdata(sd, tpg);
171
172         pads[0].flags = MEDIA_PAD_FL_SINK;
173         me->function = MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN;
174
175         ret = media_entity_pads_init(me, 1, pads);
176         if (ret < 0)
177                 goto fail;
178         return 0;
179 fail:
180         atomisp_tpg_cleanup(isp);
181         return ret;
182 }