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