Andrew de Quincey | 6bca358 | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 1 | /* |
| 2 | Driver for Philips tda8262/tda8263 DVBS Silicon tuners |
| 3 | |
| 4 | (c) 2006 Andrew de Quincey |
| 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 | |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | |
| 21 | */ |
| 22 | |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/dvb/frontend.h> |
| 25 | #include <asm/types.h> |
| 26 | |
| 27 | #include "tda826x.h" |
| 28 | |
| 29 | struct tda826x_priv { |
| 30 | /* i2c details */ |
| 31 | int i2c_address; |
| 32 | struct i2c_adapter *i2c; |
| 33 | u8 has_loopthrough:1; |
| 34 | u32 frequency; |
| 35 | }; |
| 36 | |
| 37 | static int tda826x_release(struct dvb_frontend *fe) |
| 38 | { |
| 39 | if (fe->tuner_priv) |
| 40 | kfree(fe->tuner_priv); |
| 41 | fe->tuner_priv = NULL; |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | static int tda826x_sleep(struct dvb_frontend *fe) |
| 46 | { |
| 47 | struct tda826x_priv *priv = fe->tuner_priv; |
| 48 | int ret; |
| 49 | u8 buf [] = { 0x00, 0x8d }; |
| 50 | struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = buf, .len = 2 }; |
| 51 | |
| 52 | if (!priv->has_loopthrough) |
| 53 | buf[1] = 0xad; |
| 54 | |
| 55 | if (fe->ops.i2c_gate_ctrl) |
| 56 | fe->ops.i2c_gate_ctrl(fe, 1); |
| 57 | if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) { |
| 58 | printk("%s: i2c error\n", __FUNCTION__); |
| 59 | } |
| 60 | if (fe->ops.i2c_gate_ctrl) |
| 61 | fe->ops.i2c_gate_ctrl(fe, 0); |
| 62 | printk("%s:\n", __FUNCTION__); |
| 63 | |
| 64 | return (ret == 1) ? 0 : ret; |
| 65 | } |
| 66 | |
| 67 | static int tda826x_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params) |
| 68 | { |
| 69 | struct tda826x_priv *priv = fe->tuner_priv; |
| 70 | int ret; |
| 71 | u32 div; |
| 72 | u8 buf [11]; |
| 73 | struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = buf, .len = 11 }; |
| 74 | |
| 75 | div = (params->frequency + (1000-1)) / 1000; |
| 76 | |
| 77 | buf[0] = 0x00; // subaddress |
| 78 | buf[1] = 0x09; // powerdown RSSI + the magic value 1 |
| 79 | if (!priv->has_loopthrough) |
| 80 | buf[1] |= 0x20; // power down loopthrough if not needed |
| 81 | buf[2] = (1<<5) | 0x0b; // 1Mhz + 0.45 VCO |
| 82 | buf[3] = div >> 7; |
| 83 | buf[4] = div << 1; |
| 84 | buf[5] = 0xff; // basedband filter to max |
| 85 | buf[6] = 0xfe; // gains at max + no RF attenuation |
| 86 | buf[7] = 0x83; // charge pumps at high, tests off |
| 87 | buf[8] = 0x80; // recommended value 4 for AMPVCO + disable ports. |
| 88 | buf[9] = 0x1a; // normal caltime + recommended values for SELTH + SELVTL |
| 89 | buf[10] = 0xd4; // recommended value 13 for BBIAS + unknown bit set on |
| 90 | |
| 91 | if (fe->ops.i2c_gate_ctrl) |
| 92 | fe->ops.i2c_gate_ctrl(fe, 1); |
| 93 | if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) { |
| 94 | printk("%s: i2c error\n", __FUNCTION__); |
| 95 | } |
| 96 | if (fe->ops.i2c_gate_ctrl) |
| 97 | fe->ops.i2c_gate_ctrl(fe, 0); |
| 98 | |
| 99 | priv->frequency = div * 1000; |
| 100 | printk("%s:\n", __FUNCTION__); |
| 101 | |
| 102 | return (ret == 1) ? 0 : ret; |
| 103 | } |
| 104 | |
| 105 | static int tda826x_get_frequency(struct dvb_frontend *fe, u32 *frequency) |
| 106 | { |
| 107 | struct tda826x_priv *priv = fe->tuner_priv; |
| 108 | *frequency = priv->frequency; |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | static struct dvb_tuner_ops tda826x_tuner_ops = { |
Trent Piepho | ef09c07 | 2006-08-08 09:10:11 -0300 | [diff] [blame] | 113 | .info = { |
| 114 | .name = "Philips TDA826X", |
| 115 | .frequency_min = 950000, |
| 116 | .frequency_min = 2175000 |
| 117 | }, |
Andrew de Quincey | 6bca358 | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 118 | .release = tda826x_release, |
| 119 | .sleep = tda826x_sleep, |
| 120 | .set_params = tda826x_set_params, |
| 121 | .get_frequency = tda826x_get_frequency, |
| 122 | }; |
| 123 | |
| 124 | struct dvb_frontend *tda826x_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c, int has_loopthrough) |
| 125 | { |
| 126 | struct tda826x_priv *priv = NULL; |
| 127 | u8 b1 [] = { 0, 0 }; |
Trent Piepho | ef09c07 | 2006-08-08 09:10:11 -0300 | [diff] [blame] | 128 | struct i2c_msg msg [] = { { .addr = addr, .flags = I2C_M_RD, .buf = b1, .len = 2 } }; |
Andrew de Quincey | 6bca358 | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 129 | int ret; |
| 130 | |
| 131 | if (fe->ops.i2c_gate_ctrl) |
| 132 | fe->ops.i2c_gate_ctrl(fe, 1); |
Trent Piepho | ef09c07 | 2006-08-08 09:10:11 -0300 | [diff] [blame] | 133 | ret = i2c_transfer (i2c, msg, 1); |
Andrew de Quincey | 6bca358 | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 134 | if (fe->ops.i2c_gate_ctrl) |
| 135 | fe->ops.i2c_gate_ctrl(fe, 0); |
| 136 | |
| 137 | if (ret != 2) |
| 138 | return NULL; |
| 139 | if (!(b1[1] & 0x80)) |
| 140 | return NULL; |
| 141 | |
| 142 | priv = kzalloc(sizeof(struct tda826x_priv), GFP_KERNEL); |
| 143 | if (priv == NULL) |
| 144 | return NULL; |
| 145 | |
| 146 | priv->i2c_address = addr; |
| 147 | priv->i2c = i2c; |
| 148 | priv->has_loopthrough = has_loopthrough; |
| 149 | |
| 150 | memcpy(&fe->ops.tuner_ops, &tda826x_tuner_ops, sizeof(struct dvb_tuner_ops)); |
Andrew de Quincey | 6bca358 | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 151 | |
| 152 | fe->tuner_priv = priv; |
| 153 | printk("%s:\n", __FUNCTION__); |
| 154 | |
| 155 | return fe; |
| 156 | } |
| 157 | EXPORT_SYMBOL(tda826x_attach); |
| 158 | |
| 159 | MODULE_DESCRIPTION("DVB TDA826x driver"); |
| 160 | MODULE_AUTHOR("Andrew de Quincey"); |
| 161 | MODULE_LICENSE("GPL"); |