18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci* Copyright (c) 2016 MediaTek Inc.
48c2ecf20Sopenharmony_ci* Author: Andrew-CT Chen <andrew-ct.chen@mediatek.com>
58c2ecf20Sopenharmony_ci*/
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifndef _MTK_VPU_H
88c2ecf20Sopenharmony_ci#define _MTK_VPU_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci/**
138c2ecf20Sopenharmony_ci * VPU (video processor unit) is a tiny processor controlling video hardware
148c2ecf20Sopenharmony_ci * related to video codec, scaling and color format converting.
158c2ecf20Sopenharmony_ci * VPU interfaces with other blocks by share memory and interrupt.
168c2ecf20Sopenharmony_ci **/
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_citypedef void (*ipi_handler_t) (const void *data,
198c2ecf20Sopenharmony_ci			       unsigned int len,
208c2ecf20Sopenharmony_ci			       void *priv);
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci/**
238c2ecf20Sopenharmony_ci * enum ipi_id - the id of inter-processor interrupt
248c2ecf20Sopenharmony_ci *
258c2ecf20Sopenharmony_ci * @IPI_VPU_INIT:	 The interrupt from vpu is to notfiy kernel
268c2ecf20Sopenharmony_ci *			 VPU initialization completed.
278c2ecf20Sopenharmony_ci *			 IPI_VPU_INIT is sent from VPU when firmware is
288c2ecf20Sopenharmony_ci *			 loaded. AP doesn't need to send IPI_VPU_INIT
298c2ecf20Sopenharmony_ci *			 command to VPU.
308c2ecf20Sopenharmony_ci *			 For other IPI below, AP should send the request
318c2ecf20Sopenharmony_ci *			 to VPU to trigger the interrupt.
328c2ecf20Sopenharmony_ci * @IPI_VDEC_H264:	 The interrupt from vpu is to notify kernel to
338c2ecf20Sopenharmony_ci *			 handle H264 vidoe decoder job, and vice versa.
348c2ecf20Sopenharmony_ci *			 Decode output format is always MT21 no matter what
358c2ecf20Sopenharmony_ci *			 the input format is.
368c2ecf20Sopenharmony_ci * @IPI_VDEC_VP8:	 The interrupt from is to notify kernel to
378c2ecf20Sopenharmony_ci *			 handle VP8 video decoder job, and vice versa.
388c2ecf20Sopenharmony_ci *			 Decode output format is always MT21 no matter what
398c2ecf20Sopenharmony_ci *			 the input format is.
408c2ecf20Sopenharmony_ci * @IPI_VDEC_VP9:	 The interrupt from vpu is to notify kernel to
418c2ecf20Sopenharmony_ci *			 handle VP9 video decoder job, and vice versa.
428c2ecf20Sopenharmony_ci *			 Decode output format is always MT21 no matter what
438c2ecf20Sopenharmony_ci *			 the input format is.
448c2ecf20Sopenharmony_ci * @IPI_VENC_H264:	 The interrupt from vpu is to notify kernel to
458c2ecf20Sopenharmony_ci *			 handle H264 video encoder job, and vice versa.
468c2ecf20Sopenharmony_ci * @IPI_VENC_VP8:	 The interrupt fro vpu is to notify kernel to
478c2ecf20Sopenharmony_ci *			 handle VP8 video encoder job,, and vice versa.
488c2ecf20Sopenharmony_ci * @IPI_MDP:		 The interrupt from vpu is to notify kernel to
498c2ecf20Sopenharmony_ci *			 handle MDP (Media Data Path) job, and vice versa.
508c2ecf20Sopenharmony_ci * @IPI_MAX:		 The maximum IPI number
518c2ecf20Sopenharmony_ci */
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cienum ipi_id {
548c2ecf20Sopenharmony_ci	IPI_VPU_INIT = 0,
558c2ecf20Sopenharmony_ci	IPI_VDEC_H264,
568c2ecf20Sopenharmony_ci	IPI_VDEC_VP8,
578c2ecf20Sopenharmony_ci	IPI_VDEC_VP9,
588c2ecf20Sopenharmony_ci	IPI_VENC_H264,
598c2ecf20Sopenharmony_ci	IPI_VENC_VP8,
608c2ecf20Sopenharmony_ci	IPI_MDP,
618c2ecf20Sopenharmony_ci	IPI_MAX,
628c2ecf20Sopenharmony_ci};
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/**
658c2ecf20Sopenharmony_ci * enum rst_id - reset id to register reset function for VPU watchdog timeout
668c2ecf20Sopenharmony_ci *
678c2ecf20Sopenharmony_ci * @VPU_RST_ENC: encoder reset id
688c2ecf20Sopenharmony_ci * @VPU_RST_DEC: decoder reset id
698c2ecf20Sopenharmony_ci * @VPU_RST_MDP: MDP (Media Data Path) reset id
708c2ecf20Sopenharmony_ci * @VPU_RST_MAX: maximum reset id
718c2ecf20Sopenharmony_ci */
728c2ecf20Sopenharmony_cienum rst_id {
738c2ecf20Sopenharmony_ci	VPU_RST_ENC,
748c2ecf20Sopenharmony_ci	VPU_RST_DEC,
758c2ecf20Sopenharmony_ci	VPU_RST_MDP,
768c2ecf20Sopenharmony_ci	VPU_RST_MAX,
778c2ecf20Sopenharmony_ci};
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci/**
808c2ecf20Sopenharmony_ci * vpu_ipi_register - register an ipi function
818c2ecf20Sopenharmony_ci *
828c2ecf20Sopenharmony_ci * @pdev:	VPU platform device
838c2ecf20Sopenharmony_ci * @id:		IPI ID
848c2ecf20Sopenharmony_ci * @handler:	IPI handler
858c2ecf20Sopenharmony_ci * @name:	IPI name
868c2ecf20Sopenharmony_ci * @priv:	private data for IPI handler
878c2ecf20Sopenharmony_ci *
888c2ecf20Sopenharmony_ci * Register an ipi function to receive ipi interrupt from VPU.
898c2ecf20Sopenharmony_ci *
908c2ecf20Sopenharmony_ci * Return: Return 0 if ipi registers successfully, otherwise it is failed.
918c2ecf20Sopenharmony_ci */
928c2ecf20Sopenharmony_ciint vpu_ipi_register(struct platform_device *pdev, enum ipi_id id,
938c2ecf20Sopenharmony_ci		     ipi_handler_t handler, const char *name, void *priv);
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci/**
968c2ecf20Sopenharmony_ci * vpu_ipi_send - send data from AP to vpu.
978c2ecf20Sopenharmony_ci *
988c2ecf20Sopenharmony_ci * @pdev:	VPU platform device
998c2ecf20Sopenharmony_ci * @id:		IPI ID
1008c2ecf20Sopenharmony_ci * @buf:	the data buffer
1018c2ecf20Sopenharmony_ci * @len:	the data buffer length
1028c2ecf20Sopenharmony_ci *
1038c2ecf20Sopenharmony_ci * This function is thread-safe. When this function returns,
1048c2ecf20Sopenharmony_ci * VPU has received the data and starts the processing.
1058c2ecf20Sopenharmony_ci * When the processing completes, IPI handler registered
1068c2ecf20Sopenharmony_ci * by vpu_ipi_register will be called in interrupt context.
1078c2ecf20Sopenharmony_ci *
1088c2ecf20Sopenharmony_ci * Return: Return 0 if sending data successfully, otherwise it is failed.
1098c2ecf20Sopenharmony_ci **/
1108c2ecf20Sopenharmony_ciint vpu_ipi_send(struct platform_device *pdev,
1118c2ecf20Sopenharmony_ci		 enum ipi_id id, void *buf,
1128c2ecf20Sopenharmony_ci		 unsigned int len);
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci/**
1158c2ecf20Sopenharmony_ci * vpu_get_plat_device - get VPU's platform device
1168c2ecf20Sopenharmony_ci *
1178c2ecf20Sopenharmony_ci * @pdev:	the platform device of the module requesting VPU platform
1188c2ecf20Sopenharmony_ci *		device for using VPU API.
1198c2ecf20Sopenharmony_ci *
1208c2ecf20Sopenharmony_ci * Return: Return NULL if it is failed.
1218c2ecf20Sopenharmony_ci * otherwise it is VPU's platform device
1228c2ecf20Sopenharmony_ci **/
1238c2ecf20Sopenharmony_cistruct platform_device *vpu_get_plat_device(struct platform_device *pdev);
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci/**
1268c2ecf20Sopenharmony_ci * vpu_wdt_reg_handler - register a VPU watchdog handler
1278c2ecf20Sopenharmony_ci *
1288c2ecf20Sopenharmony_ci * @pdev:               VPU platform device
1298c2ecf20Sopenharmony_ci * @vpu_wdt_reset_func:	the callback reset function
1308c2ecf20Sopenharmony_ci * @private_data:       the private data for reset function
1318c2ecf20Sopenharmony_ci * @rst_id:		reset id
1328c2ecf20Sopenharmony_ci *
1338c2ecf20Sopenharmony_ci * Register a handler performing own tasks when vpu reset by watchdog
1348c2ecf20Sopenharmony_ci *
1358c2ecf20Sopenharmony_ci * Return: Return 0 if the handler is added successfully,
1368c2ecf20Sopenharmony_ci * otherwise it is failed.
1378c2ecf20Sopenharmony_ci *
1388c2ecf20Sopenharmony_ci **/
1398c2ecf20Sopenharmony_ciint vpu_wdt_reg_handler(struct platform_device *pdev,
1408c2ecf20Sopenharmony_ci			void vpu_wdt_reset_func(void *),
1418c2ecf20Sopenharmony_ci			void *priv, enum rst_id id);
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci/**
1448c2ecf20Sopenharmony_ci * vpu_get_vdec_hw_capa - get video decoder hardware capability
1458c2ecf20Sopenharmony_ci *
1468c2ecf20Sopenharmony_ci * @pdev:	VPU platform device
1478c2ecf20Sopenharmony_ci *
1488c2ecf20Sopenharmony_ci * Return: video decoder hardware capability
1498c2ecf20Sopenharmony_ci **/
1508c2ecf20Sopenharmony_ciunsigned int vpu_get_vdec_hw_capa(struct platform_device *pdev);
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci/**
1538c2ecf20Sopenharmony_ci * vpu_get_venc_hw_capa - get video encoder hardware capability
1548c2ecf20Sopenharmony_ci *
1558c2ecf20Sopenharmony_ci * @pdev:	VPU platform device
1568c2ecf20Sopenharmony_ci *
1578c2ecf20Sopenharmony_ci * Return: video encoder hardware capability
1588c2ecf20Sopenharmony_ci **/
1598c2ecf20Sopenharmony_ciunsigned int vpu_get_venc_hw_capa(struct platform_device *pdev);
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci/**
1628c2ecf20Sopenharmony_ci * vpu_load_firmware - download VPU firmware and boot it
1638c2ecf20Sopenharmony_ci *
1648c2ecf20Sopenharmony_ci * @pdev:	VPU platform device
1658c2ecf20Sopenharmony_ci *
1668c2ecf20Sopenharmony_ci * Return: Return 0 if downloading firmware successfully,
1678c2ecf20Sopenharmony_ci * otherwise it is failed
1688c2ecf20Sopenharmony_ci **/
1698c2ecf20Sopenharmony_ciint vpu_load_firmware(struct platform_device *pdev);
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci/**
1728c2ecf20Sopenharmony_ci * vpu_mapping_dm_addr - Mapping DTCM/DMEM to kernel virtual address
1738c2ecf20Sopenharmony_ci *
1748c2ecf20Sopenharmony_ci * @pdev:	VPU platform device
1758c2ecf20Sopenharmony_ci * @dmem_addr:	VPU's data memory address
1768c2ecf20Sopenharmony_ci *
1778c2ecf20Sopenharmony_ci * Mapping the VPU's DTCM (Data Tightly-Coupled Memory) /
1788c2ecf20Sopenharmony_ci * DMEM (Data Extended Memory) memory address to
1798c2ecf20Sopenharmony_ci * kernel virtual address.
1808c2ecf20Sopenharmony_ci *
1818c2ecf20Sopenharmony_ci * Return: Return ERR_PTR(-EINVAL) if mapping failed,
1828c2ecf20Sopenharmony_ci * otherwise the mapped kernel virtual address
1838c2ecf20Sopenharmony_ci **/
1848c2ecf20Sopenharmony_civoid *vpu_mapping_dm_addr(struct platform_device *pdev,
1858c2ecf20Sopenharmony_ci			  u32 dtcm_dmem_addr);
1868c2ecf20Sopenharmony_ci#endif /* _MTK_VPU_H */
187