1 /* 2 * linux-5.4/drivers/media/platform/sunxi-vin/utility/vin_os.h 3 * 4 * Copyright (c) 2007-2017 Allwinnertech Co., Ltd. 5 * 6 * This software is licensed under the terms of the GNU General Public 7 * License version 2, as published by the Free Software Foundation, and 8 * may be copied, distributed, and modified under those terms. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 */ 16 17 #ifndef __VIN__OS__H__ 18 #define __VIN__OS__H__ 19 20 #include <linux/device.h> 21 #include <linux/clk.h> 22 //#include <sunxi-clk.h> 23 #include <linux/interrupt.h> 24 #include "../platform/platform_cfg.h" 25 26 #ifdef SUNXI_MEM 27 #include <linux/ion.h> /*for all "ion api"*/ 28 #include <linux/dma-mapping.h> /*just include "PAGE_SIZE" macro*/ 29 #else 30 #include <linux/dma-mapping.h> 31 #endif 32 33 #define ION_HEAP_SYSTEM_MASK (1 << 0) 34 #define ION_HEAP_TYPE_DMA_MASK (1 << 1) 35 36 #define IS_FLAG(x, y) (((x)&(y)) == y) 37 38 #define VIN_LOG_MD (1 << 0) /*0x1 */ 39 #define VIN_LOG_FLASH (1 << 1) /*0x2 */ 40 #define VIN_LOG_CCI (1 << 2) /*0x4 */ 41 #define VIN_LOG_CSI (1 << 3) /*0x8 */ 42 #define VIN_LOG_MIPI (1 << 4) /*0x10*/ 43 #define VIN_LOG_ISP (1 << 5) /*0x20*/ 44 #define VIN_LOG_STAT (1 << 6) /*0x40*/ 45 #define VIN_LOG_SCALER (1 << 7) /*0x80*/ 46 #define VIN_LOG_POWER (1 << 8) /*0x100*/ 47 #define VIN_LOG_CONFIG (1 << 9) /*0x200*/ 48 #define VIN_LOG_VIDEO (1 << 10) /*0x400*/ 49 #define VIN_LOG_FMT (1 << 11) /*0x800*/ 50 #define VIN_LOG_TDM (1 << 12) /*0x1000*/ 51 52 extern unsigned int vin_log_mask; 53 #if defined CONFIG_VIN_LOG 54 #define vin_log(flag, arg...) do { \ 55 if (flag & vin_log_mask) { \ 56 switch (flag) { \ 57 case VIN_LOG_MD: \ 58 printk(KERN_DEBUG "[VIN_LOG_MD]" arg); \ 59 break; \ 60 case VIN_LOG_FLASH: \ 61 printk(KERN_DEBUG "[VIN_LOG_FLASH]" arg); \ 62 break; \ 63 case VIN_LOG_CCI: \ 64 printk(KERN_DEBUG "[VIN_LOG_CCI]" arg); \ 65 break; \ 66 case VIN_LOG_CSI: \ 67 printk(KERN_DEBUG "[VIN_LOG_CSI]" arg); \ 68 break; \ 69 case VIN_LOG_MIPI: \ 70 printk(KERN_DEBUG "[VIN_LOG_MIPI]" arg); \ 71 break; \ 72 case VIN_LOG_ISP: \ 73 printk(KERN_DEBUG "[VIN_LOG_ISP]" arg); \ 74 break; \ 75 case VIN_LOG_STAT: \ 76 printk(KERN_DEBUG "[VIN_LOG_STAT]" arg); \ 77 break; \ 78 case VIN_LOG_SCALER: \ 79 printk(KERN_DEBUG "[VIN_LOG_SCALER]" arg); \ 80 break; \ 81 case VIN_LOG_POWER: \ 82 printk(KERN_DEBUG "[VIN_LOG_POWER]" arg); \ 83 break; \ 84 case VIN_LOG_CONFIG: \ 85 printk(KERN_DEBUG "[VIN_LOG_CONFIG]" arg); \ 86 break; \ 87 case VIN_LOG_VIDEO: \ 88 printk(KERN_DEBUG "[VIN_LOG_VIDEO]" arg); \ 89 break; \ 90 case VIN_LOG_FMT: \ 91 printk(KERN_DEBUG "[VIN_LOG_FMT]" arg); \ 92 break; \ 93 case VIN_LOG_TDM: \ 94 printk(KERN_DEBUG "[VIN_LOG_TDM]" arg); \ 95 break; \ 96 default: \ 97 printk(KERN_DEBUG "[VIN_LOG]" arg); \ 98 break; \ 99 } \ 100 } \ 101 } while (0) 102 #else 103 #define vin_log(flag, arg...) do { } while (0) 104 #endif 105 #define vin_err(x, arg...) pr_err("[VIN_ERR]"x, ##arg) 106 #define vin_warn(x, arg...) pr_warn("[VIN_WARN]"x, ##arg) 107 #define vin_print(x, arg...) pr_info("[VIN]"x, ##arg) 108 109 struct vin_mm { 110 size_t size; 111 void *phy_addr; 112 void *vir_addr; 113 void *dma_addr; 114 struct dma_buf *buf; 115 struct dma_buf_attachment *attachment; 116 struct sg_table *sgt; 117 //struct ion_heap *heap; 118 struct dma_heap *dmaHeap; 119 }; 120 121 extern int os_gpio_set(struct gpio_config *gpio_list); 122 extern int os_gpio_write(u32 gpio, __u32 out_value, int force_value_flag); 123 extern int os_mem_alloc(struct device *dev, struct vin_mm *mem_man); 124 extern void os_mem_free(struct device *dev, struct vin_mm *mem_man); 125 126 #endif /*__VIN__OS__H__*/ 127