2 * Driver for the Conexant CX25821 PCIe bridge
4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26 #include <linux/i2c.h>
27 #include <linux/slab.h>
29 #include "cx25821-sram.h"
30 #include "cx25821-video.h"
32 MODULE_DESCRIPTION("Driver for Athena cards");
33 MODULE_AUTHOR("Shu Lin - Hiep Huynh");
34 MODULE_LICENSE("GPL");
36 static unsigned int debug
;
37 module_param(debug
, int, 0644);
38 MODULE_PARM_DESC(debug
, "enable debug messages");
40 static unsigned int card
[] = {[0 ... (CX25821_MAXBOARDS
- 1)] = UNSET
};
41 module_param_array(card
, int, NULL
, 0444);
42 MODULE_PARM_DESC(card
, "card type");
44 static unsigned int cx25821_devcount
;
46 DEFINE_MUTEX(cx25821_devlist_mutex
);
47 EXPORT_SYMBOL(cx25821_devlist_mutex
);
48 LIST_HEAD(cx25821_devlist
);
49 EXPORT_SYMBOL(cx25821_devlist
);
51 struct sram_channel cx25821_sram_channels
[] = {
55 .cmds_start
= VID_A_DOWN_CMDS
,
56 .ctrl_start
= VID_A_IQ
,
58 .fifo_start
= VID_A_DOWN_CLUSTER_1
,
59 .fifo_size
= (VID_CLUSTER_SIZE
<< 2),
60 .ptr1_reg
= DMA1_PTR1
,
61 .ptr2_reg
= DMA1_PTR2
,
62 .cnt1_reg
= DMA1_CNT1
,
63 .cnt2_reg
= DMA1_CNT2
,
64 .int_msk
= VID_A_INT_MSK
,
65 .int_stat
= VID_A_INT_STAT
,
66 .int_mstat
= VID_A_INT_MSTAT
,
67 .dma_ctl
= VID_DST_A_DMA_CTL
,
68 .gpcnt_ctl
= VID_DST_A_GPCNT_CTL
,
69 .gpcnt
= VID_DST_A_GPCNT
,
70 .vip_ctl
= VID_DST_A_VIP_CTL
,
71 .pix_frmt
= VID_DST_A_PIX_FRMT
,
77 .cmds_start
= VID_B_DOWN_CMDS
,
78 .ctrl_start
= VID_B_IQ
,
80 .fifo_start
= VID_B_DOWN_CLUSTER_1
,
81 .fifo_size
= (VID_CLUSTER_SIZE
<< 2),
82 .ptr1_reg
= DMA2_PTR1
,
83 .ptr2_reg
= DMA2_PTR2
,
84 .cnt1_reg
= DMA2_CNT1
,
85 .cnt2_reg
= DMA2_CNT2
,
86 .int_msk
= VID_B_INT_MSK
,
87 .int_stat
= VID_B_INT_STAT
,
88 .int_mstat
= VID_B_INT_MSTAT
,
89 .dma_ctl
= VID_DST_B_DMA_CTL
,
90 .gpcnt_ctl
= VID_DST_B_GPCNT_CTL
,
91 .gpcnt
= VID_DST_B_GPCNT
,
92 .vip_ctl
= VID_DST_B_VIP_CTL
,
93 .pix_frmt
= VID_DST_B_PIX_FRMT
,
99 .cmds_start
= VID_C_DOWN_CMDS
,
100 .ctrl_start
= VID_C_IQ
,
102 .fifo_start
= VID_C_DOWN_CLUSTER_1
,
103 .fifo_size
= (VID_CLUSTER_SIZE
<< 2),
104 .ptr1_reg
= DMA3_PTR1
,
105 .ptr2_reg
= DMA3_PTR2
,
106 .cnt1_reg
= DMA3_CNT1
,
107 .cnt2_reg
= DMA3_CNT2
,
108 .int_msk
= VID_C_INT_MSK
,
109 .int_stat
= VID_C_INT_STAT
,
110 .int_mstat
= VID_C_INT_MSTAT
,
111 .dma_ctl
= VID_DST_C_DMA_CTL
,
112 .gpcnt_ctl
= VID_DST_C_GPCNT_CTL
,
113 .gpcnt
= VID_DST_C_GPCNT
,
114 .vip_ctl
= VID_DST_C_VIP_CTL
,
115 .pix_frmt
= VID_DST_C_PIX_FRMT
,
121 .cmds_start
= VID_D_DOWN_CMDS
,
122 .ctrl_start
= VID_D_IQ
,
124 .fifo_start
= VID_D_DOWN_CLUSTER_1
,
125 .fifo_size
= (VID_CLUSTER_SIZE
<< 2),
126 .ptr1_reg
= DMA4_PTR1
,
127 .ptr2_reg
= DMA4_PTR2
,
128 .cnt1_reg
= DMA4_CNT1
,
129 .cnt2_reg
= DMA4_CNT2
,
130 .int_msk
= VID_D_INT_MSK
,
131 .int_stat
= VID_D_INT_STAT
,
132 .int_mstat
= VID_D_INT_MSTAT
,
133 .dma_ctl
= VID_DST_D_DMA_CTL
,
134 .gpcnt_ctl
= VID_DST_D_GPCNT_CTL
,
135 .gpcnt
= VID_DST_D_GPCNT
,
136 .vip_ctl
= VID_DST_D_VIP_CTL
,
137 .pix_frmt
= VID_DST_D_PIX_FRMT
,
143 .cmds_start
= VID_E_DOWN_CMDS
,
144 .ctrl_start
= VID_E_IQ
,
146 .fifo_start
= VID_E_DOWN_CLUSTER_1
,
147 .fifo_size
= (VID_CLUSTER_SIZE
<< 2),
148 .ptr1_reg
= DMA5_PTR1
,
149 .ptr2_reg
= DMA5_PTR2
,
150 .cnt1_reg
= DMA5_CNT1
,
151 .cnt2_reg
= DMA5_CNT2
,
152 .int_msk
= VID_E_INT_MSK
,
153 .int_stat
= VID_E_INT_STAT
,
154 .int_mstat
= VID_E_INT_MSTAT
,
155 .dma_ctl
= VID_DST_E_DMA_CTL
,
156 .gpcnt_ctl
= VID_DST_E_GPCNT_CTL
,
157 .gpcnt
= VID_DST_E_GPCNT
,
158 .vip_ctl
= VID_DST_E_VIP_CTL
,
159 .pix_frmt
= VID_DST_E_PIX_FRMT
,
165 .cmds_start
= VID_F_DOWN_CMDS
,
166 .ctrl_start
= VID_F_IQ
,
168 .fifo_start
= VID_F_DOWN_CLUSTER_1
,
169 .fifo_size
= (VID_CLUSTER_SIZE
<< 2),
170 .ptr1_reg
= DMA6_PTR1
,
171 .ptr2_reg
= DMA6_PTR2
,
172 .cnt1_reg
= DMA6_CNT1
,
173 .cnt2_reg
= DMA6_CNT2
,
174 .int_msk
= VID_F_INT_MSK
,
175 .int_stat
= VID_F_INT_STAT
,
176 .int_mstat
= VID_F_INT_MSTAT
,
177 .dma_ctl
= VID_DST_F_DMA_CTL
,
178 .gpcnt_ctl
= VID_DST_F_GPCNT_CTL
,
179 .gpcnt
= VID_DST_F_GPCNT
,
180 .vip_ctl
= VID_DST_F_VIP_CTL
,
181 .pix_frmt
= VID_DST_F_PIX_FRMT
,
187 .cmds_start
= VID_G_DOWN_CMDS
,
188 .ctrl_start
= VID_G_IQ
,
190 .fifo_start
= VID_G_DOWN_CLUSTER_1
,
191 .fifo_size
= (VID_CLUSTER_SIZE
<< 2),
192 .ptr1_reg
= DMA7_PTR1
,
193 .ptr2_reg
= DMA7_PTR2
,
194 .cnt1_reg
= DMA7_CNT1
,
195 .cnt2_reg
= DMA7_CNT2
,
196 .int_msk
= VID_G_INT_MSK
,
197 .int_stat
= VID_G_INT_STAT
,
198 .int_mstat
= VID_G_INT_MSTAT
,
199 .dma_ctl
= VID_DST_G_DMA_CTL
,
200 .gpcnt_ctl
= VID_DST_G_GPCNT_CTL
,
201 .gpcnt
= VID_DST_G_GPCNT
,
202 .vip_ctl
= VID_DST_G_VIP_CTL
,
203 .pix_frmt
= VID_DST_G_PIX_FRMT
,
209 .cmds_start
= VID_H_DOWN_CMDS
,
210 .ctrl_start
= VID_H_IQ
,
212 .fifo_start
= VID_H_DOWN_CLUSTER_1
,
213 .fifo_size
= (VID_CLUSTER_SIZE
<< 2),
214 .ptr1_reg
= DMA8_PTR1
,
215 .ptr2_reg
= DMA8_PTR2
,
216 .cnt1_reg
= DMA8_CNT1
,
217 .cnt2_reg
= DMA8_CNT2
,
218 .int_msk
= VID_H_INT_MSK
,
219 .int_stat
= VID_H_INT_STAT
,
220 .int_mstat
= VID_H_INT_MSTAT
,
221 .dma_ctl
= VID_DST_H_DMA_CTL
,
222 .gpcnt_ctl
= VID_DST_H_GPCNT_CTL
,
223 .gpcnt
= VID_DST_H_GPCNT
,
224 .vip_ctl
= VID_DST_H_VIP_CTL
,
225 .pix_frmt
= VID_DST_H_PIX_FRMT
,
229 .name
= "audio from",
230 .cmds_start
= AUD_A_DOWN_CMDS
,
231 .ctrl_start
= AUD_A_IQ
,
233 .fifo_start
= AUD_A_DOWN_CLUSTER_1
,
234 .fifo_size
= AUDIO_CLUSTER_SIZE
* 3,
235 .ptr1_reg
= DMA17_PTR1
,
236 .ptr2_reg
= DMA17_PTR2
,
237 .cnt1_reg
= DMA17_CNT1
,
238 .cnt2_reg
= DMA17_CNT2
,
243 .name
= "VID Upstream I",
244 .cmds_start
= VID_I_UP_CMDS
,
245 .ctrl_start
= VID_I_IQ
,
247 .fifo_start
= VID_I_UP_CLUSTER_1
,
248 .fifo_size
= (VID_CLUSTER_SIZE
<< 2),
249 .ptr1_reg
= DMA15_PTR1
,
250 .ptr2_reg
= DMA15_PTR2
,
251 .cnt1_reg
= DMA15_CNT1
,
252 .cnt2_reg
= DMA15_CNT2
,
253 .int_msk
= VID_I_INT_MSK
,
254 .int_stat
= VID_I_INT_STAT
,
255 .int_mstat
= VID_I_INT_MSTAT
,
256 .dma_ctl
= VID_SRC_I_DMA_CTL
,
257 .gpcnt_ctl
= VID_SRC_I_GPCNT_CTL
,
258 .gpcnt
= VID_SRC_I_GPCNT
,
260 .vid_fmt_ctl
= VID_SRC_I_FMT_CTL
,
261 .vid_active_ctl1
= VID_SRC_I_ACTIVE_CTL1
,
262 .vid_active_ctl2
= VID_SRC_I_ACTIVE_CTL2
,
263 .vid_cdt_size
= VID_SRC_I_CDT_SZ
,
269 .name
= "VID Upstream J",
270 .cmds_start
= VID_J_UP_CMDS
,
271 .ctrl_start
= VID_J_IQ
,
273 .fifo_start
= VID_J_UP_CLUSTER_1
,
274 .fifo_size
= (VID_CLUSTER_SIZE
<< 2),
275 .ptr1_reg
= DMA16_PTR1
,
276 .ptr2_reg
= DMA16_PTR2
,
277 .cnt1_reg
= DMA16_CNT1
,
278 .cnt2_reg
= DMA16_CNT2
,
279 .int_msk
= VID_J_INT_MSK
,
280 .int_stat
= VID_J_INT_STAT
,
281 .int_mstat
= VID_J_INT_MSTAT
,
282 .dma_ctl
= VID_SRC_J_DMA_CTL
,
283 .gpcnt_ctl
= VID_SRC_J_GPCNT_CTL
,
284 .gpcnt
= VID_SRC_J_GPCNT
,
286 .vid_fmt_ctl
= VID_SRC_J_FMT_CTL
,
287 .vid_active_ctl1
= VID_SRC_J_ACTIVE_CTL1
,
288 .vid_active_ctl2
= VID_SRC_J_ACTIVE_CTL2
,
289 .vid_cdt_size
= VID_SRC_J_CDT_SZ
,
295 .name
= "Audio Upstream Channel B",
296 .cmds_start
= AUD_B_UP_CMDS
,
297 .ctrl_start
= AUD_B_IQ
,
299 .fifo_start
= AUD_B_UP_CLUSTER_1
,
300 .fifo_size
= (AUDIO_CLUSTER_SIZE
* 3),
301 .ptr1_reg
= DMA22_PTR1
,
302 .ptr2_reg
= DMA22_PTR2
,
303 .cnt1_reg
= DMA22_CNT1
,
304 .cnt2_reg
= DMA22_CNT2
,
305 .int_msk
= AUD_B_INT_MSK
,
306 .int_stat
= AUD_B_INT_STAT
,
307 .int_mstat
= AUD_B_INT_MSTAT
,
308 .dma_ctl
= AUD_INT_DMA_CTL
,
309 .gpcnt_ctl
= AUD_B_GPCNT_CTL
,
310 .gpcnt
= AUD_B_GPCNT
,
311 .aud_length
= AUD_B_LNGTH
,
312 .aud_cfg
= AUD_B_CFG
,
313 .fld_aud_fifo_en
= FLD_AUD_SRC_B_FIFO_EN
,
314 .fld_aud_risc_en
= FLD_AUD_SRC_B_RISC_EN
,
318 EXPORT_SYMBOL(cx25821_sram_channels
);
320 struct sram_channel
*channel0
= &cx25821_sram_channels
[SRAM_CH00
];
321 struct sram_channel
*channel1
= &cx25821_sram_channels
[SRAM_CH01
];
322 struct sram_channel
*channel2
= &cx25821_sram_channels
[SRAM_CH02
];
323 struct sram_channel
*channel3
= &cx25821_sram_channels
[SRAM_CH03
];
324 struct sram_channel
*channel4
= &cx25821_sram_channels
[SRAM_CH04
];
325 struct sram_channel
*channel5
= &cx25821_sram_channels
[SRAM_CH05
];
326 struct sram_channel
*channel6
= &cx25821_sram_channels
[SRAM_CH06
];
327 struct sram_channel
*channel7
= &cx25821_sram_channels
[SRAM_CH07
];
328 struct sram_channel
*channel9
= &cx25821_sram_channels
[SRAM_CH09
];
329 struct sram_channel
*channel10
= &cx25821_sram_channels
[SRAM_CH10
];
330 struct sram_channel
*channel11
= &cx25821_sram_channels
[SRAM_CH11
];
332 struct cx25821_dmaqueue mpegq
;
334 static int cx25821_risc_decode(u32 risc
)
336 static const char * const instr
[16] = {
337 [RISC_SYNC
>> 28] = "sync",
338 [RISC_WRITE
>> 28] = "write",
339 [RISC_WRITEC
>> 28] = "writec",
340 [RISC_READ
>> 28] = "read",
341 [RISC_READC
>> 28] = "readc",
342 [RISC_JUMP
>> 28] = "jump",
343 [RISC_SKIP
>> 28] = "skip",
344 [RISC_WRITERM
>> 28] = "writerm",
345 [RISC_WRITECM
>> 28] = "writecm",
346 [RISC_WRITECR
>> 28] = "writecr",
348 static const int incr
[16] = {
349 [RISC_WRITE
>> 28] = 3,
350 [RISC_JUMP
>> 28] = 3,
351 [RISC_SKIP
>> 28] = 1,
352 [RISC_SYNC
>> 28] = 1,
353 [RISC_WRITERM
>> 28] = 3,
354 [RISC_WRITECM
>> 28] = 3,
355 [RISC_WRITECR
>> 28] = 4,
357 static const char * const bits
[] = {
358 "12", "13", "14", "resync",
359 "cnt0", "cnt1", "18", "19",
360 "20", "21", "22", "23",
361 "irq1", "irq2", "eol", "sol",
365 pr_cont("0x%08x [ %s",
366 risc
, instr
[risc
>> 28] ? instr
[risc
>> 28] : "INVALID");
367 for (i
= ARRAY_SIZE(bits
) - 1; i
>= 0; i
--) {
368 if (risc
& (1 << (i
+ 12)))
369 pr_cont(" %s", bits
[i
]);
371 pr_cont(" count=%d ]\n", risc
& 0xfff);
372 return incr
[risc
>> 28] ? incr
[risc
>> 28] : 1;
375 static inline int i2c_slave_did_ack(struct i2c_adapter
*i2c_adap
)
377 struct cx25821_i2c
*bus
= i2c_adap
->algo_data
;
378 struct cx25821_dev
*dev
= bus
->dev
;
379 return cx_read(bus
->reg_stat
) & 0x01;
382 void cx_i2c_read_print(struct cx25821_dev
*dev
, u32 reg
, const char *reg_string
)
387 value
= cx25821_i2c_read(&dev
->i2c_bus
[0], reg
, &tmp
);
390 static void cx25821_registers_init(struct cx25821_dev
*dev
)
394 /* enable RUN_RISC in Pecos */
395 cx_write(DEV_CNTRL2
, 0x20);
397 /* Set the master PCI interrupt masks to enable video, audio, MBIF,
398 * and GPIO interrupts
399 * I2C interrupt masking is handled by the I2C objects themselves. */
400 cx_write(PCI_INT_MSK
, 0x2001FFFF);
402 tmp
= cx_read(RDR_TLCTL0
);
403 tmp
&= ~FLD_CFG_RCB_CK_EN
; /* Clear the RCB_CK_EN bit */
404 cx_write(RDR_TLCTL0
, tmp
);
406 /* PLL-A setting for the Audio Master Clock */
407 cx_write(PLL_A_INT_FRAC
, 0x9807A58B);
409 /* PLL_A_POST = 0x1C, PLL_A_OUT_TO_PIN = 0x1 */
410 cx_write(PLL_A_POST_STAT_BIST
, 0x8000019C);
412 /* clear reset bit [31] */
413 tmp
= cx_read(PLL_A_INT_FRAC
);
414 cx_write(PLL_A_INT_FRAC
, tmp
& 0x7FFFFFFF);
416 /* PLL-B setting for Mobilygen Host Bus Interface */
417 cx_write(PLL_B_INT_FRAC
, 0x9883A86F);
419 /* PLL_B_POST = 0xD, PLL_B_OUT_TO_PIN = 0x0 */
420 cx_write(PLL_B_POST_STAT_BIST
, 0x8000018D);
422 /* clear reset bit [31] */
423 tmp
= cx_read(PLL_B_INT_FRAC
);
424 cx_write(PLL_B_INT_FRAC
, tmp
& 0x7FFFFFFF);
426 /* PLL-C setting for video upstream channel */
427 cx_write(PLL_C_INT_FRAC
, 0x96A0EA3F);
429 /* PLL_C_POST = 0x3, PLL_C_OUT_TO_PIN = 0x0 */
430 cx_write(PLL_C_POST_STAT_BIST
, 0x80000103);
432 /* clear reset bit [31] */
433 tmp
= cx_read(PLL_C_INT_FRAC
);
434 cx_write(PLL_C_INT_FRAC
, tmp
& 0x7FFFFFFF);
436 /* PLL-D setting for audio upstream channel */
437 cx_write(PLL_D_INT_FRAC
, 0x98757F5B);
439 /* PLL_D_POST = 0x13, PLL_D_OUT_TO_PIN = 0x0 */
440 cx_write(PLL_D_POST_STAT_BIST
, 0x80000113);
442 /* clear reset bit [31] */
443 tmp
= cx_read(PLL_D_INT_FRAC
);
444 cx_write(PLL_D_INT_FRAC
, tmp
& 0x7FFFFFFF);
446 /* This selects the PLL C clock source for the video upstream channel
448 tmp
= cx_read(VID_CH_CLK_SEL
);
449 cx_write(VID_CH_CLK_SEL
, (tmp
& 0x00FFFFFF) | 0x24000000);
451 /* 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for
453 * select 656/VIP DST for downstream Channel A - C */
454 tmp
= cx_read(VID_CH_MODE_SEL
);
455 /* cx_write( VID_CH_MODE_SEL, tmp | 0x1B0001FF); */
456 cx_write(VID_CH_MODE_SEL
, tmp
& 0xFFFFFE00);
458 /* enables 656 port I and J as output */
459 tmp
= cx_read(CLK_RST
);
460 /* use external ALT_PLL_REF pin as its reference clock instead */
461 tmp
|= FLD_USE_ALT_PLL_REF
;
462 cx_write(CLK_RST
, tmp
& ~(FLD_VID_I_CLK_NOE
| FLD_VID_J_CLK_NOE
));
467 int cx25821_sram_channel_setup(struct cx25821_dev
*dev
,
468 struct sram_channel
*ch
,
469 unsigned int bpl
, u32 risc
)
471 unsigned int i
, lines
;
474 if (ch
->cmds_start
== 0) {
475 cx_write(ch
->ptr1_reg
, 0);
476 cx_write(ch
->ptr2_reg
, 0);
477 cx_write(ch
->cnt2_reg
, 0);
478 cx_write(ch
->cnt1_reg
, 0);
482 bpl
= (bpl
+ 7) & ~7; /* alignment */
484 lines
= ch
->fifo_size
/ bpl
;
491 cx_write(8 + 0, RISC_JUMP
| RISC_IRQ1
| RISC_CNT_INC
);
496 for (i
= 0; i
< lines
; i
++) {
497 cx_write(cdt
+ 16 * i
, ch
->fifo_start
+ bpl
* i
);
498 cx_write(cdt
+ 16 * i
+ 4, 0);
499 cx_write(cdt
+ 16 * i
+ 8, 0);
500 cx_write(cdt
+ 16 * i
+ 12, 0);
503 /* init the first cdt buffer */
504 for (i
= 0; i
< 128; i
++)
505 cx_write(ch
->fifo_start
+ 4 * i
, i
);
509 cx_write(ch
->cmds_start
+ 0, 8);
511 cx_write(ch
->cmds_start
+ 0, risc
);
513 cx_write(ch
->cmds_start
+ 4, 0); /* 64 bits 63-32 */
514 cx_write(ch
->cmds_start
+ 8, cdt
);
515 cx_write(ch
->cmds_start
+ 12, (lines
* 16) >> 3);
516 cx_write(ch
->cmds_start
+ 16, ch
->ctrl_start
);
519 cx_write(ch
->cmds_start
+ 20, 0x80000000 | (64 >> 2));
521 cx_write(ch
->cmds_start
+ 20, 64 >> 2);
523 for (i
= 24; i
< 80; i
+= 4)
524 cx_write(ch
->cmds_start
+ i
, 0);
527 cx_write(ch
->ptr1_reg
, ch
->fifo_start
);
528 cx_write(ch
->ptr2_reg
, cdt
);
529 cx_write(ch
->cnt2_reg
, (lines
* 16) >> 3);
530 cx_write(ch
->cnt1_reg
, (bpl
>> 3) - 1);
534 EXPORT_SYMBOL(cx25821_sram_channel_setup
);
536 int cx25821_sram_channel_setup_audio(struct cx25821_dev
*dev
,
537 struct sram_channel
*ch
,
538 unsigned int bpl
, u32 risc
)
540 unsigned int i
, lines
;
543 if (ch
->cmds_start
== 0) {
544 cx_write(ch
->ptr1_reg
, 0);
545 cx_write(ch
->ptr2_reg
, 0);
546 cx_write(ch
->cnt2_reg
, 0);
547 cx_write(ch
->cnt1_reg
, 0);
551 bpl
= (bpl
+ 7) & ~7; /* alignment */
553 lines
= ch
->fifo_size
/ bpl
;
556 lines
= 3; /* for AUDIO */
560 cx_write(8 + 0, RISC_JUMP
| RISC_IRQ1
| RISC_CNT_INC
);
565 for (i
= 0; i
< lines
; i
++) {
566 cx_write(cdt
+ 16 * i
, ch
->fifo_start
+ bpl
* i
);
567 cx_write(cdt
+ 16 * i
+ 4, 0);
568 cx_write(cdt
+ 16 * i
+ 8, 0);
569 cx_write(cdt
+ 16 * i
+ 12, 0);
574 cx_write(ch
->cmds_start
+ 0, 8);
576 cx_write(ch
->cmds_start
+ 0, risc
);
578 cx_write(ch
->cmds_start
+ 4, 0); /* 64 bits 63-32 */
579 cx_write(ch
->cmds_start
+ 8, cdt
);
580 cx_write(ch
->cmds_start
+ 12, (lines
* 16) >> 3);
581 cx_write(ch
->cmds_start
+ 16, ch
->ctrl_start
);
585 cx_write(ch
->cmds_start
+ 20, 0x80000000 | (64 >> 2));
587 cx_write(ch
->cmds_start
+ 20, 64 >> 2);
590 for (i
= 24; i
< 80; i
+= 4)
591 cx_write(ch
->cmds_start
+ i
, 0);
594 cx_write(ch
->ptr1_reg
, ch
->fifo_start
);
595 cx_write(ch
->ptr2_reg
, cdt
);
596 cx_write(ch
->cnt2_reg
, (lines
* 16) >> 3);
597 cx_write(ch
->cnt1_reg
, (bpl
>> 3) - 1);
601 EXPORT_SYMBOL(cx25821_sram_channel_setup_audio
);
603 void cx25821_sram_channel_dump(struct cx25821_dev
*dev
, struct sram_channel
*ch
)
605 static char *name
[] = {
622 unsigned int i
, j
, n
;
624 pr_warn("%s: %s - dma channel status dump\n", dev
->name
, ch
->name
);
625 for (i
= 0; i
< ARRAY_SIZE(name
); i
++)
626 pr_warn("cmds + 0x%2x: %-15s: 0x%08x\n",
627 i
* 4, name
[i
], cx_read(ch
->cmds_start
+ 4 * i
));
630 for (i
= 0; i
< 4;) {
631 risc
= cx_read(ch
->cmds_start
+ 4 * (i
+ 14));
632 pr_warn("cmds + 0x%2x: risc%d: ", j
+ i
* 4, i
);
633 i
+= cx25821_risc_decode(risc
);
636 for (i
= 0; i
< (64 >> 2); i
+= n
) {
637 risc
= cx_read(ch
->ctrl_start
+ 4 * i
);
638 /* No consideration for bits 63-32 */
640 pr_warn("ctrl + 0x%2x (0x%08x): iq %x: ",
641 i
* 4, ch
->ctrl_start
+ 4 * i
, i
);
642 n
= cx25821_risc_decode(risc
);
643 for (j
= 1; j
< n
; j
++) {
644 risc
= cx_read(ch
->ctrl_start
+ 4 * (i
+ j
));
645 pr_warn("ctrl + 0x%2x : iq %x: 0x%08x [ arg #%d ]\n",
646 4 * (i
+ j
), i
+ j
, risc
, j
);
650 pr_warn(" : fifo: 0x%08x -> 0x%x\n",
651 ch
->fifo_start
, ch
->fifo_start
+ ch
->fifo_size
);
652 pr_warn(" : ctrl: 0x%08x -> 0x%x\n",
653 ch
->ctrl_start
, ch
->ctrl_start
+ 6 * 16);
654 pr_warn(" : ptr1_reg: 0x%08x\n",
655 cx_read(ch
->ptr1_reg
));
656 pr_warn(" : ptr2_reg: 0x%08x\n",
657 cx_read(ch
->ptr2_reg
));
658 pr_warn(" : cnt1_reg: 0x%08x\n",
659 cx_read(ch
->cnt1_reg
));
660 pr_warn(" : cnt2_reg: 0x%08x\n",
661 cx_read(ch
->cnt2_reg
));
663 EXPORT_SYMBOL(cx25821_sram_channel_dump
);
665 void cx25821_sram_channel_dump_audio(struct cx25821_dev
*dev
,
666 struct sram_channel
*ch
)
668 static const char * const name
[] = {
685 u32 risc
, value
, tmp
;
686 unsigned int i
, j
, n
;
688 pr_info("\n%s: %s - dma Audio channel status dump\n",
689 dev
->name
, ch
->name
);
691 for (i
= 0; i
< ARRAY_SIZE(name
); i
++)
692 pr_info("%s: cmds + 0x%2x: %-15s: 0x%08x\n",
693 dev
->name
, i
* 4, name
[i
],
694 cx_read(ch
->cmds_start
+ 4 * i
));
697 for (i
= 0; i
< 4;) {
698 risc
= cx_read(ch
->cmds_start
+ 4 * (i
+ 14));
699 pr_warn("cmds + 0x%2x: risc%d: ", j
+ i
* 4, i
);
700 i
+= cx25821_risc_decode(risc
);
703 for (i
= 0; i
< (64 >> 2); i
+= n
) {
704 risc
= cx_read(ch
->ctrl_start
+ 4 * i
);
705 /* No consideration for bits 63-32 */
707 pr_warn("ctrl + 0x%2x (0x%08x): iq %x: ",
708 i
* 4, ch
->ctrl_start
+ 4 * i
, i
);
709 n
= cx25821_risc_decode(risc
);
711 for (j
= 1; j
< n
; j
++) {
712 risc
= cx_read(ch
->ctrl_start
+ 4 * (i
+ j
));
713 pr_warn("ctrl + 0x%2x : iq %x: 0x%08x [ arg #%d ]\n",
714 4 * (i
+ j
), i
+ j
, risc
, j
);
718 pr_warn(" : fifo: 0x%08x -> 0x%x\n",
719 ch
->fifo_start
, ch
->fifo_start
+ ch
->fifo_size
);
720 pr_warn(" : ctrl: 0x%08x -> 0x%x\n",
721 ch
->ctrl_start
, ch
->ctrl_start
+ 6 * 16);
722 pr_warn(" : ptr1_reg: 0x%08x\n",
723 cx_read(ch
->ptr1_reg
));
724 pr_warn(" : ptr2_reg: 0x%08x\n",
725 cx_read(ch
->ptr2_reg
));
726 pr_warn(" : cnt1_reg: 0x%08x\n",
727 cx_read(ch
->cnt1_reg
));
728 pr_warn(" : cnt2_reg: 0x%08x\n",
729 cx_read(ch
->cnt2_reg
));
731 for (i
= 0; i
< 4; i
++) {
732 risc
= cx_read(ch
->cmds_start
+ 56 + (i
* 4));
733 pr_warn("instruction %d = 0x%x\n", i
, risc
);
736 /* read data from the first cdt buffer */
737 risc
= cx_read(AUD_A_CDT
);
738 pr_warn("\nread cdt loc=0x%x\n", risc
);
739 for (i
= 0; i
< 8; i
++) {
740 n
= cx_read(risc
+ i
* 4);
745 value
= cx_read(CLK_RST
);
746 CX25821_INFO(" CLK_RST = 0x%x\n\n", value
);
748 value
= cx_read(PLL_A_POST_STAT_BIST
);
749 CX25821_INFO(" PLL_A_POST_STAT_BIST = 0x%x\n\n", value
);
750 value
= cx_read(PLL_A_INT_FRAC
);
751 CX25821_INFO(" PLL_A_INT_FRAC = 0x%x\n\n", value
);
753 value
= cx_read(PLL_B_POST_STAT_BIST
);
754 CX25821_INFO(" PLL_B_POST_STAT_BIST = 0x%x\n\n", value
);
755 value
= cx_read(PLL_B_INT_FRAC
);
756 CX25821_INFO(" PLL_B_INT_FRAC = 0x%x\n\n", value
);
758 value
= cx_read(PLL_C_POST_STAT_BIST
);
759 CX25821_INFO(" PLL_C_POST_STAT_BIST = 0x%x\n\n", value
);
760 value
= cx_read(PLL_C_INT_FRAC
);
761 CX25821_INFO(" PLL_C_INT_FRAC = 0x%x\n\n", value
);
763 value
= cx_read(PLL_D_POST_STAT_BIST
);
764 CX25821_INFO(" PLL_D_POST_STAT_BIST = 0x%x\n\n", value
);
765 value
= cx_read(PLL_D_INT_FRAC
);
766 CX25821_INFO(" PLL_D_INT_FRAC = 0x%x\n\n", value
);
768 value
= cx25821_i2c_read(&dev
->i2c_bus
[0], AFE_AB_DIAG_CTRL
, &tmp
);
769 CX25821_INFO(" AFE_AB_DIAG_CTRL (0x10900090) = 0x%x\n\n", value
);
771 EXPORT_SYMBOL(cx25821_sram_channel_dump_audio
);
773 static void cx25821_shutdown(struct cx25821_dev
*dev
)
777 /* disable RISC controller */
778 cx_write(DEV_CNTRL2
, 0);
780 /* Disable Video A/B activity */
781 for (i
= 0; i
< VID_CHANNEL_NUM
; i
++) {
782 cx_write(dev
->channels
[i
].sram_channels
->dma_ctl
, 0);
783 cx_write(dev
->channels
[i
].sram_channels
->int_msk
, 0);
786 for (i
= VID_UPSTREAM_SRAM_CHANNEL_I
;
787 i
<= VID_UPSTREAM_SRAM_CHANNEL_J
; i
++) {
788 cx_write(dev
->channels
[i
].sram_channels
->dma_ctl
, 0);
789 cx_write(dev
->channels
[i
].sram_channels
->int_msk
, 0);
792 /* Disable Audio activity */
793 cx_write(AUD_INT_DMA_CTL
, 0);
795 /* Disable Serial port */
796 cx_write(UART_CTL
, 0);
798 /* Disable Interrupts */
799 cx_write(PCI_INT_MSK
, 0);
800 cx_write(AUD_A_INT_MSK
, 0);
803 void cx25821_set_pixel_format(struct cx25821_dev
*dev
, int channel_select
,
806 if (channel_select
<= 7 && channel_select
>= 0) {
807 cx_write(dev
->channels
[channel_select
].sram_channels
->pix_frmt
,
809 dev
->channels
[channel_select
].pixel_formats
= format
;
813 static void cx25821_set_vip_mode(struct cx25821_dev
*dev
,
814 struct sram_channel
*ch
)
816 cx_write(ch
->pix_frmt
, PIXEL_FRMT_422
);
817 cx_write(ch
->vip_ctl
, PIXEL_ENGINE_VIP1
);
820 static void cx25821_initialize(struct cx25821_dev
*dev
)
824 dprintk(1, "%s()\n", __func__
);
826 cx25821_shutdown(dev
);
827 cx_write(PCI_INT_STAT
, 0xffffffff);
829 for (i
= 0; i
< VID_CHANNEL_NUM
; i
++)
830 cx_write(dev
->channels
[i
].sram_channels
->int_stat
, 0xffffffff);
832 cx_write(AUD_A_INT_STAT
, 0xffffffff);
833 cx_write(AUD_B_INT_STAT
, 0xffffffff);
834 cx_write(AUD_C_INT_STAT
, 0xffffffff);
835 cx_write(AUD_D_INT_STAT
, 0xffffffff);
836 cx_write(AUD_E_INT_STAT
, 0xffffffff);
838 cx_write(CLK_DELAY
, cx_read(CLK_DELAY
) & 0x80000000);
839 cx_write(PAD_CTRL
, 0x12); /* for I2C */
840 cx25821_registers_init(dev
); /* init Pecos registers */
843 for (i
= 0; i
< VID_CHANNEL_NUM
; i
++) {
844 cx25821_set_vip_mode(dev
, dev
->channels
[i
].sram_channels
);
845 cx25821_sram_channel_setup(dev
, dev
->channels
[i
].sram_channels
,
847 dev
->channels
[i
].pixel_formats
= PIXEL_FRMT_422
;
848 dev
->channels
[i
].use_cif_resolution
= FALSE
;
851 /* Probably only affect Downstream */
852 for (i
= VID_UPSTREAM_SRAM_CHANNEL_I
;
853 i
<= VID_UPSTREAM_SRAM_CHANNEL_J
; i
++) {
854 cx25821_set_vip_mode(dev
, dev
->channels
[i
].sram_channels
);
857 cx25821_sram_channel_setup_audio(dev
,
858 dev
->channels
[SRAM_CH08
].sram_channels
, 128, 0);
860 cx25821_gpio_init(dev
);
863 static int cx25821_get_resources(struct cx25821_dev
*dev
)
865 if (request_mem_region(pci_resource_start(dev
->pci
, 0),
866 pci_resource_len(dev
->pci
, 0), dev
->name
))
869 pr_err("%s: can't get MMIO memory @ 0x%llx\n",
870 dev
->name
, (unsigned long long)pci_resource_start(dev
->pci
, 0));
875 static void cx25821_dev_checkrevision(struct cx25821_dev
*dev
)
877 dev
->hwrevision
= cx_read(RDR_CFG2
) & 0xff;
879 pr_info("%s(): Hardware revision = 0x%02x\n",
880 __func__
, dev
->hwrevision
);
883 static void cx25821_iounmap(struct cx25821_dev
*dev
)
888 /* Releasing IO memory */
889 if (dev
->lmmio
!= NULL
) {
890 CX25821_INFO("Releasing lmmio.\n");
896 static int cx25821_dev_setup(struct cx25821_dev
*dev
)
900 pr_info("\n***********************************\n");
901 pr_info("cx25821 set up\n");
902 pr_info("***********************************\n\n");
904 mutex_init(&dev
->lock
);
906 atomic_inc(&dev
->refcount
);
908 dev
->nr
= ++cx25821_devcount
;
909 sprintf(dev
->name
, "cx25821[%d]", dev
->nr
);
911 mutex_lock(&cx25821_devlist_mutex
);
912 list_add_tail(&dev
->devlist
, &cx25821_devlist
);
913 mutex_unlock(&cx25821_devlist_mutex
);
915 strcpy(cx25821_boards
[UNKNOWN_BOARD
].name
, "unknown");
916 strcpy(cx25821_boards
[CX25821_BOARD
].name
, "cx25821");
918 if (dev
->pci
->device
!= 0x8210) {
919 pr_info("%s(): Exiting. Incorrect Hardware device = 0x%02x\n",
920 __func__
, dev
->pci
->device
);
923 pr_info("Athena Hardware device = 0x%02x\n", dev
->pci
->device
);
926 /* Apply a sensible clock frequency for the PCIe bridge */
927 dev
->clk_freq
= 28000000;
928 for (i
= 0; i
< MAX_VID_CHANNEL_NUM
; i
++)
929 dev
->channels
[i
].sram_channels
= &cx25821_sram_channels
[i
];
932 CX25821_INFO("dev->nr > 1!");
935 dev
->board
= 1; /* card[dev->nr]; */
936 dev
->_max_num_decoders
= MAX_DECODERS
;
938 dev
->pci_bus
= dev
->pci
->bus
->number
;
939 dev
->pci_slot
= PCI_SLOT(dev
->pci
->devfn
);
940 dev
->pci_irqmask
= 0x001f00;
942 /* External Master 1 Bus */
943 dev
->i2c_bus
[0].nr
= 0;
944 dev
->i2c_bus
[0].dev
= dev
;
945 dev
->i2c_bus
[0].reg_stat
= I2C1_STAT
;
946 dev
->i2c_bus
[0].reg_ctrl
= I2C1_CTRL
;
947 dev
->i2c_bus
[0].reg_addr
= I2C1_ADDR
;
948 dev
->i2c_bus
[0].reg_rdata
= I2C1_RDATA
;
949 dev
->i2c_bus
[0].reg_wdata
= I2C1_WDATA
;
950 dev
->i2c_bus
[0].i2c_period
= (0x07 << 24); /* 1.95MHz */
952 if (cx25821_get_resources(dev
) < 0) {
953 pr_err("%s: No more PCIe resources for subsystem: %04x:%04x\n",
954 dev
->name
, dev
->pci
->subsystem_vendor
,
955 dev
->pci
->subsystem_device
);
962 dev
->base_io_addr
= pci_resource_start(dev
->pci
, 0);
963 io_size
= pci_resource_len(dev
->pci
, 0);
965 if (!dev
->base_io_addr
) {
966 CX25821_ERR("No PCI Memory resources, exiting!\n");
970 dev
->lmmio
= ioremap(dev
->base_io_addr
, pci_resource_len(dev
->pci
, 0));
973 CX25821_ERR("ioremap failed, maybe increasing __VMALLOC_RESERVE in page.h\n");
974 cx25821_iounmap(dev
);
978 dev
->bmmio
= (u8 __iomem
*) dev
->lmmio
;
980 pr_info("%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
981 dev
->name
, dev
->pci
->subsystem_vendor
,
982 dev
->pci
->subsystem_device
, cx25821_boards
[dev
->board
].name
,
983 dev
->board
, card
[dev
->nr
] == dev
->board
?
984 "insmod option" : "autodetected");
987 cx25821_initialize(dev
);
989 cx25821_i2c_register(&dev
->i2c_bus
[0]);
990 /* cx25821_i2c_register(&dev->i2c_bus[1]);
991 * cx25821_i2c_register(&dev->i2c_bus[2]); */
993 CX25821_INFO("i2c register! bus->i2c_rc = %d\n",
994 dev
->i2c_bus
[0].i2c_rc
);
996 cx25821_card_setup(dev
);
998 if (medusa_video_init(dev
) < 0)
999 CX25821_ERR("%s(): Failed to initialize medusa!\n", __func__
);
1001 cx25821_video_register(dev
);
1003 /* register IOCTL device */
1004 dev
->ioctl_dev
= cx25821_vdev_init(dev
, dev
->pci
,
1005 &cx25821_videoioctl_template
, "video");
1007 if (video_register_device
1008 (dev
->ioctl_dev
, VFL_TYPE_GRABBER
, VIDEO_IOCTL_CH
) < 0) {
1009 cx25821_videoioctl_unregister(dev
);
1010 pr_err("%s(): Failed to register video adapter for IOCTL, so unregistering videoioctl device\n",
1014 cx25821_dev_checkrevision(dev
);
1015 CX25821_INFO("setup done!\n");
1020 void cx25821_start_upstream_video_ch1(struct cx25821_dev
*dev
,
1021 struct upstream_user_struct
*up_data
)
1023 dev
->_isNTSC
= !strcmp(dev
->vid_stdname
, "NTSC") ? 1 : 0;
1025 dev
->tvnorm
= !dev
->_isNTSC
? V4L2_STD_PAL_BG
: V4L2_STD_NTSC_M
;
1026 medusa_set_videostandard(dev
);
1028 cx25821_vidupstream_init_ch1(dev
, dev
->channel_select
,
1032 void cx25821_start_upstream_video_ch2(struct cx25821_dev
*dev
,
1033 struct upstream_user_struct
*up_data
)
1035 dev
->_isNTSC_ch2
= !strcmp(dev
->vid_stdname_ch2
, "NTSC") ? 1 : 0;
1037 dev
->tvnorm
= !dev
->_isNTSC_ch2
? V4L2_STD_PAL_BG
: V4L2_STD_NTSC_M
;
1038 medusa_set_videostandard(dev
);
1040 cx25821_vidupstream_init_ch2(dev
, dev
->channel_select_ch2
,
1041 dev
->pixel_format_ch2
);
1044 void cx25821_start_upstream_audio(struct cx25821_dev
*dev
,
1045 struct upstream_user_struct
*up_data
)
1047 cx25821_audio_upstream_init(dev
, AUDIO_UPSTREAM_SRAM_CHANNEL_B
);
1050 void cx25821_dev_unregister(struct cx25821_dev
*dev
)
1054 if (!dev
->base_io_addr
)
1057 cx25821_free_mem_upstream_ch1(dev
);
1058 cx25821_free_mem_upstream_ch2(dev
);
1059 cx25821_free_mem_upstream_audio(dev
);
1061 release_mem_region(dev
->base_io_addr
, pci_resource_len(dev
->pci
, 0));
1063 if (!atomic_dec_and_test(&dev
->refcount
))
1066 for (i
= 0; i
< VID_CHANNEL_NUM
; i
++)
1067 cx25821_video_unregister(dev
, i
);
1069 for (i
= VID_UPSTREAM_SRAM_CHANNEL_I
;
1070 i
<= AUDIO_UPSTREAM_SRAM_CHANNEL_B
; i
++) {
1071 cx25821_video_unregister(dev
, i
);
1074 cx25821_videoioctl_unregister(dev
);
1076 cx25821_i2c_unregister(&dev
->i2c_bus
[0]);
1077 cx25821_iounmap(dev
);
1079 EXPORT_SYMBOL(cx25821_dev_unregister
);
1081 static __le32
*cx25821_risc_field(__le32
* rp
, struct scatterlist
*sglist
,
1082 unsigned int offset
, u32 sync_line
,
1083 unsigned int bpl
, unsigned int padding
,
1086 struct scatterlist
*sg
;
1087 unsigned int line
, todo
;
1089 /* sync instruction */
1090 if (sync_line
!= NO_SYNC_LINE
)
1091 *(rp
++) = cpu_to_le32(RISC_RESYNC
| sync_line
);
1095 for (line
= 0; line
< lines
; line
++) {
1096 while (offset
&& offset
>= sg_dma_len(sg
)) {
1097 offset
-= sg_dma_len(sg
);
1100 if (bpl
<= sg_dma_len(sg
) - offset
) {
1101 /* fits into current chunk */
1102 *(rp
++) = cpu_to_le32(RISC_WRITE
| RISC_SOL
| RISC_EOL
|
1104 *(rp
++) = cpu_to_le32(sg_dma_address(sg
) + offset
);
1105 *(rp
++) = cpu_to_le32(0); /* bits 63-32 */
1108 /* scanline needs to be split */
1110 *(rp
++) = cpu_to_le32(RISC_WRITE
| RISC_SOL
|
1111 (sg_dma_len(sg
) - offset
));
1112 *(rp
++) = cpu_to_le32(sg_dma_address(sg
) + offset
);
1113 *(rp
++) = cpu_to_le32(0); /* bits 63-32 */
1114 todo
-= (sg_dma_len(sg
) - offset
);
1117 while (todo
> sg_dma_len(sg
)) {
1118 *(rp
++) = cpu_to_le32(RISC_WRITE
|
1120 *(rp
++) = cpu_to_le32(sg_dma_address(sg
));
1121 *(rp
++) = cpu_to_le32(0); /* bits 63-32 */
1122 todo
-= sg_dma_len(sg
);
1125 *(rp
++) = cpu_to_le32(RISC_WRITE
| RISC_EOL
| todo
);
1126 *(rp
++) = cpu_to_le32(sg_dma_address(sg
));
1127 *(rp
++) = cpu_to_le32(0); /* bits 63-32 */
1137 int cx25821_risc_buffer(struct pci_dev
*pci
, struct btcx_riscmem
*risc
,
1138 struct scatterlist
*sglist
, unsigned int top_offset
,
1139 unsigned int bottom_offset
, unsigned int bpl
,
1140 unsigned int padding
, unsigned int lines
)
1148 if (UNSET
!= top_offset
)
1150 if (UNSET
!= bottom_offset
)
1153 /* estimate risc mem: worst case is one write per page border +
1154 one write per scan line + syncs + jump (all 2 dwords). Padding
1155 can cause next bpl to start close to a page border. First DMA
1156 region may be smaller than PAGE_SIZE */
1157 /* write and jump need and extra dword */
1158 instructions
= fields
* (1 + ((bpl
+ padding
) * lines
) / PAGE_SIZE
+
1161 rc
= btcx_riscmem_alloc(pci
, risc
, instructions
* 12);
1166 /* write risc instructions */
1169 if (UNSET
!= top_offset
) {
1170 rp
= cx25821_risc_field(rp
, sglist
, top_offset
, 0, bpl
, padding
,
1174 if (UNSET
!= bottom_offset
) {
1175 rp
= cx25821_risc_field(rp
, sglist
, bottom_offset
, 0x200, bpl
,
1179 /* save pointer to jmp instruction address */
1181 BUG_ON((risc
->jmp
- risc
->cpu
+ 2) * sizeof(*risc
->cpu
) > risc
->size
);
1186 static __le32
*cx25821_risc_field_audio(__le32
* rp
, struct scatterlist
*sglist
,
1187 unsigned int offset
, u32 sync_line
,
1188 unsigned int bpl
, unsigned int padding
,
1189 unsigned int lines
, unsigned int lpi
)
1191 struct scatterlist
*sg
;
1192 unsigned int line
, todo
, sol
;
1194 /* sync instruction */
1195 if (sync_line
!= NO_SYNC_LINE
)
1196 *(rp
++) = cpu_to_le32(RISC_RESYNC
| sync_line
);
1200 for (line
= 0; line
< lines
; line
++) {
1201 while (offset
&& offset
>= sg_dma_len(sg
)) {
1202 offset
-= sg_dma_len(sg
);
1206 if (lpi
&& line
> 0 && !(line
% lpi
))
1207 sol
= RISC_SOL
| RISC_IRQ1
| RISC_CNT_INC
;
1211 if (bpl
<= sg_dma_len(sg
) - offset
) {
1212 /* fits into current chunk */
1213 *(rp
++) = cpu_to_le32(RISC_WRITE
| sol
| RISC_EOL
|
1215 *(rp
++) = cpu_to_le32(sg_dma_address(sg
) + offset
);
1216 *(rp
++) = cpu_to_le32(0); /* bits 63-32 */
1219 /* scanline needs to be split */
1221 *(rp
++) = cpu_to_le32(RISC_WRITE
| sol
|
1222 (sg_dma_len(sg
) - offset
));
1223 *(rp
++) = cpu_to_le32(sg_dma_address(sg
) + offset
);
1224 *(rp
++) = cpu_to_le32(0); /* bits 63-32 */
1225 todo
-= (sg_dma_len(sg
) - offset
);
1228 while (todo
> sg_dma_len(sg
)) {
1229 *(rp
++) = cpu_to_le32(RISC_WRITE
|
1231 *(rp
++) = cpu_to_le32(sg_dma_address(sg
));
1232 *(rp
++) = cpu_to_le32(0); /* bits 63-32 */
1233 todo
-= sg_dma_len(sg
);
1236 *(rp
++) = cpu_to_le32(RISC_WRITE
| RISC_EOL
| todo
);
1237 *(rp
++) = cpu_to_le32(sg_dma_address(sg
));
1238 *(rp
++) = cpu_to_le32(0); /* bits 63-32 */
1247 int cx25821_risc_databuffer_audio(struct pci_dev
*pci
,
1248 struct btcx_riscmem
*risc
,
1249 struct scatterlist
*sglist
,
1251 unsigned int lines
, unsigned int lpi
)
1257 /* estimate risc mem: worst case is one write per page border +
1258 one write per scan line + syncs + jump (all 2 dwords). Here
1259 there is no padding and no sync. First DMA region may be smaller
1261 /* Jump and write need an extra dword */
1262 instructions
= 1 + (bpl
* lines
) / PAGE_SIZE
+ lines
;
1265 rc
= btcx_riscmem_alloc(pci
, risc
, instructions
* 12);
1269 /* write risc instructions */
1271 rp
= cx25821_risc_field_audio(rp
, sglist
, 0, NO_SYNC_LINE
, bpl
, 0,
1274 /* save pointer to jmp instruction address */
1276 BUG_ON((risc
->jmp
- risc
->cpu
+ 2) * sizeof(*risc
->cpu
) > risc
->size
);
1279 EXPORT_SYMBOL(cx25821_risc_databuffer_audio
);
1281 int cx25821_risc_stopper(struct pci_dev
*pci
, struct btcx_riscmem
*risc
,
1282 u32 reg
, u32 mask
, u32 value
)
1287 rc
= btcx_riscmem_alloc(pci
, risc
, 4 * 16);
1292 /* write risc instructions */
1295 *(rp
++) = cpu_to_le32(RISC_WRITECR
| RISC_IRQ1
);
1296 *(rp
++) = cpu_to_le32(reg
);
1297 *(rp
++) = cpu_to_le32(value
);
1298 *(rp
++) = cpu_to_le32(mask
);
1299 *(rp
++) = cpu_to_le32(RISC_JUMP
);
1300 *(rp
++) = cpu_to_le32(risc
->dma
);
1301 *(rp
++) = cpu_to_le32(0); /* bits 63-32 */
1305 void cx25821_free_buffer(struct videobuf_queue
*q
, struct cx25821_buffer
*buf
)
1307 struct videobuf_dmabuf
*dma
= videobuf_to_dma(&buf
->vb
);
1309 BUG_ON(in_interrupt());
1310 videobuf_waiton(q
, &buf
->vb
, 0, 0);
1311 videobuf_dma_unmap(q
->dev
, dma
);
1312 videobuf_dma_free(dma
);
1313 btcx_riscmem_free(to_pci_dev(q
->dev
), &buf
->risc
);
1314 buf
->vb
.state
= VIDEOBUF_NEEDS_INIT
;
1317 static irqreturn_t
cx25821_irq(int irq
, void *dev_id
)
1319 struct cx25821_dev
*dev
= dev_id
;
1320 u32 pci_status
, pci_mask
;
1323 u32 mask
[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
1325 pci_status
= cx_read(PCI_INT_STAT
);
1326 pci_mask
= cx_read(PCI_INT_MSK
);
1328 if (pci_status
== 0)
1331 for (i
= 0; i
< VID_CHANNEL_NUM
; i
++) {
1332 if (pci_status
& mask
[i
]) {
1333 vid_status
= cx_read(dev
->channels
[i
].
1334 sram_channels
->int_stat
);
1337 handled
+= cx25821_video_irq(dev
, i
,
1340 cx_write(PCI_INT_STAT
, mask
[i
]);
1345 return IRQ_RETVAL(handled
);
1348 void cx25821_print_irqbits(char *name
, char *tag
, char **strings
,
1349 int len
, u32 bits
, u32 mask
)
1353 printk(KERN_DEBUG
pr_fmt("%s: %s [0x%x]"), name
, tag
, bits
);
1355 for (i
= 0; i
< len
; i
++) {
1356 if (!(bits
& (1 << i
)))
1359 pr_cont(" %s", strings
[i
]);
1362 if (!(mask
& (1 << i
)))
1368 EXPORT_SYMBOL(cx25821_print_irqbits
);
1370 struct cx25821_dev
*cx25821_dev_get(struct pci_dev
*pci
)
1372 struct cx25821_dev
*dev
= pci_get_drvdata(pci
);
1375 EXPORT_SYMBOL(cx25821_dev_get
);
1377 static int __devinit
cx25821_initdev(struct pci_dev
*pci_dev
,
1378 const struct pci_device_id
*pci_id
)
1380 struct cx25821_dev
*dev
;
1383 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
1387 err
= v4l2_device_register(&pci_dev
->dev
, &dev
->v4l2_dev
);
1393 if (pci_enable_device(pci_dev
)) {
1396 pr_info("pci enable failed!\n");
1398 goto fail_unregister_device
;
1401 pr_info("Athena pci enable !\n");
1403 err
= cx25821_dev_setup(dev
);
1406 goto fail_unregister_device
;
1408 goto fail_unregister_pci
;
1411 /* print pci info */
1412 pci_read_config_byte(pci_dev
, PCI_CLASS_REVISION
, &dev
->pci_rev
);
1413 pci_read_config_byte(pci_dev
, PCI_LATENCY_TIMER
, &dev
->pci_lat
);
1414 pr_info("%s/0: found at %s, rev: %d, irq: %d, latency: %d, mmio: 0x%llx\n",
1415 dev
->name
, pci_name(pci_dev
), dev
->pci_rev
, pci_dev
->irq
,
1416 dev
->pci_lat
, (unsigned long long)dev
->base_io_addr
);
1418 pci_set_master(pci_dev
);
1419 if (!pci_dma_supported(pci_dev
, 0xffffffff)) {
1420 pr_err("%s/0: Oops: no 32bit PCI DMA ???\n", dev
->name
);
1425 err
= request_irq(pci_dev
->irq
, cx25821_irq
,
1426 IRQF_SHARED
, dev
->name
, dev
);
1429 pr_err("%s: can't get IRQ %d\n", dev
->name
, pci_dev
->irq
);
1436 pr_info("cx25821_initdev() can't get IRQ !\n");
1437 cx25821_dev_unregister(dev
);
1439 fail_unregister_pci
:
1440 pci_disable_device(pci_dev
);
1441 fail_unregister_device
:
1442 v4l2_device_unregister(&dev
->v4l2_dev
);
1449 static void __devexit
cx25821_finidev(struct pci_dev
*pci_dev
)
1451 struct v4l2_device
*v4l2_dev
= pci_get_drvdata(pci_dev
);
1452 struct cx25821_dev
*dev
= get_cx25821(v4l2_dev
);
1454 cx25821_shutdown(dev
);
1455 pci_disable_device(pci_dev
);
1457 /* unregister stuff */
1459 free_irq(pci_dev
->irq
, dev
);
1461 mutex_lock(&cx25821_devlist_mutex
);
1462 list_del(&dev
->devlist
);
1463 mutex_unlock(&cx25821_devlist_mutex
);
1465 cx25821_dev_unregister(dev
);
1466 v4l2_device_unregister(v4l2_dev
);
1470 static DEFINE_PCI_DEVICE_TABLE(cx25821_pci_tbl
) = {
1472 /* CX25821 Athena */
1475 .subvendor
= 0x14f1,
1476 .subdevice
= 0x0920,
1479 /* --- end of list --- */
1483 MODULE_DEVICE_TABLE(pci
, cx25821_pci_tbl
);
1485 static struct pci_driver cx25821_pci_driver
= {
1487 .id_table
= cx25821_pci_tbl
,
1488 .probe
= cx25821_initdev
,
1489 .remove
= __devexit_p(cx25821_finidev
),
1495 static int __init
cx25821_init(void)
1497 pr_info("driver version %d.%d.%d loaded\n",
1498 (CX25821_VERSION_CODE
>> 16) & 0xff,
1499 (CX25821_VERSION_CODE
>> 8) & 0xff,
1500 CX25821_VERSION_CODE
& 0xff);
1501 return pci_register_driver(&cx25821_pci_driver
);
1504 static void __exit
cx25821_fini(void)
1506 pci_unregister_driver(&cx25821_pci_driver
);
1509 module_init(cx25821_init
);
1510 module_exit(cx25821_fini
);