2 * Copyright (C) 2015 VanguardiaSur - www.vanguardiasur.com.ar
4 * Copyright (C) 2015 Industrial Research Institute for Automation
5 * and Measurements PIAP
6 * Written by Krzysztof Ha?asa
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License
10 * as published by the Free Software Foundation.
13 #include <linux/mutex.h>
14 #include <linux/pci.h>
15 #include <linux/timer.h>
16 #include <linux/videodev2.h>
17 #include <media/v4l2-common.h>
18 #include <media/v4l2-ctrls.h>
19 #include <media/v4l2-device.h>
20 #include <media/v4l2-ioctl.h>
21 #include <media/videobuf2-v4l2.h>
22 #include <sound/pcm.h>
24 #include "tw686x-regs.h"
26 #define TYPE_MAX_CHANNELS 0x0f
27 #define TYPE_SECOND_GEN 0x10
28 #define TW686X_DEF_PHASE_REF 0x1518
30 #define TW686X_FIELD_MODE 0x3
31 #define TW686X_FRAME_MODE 0x2
33 #define TW686X_SG_MODE 0x0
35 #define TW686X_AUDIO_PAGE_SZ 4096
36 #define TW686X_AUDIO_PAGE_MAX 16
37 #define TW686X_AUDIO_PERIODS_MIN 2
38 #define TW686X_AUDIO_PERIODS_MAX TW686X_AUDIO_PAGE_MAX
40 struct tw686x_format {
47 struct tw686x_dma_desc {
53 struct tw686x_audio_buf {
56 struct list_head list;
59 struct tw686x_v4l2_buf {
60 struct vb2_v4l2_buffer vb;
61 struct list_head list;
64 struct tw686x_audio_channel {
65 struct tw686x_dev *dev;
66 struct snd_pcm_substream *ss;
68 struct tw686x_audio_buf *curr_bufs[2];
69 struct tw686x_dma_desc dma_descs[2];
72 struct tw686x_audio_buf buf[TW686X_AUDIO_PAGE_MAX];
73 struct list_head buf_list;
77 struct tw686x_video_channel {
78 struct tw686x_dev *dev;
80 struct vb2_queue vidq;
81 struct list_head vidq_queued;
82 struct video_device *device;
83 struct tw686x_v4l2_buf *curr_bufs[2];
84 struct tw686x_dma_desc dma_descs[2];
86 struct v4l2_ctrl_handler ctrl_handler;
87 const struct tw686x_format *format;
88 struct mutex vb_mutex;
90 v4l2_std_id video_standard;
91 unsigned int width, height;
92 unsigned int h_halve, v_halve;
97 unsigned int sequence;
103 * struct tw686x_dev - global device status
104 * @lock: spinlock controlling access to the
105 * shared device registers (DMA enable/disable).
110 struct v4l2_device v4l2_dev;
111 struct snd_card *snd_card;
115 struct pci_dev *pci_dev;
120 struct tw686x_video_channel *video_channels;
121 struct tw686x_audio_channel *audio_channels;
123 int audio_rate; /* per-device value */
125 struct timer_list dma_delay_timer;
126 u32 pending_dma_en; /* must be protected by lock */
127 u32 pending_dma_cmd; /* must be protected by lock */
130 static inline uint32_t reg_read(struct tw686x_dev *dev, unsigned int reg)
132 return readl(dev->mmio + reg);
135 static inline void reg_write(struct tw686x_dev *dev, unsigned int reg,
138 writel(value, dev->mmio + reg);
141 static inline unsigned int max_channels(struct tw686x_dev *dev)
143 return dev->type & TYPE_MAX_CHANNELS; /* 4 or 8 channels */
146 void tw686x_enable_channel(struct tw686x_dev *dev, unsigned int channel);
147 void tw686x_disable_channel(struct tw686x_dev *dev, unsigned int channel);
149 int tw686x_video_init(struct tw686x_dev *dev);
150 void tw686x_video_free(struct tw686x_dev *dev);
151 void tw686x_video_irq(struct tw686x_dev *dev, unsigned long requests,
152 unsigned int pb_status, unsigned int fifo_status,
153 unsigned int *reset_ch);
155 int tw686x_audio_init(struct tw686x_dev *dev);
156 void tw686x_audio_free(struct tw686x_dev *dev);
157 void tw686x_audio_irq(struct tw686x_dev *dev, unsigned long requests,
158 unsigned int pb_status);