1 /* 2 * Copyright (c) 2021 Rockchip Electronics Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef __MPP_DEVICE_H__ 17 #define __MPP_DEVICE_H__ 18 19 #include "mpp_err.h" 20 #include "mpp_dev_defs.h" 21 22 typedef enum MppDevIoctlCmd_e { 23 /* device batch mode config */ 24 MPP_DEV_BATCH_ON, 25 MPP_DEV_BATCH_OFF, 26 27 /* hardware operation setup config */ 28 MPP_DEV_REG_WR, 29 MPP_DEV_REG_RD, 30 MPP_DEV_REG_OFFSET, 31 MPP_DEV_RCB_INFO, 32 MPP_DEV_SET_INFO, 33 34 MPP_DEV_CMD_SEND, 35 MPP_DEV_CMD_POLL, 36 37 MPP_DEV_IOCTL_CMD_BUTT, 38 } MppDevIoctlCmd; 39 40 /* for MPP_DEV_REG_WR */ 41 typedef struct MppDevRegWrCfg_t { 42 void *reg; 43 unsigned int size; 44 unsigned int offset; 45 } MppDevRegWrCfg; 46 47 /* for MPP_DEV_REG_RD */ 48 typedef struct MppDevRegRdCfg_t { 49 void *reg; 50 unsigned int size; 51 unsigned int offset; 52 } MppDevRegRdCfg; 53 54 /* for MPP_DEV_REG_OFFSET */ 55 typedef struct MppDevRegOffsetCfg_t { 56 unsigned int reg_idx; 57 unsigned int offset; 58 } MppDevRegOffsetCfg; 59 60 /* for MPP_DEV_RCB_INFO */ 61 typedef struct MppDevRcbInfoCfg_t { 62 unsigned int reg_idx; 63 unsigned int size; 64 } MppDevRcbInfoCfg; 65 66 /* for MPP_DEV_SET_INFO */ 67 typedef struct MppDevSetInfoCfg_t { 68 unsigned int type; 69 unsigned int flag; 70 RK_U64 data; 71 } MppDevInfoCfg; 72 73 typedef struct MppDevApi_t { 74 const char *name; 75 unsigned int ctx_size; 76 MPP_RET (*init)(void *ctx, MppClientType type); 77 MPP_RET (*deinit)(void *ctx); 78 79 /* bat mode function */ 80 MPP_RET (*attach)(void *ctx); 81 MPP_RET (*detach)(void *ctx); 82 83 /* config the cmd on preparing */ 84 MPP_RET (*reg_wr)(void *ctx, MppDevRegWrCfg *cfg); 85 MPP_RET (*reg_rd)(void *ctx, MppDevRegRdCfg *cfg); 86 MPP_RET (*reg_offset)(void *ctx, MppDevRegOffsetCfg *cfg); 87 MPP_RET (*rcb_info)(void *ctx, MppDevRcbInfoCfg *cfg); 88 MPP_RET (*set_info)(void *ctx, MppDevInfoCfg *cfg); 89 90 /* send cmd to hardware */ 91 MPP_RET (*cmd_send)(void *ctx); 92 93 /* poll cmd from hardware */ 94 MPP_RET (*cmd_poll)(void *ctx); 95 } MppDevApi; 96 97 typedef void *MppDev; 98 99 #ifdef __cplusplus 100 extern "C" { 101 #endif 102 103 MPP_RET mpp_dev_init(MppDev *ctx, MppClientType type); 104 MPP_RET mpp_dev_deinit(MppDev ctx); 105 106 MPP_RET mpp_dev_ioctl(MppDev ctx, signed int cmd, void *param); 107 108 /* special helper function for large address offset config */ 109 MPP_RET mpp_dev_set_reg_offset(MppDev dev, signed int index, unsigned int offset); 110 111 #ifdef __cplusplus 112 } 113 #endif 114 115 #endif /* __MPP_DEVICE_H__ */