summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBhanu Murthy V <bmurthyv@nvidia.com>2018-11-09 16:37:13 -0500
committermobile promotions <svcmobile_promotions@nvidia.com>2019-02-01 02:27:58 -0500
commitd67df23b0aa8740daee98386b6fe09ce0afc4ea5 (patch)
tree72a12b29f48e58bd44d7a39055d33a48c7bb3fd9
parent3ef8b6a33d67d6a7e2d10ed0eede148d88c01152 (diff)
drivers: camera: Add sensor blob utilities
Add utilities for sensor blob creation and writing in CCPLEX. The blob creation will be common across platorms for sensor drivers. Blob writing in CCPLEX will be used based on the RCE support on the platform. Add version in camera common and tvcf supported apis to evaluate and verify blob support in sensor drivers. Bug 2433156 Change-Id: Ie395be7d4ad959ae0efab9e72d1373fa7bd39d27 Signed-off-by: Bhanu Murthy V <bmurthyv@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1941462 (cherry picked from commit 187cb4926fbe68e653ba6e372b291da04605c946) Reviewed-on: https://git-master.nvidia.com/r/2006762 Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com> Tested-by: Ian Kaszubski <ikaszubski@nvidia.com> Reviewed-by: Vincent Chung <vincentc@nvidia.com> GVS: Gerrit_Virtual_Submit Reviewed-by: Frank Chen <frankc@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
-rw-r--r--drivers/media/platform/tegra/camera/Makefile2
-rw-r--r--drivers/media/platform/tegra/camera/tegracam_core.c3
-rw-r--r--drivers/media/platform/tegra/camera/tegracam_utils.c212
-rw-r--r--include/media/camera_common.h1
-rw-r--r--include/media/tegracam_utils.h48
5 files changed, 264 insertions, 2 deletions
diff --git a/drivers/media/platform/tegra/camera/Makefile b/drivers/media/platform/tegra/camera/Makefile
index 8072676a8..a67a6a0cc 100644
--- a/drivers/media/platform/tegra/camera/Makefile
+++ b/drivers/media/platform/tegra/camera/Makefile
@@ -8,7 +8,7 @@ ccflags-y += -Werror
8obj-y += vi/ 8obj-y += vi/
9obj-y += csi/ 9obj-y += csi/
10obj-y += camera_common.o camera_gpio.o sensor_common.o camera_version_utils.o \ 10obj-y += camera_common.o camera_gpio.o sensor_common.o camera_version_utils.o \
11 tegracam_ctrls.o tegracam_core.o tegracam_v4l2.o 11 tegracam_ctrls.o tegracam_core.o tegracam_v4l2.o tegracam_utils.o
12obj-$(CONFIG_TEGRA_CAMERA_RTCPU) += capture_common.o 12obj-$(CONFIG_TEGRA_CAMERA_RTCPU) += capture_common.o
13obj-$(CONFIG_TEGRA_CAMERA_RTCPU) += isp/isp_channel.o 13obj-$(CONFIG_TEGRA_CAMERA_RTCPU) += isp/isp_channel.o
14obj-$(CONFIG_TEGRA_CAMERA_RTCPU) += isp/capture_isp.o 14obj-$(CONFIG_TEGRA_CAMERA_RTCPU) += isp/capture_isp.o
diff --git a/drivers/media/platform/tegra/camera/tegracam_core.c b/drivers/media/platform/tegra/camera/tegracam_core.c
index 5a17322ff..9df1c3ea4 100644
--- a/drivers/media/platform/tegra/camera/tegracam_core.c
+++ b/drivers/media/platform/tegra/camera/tegracam_core.c
@@ -22,7 +22,7 @@
22/* use semantic versioning convention */ 22/* use semantic versioning convention */
23#define TEGRACAM_MAJOR_VERSION 2 23#define TEGRACAM_MAJOR_VERSION 2
24#define TEGRACAM_MINOR_VERSION 0 24#define TEGRACAM_MINOR_VERSION 0
25#define TEGRACAM_PATCH_VERSION 1 25#define TEGRACAM_PATCH_VERSION 2
26 26
27u32 tegracam_version(u8 major, u8 minor, u8 patch) 27u32 tegracam_version(u8 major, u8 minor, u8 patch)
28{ 28{
@@ -133,6 +133,7 @@ int tegracam_device_register(struct tegracam_device *tc_dev)
133 /* add version info to identify the right feature set */ 133 /* add version info to identify the right feature set */
134 tc_dev->version = tegracam_version(TEGRACAM_MAJOR_VERSION, 134 tc_dev->version = tegracam_version(TEGRACAM_MAJOR_VERSION,
135 TEGRACAM_MINOR_VERSION, TEGRACAM_PATCH_VERSION); 135 TEGRACAM_MINOR_VERSION, TEGRACAM_PATCH_VERSION);
136 s_data->version = tc_dev->version;
136 dev_info(dev, "tegracam sensor driver:%s_v%d.%d.%d\n", 137 dev_info(dev, "tegracam sensor driver:%s_v%d.%d.%d\n",
137 tc_dev->name, TEGRACAM_MAJOR_VERSION, 138 tc_dev->name, TEGRACAM_MAJOR_VERSION,
138 TEGRACAM_MINOR_VERSION, TEGRACAM_PATCH_VERSION); 139 TEGRACAM_MINOR_VERSION, TEGRACAM_PATCH_VERSION);
diff --git a/drivers/media/platform/tegra/camera/tegracam_utils.c b/drivers/media/platform/tegra/camera/tegracam_utils.c
new file mode 100644
index 000000000..1339addcc
--- /dev/null
+++ b/drivers/media/platform/tegra/camera/tegracam_utils.c
@@ -0,0 +1,212 @@
1/*
2 * tegracam_utils - tegra camera framework utilities
3 *
4 * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <linux/types.h>
20#include <linux/regmap.h>
21#include <media/tegracam_core.h>
22#include <media/tegracam_utils.h>
23
24bool is_tvcf_supported(u32 version)
25{
26 /* 2.0.0 is the base tvcf version sensor driver*/
27 return (version >= tegracam_version(2, 0, 0) ? true : false);
28}
29EXPORT_SYMBOL_GPL(is_tvcf_supported);
30
31void conv_u32_u8arr(u32 input, u8 *output)
32{
33 output[0] = (input >> 24) & 0xFF;
34 output[1] = (input >> 16) & 0xFF;
35 output[2] = (input >> 8) & 0xFF;
36 output[3] = input & 0xFF;
37}
38EXPORT_SYMBOL_GPL(conv_u32_u8arr);
39
40void conv_u16_u8arr(u16 input, u8 *output)
41{
42 output[0] = (input >> 8) & 0xFF;
43 output[1] = input & 0xFF;
44}
45EXPORT_SYMBOL_GPL(conv_u16_u8arr);
46
47static inline int is_valid_blob(struct sensor_blob *blob, u32 size)
48{
49 if (!blob)
50 return -EINVAL;
51
52 if ((blob->num_cmds >= MAX_COMMANDS) ||
53 ((blob->buf_size + size) >= MAX_BLOB_SIZE))
54 return -ENOMEM;
55
56 return 0;
57}
58
59int prepare_write_cmd(struct sensor_blob *blob,
60 u32 size, u32 addr, u8 *buf)
61{
62 struct sensor_cmd *cmd = NULL;
63 int err = 0;
64
65 err = is_valid_blob(blob, size);
66 if (err)
67 return err;
68
69 cmd = &blob->cmds[blob->num_cmds++];
70 cmd->opcode = ((SENSOR_OPCODE_WRITE << 24) | size);
71 cmd->addr = addr;
72
73 memcpy(&blob->buf[blob->buf_size], buf, size);
74
75 blob->buf_size += size;
76
77 return 0;
78}
79EXPORT_SYMBOL_GPL(prepare_write_cmd);
80
81int prepare_read_cmd(struct sensor_blob *blob,
82 u32 size, u32 addr)
83{
84 struct sensor_cmd *cmd = NULL;
85 int err = 0;
86
87 err = is_valid_blob(blob, size);
88 if (err)
89 return err;
90
91 cmd = &blob->cmds[blob->num_cmds++];
92 cmd->opcode = ((SENSOR_OPCODE_READ << 24) | size);
93 cmd->addr = addr;
94
95 blob->buf_size += size;
96
97 return 0;
98}
99EXPORT_SYMBOL_GPL(prepare_read_cmd);
100
101int prepare_sleep_cmd(struct sensor_blob *blob, u32 time_in_us)
102{
103 struct sensor_cmd *cmd = NULL;
104 int err = 0;
105
106 err = is_valid_blob(blob, 0);
107 if (err)
108 return err;
109
110 cmd = &blob->cmds[blob->num_cmds++];
111 cmd->opcode = (SENSOR_OPCODE_SLEEP << 24) | time_in_us;
112
113 return 0;
114}
115EXPORT_SYMBOL_GPL(prepare_sleep_cmd);
116
117int prepare_done_cmd(struct sensor_blob *blob)
118{
119 struct sensor_cmd *cmd = NULL;
120 int err = 0;
121
122 err = is_valid_blob(blob, 0);
123 if (err)
124 return err;
125
126 cmd = &blob->cmds[blob->num_cmds++];
127 cmd->opcode = SENSOR_OPCODE_DONE;
128
129 return 0;
130}
131EXPORT_SYMBOL_GPL(prepare_done_cmd);
132
133int convert_table_to_blob(struct sensor_blob *blob,
134 const struct reg_8 table[],
135 u16 wait_ms_addr, u16 end_addr)
136{
137 const struct reg_8 *next;
138 u16 addr;
139 u8 val;
140 int range_start = -1;
141 int range_count = 0;
142 u8 buf[16];
143
144 for (next = table;; next++) {