Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 1 | /* |
| 2 | Mantis VP-2033 driver |
| 3 | |
Manu Abraham | 8825a09 | 2009-12-15 09:13:49 -0300 | [diff] [blame] | 4 | Copyright (C) Manu Abraham (abraham.manu@gmail.com) |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 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 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 21 | #include <linux/signal.h> |
| 22 | #include <linux/sched.h> |
| 23 | #include <linux/interrupt.h> |
| 24 | |
| 25 | #include "dmxdev.h" |
| 26 | #include "dvbdev.h" |
| 27 | #include "dvb_demux.h" |
| 28 | #include "dvb_frontend.h" |
| 29 | #include "dvb_net.h" |
| 30 | |
| 31 | #include "tda1002x.h" |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 32 | #include "mantis_common.h" |
Manu Abraham | bc832fa | 2009-12-04 05:57:28 -0300 | [diff] [blame] | 33 | #include "mantis_ioc.h" |
| 34 | #include "mantis_dvb.h" |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 35 | #include "mantis_vp2033.h" |
| 36 | |
Manu Abraham | df0cca1 | 2009-12-02 22:07:24 -0300 | [diff] [blame] | 37 | #define MANTIS_MODEL_NAME "VP-2033" |
| 38 | #define MANTIS_DEV_TYPE "DVB-C" |
| 39 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 40 | struct tda1002x_config vp2033_tda1002x_cu1216_config = { |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 41 | .demod_address = 0x18 >> 1, |
| 42 | .invert = 1, |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 43 | }; |
| 44 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 45 | struct tda10023_config vp2033_tda10023_cu1216_config = { |
| 46 | .demod_address = 0x18 >> 1, |
| 47 | .invert = 1, |
| 48 | }; |
| 49 | |
| 50 | static u8 read_pwm(struct mantis_pci *mantis) |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 51 | { |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 52 | struct i2c_adapter *adapter = &mantis->adapter; |
| 53 | |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 54 | u8 b = 0xff; |
| 55 | u8 pwm; |
| 56 | struct i2c_msg msg[] = { |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 57 | {.addr = 0x50, .flags = 0, .buf = &b, .len = 1}, |
| 58 | {.addr = 0x50, .flags = I2C_M_RD, .buf = &pwm, .len = 1} |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 59 | }; |
| 60 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 61 | if ((i2c_transfer(adapter, msg, 2) != 2) |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 62 | || (pwm == 0xff)) |
| 63 | pwm = 0x48; |
| 64 | |
| 65 | return pwm; |
| 66 | } |
| 67 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 68 | static int tda1002x_cu1216_tuner_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params) |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 69 | { |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 70 | struct mantis_pci *mantis = fe->dvb->priv; |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 71 | struct i2c_adapter *adapter = &mantis->adapter; |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 72 | |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 73 | u8 buf[6]; |
Manu Abraham | f5ae4f6 | 2009-12-15 08:47:21 -0300 | [diff] [blame] | 74 | struct i2c_msg msg = {.addr = 0x60, .flags = 0, .buf = buf, .len = sizeof(buf)}; |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 75 | int i; |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 76 | |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 77 | #define CU1216_IF 36125000 |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 78 | #define TUNER_MUL 62500 |
| 79 | |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 80 | u32 div = (params->frequency + CU1216_IF + TUNER_MUL / 2) / TUNER_MUL; |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 81 | |
| 82 | buf[0] = (div >> 8) & 0x7f; |
| 83 | buf[1] = div & 0xff; |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 84 | buf[2] = 0xce; |
| 85 | buf[3] = (params->frequency < 150000000 ? 0x01 : |
| 86 | params->frequency < 445000000 ? 0x02 : 0x04); |
| 87 | buf[4] = 0xde; |
| 88 | buf[5] = 0x20; |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 89 | |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 90 | if (fe->ops.i2c_gate_ctrl) |
| 91 | fe->ops.i2c_gate_ctrl(fe, 1); |
| 92 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 93 | if (i2c_transfer(adapter, &msg, 1) != 1) |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 94 | return -EIO; |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 95 | |
| 96 | /* wait for the pll lock */ |
| 97 | msg.flags = I2C_M_RD; |
| 98 | msg.len = 1; |
| 99 | for (i = 0; i < 20; i++) { |
| 100 | if (fe->ops.i2c_gate_ctrl) |
| 101 | fe->ops.i2c_gate_ctrl(fe, 1); |
| 102 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 103 | if (i2c_transfer(adapter, &msg, 1) == 1 && (buf[0] & 0x40)) |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 104 | break; |
| 105 | |
| 106 | msleep(10); |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 107 | } |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 108 | |
| 109 | /* switch the charge pump to the lower current */ |
| 110 | msg.flags = 0; |
| 111 | msg.len = 2; |
| 112 | msg.buf = &buf[2]; |
| 113 | buf[2] &= ~0x40; |
| 114 | if (fe->ops.i2c_gate_ctrl) |
| 115 | fe->ops.i2c_gate_ctrl(fe, 1); |
| 116 | |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 117 | if (i2c_transfer(adapter, &msg, 1) != 1) |
Manu Abraham | 2687d83 | 2009-12-04 04:39:14 -0300 | [diff] [blame] | 118 | return -EIO; |
Manu Abraham | da7365f | 2009-12-02 22:11:00 -0300 | [diff] [blame] | 119 | |
Manu Abraham | 41e840b | 2009-12-02 21:57:10 -0300 | [diff] [blame] | 120 | return 0; |
| 121 | } |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 122 | |
| 123 | static int vp2033_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *fe) |
| 124 | { |
| 125 | struct i2c_adapter *adapter = &mantis->adapter; |
| 126 | |
Manu Abraham | bc832fa | 2009-12-04 05:57:28 -0300 | [diff] [blame] | 127 | int err = 0; |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 128 | |
Manu Abraham | bc832fa | 2009-12-04 05:57:28 -0300 | [diff] [blame] | 129 | err = mantis_frontend_power(mantis, POWER_ON); |
| 130 | if (err == 0) { |
| 131 | mantis_frontend_soft_reset(mantis); |
| 132 | msleep(250); |
| 133 | |
| 134 | dprintk(MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)"); |
| 135 | fe = tda10021_attach(&vp2033_tda1002x_cu1216_config, |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 136 | adapter, |
| 137 | read_pwm(mantis)); |
| 138 | |
| 139 | if (fe) { |
| 140 | dprintk(MANTIS_ERROR, 1, |
Manu Abraham | bc832fa | 2009-12-04 05:57:28 -0300 | [diff] [blame] | 141 | "found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x", |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 142 | vp2033_tda1002x_cu1216_config.demod_address); |
Manu Abraham | bc832fa | 2009-12-04 05:57:28 -0300 | [diff] [blame] | 143 | } else { |
| 144 | fe = tda10023_attach(&vp2033_tda10023_cu1216_config, |
| 145 | adapter, |
| 146 | read_pwm(mantis)); |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 147 | |
Manu Abraham | bc832fa | 2009-12-04 05:57:28 -0300 | [diff] [blame] | 148 | if (fe) { |
| 149 | dprintk(MANTIS_ERROR, 1, |
| 150 | "found Philips CU1216 DVB-C frontend (TDA10023) @ 0x%02x", |
| 151 | vp2033_tda1002x_cu1216_config.demod_address); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | if (fe) { |
| 156 | fe->ops.tuner_ops.set_params = tda1002x_cu1216_tuner_set; |
| 157 | dprintk(MANTIS_ERROR, 1, "Mantis DVB-C Philips CU1216 frontend attach success"); |
| 158 | } else { |
| 159 | return -1; |
| 160 | } |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 161 | } else { |
Manu Abraham | bc832fa | 2009-12-04 05:57:28 -0300 | [diff] [blame] | 162 | dprintk(MANTIS_ERROR, 1, "Frontend on <%s> POWER ON failed! <%d>", |
| 163 | adapter->name, |
| 164 | err); |
| 165 | |
| 166 | return -EIO; |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | mantis->fe = fe; |
| 170 | dprintk(MANTIS_DEBUG, 1, "Done!"); |
| 171 | |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | struct mantis_hwconfig vp2033_config = { |
| 176 | .model_name = MANTIS_MODEL_NAME, |
| 177 | .dev_type = MANTIS_DEV_TYPE, |
| 178 | .ts_size = MANTIS_TS_204, |
| 179 | |
| 180 | .baud_rate = MANTIS_BAUD_9600, |
| 181 | .parity = MANTIS_PARITY_NONE, |
| 182 | .bytes = 0, |
| 183 | |
| 184 | .frontend_init = vp2033_frontend_init, |
Manu Abraham | bc832fa | 2009-12-04 05:57:28 -0300 | [diff] [blame] | 185 | .power = GPIF_A12, |
| 186 | .reset = GPIF_A13, |
Manu Abraham | b3b9614 | 2009-12-04 05:41:11 -0300 | [diff] [blame] | 187 | }; |