22 #include <linux/device.h>
33 #define IVTV_MBOX_FIRMWARE_DONE 0x00000004
34 #define IVTV_MBOX_DRIVER_DONE 0x00000002
35 #define IVTV_MBOX_DRIVER_BUSY 0x00000001
37 #define MBOX_BASE 0x44
40 static int pvr2_encoder_write_words(
struct pvr2_hdw *hdw,
47 unsigned int chunkCnt;
61 if (chunkCnt > dlen) chunkCnt =
dlen;
65 for (idx = 0; idx < chunkCnt; idx++) {
68 hdw->
cmd_buffer[bAddr+5] = ((addr>>8) & 0xffu);
69 hdw->
cmd_buffer[bAddr+4] = ((addr>>16) & 0xffu);
86 static int pvr2_encoder_read_words(
struct pvr2_hdw *hdw,
92 unsigned int chunkCnt;
106 if (chunkCnt > dlen) chunkCnt =
dlen;
107 if (chunkCnt < 16) chunkCnt = 1;
121 (chunkCnt == 1 ? 4 : 16 * 4));
124 for (idx = 0; idx < chunkCnt; idx++) {
141 static int pvr2_encoder_cmd(
void *ctxt,
147 unsigned int poll_count;
148 unsigned int try_count = 0;
188 if (arg_cnt_send > (
ARRAY_SIZE(wrData) - 4)) {
191 "Failed to write cx23416 command"
192 " - too many input arguments"
193 " (was given %u limit %lu)",
194 arg_cnt_send, (
long unsigned)
ARRAY_SIZE(wrData) - 4);
198 if (arg_cnt_recv > (
ARRAY_SIZE(rdData) - 4)) {
201 "Failed to write cx23416 command"
202 " - too many return arguments"
203 " (was given %u limit %lu)",
204 arg_cnt_recv, (
long unsigned)
ARRAY_SIZE(rdData) - 4);
222 wrData[3] = 0x00060000;
223 for (idx = 0; idx < arg_cnt_send; idx++) {
224 wrData[idx+4] = argp[
idx];
230 ret = pvr2_encoder_write_words(hdw,
MBOX_BASE,wrData,idx);
233 ret = pvr2_encoder_write_words(hdw,
MBOX_BASE,wrData,1);
238 ret = pvr2_encoder_read_words(hdw,
MBOX_BASE,rdData,
246 if (rdData[0] && (poll_count < 1000))
continue;
251 "Encoder timed out waiting for us"
252 "; arranging to retry");
256 "***WARNING*** device's encoder"
257 " appears to be stuck"
258 " (status=0x%08x)",rdData[0]);
262 "Encoder command: 0x%02x",cmd);
263 for (idx = 4; idx < arg_cnt_send; idx++) {
266 "Encoder arg%d: 0x%08x",
273 if (try_count < 20)
continue;
276 "Too many retries...");
283 "State bit %s <-- %s",
289 "State bit %s <-- %s",
290 "state_encoder_runok",
296 "Giving up on command."
297 " This is normally recovered via a firmware"
298 " reload and re-initialization; concern"
299 " is only warranted if this happens repeatedly"
304 for (idx = 0; idx < arg_cnt_recv; idx++) {
305 argp[
idx] = rdData[idx+4];
309 ret = pvr2_encoder_write_words(hdw,
MBOX_BASE,wrData,1);
318 static int pvr2_encoder_vcmd(
struct pvr2_hdw *hdw,
int cmd,
328 "Failed to write cx23416 command"
329 " - too many arguments"
330 " (was given %u limit %lu)",
336 for (idx = 0; idx < args; idx++) {
341 return pvr2_encoder_cmd(hdw,cmd,args,0,data);
347 static int pvr2_encoder_prep_config(
struct pvr2_hdw *hdw)
361 pvr2_encoder_write_words(hdw,0x01fe,dat,1);
362 pvr2_encoder_write_words(hdw,0x023e,dat,1);
386 if (hdw->
hdw_desc->flag_has_cx25840) {
423 "Error from cx2341x module code=%d",ret);
438 " (cx2341x module)");
447 ret |= pvr2_encoder_prep_config(hdw);
451 if (hdw->
hdw_desc->flag_has_cx25840) {
456 if (!ret) ret = pvr2_encoder_vcmd(
461 if (!ret) ret = pvr2_encoder_vcmd(
463 0, 0, 0x10000000, 0xffffffff);
465 if (!ret) ret = pvr2_encoder_vcmd(
471 "Failed to configure cx23416");
478 ret = pvr2_encoder_vcmd(
483 "Failed to initialize cx23416 video input");