13d0407baSopenharmony_ci/*
23d0407baSopenharmony_ci * Copyright (c) 2021 Rockchip Electronics Co., Ltd.
33d0407baSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
43d0407baSopenharmony_ci * you may not use this file except in compliance with the License.
53d0407baSopenharmony_ci * You may obtain a copy of the License at
63d0407baSopenharmony_ci *
73d0407baSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
83d0407baSopenharmony_ci *
93d0407baSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
103d0407baSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
113d0407baSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
123d0407baSopenharmony_ci * See the License for the specific language governing permissions and
133d0407baSopenharmony_ci * limitations under the License.
143d0407baSopenharmony_ci */
153d0407baSopenharmony_ci
163d0407baSopenharmony_ci#ifndef __MPP_DEVICE_H__
173d0407baSopenharmony_ci#define __MPP_DEVICE_H__
183d0407baSopenharmony_ci
193d0407baSopenharmony_ci#include "mpp_err.h"
203d0407baSopenharmony_ci#include "mpp_dev_defs.h"
213d0407baSopenharmony_ci
223d0407baSopenharmony_citypedef enum MppDevIoctlCmd_e {
233d0407baSopenharmony_ci    /* device batch mode config */
243d0407baSopenharmony_ci    MPP_DEV_BATCH_ON,
253d0407baSopenharmony_ci    MPP_DEV_BATCH_OFF,
263d0407baSopenharmony_ci
273d0407baSopenharmony_ci    /* hardware operation setup config */
283d0407baSopenharmony_ci    MPP_DEV_REG_WR,
293d0407baSopenharmony_ci    MPP_DEV_REG_RD,
303d0407baSopenharmony_ci    MPP_DEV_REG_OFFSET,
313d0407baSopenharmony_ci    MPP_DEV_RCB_INFO,
323d0407baSopenharmony_ci    MPP_DEV_SET_INFO,
333d0407baSopenharmony_ci
343d0407baSopenharmony_ci    MPP_DEV_CMD_SEND,
353d0407baSopenharmony_ci    MPP_DEV_CMD_POLL,
363d0407baSopenharmony_ci
373d0407baSopenharmony_ci    MPP_DEV_IOCTL_CMD_BUTT,
383d0407baSopenharmony_ci} MppDevIoctlCmd;
393d0407baSopenharmony_ci
403d0407baSopenharmony_ci/* for MPP_DEV_REG_WR */
413d0407baSopenharmony_citypedef struct MppDevRegWrCfg_t {
423d0407baSopenharmony_ci    void *reg;
433d0407baSopenharmony_ci    unsigned int size;
443d0407baSopenharmony_ci    unsigned int offset;
453d0407baSopenharmony_ci} MppDevRegWrCfg;
463d0407baSopenharmony_ci
473d0407baSopenharmony_ci/* for MPP_DEV_REG_RD */
483d0407baSopenharmony_citypedef struct MppDevRegRdCfg_t {
493d0407baSopenharmony_ci    void *reg;
503d0407baSopenharmony_ci    unsigned int size;
513d0407baSopenharmony_ci    unsigned int offset;
523d0407baSopenharmony_ci} MppDevRegRdCfg;
533d0407baSopenharmony_ci
543d0407baSopenharmony_ci/* for MPP_DEV_REG_OFFSET */
553d0407baSopenharmony_citypedef struct MppDevRegOffsetCfg_t {
563d0407baSopenharmony_ci    unsigned int reg_idx;
573d0407baSopenharmony_ci    unsigned int offset;
583d0407baSopenharmony_ci} MppDevRegOffsetCfg;
593d0407baSopenharmony_ci
603d0407baSopenharmony_ci/* for MPP_DEV_RCB_INFO */
613d0407baSopenharmony_citypedef struct MppDevRcbInfoCfg_t {
623d0407baSopenharmony_ci    unsigned int reg_idx;
633d0407baSopenharmony_ci    unsigned int size;
643d0407baSopenharmony_ci} MppDevRcbInfoCfg;
653d0407baSopenharmony_ci
663d0407baSopenharmony_ci/* for MPP_DEV_SET_INFO */
673d0407baSopenharmony_citypedef struct MppDevSetInfoCfg_t {
683d0407baSopenharmony_ci    unsigned int type;
693d0407baSopenharmony_ci    unsigned int flag;
703d0407baSopenharmony_ci    RK_U64 data;
713d0407baSopenharmony_ci} MppDevInfoCfg;
723d0407baSopenharmony_ci
733d0407baSopenharmony_citypedef struct MppDevApi_t {
743d0407baSopenharmony_ci    const char *name;
753d0407baSopenharmony_ci    unsigned int ctx_size;
763d0407baSopenharmony_ci    MPP_RET (*init)(void *ctx, MppClientType type);
773d0407baSopenharmony_ci    MPP_RET (*deinit)(void *ctx);
783d0407baSopenharmony_ci
793d0407baSopenharmony_ci    /* bat mode function */
803d0407baSopenharmony_ci    MPP_RET (*attach)(void *ctx);
813d0407baSopenharmony_ci    MPP_RET (*detach)(void *ctx);
823d0407baSopenharmony_ci
833d0407baSopenharmony_ci    /* config the cmd on preparing */
843d0407baSopenharmony_ci    MPP_RET (*reg_wr)(void *ctx, MppDevRegWrCfg *cfg);
853d0407baSopenharmony_ci    MPP_RET (*reg_rd)(void *ctx, MppDevRegRdCfg *cfg);
863d0407baSopenharmony_ci    MPP_RET (*reg_offset)(void *ctx, MppDevRegOffsetCfg *cfg);
873d0407baSopenharmony_ci    MPP_RET (*rcb_info)(void *ctx, MppDevRcbInfoCfg *cfg);
883d0407baSopenharmony_ci    MPP_RET (*set_info)(void *ctx, MppDevInfoCfg *cfg);
893d0407baSopenharmony_ci
903d0407baSopenharmony_ci    /* send cmd to hardware */
913d0407baSopenharmony_ci    MPP_RET (*cmd_send)(void *ctx);
923d0407baSopenharmony_ci
933d0407baSopenharmony_ci    /* poll cmd from hardware */
943d0407baSopenharmony_ci    MPP_RET (*cmd_poll)(void *ctx);
953d0407baSopenharmony_ci} MppDevApi;
963d0407baSopenharmony_ci
973d0407baSopenharmony_citypedef void *MppDev;
983d0407baSopenharmony_ci
993d0407baSopenharmony_ci#ifdef __cplusplus
1003d0407baSopenharmony_ciextern "C" {
1013d0407baSopenharmony_ci#endif
1023d0407baSopenharmony_ci
1033d0407baSopenharmony_ciMPP_RET mpp_dev_init(MppDev *ctx, MppClientType type);
1043d0407baSopenharmony_ciMPP_RET mpp_dev_deinit(MppDev ctx);
1053d0407baSopenharmony_ci
1063d0407baSopenharmony_ciMPP_RET mpp_dev_ioctl(MppDev ctx, signed int cmd, void *param);
1073d0407baSopenharmony_ci
1083d0407baSopenharmony_ci/* special helper function for large address offset config */
1093d0407baSopenharmony_ciMPP_RET mpp_dev_set_reg_offset(MppDev dev, signed int index, unsigned int offset);
1103d0407baSopenharmony_ci
1113d0407baSopenharmony_ci#ifdef __cplusplus
1123d0407baSopenharmony_ci}
1133d0407baSopenharmony_ci#endif
1143d0407baSopenharmony_ci
1153d0407baSopenharmony_ci#endif /* __MPP_DEVICE_H__ */