• RK3588camera: AHD摄像头转MIPI转接芯片调试


    我们常见的摄像头接口一般有MIPI、USB、DVP等等,但是MIPI摄像头受限于高速信号的传输距离问题,导致走线不能太长,这样在安防监控领域、车载等领域,使用就很受限,因此会引入一些技术延长摄像头的数据传输距离,例如之前文章所提到的serdes,本文主要介绍一下AHD摄像头对接RK3588的调试。

    目录

    (1)AHD摄像头

    (2)转接芯片

    (3)AHD转MIPI调试

    ①nvp6188_g_mbus_config接口

    ②bus fmt配置

    ③DTS配置

    (4)AHD转BT1120

    ①驱动nvp6158_g_mbus_config配置

    ②nvp6158_querystd接口配置

    ③DTS配置

    ④pinctrl的配置

    (5)APK预览

    (6)抓图指令调试


    (1)AHD摄像头

    网上有很多关于AHD摄像头的介绍,这里不再赘述,这里提一下,AHD摄像头跟我前文介绍的serdes有一点类似,有一个目的是提高了传输的距离。常用于车载、安防等领域。

    AHD是模拟摄像头,因此需要AD转换芯片来转换,输出数字信号给到主控进行接收。

    (2)转接芯片

    上述AHD摄像头需要转接芯片转成数字信号输出,一般是AHD转MIPI或者AHD转BT656/BT1120并口输出。前级摄像头有的厂家也会兼容TVI、CVBS等信号。

    CVBS可以参考前一篇文章的介绍。

    这篇文章主要给大家分享一下,AHD摄像头转MIPI或者BT1120转接芯片的调试。

    常见的转接芯片有:NVP系列的NVP6188/NVP6324/NVP6158C

    TP系列的:TP2815/TP9950/TP9930/TP2825等

    RN系列的:RN6854/RN6752等等

    这里我们以介绍调试N6为例。

    (3)AHD转MIPI调试

    同样的转接芯片的驱动也是基于V4l2框架的,因为主要介绍一下相关接口的配置即可。

    ①nvp6188_g_mbus_config接口

    该接口配置主要配置了MIPI接口,4lane模式,以及4路虚拟通道的类型。如果需要接多路摄像头的话,需要配置这个。

    1. static int nvp6188_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad_id,
    2. struct v4l2_mbus_config *cfg)
    3. {
    4. cfg->type = V4L2_MBUS_CSI2_DPHY;
    5. cfg->flags = V4L2_MBUS_CSI2_4_LANE |
    6. V4L2_MBUS_CSI2_CHANNELS;
    7. return 0;
    8. }

    ②bus fmt配置

    图像格式一般都是YUV422的类型。配置如下:

    .bus_fmt = MEDIA_BUS_FMT_UYVY8_2X8,
    

    其他的配置其他文章也都有描述,这里不再赘述。

    ③DTS配置

    dts配置基本与camera配置相差无几,这里直接贴一下:

    1. &csi2_dphy0_hw {
    2. status = "okay";
    3. };
    4. &csi2_dphy0 {
    5. status = "okay";
    6. ports {
    7. #address-cells = <1>;
    8. #size-cells = <0>;
    9. port@0 {
    10. reg = <0>;
    11. #address-cells = <1>;
    12. #size-cells = <0>;
    13. mipi_dphy0_in_nvp6188: endpoint@1 {
    14. reg = <1>;
    15. remote-endpoint = <&nvp6188_out>;
    16. data-lanes = <1 2 3 4>;
    17. };
    18. };
    19. port@1 {
    20. reg = <1>;
    21. #address-cells = <1>;
    22. #size-cells = <0>;
    23. csidphy0_out: endpoint@0 {
    24. reg = <0>;
    25. remote-endpoint = <&mipi2_csi2_input>;
    26. };
    27. };
    28. };
    29. };
    30. &i2c7 {
    31. status = "okay";
    32. nvp6188: nvp6188@31 {
    33. compatible = "nvp6188";
    34. status = "okay";
    35. reg = <0x31>;
    36. clocks = <&cru CLK_MIPI_CAMARAOUT_M2>;
    37. clock-names = "xvclk";
    38. power-domains = <&power RK3588_PD_VI>;
    39. pinctrl-names = "default";
    40. pinctrl-0 = <&mipim1_camera1_clk>;
    41. rockchip,grf = <&sys_grf>;
    42. /*power-gpios = <&gpio3 RK_PC6 GPIO_ACTIVE_HIGH>;*/
    43. reset-gpios = <&gpio3 RK_PB3 GPIO_ACTIVE_HIGH>;
    44. rockchip,camera-module-index = <0>;
    45. rockchip,camera-module-facing = "back";
    46. rockchip,camera-module-name = "nvp6188";
    47. rockchip,camera-module-lens-name = "nvp6188";
    48. port {
    49. nvp6188_out: endpoint {
    50. remote-endpoint = <&mipi_dphy0_in_nvp6188>;
    51. data-lanes = <1 2 3 4>;
    52. };
    53. };
    54. };
    55. };
    56. &mipi2_csi2 {
    57. status = "okay";
    58. ports {
    59. #address-cells = <1>;
    60. #size-cells = <0>;
    61. port@0 {
    62. reg = <0>;
    63. #address-cells = <1>;
    64. #size-cells = <0>;
    65. mipi2_csi2_input: endpoint@1 {
    66. reg = <1>;
    67. remote-endpoint = <&csidphy0_out>;
    68. };
    69. };
    70. port@1 {
    71. reg = <1>;
    72. #address-cells = <1>;
    73. #size-cells = <0>;
    74. mipi2_csi2_output: endpoint@0 {
    75. reg = <0>;
    76. remote-endpoint = <&cif_mipi2_in>;
    77. };
    78. };
    79. };
    80. };
    81. &rkcif_mipi_lvds2 {
    82. status = "okay";
    83. /* parameters for do cif reset detecting:
    84. * index0: monitor mode,
    85. 0 for idle,
    86. 1 for continue,
    87. 2 for trigger,
    88. 3 for hotplug (for nextchip)
    89. * index1: the frame id to start timer,
    90. min is 2
    91. * index2: frame num of monitoring cycle
    92. * index3: err time for keep monitoring
    93. after finding out err (ms)
    94. * index4: csi2 err reference val for resetting
    95. */
    96. rockchip,cif-monitor = <3 2 1 1000 5>;
    97. port {
    98. cif_mipi2_in: endpoint {
    99. remote-endpoint = <&mipi2_csi2_output>;
    100. };
    101. };
    102. };
    103. &rkcif {
    104. status = "okay";
    105. rockchip,android-usb-camerahal-enable;
    106. // memory-region = <&cif_reserved>;
    107. };
    108. &rkcif_mmu {
    109. status = "okay";
    110. };

    需要注意的只有rockchip,android-usb-camerahal-enable;这个配置,该配置是在多路摄像头的时候使用,可以让应用注册4路摄像头,从而apk可以同时预览4路。如果是自行开发应用,使用v4l2从video节点直接取数据流的话,那么可以不用。

    (4)AHD转BT1120

    AHD 转BT1120的调试,这里介绍一下NVP6158C的调试

    ①驱动nvp6158_g_mbus_config配置

    这个配置与MIPI的配置略有不同,需要注意区分,其中极性一定需要配置。

    1. static int nvp6158_g_mbus_config(struct v4l2_subdev *sd, unsigned int pad,
    2. struct v4l2_mbus_config *cfg)
    3. {
    4. struct nvp6158 *nvp6158 = to_nvp6158(sd);
    5. cfg->type = V4L2_MBUS_BT656;
    6. if (nvp6158->dual_edge == 1) {
    7. cfg->flags = RKMODULE_CAMERA_BT656_CHANNELS |
    8. V4L2_MBUS_PCLK_SAMPLE_RISING |
    9. V4L2_MBUS_PCLK_SAMPLE_FALLING;
    10. } else {
    11. cfg->flags = RKMODULE_CAMERA_BT656_CHANNELS |
    12. V4L2_MBUS_PCLK_SAMPLE_RISING;
    13. }
    14. return 0;
    15. }

    ②nvp6158_querystd接口配置

    该接口一定需要配置,其中BT1120需要声明为V4L2_STD_ATSC

    1. static int nvp6158_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
    2. {
    3. struct nvp6158 *nvp6158 = to_nvp6158(sd);
    4. if ((nvp6158->mode > BT656I_TEST_MODES) &&
    5. (nvp6158->mode < NVP6158_DVP_MODES_END)) {
    6. /* for vicap detect bt1120 */
    7. *std = V4L2_STD_ATSC;
    8. } else {
    9. *std = V4L2_STD_PAL;
    10. }
    11. return 0;
    12. }

    ③DTS配置

    dts配置参考如下:

    1. &i2c2 {
    2. status = "okay";
    3. pinctrl-names = "default";
    4. pinctrl-0 = <&i2c2m4_xfer>;
    5. nvp6158: nvp6158@30 {
    6. compatible = "nvp6158-v4l2";
    7. status = "okay";
    8. reg = <0x30>;
    9. clocks = <&cru CLK_CIFOUT_OUT>;
    10. clock-names = "xvclk";
    11. power-domains = <&power RK3588_PD_VI>;
    12. pinctrl-names = "default";
    13. pinctrl-0 = <&cif_clk &cif_dvp_clk &cif_dvp_bus8 &cif_dvp_bus16>;
    14. // pwr-gpios = <&gpio1 RK_PA6 GPIO_ACTIVE_HIGH>;
    15. pwr2-gpios = <&gpio1 RK_PA5 GPIO_ACTIVE_HIGH>;
    16. rst-gpios = <&gpio1 RK_PA3 GPIO_ACTIVE_HIGH>;
    17. // rst2-gpios = <&gpio3 RK_PC1 GPIO_ACTIVE_HIGH>;
    18. // pwdn-gpios = <&gpio1 RK_PA4 GPIO_ACTIVE_HIGH>;
    19. // pwdn2-gpios = <&gpio4 RK_PA6 GPIO_ACTIVE_HIGH>;
    20. rockchip,camera-module-index = <0>;
    21. rockchip,camera-module-facing = "back";
    22. rockchip,camera-module-name = "default";
    23. rockchip,camera-module-lens-name = "default";
    24. rockchip,dvp_mode = "BT1120"; //BT656 or BT1120 or BT656_TEST
    25. rockchip,channel_nums = <4>; //channel nums, 1/2/4
    26. rockchip,dual_edge = <1>; // pclk dual edge, 0/1
    27. rockchip,default_rect= <1920 1080>; // default resolution
    28. port {
    29. nvp6158_out: endpoint {
    30. remote-endpoint = <&dvp_in_bcam1>;
    31. };
    32. };
    33. };
    34. };
    35. &rkcif {
    36. status = "okay";
    37. };
    38. &rkcif_dvp {
    39. status = "okay";
    40. ports {
    41. #address-cells = <1>;
    42. #size-cells = <0>;
    43. port@0 {
    44. #address-cells = <1>;
    45. #size-cells = <0>;
    46. /* Parallel bus endpoint */
    47. dvp_in_bcam1: endpoint@1 {
    48. reg = <1>;
    49. remote-endpoint = <&nvp6158_out>;
    50. bus-width = <16>;
    51. };
    52. };
    53. };
    54. };
    55. &rkcif_mmu {
    56. status = "okay";
    57. };

    ④pinctrl的配置

    这里需要特别注意的是,pinctrl的引用一定需要正确。这里引用的是并口的16条总线以及相关的clk。

    pinctrl-0 = <&cif_clk &cif_dvp_clk &cif_dvp_bus8 &cif_dvp_bus16>;

    (5)APK预览

    如果是走官方的USBCAMERAHAL的话,可以打开上述DTS的配置:rockchip,android-usb-camerahal-enable就会注册4路,之后就可以使用多摄的APK进行预览。

    (6)抓图指令调试

    开数据流

    v4l2-ctl --verbose -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat='NV12' --stream-mmap=4

    抓图:

    v4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat='NV12' --stream-mmap=3 --stream-skip=4 --stream-to=/data/1920x1080p60_nv12.yuv --stream-count=5 --stream-poll

  • 相关阅读:
    后台返回前端 is....开头字段被屏蔽
    (17)线程的实例认识:wait,waitany,waitall,及经典死锁问题
    Python基础之生成器
    [附源码]java毕业设计社团管理系统
    6.1_6 Python3.x入门 P6 【字符串格式化】四种方式(手动、%-formatting、str.format()、f-String)
    数据链路层——MAC帧、ARP协议详解
    分享一个Java毕业设计项目——叮当书城项目
    Spring Boot: 约定优于配置的软件设计思想
    七、【VUE基础】事件处理
    Polygon zkEVM协议治理、升级及其流程
  • 原文地址:https://blog.csdn.net/qq_34341546/article/details/133688513