1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * Copyright (c) 2016 MediaTek Inc. 4*4882a593Smuzhiyun * Author: Andrew-CT Chen <andrew-ct.chen@mediatek.com> 5*4882a593Smuzhiyun */ 6*4882a593Smuzhiyun 7*4882a593Smuzhiyun #ifndef _MTK_VPU_H 8*4882a593Smuzhiyun #define _MTK_VPU_H 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun #include <linux/platform_device.h> 11*4882a593Smuzhiyun 12*4882a593Smuzhiyun /** 13*4882a593Smuzhiyun * VPU (video processor unit) is a tiny processor controlling video hardware 14*4882a593Smuzhiyun * related to video codec, scaling and color format converting. 15*4882a593Smuzhiyun * VPU interfaces with other blocks by share memory and interrupt. 16*4882a593Smuzhiyun **/ 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun typedef void (*ipi_handler_t) (const void *data, 19*4882a593Smuzhiyun unsigned int len, 20*4882a593Smuzhiyun void *priv); 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun /** 23*4882a593Smuzhiyun * enum ipi_id - the id of inter-processor interrupt 24*4882a593Smuzhiyun * 25*4882a593Smuzhiyun * @IPI_VPU_INIT: The interrupt from vpu is to notfiy kernel 26*4882a593Smuzhiyun * VPU initialization completed. 27*4882a593Smuzhiyun * IPI_VPU_INIT is sent from VPU when firmware is 28*4882a593Smuzhiyun * loaded. AP doesn't need to send IPI_VPU_INIT 29*4882a593Smuzhiyun * command to VPU. 30*4882a593Smuzhiyun * For other IPI below, AP should send the request 31*4882a593Smuzhiyun * to VPU to trigger the interrupt. 32*4882a593Smuzhiyun * @IPI_VDEC_H264: The interrupt from vpu is to notify kernel to 33*4882a593Smuzhiyun * handle H264 vidoe decoder job, and vice versa. 34*4882a593Smuzhiyun * Decode output format is always MT21 no matter what 35*4882a593Smuzhiyun * the input format is. 36*4882a593Smuzhiyun * @IPI_VDEC_VP8: The interrupt from is to notify kernel to 37*4882a593Smuzhiyun * handle VP8 video decoder job, and vice versa. 38*4882a593Smuzhiyun * Decode output format is always MT21 no matter what 39*4882a593Smuzhiyun * the input format is. 40*4882a593Smuzhiyun * @IPI_VDEC_VP9: The interrupt from vpu is to notify kernel to 41*4882a593Smuzhiyun * handle VP9 video decoder job, and vice versa. 42*4882a593Smuzhiyun * Decode output format is always MT21 no matter what 43*4882a593Smuzhiyun * the input format is. 44*4882a593Smuzhiyun * @IPI_VENC_H264: The interrupt from vpu is to notify kernel to 45*4882a593Smuzhiyun * handle H264 video encoder job, and vice versa. 46*4882a593Smuzhiyun * @IPI_VENC_VP8: The interrupt fro vpu is to notify kernel to 47*4882a593Smuzhiyun * handle VP8 video encoder job,, and vice versa. 48*4882a593Smuzhiyun * @IPI_MDP: The interrupt from vpu is to notify kernel to 49*4882a593Smuzhiyun * handle MDP (Media Data Path) job, and vice versa. 50*4882a593Smuzhiyun * @IPI_MAX: The maximum IPI number 51*4882a593Smuzhiyun */ 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun enum ipi_id { 54*4882a593Smuzhiyun IPI_VPU_INIT = 0, 55*4882a593Smuzhiyun IPI_VDEC_H264, 56*4882a593Smuzhiyun IPI_VDEC_VP8, 57*4882a593Smuzhiyun IPI_VDEC_VP9, 58*4882a593Smuzhiyun IPI_VENC_H264, 59*4882a593Smuzhiyun IPI_VENC_VP8, 60*4882a593Smuzhiyun IPI_MDP, 61*4882a593Smuzhiyun IPI_MAX, 62*4882a593Smuzhiyun }; 63*4882a593Smuzhiyun 64*4882a593Smuzhiyun /** 65*4882a593Smuzhiyun * enum rst_id - reset id to register reset function for VPU watchdog timeout 66*4882a593Smuzhiyun * 67*4882a593Smuzhiyun * @VPU_RST_ENC: encoder reset id 68*4882a593Smuzhiyun * @VPU_RST_DEC: decoder reset id 69*4882a593Smuzhiyun * @VPU_RST_MDP: MDP (Media Data Path) reset id 70*4882a593Smuzhiyun * @VPU_RST_MAX: maximum reset id 71*4882a593Smuzhiyun */ 72*4882a593Smuzhiyun enum rst_id { 73*4882a593Smuzhiyun VPU_RST_ENC, 74*4882a593Smuzhiyun VPU_RST_DEC, 75*4882a593Smuzhiyun VPU_RST_MDP, 76*4882a593Smuzhiyun VPU_RST_MAX, 77*4882a593Smuzhiyun }; 78*4882a593Smuzhiyun 79*4882a593Smuzhiyun /** 80*4882a593Smuzhiyun * vpu_ipi_register - register an ipi function 81*4882a593Smuzhiyun * 82*4882a593Smuzhiyun * @pdev: VPU platform device 83*4882a593Smuzhiyun * @id: IPI ID 84*4882a593Smuzhiyun * @handler: IPI handler 85*4882a593Smuzhiyun * @name: IPI name 86*4882a593Smuzhiyun * @priv: private data for IPI handler 87*4882a593Smuzhiyun * 88*4882a593Smuzhiyun * Register an ipi function to receive ipi interrupt from VPU. 89*4882a593Smuzhiyun * 90*4882a593Smuzhiyun * Return: Return 0 if ipi registers successfully, otherwise it is failed. 91*4882a593Smuzhiyun */ 92*4882a593Smuzhiyun int vpu_ipi_register(struct platform_device *pdev, enum ipi_id id, 93*4882a593Smuzhiyun ipi_handler_t handler, const char *name, void *priv); 94*4882a593Smuzhiyun 95*4882a593Smuzhiyun /** 96*4882a593Smuzhiyun * vpu_ipi_send - send data from AP to vpu. 97*4882a593Smuzhiyun * 98*4882a593Smuzhiyun * @pdev: VPU platform device 99*4882a593Smuzhiyun * @id: IPI ID 100*4882a593Smuzhiyun * @buf: the data buffer 101*4882a593Smuzhiyun * @len: the data buffer length 102*4882a593Smuzhiyun * 103*4882a593Smuzhiyun * This function is thread-safe. When this function returns, 104*4882a593Smuzhiyun * VPU has received the data and starts the processing. 105*4882a593Smuzhiyun * When the processing completes, IPI handler registered 106*4882a593Smuzhiyun * by vpu_ipi_register will be called in interrupt context. 107*4882a593Smuzhiyun * 108*4882a593Smuzhiyun * Return: Return 0 if sending data successfully, otherwise it is failed. 109*4882a593Smuzhiyun **/ 110*4882a593Smuzhiyun int vpu_ipi_send(struct platform_device *pdev, 111*4882a593Smuzhiyun enum ipi_id id, void *buf, 112*4882a593Smuzhiyun unsigned int len); 113*4882a593Smuzhiyun 114*4882a593Smuzhiyun /** 115*4882a593Smuzhiyun * vpu_get_plat_device - get VPU's platform device 116*4882a593Smuzhiyun * 117*4882a593Smuzhiyun * @pdev: the platform device of the module requesting VPU platform 118*4882a593Smuzhiyun * device for using VPU API. 119*4882a593Smuzhiyun * 120*4882a593Smuzhiyun * Return: Return NULL if it is failed. 121*4882a593Smuzhiyun * otherwise it is VPU's platform device 122*4882a593Smuzhiyun **/ 123*4882a593Smuzhiyun struct platform_device *vpu_get_plat_device(struct platform_device *pdev); 124*4882a593Smuzhiyun 125*4882a593Smuzhiyun /** 126*4882a593Smuzhiyun * vpu_wdt_reg_handler - register a VPU watchdog handler 127*4882a593Smuzhiyun * 128*4882a593Smuzhiyun * @pdev: VPU platform device 129*4882a593Smuzhiyun * @vpu_wdt_reset_func: the callback reset function 130*4882a593Smuzhiyun * @private_data: the private data for reset function 131*4882a593Smuzhiyun * @rst_id: reset id 132*4882a593Smuzhiyun * 133*4882a593Smuzhiyun * Register a handler performing own tasks when vpu reset by watchdog 134*4882a593Smuzhiyun * 135*4882a593Smuzhiyun * Return: Return 0 if the handler is added successfully, 136*4882a593Smuzhiyun * otherwise it is failed. 137*4882a593Smuzhiyun * 138*4882a593Smuzhiyun **/ 139*4882a593Smuzhiyun int vpu_wdt_reg_handler(struct platform_device *pdev, 140*4882a593Smuzhiyun void vpu_wdt_reset_func(void *), 141*4882a593Smuzhiyun void *priv, enum rst_id id); 142*4882a593Smuzhiyun 143*4882a593Smuzhiyun /** 144*4882a593Smuzhiyun * vpu_get_vdec_hw_capa - get video decoder hardware capability 145*4882a593Smuzhiyun * 146*4882a593Smuzhiyun * @pdev: VPU platform device 147*4882a593Smuzhiyun * 148*4882a593Smuzhiyun * Return: video decoder hardware capability 149*4882a593Smuzhiyun **/ 150*4882a593Smuzhiyun unsigned int vpu_get_vdec_hw_capa(struct platform_device *pdev); 151*4882a593Smuzhiyun 152*4882a593Smuzhiyun /** 153*4882a593Smuzhiyun * vpu_get_venc_hw_capa - get video encoder hardware capability 154*4882a593Smuzhiyun * 155*4882a593Smuzhiyun * @pdev: VPU platform device 156*4882a593Smuzhiyun * 157*4882a593Smuzhiyun * Return: video encoder hardware capability 158*4882a593Smuzhiyun **/ 159*4882a593Smuzhiyun unsigned int vpu_get_venc_hw_capa(struct platform_device *pdev); 160*4882a593Smuzhiyun 161*4882a593Smuzhiyun /** 162*4882a593Smuzhiyun * vpu_load_firmware - download VPU firmware and boot it 163*4882a593Smuzhiyun * 164*4882a593Smuzhiyun * @pdev: VPU platform device 165*4882a593Smuzhiyun * 166*4882a593Smuzhiyun * Return: Return 0 if downloading firmware successfully, 167*4882a593Smuzhiyun * otherwise it is failed 168*4882a593Smuzhiyun **/ 169*4882a593Smuzhiyun int vpu_load_firmware(struct platform_device *pdev); 170*4882a593Smuzhiyun 171*4882a593Smuzhiyun /** 172*4882a593Smuzhiyun * vpu_mapping_dm_addr - Mapping DTCM/DMEM to kernel virtual address 173*4882a593Smuzhiyun * 174*4882a593Smuzhiyun * @pdev: VPU platform device 175*4882a593Smuzhiyun * @dmem_addr: VPU's data memory address 176*4882a593Smuzhiyun * 177*4882a593Smuzhiyun * Mapping the VPU's DTCM (Data Tightly-Coupled Memory) / 178*4882a593Smuzhiyun * DMEM (Data Extended Memory) memory address to 179*4882a593Smuzhiyun * kernel virtual address. 180*4882a593Smuzhiyun * 181*4882a593Smuzhiyun * Return: Return ERR_PTR(-EINVAL) if mapping failed, 182*4882a593Smuzhiyun * otherwise the mapped kernel virtual address 183*4882a593Smuzhiyun **/ 184*4882a593Smuzhiyun void *vpu_mapping_dm_addr(struct platform_device *pdev, 185*4882a593Smuzhiyun u32 dtcm_dmem_addr); 186*4882a593Smuzhiyun #endif /* _MTK_VPU_H */ 187