Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the Conexant CX25821 PCIe bridge |
| 3 | * |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 4 | * Copyright (C) 2009 Conexant Systems Inc. |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 5 | * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com> |
| 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 | * |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | */ |
| 22 | |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 23 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 24 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 25 | #include "cx25821.h" |
| 26 | #include "cx25821-medusa-video.h" |
| 27 | #include "cx25821-biffuncs.h" |
| 28 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 29 | /* |
| 30 | * medusa_enable_bluefield_output() |
| 31 | * |
| 32 | * Enable the generation of blue filed output if no video |
| 33 | * |
| 34 | */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 35 | static void medusa_enable_bluefield_output(struct cx25821_dev *dev, int channel, |
| 36 | int enable) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 37 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 38 | int ret_val = 1; |
| 39 | u32 value = 0; |
| 40 | u32 tmp = 0; |
| 41 | int out_ctrl = OUT_CTRL1; |
| 42 | int out_ctrl_ns = OUT_CTRL_NS; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 43 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 44 | switch (channel) { |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 45 | default: |
| 46 | case VDEC_A: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 47 | break; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 48 | case VDEC_B: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 49 | out_ctrl = VDEC_B_OUT_CTRL1; |
| 50 | out_ctrl_ns = VDEC_B_OUT_CTRL_NS; |
| 51 | break; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 52 | case VDEC_C: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 53 | out_ctrl = VDEC_C_OUT_CTRL1; |
| 54 | out_ctrl_ns = VDEC_C_OUT_CTRL_NS; |
| 55 | break; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 56 | case VDEC_D: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 57 | out_ctrl = VDEC_D_OUT_CTRL1; |
| 58 | out_ctrl_ns = VDEC_D_OUT_CTRL_NS; |
| 59 | break; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 60 | case VDEC_E: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 61 | out_ctrl = VDEC_E_OUT_CTRL1; |
| 62 | out_ctrl_ns = VDEC_E_OUT_CTRL_NS; |
| 63 | return; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 64 | case VDEC_F: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 65 | out_ctrl = VDEC_F_OUT_CTRL1; |
| 66 | out_ctrl_ns = VDEC_F_OUT_CTRL_NS; |
| 67 | return; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 68 | case VDEC_G: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 69 | out_ctrl = VDEC_G_OUT_CTRL1; |
| 70 | out_ctrl_ns = VDEC_G_OUT_CTRL_NS; |
| 71 | return; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 72 | case VDEC_H: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 73 | out_ctrl = VDEC_H_OUT_CTRL1; |
| 74 | out_ctrl_ns = VDEC_H_OUT_CTRL_NS; |
| 75 | return; |
| 76 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 77 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 78 | value = cx25821_i2c_read(&dev->i2c_bus[0], out_ctrl, &tmp); |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 79 | value &= 0xFFFFFF7F; /* clear BLUE_FIELD_EN */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 80 | if (enable) |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 81 | value |= 0x00000080; /* set BLUE_FIELD_EN */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 82 | ret_val = cx25821_i2c_write(&dev->i2c_bus[0], out_ctrl, value); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 83 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 84 | value = cx25821_i2c_read(&dev->i2c_bus[0], out_ctrl_ns, &tmp); |
| 85 | value &= 0xFFFFFF7F; |
| 86 | if (enable) |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 87 | value |= 0x00000080; /* set BLUE_FIELD_EN */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 88 | ret_val = cx25821_i2c_write(&dev->i2c_bus[0], out_ctrl_ns, value); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 89 | } |
| 90 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 91 | static int medusa_initialize_ntsc(struct cx25821_dev *dev) |
| 92 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 93 | int ret_val = 0; |
| 94 | int i = 0; |
| 95 | u32 value = 0; |
| 96 | u32 tmp = 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 97 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 98 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 99 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 100 | for (i = 0; i < MAX_DECODERS; i++) { |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 101 | /* set video format NTSC-M */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 102 | value = |
| 103 | cx25821_i2c_read(&dev->i2c_bus[0], MODE_CTRL + (0x200 * i), |
| 104 | &tmp); |
| 105 | value &= 0xFFFFFFF0; |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 106 | /* enable the fast locking mode bit[16] */ |
| 107 | value |= 0x10001; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 108 | ret_val = |
| 109 | cx25821_i2c_write(&dev->i2c_bus[0], MODE_CTRL + (0x200 * i), |
| 110 | value); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 111 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 112 | /* resolution NTSC 720x480 */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 113 | value = |
| 114 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 115 | HORIZ_TIM_CTRL + (0x200 * i), &tmp); |
| 116 | value &= 0x00C00C00; |
| 117 | value |= 0x612D0074; |
| 118 | ret_val = |
| 119 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 120 | HORIZ_TIM_CTRL + (0x200 * i), value); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 121 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 122 | value = |
| 123 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 124 | VERT_TIM_CTRL + (0x200 * i), &tmp); |
| 125 | value &= 0x00C00C00; |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 126 | value |= 0x1C1E001A; /* vblank_cnt + 2 to get camera ID */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 127 | ret_val = |
| 128 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 129 | VERT_TIM_CTRL + (0x200 * i), value); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 130 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 131 | /* chroma subcarrier step size */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 132 | ret_val = |
| 133 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 134 | SC_STEP_SIZE + (0x200 * i), 0x43E00000); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 135 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 136 | /* enable VIP optional active */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 137 | value = |
| 138 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 139 | OUT_CTRL_NS + (0x200 * i), &tmp); |
| 140 | value &= 0xFFFBFFFF; |
| 141 | value |= 0x00040000; |
| 142 | ret_val = |
| 143 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 144 | OUT_CTRL_NS + (0x200 * i), value); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 145 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 146 | /* enable VIP optional active (VIP_OPT_AL) for direct output. */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 147 | value = |
| 148 | cx25821_i2c_read(&dev->i2c_bus[0], OUT_CTRL1 + (0x200 * i), |
| 149 | &tmp); |
| 150 | value &= 0xFFFBFFFF; |
| 151 | value |= 0x00040000; |
| 152 | ret_val = |
| 153 | cx25821_i2c_write(&dev->i2c_bus[0], OUT_CTRL1 + (0x200 * i), |
| 154 | value); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 155 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 156 | /* |
| 157 | * clear VPRES_VERT_EN bit, fixes the chroma run away problem |
| 158 | * when the input switching rate < 16 fields |
| 159 | */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 160 | value = |
| 161 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 162 | MISC_TIM_CTRL + (0x200 * i), &tmp); |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 163 | /* disable special play detection */ |
| 164 | value = setBitAtPos(value, 14); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 165 | value = clearBitAtPos(value, 15); |
| 166 | ret_val = |
| 167 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 168 | MISC_TIM_CTRL + (0x200 * i), value); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 169 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 170 | /* set vbi_gate_en to 0 */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 171 | value = |
| 172 | cx25821_i2c_read(&dev->i2c_bus[0], DFE_CTRL1 + (0x200 * i), |
| 173 | &tmp); |
| 174 | value = clearBitAtPos(value, 29); |
| 175 | ret_val = |
| 176 | cx25821_i2c_write(&dev->i2c_bus[0], DFE_CTRL1 + (0x200 * i), |
| 177 | value); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 178 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 179 | /* Enable the generation of blue field output if no video */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 180 | medusa_enable_bluefield_output(dev, i, 1); |
| 181 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 182 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 183 | for (i = 0; i < MAX_ENCODERS; i++) { |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 184 | /* NTSC hclock */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 185 | value = |
| 186 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 187 | DENC_A_REG_1 + (0x100 * i), &tmp); |
| 188 | value &= 0xF000FC00; |
| 189 | value |= 0x06B402D0; |
| 190 | ret_val = |
| 191 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 192 | DENC_A_REG_1 + (0x100 * i), value); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 193 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 194 | /* burst begin and burst end */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 195 | value = |
| 196 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 197 | DENC_A_REG_2 + (0x100 * i), &tmp); |
| 198 | value &= 0xFF000000; |
| 199 | value |= 0x007E9054; |
| 200 | ret_val = |
| 201 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 202 | DENC_A_REG_2 + (0x100 * i), value); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 203 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 204 | value = |
| 205 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 206 | DENC_A_REG_3 + (0x100 * i), &tmp); |
| 207 | value &= 0xFC00FE00; |
| 208 | value |= 0x00EC00F0; |
| 209 | ret_val = |
| 210 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 211 | DENC_A_REG_3 + (0x100 * i), value); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 212 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 213 | /* set NTSC vblank, no phase alternation, 7.5 IRE pedestal */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 214 | value = |
| 215 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 216 | DENC_A_REG_4 + (0x100 * i), &tmp); |
| 217 | value &= 0x00FCFFFF; |
| 218 | value |= 0x13020000; |
| 219 | ret_val = |
| 220 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 221 | DENC_A_REG_4 + (0x100 * i), value); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 222 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 223 | value = |
| 224 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 225 | DENC_A_REG_5 + (0x100 * i), &tmp); |
| 226 | value &= 0xFFFF0000; |
| 227 | value |= 0x0000E575; |
| 228 | ret_val = |
| 229 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 230 | DENC_A_REG_5 + (0x100 * i), value); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 231 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 232 | ret_val = |
| 233 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 234 | DENC_A_REG_6 + (0x100 * i), 0x009A89C1); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 235 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 236 | /* Subcarrier Increment */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 237 | ret_val = |
| 238 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 239 | DENC_A_REG_7 + (0x100 * i), 0x21F07C1F); |
| 240 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 241 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 242 | /* set picture resolutions */ |
| 243 | /* 0 - 720 */ |
| 244 | ret_val = cx25821_i2c_write(&dev->i2c_bus[0], HSCALE_CTRL, 0x0); |
| 245 | /* 0 - 480 */ |
| 246 | ret_val = cx25821_i2c_write(&dev->i2c_bus[0], VSCALE_CTRL, 0x0); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 247 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 248 | /* set Bypass input format to NTSC 525 lines */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 249 | value = cx25821_i2c_read(&dev->i2c_bus[0], BYP_AB_CTRL, &tmp); |
| 250 | value |= 0x00080200; |
| 251 | ret_val = cx25821_i2c_write(&dev->i2c_bus[0], BYP_AB_CTRL, value); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 252 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 253 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 254 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 255 | return ret_val; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 256 | } |
| 257 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 258 | static int medusa_PALCombInit(struct cx25821_dev *dev, int dec) |
| 259 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 260 | int ret_val = -1; |
| 261 | u32 value = 0, tmp = 0; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 262 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 263 | /* Setup for 2D threshold */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 264 | ret_val = |
| 265 | cx25821_i2c_write(&dev->i2c_bus[0], COMB_2D_HFS_CFG + (0x200 * dec), |
| 266 | 0x20002861); |
| 267 | ret_val = |
| 268 | cx25821_i2c_write(&dev->i2c_bus[0], COMB_2D_HFD_CFG + (0x200 * dec), |
| 269 | 0x20002861); |
| 270 | ret_val = |
| 271 | cx25821_i2c_write(&dev->i2c_bus[0], COMB_2D_LF_CFG + (0x200 * dec), |
| 272 | 0x200A1023); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 273 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 274 | /* Setup flat chroma and luma thresholds */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 275 | value = |
| 276 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 277 | COMB_FLAT_THRESH_CTRL + (0x200 * dec), &tmp); |
| 278 | value &= 0x06230000; |
| 279 | ret_val = |
| 280 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 281 | COMB_FLAT_THRESH_CTRL + (0x200 * dec), value); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 282 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 283 | /* set comb 2D blend */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 284 | ret_val = |
| 285 | cx25821_i2c_write(&dev->i2c_bus[0], COMB_2D_BLEND + (0x200 * dec), |
| 286 | 0x210F0F0F); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 287 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 288 | /* COMB MISC CONTROL */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 289 | ret_val = |
| 290 | cx25821_i2c_write(&dev->i2c_bus[0], COMB_MISC_CTRL + (0x200 * dec), |
| 291 | 0x41120A7F); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 292 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 293 | return ret_val; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 294 | } |
| 295 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 296 | static int medusa_initialize_pal(struct cx25821_dev *dev) |
| 297 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 298 | int ret_val = 0; |
| 299 | int i = 0; |
| 300 | u32 value = 0; |
| 301 | u32 tmp = 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 302 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 303 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 304 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 305 | for (i = 0; i < MAX_DECODERS; i++) { |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 306 | /* set video format PAL-BDGHI */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 307 | value = |
| 308 | cx25821_i2c_read(&dev->i2c_bus[0], MODE_CTRL + (0x200 * i), |
| 309 | &tmp); |
| 310 | value &= 0xFFFFFFF0; |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 311 | /* enable the fast locking mode bit[16] */ |
| 312 | value |= 0x10004; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 313 | ret_val = |
| 314 | cx25821_i2c_write(&dev->i2c_bus[0], MODE_CTRL + (0x200 * i), |
| 315 | value); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 316 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 317 | /* resolution PAL 720x576 */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 318 | value = |
| 319 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 320 | HORIZ_TIM_CTRL + (0x200 * i), &tmp); |
| 321 | value &= 0x00C00C00; |
| 322 | value |= 0x632D007D; |
| 323 | ret_val = |
| 324 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 325 | HORIZ_TIM_CTRL + (0x200 * i), value); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 326 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 327 | /* vblank656_cnt=x26, vactive_cnt=240h, vblank_cnt=x24 */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 328 | value = |
| 329 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 330 | VERT_TIM_CTRL + (0x200 * i), &tmp); |
| 331 | value &= 0x00C00C00; |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 332 | value |= 0x28240026; /* vblank_cnt + 2 to get camera ID */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 333 | ret_val = |
| 334 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 335 | VERT_TIM_CTRL + (0x200 * i), value); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 336 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 337 | /* chroma subcarrier step size */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 338 | ret_val = |
| 339 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 340 | SC_STEP_SIZE + (0x200 * i), 0x5411E2D0); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 341 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 342 | /* enable VIP optional active */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 343 | value = |
| 344 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 345 | OUT_CTRL_NS + (0x200 * i), &tmp); |
| 346 | value &= 0xFFFBFFFF; |
| 347 | value |= 0x00040000; |
| 348 | ret_val = |
| 349 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 350 | OUT_CTRL_NS + (0x200 * i), value); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 351 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 352 | /* enable VIP optional active (VIP_OPT_AL) for direct output. */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 353 | value = |
| 354 | cx25821_i2c_read(&dev->i2c_bus[0], OUT_CTRL1 + (0x200 * i), |
| 355 | &tmp); |
| 356 | value &= 0xFFFBFFFF; |
| 357 | value |= 0x00040000; |
| 358 | ret_val = |
| 359 | cx25821_i2c_write(&dev->i2c_bus[0], OUT_CTRL1 + (0x200 * i), |
| 360 | value); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 361 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 362 | /* |
| 363 | * clear VPRES_VERT_EN bit, fixes the chroma run away problem |
| 364 | * when the input switching rate < 16 fields |
| 365 | */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 366 | value = |
| 367 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 368 | MISC_TIM_CTRL + (0x200 * i), &tmp); |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 369 | /* disable special play detection */ |
| 370 | value = setBitAtPos(value, 14); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 371 | value = clearBitAtPos(value, 15); |
| 372 | ret_val = |
| 373 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 374 | MISC_TIM_CTRL + (0x200 * i), value); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 375 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 376 | /* set vbi_gate_en to 0 */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 377 | value = |
| 378 | cx25821_i2c_read(&dev->i2c_bus[0], DFE_CTRL1 + (0x200 * i), |
| 379 | &tmp); |
| 380 | value = clearBitAtPos(value, 29); |
| 381 | ret_val = |
| 382 | cx25821_i2c_write(&dev->i2c_bus[0], DFE_CTRL1 + (0x200 * i), |
| 383 | value); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 384 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 385 | medusa_PALCombInit(dev, i); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 386 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 387 | /* Enable the generation of blue field output if no video */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 388 | medusa_enable_bluefield_output(dev, i, 1); |
| 389 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 390 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 391 | for (i = 0; i < MAX_ENCODERS; i++) { |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 392 | /* PAL hclock */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 393 | value = |
| 394 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 395 | DENC_A_REG_1 + (0x100 * i), &tmp); |
| 396 | value &= 0xF000FC00; |
| 397 | value |= 0x06C002D0; |
| 398 | ret_val = |
| 399 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 400 | DENC_A_REG_1 + (0x100 * i), value); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 401 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 402 | /* burst begin and burst end */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 403 | value = |
| 404 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 405 | DENC_A_REG_2 + (0x100 * i), &tmp); |
| 406 | value &= 0xFF000000; |
| 407 | value |= 0x007E9754; |
| 408 | ret_val = |
| 409 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 410 | DENC_A_REG_2 + (0x100 * i), value); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 411 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 412 | /* hblank and vactive */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 413 | value = |
| 414 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 415 | DENC_A_REG_3 + (0x100 * i), &tmp); |
| 416 | value &= 0xFC00FE00; |
| 417 | value |= 0x00FC0120; |
| 418 | ret_val = |
| 419 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 420 | DENC_A_REG_3 + (0x100 * i), value); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 421 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 422 | /* set PAL vblank, phase alternation, 0 IRE pedestal */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 423 | value = |
| 424 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 425 | DENC_A_REG_4 + (0x100 * i), &tmp); |
| 426 | value &= 0x00FCFFFF; |
| 427 | value |= 0x14010000; |
| 428 | ret_val = |
| 429 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 430 | DENC_A_REG_4 + (0x100 * i), value); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 431 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 432 | value = |
| 433 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 434 | DENC_A_REG_5 + (0x100 * i), &tmp); |
| 435 | value &= 0xFFFF0000; |
| 436 | value |= 0x0000F078; |
| 437 | ret_val = |
| 438 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 439 | DENC_A_REG_5 + (0x100 * i), value); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 440 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 441 | ret_val = |
| 442 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 443 | DENC_A_REG_6 + (0x100 * i), 0x00A493CF); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 444 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 445 | /* Subcarrier Increment */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 446 | ret_val = |
| 447 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 448 | DENC_A_REG_7 + (0x100 * i), 0x2A098ACB); |
| 449 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 450 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 451 | /* set picture resolutions */ |
| 452 | /* 0 - 720 */ |
| 453 | ret_val = cx25821_i2c_write(&dev->i2c_bus[0], HSCALE_CTRL, 0x0); |
| 454 | /* 0 - 576 */ |
| 455 | ret_val = cx25821_i2c_write(&dev->i2c_bus[0], VSCALE_CTRL, 0x0); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 456 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 457 | /* set Bypass input format to PAL 625 lines */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 458 | value = cx25821_i2c_read(&dev->i2c_bus[0], BYP_AB_CTRL, &tmp); |
| 459 | value &= 0xFFF7FDFF; |
| 460 | ret_val = cx25821_i2c_write(&dev->i2c_bus[0], BYP_AB_CTRL, value); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 461 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 462 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 463 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 464 | return ret_val; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 465 | } |
| 466 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 467 | int medusa_set_videostandard(struct cx25821_dev *dev) |
| 468 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 469 | int status = STATUS_SUCCESS; |
| 470 | u32 value = 0, tmp = 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 471 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 472 | if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 473 | status = medusa_initialize_pal(dev); |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 474 | else |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 475 | status = medusa_initialize_ntsc(dev); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 476 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 477 | /* Enable DENC_A output */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 478 | value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_A_REG_4, &tmp); |
| 479 | value = setBitAtPos(value, 4); |
| 480 | status = cx25821_i2c_write(&dev->i2c_bus[0], DENC_A_REG_4, value); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 481 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 482 | /* Enable DENC_B output */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 483 | value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_B_REG_4, &tmp); |
| 484 | value = setBitAtPos(value, 4); |
| 485 | status = cx25821_i2c_write(&dev->i2c_bus[0], DENC_B_REG_4, value); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 486 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 487 | return status; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 488 | } |
| 489 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 490 | void medusa_set_resolution(struct cx25821_dev *dev, int width, |
| 491 | int decoder_select) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 492 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 493 | int decoder = 0; |
| 494 | int decoder_count = 0; |
| 495 | int ret_val = 0; |
| 496 | u32 hscale = 0x0; |
| 497 | u32 vscale = 0x0; |
| 498 | const int MAX_WIDTH = 720; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 499 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 500 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 501 | |
Leonid V. Fedorenchik | 09c3544 | 2011-10-22 01:43:38 -0300 | [diff] [blame] | 502 | /* validate the width */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 503 | if (width > MAX_WIDTH) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 504 | pr_info("%s(): width %d > MAX_WIDTH %d ! resetting to MAX_WIDTH\n", |
| 505 | __func__, width, MAX_WIDTH); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 506 | width = MAX_WIDTH; |
| 507 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 508 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 509 | if (decoder_select <= 7 && decoder_select >= 0) { |
| 510 | decoder = decoder_select; |
| 511 | decoder_count = decoder_select + 1; |
| 512 | } else { |
| 513 | decoder = 0; |
| 514 | decoder_count = _num_decoders; |
| 515 | } |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 516 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 517 | switch (width) { |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 518 | case 320: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 519 | hscale = 0x13E34B; |
| 520 | vscale = 0x0; |
| 521 | break; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 522 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 523 | case 352: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 524 | hscale = 0x10A273; |
| 525 | vscale = 0x0; |
| 526 | break; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 527 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 528 | case 176: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 529 | hscale = 0x3115B2; |
| 530 | vscale = 0x1E00; |
| 531 | break; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 532 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 533 | case 160: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 534 | hscale = 0x378D84; |
| 535 | vscale = 0x1E00; |
| 536 | break; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 537 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 538 | default: /* 720 */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 539 | hscale = 0x0; |
| 540 | vscale = 0x0; |
| 541 | break; |
| 542 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 543 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 544 | for (; decoder < decoder_count; decoder++) { |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 545 | /* write scaling values for each decoder */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 546 | ret_val = |
| 547 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 548 | HSCALE_CTRL + (0x200 * decoder), hscale); |
| 549 | ret_val = |
| 550 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 551 | VSCALE_CTRL + (0x200 * decoder), vscale); |
| 552 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 553 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 554 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 555 | } |
| 556 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 557 | static void medusa_set_decoderduration(struct cx25821_dev *dev, int decoder, |
| 558 | int duration) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 559 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 560 | int ret_val = 0; |
| 561 | u32 fld_cnt = 0; |
| 562 | u32 tmp = 0; |
| 563 | u32 disp_cnt_reg = DISP_AB_CNT; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 564 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 565 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 566 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 567 | /* no support */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 568 | if (decoder < VDEC_A && decoder > VDEC_H) { |
| 569 | mutex_unlock(&dev->lock); |
| 570 | return; |
| 571 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 572 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 573 | switch (decoder) { |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 574 | default: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 575 | break; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 576 | case VDEC_C: |
| 577 | case VDEC_D: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 578 | disp_cnt_reg = DISP_CD_CNT; |
| 579 | break; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 580 | case VDEC_E: |
| 581 | case VDEC_F: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 582 | disp_cnt_reg = DISP_EF_CNT; |
| 583 | break; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 584 | case VDEC_G: |
| 585 | case VDEC_H: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 586 | disp_cnt_reg = DISP_GH_CNT; |
| 587 | break; |
| 588 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 589 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 590 | _display_field_cnt[decoder] = duration; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 591 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 592 | /* update hardware */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 593 | fld_cnt = cx25821_i2c_read(&dev->i2c_bus[0], disp_cnt_reg, &tmp); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 594 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 595 | if (!(decoder % 2)) { /* EVEN decoder */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 596 | fld_cnt &= 0xFFFF0000; |
| 597 | fld_cnt |= duration; |
| 598 | } else { |
| 599 | fld_cnt &= 0x0000FFFF; |
| 600 | fld_cnt |= ((u32) duration) << 16; |
| 601 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 602 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 603 | ret_val = cx25821_i2c_write(&dev->i2c_bus[0], disp_cnt_reg, fld_cnt); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 604 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 605 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 606 | } |
| 607 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 608 | /* Map to Medusa register setting */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 609 | static int mapM(int srcMin, |
| 610 | int srcMax, int srcVal, int dstMin, int dstMax, int *dstVal) |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 611 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 612 | int numerator; |
| 613 | int denominator; |
| 614 | int quotient; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 615 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 616 | if ((srcMin == srcMax) || (srcVal < srcMin) || (srcVal > srcMax)) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 617 | return -1; |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 618 | /* |
| 619 | * This is the overall expression used: |
| 620 | * *dstVal = |
| 621 | * (srcVal - srcMin)*(dstMax - dstMin) / (srcMax - srcMin) + dstMin; |
| 622 | * but we need to account for rounding so below we use the modulus |
| 623 | * operator to find the remainder and increment if necessary. |
| 624 | */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 625 | numerator = (srcVal - srcMin) * (dstMax - dstMin); |
| 626 | denominator = srcMax - srcMin; |
| 627 | quotient = numerator / denominator; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 628 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 629 | if (2 * (numerator % denominator) >= denominator) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 630 | quotient++; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 631 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 632 | *dstVal = quotient + dstMin; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 633 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 634 | return 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | static unsigned long convert_to_twos(long numeric, unsigned long bits_len) |
| 638 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 639 | unsigned char temp; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 640 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 641 | if (numeric >= 0) |
| 642 | return numeric; |
| 643 | else { |
| 644 | temp = ~(abs(numeric) & 0xFF); |
| 645 | temp += 1; |
| 646 | return temp; |
| 647 | } |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 648 | } |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 649 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 650 | int medusa_set_brightness(struct cx25821_dev *dev, int brightness, int decoder) |
| 651 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 652 | int ret_val = 0; |
| 653 | int value = 0; |
| 654 | u32 val = 0, tmp = 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 655 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 656 | mutex_lock(&dev->lock); |
Leonid V. Fedorenchik | 49faae8 | 2011-10-22 01:43:39 -0300 | [diff] [blame^] | 657 | if ((brightness > VIDEO_PROCAMP_MAX) || |
| 658 | (brightness < VIDEO_PROCAMP_MIN)) { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 659 | mutex_unlock(&dev->lock); |
| 660 | return -1; |
| 661 | } |
| 662 | ret_val = |
| 663 | mapM(VIDEO_PROCAMP_MIN, VIDEO_PROCAMP_MAX, brightness, |
| 664 | SIGNED_BYTE_MIN, SIGNED_BYTE_MAX, &value); |
| 665 | value = convert_to_twos(value, 8); |
| 666 | val = |
| 667 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 668 | VDEC_A_BRITE_CTRL + (0x200 * decoder), &tmp); |
| 669 | val &= 0xFFFFFF00; |
| 670 | ret_val |= |
| 671 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 672 | VDEC_A_BRITE_CTRL + (0x200 * decoder), |
| 673 | val | value); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 674 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 675 | return ret_val; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 676 | } |
| 677 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 678 | int medusa_set_contrast(struct cx25821_dev *dev, int contrast, int decoder) |
| 679 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 680 | int ret_val = 0; |
| 681 | int value = 0; |
| 682 | u32 val = 0, tmp = 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 683 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 684 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 685 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 686 | if ((contrast > VIDEO_PROCAMP_MAX) || (contrast < VIDEO_PROCAMP_MIN)) { |
| 687 | mutex_unlock(&dev->lock); |
| 688 | return -1; |
| 689 | } |
| 690 | |
| 691 | ret_val = |
| 692 | mapM(VIDEO_PROCAMP_MIN, VIDEO_PROCAMP_MAX, contrast, |
| 693 | UNSIGNED_BYTE_MIN, UNSIGNED_BYTE_MAX, &value); |
| 694 | val = |
| 695 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 696 | VDEC_A_CNTRST_CTRL + (0x200 * decoder), &tmp); |
| 697 | val &= 0xFFFFFF00; |
| 698 | ret_val |= |
| 699 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 700 | VDEC_A_CNTRST_CTRL + (0x200 * decoder), |
| 701 | val | value); |
| 702 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 703 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 704 | return ret_val; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 705 | } |
| 706 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 707 | int medusa_set_hue(struct cx25821_dev *dev, int hue, int decoder) |
| 708 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 709 | int ret_val = 0; |
| 710 | int value = 0; |
| 711 | u32 val = 0, tmp = 0; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 712 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 713 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 714 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 715 | if ((hue > VIDEO_PROCAMP_MAX) || (hue < VIDEO_PROCAMP_MIN)) { |
| 716 | mutex_unlock(&dev->lock); |
| 717 | return -1; |
| 718 | } |
| 719 | |
| 720 | ret_val = |
| 721 | mapM(VIDEO_PROCAMP_MIN, VIDEO_PROCAMP_MAX, hue, SIGNED_BYTE_MIN, |
| 722 | SIGNED_BYTE_MAX, &value); |
| 723 | |
| 724 | value = convert_to_twos(value, 8); |
| 725 | val = |
| 726 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 727 | VDEC_A_HUE_CTRL + (0x200 * decoder), &tmp); |
| 728 | val &= 0xFFFFFF00; |
| 729 | |
| 730 | ret_val |= |
| 731 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 732 | VDEC_A_HUE_CTRL + (0x200 * decoder), val | value); |
| 733 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 734 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 735 | return ret_val; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 736 | } |
| 737 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 738 | int medusa_set_saturation(struct cx25821_dev *dev, int saturation, int decoder) |
| 739 | { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 740 | int ret_val = 0; |
| 741 | int value = 0; |
| 742 | u32 val = 0, tmp = 0; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 743 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 744 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 745 | |
Leonid V. Fedorenchik | 49faae8 | 2011-10-22 01:43:39 -0300 | [diff] [blame^] | 746 | if ((saturation > VIDEO_PROCAMP_MAX) || |
| 747 | (saturation < VIDEO_PROCAMP_MIN)) { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 748 | mutex_unlock(&dev->lock); |
| 749 | return -1; |
| 750 | } |
| 751 | |
| 752 | ret_val = |
| 753 | mapM(VIDEO_PROCAMP_MIN, VIDEO_PROCAMP_MAX, saturation, |
| 754 | UNSIGNED_BYTE_MIN, UNSIGNED_BYTE_MAX, &value); |
| 755 | |
| 756 | val = |
| 757 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 758 | VDEC_A_USAT_CTRL + (0x200 * decoder), &tmp); |
| 759 | val &= 0xFFFFFF00; |
| 760 | ret_val |= |
| 761 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 762 | VDEC_A_USAT_CTRL + (0x200 * decoder), |
| 763 | val | value); |
| 764 | |
| 765 | val = |
| 766 | cx25821_i2c_read(&dev->i2c_bus[0], |
| 767 | VDEC_A_VSAT_CTRL + (0x200 * decoder), &tmp); |
| 768 | val &= 0xFFFFFF00; |
| 769 | ret_val |= |
| 770 | cx25821_i2c_write(&dev->i2c_bus[0], |
| 771 | VDEC_A_VSAT_CTRL + (0x200 * decoder), |
| 772 | val | value); |
| 773 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 774 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 775 | return ret_val; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 776 | } |
| 777 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 778 | /* Program the display sequence and monitor output. */ |
| 779 | |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 780 | int medusa_video_init(struct cx25821_dev *dev) |
| 781 | { |
Ruslan Pisarev | e4115bb | 2010-09-27 10:01:36 -0300 | [diff] [blame] | 782 | u32 value = 0, tmp = 0; |
| 783 | int ret_val = 0; |
| 784 | int i = 0; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 785 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 786 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 787 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 788 | _num_decoders = dev->_max_num_decoders; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 789 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 790 | /* disable Auto source selection on all video decoders */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 791 | value = cx25821_i2c_read(&dev->i2c_bus[0], MON_A_CTRL, &tmp); |
| 792 | value &= 0xFFFFF0FF; |
| 793 | ret_val = cx25821_i2c_write(&dev->i2c_bus[0], MON_A_CTRL, value); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 794 | |
Mauro Carvalho Chehab | 64561a3 | 2010-05-05 12:30:01 -0300 | [diff] [blame] | 795 | if (ret_val < 0) |
| 796 | goto error; |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 797 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 798 | /* Turn off Master source switch enable */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 799 | value = cx25821_i2c_read(&dev->i2c_bus[0], MON_A_CTRL, &tmp); |
| 800 | value &= 0xFFFFFFDF; |
| 801 | ret_val = cx25821_i2c_write(&dev->i2c_bus[0], MON_A_CTRL, value); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 802 | |
Dan Carpenter | 7a02f54 | 2009-12-28 18:59:46 +0200 | [diff] [blame] | 803 | if (ret_val < 0) |
Mauro Carvalho Chehab | 64561a3 | 2010-05-05 12:30:01 -0300 | [diff] [blame] | 804 | goto error; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 805 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 806 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 807 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 808 | for (i = 0; i < _num_decoders; i++) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 809 | medusa_set_decoderduration(dev, i, _display_field_cnt[i]); |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 810 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 811 | mutex_lock(&dev->lock); |
| 812 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 813 | /* Select monitor as DENC A input, power up the DAC */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 814 | value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_AB_CTRL, &tmp); |
| 815 | value &= 0xFF70FF70; |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 816 | value |= 0x00090008; /* set en_active */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 817 | ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DENC_AB_CTRL, value); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 818 | |
Mauro Carvalho Chehab | 64561a3 | 2010-05-05 12:30:01 -0300 | [diff] [blame] | 819 | if (ret_val < 0) |
| 820 | goto error; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 821 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 822 | /* enable input is VIP/656 */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 823 | value = cx25821_i2c_read(&dev->i2c_bus[0], BYP_AB_CTRL, &tmp); |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 824 | value |= 0x00040100; /* enable VIP */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 825 | ret_val = cx25821_i2c_write(&dev->i2c_bus[0], BYP_AB_CTRL, value); |
| 826 | |
Mauro Carvalho Chehab | 64561a3 | 2010-05-05 12:30:01 -0300 | [diff] [blame] | 827 | if (ret_val < 0) |
| 828 | goto error; |
| 829 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 830 | /* select AFE clock to output mode */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 831 | value = cx25821_i2c_read(&dev->i2c_bus[0], AFE_AB_DIAG_CTRL, &tmp); |
| 832 | value &= 0x83FFFFFF; |
Ruslan Pisarev | e4115bb | 2010-09-27 10:01:36 -0300 | [diff] [blame] | 833 | ret_val = |
Mauro Carvalho Chehab | 3e9442c | 2010-07-04 15:37:05 -0300 | [diff] [blame] | 834 | cx25821_i2c_write(&dev->i2c_bus[0], AFE_AB_DIAG_CTRL, |
| 835 | value | 0x10000000); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 836 | |
Mauro Carvalho Chehab | 64561a3 | 2010-05-05 12:30:01 -0300 | [diff] [blame] | 837 | if (ret_val < 0) |
| 838 | goto error; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 839 | |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 840 | /* Turn on all of the data out and control output pins. */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 841 | value = cx25821_i2c_read(&dev->i2c_bus[0], PIN_OE_CTRL, &tmp); |
| 842 | value &= 0xFEF0FE00; |
| 843 | if (_num_decoders == MAX_DECODERS) { |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 844 | /* |
| 845 | * Note: The octal board does not support control pins(bit16-19) |
| 846 | * These bits are ignored in the octal board. |
| 847 | * |
| 848 | * disable VDEC A-C port, default to Mobilygen Interface |
| 849 | */ |
| 850 | value |= 0x010001F8; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 851 | } else { |
Olimpiu Pascariu | 0dd8be8 | 2010-03-21 15:46:26 -0300 | [diff] [blame] | 852 | /* disable VDEC A-C port, default to Mobilygen Interface */ |
| 853 | value |= 0x010F0108; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | value |= 7; |
| 857 | ret_val = cx25821_i2c_write(&dev->i2c_bus[0], PIN_OE_CTRL, value); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 858 | |
Mauro Carvalho Chehab | 64561a3 | 2010-05-05 12:30:01 -0300 | [diff] [blame] | 859 | if (ret_val < 0) |
| 860 | goto error; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 861 | |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 862 | |
Mauro Carvalho Chehab | bb4c9a7 | 2009-09-13 11:25:45 -0300 | [diff] [blame] | 863 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 864 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 865 | ret_val = medusa_set_videostandard(dev); |
Palash Bandyopadhyay | 6d8c2ba | 2010-07-04 14:15:38 -0300 | [diff] [blame] | 866 | |
Mauro Carvalho Chehab | 64561a3 | 2010-05-05 12:30:01 -0300 | [diff] [blame] | 867 | return ret_val; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 868 | |
Mauro Carvalho Chehab | 64561a3 | 2010-05-05 12:30:01 -0300 | [diff] [blame] | 869 | error: |
| 870 | mutex_unlock(&dev->lock); |
| 871 | return ret_val; |
Mauro Carvalho Chehab | 02b20b0 | 2009-09-15 11:33:54 -0300 | [diff] [blame] | 872 | } |