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 | |
Andrew de Quincey | 8b9a466 | 2006-08-08 09:10:11 -0300 | [diff] [blame] | 29 | static int debug = 0; |
| 30 | #define dprintk(args...) \ |
| 31 | do { \ |
| 32 | if (debug) printk(KERN_DEBUG "tda826x: " args); \ |
| 33 | } while (0) |
| 34 | |
Andrew de Quincey | 6bca358 | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 35 | struct tda826x_priv { |
| 36 | /* i2c details */ |
| 37 | int i2c_address; |
| 38 | struct i2c_adapter *i2c; |
| 39 | u8 has_loopthrough:1; |
| 40 | u32 frequency; |
| 41 | }; |
| 42 | |
| 43 | static int tda826x_release(struct dvb_frontend *fe) |
| 44 | { |
Michael Krufky | 2213918 | 2006-11-19 19:49:11 -0300 | [diff] [blame] | 45 | kfree(fe->tuner_priv); |
Andrew de Quincey | 6bca358 | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 46 | fe->tuner_priv = NULL; |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | static int tda826x_sleep(struct dvb_frontend *fe) |
| 51 | { |
| 52 | struct tda826x_priv *priv = fe->tuner_priv; |
| 53 | int ret; |
| 54 | u8 buf [] = { 0x00, 0x8d }; |
| 55 | struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = buf, .len = 2 }; |
| 56 | |
Andrew de Quincey | 8b9a466 | 2006-08-08 09:10:11 -0300 | [diff] [blame] | 57 | dprintk("%s:\n", __FUNCTION__); |
| 58 | |
Andrew de Quincey | 6bca358 | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 59 | if (!priv->has_loopthrough) |
| 60 | buf[1] = 0xad; |
| 61 | |
| 62 | if (fe->ops.i2c_gate_ctrl) |
| 63 | fe->ops.i2c_gate_ctrl(fe, 1); |
| 64 | if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) { |
Andrew de Quincey | 8b9a466 | 2006-08-08 09:10:11 -0300 | [diff] [blame] | 65 | dprintk("%s: i2c error\n", __FUNCTION__); |
Andrew de Quincey | 6bca358 | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 66 | } |
| 67 | if (fe->ops.i2c_gate_ctrl) |
| 68 | fe->ops.i2c_gate_ctrl(fe, 0); |
Andrew de Quincey | 6bca358 | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 69 | |
| 70 | return (ret == 1) ? 0 : ret; |
| 71 | } |
| 72 | |
| 73 | static int tda826x_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params) |
| 74 | { |
| 75 | struct tda826x_priv *priv = fe->tuner_priv; |
| 76 | int ret; |
| 77 | u32 div; |
| 78 | u8 buf [11]; |
| 79 | struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = buf, .len = 11 }; |
| 80 | |
Andrew de Quincey | 8b9a466 | 2006-08-08 09:10:11 -0300 | [diff] [blame] | 81 | dprintk("%s:\n", __FUNCTION__); |
| 82 | |
Andrew de Quincey | 6bca358 | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 83 | div = (params->frequency + (1000-1)) / 1000; |
| 84 | |
| 85 | buf[0] = 0x00; // subaddress |
| 86 | buf[1] = 0x09; // powerdown RSSI + the magic value 1 |
| 87 | if (!priv->has_loopthrough) |
| 88 | buf[1] |= 0x20; // power down loopthrough if not needed |
| 89 | buf[2] = (1<<5) | 0x0b; // 1Mhz + 0.45 VCO |
| 90 | buf[3] = div >> 7; |
| 91 | buf[4] = div << 1; |
| 92 | buf[5] = 0xff; // basedband filter to max |
| 93 | buf[6] = 0xfe; // gains at max + no RF attenuation |
| 94 | buf[7] = 0x83; // charge pumps at high, tests off |
| 95 | buf[8] = 0x80; // recommended value 4 for AMPVCO + disable ports. |
| 96 | buf[9] = 0x1a; // normal caltime + recommended values for SELTH + SELVTL |
| 97 | buf[10] = 0xd4; // recommended value 13 for BBIAS + unknown bit set on |
| 98 | |
| 99 | if (fe->ops.i2c_gate_ctrl) |
| 100 | fe->ops.i2c_gate_ctrl(fe, 1); |
| 101 | if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) { |
Andrew de Quincey | 8b9a466 | 2006-08-08 09:10:11 -0300 | [diff] [blame] | 102 | dprintk("%s: i2c error\n", __FUNCTION__); |
Andrew de Quincey | 6bca358 | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 103 | } |
| 104 | if (fe->ops.i2c_gate_ctrl) |
| 105 | fe->ops.i2c_gate_ctrl(fe, 0); |
| 106 | |
| 107 | priv->frequency = div * 1000; |
Andrew de Quincey | 6bca358 | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 108 | |
| 109 | return (ret == 1) ? 0 : ret; |
| 110 | } |
| 111 | |
| 112 | static int tda826x_get_frequency(struct dvb_frontend *fe, u32 *frequency) |
| 113 | { |
| 114 | struct tda826x_priv *priv = fe->tuner_priv; |
| 115 | *frequency = priv->frequency; |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | static struct dvb_tuner_ops tda826x_tuner_ops = { |
Trent Piepho | ef09c07 | 2006-08-08 09:10:11 -0300 | [diff] [blame] | 120 | .info = { |
| 121 | .name = "Philips TDA826X", |
| 122 | .frequency_min = 950000, |
Alexey Dobriyan | d027c4d | 2006-11-03 07:14:32 -0300 | [diff] [blame] | 123 | .frequency_max = 2175000 |
Trent Piepho | ef09c07 | 2006-08-08 09:10:11 -0300 | [diff] [blame] | 124 | }, |
Andrew de Quincey | 6bca358 | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 125 | .release = tda826x_release, |
| 126 | .sleep = tda826x_sleep, |
| 127 | .set_params = tda826x_set_params, |
| 128 | .get_frequency = tda826x_get_frequency, |
| 129 | }; |
| 130 | |
| 131 | struct dvb_frontend *tda826x_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c, int has_loopthrough) |
| 132 | { |
| 133 | struct tda826x_priv *priv = NULL; |
| 134 | u8 b1 [] = { 0, 0 }; |
Andrew de Quincey | e4a49d7 | 2006-08-08 15:48:07 -0300 | [diff] [blame] | 135 | 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] | 136 | int ret; |
| 137 | |
Andrew de Quincey | 8b9a466 | 2006-08-08 09:10:11 -0300 | [diff] [blame] | 138 | dprintk("%s:\n", __FUNCTION__); |
| 139 | |
Andrew de Quincey | 6bca358 | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 140 | if (fe->ops.i2c_gate_ctrl) |
| 141 | fe->ops.i2c_gate_ctrl(fe, 1); |
Andrew de Quincey | e4a49d7 | 2006-08-08 15:48:07 -0300 | [diff] [blame] | 142 | ret = i2c_transfer (i2c, &msg, 1); |
Andrew de Quincey | 6bca358 | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 143 | if (fe->ops.i2c_gate_ctrl) |
| 144 | fe->ops.i2c_gate_ctrl(fe, 0); |
| 145 | |
Andrew de Quincey | e4a49d7 | 2006-08-08 15:48:07 -0300 | [diff] [blame] | 146 | if (ret != 1) |
Andrew de Quincey | 6bca358 | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 147 | return NULL; |
| 148 | if (!(b1[1] & 0x80)) |
| 149 | return NULL; |
| 150 | |
| 151 | priv = kzalloc(sizeof(struct tda826x_priv), GFP_KERNEL); |
| 152 | if (priv == NULL) |
| 153 | return NULL; |
| 154 | |
| 155 | priv->i2c_address = addr; |
| 156 | priv->i2c = i2c; |
| 157 | priv->has_loopthrough = has_loopthrough; |
| 158 | |
| 159 | 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] | 160 | |
| 161 | fe->tuner_priv = priv; |
Andrew de Quincey | 6bca358 | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 162 | |
| 163 | return fe; |
| 164 | } |
| 165 | EXPORT_SYMBOL(tda826x_attach); |
| 166 | |
Andrew de Quincey | 8b9a466 | 2006-08-08 09:10:11 -0300 | [diff] [blame] | 167 | module_param(debug, int, 0644); |
| 168 | MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); |
| 169 | |
Andrew de Quincey | 6bca358 | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 170 | MODULE_DESCRIPTION("DVB TDA826x driver"); |
| 171 | MODULE_AUTHOR("Andrew de Quincey"); |
| 172 | MODULE_LICENSE("GPL"); |