1/* 2 * Xilinx Framebuffer DMA support header file 3 * 4 * Copyright (C) 2017 Xilinx, Inc. All rights reserved. 5 * 6 * This is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 */ 11 12#ifndef __XILINX_FRMBUF_DMA_H 13#define __XILINX_FRMBUF_DMA_H 14 15#include <linux/dmaengine.h> 16 17/* Modes to enable early callback */ 18/* To avoid first frame delay */ 19#define EARLY_CALLBACK BIT(1) 20/* Give callback at start of descriptor processing */ 21#define EARLY_CALLBACK_START_DESC BIT(2) 22/** 23 * enum vid_frmwork_type - Linux video framework type 24 * @XDMA_DRM: fourcc is of type DRM 25 * @XDMA_V4L2: fourcc is of type V4L2 26 */ 27enum vid_frmwork_type { 28 XDMA_DRM = 0, 29 XDMA_V4L2, 30}; 31 32/** 33 * enum operation_mode - FB IP control register field settings to select mode 34 * @DEFAULT : Use default mode, No explicit bit field settings required. 35 * @AUTO_RESTART : Use auto-restart mode by setting BIT(7) of control register. 36 */ 37enum operation_mode { 38 DEFAULT = 0x0, 39 AUTO_RESTART = BIT(7), 40}; 41 42/** 43 * enum fid_modes - FB IP fid mode register settings to select mode 44 * @FID_MODE_0: carries the fid value shared by application 45 * @FID_MODE_1: sets the fid after first frame 46 * @FID_MODE_2: sets the fid after second frame 47 */ 48enum fid_modes { 49 FID_MODE_0 = 0, 50 FID_MODE_1 = 1, 51 FID_MODE_2 = 2, 52}; 53 54#if IS_ENABLED(CONFIG_XILINX_FRMBUF) 55/** 56 * xilinx_xdma_set_mode - Set operation mode for framebuffer IP 57 * @chan: dma channel instance 58 * @mode: Famebuffer IP operation mode. 59 * This routine is used when utilizing "video format aware" Xilinx DMA IP 60 * (such as Video Framebuffer Read or Video Framebuffer Write). This call 61 * must be made prior to dma_async_issue_pending(). This routine should be 62 * called by client driver to set the operation mode for framebuffer IP based 63 * upon the use-case, for e.g. for non-streaming usecases (like MEM2MEM) it's 64 * more appropriate to use default mode unlike streaming usecases where 65 * auto-restart mode is more suitable. 66 * 67 * auto-restart or free running mode. 68 */ 69void xilinx_xdma_set_mode(struct dma_chan *chan, enum operation_mode mode); 70 71/** 72 * xilinx_xdma_drm_config - configure video format in video aware DMA 73 * @chan: dma channel instance 74 * @drm_fourcc: DRM fourcc code describing the memory layout of video data 75 * 76 * This routine is used when utilizing "video format aware" Xilinx DMA IP 77 * (such as Video Framebuffer Read or Video Framebuffer Write). This call 78 * must be made prior to dma_async_issue_pending() to establish the video 79 * data memory format within the hardware DMA. 80 */ 81void xilinx_xdma_drm_config(struct dma_chan *chan, u32 drm_fourcc); 82 83/** 84 * xilinx_xdma_v4l2_config - configure video format in video aware DMA 85 * @chan: dma channel instance 86 * @v4l2_fourcc: V4L2 fourcc code describing the memory layout of video data 87 * 88 * This routine is used when utilizing "video format aware" Xilinx DMA IP 89 * (such as Video Framebuffer Read or Video Framebuffer Write). This call 90 * must be made prior to dma_async_issue_pending() to establish the video 91 * data memory format within the hardware DMA. 92 */ 93void xilinx_xdma_v4l2_config(struct dma_chan *chan, u32 v4l2_fourcc); 94 95/** 96 * xilinx_xdma_get_drm_vid_fmts - obtain list of supported DRM mem formats 97 * @chan: dma channel instance 98 * @fmt_cnt: Output param - total count of supported DRM fourcc codes 99 * @fmts: Output param - pointer to array of DRM fourcc codes (not a copy) 100 * 101 * Return: a reference to an array of DRM fourcc codes supported by this 102 * instance of the Video Framebuffer Driver 103 */ 104int xilinx_xdma_get_drm_vid_fmts(struct dma_chan *chan, u32 *fmt_cnt, 105 u32 **fmts); 106 107/** 108 * xilinx_xdma_get_v4l2_vid_fmts - obtain list of supported V4L2 mem formats 109 * @chan: dma channel instance 110 * @fmt_cnt: Output param - total count of supported V4L2 fourcc codes 111 * @fmts: Output param - pointer to array of V4L2 fourcc codes (not a copy) 112 * 113 * Return: a reference to an array of V4L2 fourcc codes supported by this 114 * instance of the Video Framebuffer Driver 115 */ 116int xilinx_xdma_get_v4l2_vid_fmts(struct dma_chan *chan, u32 *fmt_cnt, 117 u32 **fmts); 118 119/** 120 * xilinx_xdma_get_fid - Get the Field ID of the buffer received. 121 * This function should be called from the callback function registered 122 * per descriptor in prep_interleaved. 123 * 124 * @chan: dma channel instance 125 * @async_tx: descriptor whose parent structure contains fid. 126 * @fid: Output param - Field ID of the buffer. 0 - even, 1 - odd. 127 * 128 * Return: 0 on success, -EINVAL in case of invalid chan 129 */ 130int xilinx_xdma_get_fid(struct dma_chan *chan, 131 struct dma_async_tx_descriptor *async_tx, u32 *fid); 132 133/** 134 * xilinx_xdma_set_fid - Set the Field ID of the buffer to be transmitted 135 * @chan: dma channel instance 136 * @async_tx: dma async tx descriptor for the buffer 137 * @fid: Field ID of the buffer. 0 - even, 1 - odd. 138 * 139 * Return: 0 on success, -EINVAL in case of invalid chan 140 */ 141int xilinx_xdma_set_fid(struct dma_chan *chan, 142 struct dma_async_tx_descriptor *async_tx, u32 fid); 143 144/** 145 * xilinx_xdma_get_fid_err_flag - Get the Field ID error flag. 146 * 147 * @chan: dma channel instance 148 * @fid_err_flag: Field id error detect flag. 0 - no error, 1 - error. 149 * 150 * Return: 0 on success, -EINVAL in case of invalid chan 151 */ 152int xilinx_xdma_get_fid_err_flag(struct dma_chan *chan, 153 u32 *fid_err_flag); 154 155/** 156 * xilinx_xdma_get_fid_out - Get the Field ID out signal value. 157 * 158 * @chan: dma channel instance 159 * @fid_out_val: Field id out signal value. 160 * 161 * Return: 0 on success, -EINVAL in case of invalid chan 162 */ 163int xilinx_xdma_get_fid_out(struct dma_chan *chan, 164 u32 *fid_out_val); 165 166/**: 167 * xilinx_xdma_get_earlycb - Get info if early callback has been enabled. 168 * 169 * @chan: dma channel instance 170 * @async_tx: descriptor whose parent structure contains fid. 171 * @earlycb: Output param - Early callback mode 172 * 173 * Return: 0 on success, -EINVAL in case of invalid chan 174 */ 175int xilinx_xdma_get_earlycb(struct dma_chan *chan, 176 struct dma_async_tx_descriptor *async_tx, 177 u32 *earlycb); 178 179/** 180 * xilinx_xdma_set_earlycb - Enable/Disable early callback 181 * @chan: dma channel instance 182 * @async_tx: dma async tx descriptor for the buffer 183 * @earlycb: Enable early callback mode for descriptor 184 * 185 * Return: 0 on success, -EINVAL in case of invalid chan 186 */ 187int xilinx_xdma_set_earlycb(struct dma_chan *chan, 188 struct dma_async_tx_descriptor *async_tx, 189 u32 earlycb); 190/** 191 * xilinx_xdma_get_width_align - Get width alignment value 192 * 193 * @chan: dma channel instance 194 * @width_align: width alignment value 195 * 196 * Return: 0 on success, -ENODEV in case no framebuffer device found 197 */ 198int xilinx_xdma_get_width_align(struct dma_chan *chan, u32 *width_align); 199 200#else 201static inline void xilinx_xdma_set_mode(struct dma_chan *chan, 202 enum operation_mode mode) 203{ } 204 205static inline void xilinx_xdma_drm_config(struct dma_chan *chan, u32 drm_fourcc) 206{ } 207 208static inline void xilinx_xdma_v4l2_config(struct dma_chan *chan, 209 u32 v4l2_fourcc) 210{ } 211 212static inline int xilinx_xdma_get_drm_vid_fmts(struct dma_chan *chan, 213 u32 *fmt_cnt, u32 **fmts) 214{ 215 return -ENODEV; 216} 217 218static inline int xilinx_xdma_get_v4l2_vid_fmts(struct dma_chan *chan, 219 u32 *fmt_cnt,u32 **fmts) 220{ 221 return -ENODEV; 222} 223 224static inline int xilinx_xdma_get_fid(struct dma_chan *chan, 225 struct dma_async_tx_descriptor *async_tx, 226 u32 *fid) 227{ 228 return -ENODEV; 229} 230 231static inline int xilinx_xdma_set_fid(struct dma_chan *chan, 232 struct dma_async_tx_descriptor *async_tx, 233 u32 fid) 234{ 235 return -ENODEV; 236} 237 238static inline int xilinx_xdma_get_earlycb(struct dma_chan *chan, 239 struct dma_async_tx_descriptor *atx, 240 u32 *earlycb) 241{ 242 return -ENODEV; 243} 244 245static inline int xilinx_xdma_set_earlycb(struct dma_chan *chan, 246 struct dma_async_tx_descriptor *atx, 247 u32 earlycb) 248{ 249 return -ENODEV; 250} 251 252static inline int xilinx_xdma_get_width_align(struct dma_chan *chan, u32 *width_align) 253{ 254 return -ENODEV; 255} 256#endif 257 258#endif /*__XILINX_FRMBUF_DMA_H*/ 259