subdev.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*
  2. * Copyright (c) 2021 Alibaba Group. All rights reserved.
  3. * License-Identifier: Apache-2.0
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  6. * not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #include <linux/string.h>
  19. #include "video.h"
  20. #include "video_ioctl.h"
  21. #include "subdev.h"
  22. #ifndef ARRAY_SIZE
  23. #define ARRAY_SIZE(arr) ( sizeof(arr) / sizeof((arr)[0]) )
  24. #endif
  25. static void dump_dts_frame_cfg(subdev_dts_frame_cfg_t *frame_cfg)
  26. {
  27. video_info(">>>> dump_dts_frame_cfg begin >>>>\n");
  28. video_info("\t idx = %u\n", frame_cfg->idx);
  29. video_info("\t name = %s\n", frame_cfg->output_name);
  30. video_info("\t max_width = %u\n", frame_cfg->max_width);
  31. video_info("\t max_height = %u\n", frame_cfg->max_height);
  32. video_info("\t bit_per_pixel = %d\n", frame_cfg->bit_per_pixel);
  33. video_info("\t frame_count = %u\n", frame_cfg->frame_count);
  34. video_info("<<<< dump_dts_frame_cfg end <<<<\n");
  35. }
  36. static void init_dts_frame_cfg(subdev_dts_frame_cfg_t *frame_cfg)
  37. {
  38. if (frame_cfg == NULL) {
  39. video_err("frame_cfg is NULL\n");
  40. return;
  41. }
  42. frame_cfg->idx = -1;
  43. frame_cfg->max_width = 0;
  44. frame_cfg->max_height = 0;
  45. frame_cfg->bit_per_pixel = 12;
  46. frame_cfg->frame_count = 2;
  47. strcpy(frame_cfg->output_name, "unknown");
  48. }
  49. static int subdev_get_dts_frame_cfg(struct fwnode_handle *node, subdev_dts_frame_cfg_t *frame_cfg)
  50. {
  51. if (frame_cfg == NULL) {
  52. video_err("frame_cfg is NULL\n");
  53. return -1;
  54. }
  55. fwnode_property_read_u32_array(node, "max_width", &frame_cfg->max_width, 1);
  56. fwnode_property_read_u32_array(node, "max_height", &frame_cfg->max_height, 1);
  57. fwnode_property_read_u32_array(node, "bit_per_pixel", &frame_cfg->bit_per_pixel, 1);
  58. fwnode_property_read_u32_array(node, "frame_count", &frame_cfg->frame_count, 1);
  59. return 0;
  60. }
  61. static int sensor_press_dts(struct fwnode_handle *node, sub_dev_info_t *subdev)
  62. {
  63. //int ret = 0;
  64. //const char *path;
  65. /*
  66. ret = fwnode_property_read_string(node, "path_type", &path);
  67. if (ret != 0) {
  68. video_err("sensor dts press error!!!!!, %s, %d\n", __func__, __LINE__);
  69. goto error;
  70. }
  71. */
  72. int ret = 0;
  73. uint32_t csi_idx, flash_led_idx, mode_idx;
  74. ret = fwnode_property_read_u32_array(node, "csi_idx", &csi_idx, 1);
  75. if(ret != 0) {
  76. return -1;
  77. }
  78. ret = fwnode_property_read_u32_array(node, "flash_led_idx", &flash_led_idx, 1);
  79. if(ret != 0) {
  80. flash_led_idx = -1;
  81. }
  82. ret = fwnode_property_read_u32_array(node, "mode_idx", &mode_idx, 1);
  83. if(ret != 0) {
  84. mode_idx = -1;
  85. }
  86. video_info("flash_led idx is %u\n", flash_led_idx);
  87. subdev->param[0] = (char)csi_idx;
  88. subdev->param[1] = fwnode_property_read_bool(node, "skip_init");
  89. subdev->param[2] = (char)flash_led_idx;
  90. subdev->param[3] = (char)mode_idx;
  91. video_info("subdev->param[0] is %d\n", subdev->param[0]);
  92. video_info("subdev->param[2] is %d\n", subdev->param[2]);
  93. video_info("subdev->param[3] is %d\n", subdev->param[3]);
  94. subdev->param_size = 3;
  95. return 0;
  96. }
  97. static int vipre_press_dts(struct fwnode_handle *node, sub_dev_info_t *subdev)
  98. {
  99. //int ret = 0;
  100. //const char *path;
  101. vipre_ipi_dts_arg_t param;
  102. param.dma_mode = 111;
  103. /*
  104. ret = fwnode_property_read_string(node, "path_type", &path);
  105. if (ret != 0) {
  106. video_err("sensor dts press error!!!!!, %s, %d\n", __func__, __LINE__);
  107. goto error;
  108. }
  109. */
  110. memcpy(subdev->param, &param, sizeof(vipre_ipi_dts_arg_t));
  111. subdev->param_size = sizeof(vipre_ipi_dts_arg_t);
  112. return 0;
  113. }
  114. static int isp_press_dts(struct fwnode_handle *node, sub_dev_info_t *subdev)
  115. {
  116. int ret = 0;
  117. int idx;
  118. const char *path;
  119. isp_dts_arg_t param;
  120. struct fwnode_handle *child;
  121. subdev_dts_frame_cfg_t *dts_frame_cfg = &(param.dts_path_frame_cfg);
  122. init_dts_frame_cfg(dts_frame_cfg);
  123. child = fwnode_get_named_child_node(node, "output");
  124. if (child == NULL) {
  125. subdev->param_size = 0;
  126. return 0; // return with all default values
  127. }
  128. ret = subdev_get_dts_frame_cfg(child, dts_frame_cfg);
  129. if (ret == 0) {
  130. fwnode_property_read_u32_array(node, "idx", &idx, 1);
  131. dts_frame_cfg->idx = idx;
  132. fwnode_property_read_string(node, "path_type", &path);
  133. snprintf(dts_frame_cfg->output_name, sizeof(dts_frame_cfg->output_name), "isp%d:%s", idx, path);
  134. dump_dts_frame_cfg(dts_frame_cfg);
  135. }
  136. else {
  137. video_err("%s, subdev_get_dts_frame_cfg() failed, ret=%d\n", __func__, ret);
  138. subdev->param_size = 0;
  139. return -1;
  140. }
  141. memcpy(subdev->param, &param, sizeof(subdev_dts_frame_cfg_t));
  142. subdev->param_size = sizeof(isp_dts_arg_t);
  143. return 0;
  144. }
  145. static int ry_press_dts(struct fwnode_handle *node, sub_dev_info_t *subdev)
  146. {
  147. int ret = 0;
  148. int idx;
  149. const char *path;
  150. ry_dts_arg_t param;
  151. struct fwnode_handle *child;
  152. subdev_dts_frame_cfg_t *dts_frame_cfg = &(param.dts_path_frame_cfg);
  153. init_dts_frame_cfg(dts_frame_cfg);
  154. child = fwnode_get_named_child_node(node, "output");
  155. if (child == NULL) {
  156. subdev->param_size = 0;
  157. return 0; // return with all default values
  158. }
  159. ret = subdev_get_dts_frame_cfg(child, dts_frame_cfg);
  160. if (ret == 0) {
  161. fwnode_property_read_u32_array(node, "idx", &idx, 1);
  162. dts_frame_cfg->idx = idx;
  163. fwnode_property_read_string(node, "path_type", &path);
  164. snprintf(dts_frame_cfg->output_name, sizeof(dts_frame_cfg->output_name), "ry%d:%s", idx, path);
  165. dump_dts_frame_cfg(dts_frame_cfg);
  166. }
  167. else {
  168. video_err("%s, subdev_get_dts_frame_cfg() failed, ret=%d\n", __func__, ret);
  169. subdev->param_size = 0;
  170. return -1;
  171. }
  172. memcpy(subdev->param, &param, sizeof(subdev_dts_frame_cfg_t));
  173. subdev->param_size = sizeof(ry_dts_arg_t);
  174. return 0;
  175. }
  176. static int dw_parse_dts(struct fwnode_handle *node, sub_dev_info_t *subdev)
  177. {
  178. int idx;
  179. const char *path;
  180. int dw_dst_depth;
  181. dw_dts_arg_t param;
  182. dw_dst_depth = 2; // init
  183. fwnode_property_read_u32_array(node, "idx", &idx, 1);
  184. fwnode_property_read_string(node, "path_type", &path);
  185. fwnode_property_read_u32_array(node, "dw_dst_depth", &dw_dst_depth, 1);
  186. param.dw_dst_depth = dw_dst_depth;
  187. video_info(">>>> dump dw_dts_arg_t begin >>>>\n");
  188. video_info("\t idx = %d\n", idx);
  189. video_info("\t path_type = %s\n", path);
  190. video_info("\t dw_dst_depth = %d\n", dw_dst_depth);
  191. video_info("<<<< dump dw_dts_arg_t end <<<<\n");
  192. memcpy(subdev->param, &param, sizeof(dw_dts_arg_t));
  193. subdev->param_size = sizeof(dw_dts_arg_t);
  194. return 0;
  195. }
  196. static int dsp_press_dts(struct fwnode_handle *node, sub_dev_info_t *subdev)
  197. {
  198. int ret = 0;
  199. int idx;
  200. const char *path;
  201. dsp_dts_arg_t param;
  202. struct fwnode_handle *child;
  203. subdev_dts_frame_cfg_t *dts_frame_cfg = &(param.dts_path_frame_cfg);
  204. init_dts_frame_cfg(dts_frame_cfg);
  205. child = fwnode_get_named_child_node(node, "output");
  206. if (child == NULL) {
  207. subdev->param_size = 0;
  208. return 0; // return with all default values
  209. }
  210. ret = subdev_get_dts_frame_cfg(child, dts_frame_cfg);
  211. if (ret == 0) {
  212. fwnode_property_read_u32_array(node, "idx", &idx, 1);
  213. dts_frame_cfg->idx = idx;
  214. fwnode_property_read_string(node, "path_type", &path);
  215. snprintf(dts_frame_cfg->output_name, sizeof(dts_frame_cfg->output_name), "dsp%d:%s", idx, path);
  216. dump_dts_frame_cfg(dts_frame_cfg);
  217. }
  218. else {
  219. video_err("%s, subdev_get_dts_frame_cfg() failed, ret=%d\n", __func__, ret);
  220. subdev->param_size = 0;
  221. return -1;
  222. }
  223. memcpy(subdev->param, &param, sizeof(dsp_dts_arg_t));
  224. subdev->param_size = sizeof(dsp_dts_arg_t);
  225. return 0;
  226. }
  227. static subdev_dts_press_t subdev_dts_press[] = {
  228. {.subdev_name = "vivcam", .press = sensor_press_dts},
  229. {.subdev_name = "vipre", .press = vipre_press_dts},
  230. {.subdev_name = "isp", .press = isp_press_dts},
  231. {.subdev_name = "ry", .press = ry_press_dts},
  232. {.subdev_name = "dw", .press = dw_parse_dts},
  233. {.subdev_name = "dsp", .press = dsp_press_dts},
  234. };
  235. int video_subdev_press_dts(struct fwnode_handle *node, sub_dev_info_t *subdev)
  236. {
  237. int i = 0;
  238. for (i = 0; i < sizeof(subdev_dts_press) / sizeof(subdev_dts_press[0]); i++) {
  239. if (strcmp(subdev_dts_press[i].subdev_name, subdev->name) == 0) {
  240. return subdev_dts_press[i].press(node, subdev);
  241. }
  242. }
  243. return -1;
  244. }