xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/IspFec/src/RkIspFecHw.cpp (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *  Copyright (c) 2022 Rockchip Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #include "RkIspFecHw.h"
19 #include <errno.h>
20 #include <fcntl.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <sys/ioctl.h>
24 #include <sys/types.h>
25 #include <string.h>
26 #include <unistd.h>
27 #include <linux/videodev2.h>
28 
29 namespace RKISPFEC {
30 
RkIspFecHw(const char * dev)31 RkIspFecHw::RkIspFecHw(const char* dev)
32 {
33     printf("I: open fec dev %s\n", dev);
34     mFd = ::open(dev, O_RDWR | O_CLOEXEC);
35     if (mFd == -1)
36         printf("E: open %s failed %s !", dev, strerror(errno));
37     printf("I: open fec dev %s done !\n", dev);
38 }
39 
~RkIspFecHw()40 RkIspFecHw::~RkIspFecHw()
41 {
42     if (mFd >= 0 )
43         ::close(mFd);
44 }
45 
46 int
process(struct rkispp_fec_in_out & param)47 RkIspFecHw::process(struct rkispp_fec_in_out& param)
48 {
49     if (mFd < 0) {
50         printf("E: wrong fec fd \n");
51         return -1;
52     }
53 
54     int ret = ioctl(mFd, RKISPP_CMD_FEC_IN_OUT, &param);
55 
56     if (ret == -EAGAIN) // try again
57         ret = ioctl(mFd, RKISPP_CMD_FEC_IN_OUT, &param);
58 
59     return ret;
60 }
61 
62 };
63