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