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