Thomas Gleixner | c942fdd | 2019-05-27 08:55:06 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 2 | /* |
| 3 | * Driver for Xceive XC5000 "QAM/8VSB single chip tuner" |
| 4 | * |
| 5 | * Copyright (c) 2007 Xceive Corporation |
Steven Toth | 6d89761 | 2008-09-03 17:12:12 -0300 | [diff] [blame] | 6 | * Copyright (c) 2007 Steven Toth <stoth@linuxtv.org> |
Devin Heitmueller | e80858e | 2009-05-14 21:31:11 -0300 | [diff] [blame] | 7 | * Copyright (c) 2009 Devin Heitmueller <dheitmueller@kernellabs.com> |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/moduleparam.h> |
Steven Toth | 4917019 | 2008-01-15 21:57:14 -0300 | [diff] [blame] | 12 | #include <linux/videodev2.h> |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 13 | #include <linux/delay.h> |
Mauro Carvalho Chehab | f7a27ff | 2014-05-21 13:57:30 -0300 | [diff] [blame] | 14 | #include <linux/workqueue.h> |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 15 | #include <linux/dvb/frontend.h> |
| 16 | #include <linux/i2c.h> |
| 17 | |
Mauro Carvalho Chehab | fada193 | 2017-12-28 13:03:51 -0500 | [diff] [blame] | 18 | #include <media/dvb_frontend.h> |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 19 | |
| 20 | #include "xc5000.h" |
Michael Krufky | 89fd285 | 2008-09-06 11:44:53 -0300 | [diff] [blame] | 21 | #include "tuner-i2c.h" |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 22 | |
| 23 | static int debug; |
| 24 | module_param(debug, int, 0644); |
| 25 | MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off)."); |
| 26 | |
Devin Heitmueller | b6bd5eb | 2009-04-28 13:53:38 -0300 | [diff] [blame] | 27 | static int no_poweroff; |
| 28 | module_param(no_poweroff, int, 0644); |
| 29 | MODULE_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 Krufky | 89fd285 | 2008-09-06 11:44:53 -0300 | [diff] [blame] | 33 | static DEFINE_MUTEX(xc5000_list_mutex); |
| 34 | static LIST_HEAD(hybrid_tuner_instance_list); |
| 35 | |
Steven Toth | 8f3cd53 | 2008-10-16 20:29:38 -0300 | [diff] [blame] | 36 | #define dprintk(level, fmt, arg...) if (debug >= level) \ |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 37 | printk(KERN_INFO "%s: " fmt, "xc5000", ## arg) |
| 38 | |
Michael Krufky | ffb4123 | 2008-09-06 10:52:30 -0300 | [diff] [blame] | 39 | struct xc5000_priv { |
Michael Krufky | 89fd285 | 2008-09-06 11:44:53 -0300 | [diff] [blame] | 40 | struct tuner_i2c_props i2c_props; |
| 41 | struct list_head hybrid_tuner_instance_list; |
Michael Krufky | ffb4123 | 2008-09-06 10:52:30 -0300 | [diff] [blame] | 42 | |
Michael Krufky | 2a6003c | 2008-09-06 13:54:45 -0300 | [diff] [blame] | 43 | u32 if_khz; |
Michael Krufky | 409328a4 | 2012-04-16 15:21:51 -0300 | [diff] [blame] | 44 | u16 xtal_khz; |
Mauro Carvalho Chehab | a3eec91 | 2014-07-21 14:21:18 -0300 | [diff] [blame] | 45 | u32 freq_hz, freq_offset; |
Michael Krufky | ffb4123 | 2008-09-06 10:52:30 -0300 | [diff] [blame] | 46 | u32 bandwidth; |
| 47 | u8 video_standard; |
Mauro Carvalho Chehab | 1643520 | 2014-08-09 21:47:21 -0300 | [diff] [blame] | 48 | unsigned int mode; |
Michael Krufky | ffb4123 | 2008-09-06 10:52:30 -0300 | [diff] [blame] | 49 | u8 rf_mode; |
Devin Heitmueller | 496e905 | 2009-09-24 13:27:24 -0300 | [diff] [blame] | 50 | u8 radio_input; |
Richard Vollkommer | 52e269b | 2014-10-25 17:17:22 -0300 | [diff] [blame] | 51 | u16 output_amp; |
Michael Krufky | 76efb0ba | 2012-02-06 19:40:32 -0300 | [diff] [blame] | 52 | |
Michael Krufky | 6fab81d | 2012-02-08 14:57:39 -0300 | [diff] [blame] | 53 | int chip_id; |
Devin Heitmueller | de49bc6 | 2012-08-06 22:47:08 -0300 | [diff] [blame] | 54 | u16 pll_register_no; |
Devin Heitmueller | 22d5c6f | 2012-08-06 22:47:09 -0300 | [diff] [blame] | 55 | u8 init_status_supported; |
| 56 | u8 fw_checksum_supported; |
Mauro Carvalho Chehab | f7a27ff | 2014-05-21 13:57:30 -0300 | [diff] [blame] | 57 | |
| 58 | struct dvb_frontend *fe; |
| 59 | struct delayed_work timer_sleep; |
Shuah Khan | 5264a52 | 2014-09-22 21:30:46 -0300 | [diff] [blame] | 60 | |
| 61 | const struct firmware *firmware; |
Michael Krufky | ffb4123 | 2008-09-06 10:52:30 -0300 | [diff] [blame] | 62 | }; |
| 63 | |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 64 | /* Misc Defines */ |
Dmitri Belimov | 724dcbf | 2011-02-01 05:25:19 -0300 | [diff] [blame] | 65 | #define MAX_TV_STANDARD 24 |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 66 | #define XC_MAX_I2C_WRITE_LENGTH 64 |
| 67 | |
Mauro Carvalho Chehab | f7a27ff | 2014-05-21 13:57:30 -0300 | [diff] [blame] | 68 | /* Time to suspend after the .sleep callback is called */ |
| 69 | #define XC5000_SLEEP_TIME 5000 /* ms */ |
| 70 | |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 71 | /* Signal Types */ |
| 72 | #define XC_RF_MODE_AIR 0 |
| 73 | #define XC_RF_MODE_CABLE 1 |
| 74 | |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 75 | /* Product id */ |
| 76 | #define XC_PRODUCT_ID_FW_NOT_LOADED 0x2000 |
Mauro Carvalho Chehab | 5015c27 | 2014-05-21 13:41:01 -0300 | [diff] [blame] | 77 | #define XC_PRODUCT_ID_FW_LOADED 0x1388 |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 78 | |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 79 | /* 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 Heitmueller | 7f05b53 | 2009-04-02 22:02:39 -0300 | [diff] [blame] | 87 | #define XREG_POWER_DOWN 0x0A /* Obsolete */ |
Dmitri Belimov | 724dcbf | 2011-02-01 05:25:19 -0300 | [diff] [blame] | 88 | /* Set the output amplitude - SIF for analog, DTVP/DTVN for digital */ |
| 89 | #define XREG_OUTPUT_AMP 0x0B |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 90 | #define XREG_SIGNALSOURCE 0x0D /* 0=Air, 1=Cable */ |
| 91 | #define XREG_SMOOTHEDCVBS 0x0E |
| 92 | #define XREG_XTALFREQ 0x0F |
Devin Heitmueller | 81c4dfe | 2009-04-02 22:40:29 -0300 | [diff] [blame] | 93 | #define XREG_FINERFREQ 0x10 |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 94 | #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 Heitmueller | bae7b7d | 2009-04-02 22:24:38 -0300 | [diff] [blame] | 106 | #define XREG_BUILD 0x0D |
Devin Heitmueller | 7c287f1 | 2012-08-06 22:46:56 -0300 | [diff] [blame] | 107 | #define XREG_TOTALGAIN 0x0F |
Devin Heitmueller | 22d5c6f | 2012-08-06 22:47:09 -0300 | [diff] [blame] | 108 | #define XREG_FW_CHECKSUM 0x12 |
| 109 | #define XREG_INIT_STATUS 0x13 |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 110 | |
| 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 Toth | 8f3cd53 | 2008-10-16 20:29:38 -0300 | [diff] [blame] | 144 | struct XC_TV_STANDARD { |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 145 | char *name; |
| 146 | u16 audio_mode; |
| 147 | u16 video_mode; |
Steven Toth | 8f3cd53 | 2008-10-16 20:29:38 -0300 | [diff] [blame] | 148 | }; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 149 | |
| 150 | /* Tuner standards */ |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 151 | #define MN_NTSC_PAL_BTSC 0 |
| 152 | #define MN_NTSC_PAL_A2 1 |
| 153 | #define MN_NTSC_PAL_EIAJ 2 |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 154 | #define MN_NTSC_PAL_MONO 3 |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 155 | #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 Chehab | 5015c27 | 2014-05-21 13:41:01 -0300 | [diff] [blame] | 164 | #define DK_SECAM_A2LDK3 13 |
| 165 | #define DK_SECAM_A2MONO 14 |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 166 | #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 Chehab | 5015c27 | 2014-05-21 13:41:01 -0300 | [diff] [blame] | 172 | #define FM_RADIO_INPUT2 21 |
| 173 | #define FM_RADIO_INPUT1 22 |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 174 | #define FM_RADIO_INPUT1_MONO 23 |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 175 | |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 176 | static struct XC_TV_STANDARD xc5000_standard[MAX_TV_STANDARD] = { |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 177 | {"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 Toth | 8f3cd53 | 2008-10-16 20:29:38 -0300 | [diff] [blame] | 190 | {"D/K-SECAM-A2 L/DK3", 0x0E00, 0x8009}, |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 191 | {"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 Belimov | 724dcbf | 2011-02-01 05:25:19 -0300 | [diff] [blame] | 199 | {"FM Radio-INPUT1", 0x0208, 0x9002}, |
| 200 | {"FM Radio-INPUT1_MONO", 0x0278, 0x9002} |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 201 | }; |
| 202 | |
Michael Krufky | ddea427 | 2012-02-07 02:39:36 -0300 | [diff] [blame] | 203 | |
| 204 | struct xc5000_fw_cfg { |
| 205 | char *name; |
| 206 | u16 size; |
Devin Heitmueller | de49bc6 | 2012-08-06 22:47:08 -0300 | [diff] [blame] | 207 | u16 pll_reg; |
Devin Heitmueller | 22d5c6f | 2012-08-06 22:47:09 -0300 | [diff] [blame] | 208 | u8 init_status_supported; |
| 209 | u8 fw_checksum_supported; |
Michael Krufky | ddea427 | 2012-02-07 02:39:36 -0300 | [diff] [blame] | 210 | }; |
| 211 | |
Tim Gardner | 3422f2a6 | 2012-07-25 09:15:19 -0300 | [diff] [blame] | 212 | #define XC5000A_FIRMWARE "dvb-fe-xc5000-1.6.114.fw" |
Michael Krufky | a3db60b | 2012-02-08 15:03:07 -0300 | [diff] [blame] | 213 | static const struct xc5000_fw_cfg xc5000a_1_6_114 = { |
Tim Gardner | 3422f2a6 | 2012-07-25 09:15:19 -0300 | [diff] [blame] | 214 | .name = XC5000A_FIRMWARE, |
Michael Krufky | 76efb0ba | 2012-02-06 19:40:32 -0300 | [diff] [blame] | 215 | .size = 12401, |
Devin Heitmueller | de49bc6 | 2012-08-06 22:47:08 -0300 | [diff] [blame] | 216 | .pll_reg = 0x806c, |
Michael Krufky | 76efb0ba | 2012-02-06 19:40:32 -0300 | [diff] [blame] | 217 | }; |
| 218 | |
Devin Heitmueller | 3de5bff | 2012-08-06 22:47:14 -0300 | [diff] [blame] | 219 | #define XC5000C_FIRMWARE "dvb-fe-xc5000c-4.1.30.7.fw" |
Michael Krufky | 7d3d0d8 | 2012-04-16 14:59:32 -0300 | [diff] [blame] | 220 | static const struct xc5000_fw_cfg xc5000c_41_024_5 = { |
Tim Gardner | 3422f2a6 | 2012-07-25 09:15:19 -0300 | [diff] [blame] | 221 | .name = XC5000C_FIRMWARE, |
Michael Krufky | 7d3d0d8 | 2012-04-16 14:59:32 -0300 | [diff] [blame] | 222 | .size = 16497, |
Devin Heitmueller | de49bc6 | 2012-08-06 22:47:08 -0300 | [diff] [blame] | 223 | .pll_reg = 0x13, |
Devin Heitmueller | 22d5c6f | 2012-08-06 22:47:09 -0300 | [diff] [blame] | 224 | .init_status_supported = 1, |
| 225 | .fw_checksum_supported = 1, |
Michael Krufky | d839880 | 2012-02-07 01:16:27 -0300 | [diff] [blame] | 226 | }; |
| 227 | |
Michael Krufky | a3db60b | 2012-02-08 15:03:07 -0300 | [diff] [blame] | 228 | static inline const struct xc5000_fw_cfg *xc5000_assign_firmware(int chip_id) |
Michael Krufky | ddea427 | 2012-02-07 02:39:36 -0300 | [diff] [blame] | 229 | { |
Michael Krufky | 6fab81d | 2012-02-08 14:57:39 -0300 | [diff] [blame] | 230 | switch (chip_id) { |
Michael Krufky | ddea427 | 2012-02-07 02:39:36 -0300 | [diff] [blame] | 231 | default: |
Michael Krufky | 6fab81d | 2012-02-08 14:57:39 -0300 | [diff] [blame] | 232 | case XC5000A: |
Michael Krufky | ddea427 | 2012-02-07 02:39:36 -0300 | [diff] [blame] | 233 | return &xc5000a_1_6_114; |
Michael Krufky | 6fab81d | 2012-02-08 14:57:39 -0300 | [diff] [blame] | 234 | case XC5000C: |
Michael Krufky | 7d3d0d8 | 2012-04-16 14:59:32 -0300 | [diff] [blame] | 235 | return &xc5000c_41_024_5; |
Michael Krufky | ddea427 | 2012-02-07 02:39:36 -0300 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | |
Devin Heitmueller | de49bc6 | 2012-08-06 22:47:08 -0300 | [diff] [blame] | 239 | static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force); |
Devin Heitmueller | 91bd625 | 2008-11-15 23:29:11 -0300 | [diff] [blame] | 240 | static int xc5000_is_firmware_loaded(struct dvb_frontend *fe); |
Devin Heitmueller | bdd3356 | 2008-11-16 20:17:14 -0300 | [diff] [blame] | 241 | static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val); |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 242 | static int xc5000_tuner_reset(struct dvb_frontend *fe); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 243 | |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 244 | static int xc_send_i2c_data(struct xc5000_priv *priv, u8 *buf, int len) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 245 | { |
Devin Heitmueller | d7800d4 | 2008-11-16 20:20:06 -0300 | [diff] [blame] | 246 | 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 Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 251 | return -EREMOTEIO; |
Devin Heitmueller | d7800d4 | 2008-11-16 20:20:06 -0300 | [diff] [blame] | 252 | } |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 253 | return 0; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 254 | } |
| 255 | |
Mauro Carvalho Chehab | 1cdffda | 2010-07-05 18:38:46 -0300 | [diff] [blame] | 256 | #if 0 |
Devin Heitmueller | bdd3356 | 2008-11-16 20:17:14 -0300 | [diff] [blame] | 257 | /* 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 Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 260 | static int xc_read_i2c_data(struct xc5000_priv *priv, u8 *buf, int len) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 261 | { |
Devin Heitmueller | bdd3356 | 2008-11-16 20:17:14 -0300 | [diff] [blame] | 262 | 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 Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 270 | } |
Mauro Carvalho Chehab | 1cdffda | 2010-07-05 18:38:46 -0300 | [diff] [blame] | 271 | #endif |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 272 | |
Dmitri Belimov | 4743319 | 2010-05-18 04:30:11 -0300 | [diff] [blame] | 273 | static 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 Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 290 | return 0; |
Dmitri Belimov | 4743319 | 2010-05-18 04:30:11 -0300 | [diff] [blame] | 291 | } |
| 292 | |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 293 | static int xc5000_tuner_reset(struct dvb_frontend *fe) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 294 | { |
| 295 | struct xc5000_priv *priv = fe->tuner_priv; |
| 296 | int ret; |
| 297 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 298 | dprintk(1, "%s()\n", __func__); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 299 | |
Michael Krufky | d7cba04 | 2008-09-12 13:31:45 -0300 | [diff] [blame] | 300 | if (fe->callback) { |
| 301 | ret = fe->callback(((fe->dvb) && (fe->dvb->priv)) ? |
Michael Krufky | 3065096 | 2008-09-06 14:56:58 -0300 | [diff] [blame] | 302 | fe->dvb->priv : |
| 303 | priv->i2c_props.adap->algo_data, |
Michael Krufky | d7cba04 | 2008-09-12 13:31:45 -0300 | [diff] [blame] | 304 | DVB_FRONTEND_COMPONENT_TUNER, |
Michael Krufky | 3065096 | 2008-09-06 14:56:58 -0300 | [diff] [blame] | 305 | XC5000_TUNER_RESET, 0); |
Devin Heitmueller | 91bd625 | 2008-11-15 23:29:11 -0300 | [diff] [blame] | 306 | if (ret) { |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 307 | printk(KERN_ERR "xc5000: reset failed\n"); |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 308 | return ret; |
Devin Heitmueller | 91bd625 | 2008-11-15 23:29:11 -0300 | [diff] [blame] | 309 | } |
| 310 | } else { |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 311 | printk(KERN_ERR "xc5000: no tuner reset callback function, fatal\n"); |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 312 | return -EINVAL; |
Devin Heitmueller | 91bd625 | 2008-11-15 23:29:11 -0300 | [diff] [blame] | 313 | } |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 314 | return 0; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 315 | } |
| 316 | |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 317 | static int xc_write_reg(struct xc5000_priv *priv, u16 reg_addr, u16 i2c_data) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 318 | { |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 319 | u8 buf[4]; |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 320 | int watch_dog_timer = 100; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 321 | int result; |
| 322 | |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 323 | 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 Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 327 | result = xc_send_i2c_data(priv, buf, 4); |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 328 | if (result == 0) { |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 329 | /* wait for busy flag to clear */ |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 330 | while ((watch_dog_timer > 0) && (result == 0)) { |
Mauro Carvalho Chehab | 1cdffda | 2010-07-05 18:38:46 -0300 | [diff] [blame] | 331 | result = xc5000_readreg(priv, XREG_BUSY, (u16 *)buf); |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 332 | if (result == 0) { |
Dmitri Belimov | 4743319 | 2010-05-18 04:30:11 -0300 | [diff] [blame] | 333 | if ((buf[0] == 0) && (buf[1] == 0)) { |
| 334 | /* busy flag cleared */ |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 335 | break; |
Dmitri Belimov | 4743319 | 2010-05-18 04:30:11 -0300 | [diff] [blame] | 336 | } else { |
Mauro Carvalho Chehab | e5bf4a1 | 2014-05-21 13:15:17 -0300 | [diff] [blame] | 337 | msleep(5); /* wait 5 ms */ |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 338 | watch_dog_timer--; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | } |
| 342 | } |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 343 | if (watch_dog_timer <= 0) |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 344 | result = -EREMOTEIO; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 345 | |
| 346 | return result; |
| 347 | } |
| 348 | |
David Woodhouse | c63e87e | 2008-05-24 00:13:34 +0100 | [diff] [blame] | 349 | static int xc_load_i2c_sequence(struct dvb_frontend *fe, const u8 *i2c_sequence) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 350 | { |
| 351 | struct xc5000_priv *priv = fe->tuner_priv; |
| 352 | |
| 353 | int i, nbytes_to_send, result; |
| 354 | unsigned int len, pos, index; |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 355 | u8 buf[XC_MAX_I2C_WRITE_LENGTH]; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 356 | |
Steven Toth | 8f3cd53 | 2008-10-16 20:29:38 -0300 | [diff] [blame] | 357 | 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 Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 361 | if (len == 0x0000) { |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 362 | /* RESET command */ |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 363 | result = xc5000_tuner_reset(fe); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 364 | index += 2; |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 365 | if (result != 0) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 366 | return result; |
| 367 | } else if (len & 0x8000) { |
| 368 | /* WAIT command */ |
Mauro Carvalho Chehab | e5bf4a1 | 2014-05-21 13:15:17 -0300 | [diff] [blame] | 369 | msleep(len & 0x7FFF); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 370 | 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 Toth | 8f3cd53 | 2008-10-16 20:29:38 -0300 | [diff] [blame] | 380 | if ((len - pos) > XC_MAX_I2C_WRITE_LENGTH - 2) |
| 381 | nbytes_to_send = |
| 382 | XC_MAX_I2C_WRITE_LENGTH; |
| 383 | else |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 384 | nbytes_to_send = (len - pos + 2); |
Steven Toth | 8f3cd53 | 2008-10-16 20:29:38 -0300 | [diff] [blame] | 385 | for (i = 2; i < nbytes_to_send; i++) { |
| 386 | buf[i] = i2c_sequence[index + pos + |
| 387 | i - 2]; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 388 | } |
Steven Toth | 8f3cd53 | 2008-10-16 20:29:38 -0300 | [diff] [blame] | 389 | result = xc_send_i2c_data(priv, buf, |
| 390 | nbytes_to_send); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 391 | |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 392 | if (result != 0) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 393 | return result; |
| 394 | |
| 395 | pos += nbytes_to_send - 2; |
| 396 | } |
| 397 | index += len; |
| 398 | } |
| 399 | } |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 400 | return 0; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 401 | } |
| 402 | |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 403 | static int xc_initialize(struct xc5000_priv *priv) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 404 | { |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 405 | dprintk(1, "%s()\n", __func__); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 406 | return xc_write_reg(priv, XREG_INIT, 0); |
| 407 | } |
| 408 | |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 409 | static int xc_set_tv_standard(struct xc5000_priv *priv, |
| 410 | u16 video_mode, u16 audio_mode, u8 radio_mode) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 411 | { |
| 412 | int ret; |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 413 | dprintk(1, "%s(0x%04x,0x%04x)\n", __func__, video_mode, audio_mode); |
| 414 | if (radio_mode) { |
Dmitri Belimov | 01ae728 | 2013-03-13 00:23:36 -0300 | [diff] [blame] | 415 | dprintk(1, "%s() Standard = %s\n", |
| 416 | __func__, |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 417 | xc5000_standard[radio_mode].name); |
Dmitri Belimov | 01ae728 | 2013-03-13 00:23:36 -0300 | [diff] [blame] | 418 | } else { |
| 419 | dprintk(1, "%s() Standard = %s\n", |
| 420 | __func__, |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 421 | xc5000_standard[priv->video_standard].name); |
Dmitri Belimov | 01ae728 | 2013-03-13 00:23:36 -0300 | [diff] [blame] | 422 | } |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 423 | |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 424 | ret = xc_write_reg(priv, XREG_VIDEO_MODE, video_mode); |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 425 | if (ret == 0) |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 426 | ret = xc_write_reg(priv, XREG_AUDIO_MODE, audio_mode); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 427 | |
| 428 | return ret; |
| 429 | } |
| 430 | |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 431 | static int xc_set_signal_source(struct xc5000_priv *priv, u16 rf_mode) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 432 | { |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 433 | dprintk(1, "%s(%d) Source = %s\n", __func__, rf_mode, |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 434 | rf_mode == XC_RF_MODE_AIR ? "ANTENNA" : "CABLE"); |
| 435 | |
Steven Toth | 8f3cd53 | 2008-10-16 20:29:38 -0300 | [diff] [blame] | 436 | if ((rf_mode != XC_RF_MODE_AIR) && (rf_mode != XC_RF_MODE_CABLE)) { |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 437 | rf_mode = XC_RF_MODE_CABLE; |
| 438 | printk(KERN_ERR |
| 439 | "%s(), Invalid mode, defaulting to CABLE", |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 440 | __func__); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 441 | } |
| 442 | return xc_write_reg(priv, XREG_SIGNALSOURCE, rf_mode); |
| 443 | } |
| 444 | |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 445 | static const struct dvb_tuner_ops xc5000_tuner_ops; |
| 446 | |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 447 | static int xc_set_rf_frequency(struct xc5000_priv *priv, u32 freq_hz) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 448 | { |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 449 | u16 freq_code; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 450 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 451 | dprintk(1, "%s(%u)\n", __func__, freq_hz); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 452 | |
Mauro Carvalho Chehab | a3f90c7 | 2018-07-05 18:59:35 -0400 | [diff] [blame] | 453 | if ((freq_hz > xc5000_tuner_ops.info.frequency_max_hz) || |
| 454 | (freq_hz < xc5000_tuner_ops.info.frequency_min_hz)) |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 455 | return -EINVAL; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 456 | |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 457 | freq_code = (u16)(freq_hz / 15625); |
| 458 | |
Devin Heitmueller | 81c4dfe | 2009-04-02 22:40:29 -0300 | [diff] [blame] | 459 | /* 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 Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 463 | } |
| 464 | |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 465 | |
| 466 | static int xc_set_IF_frequency(struct xc5000_priv *priv, u32 freq_khz) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 467 | { |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 468 | u32 freq_code = (freq_khz * 1024)/1000; |
| 469 | dprintk(1, "%s(freq_khz = %d) freq_code = 0x%x\n", |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 470 | __func__, freq_khz, freq_code); |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 471 | |
| 472 | return xc_write_reg(priv, XREG_IF_OUT, freq_code); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 473 | } |
| 474 | |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 475 | |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 476 | static int xc_get_adc_envelope(struct xc5000_priv *priv, u16 *adc_envelope) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 477 | { |
Devin Heitmueller | bdd3356 | 2008-11-16 20:17:14 -0300 | [diff] [blame] | 478 | return xc5000_readreg(priv, XREG_ADC_ENV, adc_envelope); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 479 | } |
| 480 | |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 481 | static int xc_get_frequency_error(struct xc5000_priv *priv, u32 *freq_error_hz) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 482 | { |
| 483 | int result; |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 484 | u16 reg_data; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 485 | u32 tmp; |
| 486 | |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 487 | result = xc5000_readreg(priv, XREG_FREQ_ERROR, ®_data); |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 488 | if (result != 0) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 489 | return result; |
| 490 | |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 491 | tmp = (u32)reg_data; |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 492 | (*freq_error_hz) = (tmp * 15625) / 1000; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 493 | return result; |
| 494 | } |
| 495 | |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 496 | static int xc_get_lock_status(struct xc5000_priv *priv, u16 *lock_status) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 497 | { |
Devin Heitmueller | bdd3356 | 2008-11-16 20:17:14 -0300 | [diff] [blame] | 498 | return xc5000_readreg(priv, XREG_LOCK, lock_status); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 499 | } |
| 500 | |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 501 | static int xc_get_version(struct xc5000_priv *priv, |
| 502 | u8 *hw_majorversion, u8 *hw_minorversion, |
| 503 | u8 *fw_majorversion, u8 *fw_minorversion) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 504 | { |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 505 | u16 data; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 506 | int result; |
| 507 | |
Devin Heitmueller | bdd3356 | 2008-11-16 20:17:14 -0300 | [diff] [blame] | 508 | result = xc5000_readreg(priv, XREG_VERSION, &data); |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 509 | if (result != 0) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 510 | return result; |
| 511 | |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 512 | (*hw_majorversion) = (data >> 12) & 0x0F; |
| 513 | (*hw_minorversion) = (data >> 8) & 0x0F; |
| 514 | (*fw_majorversion) = (data >> 4) & 0x0F; |
| 515 | (*fw_minorversion) = data & 0x0F; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 516 | |
| 517 | return 0; |
| 518 | } |
| 519 | |
Devin Heitmueller | bae7b7d | 2009-04-02 22:24:38 -0300 | [diff] [blame] | 520 | static int xc_get_buildversion(struct xc5000_priv *priv, u16 *buildrev) |
| 521 | { |
| 522 | return xc5000_readreg(priv, XREG_BUILD, buildrev); |
| 523 | } |
| 524 | |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 525 | static int xc_get_hsync_freq(struct xc5000_priv *priv, u32 *hsync_freq_hz) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 526 | { |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 527 | u16 reg_data; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 528 | int result; |
| 529 | |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 530 | result = xc5000_readreg(priv, XREG_HSYNC_FREQ, ®_data); |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 531 | if (result != 0) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 532 | return result; |
| 533 | |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 534 | (*hsync_freq_hz) = ((reg_data & 0x0fff) * 763)/100; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 535 | return result; |
| 536 | } |
| 537 | |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 538 | static int xc_get_frame_lines(struct xc5000_priv *priv, u16 *frame_lines) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 539 | { |
Devin Heitmueller | bdd3356 | 2008-11-16 20:17:14 -0300 | [diff] [blame] | 540 | return xc5000_readreg(priv, XREG_FRAME_LINES, frame_lines); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 541 | } |
| 542 | |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 543 | static int xc_get_quality(struct xc5000_priv *priv, u16 *quality) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 544 | { |
Devin Heitmueller | bdd3356 | 2008-11-16 20:17:14 -0300 | [diff] [blame] | 545 | return xc5000_readreg(priv, XREG_QUALITY, quality); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 546 | } |
| 547 | |
Devin Heitmueller | 7c287f1 | 2012-08-06 22:46:56 -0300 | [diff] [blame] | 548 | static int xc_get_analogsnr(struct xc5000_priv *priv, u16 *snr) |
| 549 | { |
| 550 | return xc5000_readreg(priv, XREG_SNR, snr); |
| 551 | } |
| 552 | |
| 553 | static int xc_get_totalgain(struct xc5000_priv *priv, u16 *totalgain) |
| 554 | { |
| 555 | return xc5000_readreg(priv, XREG_TOTALGAIN, totalgain); |
| 556 | } |
| 557 | |
Devin Heitmueller | a78baac | 2008-11-16 20:48:31 -0300 | [diff] [blame] | 558 | #define XC_TUNE_ANALOG 0 |
| 559 | #define XC_TUNE_DIGITAL 1 |
| 560 | static int xc_tune_channel(struct xc5000_priv *priv, u32 freq_hz, int mode) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 561 | { |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 562 | dprintk(1, "%s(%u)\n", __func__, freq_hz); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 563 | |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 564 | if (xc_set_rf_frequency(priv, freq_hz) != 0) |
Devin Heitmueller | d9928a1 | 2017-04-19 20:13:52 -0300 | [diff] [blame] | 565 | return -EREMOTEIO; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 566 | |
Devin Heitmueller | d9928a1 | 2017-04-19 20:13:52 -0300 | [diff] [blame] | 567 | return 0; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 568 | } |
| 569 | |
Michael Krufky | 7d3d0d8 | 2012-04-16 14:59:32 -0300 | [diff] [blame] | 570 | static int xc_set_xtal(struct dvb_frontend *fe) |
| 571 | { |
| 572 | struct xc5000_priv *priv = fe->tuner_priv; |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 573 | int ret = 0; |
Michael Krufky | 7d3d0d8 | 2012-04-16 14:59:32 -0300 | [diff] [blame] | 574 | |
| 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 Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 595 | |
Mauro Carvalho Chehab | 8604f35 | 2014-07-30 11:09:15 -0300 | [diff] [blame] | 596 | static int xc5000_fwupload(struct dvb_frontend *fe, |
| 597 | const struct xc5000_fw_cfg *desired_fw, |
| 598 | const struct firmware *fw) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 599 | { |
| 600 | struct xc5000_priv *priv = fe->tuner_priv; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 601 | int ret; |
Mauro Carvalho Chehab | 8604f35 | 2014-07-30 11:09:15 -0300 | [diff] [blame] | 602 | |
| 603 | /* request the firmware, this will block and timeout */ |
| 604 | dprintk(1, "waiting for firmware upload (%s)...\n", |
| 605 | desired_fw->name); |
| 606 | |
Devin Heitmueller | de49bc6 | 2012-08-06 22:47:08 -0300 | [diff] [blame] | 607 | priv->pll_register_no = desired_fw->pll_reg; |
Devin Heitmueller | 22d5c6f | 2012-08-06 22:47:09 -0300 | [diff] [blame] | 608 | priv->init_status_supported = desired_fw->init_status_supported; |
| 609 | priv->fw_checksum_supported = desired_fw->fw_checksum_supported; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 610 | |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 611 | |
Mauro Carvalho Chehab | 8604f35 | 2014-07-30 11:09:15 -0300 | [diff] [blame] | 612 | 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 Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 619 | |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 620 | return ret; |
| 621 | } |
| 622 | |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 623 | static void xc_debug_dump(struct xc5000_priv *priv) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 624 | { |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 625 | 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 Heitmueller | 7c287f1 | 2012-08-06 22:46:56 -0300 | [diff] [blame] | 631 | u16 snr; |
| 632 | u16 totalgain; |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 633 | u8 hw_majorversion = 0, hw_minorversion = 0; |
| 634 | u8 fw_majorversion = 0, fw_minorversion = 0; |
Devin Heitmueller | bae7b7d | 2009-04-02 22:24:38 -0300 | [diff] [blame] | 635 | u16 fw_buildversion = 0; |
Devin Heitmueller | de49bc6 | 2012-08-06 22:47:08 -0300 | [diff] [blame] | 636 | u16 regval; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 637 | |
| 638 | /* Wait for stats to stabilize. |
| 639 | * Frame Lines needs two frame times after initial lock |
| 640 | * before it is valid. |
| 641 | */ |
Mauro Carvalho Chehab | e5bf4a1 | 2014-05-21 13:15:17 -0300 | [diff] [blame] | 642 | msleep(100); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 643 | |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 644 | xc_get_adc_envelope(priv, &adc_envelope); |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 645 | dprintk(1, "*** ADC envelope (0-1023) = %d\n", adc_envelope); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 646 | |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 647 | xc_get_frequency_error(priv, &freq_error_hz); |
| 648 | dprintk(1, "*** Frequency error = %d Hz\n", freq_error_hz); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 649 | |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 650 | xc_get_lock_status(priv, &lock_status); |
| 651 | dprintk(1, "*** Lock status (0-Wait, 1-Locked, 2-No-signal) = %d\n", |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 652 | lock_status); |
| 653 | |
| 654 | xc_get_version(priv, &hw_majorversion, &hw_minorversion, |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 655 | &fw_majorversion, &fw_minorversion); |
Devin Heitmueller | bae7b7d | 2009-04-02 22:24:38 -0300 | [diff] [blame] | 656 | xc_get_buildversion(priv, &fw_buildversion); |
Devin Heitmueller | ca60a45d | 2012-08-06 22:47:11 -0300 | [diff] [blame] | 657 | dprintk(1, "*** HW: V%d.%d, FW: V %d.%d.%d\n", |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 658 | hw_majorversion, hw_minorversion, |
Devin Heitmueller | bae7b7d | 2009-04-02 22:24:38 -0300 | [diff] [blame] | 659 | fw_majorversion, fw_minorversion, fw_buildversion); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 660 | |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 661 | xc_get_hsync_freq(priv, &hsync_freq_hz); |
| 662 | dprintk(1, "*** Horizontal sync frequency = %d Hz\n", hsync_freq_hz); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 663 | |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 664 | xc_get_frame_lines(priv, &frame_lines); |
| 665 | dprintk(1, "*** Frame lines = %d\n", frame_lines); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 666 | |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 667 | xc_get_quality(priv, &quality); |
Devin Heitmueller | 1aa9c487 | 2012-08-06 22:46:55 -0300 | [diff] [blame] | 668 | dprintk(1, "*** Quality (0:<8dB, 7:>56dB) = %d\n", quality & 0x07); |
Devin Heitmueller | 7c287f1 | 2012-08-06 22:46:56 -0300 | [diff] [blame] | 669 | |
| 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 Heitmueller | de49bc6 | 2012-08-06 22:47:08 -0300 | [diff] [blame] | 676 | |
| 677 | if (priv->pll_register_no) { |
Mauro Carvalho Chehab | 7621b8c | 2017-11-01 17:05:43 -0400 | [diff] [blame] | 678 | if (!xc5000_readreg(priv, priv->pll_register_no, ®val)) |
| 679 | dprintk(1, "*** PLL lock status = 0x%04x\n", regval); |
Devin Heitmueller | de49bc6 | 2012-08-06 22:47:08 -0300 | [diff] [blame] | 680 | } |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 681 | } |
| 682 | |
Mauro Carvalho Chehab | 1643520 | 2014-08-09 21:47:21 -0300 | [diff] [blame] | 683 | static 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 Vollkommer | 52e269b | 2014-10-25 17:17:22 -0300 | [diff] [blame] | 712 | 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 Chehab | 1643520 | 2014-08-09 21:47:21 -0300 | [diff] [blame] | 715 | |
| 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 Chehab | 59b94f3e | 2014-08-09 21:47:24 -0300 | [diff] [blame] | 726 | static int xc5000_set_digital_params(struct dvb_frontend *fe) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 727 | { |
Mauro Carvalho Chehab | 1643520 | 2014-08-09 21:47:21 -0300 | [diff] [blame] | 728 | int b; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 729 | struct xc5000_priv *priv = fe->tuner_priv; |
Mauro Carvalho Chehab | fd66c45 | 2011-12-17 20:36:57 -0300 | [diff] [blame] | 730 | 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 Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 733 | |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 734 | if (xc_load_fw_and_init_tuner(fe, 0) != 0) { |
Devin Heitmueller | fc7a74b | 2012-08-06 22:47:01 -0300 | [diff] [blame] | 735 | dprintk(1, "Unable to load firmware and init tuner\n"); |
| 736 | return -EINVAL; |
Devin Heitmueller | 760c466 | 2009-10-13 23:44:14 -0300 | [diff] [blame] | 737 | } |
Devin Heitmueller | 8e4c679 | 2008-11-16 20:41:07 -0300 | [diff] [blame] | 738 | |
Mauro Carvalho Chehab | fd66c45 | 2011-12-17 20:36:57 -0300 | [diff] [blame] | 739 | dprintk(1, "%s() frequency=%d (Hz)\n", __func__, freq); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 740 | |
Mauro Carvalho Chehab | fd66c45 | 2011-12-17 20:36:57 -0300 | [diff] [blame] | 741 | switch (delsys) { |
| 742 | case SYS_ATSC: |
| 743 | dprintk(1, "%s() VSB modulation\n", __func__); |
| 744 | priv->rf_mode = XC_RF_MODE_AIR; |
Mauro Carvalho Chehab | a3eec91 | 2014-07-21 14:21:18 -0300 | [diff] [blame] | 745 | priv->freq_offset = 1750000; |
Mauro Carvalho Chehab | fd66c45 | 2011-12-17 20:36:57 -0300 | [diff] [blame] | 746 | 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 Chehab | a3eec91 | 2014-07-21 14:21:18 -0300 | [diff] [blame] | 751 | priv->freq_offset = 1750000; |
Mauro Carvalho Chehab | fd66c45 | 2011-12-17 20:36:57 -0300 | [diff] [blame] | 752 | priv->video_standard = DTV6; |
| 753 | break; |
Mauro Carvalho Chehab | 5cf73ce | 2012-07-05 14:07:59 -0300 | [diff] [blame] | 754 | 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 Chehab | 06eeefe | 2017-05-18 08:13:28 -0300 | [diff] [blame] | 759 | /* fall through */ |
Mauro Carvalho Chehab | 5cf73ce | 2012-07-05 14:07:59 -0300 | [diff] [blame] | 760 | case SYS_DMBTH: |
Mauro Carvalho Chehab | fd66c45 | 2011-12-17 20:36:57 -0300 | [diff] [blame] | 761 | case SYS_DVBT: |
| 762 | case SYS_DVBT2: |
David T.L. Wong | 6c99080 | 2009-05-04 22:59:58 -0300 | [diff] [blame] | 763 | dprintk(1, "%s() OFDM\n", __func__); |
Mauro Carvalho Chehab | fd66c45 | 2011-12-17 20:36:57 -0300 | [diff] [blame] | 764 | switch (bw) { |
| 765 | case 6000000: |
David T.L. Wong | 6c99080 | 2009-05-04 22:59:58 -0300 | [diff] [blame] | 766 | priv->video_standard = DTV6; |
Mauro Carvalho Chehab | a3eec91 | 2014-07-21 14:21:18 -0300 | [diff] [blame] | 767 | priv->freq_offset = 1750000; |
David T.L. Wong | 6c99080 | 2009-05-04 22:59:58 -0300 | [diff] [blame] | 768 | break; |
Mauro Carvalho Chehab | fd66c45 | 2011-12-17 20:36:57 -0300 | [diff] [blame] | 769 | case 7000000: |
Mauro Carvalho Chehab | 0433cd2 | 2011-12-09 08:01:01 -0200 | [diff] [blame] | 770 | priv->video_standard = DTV7; |
Mauro Carvalho Chehab | a3eec91 | 2014-07-21 14:21:18 -0300 | [diff] [blame] | 771 | priv->freq_offset = 2250000; |
Mauro Carvalho Chehab | 0433cd2 | 2011-12-09 08:01:01 -0200 | [diff] [blame] | 772 | break; |
Mauro Carvalho Chehab | fd66c45 | 2011-12-17 20:36:57 -0300 | [diff] [blame] | 773 | case 8000000: |
David T.L. Wong | 6c99080 | 2009-05-04 22:59:58 -0300 | [diff] [blame] | 774 | priv->video_standard = DTV8; |
Mauro Carvalho Chehab | a3eec91 | 2014-07-21 14:21:18 -0300 | [diff] [blame] | 775 | priv->freq_offset = 2750000; |
David T.L. Wong | 6c99080 | 2009-05-04 22:59:58 -0300 | [diff] [blame] | 776 | break; |
| 777 | default: |
| 778 | printk(KERN_ERR "xc5000 bandwidth not set!\n"); |
| 779 | return -EINVAL; |
| 780 | } |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 781 | priv->rf_mode = XC_RF_MODE_AIR; |
Dan Carpenter | cf1364b | 2013-01-13 15:31:33 -0300 | [diff] [blame] | 782 | break; |
Mauro Carvalho Chehab | fd66c45 | 2011-12-17 20:36:57 -0300 | [diff] [blame] | 783 | 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 Chehab | fd66c45 | 2011-12-17 20:36:57 -0300 | [diff] [blame] | 788 | priv->video_standard = DTV6; |
Mauro Carvalho Chehab | a3eec91 | 2014-07-21 14:21:18 -0300 | [diff] [blame] | 789 | priv->freq_offset = 1750000; |
Mauro Carvalho Chehab | fd66c45 | 2011-12-17 20:36:57 -0300 | [diff] [blame] | 790 | b = 6; |
| 791 | } else if (bw <= 7000000) { |
Mauro Carvalho Chehab | fd66c45 | 2011-12-17 20:36:57 -0300 | [diff] [blame] | 792 | priv->video_standard = DTV7; |
Mauro Carvalho Chehab | a3eec91 | 2014-07-21 14:21:18 -0300 | [diff] [blame] | 793 | priv->freq_offset = 2250000; |
Mauro Carvalho Chehab | fd66c45 | 2011-12-17 20:36:57 -0300 | [diff] [blame] | 794 | b = 7; |
| 795 | } else { |
Mauro Carvalho Chehab | fd66c45 | 2011-12-17 20:36:57 -0300 | [diff] [blame] | 796 | priv->video_standard = DTV7_8; |
Mauro Carvalho Chehab | a3eec91 | 2014-07-21 14:21:18 -0300 | [diff] [blame] | 797 | priv->freq_offset = 2750000; |
Mauro Carvalho Chehab | fd66c45 | 2011-12-17 20:36:57 -0300 | [diff] [blame] | 798 | b = 8; |
Igor M. Liplianin | e80edce | 2011-01-25 17:03:00 -0300 | [diff] [blame] | 799 | } |
Mauro Carvalho Chehab | fd66c45 | 2011-12-17 20:36:57 -0300 | [diff] [blame] | 800 | 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 Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 805 | return -EINVAL; |
| 806 | } |
| 807 | |
Mauro Carvalho Chehab | a3eec91 | 2014-07-21 14:21:18 -0300 | [diff] [blame] | 808 | priv->freq_hz = freq - priv->freq_offset; |
Mauro Carvalho Chehab | 1643520 | 2014-08-09 21:47:21 -0300 | [diff] [blame] | 809 | priv->mode = V4L2_TUNER_DIGITAL_TV; |
Mauro Carvalho Chehab | a3eec91 | 2014-07-21 14:21:18 -0300 | [diff] [blame] | 810 | |
Mauro Carvalho Chehab | fd66c45 | 2011-12-17 20:36:57 -0300 | [diff] [blame] | 811 | dprintk(1, "%s() frequency=%d (compensated to %d)\n", |
| 812 | __func__, freq, priv->freq_hz); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 813 | |
Mauro Carvalho Chehab | 1643520 | 2014-08-09 21:47:21 -0300 | [diff] [blame] | 814 | return xc5000_tune_digital(fe); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 815 | } |
| 816 | |
Steven Toth | e470d81 | 2008-06-21 21:06:02 -0300 | [diff] [blame] | 817 | static 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 Chehab | 7621b8c | 2017-11-01 17:05:43 -0400 | [diff] [blame] | 824 | if (!ret) { |
Steven Toth | e470d81 | 2008-06-21 21:06:02 -0300 | [diff] [blame] | 825 | if (id == XC_PRODUCT_ID_FW_NOT_LOADED) |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 826 | ret = -ENOENT; |
Steven Toth | e470d81 | 2008-06-21 21:06:02 -0300 | [diff] [blame] | 827 | else |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 828 | ret = 0; |
Mauro Carvalho Chehab | 7621b8c | 2017-11-01 17:05:43 -0400 | [diff] [blame] | 829 | dprintk(1, "%s() returns id = 0x%x\n", __func__, id); |
| 830 | } else { |
| 831 | dprintk(1, "%s() returns error %d\n", __func__, ret); |
Steven Toth | e470d81 | 2008-06-21 21:06:02 -0300 | [diff] [blame] | 832 | } |
| 833 | |
Steven Toth | e470d81 | 2008-06-21 21:06:02 -0300 | [diff] [blame] | 834 | return ret; |
| 835 | } |
| 836 | |
Mauro Carvalho Chehab | c3d6676 | 2014-08-09 21:47:22 -0300 | [diff] [blame] | 837 | static void xc5000_config_tv(struct dvb_frontend *fe, |
| 838 | struct analog_parameters *params) |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 839 | { |
| 840 | struct xc5000_priv *priv = fe->tuner_priv; |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 841 | |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 842 | dprintk(1, "%s() frequency=%d (in units of 62.5khz)\n", |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 843 | __func__, params->frequency); |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 844 | |
Mauro Carvalho Chehab | 1fab14e | 2009-03-03 14:35:41 -0300 | [diff] [blame] | 845 | /* 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 Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 849 | |
| 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 Toth | 8f3cd53 | 2008-10-16 20:29:38 -0300 | [diff] [blame] | 856 | if (params->std & V4L2_STD_MN) { |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 857 | /* default to BTSC audio standard */ |
| 858 | priv->video_standard = MN_NTSC_PAL_BTSC; |
Mauro Carvalho Chehab | c3d6676 | 2014-08-09 21:47:22 -0300 | [diff] [blame] | 859 | return; |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 860 | } |
| 861 | |
Steven Toth | 8f3cd53 | 2008-10-16 20:29:38 -0300 | [diff] [blame] | 862 | if (params->std & V4L2_STD_PAL_BG) { |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 863 | /* default to NICAM audio standard */ |
| 864 | priv->video_standard = BG_PAL_NICAM; |
Mauro Carvalho Chehab | c3d6676 | 2014-08-09 21:47:22 -0300 | [diff] [blame] | 865 | return; |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 866 | } |
| 867 | |
Steven Toth | 8f3cd53 | 2008-10-16 20:29:38 -0300 | [diff] [blame] | 868 | if (params->std & V4L2_STD_PAL_I) { |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 869 | /* default to NICAM audio standard */ |
| 870 | priv->video_standard = I_PAL_NICAM; |
Mauro Carvalho Chehab | c3d6676 | 2014-08-09 21:47:22 -0300 | [diff] [blame] | 871 | return; |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 872 | } |
| 873 | |
Steven Toth | 8f3cd53 | 2008-10-16 20:29:38 -0300 | [diff] [blame] | 874 | if (params->std & V4L2_STD_PAL_DK) { |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 875 | /* default to NICAM audio standard */ |
| 876 | priv->video_standard = DK_PAL_NICAM; |
Mauro Carvalho Chehab | c3d6676 | 2014-08-09 21:47:22 -0300 | [diff] [blame] | 877 | return; |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 878 | } |
| 879 | |
Steven Toth | 8f3cd53 | 2008-10-16 20:29:38 -0300 | [diff] [blame] | 880 | if (params->std & V4L2_STD_SECAM_DK) { |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 881 | /* default to A2 DK1 audio standard */ |
| 882 | priv->video_standard = DK_SECAM_A2DK1; |
Mauro Carvalho Chehab | c3d6676 | 2014-08-09 21:47:22 -0300 | [diff] [blame] | 883 | return; |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 884 | } |
| 885 | |
Steven Toth | 8f3cd53 | 2008-10-16 20:29:38 -0300 | [diff] [blame] | 886 | if (params->std & V4L2_STD_SECAM_L) { |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 887 | priv->video_standard = L_SECAM_NICAM; |
Mauro Carvalho Chehab | c3d6676 | 2014-08-09 21:47:22 -0300 | [diff] [blame] | 888 | return; |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 889 | } |
| 890 | |
Steven Toth | 8f3cd53 | 2008-10-16 20:29:38 -0300 | [diff] [blame] | 891 | if (params->std & V4L2_STD_SECAM_LC) { |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 892 | priv->video_standard = LC_SECAM_NICAM; |
Mauro Carvalho Chehab | c3d6676 | 2014-08-09 21:47:22 -0300 | [diff] [blame] | 893 | return; |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 894 | } |
Mauro Carvalho Chehab | c3d6676 | 2014-08-09 21:47:22 -0300 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | static 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 Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 902 | |
| 903 | tune_channel: |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 904 | ret = xc_set_signal_source(priv, priv->rf_mode); |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 905 | if (ret != 0) { |
Steven Toth | 8f3cd53 | 2008-10-16 20:29:38 -0300 | [diff] [blame] | 906 | printk(KERN_ERR |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 907 | "xc5000: xc_set_signal_source(%d) failed\n", |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 908 | priv->rf_mode); |
| 909 | return -EREMOTEIO; |
| 910 | } |
| 911 | |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 912 | 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 Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 915 | if (ret != 0) { |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 916 | printk(KERN_ERR "xc5000: xc_set_tv_standard failed\n"); |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 917 | return -EREMOTEIO; |
| 918 | } |
| 919 | |
Dmitri Belimov | 724dcbf | 2011-02-01 05:25:19 -0300 | [diff] [blame] | 920 | xc_write_reg(priv, XREG_OUTPUT_AMP, 0x09); |
| 921 | |
Devin Heitmueller | a78baac | 2008-11-16 20:48:31 -0300 | [diff] [blame] | 922 | xc_tune_channel(priv, priv->freq_hz, XC_TUNE_ANALOG); |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 923 | |
| 924 | if (debug) |
| 925 | xc_debug_dump(priv); |
| 926 | |
Devin Heitmueller | de49bc6 | 2012-08-06 22:47:08 -0300 | [diff] [blame] | 927 | if (priv->pll_register_no != 0) { |
| 928 | msleep(20); |
Mauro Carvalho Chehab | 7621b8c | 2017-11-01 17:05:43 -0400 | [diff] [blame] | 929 | ret = xc5000_readreg(priv, priv->pll_register_no, |
| 930 | &pll_lock_status); |
| 931 | if (ret) |
| 932 | return ret; |
Devin Heitmueller | de49bc6 | 2012-08-06 22:47:08 -0300 | [diff] [blame] | 933 | 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 Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 937 | if (xc_load_fw_and_init_tuner(fe, 1) != 0) { |
Devin Heitmueller | de49bc6 | 2012-08-06 22:47:08 -0300 | [diff] [blame] | 938 | printk(KERN_ERR "xc5000: Unable to reload fw\n"); |
| 939 | return -EREMOTEIO; |
| 940 | } |
| 941 | goto tune_channel; |
| 942 | } |
| 943 | } |
| 944 | |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 945 | return 0; |
| 946 | } |
| 947 | |
Mauro Carvalho Chehab | c3d6676 | 2014-08-09 21:47:22 -0300 | [diff] [blame] | 948 | static int xc5000_config_radio(struct dvb_frontend *fe, |
| 949 | struct analog_parameters *params) |
| 950 | |
Beholder Intl. Ltd. Dmitry Belimov | d7009cd | 2009-09-24 13:13:28 -0300 | [diff] [blame] | 951 | { |
| 952 | struct xc5000_priv *priv = fe->tuner_priv; |
Beholder Intl. Ltd. Dmitry Belimov | d7009cd | 2009-09-24 13:13:28 -0300 | [diff] [blame] | 953 | |
| 954 | dprintk(1, "%s() frequency=%d (in units of khz)\n", |
| 955 | __func__, params->frequency); |
| 956 | |
Devin Heitmueller | 496e905 | 2009-09-24 13:27:24 -0300 | [diff] [blame] | 957 | 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 Chehab | c3d6676 | 2014-08-09 21:47:22 -0300 | [diff] [blame] | 962 | priv->freq_hz = params->frequency * 125 / 2; |
| 963 | priv->rf_mode = XC_RF_MODE_AIR; |
| 964 | |
| 965 | return 0; |
| 966 | } |
| 967 | |
| 968 | static 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 Heitmueller | 496e905 | 2009-09-24 13:27:24 -0300 | [diff] [blame] | 974 | if (priv->radio_input == XC5000_RADIO_FM1) |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 975 | radio_input = FM_RADIO_INPUT1; |
Devin Heitmueller | 496e905 | 2009-09-24 13:27:24 -0300 | [diff] [blame] | 976 | else if (priv->radio_input == XC5000_RADIO_FM2) |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 977 | radio_input = FM_RADIO_INPUT2; |
Dmitri Belimov | 724dcbf | 2011-02-01 05:25:19 -0300 | [diff] [blame] | 978 | else if (priv->radio_input == XC5000_RADIO_FM1_MONO) |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 979 | radio_input = FM_RADIO_INPUT1_MONO; |
Devin Heitmueller | 496e905 | 2009-09-24 13:27:24 -0300 | [diff] [blame] | 980 | else { |
| 981 | dprintk(1, "%s() unknown radio input %d\n", __func__, |
| 982 | priv->radio_input); |
| 983 | return -EINVAL; |
| 984 | } |
| 985 | |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 986 | 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 Belimov | d7009cd | 2009-09-24 13:13:28 -0300 | [diff] [blame] | 988 | |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 989 | if (ret != 0) { |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 990 | printk(KERN_ERR "xc5000: xc_set_tv_standard failed\n"); |
Beholder Intl. Ltd. Dmitry Belimov | d7009cd | 2009-09-24 13:13:28 -0300 | [diff] [blame] | 991 | return -EREMOTEIO; |
| 992 | } |
| 993 | |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 994 | ret = xc_set_signal_source(priv, priv->rf_mode); |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 995 | if (ret != 0) { |
Beholder Intl. Ltd. Dmitry Belimov | d7009cd | 2009-09-24 13:13:28 -0300 | [diff] [blame] | 996 | printk(KERN_ERR |
Mauro Carvalho Chehab | 303ddd9 | 2014-05-21 13:23:27 -0300 | [diff] [blame] | 997 | "xc5000: xc_set_signal_source(%d) failed\n", |
Beholder Intl. Ltd. Dmitry Belimov | d7009cd | 2009-09-24 13:13:28 -0300 | [diff] [blame] | 998 | priv->rf_mode); |
| 999 | return -EREMOTEIO; |
| 1000 | } |
| 1001 | |
Dmitri Belimov | 724dcbf | 2011-02-01 05:25:19 -0300 | [diff] [blame] | 1002 | 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 Belimov | d7009cd | 2009-09-24 13:13:28 -0300 | [diff] [blame] | 1008 | xc_tune_channel(priv, priv->freq_hz, XC_TUNE_ANALOG); |
| 1009 | |
| 1010 | return 0; |
| 1011 | } |
| 1012 | |
Mauro Carvalho Chehab | 59b94f3e | 2014-08-09 21:47:24 -0300 | [diff] [blame] | 1013 | static int xc5000_set_params(struct dvb_frontend *fe) |
Mauro Carvalho Chehab | c3d6676 | 2014-08-09 21:47:22 -0300 | [diff] [blame] | 1014 | { |
| 1015 | struct xc5000_priv *priv = fe->tuner_priv; |
| 1016 | |
Mauro Carvalho Chehab | 5275a3b | 2014-08-09 23:14:22 -0300 | [diff] [blame] | 1017 | 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 Chehab | c3d6676 | 2014-08-09 21:47:22 -0300 | [diff] [blame] | 1022 | 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 Belimov | d7009cd | 2009-09-24 13:13:28 -0300 | [diff] [blame] | 1034 | static 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 Chehab | c3d6676 | 2014-08-09 21:47:22 -0300 | [diff] [blame] | 1038 | int ret; |
Beholder Intl. Ltd. Dmitry Belimov | d7009cd | 2009-09-24 13:13:28 -0300 | [diff] [blame] | 1039 | |
| 1040 | if (priv->i2c_props.adap == NULL) |
| 1041 | return -EINVAL; |
| 1042 | |
Beholder Intl. Ltd. Dmitry Belimov | d7009cd | 2009-09-24 13:13:28 -0300 | [diff] [blame] | 1043 | switch (params->mode) { |
| 1044 | case V4L2_TUNER_RADIO: |
Mauro Carvalho Chehab | c3d6676 | 2014-08-09 21:47:22 -0300 | [diff] [blame] | 1045 | ret = xc5000_config_radio(fe, params); |
| 1046 | if (ret) |
| 1047 | return ret; |
Beholder Intl. Ltd. Dmitry Belimov | d7009cd | 2009-09-24 13:13:28 -0300 | [diff] [blame] | 1048 | break; |
| 1049 | case V4L2_TUNER_ANALOG_TV: |
Mauro Carvalho Chehab | c3d6676 | 2014-08-09 21:47:22 -0300 | [diff] [blame] | 1050 | xc5000_config_tv(fe, params); |
| 1051 | break; |
| 1052 | default: |
Beholder Intl. Ltd. Dmitry Belimov | d7009cd | 2009-09-24 13:13:28 -0300 | [diff] [blame] | 1053 | break; |
| 1054 | } |
Mauro Carvalho Chehab | c3d6676 | 2014-08-09 21:47:22 -0300 | [diff] [blame] | 1055 | priv->mode = params->mode; |
Beholder Intl. Ltd. Dmitry Belimov | d7009cd | 2009-09-24 13:13:28 -0300 | [diff] [blame] | 1056 | |
Mauro Carvalho Chehab | 59b94f3e | 2014-08-09 21:47:24 -0300 | [diff] [blame] | 1057 | return xc5000_set_params(fe); |
Beholder Intl. Ltd. Dmitry Belimov | d7009cd | 2009-09-24 13:13:28 -0300 | [diff] [blame] | 1058 | } |
| 1059 | |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1060 | static int xc5000_get_frequency(struct dvb_frontend *fe, u32 *freq) |
| 1061 | { |
| 1062 | struct xc5000_priv *priv = fe->tuner_priv; |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1063 | dprintk(1, "%s()\n", __func__); |
Mauro Carvalho Chehab | a3eec91 | 2014-07-21 14:21:18 -0300 | [diff] [blame] | 1064 | *freq = priv->freq_hz + priv->freq_offset; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1065 | return 0; |
| 1066 | } |
| 1067 | |
Mauro Carvalho Chehab | 3562103 | 2011-09-23 13:03:42 -0300 | [diff] [blame] | 1068 | static 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 Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1076 | static int xc5000_get_bandwidth(struct dvb_frontend *fe, u32 *bw) |
| 1077 | { |
| 1078 | struct xc5000_priv *priv = fe->tuner_priv; |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1079 | dprintk(1, "%s()\n", __func__); |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 1080 | |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1081 | *bw = priv->bandwidth; |
| 1082 | return 0; |
| 1083 | } |
| 1084 | |
| 1085 | static int xc5000_get_status(struct dvb_frontend *fe, u32 *status) |
| 1086 | { |
| 1087 | struct xc5000_priv *priv = fe->tuner_priv; |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 1088 | u16 lock_status = 0; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1089 | |
| 1090 | xc_get_lock_status(priv, &lock_status); |
| 1091 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1092 | dprintk(1, "%s() lock_status = 0x%08x\n", __func__, lock_status); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1093 | |
| 1094 | *status = lock_status; |
| 1095 | |
| 1096 | return 0; |
| 1097 | } |
| 1098 | |
Devin Heitmueller | de49bc6 | 2012-08-06 22:47:08 -0300 | [diff] [blame] | 1099 | static int xc_load_fw_and_init_tuner(struct dvb_frontend *fe, int force) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1100 | { |
| 1101 | struct xc5000_priv *priv = fe->tuner_priv; |
Mauro Carvalho Chehab | 8604f35 | 2014-07-30 11:09:15 -0300 | [diff] [blame] | 1102 | const struct xc5000_fw_cfg *desired_fw = xc5000_assign_firmware(priv->chip_id); |
| 1103 | const struct firmware *fw; |
Mauro Carvalho Chehab | 2621c0b | 2014-07-30 10:36:32 -0300 | [diff] [blame] | 1104 | int ret, i; |
Devin Heitmueller | de49bc6 | 2012-08-06 22:47:08 -0300 | [diff] [blame] | 1105 | u16 pll_lock_status; |
Devin Heitmueller | 22d5c6f | 2012-08-06 22:47:09 -0300 | [diff] [blame] | 1106 | u16 fw_ck; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1107 | |
Mauro Carvalho Chehab | f7a27ff | 2014-05-21 13:57:30 -0300 | [diff] [blame] | 1108 | cancel_delayed_work(&priv->timer_sleep); |
| 1109 | |
Mauro Carvalho Chehab | 2621c0b | 2014-07-30 10:36:32 -0300 | [diff] [blame] | 1110 | if (!force && xc5000_is_firmware_loaded(fe) == 0) |
| 1111 | return 0; |
Devin Heitmueller | de49bc6 | 2012-08-06 22:47:08 -0300 | [diff] [blame] | 1112 | |
Shuah Khan | 5264a52 | 2014-09-22 21:30:46 -0300 | [diff] [blame] | 1113 | 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 Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 1120 | dprintk(1, "firmware read %zu bytes.\n", fw->size); |
Mauro Carvalho Chehab | 8604f35 | 2014-07-30 11:09:15 -0300 | [diff] [blame] | 1121 | |
Shuah Khan | 5264a52 | 2014-09-22 21:30:46 -0300 | [diff] [blame] | 1122 | 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 Chehab | 8604f35 | 2014-07-30 11:09:15 -0300 | [diff] [blame] | 1130 | |
Mauro Carvalho Chehab | 2621c0b | 2014-07-30 10:36:32 -0300 | [diff] [blame] | 1131 | /* Try up to 5 times to load firmware */ |
| 1132 | for (i = 0; i < 5; i++) { |
Mauro Carvalho Chehab | ee67674 | 2014-07-30 11:17:46 -0300 | [diff] [blame] | 1133 | if (i) |
| 1134 | printk(KERN_CONT " - retrying to upload firmware.\n"); |
| 1135 | |
Mauro Carvalho Chehab | 8604f35 | 2014-07-30 11:09:15 -0300 | [diff] [blame] | 1136 | ret = xc5000_fwupload(fe, desired_fw, fw); |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 1137 | if (ret != 0) |
Mauro Carvalho Chehab | 8604f35 | 2014-07-30 11:09:15 -0300 | [diff] [blame] | 1138 | goto err; |
Devin Heitmueller | fc7a74b | 2012-08-06 22:47:01 -0300 | [diff] [blame] | 1139 | |
Devin Heitmueller | de49bc6 | 2012-08-06 22:47:08 -0300 | [diff] [blame] | 1140 | msleep(20); |
| 1141 | |
Devin Heitmueller | 22d5c6f | 2012-08-06 22:47:09 -0300 | [diff] [blame] | 1142 | if (priv->fw_checksum_supported) { |
Mauro Carvalho Chehab | 2621c0b | 2014-07-30 10:36:32 -0300 | [diff] [blame] | 1143 | if (xc5000_readreg(priv, XREG_FW_CHECKSUM, &fw_ck)) { |
Mauro Carvalho Chehab | ee67674 | 2014-07-30 11:17:46 -0300 | [diff] [blame] | 1144 | printk(KERN_ERR |
| 1145 | "xc5000: FW checksum reading failed."); |
Mauro Carvalho Chehab | 2621c0b | 2014-07-30 10:36:32 -0300 | [diff] [blame] | 1146 | continue; |
Devin Heitmueller | 22d5c6f | 2012-08-06 22:47:09 -0300 | [diff] [blame] | 1147 | } |
| 1148 | |
Mauro Carvalho Chehab | 2621c0b | 2014-07-30 10:36:32 -0300 | [diff] [blame] | 1149 | if (!fw_ck) { |
Mauro Carvalho Chehab | ee67674 | 2014-07-30 11:17:46 -0300 | [diff] [blame] | 1150 | printk(KERN_ERR |
| 1151 | "xc5000: FW checksum failed = 0x%04x.", |
| 1152 | fw_ck); |
Mauro Carvalho Chehab | 2621c0b | 2014-07-30 10:36:32 -0300 | [diff] [blame] | 1153 | continue; |
Devin Heitmueller | 22d5c6f | 2012-08-06 22:47:09 -0300 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | |
Devin Heitmueller | fc7a74b | 2012-08-06 22:47:01 -0300 | [diff] [blame] | 1157 | /* Start the tuner self-calibration process */ |
Mauro Carvalho Chehab | 2621c0b | 2014-07-30 10:36:32 -0300 | [diff] [blame] | 1158 | ret = xc_initialize(priv); |
| 1159 | if (ret) { |
Colin Ian King | 26c7e7b | 2017-04-12 11:04:13 -0300 | [diff] [blame] | 1160 | printk(KERN_ERR "xc5000: Can't request self-calibration."); |
Mauro Carvalho Chehab | 2621c0b | 2014-07-30 10:36:32 -0300 | [diff] [blame] | 1161 | continue; |
| 1162 | } |
Devin Heitmueller | de49bc6 | 2012-08-06 22:47:08 -0300 | [diff] [blame] | 1163 | |
Devin Heitmueller | fc7a74b | 2012-08-06 22:47:01 -0300 | [diff] [blame] | 1164 | /* 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 Chehab | e5bf4a1 | 2014-05-21 13:15:17 -0300 | [diff] [blame] | 1169 | msleep(100); |
Devin Heitmueller | fc7a74b | 2012-08-06 22:47:01 -0300 | [diff] [blame] | 1170 | |
Devin Heitmueller | 22d5c6f | 2012-08-06 22:47:09 -0300 | [diff] [blame] | 1171 | if (priv->init_status_supported) { |
Mauro Carvalho Chehab | 2621c0b | 2014-07-30 10:36:32 -0300 | [diff] [blame] | 1172 | if (xc5000_readreg(priv, XREG_INIT_STATUS, &fw_ck)) { |
Mauro Carvalho Chehab | ee67674 | 2014-07-30 11:17:46 -0300 | [diff] [blame] | 1173 | printk(KERN_ERR |
| 1174 | "xc5000: FW failed reading init status."); |
Mauro Carvalho Chehab | 2621c0b | 2014-07-30 10:36:32 -0300 | [diff] [blame] | 1175 | continue; |
Devin Heitmueller | 22d5c6f | 2012-08-06 22:47:09 -0300 | [diff] [blame] | 1176 | } |
| 1177 | |
Mauro Carvalho Chehab | 2621c0b | 2014-07-30 10:36:32 -0300 | [diff] [blame] | 1178 | if (!fw_ck) { |
Mauro Carvalho Chehab | ee67674 | 2014-07-30 11:17:46 -0300 | [diff] [blame] | 1179 | printk(KERN_ERR |
| 1180 | "xc5000: FW init status failed = 0x%04x.", |
| 1181 | fw_ck); |
Mauro Carvalho Chehab | 2621c0b | 2014-07-30 10:36:32 -0300 | [diff] [blame] | 1182 | continue; |
Devin Heitmueller | 22d5c6f | 2012-08-06 22:47:09 -0300 | [diff] [blame] | 1183 | } |
| 1184 | } |
| 1185 | |
Devin Heitmueller | de49bc6 | 2012-08-06 22:47:08 -0300 | [diff] [blame] | 1186 | if (priv->pll_register_no) { |
Mauro Carvalho Chehab | 7621b8c | 2017-11-01 17:05:43 -0400 | [diff] [blame] | 1187 | ret = xc5000_readreg(priv, priv->pll_register_no, |
| 1188 | &pll_lock_status); |
| 1189 | if (ret) |
| 1190 | continue; |
Devin Heitmueller | de49bc6 | 2012-08-06 22:47:08 -0300 | [diff] [blame] | 1191 | if (pll_lock_status > 63) { |
| 1192 | /* PLL is unlocked, force reload of the firmware */ |
Mauro Carvalho Chehab | ee67674 | 2014-07-30 11:17:46 -0300 | [diff] [blame] | 1193 | printk(KERN_ERR |
| 1194 | "xc5000: PLL not running after fwload."); |
Mauro Carvalho Chehab | 2621c0b | 2014-07-30 10:36:32 -0300 | [diff] [blame] | 1195 | continue; |
Devin Heitmueller | de49bc6 | 2012-08-06 22:47:08 -0300 | [diff] [blame] | 1196 | } |
| 1197 | } |
| 1198 | |
Devin Heitmueller | fc7a74b | 2012-08-06 22:47:01 -0300 | [diff] [blame] | 1199 | /* Default to "CABLE" mode */ |
Mauro Carvalho Chehab | 2621c0b | 2014-07-30 10:36:32 -0300 | [diff] [blame] | 1200 | ret = xc_write_reg(priv, XREG_SIGNALSOURCE, XC_RF_MODE_CABLE); |
Mauro Carvalho Chehab | ee67674 | 2014-07-30 11:17:46 -0300 | [diff] [blame] | 1201 | if (!ret) |
| 1202 | break; |
| 1203 | printk(KERN_ERR "xc5000: can't set to cable mode."); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1204 | } |
| 1205 | |
Mauro Carvalho Chehab | 8604f35 | 2014-07-30 11:09:15 -0300 | [diff] [blame] | 1206 | err: |
Mauro Carvalho Chehab | ee67674 | 2014-07-30 11:17:46 -0300 | [diff] [blame] | 1207 | 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 Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1213 | return ret; |
| 1214 | } |
| 1215 | |
Mauro Carvalho Chehab | f7a27ff | 2014-05-21 13:57:30 -0300 | [diff] [blame] | 1216 | static 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 Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 1235 | static int xc5000_sleep(struct dvb_frontend *fe) |
| 1236 | { |
Mauro Carvalho Chehab | f7a27ff | 2014-05-21 13:57:30 -0300 | [diff] [blame] | 1237 | struct xc5000_priv *priv = fe->tuner_priv; |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 1238 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1239 | dprintk(1, "%s()\n", __func__); |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 1240 | |
Devin Heitmueller | b6bd5eb | 2009-04-28 13:53:38 -0300 | [diff] [blame] | 1241 | /* Avoid firmware reload on slow devices */ |
| 1242 | if (no_poweroff) |
| 1243 | return 0; |
| 1244 | |
Mauro Carvalho Chehab | f7a27ff | 2014-05-21 13:57:30 -0300 | [diff] [blame] | 1245 | schedule_delayed_work(&priv->timer_sleep, |
| 1246 | msecs_to_jiffies(XC5000_SLEEP_TIME)); |
| 1247 | |
| 1248 | return 0; |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 1249 | } |
| 1250 | |
Mauro Carvalho Chehab | 91a5307 | 2014-08-09 21:47:20 -0300 | [diff] [blame] | 1251 | static 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 Khan | 27ccd69 | 2014-08-13 22:09:24 -0300 | [diff] [blame] | 1269 | static 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 Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1283 | static int xc5000_init(struct dvb_frontend *fe) |
| 1284 | { |
| 1285 | struct xc5000_priv *priv = fe->tuner_priv; |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1286 | dprintk(1, "%s()\n", __func__); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1287 | |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 1288 | if (xc_load_fw_and_init_tuner(fe, 0) != 0) { |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 1289 | printk(KERN_ERR "xc5000: Unable to initialise tuner\n"); |
| 1290 | return -EREMOTEIO; |
| 1291 | } |
| 1292 | |
| 1293 | if (debug) |
| 1294 | xc_debug_dump(priv); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1295 | |
| 1296 | return 0; |
| 1297 | } |
| 1298 | |
Max Kellermann | 194ced7 | 2016-08-09 18:32:31 -0300 | [diff] [blame] | 1299 | static void xc5000_release(struct dvb_frontend *fe) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1300 | { |
Michael Krufky | 89fd285 | 2008-09-06 11:44:53 -0300 | [diff] [blame] | 1301 | struct xc5000_priv *priv = fe->tuner_priv; |
| 1302 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1303 | dprintk(1, "%s()\n", __func__); |
Michael Krufky | 89fd285 | 2008-09-06 11:44:53 -0300 | [diff] [blame] | 1304 | |
| 1305 | mutex_lock(&xc5000_list_mutex); |
| 1306 | |
Mauro Carvalho Chehab | f7a27ff | 2014-05-21 13:57:30 -0300 | [diff] [blame] | 1307 | if (priv) { |
| 1308 | cancel_delayed_work(&priv->timer_sleep); |
Devin Heitmueller | 856260a | 2014-09-22 21:30:46 -0300 | [diff] [blame] | 1309 | if (priv->firmware) { |
| 1310 | release_firmware(priv->firmware); |
| 1311 | priv->firmware = NULL; |
| 1312 | } |
Dan Carpenter | 4961a53 | 2014-09-25 08:40:08 -0300 | [diff] [blame] | 1313 | hybrid_tuner_release_state(priv); |
Mauro Carvalho Chehab | f7a27ff | 2014-05-21 13:57:30 -0300 | [diff] [blame] | 1314 | } |
Michael Krufky | 89fd285 | 2008-09-06 11:44:53 -0300 | [diff] [blame] | 1315 | |
| 1316 | mutex_unlock(&xc5000_list_mutex); |
| 1317 | |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1318 | fe->tuner_priv = NULL; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1319 | } |
| 1320 | |
Dmitri Belimov | 724dcbf | 2011-02-01 05:25:19 -0300 | [diff] [blame] | 1321 | static 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 Vollkommer | 52e269b | 2014-10-25 17:17:22 -0300 | [diff] [blame] | 1334 | if (p->output_amp) |
| 1335 | priv->output_amp = p->output_amp; |
| 1336 | |
Dmitri Belimov | 724dcbf | 2011-02-01 05:25:19 -0300 | [diff] [blame] | 1337 | return 0; |
| 1338 | } |
| 1339 | |
| 1340 | |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1341 | static const struct dvb_tuner_ops xc5000_tuner_ops = { |
| 1342 | .info = { |
Mauro Carvalho Chehab | a3f90c7 | 2018-07-05 18:59:35 -0400 | [diff] [blame] | 1343 | .name = "Xceive XC5000", |
| 1344 | .frequency_min_hz = 1 * MHz, |
| 1345 | .frequency_max_hz = 1023 * MHz, |
| 1346 | .frequency_step_hz = 50 * kHz, |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1347 | }, |
| 1348 | |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 1349 | .release = xc5000_release, |
| 1350 | .init = xc5000_init, |
| 1351 | .sleep = xc5000_sleep, |
Mauro Carvalho Chehab | 91a5307 | 2014-08-09 21:47:20 -0300 | [diff] [blame] | 1352 | .suspend = xc5000_suspend, |
Shuah Khan | 27ccd69 | 2014-08-13 22:09:24 -0300 | [diff] [blame] | 1353 | .resume = xc5000_resume, |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1354 | |
Dmitri Belimov | 724dcbf | 2011-02-01 05:25:19 -0300 | [diff] [blame] | 1355 | .set_config = xc5000_set_config, |
Mauro Carvalho Chehab | 59b94f3e | 2014-08-09 21:47:24 -0300 | [diff] [blame] | 1356 | .set_params = xc5000_set_digital_params, |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 1357 | .set_analog_params = xc5000_set_analog_params, |
| 1358 | .get_frequency = xc5000_get_frequency, |
Mauro Carvalho Chehab | 3562103 | 2011-09-23 13:03:42 -0300 | [diff] [blame] | 1359 | .get_if_frequency = xc5000_get_if_frequency, |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 1360 | .get_bandwidth = xc5000_get_bandwidth, |
| 1361 | .get_status = xc5000_get_status |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1362 | }; |
| 1363 | |
Michael Krufky | 4872354 | 2008-05-10 14:34:09 -0300 | [diff] [blame] | 1364 | struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe, |
| 1365 | struct i2c_adapter *i2c, |
lawrence rust | 2e4e98e | 2010-08-25 09:50:20 -0300 | [diff] [blame] | 1366 | const struct xc5000_config *cfg) |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1367 | { |
| 1368 | struct xc5000_priv *priv = NULL; |
Michael Krufky | 89fd285 | 2008-09-06 11:44:53 -0300 | [diff] [blame] | 1369 | int instance; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1370 | u16 id = 0; |
| 1371 | |
Michael Krufky | 89fd285 | 2008-09-06 11:44:53 -0300 | [diff] [blame] | 1372 | dprintk(1, "%s(%d-%04x)\n", __func__, |
| 1373 | i2c ? i2c_adapter_id(i2c) : -1, |
| 1374 | cfg ? cfg->i2c_address : -1); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1375 | |
Michael Krufky | 89fd285 | 2008-09-06 11:44:53 -0300 | [diff] [blame] | 1376 | mutex_lock(&xc5000_list_mutex); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1377 | |
Michael Krufky | 89fd285 | 2008-09-06 11:44:53 -0300 | [diff] [blame] | 1378 | 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 Krufky | 89fd285 | 2008-09-06 11:44:53 -0300 | [diff] [blame] | 1384 | case 1: |
| 1385 | /* new tuner instance */ |
Mauro Carvalho Chehab | c6f56e7 | 2011-12-26 20:02:28 -0300 | [diff] [blame] | 1386 | priv->bandwidth = 6000000; |
Michael Krufky | 89fd285 | 2008-09-06 11:44:53 -0300 | [diff] [blame] | 1387 | fe->tuner_priv = priv; |
Mauro Carvalho Chehab | f7a27ff | 2014-05-21 13:57:30 -0300 | [diff] [blame] | 1388 | priv->fe = fe; |
| 1389 | INIT_DELAYED_WORK(&priv->timer_sleep, xc5000_do_timer_sleep); |
Michael Krufky | 89fd285 | 2008-09-06 11:44:53 -0300 | [diff] [blame] | 1390 | break; |
| 1391 | default: |
| 1392 | /* existing tuner instance */ |
| 1393 | fe->tuner_priv = priv; |
| 1394 | break; |
| 1395 | } |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1396 | |
Devin Heitmueller | ea22786 | 2009-03-11 02:58:53 -0300 | [diff] [blame] | 1397 | 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 Krufky | 7d3d0d8 | 2012-04-16 14:59:32 -0300 | [diff] [blame] | 1404 | if (priv->xtal_khz == 0) |
| 1405 | priv->xtal_khz = cfg->xtal_khz; |
| 1406 | |
Devin Heitmueller | 496e905 | 2009-09-24 13:27:24 -0300 | [diff] [blame] | 1407 | if (priv->radio_input == 0) |
| 1408 | priv->radio_input = cfg->radio_input; |
| 1409 | |
Michael Krufky | 6fab81d | 2012-02-08 14:57:39 -0300 | [diff] [blame] | 1410 | /* don't override chip id if it's already been set |
Michael Krufky | 76efb0ba | 2012-02-06 19:40:32 -0300 | [diff] [blame] | 1411 | unless explicitly specified */ |
Michael Krufky | 6fab81d | 2012-02-08 14:57:39 -0300 | [diff] [blame] | 1412 | 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 Krufky | 76efb0ba | 2012-02-06 19:40:32 -0300 | [diff] [blame] | 1416 | |
Richard Vollkommer | 52e269b | 2014-10-25 17:17:22 -0300 | [diff] [blame] | 1417 | /* 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 Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 1423 | /* Check if firmware has been loaded. It is possible that another |
| 1424 | instance of the driver has loaded the firmware. |
| 1425 | */ |
Mauro Carvalho Chehab | 859ae7f | 2014-05-21 13:08:18 -0300 | [diff] [blame] | 1426 | if (xc5000_readreg(priv, XREG_PRODUCT_ID, &id) != 0) |
Michael Krufky | 89fd285 | 2008-09-06 11:44:53 -0300 | [diff] [blame] | 1427 | goto fail; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1428 | |
Steven Toth | 8f3cd53 | 2008-10-16 20:29:38 -0300 | [diff] [blame] | 1429 | switch (id) { |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 1430 | 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 Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 1436 | 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 Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 1443 | break; |
| 1444 | default: |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1445 | printk(KERN_ERR |
| 1446 | "xc5000: Device not found at addr 0x%02x (0x%x)\n", |
| 1447 | cfg->i2c_address, id); |
Michael Krufky | 89fd285 | 2008-09-06 11:44:53 -0300 | [diff] [blame] | 1448 | goto fail; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1449 | } |
| 1450 | |
Michael Krufky | 89fd285 | 2008-09-06 11:44:53 -0300 | [diff] [blame] | 1451 | mutex_unlock(&xc5000_list_mutex); |
| 1452 | |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1453 | memcpy(&fe->ops.tuner_ops, &xc5000_tuner_ops, |
| 1454 | sizeof(struct dvb_tuner_ops)); |
| 1455 | |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1456 | return fe; |
Michael Krufky | 89fd285 | 2008-09-06 11:44:53 -0300 | [diff] [blame] | 1457 | fail: |
| 1458 | mutex_unlock(&xc5000_list_mutex); |
| 1459 | |
| 1460 | xc5000_release(fe); |
| 1461 | return NULL; |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1462 | } |
| 1463 | EXPORT_SYMBOL(xc5000_attach); |
| 1464 | |
| 1465 | MODULE_AUTHOR("Steven Toth"); |
Steven Toth | e12671cf | 2007-12-20 01:14:43 -0300 | [diff] [blame] | 1466 | MODULE_DESCRIPTION("Xceive xc5000 silicon tuner driver"); |
Steven Toth | aacb9d3 | 2007-12-18 01:55:51 -0300 | [diff] [blame] | 1467 | MODULE_LICENSE("GPL"); |
Tim Gardner | 3422f2a6 | 2012-07-25 09:15:19 -0300 | [diff] [blame] | 1468 | MODULE_FIRMWARE(XC5000A_FIRMWARE); |
| 1469 | MODULE_FIRMWARE(XC5000C_FIRMWARE); |