]> rtime.felk.cvut.cz Git - zynq/linux.git/blob - drivers/media/platform/xilinx/xilinx-scenechange.h
v4l: xilinx: scd: Request IRQ after completing initialization
[zynq/linux.git] / drivers / media / platform / xilinx / xilinx-scenechange.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Xilinx Scene Change Detection driver
4  *
5  * Copyright (C) 2018 Xilinx, Inc.
6  *
7  * Authors: Anand Ashok Dumbre <anand.ashok.dumbre@xilinx.com>
8  *          Satish Kumar Nagireddy <satish.nagireddy.nagireddy@xilinx.com>
9  */
10
11 #ifndef _XILINX_SCENECHANGE_H_
12 #define _XILINX_SCENECHANGE_H_
13
14 #include <linux/clk.h>
15 #include <linux/delay.h>
16 #include <linux/dmaengine.h>
17 #include <linux/gpio/consumer.h>
18 #include <linux/interrupt.h>
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/of.h>
22 #include <linux/platform_device.h>
23 #include <linux/xilinx-v4l2-controls.h>
24
25 #include <media/v4l2-async.h>
26 #include <media/v4l2-ctrls.h>
27 #include <media/v4l2-device.h>
28 #include <media/v4l2-subdev.h>
29 #include "../../../dma/dmaengine.h"
30
31 /* Register/Descriptor Offsets */
32 #define XSCD_CTRL_OFFSET                0x000
33 #define XSCD_CTRL_AP_START              BIT(0)
34 #define XSCD_CTRL_AP_DONE               BIT(1)
35 #define XSCD_CTRL_AP_IDLE               BIT(2)
36 #define XSCD_CTRL_AP_READY              BIT(3)
37 #define XSCD_CTRL_AUTO_RESTART          BIT(7)
38
39 #define XSCD_GIE_OFFSET                 0x004
40 #define XSCD_GIE_EN                     BIT(0)
41
42 #define XSCD_IE_OFFSET                  0x008
43 #define XSCD_IE_AP_DONE                 BIT(0)
44 #define XSCD_IE_AP_READY                BIT(1)
45
46 #define XSCD_ISR_OFFSET                 0x00c
47 #define XSCD_WIDTH_OFFSET               0x010
48 #define XSCD_HEIGHT_OFFSET              0x018
49 #define XSCD_STRIDE_OFFSET              0x020
50 #define XSCD_VID_FMT_OFFSET             0x028
51 #define XSCD_VID_FMT_RGB                0
52 #define XSCD_VID_FMT_YUV_444            1
53 #define XSCD_VID_FMT_YUV_422            2
54 #define XSCD_VID_FMT_YUV_420            3
55 #define XSCD_VID_FMT_Y8                 24
56 #define XSCD_VID_FMT_Y10                25
57
58 #define XSCD_SUBSAMPLE_OFFSET           0x030
59 #define XSCD_SAD_OFFSET                 0x038
60 #define XSCD_ADDR_OFFSET                0x040
61 #define XSCD_CHAN_OFFSET                0x100
62 #define XSCD_CHAN_EN_OFFSET             0x780
63
64 #define XSCD_MAX_CHANNELS               8
65
66 /****************************** PROTOTYPES ************************************/
67
68 struct xscd_device;
69
70 /**
71  * struct xscd_dma_desc - DMA channel
72  * @luma_plane_addr: Luma plane buffer address
73  * @vsize: width of the luma frame
74  * @hsize: height of the luma frame
75  * @stride: stride of the luma frame
76  */
77 struct xscd_dma_desc {
78         dma_addr_t luma_plane_addr;
79         u32 vsize;
80         u32 hsize;
81         u32 stride;
82 };
83
84 /**
85  * struct xscd_dma_tx_descriptor - Per Transaction structure
86  * @async_tx: Async transaction descriptor
87  * @sw: Software Descriptor
88  * @node: Node in the channel descriptor list
89  */
90 struct xscd_dma_tx_descriptor {
91         struct dma_async_tx_descriptor async_tx;
92         struct xscd_dma_desc sw;
93         struct list_head node;
94 };
95
96 static inline struct xscd_dma_tx_descriptor *
97 to_xscd_dma_tx_descriptor(struct dma_async_tx_descriptor *tx)
98 {
99         return container_of(tx, struct xscd_dma_tx_descriptor, async_tx);
100 }
101
102 /**
103  * struct xscd_dma_chan - DMA Channel structure
104  * @xscd: SCD device
105  * @iomem: I/O memory address of the channel registers
106  * @lock: Descriptor operation lock
107  * @chan_node: Member of a list of framebuffer channel instances
108  * @pending_list: Descriptors waiting
109  * @done_list: Complete descriptors
110  * @staged_desc: Next buffer to be programmed
111  * @active_desc: Currently active buffer being read/written to
112  * @common: DMA common channel
113  * @idle: Channel idle state
114  * @tasklet: Cleanup work after irq
115  * @id: scene change channel ID
116  * @en: Channel is enabled
117  * @valid_interrupt: Valid interrupt for the channel
118  */
119 struct xscd_dma_chan {
120         struct xscd_device *xscd;
121         void __iomem *iomem;
122
123         /* Descriptor operation Lock */
124         spinlock_t lock;
125         struct list_head chan_node;
126         struct list_head pending_list;
127         struct list_head done_list;
128         struct xscd_dma_tx_descriptor *staged_desc;
129         struct xscd_dma_tx_descriptor *active_desc;
130         struct dma_chan common;
131         bool idle;
132         struct tasklet_struct tasklet;
133         u8 id;
134         bool en;
135         bool valid_interrupt;
136 };
137
138 static inline struct xscd_dma_chan *to_xscd_dma_chan(struct dma_chan *chan)
139 {
140         return container_of(chan, struct xscd_dma_chan, common);
141 }
142
143 /**
144  * struct xscd_chan - Video Stream structure
145  * @id: scene change channel ID
146  * @iomem: I/O memory address of the channel registers
147  * @xscd: SCD device
148  * @subdev: V4L2 subdevice
149  * @pads: media pads
150  * @format: active V4L2 media bus format for the pad
151  * @event: scene change event
152  * @dmachan: dma channel part of the scenechange stream
153  * @lock: lock to protect active stream count variable
154  */
155 struct xscd_chan {
156         int id;
157         void __iomem *iomem;
158         struct xscd_device *xscd;
159         struct v4l2_subdev subdev;
160         struct media_pad pads[2];
161         struct v4l2_mbus_framefmt format;
162         struct v4l2_event event;
163         struct xscd_dma_chan dmachan;
164
165         /* Lock to protect active stream count */
166         struct mutex lock;
167 };
168
169 static inline struct xscd_chan *to_xscd_chan(struct v4l2_subdev *subdev)
170 {
171         return container_of(subdev, struct xscd_chan, subdev);
172 }
173
174 /**
175  * struct xscd_device - Xilinx Scene Change Detection device structure
176  * @dev: (OF) device
177  * @iomem: device I/O register space remapped to kernel virtual memory
178  * @rst_gpio: reset GPIO
179  * @clk: video core clock
180  * @irq: Device IRQ
181  * @memory_based: Flag to identify memory based mode
182  * @num_streams: Number of streams in the design
183  * @chans: video stream instances
184  * @dma_device: DMA device structure
185  * @channels: DMA channels
186  * @active_streams: Number of active streams
187  */
188 struct xscd_device {
189         struct device *dev;
190         void __iomem *iomem;
191         struct gpio_desc *rst_gpio;
192         struct clk *clk;
193         int irq;
194
195         u8 memory_based;
196         int num_streams;
197
198         struct xscd_chan *chans[XSCD_MAX_CHANNELS];
199
200         struct dma_device dma_device;
201         struct xscd_dma_chan *channels[XSCD_MAX_CHANNELS];
202         u8 active_streams;
203 };
204
205 /*
206  * Register related operations
207  */
208 static inline u32 xscd_read(void __iomem *iomem, u32 addr)
209 {
210         return ioread32(iomem + addr);
211 }
212
213 static inline void xscd_write(void __iomem *iomem, u32 addr, u32 value)
214 {
215         iowrite32(value, iomem + addr);
216 }
217
218 static inline void xscd_clr(void __iomem *iomem, u32 addr, u32 clr)
219 {
220         xscd_write(iomem, addr, xscd_read(iomem, addr) & ~clr);
221 }
222
223 static inline void xscd_set(void __iomem *iomem, u32 addr, u32 set)
224 {
225         xscd_write(iomem, addr, xscd_read(iomem, addr) | set);
226 }
227
228 void xscd_dma_start_transfer(struct xscd_dma_chan *chan);
229 void xscd_dma_start(struct xscd_dma_chan *chan);
230 void xscd_dma_chan_enable(struct xscd_dma_chan *chan, int chan_en);
231 void xscd_dma_reset(struct xscd_dma_chan *chan);
232 void xscd_dma_halt(struct xscd_dma_chan *chan);
233 void xscd_dma_irq_handler(struct xscd_device *xscd);
234 int xscd_dma_init(struct xscd_device *xscd);
235 void xscd_dma_cleanup(struct xscd_device *xscd);
236
237 void xscd_chan_irq_handler(struct xscd_chan *chan);
238 int xscd_chan_init(struct xscd_device *xscd, unsigned int chan_id,
239                    struct device_node *node);
240 #endif