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