blob: 734a92caad8d0a2a626f78af4106cdc5c98490d6 [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Steven Tothaacb9d32007-12-18 01:55:51 -03002/*
3 * Driver for Xceive XC5000 "QAM/8VSB single chip tuner"
4 *
5 * Copyright (c) 2007 Xceive Corporation
Steven Toth6d897612008-09-03 17:12:12 -03006 * Copyright (c) 2007 Steven Toth <stoth@linuxtv.org>
Devin Heitmuellere80858e2009-05-14 21:31:11 -03007 * Copyright (c) 2009 Devin Heitmueller <dheitmueller@kernellabs.com>
Steven Tothaacb9d32007-12-18 01:55:51 -03008 */
9
10#include <linux/module.h>
11#include <linux/moduleparam.h>
Steven Toth49170192008-01-15 21:57:14 -030012#include <linux/videodev2.h>
Steven Tothaacb9d32007-12-18 01:55:51 -030013#include <linux/delay.h>
Mauro Carvalho Chehabf7a27ff2014-05-21 13:57:30 -030014#include <linux/workqueue.h>
Steven Tothaacb9d32007-12-18 01:55:51 -030015#include <linux/dvb/frontend.h>
16#include <linux/i2c.h>
17
Mauro Carvalho Chehabfada1932017-12-28 13:03:51 -050018#include <media/dvb_frontend.h>
Steven Tothaacb9d32007-12-18 01:55:51 -030019
20#include "xc5000.h"
Michael Krufky89fd2852008-09-06 11:44:53 -030021#include "tuner-i2c.h"
Steven Tothaacb9d32007-12-18 01:55:51 -030022
23static int debug;
24module_param(debug, int, 0644);
25MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
26
Devin Heitmuellerb6bd5eb2009-04-28 13:53:38 -030027static int no_poweroff;
28module_param(no_poweroff, int, 0644);
29MODULE_PARM_DESC(no_poweroff, "0 (default) powers device off when not used.\n"
30 "\t\t1 keep device energized and with tuner ready all the times.\n"
31 "\t\tFaster, but consumes more power and keeps the device hotter");
32
Michael Krufky89fd2852008-09-06 11:44:53 -030033static DEFINE_MUTEX(xc5000_list_mutex);
34static LIST_HEAD(hybrid_tuner_instance_list);
35
Steven Toth8f3cd532008-10-16 20:29:38 -030036#define dprintk(level, fmt, arg...) if (debug >= level) \
Steven Tothaacb9d32007-12-18 01:55:51 -030037 printk(KERN_INFO "%s: " fmt, "xc5000", ## arg)
38
Michael Krufkyffb41232008-09-06 10:52:30 -030039struct xc5000_priv {
Michael Krufky89fd2852008-09-06 11:44:53 -030040 struct tuner_i2c_props i2c_props;
41 struct list_head hybrid_tuner_instance_list;
Michael Krufkyffb41232008-09-06 10:52:30 -030042
Michael Krufky2a6003c2008-09-06 13:54:45 -030043 u32 if_khz;
Michael Krufky409328a42012-04-16 15:21:51 -030044 u16 xtal_khz;
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -030045 u32 freq_hz, freq_offset;
Michael Krufkyffb41232008-09-06 10:52:30 -030046 u32 bandwidth;
47 u8 video_standard;
Mauro Carvalho Chehab16435202014-08-09 21:47:21 -030048 unsigned int mode;
Michael Krufkyffb41232008-09-06 10:52:30 -030049 u8 rf_mode;
Devin Heitmueller496e9052009-09-24 13:27:24 -030050 u8 radio_input;
Richard Vollkommer52e269b2014-10-25 17:17:22 -030051 u16 output_amp;
Michael Krufky76efb0ba2012-02-06 19:40:32 -030052
Michael Krufky6fab81d2012-02-08 14:57:39 -030053 int chip_id;
Devin Heitmuellerde49bc62012-08-06 22:47:08 -030054 u16 pll_register_no;
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -030055 u8 init_status_supported;
56 u8 fw_checksum_supported;
Mauro Carvalho Chehabf7a27ff2014-05-21 13:57:30 -030057
58 struct dvb_frontend *fe;
59 struct delayed_work timer_sleep;
Shuah Khan5264a522014-09-22 21:30:46 -030060
61 const struct firmware *firmware;
Michael Krufkyffb41232008-09-06 10:52:30 -030062};
63
Steven Tothaacb9d32007-12-18 01:55:51 -030064/* Misc Defines */
Dmitri Belimov724dcbf2011-02-01 05:25:19 -030065#define MAX_TV_STANDARD 24
Steven Tothaacb9d32007-12-18 01:55:51 -030066#define XC_MAX_I2C_WRITE_LENGTH 64
67
Mauro Carvalho Chehabf7a27ff2014-05-21 13:57:30 -030068/* Time to suspend after the .sleep callback is called */
69#define XC5000_SLEEP_TIME 5000 /* ms */
70
Steven Tothaacb9d32007-12-18 01:55:51 -030071/* Signal Types */
72#define XC_RF_MODE_AIR 0
73#define XC_RF_MODE_CABLE 1
74
Steven Toth27c685a2008-01-05 16:50:14 -030075/* Product id */
76#define XC_PRODUCT_ID_FW_NOT_LOADED 0x2000
Mauro Carvalho Chehab5015c272014-05-21 13:41:01 -030077#define XC_PRODUCT_ID_FW_LOADED 0x1388
Steven Toth27c685a2008-01-05 16:50:14 -030078
Steven Tothaacb9d32007-12-18 01:55:51 -030079/* Registers */
80#define XREG_INIT 0x00
81#define XREG_VIDEO_MODE 0x01
82#define XREG_AUDIO_MODE 0x02
83#define XREG_RF_FREQ 0x03
84#define XREG_D_CODE 0x04
85#define XREG_IF_OUT 0x05
86#define XREG_SEEK_MODE 0x07
Devin Heitmueller7f05b532009-04-02 22:02:39 -030087#define XREG_POWER_DOWN 0x0A /* Obsolete */
Dmitri Belimov724dcbf2011-02-01 05:25:19 -030088/* Set the output amplitude - SIF for analog, DTVP/DTVN for digital */
89#define XREG_OUTPUT_AMP 0x0B
Steven Tothaacb9d32007-12-18 01:55:51 -030090#define XREG_SIGNALSOURCE 0x0D /* 0=Air, 1=Cable */
91#define XREG_SMOOTHEDCVBS 0x0E
92#define XREG_XTALFREQ 0x0F
Devin Heitmueller81c4dfe2009-04-02 22:40:29 -030093#define XREG_FINERFREQ 0x10
Steven Tothaacb9d32007-12-18 01:55:51 -030094#define XREG_DDIMODE 0x11
95
96#define XREG_ADC_ENV 0x00
97#define XREG_QUALITY 0x01
98#define XREG_FRAME_LINES 0x02
99#define XREG_HSYNC_FREQ 0x03
100#define XREG_LOCK 0x04
101#define XREG_FREQ_ERROR 0x05
102#define XREG_SNR 0x06
103#define XREG_VERSION 0x07
104#define XREG_PRODUCT_ID 0x08
105#define XREG_BUSY 0x09
Devin Heitmuellerbae7b7d2009-04-02 22:24:38 -0300106#define XREG_BUILD 0x0D
Devin Heitmueller7c287f12012-08-06 22:46:56 -0300107#define XREG_TOTALGAIN 0x0F
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -0300108#define XREG_FW_CHECKSUM 0x12
109#define XREG_INIT_STATUS 0x13
Steven Tothaacb9d32007-12-18 01:55:51 -0300110
111/*
112 Basic firmware description. This will remain with
113 the driver for documentation purposes.
114
115 This represents an I2C firmware file encoded as a
116 string of unsigned char. Format is as follows:
117
118 char[0 ]=len0_MSB -> len = len_MSB * 256 + len_LSB
119 char[1 ]=len0_LSB -> length of first write transaction
120 char[2 ]=data0 -> first byte to be sent
121 char[3 ]=data1
122 char[4 ]=data2
123 char[ ]=...
124 char[M ]=dataN -> last byte to be sent
125 char[M+1]=len1_MSB -> len = len_MSB * 256 + len_LSB
126 char[M+2]=len1_LSB -> length of second write transaction
127 char[M+3]=data0
128 char[M+4]=data1
129 ...
130 etc.
131
132 The [len] value should be interpreted as follows:
133
134 len= len_MSB _ len_LSB
135 len=1111_1111_1111_1111 : End of I2C_SEQUENCE
136 len=0000_0000_0000_0000 : Reset command: Do hardware reset
137 len=0NNN_NNNN_NNNN_NNNN : Normal transaction: number of bytes = {1:32767)
138 len=1WWW_WWWW_WWWW_WWWW : Wait command: wait for {1:32767} ms
139
140 For the RESET and WAIT commands, the two following bytes will contain
141 immediately the length of the following transaction.
142
143*/
Steven Toth8f3cd532008-10-16 20:29:38 -0300144struct XC_TV_STANDARD {
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300145 char *name;
146 u16 audio_mode;
147 u16 video_mode;
Steven Toth8f3cd532008-10-16 20:29:38 -0300148};
Steven Tothaacb9d32007-12-18 01:55:51 -0300149
150/* Tuner standards */
Steven Toth27c685a2008-01-05 16:50:14 -0300151#define MN_NTSC_PAL_BTSC 0
152#define MN_NTSC_PAL_A2 1
153#define MN_NTSC_PAL_EIAJ 2
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300154#define MN_NTSC_PAL_MONO 3
Steven Toth27c685a2008-01-05 16:50:14 -0300155#define BG_PAL_A2 4
156#define BG_PAL_NICAM 5
157#define BG_PAL_MONO 6
158#define I_PAL_NICAM 7
159#define I_PAL_NICAM_MONO 8
160#define DK_PAL_A2 9
161#define DK_PAL_NICAM 10
162#define DK_PAL_MONO 11
163#define DK_SECAM_A2DK1 12
Mauro Carvalho Chehab5015c272014-05-21 13:41:01 -0300164#define DK_SECAM_A2LDK3 13
165#define DK_SECAM_A2MONO 14
Steven Toth27c685a2008-01-05 16:50:14 -0300166#define L_SECAM_NICAM 15
167#define LC_SECAM_NICAM 16
168#define DTV6 17
169#define DTV8 18
170#define DTV7_8 19
171#define DTV7 20
Mauro Carvalho Chehab5015c272014-05-21 13:41:01 -0300172#define FM_RADIO_INPUT2 21
173#define FM_RADIO_INPUT1 22
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300174#define FM_RADIO_INPUT1_MONO 23
Steven Tothaacb9d32007-12-18 01:55:51 -0300175
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300176static struct XC_TV_STANDARD xc5000_standard[MAX_TV_STANDARD] = {
Steven Tothaacb9d32007-12-18 01:55:51 -0300177 {"M/N-NTSC/PAL-BTSC", 0x0400, 0x8020},
178 {"M/N-NTSC/PAL-A2", 0x0600, 0x8020},
179 {"M/N-NTSC/PAL-EIAJ", 0x0440, 0x8020},
180 {"M/N-NTSC/PAL-Mono", 0x0478, 0x8020},
181 {"B/G-PAL-A2", 0x0A00, 0x8049},
182 {"B/G-PAL-NICAM", 0x0C04, 0x8049},
183 {"B/G-PAL-MONO", 0x0878, 0x8059},
184 {"I-PAL-NICAM", 0x1080, 0x8009},
185 {"I-PAL-NICAM-MONO", 0x0E78, 0x8009},
186 {"D/K-PAL-A2", 0x1600, 0x8009},
187 {"D/K-PAL-NICAM", 0x0E80, 0x8009},
188 {"D/K-PAL-MONO", 0x1478, 0x8009},
189 {"D/K-SECAM-A2 DK1", 0x1200, 0x8009},
Steven Toth8f3cd532008-10-16 20:29:38 -0300190 {"D/K-SECAM-A2 L/DK3", 0x0E00, 0x8009},
Steven Tothaacb9d32007-12-18 01:55:51 -0300191 {"D/K-SECAM-A2 MONO", 0x1478, 0x8009},
192 {"L-SECAM-NICAM", 0x8E82, 0x0009},
193 {"L'-SECAM-NICAM", 0x8E82, 0x4009},
194 {"DTV6", 0x00C0, 0x8002},
195 {"DTV8", 0x00C0, 0x800B},
196 {"DTV7/8", 0x00C0, 0x801B},
197 {"DTV7", 0x00C0, 0x8007},
198 {"FM Radio-INPUT2", 0x9802, 0x9002},
Dmitri Belimov724dcbf2011-02-01 05:25:19 -0300199 {"FM Radio-INPUT1", 0x0208, 0x9002},
200 {"FM Radio-INPUT1_MONO", 0x0278, 0x9002}
Steven Tothaacb9d32007-12-18 01:55:51 -0300201};
202
Michael Krufkyddea4272012-02-07 02:39:36 -0300203
204struct xc5000_fw_cfg {
205 char *name;
206 u16 size;
Devin Heitmuellerde49bc62012-08-06 22:47:08 -0300207 u16 pll_reg;
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -0300208 u8 init_status_supported;
209 u8 fw_checksum_supported;
Michael Krufkyddea4272012-02-07 02:39:36 -0300210};
211
Tim Gardner3422f2a62012-07-25 09:15:19 -0300212#define XC5000A_FIRMWARE "dvb-fe-xc5000-1.6.114.fw"
Michael Krufkya3db60b2012-02-08 15:03:07 -0300213static const struct xc5000_fw_cfg xc5000a_1_6_114 = {
Tim Gardner3422f2a62012-07-25 09:15:19 -0300214 .name = XC5000A_FIRMWARE,
Michael Krufky76efb0ba2012-02-06 19:40:32 -0300215 .size = 12401,
Devin Heitmuellerde49bc62012-08-06 22:47:08 -0300216 .pll_reg = 0x806c,
Michael Krufky76efb0ba2012-02-06 19:40:32 -0300217};
218
Devin Heitmueller3de5bff2012-08-06 22:47:14 -0300219#define XC5000C_FIRMWARE "dvb-fe-xc5000c-4.1.30.7.fw"
Michael Krufky7d3d0d82012-04-16 14:59:32 -0300220static const struct xc5000_fw_cfg xc5000c_41_024_5 = {
Tim Gardner3422f2a62012-07-25 09:15:19 -0300221 .name = XC5000C_FIRMWARE,
Michael Krufky7d3d0d82012-04-16 14:59:32 -0300222 .size = 16497,
Devin Heitmuellerde49bc62012-08-06 22:47:08 -0300223 .pll_reg = 0x13,
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -0300224 .init_status_supported = 1,
225 .fw_checksum_supported = 1,
Michael Krufkyd8398802012-02-07 01:16:27 -0300226};
227
Michael Krufkya3db60b2012-02-08 15:03:07 -0300228static inline const struct xc5000_fw_cfg *xc5000_assign_firmware(int chip_id)
Michael Krufkyddea4272012-02-07 02:39:36 -0300229{
Michael Krufky6fab81d2012-02-08 14:57:39 -0300230 switch (chip_id) {
Michael Krufkyddea4272012-02-07 02:39:36 -0300231 default:
Michael Krufky6fab81d2012-02-08 14:57:39 -0300232 case XC5000A:
Michael Krufkyddea4272012-02-07 02:39:36 -0300233 return &xc5000a_1_6_114;
Michael Krufky6fab81d2012-02-08 14:57:39 -0300234 case XC5000C:
Michael Krufky7d3d0d82012-04-16 14:59:32 -0300235 return &xc5000c_41_024_5;
Michael Krufkyddea4272012-02-07 02:39:36 -0300236 }
237}
238
Devin Heitmuellerde49bc62012-08-06 22:47:08 -0300239static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force);
Devin Heitmueller91bd6252008-11-15 23:29:11 -0300240static int xc5000_is_firmware_loaded(struct dvb_frontend *fe);
Devin Heitmuellerbdd33562008-11-16 20:17:14 -0300241static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val);
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300242static int xc5000_tuner_reset(struct dvb_frontend *fe);
Steven Tothaacb9d32007-12-18 01:55:51 -0300243
Steven Tothe12671cf2007-12-20 01:14:43 -0300244static int xc_send_i2c_data(struct xc5000_priv *priv, u8 *buf, int len)
Steven Tothaacb9d32007-12-18 01:55:51 -0300245{
Devin Heitmuellerd7800d42008-11-16 20:20:06 -0300246 struct i2c_msg msg = { .addr = priv->i2c_props.addr,
247 .flags = 0, .buf = buf, .len = len };
248
249 if (i2c_transfer(priv->i2c_props.adap, &msg, 1) != 1) {
250 printk(KERN_ERR "xc5000: I2C write failed (len=%i)\n", len);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300251 return -EREMOTEIO;
Devin Heitmuellerd7800d42008-11-16 20:20:06 -0300252 }
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300253 return 0;
Steven Tothaacb9d32007-12-18 01:55:51 -0300254}
255
Mauro Carvalho Chehab1cdffda2010-07-05 18:38:46 -0300256#if 0
Devin Heitmuellerbdd33562008-11-16 20:17:14 -0300257/* This routine is never used because the only time we read data from the
258 i2c bus is when we read registers, and we want that to be an atomic i2c
259 transaction in case we are on a multi-master bus */
Steven Tothe12671cf2007-12-20 01:14:43 -0300260static int xc_read_i2c_data(struct xc5000_priv *priv, u8 *buf, int len)
Steven Tothaacb9d32007-12-18 01:55:51 -0300261{
Devin Heitmuellerbdd33562008-11-16 20:17:14 -0300262 struct i2c_msg msg = { .addr = priv->i2c_props.addr,
263 .flags = I2C_M_RD, .buf = buf, .len = len };
264
265 if (i2c_transfer(priv->i2c_props.adap, &msg, 1) != 1) {
266 printk(KERN_ERR "xc5000 I2C read failed (len=%i)\n", len);
267 return -EREMOTEIO;
268 }
269 return 0;
Steven Tothaacb9d32007-12-18 01:55:51 -0300270}
Mauro Carvalho Chehab1cdffda2010-07-05 18:38:46 -0300271#endif
Steven Tothaacb9d32007-12-18 01:55:51 -0300272
Dmitri Belimov47433192010-05-18 04:30:11 -0300273static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val)
274{
275 u8 buf[2] = { reg >> 8, reg & 0xff };
276 u8 bval[2] = { 0, 0 };
277 struct i2c_msg msg[2] = {
278 { .addr = priv->i2c_props.addr,
279 .flags = 0, .buf = &buf[0], .len = 2 },
280 { .addr = priv->i2c_props.addr,
281 .flags = I2C_M_RD, .buf = &bval[0], .len = 2 },
282 };
283
284 if (i2c_transfer(priv->i2c_props.adap, msg, 2) != 2) {
285 printk(KERN_WARNING "xc5000: I2C read failed\n");
286 return -EREMOTEIO;
287 }
288
289 *val = (bval[0] << 8) | bval[1];
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300290 return 0;
Dmitri Belimov47433192010-05-18 04:30:11 -0300291}
292
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300293static int xc5000_tuner_reset(struct dvb_frontend *fe)
Steven Tothaacb9d32007-12-18 01:55:51 -0300294{
295 struct xc5000_priv *priv = fe->tuner_priv;
296 int ret;
297
Harvey Harrison271ddbf2008-04-08 23:20:00 -0300298 dprintk(1, "%s()\n", __func__);
Steven Tothaacb9d32007-12-18 01:55:51 -0300299
Michael Krufkyd7cba042008-09-12 13:31:45 -0300300 if (fe->callback) {
301 ret = fe->callback(((fe->dvb) && (fe->dvb->priv)) ?
Michael Krufky30650962008-09-06 14:56:58 -0300302 fe->dvb->priv :
303 priv->i2c_props.adap->algo_data,
Michael Krufkyd7cba042008-09-12 13:31:45 -0300304 DVB_FRONTEND_COMPONENT_TUNER,
Michael Krufky30650962008-09-06 14:56:58 -0300305 XC5000_TUNER_RESET, 0);
Devin Heitmueller91bd6252008-11-15 23:29:11 -0300306 if (ret) {
Steven Tothaacb9d32007-12-18 01:55:51 -0300307 printk(KERN_ERR "xc5000: reset failed\n");
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300308 return ret;
Devin Heitmueller91bd6252008-11-15 23:29:11 -0300309 }
310 } else {
Steven Toth27c685a2008-01-05 16:50:14 -0300311 printk(KERN_ERR "xc5000: no tuner reset callback function, fatal\n");
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300312 return -EINVAL;
Devin Heitmueller91bd6252008-11-15 23:29:11 -0300313 }
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300314 return 0;
Steven Tothaacb9d32007-12-18 01:55:51 -0300315}
316
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300317static int xc_write_reg(struct xc5000_priv *priv, u16 reg_addr, u16 i2c_data)
Steven Tothaacb9d32007-12-18 01:55:51 -0300318{
Steven Tothe12671cf2007-12-20 01:14:43 -0300319 u8 buf[4];
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300320 int watch_dog_timer = 100;
Steven Tothaacb9d32007-12-18 01:55:51 -0300321 int result;
322
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300323 buf[0] = (reg_addr >> 8) & 0xFF;
324 buf[1] = reg_addr & 0xFF;
325 buf[2] = (i2c_data >> 8) & 0xFF;
326 buf[3] = i2c_data & 0xFF;
Steven Tothaacb9d32007-12-18 01:55:51 -0300327 result = xc_send_i2c_data(priv, buf, 4);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300328 if (result == 0) {
Steven Tothaacb9d32007-12-18 01:55:51 -0300329 /* wait for busy flag to clear */
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300330 while ((watch_dog_timer > 0) && (result == 0)) {
Mauro Carvalho Chehab1cdffda2010-07-05 18:38:46 -0300331 result = xc5000_readreg(priv, XREG_BUSY, (u16 *)buf);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300332 if (result == 0) {
Dmitri Belimov47433192010-05-18 04:30:11 -0300333 if ((buf[0] == 0) && (buf[1] == 0)) {
334 /* busy flag cleared */
Steven Tothaacb9d32007-12-18 01:55:51 -0300335 break;
Dmitri Belimov47433192010-05-18 04:30:11 -0300336 } else {
Mauro Carvalho Chehabe5bf4a12014-05-21 13:15:17 -0300337 msleep(5); /* wait 5 ms */
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300338 watch_dog_timer--;
Steven Tothaacb9d32007-12-18 01:55:51 -0300339 }
340 }
341 }
342 }
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300343 if (watch_dog_timer <= 0)
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300344 result = -EREMOTEIO;
Steven Tothaacb9d32007-12-18 01:55:51 -0300345
346 return result;
347}
348
David Woodhousec63e87e2008-05-24 00:13:34 +0100349static int xc_load_i2c_sequence(struct dvb_frontend *fe, const u8 *i2c_sequence)
Steven Tothaacb9d32007-12-18 01:55:51 -0300350{
351 struct xc5000_priv *priv = fe->tuner_priv;
352
353 int i, nbytes_to_send, result;
354 unsigned int len, pos, index;
Steven Tothe12671cf2007-12-20 01:14:43 -0300355 u8 buf[XC_MAX_I2C_WRITE_LENGTH];
Steven Tothaacb9d32007-12-18 01:55:51 -0300356
Steven Toth8f3cd532008-10-16 20:29:38 -0300357 index = 0;
358 while ((i2c_sequence[index] != 0xFF) ||
359 (i2c_sequence[index + 1] != 0xFF)) {
360 len = i2c_sequence[index] * 256 + i2c_sequence[index+1];
Steven Tothe12671cf2007-12-20 01:14:43 -0300361 if (len == 0x0000) {
Steven Tothaacb9d32007-12-18 01:55:51 -0300362 /* RESET command */
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300363 result = xc5000_tuner_reset(fe);
Steven Tothaacb9d32007-12-18 01:55:51 -0300364 index += 2;
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300365 if (result != 0)
Steven Tothaacb9d32007-12-18 01:55:51 -0300366 return result;
367 } else if (len & 0x8000) {
368 /* WAIT command */
Mauro Carvalho Chehabe5bf4a12014-05-21 13:15:17 -0300369 msleep(len & 0x7FFF);
Steven Tothaacb9d32007-12-18 01:55:51 -0300370 index += 2;
371 } else {
372 /* Send i2c data whilst ensuring individual transactions
373 * do not exceed XC_MAX_I2C_WRITE_LENGTH bytes.
374 */
375 index += 2;
376 buf[0] = i2c_sequence[index];
377 buf[1] = i2c_sequence[index + 1];
378 pos = 2;
379 while (pos < len) {
Steven Toth8f3cd532008-10-16 20:29:38 -0300380 if ((len - pos) > XC_MAX_I2C_WRITE_LENGTH - 2)
381 nbytes_to_send =
382 XC_MAX_I2C_WRITE_LENGTH;
383 else
Steven Tothaacb9d32007-12-18 01:55:51 -0300384 nbytes_to_send = (len - pos + 2);
Steven Toth8f3cd532008-10-16 20:29:38 -0300385 for (i = 2; i < nbytes_to_send; i++) {
386 buf[i] = i2c_sequence[index + pos +
387 i - 2];
Steven Tothaacb9d32007-12-18 01:55:51 -0300388 }
Steven Toth8f3cd532008-10-16 20:29:38 -0300389 result = xc_send_i2c_data(priv, buf,
390 nbytes_to_send);
Steven Tothaacb9d32007-12-18 01:55:51 -0300391
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300392 if (result != 0)
Steven Tothaacb9d32007-12-18 01:55:51 -0300393 return result;
394
395 pos += nbytes_to_send - 2;
396 }
397 index += len;
398 }
399 }
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300400 return 0;
Steven Tothaacb9d32007-12-18 01:55:51 -0300401}
402
Steven Tothe12671cf2007-12-20 01:14:43 -0300403static int xc_initialize(struct xc5000_priv *priv)
Steven Tothaacb9d32007-12-18 01:55:51 -0300404{
Harvey Harrison271ddbf2008-04-08 23:20:00 -0300405 dprintk(1, "%s()\n", __func__);
Steven Tothaacb9d32007-12-18 01:55:51 -0300406 return xc_write_reg(priv, XREG_INIT, 0);
407}
408
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300409static int xc_set_tv_standard(struct xc5000_priv *priv,
410 u16 video_mode, u16 audio_mode, u8 radio_mode)
Steven Tothaacb9d32007-12-18 01:55:51 -0300411{
412 int ret;
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300413 dprintk(1, "%s(0x%04x,0x%04x)\n", __func__, video_mode, audio_mode);
414 if (radio_mode) {
Dmitri Belimov01ae7282013-03-13 00:23:36 -0300415 dprintk(1, "%s() Standard = %s\n",
416 __func__,
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300417 xc5000_standard[radio_mode].name);
Dmitri Belimov01ae7282013-03-13 00:23:36 -0300418 } else {
419 dprintk(1, "%s() Standard = %s\n",
420 __func__,
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300421 xc5000_standard[priv->video_standard].name);
Dmitri Belimov01ae7282013-03-13 00:23:36 -0300422 }
Steven Tothaacb9d32007-12-18 01:55:51 -0300423
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300424 ret = xc_write_reg(priv, XREG_VIDEO_MODE, video_mode);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300425 if (ret == 0)
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300426 ret = xc_write_reg(priv, XREG_AUDIO_MODE, audio_mode);
Steven Tothaacb9d32007-12-18 01:55:51 -0300427
428 return ret;
429}
430
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300431static int xc_set_signal_source(struct xc5000_priv *priv, u16 rf_mode)
Steven Tothaacb9d32007-12-18 01:55:51 -0300432{
Harvey Harrison271ddbf2008-04-08 23:20:00 -0300433 dprintk(1, "%s(%d) Source = %s\n", __func__, rf_mode,
Steven Tothaacb9d32007-12-18 01:55:51 -0300434 rf_mode == XC_RF_MODE_AIR ? "ANTENNA" : "CABLE");
435
Steven Toth8f3cd532008-10-16 20:29:38 -0300436 if ((rf_mode != XC_RF_MODE_AIR) && (rf_mode != XC_RF_MODE_CABLE)) {
Steven Tothaacb9d32007-12-18 01:55:51 -0300437 rf_mode = XC_RF_MODE_CABLE;
438 printk(KERN_ERR
439 "%s(), Invalid mode, defaulting to CABLE",
Harvey Harrison271ddbf2008-04-08 23:20:00 -0300440 __func__);
Steven Tothaacb9d32007-12-18 01:55:51 -0300441 }
442 return xc_write_reg(priv, XREG_SIGNALSOURCE, rf_mode);
443}
444
Steven Tothe12671cf2007-12-20 01:14:43 -0300445static const struct dvb_tuner_ops xc5000_tuner_ops;
446
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300447static int xc_set_rf_frequency(struct xc5000_priv *priv, u32 freq_hz)
Steven Tothaacb9d32007-12-18 01:55:51 -0300448{
Steven Tothe12671cf2007-12-20 01:14:43 -0300449 u16 freq_code;
Steven Tothaacb9d32007-12-18 01:55:51 -0300450
Harvey Harrison271ddbf2008-04-08 23:20:00 -0300451 dprintk(1, "%s(%u)\n", __func__, freq_hz);
Steven Tothaacb9d32007-12-18 01:55:51 -0300452
Mauro Carvalho Chehaba3f90c72018-07-05 18:59:35 -0400453 if ((freq_hz > xc5000_tuner_ops.info.frequency_max_hz) ||
454 (freq_hz < xc5000_tuner_ops.info.frequency_min_hz))
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300455 return -EINVAL;
Steven Tothaacb9d32007-12-18 01:55:51 -0300456
Steven Tothe12671cf2007-12-20 01:14:43 -0300457 freq_code = (u16)(freq_hz / 15625);
458
Devin Heitmueller81c4dfe2009-04-02 22:40:29 -0300459 /* Starting in firmware version 1.1.44, Xceive recommends using the
460 FINERFREQ for all normal tuning (the doc indicates reg 0x03 should
461 only be used for fast scanning for channel lock) */
462 return xc_write_reg(priv, XREG_FINERFREQ, freq_code);
Steven Tothaacb9d32007-12-18 01:55:51 -0300463}
464
Steven Tothe12671cf2007-12-20 01:14:43 -0300465
466static int xc_set_IF_frequency(struct xc5000_priv *priv, u32 freq_khz)
Steven Tothaacb9d32007-12-18 01:55:51 -0300467{
Steven Tothe12671cf2007-12-20 01:14:43 -0300468 u32 freq_code = (freq_khz * 1024)/1000;
469 dprintk(1, "%s(freq_khz = %d) freq_code = 0x%x\n",
Harvey Harrison271ddbf2008-04-08 23:20:00 -0300470 __func__, freq_khz, freq_code);
Steven Tothe12671cf2007-12-20 01:14:43 -0300471
472 return xc_write_reg(priv, XREG_IF_OUT, freq_code);
Steven Tothaacb9d32007-12-18 01:55:51 -0300473}
474
Steven Tothe12671cf2007-12-20 01:14:43 -0300475
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300476static int xc_get_adc_envelope(struct xc5000_priv *priv, u16 *adc_envelope)
Steven Tothaacb9d32007-12-18 01:55:51 -0300477{
Devin Heitmuellerbdd33562008-11-16 20:17:14 -0300478 return xc5000_readreg(priv, XREG_ADC_ENV, adc_envelope);
Steven Tothaacb9d32007-12-18 01:55:51 -0300479}
480
Steven Tothe12671cf2007-12-20 01:14:43 -0300481static int xc_get_frequency_error(struct xc5000_priv *priv, u32 *freq_error_hz)
Steven Tothaacb9d32007-12-18 01:55:51 -0300482{
483 int result;
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300484 u16 reg_data;
Steven Tothaacb9d32007-12-18 01:55:51 -0300485 u32 tmp;
486
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300487 result = xc5000_readreg(priv, XREG_FREQ_ERROR, &reg_data);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300488 if (result != 0)
Steven Tothaacb9d32007-12-18 01:55:51 -0300489 return result;
490
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300491 tmp = (u32)reg_data;
Steven Tothe12671cf2007-12-20 01:14:43 -0300492 (*freq_error_hz) = (tmp * 15625) / 1000;
Steven Tothaacb9d32007-12-18 01:55:51 -0300493 return result;
494}
495
Steven Tothe12671cf2007-12-20 01:14:43 -0300496static int xc_get_lock_status(struct xc5000_priv *priv, u16 *lock_status)
Steven Tothaacb9d32007-12-18 01:55:51 -0300497{
Devin Heitmuellerbdd33562008-11-16 20:17:14 -0300498 return xc5000_readreg(priv, XREG_LOCK, lock_status);
Steven Tothaacb9d32007-12-18 01:55:51 -0300499}
500
Steven Tothe12671cf2007-12-20 01:14:43 -0300501static int xc_get_version(struct xc5000_priv *priv,
502 u8 *hw_majorversion, u8 *hw_minorversion,
503 u8 *fw_majorversion, u8 *fw_minorversion)
Steven Tothaacb9d32007-12-18 01:55:51 -0300504{
Steven Tothe12671cf2007-12-20 01:14:43 -0300505 u16 data;
Steven Tothaacb9d32007-12-18 01:55:51 -0300506 int result;
507
Devin Heitmuellerbdd33562008-11-16 20:17:14 -0300508 result = xc5000_readreg(priv, XREG_VERSION, &data);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300509 if (result != 0)
Steven Tothaacb9d32007-12-18 01:55:51 -0300510 return result;
511
Steven Tothe12671cf2007-12-20 01:14:43 -0300512 (*hw_majorversion) = (data >> 12) & 0x0F;
513 (*hw_minorversion) = (data >> 8) & 0x0F;
514 (*fw_majorversion) = (data >> 4) & 0x0F;
515 (*fw_minorversion) = data & 0x0F;
Steven Tothaacb9d32007-12-18 01:55:51 -0300516
517 return 0;
518}
519
Devin Heitmuellerbae7b7d2009-04-02 22:24:38 -0300520static int xc_get_buildversion(struct xc5000_priv *priv, u16 *buildrev)
521{
522 return xc5000_readreg(priv, XREG_BUILD, buildrev);
523}
524
Steven Tothe12671cf2007-12-20 01:14:43 -0300525static int xc_get_hsync_freq(struct xc5000_priv *priv, u32 *hsync_freq_hz)
Steven Tothaacb9d32007-12-18 01:55:51 -0300526{
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300527 u16 reg_data;
Steven Tothaacb9d32007-12-18 01:55:51 -0300528 int result;
529
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300530 result = xc5000_readreg(priv, XREG_HSYNC_FREQ, &reg_data);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300531 if (result != 0)
Steven Tothaacb9d32007-12-18 01:55:51 -0300532 return result;
533
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300534 (*hsync_freq_hz) = ((reg_data & 0x0fff) * 763)/100;
Steven Tothaacb9d32007-12-18 01:55:51 -0300535 return result;
536}
537
Steven Tothe12671cf2007-12-20 01:14:43 -0300538static int xc_get_frame_lines(struct xc5000_priv *priv, u16 *frame_lines)
Steven Tothaacb9d32007-12-18 01:55:51 -0300539{
Devin Heitmuellerbdd33562008-11-16 20:17:14 -0300540 return xc5000_readreg(priv, XREG_FRAME_LINES, frame_lines);
Steven Tothaacb9d32007-12-18 01:55:51 -0300541}
542
Steven Tothe12671cf2007-12-20 01:14:43 -0300543static int xc_get_quality(struct xc5000_priv *priv, u16 *quality)
Steven Tothaacb9d32007-12-18 01:55:51 -0300544{
Devin Heitmuellerbdd33562008-11-16 20:17:14 -0300545 return xc5000_readreg(priv, XREG_QUALITY, quality);
Steven Tothaacb9d32007-12-18 01:55:51 -0300546}
547
Devin Heitmueller7c287f12012-08-06 22:46:56 -0300548static int xc_get_analogsnr(struct xc5000_priv *priv, u16 *snr)
549{
550 return xc5000_readreg(priv, XREG_SNR, snr);
551}
552
553static int xc_get_totalgain(struct xc5000_priv *priv, u16 *totalgain)
554{
555 return xc5000_readreg(priv, XREG_TOTALGAIN, totalgain);
556}
557
Devin Heitmuellera78baac2008-11-16 20:48:31 -0300558#define XC_TUNE_ANALOG 0
559#define XC_TUNE_DIGITAL 1
560static int xc_tune_channel(struct xc5000_priv *priv, u32 freq_hz, int mode)
Steven Tothaacb9d32007-12-18 01:55:51 -0300561{
Harvey Harrison271ddbf2008-04-08 23:20:00 -0300562 dprintk(1, "%s(%u)\n", __func__, freq_hz);
Steven Tothaacb9d32007-12-18 01:55:51 -0300563
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300564 if (xc_set_rf_frequency(priv, freq_hz) != 0)
Devin Heitmuellerd9928a12017-04-19 20:13:52 -0300565 return -EREMOTEIO;
Steven Tothaacb9d32007-12-18 01:55:51 -0300566
Devin Heitmuellerd9928a12017-04-19 20:13:52 -0300567 return 0;
Steven Tothaacb9d32007-12-18 01:55:51 -0300568}
569
Michael Krufky7d3d0d82012-04-16 14:59:32 -0300570static int xc_set_xtal(struct dvb_frontend *fe)
571{
572 struct xc5000_priv *priv = fe->tuner_priv;
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300573 int ret = 0;
Michael Krufky7d3d0d82012-04-16 14:59:32 -0300574
575 switch (priv->chip_id) {
576 default:
577 case XC5000A:
578 /* 32.000 MHz xtal is default */
579 break;
580 case XC5000C:
581 switch (priv->xtal_khz) {
582 default:
583 case 32000:
584 /* 32.000 MHz xtal is default */
585 break;
586 case 31875:
587 /* 31.875 MHz xtal configuration */
588 ret = xc_write_reg(priv, 0x000f, 0x8081);
589 break;
590 }
591 break;
592 }
593 return ret;
594}
Steven Tothaacb9d32007-12-18 01:55:51 -0300595
Mauro Carvalho Chehab8604f352014-07-30 11:09:15 -0300596static int xc5000_fwupload(struct dvb_frontend *fe,
597 const struct xc5000_fw_cfg *desired_fw,
598 const struct firmware *fw)
Steven Tothaacb9d32007-12-18 01:55:51 -0300599{
600 struct xc5000_priv *priv = fe->tuner_priv;
Steven Tothaacb9d32007-12-18 01:55:51 -0300601 int ret;
Mauro Carvalho Chehab8604f352014-07-30 11:09:15 -0300602
603 /* request the firmware, this will block and timeout */
604 dprintk(1, "waiting for firmware upload (%s)...\n",
605 desired_fw->name);
606
Devin Heitmuellerde49bc62012-08-06 22:47:08 -0300607 priv->pll_register_no = desired_fw->pll_reg;
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -0300608 priv->init_status_supported = desired_fw->init_status_supported;
609 priv->fw_checksum_supported = desired_fw->fw_checksum_supported;
Steven Tothaacb9d32007-12-18 01:55:51 -0300610
Steven Tothe12671cf2007-12-20 01:14:43 -0300611
Mauro Carvalho Chehab8604f352014-07-30 11:09:15 -0300612 dprintk(1, "firmware uploading...\n");
613 ret = xc_load_i2c_sequence(fe, fw->data);
614 if (!ret) {
615 ret = xc_set_xtal(fe);
616 dprintk(1, "Firmware upload complete...\n");
617 } else
618 printk(KERN_ERR "xc5000: firmware upload failed...\n");
Steven Tothaacb9d32007-12-18 01:55:51 -0300619
Steven Tothaacb9d32007-12-18 01:55:51 -0300620 return ret;
621}
622
Steven Tothe12671cf2007-12-20 01:14:43 -0300623static void xc_debug_dump(struct xc5000_priv *priv)
Steven Tothaacb9d32007-12-18 01:55:51 -0300624{
Steven Tothe12671cf2007-12-20 01:14:43 -0300625 u16 adc_envelope;
626 u32 freq_error_hz = 0;
627 u16 lock_status;
628 u32 hsync_freq_hz = 0;
629 u16 frame_lines;
630 u16 quality;
Devin Heitmueller7c287f12012-08-06 22:46:56 -0300631 u16 snr;
632 u16 totalgain;
Steven Tothe12671cf2007-12-20 01:14:43 -0300633 u8 hw_majorversion = 0, hw_minorversion = 0;
634 u8 fw_majorversion = 0, fw_minorversion = 0;
Devin Heitmuellerbae7b7d2009-04-02 22:24:38 -0300635 u16 fw_buildversion = 0;
Devin Heitmuellerde49bc62012-08-06 22:47:08 -0300636 u16 regval;
Steven Tothaacb9d32007-12-18 01:55:51 -0300637
638 /* Wait for stats to stabilize.
639 * Frame Lines needs two frame times after initial lock
640 * before it is valid.
641 */
Mauro Carvalho Chehabe5bf4a12014-05-21 13:15:17 -0300642 msleep(100);
Steven Tothaacb9d32007-12-18 01:55:51 -0300643
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300644 xc_get_adc_envelope(priv, &adc_envelope);
Steven Tothe12671cf2007-12-20 01:14:43 -0300645 dprintk(1, "*** ADC envelope (0-1023) = %d\n", adc_envelope);
Steven Tothaacb9d32007-12-18 01:55:51 -0300646
Steven Tothe12671cf2007-12-20 01:14:43 -0300647 xc_get_frequency_error(priv, &freq_error_hz);
648 dprintk(1, "*** Frequency error = %d Hz\n", freq_error_hz);
Steven Tothaacb9d32007-12-18 01:55:51 -0300649
Steven Tothe12671cf2007-12-20 01:14:43 -0300650 xc_get_lock_status(priv, &lock_status);
651 dprintk(1, "*** Lock status (0-Wait, 1-Locked, 2-No-signal) = %d\n",
Steven Tothaacb9d32007-12-18 01:55:51 -0300652 lock_status);
653
654 xc_get_version(priv, &hw_majorversion, &hw_minorversion,
Steven Tothe12671cf2007-12-20 01:14:43 -0300655 &fw_majorversion, &fw_minorversion);
Devin Heitmuellerbae7b7d2009-04-02 22:24:38 -0300656 xc_get_buildversion(priv, &fw_buildversion);
Devin Heitmuellerca60a45d2012-08-06 22:47:11 -0300657 dprintk(1, "*** HW: V%d.%d, FW: V %d.%d.%d\n",
Steven Tothaacb9d32007-12-18 01:55:51 -0300658 hw_majorversion, hw_minorversion,
Devin Heitmuellerbae7b7d2009-04-02 22:24:38 -0300659 fw_majorversion, fw_minorversion, fw_buildversion);
Steven Tothaacb9d32007-12-18 01:55:51 -0300660
Steven Tothe12671cf2007-12-20 01:14:43 -0300661 xc_get_hsync_freq(priv, &hsync_freq_hz);
662 dprintk(1, "*** Horizontal sync frequency = %d Hz\n", hsync_freq_hz);
Steven Tothaacb9d32007-12-18 01:55:51 -0300663
Steven Tothe12671cf2007-12-20 01:14:43 -0300664 xc_get_frame_lines(priv, &frame_lines);
665 dprintk(1, "*** Frame lines = %d\n", frame_lines);
Steven Tothaacb9d32007-12-18 01:55:51 -0300666
Steven Tothe12671cf2007-12-20 01:14:43 -0300667 xc_get_quality(priv, &quality);
Devin Heitmueller1aa9c4872012-08-06 22:46:55 -0300668 dprintk(1, "*** Quality (0:<8dB, 7:>56dB) = %d\n", quality & 0x07);
Devin Heitmueller7c287f12012-08-06 22:46:56 -0300669
670 xc_get_analogsnr(priv, &snr);
671 dprintk(1, "*** Unweighted analog SNR = %d dB\n", snr & 0x3f);
672
673 xc_get_totalgain(priv, &totalgain);
674 dprintk(1, "*** Total gain = %d.%d dB\n", totalgain / 256,
675 (totalgain % 256) * 100 / 256);
Devin Heitmuellerde49bc62012-08-06 22:47:08 -0300676
677 if (priv->pll_register_no) {
Mauro Carvalho Chehab7621b8c2017-11-01 17:05:43 -0400678 if (!xc5000_readreg(priv, priv->pll_register_no, &regval))
679 dprintk(1, "*** PLL lock status = 0x%04x\n", regval);
Devin Heitmuellerde49bc62012-08-06 22:47:08 -0300680 }
Steven Tothaacb9d32007-12-18 01:55:51 -0300681}
682
Mauro Carvalho Chehab16435202014-08-09 21:47:21 -0300683static int xc5000_tune_digital(struct dvb_frontend *fe)
684{
685 struct xc5000_priv *priv = fe->tuner_priv;
686 int ret;
687 u32 bw = fe->dtv_property_cache.bandwidth_hz;
688
689 ret = xc_set_signal_source(priv, priv->rf_mode);
690 if (ret != 0) {
691 printk(KERN_ERR
692 "xc5000: xc_set_signal_source(%d) failed\n",
693 priv->rf_mode);
694 return -EREMOTEIO;
695 }
696
697 ret = xc_set_tv_standard(priv,
698 xc5000_standard[priv->video_standard].video_mode,
699 xc5000_standard[priv->video_standard].audio_mode, 0);
700 if (ret != 0) {
701 printk(KERN_ERR "xc5000: xc_set_tv_standard failed\n");
702 return -EREMOTEIO;
703 }
704
705 ret = xc_set_IF_frequency(priv, priv->if_khz);
706 if (ret != 0) {
707 printk(KERN_ERR "xc5000: xc_Set_IF_frequency(%d) failed\n",
708 priv->if_khz);
709 return -EIO;
710 }
711
Richard Vollkommer52e269b2014-10-25 17:17:22 -0300712 dprintk(1, "%s() setting OUTPUT_AMP to 0x%x\n",
713 __func__, priv->output_amp);
714 xc_write_reg(priv, XREG_OUTPUT_AMP, priv->output_amp);
Mauro Carvalho Chehab16435202014-08-09 21:47:21 -0300715
716 xc_tune_channel(priv, priv->freq_hz, XC_TUNE_DIGITAL);
717
718 if (debug)
719 xc_debug_dump(priv);
720
721 priv->bandwidth = bw;
722
723 return 0;
724}
725
Mauro Carvalho Chehab59b94f3e2014-08-09 21:47:24 -0300726static int xc5000_set_digital_params(struct dvb_frontend *fe)
Steven Tothaacb9d32007-12-18 01:55:51 -0300727{
Mauro Carvalho Chehab16435202014-08-09 21:47:21 -0300728 int b;
Steven Tothaacb9d32007-12-18 01:55:51 -0300729 struct xc5000_priv *priv = fe->tuner_priv;
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300730 u32 bw = fe->dtv_property_cache.bandwidth_hz;
731 u32 freq = fe->dtv_property_cache.frequency;
732 u32 delsys = fe->dtv_property_cache.delivery_system;
Steven Tothaacb9d32007-12-18 01:55:51 -0300733
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300734 if (xc_load_fw_and_init_tuner(fe, 0) != 0) {
Devin Heitmuellerfc7a74b2012-08-06 22:47:01 -0300735 dprintk(1, "Unable to load firmware and init tuner\n");
736 return -EINVAL;
Devin Heitmueller760c4662009-10-13 23:44:14 -0300737 }
Devin Heitmueller8e4c6792008-11-16 20:41:07 -0300738
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300739 dprintk(1, "%s() frequency=%d (Hz)\n", __func__, freq);
Steven Tothaacb9d32007-12-18 01:55:51 -0300740
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300741 switch (delsys) {
742 case SYS_ATSC:
743 dprintk(1, "%s() VSB modulation\n", __func__);
744 priv->rf_mode = XC_RF_MODE_AIR;
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -0300745 priv->freq_offset = 1750000;
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300746 priv->video_standard = DTV6;
747 break;
748 case SYS_DVBC_ANNEX_B:
749 dprintk(1, "%s() QAM modulation\n", __func__);
750 priv->rf_mode = XC_RF_MODE_CABLE;
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -0300751 priv->freq_offset = 1750000;
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300752 priv->video_standard = DTV6;
753 break;
Mauro Carvalho Chehab5cf73ce2012-07-05 14:07:59 -0300754 case SYS_ISDBT:
755 /* All ISDB-T are currently for 6 MHz bw */
756 if (!bw)
757 bw = 6000000;
758 /* fall to OFDM handling */
Mauro Carvalho Chehab06eeefe2017-05-18 08:13:28 -0300759 /* fall through */
Mauro Carvalho Chehab5cf73ce2012-07-05 14:07:59 -0300760 case SYS_DMBTH:
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300761 case SYS_DVBT:
762 case SYS_DVBT2:
David T.L. Wong6c990802009-05-04 22:59:58 -0300763 dprintk(1, "%s() OFDM\n", __func__);
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300764 switch (bw) {
765 case 6000000:
David T.L. Wong6c990802009-05-04 22:59:58 -0300766 priv->video_standard = DTV6;
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -0300767 priv->freq_offset = 1750000;
David T.L. Wong6c990802009-05-04 22:59:58 -0300768 break;
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300769 case 7000000:
Mauro Carvalho Chehab0433cd22011-12-09 08:01:01 -0200770 priv->video_standard = DTV7;
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -0300771 priv->freq_offset = 2250000;
Mauro Carvalho Chehab0433cd22011-12-09 08:01:01 -0200772 break;
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300773 case 8000000:
David T.L. Wong6c990802009-05-04 22:59:58 -0300774 priv->video_standard = DTV8;
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -0300775 priv->freq_offset = 2750000;
David T.L. Wong6c990802009-05-04 22:59:58 -0300776 break;
777 default:
778 printk(KERN_ERR "xc5000 bandwidth not set!\n");
779 return -EINVAL;
780 }
Steven Tothaacb9d32007-12-18 01:55:51 -0300781 priv->rf_mode = XC_RF_MODE_AIR;
Dan Carpentercf1364b2013-01-13 15:31:33 -0300782 break;
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300783 case SYS_DVBC_ANNEX_A:
784 case SYS_DVBC_ANNEX_C:
785 dprintk(1, "%s() QAM modulation\n", __func__);
786 priv->rf_mode = XC_RF_MODE_CABLE;
787 if (bw <= 6000000) {
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300788 priv->video_standard = DTV6;
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -0300789 priv->freq_offset = 1750000;
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300790 b = 6;
791 } else if (bw <= 7000000) {
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300792 priv->video_standard = DTV7;
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -0300793 priv->freq_offset = 2250000;
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300794 b = 7;
795 } else {
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300796 priv->video_standard = DTV7_8;
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -0300797 priv->freq_offset = 2750000;
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300798 b = 8;
Igor M. Liplianine80edce2011-01-25 17:03:00 -0300799 }
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300800 dprintk(1, "%s() Bandwidth %dMHz (%d)\n", __func__,
801 b, bw);
802 break;
803 default:
804 printk(KERN_ERR "xc5000: delivery system is not supported!\n");
Steven Tothaacb9d32007-12-18 01:55:51 -0300805 return -EINVAL;
806 }
807
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -0300808 priv->freq_hz = freq - priv->freq_offset;
Mauro Carvalho Chehab16435202014-08-09 21:47:21 -0300809 priv->mode = V4L2_TUNER_DIGITAL_TV;
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -0300810
Mauro Carvalho Chehabfd66c452011-12-17 20:36:57 -0300811 dprintk(1, "%s() frequency=%d (compensated to %d)\n",
812 __func__, freq, priv->freq_hz);
Steven Tothaacb9d32007-12-18 01:55:51 -0300813
Mauro Carvalho Chehab16435202014-08-09 21:47:21 -0300814 return xc5000_tune_digital(fe);
Steven Tothaacb9d32007-12-18 01:55:51 -0300815}
816
Steven Tothe470d812008-06-21 21:06:02 -0300817static int xc5000_is_firmware_loaded(struct dvb_frontend *fe)
818{
819 struct xc5000_priv *priv = fe->tuner_priv;
820 int ret;
821 u16 id;
822
823 ret = xc5000_readreg(priv, XREG_PRODUCT_ID, &id);
Mauro Carvalho Chehab7621b8c2017-11-01 17:05:43 -0400824 if (!ret) {
Steven Tothe470d812008-06-21 21:06:02 -0300825 if (id == XC_PRODUCT_ID_FW_NOT_LOADED)
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300826 ret = -ENOENT;
Steven Tothe470d812008-06-21 21:06:02 -0300827 else
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300828 ret = 0;
Mauro Carvalho Chehab7621b8c2017-11-01 17:05:43 -0400829 dprintk(1, "%s() returns id = 0x%x\n", __func__, id);
830 } else {
831 dprintk(1, "%s() returns error %d\n", __func__, ret);
Steven Tothe470d812008-06-21 21:06:02 -0300832 }
833
Steven Tothe470d812008-06-21 21:06:02 -0300834 return ret;
835}
836
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300837static void xc5000_config_tv(struct dvb_frontend *fe,
838 struct analog_parameters *params)
Steven Toth27c685a2008-01-05 16:50:14 -0300839{
840 struct xc5000_priv *priv = fe->tuner_priv;
Steven Toth27c685a2008-01-05 16:50:14 -0300841
Steven Toth27c685a2008-01-05 16:50:14 -0300842 dprintk(1, "%s() frequency=%d (in units of 62.5khz)\n",
Harvey Harrison271ddbf2008-04-08 23:20:00 -0300843 __func__, params->frequency);
Steven Toth27c685a2008-01-05 16:50:14 -0300844
Mauro Carvalho Chehab1fab14e2009-03-03 14:35:41 -0300845 /* Fix me: it could be air. */
846 priv->rf_mode = params->mode;
847 if (params->mode > XC_RF_MODE_CABLE)
848 priv->rf_mode = XC_RF_MODE_CABLE;
Steven Toth27c685a2008-01-05 16:50:14 -0300849
850 /* params->frequency is in units of 62.5khz */
851 priv->freq_hz = params->frequency * 62500;
852
853 /* FIX ME: Some video standards may have several possible audio
854 standards. We simply default to one of them here.
855 */
Steven Toth8f3cd532008-10-16 20:29:38 -0300856 if (params->std & V4L2_STD_MN) {
Steven Toth27c685a2008-01-05 16:50:14 -0300857 /* default to BTSC audio standard */
858 priv->video_standard = MN_NTSC_PAL_BTSC;
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300859 return;
Steven Toth27c685a2008-01-05 16:50:14 -0300860 }
861
Steven Toth8f3cd532008-10-16 20:29:38 -0300862 if (params->std & V4L2_STD_PAL_BG) {
Steven Toth27c685a2008-01-05 16:50:14 -0300863 /* default to NICAM audio standard */
864 priv->video_standard = BG_PAL_NICAM;
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300865 return;
Steven Toth27c685a2008-01-05 16:50:14 -0300866 }
867
Steven Toth8f3cd532008-10-16 20:29:38 -0300868 if (params->std & V4L2_STD_PAL_I) {
Steven Toth27c685a2008-01-05 16:50:14 -0300869 /* default to NICAM audio standard */
870 priv->video_standard = I_PAL_NICAM;
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300871 return;
Steven Toth27c685a2008-01-05 16:50:14 -0300872 }
873
Steven Toth8f3cd532008-10-16 20:29:38 -0300874 if (params->std & V4L2_STD_PAL_DK) {
Steven Toth27c685a2008-01-05 16:50:14 -0300875 /* default to NICAM audio standard */
876 priv->video_standard = DK_PAL_NICAM;
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300877 return;
Steven Toth27c685a2008-01-05 16:50:14 -0300878 }
879
Steven Toth8f3cd532008-10-16 20:29:38 -0300880 if (params->std & V4L2_STD_SECAM_DK) {
Steven Toth27c685a2008-01-05 16:50:14 -0300881 /* default to A2 DK1 audio standard */
882 priv->video_standard = DK_SECAM_A2DK1;
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300883 return;
Steven Toth27c685a2008-01-05 16:50:14 -0300884 }
885
Steven Toth8f3cd532008-10-16 20:29:38 -0300886 if (params->std & V4L2_STD_SECAM_L) {
Steven Toth27c685a2008-01-05 16:50:14 -0300887 priv->video_standard = L_SECAM_NICAM;
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300888 return;
Steven Toth27c685a2008-01-05 16:50:14 -0300889 }
890
Steven Toth8f3cd532008-10-16 20:29:38 -0300891 if (params->std & V4L2_STD_SECAM_LC) {
Steven Toth27c685a2008-01-05 16:50:14 -0300892 priv->video_standard = LC_SECAM_NICAM;
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300893 return;
Steven Toth27c685a2008-01-05 16:50:14 -0300894 }
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300895}
896
897static int xc5000_set_tv_freq(struct dvb_frontend *fe)
898{
899 struct xc5000_priv *priv = fe->tuner_priv;
900 u16 pll_lock_status;
901 int ret;
Steven Toth27c685a2008-01-05 16:50:14 -0300902
903tune_channel:
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300904 ret = xc_set_signal_source(priv, priv->rf_mode);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300905 if (ret != 0) {
Steven Toth8f3cd532008-10-16 20:29:38 -0300906 printk(KERN_ERR
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300907 "xc5000: xc_set_signal_source(%d) failed\n",
Steven Toth27c685a2008-01-05 16:50:14 -0300908 priv->rf_mode);
909 return -EREMOTEIO;
910 }
911
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300912 ret = xc_set_tv_standard(priv,
913 xc5000_standard[priv->video_standard].video_mode,
914 xc5000_standard[priv->video_standard].audio_mode, 0);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300915 if (ret != 0) {
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300916 printk(KERN_ERR "xc5000: xc_set_tv_standard failed\n");
Steven Toth27c685a2008-01-05 16:50:14 -0300917 return -EREMOTEIO;
918 }
919
Dmitri Belimov724dcbf2011-02-01 05:25:19 -0300920 xc_write_reg(priv, XREG_OUTPUT_AMP, 0x09);
921
Devin Heitmuellera78baac2008-11-16 20:48:31 -0300922 xc_tune_channel(priv, priv->freq_hz, XC_TUNE_ANALOG);
Steven Toth27c685a2008-01-05 16:50:14 -0300923
924 if (debug)
925 xc_debug_dump(priv);
926
Devin Heitmuellerde49bc62012-08-06 22:47:08 -0300927 if (priv->pll_register_no != 0) {
928 msleep(20);
Mauro Carvalho Chehab7621b8c2017-11-01 17:05:43 -0400929 ret = xc5000_readreg(priv, priv->pll_register_no,
930 &pll_lock_status);
931 if (ret)
932 return ret;
Devin Heitmuellerde49bc62012-08-06 22:47:08 -0300933 if (pll_lock_status > 63) {
934 /* PLL is unlocked, force reload of the firmware */
935 dprintk(1, "xc5000: PLL not locked (0x%x). Reloading...\n",
936 pll_lock_status);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300937 if (xc_load_fw_and_init_tuner(fe, 1) != 0) {
Devin Heitmuellerde49bc62012-08-06 22:47:08 -0300938 printk(KERN_ERR "xc5000: Unable to reload fw\n");
939 return -EREMOTEIO;
940 }
941 goto tune_channel;
942 }
943 }
944
Steven Toth27c685a2008-01-05 16:50:14 -0300945 return 0;
946}
947
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300948static int xc5000_config_radio(struct dvb_frontend *fe,
949 struct analog_parameters *params)
950
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -0300951{
952 struct xc5000_priv *priv = fe->tuner_priv;
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -0300953
954 dprintk(1, "%s() frequency=%d (in units of khz)\n",
955 __func__, params->frequency);
956
Devin Heitmueller496e9052009-09-24 13:27:24 -0300957 if (priv->radio_input == XC5000_RADIO_NOT_CONFIGURED) {
958 dprintk(1, "%s() radio input not configured\n", __func__);
959 return -EINVAL;
960 }
961
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -0300962 priv->freq_hz = params->frequency * 125 / 2;
963 priv->rf_mode = XC_RF_MODE_AIR;
964
965 return 0;
966}
967
968static int xc5000_set_radio_freq(struct dvb_frontend *fe)
969{
970 struct xc5000_priv *priv = fe->tuner_priv;
971 int ret;
972 u8 radio_input;
973
Devin Heitmueller496e9052009-09-24 13:27:24 -0300974 if (priv->radio_input == XC5000_RADIO_FM1)
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300975 radio_input = FM_RADIO_INPUT1;
Devin Heitmueller496e9052009-09-24 13:27:24 -0300976 else if (priv->radio_input == XC5000_RADIO_FM2)
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300977 radio_input = FM_RADIO_INPUT2;
Dmitri Belimov724dcbf2011-02-01 05:25:19 -0300978 else if (priv->radio_input == XC5000_RADIO_FM1_MONO)
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300979 radio_input = FM_RADIO_INPUT1_MONO;
Devin Heitmueller496e9052009-09-24 13:27:24 -0300980 else {
981 dprintk(1, "%s() unknown radio input %d\n", __func__,
982 priv->radio_input);
983 return -EINVAL;
984 }
985
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300986 ret = xc_set_tv_standard(priv, xc5000_standard[radio_input].video_mode,
987 xc5000_standard[radio_input].audio_mode, radio_input);
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -0300988
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300989 if (ret != 0) {
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300990 printk(KERN_ERR "xc5000: xc_set_tv_standard failed\n");
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -0300991 return -EREMOTEIO;
992 }
993
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300994 ret = xc_set_signal_source(priv, priv->rf_mode);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -0300995 if (ret != 0) {
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -0300996 printk(KERN_ERR
Mauro Carvalho Chehab303ddd92014-05-21 13:23:27 -0300997 "xc5000: xc_set_signal_source(%d) failed\n",
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -0300998 priv->rf_mode);
999 return -EREMOTEIO;
1000 }
1001
Dmitri Belimov724dcbf2011-02-01 05:25:19 -03001002 if ((priv->radio_input == XC5000_RADIO_FM1) ||
1003 (priv->radio_input == XC5000_RADIO_FM2))
1004 xc_write_reg(priv, XREG_OUTPUT_AMP, 0x09);
1005 else if (priv->radio_input == XC5000_RADIO_FM1_MONO)
1006 xc_write_reg(priv, XREG_OUTPUT_AMP, 0x06);
1007
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -03001008 xc_tune_channel(priv, priv->freq_hz, XC_TUNE_ANALOG);
1009
1010 return 0;
1011}
1012
Mauro Carvalho Chehab59b94f3e2014-08-09 21:47:24 -03001013static int xc5000_set_params(struct dvb_frontend *fe)
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -03001014{
1015 struct xc5000_priv *priv = fe->tuner_priv;
1016
Mauro Carvalho Chehab5275a3b2014-08-09 23:14:22 -03001017 if (xc_load_fw_and_init_tuner(fe, 0) != 0) {
1018 dprintk(1, "Unable to load firmware and init tuner\n");
1019 return -EINVAL;
1020 }
1021
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -03001022 switch (priv->mode) {
1023 case V4L2_TUNER_RADIO:
1024 return xc5000_set_radio_freq(fe);
1025 case V4L2_TUNER_ANALOG_TV:
1026 return xc5000_set_tv_freq(fe);
1027 case V4L2_TUNER_DIGITAL_TV:
1028 return xc5000_tune_digital(fe);
1029 }
1030
1031 return 0;
1032}
1033
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -03001034static int xc5000_set_analog_params(struct dvb_frontend *fe,
1035 struct analog_parameters *params)
1036{
1037 struct xc5000_priv *priv = fe->tuner_priv;
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -03001038 int ret;
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -03001039
1040 if (priv->i2c_props.adap == NULL)
1041 return -EINVAL;
1042
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -03001043 switch (params->mode) {
1044 case V4L2_TUNER_RADIO:
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -03001045 ret = xc5000_config_radio(fe, params);
1046 if (ret)
1047 return ret;
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -03001048 break;
1049 case V4L2_TUNER_ANALOG_TV:
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -03001050 xc5000_config_tv(fe, params);
1051 break;
1052 default:
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -03001053 break;
1054 }
Mauro Carvalho Chehabc3d66762014-08-09 21:47:22 -03001055 priv->mode = params->mode;
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -03001056
Mauro Carvalho Chehab59b94f3e2014-08-09 21:47:24 -03001057 return xc5000_set_params(fe);
Beholder Intl. Ltd. Dmitry Belimovd7009cd2009-09-24 13:13:28 -03001058}
1059
Steven Tothaacb9d32007-12-18 01:55:51 -03001060static int xc5000_get_frequency(struct dvb_frontend *fe, u32 *freq)
1061{
1062 struct xc5000_priv *priv = fe->tuner_priv;
Harvey Harrison271ddbf2008-04-08 23:20:00 -03001063 dprintk(1, "%s()\n", __func__);
Mauro Carvalho Chehaba3eec912014-07-21 14:21:18 -03001064 *freq = priv->freq_hz + priv->freq_offset;
Steven Tothaacb9d32007-12-18 01:55:51 -03001065 return 0;
1066}
1067
Mauro Carvalho Chehab35621032011-09-23 13:03:42 -03001068static int xc5000_get_if_frequency(struct dvb_frontend *fe, u32 *freq)
1069{
1070 struct xc5000_priv *priv = fe->tuner_priv;
1071 dprintk(1, "%s()\n", __func__);
1072 *freq = priv->if_khz * 1000;
1073 return 0;
1074}
1075
Steven Tothaacb9d32007-12-18 01:55:51 -03001076static int xc5000_get_bandwidth(struct dvb_frontend *fe, u32 *bw)
1077{
1078 struct xc5000_priv *priv = fe->tuner_priv;
Harvey Harrison271ddbf2008-04-08 23:20:00 -03001079 dprintk(1, "%s()\n", __func__);
Steven Toth27c685a2008-01-05 16:50:14 -03001080
Steven Tothaacb9d32007-12-18 01:55:51 -03001081 *bw = priv->bandwidth;
1082 return 0;
1083}
1084
1085static int xc5000_get_status(struct dvb_frontend *fe, u32 *status)
1086{
1087 struct xc5000_priv *priv = fe->tuner_priv;
Steven Tothe12671cf2007-12-20 01:14:43 -03001088 u16 lock_status = 0;
Steven Tothaacb9d32007-12-18 01:55:51 -03001089
1090 xc_get_lock_status(priv, &lock_status);
1091
Harvey Harrison271ddbf2008-04-08 23:20:00 -03001092 dprintk(1, "%s() lock_status = 0x%08x\n", __func__, lock_status);
Steven Tothaacb9d32007-12-18 01:55:51 -03001093
1094 *status = lock_status;
1095
1096 return 0;
1097}
1098
Devin Heitmuellerde49bc62012-08-06 22:47:08 -03001099static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force)
Steven Tothaacb9d32007-12-18 01:55:51 -03001100{
1101 struct xc5000_priv *priv = fe->tuner_priv;
Mauro Carvalho Chehab8604f352014-07-30 11:09:15 -03001102 const struct xc5000_fw_cfg *desired_fw = xc5000_assign_firmware(priv->chip_id);
1103 const struct firmware *fw;
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001104 int ret, i;
Devin Heitmuellerde49bc62012-08-06 22:47:08 -03001105 u16 pll_lock_status;
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -03001106 u16 fw_ck;
Steven Tothaacb9d32007-12-18 01:55:51 -03001107
Mauro Carvalho Chehabf7a27ff2014-05-21 13:57:30 -03001108 cancel_delayed_work(&priv->timer_sleep);
1109
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001110 if (!force && xc5000_is_firmware_loaded(fe) == 0)
1111 return 0;
Devin Heitmuellerde49bc62012-08-06 22:47:08 -03001112
Shuah Khan5264a522014-09-22 21:30:46 -03001113 if (!priv->firmware) {
1114 ret = request_firmware(&fw, desired_fw->name,
1115 priv->i2c_props.adap->dev.parent);
1116 if (ret) {
1117 pr_err("xc5000: Upload failed. rc %d\n", ret);
1118 return ret;
1119 }
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08001120 dprintk(1, "firmware read %zu bytes.\n", fw->size);
Mauro Carvalho Chehab8604f352014-07-30 11:09:15 -03001121
Shuah Khan5264a522014-09-22 21:30:46 -03001122 if (fw->size != desired_fw->size) {
1123 pr_err("xc5000: Firmware file with incorrect size\n");
1124 release_firmware(fw);
1125 return -EINVAL;
1126 }
1127 priv->firmware = fw;
1128 } else
1129 fw = priv->firmware;
Mauro Carvalho Chehab8604f352014-07-30 11:09:15 -03001130
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001131 /* Try up to 5 times to load firmware */
1132 for (i = 0; i < 5; i++) {
Mauro Carvalho Chehabee676742014-07-30 11:17:46 -03001133 if (i)
1134 printk(KERN_CONT " - retrying to upload firmware.\n");
1135
Mauro Carvalho Chehab8604f352014-07-30 11:09:15 -03001136 ret = xc5000_fwupload(fe, desired_fw, fw);
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -03001137 if (ret != 0)
Mauro Carvalho Chehab8604f352014-07-30 11:09:15 -03001138 goto err;
Devin Heitmuellerfc7a74b2012-08-06 22:47:01 -03001139
Devin Heitmuellerde49bc62012-08-06 22:47:08 -03001140 msleep(20);
1141
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -03001142 if (priv->fw_checksum_supported) {
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001143 if (xc5000_readreg(priv, XREG_FW_CHECKSUM, &fw_ck)) {
Mauro Carvalho Chehabee676742014-07-30 11:17:46 -03001144 printk(KERN_ERR
1145 "xc5000: FW checksum reading failed.");
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001146 continue;
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -03001147 }
1148
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001149 if (!fw_ck) {
Mauro Carvalho Chehabee676742014-07-30 11:17:46 -03001150 printk(KERN_ERR
1151 "xc5000: FW checksum failed = 0x%04x.",
1152 fw_ck);
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001153 continue;
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -03001154 }
1155 }
1156
Devin Heitmuellerfc7a74b2012-08-06 22:47:01 -03001157 /* Start the tuner self-calibration process */
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001158 ret = xc_initialize(priv);
1159 if (ret) {
Colin Ian King26c7e7b2017-04-12 11:04:13 -03001160 printk(KERN_ERR "xc5000: Can't request self-calibration.");
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001161 continue;
1162 }
Devin Heitmuellerde49bc62012-08-06 22:47:08 -03001163
Devin Heitmuellerfc7a74b2012-08-06 22:47:01 -03001164 /* Wait for calibration to complete.
1165 * We could continue but XC5000 will clock stretch subsequent
1166 * I2C transactions until calibration is complete. This way we
1167 * don't have to rely on clock stretching working.
1168 */
Mauro Carvalho Chehabe5bf4a12014-05-21 13:15:17 -03001169 msleep(100);
Devin Heitmuellerfc7a74b2012-08-06 22:47:01 -03001170
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -03001171 if (priv->init_status_supported) {
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001172 if (xc5000_readreg(priv, XREG_INIT_STATUS, &fw_ck)) {
Mauro Carvalho Chehabee676742014-07-30 11:17:46 -03001173 printk(KERN_ERR
1174 "xc5000: FW failed reading init status.");
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001175 continue;
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -03001176 }
1177
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001178 if (!fw_ck) {
Mauro Carvalho Chehabee676742014-07-30 11:17:46 -03001179 printk(KERN_ERR
1180 "xc5000: FW init status failed = 0x%04x.",
1181 fw_ck);
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001182 continue;
Devin Heitmueller22d5c6f2012-08-06 22:47:09 -03001183 }
1184 }
1185
Devin Heitmuellerde49bc62012-08-06 22:47:08 -03001186 if (priv->pll_register_no) {
Mauro Carvalho Chehab7621b8c2017-11-01 17:05:43 -04001187 ret = xc5000_readreg(priv, priv->pll_register_no,
1188 &pll_lock_status);
1189 if (ret)
1190 continue;
Devin Heitmuellerde49bc62012-08-06 22:47:08 -03001191 if (pll_lock_status > 63) {
1192 /* PLL is unlocked, force reload of the firmware */
Mauro Carvalho Chehabee676742014-07-30 11:17:46 -03001193 printk(KERN_ERR
1194 "xc5000: PLL not running after fwload.");
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001195 continue;
Devin Heitmuellerde49bc62012-08-06 22:47:08 -03001196 }
1197 }
1198
Devin Heitmuellerfc7a74b2012-08-06 22:47:01 -03001199 /* Default to "CABLE" mode */
Mauro Carvalho Chehab2621c0b2014-07-30 10:36:32 -03001200 ret = xc_write_reg(priv, XREG_SIGNALSOURCE, XC_RF_MODE_CABLE);
Mauro Carvalho Chehabee676742014-07-30 11:17:46 -03001201 if (!ret)
1202 break;
1203 printk(KERN_ERR "xc5000: can't set to cable mode.");
Steven Tothaacb9d32007-12-18 01:55:51 -03001204 }
1205
Mauro Carvalho Chehab8604f352014-07-30 11:09:15 -03001206err:
Mauro Carvalho Chehabee676742014-07-30 11:17:46 -03001207 if (!ret)
1208 printk(KERN_INFO "xc5000: Firmware %s loaded and running.\n",
1209 desired_fw->name);
1210 else
1211 printk(KERN_CONT " - too many retries. Giving up\n");
1212
Steven Tothaacb9d32007-12-18 01:55:51 -03001213 return ret;
1214}
1215
Mauro Carvalho Chehabf7a27ff2014-05-21 13:57:30 -03001216static void xc5000_do_timer_sleep(struct work_struct *timer_sleep)
1217{
1218 struct xc5000_priv *priv =container_of(timer_sleep, struct xc5000_priv,
1219 timer_sleep.work);
1220 struct dvb_frontend *fe = priv->fe;
1221 int ret;
1222
1223 dprintk(1, "%s()\n", __func__);
1224
1225 /* According to Xceive technical support, the "powerdown" register
1226 was removed in newer versions of the firmware. The "supported"
1227 way to sleep the tuner is to pull the reset pin low for 10ms */
1228 ret = xc5000_tuner_reset(fe);
1229 if (ret != 0)
1230 printk(KERN_ERR
1231 "xc5000: %s() unable to shutdown tuner\n",
1232 __func__);
1233}
1234
Steven Tothe12671cf2007-12-20 01:14:43 -03001235static int xc5000_sleep(struct dvb_frontend *fe)
1236{
Mauro Carvalho Chehabf7a27ff2014-05-21 13:57:30 -03001237 struct xc5000_priv *priv = fe->tuner_priv;
Steven Toth27c685a2008-01-05 16:50:14 -03001238
Harvey Harrison271ddbf2008-04-08 23:20:00 -03001239 dprintk(1, "%s()\n", __func__);
Steven Tothe12671cf2007-12-20 01:14:43 -03001240
Devin Heitmuellerb6bd5eb2009-04-28 13:53:38 -03001241 /* Avoid firmware reload on slow devices */
1242 if (no_poweroff)
1243 return 0;
1244
Mauro Carvalho Chehabf7a27ff2014-05-21 13:57:30 -03001245 schedule_delayed_work(&priv->timer_sleep,
1246 msecs_to_jiffies(XC5000_SLEEP_TIME));
1247
1248 return 0;
Steven Tothe12671cf2007-12-20 01:14:43 -03001249}
1250
Mauro Carvalho Chehab91a53072014-08-09 21:47:20 -03001251static int xc5000_suspend(struct dvb_frontend *fe)
1252{
1253 struct xc5000_priv *priv = fe->tuner_priv;
1254 int ret;
1255
1256 dprintk(1, "%s()\n", __func__);
1257
1258 cancel_delayed_work(&priv->timer_sleep);
1259
1260 ret = xc5000_tuner_reset(fe);
1261 if (ret != 0)
1262 printk(KERN_ERR
1263 "xc5000: %s() unable to shutdown tuner\n",
1264 __func__);
1265
1266 return 0;
1267}
1268
Shuah Khan27ccd692014-08-13 22:09:24 -03001269static int xc5000_resume(struct dvb_frontend *fe)
1270{
1271 struct xc5000_priv *priv = fe->tuner_priv;
1272
1273 dprintk(1, "%s()\n", __func__);
1274
1275 /* suspended before firmware is loaded.
1276 Avoid firmware load in resume path. */
1277 if (!priv->firmware)
1278 return 0;
1279
1280 return xc5000_set_params(fe);
1281}
1282
Steven Tothaacb9d32007-12-18 01:55:51 -03001283static int xc5000_init(struct dvb_frontend *fe)
1284{
1285 struct xc5000_priv *priv = fe->tuner_priv;
Harvey Harrison271ddbf2008-04-08 23:20:00 -03001286 dprintk(1, "%s()\n", __func__);
Steven Tothaacb9d32007-12-18 01:55:51 -03001287
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -03001288 if (xc_load_fw_and_init_tuner(fe, 0) != 0) {
Steven Tothe12671cf2007-12-20 01:14:43 -03001289 printk(KERN_ERR "xc5000: Unable to initialise tuner\n");
1290 return -EREMOTEIO;
1291 }
1292
1293 if (debug)
1294 xc_debug_dump(priv);
Steven Tothaacb9d32007-12-18 01:55:51 -03001295
1296 return 0;
1297}
1298
Max Kellermann194ced72016-08-09 18:32:31 -03001299static void xc5000_release(struct dvb_frontend *fe)
Steven Tothaacb9d32007-12-18 01:55:51 -03001300{
Michael Krufky89fd2852008-09-06 11:44:53 -03001301 struct xc5000_priv *priv = fe->tuner_priv;
1302
Harvey Harrison271ddbf2008-04-08 23:20:00 -03001303 dprintk(1, "%s()\n", __func__);
Michael Krufky89fd2852008-09-06 11:44:53 -03001304
1305 mutex_lock(&xc5000_list_mutex);
1306
Mauro Carvalho Chehabf7a27ff2014-05-21 13:57:30 -03001307 if (priv) {
1308 cancel_delayed_work(&priv->timer_sleep);
Devin Heitmueller856260a2014-09-22 21:30:46 -03001309 if (priv->firmware) {
1310 release_firmware(priv->firmware);
1311 priv->firmware = NULL;
1312 }
Dan Carpenter4961a532014-09-25 08:40:08 -03001313 hybrid_tuner_release_state(priv);
Mauro Carvalho Chehabf7a27ff2014-05-21 13:57:30 -03001314 }
Michael Krufky89fd2852008-09-06 11:44:53 -03001315
1316 mutex_unlock(&xc5000_list_mutex);
1317
Steven Tothaacb9d32007-12-18 01:55:51 -03001318 fe->tuner_priv = NULL;
Steven Tothaacb9d32007-12-18 01:55:51 -03001319}
1320
Dmitri Belimov724dcbf2011-02-01 05:25:19 -03001321static int xc5000_set_config(struct dvb_frontend *fe, void *priv_cfg)
1322{
1323 struct xc5000_priv *priv = fe->tuner_priv;
1324 struct xc5000_config *p = priv_cfg;
1325
1326 dprintk(1, "%s()\n", __func__);
1327
1328 if (p->if_khz)
1329 priv->if_khz = p->if_khz;
1330
1331 if (p->radio_input)
1332 priv->radio_input = p->radio_input;
1333
Richard Vollkommer52e269b2014-10-25 17:17:22 -03001334 if (p->output_amp)
1335 priv->output_amp = p->output_amp;
1336
Dmitri Belimov724dcbf2011-02-01 05:25:19 -03001337 return 0;
1338}
1339
1340
Steven Tothaacb9d32007-12-18 01:55:51 -03001341static const struct dvb_tuner_ops xc5000_tuner_ops = {
1342 .info = {
Mauro Carvalho Chehaba3f90c72018-07-05 18:59:35 -04001343 .name = "Xceive XC5000",
1344 .frequency_min_hz = 1 * MHz,
1345 .frequency_max_hz = 1023 * MHz,
1346 .frequency_step_hz = 50 * kHz,
Steven Tothaacb9d32007-12-18 01:55:51 -03001347 },
1348
Steven Toth27c685a2008-01-05 16:50:14 -03001349 .release = xc5000_release,
1350 .init = xc5000_init,
1351 .sleep = xc5000_sleep,
Mauro Carvalho Chehab91a53072014-08-09 21:47:20 -03001352 .suspend = xc5000_suspend,
Shuah Khan27ccd692014-08-13 22:09:24 -03001353 .resume = xc5000_resume,
Steven Tothaacb9d32007-12-18 01:55:51 -03001354
Dmitri Belimov724dcbf2011-02-01 05:25:19 -03001355 .set_config = xc5000_set_config,
Mauro Carvalho Chehab59b94f3e2014-08-09 21:47:24 -03001356 .set_params = xc5000_set_digital_params,
Steven Toth27c685a2008-01-05 16:50:14 -03001357 .set_analog_params = xc5000_set_analog_params,
1358 .get_frequency = xc5000_get_frequency,
Mauro Carvalho Chehab35621032011-09-23 13:03:42 -03001359 .get_if_frequency = xc5000_get_if_frequency,
Steven Toth27c685a2008-01-05 16:50:14 -03001360 .get_bandwidth = xc5000_get_bandwidth,
1361 .get_status = xc5000_get_status
Steven Tothaacb9d32007-12-18 01:55:51 -03001362};
1363
Michael Krufky48723542008-05-10 14:34:09 -03001364struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe,
1365 struct i2c_adapter *i2c,
lawrence rust2e4e98e2010-08-25 09:50:20 -03001366 const struct xc5000_config *cfg)
Steven Tothaacb9d32007-12-18 01:55:51 -03001367{
1368 struct xc5000_priv *priv = NULL;
Michael Krufky89fd2852008-09-06 11:44:53 -03001369 int instance;
Steven Tothaacb9d32007-12-18 01:55:51 -03001370 u16 id = 0;
1371
Michael Krufky89fd2852008-09-06 11:44:53 -03001372 dprintk(1, "%s(%d-%04x)\n", __func__,
1373 i2c ? i2c_adapter_id(i2c) : -1,
1374 cfg ? cfg->i2c_address : -1);
Steven Tothaacb9d32007-12-18 01:55:51 -03001375
Michael Krufky89fd2852008-09-06 11:44:53 -03001376 mutex_lock(&xc5000_list_mutex);
Steven Tothaacb9d32007-12-18 01:55:51 -03001377
Michael Krufky89fd2852008-09-06 11:44:53 -03001378 instance = hybrid_tuner_request_state(struct xc5000_priv, priv,
1379 hybrid_tuner_instance_list,
1380 i2c, cfg->i2c_address, "xc5000");
1381 switch (instance) {
1382 case 0:
1383 goto fail;
Michael Krufky89fd2852008-09-06 11:44:53 -03001384 case 1:
1385 /* new tuner instance */
Mauro Carvalho Chehabc6f56e72011-12-26 20:02:28 -03001386 priv->bandwidth = 6000000;
Michael Krufky89fd2852008-09-06 11:44:53 -03001387 fe->tuner_priv = priv;
Mauro Carvalho Chehabf7a27ff2014-05-21 13:57:30 -03001388 priv->fe = fe;
1389 INIT_DELAYED_WORK(&priv->timer_sleep, xc5000_do_timer_sleep);
Michael Krufky89fd2852008-09-06 11:44:53 -03001390 break;
1391 default:
1392 /* existing tuner instance */
1393 fe->tuner_priv = priv;
1394 break;
1395 }
Steven Tothaacb9d32007-12-18 01:55:51 -03001396
Devin Heitmuellerea227862009-03-11 02:58:53 -03001397 if (priv->if_khz == 0) {
1398 /* If the IF hasn't been set yet, use the value provided by
1399 the caller (occurs in hybrid devices where the analog
1400 call to xc5000_attach occurs before the digital side) */
1401 priv->if_khz = cfg->if_khz;
1402 }
1403
Michael Krufky7d3d0d82012-04-16 14:59:32 -03001404 if (priv->xtal_khz == 0)
1405 priv->xtal_khz = cfg->xtal_khz;
1406
Devin Heitmueller496e9052009-09-24 13:27:24 -03001407 if (priv->radio_input == 0)
1408 priv->radio_input = cfg->radio_input;
1409
Michael Krufky6fab81d2012-02-08 14:57:39 -03001410 /* don't override chip id if it's already been set
Michael Krufky76efb0ba2012-02-06 19:40:32 -03001411 unless explicitly specified */
Michael Krufky6fab81d2012-02-08 14:57:39 -03001412 if ((priv->chip_id == 0) || (cfg->chip_id))
1413 /* use default chip id if none specified, set to 0 so
1414 it can be overridden if this is a hybrid driver */
1415 priv->chip_id = (cfg->chip_id) ? cfg->chip_id : 0;
Michael Krufky76efb0ba2012-02-06 19:40:32 -03001416
Richard Vollkommer52e269b2014-10-25 17:17:22 -03001417 /* don't override output_amp if it's already been set
1418 unless explicitly specified */
1419 if ((priv->output_amp == 0) || (cfg->output_amp))
1420 /* use default output_amp value if none specified */
1421 priv->output_amp = (cfg->output_amp) ? cfg->output_amp : 0x8a;
1422
Steven Toth27c685a2008-01-05 16:50:14 -03001423 /* Check if firmware has been loaded. It is possible that another
1424 instance of the driver has loaded the firmware.
1425 */
Mauro Carvalho Chehab859ae7f2014-05-21 13:08:18 -03001426 if (xc5000_readreg(priv, XREG_PRODUCT_ID, &id) != 0)
Michael Krufky89fd2852008-09-06 11:44:53 -03001427 goto fail;
Steven Tothaacb9d32007-12-18 01:55:51 -03001428
Steven Toth8f3cd532008-10-16 20:29:38 -03001429 switch (id) {
Steven Toth27c685a2008-01-05 16:50:14 -03001430 case XC_PRODUCT_ID_FW_LOADED:
1431 printk(KERN_INFO
1432 "xc5000: Successfully identified at address 0x%02x\n",
1433 cfg->i2c_address);
1434 printk(KERN_INFO
1435 "xc5000: Firmware has been loaded previously\n");
Steven Toth27c685a2008-01-05 16:50:14 -03001436 break;
1437 case XC_PRODUCT_ID_FW_NOT_LOADED:
1438 printk(KERN_INFO
1439 "xc5000: Successfully identified at address 0x%02x\n",
1440 cfg->i2c_address);
1441 printk(KERN_INFO
1442 "xc5000: Firmware has not been loaded previously\n");
Steven Toth27c685a2008-01-05 16:50:14 -03001443 break;
1444 default:
Steven Tothaacb9d32007-12-18 01:55:51 -03001445 printk(KERN_ERR
1446 "xc5000: Device not found at addr 0x%02x (0x%x)\n",
1447 cfg->i2c_address, id);
Michael Krufky89fd2852008-09-06 11:44:53 -03001448 goto fail;
Steven Tothaacb9d32007-12-18 01:55:51 -03001449 }
1450
Michael Krufky89fd2852008-09-06 11:44:53 -03001451 mutex_unlock(&xc5000_list_mutex);
1452
Steven Tothaacb9d32007-12-18 01:55:51 -03001453 memcpy(&fe->ops.tuner_ops, &xc5000_tuner_ops,
1454 sizeof(struct dvb_tuner_ops));
1455
Steven Tothaacb9d32007-12-18 01:55:51 -03001456 return fe;
Michael Krufky89fd2852008-09-06 11:44:53 -03001457fail:
1458 mutex_unlock(&xc5000_list_mutex);
1459
1460 xc5000_release(fe);
1461 return NULL;
Steven Tothaacb9d32007-12-18 01:55:51 -03001462}
1463EXPORT_SYMBOL(xc5000_attach);
1464
1465MODULE_AUTHOR("Steven Toth");
Steven Tothe12671cf2007-12-20 01:14:43 -03001466MODULE_DESCRIPTION("Xceive xc5000 silicon tuner driver");
Steven Tothaacb9d32007-12-18 01:55:51 -03001467MODULE_LICENSE("GPL");
Tim Gardner3422f2a62012-07-25 09:15:19 -03001468MODULE_FIRMWARE(XC5000A_FIRMWARE);
1469MODULE_FIRMWARE(XC5000C_FIRMWARE);