Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 1 | /* |
| 2 | * cx18 firmware functions |
| 3 | * |
| 4 | * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl> |
Andy Walls | 1ed9dcc | 2008-11-22 01:37:34 -0300 | [diff] [blame^] | 5 | * Copyright (C) 2008 Andy Walls <awalls@radix.net> |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 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 |
| 20 | * 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | #include "cx18-driver.h" |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 24 | #include "cx18-io.h" |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 25 | #include "cx18-scb.h" |
| 26 | #include "cx18-irq.h" |
| 27 | #include "cx18-firmware.h" |
| 28 | #include "cx18-cards.h" |
| 29 | #include <linux/firmware.h> |
| 30 | |
| 31 | #define CX18_PROC_SOFT_RESET 0xc70010 |
| 32 | #define CX18_DDR_SOFT_RESET 0xc70014 |
| 33 | #define CX18_CLOCK_SELECT1 0xc71000 |
| 34 | #define CX18_CLOCK_SELECT2 0xc71004 |
| 35 | #define CX18_HALF_CLOCK_SELECT1 0xc71008 |
| 36 | #define CX18_HALF_CLOCK_SELECT2 0xc7100C |
| 37 | #define CX18_CLOCK_POLARITY1 0xc71010 |
| 38 | #define CX18_CLOCK_POLARITY2 0xc71014 |
| 39 | #define CX18_ADD_DELAY_ENABLE1 0xc71018 |
| 40 | #define CX18_ADD_DELAY_ENABLE2 0xc7101C |
| 41 | #define CX18_CLOCK_ENABLE1 0xc71020 |
| 42 | #define CX18_CLOCK_ENABLE2 0xc71024 |
| 43 | |
| 44 | #define CX18_REG_BUS_TIMEOUT_EN 0xc72024 |
| 45 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 46 | #define CX18_FAST_CLOCK_PLL_INT 0xc78000 |
| 47 | #define CX18_FAST_CLOCK_PLL_FRAC 0xc78004 |
| 48 | #define CX18_FAST_CLOCK_PLL_POST 0xc78008 |
| 49 | #define CX18_FAST_CLOCK_PLL_PRESCALE 0xc7800C |
| 50 | #define CX18_FAST_CLOCK_PLL_ADJUST_BANDWIDTH 0xc78010 |
| 51 | |
| 52 | #define CX18_SLOW_CLOCK_PLL_INT 0xc78014 |
| 53 | #define CX18_SLOW_CLOCK_PLL_FRAC 0xc78018 |
| 54 | #define CX18_SLOW_CLOCK_PLL_POST 0xc7801C |
| 55 | #define CX18_MPEG_CLOCK_PLL_INT 0xc78040 |
| 56 | #define CX18_MPEG_CLOCK_PLL_FRAC 0xc78044 |
| 57 | #define CX18_MPEG_CLOCK_PLL_POST 0xc78048 |
| 58 | #define CX18_PLL_POWER_DOWN 0xc78088 |
| 59 | #define CX18_SW1_INT_STATUS 0xc73104 |
| 60 | #define CX18_SW1_INT_ENABLE_PCI 0xc7311C |
| 61 | #define CX18_SW2_INT_SET 0xc73140 |
| 62 | #define CX18_SW2_INT_STATUS 0xc73144 |
| 63 | #define CX18_ADEC_CONTROL 0xc78120 |
| 64 | |
| 65 | #define CX18_DDR_REQUEST_ENABLE 0xc80000 |
| 66 | #define CX18_DDR_CHIP_CONFIG 0xc80004 |
| 67 | #define CX18_DDR_REFRESH 0xc80008 |
| 68 | #define CX18_DDR_TIMING1 0xc8000C |
| 69 | #define CX18_DDR_TIMING2 0xc80010 |
| 70 | #define CX18_DDR_POWER_REG 0xc8001C |
| 71 | |
| 72 | #define CX18_DDR_TUNE_LANE 0xc80048 |
| 73 | #define CX18_DDR_INITIAL_EMRS 0xc80054 |
| 74 | #define CX18_DDR_MB_PER_ROW_7 0xc8009C |
| 75 | #define CX18_DDR_BASE_63_ADDR 0xc804FC |
| 76 | |
| 77 | #define CX18_WMB_CLIENT02 0xc90108 |
| 78 | #define CX18_WMB_CLIENT05 0xc90114 |
| 79 | #define CX18_WMB_CLIENT06 0xc90118 |
| 80 | #define CX18_WMB_CLIENT07 0xc9011C |
| 81 | #define CX18_WMB_CLIENT08 0xc90120 |
| 82 | #define CX18_WMB_CLIENT09 0xc90124 |
| 83 | #define CX18_WMB_CLIENT10 0xc90128 |
| 84 | #define CX18_WMB_CLIENT11 0xc9012C |
| 85 | #define CX18_WMB_CLIENT12 0xc90130 |
| 86 | #define CX18_WMB_CLIENT13 0xc90134 |
| 87 | #define CX18_WMB_CLIENT14 0xc90138 |
| 88 | |
| 89 | #define CX18_DSP0_INTERRUPT_MASK 0xd0004C |
| 90 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 91 | #define APU_ROM_SYNC1 0x6D676553 /* "mgeS" */ |
| 92 | #define APU_ROM_SYNC2 0x72646548 /* "rdeH" */ |
| 93 | |
| 94 | struct cx18_apu_rom_seghdr { |
| 95 | u32 sync1; |
| 96 | u32 sync2; |
| 97 | u32 addr; |
| 98 | u32 size; |
| 99 | }; |
| 100 | |
Hans Verkuil | 82fc52a | 2008-07-19 08:34:12 -0300 | [diff] [blame] | 101 | static int load_cpu_fw_direct(const char *fn, u8 __iomem *mem, struct cx18 *cx) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 102 | { |
| 103 | const struct firmware *fw = NULL; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 104 | int i, j; |
Hans Verkuil | 82fc52a | 2008-07-19 08:34:12 -0300 | [diff] [blame] | 105 | unsigned size; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 106 | u32 __iomem *dst = (u32 __iomem *)mem; |
| 107 | const u32 *src; |
| 108 | |
Hans Verkuil | 82fc52a | 2008-07-19 08:34:12 -0300 | [diff] [blame] | 109 | if (request_firmware(&fw, fn, &cx->dev->dev)) { |
| 110 | CX18_ERR("Unable to open firmware %s\n", fn); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 111 | CX18_ERR("Did you put the firmware in the hotplug firmware directory?\n"); |
| 112 | return -ENOMEM; |
| 113 | } |
| 114 | |
| 115 | src = (const u32 *)fw->data; |
| 116 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 117 | for (i = 0; i < fw->size; i += 4096) { |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 118 | cx18_setup_page(cx, i); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 119 | for (j = i; j < fw->size && j < i + 4096; j += 4) { |
| 120 | /* no need for endianness conversion on the ppc */ |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 121 | cx18_raw_writel(cx, *src, dst); |
| 122 | if (cx18_raw_readl(cx, dst) != *src) { |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 123 | CX18_ERR("Mismatch at offset %x\n", i); |
| 124 | release_firmware(fw); |
Andy Walls | ee2d64f | 2008-11-16 01:38:19 -0300 | [diff] [blame] | 125 | cx18_setup_page(cx, 0); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 126 | return -EIO; |
| 127 | } |
| 128 | dst++; |
| 129 | src++; |
| 130 | } |
| 131 | } |
| 132 | if (!test_bit(CX18_F_I_LOADED_FW, &cx->i_flags)) |
| 133 | CX18_INFO("loaded %s firmware (%zd bytes)\n", fn, fw->size); |
Hans Verkuil | 82fc52a | 2008-07-19 08:34:12 -0300 | [diff] [blame] | 134 | size = fw->size; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 135 | release_firmware(fw); |
Andy Walls | ee2d64f | 2008-11-16 01:38:19 -0300 | [diff] [blame] | 136 | cx18_setup_page(cx, SCB_OFFSET); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 137 | return size; |
| 138 | } |
| 139 | |
Andy Walls | 2d1a1b0 | 2008-11-08 17:14:22 -0300 | [diff] [blame] | 140 | static int load_apu_fw_direct(const char *fn, u8 __iomem *dst, struct cx18 *cx, |
| 141 | u32 *entry_addr) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 142 | { |
| 143 | const struct firmware *fw = NULL; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 144 | int i, j; |
Hans Verkuil | 82fc52a | 2008-07-19 08:34:12 -0300 | [diff] [blame] | 145 | unsigned size; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 146 | const u32 *src; |
| 147 | struct cx18_apu_rom_seghdr seghdr; |
| 148 | const u8 *vers; |
| 149 | u32 offset = 0; |
| 150 | u32 apu_version = 0; |
| 151 | int sz; |
| 152 | |
Hans Verkuil | 82fc52a | 2008-07-19 08:34:12 -0300 | [diff] [blame] | 153 | if (request_firmware(&fw, fn, &cx->dev->dev)) { |
| 154 | CX18_ERR("unable to open firmware %s\n", fn); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 155 | CX18_ERR("did you put the firmware in the hotplug firmware directory?\n"); |
Andy Walls | ee2d64f | 2008-11-16 01:38:19 -0300 | [diff] [blame] | 156 | cx18_setup_page(cx, 0); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 157 | return -ENOMEM; |
| 158 | } |
| 159 | |
Andy Walls | c7abfb4 | 2008-11-09 19:51:44 -0300 | [diff] [blame] | 160 | *entry_addr = 0; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 161 | src = (const u32 *)fw->data; |
| 162 | vers = fw->data + sizeof(seghdr); |
| 163 | sz = fw->size; |
| 164 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 165 | apu_version = (vers[0] << 24) | (vers[4] << 16) | vers[32]; |
Hans Verkuil | 82fc52a | 2008-07-19 08:34:12 -0300 | [diff] [blame] | 166 | while (offset + sizeof(seghdr) < fw->size) { |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 167 | /* TODO: byteswapping */ |
| 168 | memcpy(&seghdr, src + offset / 4, sizeof(seghdr)); |
| 169 | offset += sizeof(seghdr); |
| 170 | if (seghdr.sync1 != APU_ROM_SYNC1 || |
| 171 | seghdr.sync2 != APU_ROM_SYNC2) { |
| 172 | offset += seghdr.size; |
| 173 | continue; |
| 174 | } |
| 175 | CX18_DEBUG_INFO("load segment %x-%x\n", seghdr.addr, |
| 176 | seghdr.addr + seghdr.size - 1); |
Andy Walls | c7abfb4 | 2008-11-09 19:51:44 -0300 | [diff] [blame] | 177 | if (*entry_addr == 0) |
Andy Walls | 2d1a1b0 | 2008-11-08 17:14:22 -0300 | [diff] [blame] | 178 | *entry_addr = seghdr.addr; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 179 | if (offset + seghdr.size > sz) |
| 180 | break; |
| 181 | for (i = 0; i < seghdr.size; i += 4096) { |
Andy Walls | 2d1a1b0 | 2008-11-08 17:14:22 -0300 | [diff] [blame] | 182 | cx18_setup_page(cx, seghdr.addr + i); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 183 | for (j = i; j < seghdr.size && j < i + 4096; j += 4) { |
| 184 | /* no need for endianness conversion on the ppc */ |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 185 | cx18_raw_writel(cx, src[(offset + j) / 4], |
| 186 | dst + seghdr.addr + j); |
| 187 | if (cx18_raw_readl(cx, dst + seghdr.addr + j) |
| 188 | != src[(offset + j) / 4]) { |
| 189 | CX18_ERR("Mismatch at offset %x\n", |
| 190 | offset + j); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 191 | release_firmware(fw); |
Andy Walls | ee2d64f | 2008-11-16 01:38:19 -0300 | [diff] [blame] | 192 | cx18_setup_page(cx, 0); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 193 | return -EIO; |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | offset += seghdr.size; |
| 198 | } |
| 199 | if (!test_bit(CX18_F_I_LOADED_FW, &cx->i_flags)) |
| 200 | CX18_INFO("loaded %s firmware V%08x (%zd bytes)\n", |
| 201 | fn, apu_version, fw->size); |
Hans Verkuil | 82fc52a | 2008-07-19 08:34:12 -0300 | [diff] [blame] | 202 | size = fw->size; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 203 | release_firmware(fw); |
Andy Walls | ee2d64f | 2008-11-16 01:38:19 -0300 | [diff] [blame] | 204 | cx18_setup_page(cx, 0); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 205 | return size; |
| 206 | } |
| 207 | |
| 208 | void cx18_halt_firmware(struct cx18 *cx) |
| 209 | { |
| 210 | CX18_DEBUG_INFO("Preparing for firmware halt.\n"); |
Andy Walls | ced0737 | 2008-11-02 10:59:04 -0300 | [diff] [blame] | 211 | cx18_write_reg_expect(cx, 0x000F000F, CX18_PROC_SOFT_RESET, |
| 212 | 0x0000000F, 0x000F000F); |
| 213 | cx18_write_reg_expect(cx, 0x00020002, CX18_ADEC_CONTROL, |
| 214 | 0x00000002, 0x00020002); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | void cx18_init_power(struct cx18 *cx, int lowpwr) |
| 218 | { |
| 219 | /* power-down Spare and AOM PLLs */ |
| 220 | /* power-up fast, slow and mpeg PLLs */ |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 221 | cx18_write_reg(cx, 0x00000008, CX18_PLL_POWER_DOWN); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 222 | |
| 223 | /* ADEC out of sleep */ |
Andy Walls | ced0737 | 2008-11-02 10:59:04 -0300 | [diff] [blame] | 224 | cx18_write_reg_expect(cx, 0x00020000, CX18_ADEC_CONTROL, |
| 225 | 0x00000000, 0x00020002); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 226 | |
| 227 | /* The fast clock is at 200/245 MHz */ |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 228 | cx18_write_reg(cx, lowpwr ? 0xD : 0x11, CX18_FAST_CLOCK_PLL_INT); |
| 229 | cx18_write_reg(cx, lowpwr ? 0x1EFBF37 : 0x038E3D7, |
| 230 | CX18_FAST_CLOCK_PLL_FRAC); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 231 | |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 232 | cx18_write_reg(cx, 2, CX18_FAST_CLOCK_PLL_POST); |
| 233 | cx18_write_reg(cx, 1, CX18_FAST_CLOCK_PLL_PRESCALE); |
| 234 | cx18_write_reg(cx, 4, CX18_FAST_CLOCK_PLL_ADJUST_BANDWIDTH); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 235 | |
| 236 | /* set slow clock to 125/120 MHz */ |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 237 | cx18_write_reg(cx, lowpwr ? 0x11 : 0x10, CX18_SLOW_CLOCK_PLL_INT); |
| 238 | cx18_write_reg(cx, lowpwr ? 0xEBAF05 : 0x18618A8, |
| 239 | CX18_SLOW_CLOCK_PLL_FRAC); |
| 240 | cx18_write_reg(cx, 4, CX18_SLOW_CLOCK_PLL_POST); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 241 | |
| 242 | /* mpeg clock pll 54MHz */ |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 243 | cx18_write_reg(cx, 0xF, CX18_MPEG_CLOCK_PLL_INT); |
| 244 | cx18_write_reg(cx, 0x2BCFEF, CX18_MPEG_CLOCK_PLL_FRAC); |
| 245 | cx18_write_reg(cx, 8, CX18_MPEG_CLOCK_PLL_POST); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 246 | |
| 247 | /* Defaults */ |
| 248 | /* APU = SC or SC/2 = 125/62.5 */ |
| 249 | /* EPU = SC = 125 */ |
| 250 | /* DDR = FC = 180 */ |
| 251 | /* ENC = SC = 125 */ |
| 252 | /* AI1 = SC = 125 */ |
| 253 | /* VIM2 = disabled */ |
| 254 | /* PCI = FC/2 = 90 */ |
| 255 | /* AI2 = disabled */ |
| 256 | /* DEMUX = disabled */ |
| 257 | /* AO = SC/2 = 62.5 */ |
| 258 | /* SER = 54MHz */ |
| 259 | /* VFC = disabled */ |
| 260 | /* USB = disabled */ |
| 261 | |
Andy Walls | ced0737 | 2008-11-02 10:59:04 -0300 | [diff] [blame] | 262 | if (lowpwr) { |
| 263 | cx18_write_reg_expect(cx, 0xFFFF0020, CX18_CLOCK_SELECT1, |
| 264 | 0x00000020, 0xFFFFFFFF); |
| 265 | cx18_write_reg_expect(cx, 0xFFFF0004, CX18_CLOCK_SELECT2, |
| 266 | 0x00000004, 0xFFFFFFFF); |
| 267 | } else { |
| 268 | /* This doesn't explicitly set every clock select */ |
| 269 | cx18_write_reg_expect(cx, 0x00060004, CX18_CLOCK_SELECT1, |
| 270 | 0x00000004, 0x00060006); |
| 271 | cx18_write_reg_expect(cx, 0x00060006, CX18_CLOCK_SELECT2, |
| 272 | 0x00000006, 0x00060006); |
| 273 | } |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 274 | |
Andy Walls | ced0737 | 2008-11-02 10:59:04 -0300 | [diff] [blame] | 275 | cx18_write_reg_expect(cx, 0xFFFF0002, CX18_HALF_CLOCK_SELECT1, |
| 276 | 0x00000002, 0xFFFFFFFF); |
| 277 | cx18_write_reg_expect(cx, 0xFFFF0104, CX18_HALF_CLOCK_SELECT2, |
| 278 | 0x00000104, 0xFFFFFFFF); |
| 279 | cx18_write_reg_expect(cx, 0xFFFF9026, CX18_CLOCK_ENABLE1, |
| 280 | 0x00009026, 0xFFFFFFFF); |
| 281 | cx18_write_reg_expect(cx, 0xFFFF3105, CX18_CLOCK_ENABLE2, |
| 282 | 0x00003105, 0xFFFFFFFF); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | void cx18_init_memory(struct cx18 *cx) |
| 286 | { |
| 287 | cx18_msleep_timeout(10, 0); |
Andy Walls | ced0737 | 2008-11-02 10:59:04 -0300 | [diff] [blame] | 288 | cx18_write_reg_expect(cx, 0x00010000, CX18_DDR_SOFT_RESET, |
| 289 | 0x00000000, 0x00010001); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 290 | cx18_msleep_timeout(10, 0); |
| 291 | |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 292 | cx18_write_reg(cx, cx->card->ddr.chip_config, CX18_DDR_CHIP_CONFIG); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 293 | |
| 294 | cx18_msleep_timeout(10, 0); |
| 295 | |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 296 | cx18_write_reg(cx, cx->card->ddr.refresh, CX18_DDR_REFRESH); |
| 297 | cx18_write_reg(cx, cx->card->ddr.timing1, CX18_DDR_TIMING1); |
| 298 | cx18_write_reg(cx, cx->card->ddr.timing2, CX18_DDR_TIMING2); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 299 | |
| 300 | cx18_msleep_timeout(10, 0); |
| 301 | |
| 302 | /* Initialize DQS pad time */ |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 303 | cx18_write_reg(cx, cx->card->ddr.tune_lane, CX18_DDR_TUNE_LANE); |
| 304 | cx18_write_reg(cx, cx->card->ddr.initial_emrs, CX18_DDR_INITIAL_EMRS); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 305 | |
| 306 | cx18_msleep_timeout(10, 0); |
| 307 | |
Andy Walls | ced0737 | 2008-11-02 10:59:04 -0300 | [diff] [blame] | 308 | cx18_write_reg_expect(cx, 0x00020000, CX18_DDR_SOFT_RESET, |
| 309 | 0x00000000, 0x00020002); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 310 | cx18_msleep_timeout(10, 0); |
| 311 | |
| 312 | /* use power-down mode when idle */ |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 313 | cx18_write_reg(cx, 0x00000010, CX18_DDR_POWER_REG); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 314 | |
Andy Walls | ced0737 | 2008-11-02 10:59:04 -0300 | [diff] [blame] | 315 | cx18_write_reg_expect(cx, 0x00010001, CX18_REG_BUS_TIMEOUT_EN, |
| 316 | 0x00000001, 0x00010001); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 317 | |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 318 | cx18_write_reg(cx, 0x48, CX18_DDR_MB_PER_ROW_7); |
| 319 | cx18_write_reg(cx, 0xE0000, CX18_DDR_BASE_63_ADDR); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 320 | |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 321 | cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT02); /* AO */ |
| 322 | cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT09); /* AI2 */ |
| 323 | cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT05); /* VIM1 */ |
| 324 | cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT06); /* AI1 */ |
| 325 | cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT07); /* 3D comb */ |
| 326 | cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT10); /* ME */ |
| 327 | cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT12); /* ENC */ |
| 328 | cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT13); /* PK */ |
| 329 | cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT11); /* RC */ |
| 330 | cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT14); /* AVO */ |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | int cx18_firmware_init(struct cx18 *cx) |
| 334 | { |
| 335 | /* Allow chip to control CLKRUN */ |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 336 | cx18_write_reg(cx, 0x5, CX18_DSP0_INTERRUPT_MASK); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 337 | |
Andy Walls | ced0737 | 2008-11-02 10:59:04 -0300 | [diff] [blame] | 338 | /* Stop the firmware */ |
| 339 | cx18_write_reg_expect(cx, 0x000F000F, CX18_PROC_SOFT_RESET, |
| 340 | 0x0000000F, 0x000F000F); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 341 | |
| 342 | cx18_msleep_timeout(1, 0); |
| 343 | |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 344 | cx18_sw1_irq_enable(cx, IRQ_CPU_TO_EPU | IRQ_APU_TO_EPU); |
| 345 | cx18_sw2_irq_enable(cx, IRQ_CPU_TO_EPU_ACK | IRQ_APU_TO_EPU_ACK); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 346 | |
| 347 | /* Only if the processor is not running */ |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 348 | if (cx18_read_reg(cx, CX18_PROC_SOFT_RESET) & 8) { |
Andy Walls | c7abfb4 | 2008-11-09 19:51:44 -0300 | [diff] [blame] | 349 | u32 fw_entry_addr = 0; |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 350 | int sz = load_apu_fw_direct("v4l-cx23418-apu.fw", |
Andy Walls | 2d1a1b0 | 2008-11-08 17:14:22 -0300 | [diff] [blame] | 351 | cx->enc_mem, cx, &fw_entry_addr); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 352 | |
Andy Walls | c7abfb4 | 2008-11-09 19:51:44 -0300 | [diff] [blame] | 353 | if (sz <= 0) |
| 354 | return sz; |
| 355 | |
Andy Walls | 2d1a1b0 | 2008-11-08 17:14:22 -0300 | [diff] [blame] | 356 | /* Clear bit0 for APU to start from 0 */ |
| 357 | cx18_write_reg(cx, cx18_read_reg(cx, 0xc72030) & ~1, 0xc72030); |
| 358 | |
| 359 | cx18_write_enc(cx, 0xE51FF004, 0); /* ldr pc, [pc, #-4] */ |
| 360 | cx18_write_enc(cx, fw_entry_addr, 4); |
| 361 | |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 362 | /* Start APU */ |
Andy Walls | ced0737 | 2008-11-02 10:59:04 -0300 | [diff] [blame] | 363 | cx18_write_reg_expect(cx, 0x00010000, CX18_PROC_SOFT_RESET, |
| 364 | 0x00000000, 0x00010001); |
Hans Verkuil | f24648e | 2008-06-22 12:11:13 -0300 | [diff] [blame] | 365 | cx18_msleep_timeout(500, 0); |
| 366 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 367 | sz = sz <= 0 ? sz : load_cpu_fw_direct("v4l-cx23418-cpu.fw", |
Hans Verkuil | 82fc52a | 2008-07-19 08:34:12 -0300 | [diff] [blame] | 368 | cx->enc_mem, cx); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 369 | |
| 370 | if (sz > 0) { |
| 371 | int retries = 0; |
| 372 | |
| 373 | /* start the CPU */ |
Andy Walls | ced0737 | 2008-11-02 10:59:04 -0300 | [diff] [blame] | 374 | cx18_write_reg_expect(cx, |
| 375 | 0x00080000, CX18_PROC_SOFT_RESET, |
| 376 | 0x00000000, 0x00080008); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 377 | while (retries++ < 50) { /* Loop for max 500mS */ |
Andy Walls | b152642 | 2008-08-30 16:03:44 -0300 | [diff] [blame] | 378 | if ((cx18_read_reg(cx, CX18_PROC_SOFT_RESET) |
| 379 | & 1) == 0) |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 380 | break; |
| 381 | cx18_msleep_timeout(10, 0); |
| 382 | } |
| 383 | cx18_msleep_timeout(200, 0); |
| 384 | if (retries == 51) { |
| 385 | CX18_ERR("Could not start the CPU\n"); |
| 386 | return -EIO; |
| 387 | } |
| 388 | } |
| 389 | if (sz <= 0) |
| 390 | return -EIO; |
| 391 | } |
Andy Walls | d20ceec | 2008-11-09 18:14:07 -0300 | [diff] [blame] | 392 | |
| 393 | /* |
| 394 | * The CPU firmware apparently sets up to receive an interrupt for it's |
| 395 | * outgoing IRQ_CPU_TO_EPU_ACK to us (*boggle*). We get an interrupt |
| 396 | * when it sends us an ack, but by the time we process it, that flag in |
| 397 | * the SW2 status register has been cleared by the CPU firmware. |
| 398 | * We'll prevent that not so useful behavior by clearing the CPU's |
| 399 | * interrupt enables for Ack IRQ's we want to process. |
| 400 | */ |
| 401 | cx18_sw2_irq_disable_cpu(cx, IRQ_CPU_TO_EPU_ACK | IRQ_APU_TO_EPU_ACK); |
| 402 | |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 403 | /* initialize GPIO */ |
Andy Walls | ced0737 | 2008-11-02 10:59:04 -0300 | [diff] [blame] | 404 | cx18_write_reg_expect(cx, 0x14001400, 0xc78110, 0x00001400, 0x14001400); |
Hans Verkuil | 1c1e45d | 2008-04-28 20:24:33 -0300 | [diff] [blame] | 405 | return 0; |
| 406 | } |