Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 1 | /* |
| 2 | Mantis VP-2033 driver |
| 3 | |
| 4 | Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com) |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | */ |
| 20 | |
| 21 | #include "mantis_common.h" |
| 22 | #include "mantis_vp2033.h" |
| 23 | |
Manu Abraham | df0cca1 | 2009-12-02 22:07:24 -0300 | [diff] [blame] | 24 | #define MANTIS_MODEL_NAME "VP-2033" |
| 25 | #define MANTIS_DEV_TYPE "DVB-C" |
| 26 | |
| 27 | struct mantis_hwconfig vp2033_mantis_config = { |
| 28 | .model_name = MANTIS_MODEL_NAME, |
| 29 | .dev_type = MANTIS_DEV_TYPE, |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 30 | .ts_size = MANTIS_TS_204, |
Manu Abraham | df0cca1 | 2009-12-02 22:07:24 -0300 | [diff] [blame] | 31 | }; |
| 32 | |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 33 | struct tda1002x_config philips_cu1216_config = { |
| 34 | .demod_address = 0x18 >> 1, |
| 35 | .invert = 1, |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 36 | }; |
| 37 | |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 38 | u8 read_pwm(struct mantis_pci *mantis) |
| 39 | { |
| 40 | u8 b = 0xff; |
| 41 | u8 pwm; |
| 42 | struct i2c_msg msg[] = { |
| 43 | {.addr = 0x50,.flags = 0,.buf = &b,.len = 1}, |
| 44 | {.addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1} |
| 45 | }; |
| 46 | |
| 47 | if ((i2c_transfer(&mantis->adapter, msg, 2) != 2) |
| 48 | || (pwm == 0xff)) |
| 49 | pwm = 0x48; |
| 50 | |
| 51 | return pwm; |
| 52 | } |
| 53 | |
| 54 | int philips_cu1216_tuner_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params) |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 55 | { |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 56 | struct mantis_pci *mantis = fe->dvb->priv; |
| 57 | |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 58 | u8 buf[6]; |
| 59 | struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof(buf) }; |
| 60 | int i; |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 61 | |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 62 | #define CU1216_IF 36125000 |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 63 | #define TUNER_MUL 62500 |
| 64 | |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 65 | u32 div = (params->frequency + CU1216_IF + TUNER_MUL / 2) / TUNER_MUL; |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 66 | |
| 67 | buf[0] = (div >> 8) & 0x7f; |
| 68 | buf[1] = div & 0xff; |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 69 | buf[2] = 0xce; |
| 70 | buf[3] = (params->frequency < 150000000 ? 0x01 : |
| 71 | params->frequency < 445000000 ? 0x02 : 0x04); |
| 72 | buf[4] = 0xde; |
| 73 | buf[5] = 0x20; |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 74 | |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 75 | if (fe->ops.i2c_gate_ctrl) |
| 76 | fe->ops.i2c_gate_ctrl(fe, 1); |
| 77 | |
| 78 | if (i2c_transfer(&mantis->adapter, &msg, 1) != 1) |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 79 | return -EIO; |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 80 | |
| 81 | /* wait for the pll lock */ |
| 82 | msg.flags = I2C_M_RD; |
| 83 | msg.len = 1; |
| 84 | for (i = 0; i < 20; i++) { |
| 85 | if (fe->ops.i2c_gate_ctrl) |
| 86 | fe->ops.i2c_gate_ctrl(fe, 1); |
| 87 | |
| 88 | if (i2c_transfer(&mantis->adapter, &msg, 1) == 1 && (buf[0] & 0x40)) |
| 89 | break; |
| 90 | |
| 91 | msleep(10); |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 92 | } |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 93 | |
| 94 | /* switch the charge pump to the lower current */ |
| 95 | msg.flags = 0; |
| 96 | msg.len = 2; |
| 97 | msg.buf = &buf[2]; |
| 98 | buf[2] &= ~0x40; |
| 99 | if (fe->ops.i2c_gate_ctrl) |
| 100 | fe->ops.i2c_gate_ctrl(fe, 1); |
| 101 | |
| 102 | if (i2c_transfer(&mantis->adapter, &msg, 1) != 1) |
| 103 | return -EIO; |
Manu Abraham | da7365f | 2009-12-02 22:11:00 -0300 | [diff] [blame] | 104 | |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 105 | return 0; |
| 106 | } |