Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 1 | /* |
| 2 | ivtv firmware functions. |
| 3 | Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com> |
| 4 | Copyright (C) 2004 Chris Kennedy <c@groovy.org> |
| 5 | Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl> |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | */ |
| 21 | |
| 22 | #include "ivtv-driver.h" |
| 23 | #include "ivtv-mailbox.h" |
| 24 | #include "ivtv-firmware.h" |
Ian Armstrong | a54d1de | 2008-01-26 08:52:58 -0300 | [diff] [blame] | 25 | #include "ivtv-yuv.h" |
Ian Armstrong | 215659d | 2010-06-12 13:41:57 -0300 | [diff] [blame] | 26 | #include "ivtv-ioctl.h" |
| 27 | #include "ivtv-cards.h" |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 28 | #include <linux/firmware.h> |
Ian Armstrong | 215659d | 2010-06-12 13:41:57 -0300 | [diff] [blame] | 29 | #include <media/saa7127.h> |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 30 | |
| 31 | #define IVTV_MASK_SPU_ENABLE 0xFFFFFFFE |
| 32 | #define IVTV_MASK_VPU_ENABLE15 0xFFFFFFF6 |
| 33 | #define IVTV_MASK_VPU_ENABLE16 0xFFFFFFFB |
| 34 | #define IVTV_CMD_VDM_STOP 0x00000000 |
| 35 | #define IVTV_CMD_AO_STOP 0x00000005 |
| 36 | #define IVTV_CMD_APU_PING 0x00000000 |
| 37 | #define IVTV_CMD_VPU_STOP15 0xFFFFFFFE |
| 38 | #define IVTV_CMD_VPU_STOP16 0xFFFFFFEE |
| 39 | #define IVTV_CMD_HW_BLOCKS_RST 0xFFFFFFFF |
| 40 | #define IVTV_CMD_SPU_STOP 0x00000001 |
| 41 | #define IVTV_CMD_SDRAM_PRECHARGE_INIT 0x0000001A |
| 42 | #define IVTV_CMD_SDRAM_REFRESH_INIT 0x80000640 |
Mauro Carvalho Chehab | 201700d | 2007-07-19 11:21:04 -0300 | [diff] [blame] | 43 | #define IVTV_SDRAM_SLEEPTIME 600 |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 44 | |
| 45 | #define IVTV_DECODE_INIT_MPEG_FILENAME "v4l-cx2341x-init.mpg" |
| 46 | #define IVTV_DECODE_INIT_MPEG_SIZE (152*1024) |
| 47 | |
| 48 | /* Encoder/decoder firmware sizes */ |
| 49 | #define IVTV_FW_ENC_SIZE (376836) |
| 50 | #define IVTV_FW_DEC_SIZE (256*1024) |
| 51 | |
| 52 | static int load_fw_direct(const char *fn, volatile u8 __iomem *mem, struct ivtv *itv, long size) |
| 53 | { |
| 54 | const struct firmware *fw = NULL; |
| 55 | int retries = 3; |
| 56 | |
| 57 | retry: |
Hans Verkuil | 8ac05ae | 2009-02-07 07:02:27 -0300 | [diff] [blame] | 58 | if (retries && request_firmware(&fw, fn, &itv->pdev->dev) == 0) { |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 59 | int i; |
| 60 | volatile u32 __iomem *dst = (volatile u32 __iomem *)mem; |
| 61 | const u32 *src = (const u32 *)fw->data; |
| 62 | |
Hans Verkuil | a957641 | 2007-05-29 07:18:55 -0300 | [diff] [blame] | 63 | if (fw->size != size) { |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 64 | /* Due to race conditions in firmware loading (esp. with udev <0.95) |
| 65 | the wrong file was sometimes loaded. So we check filesizes to |
| 66 | see if at least the right-sized file was loaded. If not, then we |
| 67 | retry. */ |
Hans Verkuil | ae38d93 | 2007-07-17 13:42:43 -0300 | [diff] [blame] | 68 | IVTV_INFO("Retry: file loaded was not %s (expected size %ld, got %zd)\n", fn, size, fw->size); |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 69 | release_firmware(fw); |
| 70 | retries--; |
| 71 | goto retry; |
| 72 | } |
| 73 | for (i = 0; i < fw->size; i += 4) { |
| 74 | /* no need for endianness conversion on the ppc */ |
| 75 | __raw_writel(*src, dst); |
| 76 | dst++; |
| 77 | src++; |
| 78 | } |
Hans Verkuil | ae38d93 | 2007-07-17 13:42:43 -0300 | [diff] [blame] | 79 | IVTV_INFO("Loaded %s firmware (%zd bytes)\n", fn, fw->size); |
Hans Verkuil | be9a5c7 | 2007-07-22 11:12:26 -0300 | [diff] [blame] | 80 | release_firmware(fw); |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 81 | return size; |
| 82 | } |
Hans Verkuil | ae38d93 | 2007-07-17 13:42:43 -0300 | [diff] [blame] | 83 | IVTV_ERR("Unable to open firmware %s (must be %ld bytes)\n", fn, size); |
| 84 | IVTV_ERR("Did you put the firmware in the hotplug firmware directory?\n"); |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 85 | return -ENOMEM; |
| 86 | } |
| 87 | |
| 88 | void ivtv_halt_firmware(struct ivtv *itv) |
| 89 | { |
| 90 | IVTV_DEBUG_INFO("Preparing for firmware halt.\n"); |
| 91 | if (itv->has_cx23415 && itv->dec_mbox.mbox) |
| 92 | ivtv_vapi(itv, CX2341X_DEC_HALT_FW, 0); |
| 93 | if (itv->enc_mbox.mbox) |
| 94 | ivtv_vapi(itv, CX2341X_ENC_HALT_FW, 0); |
| 95 | |
Mauro Carvalho Chehab | 201700d | 2007-07-19 11:21:04 -0300 | [diff] [blame] | 96 | ivtv_msleep_timeout(10, 0); |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 97 | itv->enc_mbox.mbox = itv->dec_mbox.mbox = NULL; |
| 98 | |
| 99 | IVTV_DEBUG_INFO("Stopping VDM\n"); |
| 100 | write_reg(IVTV_CMD_VDM_STOP, IVTV_REG_VDM); |
| 101 | |
| 102 | IVTV_DEBUG_INFO("Stopping AO\n"); |
| 103 | write_reg(IVTV_CMD_AO_STOP, IVTV_REG_AO); |
| 104 | |
| 105 | IVTV_DEBUG_INFO("pinging (?) APU\n"); |
| 106 | write_reg(IVTV_CMD_APU_PING, IVTV_REG_APU); |
| 107 | |
| 108 | IVTV_DEBUG_INFO("Stopping VPU\n"); |
| 109 | if (!itv->has_cx23415) |
| 110 | write_reg(IVTV_CMD_VPU_STOP16, IVTV_REG_VPU); |
| 111 | else |
| 112 | write_reg(IVTV_CMD_VPU_STOP15, IVTV_REG_VPU); |
| 113 | |
| 114 | IVTV_DEBUG_INFO("Resetting Hw Blocks\n"); |
| 115 | write_reg(IVTV_CMD_HW_BLOCKS_RST, IVTV_REG_HW_BLOCKS); |
| 116 | |
| 117 | IVTV_DEBUG_INFO("Stopping SPU\n"); |
| 118 | write_reg(IVTV_CMD_SPU_STOP, IVTV_REG_SPU); |
| 119 | |
Mauro Carvalho Chehab | 201700d | 2007-07-19 11:21:04 -0300 | [diff] [blame] | 120 | ivtv_msleep_timeout(10, 0); |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 121 | |
| 122 | IVTV_DEBUG_INFO("init Encoder SDRAM pre-charge\n"); |
| 123 | write_reg(IVTV_CMD_SDRAM_PRECHARGE_INIT, IVTV_REG_ENC_SDRAM_PRECHARGE); |
| 124 | |
| 125 | IVTV_DEBUG_INFO("init Encoder SDRAM refresh to 1us\n"); |
| 126 | write_reg(IVTV_CMD_SDRAM_REFRESH_INIT, IVTV_REG_ENC_SDRAM_REFRESH); |
| 127 | |
| 128 | if (itv->has_cx23415) { |
| 129 | IVTV_DEBUG_INFO("init Decoder SDRAM pre-charge\n"); |
| 130 | write_reg(IVTV_CMD_SDRAM_PRECHARGE_INIT, IVTV_REG_DEC_SDRAM_PRECHARGE); |
| 131 | |
| 132 | IVTV_DEBUG_INFO("init Decoder SDRAM refresh to 1us\n"); |
| 133 | write_reg(IVTV_CMD_SDRAM_REFRESH_INIT, IVTV_REG_DEC_SDRAM_REFRESH); |
| 134 | } |
| 135 | |
Mauro Carvalho Chehab | 201700d | 2007-07-19 11:21:04 -0300 | [diff] [blame] | 136 | IVTV_DEBUG_INFO("Sleeping for %dms\n", IVTV_SDRAM_SLEEPTIME); |
| 137 | ivtv_msleep_timeout(IVTV_SDRAM_SLEEPTIME, 0); |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | void ivtv_firmware_versions(struct ivtv *itv) |
| 141 | { |
| 142 | u32 data[CX2341X_MBOX_MAX_DATA]; |
| 143 | |
| 144 | /* Encoder */ |
| 145 | ivtv_vapi_result(itv, data, CX2341X_ENC_GET_VERSION, 0); |
| 146 | IVTV_INFO("Encoder revision: 0x%08x\n", data[0]); |
| 147 | |
| 148 | if (data[0] != 0x02060039) |
| 149 | IVTV_WARN("Recommended firmware version is 0x02060039.\n"); |
| 150 | |
| 151 | if (itv->has_cx23415) { |
| 152 | /* Decoder */ |
| 153 | ivtv_vapi_result(itv, data, CX2341X_DEC_GET_VERSION, 0); |
| 154 | IVTV_INFO("Decoder revision: 0x%08x\n", data[0]); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | static int ivtv_firmware_copy(struct ivtv *itv) |
| 159 | { |
| 160 | IVTV_DEBUG_INFO("Loading encoder image\n"); |
| 161 | if (load_fw_direct(CX2341X_FIRM_ENC_FILENAME, |
| 162 | itv->enc_mem, itv, IVTV_FW_ENC_SIZE) != IVTV_FW_ENC_SIZE) { |
| 163 | IVTV_DEBUG_WARN("failed loading encoder firmware\n"); |
| 164 | return -3; |
| 165 | } |
| 166 | if (!itv->has_cx23415) |
| 167 | return 0; |
| 168 | |
| 169 | IVTV_DEBUG_INFO("Loading decoder image\n"); |
| 170 | if (load_fw_direct(CX2341X_FIRM_DEC_FILENAME, |
| 171 | itv->dec_mem, itv, IVTV_FW_DEC_SIZE) != IVTV_FW_DEC_SIZE) { |
| 172 | IVTV_DEBUG_WARN("failed loading decoder firmware\n"); |
| 173 | return -1; |
| 174 | } |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | static volatile struct ivtv_mailbox __iomem *ivtv_search_mailbox(const volatile u8 __iomem *mem, u32 size) |
| 179 | { |
| 180 | int i; |
| 181 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 182 | /* mailbox is preceded by a 16 byte 'magic cookie' starting at a 256-byte |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 183 | address boundary */ |
| 184 | for (i = 0; i < size; i += 0x100) { |
| 185 | if (readl(mem + i) == 0x12345678 && |
| 186 | readl(mem + i + 4) == 0x34567812 && |
| 187 | readl(mem + i + 8) == 0x56781234 && |
| 188 | readl(mem + i + 12) == 0x78123456) { |
| 189 | return (volatile struct ivtv_mailbox __iomem *)(mem + i + 16); |
| 190 | } |
| 191 | } |
| 192 | return NULL; |
| 193 | } |
| 194 | |
| 195 | int ivtv_firmware_init(struct ivtv *itv) |
| 196 | { |
| 197 | int err; |
| 198 | |
| 199 | ivtv_halt_firmware(itv); |
| 200 | |
| 201 | /* load firmware */ |
| 202 | err = ivtv_firmware_copy(itv); |
| 203 | if (err) { |
| 204 | IVTV_DEBUG_WARN("Error %d loading firmware\n", err); |
| 205 | return err; |
| 206 | } |
| 207 | |
| 208 | /* start firmware */ |
| 209 | write_reg(read_reg(IVTV_REG_SPU) & IVTV_MASK_SPU_ENABLE, IVTV_REG_SPU); |
Mauro Carvalho Chehab | 201700d | 2007-07-19 11:21:04 -0300 | [diff] [blame] | 210 | ivtv_msleep_timeout(100, 0); |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 211 | if (itv->has_cx23415) |
| 212 | write_reg(read_reg(IVTV_REG_VPU) & IVTV_MASK_VPU_ENABLE15, IVTV_REG_VPU); |
| 213 | else |
| 214 | write_reg(read_reg(IVTV_REG_VPU) & IVTV_MASK_VPU_ENABLE16, IVTV_REG_VPU); |
Mauro Carvalho Chehab | 201700d | 2007-07-19 11:21:04 -0300 | [diff] [blame] | 215 | ivtv_msleep_timeout(100, 0); |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 216 | |
| 217 | /* find mailboxes and ping firmware */ |
| 218 | itv->enc_mbox.mbox = ivtv_search_mailbox(itv->enc_mem, IVTV_ENCODER_SIZE); |
| 219 | if (itv->enc_mbox.mbox == NULL) |
| 220 | IVTV_ERR("Encoder mailbox not found\n"); |
| 221 | else if (ivtv_vapi(itv, CX2341X_ENC_PING_FW, 0)) { |
| 222 | IVTV_ERR("Encoder firmware dead!\n"); |
| 223 | itv->enc_mbox.mbox = NULL; |
| 224 | } |
| 225 | if (itv->enc_mbox.mbox == NULL) |
| 226 | return -ENODEV; |
| 227 | |
| 228 | if (!itv->has_cx23415) |
| 229 | return 0; |
| 230 | |
| 231 | itv->dec_mbox.mbox = ivtv_search_mailbox(itv->dec_mem, IVTV_DECODER_SIZE); |
Ian Armstrong | a54d1de | 2008-01-26 08:52:58 -0300 | [diff] [blame] | 232 | if (itv->dec_mbox.mbox == NULL) { |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 233 | IVTV_ERR("Decoder mailbox not found\n"); |
Ian Armstrong | a54d1de | 2008-01-26 08:52:58 -0300 | [diff] [blame] | 234 | } else if (itv->has_cx23415 && ivtv_vapi(itv, CX2341X_DEC_PING_FW, 0)) { |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 235 | IVTV_ERR("Decoder firmware dead!\n"); |
| 236 | itv->dec_mbox.mbox = NULL; |
Ian Armstrong | a54d1de | 2008-01-26 08:52:58 -0300 | [diff] [blame] | 237 | } else { |
| 238 | /* Firmware okay, so check yuv output filter table */ |
| 239 | ivtv_yuv_filter_check(itv); |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 240 | } |
| 241 | return itv->dec_mbox.mbox ? 0 : -ENODEV; |
| 242 | } |
| 243 | |
| 244 | void ivtv_init_mpeg_decoder(struct ivtv *itv) |
| 245 | { |
| 246 | u32 data[CX2341X_MBOX_MAX_DATA]; |
| 247 | long readbytes; |
| 248 | volatile u8 __iomem *mem_offset; |
| 249 | |
| 250 | data[0] = 0; |
Hans Verkuil | f7b80e6 | 2010-06-27 06:07:26 -0300 | [diff] [blame] | 251 | data[1] = itv->cxhdl.width; /* YUV source width */ |
| 252 | data[2] = itv->cxhdl.height; |
| 253 | data[3] = itv->cxhdl.audio_properties; /* Audio settings to use, |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 254 | bitmap. see docs. */ |
| 255 | if (ivtv_api(itv, CX2341X_DEC_SET_DECODER_SOURCE, 4, data)) { |
| 256 | IVTV_ERR("ivtv_init_mpeg_decoder failed to set decoder source\n"); |
| 257 | return; |
| 258 | } |
| 259 | |
| 260 | if (ivtv_vapi(itv, CX2341X_DEC_START_PLAYBACK, 2, 0, 1) != 0) { |
| 261 | IVTV_ERR("ivtv_init_mpeg_decoder failed to start playback\n"); |
| 262 | return; |
| 263 | } |
Andy Walls | 587808d | 2010-02-10 15:34:46 -0300 | [diff] [blame] | 264 | ivtv_api_get_data(&itv->dec_mbox, IVTV_MBOX_DMA, 2, data); |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 265 | mem_offset = itv->dec_mem + data[1]; |
| 266 | |
| 267 | if ((readbytes = load_fw_direct(IVTV_DECODE_INIT_MPEG_FILENAME, |
| 268 | mem_offset, itv, IVTV_DECODE_INIT_MPEG_SIZE)) <= 0) { |
| 269 | IVTV_DEBUG_WARN("failed to read mpeg decoder initialisation file %s\n", |
| 270 | IVTV_DECODE_INIT_MPEG_FILENAME); |
| 271 | } else { |
| 272 | ivtv_vapi(itv, CX2341X_DEC_SCHED_DMA_FROM_HOST, 3, 0, readbytes, 0); |
Mauro Carvalho Chehab | 201700d | 2007-07-19 11:21:04 -0300 | [diff] [blame] | 273 | ivtv_msleep_timeout(100, 0); |
Hans Verkuil | 1a0adaf | 2007-04-27 12:31:25 -0300 | [diff] [blame] | 274 | } |
| 275 | ivtv_vapi(itv, CX2341X_DEC_STOP_PLAYBACK, 4, 0, 0, 0, 1); |
| 276 | } |
Ian Armstrong | 914610e | 2010-06-12 13:33:21 -0300 | [diff] [blame] | 277 | |
Ian Armstrong | 215659d | 2010-06-12 13:41:57 -0300 | [diff] [blame] | 278 | /* Try to restart the card & restore previous settings */ |
| 279 | int ivtv_firmware_restart(struct ivtv *itv) |
| 280 | { |
| 281 | int rc = 0; |
| 282 | v4l2_std_id std; |
Ian Armstrong | 215659d | 2010-06-12 13:41:57 -0300 | [diff] [blame] | 283 | |
| 284 | if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) |
| 285 | /* Display test image during restart */ |
| 286 | ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_routing, |
| 287 | SAA7127_INPUT_TYPE_TEST_IMAGE, |
| 288 | itv->card->video_outputs[itv->active_output].video_output, |
| 289 | 0); |
| 290 | |
| 291 | mutex_lock(&itv->udma.lock); |
| 292 | |
| 293 | rc = ivtv_firmware_init(itv); |
| 294 | if (rc) { |
| 295 | mutex_unlock(&itv->udma.lock); |
| 296 | return rc; |
| 297 | } |
| 298 | |
| 299 | /* Allow settings to reload */ |
| 300 | ivtv_mailbox_cache_invalidate(itv); |
| 301 | |
Ian Armstrong | c5874c9 | 2011-05-29 21:33:17 -0300 | [diff] [blame] | 302 | /* Restore encoder video standard */ |
Ian Armstrong | 215659d | 2010-06-12 13:41:57 -0300 | [diff] [blame] | 303 | std = itv->std; |
| 304 | itv->std = 0; |
Ian Armstrong | c5874c9 | 2011-05-29 21:33:17 -0300 | [diff] [blame] | 305 | ivtv_s_std_enc(itv, &std); |
Ian Armstrong | 215659d | 2010-06-12 13:41:57 -0300 | [diff] [blame] | 306 | |
| 307 | if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) { |
| 308 | ivtv_init_mpeg_decoder(itv); |
| 309 | |
Ian Armstrong | c5874c9 | 2011-05-29 21:33:17 -0300 | [diff] [blame] | 310 | /* Restore decoder video standard */ |
| 311 | std = itv->std_out; |
| 312 | itv->std_out = 0; |
| 313 | ivtv_s_std_dec(itv, &std); |
| 314 | |
Ian Armstrong | 215659d | 2010-06-12 13:41:57 -0300 | [diff] [blame] | 315 | /* Restore framebuffer if active */ |
| 316 | if (itv->ivtvfb_restore) |
| 317 | itv->ivtvfb_restore(itv); |
| 318 | |
| 319 | /* Restore alpha settings */ |
| 320 | ivtv_set_osd_alpha(itv); |
| 321 | |
| 322 | /* Restore normal output */ |
| 323 | ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_routing, |
| 324 | SAA7127_INPUT_TYPE_NORMAL, |
| 325 | itv->card->video_outputs[itv->active_output].video_output, |
| 326 | 0); |
| 327 | } |
| 328 | |
| 329 | mutex_unlock(&itv->udma.lock); |
| 330 | return rc; |
| 331 | } |
| 332 | |
Ian Armstrong | 914610e | 2010-06-12 13:33:21 -0300 | [diff] [blame] | 333 | /* Check firmware running state. The checks fall through |
| 334 | allowing multiple failures to be logged. */ |
| 335 | int ivtv_firmware_check(struct ivtv *itv, char *where) |
| 336 | { |
| 337 | int res = 0; |
| 338 | |
| 339 | /* Check encoder is still running */ |
| 340 | if (ivtv_vapi(itv, CX2341X_ENC_PING_FW, 0) < 0) { |
| 341 | IVTV_WARN("Encoder has died : %s\n", where); |
| 342 | res = -1; |
| 343 | } |
| 344 | |
| 345 | /* Also check audio. Only check if not in use & encoder is okay */ |
| 346 | if (!res && !atomic_read(&itv->capturing) && |
| 347 | (!atomic_read(&itv->decoding) || |
| 348 | (atomic_read(&itv->decoding) < 2 && test_bit(IVTV_F_I_DEC_YUV, |
| 349 | &itv->i_flags)))) { |
| 350 | |
| 351 | if (ivtv_vapi(itv, CX2341X_ENC_MISC, 1, 12) < 0) { |
| 352 | IVTV_WARN("Audio has died (Encoder OK) : %s\n", where); |
| 353 | res = -2; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) { |
| 358 | /* Second audio check. Skip if audio already failed */ |
| 359 | if (res != -2 && read_dec(0x100) != read_dec(0x104)) { |
| 360 | /* Wait & try again to be certain. */ |
| 361 | ivtv_msleep_timeout(14, 0); |
| 362 | if (read_dec(0x100) != read_dec(0x104)) { |
| 363 | IVTV_WARN("Audio has died (Decoder) : %s\n", |
| 364 | where); |
| 365 | res = -1; |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | /* Check decoder is still running */ |
| 370 | if (ivtv_vapi(itv, CX2341X_DEC_PING_FW, 0) < 0) { |
| 371 | IVTV_WARN("Decoder has died : %s\n", where); |
| 372 | res = -1; |
| 373 | } |
| 374 | } |
| 375 | |
Ian Armstrong | 215659d | 2010-06-12 13:41:57 -0300 | [diff] [blame] | 376 | /* If something failed & currently idle, try to reload */ |
| 377 | if (res && !atomic_read(&itv->capturing) && |
| 378 | !atomic_read(&itv->decoding)) { |
| 379 | IVTV_INFO("Detected in %s that firmware had failed - " |
| 380 | "Reloading\n", where); |
| 381 | res = ivtv_firmware_restart(itv); |
| 382 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 383 | * Even if restarted ok, still signal a problem had occurred. |
Ian Armstrong | 215659d | 2010-06-12 13:41:57 -0300 | [diff] [blame] | 384 | * The caller can come through this function again to check |
| 385 | * if things are really ok after the restart. |
| 386 | */ |
| 387 | if (!res) { |
| 388 | IVTV_INFO("Firmware restart okay\n"); |
| 389 | res = -EAGAIN; |
| 390 | } else { |
| 391 | IVTV_INFO("Firmware restart failed\n"); |
| 392 | } |
| 393 | } else if (res) { |
| 394 | res = -EIO; |
| 395 | } |
| 396 | |
Ian Armstrong | 914610e | 2010-06-12 13:33:21 -0300 | [diff] [blame] | 397 | return res; |
| 398 | } |