blob: 2a039de8ab9ae822917ac65c36b40002897b998e [file] [log] [blame]
Steven Tothaacb9d32007-12-18 01:55:51 -03001/*
2 * Driver for Xceive XC5000 "QAM/8VSB single chip tuner"
3 *
4 * Copyright (c) 2007 Xceive Corporation
Steven Toth6d897612008-09-03 17:12:12 -03005 * Copyright (c) 2007 Steven Toth <stoth@linuxtv.org>
Devin Heitmuellere80858e2009-05-14 21:31:11 -03006 * Copyright (c) 2009 Devin Heitmueller <dheitmueller@kernellabs.com>
Steven Tothaacb9d32007-12-18 01:55:51 -03007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 *
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#include <linux/module.h>
25#include <linux/moduleparam.h>
Steven Toth49170192008-01-15 21:57:14 -030026#include <linux/videodev2.h>
Steven Tothaacb9d32007-12-18 01:55:51 -030027#include <linux/delay.h>
Mauro Carvalho Chehabf7a27ff2014-05-21 13:57:30 -030028#include <linux/workqueue.h>
Steven Tothaacb9d32007-12-18 01:55:51 -030029#include <linux/dvb/frontend.h>
30#include <linux/i2c.h>
31
32#include "dvb_frontend.h"
33
34#include "xc5000.h"
Michael Krufky89fd2852008-09-06 11:44:53 -030035#include "tuner-i2c.h"
Steven Tothaacb9d32007-12-18 01:55:51 -030036
37static int debug;
38module_param(debug, int, 0644);
39MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
40
Devin Heitmuellerb6bd5eb2009-04-28 13:53:38 -030041static int no_poweroff;
42module_param(no_poweroff, int, 0644);
43MODULE_PARM_DESC(no_poweroff, "0 (default) powers device off when not used.\n"
44 "\t\t1 keep device energized and with tuner ready all the times.\n"
45 "\t\tFaster, but consumes more power and keeps the device hotter");
46
Michael Krufky89fd2852008-09-06 11:44:53 -030047static DEFINE_MUTEX(xc5000_list_mutex);
48static LIST_HEAD(hybrid_tuner_instance_list);
49
Steven Toth8f3cd532008-10-16 20:29:38 -030050#define dprintk(level, fmt, arg...) if (debug >= level) \
Steven Tothaacb9d32007-12-18 01:55:51 -030051 printk(KERN_INFO "%s: " fmt, "xc5000", ## arg)
52
Michael Krufkyffb41232008-09-06 10:52:30 -030053struct xc5000_priv {
Michael Krufky89fd2852008-09-06 11:44:53 -030054 struct tuner_i2c_props i2c_props;
55 struct list_head hybrid_tuner_instance_list;
Michael Krufkyffb41232008-09-06 10:52:30 -030056
Michael Krufky2a6003c2008-09-06 13:54:45 -030057 u32 if_khz;
Michael Krufky409328a2012-04-16 15:21:51 -030058 u16 xtal_khz;
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -030059 u32 freq_hz, freq_offset;
Michael Krufkyffb41232008-09-06 10:52:30 -030060 u32 bandwidth;
61 u8 video_standard;
Mauro Carvalho Chehab16435202014-08-09 21:47:21 -030062 unsigned int mode;
Michael Krufkyffb41232008-09-06 10:52:30 -030063 u8 rf_mode;
Devin Heitmueller496e9052009-09-24 13:27:24 -030064 u8 radio_input;
Richard Vollkommer52e269b2014-10-25 17:17:22 -030065 u16 output_amp;
Michael Krufky76efb0ba2012-02-06 19:40:32 -030066
Michael Krufky6fab81d2012-02-08 14:57:39 -030067 int chip_id;
Devin Heitmuellerde49bc62012-08-06 22:47:08 -030068 u16 pll_register_no;
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -030069 u8 init_status_supported;
70 u8 fw_checksum_supported;
Mauro Carvalho Chehabf7a27ff2014-05-21 13:57:30 -030071
72 struct dvb_frontend *fe;
73 struct delayed_work timer_sleep;
Shuah Khan5264a522014-09-22 21:30:46 -030074
75 const struct firmware *firmware;
Michael Krufkyffb41232008-09-06 10:52:30 -030076};
77
Steven Tothaacb9d32007-12-18 01:55:51 -030078/* Misc Defines */
Dmitri Belimov724dcbf2011-02-01 05:25:19 -030079#define MAX_TV_STANDARD 24
Steven Tothaacb9d32007-12-18 01:55:51 -030080#define XC_MAX_I2C_WRITE_LENGTH 64
81
Mauro Carvalho Chehabf7a27ff2014-05-21 13:57:30 -030082/* Time to suspend after the .sleep callback is called */
83#define XC5000_SLEEP_TIME 5000 /* ms */
84
Steven Tothaacb9d32007-12-18 01:55:51 -030085/* Signal Types */
86#define XC_RF_MODE_AIR 0
87#define XC_RF_MODE_CABLE 1
88
Steven Toth27c685a2008-01-05 16:50:14 -030089/* Product id */
90#define XC_PRODUCT_ID_FW_NOT_LOADED 0x2000
Mauro Carvalho Chehab5015c272014-05-21 13:41:01 -030091#define XC_PRODUCT_ID_FW_LOADED 0x1388
Steven Toth27c685a2008-01-05 16:50:14 -030092
Steven Tothaacb9d32007-12-18 01:55:51 -030093/* Registers */
94#define XREG_INIT 0x00
95#define XREG_VIDEO_MODE 0x01
96#define XREG_AUDIO_MODE 0x02
97#define XREG_RF_FREQ 0x03
98#define XREG_D_CODE 0x04
99#define XREG_IF_OUT 0x05
100#define XREG_SEEK_MODE 0x07
Devin Heitmueller7f05b532009-04-02 22:02:39 -0300101#define XREG_POWER_DOWN 0x0A /* Obsolete */
Dmitri Belimov724dcbf2011-02-01 05:25:19 -0300102/* Set the output amplitude - SIF for analog, DTVP/DTVN for digital */
103#define XREG_OUTPUT_AMP 0x0B
Steven Tothaacb9d32007-12-18 01:55:51 -0300104#define XREG_SIGNALSOURCE 0x0D /* 0=Air, 1=Cable */
105#define XREG_SMOOTHEDCVBS 0x0E
106#define XREG_XTALFREQ 0x0F
Devin Heitmueller81c4dfe2009-04-02 22:40:29 -0300107#define XREG_FINERFREQ 0x10
Steven Tothaacb9d32007-12-18 01:55:51 -0300108#define XREG_DDIMODE 0x11
109
110#define XREG_ADC_ENV 0x00
111#define XREG_QUALITY 0x01
112#define XREG_FRAME_LINES 0x02
113#define XREG_HSYNC_FREQ 0x03
114#define XREG_LOCK 0x04
115#define XREG_FREQ_ERROR 0x05
116#define XREG_SNR 0x06
117#define XREG_VERSION 0x07
118#define XREG_PRODUCT_ID 0x08
119#define XREG_BUSY 0x09
Devin Heitmuellerbae7b7d2009-04-02 22:24:38 -0300120#define XREG_BUILD 0x0D
Devin Heitmueller7c287f12012-08-06 22:46:56 -0300121#define XREG_TOTALGAIN 0x0F
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -0300122#define XREG_FW_CHECKSUM 0x12
123#define XREG_INIT_STATUS 0x13
Steven Tothaacb9d32007-12-18 01:55:51 -0300124
125/*
126 Basic firmware description. This will remain with
127 the driver for documentation purposes.
128
129 This represents an I2C firmware file encoded as a
130 string of unsigned char. Format is as follows:
131
132 char[0 ]=len0_MSB -> len = len_MSB * 256 + len_LSB
133 char[1 ]=len0_LSB -> length of first write transaction
134 char[2 ]=data0 -> first byte to be sent
135 char[3 ]=data1
136 char[4 ]=data2
137 char[ ]=...
138 char[M ]=dataN -> last byte to be sent
139 char[M+1]=len1_MSB -> len = len_MSB * 256 + len_LSB
140 char[M+2]=len1_LSB -> length of second write transaction
141 char[M+3]=data0
142 char[M+4]=data1
143 ...
144 etc.
145
146 The [len] value should be interpreted as follows:
147
148 len= len_MSB _ len_LSB
149 len=1111_1111_1111_1111 : End of I2C_SEQUENCE
150 len=0000_0000_0000_0000 : Reset command: Do hardware reset
151 len=0NNN_NNNN_NNNN_NNNN : Normal transaction: number of bytes = {1:32767)
152 len=1WWW_WWWW_WWWW_WWWW : Wait command: wait for {1:32767} ms
153
154 For the RESET and WAIT commands, the two following bytes will contain
155 immediately the length of the following transaction.
156
157*/
Steven Toth8f3cd532008-10-16 20:29:38 -0300158struct XC_TV_STANDARD {
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300159 char *name;
160 u16 audio_mode;
161 u16 video_mode;
Steven Toth8f3cd532008-10-16 20:29:38 -0300162};
Steven Tothaacb9d32007-12-18 01:55:51 -0300163
164/* Tuner standards */
Steven Toth27c685a2008-01-05 16:50:14 -0300165#define MN_NTSC_PAL_BTSC 0
166#define MN_NTSC_PAL_A2 1
167#define MN_NTSC_PAL_EIAJ 2
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300168#define MN_NTSC_PAL_MONO 3
Steven Toth27c685a2008-01-05 16:50:14 -0300169#define BG_PAL_A2 4
170#define BG_PAL_NICAM 5
171#define BG_PAL_MONO 6
172#define I_PAL_NICAM 7
173#define I_PAL_NICAM_MONO 8
174#define DK_PAL_A2 9
175#define DK_PAL_NICAM 10
176#define DK_PAL_MONO 11
177#define DK_SECAM_A2DK1 12
Mauro Carvalho Chehab5015c272014-05-21 13:41:01 -0300178#define DK_SECAM_A2LDK3 13
179#define DK_SECAM_A2MONO 14
Steven Toth27c685a2008-01-05 16:50:14 -0300180#define L_SECAM_NICAM 15
181#define LC_SECAM_NICAM 16
182#define DTV6 17
183#define DTV8 18
184#define DTV7_8 19
185#define DTV7 20
Mauro Carvalho Chehab5015c272014-05-21 13:41:01 -0300186#define FM_RADIO_INPUT2 21
187#define FM_RADIO_INPUT1 22
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300188#define FM_RADIO_INPUT1_MONO 23
Steven Tothaacb9d32007-12-18 01:55:51 -0300189
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300190static struct XC_TV_STANDARD xc5000_standard[MAX_TV_STANDARD] = {
Steven Tothaacb9d32007-12-18 01:55:51 -0300191 {"M/N-NTSC/PAL-BTSC", 0x0400, 0x8020},
192 {"M/N-NTSC/PAL-A2", 0x0600, 0x8020},
193 {"M/N-NTSC/PAL-EIAJ", 0x0440, 0x8020},
194 {"M/N-NTSC/PAL-Mono", 0x0478, 0x8020},
195 {"B/G-PAL-A2", 0x0A00, 0x8049},
196 {"B/G-PAL-NICAM", 0x0C04, 0x8049},
197 {"B/G-PAL-MONO", 0x0878, 0x8059},
198 {"I-PAL-NICAM", 0x1080, 0x8009},
199 {"I-PAL-NICAM-MONO", 0x0E78, 0x8009},
200 {"D/K-PAL-A2", 0x1600, 0x8009},
201 {"D/K-PAL-NICAM", 0x0E80, 0x8009},
202 {"D/K-PAL-MONO", 0x1478, 0x8009},
203 {"D/K-SECAM-A2 DK1", 0x1200, 0x8009},
Steven Toth8f3cd532008-10-16 20:29:38 -0300204 {"D/K-SECAM-A2 L/DK3", 0x0E00, 0x8009},
Steven Tothaacb9d32007-12-18 01:55:51 -0300205 {"D/K-SECAM-A2 MONO", 0x1478, 0x8009},
206 {"L-SECAM-NICAM", 0x8E82, 0x0009},
207 {"L'-SECAM-NICAM", 0x8E82, 0x4009},
208 {"DTV6", 0x00C0, 0x8002},
209 {"DTV8", 0x00C0, 0x800B},
210 {"DTV7/8", 0x00C0, 0x801B},
211 {"DTV7", 0x00C0, 0x8007},
212 {"FM Radio-INPUT2", 0x9802, 0x9002},
Dmitri Belimov724dcbf2011-02-01 05:25:19 -0300213 {"FM Radio-INPUT1", 0x0208, 0x9002},
214 {"FM Radio-INPUT1_MONO", 0x0278, 0x9002}
Steven Tothaacb9d32007-12-18 01:55:51 -0300215};
216
Michael Krufkyddea4272012-02-07 02:39:36 -0300217
218struct xc5000_fw_cfg {
219 char *name;
220 u16 size;
Devin Heitmuellerde49bc62012-08-06 22:47:08 -0300221 u16 pll_reg;
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -0300222 u8 init_status_supported;
223 u8 fw_checksum_supported;
Michael Krufkyddea4272012-02-07 02:39:36 -0300224};
225
Tim Gardner3422f2a62012-07-25 09:15:19 -0300226#define XC5000A_FIRMWARE "dvb-fe-xc5000-1.6.114.fw"
Michael Krufkya3db60b2012-02-08 15:03:07 -0300227static const struct xc5000_fw_cfg xc5000a_1_6_114 = {
Tim Gardner3422f2a62012-07-25 09:15:19 -0300228 .name = XC5000A_FIRMWARE,
Michael Krufky76efb0ba2012-02-06 19:40:32 -0300229 .size = 12401,
Devin Heitmuellerde49bc62012-08-06 22:47:08 -0300230 .pll_reg = 0x806c,
Michael Krufky76efb0ba2012-02-06 19:40:32 -0300231};
232
Devin Heitmueller3de5bff2012-08-06 22:47:14 -0300233#define XC5000C_FIRMWARE "dvb-fe-xc5000c-4.1.30.7.fw"
Michael Krufky7d3d0d82012-04-16 14:59:32 -0300234static const struct xc5000_fw_cfg xc5000c_41_024_5 = {
Tim Gardner3422f2a62012-07-25 09:15:19 -0300235 .name = XC5000C_FIRMWARE,
Michael Krufky7d3d0d82012-04-16 14:59:32 -0300236 .size = 16497,
Devin Heitmuellerde49bc62012-08-06 22:47:08 -0300237 .pll_reg = 0x13,
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -0300238 .init_status_supported = 1,
239 .fw_checksum_supported = 1,
Michael Krufkyd8398802012-02-07 01:16:27 -0300240};
241
Michael Krufkya3db60b2012-02-08 15:03:07 -0300242static inline const struct xc5000_fw_cfg *xc5000_assign_firmware(int chip_id)
Michael Krufkyddea4272012-02-07 02:39:36 -0300243{
Michael Krufky6fab81d2012-02-08 14:57:39 -0300244 switch (chip_id) {
Michael Krufkyddea4272012-02-07 02:39:36 -0300245 default:
Michael Krufky6fab81d2012-02-08 14:57:39 -0300246 case XC5000A:
Michael Krufkyddea4272012-02-07 02:39:36 -0300247 return &xc5000a_1_6_114;
Michael Krufky6fab81d2012-02-08 14:57:39 -0300248 case XC5000C:
Michael Krufky7d3d0d82012-04-16 14:59:32 -0300249 return &xc5000c_41_024_5;
Michael Krufkyddea4272012-02-07 02:39:36 -0300250 }
251}
252
Devin Heitmuellerde49bc62012-08-06 22:47:08 -0300253static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force);
Devin Heitmueller91bd6252008-11-15 23:29:11 -0300254static int xc5000_is_firmware_loaded(struct dvb_frontend *fe);
Devin Heitmuellerbdd33562008-11-16 20:17:14 -0300255static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val);
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300256static int xc5000_tuner_reset(struct dvb_frontend *fe);
Steven Tothaacb9d32007-12-18 01:55:51 -0300257
Steven Tothe12671c2007-12-20 01:14:43 -0300258static int xc_send_i2c_data(struct xc5000_priv *priv, u8 *buf, int len)
Steven Tothaacb9d32007-12-18 01:55:51 -0300259{
Devin Heitmuellerd7800d42008-11-16 20:20:06 -0300260 struct i2c_msg msg = { .addr = priv->i2c_props.addr,
261 .flags = 0, .buf = buf, .len = len };
262
263 if (i2c_transfer(priv->i2c_props.adap, &msg, 1) != 1) {
264 printk(KERN_ERR "xc5000: I2C write failed (len=%i)\n", len);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300265 return -EREMOTEIO;
Devin Heitmuellerd7800d42008-11-16 20:20:06 -0300266 }
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300267 return 0;
Steven Tothaacb9d32007-12-18 01:55:51 -0300268}
269
Mauro Carvalho Chehab1cdffda2010-07-05 18:38:46 -0300270#if 0
Devin Heitmuellerbdd33562008-11-16 20:17:14 -0300271/* This routine is never used because the only time we read data from the
272 i2c bus is when we read registers, and we want that to be an atomic i2c
273 transaction in case we are on a multi-master bus */
Steven Tothe12671c2007-12-20 01:14:43 -0300274static int xc_read_i2c_data(struct xc5000_priv *priv, u8 *buf, int len)
Steven Tothaacb9d32007-12-18 01:55:51 -0300275{
Devin Heitmuellerbdd33562008-11-16 20:17:14 -0300276 struct i2c_msg msg = { .addr = priv->i2c_props.addr,
277 .flags = I2C_M_RD, .buf = buf, .len = len };
278
279 if (i2c_transfer(priv->i2c_props.adap, &msg, 1) != 1) {
280 printk(KERN_ERR "xc5000 I2C read failed (len=%i)\n", len);
281 return -EREMOTEIO;
282 }
283 return 0;
Steven Tothaacb9d32007-12-18 01:55:51 -0300284}
Mauro Carvalho Chehab1cdffda2010-07-05 18:38:46 -0300285#endif
Steven Tothaacb9d32007-12-18 01:55:51 -0300286
Dmitri Belimov47433192010-05-18 04:30:11 -0300287static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val)
288{
289 u8 buf[2] = { reg >> 8, reg & 0xff };
290 u8 bval[2] = { 0, 0 };
291 struct i2c_msg msg[2] = {
292 { .addr = priv->i2c_props.addr,
293 .flags = 0, .buf = &buf[0], .len = 2 },
294 { .addr = priv->i2c_props.addr,
295 .flags = I2C_M_RD, .buf = &bval[0], .len = 2 },
296 };
297
298 if (i2c_transfer(priv->i2c_props.adap, msg, 2) != 2) {
299 printk(KERN_WARNING "xc5000: I2C read failed\n");
300 return -EREMOTEIO;
301 }
302
303 *val = (bval[0] << 8) | bval[1];
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300304 return 0;
Dmitri Belimov47433192010-05-18 04:30:11 -0300305}
306
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300307static int xc5000_tuner_reset(struct dvb_frontend *fe)
Steven Tothaacb9d32007-12-18 01:55:51 -0300308{
309 struct xc5000_priv *priv = fe->tuner_priv;
310 int ret;
311
Harvey Harrison271ddbf2008-04-08 23:20:00 -0300312 dprintk(1, "%s()\n", __func__);
Steven Tothaacb9d32007-12-18 01:55:51 -0300313
Michael Krufkyd7cba042008-09-12 13:31:45 -0300314 if (fe->callback) {
315 ret = fe->callback(((fe->dvb) && (fe->dvb->priv)) ?
Michael Krufky30650962008-09-06 14:56:58 -0300316 fe->dvb->priv :
317 priv->i2c_props.adap->algo_data,
Michael Krufkyd7cba042008-09-12 13:31:45 -0300318 DVB_FRONTEND_COMPONENT_TUNER,
Michael Krufky30650962008-09-06 14:56:58 -0300319 XC5000_TUNER_RESET, 0);
Devin Heitmueller91bd6252008-11-15 23:29:11 -0300320 if (ret) {
Steven Tothaacb9d32007-12-18 01:55:51 -0300321 printk(KERN_ERR "xc5000: reset failed\n");
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300322 return ret;
Devin Heitmueller91bd6252008-11-15 23:29:11 -0300323 }
324 } else {
Steven Toth27c685a2008-01-05 16:50:14 -0300325 printk(KERN_ERR "xc5000: no tuner reset callback function, fatal\n");
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300326 return -EINVAL;
Devin Heitmueller91bd6252008-11-15 23:29:11 -0300327 }
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300328 return 0;
Steven Tothaacb9d32007-12-18 01:55:51 -0300329}
330
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300331static int xc_write_reg(struct xc5000_priv *priv, u16 reg_addr, u16 i2c_data)
Steven Tothaacb9d32007-12-18 01:55:51 -0300332{
Steven Tothe12671c2007-12-20 01:14:43 -0300333 u8 buf[4];
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300334 int watch_dog_timer = 100;
Steven Tothaacb9d32007-12-18 01:55:51 -0300335 int result;
336
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300337 buf[0] = (reg_addr >> 8) & 0xFF;
338 buf[1] = reg_addr & 0xFF;
339 buf[2] = (i2c_data >> 8) & 0xFF;
340 buf[3] = i2c_data & 0xFF;
Steven Tothaacb9d32007-12-18 01:55:51 -0300341 result = xc_send_i2c_data(priv, buf, 4);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300342 if (result == 0) {
Steven Tothaacb9d32007-12-18 01:55:51 -0300343 /* wait for busy flag to clear */
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300344 while ((watch_dog_timer > 0) && (result == 0)) {
Mauro Carvalho Chehab1cdffda2010-07-05 18:38:46 -0300345 result = xc5000_readreg(priv, XREG_BUSY, (u16 *)buf);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300346 if (result == 0) {
Dmitri Belimov47433192010-05-18 04:30:11 -0300347 if ((buf[0] == 0) && (buf[1] == 0)) {
348 /* busy flag cleared */
Steven Tothaacb9d32007-12-18 01:55:51 -0300349 break;
Dmitri Belimov47433192010-05-18 04:30:11 -0300350 } else {
Mauro Carvalho Chehabe5bf4a12014-05-21 13:15:17 -0300351 msleep(5); /* wait 5 ms */
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300352 watch_dog_timer--;
Steven Tothaacb9d32007-12-18 01:55:51 -0300353 }
354 }
355 }
356 }
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300357 if (watch_dog_timer <= 0)
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300358 result = -EREMOTEIO;
Steven Tothaacb9d32007-12-18 01:55:51 -0300359
360 return result;
361}
362
David Woodhousec63e87e2008-05-24 00:13:34 +0100363static int xc_load_i2c_sequence(struct dvb_frontend *fe, const u8 *i2c_sequence)
Steven Tothaacb9d32007-12-18 01:55:51 -0300364{
365 struct xc5000_priv *priv = fe->tuner_priv;
366
367 int i, nbytes_to_send, result;
368 unsigned int len, pos, index;
Steven Tothe12671c2007-12-20 01:14:43 -0300369 u8 buf[XC_MAX_I2C_WRITE_LENGTH];
Steven Tothaacb9d32007-12-18 01:55:51 -0300370
Steven Toth8f3cd532008-10-16 20:29:38 -0300371 index = 0;
372 while ((i2c_sequence[index] != 0xFF) ||
373 (i2c_sequence[index + 1] != 0xFF)) {
374 len = i2c_sequence[index] * 256 + i2c_sequence[index+1];
Steven Tothe12671c2007-12-20 01:14:43 -0300375 if (len == 0x0000) {
Steven Tothaacb9d32007-12-18 01:55:51 -0300376 /* RESET command */
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300377 result = xc5000_tuner_reset(fe);
Steven Tothaacb9d32007-12-18 01:55:51 -0300378 index += 2;
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300379 if (result != 0)
Steven Tothaacb9d32007-12-18 01:55:51 -0300380 return result;
381 } else if (len & 0x8000) {
382 /* WAIT command */
Mauro Carvalho Chehabe5bf4a12014-05-21 13:15:17 -0300383 msleep(len & 0x7FFF);
Steven Tothaacb9d32007-12-18 01:55:51 -0300384 index += 2;
385 } else {
386 /* Send i2c data whilst ensuring individual transactions
387 * do not exceed XC_MAX_I2C_WRITE_LENGTH bytes.
388 */
389 index += 2;
390 buf[0] = i2c_sequence[index];
391 buf[1] = i2c_sequence[index + 1];
392 pos = 2;
393 while (pos < len) {
Steven Toth8f3cd532008-10-16 20:29:38 -0300394 if ((len - pos) > XC_MAX_I2C_WRITE_LENGTH - 2)
395 nbytes_to_send =
396 XC_MAX_I2C_WRITE_LENGTH;
397 else
Steven Tothaacb9d32007-12-18 01:55:51 -0300398 nbytes_to_send = (len - pos + 2);
Steven Toth8f3cd532008-10-16 20:29:38 -0300399 for (i = 2; i < nbytes_to_send; i++) {
400 buf[i] = i2c_sequence[index + pos +
401 i - 2];
Steven Tothaacb9d32007-12-18 01:55:51 -0300402 }
Steven Toth8f3cd532008-10-16 20:29:38 -0300403 result = xc_send_i2c_data(priv, buf,
404 nbytes_to_send);
Steven Tothaacb9d32007-12-18 01:55:51 -0300405
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300406 if (result != 0)
Steven Tothaacb9d32007-12-18 01:55:51 -0300407 return result;
408
409 pos += nbytes_to_send - 2;
410 }
411 index += len;
412 }
413 }
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300414 return 0;
Steven Tothaacb9d32007-12-18 01:55:51 -0300415}
416
Steven Tothe12671c2007-12-20 01:14:43 -0300417static int xc_initialize(struct xc5000_priv *priv)
Steven Tothaacb9d32007-12-18 01:55:51 -0300418{
Harvey Harrison271ddbf2008-04-08 23:20:00 -0300419 dprintk(1, "%s()\n", __func__);
Steven Tothaacb9d32007-12-18 01:55:51 -0300420 return xc_write_reg(priv, XREG_INIT, 0);
421}
422
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300423static int xc_set_tv_standard(struct xc5000_priv *priv,
424 u16 video_mode, u16 audio_mode, u8 radio_mode)
Steven Tothaacb9d32007-12-18 01:55:51 -0300425{
426 int ret;
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300427 dprintk(1, "%s(0x%04x,0x%04x)\n", __func__, video_mode, audio_mode);
428 if (radio_mode) {
Dmitri Belimov01ae7282013-03-13 00:23:36 -0300429 dprintk(1, "%s() Standard = %s\n",
430 __func__,
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300431 xc5000_standard[radio_mode].name);
Dmitri Belimov01ae7282013-03-13 00:23:36 -0300432 } else {
433 dprintk(1, "%s() Standard = %s\n",
434 __func__,
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300435 xc5000_standard[priv->video_standard].name);
Dmitri Belimov01ae7282013-03-13 00:23:36 -0300436 }
Steven Tothaacb9d32007-12-18 01:55:51 -0300437
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300438 ret = xc_write_reg(priv, XREG_VIDEO_MODE, video_mode);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300439 if (ret == 0)
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300440 ret = xc_write_reg(priv, XREG_AUDIO_MODE, audio_mode);
Steven Tothaacb9d32007-12-18 01:55:51 -0300441
442 return ret;
443}
444
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300445static int xc_set_signal_source(struct xc5000_priv *priv, u16 rf_mode)
Steven Tothaacb9d32007-12-18 01:55:51 -0300446{
Harvey Harrison271ddbf2008-04-08 23:20:00 -0300447 dprintk(1, "%s(%d) Source = %s\n", __func__, rf_mode,
Steven Tothaacb9d32007-12-18 01:55:51 -0300448 rf_mode == XC_RF_MODE_AIR ? "ANTENNA" : "CABLE");
449
Steven Toth8f3cd532008-10-16 20:29:38 -0300450 if ((rf_mode != XC_RF_MODE_AIR) && (rf_mode != XC_RF_MODE_CABLE)) {
Steven Tothaacb9d32007-12-18 01:55:51 -0300451 rf_mode = XC_RF_MODE_CABLE;
452 printk(KERN_ERR
453 "%s(), Invalid mode, defaulting to CABLE",
Harvey Harrison271ddbf2008-04-08 23:20:00 -0300454 __func__);
Steven Tothaacb9d32007-12-18 01:55:51 -0300455 }
456 return xc_write_reg(priv, XREG_SIGNALSOURCE, rf_mode);
457}
458
Steven Tothe12671c2007-12-20 01:14:43 -0300459static const struct dvb_tuner_ops xc5000_tuner_ops;
460
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300461static int xc_set_rf_frequency(struct xc5000_priv *priv, u32 freq_hz)
Steven Tothaacb9d32007-12-18 01:55:51 -0300462{
Steven Tothe12671c2007-12-20 01:14:43 -0300463 u16 freq_code;
Steven Tothaacb9d32007-12-18 01:55:51 -0300464
Harvey Harrison271ddbf2008-04-08 23:20:00 -0300465 dprintk(1, "%s(%u)\n", __func__, freq_hz);
Steven Tothaacb9d32007-12-18 01:55:51 -0300466
Steven Tothe12671c2007-12-20 01:14:43 -0300467 if ((freq_hz > xc5000_tuner_ops.info.frequency_max) ||
468 (freq_hz < xc5000_tuner_ops.info.frequency_min))
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300469 return -EINVAL;
Steven Tothaacb9d32007-12-18 01:55:51 -0300470
Steven Tothe12671c2007-12-20 01:14:43 -0300471 freq_code = (u16)(freq_hz / 15625);
472
Devin Heitmueller81c4dfe2009-04-02 22:40:29 -0300473 /* Starting in firmware version 1.1.44, Xceive recommends using the
474 FINERFREQ for all normal tuning (the doc indicates reg 0x03 should
475 only be used for fast scanning for channel lock) */
476 return xc_write_reg(priv, XREG_FINERFREQ, freq_code);
Steven Tothaacb9d32007-12-18 01:55:51 -0300477}
478
Steven Tothe12671c2007-12-20 01:14:43 -0300479
480static int xc_set_IF_frequency(struct xc5000_priv *priv, u32 freq_khz)
Steven Tothaacb9d32007-12-18 01:55:51 -0300481{
Steven Tothe12671c2007-12-20 01:14:43 -0300482 u32 freq_code = (freq_khz * 1024)/1000;
483 dprintk(1, "%s(freq_khz = %d) freq_code = 0x%x\n",
Harvey Harrison271ddbf2008-04-08 23:20:00 -0300484 __func__, freq_khz, freq_code);
Steven Tothe12671c2007-12-20 01:14:43 -0300485
486 return xc_write_reg(priv, XREG_IF_OUT, freq_code);
Steven Tothaacb9d32007-12-18 01:55:51 -0300487}
488
Steven Tothe12671c2007-12-20 01:14:43 -0300489
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300490static int xc_get_adc_envelope(struct xc5000_priv *priv, u16 *adc_envelope)
Steven Tothaacb9d32007-12-18 01:55:51 -0300491{
Devin Heitmuellerbdd33562008-11-16 20:17:14 -0300492 return xc5000_readreg(priv, XREG_ADC_ENV, adc_envelope);
Steven Tothaacb9d32007-12-18 01:55:51 -0300493}
494
Steven Tothe12671c2007-12-20 01:14:43 -0300495static int xc_get_frequency_error(struct xc5000_priv *priv, u32 *freq_error_hz)
Steven Tothaacb9d32007-12-18 01:55:51 -0300496{
497 int result;
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300498 u16 reg_data;
Steven Tothaacb9d32007-12-18 01:55:51 -0300499 u32 tmp;
500
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300501 result = xc5000_readreg(priv, XREG_FREQ_ERROR, &reg_data);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300502 if (result != 0)
Steven Tothaacb9d32007-12-18 01:55:51 -0300503 return result;
504
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300505 tmp = (u32)reg_data;
Steven Tothe12671c2007-12-20 01:14:43 -0300506 (*freq_error_hz) = (tmp * 15625) / 1000;
Steven Tothaacb9d32007-12-18 01:55:51 -0300507 return result;
508}
509
Steven Tothe12671c2007-12-20 01:14:43 -0300510static int xc_get_lock_status(struct xc5000_priv *priv, u16 *lock_status)
Steven Tothaacb9d32007-12-18 01:55:51 -0300511{
Devin Heitmuellerbdd33562008-11-16 20:17:14 -0300512 return xc5000_readreg(priv, XREG_LOCK, lock_status);
Steven Tothaacb9d32007-12-18 01:55:51 -0300513}
514
Steven Tothe12671c2007-12-20 01:14:43 -0300515static int xc_get_version(struct xc5000_priv *priv,
516 u8 *hw_majorversion, u8 *hw_minorversion,
517 u8 *fw_majorversion, u8 *fw_minorversion)
Steven Tothaacb9d32007-12-18 01:55:51 -0300518{
Steven Tothe12671c2007-12-20 01:14:43 -0300519 u16 data;
Steven Tothaacb9d32007-12-18 01:55:51 -0300520 int result;
521
Devin Heitmuellerbdd33562008-11-16 20:17:14 -0300522 result = xc5000_readreg(priv, XREG_VERSION, &data);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300523 if (result != 0)
Steven Tothaacb9d32007-12-18 01:55:51 -0300524 return result;
525
Steven Tothe12671c2007-12-20 01:14:43 -0300526 (*hw_majorversion) = (data >> 12) & 0x0F;
527 (*hw_minorversion) = (data >> 8) & 0x0F;
528 (*fw_majorversion) = (data >> 4) & 0x0F;
529 (*fw_minorversion) = data & 0x0F;
Steven Tothaacb9d32007-12-18 01:55:51 -0300530
531 return 0;
532}
533
Devin Heitmuellerbae7b7d2009-04-02 22:24:38 -0300534static int xc_get_buildversion(struct xc5000_priv *priv, u16 *buildrev)
535{
536 return xc5000_readreg(priv, XREG_BUILD, buildrev);
537}
538
Steven Tothe12671c2007-12-20 01:14:43 -0300539static int xc_get_hsync_freq(struct xc5000_priv *priv, u32 *hsync_freq_hz)
Steven Tothaacb9d32007-12-18 01:55:51 -0300540{
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300541 u16 reg_data;
Steven Tothaacb9d32007-12-18 01:55:51 -0300542 int result;
543
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300544 result = xc5000_readreg(priv, XREG_HSYNC_FREQ, &reg_data);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300545 if (result != 0)
Steven Tothaacb9d32007-12-18 01:55:51 -0300546 return result;
547
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300548 (*hsync_freq_hz) = ((reg_data & 0x0fff) * 763)/100;
Steven Tothaacb9d32007-12-18 01:55:51 -0300549 return result;
550}
551
Steven Tothe12671c2007-12-20 01:14:43 -0300552static int xc_get_frame_lines(struct xc5000_priv *priv, u16 *frame_lines)
Steven Tothaacb9d32007-12-18 01:55:51 -0300553{
Devin Heitmuellerbdd33562008-11-16 20:17:14 -0300554 return xc5000_readreg(priv, XREG_FRAME_LINES, frame_lines);
Steven Tothaacb9d32007-12-18 01:55:51 -0300555}
556
Steven Tothe12671c2007-12-20 01:14:43 -0300557static int xc_get_quality(struct xc5000_priv *priv, u16 *quality)
Steven Tothaacb9d32007-12-18 01:55:51 -0300558{
Devin Heitmuellerbdd33562008-11-16 20:17:14 -0300559 return xc5000_readreg(priv, XREG_QUALITY, quality);
Steven Tothaacb9d32007-12-18 01:55:51 -0300560}
561
Devin Heitmueller7c287f12012-08-06 22:46:56 -0300562static int xc_get_analogsnr(struct xc5000_priv *priv, u16 *snr)
563{
564 return xc5000_readreg(priv, XREG_SNR, snr);
565}
566
567static int xc_get_totalgain(struct xc5000_priv *priv, u16 *totalgain)
568{
569 return xc5000_readreg(priv, XREG_TOTALGAIN, totalgain);
570}
571
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300572static u16 wait_for_lock(struct xc5000_priv *priv)
Steven Tothaacb9d32007-12-18 01:55:51 -0300573{
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300574 u16 lock_state = 0;
575 int watch_dog_count = 40;
Steven Tothe12671c2007-12-20 01:14:43 -0300576
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300577 while ((lock_state == 0) && (watch_dog_count > 0)) {
578 xc_get_lock_status(priv, &lock_state);
579 if (lock_state != 1) {
Mauro Carvalho Chehabe5bf4a12014-05-21 13:15:17 -0300580 msleep(5);
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300581 watch_dog_count--;
Steven Tothaacb9d32007-12-18 01:55:51 -0300582 }
583 }
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300584 return lock_state;
Steven Tothaacb9d32007-12-18 01:55:51 -0300585}
586
Devin Heitmuellera78baac2008-11-16 20:48:31 -0300587#define XC_TUNE_ANALOG 0
588#define XC_TUNE_DIGITAL 1
589static int xc_tune_channel(struct xc5000_priv *priv, u32 freq_hz, int mode)
Steven Tothaacb9d32007-12-18 01:55:51 -0300590{
591 int found = 0;
592
Harvey Harrison271ddbf2008-04-08 23:20:00 -0300593 dprintk(1, "%s(%u)\n", __func__, freq_hz);
Steven Tothaacb9d32007-12-18 01:55:51 -0300594
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300595 if (xc_set_rf_frequency(priv, freq_hz) != 0)
Steven Tothaacb9d32007-12-18 01:55:51 -0300596 return 0;
597
Devin Heitmuellera78baac2008-11-16 20:48:31 -0300598 if (mode == XC_TUNE_ANALOG) {
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300599 if (wait_for_lock(priv) == 1)
Devin Heitmuellera78baac2008-11-16 20:48:31 -0300600 found = 1;
601 }
Steven Tothaacb9d32007-12-18 01:55:51 -0300602
603 return found;
604}
605
Michael Krufky7d3d0d82012-04-16 14:59:32 -0300606static int xc_set_xtal(struct dvb_frontend *fe)
607{
608 struct xc5000_priv *priv = fe->tuner_priv;
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300609 int ret = 0;
Michael Krufky7d3d0d82012-04-16 14:59:32 -0300610
611 switch (priv->chip_id) {
612 default:
613 case XC5000A:
614 /* 32.000 MHz xtal is default */
615 break;
616 case XC5000C:
617 switch (priv->xtal_khz) {
618 default:
619 case 32000:
620 /* 32.000 MHz xtal is default */
621 break;
622 case 31875:
623 /* 31.875 MHz xtal configuration */
624 ret = xc_write_reg(priv, 0x000f, 0x8081);
625 break;
626 }
627 break;
628 }
629 return ret;
630}
Steven Tothaacb9d32007-12-18 01:55:51 -0300631
Mauro Carvalho Chehab8604f352014-07-30 11:09:15 -0300632static int xc5000_fwupload(struct dvb_frontend *fe,
633 const struct xc5000_fw_cfg *desired_fw,
634 const struct firmware *fw)
Steven Tothaacb9d32007-12-18 01:55:51 -0300635{
636 struct xc5000_priv *priv = fe->tuner_priv;
Steven Tothaacb9d32007-12-18 01:55:51 -0300637 int ret;
Mauro Carvalho Chehab8604f352014-07-30 11:09:15 -0300638
639 /* request the firmware, this will block and timeout */
640 dprintk(1, "waiting for firmware upload (%s)...\n",
641 desired_fw->name);
642
Devin Heitmuellerde49bc62012-08-06 22:47:08 -0300643 priv->pll_register_no = desired_fw->pll_reg;
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -0300644 priv->init_status_supported = desired_fw->init_status_supported;
645 priv->fw_checksum_supported = desired_fw->fw_checksum_supported;
Steven Tothaacb9d32007-12-18 01:55:51 -0300646
Steven Tothe12671c2007-12-20 01:14:43 -0300647
Mauro Carvalho Chehab8604f352014-07-30 11:09:15 -0300648 dprintk(1, "firmware uploading...\n");
649 ret = xc_load_i2c_sequence(fe, fw->data);
650 if (!ret) {
651 ret = xc_set_xtal(fe);
652 dprintk(1, "Firmware upload complete...\n");
653 } else
654 printk(KERN_ERR "xc5000: firmware upload failed...\n");
Steven Tothaacb9d32007-12-18 01:55:51 -0300655
Steven Tothaacb9d32007-12-18 01:55:51 -0300656 return ret;
657}
658
Steven Tothe12671c2007-12-20 01:14:43 -0300659static void xc_debug_dump(struct xc5000_priv *priv)
Steven Tothaacb9d32007-12-18 01:55:51 -0300660{
Steven Tothe12671c2007-12-20 01:14:43 -0300661 u16 adc_envelope;
662 u32 freq_error_hz = 0;
663 u16 lock_status;
664 u32 hsync_freq_hz = 0;
665 u16 frame_lines;
666 u16 quality;
Devin Heitmueller7c287f12012-08-06 22:46:56 -0300667 u16 snr;
668 u16 totalgain;
Steven Tothe12671c2007-12-20 01:14:43 -0300669 u8 hw_majorversion = 0, hw_minorversion = 0;
670 u8 fw_majorversion = 0, fw_minorversion = 0;
Devin Heitmuellerbae7b7d2009-04-02 22:24:38 -0300671 u16 fw_buildversion = 0;
Devin Heitmuellerde49bc62012-08-06 22:47:08 -0300672 u16 regval;
Steven Tothaacb9d32007-12-18 01:55:51 -0300673
674 /* Wait for stats to stabilize.
675 * Frame Lines needs two frame times after initial lock
676 * before it is valid.
677 */
Mauro Carvalho Chehabe5bf4a12014-05-21 13:15:17 -0300678 msleep(100);
Steven Tothaacb9d32007-12-18 01:55:51 -0300679
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300680 xc_get_adc_envelope(priv, &adc_envelope);
Steven Tothe12671c2007-12-20 01:14:43 -0300681 dprintk(1, "*** ADC envelope (0-1023) = %d\n", adc_envelope);
Steven Tothaacb9d32007-12-18 01:55:51 -0300682
Steven Tothe12671c2007-12-20 01:14:43 -0300683 xc_get_frequency_error(priv, &freq_error_hz);
684 dprintk(1, "*** Frequency error = %d Hz\n", freq_error_hz);
Steven Tothaacb9d32007-12-18 01:55:51 -0300685
Steven Tothe12671c2007-12-20 01:14:43 -0300686 xc_get_lock_status(priv, &lock_status);
687 dprintk(1, "*** Lock status (0-Wait, 1-Locked, 2-No-signal) = %d\n",
Steven Tothaacb9d32007-12-18 01:55:51 -0300688 lock_status);
689
690 xc_get_version(priv, &hw_majorversion, &hw_minorversion,
Steven Tothe12671c2007-12-20 01:14:43 -0300691 &fw_majorversion, &fw_minorversion);
Devin Heitmuellerbae7b7d2009-04-02 22:24:38 -0300692 xc_get_buildversion(priv, &fw_buildversion);
Devin Heitmuellerca60a45d2012-08-06 22:47:11 -0300693 dprintk(1, "*** HW: V%d.%d, FW: V %d.%d.%d\n",
Steven Tothaacb9d32007-12-18 01:55:51 -0300694 hw_majorversion, hw_minorversion,
Devin Heitmuellerbae7b7d2009-04-02 22:24:38 -0300695 fw_majorversion, fw_minorversion, fw_buildversion);
Steven Tothaacb9d32007-12-18 01:55:51 -0300696
Steven Tothe12671c2007-12-20 01:14:43 -0300697 xc_get_hsync_freq(priv, &hsync_freq_hz);
698 dprintk(1, "*** Horizontal sync frequency = %d Hz\n", hsync_freq_hz);
Steven Tothaacb9d32007-12-18 01:55:51 -0300699
Steven Tothe12671c2007-12-20 01:14:43 -0300700 xc_get_frame_lines(priv, &frame_lines);
701 dprintk(1, "*** Frame lines = %d\n", frame_lines);
Steven Tothaacb9d32007-12-18 01:55:51 -0300702
Steven Tothe12671c2007-12-20 01:14:43 -0300703 xc_get_quality(priv, &quality);
Devin Heitmueller1aa9c4872012-08-06 22:46:55 -0300704 dprintk(1, "*** Quality (0:<8dB, 7:>56dB) = %d\n", quality & 0x07);
Devin Heitmueller7c287f12012-08-06 22:46:56 -0300705
706 xc_get_analogsnr(priv, &snr);
707 dprintk(1, "*** Unweighted analog SNR = %d dB\n", snr & 0x3f);
708
709 xc_get_totalgain(priv, &totalgain);
710 dprintk(1, "*** Total gain = %d.%d dB\n", totalgain / 256,
711 (totalgain % 256) * 100 / 256);
Devin Heitmuellerde49bc62012-08-06 22:47:08 -0300712
713 if (priv->pll_register_no) {
714 xc5000_readreg(priv, priv->pll_register_no, &regval);
715 dprintk(1, "*** PLL lock status = 0x%04x\n", regval);
716 }
Steven Tothaacb9d32007-12-18 01:55:51 -0300717}
718
Mauro Carvalho Chehab16435202014-08-09 21:47:21 -0300719static int xc5000_tune_digital(struct dvb_frontend *fe)
720{
721 struct xc5000_priv *priv = fe->tuner_priv;
722 int ret;
723 u32 bw = fe->dtv_property_cache.bandwidth_hz;
724
725 ret = xc_set_signal_source(priv, priv->rf_mode);
726 if (ret != 0) {
727 printk(KERN_ERR
728 "xc5000: xc_set_signal_source(%d) failed\n",
729 priv->rf_mode);
730 return -EREMOTEIO;
731 }
732
733 ret = xc_set_tv_standard(priv,
734 xc5000_standard[priv->video_standard].video_mode,
735 xc5000_standard[priv->video_standard].audio_mode, 0);
736 if (ret != 0) {
737 printk(KERN_ERR "xc5000: xc_set_tv_standard failed\n");
738 return -EREMOTEIO;
739 }
740
741 ret = xc_set_IF_frequency(priv, priv->if_khz);
742 if (ret != 0) {
743 printk(KERN_ERR "xc5000: xc_Set_IF_frequency(%d) failed\n",
744 priv->if_khz);
745 return -EIO;
746 }
747
Richard Vollkommer52e269b2014-10-25 17:17:22 -0300748 dprintk(1, "%s() setting OUTPUT_AMP to 0x%x\n",
749 __func__, priv->output_amp);
750 xc_write_reg(priv, XREG_OUTPUT_AMP, priv->output_amp);
Mauro Carvalho Chehab16435202014-08-09 21:47:21 -0300751
752 xc_tune_channel(priv, priv->freq_hz, XC_TUNE_DIGITAL);
753
754 if (debug)
755 xc_debug_dump(priv);
756
757 priv->bandwidth = bw;
758
759 return 0;
760}
761
Mauro Carvalho Chehab59b94f32014-08-09 21:47:24 -0300762static int xc5000_set_digital_params(struct dvb_frontend *fe)
Steven Tothaacb9d32007-12-18 01:55:51 -0300763{
Mauro Carvalho Chehab16435202014-08-09 21:47:21 -0300764 int b;
Steven Tothaacb9d32007-12-18 01:55:51 -0300765 struct xc5000_priv *priv = fe->tuner_priv;
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300766 u32 bw = fe->dtv_property_cache.bandwidth_hz;
767 u32 freq = fe->dtv_property_cache.frequency;
768 u32 delsys = fe->dtv_property_cache.delivery_system;
Steven Tothaacb9d32007-12-18 01:55:51 -0300769
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300770 if (xc_load_fw_and_init_tuner(fe, 0) != 0) {
Devin Heitmuellerfc7a74b2012-08-06 22:47:01 -0300771 dprintk(1, "Unable to load firmware and init tuner\n");
772 return -EINVAL;
Devin Heitmueller760c4662009-10-13 23:44:14 -0300773 }
Devin Heitmueller8e4c6792008-11-16 20:41:07 -0300774
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300775 dprintk(1, "%s() frequency=%d (Hz)\n", __func__, freq);
Steven Tothaacb9d32007-12-18 01:55:51 -0300776
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300777 switch (delsys) {
778 case SYS_ATSC:
779 dprintk(1, "%s() VSB modulation\n", __func__);
780 priv->rf_mode = XC_RF_MODE_AIR;
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -0300781 priv->freq_offset = 1750000;
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300782 priv->video_standard = DTV6;
783 break;
784 case SYS_DVBC_ANNEX_B:
785 dprintk(1, "%s() QAM modulation\n", __func__);
786 priv->rf_mode = XC_RF_MODE_CABLE;
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -0300787 priv->freq_offset = 1750000;
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300788 priv->video_standard = DTV6;
789 break;
Mauro Carvalho Chehab5cf73ce2012-07-05 14:07:59 -0300790 case SYS_ISDBT:
791 /* All ISDB-T are currently for 6 MHz bw */
792 if (!bw)
793 bw = 6000000;
794 /* fall to OFDM handling */
795 case SYS_DMBTH:
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300796 case SYS_DVBT:
797 case SYS_DVBT2:
David T.L. Wong6c990802009-05-04 22:59:58 -0300798 dprintk(1, "%s() OFDM\n", __func__);
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300799 switch (bw) {
800 case 6000000:
David T.L. Wong6c990802009-05-04 22:59:58 -0300801 priv->video_standard = DTV6;
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -0300802 priv->freq_offset = 1750000;
David T.L. Wong6c990802009-05-04 22:59:58 -0300803 break;
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300804 case 7000000:
Mauro Carvalho Chehab0433cd22011-12-09 08:01:01 -0200805 priv->video_standard = DTV7;
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -0300806 priv->freq_offset = 2250000;
Mauro Carvalho Chehab0433cd22011-12-09 08:01:01 -0200807 break;
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300808 case 8000000:
David T.L. Wong6c990802009-05-04 22:59:58 -0300809 priv->video_standard = DTV8;
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -0300810 priv->freq_offset = 2750000;
David T.L. Wong6c990802009-05-04 22:59:58 -0300811 break;
812 default:
813 printk(KERN_ERR "xc5000 bandwidth not set!\n");
814 return -EINVAL;
815 }
Steven Tothaacb9d32007-12-18 01:55:51 -0300816 priv->rf_mode = XC_RF_MODE_AIR;
Dan Carpentercf1364b2013-01-13 15:31:33 -0300817 break;
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300818 case SYS_DVBC_ANNEX_A:
819 case SYS_DVBC_ANNEX_C:
820 dprintk(1, "%s() QAM modulation\n", __func__);
821 priv->rf_mode = XC_RF_MODE_CABLE;
822 if (bw <= 6000000) {
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300823 priv->video_standard = DTV6;
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -0300824 priv->freq_offset = 1750000;
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300825 b = 6;
826 } else if (bw <= 7000000) {
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300827 priv->video_standard = DTV7;
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -0300828 priv->freq_offset = 2250000;
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300829 b = 7;
830 } else {
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300831 priv->video_standard = DTV7_8;
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -0300832 priv->freq_offset = 2750000;
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300833 b = 8;
Igor M. Liplianine80edce2011-01-25 17:03:00 -0300834 }
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300835 dprintk(1, "%s() Bandwidth %dMHz (%d)\n", __func__,
836 b, bw);
837 break;
838 default:
839 printk(KERN_ERR "xc5000: delivery system is not supported!\n");
Steven Tothaacb9d32007-12-18 01:55:51 -0300840 return -EINVAL;
841 }
842
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -0300843 priv->freq_hz = freq - priv->freq_offset;
Mauro Carvalho Chehab16435202014-08-09 21:47:21 -0300844 priv->mode = V4L2_TUNER_DIGITAL_TV;
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -0300845
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300846 dprintk(1, "%s() frequency=%d (compensated to %d)\n",
847 __func__, freq, priv->freq_hz);
Steven Tothaacb9d32007-12-18 01:55:51 -0300848
Mauro Carvalho Chehab16435202014-08-09 21:47:21 -0300849 return xc5000_tune_digital(fe);
Steven Tothaacb9d32007-12-18 01:55:51 -0300850}
851
Steven Tothe470d812008-06-21 21:06:02 -0300852static int xc5000_is_firmware_loaded(struct dvb_frontend *fe)
853{
854 struct xc5000_priv *priv = fe->tuner_priv;
855 int ret;
856 u16 id;
857
858 ret = xc5000_readreg(priv, XREG_PRODUCT_ID, &id);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300859 if (ret == 0) {
Steven Tothe470d812008-06-21 21:06:02 -0300860 if (id == XC_PRODUCT_ID_FW_NOT_LOADED)
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300861 ret = -ENOENT;
Steven Tothe470d812008-06-21 21:06:02 -0300862 else
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300863 ret = 0;
Steven Tothe470d812008-06-21 21:06:02 -0300864 }
865
866 dprintk(1, "%s() returns %s id = 0x%x\n", __func__,
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300867 ret == 0 ? "True" : "False", id);
Steven Tothe470d812008-06-21 21:06:02 -0300868 return ret;
869}
870
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300871static void xc5000_config_tv(struct dvb_frontend *fe,
872 struct analog_parameters *params)
Steven Toth27c685a2008-01-05 16:50:14 -0300873{
874 struct xc5000_priv *priv = fe->tuner_priv;
Steven Toth27c685a2008-01-05 16:50:14 -0300875
Steven Toth27c685a2008-01-05 16:50:14 -0300876 dprintk(1, "%s() frequency=%d (in units of 62.5khz)\n",
Harvey Harrison271ddbf2008-04-08 23:20:00 -0300877 __func__, params->frequency);
Steven Toth27c685a2008-01-05 16:50:14 -0300878
Mauro Carvalho Chehab1fab14e2009-03-03 14:35:41 -0300879 /* Fix me: it could be air. */
880 priv->rf_mode = params->mode;
881 if (params->mode > XC_RF_MODE_CABLE)
882 priv->rf_mode = XC_RF_MODE_CABLE;
Steven Toth27c685a2008-01-05 16:50:14 -0300883
884 /* params->frequency is in units of 62.5khz */
885 priv->freq_hz = params->frequency * 62500;
886
887 /* FIX ME: Some video standards may have several possible audio
888 standards. We simply default to one of them here.
889 */
Steven Toth8f3cd532008-10-16 20:29:38 -0300890 if (params->std & V4L2_STD_MN) {
Steven Toth27c685a2008-01-05 16:50:14 -0300891 /* default to BTSC audio standard */
892 priv->video_standard = MN_NTSC_PAL_BTSC;
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300893 return;
Steven Toth27c685a2008-01-05 16:50:14 -0300894 }
895
Steven Toth8f3cd532008-10-16 20:29:38 -0300896 if (params->std & V4L2_STD_PAL_BG) {
Steven Toth27c685a2008-01-05 16:50:14 -0300897 /* default to NICAM audio standard */
898 priv->video_standard = BG_PAL_NICAM;
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300899 return;
Steven Toth27c685a2008-01-05 16:50:14 -0300900 }
901
Steven Toth8f3cd532008-10-16 20:29:38 -0300902 if (params->std & V4L2_STD_PAL_I) {
Steven Toth27c685a2008-01-05 16:50:14 -0300903 /* default to NICAM audio standard */
904 priv->video_standard = I_PAL_NICAM;
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300905 return;
Steven Toth27c685a2008-01-05 16:50:14 -0300906 }
907
Steven Toth8f3cd532008-10-16 20:29:38 -0300908 if (params->std & V4L2_STD_PAL_DK) {
Steven Toth27c685a2008-01-05 16:50:14 -0300909 /* default to NICAM audio standard */
910 priv->video_standard = DK_PAL_NICAM;
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300911 return;
Steven Toth27c685a2008-01-05 16:50:14 -0300912 }
913
Steven Toth8f3cd532008-10-16 20:29:38 -0300914 if (params->std & V4L2_STD_SECAM_DK) {
Steven Toth27c685a2008-01-05 16:50:14 -0300915 /* default to A2 DK1 audio standard */
916 priv->video_standard = DK_SECAM_A2DK1;
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300917 return;
Steven Toth27c685a2008-01-05 16:50:14 -0300918 }
919
Steven Toth8f3cd532008-10-16 20:29:38 -0300920 if (params->std & V4L2_STD_SECAM_L) {
Steven Toth27c685a2008-01-05 16:50:14 -0300921 priv->video_standard = L_SECAM_NICAM;
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300922 return;
Steven Toth27c685a2008-01-05 16:50:14 -0300923 }
924
Steven Toth8f3cd532008-10-16 20:29:38 -0300925 if (params->std & V4L2_STD_SECAM_LC) {
Steven Toth27c685a2008-01-05 16:50:14 -0300926 priv->video_standard = LC_SECAM_NICAM;
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300927 return;
Steven Toth27c685a2008-01-05 16:50:14 -0300928 }
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300929}
930
931static int xc5000_set_tv_freq(struct dvb_frontend *fe)
932{
933 struct xc5000_priv *priv = fe->tuner_priv;
934 u16 pll_lock_status;
935 int ret;
Steven Toth27c685a2008-01-05 16:50:14 -0300936
937tune_channel:
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300938 ret = xc_set_signal_source(priv, priv->rf_mode);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300939 if (ret != 0) {
Steven Toth8f3cd532008-10-16 20:29:38 -0300940 printk(KERN_ERR
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300941 "xc5000: xc_set_signal_source(%d) failed\n",
Steven Toth27c685a2008-01-05 16:50:14 -0300942 priv->rf_mode);
943 return -EREMOTEIO;
944 }
945
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300946 ret = xc_set_tv_standard(priv,
947 xc5000_standard[priv->video_standard].video_mode,
948 xc5000_standard[priv->video_standard].audio_mode, 0);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300949 if (ret != 0) {
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300950 printk(KERN_ERR "xc5000: xc_set_tv_standard failed\n");
Steven Toth27c685a2008-01-05 16:50:14 -0300951 return -EREMOTEIO;
952 }
953
Dmitri Belimov724dcbf2011-02-01 05:25:19 -0300954 xc_write_reg(priv, XREG_OUTPUT_AMP, 0x09);
955
Devin Heitmuellera78baac2008-11-16 20:48:31 -0300956 xc_tune_channel(priv, priv->freq_hz, XC_TUNE_ANALOG);
Steven Toth27c685a2008-01-05 16:50:14 -0300957
958 if (debug)
959 xc_debug_dump(priv);
960
Devin Heitmuellerde49bc62012-08-06 22:47:08 -0300961 if (priv->pll_register_no != 0) {
962 msleep(20);
963 xc5000_readreg(priv, priv->pll_register_no, &pll_lock_status);
964 if (pll_lock_status > 63) {
965 /* PLL is unlocked, force reload of the firmware */
966 dprintk(1, "xc5000: PLL not locked (0x%x). Reloading...\n",
967 pll_lock_status);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300968 if (xc_load_fw_and_init_tuner(fe, 1) != 0) {
Devin Heitmuellerde49bc62012-08-06 22:47:08 -0300969 printk(KERN_ERR "xc5000: Unable to reload fw\n");
970 return -EREMOTEIO;
971 }
972 goto tune_channel;
973 }
974 }
975
Steven Toth27c685a2008-01-05 16:50:14 -0300976 return 0;
977}
978
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300979static int xc5000_config_radio(struct dvb_frontend *fe,
980 struct analog_parameters *params)
981
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -0300982{
983 struct xc5000_priv *priv = fe->tuner_priv;
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -0300984
985 dprintk(1, "%s() frequency=%d (in units of khz)\n",
986 __func__, params->frequency);
987
Devin Heitmueller496e9052009-09-24 13:27:24 -0300988 if (priv->radio_input == XC5000_RADIO_NOT_CONFIGURED) {
989 dprintk(1, "%s() radio input not configured\n", __func__);
990 return -EINVAL;
991 }
992
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300993 priv->freq_hz = params->frequency * 125 / 2;
994 priv->rf_mode = XC_RF_MODE_AIR;
995
996 return 0;
997}
998
999static int xc5000_set_radio_freq(struct dvb_frontend *fe)
1000{
1001 struct xc5000_priv *priv = fe->tuner_priv;
1002 int ret;
1003 u8 radio_input;
1004
Devin Heitmueller496e9052009-09-24 13:27:24 -03001005 if (priv->radio_input == XC5000_RADIO_FM1)
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -03001006 radio_input = FM_RADIO_INPUT1;
Devin Heitmueller496e9052009-09-24 13:27:24 -03001007 else if (priv->radio_input == XC5000_RADIO_FM2)
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -03001008 radio_input = FM_RADIO_INPUT2;
Dmitri Belimov724dcbf2011-02-01 05:25:19 -03001009 else if (priv->radio_input == XC5000_RADIO_FM1_MONO)
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -03001010 radio_input = FM_RADIO_INPUT1_MONO;
Devin Heitmueller496e9052009-09-24 13:27:24 -03001011 else {
1012 dprintk(1, "%s() unknown radio input %d\n", __func__,
1013 priv->radio_input);
1014 return -EINVAL;
1015 }
1016
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -03001017 ret = xc_set_tv_standard(priv, xc5000_standard[radio_input].video_mode,
1018 xc5000_standard[radio_input].audio_mode, radio_input);
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -03001019
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -03001020 if (ret != 0) {
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -03001021 printk(KERN_ERR "xc5000: xc_set_tv_standard failed\n");
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -03001022 return -EREMOTEIO;
1023 }
1024
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -03001025 ret = xc_set_signal_source(priv, priv->rf_mode);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -03001026 if (ret != 0) {
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -03001027 printk(KERN_ERR
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -03001028 "xc5000: xc_set_signal_source(%d) failed\n",
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -03001029 priv->rf_mode);
1030 return -EREMOTEIO;
1031 }
1032
Dmitri Belimov724dcbf2011-02-01 05:25:19 -03001033 if ((priv->radio_input == XC5000_RADIO_FM1) ||
1034 (priv->radio_input == XC5000_RADIO_FM2))
1035 xc_write_reg(priv, XREG_OUTPUT_AMP, 0x09);
1036 else if (priv->radio_input == XC5000_RADIO_FM1_MONO)
1037 xc_write_reg(priv, XREG_OUTPUT_AMP, 0x06);
1038
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -03001039 xc_tune_channel(priv, priv->freq_hz, XC_TUNE_ANALOG);
1040
1041 return 0;
1042}
1043
Mauro Carvalho Chehab59b94f32014-08-09 21:47:24 -03001044static int xc5000_set_params(struct dvb_frontend *fe)
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -03001045{
1046 struct xc5000_priv *priv = fe->tuner_priv;
1047
Mauro Carvalho Chehab5275a3b2014-08-09 23:14:22 -03001048 if (xc_load_fw_and_init_tuner(fe, 0) != 0) {
1049 dprintk(1, "Unable to load firmware and init tuner\n");
1050 return -EINVAL;
1051 }
1052
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -03001053 switch (priv->mode) {
1054 case V4L2_TUNER_RADIO:
1055 return xc5000_set_radio_freq(fe);
1056 case V4L2_TUNER_ANALOG_TV:
1057 return xc5000_set_tv_freq(fe);
1058 case V4L2_TUNER_DIGITAL_TV:
1059 return xc5000_tune_digital(fe);
1060 }
1061
1062 return 0;
1063}
1064
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -03001065static int xc5000_set_analog_params(struct dvb_frontend *fe,
1066 struct analog_parameters *params)
1067{
1068 struct xc5000_priv *priv = fe->tuner_priv;
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -03001069 int ret;
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -03001070
1071 if (priv->i2c_props.adap == NULL)
1072 return -EINVAL;
1073
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -03001074 switch (params->mode) {
1075 case V4L2_TUNER_RADIO:
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -03001076 ret = xc5000_config_radio(fe, params);
1077 if (ret)
1078 return ret;
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -03001079 break;
1080 case V4L2_TUNER_ANALOG_TV:
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -03001081 xc5000_config_tv(fe, params);
1082 break;
1083 default:
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -03001084 break;
1085 }
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -03001086 priv->mode = params->mode;
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -03001087
Mauro Carvalho Chehab59b94f32014-08-09 21:47:24 -03001088 return xc5000_set_params(fe);
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -03001089}
1090
Steven Tothaacb9d32007-12-18 01:55:51 -03001091static int xc5000_get_frequency(struct dvb_frontend *fe, u32 *freq)
1092{
1093 struct xc5000_priv *priv = fe->tuner_priv;
Harvey Harrison271ddbf2008-04-08 23:20:00 -03001094 dprintk(1, "%s()\n", __func__);
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -03001095 *freq = priv->freq_hz + priv->freq_offset;
Steven Tothaacb9d32007-12-18 01:55:51 -03001096 return 0;
1097}
1098
Mauro Carvalho Chehab35621032011-09-23 13:03:42 -03001099static int xc5000_get_if_frequency(struct dvb_frontend *fe, u32 *freq)
1100{
1101 struct xc5000_priv *priv = fe->tuner_priv;
1102 dprintk(1, "%s()\n", __func__);
1103 *freq = priv->if_khz * 1000;
1104 return 0;
1105}
1106
Steven Tothaacb9d32007-12-18 01:55:51 -03001107static int xc5000_get_bandwidth(struct dvb_frontend *fe, u32 *bw)
1108{
1109 struct xc5000_priv *priv = fe->tuner_priv;
Harvey Harrison271ddbf2008-04-08 23:20:00 -03001110 dprintk(1, "%s()\n", __func__);
Steven Toth27c685a2008-01-05 16:50:14 -03001111
Steven Tothaacb9d32007-12-18 01:55:51 -03001112 *bw = priv->bandwidth;
1113 return 0;
1114}
1115
1116static int xc5000_get_status(struct dvb_frontend *fe, u32 *status)
1117{
1118 struct xc5000_priv *priv = fe->tuner_priv;
Steven Tothe12671c2007-12-20 01:14:43 -03001119 u16 lock_status = 0;
Steven Tothaacb9d32007-12-18 01:55:51 -03001120
1121 xc_get_lock_status(priv, &lock_status);
1122
Harvey Harrison271ddbf2008-04-08 23:20:00 -03001123 dprintk(1, "%s() lock_status = 0x%08x\n", __func__, lock_status);
Steven Tothaacb9d32007-12-18 01:55:51 -03001124
1125 *status = lock_status;
1126
1127 return 0;
1128}
1129
Devin Heitmuellerde49bc62012-08-06 22:47:08 -03001130static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force)
Steven Tothaacb9d32007-12-18 01:55:51 -03001131{
1132 struct xc5000_priv *priv = fe->tuner_priv;
Mauro Carvalho Chehab8604f352014-07-30 11:09:15 -03001133 const struct xc5000_fw_cfg *desired_fw = xc5000_assign_firmware(priv->chip_id);
1134 const struct firmware *fw;
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001135 int ret, i;
Devin Heitmuellerde49bc62012-08-06 22:47:08 -03001136 u16 pll_lock_status;
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -03001137 u16 fw_ck;
Steven Tothaacb9d32007-12-18 01:55:51 -03001138
Mauro Carvalho Chehabf7a27ff2014-05-21 13:57:30 -03001139 cancel_delayed_work(&priv->timer_sleep);
1140
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001141 if (!force && xc5000_is_firmware_loaded(fe) == 0)
1142 return 0;
Devin Heitmuellerde49bc62012-08-06 22:47:08 -03001143
Shuah Khan5264a522014-09-22 21:30:46 -03001144 if (!priv->firmware) {
1145 ret = request_firmware(&fw, desired_fw->name,
1146 priv->i2c_props.adap->dev.parent);
1147 if (ret) {
1148 pr_err("xc5000: Upload failed. rc %d\n", ret);
1149 return ret;
1150 }
1151 dprintk(1, "firmware read %Zu bytes.\n", fw->size);
Mauro Carvalho Chehab8604f352014-07-30 11:09:15 -03001152
Shuah Khan5264a522014-09-22 21:30:46 -03001153 if (fw->size != desired_fw->size) {
1154 pr_err("xc5000: Firmware file with incorrect size\n");
1155 release_firmware(fw);
1156 return -EINVAL;
1157 }
1158 priv->firmware = fw;
1159 } else
1160 fw = priv->firmware;
Mauro Carvalho Chehab8604f352014-07-30 11:09:15 -03001161
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001162 /* Try up to 5 times to load firmware */
1163 for (i = 0; i < 5; i++) {
Mauro Carvalho Chehabee676742014-07-30 11:17:46 -03001164 if (i)
1165 printk(KERN_CONT " - retrying to upload firmware.\n");
1166
Mauro Carvalho Chehab8604f352014-07-30 11:09:15 -03001167 ret = xc5000_fwupload(fe, desired_fw, fw);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -03001168 if (ret != 0)
Mauro Carvalho Chehab8604f352014-07-30 11:09:15 -03001169 goto err;
Devin Heitmuellerfc7a74b2012-08-06 22:47:01 -03001170
Devin Heitmuellerde49bc62012-08-06 22:47:08 -03001171 msleep(20);
1172
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -03001173 if (priv->fw_checksum_supported) {
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001174 if (xc5000_readreg(priv, XREG_FW_CHECKSUM, &fw_ck)) {
Mauro Carvalho Chehabee676742014-07-30 11:17:46 -03001175 printk(KERN_ERR
1176 "xc5000: FW checksum reading failed.");
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001177 continue;
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -03001178 }
1179
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001180 if (!fw_ck) {
Mauro Carvalho Chehabee676742014-07-30 11:17:46 -03001181 printk(KERN_ERR
1182 "xc5000: FW checksum failed = 0x%04x.",
1183 fw_ck);
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001184 continue;
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -03001185 }
1186 }
1187
Devin Heitmuellerfc7a74b2012-08-06 22:47:01 -03001188 /* Start the tuner self-calibration process */
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001189 ret = xc_initialize(priv);
1190 if (ret) {
Mauro Carvalho Chehabee676742014-07-30 11:17:46 -03001191 printk(KERN_ERR
1192 "xc5000: Can't request Self-callibration.");
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001193 continue;
1194 }
Devin Heitmuellerde49bc62012-08-06 22:47:08 -03001195
Devin Heitmuellerfc7a74b2012-08-06 22:47:01 -03001196 /* Wait for calibration to complete.
1197 * We could continue but XC5000 will clock stretch subsequent
1198 * I2C transactions until calibration is complete. This way we
1199 * don't have to rely on clock stretching working.
1200 */
Mauro Carvalho Chehabe5bf4a12014-05-21 13:15:17 -03001201 msleep(100);
Devin Heitmuellerfc7a74b2012-08-06 22:47:01 -03001202
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -03001203 if (priv->init_status_supported) {
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001204 if (xc5000_readreg(priv, XREG_INIT_STATUS, &fw_ck)) {
Mauro Carvalho Chehabee676742014-07-30 11:17:46 -03001205 printk(KERN_ERR
1206 "xc5000: FW failed reading init status.");
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001207 continue;
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -03001208 }
1209
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001210 if (!fw_ck) {
Mauro Carvalho Chehabee676742014-07-30 11:17:46 -03001211 printk(KERN_ERR
1212 "xc5000: FW init status failed = 0x%04x.",
1213 fw_ck);
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001214 continue;
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -03001215 }
1216 }
1217
Devin Heitmuellerde49bc62012-08-06 22:47:08 -03001218 if (priv->pll_register_no) {
1219 xc5000_readreg(priv, priv->pll_register_no,
1220 &pll_lock_status);
1221 if (pll_lock_status > 63) {
1222 /* PLL is unlocked, force reload of the firmware */
Mauro Carvalho Chehabee676742014-07-30 11:17:46 -03001223 printk(KERN_ERR
1224 "xc5000: PLL not running after fwload.");
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001225 continue;
Devin Heitmuellerde49bc62012-08-06 22:47:08 -03001226 }
1227 }
1228
Devin Heitmuellerfc7a74b2012-08-06 22:47:01 -03001229 /* Default to "CABLE" mode */
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001230 ret = xc_write_reg(priv, XREG_SIGNALSOURCE, XC_RF_MODE_CABLE);
Mauro Carvalho Chehabee676742014-07-30 11:17:46 -03001231 if (!ret)
1232 break;
1233 printk(KERN_ERR "xc5000: can't set to cable mode.");
Steven Tothaacb9d32007-12-18 01:55:51 -03001234 }
1235
Mauro Carvalho Chehab8604f352014-07-30 11:09:15 -03001236err:
Mauro Carvalho Chehabee676742014-07-30 11:17:46 -03001237 if (!ret)
1238 printk(KERN_INFO "xc5000: Firmware %s loaded and running.\n",
1239 desired_fw->name);
1240 else
1241 printk(KERN_CONT " - too many retries. Giving up\n");
1242
Steven Tothaacb9d32007-12-18 01:55:51 -03001243 return ret;
1244}
1245
Mauro Carvalho Chehabf7a27ff2014-05-21 13:57:30 -03001246static void xc5000_do_timer_sleep(struct work_struct *timer_sleep)
1247{
1248 struct xc5000_priv *priv =container_of(timer_sleep, struct xc5000_priv,
1249 timer_sleep.work);
1250 struct dvb_frontend *fe = priv->fe;
1251 int ret;
1252
1253 dprintk(1, "%s()\n", __func__);
1254
1255 /* According to Xceive technical support, the "powerdown" register
1256 was removed in newer versions of the firmware. The "supported"
1257 way to sleep the tuner is to pull the reset pin low for 10ms */
1258 ret = xc5000_tuner_reset(fe);
1259 if (ret != 0)
1260 printk(KERN_ERR
1261 "xc5000: %s() unable to shutdown tuner\n",
1262 __func__);
1263}
1264
Steven Tothe12671c2007-12-20 01:14:43 -03001265static int xc5000_sleep(struct dvb_frontend *fe)
1266{
Mauro Carvalho Chehabf7a27ff2014-05-21 13:57:30 -03001267 struct xc5000_priv *priv = fe->tuner_priv;
Steven Toth27c685a2008-01-05 16:50:14 -03001268
Harvey Harrison271ddbf2008-04-08 23:20:00 -03001269 dprintk(1, "%s()\n", __func__);
Steven Tothe12671c2007-12-20 01:14:43 -03001270
Devin Heitmuellerb6bd5eb2009-04-28 13:53:38 -03001271 /* Avoid firmware reload on slow devices */
1272 if (no_poweroff)
1273 return 0;
1274
Mauro Carvalho Chehabf7a27ff2014-05-21 13:57:30 -03001275 schedule_delayed_work(&priv->timer_sleep,
1276 msecs_to_jiffies(XC5000_SLEEP_TIME));
1277
1278 return 0;
Steven Tothe12671c2007-12-20 01:14:43 -03001279}
1280
Mauro Carvalho Chehab91a53072014-08-09 21:47:20 -03001281static int xc5000_suspend(struct dvb_frontend *fe)
1282{
1283 struct xc5000_priv *priv = fe->tuner_priv;
1284 int ret;
1285
1286 dprintk(1, "%s()\n", __func__);
1287
1288 cancel_delayed_work(&priv->timer_sleep);
1289
1290 ret = xc5000_tuner_reset(fe);
1291 if (ret != 0)
1292 printk(KERN_ERR
1293 "xc5000: %s() unable to shutdown tuner\n",
1294 __func__);
1295
1296 return 0;
1297}
1298
Shuah Khan27ccd692014-08-13 22:09:24 -03001299static int xc5000_resume(struct dvb_frontend *fe)
1300{
1301 struct xc5000_priv *priv = fe->tuner_priv;
1302
1303 dprintk(1, "%s()\n", __func__);
1304
1305 /* suspended before firmware is loaded.
1306 Avoid firmware load in resume path. */
1307 if (!priv->firmware)
1308 return 0;
1309
1310 return xc5000_set_params(fe);
1311}
1312
Steven Tothaacb9d32007-12-18 01:55:51 -03001313static int xc5000_init(struct dvb_frontend *fe)
1314{
1315 struct xc5000_priv *priv = fe->tuner_priv;
Harvey Harrison271ddbf2008-04-08 23:20:00 -03001316 dprintk(1, "%s()\n", __func__);
Steven Tothaacb9d32007-12-18 01:55:51 -03001317
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -03001318 if (xc_load_fw_and_init_tuner(fe, 0) != 0) {
Steven Tothe12671c2007-12-20 01:14:43 -03001319 printk(KERN_ERR "xc5000: Unable to initialise tuner\n");
1320 return -EREMOTEIO;
1321 }
1322
1323 if (debug)
1324 xc_debug_dump(priv);
Steven Tothaacb9d32007-12-18 01:55:51 -03001325
1326 return 0;
1327}
1328
1329static int xc5000_release(struct dvb_frontend *fe)
1330{
Michael Krufky89fd2852008-09-06 11:44:53 -03001331 struct xc5000_priv *priv = fe->tuner_priv;
1332
Harvey Harrison271ddbf2008-04-08 23:20:00 -03001333 dprintk(1, "%s()\n", __func__);
Michael Krufky89fd2852008-09-06 11:44:53 -03001334
1335 mutex_lock(&xc5000_list_mutex);
1336
Mauro Carvalho Chehabf7a27ff2014-05-21 13:57:30 -03001337 if (priv) {
1338 cancel_delayed_work(&priv->timer_sleep);
Markus Elfringdc89cfc2014-11-30 15:05:48 -03001339 release_firmware(priv->firmware);
Dan Carpenter4961a532014-09-25 08:40:08 -03001340 hybrid_tuner_release_state(priv);
Mauro Carvalho Chehabf7a27ff2014-05-21 13:57:30 -03001341 }
Michael Krufky89fd2852008-09-06 11:44:53 -03001342
1343 mutex_unlock(&xc5000_list_mutex);
1344
Steven Tothaacb9d32007-12-18 01:55:51 -03001345 fe->tuner_priv = NULL;
Michael Krufky89fd2852008-09-06 11:44:53 -03001346
Steven Tothaacb9d32007-12-18 01:55:51 -03001347 return 0;
1348}
1349
Dmitri Belimov724dcbf2011-02-01 05:25:19 -03001350static int xc5000_set_config(struct dvb_frontend *fe, void *priv_cfg)
1351{
1352 struct xc5000_priv *priv = fe->tuner_priv;
1353 struct xc5000_config *p = priv_cfg;
1354
1355 dprintk(1, "%s()\n", __func__);
1356
1357 if (p->if_khz)
1358 priv->if_khz = p->if_khz;
1359
1360 if (p->radio_input)
1361 priv->radio_input = p->radio_input;
1362
Richard Vollkommer52e269b2014-10-25 17:17:22 -03001363 if (p->output_amp)
1364 priv->output_amp = p->output_amp;
1365
Dmitri Belimov724dcbf2011-02-01 05:25:19 -03001366 return 0;
1367}
1368
1369
Steven Tothaacb9d32007-12-18 01:55:51 -03001370static const struct dvb_tuner_ops xc5000_tuner_ops = {
1371 .info = {
1372 .name = "Xceive XC5000",
1373 .frequency_min = 1000000,
1374 .frequency_max = 1023000000,
1375 .frequency_step = 50000,
1376 },
1377
Steven Toth27c685a2008-01-05 16:50:14 -03001378 .release = xc5000_release,
1379 .init = xc5000_init,
1380 .sleep = xc5000_sleep,
Mauro Carvalho Chehab91a53072014-08-09 21:47:20 -03001381 .suspend = xc5000_suspend,
Shuah Khan27ccd692014-08-13 22:09:24 -03001382 .resume = xc5000_resume,
Steven Tothaacb9d32007-12-18 01:55:51 -03001383
Dmitri Belimov724dcbf2011-02-01 05:25:19 -03001384 .set_config = xc5000_set_config,
Mauro Carvalho Chehab59b94f32014-08-09 21:47:24 -03001385 .set_params = xc5000_set_digital_params,
Steven Toth27c685a2008-01-05 16:50:14 -03001386 .set_analog_params = xc5000_set_analog_params,
1387 .get_frequency = xc5000_get_frequency,
Mauro Carvalho Chehab35621032011-09-23 13:03:42 -03001388 .get_if_frequency = xc5000_get_if_frequency,
Steven Toth27c685a2008-01-05 16:50:14 -03001389 .get_bandwidth = xc5000_get_bandwidth,
1390 .get_status = xc5000_get_status
Steven Tothaacb9d32007-12-18 01:55:51 -03001391};
1392
Michael Krufky48723542008-05-10 14:34:09 -03001393struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe,
1394 struct i2c_adapter *i2c,
lawrence rust2e4e98e2010-08-25 09:50:20 -03001395 const struct xc5000_config *cfg)
Steven Tothaacb9d32007-12-18 01:55:51 -03001396{
1397 struct xc5000_priv *priv = NULL;
Michael Krufky89fd2852008-09-06 11:44:53 -03001398 int instance;
Steven Tothaacb9d32007-12-18 01:55:51 -03001399 u16 id = 0;
1400
Michael Krufky89fd2852008-09-06 11:44:53 -03001401 dprintk(1, "%s(%d-%04x)\n", __func__,
1402 i2c ? i2c_adapter_id(i2c) : -1,
1403 cfg ? cfg->i2c_address : -1);
Steven Tothaacb9d32007-12-18 01:55:51 -03001404
Michael Krufky89fd2852008-09-06 11:44:53 -03001405 mutex_lock(&xc5000_list_mutex);
Steven Tothaacb9d32007-12-18 01:55:51 -03001406
Michael Krufky89fd2852008-09-06 11:44:53 -03001407 instance = hybrid_tuner_request_state(struct xc5000_priv, priv,
1408 hybrid_tuner_instance_list,
1409 i2c, cfg->i2c_address, "xc5000");
1410 switch (instance) {
1411 case 0:
1412 goto fail;
Michael Krufky89fd2852008-09-06 11:44:53 -03001413 case 1:
1414 /* new tuner instance */
Mauro Carvalho Chehabc6f56e72011-12-26 20:02:28 -03001415 priv->bandwidth = 6000000;
Michael Krufky89fd2852008-09-06 11:44:53 -03001416 fe->tuner_priv = priv;
Mauro Carvalho Chehabf7a27ff2014-05-21 13:57:30 -03001417 priv->fe = fe;
1418 INIT_DELAYED_WORK(&priv->timer_sleep, xc5000_do_timer_sleep);
Michael Krufky89fd2852008-09-06 11:44:53 -03001419 break;
1420 default:
1421 /* existing tuner instance */
1422 fe->tuner_priv = priv;
1423 break;
1424 }
Steven Tothaacb9d32007-12-18 01:55:51 -03001425
Devin Heitmuellerea227862009-03-11 02:58:53 -03001426 if (priv->if_khz == 0) {
1427 /* If the IF hasn't been set yet, use the value provided by
1428 the caller (occurs in hybrid devices where the analog
1429 call to xc5000_attach occurs before the digital side) */
1430 priv->if_khz = cfg->if_khz;
1431 }
1432
Michael Krufky7d3d0d82012-04-16 14:59:32 -03001433 if (priv->xtal_khz == 0)
1434 priv->xtal_khz = cfg->xtal_khz;
1435
Devin Heitmueller496e9052009-09-24 13:27:24 -03001436 if (priv->radio_input == 0)
1437 priv->radio_input = cfg->radio_input;
1438
Michael Krufky6fab81d2012-02-08 14:57:39 -03001439 /* don't override chip id if it's already been set
Michael Krufky76efb0ba2012-02-06 19:40:32 -03001440 unless explicitly specified */
Michael Krufky6fab81d2012-02-08 14:57:39 -03001441 if ((priv->chip_id == 0) || (cfg->chip_id))
1442 /* use default chip id if none specified, set to 0 so
1443 it can be overridden if this is a hybrid driver */
1444 priv->chip_id = (cfg->chip_id) ? cfg->chip_id : 0;
Michael Krufky76efb0ba2012-02-06 19:40:32 -03001445
Richard Vollkommer52e269b2014-10-25 17:17:22 -03001446 /* don't override output_amp if it's already been set
1447 unless explicitly specified */
1448 if ((priv->output_amp == 0) || (cfg->output_amp))
1449 /* use default output_amp value if none specified */
1450 priv->output_amp = (cfg->output_amp) ? cfg->output_amp : 0x8a;
1451
Steven Toth27c685a2008-01-05 16:50:14 -03001452 /* Check if firmware has been loaded. It is possible that another
1453 instance of the driver has loaded the firmware.
1454 */
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -03001455 if (xc5000_readreg(priv, XREG_PRODUCT_ID, &id) != 0)
Michael Krufky89fd2852008-09-06 11:44:53 -03001456 goto fail;
Steven Tothaacb9d32007-12-18 01:55:51 -03001457
Steven Toth8f3cd532008-10-16 20:29:38 -03001458 switch (id) {
Steven Toth27c685a2008-01-05 16:50:14 -03001459 case XC_PRODUCT_ID_FW_LOADED:
1460 printk(KERN_INFO
1461 "xc5000: Successfully identified at address 0x%02x\n",
1462 cfg->i2c_address);
1463 printk(KERN_INFO
1464 "xc5000: Firmware has been loaded previously\n");
Steven Toth27c685a2008-01-05 16:50:14 -03001465 break;
1466 case XC_PRODUCT_ID_FW_NOT_LOADED:
1467 printk(KERN_INFO
1468 "xc5000: Successfully identified at address 0x%02x\n",
1469 cfg->i2c_address);
1470 printk(KERN_INFO
1471 "xc5000: Firmware has not been loaded previously\n");
Steven Toth27c685a2008-01-05 16:50:14 -03001472 break;
1473 default:
Steven Tothaacb9d32007-12-18 01:55:51 -03001474 printk(KERN_ERR
1475 "xc5000: Device not found at addr 0x%02x (0x%x)\n",
1476 cfg->i2c_address, id);
Michael Krufky89fd2852008-09-06 11:44:53 -03001477 goto fail;
Steven Tothaacb9d32007-12-18 01:55:51 -03001478 }
1479
Michael Krufky89fd2852008-09-06 11:44:53 -03001480 mutex_unlock(&xc5000_list_mutex);
1481
Steven Tothaacb9d32007-12-18 01:55:51 -03001482 memcpy(&fe->ops.tuner_ops, &xc5000_tuner_ops,
1483 sizeof(struct dvb_tuner_ops));
1484
Steven Tothaacb9d32007-12-18 01:55:51 -03001485 return fe;
Michael Krufky89fd2852008-09-06 11:44:53 -03001486fail:
1487 mutex_unlock(&xc5000_list_mutex);
1488
1489 xc5000_release(fe);
1490 return NULL;
Steven Tothaacb9d32007-12-18 01:55:51 -03001491}
1492EXPORT_SYMBOL(xc5000_attach);
1493
1494MODULE_AUTHOR("Steven Toth");
Steven Tothe12671c2007-12-20 01:14:43 -03001495MODULE_DESCRIPTION("Xceive xc5000 silicon tuner driver");
Steven Tothaacb9d32007-12-18 01:55:51 -03001496MODULE_LICENSE("GPL");
Tim Gardner3422f2a62012-07-25 09:15:19 -03001497MODULE_FIRMWARE(XC5000A_FIRMWARE);
1498MODULE_FIRMWARE(XC5000C_FIRMWARE);