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