Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 1 | /* |
| 2 | * For Philips TEA5761 FM Chip |
| 3 | * I2C address is allways 0x20 (0x10 at 7-bit mode). |
| 4 | * |
| 5 | * Copyright (c) 2005-2007 Mauro Carvalho Chehab (mchehab@infradead.org) |
| 6 | * This code is placed under the terms of the GNUv2 General Public License |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | #include <linux/i2c.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/slab.h> |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 12 | #include <linux/delay.h> |
Hans Verkuil | 7f6adea | 2009-02-19 17:31:17 -0300 | [diff] [blame] | 13 | #include <linux/videodev2.h> |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 14 | #include <media/tuner.h> |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 15 | #include "tuner-i2c.h" |
| 16 | #include "tea5761.h" |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 17 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 18 | static int debug; |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 19 | module_param(debug, int, 0644); |
| 20 | MODULE_PARM_DESC(debug, "enable verbose debug messages"); |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 21 | |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 22 | struct tea5761_priv { |
| 23 | struct tuner_i2c_props i2c_props; |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 24 | |
| 25 | u32 frequency; |
Mauro Carvalho Chehab | 2d351df | 2011-02-14 18:53:12 -0200 | [diff] [blame] | 26 | bool standby; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 27 | }; |
| 28 | |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 29 | /*****************************************************************************/ |
| 30 | |
| 31 | /*************************** |
| 32 | * TEA5761HN I2C registers * |
| 33 | ***************************/ |
| 34 | |
| 35 | /* INTREG - Read: bytes 0 and 1 / Write: byte 0 */ |
| 36 | |
| 37 | /* first byte for reading */ |
| 38 | #define TEA5761_INTREG_IFFLAG 0x10 |
| 39 | #define TEA5761_INTREG_LEVFLAG 0x8 |
| 40 | #define TEA5761_INTREG_FRRFLAG 0x2 |
| 41 | #define TEA5761_INTREG_BLFLAG 0x1 |
| 42 | |
| 43 | /* second byte for reading / byte for writing */ |
| 44 | #define TEA5761_INTREG_IFMSK 0x10 |
| 45 | #define TEA5761_INTREG_LEVMSK 0x8 |
| 46 | #define TEA5761_INTREG_FRMSK 0x2 |
| 47 | #define TEA5761_INTREG_BLMSK 0x1 |
| 48 | |
| 49 | /* FRQSET - Read: bytes 2 and 3 / Write: byte 1 and 2 */ |
| 50 | |
| 51 | /* First byte */ |
| 52 | #define TEA5761_FRQSET_SEARCH_UP 0x80 /* 1=Station search from botton to up */ |
| 53 | #define TEA5761_FRQSET_SEARCH_MODE 0x40 /* 1=Search mode */ |
| 54 | |
| 55 | /* Bits 0-5 for divider MSB */ |
| 56 | |
| 57 | /* Second byte */ |
| 58 | /* Bits 0-7 for divider LSB */ |
| 59 | |
| 60 | /* TNCTRL - Read: bytes 4 and 5 / Write: Bytes 3 and 4 */ |
| 61 | |
| 62 | /* first byte */ |
| 63 | |
| 64 | #define TEA5761_TNCTRL_PUPD_0 0x40 /* Power UP/Power Down MSB */ |
| 65 | #define TEA5761_TNCTRL_BLIM 0X20 /* 1= Japan Frequencies, 0= European frequencies */ |
| 66 | #define TEA5761_TNCTRL_SWPM 0x10 /* 1= software port is FRRFLAG */ |
| 67 | #define TEA5761_TNCTRL_IFCTC 0x08 /* 1= IF count time 15.02 ms, 0= IF count time 2.02 ms */ |
| 68 | #define TEA5761_TNCTRL_AFM 0x04 |
| 69 | #define TEA5761_TNCTRL_SMUTE 0x02 /* 1= Soft mute */ |
| 70 | #define TEA5761_TNCTRL_SNC 0x01 |
| 71 | |
| 72 | /* second byte */ |
| 73 | |
| 74 | #define TEA5761_TNCTRL_MU 0x80 /* 1=Hard mute */ |
| 75 | #define TEA5761_TNCTRL_SSL_1 0x40 |
| 76 | #define TEA5761_TNCTRL_SSL_0 0x20 |
| 77 | #define TEA5761_TNCTRL_HLSI 0x10 |
| 78 | #define TEA5761_TNCTRL_MST 0x08 /* 1 = mono */ |
| 79 | #define TEA5761_TNCTRL_SWP 0x04 |
| 80 | #define TEA5761_TNCTRL_DTC 0x02 /* 1 = deemphasis 50 us, 0 = deemphasis 75 us */ |
| 81 | #define TEA5761_TNCTRL_AHLSI 0x01 |
| 82 | |
| 83 | /* FRQCHECK - Read: bytes 6 and 7 */ |
| 84 | /* First byte */ |
| 85 | |
| 86 | /* Bits 0-5 for divider MSB */ |
| 87 | |
| 88 | /* Second byte */ |
| 89 | /* Bits 0-7 for divider LSB */ |
| 90 | |
| 91 | /* TUNCHECK - Read: bytes 8 and 9 */ |
| 92 | |
| 93 | /* First byte */ |
| 94 | #define TEA5761_TUNCHECK_IF_MASK 0x7e /* IF count */ |
| 95 | #define TEA5761_TUNCHECK_TUNTO 0x01 |
| 96 | |
| 97 | /* Second byte */ |
| 98 | #define TEA5761_TUNCHECK_LEV_MASK 0xf0 /* Level Count */ |
| 99 | #define TEA5761_TUNCHECK_LD 0x08 |
| 100 | #define TEA5761_TUNCHECK_STEREO 0x04 |
| 101 | |
| 102 | /* TESTREG - Read: bytes 10 and 11 / Write: bytes 5 and 6 */ |
| 103 | |
| 104 | /* All zero = no test mode */ |
| 105 | |
| 106 | /* MANID - Read: bytes 12 and 13 */ |
| 107 | |
| 108 | /* First byte - should be 0x10 */ |
| 109 | #define TEA5767_MANID_VERSION_MASK 0xf0 /* Version = 1 */ |
| 110 | #define TEA5767_MANID_ID_MSB_MASK 0x0f /* Manufacurer ID - should be 0 */ |
| 111 | |
| 112 | /* Second byte - Should be 0x2b */ |
| 113 | |
| 114 | #define TEA5767_MANID_ID_LSB_MASK 0xfe /* Manufacturer ID - should be 0x15 */ |
| 115 | #define TEA5767_MANID_IDAV 0x01 /* 1 = Chip has ID, 0 = Chip has no ID */ |
| 116 | |
| 117 | /* Chip ID - Read: bytes 14 and 15 */ |
| 118 | |
| 119 | /* First byte - should be 0x57 */ |
| 120 | |
| 121 | /* Second byte - should be 0x61 */ |
| 122 | |
| 123 | /*****************************************************************************/ |
| 124 | |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 125 | #define FREQ_OFFSET 0 /* for TEA5767, it is 700 to give the right freq */ |
| 126 | static void tea5761_status_dump(unsigned char *buffer) |
| 127 | { |
| 128 | unsigned int div, frq; |
| 129 | |
| 130 | div = ((buffer[2] & 0x3f) << 8) | buffer[3]; |
| 131 | |
| 132 | frq = 1000 * (div * 32768 / 1000 + FREQ_OFFSET + 225) / 4; /* Freq in KHz */ |
| 133 | |
Michael Krufky | 2756665 | 2008-04-22 14:41:53 -0300 | [diff] [blame] | 134 | printk(KERN_INFO "tea5761: Frequency %d.%03d KHz (divider = 0x%04x)\n", |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 135 | frq / 1000, frq % 1000, div); |
| 136 | } |
| 137 | |
| 138 | /* Freq should be specifyed at 62.5 Hz */ |
Mauro Carvalho Chehab | 2d351df | 2011-02-14 18:53:12 -0200 | [diff] [blame] | 139 | static int __set_radio_freq(struct dvb_frontend *fe, |
| 140 | unsigned int freq, |
| 141 | bool mono) |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 142 | { |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 143 | struct tea5761_priv *priv = fe->tuner_priv; |
Mauro Carvalho Chehab | 2d351df | 2011-02-14 18:53:12 -0200 | [diff] [blame] | 144 | unsigned int frq = freq; |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 145 | unsigned char buffer[7] = {0, 0, 0, 0, 0, 0, 0 }; |
| 146 | unsigned div; |
| 147 | int rc; |
| 148 | |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 149 | tuner_dbg("radio freq counter %d\n", frq); |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 150 | |
Mauro Carvalho Chehab | 2d351df | 2011-02-14 18:53:12 -0200 | [diff] [blame] | 151 | if (priv->standby) { |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 152 | tuner_dbg("TEA5761 set to standby mode\n"); |
| 153 | buffer[5] |= TEA5761_TNCTRL_MU; |
| 154 | } else { |
| 155 | buffer[4] |= TEA5761_TNCTRL_PUPD_0; |
| 156 | } |
| 157 | |
| 158 | |
Mauro Carvalho Chehab | 2d351df | 2011-02-14 18:53:12 -0200 | [diff] [blame] | 159 | if (mono) { |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 160 | tuner_dbg("TEA5761 set to mono\n"); |
| 161 | buffer[5] |= TEA5761_TNCTRL_MST; |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 162 | } else { |
| 163 | tuner_dbg("TEA5761 set to stereo\n"); |
| 164 | } |
| 165 | |
| 166 | div = (1000 * (frq * 4 / 16 + 700 + 225) ) >> 15; |
| 167 | buffer[1] = (div >> 8) & 0x3f; |
| 168 | buffer[2] = div & 0xff; |
| 169 | |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 170 | if (debug) |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 171 | tea5761_status_dump(buffer); |
| 172 | |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 173 | if (7 != (rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 7))) |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 174 | tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 175 | |
| 176 | priv->frequency = frq * 125 / 2; |
| 177 | |
| 178 | return 0; |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 179 | } |
| 180 | |
Mauro Carvalho Chehab | 2d351df | 2011-02-14 18:53:12 -0200 | [diff] [blame] | 181 | static int set_radio_freq(struct dvb_frontend *fe, |
| 182 | struct analog_parameters *params) |
| 183 | { |
| 184 | struct tea5761_priv *priv = fe->analog_demod_priv; |
| 185 | |
| 186 | priv->standby = false; |
| 187 | |
| 188 | return __set_radio_freq(fe, params->frequency, |
| 189 | params->audmode == V4L2_TUNER_MODE_MONO); |
| 190 | } |
| 191 | |
| 192 | static int set_radio_sleep(struct dvb_frontend *fe) |
| 193 | { |
| 194 | struct tea5761_priv *priv = fe->analog_demod_priv; |
| 195 | |
| 196 | priv->standby = true; |
| 197 | |
| 198 | return __set_radio_freq(fe, priv->frequency, false); |
| 199 | } |
| 200 | |
Michael Krufky | fd443f7 | 2007-08-31 16:39:57 -0300 | [diff] [blame] | 201 | static int tea5761_read_status(struct dvb_frontend *fe, char *buffer) |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 202 | { |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 203 | struct tea5761_priv *priv = fe->tuner_priv; |
Michael Krufky | fd443f7 | 2007-08-31 16:39:57 -0300 | [diff] [blame] | 204 | int rc; |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 205 | |
Michael Krufky | fd443f7 | 2007-08-31 16:39:57 -0300 | [diff] [blame] | 206 | memset(buffer, 0, 16); |
| 207 | if (16 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 16))) { |
| 208 | tuner_warn("i2c i/o error: rc == %d (should be 16)\n", rc); |
| 209 | return -EREMOTEIO; |
| 210 | } |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 211 | |
Michael Krufky | fd443f7 | 2007-08-31 16:39:57 -0300 | [diff] [blame] | 212 | return 0; |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 213 | } |
| 214 | |
Michael Krufky | fd443f7 | 2007-08-31 16:39:57 -0300 | [diff] [blame] | 215 | static inline int tea5761_signal(struct dvb_frontend *fe, const char *buffer) |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 216 | { |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 217 | struct tea5761_priv *priv = fe->tuner_priv; |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 218 | |
Michael Krufky | fd443f7 | 2007-08-31 16:39:57 -0300 | [diff] [blame] | 219 | int signal = ((buffer[9] & TEA5761_TUNCHECK_LEV_MASK) << (13 - 4)); |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 220 | |
Michael Krufky | fd443f7 | 2007-08-31 16:39:57 -0300 | [diff] [blame] | 221 | tuner_dbg("Signal strength: %d\n", signal); |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 222 | |
Michael Krufky | fd443f7 | 2007-08-31 16:39:57 -0300 | [diff] [blame] | 223 | return signal; |
| 224 | } |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 225 | |
Michael Krufky | fd443f7 | 2007-08-31 16:39:57 -0300 | [diff] [blame] | 226 | static inline int tea5761_stereo(struct dvb_frontend *fe, const char *buffer) |
| 227 | { |
| 228 | struct tea5761_priv *priv = fe->tuner_priv; |
| 229 | |
| 230 | int stereo = buffer[9] & TEA5761_TUNCHECK_STEREO; |
| 231 | |
| 232 | tuner_dbg("Radio ST GET = %02x\n", stereo); |
| 233 | |
| 234 | return (stereo ? V4L2_TUNER_SUB_STEREO : 0); |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 235 | } |
| 236 | |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 237 | static int tea5761_get_status(struct dvb_frontend *fe, u32 *status) |
| 238 | { |
Michael Krufky | fd443f7 | 2007-08-31 16:39:57 -0300 | [diff] [blame] | 239 | unsigned char buffer[16]; |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 240 | |
| 241 | *status = 0; |
| 242 | |
Michael Krufky | fd443f7 | 2007-08-31 16:39:57 -0300 | [diff] [blame] | 243 | if (0 == tea5761_read_status(fe, buffer)) { |
| 244 | if (tea5761_signal(fe, buffer)) |
| 245 | *status = TUNER_STATUS_LOCKED; |
| 246 | if (tea5761_stereo(fe, buffer)) |
| 247 | *status |= TUNER_STATUS_STEREO; |
| 248 | } |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 249 | |
Michael Krufky | fd443f7 | 2007-08-31 16:39:57 -0300 | [diff] [blame] | 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | static int tea5761_get_rf_strength(struct dvb_frontend *fe, u16 *strength) |
| 254 | { |
| 255 | unsigned char buffer[16]; |
| 256 | |
| 257 | *strength = 0; |
| 258 | |
| 259 | if (0 == tea5761_read_status(fe, buffer)) |
| 260 | *strength = tea5761_signal(fe, buffer); |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 261 | |
| 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | int tea5761_autodetection(struct i2c_adapter* i2c_adap, u8 i2c_addr) |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 266 | { |
| 267 | unsigned char buffer[16]; |
| 268 | int rc; |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 269 | struct tuner_i2c_props i2c = { .adap = i2c_adap, .addr = i2c_addr }; |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 270 | |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 271 | if (16 != (rc = tuner_i2c_xfer_recv(&i2c, buffer, 16))) { |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 272 | printk(KERN_WARNING "it is not a TEA5761. Received %i chars.\n", rc); |
Mauro Carvalho Chehab | 867e835 | 2008-04-23 17:27:27 -0300 | [diff] [blame] | 273 | return -EINVAL; |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 274 | } |
| 275 | |
Mauro Carvalho Chehab | 867e835 | 2008-04-23 17:27:27 -0300 | [diff] [blame] | 276 | if ((buffer[13] != 0x2b) || (buffer[14] != 0x57) || (buffer[15] != 0x061)) { |
| 277 | printk(KERN_WARNING "Manufacturer ID= 0x%02x, Chip ID = %02x%02x." |
| 278 | " It is not a TEA5761\n", |
| 279 | buffer[13], buffer[14], buffer[15]); |
| 280 | return -EINVAL; |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 281 | } |
Mauro Carvalho Chehab | 867e835 | 2008-04-23 17:27:27 -0300 | [diff] [blame] | 282 | printk(KERN_WARNING "tea5761: TEA%02x%02x detected. " |
| 283 | "Manufacturer ID= 0x%02x\n", |
| 284 | buffer[14], buffer[15], buffer[13]); |
| 285 | |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 286 | return 0; |
| 287 | } |
| 288 | |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 289 | static int tea5761_release(struct dvb_frontend *fe) |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 290 | { |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 291 | kfree(fe->tuner_priv); |
| 292 | fe->tuner_priv = NULL; |
| 293 | |
| 294 | return 0; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 295 | } |
| 296 | |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 297 | static int tea5761_get_frequency(struct dvb_frontend *fe, u32 *frequency) |
| 298 | { |
| 299 | struct tea5761_priv *priv = fe->tuner_priv; |
| 300 | *frequency = priv->frequency; |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | static struct dvb_tuner_ops tea5761_tuner_ops = { |
| 305 | .info = { |
| 306 | .name = "tea5761", // Philips TEA5761HN FM Radio |
| 307 | }, |
| 308 | .set_analog_params = set_radio_freq, |
Mauro Carvalho Chehab | 2d351df | 2011-02-14 18:53:12 -0200 | [diff] [blame] | 309 | .sleep = set_radio_sleep, |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 310 | .release = tea5761_release, |
| 311 | .get_frequency = tea5761_get_frequency, |
| 312 | .get_status = tea5761_get_status, |
Michael Krufky | fd443f7 | 2007-08-31 16:39:57 -0300 | [diff] [blame] | 313 | .get_rf_strength = tea5761_get_rf_strength, |
Michael Krufky | e407cd5 | 2007-06-06 16:16:29 -0300 | [diff] [blame] | 314 | }; |
| 315 | |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 316 | struct dvb_frontend *tea5761_attach(struct dvb_frontend *fe, |
| 317 | struct i2c_adapter* i2c_adap, |
| 318 | u8 i2c_addr) |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 319 | { |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 320 | struct tea5761_priv *priv = NULL; |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 321 | |
Marcin Slusarz | 4277106 | 2008-05-11 19:51:07 -0300 | [diff] [blame] | 322 | if (tea5761_autodetection(i2c_adap, i2c_addr) != 0) |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 323 | return NULL; |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 324 | |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 325 | priv = kzalloc(sizeof(struct tea5761_priv), GFP_KERNEL); |
| 326 | if (priv == NULL) |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 327 | return NULL; |
| 328 | fe->tuner_priv = priv; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 329 | |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 330 | priv->i2c_props.addr = i2c_addr; |
| 331 | priv->i2c_props.adap = i2c_adap; |
Michael Krufky | 2756665 | 2008-04-22 14:41:53 -0300 | [diff] [blame] | 332 | priv->i2c_props.name = "tea5761"; |
Michael Krufky | db8a695 | 2007-08-21 01:24:42 -0300 | [diff] [blame] | 333 | |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 334 | memcpy(&fe->ops.tuner_ops, &tea5761_tuner_ops, |
| 335 | sizeof(struct dvb_tuner_ops)); |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 336 | |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 337 | tuner_info("type set to %s\n", "Philips TEA5761HN FM Radio"); |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 338 | |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 339 | return fe; |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 340 | } |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 341 | |
| 342 | |
| 343 | EXPORT_SYMBOL_GPL(tea5761_attach); |
| 344 | EXPORT_SYMBOL_GPL(tea5761_autodetection); |
| 345 | |
| 346 | MODULE_DESCRIPTION("Philips TEA5761 FM tuner driver"); |
| 347 | MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); |
| 348 | MODULE_LICENSE("GPL"); |