4 * Copyright (C) 2014 Akihiro Tsukada <tskd08@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation version 2.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
20 #include <linux/atomic.h>
21 #include <linux/types.h>
23 #include <media/dvb_demux.h>
24 #include <media/dvb_frontend.h>
25 #include <media/dmxdev.h>
29 #include "qm1d1c0042.h"
31 #define DRV_NAME KBUILD_MODNAME
36 * register index of the FPGA chip
38 #define REG_VERSION 0x00
40 #define REG_SYSTEM_W 0x08
41 #define REG_SYSTEM_R 0x0c
42 #define REG_I2C_W 0x10
43 #define REG_I2C_R 0x14
44 #define REG_RAM_W 0x18
45 #define REG_RAM_R 0x1c
46 #define REG_DMA_BASE 0x40 /* regs for FE[i] = REG_DMA_BASE + 0x18 * i */
47 #define OFST_DMA_DESC_L 0x00
48 #define OFST_DMA_DESC_H 0x04
49 #define OFST_DMA_CTL 0x08
50 #define OFST_TS_CTL 0x0c
51 #define OFST_STATUS 0x10
52 #define OFST_TS_ERR 0x14
55 * internal buffer for I2C
57 #define PT3_I2C_MAX 4091
67 #define TS_PACKET_SZ 188
68 /* DMA transfers must not cross 4GiB, so use one page / transfer */
69 #define DATA_XFER_SZ 4096
70 #define DATA_BUF_XFERS 47
71 /* (num_bufs * DATA_BUF_SZ) % TS_PACKET_SZ must be 0 */
72 #define DATA_BUF_SZ (DATA_BUF_XFERS * DATA_XFER_SZ)
73 #define MAX_DATA_BUFS 16
74 #define MIN_DATA_BUFS 2
76 #define DESCS_IN_PAGE (PAGE_SIZE / sizeof(struct xfer_desc))
77 #define MAX_NUM_XFERS (MAX_DATA_BUFS * DATA_BUF_XFERS)
78 #define MAX_DESC_BUFS DIV_ROUND_UP(MAX_NUM_XFERS, DESCS_IN_PAGE)
80 /* DMA transfer description.
81 * device is passed a pointer to this struct, dma-reads it,
82 * and gets the DMA buffer ring for storing TS data.
85 u32 addr_l
; /* bus address of target data buffer */
88 u32 next_l
; /* bus adddress of the next xfer_desc */
92 /* A DMA mapping of a page containing xfer_desc's */
93 struct xfer_desc_buffer
{
95 struct xfer_desc
*descs
; /* PAGE_SIZE (xfer_desc[DESCS_IN_PAGE]) */
98 /* A DMA mapping of a data buffer */
99 struct dma_data_buffer
{
101 u8
*data
; /* size: u8[PAGE_SIZE] */
107 struct pt3_adap_config
{
108 struct i2c_board_info demod_info
;
109 struct tc90522_config demod_cfg
;
111 struct i2c_board_info tuner_info
;
113 struct qm1d1c0042_config qm1d1c0042
;
114 struct mxl301rf_config mxl301rf
;
120 struct dvb_adapter dvb_adap
; /* dvb_adap.priv => struct pt3_board */
123 struct dvb_demux demux
;
124 struct dmxdev dmxdev
;
125 struct dvb_frontend
*fe
;
126 struct i2c_client
*i2c_demod
;
127 struct i2c_client
*i2c_tuner
;
129 /* data fetch thread */
130 struct task_struct
*thread
;
134 bool cur_lnb
; /* current LNB power status (on/off) */
136 /* items below are for DMA */
137 struct dma_data_buffer buffer
[MAX_DATA_BUFS
];
140 int num_bufs
; /* == pt3_board->num_bufs */
141 int num_discard
; /* how many access units to discard initially */
143 struct xfer_desc_buffer desc_buf
[MAX_DESC_BUFS
];
144 int num_desc_bufs
; /* == num_bufs * DATA_BUF_XFERS / DESCS_IN_PAGE */
149 struct pci_dev
*pdev
;
150 void __iomem
*regs
[2];
151 /* regs[0]: registers, regs[1]: internal memory, used for I2C */
155 /* LNB power shared among sat-FEs */
156 int lnb_on_cnt
; /* LNB power on count */
158 /* LNA shared among terr-FEs */
159 int lna_on_cnt
; /* booster enabled count */
161 int num_bufs
; /* number of DMA buffers allocated/mapped per FE */
163 struct i2c_adapter i2c_adap
;
164 struct pt3_i2cbuf
*i2c_buf
;
166 struct pt3_adapter
*adaps
[PT3_NUM_FE
];
173 extern int pt3_alloc_dmabuf(struct pt3_adapter
*adap
);
174 extern void pt3_init_dmabuf(struct pt3_adapter
*adap
);
175 extern void pt3_free_dmabuf(struct pt3_adapter
*adap
);
176 extern int pt3_start_dma(struct pt3_adapter
*adap
);
177 extern int pt3_stop_dma(struct pt3_adapter
*adap
);
178 extern int pt3_proc_dma(struct pt3_adapter
*adap
);
180 extern int pt3_i2c_master_xfer(struct i2c_adapter
*adap
,
181 struct i2c_msg
*msgs
, int num
);
182 extern u32
pt3_i2c_functionality(struct i2c_adapter
*adap
);
183 extern void pt3_i2c_reset(struct pt3_board
*pt3
);
184 extern int pt3_init_all_demods(struct pt3_board
*pt3
);
185 extern int pt3_init_all_mxl301rf(struct pt3_board
*pt3
);