hc
2023-11-22 f743a7adbd6e230d66a6206fa115b59fec2d88eb
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
/*
 *************************************************************************
 * Rockchip driver for CIF ISP 1.0
 * (Based on Intel driver for sofiaxxx)
 *
 * Copyright (C) 2015 Intel Mobile Communications GmbH
 * Copyright (C) 2016 Fuzhou Rockchip 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 as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *************************************************************************
 */
 
#include <linux/kernel.h>
#include <linux/platform_data/rk_isp10_platform.h>
#include "cif_isp10.h"
#include "cif_isp10_img_src_ops.h"
 
struct cif_isp10_img_src {
   void *img_src;
   const struct cif_isp10_img_src_ops *ops;
};
 
struct cif_isp10_img_src *cif_isp10_img_src_to_img_src(
   CIF_ISP10_PLTFRM_DEVICE dev,
   struct pltfrm_soc_cfg *soc_cfg)
{
   int ret = 0;
   int i;
   const char *device_type;
   struct cif_isp10_img_src *img_src;
 
   img_src = devm_kzalloc(dev, sizeof(*img_src), GFP_KERNEL);
   if (!img_src) {
       ret = -ENOMEM;
       goto err;
   }
 
   device_type = cif_isp10_pltfrm_get_device_type(dev);
 
   img_src->ops = NULL;
   for (i = 0; i < ARRAY_SIZE(cif_isp10_img_src_ops); i++) {
       if (!strcmp(device_type, cif_isp10_img_src_ops->device_type)) {
           img_src->ops = &cif_isp10_img_src_ops[i].ops;
           break;
       }
   }
   if (!img_src->ops) {
       cif_isp10_pltfrm_pr_err(NULL,
           "unsupported device type %s\n",
           device_type);
       ret = -EINVAL;
       goto err;
   }
 
   WARN_ON(!img_src->ops->to_img_src);
   WARN_ON(!img_src->ops->s_streaming);
   WARN_ON(!img_src->ops->s_power);
   WARN_ON(!img_src->ops->enum_strm_fmts);
   WARN_ON(!img_src->ops->s_strm_fmt);
   WARN_ON(!img_src->ops->g_ctrl);
   WARN_ON(!img_src->ops->s_ctrl);
 
   img_src->img_src = img_src->ops->to_img_src(dev, soc_cfg);
   if (IS_ERR_OR_NULL(img_src->img_src)) {
       cif_isp10_pltfrm_pr_err(NULL,
           "to_img_src failed!\n");
       ret = -EFAULT;
       goto err;
   }
 
   return img_src;
err:
   cif_isp10_pltfrm_pr_err(NULL, "failed with error %d\n",
       ret);
   if (!IS_ERR_OR_NULL(img_src))
       devm_kfree(dev, img_src);
 
   return ERR_PTR(ret);
}
 
int cif_isp10_img_src_s_streaming(
   struct cif_isp10_img_src *img_src,
   bool enable)
{
   return img_src->ops->s_streaming(img_src->img_src, enable);
}
 
int cif_isp10_img_src_s_power(
   struct cif_isp10_img_src *img_src,
   bool on)
{
   return img_src->ops->s_power(img_src->img_src, on);
}
 
int cif_isp10_img_src_enum_strm_fmts(
   struct cif_isp10_img_src *img_src,
   u32 index,
   struct cif_isp10_strm_fmt_desc *strm_fmt_desc)
{
   return img_src->ops->enum_strm_fmts(img_src->img_src,
       index, strm_fmt_desc);
}
 
int cif_isp10_img_src_s_strm_fmt(
   struct cif_isp10_img_src *img_src,
   struct cif_isp10_strm_fmt *strm_fmt)
{
   if (!img_src) {
       cif_isp10_pltfrm_pr_err(NULL, "img_src is NULL\n");
       return -EINVAL;
   }
   return img_src->ops->s_strm_fmt(img_src->img_src, strm_fmt);
}
 
int cif_isp10_img_src_g_ctrl(
   struct cif_isp10_img_src *img_src,
   int id,
   int *val)
{
   if (!img_src) {
       cif_isp10_pltfrm_pr_err(NULL, "img_src is NULL\n");
       return -EINVAL;
   }
   return img_src->ops->g_ctrl(img_src->img_src, id, val);
}
 
int cif_isp10_img_src_s_ctrl(
   struct cif_isp10_img_src *img_src,
   int id,
   int val)
{
   if (!img_src) {
       cif_isp10_pltfrm_pr_err(NULL, "img_src is NULL\n");
       return -EINVAL;
   }
   return img_src->ops->s_ctrl(img_src->img_src, id, val);
}
 
int cif_isp10_img_src_s_ext_ctrls(
   struct cif_isp10_img_src *img_src,
   struct cif_isp10_img_src_ext_ctrl *ctrl)
{
   if (!img_src) {
       cif_isp10_pltfrm_pr_err(NULL, "img_src is NULL\n");
       return -EINVAL;
   }
   return img_src->ops->s_ext_ctrls(img_src->img_src, ctrl);
}
 
long cif_isp10_img_src_ioctl(
   struct cif_isp10_img_src *img_src,
   unsigned int cmd,
   void *arg)
{
   if (!img_src) {
       cif_isp10_pltfrm_pr_err(NULL, "img_src is NULL\n");
       return -EINVAL;
   }
   return img_src->ops->ioctl(img_src->img_src, cmd, arg);
}
 
const char *cif_isp10_img_src_g_name(
   struct cif_isp10_img_src *img_src)
{
   if (!img_src) {
       cif_isp10_pltfrm_pr_err(NULL, "img_src is NULL\n");
       return ERR_PTR(-EINVAL);
   }
   return img_src->ops->g_name(img_src->img_src);
}
 
void *cif_isp10_img_src_g_img_src(
   struct cif_isp10_img_src *img_src)
{
   if (img_src) {
       return img_src->img_src;
   }
 
   return NULL;
}
 
int cif_isp10_img_src_s_frame_interval(
       struct cif_isp10_img_src *img_src,
       struct cif_isp10_frm_intrvl *frm_intrvl)
{
   if (img_src)
       return img_src->ops->s_frame_interval(
           img_src->img_src,
           frm_intrvl);
   return -EINVAL;
}
 
int cif_isp10_img_src_g_frame_interval(
       struct cif_isp10_img_src *img_src,
       struct cif_isp10_frm_intrvl *frm_intrvl)
{
   if (img_src)
       return img_src->ops->g_frame_interval(
           img_src->img_src,
           frm_intrvl);
   return -EINVAL;
}
 
int cif_isp10_img_src_enum_frame_size(
   struct cif_isp10_img_src *img_src,
   void *fse)
{
   if (img_src)
       return img_src->ops->enum_frame_size(
           img_src->img_src,
           fse);
   return -EINVAL;
}