2 *************************************************************************
3 * Rockchip driver for CIF ISP 1.0
4 * (Based on Intel driver for sofiaxxx)
6 * Copyright (C) 2015 Intel Mobile Communications GmbH
7 * Copyright (C) 2016 Fuzhou Rockchip Electronics Co., Ltd.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *************************************************************************
17 #include <linux/kernel.h>
18 #include <linux/platform_data/rk_isp10_platform.h>
19 #include "cif_isp10.h"
20 #include "cif_isp10_img_src_ops.h"
22 struct cif_isp10_img_src {
24 const struct cif_isp10_img_src_ops *ops;
27 struct cif_isp10_img_src *cif_isp10_img_src_to_img_src(
28 CIF_ISP10_PLTFRM_DEVICE dev,
29 struct pltfrm_soc_cfg *soc_cfg)
33 const char *device_type;
34 struct cif_isp10_img_src *img_src;
36 img_src = devm_kzalloc(dev, sizeof(*img_src), GFP_KERNEL);
42 device_type = cif_isp10_pltfrm_get_device_type(dev);
45 for (i = 0; i < ARRAY_SIZE(cif_isp10_img_src_ops); i++) {
46 if (!strcmp(device_type, cif_isp10_img_src_ops->device_type)) {
47 img_src->ops = &cif_isp10_img_src_ops[i].ops;
52 cif_isp10_pltfrm_pr_err(NULL,
53 "unsupported device type %s\n",
59 WARN_ON(!img_src->ops->to_img_src);
60 WARN_ON(!img_src->ops->s_streaming);
61 WARN_ON(!img_src->ops->s_power);
62 WARN_ON(!img_src->ops->enum_strm_fmts);
63 WARN_ON(!img_src->ops->s_strm_fmt);
64 WARN_ON(!img_src->ops->g_ctrl);
65 WARN_ON(!img_src->ops->s_ctrl);
67 img_src->img_src = img_src->ops->to_img_src(dev, soc_cfg);
68 if (IS_ERR_OR_NULL(img_src->img_src)) {
69 cif_isp10_pltfrm_pr_err(NULL,
70 "to_img_src failed!\n");
77 cif_isp10_pltfrm_pr_err(NULL, "failed with error %d\n",
79 if (!IS_ERR_OR_NULL(img_src))
80 devm_kfree(dev, img_src);
85 int cif_isp10_img_src_s_streaming(
86 struct cif_isp10_img_src *img_src,
89 return img_src->ops->s_streaming(img_src->img_src, enable);
92 int cif_isp10_img_src_s_power(
93 struct cif_isp10_img_src *img_src,
96 return img_src->ops->s_power(img_src->img_src, on);
99 int cif_isp10_img_src_enum_strm_fmts(
100 struct cif_isp10_img_src *img_src,
102 struct cif_isp10_strm_fmt_desc *strm_fmt_desc)
104 return img_src->ops->enum_strm_fmts(img_src->img_src,
105 index, strm_fmt_desc);
108 int cif_isp10_img_src_s_strm_fmt(
109 struct cif_isp10_img_src *img_src,
110 struct cif_isp10_strm_fmt *strm_fmt)
113 cif_isp10_pltfrm_pr_err(NULL, "img_src is NULL\n");
116 return img_src->ops->s_strm_fmt(img_src->img_src, strm_fmt);
119 int cif_isp10_img_src_g_ctrl(
120 struct cif_isp10_img_src *img_src,
125 cif_isp10_pltfrm_pr_err(NULL, "img_src is NULL\n");
128 return img_src->ops->g_ctrl(img_src->img_src, id, val);
131 int cif_isp10_img_src_s_ctrl(
132 struct cif_isp10_img_src *img_src,
137 cif_isp10_pltfrm_pr_err(NULL, "img_src is NULL\n");
140 return img_src->ops->s_ctrl(img_src->img_src, id, val);
143 int cif_isp10_img_src_s_ext_ctrls(
144 struct cif_isp10_img_src *img_src,
145 struct cif_isp10_img_src_ext_ctrl *ctrl)
148 cif_isp10_pltfrm_pr_err(NULL, "img_src is NULL\n");
151 return img_src->ops->s_ext_ctrls(img_src->img_src, ctrl);
154 long cif_isp10_img_src_ioctl(
155 struct cif_isp10_img_src *img_src,
160 cif_isp10_pltfrm_pr_err(NULL, "img_src is NULL\n");
163 return img_src->ops->ioctl(img_src->img_src, cmd, arg);
166 const char *cif_isp10_img_src_g_name(
167 struct cif_isp10_img_src *img_src)
170 cif_isp10_pltfrm_pr_err(NULL, "img_src is NULL\n");
171 return ERR_PTR(-EINVAL);
173 return img_src->ops->g_name(img_src->img_src);