Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 1 | /* tuner-xc2028 |
| 2 | * |
Mauro Carvalho Chehab | 33e5316 | 2008-04-21 06:58:48 -0300 | [diff] [blame] | 3 | * Copyright (c) 2007-2008 Mauro Carvalho Chehab (mchehab@infradead.org) |
Mauro Carvalho Chehab | 983d214 | 2007-10-29 23:44:18 -0300 | [diff] [blame] | 4 | * |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 5 | * Copyright (c) 2007 Michel Ludwig (michel.ludwig@gmail.com) |
| 6 | * - frontend interface |
Mauro Carvalho Chehab | 983d214 | 2007-10-29 23:44:18 -0300 | [diff] [blame] | 7 | * |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 8 | * This code is placed under the terms of the GNU General Public License v2 |
| 9 | */ |
| 10 | |
| 11 | #include <linux/i2c.h> |
| 12 | #include <asm/div64.h> |
| 13 | #include <linux/firmware.h> |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 14 | #include <linux/videodev2.h> |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 15 | #include <linux/delay.h> |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 16 | #include <media/tuner.h> |
Mauro Carvalho Chehab | 3b20532 | 2007-09-27 18:27:03 -0300 | [diff] [blame] | 17 | #include <linux/mutex.h> |
Al Viro | 84a9f33 | 2008-06-22 14:19:29 -0300 | [diff] [blame] | 18 | #include <asm/unaligned.h> |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 19 | #include "tuner-i2c.h" |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 20 | #include "tuner-xc2028.h" |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 21 | #include "tuner-xc2028-types.h" |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 22 | |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 23 | #include <linux/dvb/frontend.h> |
| 24 | #include "dvb_frontend.h" |
| 25 | |
Mauro Carvalho Chehab | ef8c188 | 2007-11-16 16:28:21 -0300 | [diff] [blame] | 26 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame] | 27 | static int debug; |
| 28 | module_param(debug, int, 0644); |
| 29 | MODULE_PARM_DESC(debug, "enable verbose debug messages"); |
| 30 | |
Mauro Carvalho Chehab | a82200f | 2007-11-15 11:58:00 -0300 | [diff] [blame] | 31 | static char audio_std[8]; |
| 32 | module_param_string(audio_std, audio_std, sizeof(audio_std), 0); |
| 33 | MODULE_PARM_DESC(audio_std, |
| 34 | "Audio standard. XC3028 audio decoder explicitly " |
| 35 | "needs to know what audio\n" |
| 36 | "standard is needed for some video standards with audio A2 or NICAM.\n" |
| 37 | "The valid values are:\n" |
| 38 | "A2\n" |
| 39 | "A2/A\n" |
| 40 | "A2/B\n" |
| 41 | "NICAM\n" |
| 42 | "NICAM/A\n" |
| 43 | "NICAM/B\n"); |
| 44 | |
Mauro Carvalho Chehab | 5c913c0 | 2008-04-22 14:46:24 -0300 | [diff] [blame] | 45 | static char firmware_name[FIRMWARE_NAME_MAX]; |
| 46 | module_param_string(firmware_name, firmware_name, sizeof(firmware_name), 0); |
| 47 | MODULE_PARM_DESC(firmware_name, "Firmware file name. Allows overriding the " |
| 48 | "default firmware name\n"); |
| 49 | |
Michael Krufky | c663d03 | 2008-04-18 21:22:50 -0300 | [diff] [blame] | 50 | static LIST_HEAD(hybrid_tuner_instance_list); |
Chris Pascoe | aa501be | 2007-11-19 04:45:38 -0300 | [diff] [blame] | 51 | static DEFINE_MUTEX(xc2028_list_mutex); |
| 52 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 53 | /* struct for storing firmware table */ |
| 54 | struct firmware_description { |
| 55 | unsigned int type; |
| 56 | v4l2_std_id id; |
Mauro Carvalho Chehab | 66c2d53 | 2007-11-25 19:26:36 -0300 | [diff] [blame] | 57 | __u16 int_freq; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 58 | unsigned char *ptr; |
| 59 | unsigned int size; |
| 60 | }; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 61 | |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 62 | struct firmware_properties { |
| 63 | unsigned int type; |
| 64 | v4l2_std_id id; |
| 65 | v4l2_std_id std_req; |
Mauro Carvalho Chehab | 66c2d53 | 2007-11-25 19:26:36 -0300 | [diff] [blame] | 66 | __u16 int_freq; |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 67 | unsigned int scode_table; |
| 68 | int scode_nr; |
| 69 | }; |
| 70 | |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 71 | struct xc2028_data { |
Michael Krufky | c663d03 | 2008-04-18 21:22:50 -0300 | [diff] [blame] | 72 | struct list_head hybrid_tuner_instance_list; |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 73 | struct tuner_i2c_props i2c_props; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 74 | __u32 frequency; |
| 75 | |
| 76 | struct firmware_description *firm; |
| 77 | int firm_size; |
Chris Pascoe | 06fd82d | 2007-11-19 06:06:08 -0300 | [diff] [blame] | 78 | __u16 firm_version; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 79 | |
Chris Pascoe | 8bf799a | 2007-11-19 11:35:45 -0300 | [diff] [blame] | 80 | __u16 hwmodel; |
| 81 | __u16 hwvers; |
| 82 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 83 | struct xc2028_ctrl ctrl; |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 84 | |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 85 | struct firmware_properties cur_fw; |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 86 | |
| 87 | struct mutex lock; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 88 | }; |
| 89 | |
Chris Pascoe | 47cc5b7 | 2007-11-19 04:14:23 -0300 | [diff] [blame] | 90 | #define i2c_send(priv, buf, size) ({ \ |
| 91 | int _rc; \ |
| 92 | _rc = tuner_i2c_xfer_send(&priv->i2c_props, buf, size); \ |
| 93 | if (size != _rc) \ |
| 94 | tuner_info("i2c output error: rc = %d (should be %d)\n",\ |
| 95 | _rc, (int)size); \ |
| 96 | _rc; \ |
| 97 | }) |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 98 | |
Chris Pascoe | 47cc5b7 | 2007-11-19 04:14:23 -0300 | [diff] [blame] | 99 | #define i2c_rcv(priv, buf, size) ({ \ |
| 100 | int _rc; \ |
| 101 | _rc = tuner_i2c_xfer_recv(&priv->i2c_props, buf, size); \ |
| 102 | if (size != _rc) \ |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame] | 103 | tuner_err("i2c input error: rc = %d (should be %d)\n", \ |
Chris Pascoe | 47cc5b7 | 2007-11-19 04:14:23 -0300 | [diff] [blame] | 104 | _rc, (int)size); \ |
| 105 | _rc; \ |
| 106 | }) |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 107 | |
Chris Pascoe | 7d58d11 | 2007-11-19 04:31:58 -0300 | [diff] [blame] | 108 | #define i2c_send_recv(priv, obuf, osize, ibuf, isize) ({ \ |
| 109 | int _rc; \ |
| 110 | _rc = tuner_i2c_xfer_send_recv(&priv->i2c_props, obuf, osize, \ |
| 111 | ibuf, isize); \ |
| 112 | if (isize != _rc) \ |
| 113 | tuner_err("i2c input error: rc = %d (should be %d)\n", \ |
| 114 | _rc, (int)isize); \ |
| 115 | _rc; \ |
| 116 | }) |
| 117 | |
Chris Pascoe | 47cc5b7 | 2007-11-19 04:14:23 -0300 | [diff] [blame] | 118 | #define send_seq(priv, data...) ({ \ |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 119 | static u8 _val[] = data; \ |
Chris Pascoe | 47cc5b7 | 2007-11-19 04:14:23 -0300 | [diff] [blame] | 120 | int _rc; \ |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 121 | if (sizeof(_val) != \ |
Chris Pascoe | 47cc5b7 | 2007-11-19 04:14:23 -0300 | [diff] [blame] | 122 | (_rc = tuner_i2c_xfer_send(&priv->i2c_props, \ |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 123 | _val, sizeof(_val)))) { \ |
Chris Pascoe | 47cc5b7 | 2007-11-19 04:14:23 -0300 | [diff] [blame] | 124 | tuner_err("Error on line %d: %d\n", __LINE__, _rc); \ |
| 125 | } else \ |
| 126 | msleep(10); \ |
| 127 | _rc; \ |
| 128 | }) |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 129 | |
Devin Heitmueller | 8324402 | 2008-04-17 21:41:16 -0300 | [diff] [blame] | 130 | static int xc2028_get_reg(struct xc2028_data *priv, u16 reg, u16 *val) |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 131 | { |
Mauro Carvalho Chehab | b873e1a | 2007-11-05 08:41:50 -0300 | [diff] [blame] | 132 | unsigned char buf[2]; |
Chris Pascoe | 7d58d11 | 2007-11-19 04:31:58 -0300 | [diff] [blame] | 133 | unsigned char ibuf[2]; |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 134 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 135 | tuner_dbg("%s %04x called\n", __func__, reg); |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 136 | |
Chris Pascoe | 7d58d11 | 2007-11-19 04:31:58 -0300 | [diff] [blame] | 137 | buf[0] = reg >> 8; |
Mauro Carvalho Chehab | 80b5220 | 2007-11-05 09:07:13 -0300 | [diff] [blame] | 138 | buf[1] = (unsigned char) reg; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 139 | |
Chris Pascoe | 7d58d11 | 2007-11-19 04:31:58 -0300 | [diff] [blame] | 140 | if (i2c_send_recv(priv, buf, 2, ibuf, 2) != 2) |
| 141 | return -EIO; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 142 | |
Chris Pascoe | 7d58d11 | 2007-11-19 04:31:58 -0300 | [diff] [blame] | 143 | *val = (ibuf[1]) | (ibuf[0] << 8); |
| 144 | return 0; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 145 | } |
| 146 | |
Chris Pascoe | e026268 | 2007-12-02 06:30:50 -0300 | [diff] [blame] | 147 | #define dump_firm_type(t) dump_firm_type_and_int_freq(t, 0) |
Adrian Bunk | 29bec0b | 2008-04-22 14:41:45 -0300 | [diff] [blame] | 148 | static void dump_firm_type_and_int_freq(unsigned int type, u16 int_freq) |
Mauro Carvalho Chehab | 43efe70 | 2007-11-14 19:30:28 -0300 | [diff] [blame] | 149 | { |
| 150 | if (type & BASE) |
| 151 | printk("BASE "); |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 152 | if (type & INIT1) |
| 153 | printk("INIT1 "); |
Mauro Carvalho Chehab | 43efe70 | 2007-11-14 19:30:28 -0300 | [diff] [blame] | 154 | if (type & F8MHZ) |
| 155 | printk("F8MHZ "); |
| 156 | if (type & MTS) |
| 157 | printk("MTS "); |
| 158 | if (type & D2620) |
| 159 | printk("D2620 "); |
| 160 | if (type & D2633) |
| 161 | printk("D2633 "); |
| 162 | if (type & DTV6) |
| 163 | printk("DTV6 "); |
| 164 | if (type & QAM) |
| 165 | printk("QAM "); |
| 166 | if (type & DTV7) |
| 167 | printk("DTV7 "); |
| 168 | if (type & DTV78) |
| 169 | printk("DTV78 "); |
| 170 | if (type & DTV8) |
| 171 | printk("DTV8 "); |
| 172 | if (type & FM) |
| 173 | printk("FM "); |
| 174 | if (type & INPUT1) |
| 175 | printk("INPUT1 "); |
| 176 | if (type & LCD) |
| 177 | printk("LCD "); |
| 178 | if (type & NOGD) |
| 179 | printk("NOGD "); |
| 180 | if (type & MONO) |
| 181 | printk("MONO "); |
| 182 | if (type & ATSC) |
| 183 | printk("ATSC "); |
| 184 | if (type & IF) |
| 185 | printk("IF "); |
| 186 | if (type & LG60) |
| 187 | printk("LG60 "); |
| 188 | if (type & ATI638) |
| 189 | printk("ATI638 "); |
| 190 | if (type & OREN538) |
| 191 | printk("OREN538 "); |
| 192 | if (type & OREN36) |
| 193 | printk("OREN36 "); |
| 194 | if (type & TOYOTA388) |
| 195 | printk("TOYOTA388 "); |
| 196 | if (type & TOYOTA794) |
| 197 | printk("TOYOTA794 "); |
| 198 | if (type & DIBCOM52) |
| 199 | printk("DIBCOM52 "); |
| 200 | if (type & ZARLINK456) |
| 201 | printk("ZARLINK456 "); |
| 202 | if (type & CHINA) |
| 203 | printk("CHINA "); |
| 204 | if (type & F6MHZ) |
| 205 | printk("F6MHZ "); |
| 206 | if (type & INPUT2) |
| 207 | printk("INPUT2 "); |
| 208 | if (type & SCODE) |
| 209 | printk("SCODE "); |
Chris Pascoe | e026268 | 2007-12-02 06:30:50 -0300 | [diff] [blame] | 210 | if (type & HAS_IF) |
| 211 | printk("HAS_IF_%d ", int_freq); |
Mauro Carvalho Chehab | 43efe70 | 2007-11-14 19:30:28 -0300 | [diff] [blame] | 212 | } |
| 213 | |
Mauro Carvalho Chehab | ef8c188 | 2007-11-16 16:28:21 -0300 | [diff] [blame] | 214 | static v4l2_std_id parse_audio_std_option(void) |
Mauro Carvalho Chehab | a82200f | 2007-11-15 11:58:00 -0300 | [diff] [blame] | 215 | { |
Chris Pascoe | e155d90 | 2007-11-19 04:16:47 -0300 | [diff] [blame] | 216 | if (strcasecmp(audio_std, "A2") == 0) |
Mauro Carvalho Chehab | a82200f | 2007-11-15 11:58:00 -0300 | [diff] [blame] | 217 | return V4L2_STD_A2; |
Chris Pascoe | e155d90 | 2007-11-19 04:16:47 -0300 | [diff] [blame] | 218 | if (strcasecmp(audio_std, "A2/A") == 0) |
Mauro Carvalho Chehab | a82200f | 2007-11-15 11:58:00 -0300 | [diff] [blame] | 219 | return V4L2_STD_A2_A; |
Chris Pascoe | e155d90 | 2007-11-19 04:16:47 -0300 | [diff] [blame] | 220 | if (strcasecmp(audio_std, "A2/B") == 0) |
Mauro Carvalho Chehab | a82200f | 2007-11-15 11:58:00 -0300 | [diff] [blame] | 221 | return V4L2_STD_A2_B; |
Chris Pascoe | e155d90 | 2007-11-19 04:16:47 -0300 | [diff] [blame] | 222 | if (strcasecmp(audio_std, "NICAM") == 0) |
Mauro Carvalho Chehab | a82200f | 2007-11-15 11:58:00 -0300 | [diff] [blame] | 223 | return V4L2_STD_NICAM; |
Chris Pascoe | e155d90 | 2007-11-19 04:16:47 -0300 | [diff] [blame] | 224 | if (strcasecmp(audio_std, "NICAM/A") == 0) |
Mauro Carvalho Chehab | a82200f | 2007-11-15 11:58:00 -0300 | [diff] [blame] | 225 | return V4L2_STD_NICAM_A; |
Chris Pascoe | e155d90 | 2007-11-19 04:16:47 -0300 | [diff] [blame] | 226 | if (strcasecmp(audio_std, "NICAM/B") == 0) |
Mauro Carvalho Chehab | a82200f | 2007-11-15 11:58:00 -0300 | [diff] [blame] | 227 | return V4L2_STD_NICAM_B; |
| 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 232 | static void free_firmware(struct xc2028_data *priv) |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 233 | { |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 234 | int i; |
Mauro Carvalho Chehab | 92b75ab | 2008-04-17 21:40:53 -0300 | [diff] [blame] | 235 | tuner_dbg("%s called\n", __func__); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 236 | |
| 237 | if (!priv->firm) |
| 238 | return; |
| 239 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 240 | for (i = 0; i < priv->firm_size; i++) |
| 241 | kfree(priv->firm[i].ptr); |
| 242 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 243 | kfree(priv->firm); |
| 244 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 245 | priv->firm = NULL; |
Chris Pascoe | 06fd82d | 2007-11-19 06:06:08 -0300 | [diff] [blame] | 246 | priv->firm_size = 0; |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 247 | |
| 248 | memset(&priv->cur_fw, 0, sizeof(priv->cur_fw)); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 249 | } |
| 250 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 251 | static int load_all_firmwares(struct dvb_frontend *fe) |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 252 | { |
| 253 | struct xc2028_data *priv = fe->tuner_priv; |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 254 | const struct firmware *fw = NULL; |
David Woodhouse | c63e87e | 2008-05-24 00:13:34 +0100 | [diff] [blame] | 255 | const unsigned char *p, *endp; |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 256 | int rc = 0; |
| 257 | int n, n_array; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 258 | char name[33]; |
Mauro Carvalho Chehab | 5c913c0 | 2008-04-22 14:46:24 -0300 | [diff] [blame] | 259 | char *fname; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 260 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 261 | tuner_dbg("%s called\n", __func__); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 262 | |
Mauro Carvalho Chehab | 5c913c0 | 2008-04-22 14:46:24 -0300 | [diff] [blame] | 263 | if (!firmware_name[0]) |
| 264 | fname = priv->ctrl.fname; |
| 265 | else |
| 266 | fname = firmware_name; |
| 267 | |
| 268 | tuner_dbg("Reading firmware %s\n", fname); |
| 269 | rc = request_firmware(&fw, fname, &priv->i2c_props.adap->dev); |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 270 | if (rc < 0) { |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 271 | if (rc == -ENOENT) |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame] | 272 | tuner_err("Error: firmware %s not found.\n", |
Mauro Carvalho Chehab | 5c913c0 | 2008-04-22 14:46:24 -0300 | [diff] [blame] | 273 | fname); |
Mauro Carvalho Chehab | 2e4160c | 2007-07-18 13:33:23 -0300 | [diff] [blame] | 274 | else |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame] | 275 | tuner_err("Error %d while requesting firmware %s \n", |
Mauro Carvalho Chehab | 5c913c0 | 2008-04-22 14:46:24 -0300 | [diff] [blame] | 276 | rc, fname); |
Mauro Carvalho Chehab | 2e4160c | 2007-07-18 13:33:23 -0300 | [diff] [blame] | 277 | |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 278 | return rc; |
| 279 | } |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 280 | p = fw->data; |
| 281 | endp = p + fw->size; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 282 | |
Chris Pascoe | 06fd82d | 2007-11-19 06:06:08 -0300 | [diff] [blame] | 283 | if (fw->size < sizeof(name) - 1 + 2 + 2) { |
| 284 | tuner_err("Error: firmware file %s has invalid size!\n", |
Mauro Carvalho Chehab | 5c913c0 | 2008-04-22 14:46:24 -0300 | [diff] [blame] | 285 | fname); |
Chris Pascoe | 06fd82d | 2007-11-19 06:06:08 -0300 | [diff] [blame] | 286 | goto corrupt; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 287 | } |
| 288 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 289 | memcpy(name, p, sizeof(name) - 1); |
| 290 | name[sizeof(name) - 1] = 0; |
| 291 | p += sizeof(name) - 1; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 292 | |
Al Viro | 84a9f33 | 2008-06-22 14:19:29 -0300 | [diff] [blame] | 293 | priv->firm_version = get_unaligned_le16(p); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 294 | p += 2; |
| 295 | |
Al Viro | 84a9f33 | 2008-06-22 14:19:29 -0300 | [diff] [blame] | 296 | n_array = get_unaligned_le16(p); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 297 | p += 2; |
| 298 | |
Chris Pascoe | 06fd82d | 2007-11-19 06:06:08 -0300 | [diff] [blame] | 299 | tuner_info("Loading %d firmware images from %s, type: %s, ver %d.%d\n", |
Mauro Carvalho Chehab | 5c913c0 | 2008-04-22 14:46:24 -0300 | [diff] [blame] | 300 | n_array, fname, name, |
Chris Pascoe | 06fd82d | 2007-11-19 06:06:08 -0300 | [diff] [blame] | 301 | priv->firm_version >> 8, priv->firm_version & 0xff); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 302 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 303 | priv->firm = kzalloc(sizeof(*priv->firm) * n_array, GFP_KERNEL); |
Chris Pascoe | 06fd82d | 2007-11-19 06:06:08 -0300 | [diff] [blame] | 304 | if (priv->firm == NULL) { |
| 305 | tuner_err("Not enough memory to load firmware file.\n"); |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 306 | rc = -ENOMEM; |
Chris Pascoe | 06fd82d | 2007-11-19 06:06:08 -0300 | [diff] [blame] | 307 | goto err; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 308 | } |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 309 | priv->firm_size = n_array; |
Chris Pascoe | 06fd82d | 2007-11-19 06:06:08 -0300 | [diff] [blame] | 310 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 311 | n = -1; |
| 312 | while (p < endp) { |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 313 | __u32 type, size; |
| 314 | v4l2_std_id id; |
Mauro Carvalho Chehab | 66c2d53 | 2007-11-25 19:26:36 -0300 | [diff] [blame] | 315 | __u16 int_freq = 0; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 316 | |
| 317 | n++; |
| 318 | if (n >= n_array) { |
Chris Pascoe | 06fd82d | 2007-11-19 06:06:08 -0300 | [diff] [blame] | 319 | tuner_err("More firmware images in file than " |
| 320 | "were expected!\n"); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 321 | goto corrupt; |
| 322 | } |
| 323 | |
| 324 | /* Checks if there's enough bytes to read */ |
Al Viro | 84a9f33 | 2008-06-22 14:19:29 -0300 | [diff] [blame] | 325 | if (endp - p < sizeof(type) + sizeof(id) + sizeof(size)) |
| 326 | goto header; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 327 | |
Al Viro | 84a9f33 | 2008-06-22 14:19:29 -0300 | [diff] [blame] | 328 | type = get_unaligned_le32(p); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 329 | p += sizeof(type); |
| 330 | |
Al Viro | 84a9f33 | 2008-06-22 14:19:29 -0300 | [diff] [blame] | 331 | id = get_unaligned_le64(p); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 332 | p += sizeof(id); |
| 333 | |
Mauro Carvalho Chehab | 66c2d53 | 2007-11-25 19:26:36 -0300 | [diff] [blame] | 334 | if (type & HAS_IF) { |
Al Viro | 84a9f33 | 2008-06-22 14:19:29 -0300 | [diff] [blame] | 335 | int_freq = get_unaligned_le16(p); |
Mauro Carvalho Chehab | 66c2d53 | 2007-11-25 19:26:36 -0300 | [diff] [blame] | 336 | p += sizeof(int_freq); |
Al Viro | 84a9f33 | 2008-06-22 14:19:29 -0300 | [diff] [blame] | 337 | if (endp - p < sizeof(size)) |
| 338 | goto header; |
Mauro Carvalho Chehab | 66c2d53 | 2007-11-25 19:26:36 -0300 | [diff] [blame] | 339 | } |
| 340 | |
Al Viro | 84a9f33 | 2008-06-22 14:19:29 -0300 | [diff] [blame] | 341 | size = get_unaligned_le32(p); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 342 | p += sizeof(size); |
| 343 | |
Al Viro | 84a9f33 | 2008-06-22 14:19:29 -0300 | [diff] [blame] | 344 | if (!size || size > endp - p) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame] | 345 | tuner_err("Firmware type "); |
Mauro Carvalho Chehab | 43efe70 | 2007-11-14 19:30:28 -0300 | [diff] [blame] | 346 | dump_firm_type(type); |
Mauro Carvalho Chehab | ef8c188 | 2007-11-16 16:28:21 -0300 | [diff] [blame] | 347 | printk("(%x), id %llx is corrupted " |
| 348 | "(size=%d, expected %d)\n", |
Chris Pascoe | 91240dd | 2007-11-19 04:38:53 -0300 | [diff] [blame] | 349 | type, (unsigned long long)id, |
Mauro Carvalho Chehab | ef8c188 | 2007-11-16 16:28:21 -0300 | [diff] [blame] | 350 | (unsigned)(endp - p), size); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 351 | goto corrupt; |
| 352 | } |
| 353 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 354 | priv->firm[n].ptr = kzalloc(size, GFP_KERNEL); |
Chris Pascoe | 06fd82d | 2007-11-19 06:06:08 -0300 | [diff] [blame] | 355 | if (priv->firm[n].ptr == NULL) { |
| 356 | tuner_err("Not enough memory to load firmware file.\n"); |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 357 | rc = -ENOMEM; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 358 | goto err; |
| 359 | } |
Chris Pascoe | 06fd82d | 2007-11-19 06:06:08 -0300 | [diff] [blame] | 360 | tuner_dbg("Reading firmware type "); |
| 361 | if (debug) { |
Chris Pascoe | e026268 | 2007-12-02 06:30:50 -0300 | [diff] [blame] | 362 | dump_firm_type_and_int_freq(type, int_freq); |
Chris Pascoe | 06fd82d | 2007-11-19 06:06:08 -0300 | [diff] [blame] | 363 | printk("(%x), id %llx, size=%d.\n", |
Chris Pascoe | e026268 | 2007-12-02 06:30:50 -0300 | [diff] [blame] | 364 | type, (unsigned long long)id, size); |
Chris Pascoe | 06fd82d | 2007-11-19 06:06:08 -0300 | [diff] [blame] | 365 | } |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 366 | |
| 367 | memcpy(priv->firm[n].ptr, p, size); |
| 368 | priv->firm[n].type = type; |
| 369 | priv->firm[n].id = id; |
| 370 | priv->firm[n].size = size; |
Mauro Carvalho Chehab | 66c2d53 | 2007-11-25 19:26:36 -0300 | [diff] [blame] | 371 | priv->firm[n].int_freq = int_freq; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 372 | |
| 373 | p += size; |
| 374 | } |
| 375 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 376 | if (n + 1 != priv->firm_size) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame] | 377 | tuner_err("Firmware file is incomplete!\n"); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 378 | goto corrupt; |
| 379 | } |
| 380 | |
| 381 | goto done; |
| 382 | |
Al Viro | 84a9f33 | 2008-06-22 14:19:29 -0300 | [diff] [blame] | 383 | header: |
| 384 | tuner_err("Firmware header is incomplete!\n"); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 385 | corrupt: |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 386 | rc = -EINVAL; |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame] | 387 | tuner_err("Error: firmware file is corrupted!\n"); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 388 | |
| 389 | err: |
Chris Pascoe | 06fd82d | 2007-11-19 06:06:08 -0300 | [diff] [blame] | 390 | tuner_info("Releasing partially loaded firmware file.\n"); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 391 | free_firmware(priv); |
| 392 | |
| 393 | done: |
| 394 | release_firmware(fw); |
Chris Pascoe | 06fd82d | 2007-11-19 06:06:08 -0300 | [diff] [blame] | 395 | if (rc == 0) |
| 396 | tuner_dbg("Firmware files loaded.\n"); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 397 | |
| 398 | return rc; |
| 399 | } |
| 400 | |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 401 | static int seek_firmware(struct dvb_frontend *fe, unsigned int type, |
| 402 | v4l2_std_id *id) |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 403 | { |
| 404 | struct xc2028_data *priv = fe->tuner_priv; |
Chris Pascoe | b153529 | 2007-11-19 10:04:06 -0300 | [diff] [blame] | 405 | int i, best_i = -1, best_nr_matches = 0; |
Mauro Carvalho Chehab | 33e5316 | 2008-04-21 06:58:48 -0300 | [diff] [blame] | 406 | unsigned int type_mask = 0; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 407 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 408 | tuner_dbg("%s called, want type=", __func__); |
Chris Pascoe | b153529 | 2007-11-19 10:04:06 -0300 | [diff] [blame] | 409 | if (debug) { |
| 410 | dump_firm_type(type); |
| 411 | printk("(%x), id %016llx.\n", type, (unsigned long long)*id); |
| 412 | } |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 413 | |
| 414 | if (!priv->firm) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame] | 415 | tuner_err("Error! firmware not loaded\n"); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 416 | return -EINVAL; |
| 417 | } |
| 418 | |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 419 | if (((type & ~SCODE) == 0) && (*id == 0)) |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 420 | *id = V4L2_STD_PAL; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 421 | |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 422 | if (type & BASE) |
Mauro Carvalho Chehab | 33e5316 | 2008-04-21 06:58:48 -0300 | [diff] [blame] | 423 | type_mask = BASE_TYPES; |
Chris Pascoe | ef207fe | 2007-12-02 09:30:55 -0300 | [diff] [blame] | 424 | else if (type & SCODE) { |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 425 | type &= SCODE_TYPES; |
Mauro Carvalho Chehab | 33e5316 | 2008-04-21 06:58:48 -0300 | [diff] [blame] | 426 | type_mask = SCODE_TYPES & ~HAS_IF; |
Chris Pascoe | ef207fe | 2007-12-02 09:30:55 -0300 | [diff] [blame] | 427 | } else if (type & DTV_TYPES) |
Mauro Carvalho Chehab | 33e5316 | 2008-04-21 06:58:48 -0300 | [diff] [blame] | 428 | type_mask = DTV_TYPES; |
Chris Pascoe | 11a9eff | 2007-11-19 23:18:36 -0300 | [diff] [blame] | 429 | else if (type & STD_SPECIFIC_TYPES) |
Mauro Carvalho Chehab | 33e5316 | 2008-04-21 06:58:48 -0300 | [diff] [blame] | 430 | type_mask = STD_SPECIFIC_TYPES; |
| 431 | |
| 432 | type &= type_mask; |
| 433 | |
Harvey Harrison | 8367fe2 | 2008-04-25 01:28:10 -0300 | [diff] [blame] | 434 | if (!(type & SCODE)) |
Mauro Carvalho Chehab | 33e5316 | 2008-04-21 06:58:48 -0300 | [diff] [blame] | 435 | type_mask = ~0; |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 436 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 437 | /* Seek for exact match */ |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 438 | for (i = 0; i < priv->firm_size; i++) { |
Mauro Carvalho Chehab | 33e5316 | 2008-04-21 06:58:48 -0300 | [diff] [blame] | 439 | if ((type == (priv->firm[i].type & type_mask)) && |
Chris Pascoe | ef207fe | 2007-12-02 09:30:55 -0300 | [diff] [blame] | 440 | (*id == priv->firm[i].id)) |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 441 | goto found; |
| 442 | } |
| 443 | |
| 444 | /* Seek for generic video standard match */ |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 445 | for (i = 0; i < priv->firm_size; i++) { |
Chris Pascoe | b153529 | 2007-11-19 10:04:06 -0300 | [diff] [blame] | 446 | v4l2_std_id match_mask; |
| 447 | int nr_matches; |
| 448 | |
Mauro Carvalho Chehab | 33e5316 | 2008-04-21 06:58:48 -0300 | [diff] [blame] | 449 | if (type != (priv->firm[i].type & type_mask)) |
Chris Pascoe | b153529 | 2007-11-19 10:04:06 -0300 | [diff] [blame] | 450 | continue; |
| 451 | |
| 452 | match_mask = *id & priv->firm[i].id; |
| 453 | if (!match_mask) |
| 454 | continue; |
| 455 | |
| 456 | if ((*id & match_mask) == *id) |
| 457 | goto found; /* Supports all the requested standards */ |
| 458 | |
| 459 | nr_matches = hweight64(match_mask); |
| 460 | if (nr_matches > best_nr_matches) { |
| 461 | best_nr_matches = nr_matches; |
| 462 | best_i = i; |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | if (best_nr_matches > 0) { |
| 467 | tuner_dbg("Selecting best matching firmware (%d bits) for " |
| 468 | "type=", best_nr_matches); |
| 469 | dump_firm_type(type); |
| 470 | printk("(%x), id %016llx:\n", type, (unsigned long long)*id); |
| 471 | i = best_i; |
| 472 | goto found; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | /*FIXME: Would make sense to seek for type "hint" match ? */ |
| 476 | |
Chris Pascoe | b153529 | 2007-11-19 10:04:06 -0300 | [diff] [blame] | 477 | i = -ENOENT; |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 478 | goto ret; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 479 | |
| 480 | found: |
| 481 | *id = priv->firm[i].id; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 482 | |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 483 | ret: |
Chris Pascoe | b153529 | 2007-11-19 10:04:06 -0300 | [diff] [blame] | 484 | tuner_dbg("%s firmware for type=", (i < 0) ? "Can't find" : "Found"); |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame] | 485 | if (debug) { |
| 486 | dump_firm_type(type); |
Chris Pascoe | 91240dd | 2007-11-19 04:38:53 -0300 | [diff] [blame] | 487 | printk("(%x), id %016llx.\n", type, (unsigned long long)*id); |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame] | 488 | } |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 489 | return i; |
| 490 | } |
| 491 | |
Michael Krufky | d7cba04 | 2008-09-12 13:31:45 -0300 | [diff] [blame] | 492 | static inline int do_tuner_callback(struct dvb_frontend *fe, int cmd, int arg) |
| 493 | { |
| 494 | struct xc2028_data *priv = fe->tuner_priv; |
| 495 | |
| 496 | /* analog side (tuner-core) uses i2c_adap->algo_data. |
| 497 | * digital side is not guaranteed to have algo_data defined. |
| 498 | * |
| 499 | * digital side will always have fe->dvb defined. |
| 500 | * analog side (tuner-core) doesn't (yet) define fe->dvb. |
| 501 | */ |
| 502 | |
| 503 | return (!fe->callback) ? -EINVAL : |
| 504 | fe->callback(((fe->dvb) && (fe->dvb->priv)) ? |
| 505 | fe->dvb->priv : priv->i2c_props.adap->algo_data, |
| 506 | DVB_FRONTEND_COMPONENT_TUNER, cmd, arg); |
| 507 | } |
| 508 | |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 509 | static int load_firmware(struct dvb_frontend *fe, unsigned int type, |
| 510 | v4l2_std_id *id) |
| 511 | { |
| 512 | struct xc2028_data *priv = fe->tuner_priv; |
| 513 | int pos, rc; |
Chris Pascoe | 0a196b6 | 2007-11-19 09:29:59 -0300 | [diff] [blame] | 514 | unsigned char *p, *endp, buf[priv->ctrl.max_len]; |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 515 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 516 | tuner_dbg("%s called\n", __func__); |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 517 | |
| 518 | pos = seek_firmware(fe, type, id); |
| 519 | if (pos < 0) |
| 520 | return pos; |
| 521 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame] | 522 | tuner_info("Loading firmware for type="); |
Chris Pascoe | b153529 | 2007-11-19 10:04:06 -0300 | [diff] [blame] | 523 | dump_firm_type(priv->firm[pos].type); |
| 524 | printk("(%x), id %016llx.\n", priv->firm[pos].type, |
| 525 | (unsigned long long)*id); |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame] | 526 | |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 527 | p = priv->firm[pos].ptr; |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 528 | endp = p + priv->firm[pos].size; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 529 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 530 | while (p < endp) { |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 531 | __u16 size; |
| 532 | |
| 533 | /* Checks if there's enough bytes to read */ |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 534 | if (p + sizeof(size) > endp) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame] | 535 | tuner_err("Firmware chunk size is wrong\n"); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 536 | return -EINVAL; |
| 537 | } |
| 538 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 539 | size = le16_to_cpu(*(__u16 *) p); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 540 | p += sizeof(size); |
| 541 | |
| 542 | if (size == 0xffff) |
| 543 | return 0; |
| 544 | |
| 545 | if (!size) { |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 546 | /* Special callback command received */ |
Michael Krufky | d7cba04 | 2008-09-12 13:31:45 -0300 | [diff] [blame] | 547 | rc = do_tuner_callback(fe, XC2028_TUNER_RESET, 0); |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 548 | if (rc < 0) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame] | 549 | tuner_err("Error at RESET code %d\n", |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 550 | (*p) & 0x7f); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 551 | return -EINVAL; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 552 | } |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 553 | continue; |
| 554 | } |
Michel Ludwig | 5403bba | 2007-11-16 07:49:49 -0300 | [diff] [blame] | 555 | if (size >= 0xff00) { |
| 556 | switch (size) { |
| 557 | case 0xff00: |
Michael Krufky | d7cba04 | 2008-09-12 13:31:45 -0300 | [diff] [blame] | 558 | rc = do_tuner_callback(fe, XC2028_RESET_CLK, 0); |
Michel Ludwig | 5403bba | 2007-11-16 07:49:49 -0300 | [diff] [blame] | 559 | if (rc < 0) { |
| 560 | tuner_err("Error at RESET code %d\n", |
| 561 | (*p) & 0x7f); |
| 562 | return -EINVAL; |
| 563 | } |
Chris Pascoe | b32f9fb | 2007-11-19 04:53:50 -0300 | [diff] [blame] | 564 | break; |
Michel Ludwig | 5403bba | 2007-11-16 07:49:49 -0300 | [diff] [blame] | 565 | default: |
| 566 | tuner_info("Invalid RESET code %d\n", |
| 567 | size & 0x7f); |
| 568 | return -EINVAL; |
| 569 | |
| 570 | } |
Mauro Carvalho Chehab | 2d4c0ac | 2007-11-16 09:43:19 -0300 | [diff] [blame] | 571 | continue; |
Michel Ludwig | 5403bba | 2007-11-16 07:49:49 -0300 | [diff] [blame] | 572 | } |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 573 | |
| 574 | /* Checks for a sleep command */ |
| 575 | if (size & 0x8000) { |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 576 | msleep(size & 0x7fff); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 577 | continue; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 578 | } |
| 579 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 580 | if ((size + p > endp)) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame] | 581 | tuner_err("missing bytes: need %d, have %d\n", |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 582 | size, (int)(endp - p)); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 583 | return -EINVAL; |
| 584 | } |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 585 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 586 | buf[0] = *p; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 587 | p++; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 588 | size--; |
| 589 | |
| 590 | /* Sends message chunks */ |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 591 | while (size > 0) { |
Chris Pascoe | 0a196b6 | 2007-11-19 09:29:59 -0300 | [diff] [blame] | 592 | int len = (size < priv->ctrl.max_len - 1) ? |
| 593 | size : priv->ctrl.max_len - 1; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 594 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 595 | memcpy(buf + 1, p, len); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 596 | |
Chris Pascoe | 47cc5b7 | 2007-11-19 04:14:23 -0300 | [diff] [blame] | 597 | rc = i2c_send(priv, buf, len + 1); |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 598 | if (rc < 0) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame] | 599 | tuner_err("%d returned from send\n", rc); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 600 | return -EINVAL; |
| 601 | } |
| 602 | |
| 603 | p += len; |
| 604 | size -= len; |
| 605 | } |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 606 | } |
Mauro Carvalho Chehab | 43efe70 | 2007-11-14 19:30:28 -0300 | [diff] [blame] | 607 | return 0; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 608 | } |
| 609 | |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 610 | static int load_scode(struct dvb_frontend *fe, unsigned int type, |
Mauro Carvalho Chehab | 66c2d53 | 2007-11-25 19:26:36 -0300 | [diff] [blame] | 611 | v4l2_std_id *id, __u16 int_freq, int scode) |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 612 | { |
| 613 | struct xc2028_data *priv = fe->tuner_priv; |
| 614 | int pos, rc; |
| 615 | unsigned char *p; |
| 616 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 617 | tuner_dbg("%s called\n", __func__); |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 618 | |
Mauro Carvalho Chehab | 66c2d53 | 2007-11-25 19:26:36 -0300 | [diff] [blame] | 619 | if (!int_freq) { |
| 620 | pos = seek_firmware(fe, type, id); |
| 621 | if (pos < 0) |
| 622 | return pos; |
| 623 | } else { |
| 624 | for (pos = 0; pos < priv->firm_size; pos++) { |
| 625 | if ((priv->firm[pos].int_freq == int_freq) && |
Chris Pascoe | 9ca01e7 | 2007-12-02 06:54:17 -0300 | [diff] [blame] | 626 | (priv->firm[pos].type & HAS_IF)) |
Mauro Carvalho Chehab | 66c2d53 | 2007-11-25 19:26:36 -0300 | [diff] [blame] | 627 | break; |
| 628 | } |
| 629 | if (pos == priv->firm_size) |
| 630 | return -ENOENT; |
| 631 | } |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 632 | |
| 633 | p = priv->firm[pos].ptr; |
| 634 | |
Chris Pascoe | 9ca01e7 | 2007-12-02 06:54:17 -0300 | [diff] [blame] | 635 | if (priv->firm[pos].type & HAS_IF) { |
Mauro Carvalho Chehab | 66c2d53 | 2007-11-25 19:26:36 -0300 | [diff] [blame] | 636 | if (priv->firm[pos].size != 12 * 16 || scode >= 16) |
| 637 | return -EINVAL; |
| 638 | p += 12 * scode; |
| 639 | } else { |
| 640 | /* 16 SCODE entries per file; each SCODE entry is 12 bytes and |
| 641 | * has a 2-byte size header in the firmware format. */ |
| 642 | if (priv->firm[pos].size != 14 * 16 || scode >= 16 || |
| 643 | le16_to_cpu(*(__u16 *)(p + 14 * scode)) != 12) |
| 644 | return -EINVAL; |
| 645 | p += 14 * scode + 2; |
| 646 | } |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 647 | |
Chris Pascoe | d7b22c5 | 2007-11-19 10:12:45 -0300 | [diff] [blame] | 648 | tuner_info("Loading SCODE for type="); |
Chris Pascoe | e026268 | 2007-12-02 06:30:50 -0300 | [diff] [blame] | 649 | dump_firm_type_and_int_freq(priv->firm[pos].type, |
| 650 | priv->firm[pos].int_freq); |
Chris Pascoe | d7b22c5 | 2007-11-19 10:12:45 -0300 | [diff] [blame] | 651 | printk("(%x), id %016llx.\n", priv->firm[pos].type, |
| 652 | (unsigned long long)*id); |
| 653 | |
Chris Pascoe | 06fd82d | 2007-11-19 06:06:08 -0300 | [diff] [blame] | 654 | if (priv->firm_version < 0x0202) |
Chris Pascoe | 47cc5b7 | 2007-11-19 04:14:23 -0300 | [diff] [blame] | 655 | rc = send_seq(priv, {0x20, 0x00, 0x00, 0x00}); |
| 656 | else |
| 657 | rc = send_seq(priv, {0xa0, 0x00, 0x00, 0x00}); |
| 658 | if (rc < 0) |
| 659 | return -EIO; |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 660 | |
Mauro Carvalho Chehab | 66c2d53 | 2007-11-25 19:26:36 -0300 | [diff] [blame] | 661 | rc = i2c_send(priv, p, 12); |
Chris Pascoe | 47cc5b7 | 2007-11-19 04:14:23 -0300 | [diff] [blame] | 662 | if (rc < 0) |
| 663 | return -EIO; |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 664 | |
Chris Pascoe | 47cc5b7 | 2007-11-19 04:14:23 -0300 | [diff] [blame] | 665 | rc = send_seq(priv, {0x00, 0x8c}); |
| 666 | if (rc < 0) |
| 667 | return -EIO; |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 668 | |
| 669 | return 0; |
| 670 | } |
| 671 | |
Mauro Carvalho Chehab | 00deff1 | 2007-11-24 10:13:42 -0300 | [diff] [blame] | 672 | static int check_firmware(struct dvb_frontend *fe, unsigned int type, |
Mauro Carvalho Chehab | 66c2d53 | 2007-11-25 19:26:36 -0300 | [diff] [blame] | 673 | v4l2_std_id std, __u16 int_freq) |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 674 | { |
Mauro Carvalho Chehab | 00deff1 | 2007-11-24 10:13:42 -0300 | [diff] [blame] | 675 | struct xc2028_data *priv = fe->tuner_priv; |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 676 | struct firmware_properties new_fw; |
Mauro Carvalho Chehab | 00deff1 | 2007-11-24 10:13:42 -0300 | [diff] [blame] | 677 | int rc = 0, is_retry = 0; |
| 678 | u16 version, hwmodel; |
| 679 | v4l2_std_id std0; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 680 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 681 | tuner_dbg("%s called\n", __func__); |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 682 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 683 | if (!priv->firm) { |
Michel Ludwig | a37b4c9 | 2007-11-16 07:46:14 -0300 | [diff] [blame] | 684 | if (!priv->ctrl.fname) { |
| 685 | tuner_info("xc2028/3028 firmware name not set!\n"); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 686 | return -EINVAL; |
Michel Ludwig | a37b4c9 | 2007-11-16 07:46:14 -0300 | [diff] [blame] | 687 | } |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 688 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 689 | rc = load_all_firmwares(fe); |
| 690 | if (rc < 0) |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 691 | return rc; |
| 692 | } |
| 693 | |
Mauro Carvalho Chehab | 0f6dac1 | 2008-01-05 16:47:16 -0300 | [diff] [blame] | 694 | if (priv->ctrl.mts && !(type & FM)) |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 695 | type |= MTS; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 696 | |
Chris Pascoe | 8bf799a | 2007-11-19 11:35:45 -0300 | [diff] [blame] | 697 | retry: |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 698 | new_fw.type = type; |
| 699 | new_fw.id = std; |
| 700 | new_fw.std_req = std; |
| 701 | new_fw.scode_table = SCODE | priv->ctrl.scode_table; |
| 702 | new_fw.scode_nr = 0; |
Mauro Carvalho Chehab | 66c2d53 | 2007-11-25 19:26:36 -0300 | [diff] [blame] | 703 | new_fw.int_freq = int_freq; |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 704 | |
| 705 | tuner_dbg("checking firmware, user requested type="); |
| 706 | if (debug) { |
| 707 | dump_firm_type(new_fw.type); |
Chris Pascoe | e026268 | 2007-12-02 06:30:50 -0300 | [diff] [blame] | 708 | printk("(%x), id %016llx, ", new_fw.type, |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 709 | (unsigned long long)new_fw.std_req); |
Chris Pascoe | e026268 | 2007-12-02 06:30:50 -0300 | [diff] [blame] | 710 | if (!int_freq) { |
| 711 | printk("scode_tbl "); |
| 712 | dump_firm_type(priv->ctrl.scode_table); |
| 713 | printk("(%x), ", priv->ctrl.scode_table); |
| 714 | } else |
| 715 | printk("int_freq %d, ", new_fw.int_freq); |
| 716 | printk("scode_nr %d\n", new_fw.scode_nr); |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | /* No need to reload base firmware if it matches */ |
| 720 | if (((BASE | new_fw.type) & BASE_TYPES) == |
| 721 | (priv->cur_fw.type & BASE_TYPES)) { |
| 722 | tuner_dbg("BASE firmware not changed.\n"); |
| 723 | goto skip_base; |
| 724 | } |
| 725 | |
| 726 | /* Updating BASE - forget about all currently loaded firmware */ |
| 727 | memset(&priv->cur_fw, 0, sizeof(priv->cur_fw)); |
| 728 | |
| 729 | /* Reset is needed before loading firmware */ |
Michael Krufky | d7cba04 | 2008-09-12 13:31:45 -0300 | [diff] [blame] | 730 | rc = do_tuner_callback(fe, XC2028_TUNER_RESET, 0); |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 731 | if (rc < 0) |
| 732 | goto fail; |
| 733 | |
Chris Pascoe | 47bd5bc | 2007-11-19 23:11:37 -0300 | [diff] [blame] | 734 | /* BASE firmwares are all std0 */ |
| 735 | std0 = 0; |
| 736 | rc = load_firmware(fe, BASE | new_fw.type, &std0); |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 737 | if (rc < 0) { |
| 738 | tuner_err("Error %d while loading base firmware\n", |
| 739 | rc); |
| 740 | goto fail; |
| 741 | } |
Michel Ludwig | 5403bba | 2007-11-16 07:49:49 -0300 | [diff] [blame] | 742 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 743 | /* Load INIT1, if needed */ |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame] | 744 | tuner_dbg("Load init1 firmware, if exists\n"); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 745 | |
Chris Pascoe | 47bd5bc | 2007-11-19 23:11:37 -0300 | [diff] [blame] | 746 | rc = load_firmware(fe, BASE | INIT1 | new_fw.type, &std0); |
Chris Pascoe | 1ad0b79 | 2007-11-19 23:43:13 -0300 | [diff] [blame] | 747 | if (rc == -ENOENT) |
| 748 | rc = load_firmware(fe, (BASE | INIT1 | new_fw.type) & ~F8MHZ, |
| 749 | &std0); |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 750 | if (rc < 0 && rc != -ENOENT) { |
| 751 | tuner_err("Error %d while loading init1 firmware\n", |
| 752 | rc); |
| 753 | goto fail; |
Mauro Carvalho Chehab | 2e4160c | 2007-07-18 13:33:23 -0300 | [diff] [blame] | 754 | } |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 755 | |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 756 | skip_base: |
| 757 | /* |
| 758 | * No need to reload standard specific firmware if base firmware |
| 759 | * was not reloaded and requested video standards have not changed. |
| 760 | */ |
| 761 | if (priv->cur_fw.type == (BASE | new_fw.type) && |
| 762 | priv->cur_fw.std_req == std) { |
| 763 | tuner_dbg("Std-specific firmware already loaded.\n"); |
| 764 | goto skip_std_specific; |
| 765 | } |
Mauro Carvalho Chehab | a82200f | 2007-11-15 11:58:00 -0300 | [diff] [blame] | 766 | |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 767 | /* Reloading std-specific firmware forces a SCODE update */ |
| 768 | priv->cur_fw.scode_table = 0; |
| 769 | |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 770 | rc = load_firmware(fe, new_fw.type, &new_fw.id); |
Mauro Carvalho Chehab | cca8379 | 2007-11-22 11:47:18 -0300 | [diff] [blame] | 771 | if (rc == -ENOENT) |
| 772 | rc = load_firmware(fe, new_fw.type & ~F8MHZ, &new_fw.id); |
| 773 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 774 | if (rc < 0) |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 775 | goto fail; |
| 776 | |
| 777 | skip_std_specific: |
| 778 | if (priv->cur_fw.scode_table == new_fw.scode_table && |
| 779 | priv->cur_fw.scode_nr == new_fw.scode_nr) { |
| 780 | tuner_dbg("SCODE firmware already loaded.\n"); |
| 781 | goto check_device; |
| 782 | } |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 783 | |
Mauro Carvalho Chehab | 40ae91a | 2008-02-14 01:52:48 -0300 | [diff] [blame] | 784 | if (new_fw.type & FM) |
| 785 | goto check_device; |
| 786 | |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 787 | /* Load SCODE firmware, if exists */ |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 788 | tuner_dbg("Trying to load scode %d\n", new_fw.scode_nr); |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 789 | |
Mauro Carvalho Chehab | 66c2d53 | 2007-11-25 19:26:36 -0300 | [diff] [blame] | 790 | rc = load_scode(fe, new_fw.type | new_fw.scode_table, &new_fw.id, |
| 791 | new_fw.int_freq, new_fw.scode_nr); |
Mauro Carvalho Chehab | 43efe70 | 2007-11-14 19:30:28 -0300 | [diff] [blame] | 792 | |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 793 | check_device: |
Chris Pascoe | 8bf799a | 2007-11-19 11:35:45 -0300 | [diff] [blame] | 794 | if (xc2028_get_reg(priv, 0x0004, &version) < 0 || |
| 795 | xc2028_get_reg(priv, 0x0008, &hwmodel) < 0) { |
| 796 | tuner_err("Unable to read tuner registers.\n"); |
| 797 | goto fail; |
| 798 | } |
Mauro Carvalho Chehab | 80b5220 | 2007-11-05 09:07:13 -0300 | [diff] [blame] | 799 | |
Devin Heitmueller | b37f2d6 | 2008-04-21 07:02:09 -0300 | [diff] [blame] | 800 | tuner_dbg("Device is Xceive %d version %d.%d, " |
| 801 | "firmware version %d.%d\n", |
| 802 | hwmodel, (version & 0xf000) >> 12, (version & 0xf00) >> 8, |
| 803 | (version & 0xf0) >> 4, version & 0xf); |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 804 | |
Chris Pascoe | 8bf799a | 2007-11-19 11:35:45 -0300 | [diff] [blame] | 805 | /* Check firmware version against what we downloaded. */ |
| 806 | if (priv->firm_version != ((version & 0xf0) << 4 | (version & 0x0f))) { |
| 807 | tuner_err("Incorrect readback of firmware version.\n"); |
| 808 | goto fail; |
| 809 | } |
| 810 | |
| 811 | /* Check that the tuner hardware model remains consistent over time. */ |
| 812 | if (priv->hwmodel == 0 && (hwmodel == 2028 || hwmodel == 3028)) { |
| 813 | priv->hwmodel = hwmodel; |
| 814 | priv->hwvers = version & 0xff00; |
| 815 | } else if (priv->hwmodel == 0 || priv->hwmodel != hwmodel || |
| 816 | priv->hwvers != (version & 0xff00)) { |
| 817 | tuner_err("Read invalid device hardware information - tuner " |
| 818 | "hung?\n"); |
| 819 | goto fail; |
| 820 | } |
| 821 | |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 822 | memcpy(&priv->cur_fw, &new_fw, sizeof(priv->cur_fw)); |
| 823 | |
| 824 | /* |
| 825 | * By setting BASE in cur_fw.type only after successfully loading all |
| 826 | * firmwares, we can: |
| 827 | * 1. Identify that BASE firmware with type=0 has been loaded; |
| 828 | * 2. Tell whether BASE firmware was just changed the next time through. |
| 829 | */ |
| 830 | priv->cur_fw.type |= BASE; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 831 | |
| 832 | return 0; |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 833 | |
| 834 | fail: |
| 835 | memset(&priv->cur_fw, 0, sizeof(priv->cur_fw)); |
Chris Pascoe | 8bf799a | 2007-11-19 11:35:45 -0300 | [diff] [blame] | 836 | if (!is_retry) { |
| 837 | msleep(50); |
| 838 | is_retry = 1; |
| 839 | tuner_dbg("Retrying firmware load\n"); |
| 840 | goto retry; |
| 841 | } |
| 842 | |
Chris Pascoe | e0f0b37 | 2007-11-19 11:22:03 -0300 | [diff] [blame] | 843 | if (rc == -ENOENT) |
| 844 | rc = -EINVAL; |
| 845 | return rc; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 846 | } |
| 847 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 848 | static int xc2028_signal(struct dvb_frontend *fe, u16 *strength) |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 849 | { |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 850 | struct xc2028_data *priv = fe->tuner_priv; |
Chris Pascoe | 7d58d11 | 2007-11-19 04:31:58 -0300 | [diff] [blame] | 851 | u16 frq_lock, signal = 0; |
| 852 | int rc; |
Mauro Carvalho Chehab | 3b20532 | 2007-09-27 18:27:03 -0300 | [diff] [blame] | 853 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 854 | tuner_dbg("%s called\n", __func__); |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 855 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 856 | mutex_lock(&priv->lock); |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 857 | |
Mauro Carvalho Chehab | 80b5220 | 2007-11-05 09:07:13 -0300 | [diff] [blame] | 858 | /* Sync Lock Indicator */ |
Chris Pascoe | 7d58d11 | 2007-11-19 04:31:58 -0300 | [diff] [blame] | 859 | rc = xc2028_get_reg(priv, 0x0002, &frq_lock); |
Mauro Carvalho Chehab | b0166ab | 2008-04-24 11:19:55 -0300 | [diff] [blame] | 860 | if (rc < 0) |
Mauro Carvalho Chehab | 3b20532 | 2007-09-27 18:27:03 -0300 | [diff] [blame] | 861 | goto ret; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 862 | |
Mauro Carvalho Chehab | b0166ab | 2008-04-24 11:19:55 -0300 | [diff] [blame] | 863 | /* Frequency is locked */ |
| 864 | if (frq_lock == 1) |
| 865 | signal = 32768; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 866 | |
Mauro Carvalho Chehab | 80b5220 | 2007-11-05 09:07:13 -0300 | [diff] [blame] | 867 | /* Get SNR of the video signal */ |
Chris Pascoe | 7d58d11 | 2007-11-19 04:31:58 -0300 | [diff] [blame] | 868 | rc = xc2028_get_reg(priv, 0x0040, &signal); |
| 869 | if (rc < 0) |
Mauro Carvalho Chehab | b0166ab | 2008-04-24 11:19:55 -0300 | [diff] [blame] | 870 | goto ret; |
| 871 | |
| 872 | /* Use both frq_lock and signal to generate the result */ |
| 873 | signal = signal || ((signal & 0x07) << 12); |
Mauro Carvalho Chehab | 3b20532 | 2007-09-27 18:27:03 -0300 | [diff] [blame] | 874 | |
| 875 | ret: |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 876 | mutex_unlock(&priv->lock); |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 877 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 878 | *strength = signal; |
| 879 | |
Mauro Carvalho Chehab | b0166ab | 2008-04-24 11:19:55 -0300 | [diff] [blame] | 880 | tuner_dbg("signal strength is %d\n", signal); |
| 881 | |
Chris Pascoe | 7d58d11 | 2007-11-19 04:31:58 -0300 | [diff] [blame] | 882 | return rc; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | #define DIV 15625 |
| 886 | |
Mauro Carvalho Chehab | 00deff1 | 2007-11-24 10:13:42 -0300 | [diff] [blame] | 887 | static int generic_set_freq(struct dvb_frontend *fe, u32 freq /* in HZ */, |
Mauro Carvalho Chehab | 66c2d53 | 2007-11-25 19:26:36 -0300 | [diff] [blame] | 888 | enum tuner_mode new_mode, |
| 889 | unsigned int type, |
| 890 | v4l2_std_id std, |
| 891 | u16 int_freq) |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 892 | { |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 893 | struct xc2028_data *priv = fe->tuner_priv; |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 894 | int rc = -EINVAL; |
Chris Pascoe | 2ce4b3a | 2007-11-19 06:20:17 -0300 | [diff] [blame] | 895 | unsigned char buf[4]; |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 896 | u32 div, offset = 0; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 897 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 898 | tuner_dbg("%s called\n", __func__); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 899 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 900 | mutex_lock(&priv->lock); |
| 901 | |
Chris Pascoe | 2ce4b3a | 2007-11-19 06:20:17 -0300 | [diff] [blame] | 902 | tuner_dbg("should set frequency %d kHz\n", freq / 1000); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 903 | |
Mauro Carvalho Chehab | 66c2d53 | 2007-11-25 19:26:36 -0300 | [diff] [blame] | 904 | if (check_firmware(fe, type, std, int_freq) < 0) |
Mauro Carvalho Chehab | 3b20532 | 2007-09-27 18:27:03 -0300 | [diff] [blame] | 905 | goto ret; |
Mauro Carvalho Chehab | 2e4160c | 2007-07-18 13:33:23 -0300 | [diff] [blame] | 906 | |
Mauro Carvalho Chehab | 2800ae9 | 2007-11-22 12:48:04 -0300 | [diff] [blame] | 907 | /* On some cases xc2028 can disable video output, if |
| 908 | * very weak signals are received. By sending a soft |
| 909 | * reset, this is re-enabled. So, it is better to always |
| 910 | * send a soft reset before changing channels, to be sure |
| 911 | * that xc2028 will be in a safe state. |
| 912 | * Maybe this might also be needed for DTV. |
| 913 | */ |
Mauro Carvalho Chehab | 00deff1 | 2007-11-24 10:13:42 -0300 | [diff] [blame] | 914 | if (new_mode == T_ANALOG_TV) { |
Mauro Carvalho Chehab | 2800ae9 | 2007-11-22 12:48:04 -0300 | [diff] [blame] | 915 | rc = send_seq(priv, {0x00, 0x00}); |
Michael Krufky | d536c9d | 2007-12-18 10:42:33 -0300 | [diff] [blame] | 916 | } else if (priv->cur_fw.type & ATSC) { |
| 917 | offset = 1750000; |
| 918 | } else { |
Mauro Carvalho Chehab | d4e7668 | 2007-07-18 23:14:25 -0300 | [diff] [blame] | 919 | offset = 2750000; |
Chris Pascoe | 897b842 | 2007-12-02 09:39:18 -0300 | [diff] [blame] | 920 | /* |
| 921 | * We must adjust the offset by 500kHz in two cases in order |
| 922 | * to correctly center the IF output: |
| 923 | * 1) When the ZARLINK456 or DIBCOM52 tables were explicitly |
| 924 | * selected and a 7MHz channel is tuned; |
| 925 | * 2) When tuning a VHF channel with DTV78 firmware. |
| 926 | */ |
| 927 | if (((priv->cur_fw.type & DTV7) && |
| 928 | (priv->cur_fw.scode_table & (ZARLINK456 | DIBCOM52))) || |
| 929 | ((priv->cur_fw.type & DTV78) && freq < 470000000)) |
Chris Pascoe | a44f1c4 | 2007-11-19 06:35:26 -0300 | [diff] [blame] | 930 | offset -= 500000; |
| 931 | } |
Mauro Carvalho Chehab | 2e4160c | 2007-07-18 13:33:23 -0300 | [diff] [blame] | 932 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 933 | div = (freq - offset + DIV / 2) / DIV; |
Mauro Carvalho Chehab | 2e4160c | 2007-07-18 13:33:23 -0300 | [diff] [blame] | 934 | |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 935 | /* CMD= Set frequency */ |
Chris Pascoe | 06fd82d | 2007-11-19 06:06:08 -0300 | [diff] [blame] | 936 | if (priv->firm_version < 0x0202) |
Chris Pascoe | 47cc5b7 | 2007-11-19 04:14:23 -0300 | [diff] [blame] | 937 | rc = send_seq(priv, {0x00, 0x02, 0x00, 0x00}); |
| 938 | else |
| 939 | rc = send_seq(priv, {0x80, 0x02, 0x00, 0x00}); |
| 940 | if (rc < 0) |
| 941 | goto ret; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 942 | |
Mauro Carvalho Chehab | 1fe87369 | 2008-04-22 14:45:20 -0300 | [diff] [blame] | 943 | /* Return code shouldn't be checked. |
| 944 | The reset CLK is needed only with tm6000. |
| 945 | Driver should work fine even if this fails. |
| 946 | */ |
Michael Krufky | d7cba04 | 2008-09-12 13:31:45 -0300 | [diff] [blame] | 947 | do_tuner_callback(fe, XC2028_RESET_CLK, 1); |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 948 | |
| 949 | msleep(10); |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 950 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 951 | buf[0] = 0xff & (div >> 24); |
| 952 | buf[1] = 0xff & (div >> 16); |
| 953 | buf[2] = 0xff & (div >> 8); |
| 954 | buf[3] = 0xff & (div); |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 955 | |
Chris Pascoe | 47cc5b7 | 2007-11-19 04:14:23 -0300 | [diff] [blame] | 956 | rc = i2c_send(priv, buf, sizeof(buf)); |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 957 | if (rc < 0) |
Mauro Carvalho Chehab | 3b20532 | 2007-09-27 18:27:03 -0300 | [diff] [blame] | 958 | goto ret; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 959 | msleep(100); |
| 960 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 961 | priv->frequency = freq; |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 962 | |
Chris Pascoe | 2ce4b3a | 2007-11-19 06:20:17 -0300 | [diff] [blame] | 963 | tuner_dbg("divisor= %02x %02x %02x %02x (freq=%d.%03d)\n", |
| 964 | buf[0], buf[1], buf[2], buf[3], |
| 965 | freq / 1000000, (freq % 1000000) / 1000); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 966 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 967 | rc = 0; |
Mauro Carvalho Chehab | 3b20532 | 2007-09-27 18:27:03 -0300 | [diff] [blame] | 968 | |
| 969 | ret: |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 970 | mutex_unlock(&priv->lock); |
| 971 | |
| 972 | return rc; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 973 | } |
| 974 | |
Mauro Carvalho Chehab | 00deff1 | 2007-11-24 10:13:42 -0300 | [diff] [blame] | 975 | static int xc2028_set_analog_freq(struct dvb_frontend *fe, |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 976 | struct analog_parameters *p) |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 977 | { |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 978 | struct xc2028_data *priv = fe->tuner_priv; |
Mauro Carvalho Chehab | 00deff1 | 2007-11-24 10:13:42 -0300 | [diff] [blame] | 979 | unsigned int type=0; |
| 980 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 981 | tuner_dbg("%s called\n", __func__); |
Mauro Carvalho Chehab | c71d4bc | 2007-11-22 11:47:18 -0300 | [diff] [blame] | 982 | |
Mauro Carvalho Chehab | d74cb25 | 2007-11-24 10:20:15 -0300 | [diff] [blame] | 983 | if (p->mode == V4L2_TUNER_RADIO) { |
| 984 | type |= FM; |
| 985 | if (priv->ctrl.input1) |
| 986 | type |= INPUT1; |
| 987 | return generic_set_freq(fe, (625l * p->frequency) / 10, |
Mauro Carvalho Chehab | 66c2d53 | 2007-11-25 19:26:36 -0300 | [diff] [blame] | 988 | T_ANALOG_TV, type, 0, 0); |
Mauro Carvalho Chehab | d74cb25 | 2007-11-24 10:20:15 -0300 | [diff] [blame] | 989 | } |
| 990 | |
Mauro Carvalho Chehab | a5e9fe1 | 2007-11-23 11:36:18 -0300 | [diff] [blame] | 991 | /* if std is not defined, choose one */ |
| 992 | if (!p->std) |
| 993 | p->std = V4L2_STD_MN; |
| 994 | |
| 995 | /* PAL/M, PAL/N, PAL/Nc and NTSC variants should use 6MHz firmware */ |
Mauro Carvalho Chehab | 00deff1 | 2007-11-24 10:13:42 -0300 | [diff] [blame] | 996 | if (!(p->std & V4L2_STD_MN)) |
| 997 | type |= F8MHZ; |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 998 | |
Mauro Carvalho Chehab | 00deff1 | 2007-11-24 10:13:42 -0300 | [diff] [blame] | 999 | /* Add audio hack to std mask */ |
| 1000 | p->std |= parse_audio_std_option(); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1001 | |
Mauro Carvalho Chehab | 00deff1 | 2007-11-24 10:13:42 -0300 | [diff] [blame] | 1002 | return generic_set_freq(fe, 62500l * p->frequency, |
Mauro Carvalho Chehab | 66c2d53 | 2007-11-25 19:26:36 -0300 | [diff] [blame] | 1003 | T_ANALOG_TV, type, p->std, 0); |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 1004 | } |
| 1005 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1006 | static int xc2028_set_params(struct dvb_frontend *fe, |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 1007 | struct dvb_frontend_parameters *p) |
| 1008 | { |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1009 | struct xc2028_data *priv = fe->tuner_priv; |
Mauro Carvalho Chehab | 00deff1 | 2007-11-24 10:13:42 -0300 | [diff] [blame] | 1010 | unsigned int type=0; |
Mauro Carvalho Chehab | d04aa54 | 2007-11-24 10:47:03 -0300 | [diff] [blame] | 1011 | fe_bandwidth_t bw = BANDWIDTH_8_MHZ; |
Chris Pascoe | ad35ce9 | 2007-12-02 06:36:42 -0300 | [diff] [blame] | 1012 | u16 demod = 0; |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 1013 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1014 | tuner_dbg("%s called\n", __func__); |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 1015 | |
Mauro Carvalho Chehab | d04aa54 | 2007-11-24 10:47:03 -0300 | [diff] [blame] | 1016 | switch(fe->ops.info.type) { |
Mauro Carvalho Chehab | d04aa54 | 2007-11-24 10:47:03 -0300 | [diff] [blame] | 1017 | case FE_OFDM: |
| 1018 | bw = p->u.ofdm.bandwidth; |
| 1019 | break; |
| 1020 | case FE_QAM: |
Mauro Carvalho Chehab | 5c15648 | 2007-12-02 00:02:18 -0300 | [diff] [blame] | 1021 | tuner_info("WARN: There are some reports that " |
| 1022 | "QAM 6 MHz doesn't work.\n" |
| 1023 | "If this works for you, please report by " |
| 1024 | "e-mail to: v4l-dvb-maintainer@linuxtv.org\n"); |
Mauro Carvalho Chehab | d04aa54 | 2007-11-24 10:47:03 -0300 | [diff] [blame] | 1025 | bw = BANDWIDTH_6_MHZ; |
| 1026 | type |= QAM; |
| 1027 | break; |
| 1028 | case FE_ATSC: |
| 1029 | bw = BANDWIDTH_6_MHZ; |
Mauro Carvalho Chehab | 0975fc6 | 2008-09-28 02:24:44 -0300 | [diff] [blame] | 1030 | /* The only ATSC firmware (at least on v2.7) is D2633 */ |
| 1031 | type |= ATSC | D2633; |
Mauro Carvalho Chehab | d04aa54 | 2007-11-24 10:47:03 -0300 | [diff] [blame] | 1032 | break; |
Mauro Carvalho Chehab | 5c15648 | 2007-12-02 00:02:18 -0300 | [diff] [blame] | 1033 | /* DVB-S is not supported */ |
| 1034 | default: |
| 1035 | return -EINVAL; |
Mauro Carvalho Chehab | d04aa54 | 2007-11-24 10:47:03 -0300 | [diff] [blame] | 1036 | } |
| 1037 | |
Mauro Carvalho Chehab | 00deff1 | 2007-11-24 10:13:42 -0300 | [diff] [blame] | 1038 | switch (bw) { |
| 1039 | case BANDWIDTH_8_MHZ: |
Chris Pascoe | 3dfefc5 | 2007-12-02 10:07:06 -0300 | [diff] [blame] | 1040 | if (p->frequency < 470000000) |
| 1041 | priv->ctrl.vhfbw7 = 0; |
| 1042 | else |
| 1043 | priv->ctrl.uhfbw8 = 1; |
| 1044 | type |= (priv->ctrl.vhfbw7 && priv->ctrl.uhfbw8) ? DTV78 : DTV8; |
| 1045 | type |= F8MHZ; |
Mauro Carvalho Chehab | 00deff1 | 2007-11-24 10:13:42 -0300 | [diff] [blame] | 1046 | break; |
| 1047 | case BANDWIDTH_7_MHZ: |
Chris Pascoe | 3dfefc5 | 2007-12-02 10:07:06 -0300 | [diff] [blame] | 1048 | if (p->frequency < 470000000) |
| 1049 | priv->ctrl.vhfbw7 = 1; |
| 1050 | else |
| 1051 | priv->ctrl.uhfbw8 = 0; |
| 1052 | type |= (priv->ctrl.vhfbw7 && priv->ctrl.uhfbw8) ? DTV78 : DTV7; |
| 1053 | type |= F8MHZ; |
Mauro Carvalho Chehab | 00deff1 | 2007-11-24 10:13:42 -0300 | [diff] [blame] | 1054 | break; |
| 1055 | case BANDWIDTH_6_MHZ: |
Chris Pascoe | 3dfefc5 | 2007-12-02 10:07:06 -0300 | [diff] [blame] | 1056 | type |= DTV6; |
| 1057 | priv->ctrl.vhfbw7 = 0; |
| 1058 | priv->ctrl.uhfbw8 = 0; |
Mauro Carvalho Chehab | 00deff1 | 2007-11-24 10:13:42 -0300 | [diff] [blame] | 1059 | break; |
| 1060 | default: |
| 1061 | tuner_err("error: bandwidth not supported.\n"); |
| 1062 | }; |
| 1063 | |
Mauro Carvalho Chehab | 0975fc6 | 2008-09-28 02:24:44 -0300 | [diff] [blame] | 1064 | /* |
| 1065 | Selects between D2633 or D2620 firmware. |
| 1066 | It doesn't make sense for ATSC, since it should be D2633 on all cases |
| 1067 | */ |
| 1068 | if (fe->ops.info.type != FE_ATSC) { |
| 1069 | switch (priv->ctrl.type) { |
| 1070 | case XC2028_D2633: |
| 1071 | type |= D2633; |
| 1072 | break; |
| 1073 | case XC2028_D2620: |
| 1074 | type |= D2620; |
| 1075 | break; |
| 1076 | case XC2028_AUTO: |
| 1077 | default: |
| 1078 | /* Zarlink seems to need D2633 */ |
| 1079 | if (priv->ctrl.demod == XC3028_FE_ZARLINK456) |
| 1080 | type |= D2633; |
| 1081 | else |
| 1082 | type |= D2620; |
| 1083 | } |
| 1084 | } |
| 1085 | |
Mauro Carvalho Chehab | 66c2d53 | 2007-11-25 19:26:36 -0300 | [diff] [blame] | 1086 | /* All S-code tables need a 200kHz shift */ |
| 1087 | if (priv->ctrl.demod) |
Chris Pascoe | ad35ce9 | 2007-12-02 06:36:42 -0300 | [diff] [blame] | 1088 | demod = priv->ctrl.demod + 200; |
Mauro Carvalho Chehab | b542dfd | 2007-11-24 11:07:12 -0300 | [diff] [blame] | 1089 | |
Mauro Carvalho Chehab | 00deff1 | 2007-11-24 10:13:42 -0300 | [diff] [blame] | 1090 | return generic_set_freq(fe, p->frequency, |
Chris Pascoe | ad35ce9 | 2007-12-02 06:36:42 -0300 | [diff] [blame] | 1091 | T_DIGITAL_TV, type, 0, demod); |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 1092 | } |
| 1093 | |
Chris Pascoe | 45819c3 | 2007-11-19 11:41:20 -0300 | [diff] [blame] | 1094 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1095 | static int xc2028_dvb_release(struct dvb_frontend *fe) |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 1096 | { |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1097 | struct xc2028_data *priv = fe->tuner_priv; |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 1098 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1099 | tuner_dbg("%s called\n", __func__); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1100 | |
Chris Pascoe | aa501be | 2007-11-19 04:45:38 -0300 | [diff] [blame] | 1101 | mutex_lock(&xc2028_list_mutex); |
| 1102 | |
Michael Krufky | c663d03 | 2008-04-18 21:22:50 -0300 | [diff] [blame] | 1103 | /* only perform final cleanup if this is the last instance */ |
| 1104 | if (hybrid_tuner_report_instance_count(priv) == 1) { |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 1105 | kfree(priv->ctrl.fname); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 1106 | free_firmware(priv); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 1107 | } |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 1108 | |
Michael Krufky | c663d03 | 2008-04-18 21:22:50 -0300 | [diff] [blame] | 1109 | if (priv) |
| 1110 | hybrid_tuner_release_state(priv); |
| 1111 | |
Chris Pascoe | aa501be | 2007-11-19 04:45:38 -0300 | [diff] [blame] | 1112 | mutex_unlock(&xc2028_list_mutex); |
| 1113 | |
Michael Krufky | c663d03 | 2008-04-18 21:22:50 -0300 | [diff] [blame] | 1114 | fe->tuner_priv = NULL; |
| 1115 | |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 1116 | return 0; |
| 1117 | } |
| 1118 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1119 | static int xc2028_get_frequency(struct dvb_frontend *fe, u32 *frequency) |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 1120 | { |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1121 | struct xc2028_data *priv = fe->tuner_priv; |
| 1122 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1123 | tuner_dbg("%s called\n", __func__); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1124 | |
| 1125 | *frequency = priv->frequency; |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 1126 | |
| 1127 | return 0; |
| 1128 | } |
| 1129 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 1130 | static int xc2028_set_config(struct dvb_frontend *fe, void *priv_cfg) |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 1131 | { |
| 1132 | struct xc2028_data *priv = fe->tuner_priv; |
| 1133 | struct xc2028_ctrl *p = priv_cfg; |
Chris Pascoe | 0a196b6 | 2007-11-19 09:29:59 -0300 | [diff] [blame] | 1134 | int rc = 0; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 1135 | |
Harvey Harrison | 7e28adb | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 1136 | tuner_dbg("%s called\n", __func__); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 1137 | |
Chris Pascoe | 06fd82d | 2007-11-19 06:06:08 -0300 | [diff] [blame] | 1138 | mutex_lock(&priv->lock); |
| 1139 | |
Chris Pascoe | 0a196b6 | 2007-11-19 09:29:59 -0300 | [diff] [blame] | 1140 | memcpy(&priv->ctrl, p, sizeof(priv->ctrl)); |
Mauro Carvalho Chehab | 92b75ab | 2008-04-17 21:40:53 -0300 | [diff] [blame] | 1141 | if (priv->ctrl.max_len < 9) |
| 1142 | priv->ctrl.max_len = 13; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 1143 | |
| 1144 | if (p->fname) { |
Mauro Carvalho Chehab | 92b75ab | 2008-04-17 21:40:53 -0300 | [diff] [blame] | 1145 | if (priv->ctrl.fname && strcmp(p->fname, priv->ctrl.fname)) { |
| 1146 | kfree(priv->ctrl.fname); |
| 1147 | free_firmware(priv); |
| 1148 | } |
| 1149 | |
Chris Pascoe | 0a196b6 | 2007-11-19 09:29:59 -0300 | [diff] [blame] | 1150 | priv->ctrl.fname = kstrdup(p->fname, GFP_KERNEL); |
| 1151 | if (priv->ctrl.fname == NULL) |
| 1152 | rc = -ENOMEM; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 1153 | } |
| 1154 | |
Chris Pascoe | 06fd82d | 2007-11-19 06:06:08 -0300 | [diff] [blame] | 1155 | mutex_unlock(&priv->lock); |
| 1156 | |
Chris Pascoe | 0a196b6 | 2007-11-19 09:29:59 -0300 | [diff] [blame] | 1157 | return rc; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 1158 | } |
| 1159 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1160 | static const struct dvb_tuner_ops xc2028_dvb_tuner_ops = { |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 1161 | .info = { |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 1162 | .name = "Xceive XC3028", |
| 1163 | .frequency_min = 42000000, |
| 1164 | .frequency_max = 864000000, |
| 1165 | .frequency_step = 50000, |
| 1166 | }, |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 1167 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 1168 | .set_config = xc2028_set_config, |
Mauro Carvalho Chehab | 00deff1 | 2007-11-24 10:13:42 -0300 | [diff] [blame] | 1169 | .set_analog_params = xc2028_set_analog_freq, |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1170 | .release = xc2028_dvb_release, |
| 1171 | .get_frequency = xc2028_get_frequency, |
| 1172 | .get_rf_strength = xc2028_signal, |
| 1173 | .set_params = xc2028_set_params, |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 1174 | }; |
| 1175 | |
Michael Krufky | 7972f98 | 2007-12-21 16:12:09 -0300 | [diff] [blame] | 1176 | struct dvb_frontend *xc2028_attach(struct dvb_frontend *fe, |
| 1177 | struct xc2028_config *cfg) |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 1178 | { |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1179 | struct xc2028_data *priv; |
Michael Krufky | c663d03 | 2008-04-18 21:22:50 -0300 | [diff] [blame] | 1180 | int instance; |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 1181 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame] | 1182 | if (debug) |
Michael Krufky | 2756665 | 2008-04-22 14:41:53 -0300 | [diff] [blame] | 1183 | printk(KERN_DEBUG "xc2028: Xcv2028/3028 init called!\n"); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1184 | |
Mauro Carvalho Chehab | b412ba7 | 2008-04-22 14:46:11 -0300 | [diff] [blame] | 1185 | if (NULL == cfg) |
Michel Ludwig | a37b4c9 | 2007-11-16 07:46:14 -0300 | [diff] [blame] | 1186 | return NULL; |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1187 | |
Michel Ludwig | a37b4c9 | 2007-11-16 07:46:14 -0300 | [diff] [blame] | 1188 | if (!fe) { |
Michael Krufky | 2756665 | 2008-04-22 14:41:53 -0300 | [diff] [blame] | 1189 | printk(KERN_ERR "xc2028: No frontend!\n"); |
Michel Ludwig | a37b4c9 | 2007-11-16 07:46:14 -0300 | [diff] [blame] | 1190 | return NULL; |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1191 | } |
| 1192 | |
Chris Pascoe | aa501be | 2007-11-19 04:45:38 -0300 | [diff] [blame] | 1193 | mutex_lock(&xc2028_list_mutex); |
| 1194 | |
Michael Krufky | c663d03 | 2008-04-18 21:22:50 -0300 | [diff] [blame] | 1195 | instance = hybrid_tuner_request_state(struct xc2028_data, priv, |
| 1196 | hybrid_tuner_instance_list, |
| 1197 | cfg->i2c_adap, cfg->i2c_addr, |
| 1198 | "xc2028"); |
| 1199 | switch (instance) { |
| 1200 | case 0: |
| 1201 | /* memory allocation failure */ |
| 1202 | goto fail; |
| 1203 | break; |
| 1204 | case 1: |
| 1205 | /* new tuner instance */ |
Chris Pascoe | 0a196b6 | 2007-11-19 09:29:59 -0300 | [diff] [blame] | 1206 | priv->ctrl.max_len = 13; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 1207 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1208 | mutex_init(&priv->lock); |
| 1209 | |
Michael Krufky | c663d03 | 2008-04-18 21:22:50 -0300 | [diff] [blame] | 1210 | fe->tuner_priv = priv; |
| 1211 | break; |
| 1212 | case 2: |
| 1213 | /* existing tuner instance */ |
| 1214 | fe->tuner_priv = priv; |
| 1215 | break; |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1216 | } |
Michel Ludwig | a37b4c9 | 2007-11-16 07:46:14 -0300 | [diff] [blame] | 1217 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1218 | memcpy(&fe->ops.tuner_ops, &xc2028_dvb_tuner_ops, |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 1219 | sizeof(xc2028_dvb_tuner_ops)); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1220 | |
| 1221 | tuner_info("type set to %s\n", "XCeive xc2028/xc3028 tuner"); |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 1222 | |
Mauro Carvalho Chehab | 71a2ee3 | 2007-11-22 12:19:37 -0300 | [diff] [blame] | 1223 | if (cfg->ctrl) |
| 1224 | xc2028_set_config(fe, cfg->ctrl); |
| 1225 | |
Chris Pascoe | aa501be | 2007-11-19 04:45:38 -0300 | [diff] [blame] | 1226 | mutex_unlock(&xc2028_list_mutex); |
| 1227 | |
Michel Ludwig | a37b4c9 | 2007-11-16 07:46:14 -0300 | [diff] [blame] | 1228 | return fe; |
Michael Krufky | c663d03 | 2008-04-18 21:22:50 -0300 | [diff] [blame] | 1229 | fail: |
| 1230 | mutex_unlock(&xc2028_list_mutex); |
| 1231 | |
| 1232 | xc2028_dvb_release(fe); |
| 1233 | return NULL; |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 1234 | } |
Michel Ludwig | a37b4c9 | 2007-11-16 07:46:14 -0300 | [diff] [blame] | 1235 | |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 1236 | EXPORT_SYMBOL(xc2028_attach); |
| 1237 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1238 | MODULE_DESCRIPTION("Xceive xc2028/xc3028 tuner driver"); |
Mauro Carvalho Chehab | 983d214 | 2007-10-29 23:44:18 -0300 | [diff] [blame] | 1239 | MODULE_AUTHOR("Michel Ludwig <michel.ludwig@gmail.com>"); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 1240 | MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); |
| 1241 | MODULE_LICENSE("GPL"); |