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 | |
Hans Verkuil | 9dd659d | 2007-11-04 11:03:36 -0300 | [diff] [blame] | 25 | #define PREFIX "xc2028" |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 26 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 27 | static int debug; |
| 28 | module_param(debug, int, 0644); |
| 29 | MODULE_PARM_DESC(debug, "enable verbose debug messages"); |
| 30 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 31 | static LIST_HEAD(xc2028_list); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 32 | /* struct for storing firmware table */ |
| 33 | struct firmware_description { |
| 34 | unsigned int type; |
| 35 | v4l2_std_id id; |
| 36 | unsigned char *ptr; |
| 37 | unsigned int size; |
| 38 | }; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 39 | |
| 40 | struct xc2028_data { |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 41 | struct list_head xc2028_list; |
| 42 | struct tuner_i2c_props i2c_props; |
| 43 | int (*tuner_callback) (void *dev, |
| 44 | int command, int arg); |
| 45 | struct device *dev; |
| 46 | void *video_dev; |
| 47 | int count; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 48 | __u32 frequency; |
| 49 | |
| 50 | struct firmware_description *firm; |
| 51 | int firm_size; |
| 52 | |
| 53 | __u16 version; |
| 54 | |
| 55 | struct xc2028_ctrl ctrl; |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 56 | |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 57 | v4l2_std_id firm_type; /* video stds supported |
| 58 | by current firmware */ |
| 59 | fe_bandwidth_t bandwidth; /* Firmware bandwidth: |
| 60 | 6M, 7M or 8M */ |
| 61 | int need_load_generic; /* The generic firmware |
| 62 | were loaded? */ |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 63 | |
| 64 | int max_len; /* Max firmware chunk */ |
| 65 | |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 66 | enum tuner_mode mode; |
| 67 | struct i2c_client *i2c_client; |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 68 | |
| 69 | struct mutex lock; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 70 | }; |
| 71 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 72 | #define i2c_send(rc, priv, buf, size) do { \ |
| 73 | rc = tuner_i2c_xfer_send(&priv->i2c_props, buf, size); \ |
| 74 | if (size != rc) \ |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 75 | tuner_err("i2c output error: rc = %d (should be %d)\n", \ |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 76 | rc, (int)size); \ |
| 77 | } while (0) |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 78 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 79 | #define i2c_rcv(rc, priv, buf, size) do { \ |
| 80 | rc = tuner_i2c_xfer_recv(&priv->i2c_props, buf, size); \ |
| 81 | if (size != rc) \ |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 82 | tuner_err("i2c input error: rc = %d (should be %d)\n", \ |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 83 | rc, (int)size); \ |
| 84 | } while (0) |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 85 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 86 | #define send_seq(priv, data...) do { \ |
| 87 | int rc; \ |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 88 | static u8 _val[] = data; \ |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 89 | if (sizeof(_val) != \ |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 90 | (rc = tuner_i2c_xfer_send(&priv->i2c_props, \ |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 91 | _val, sizeof(_val)))) { \ |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 92 | tuner_err("Error on line %d: %d\n", __LINE__, rc); \ |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 93 | return -EINVAL; \ |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 94 | } \ |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 95 | msleep(10); \ |
| 96 | } while (0) |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 97 | |
Mauro Carvalho Chehab | 80b5220 | 2007-11-05 09:07:13 -0300 | [diff] [blame] | 98 | static unsigned int xc2028_get_reg(struct xc2028_data *priv, u16 reg) |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 99 | { |
| 100 | int rc; |
Mauro Carvalho Chehab | b873e1a | 2007-11-05 08:41:50 -0300 | [diff] [blame] | 101 | unsigned char buf[2]; |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 102 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 103 | tuner_dbg("%s called\n", __FUNCTION__); |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 104 | |
Mauro Carvalho Chehab | 80b5220 | 2007-11-05 09:07:13 -0300 | [diff] [blame] | 105 | buf[0] = reg>>8; |
| 106 | buf[1] = (unsigned char) reg; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 107 | |
Mauro Carvalho Chehab | 80b5220 | 2007-11-05 09:07:13 -0300 | [diff] [blame] | 108 | i2c_send(rc, priv, buf, 2); |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 109 | if (rc < 0) |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 110 | return rc; |
| 111 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 112 | i2c_rcv(rc, priv, buf, 2); |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 113 | if (rc < 0) |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 114 | return rc; |
| 115 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 116 | return (buf[1]) | (buf[0] << 8); |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 117 | } |
| 118 | |
Mauro Carvalho Chehab | 43efe70 | 2007-11-14 19:30:28 -0300 | [diff] [blame] | 119 | void dump_firm_type(unsigned int type) |
| 120 | { |
| 121 | if (type & BASE) |
| 122 | printk("BASE "); |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 123 | if (type & INIT1) |
| 124 | printk("INIT1 "); |
Mauro Carvalho Chehab | 43efe70 | 2007-11-14 19:30:28 -0300 | [diff] [blame] | 125 | if (type & F8MHZ) |
| 126 | printk("F8MHZ "); |
| 127 | if (type & MTS) |
| 128 | printk("MTS "); |
| 129 | if (type & D2620) |
| 130 | printk("D2620 "); |
| 131 | if (type & D2633) |
| 132 | printk("D2633 "); |
| 133 | if (type & DTV6) |
| 134 | printk("DTV6 "); |
| 135 | if (type & QAM) |
| 136 | printk("QAM "); |
| 137 | if (type & DTV7) |
| 138 | printk("DTV7 "); |
| 139 | if (type & DTV78) |
| 140 | printk("DTV78 "); |
| 141 | if (type & DTV8) |
| 142 | printk("DTV8 "); |
| 143 | if (type & FM) |
| 144 | printk("FM "); |
| 145 | if (type & INPUT1) |
| 146 | printk("INPUT1 "); |
| 147 | if (type & LCD) |
| 148 | printk("LCD "); |
| 149 | if (type & NOGD) |
| 150 | printk("NOGD "); |
| 151 | if (type & MONO) |
| 152 | printk("MONO "); |
| 153 | if (type & ATSC) |
| 154 | printk("ATSC "); |
| 155 | if (type & IF) |
| 156 | printk("IF "); |
| 157 | if (type & LG60) |
| 158 | printk("LG60 "); |
| 159 | if (type & ATI638) |
| 160 | printk("ATI638 "); |
| 161 | if (type & OREN538) |
| 162 | printk("OREN538 "); |
| 163 | if (type & OREN36) |
| 164 | printk("OREN36 "); |
| 165 | if (type & TOYOTA388) |
| 166 | printk("TOYOTA388 "); |
| 167 | if (type & TOYOTA794) |
| 168 | printk("TOYOTA794 "); |
| 169 | if (type & DIBCOM52) |
| 170 | printk("DIBCOM52 "); |
| 171 | if (type & ZARLINK456) |
| 172 | printk("ZARLINK456 "); |
| 173 | if (type & CHINA) |
| 174 | printk("CHINA "); |
| 175 | if (type & F6MHZ) |
| 176 | printk("F6MHZ "); |
| 177 | if (type & INPUT2) |
| 178 | printk("INPUT2 "); |
| 179 | if (type & SCODE) |
| 180 | printk("SCODE "); |
| 181 | } |
| 182 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 183 | static void free_firmware(struct xc2028_data *priv) |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 184 | { |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 185 | int i; |
| 186 | |
| 187 | if (!priv->firm) |
| 188 | return; |
| 189 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 190 | for (i = 0; i < priv->firm_size; i++) |
| 191 | kfree(priv->firm[i].ptr); |
| 192 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 193 | kfree(priv->firm); |
| 194 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 195 | priv->firm = NULL; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 196 | priv->need_load_generic = 1; |
| 197 | } |
| 198 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 199 | static int load_all_firmwares(struct dvb_frontend *fe) |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 200 | { |
| 201 | struct xc2028_data *priv = fe->tuner_priv; |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 202 | const struct firmware *fw = NULL; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 203 | unsigned char *p, *endp; |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 204 | int rc = 0; |
| 205 | int n, n_array; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 206 | char name[33]; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 207 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 208 | tuner_dbg("%s called\n", __FUNCTION__); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 209 | |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 210 | tuner_info("Reading firmware %s\n", priv->ctrl.fname); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 211 | rc = request_firmware(&fw, priv->ctrl.fname, priv->dev); |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 212 | if (rc < 0) { |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 213 | if (rc == -ENOENT) |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 214 | tuner_err("Error: firmware %s not found.\n", |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 215 | priv->ctrl.fname); |
Mauro Carvalho Chehab | 2e4160c | 2007-07-18 13:33:23 -0300 | [diff] [blame] | 216 | else |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 217 | tuner_err("Error %d while requesting firmware %s \n", |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 218 | rc, priv->ctrl.fname); |
Mauro Carvalho Chehab | 2e4160c | 2007-07-18 13:33:23 -0300 | [diff] [blame] | 219 | |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 220 | return rc; |
| 221 | } |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 222 | p = fw->data; |
| 223 | endp = p + fw->size; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 224 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 225 | if (fw->size < sizeof(name) - 1 + 2) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 226 | tuner_err("Error: firmware size is zero!\n"); |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 227 | rc = -EINVAL; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 228 | goto done; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 229 | } |
| 230 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 231 | memcpy(name, p, sizeof(name) - 1); |
| 232 | name[sizeof(name) - 1] = 0; |
| 233 | p += sizeof(name) - 1; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 234 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 235 | priv->version = le16_to_cpu(*(__u16 *) p); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 236 | p += 2; |
| 237 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 238 | tuner_info("Firmware: %s, ver %d.%d\n", name, |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 239 | priv->version >> 8, priv->version & 0xff); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 240 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 241 | if (p + 2 > endp) |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 242 | goto corrupt; |
| 243 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 244 | n_array = le16_to_cpu(*(__u16 *) p); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 245 | p += 2; |
| 246 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 247 | tuner_info("There are %d firmwares at %s\n", |
| 248 | n_array, priv->ctrl.fname); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 249 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 250 | priv->firm = kzalloc(sizeof(*priv->firm) * n_array, GFP_KERNEL); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 251 | |
| 252 | if (!fw) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 253 | tuner_err("Not enough memory for reading firmware.\n"); |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 254 | rc = -ENOMEM; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 255 | goto done; |
| 256 | } |
| 257 | |
| 258 | priv->firm_size = n_array; |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 259 | n = -1; |
| 260 | while (p < endp) { |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 261 | __u32 type, size; |
| 262 | v4l2_std_id id; |
| 263 | |
| 264 | n++; |
| 265 | if (n >= n_array) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 266 | tuner_err("Too much firmwares at the file\n"); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 267 | goto corrupt; |
| 268 | } |
| 269 | |
| 270 | /* Checks if there's enough bytes to read */ |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 271 | if (p + sizeof(type) + sizeof(id) + sizeof(size) > endp) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 272 | tuner_err("Firmware header is incomplete!\n"); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 273 | goto corrupt; |
| 274 | } |
| 275 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 276 | type = le32_to_cpu(*(__u32 *) p); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 277 | p += sizeof(type); |
| 278 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 279 | id = le64_to_cpu(*(v4l2_std_id *) p); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 280 | p += sizeof(id); |
| 281 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 282 | size = le32_to_cpu(*(v4l2_std_id *) p); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 283 | p += sizeof(size); |
| 284 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 285 | if ((!size) || (size + p > endp)) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 286 | tuner_err("Firmware type "); |
Mauro Carvalho Chehab | 43efe70 | 2007-11-14 19:30:28 -0300 | [diff] [blame] | 287 | dump_firm_type(type); |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 288 | printk("(%x), id %lx is corrupted " |
| 289 | "(size=%ld, expected %d)\n", |
| 290 | type, (unsigned long)id, endp - p, size); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 291 | goto corrupt; |
| 292 | } |
| 293 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 294 | priv->firm[n].ptr = kzalloc(size, GFP_KERNEL); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 295 | if (!priv->firm[n].ptr) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 296 | tuner_err("Not enough memory.\n"); |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 297 | rc = -ENOMEM; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 298 | goto err; |
| 299 | } |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 300 | tuner_info("Reading firmware type "); |
Mauro Carvalho Chehab | 43efe70 | 2007-11-14 19:30:28 -0300 | [diff] [blame] | 301 | dump_firm_type(type); |
| 302 | printk("(%x), id %lx, size=%d.\n", |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 303 | type, (unsigned long)id, size); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 304 | |
| 305 | memcpy(priv->firm[n].ptr, p, size); |
| 306 | priv->firm[n].type = type; |
| 307 | priv->firm[n].id = id; |
| 308 | priv->firm[n].size = size; |
| 309 | |
| 310 | p += size; |
| 311 | } |
| 312 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 313 | if (n + 1 != priv->firm_size) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 314 | tuner_err("Firmware file is incomplete!\n"); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 315 | goto corrupt; |
| 316 | } |
| 317 | |
| 318 | goto done; |
| 319 | |
| 320 | corrupt: |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 321 | rc = -EINVAL; |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 322 | tuner_err("Error: firmware file is corrupted!\n"); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 323 | |
| 324 | err: |
| 325 | tuner_info("Releasing loaded firmware file.\n"); |
| 326 | |
| 327 | free_firmware(priv); |
| 328 | |
| 329 | done: |
| 330 | release_firmware(fw); |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 331 | tuner_dbg("Firmware files loaded.\n"); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 332 | |
| 333 | return rc; |
| 334 | } |
| 335 | |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 336 | static int seek_firmware(struct dvb_frontend *fe, unsigned int type, |
| 337 | v4l2_std_id *id) |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 338 | { |
| 339 | struct xc2028_data *priv = fe->tuner_priv; |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 340 | int i; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 341 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 342 | tuner_dbg("%s called\n", __FUNCTION__); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 343 | |
| 344 | if (!priv->firm) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 345 | tuner_err("Error! firmware not loaded\n"); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 346 | return -EINVAL; |
| 347 | } |
| 348 | |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 349 | if (((type & ~SCODE) == 0) && (*id == 0)) |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 350 | *id = V4L2_STD_PAL; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 351 | |
| 352 | /* Seek for exact match */ |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 353 | for (i = 0; i < priv->firm_size; i++) { |
| 354 | if ((type == priv->firm[i].type) && (*id == priv->firm[i].id)) |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 355 | goto found; |
| 356 | } |
| 357 | |
| 358 | /* Seek for generic video standard match */ |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 359 | for (i = 0; i < priv->firm_size; i++) { |
| 360 | if ((type == priv->firm[i].type) && (*id & priv->firm[i].id)) |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 361 | goto found; |
| 362 | } |
| 363 | |
| 364 | /*FIXME: Would make sense to seek for type "hint" match ? */ |
| 365 | |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 366 | i = -EINVAL; |
| 367 | goto ret; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 368 | |
| 369 | found: |
| 370 | *id = priv->firm[i].id; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 371 | |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 372 | ret: |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 373 | tuner_dbg("%s firmware for type=", (i < 0)? "Can't find": "Found"); |
| 374 | if (debug) { |
| 375 | dump_firm_type(type); |
| 376 | printk("(%x), id %08lx.\n", type, (unsigned long)*id); |
| 377 | } |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 378 | return i; |
| 379 | } |
| 380 | |
| 381 | static int load_firmware(struct dvb_frontend *fe, unsigned int type, |
| 382 | v4l2_std_id *id) |
| 383 | { |
| 384 | struct xc2028_data *priv = fe->tuner_priv; |
| 385 | int pos, rc; |
| 386 | unsigned char *p, *endp, buf[priv->max_len]; |
| 387 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 388 | tuner_dbg("%s called\n", __FUNCTION__); |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 389 | |
| 390 | pos = seek_firmware(fe, type, id); |
| 391 | if (pos < 0) |
| 392 | return pos; |
| 393 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 394 | tuner_info("Loading firmware for type="); |
| 395 | dump_firm_type(type); |
| 396 | printk("(%x), id %08lx.\n", type, (unsigned long)*id); |
| 397 | |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 398 | p = priv->firm[pos].ptr; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 399 | |
| 400 | if (!p) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 401 | tuner_err("Firmware pointer were freed!"); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 402 | return -EINVAL; |
| 403 | } |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 404 | endp = p + priv->firm[pos].size; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 405 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 406 | while (p < endp) { |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 407 | __u16 size; |
| 408 | |
| 409 | /* Checks if there's enough bytes to read */ |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 410 | if (p + sizeof(size) > endp) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 411 | tuner_err("Firmware chunk size is wrong\n"); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 412 | return -EINVAL; |
| 413 | } |
| 414 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 415 | size = le16_to_cpu(*(__u16 *) p); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 416 | p += sizeof(size); |
| 417 | |
| 418 | if (size == 0xffff) |
| 419 | return 0; |
| 420 | |
| 421 | if (!size) { |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 422 | /* Special callback command received */ |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 423 | rc = priv->tuner_callback(priv->video_dev, |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 424 | XC2028_TUNER_RESET, 0); |
| 425 | if (rc < 0) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 426 | tuner_err("Error at RESET code %d\n", |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 427 | (*p) & 0x7f); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 428 | return -EINVAL; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 429 | } |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 430 | continue; |
| 431 | } |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 432 | |
| 433 | /* Checks for a sleep command */ |
| 434 | if (size & 0x8000) { |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 435 | msleep(size & 0x7fff); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 436 | continue; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 437 | } |
| 438 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 439 | if ((size + p > endp)) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 440 | tuner_err("missing bytes: need %d, have %d\n", |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 441 | size, (int)(endp - p)); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 442 | return -EINVAL; |
| 443 | } |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 444 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 445 | buf[0] = *p; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 446 | p++; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 447 | size--; |
| 448 | |
| 449 | /* Sends message chunks */ |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 450 | while (size > 0) { |
| 451 | int len = (size < priv->max_len - 1) ? |
| 452 | size : priv->max_len - 1; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 453 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 454 | memcpy(buf + 1, p, len); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 455 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 456 | i2c_send(rc, priv, buf, len + 1); |
| 457 | if (rc < 0) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 458 | tuner_err("%d returned from send\n", rc); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 459 | return -EINVAL; |
| 460 | } |
| 461 | |
| 462 | p += len; |
| 463 | size -= len; |
| 464 | } |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 465 | } |
Mauro Carvalho Chehab | 43efe70 | 2007-11-14 19:30:28 -0300 | [diff] [blame] | 466 | return 0; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 467 | } |
| 468 | |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 469 | static int load_scode(struct dvb_frontend *fe, unsigned int type, |
| 470 | v4l2_std_id *id, int scode) |
| 471 | { |
| 472 | struct xc2028_data *priv = fe->tuner_priv; |
| 473 | int pos, rc; |
| 474 | unsigned char *p; |
| 475 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 476 | tuner_dbg("%s called\n", __FUNCTION__); |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 477 | |
| 478 | pos = seek_firmware(fe, type, id); |
| 479 | if (pos < 0) |
| 480 | return pos; |
| 481 | |
| 482 | p = priv->firm[pos].ptr; |
| 483 | |
| 484 | if (!p) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 485 | tuner_err("Firmware pointer were freed!"); |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 486 | return -EINVAL; |
| 487 | } |
| 488 | |
| 489 | if ((priv->firm[pos].size != 12 * 16) || (scode >= 16)) |
| 490 | return -EINVAL; |
| 491 | |
| 492 | if (priv->version < 0x0202) { |
| 493 | send_seq(priv, {0x20, 0x00, 0x00, 0x00}); |
| 494 | } else { |
| 495 | send_seq(priv, {0xa0, 0x00, 0x00, 0x00}); |
| 496 | } |
| 497 | |
| 498 | i2c_send(rc, priv, p + 12 * scode, 12); |
| 499 | |
| 500 | send_seq(priv, {0x00, 0x8c}); |
| 501 | |
| 502 | return 0; |
| 503 | } |
| 504 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 505 | static int check_firmware(struct dvb_frontend *fe, enum tuner_mode new_mode, |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 506 | v4l2_std_id std, fe_bandwidth_t bandwidth) |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 507 | { |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 508 | struct xc2028_data *priv = fe->tuner_priv; |
Mauro Carvalho Chehab | 80b5220 | 2007-11-05 09:07:13 -0300 | [diff] [blame] | 509 | int rc, version, hwmodel; |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 510 | v4l2_std_id std0 = 0; |
| 511 | unsigned int type0 = 0, type = 0; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 512 | int change_digital_bandwidth; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 513 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 514 | tuner_dbg("%s called\n", __FUNCTION__); |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 515 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 516 | if (!priv->firm) { |
| 517 | if (!priv->ctrl.fname) |
| 518 | return -EINVAL; |
| 519 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 520 | rc = load_all_firmwares(fe); |
| 521 | if (rc < 0) |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 522 | return rc; |
| 523 | } |
| 524 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 525 | tuner_dbg("I am in mode %u and I should switch to mode %i\n", |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 526 | priv->mode, new_mode); |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 527 | |
| 528 | /* first of all, determine whether we have switched the mode */ |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 529 | if (new_mode != priv->mode) { |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 530 | priv->mode = new_mode; |
| 531 | priv->need_load_generic = 1; |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 532 | } |
| 533 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 534 | change_digital_bandwidth = (priv->mode == T_DIGITAL_TV |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 535 | && bandwidth != priv->bandwidth) ? 1 : 0; |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 536 | tuner_dbg("old bandwidth %u, new bandwidth %u\n", priv->bandwidth, |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 537 | bandwidth); |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 538 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 539 | if (priv->need_load_generic) { |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 540 | /* Reset is needed before loading firmware */ |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 541 | rc = priv->tuner_callback(priv->video_dev, |
| 542 | XC2028_TUNER_RESET, 0); |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 543 | if (rc < 0) |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 544 | return rc; |
| 545 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 546 | type0 = BASE; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 547 | |
| 548 | if (priv->ctrl.type == XC2028_FIRM_MTS) |
| 549 | type0 |= MTS; |
| 550 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 551 | if (priv->bandwidth == 8) |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 552 | type0 |= F8MHZ; |
| 553 | |
| 554 | /* FIXME: How to load FM and FM|INPUT1 firmwares? */ |
| 555 | |
| 556 | rc = load_firmware(fe, type0, &std0); |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 557 | if (rc < 0) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 558 | tuner_err("Error %d while loading generic firmware\n", |
| 559 | rc); |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 560 | return rc; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 561 | } |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 562 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 563 | priv->need_load_generic = 0; |
| 564 | priv->firm_type = 0; |
| 565 | if (priv->mode == T_DIGITAL_TV) |
| 566 | change_digital_bandwidth = 1; |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 567 | } |
| 568 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 569 | tuner_dbg("I should change bandwidth %u\n", change_digital_bandwidth); |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 570 | |
| 571 | if (change_digital_bandwidth) { |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 572 | |
| 573 | /*FIXME: Should allow selecting between D2620 and D2633 */ |
| 574 | type |= D2620; |
| 575 | |
| 576 | /* FIXME: When should select a DTV78 firmware? |
| 577 | */ |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 578 | switch (bandwidth) { |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 579 | case BANDWIDTH_8_MHZ: |
| 580 | type |= DTV8; |
| 581 | break; |
| 582 | case BANDWIDTH_7_MHZ: |
| 583 | type |= DTV7; |
| 584 | break; |
| 585 | case BANDWIDTH_6_MHZ: |
| 586 | /* FIXME: Should allow select also ATSC */ |
Mauro Carvalho Chehab | 43efe70 | 2007-11-14 19:30:28 -0300 | [diff] [blame] | 587 | type |= DTV6 | QAM; |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 588 | break; |
| 589 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 590 | default: |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 591 | tuner_err("error: bandwidth not supported.\n"); |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 592 | }; |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 593 | priv->bandwidth = bandwidth; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 594 | } |
| 595 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 596 | /* Load INIT1, if needed */ |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 597 | tuner_dbg("Load init1 firmware, if exists\n"); |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 598 | type0 = BASE | INIT1; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 599 | if (priv->ctrl.type == XC2028_FIRM_MTS) |
| 600 | type0 |= MTS; |
| 601 | |
| 602 | /* FIXME: Should handle errors - if INIT1 found */ |
| 603 | rc = load_firmware(fe, type0, &std0); |
| 604 | |
| 605 | /* FIXME: Should add support for FM radio |
| 606 | */ |
| 607 | |
| 608 | if (priv->ctrl.type == XC2028_FIRM_MTS) |
| 609 | type |= MTS; |
| 610 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 611 | if (priv->firm_type & std) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 612 | tuner_dbg("Std-specific firmware already loaded.\n"); |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 613 | return 0; |
Mauro Carvalho Chehab | 2e4160c | 2007-07-18 13:33:23 -0300 | [diff] [blame] | 614 | } |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 615 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 616 | rc = load_firmware(fe, type, &std); |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 617 | if (rc < 0) |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 618 | return rc; |
| 619 | |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 620 | /* Load SCODE firmware, if exists */ |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 621 | tuner_dbg("Trying to load scode 0\n"); |
Mauro Carvalho Chehab | f380e1d | 2007-11-15 08:43:53 -0300 | [diff] [blame] | 622 | type |= SCODE; |
| 623 | |
| 624 | rc = load_scode(fe, type, &std, 0); |
Mauro Carvalho Chehab | 43efe70 | 2007-11-14 19:30:28 -0300 | [diff] [blame] | 625 | |
Mauro Carvalho Chehab | 80b5220 | 2007-11-05 09:07:13 -0300 | [diff] [blame] | 626 | version = xc2028_get_reg(priv, 0x0004); |
| 627 | hwmodel = xc2028_get_reg(priv, 0x0008); |
| 628 | |
| 629 | tuner_info("Device is Xceive %d version %d.%d, " |
| 630 | "firmware version %d.%d\n", |
| 631 | hwmodel, (version & 0xf000) >> 12, (version & 0xf00) >> 8, |
| 632 | (version & 0xf0) >> 4, version & 0xf); |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 633 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 634 | priv->firm_type = std; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 635 | |
| 636 | return 0; |
| 637 | } |
| 638 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 639 | static int xc2028_signal(struct dvb_frontend *fe, u16 *strength) |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 640 | { |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 641 | struct xc2028_data *priv = fe->tuner_priv; |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 642 | int frq_lock, signal = 0; |
Mauro Carvalho Chehab | 3b20532 | 2007-09-27 18:27:03 -0300 | [diff] [blame] | 643 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 644 | tuner_dbg("%s called\n", __FUNCTION__); |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 645 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 646 | mutex_lock(&priv->lock); |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 647 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 648 | *strength = 0; |
| 649 | |
Mauro Carvalho Chehab | 80b5220 | 2007-11-05 09:07:13 -0300 | [diff] [blame] | 650 | /* Sync Lock Indicator */ |
| 651 | frq_lock = xc2028_get_reg(priv, 0x0002); |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 652 | if (frq_lock <= 0) |
Mauro Carvalho Chehab | 3b20532 | 2007-09-27 18:27:03 -0300 | [diff] [blame] | 653 | goto ret; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 654 | |
| 655 | /* Frequency is locked. Return signal quality */ |
| 656 | |
Mauro Carvalho Chehab | 80b5220 | 2007-11-05 09:07:13 -0300 | [diff] [blame] | 657 | /* Get SNR of the video signal */ |
| 658 | signal = xc2028_get_reg(priv, 0x0040); |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 659 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 660 | if (signal <= 0) |
| 661 | signal = frq_lock; |
Mauro Carvalho Chehab | 3b20532 | 2007-09-27 18:27:03 -0300 | [diff] [blame] | 662 | |
| 663 | ret: |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 664 | mutex_unlock(&priv->lock); |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 665 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 666 | *strength = signal; |
| 667 | |
| 668 | return 0; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | #define DIV 15625 |
| 672 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 673 | static int generic_set_tv_freq(struct dvb_frontend *fe, u32 freq /* in Hz */ , |
| 674 | enum tuner_mode new_mode, |
| 675 | v4l2_std_id std, fe_bandwidth_t bandwidth) |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 676 | { |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 677 | struct xc2028_data *priv = fe->tuner_priv; |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 678 | int rc = -EINVAL; |
| 679 | unsigned char buf[5]; |
| 680 | u32 div, offset = 0; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 681 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 682 | tuner_dbg("%s called\n", __FUNCTION__); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 683 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 684 | mutex_lock(&priv->lock); |
| 685 | |
Mauro Carvalho Chehab | d4e7668 | 2007-07-18 23:14:25 -0300 | [diff] [blame] | 686 | /* HACK: It seems that specific firmware need to be reloaded |
| 687 | when freq is changed */ |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 688 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 689 | priv->firm_type = 0; |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 690 | |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 691 | /* Reset GPIO 1 */ |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 692 | rc = priv->tuner_callback(priv->video_dev, XC2028_TUNER_RESET, 0); |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 693 | if (rc < 0) |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 694 | goto ret; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 695 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 696 | msleep(10); |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 697 | tuner_dbg("should set frequency %d kHz)\n", freq / 1000); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 698 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 699 | if (check_firmware(fe, new_mode, std, bandwidth) < 0) |
Mauro Carvalho Chehab | 3b20532 | 2007-09-27 18:27:03 -0300 | [diff] [blame] | 700 | goto ret; |
Mauro Carvalho Chehab | 2e4160c | 2007-07-18 13:33:23 -0300 | [diff] [blame] | 701 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 702 | if (new_mode == T_DIGITAL_TV) |
Mauro Carvalho Chehab | d4e7668 | 2007-07-18 23:14:25 -0300 | [diff] [blame] | 703 | offset = 2750000; |
Mauro Carvalho Chehab | 2e4160c | 2007-07-18 13:33:23 -0300 | [diff] [blame] | 704 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 705 | div = (freq - offset + DIV / 2) / DIV; |
Mauro Carvalho Chehab | 2e4160c | 2007-07-18 13:33:23 -0300 | [diff] [blame] | 706 | |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 707 | /* CMD= Set frequency */ |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 708 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 709 | if (priv->version < 0x0202) { |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 710 | send_seq(priv, {0x00, 0x02, 0x00, 0x00}); |
| 711 | } else { |
| 712 | send_seq(priv, {0x80, 0x02, 0x00, 0x00}); |
| 713 | } |
| 714 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 715 | rc = priv->tuner_callback(priv->video_dev, XC2028_RESET_CLK, 1); |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 716 | if (rc < 0) |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 717 | goto ret; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 718 | |
| 719 | msleep(10); |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 720 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 721 | buf[0] = 0xff & (div >> 24); |
| 722 | buf[1] = 0xff & (div >> 16); |
| 723 | buf[2] = 0xff & (div >> 8); |
| 724 | buf[3] = 0xff & (div); |
| 725 | buf[4] = 0; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 726 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 727 | i2c_send(rc, priv, buf, sizeof(buf)); |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 728 | if (rc < 0) |
Mauro Carvalho Chehab | 3b20532 | 2007-09-27 18:27:03 -0300 | [diff] [blame] | 729 | goto ret; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 730 | msleep(100); |
| 731 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 732 | priv->frequency = freq; |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 733 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 734 | tuner_dbg("divider= %02x %02x %02x %02x (freq=%d.%02d)\n", |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 735 | buf[1], buf[2], buf[3], buf[4], |
| 736 | freq / 1000000, (freq % 1000000) / 10000); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 737 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 738 | rc = 0; |
Mauro Carvalho Chehab | 3b20532 | 2007-09-27 18:27:03 -0300 | [diff] [blame] | 739 | |
| 740 | ret: |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 741 | mutex_unlock(&priv->lock); |
| 742 | |
| 743 | return rc; |
Mauro Carvalho Chehab | 6cb4587 | 2007-10-02 11:57:03 -0300 | [diff] [blame] | 744 | } |
| 745 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 746 | static int xc2028_set_tv_freq(struct dvb_frontend *fe, |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 747 | struct analog_parameters *p) |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 748 | { |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 749 | struct xc2028_data *priv = fe->tuner_priv; |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 750 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 751 | tuner_dbg("%s called\n", __FUNCTION__); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 752 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 753 | return generic_set_tv_freq(fe, 62500l * p->frequency, T_ANALOG_TV, |
| 754 | p->std, BANDWIDTH_8_MHZ /* NOT USED */); |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 755 | } |
| 756 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 757 | static int xc2028_set_params(struct dvb_frontend *fe, |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 758 | struct dvb_frontend_parameters *p) |
| 759 | { |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 760 | struct xc2028_data *priv = fe->tuner_priv; |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 761 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 762 | tuner_dbg("%s called\n", __FUNCTION__); |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 763 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 764 | /* FIXME: Only OFDM implemented */ |
| 765 | if (fe->ops.info.type != FE_OFDM) { |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 766 | tuner_err("DTV type not implemented.\n"); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 767 | return -EINVAL; |
| 768 | } |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 769 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 770 | return generic_set_tv_freq(fe, p->frequency, T_DIGITAL_TV, |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 771 | 0 /* NOT USED */, |
| 772 | p->u.ofdm.bandwidth); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 773 | |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 774 | } |
| 775 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 776 | static int xc2028_dvb_release(struct dvb_frontend *fe) |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 777 | { |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 778 | struct xc2028_data *priv = fe->tuner_priv; |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 779 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 780 | tuner_dbg("%s called\n", __FUNCTION__); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 781 | |
| 782 | priv->count--; |
| 783 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 784 | if (!priv->count) { |
Mauro Carvalho Chehab | 1808a69 | 2007-10-29 17:38:59 -0300 | [diff] [blame] | 785 | list_del(&priv->xc2028_list); |
| 786 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 787 | kfree(priv->ctrl.fname); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 788 | |
| 789 | free_firmware(priv); |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 790 | kfree(priv); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 791 | } |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 792 | |
| 793 | return 0; |
| 794 | } |
| 795 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 796 | static int xc2028_get_frequency(struct dvb_frontend *fe, u32 *frequency) |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 797 | { |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 798 | struct xc2028_data *priv = fe->tuner_priv; |
| 799 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 800 | tuner_dbg("%s called\n", __FUNCTION__); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 801 | |
| 802 | *frequency = priv->frequency; |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 803 | |
| 804 | return 0; |
| 805 | } |
| 806 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 807 | 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] | 808 | { |
| 809 | struct xc2028_data *priv = fe->tuner_priv; |
| 810 | struct xc2028_ctrl *p = priv_cfg; |
| 811 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 812 | tuner_dbg("%s called\n", __FUNCTION__); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 813 | |
| 814 | priv->ctrl.type = p->type; |
| 815 | |
| 816 | if (p->fname) { |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 817 | kfree(priv->ctrl.fname); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 818 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 819 | priv->ctrl.fname = kmalloc(strlen(p->fname) + 1, GFP_KERNEL); |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 820 | if (!priv->ctrl.fname) |
| 821 | return -ENOMEM; |
| 822 | |
| 823 | free_firmware(priv); |
| 824 | strcpy(priv->ctrl.fname, p->fname); |
| 825 | } |
| 826 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 827 | if (p->max_len > 0) |
Mauro Carvalho Chehab | 352fae1 | 2007-11-01 16:56:26 -0300 | [diff] [blame] | 828 | priv->max_len = p->max_len; |
| 829 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 830 | return 0; |
| 831 | } |
| 832 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 833 | static const struct dvb_tuner_ops xc2028_dvb_tuner_ops = { |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 834 | .info = { |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 835 | .name = "Xceive XC3028", |
| 836 | .frequency_min = 42000000, |
| 837 | .frequency_max = 864000000, |
| 838 | .frequency_step = 50000, |
| 839 | }, |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 840 | |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 841 | .set_config = xc2028_set_config, |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 842 | .set_analog_params = xc2028_set_tv_freq, |
| 843 | .release = xc2028_dvb_release, |
| 844 | .get_frequency = xc2028_get_frequency, |
| 845 | .get_rf_strength = xc2028_signal, |
| 846 | .set_params = xc2028_set_params, |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 847 | |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 848 | }; |
| 849 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 850 | int xc2028_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c_adap, |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 851 | u8 i2c_addr, struct device *dev, void *video_dev, |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 852 | int (*tuner_callback) (void *dev, int command, int arg)) |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 853 | { |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 854 | struct xc2028_data *priv; |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 855 | |
Mauro Carvalho Chehab | 83fb340 | 2007-11-15 09:44:30 -0300 | [diff] [blame^] | 856 | if (debug) |
| 857 | printk(KERN_DEBUG PREFIX "Xcv2028/3028 init called!\n"); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 858 | |
| 859 | if (NULL == dev) |
| 860 | return -ENODEV; |
| 861 | |
| 862 | if (NULL == video_dev) |
| 863 | return -ENODEV; |
| 864 | |
| 865 | if (!tuner_callback) { |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 866 | printk(KERN_ERR PREFIX "No tuner callback!\n"); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 867 | return -EINVAL; |
| 868 | } |
| 869 | |
| 870 | list_for_each_entry(priv, &xc2028_list, xc2028_list) { |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 871 | if (priv->dev == dev) |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 872 | dev = NULL; |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | if (dev) { |
| 876 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 877 | if (priv == NULL) |
| 878 | return -ENOMEM; |
| 879 | |
| 880 | fe->tuner_priv = priv; |
| 881 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 882 | priv->bandwidth = BANDWIDTH_6_MHZ; |
| 883 | priv->need_load_generic = 1; |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 884 | priv->mode = T_UNINITIALIZED; |
| 885 | priv->i2c_props.addr = i2c_addr; |
| 886 | priv->i2c_props.adap = i2c_adap; |
| 887 | priv->dev = dev; |
| 888 | priv->video_dev = video_dev; |
| 889 | priv->tuner_callback = tuner_callback; |
Mauro Carvalho Chehab | de3fe21 | 2007-10-24 09:22:08 -0300 | [diff] [blame] | 890 | priv->max_len = 13; |
| 891 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 892 | |
| 893 | mutex_init(&priv->lock); |
| 894 | |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 895 | list_add_tail(&priv->xc2028_list, &xc2028_list); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 896 | } |
Mauro Carvalho Chehab | 1808a69 | 2007-10-29 17:38:59 -0300 | [diff] [blame] | 897 | priv->count++; |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 898 | |
| 899 | memcpy(&fe->ops.tuner_ops, &xc2028_dvb_tuner_ops, |
Mauro Carvalho Chehab | ab0b9fc | 2007-11-01 17:47:42 -0300 | [diff] [blame] | 900 | sizeof(xc2028_dvb_tuner_ops)); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 901 | |
| 902 | tuner_info("type set to %s\n", "XCeive xc2028/xc3028 tuner"); |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 903 | |
| 904 | return 0; |
| 905 | } |
Michel Ludwig | 701672e | 2007-07-18 10:29:10 -0300 | [diff] [blame] | 906 | EXPORT_SYMBOL(xc2028_attach); |
| 907 | |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 908 | MODULE_DESCRIPTION("Xceive xc2028/xc3028 tuner driver"); |
Mauro Carvalho Chehab | 983d214 | 2007-10-29 23:44:18 -0300 | [diff] [blame] | 909 | MODULE_AUTHOR("Michel Ludwig <michel.ludwig@gmail.com>"); |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 910 | MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); |
| 911 | MODULE_LICENSE("GPL"); |