• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 Rockchip Electronics Co. LTD
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 #ifndef __MPP_DEVICE_H__
18 #define __MPP_DEVICE_H__
19 
20 #include "mpp_err.h"
21 #include "mpp_dev_defs.h"
22 #include "mpp_callback.h"
23 
24 typedef enum MppDevIoctlCmd_e {
25     /* device batch mode config */
26     MPP_DEV_BATCH_ON,
27     MPP_DEV_BATCH_OFF,
28     MPP_DEV_DELIMIT,
29     MPP_DEV_SET_CB_CTX,
30 
31     /* hardware operation setup config */
32     MPP_DEV_REG_WR,
33     MPP_DEV_REG_RD,
34     MPP_DEV_REG_OFFSET,
35     MPP_DEV_REG_OFFS,
36     MPP_DEV_RCB_INFO,
37     MPP_DEV_SET_INFO,
38 
39     MPP_DEV_CMD_SEND,
40     MPP_DEV_CMD_POLL,
41 
42     MPP_DEV_IOCTL_CMD_BUTT,
43 } MppDevIoctlCmd;
44 
45 /* for MPP_DEV_REG_WR */
46 typedef struct MppDevRegWrCfg_t {
47     void    *reg;
48     RK_U32  size;
49     RK_U32  offset;
50 } MppDevRegWrCfg;
51 
52 /* for MPP_DEV_REG_RD */
53 typedef struct MppDevRegRdCfg_t {
54     void    *reg;
55     RK_U32  size;
56     RK_U32  offset;
57 } MppDevRegRdCfg;
58 
59 /* for MPP_DEV_REG_OFFSET */
60 typedef struct MppDevRegOffsetCfg_t {
61     RK_U32  reg_idx;
62     RK_U32  offset;
63 } MppDevRegOffsetCfg;
64 
65 /* for multi MPP_DEV_REG_OFFSET */
66 typedef struct MppDevRegOffsCfg_t {
67     RK_S32  size;
68     RK_S32  count;
69     MppDevRegOffsetCfg cfgs[];
70 } MppDevRegOffCfgs;
71 
72 /* for MPP_DEV_RCB_INFO */
73 typedef struct MppDevRcbInfoCfg_t {
74     RK_U32  reg_idx;
75     RK_U32  size;
76 } MppDevRcbInfoCfg;
77 
78 /* for MPP_DEV_SET_INFO */
79 typedef struct MppDevSetInfoCfg_t {
80     RK_U32  type;
81     RK_U32  flag;
82     RK_U64  data;
83 } MppDevInfoCfg;
84 
85 typedef union MppDevPollEncSliceInfo_u {
86     RK_U32  val;
87     struct {
88         RK_U32  length  : 31;
89         RK_U32  last    : 1;
90     };
91 } MppDevPollEncSliceInfo;
92 
93 /* for MPP_DEV_POLL */
94 typedef struct MppDevPollCfg_t {
95     RK_S32  poll_type;
96     RK_S32  poll_ret;
97     RK_S32  count_max;
98     RK_S32  count_ret;
99     MppDevPollEncSliceInfo slice_info[];
100 } MppDevPollCfg;
101 
102 typedef struct MppDevApi_t {
103     const char  *name;
104     RK_U32      ctx_size;
105     MPP_RET     (*init)(void *ctx, MppClientType type);
106     MPP_RET     (*deinit)(void *ctx);
107 
108     /* bat mode function */
109     MPP_RET     (*attach)(void *ctx);
110     MPP_RET     (*detach)(void *ctx);
111     MPP_RET     (*delimit)(void *ctx);
112     MPP_RET     (*set_cb_ctx)(void *ctx, MppCbCtx *cb);
113 
114     /* config the cmd on preparing */
115     MPP_RET     (*reg_wr)(void *ctx, MppDevRegWrCfg *cfg);
116     MPP_RET     (*reg_rd)(void *ctx, MppDevRegRdCfg *cfg);
117     MPP_RET     (*reg_offset)(void *ctx, MppDevRegOffsetCfg *cfg);
118     MPP_RET     (*reg_offs)(void *ctx, MppDevRegOffCfgs *cfg);
119     MPP_RET     (*rcb_info)(void *ctx, MppDevRcbInfoCfg *cfg);
120     MPP_RET     (*set_info)(void *ctx, MppDevInfoCfg *cfg);
121 
122     /* send cmd to hardware */
123     MPP_RET     (*cmd_send)(void *ctx);
124 
125     /* poll cmd from hardware */
126     MPP_RET     (*cmd_poll)(void *ctx, MppDevPollCfg *cfg);
127 } MppDevApi;
128 
129 typedef void* MppDev;
130 
131 #ifdef __cplusplus
132 extern "C" {
133 #endif
134 
135 MPP_RET mpp_dev_init(MppDev *ctx, MppClientType type);
136 MPP_RET mpp_dev_deinit(MppDev ctx);
137 
138 MPP_RET mpp_dev_ioctl(MppDev ctx, RK_S32 cmd, void *param);
139 
140 /* special helper function for large address offset config */
141 MPP_RET mpp_dev_set_reg_offset(MppDev dev, RK_S32 index, RK_U32 offset);
142 
143 /* register offset multi config */
144 MPP_RET mpp_dev_multi_offset_init(MppDevRegOffCfgs **cfgs, RK_S32 size);
145 MPP_RET mpp_dev_multi_offset_deinit(MppDevRegOffCfgs *cfgs);
146 
147 MPP_RET mpp_dev_multi_offset_reset(MppDevRegOffCfgs *cfgs);
148 MPP_RET mpp_dev_multi_offset_update(MppDevRegOffCfgs *cfgs, RK_S32 index, RK_U32 offset);
149 
150 #ifdef __cplusplus
151 }
152 #endif
153 
154 #endif /* __MPP_DEVICE_H__ */
155