This source file includes following definitions.
- cx18_av_verifyfw
- cx18_av_loadfw
1
2
3
4
5
6
7
8
9 #include "cx18-driver.h"
10 #include "cx18-io.h"
11 #include <linux/firmware.h>
12
13 #define CX18_AUDIO_ENABLE 0xc72014
14 #define CX18_AI1_MUX_MASK 0x30
15 #define CX18_AI1_MUX_I2S1 0x00
16 #define CX18_AI1_MUX_I2S2 0x10
17 #define CX18_AI1_MUX_843_I2S 0x20
18 #define CX18_AI1_MUX_INVALID 0x30
19
20 #define FWFILE "v4l-cx23418-dig.fw"
21
22 static int cx18_av_verifyfw(struct cx18 *cx, const struct firmware *fw)
23 {
24 struct v4l2_subdev *sd = &cx->av_state.sd;
25 int ret = 0;
26 const u8 *data;
27 u32 size;
28 int addr;
29 u32 expected, dl_control;
30
31
32 dl_control = cx18_av_read4(cx, CXADEC_DL_CTL);
33 do {
34 dl_control &= 0x00ffffff;
35 dl_control |= 0x0f000000;
36 cx18_av_write4_noretry(cx, CXADEC_DL_CTL, dl_control);
37 dl_control = cx18_av_read4(cx, CXADEC_DL_CTL);
38 } while ((dl_control & 0xff000000) != 0x0f000000);
39
40
41 while (dl_control & 0x3fff)
42 dl_control = cx18_av_read4(cx, CXADEC_DL_CTL);
43
44 data = fw->data;
45 size = fw->size;
46 for (addr = 0; addr < size; addr++) {
47 dl_control &= 0xffff3fff;
48 expected = 0x0f000000 | ((u32)data[addr] << 16) | addr;
49 if (expected != dl_control) {
50 CX18_ERR_DEV(sd, "verification of %s firmware load failed: expected %#010x got %#010x\n",
51 FWFILE, expected, dl_control);
52 ret = -EIO;
53 break;
54 }
55 dl_control = cx18_av_read4(cx, CXADEC_DL_CTL);
56 }
57 if (ret == 0)
58 CX18_INFO_DEV(sd, "verified load of %s firmware (%d bytes)\n",
59 FWFILE, size);
60 return ret;
61 }
62
63 int cx18_av_loadfw(struct cx18 *cx)
64 {
65 struct v4l2_subdev *sd = &cx->av_state.sd;
66 const struct firmware *fw = NULL;
67 u32 size;
68 u32 u, v;
69 const u8 *ptr;
70 int i;
71 int retries1 = 0;
72
73 if (request_firmware(&fw, FWFILE, &cx->pci_dev->dev) != 0) {
74 CX18_ERR_DEV(sd, "unable to open firmware %s\n", FWFILE);
75 return -EINVAL;
76 }
77
78
79
80 while (retries1 < 5) {
81 cx18_av_write4_expect(cx, CXADEC_CHIP_CTRL, 0x00010000,
82 0x00008430, 0xffffffff);
83 cx18_av_write_expect(cx, CXADEC_STD_DET_CTL, 0xf6, 0xf6, 0xff);
84
85
86 cx18_av_write4_expect(cx, 0x8100, 0x00010000,
87 0x00008430, 0xffffffff);
88
89
90 cx18_av_write4_noretry(cx, CXADEC_DL_CTL, 0x0F000000);
91
92 ptr = fw->data;
93 size = fw->size;
94
95 for (i = 0; i < size; i++) {
96 u32 dl_control = 0x0F000000 | i | ((u32)ptr[i] << 16);
97 u32 value = 0;
98 int retries2;
99 int unrec_err = 0;
100
101 for (retries2 = 0; retries2 < CX18_MAX_MMIO_WR_RETRIES;
102 retries2++) {
103 cx18_av_write4_noretry(cx, CXADEC_DL_CTL,
104 dl_control);
105 udelay(10);
106 value = cx18_av_read4(cx, CXADEC_DL_CTL);
107 if (value == dl_control)
108 break;
109
110
111
112 if ((value & 0x3F00) != (dl_control & 0x3F00)) {
113 unrec_err = 1;
114 break;
115 }
116 }
117 if (unrec_err || retries2 >= CX18_MAX_MMIO_WR_RETRIES)
118 break;
119 }
120 if (i == size)
121 break;
122 retries1++;
123 }
124 if (retries1 >= 5) {
125 CX18_ERR_DEV(sd, "unable to load firmware %s\n", FWFILE);
126 release_firmware(fw);
127 return -EIO;
128 }
129
130 cx18_av_write4_expect(cx, CXADEC_DL_CTL,
131 0x03000000 | fw->size, 0x03000000, 0x13000000);
132
133 CX18_INFO_DEV(sd, "loaded %s firmware (%d bytes)\n", FWFILE, size);
134
135 if (cx18_av_verifyfw(cx, fw) == 0)
136 cx18_av_write4_expect(cx, CXADEC_DL_CTL,
137 0x13000000 | fw->size, 0x13000000, 0x13000000);
138
139
140 cx18_av_and_or4(cx, CXADEC_PIN_CTRL1, ~0, 0x78000);
141
142
143
144
145
146
147 cx18_av_write4(cx, CXADEC_I2S_IN_CTL, 0x000000A0);
148
149
150
151
152
153
154
155
156 cx18_av_write4(cx, CXADEC_I2S_OUT_CTL, 0x000001A0);
157
158
159
160 cx18_av_write4(cx, CXADEC_PIN_CFG3, 0x5600B687);
161
162 cx18_av_write4_expect(cx, CXADEC_STD_DET_CTL, 0x000000F6, 0x000000F6,
163 0x3F00FFFF);
164
165
166
167
168
169 cx18_av_write4(cx, 0x09CC, 1);
170
171 v = cx18_read_reg(cx, CX18_AUDIO_ENABLE);
172
173 if (v & 0x800)
174 cx18_write_reg_expect(cx, v & 0xFFFFFBFF, CX18_AUDIO_ENABLE,
175 0, 0x400);
176
177
178 v = cx18_read_reg(cx, CX18_AUDIO_ENABLE);
179 u = v & CX18_AI1_MUX_MASK;
180 v &= ~CX18_AI1_MUX_MASK;
181 if (u == CX18_AI1_MUX_843_I2S || u == CX18_AI1_MUX_INVALID) {
182
183 v |= CX18_AI1_MUX_I2S1;
184 cx18_write_reg_expect(cx, v | 0xb00, CX18_AUDIO_ENABLE,
185 v, CX18_AI1_MUX_MASK);
186
187 v = (v & ~CX18_AI1_MUX_MASK) | CX18_AI1_MUX_843_I2S;
188 } else {
189
190 v |= CX18_AI1_MUX_843_I2S;
191 cx18_write_reg_expect(cx, v | 0xb00, CX18_AUDIO_ENABLE,
192 v, CX18_AI1_MUX_MASK);
193
194 v = (v & ~CX18_AI1_MUX_MASK) | u;
195 }
196 cx18_write_reg_expect(cx, v | 0xb00, CX18_AUDIO_ENABLE,
197 v, CX18_AI1_MUX_MASK);
198
199
200 v = cx18_av_read4(cx, CXADEC_STD_DET_CTL);
201 v |= 0xFF;
202 v |= 0x400;
203 v |= 0x14000000;
204 cx18_av_write4_expect(cx, CXADEC_STD_DET_CTL, v, v, 0x3F00FFFF);
205
206 release_firmware(fw);
207 return 0;
208 }
209
210 MODULE_FIRMWARE(FWFILE);