summaryrefslogtreecommitdiff
path: root/drivers/stream_input/parser/hw_demux/aml_dvb.h (plain)
blob: f936f15efb3b092a4b3466d35adf0f47c1ed875c
1/*
2* Copyright (C) 2017 Amlogic, Inc. All rights reserved.
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful, but WITHOUT
10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12* more details.
13*
14* You should have received a copy of the GNU General Public License along
15* with this program; if not, write to the Free Software Foundation, Inc.,
16* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*
18* Description:
19*/
20#ifndef _AML_DVB_H_
21#define _AML_DVB_H_
22
23#include <linux/interrupt.h>
24#include <linux/socket.h>
25#include <linux/netdevice.h>
26#include <linux/i2c.h>
27
28#include <linux/dvb/video.h>
29#include <linux/dvb/audio.h>
30#include <linux/dvb/dmx.h>
31#include <linux/dvb/ca.h>
32#include <linux/dvb/osd.h>
33#include <linux/dvb/net.h>
34#include <linux/dvb/frontend.h>
35
36#include <linux/mutex.h>
37#include <linux/spinlock.h>
38#include <linux/interrupt.h>
39
40#ifdef CONFIG_HAS_EARLYSUSPEND
41#include <linux/earlysuspend.h>
42#endif
43
44
45#include <dvbdev.h>
46#include <demux.h>
47#include <dvb_demux.h>
48#include <dmxdev.h>
49#include <dvb_filter.h>
50#include <dvb_net.h>
51#include <dvb_ringbuffer.h>
52
53#include <linux/of.h>
54#include <linux/pinctrl/consumer.h>
55
56#include "aml_demod_gt.h"
57
58#define TS_IN_COUNT 4
59#define S2P_COUNT 3
60#define ASYNCFIFO_COUNT 3
61#if 0
62#define TS_IN_COUNT 3
63#define S2P_COUNT 2
64#define ASYNCFIFO_COUNT 2
65#endif
66
67#define DMX_DEV_COUNT 3
68#define FE_DEV_COUNT 2
69#define CHANNEL_COUNT 31
70#define FILTER_COUNT 31
71#define FILTER_LEN 15
72#define DSC_DEV_COUNT 2
73#define DSC_COUNT 8
74#define SEC_BUF_GRP_COUNT 4
75#define SEC_BUF_BUSY_SIZE 4
76#define SEC_BUF_COUNT (SEC_BUF_GRP_COUNT*8)
77
78enum aml_dmx_id_t {
79 AM_DMX_0 = 0,
80 AM_DMX_1,
81 AM_DMX_2,
82 AM_DMX_MAX,
83};
84
85enum aml_ts_source_t {
86 AM_TS_SRC_TS0,
87 AM_TS_SRC_TS1,
88 AM_TS_SRC_TS2,
89 AM_TS_SRC_TS3,
90
91 AM_TS_SRC_S_TS0,
92 AM_TS_SRC_S_TS1,
93 AM_TS_SRC_S_TS2,
94 AM_TS_SRC_S_TS3,
95
96 AM_TS_SRC_HIU,
97 AM_TS_SRC_HIU1,
98 AM_TS_SRC_DMX0,
99 AM_TS_SRC_DMX1,
100 AM_TS_SRC_DMX2
101};
102
103struct aml_sec_buf {
104 unsigned long addr;
105 int len;
106};
107
108struct aml_channel {
109 int type;
110 enum dmx_ts_pes pes_type;
111 int pid;
112 int used;
113 int filter_count;
114 struct dvb_demux_feed *feed;
115 struct dvb_demux_feed *dvr_feed;
116};
117
118struct aml_filter {
119 int chan_id;
120 int used;
121 struct dmx_section_filter *filter;
122 u8 value[FILTER_LEN];
123 u8 maskandmode[FILTER_LEN];
124 u8 maskandnotmode[FILTER_LEN];
125 u8 neq;
126};
127
128#define DVBCSA_MODE 0
129#define CIPLUS_MODE 1
130#define CBC_MODE 0
131#define ECB_MODE 1
132#define IDSA_MODE 2
133
134#define DSC_SET_EVEN 1
135#define DSC_SET_ODD 2
136#define DSC_SET_AES_EVEN 4
137#define DSC_SET_AES_ODD 8
138#define DSC_FROM_KL 16
139#define DSC_SET_SM4_EVEN 32
140#define DSC_SET_SM4_ODD 64
141
142#define DSC_KEY_SIZE_MAX 16
143
144struct aml_dsc_channel {
145 int pid;
146 u8 even[DSC_KEY_SIZE_MAX];
147 u8 odd[DSC_KEY_SIZE_MAX];
148 u8 even_iv[DSC_KEY_SIZE_MAX];
149 u8 odd_iv[DSC_KEY_SIZE_MAX];
150 int used;
151 int set;
152 int id;
153 struct aml_dsc *dsc;
154 int work_mode;
155 int mode;
156};
157
158struct aml_dsc {
159 struct dvb_device *dev;
160 struct aml_dsc_channel channel[DSC_COUNT];
161 enum aml_ts_source_t source;
162 enum aml_ts_source_t dst;
163 struct aml_dvb *dvb;
164 int id;
165 int work_mode;
166};
167
168struct aml_smallsec {
169 struct aml_dmx *dmx;
170
171 int enable;
172 int bufsize;
173#define SS_BUFSIZE_DEF (16*4*256) /*16KB*/
174 long buf;
175 long buf_map;
176};
177
178struct aml_dmxtimeout {
179 struct aml_dmx *dmx;
180
181 int enable;
182
183 int timeout;
184#define DTO_TIMEOUT_DEF (9000) /*0.5s*/
185 u32 ch_disable;
186#define DTO_CHDIS_VAS (0xfffffff8) /*v/a/s only*/
187 int match;
188
189 int trigger;
190};
191
192struct aml_dmx {
193 struct dvb_demux demux;
194 struct dmxdev dmxdev;
195 int id;
196 int feed_count;
197 int chan_count;
198 enum aml_ts_source_t source;
199 int init;
200 int record;
201 struct dmx_frontend hw_fe[DMX_DEV_COUNT];
202 struct dmx_frontend mem_fe;
203 struct dvb_net dvb_net;
204 int dmx_irq;
205 int dvr_irq;
206 struct tasklet_struct dmx_tasklet;
207 struct tasklet_struct dvr_tasklet;
208 unsigned long sec_pages;
209 unsigned long sec_pages_map;
210 int sec_total_len;
211 struct aml_sec_buf sec_buf[SEC_BUF_COUNT];
212 unsigned long pes_pages;
213 unsigned long pes_pages_map;
214 int pes_buf_len;
215 union {
216 unsigned long sub_pages;
217 unsigned long sub_buf_base;
218 };
219 union {
220 unsigned long sub_pages_map;
221 u8 *sub_buf_base_virt;
222 };
223 int sub_buf_len;
224
225 struct aml_channel channel[CHANNEL_COUNT+1];
226 struct aml_filter filter[FILTER_COUNT+1];
227 irq_handler_t irq_handler;
228 void *irq_data;
229 int aud_chan;
230 int vid_chan;
231 int sub_chan;
232 int pcr_chan;
233 u32 section_busy[SEC_BUF_BUSY_SIZE];
234 struct dvb_frontend *fe;
235 int int_check_count;
236 u32 int_check_time;
237 int in_tune;
238 int error_check;
239 int dump_ts_select;
240 int sec_buf_watchdog_count[SEC_BUF_COUNT];
241
242 struct aml_smallsec smallsec;
243 struct aml_dmxtimeout timeout;
244
245 int demux_filter_user;
246
247 unsigned long sec_cnt[3];
248 unsigned long sec_cnt_match[3];
249 unsigned long sec_cnt_crc_fail[3];
250 #define SEC_CNT_HW (0)
251 #define SEC_CNT_SW (1)
252 #define SEC_CNT_SS (2)
253 #define SEC_CNT_MAX (3)
254
255 int crc_check_count;
256 u32 crc_check_time;
257};
258
259struct aml_dvr_block {
260 u32 addr;
261 u32 len;
262};
263
264struct aml_asyncfifo {
265 int id;
266 int init;
267 int asyncfifo_irq;
268 enum aml_dmx_id_t source;
269 unsigned long pages;
270 unsigned long pages_map;
271 int buf_len;
272 int buf_toggle;
273 int buf_read;
274 int flush_size;
275 int secure_enable;
276 struct tasklet_struct asyncfifo_tasklet;
277 struct aml_dvb *dvb;
278 struct aml_dvr_block blk;
279};
280
281enum{
282 AM_TS_DISABLE,
283 AM_TS_PARALLEL,
284 AM_TS_SERIAL
285};
286
287struct aml_ts_input {
288 int mode;
289 struct pinctrl *pinctrl;
290 int control;
291 int s2p_id;
292};
293
294struct aml_s2p {
295 int invert;
296};
297
298struct aml_swfilter {
299 int user;
300 struct aml_dmx *dmx;
301 struct aml_asyncfifo *afifo;
302
303 struct dvb_ringbuffer rbuf;
304#define SF_BUFFER_SIZE (10*188*1024)
305
306 u8 wrapbuf[188];
307 int track_dmx;
308};
309
310struct aml_dvb {
311 struct dvb_device dvb_dev;
312 int ts_in_total_count;
313 struct aml_ts_input ts[TS_IN_COUNT];
314 int s2p_total_count;
315 struct aml_s2p s2p[S2P_COUNT];
316 struct aml_dmx dmx[DMX_DEV_COUNT];
317 struct aml_dsc dsc[DSC_DEV_COUNT];
318 int async_fifo_total_count;
319 struct aml_asyncfifo asyncfifo[ASYNCFIFO_COUNT];
320 struct dvb_adapter dvb_adapter;
321 struct device *dev;
322 struct platform_device *pdev;
323 enum aml_ts_source_t stb_source;
324 enum aml_ts_source_t tso_source;
325 int dmx_init;
326 int reset_flag;
327 spinlock_t slock;
328 struct timer_list watchdog_timer;
329 int dmx_watchdog_disable[DMX_DEV_COUNT];
330 struct aml_swfilter swfilter;
331 int ts_out_invert;
332
333 unsigned int tuner_num;
334 unsigned int tuner_cur;
335 struct aml_tuner *tuners;
336 bool tuner_attached;
337
338 /*bufs for dmx shared*/
339 unsigned long pes_pages;
340 unsigned long pes_pages_map;
341 int pes_buf_len;
342 unsigned long sub_pages;
343 unsigned long sub_pages_map;
344 int sub_buf_len;
345
346
347};
348
349
350/*AMLogic demux interface*/
351extern int aml_dmx_hw_init(struct aml_dmx *dmx);
352extern int aml_dmx_hw_deinit(struct aml_dmx *dmx);
353extern int aml_dmx_hw_start_feed(struct dvb_demux_feed *dvbdmxfeed);
354extern int aml_dmx_hw_stop_feed(struct dvb_demux_feed *dvbdmxfeed);
355extern int aml_dmx_hw_set_source(struct dmx_demux *demux,
356 dmx_source_t src);
357extern int aml_stb_hw_set_source(struct aml_dvb *dvb, dmx_source_t src);
358extern int aml_dsc_hw_set_source(struct aml_dsc *dsc,
359 dmx_source_t src, dmx_source_t dst);
360extern int aml_tso_hw_set_source(struct aml_dvb *dvb, dmx_source_t src);
361extern int aml_dmx_set_skipbyte(struct aml_dvb *dvb, int skipbyte);
362extern int aml_dmx_set_demux(struct aml_dvb *dvb, int id);
363extern int aml_dmx_hw_set_dump_ts_select
364 (struct dmx_demux *demux, int dump_ts_select);
365
366extern int dmx_alloc_chan(struct aml_dmx *dmx, int type,
367 int pes_type, int pid);
368extern void dmx_free_chan(struct aml_dmx *dmx, int cid);
369
370extern int dmx_get_ts_serial(enum aml_ts_source_t src);
371
372extern int dmx_get_sub_buffer(unsigned long *base, unsigned long *virt);
373extern int dmx_init_sub_buffer(struct aml_dmx *dmx, unsigned long base, unsigned long virt);
374
375/*AMLogic dsc interface*/
376extern int dsc_set_pid(struct aml_dsc_channel *ch, int pid);
377extern int dsc_set_key(struct aml_dsc_channel *ch, int flags,
378 enum ca_cw_type type, u8 *key);
379extern void dsc_release(void);
380extern int aml_ciplus_hw_set_source(int src);
381
382/*AMLogic ASYNC FIFO interface*/
383extern int aml_asyncfifo_hw_init(struct aml_asyncfifo *afifo);
384extern int aml_asyncfifo_hw_deinit(struct aml_asyncfifo *afifo);
385extern int aml_asyncfifo_hw_set_source(struct aml_asyncfifo *afifo,
386 enum aml_dmx_id_t src);
387extern int aml_asyncfifo_hw_reset(struct aml_asyncfifo *afifo);
388
389/*Get the Audio & Video PTS*/
390extern u32 aml_dmx_get_video_pts(struct aml_dvb *dvb);
391extern u32 aml_dmx_get_audio_pts(struct aml_dvb *dvb);
392extern u32 aml_dmx_get_video_pts_bit32(struct aml_dvb *dvb);
393extern u32 aml_dmx_get_audio_pts_bit32(struct aml_dvb *dvb);
394extern u32 aml_dmx_get_first_video_pts(struct aml_dvb *dvb);
395extern u32 aml_dmx_get_first_audio_pts(struct aml_dvb *dvb);
396
397/*Get the DVB device*/
398extern struct aml_dvb *aml_get_dvb_device(void);
399
400extern int aml_regist_dmx_class(void);
401extern int aml_unregist_dmx_class(void);
402extern void aml_register_parser_mconfig(void);
403
404struct devio_aml_platform_data {
405 int (*io_setup)(void *);
406 int (*io_cleanup)(void *);
407 int (*io_power)(void *, int enable);
408 int (*io_reset)(void *, int enable);
409};
410
411void get_aml_dvb(struct aml_dvb *dvb_device);
412
413/*Reset the demux device*/
414void dmx_reset_hw(struct aml_dvb *dvb);
415void dmx_reset_hw_ex(struct aml_dvb *dvb, int reset_irq);
416
417/*Reset the individual demux*/
418void dmx_reset_dmx_hw(struct aml_dvb *dvb, int id);
419void dmx_reset_dmx_id_hw_ex(struct aml_dvb *dvb, int id, int reset_irq);
420void dmx_reset_dmx_id_hw_ex_unlock(struct aml_dvb *dvb, int id, int reset_irq);
421void dmx_reset_dmx_hw_ex(struct aml_dvb *dvb,
422 struct aml_dmx *dmx,
423 int reset_irq);
424void dmx_reset_dmx_hw_ex_unlock(struct aml_dvb *dvb,
425 struct aml_dmx *dmx,
426 int reset_irq);
427
428#endif
429
430