diff options
Diffstat (limited to 'drivers/media/video/cx18/cx18-firmware.c')
-rw-r--r-- | drivers/media/video/cx18/cx18-firmware.c | 140 |
1 files changed, 75 insertions, 65 deletions
diff --git a/drivers/media/video/cx18/cx18-firmware.c b/drivers/media/video/cx18/cx18-firmware.c index 78fadd2ada5d..51534428cd00 100644 --- a/drivers/media/video/cx18/cx18-firmware.c +++ b/drivers/media/video/cx18/cx18-firmware.c | |||
@@ -20,6 +20,7 @@ | |||
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include "cx18-driver.h" | 22 | #include "cx18-driver.h" |
23 | #include "cx18-io.h" | ||
23 | #include "cx18-scb.h" | 24 | #include "cx18-scb.h" |
24 | #include "cx18-irq.h" | 25 | #include "cx18-irq.h" |
25 | #include "cx18-firmware.h" | 26 | #include "cx18-firmware.h" |
@@ -113,11 +114,11 @@ static int load_cpu_fw_direct(const char *fn, u8 __iomem *mem, struct cx18 *cx) | |||
113 | src = (const u32 *)fw->data; | 114 | src = (const u32 *)fw->data; |
114 | 115 | ||
115 | for (i = 0; i < fw->size; i += 4096) { | 116 | for (i = 0; i < fw->size; i += 4096) { |
116 | setup_page(i); | 117 | cx18_setup_page(cx, i); |
117 | for (j = i; j < fw->size && j < i + 4096; j += 4) { | 118 | for (j = i; j < fw->size && j < i + 4096; j += 4) { |
118 | /* no need for endianness conversion on the ppc */ | 119 | /* no need for endianness conversion on the ppc */ |
119 | __raw_writel(*src, dst); | 120 | cx18_raw_writel(cx, *src, dst); |
120 | if (__raw_readl(dst) != *src) { | 121 | if (cx18_raw_readl(cx, dst) != *src) { |
121 | CX18_ERR("Mismatch at offset %x\n", i); | 122 | CX18_ERR("Mismatch at offset %x\n", i); |
122 | release_firmware(fw); | 123 | release_firmware(fw); |
123 | return -EIO; | 124 | return -EIO; |
@@ -170,12 +171,15 @@ static int load_apu_fw_direct(const char *fn, u8 __iomem *dst, struct cx18 *cx) | |||
170 | if (offset + seghdr.size > sz) | 171 | if (offset + seghdr.size > sz) |
171 | break; | 172 | break; |
172 | for (i = 0; i < seghdr.size; i += 4096) { | 173 | for (i = 0; i < seghdr.size; i += 4096) { |
173 | setup_page(offset + i); | 174 | cx18_setup_page(cx, offset + i); |
174 | for (j = i; j < seghdr.size && j < i + 4096; j += 4) { | 175 | for (j = i; j < seghdr.size && j < i + 4096; j += 4) { |
175 | /* no need for endianness conversion on the ppc */ | 176 | /* no need for endianness conversion on the ppc */ |
176 | __raw_writel(src[(offset + j) / 4], dst + seghdr.addr + j); | 177 | cx18_raw_writel(cx, src[(offset + j) / 4], |
177 | if (__raw_readl(dst + seghdr.addr + j) != src[(offset + j) / 4]) { | 178 | dst + seghdr.addr + j); |
178 | CX18_ERR("Mismatch at offset %x\n", offset + j); | 179 | if (cx18_raw_readl(cx, dst + seghdr.addr + j) |
180 | != src[(offset + j) / 4]) { | ||
181 | CX18_ERR("Mismatch at offset %x\n", | ||
182 | offset + j); | ||
179 | release_firmware(fw); | 183 | release_firmware(fw); |
180 | return -EIO; | 184 | return -EIO; |
181 | } | 185 | } |
@@ -189,43 +193,45 @@ static int load_apu_fw_direct(const char *fn, u8 __iomem *dst, struct cx18 *cx) | |||
189 | size = fw->size; | 193 | size = fw->size; |
190 | release_firmware(fw); | 194 | release_firmware(fw); |
191 | /* Clear bit0 for APU to start from 0 */ | 195 | /* Clear bit0 for APU to start from 0 */ |
192 | write_reg(read_reg(0xc72030) & ~1, 0xc72030); | 196 | cx18_write_reg(cx, cx18_read_reg(cx, 0xc72030) & ~1, 0xc72030); |
193 | return size; | 197 | return size; |
194 | } | 198 | } |
195 | 199 | ||
196 | void cx18_halt_firmware(struct cx18 *cx) | 200 | void cx18_halt_firmware(struct cx18 *cx) |
197 | { | 201 | { |
198 | CX18_DEBUG_INFO("Preparing for firmware halt.\n"); | 202 | CX18_DEBUG_INFO("Preparing for firmware halt.\n"); |
199 | write_reg(0x000F000F, CX18_PROC_SOFT_RESET); /* stop the fw */ | 203 | cx18_write_reg(cx, 0x000F000F, CX18_PROC_SOFT_RESET); /* stop the fw */ |
200 | write_reg(0x00020002, CX18_ADEC_CONTROL); | 204 | cx18_write_reg(cx, 0x00020002, CX18_ADEC_CONTROL); |
201 | } | 205 | } |
202 | 206 | ||
203 | void cx18_init_power(struct cx18 *cx, int lowpwr) | 207 | void cx18_init_power(struct cx18 *cx, int lowpwr) |
204 | { | 208 | { |
205 | /* power-down Spare and AOM PLLs */ | 209 | /* power-down Spare and AOM PLLs */ |
206 | /* power-up fast, slow and mpeg PLLs */ | 210 | /* power-up fast, slow and mpeg PLLs */ |
207 | write_reg(0x00000008, CX18_PLL_POWER_DOWN); | 211 | cx18_write_reg(cx, 0x00000008, CX18_PLL_POWER_DOWN); |
208 | 212 | ||
209 | /* ADEC out of sleep */ | 213 | /* ADEC out of sleep */ |
210 | write_reg(0x00020000, CX18_ADEC_CONTROL); | 214 | cx18_write_reg(cx, 0x00020000, CX18_ADEC_CONTROL); |
211 | 215 | ||
212 | /* The fast clock is at 200/245 MHz */ | 216 | /* The fast clock is at 200/245 MHz */ |
213 | write_reg(lowpwr ? 0xD : 0x11, CX18_FAST_CLOCK_PLL_INT); | 217 | cx18_write_reg(cx, lowpwr ? 0xD : 0x11, CX18_FAST_CLOCK_PLL_INT); |
214 | write_reg(lowpwr ? 0x1EFBF37 : 0x038E3D7, CX18_FAST_CLOCK_PLL_FRAC); | 218 | cx18_write_reg(cx, lowpwr ? 0x1EFBF37 : 0x038E3D7, |
219 | CX18_FAST_CLOCK_PLL_FRAC); | ||
215 | 220 | ||
216 | write_reg(2, CX18_FAST_CLOCK_PLL_POST); | 221 | cx18_write_reg(cx, 2, CX18_FAST_CLOCK_PLL_POST); |
217 | write_reg(1, CX18_FAST_CLOCK_PLL_PRESCALE); | 222 | cx18_write_reg(cx, 1, CX18_FAST_CLOCK_PLL_PRESCALE); |
218 | write_reg(4, CX18_FAST_CLOCK_PLL_ADJUST_BANDWIDTH); | 223 | cx18_write_reg(cx, 4, CX18_FAST_CLOCK_PLL_ADJUST_BANDWIDTH); |
219 | 224 | ||
220 | /* set slow clock to 125/120 MHz */ | 225 | /* set slow clock to 125/120 MHz */ |
221 | write_reg(lowpwr ? 0x11 : 0x10, CX18_SLOW_CLOCK_PLL_INT); | 226 | cx18_write_reg(cx, lowpwr ? 0x11 : 0x10, CX18_SLOW_CLOCK_PLL_INT); |
222 | write_reg(lowpwr ? 0xEBAF05 : 0x18618A8, CX18_SLOW_CLOCK_PLL_FRAC); | 227 | cx18_write_reg(cx, lowpwr ? 0xEBAF05 : 0x18618A8, |
223 | write_reg(4, CX18_SLOW_CLOCK_PLL_POST); | 228 | CX18_SLOW_CLOCK_PLL_FRAC); |
229 | cx18_write_reg(cx, 4, CX18_SLOW_CLOCK_PLL_POST); | ||
224 | 230 | ||
225 | /* mpeg clock pll 54MHz */ | 231 | /* mpeg clock pll 54MHz */ |
226 | write_reg(0xF, CX18_MPEG_CLOCK_PLL_INT); | 232 | cx18_write_reg(cx, 0xF, CX18_MPEG_CLOCK_PLL_INT); |
227 | write_reg(0x2BCFEF, CX18_MPEG_CLOCK_PLL_FRAC); | 233 | cx18_write_reg(cx, 0x2BCFEF, CX18_MPEG_CLOCK_PLL_FRAC); |
228 | write_reg(8, CX18_MPEG_CLOCK_PLL_POST); | 234 | cx18_write_reg(cx, 8, CX18_MPEG_CLOCK_PLL_POST); |
229 | 235 | ||
230 | /* Defaults */ | 236 | /* Defaults */ |
231 | /* APU = SC or SC/2 = 125/62.5 */ | 237 | /* APU = SC or SC/2 = 125/62.5 */ |
@@ -242,81 +248,84 @@ void cx18_init_power(struct cx18 *cx, int lowpwr) | |||
242 | /* VFC = disabled */ | 248 | /* VFC = disabled */ |
243 | /* USB = disabled */ | 249 | /* USB = disabled */ |
244 | 250 | ||
245 | write_reg(lowpwr ? 0xFFFF0020 : 0x00060004, CX18_CLOCK_SELECT1); | 251 | cx18_write_reg(cx, lowpwr ? 0xFFFF0020 : 0x00060004, |
246 | write_reg(lowpwr ? 0xFFFF0004 : 0x00060006, CX18_CLOCK_SELECT2); | 252 | CX18_CLOCK_SELECT1); |
253 | cx18_write_reg(cx, lowpwr ? 0xFFFF0004 : 0x00060006, | ||
254 | CX18_CLOCK_SELECT2); | ||
247 | 255 | ||
248 | write_reg(0xFFFF0002, CX18_HALF_CLOCK_SELECT1); | 256 | cx18_write_reg(cx, 0xFFFF0002, CX18_HALF_CLOCK_SELECT1); |
249 | write_reg(0xFFFF0104, CX18_HALF_CLOCK_SELECT2); | 257 | cx18_write_reg(cx, 0xFFFF0104, CX18_HALF_CLOCK_SELECT2); |
250 | 258 | ||
251 | write_reg(0xFFFF9026, CX18_CLOCK_ENABLE1); | 259 | cx18_write_reg(cx, 0xFFFF9026, CX18_CLOCK_ENABLE1); |
252 | write_reg(0xFFFF3105, CX18_CLOCK_ENABLE2); | 260 | cx18_write_reg(cx, 0xFFFF3105, CX18_CLOCK_ENABLE2); |
253 | } | 261 | } |
254 | 262 | ||
255 | void cx18_init_memory(struct cx18 *cx) | 263 | void cx18_init_memory(struct cx18 *cx) |
256 | { | 264 | { |
257 | cx18_msleep_timeout(10, 0); | 265 | cx18_msleep_timeout(10, 0); |
258 | write_reg(0x10000, CX18_DDR_SOFT_RESET); | 266 | cx18_write_reg(cx, 0x10000, CX18_DDR_SOFT_RESET); |
259 | cx18_msleep_timeout(10, 0); | 267 | cx18_msleep_timeout(10, 0); |
260 | 268 | ||
261 | write_reg(cx->card->ddr.chip_config, CX18_DDR_CHIP_CONFIG); | 269 | cx18_write_reg(cx, cx->card->ddr.chip_config, CX18_DDR_CHIP_CONFIG); |
262 | 270 | ||
263 | cx18_msleep_timeout(10, 0); | 271 | cx18_msleep_timeout(10, 0); |
264 | 272 | ||
265 | write_reg(cx->card->ddr.refresh, CX18_DDR_REFRESH); | 273 | cx18_write_reg(cx, cx->card->ddr.refresh, CX18_DDR_REFRESH); |
266 | write_reg(cx->card->ddr.timing1, CX18_DDR_TIMING1); | 274 | cx18_write_reg(cx, cx->card->ddr.timing1, CX18_DDR_TIMING1); |
267 | write_reg(cx->card->ddr.timing2, CX18_DDR_TIMING2); | 275 | cx18_write_reg(cx, cx->card->ddr.timing2, CX18_DDR_TIMING2); |
268 | 276 | ||
269 | cx18_msleep_timeout(10, 0); | 277 | cx18_msleep_timeout(10, 0); |
270 | 278 | ||
271 | /* Initialize DQS pad time */ | 279 | /* Initialize DQS pad time */ |
272 | write_reg(cx->card->ddr.tune_lane, CX18_DDR_TUNE_LANE); | 280 | cx18_write_reg(cx, cx->card->ddr.tune_lane, CX18_DDR_TUNE_LANE); |
273 | write_reg(cx->card->ddr.initial_emrs, CX18_DDR_INITIAL_EMRS); | 281 | cx18_write_reg(cx, cx->card->ddr.initial_emrs, CX18_DDR_INITIAL_EMRS); |
274 | 282 | ||
275 | cx18_msleep_timeout(10, 0); | 283 | cx18_msleep_timeout(10, 0); |
276 | 284 | ||
277 | write_reg(0x20000, CX18_DDR_SOFT_RESET); | 285 | cx18_write_reg(cx, 0x20000, CX18_DDR_SOFT_RESET); |
278 | cx18_msleep_timeout(10, 0); | 286 | cx18_msleep_timeout(10, 0); |
279 | 287 | ||
280 | /* use power-down mode when idle */ | 288 | /* use power-down mode when idle */ |
281 | write_reg(0x00000010, CX18_DDR_POWER_REG); | 289 | cx18_write_reg(cx, 0x00000010, CX18_DDR_POWER_REG); |
282 | 290 | ||
283 | write_reg(0x10001, CX18_REG_BUS_TIMEOUT_EN); | 291 | cx18_write_reg(cx, 0x10001, CX18_REG_BUS_TIMEOUT_EN); |
284 | 292 | ||
285 | write_reg(0x48, CX18_DDR_MB_PER_ROW_7); | 293 | cx18_write_reg(cx, 0x48, CX18_DDR_MB_PER_ROW_7); |
286 | write_reg(0xE0000, CX18_DDR_BASE_63_ADDR); | 294 | cx18_write_reg(cx, 0xE0000, CX18_DDR_BASE_63_ADDR); |
287 | 295 | ||
288 | write_reg(0x00000101, CX18_WMB_CLIENT02); /* AO */ | 296 | cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT02); /* AO */ |
289 | write_reg(0x00000101, CX18_WMB_CLIENT09); /* AI2 */ | 297 | cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT09); /* AI2 */ |
290 | write_reg(0x00000101, CX18_WMB_CLIENT05); /* VIM1 */ | 298 | cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT05); /* VIM1 */ |
291 | write_reg(0x00000101, CX18_WMB_CLIENT06); /* AI1 */ | 299 | cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT06); /* AI1 */ |
292 | write_reg(0x00000101, CX18_WMB_CLIENT07); /* 3D comb */ | 300 | cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT07); /* 3D comb */ |
293 | write_reg(0x00000101, CX18_WMB_CLIENT10); /* ME */ | 301 | cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT10); /* ME */ |
294 | write_reg(0x00000101, CX18_WMB_CLIENT12); /* ENC */ | 302 | cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT12); /* ENC */ |
295 | write_reg(0x00000101, CX18_WMB_CLIENT13); /* PK */ | 303 | cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT13); /* PK */ |
296 | write_reg(0x00000101, CX18_WMB_CLIENT11); /* RC */ | 304 | cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT11); /* RC */ |
297 | write_reg(0x00000101, CX18_WMB_CLIENT14); /* AVO */ | 305 | cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT14); /* AVO */ |
298 | } | 306 | } |
299 | 307 | ||
300 | int cx18_firmware_init(struct cx18 *cx) | 308 | int cx18_firmware_init(struct cx18 *cx) |
301 | { | 309 | { |
302 | /* Allow chip to control CLKRUN */ | 310 | /* Allow chip to control CLKRUN */ |
303 | write_reg(0x5, CX18_DSP0_INTERRUPT_MASK); | 311 | cx18_write_reg(cx, 0x5, CX18_DSP0_INTERRUPT_MASK); |
304 | 312 | ||
305 | write_reg(0x000F000F, CX18_PROC_SOFT_RESET); /* stop the fw */ | 313 | cx18_write_reg(cx, 0x000F000F, CX18_PROC_SOFT_RESET); /* stop the fw */ |
306 | 314 | ||
307 | cx18_msleep_timeout(1, 0); | 315 | cx18_msleep_timeout(1, 0); |
308 | 316 | ||
309 | sw1_irq_enable(IRQ_CPU_TO_EPU | IRQ_APU_TO_EPU); | 317 | cx18_sw1_irq_enable(cx, IRQ_CPU_TO_EPU | IRQ_APU_TO_EPU); |
310 | sw2_irq_enable(IRQ_CPU_TO_EPU_ACK | IRQ_APU_TO_EPU_ACK); | 318 | cx18_sw2_irq_enable(cx, IRQ_CPU_TO_EPU_ACK | IRQ_APU_TO_EPU_ACK); |
311 | 319 | ||
312 | /* Only if the processor is not running */ | 320 | /* Only if the processor is not running */ |
313 | if (read_reg(CX18_PROC_SOFT_RESET) & 8) { | 321 | if (cx18_read_reg(cx, CX18_PROC_SOFT_RESET) & 8) { |
314 | int sz = load_apu_fw_direct("v4l-cx23418-apu.fw", | 322 | int sz = load_apu_fw_direct("v4l-cx23418-apu.fw", |
315 | cx->enc_mem, cx); | 323 | cx->enc_mem, cx); |
316 | 324 | ||
317 | write_enc(0xE51FF004, 0); | 325 | cx18_write_enc(cx, 0xE51FF004, 0); |
318 | write_enc(0xa00000, 4); /* todo: not hardcoded */ | 326 | cx18_write_enc(cx, 0xa00000, 4); /* todo: not hardcoded */ |
319 | write_reg(0x00010000, CX18_PROC_SOFT_RESET); /* Start APU */ | 327 | /* Start APU */ |
328 | cx18_write_reg(cx, 0x00010000, CX18_PROC_SOFT_RESET); | ||
320 | cx18_msleep_timeout(500, 0); | 329 | cx18_msleep_timeout(500, 0); |
321 | 330 | ||
322 | sz = sz <= 0 ? sz : load_cpu_fw_direct("v4l-cx23418-cpu.fw", | 331 | sz = sz <= 0 ? sz : load_cpu_fw_direct("v4l-cx23418-cpu.fw", |
@@ -326,9 +335,10 @@ int cx18_firmware_init(struct cx18 *cx) | |||
326 | int retries = 0; | 335 | int retries = 0; |
327 | 336 | ||
328 | /* start the CPU */ | 337 | /* start the CPU */ |
329 | write_reg(0x00080000, CX18_PROC_SOFT_RESET); | 338 | cx18_write_reg(cx, 0x00080000, CX18_PROC_SOFT_RESET); |
330 | while (retries++ < 50) { /* Loop for max 500mS */ | 339 | while (retries++ < 50) { /* Loop for max 500mS */ |
331 | if ((read_reg(CX18_PROC_SOFT_RESET) & 1) == 0) | 340 | if ((cx18_read_reg(cx, CX18_PROC_SOFT_RESET) |
341 | & 1) == 0) | ||
332 | break; | 342 | break; |
333 | cx18_msleep_timeout(10, 0); | 343 | cx18_msleep_timeout(10, 0); |
334 | } | 344 | } |
@@ -342,6 +352,6 @@ int cx18_firmware_init(struct cx18 *cx) | |||
342 | return -EIO; | 352 | return -EIO; |
343 | } | 353 | } |
344 | /* initialize GPIO */ | 354 | /* initialize GPIO */ |
345 | write_reg(0x14001400, 0xC78110); | 355 | cx18_write_reg(cx, 0x14001400, 0xC78110); |
346 | return 0; | 356 | return 0; |
347 | } | 357 | } |