2 * cx18 ADEC firmware functions
4 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #include "cx18-driver.h"
24 #include <linux/firmware.h>
26 #define CX18_AUDIO_ENABLE 0xc72014
27 #define FWFILE "v4l-cx23418-dig.fw"
29 int cx18_av_loadfw(struct cx18 *cx)
31 const struct firmware *fw = NULL;
38 if (request_firmware(&fw, FWFILE, &cx->dev->dev) != 0) {
39 CX18_ERR("unable to open firmware %s\n", FWFILE);
43 /* The firmware load often has byte errors, so allow for several
44 retries, both at byte level and at the firmware load level. */
45 while (retries1 < 5) {
46 cx18_av_write4_expect(cx, CXADEC_CHIP_CTRL, 0x00010000,
47 0x00008430, 0xffffffff); /* cx25843 */
48 cx18_av_write_expect(cx, CXADEC_STD_DET_CTL, 0xf6, 0xf6, 0xff);
50 /* Reset the Mako core, Register is alias of CXADEC_CHIP_CTRL */
51 cx18_av_write4_expect(cx, 0x8100, 0x00010000,
52 0x00008430, 0xffffffff); /* cx25843 */
54 /* Put the 8051 in reset and enable firmware upload */
55 cx18_av_write4_noretry(cx, CXADEC_DL_CTL, 0x0F000000);
60 for (i = 0; i < size; i++) {
61 u32 dl_control = 0x0F000000 | i | ((u32)ptr[i] << 16);
66 for (retries2 = 0; retries2 < CX18_MAX_MMIO_WR_RETRIES;
68 cx18_av_write4_noretry(cx, CXADEC_DL_CTL,
71 value = cx18_av_read4_noretry(cx,
73 if (value == dl_control)
75 /* Check if we can correct the byte by changing
76 the address. We can only write the lower
77 address byte of the address. */
78 if ((value & 0x3F00) != (dl_control & 0x3F00)) {
83 cx18_log_write_retries(cx, retries2,
84 cx->reg_mem + 0xc40000 + CXADEC_DL_CTL);
85 if (unrec_err || retries2 >= CX18_MAX_MMIO_WR_RETRIES)
93 CX18_ERR("unable to load firmware %s\n", FWFILE);
98 cx18_av_write4_expect(cx, CXADEC_DL_CTL,
99 0x13000000 | fw->size, 0x13000000, 0x13000000);
101 /* Output to the 416 */
102 cx18_av_and_or4(cx, CXADEC_PIN_CTRL1, ~0, 0x78000);
104 /* Audio input control 1 set to Sony mode */
105 /* Audio output input 2 is 0 for slave operation input */
106 /* 0xC4000914[5]: 0 = left sample on WS=0, 1 = left sample on WS=1 */
107 /* 0xC4000914[7]: 0 = Philips mode, 1 = Sony mode (1st SCK rising edge
108 after WS transition for first bit of audio word. */
109 cx18_av_write4(cx, CXADEC_I2S_IN_CTL, 0x000000A0);
111 /* Audio output control 1 is set to Sony mode */
112 /* Audio output control 2 is set to 1 for master mode */
113 /* 0xC4000918[5]: 0 = left sample on WS=0, 1 = left sample on WS=1 */
114 /* 0xC4000918[7]: 0 = Philips mode, 1 = Sony mode (1st SCK rising edge
115 after WS transition for first bit of audio word. */
116 /* 0xC4000918[8]: 0 = slave operation, 1 = master (SCK_OUT and WS_OUT
118 cx18_av_write4(cx, CXADEC_I2S_OUT_CTL, 0x000001A0);
120 /* set alt I2s master clock to /16 and enable alt divider i2s
122 cx18_av_write4(cx, CXADEC_PIN_CFG3, 0x5000B687);
124 cx18_av_write4_expect(cx, CXADEC_STD_DET_CTL, 0x000000F6, 0x000000F6,
126 /* CxDevWrReg(CXADEC_STD_DET_CTL, 0x000000FF); */
128 /* Set bit 0 in register 0x9CC to signify that this is MiniMe. */
129 /* Register 0x09CC is defined by the Merlin firmware, and doesn't
130 have a name in the spec. */
131 cx18_av_write4(cx, 0x09CC, 1);
133 v = cx18_read_reg(cx, CX18_AUDIO_ENABLE);
134 /* If bit 11 is 1, clear bit 10 */
136 cx18_write_reg(cx, v & 0xFFFFFBFF, CX18_AUDIO_ENABLE);
138 /* Enable WW auto audio standard detection */
139 v = cx18_av_read4(cx, CXADEC_STD_DET_CTL);
140 v |= 0xFF; /* Auto by default */
141 v |= 0x400; /* Stereo by default */
143 cx18_av_write4_expect(cx, CXADEC_STD_DET_CTL, v, v, 0x3F00FFFF);
145 release_firmware(fw);
147 CX18_INFO("loaded %s firmware (%d bytes)\n", FWFILE, size);