Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] Add support for TechniSat Skystar S2

This patch adds support for the Technisat Skystar S2 - this
has been tried before but the cx24120 driver was a bit out of shape
and it didn't got any further:

https://patchwork.linuxtv.org/patch/10575/

It is an old card, but currently being sold off for next to nothing,
so it's proving quite popular of late. Noticing it's quite similar
to the cx24116 and cx24117 I've rewritten the driver in a similar way.

There were a few registers and commands from those drivers
missing from this one I've tested out and found they do something so
they've been added in to speed up tuning and to make get_frontend
return something useful.

Signed-off-by: Jemma Denson <jdenson@gmail.com>
Signed-off-by: Patrick.Boettcher <patrick.boettcher@posteo.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

authored by

Jemma Denson and committed by
Mauro Carvalho Chehab
5afc9a25 9cae84b3

+1688 -7
+1
drivers/media/common/b2c2/Kconfig
··· 14 14 select DVB_S5H1420 if MEDIA_SUBDRV_AUTOSELECT 15 15 select DVB_TUNER_ITD1000 if MEDIA_SUBDRV_AUTOSELECT 16 16 select DVB_ISL6421 if MEDIA_SUBDRV_AUTOSELECT 17 + select DVB_CX24120 if MEDIA_SUBDRV_AUTOSELECT 17 18 select DVB_CX24123 if MEDIA_SUBDRV_AUTOSELECT 18 19 select MEDIA_TUNER_SIMPLE if MEDIA_SUBDRV_AUTOSELECT 19 20 select DVB_TUNER_CX24113 if MEDIA_SUBDRV_AUTOSELECT
+44 -7
drivers/media/common/b2c2/flexcop-fe-tuner.c
··· 12 12 #include "cx24113.h" 13 13 #include "cx24123.h" 14 14 #include "isl6421.h" 15 + #include "cx24120.h" 15 16 #include "mt352.h" 16 17 #include "bcm3510.h" 17 18 #include "nxt200x.h" ··· 26 25 * into the kernel we can't call code that's in modules. */ 27 26 #define FE_SUPPORTED(fe) (defined(CONFIG_DVB_##fe) || \ 28 27 (defined(CONFIG_DVB_##fe##_MODULE) && defined(MODULE))) 28 + 29 + #if FE_SUPPORTED(BCM3510) || FE_SUPPORTED(CX24120) 30 + static int flexcop_fe_request_firmware(struct dvb_frontend *fe, 31 + const struct firmware **fw, char *name) 32 + { 33 + struct flexcop_device *fc = fe->dvb->priv; 34 + 35 + return request_firmware(fw, name, fc->dev); 36 + } 37 + #endif 29 38 30 39 /* lnb control */ 31 40 #if FE_SUPPORTED(MT312) || FE_SUPPORTED(STV0299) ··· 456 445 457 446 /* AirStar ATSC 1st generation */ 458 447 #if FE_SUPPORTED(BCM3510) 459 - static int flexcop_fe_request_firmware(struct dvb_frontend *fe, 460 - const struct firmware **fw, char* name) 461 - { 462 - struct flexcop_device *fc = fe->dvb->priv; 463 - return request_firmware(fw, name, fc->dev); 464 - } 465 - 466 448 static struct bcm3510_config air2pc_atsc_first_gen_config = { 467 449 .demod_address = 0x0f, 468 450 .request_firmware = flexcop_fe_request_firmware, ··· 623 619 #define cablestar2_attach NULL 624 620 #endif 625 621 622 + /* SkyStar S2 PCI DVB-S/S2 card based on Conexant cx24120/cx24118 */ 623 + #if FE_SUPPORTED(CX24120) && FE_SUPPORTED(ISL6421) 624 + static const struct cx24120_config skystar2_rev3_3_cx24120_config = { 625 + .i2c_addr = 0x55, 626 + .xtal_khz = 10111, 627 + .initial_mpeg_config = { 0xa1, 0x76, 0x07 }, 628 + .request_firmware = flexcop_fe_request_firmware, 629 + }; 630 + 631 + static int skystarS2_rev33_attach(struct flexcop_device *fc, 632 + struct i2c_adapter *i2c) 633 + { 634 + fc->fe = dvb_attach(cx24120_attach, 635 + &skystar2_rev3_3_cx24120_config, i2c); 636 + if (fc->fe == NULL) 637 + return 0; 638 + 639 + fc->dev_type = FC_SKYS2_REV33; 640 + fc->fc_i2c_adap[2].no_base_addr = 1; 641 + if ((dvb_attach(isl6421_attach, fc->fe, 642 + &fc->fc_i2c_adap[2].i2c_adap, 0x08, 0, 0, false) == NULL)) { 643 + err("ISL6421 could NOT be attached!"); 644 + return 0; 645 + } 646 + info("ISL6421 successfully attached."); 647 + 648 + return 1; 649 + } 650 + #else 651 + #define skystarS2_rev33_attach NULL 652 + #endif 653 + 626 654 static struct { 627 655 flexcop_device_type_t type; 628 656 int (*attach)(struct flexcop_device *, struct i2c_adapter *); ··· 668 632 { FC_AIR_ATSC1, airstar_atsc1_attach }, 669 633 { FC_CABLE, cablestar2_attach }, 670 634 { FC_SKY_REV23, skystar2_rev23_attach }, 635 + { FC_SKYS2_REV33, skystarS2_rev33_attach }, 671 636 }; 672 637 673 638 /* try to figure out the frontend */
+1
drivers/media/common/b2c2/flexcop-misc.c
··· 56 56 [FC_SKY_REV26] = "Sky2PC/SkyStar 2 DVB-S rev 2.6", 57 57 [FC_SKY_REV27] = "Sky2PC/SkyStar 2 DVB-S rev 2.7a/u", 58 58 [FC_SKY_REV28] = "Sky2PC/SkyStar 2 DVB-S rev 2.8", 59 + [FC_SKYS2_REV33] = "Sky2PC/SkyStar S2 DVB-S/S2 rev 3.3", 59 60 }; 60 61 61 62 static const char *flexcop_bus_names[] = {
+1
drivers/media/common/b2c2/flexcop-reg.h
··· 24 24 FC_SKY_REV26, 25 25 FC_SKY_REV27, 26 26 FC_SKY_REV28, 27 + FC_SKYS2_REV33, 27 28 } flexcop_device_type_t; 28 29 29 30 typedef enum {
+7
drivers/media/dvb-frontends/Kconfig
··· 223 223 help 224 224 A Dual DVB-S/S2 tuner module. Say Y when you want to support this frontend. 225 225 226 + config DVB_CX24120 227 + tristate "Conexant CX24120 based" 228 + depends on DVB_CORE && I2C 229 + default m if !MEDIA_SUBDRV_AUTOSELECT 230 + help 231 + A DVB-S/DVB-S2 tuner module. Say Y when you want to support this frontend. 232 + 226 233 config DVB_SI21XX 227 234 tristate "Silicon Labs SI21XX based" 228 235 depends on DVB_CORE && I2C
+1
drivers/media/dvb-frontends/Makefile
··· 83 83 obj-$(CONFIG_DVB_AF9013) += af9013.o 84 84 obj-$(CONFIG_DVB_CX24116) += cx24116.o 85 85 obj-$(CONFIG_DVB_CX24117) += cx24117.o 86 + obj-$(CONFIG_DVB_CX24120) += cx24120.o 86 87 obj-$(CONFIG_DVB_SI21XX) += si21xx.o 87 88 obj-$(CONFIG_DVB_SI2168) += si2168.o 88 89 obj-$(CONFIG_DVB_STV0288) += stv0288.o
+1577
drivers/media/dvb-frontends/cx24120.c
··· 1 + /* 2 + Conexant cx24120/cx24118 - DVBS/S2 Satellite demod/tuner driver 3 + 4 + Copyright (C) 2008 Patrick Boettcher <pb@linuxtv.org> 5 + Copyright (C) 2009 Sergey Tyurin <forum.free-x.de> 6 + Updated 2012 by Jannis Achstetter <jannis_achstetter@web.de> 7 + Copyright (C) 2015 Jemma Denson <jdenson@gmail.com> 8 + April 2015 9 + Refactored & simplified driver 10 + Updated to work with delivery system supplied by DVBv5 11 + Add frequency, fec & pilot to get_frontend 12 + 13 + Cards supported: Technisat Skystar S2 14 + 15 + This program is free software; you can redistribute it and/or modify 16 + it under the terms of the GNU General Public License as published by 17 + the Free Software Foundation; either version 2 of the License, or 18 + (at your option) any later version. 19 + 20 + This program is distributed in the hope that it will be useful, 21 + but WITHOUT ANY WARRANTY; without even the implied warranty of 22 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 + GNU General Public License for more details. 24 + */ 25 + 26 + #include <linux/slab.h> 27 + #include <linux/kernel.h> 28 + #include <linux/module.h> 29 + #include <linux/moduleparam.h> 30 + #include <linux/init.h> 31 + #include <linux/firmware.h> 32 + #include "dvb_frontend.h" 33 + #include "cx24120.h" 34 + 35 + #define CX24120_SEARCH_RANGE_KHZ 5000 36 + #define CX24120_FIRMWARE "dvb-fe-cx24120-1.20.58.2.fw" 37 + 38 + /* cx24120 i2c registers */ 39 + #define CX24120_REG_CMD_START (0x00) /* write cmd_id */ 40 + #define CX24120_REG_CMD_ARGS (0x01) /* write command arguments */ 41 + #define CX24120_REG_CMD_END (0x1f) /* write 0x01 for end */ 42 + 43 + #define CX24120_REG_MAILBOX (0x33) 44 + #define CX24120_REG_FREQ3 (0x34) /* frequency */ 45 + #define CX24120_REG_FREQ2 (0x35) 46 + #define CX24120_REG_FREQ1 (0x36) 47 + 48 + #define CX24120_REG_FECMODE (0x39) /* FEC status */ 49 + #define CX24120_REG_STATUS (0x3a) /* Tuner status */ 50 + #define CX24120_REG_SIGSTR_H (0x3a) /* Signal strength high */ 51 + #define CX24120_REG_SIGSTR_L (0x3b) /* Signal strength low byte */ 52 + #define CX24120_REG_QUALITY_H (0x40) /* SNR high byte */ 53 + #define CX24120_REG_QUALITY_L (0x41) /* SNR low byte */ 54 + 55 + #define CX24120_REG_BER_HH (0x47) /* BER high byte of high word */ 56 + #define CX24120_REG_BER_HL (0x48) /* BER low byte of high word */ 57 + #define CX24120_REG_BER_LH (0x49) /* BER high byte of low word */ 58 + #define CX24120_REG_BER_LL (0x4a) /* BER low byte of low word */ 59 + 60 + #define CX24120_REG_UCB_H (0x50) /* UCB high byte */ 61 + #define CX24120_REG_UCB_L (0x51) /* UCB low byte */ 62 + 63 + #define CX24120_REG_CLKDIV (0xe6) 64 + #define CX24120_REG_RATEDIV (0xf0) 65 + 66 + #define CX24120_REG_REVISION (0xff) /* Chip revision (ro) */ 67 + 68 + 69 + /* Command messages */ 70 + enum command_message_id { 71 + CMD_VCO_SET = 0x10, /* cmd.len = 12; */ 72 + CMD_TUNEREQUEST = 0x11, /* cmd.len = 15; */ 73 + 74 + CMD_MPEG_ONOFF = 0x13, /* cmd.len = 4; */ 75 + CMD_MPEG_INIT = 0x14, /* cmd.len = 7; */ 76 + CMD_BANDWIDTH = 0x15, /* cmd.len = 12; */ 77 + CMD_CLOCK_READ = 0x16, /* read clock */ 78 + CMD_CLOCK_SET = 0x17, /* cmd.len = 10; */ 79 + 80 + CMD_DISEQC_MSG1 = 0x20, /* cmd.len = 11; */ 81 + CMD_DISEQC_MSG2 = 0x21, /* cmd.len = d->msg_len + 6; */ 82 + CMD_SETVOLTAGE = 0x22, /* cmd.len = 2; */ 83 + CMD_SETTONE = 0x23, /* cmd.len = 4; */ 84 + CMD_DISEQC_BURST = 0x24, /* cmd.len not used !!! */ 85 + 86 + CMD_READ_SNR = 0x1a, /* Read signal strength */ 87 + CMD_START_TUNER = 0x1b, /* ??? */ 88 + 89 + CMD_FWVERSION = 0x35, 90 + 91 + CMD_TUNER_INIT = 0x3c, /* cmd.len = 0x03; */ 92 + }; 93 + 94 + #define CX24120_MAX_CMD_LEN 30 95 + 96 + /* pilot mask */ 97 + #define CX24120_PILOT_OFF (0x00) 98 + #define CX24120_PILOT_ON (0x40) 99 + #define CX24120_PILOT_AUTO (0x80) 100 + 101 + /* signal status */ 102 + #define CX24120_HAS_SIGNAL (0x01) 103 + #define CX24120_HAS_CARRIER (0x02) 104 + #define CX24120_HAS_VITERBI (0x04) 105 + #define CX24120_HAS_LOCK (0x08) 106 + #define CX24120_HAS_UNK1 (0x10) 107 + #define CX24120_HAS_UNK2 (0x20) 108 + #define CX24120_STATUS_MASK (0x0f) 109 + #define CX24120_SIGNAL_MASK (0xc0) 110 + 111 + #define info(args...) do { printk(KERN_INFO "cx24120: "); \ 112 + printk(args); } while (0) 113 + #define err(args...) do { printk(KERN_ERR "cx24120: ### ERROR: "); \ 114 + printk(args); } while (0) 115 + 116 + 117 + /* The Demod/Tuner can't easily provide these, we cache them */ 118 + struct cx24120_tuning { 119 + u32 frequency; 120 + u32 symbol_rate; 121 + fe_spectral_inversion_t inversion; 122 + fe_code_rate_t fec; 123 + 124 + fe_delivery_system_t delsys; 125 + fe_modulation_t modulation; 126 + fe_pilot_t pilot; 127 + 128 + /* Demod values */ 129 + u8 fec_val; 130 + u8 fec_mask; 131 + u8 clkdiv; 132 + u8 ratediv; 133 + u8 inversion_val; 134 + u8 pilot_val; 135 + }; 136 + 137 + 138 + /* Private state */ 139 + struct cx24120_state { 140 + struct i2c_adapter *i2c; 141 + const struct cx24120_config *config; 142 + struct dvb_frontend frontend; 143 + 144 + u8 cold_init; 145 + u8 mpeg_enabled; 146 + 147 + /* current and next tuning parameters */ 148 + struct cx24120_tuning dcur; 149 + struct cx24120_tuning dnxt; 150 + }; 151 + 152 + 153 + /* Command message to firmware */ 154 + struct cx24120_cmd { 155 + u8 id; 156 + u8 len; 157 + u8 arg[CX24120_MAX_CMD_LEN]; 158 + }; 159 + 160 + 161 + /* Read single register */ 162 + static int cx24120_readreg(struct cx24120_state *state, u8 reg) 163 + { 164 + int ret; 165 + u8 buf = 0; 166 + struct i2c_msg msg[] = { 167 + { .addr = state->config->i2c_addr, 168 + .flags = 0, 169 + .len = 1, 170 + .buf = &reg }, 171 + 172 + { .addr = state->config->i2c_addr, 173 + .flags = I2C_M_RD, 174 + .len = 1, 175 + .buf = &buf } 176 + }; 177 + ret = i2c_transfer(state->i2c, msg, 2); 178 + if (ret != 2) { 179 + err("Read error: reg=0x%02x, ret=0x%02x)\n", reg, ret); 180 + return ret; 181 + } 182 + 183 + dev_dbg(&state->i2c->dev, "%s: reg=0x%02x; data=0x%02x\n", 184 + __func__, reg, buf); 185 + 186 + return buf; 187 + } 188 + 189 + 190 + /* Write single register */ 191 + static int cx24120_writereg(struct cx24120_state *state, u8 reg, u8 data) 192 + { 193 + u8 buf[] = { reg, data }; 194 + struct i2c_msg msg = { 195 + .addr = state->config->i2c_addr, 196 + .flags = 0, 197 + .buf = buf, 198 + .len = 2 }; 199 + int ret; 200 + 201 + ret = i2c_transfer(state->i2c, &msg, 1); 202 + if (ret != 1) { 203 + err("Write error: i2c_write error(err == %i, 0x%02x: 0x%02x)\n", 204 + ret, reg, data); 205 + return ret; 206 + } 207 + 208 + dev_dbg(&state->i2c->dev, "%s: reg=0x%02x; data=0x%02x\n", 209 + __func__, reg, data); 210 + 211 + return 0; 212 + } 213 + 214 + 215 + /* Write multiple registers */ 216 + static int cx24120_writeregN(struct cx24120_state *state, 217 + u8 reg, const u8 *values, u16 len, u8 incr) 218 + { 219 + int ret; 220 + u8 buf[5]; /* maximum 4 data bytes at once - flexcop limitation 221 + (very limited i2c-interface this one) */ 222 + 223 + struct i2c_msg msg = { 224 + .addr = state->config->i2c_addr, 225 + .flags = 0, 226 + .buf = buf, 227 + .len = len }; 228 + 229 + while (len) { 230 + buf[0] = reg; 231 + msg.len = len > 4 ? 4 : len; 232 + memcpy(&buf[1], values, msg.len); 233 + 234 + len -= msg.len; /* data length revers counter */ 235 + values += msg.len; /* incr data pointer */ 236 + 237 + if (incr) 238 + reg += msg.len; 239 + msg.len++; /* don't forget the addr byte */ 240 + 241 + ret = i2c_transfer(state->i2c, &msg, 1); 242 + if (ret != 1) { 243 + err("i2c_write error(err == %i, 0x%02x)\n", ret, reg); 244 + return ret; 245 + } 246 + 247 + dev_dbg(&state->i2c->dev, 248 + "%s: reg=0x%02x; data=0x%02x,0x%02x,0x%02x,0x%02x\n", 249 + __func__, reg, 250 + buf[1], buf[2], buf[3], buf[4]); 251 + 252 + } 253 + 254 + return 0; 255 + } 256 + 257 + 258 + static struct dvb_frontend_ops cx24120_ops; 259 + 260 + struct dvb_frontend *cx24120_attach(const struct cx24120_config *config, 261 + struct i2c_adapter *i2c) 262 + { 263 + struct cx24120_state *state = NULL; 264 + int demod_rev; 265 + 266 + info("Conexant cx24120/cx24118 - DVBS/S2 Satellite demod/tuner\n"); 267 + state = kzalloc(sizeof(struct cx24120_state), 268 + GFP_KERNEL); 269 + if (state == NULL) { 270 + err("Unable to allocate memory for cx24120_state\n"); 271 + goto error; 272 + } 273 + 274 + /* setup the state */ 275 + state->config = config; 276 + state->i2c = i2c; 277 + 278 + /* check if the demod is present and has proper type */ 279 + demod_rev = cx24120_readreg(state, CX24120_REG_REVISION); 280 + switch (demod_rev) { 281 + case 0x07: 282 + info("Demod cx24120 rev. 0x07 detected.\n"); 283 + break; 284 + case 0x05: 285 + info("Demod cx24120 rev. 0x05 detected.\n"); 286 + break; 287 + default: 288 + err("Unsupported demod revision: 0x%x detected.\n", 289 + demod_rev); 290 + goto error; 291 + } 292 + 293 + /* create dvb_frontend */ 294 + state->cold_init = 0; 295 + memcpy(&state->frontend.ops, &cx24120_ops, 296 + sizeof(struct dvb_frontend_ops)); 297 + state->frontend.demodulator_priv = state; 298 + 299 + info("Conexant cx24120/cx24118 attached.\n"); 300 + return &state->frontend; 301 + 302 + error: 303 + kfree(state); 304 + return NULL; 305 + } 306 + EXPORT_SYMBOL(cx24120_attach); 307 + 308 + static int cx24120_test_rom(struct cx24120_state *state) 309 + { 310 + int err, ret; 311 + 312 + err = cx24120_readreg(state, 0xfd); 313 + if (err & 4) { 314 + ret = cx24120_readreg(state, 0xdf) & 0xfe; 315 + err = cx24120_writereg(state, 0xdf, ret); 316 + } 317 + return err; 318 + } 319 + 320 + 321 + static int cx24120_read_snr(struct dvb_frontend *fe, u16 *snr) 322 + { 323 + struct cx24120_state *state = fe->demodulator_priv; 324 + 325 + *snr = (cx24120_readreg(state, CX24120_REG_QUALITY_H)<<8) | 326 + (cx24120_readreg(state, CX24120_REG_QUALITY_L)); 327 + dev_dbg(&state->i2c->dev, "%s: read SNR index = %d\n", 328 + __func__, *snr); 329 + 330 + return 0; 331 + } 332 + 333 + 334 + static int cx24120_read_ber(struct dvb_frontend *fe, u32 *ber) 335 + { 336 + struct cx24120_state *state = fe->demodulator_priv; 337 + 338 + *ber = (cx24120_readreg(state, CX24120_REG_BER_HH) << 24) | 339 + (cx24120_readreg(state, CX24120_REG_BER_HL) << 16) | 340 + (cx24120_readreg(state, CX24120_REG_BER_LH) << 8) | 341 + cx24120_readreg(state, CX24120_REG_BER_LL); 342 + dev_dbg(&state->i2c->dev, "%s: read BER index = %d\n", 343 + __func__, *ber); 344 + 345 + return 0; 346 + } 347 + 348 + static int cx24120_msg_mpeg_output_global_config(struct cx24120_state *state, 349 + u8 flag); 350 + 351 + /* Check if we're running a command that needs to disable mpeg out */ 352 + static void cx24120_check_cmd(struct cx24120_state *state, u8 id) 353 + { 354 + switch (id) { 355 + case CMD_TUNEREQUEST: 356 + case CMD_CLOCK_READ: 357 + case CMD_DISEQC_MSG1: 358 + case CMD_DISEQC_MSG2: 359 + case CMD_SETVOLTAGE: 360 + case CMD_SETTONE: 361 + cx24120_msg_mpeg_output_global_config(state, 0); 362 + /* Old driver would do a msleep(100) here */ 363 + default: 364 + return; 365 + } 366 + } 367 + 368 + 369 + /* Send a message to the firmware */ 370 + static int cx24120_message_send(struct cx24120_state *state, 371 + struct cx24120_cmd *cmd) 372 + { 373 + int ret, ficus; 374 + 375 + if (state->mpeg_enabled) { 376 + /* Disable mpeg out on certain commands */ 377 + cx24120_check_cmd(state, cmd->id); 378 + } 379 + 380 + ret = cx24120_writereg(state, CX24120_REG_CMD_START, cmd->id); 381 + ret = cx24120_writeregN(state, CX24120_REG_CMD_ARGS, &cmd->arg[0], 382 + cmd->len, 1); 383 + ret = cx24120_writereg(state, CX24120_REG_CMD_END, 0x01); 384 + 385 + ficus = 1000; 386 + while (cx24120_readreg(state, CX24120_REG_CMD_END)) { 387 + msleep(20); 388 + ficus -= 20; 389 + if (ficus == 0) { 390 + err("Error sending message to firmware\n"); 391 + return -EREMOTEIO; 392 + } 393 + } 394 + dev_dbg(&state->i2c->dev, "%s: Successfully send message 0x%02x\n", 395 + __func__, cmd->id); 396 + 397 + return 0; 398 + } 399 + 400 + /* Send a message and fill arg[] with the results */ 401 + static int cx24120_message_sendrcv(struct cx24120_state *state, 402 + struct cx24120_cmd *cmd, u8 numreg) 403 + { 404 + int ret, i; 405 + 406 + if (numreg > CX24120_MAX_CMD_LEN) { 407 + err("Too many registers to read. cmd->reg = %d", numreg); 408 + return -EREMOTEIO; 409 + } 410 + 411 + ret = cx24120_message_send(state, cmd); 412 + if (ret != 0) 413 + return ret; 414 + 415 + if (!numreg) 416 + return 0; 417 + 418 + /* Read numreg registers starting from register cmd->len */ 419 + for (i = 0; i < numreg; i++) 420 + cmd->arg[i] = cx24120_readreg(state, (cmd->len+i+1)); 421 + 422 + return 0; 423 + } 424 + 425 + 426 + 427 + static int cx24120_read_signal_strength(struct dvb_frontend *fe, 428 + u16 *signal_strength) 429 + { 430 + struct cx24120_state *state = fe->demodulator_priv; 431 + struct cx24120_cmd cmd; 432 + int ret, sigstr_h, sigstr_l; 433 + 434 + cmd.id = CMD_READ_SNR; 435 + cmd.len = 1; 436 + cmd.arg[0] = 0x00; 437 + 438 + ret = cx24120_message_send(state, &cmd); 439 + if (ret != 0) { 440 + err("error reading signal strength\n"); 441 + return -EREMOTEIO; 442 + } 443 + 444 + /* raw */ 445 + sigstr_h = (cx24120_readreg(state, CX24120_REG_SIGSTR_H) >> 6) << 8; 446 + sigstr_l = cx24120_readreg(state, CX24120_REG_SIGSTR_L); 447 + dev_dbg(&state->i2c->dev, "%s: Signal strength from firmware= 0x%x\n", 448 + __func__, (sigstr_h | sigstr_l)); 449 + 450 + /* cooked */ 451 + *signal_strength = ((sigstr_h | sigstr_l) << 5) & 0x0000ffff; 452 + dev_dbg(&state->i2c->dev, "%s: Signal strength= 0x%x\n", 453 + __func__, *signal_strength); 454 + 455 + return 0; 456 + } 457 + 458 + 459 + static int cx24120_msg_mpeg_output_global_config(struct cx24120_state *state, 460 + u8 enable) 461 + { 462 + struct cx24120_cmd cmd; 463 + int ret; 464 + 465 + cmd.id = CMD_MPEG_ONOFF; 466 + cmd.len = 4; 467 + cmd.arg[0] = 0x01; 468 + cmd.arg[1] = 0x00; 469 + cmd.arg[2] = enable ? 0 : (u8)(-1); 470 + cmd.arg[3] = 0x01; 471 + 472 + ret = cx24120_message_send(state, &cmd); 473 + if (ret != 0) { 474 + dev_dbg(&state->i2c->dev, 475 + "%s: Failed to set MPEG output to %s\n", 476 + __func__, 477 + (enable)?"enabled":"disabled"); 478 + return ret; 479 + } 480 + 481 + state->mpeg_enabled = enable; 482 + dev_dbg(&state->i2c->dev, "%s: MPEG output %s\n", 483 + __func__, 484 + (enable)?"enabled":"disabled"); 485 + 486 + return 0; 487 + } 488 + 489 + 490 + static int cx24120_msg_mpeg_output_config(struct cx24120_state *state, u8 seq) 491 + { 492 + struct cx24120_cmd cmd; 493 + struct cx24120_initial_mpeg_config i = 494 + state->config->initial_mpeg_config; 495 + 496 + cmd.id = CMD_MPEG_INIT; 497 + cmd.len = 7; 498 + cmd.arg[0] = seq; /* sequental number - can be 0,1,2 */ 499 + cmd.arg[1] = ((i.x1 & 0x01) << 1) | ((i.x1 >> 1) & 0x01); 500 + cmd.arg[2] = 0x05; 501 + cmd.arg[3] = 0x02; 502 + cmd.arg[4] = ((i.x2 >> 1) & 0x01); 503 + cmd.arg[5] = (i.x2 & 0xf0) | (i.x3 & 0x0f); 504 + cmd.arg[6] = 0x10; 505 + 506 + return cx24120_message_send(state, &cmd); 507 + } 508 + 509 + 510 + static int cx24120_diseqc_send_burst(struct dvb_frontend *fe, 511 + fe_sec_mini_cmd_t burst) 512 + { 513 + struct cx24120_state *state = fe->demodulator_priv; 514 + struct cx24120_cmd cmd; 515 + 516 + /* Yes, cmd.len is set to zero. The old driver 517 + * didn't specify any len, but also had a 518 + * memset 0 before every use of the cmd struct 519 + * which would have set it to zero. 520 + * This quite probably needs looking into. 521 + */ 522 + cmd.id = CMD_DISEQC_BURST; 523 + cmd.len = 0; 524 + cmd.arg[0] = 0x00; 525 + if (burst) 526 + cmd.arg[1] = 0x01; 527 + dev_dbg(&state->i2c->dev, "%s: burst sent.\n", __func__); 528 + 529 + return cx24120_message_send(state, &cmd); 530 + } 531 + 532 + 533 + static int cx24120_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone) 534 + { 535 + struct cx24120_state *state = fe->demodulator_priv; 536 + struct cx24120_cmd cmd; 537 + 538 + dev_dbg(&state->i2c->dev, "%s(%d)\n", 539 + __func__, tone); 540 + 541 + if ((tone != SEC_TONE_ON) && (tone != SEC_TONE_OFF)) { 542 + err("Invalid tone=%d\n", tone); 543 + return -EINVAL; 544 + } 545 + 546 + cmd.id = CMD_SETTONE; 547 + cmd.len = 4; 548 + cmd.arg[0] = 0x00; 549 + cmd.arg[1] = 0x00; 550 + cmd.arg[2] = 0x00; 551 + cmd.arg[3] = (tone == SEC_TONE_ON)?0x01:0x00; 552 + 553 + return cx24120_message_send(state, &cmd); 554 + } 555 + 556 + 557 + static int cx24120_set_voltage(struct dvb_frontend *fe, 558 + fe_sec_voltage_t voltage) 559 + { 560 + struct cx24120_state *state = fe->demodulator_priv; 561 + struct cx24120_cmd cmd; 562 + 563 + dev_dbg(&state->i2c->dev, "%s(%d)\n", 564 + __func__, voltage); 565 + 566 + cmd.id = CMD_SETVOLTAGE; 567 + cmd.len = 2; 568 + cmd.arg[0] = 0x00; 569 + cmd.arg[1] = (voltage == SEC_VOLTAGE_18)?0x01:0x00; 570 + 571 + return cx24120_message_send(state, &cmd); 572 + } 573 + 574 + 575 + static int cx24120_send_diseqc_msg(struct dvb_frontend *fe, 576 + struct dvb_diseqc_master_cmd *d) 577 + { 578 + struct cx24120_state *state = fe->demodulator_priv; 579 + struct cx24120_cmd cmd; 580 + int back_count; 581 + 582 + dev_dbg(&state->i2c->dev, "%s()\n", __func__); 583 + 584 + cmd.id = CMD_DISEQC_MSG1; 585 + cmd.len = 11; 586 + cmd.arg[0] = 0x00; 587 + cmd.arg[1] = 0x00; 588 + cmd.arg[2] = 0x03; 589 + cmd.arg[3] = 0x16; 590 + cmd.arg[4] = 0x28; 591 + cmd.arg[5] = 0x01; 592 + cmd.arg[6] = 0x01; 593 + cmd.arg[7] = 0x14; 594 + cmd.arg[8] = 0x19; 595 + cmd.arg[9] = 0x14; 596 + cmd.arg[10] = 0x1e; 597 + 598 + if (cx24120_message_send(state, &cmd)) { 599 + err("send 1st message(0x%x) failed\n", cmd.id); 600 + return -EREMOTEIO; 601 + } 602 + 603 + cmd.id = CMD_DISEQC_MSG2; 604 + cmd.len = d->msg_len + 6; 605 + cmd.arg[0] = 0x00; 606 + cmd.arg[1] = 0x01; 607 + cmd.arg[2] = 0x02; 608 + cmd.arg[3] = 0x00; 609 + cmd.arg[4] = 0x00; 610 + cmd.arg[5] = d->msg_len; 611 + 612 + memcpy(&cmd.arg[6], &d->msg, d->msg_len); 613 + 614 + if (cx24120_message_send(state, &cmd)) { 615 + err("send 2nd message(0x%x) failed\n", cmd.id); 616 + return -EREMOTEIO; 617 + } 618 + 619 + back_count = 500; 620 + do { 621 + if (!(cx24120_readreg(state, 0x93) & 0x01)) { 622 + dev_dbg(&state->i2c->dev, 623 + "%s: diseqc sequence sent success\n", 624 + __func__); 625 + return 0; 626 + } 627 + msleep(20); 628 + back_count -= 20; 629 + } while (back_count); 630 + 631 + err("Too long waiting for diseqc.\n"); 632 + return -ETIMEDOUT; 633 + } 634 + 635 + 636 + /* Read current tuning status */ 637 + static int cx24120_read_status(struct dvb_frontend *fe, fe_status_t *status) 638 + { 639 + struct cx24120_state *state = fe->demodulator_priv; 640 + int lock; 641 + 642 + lock = cx24120_readreg(state, CX24120_REG_STATUS); 643 + 644 + dev_dbg(&state->i2c->dev, "%s() status = 0x%02x\n", 645 + __func__, lock); 646 + 647 + *status = 0; 648 + 649 + if (lock & CX24120_HAS_SIGNAL) 650 + *status = FE_HAS_SIGNAL; 651 + if (lock & CX24120_HAS_CARRIER) 652 + *status |= FE_HAS_CARRIER; 653 + if (lock & CX24120_HAS_VITERBI) 654 + *status |= FE_HAS_VITERBI | FE_HAS_SYNC; 655 + if (lock & CX24120_HAS_LOCK) 656 + *status |= FE_HAS_LOCK; 657 + 658 + /* TODO: is FE_HAS_SYNC in the right place? 659 + * Other cx241xx drivers have this slightly 660 + * different */ 661 + 662 + return 0; 663 + } 664 + 665 + 666 + /* FEC & modulation lookup table 667 + * Used for decoding the REG_FECMODE register 668 + * once tuned in. 669 + */ 670 + static struct cx24120_modfec { 671 + fe_delivery_system_t delsys; 672 + fe_modulation_t mod; 673 + fe_code_rate_t fec; 674 + u8 val; 675 + } modfec_lookup_table[] = { 676 + /*delsys mod fec val */ 677 + { SYS_DVBS, QPSK, FEC_1_2, 0x01 }, 678 + { SYS_DVBS, QPSK, FEC_2_3, 0x02 }, 679 + { SYS_DVBS, QPSK, FEC_3_4, 0x03 }, 680 + { SYS_DVBS, QPSK, FEC_4_5, 0x04 }, 681 + { SYS_DVBS, QPSK, FEC_5_6, 0x05 }, 682 + { SYS_DVBS, QPSK, FEC_6_7, 0x06 }, 683 + { SYS_DVBS, QPSK, FEC_7_8, 0x07 }, 684 + 685 + { SYS_DVBS2, QPSK, FEC_1_2, 0x04 }, 686 + { SYS_DVBS2, QPSK, FEC_3_5, 0x05 }, 687 + { SYS_DVBS2, QPSK, FEC_2_3, 0x06 }, 688 + { SYS_DVBS2, QPSK, FEC_3_4, 0x07 }, 689 + { SYS_DVBS2, QPSK, FEC_4_5, 0x08 }, 690 + { SYS_DVBS2, QPSK, FEC_5_6, 0x09 }, 691 + { SYS_DVBS2, QPSK, FEC_8_9, 0x0a }, 692 + { SYS_DVBS2, QPSK, FEC_9_10, 0x0b }, 693 + 694 + { SYS_DVBS2, PSK_8, FEC_3_5, 0x0c }, 695 + { SYS_DVBS2, PSK_8, FEC_2_3, 0x0d }, 696 + { SYS_DVBS2, PSK_8, FEC_3_4, 0x0e }, 697 + { SYS_DVBS2, PSK_8, FEC_5_6, 0x0f }, 698 + { SYS_DVBS2, PSK_8, FEC_8_9, 0x10 }, 699 + { SYS_DVBS2, PSK_8, FEC_9_10, 0x11 }, 700 + }; 701 + 702 + 703 + /* Retrieve current fec, modulation & pilot values */ 704 + static int cx24120_get_fec(struct dvb_frontend *fe) 705 + { 706 + struct dtv_frontend_properties *c = &fe->dtv_property_cache; 707 + struct cx24120_state *state = fe->demodulator_priv; 708 + int idx; 709 + int ret; 710 + int GettedFEC; 711 + 712 + dev_dbg(&state->i2c->dev, "%s()\n", __func__); 713 + 714 + ret = cx24120_readreg(state, CX24120_REG_FECMODE); 715 + GettedFEC = ret & 0x3f; /* Lower 6 bits */ 716 + 717 + dev_dbg(&state->i2c->dev, "%s: Get FEC: %d\n", __func__, GettedFEC); 718 + 719 + for (idx = 0; idx < ARRAY_SIZE(modfec_lookup_table); idx++) { 720 + if (modfec_lookup_table[idx].delsys != state->dcur.delsys) 721 + continue; 722 + if (modfec_lookup_table[idx].val != GettedFEC) 723 + continue; 724 + 725 + break; /* found */ 726 + } 727 + 728 + if (idx >= ARRAY_SIZE(modfec_lookup_table)) { 729 + dev_dbg(&state->i2c->dev, "%s: Couldn't find fec!\n", 730 + __func__); 731 + return -EINVAL; 732 + } 733 + 734 + /* save values back to cache */ 735 + c->modulation = modfec_lookup_table[idx].mod; 736 + c->fec_inner = modfec_lookup_table[idx].fec; 737 + c->pilot = (ret & 0x80) ? PILOT_ON : PILOT_OFF; 738 + 739 + dev_dbg(&state->i2c->dev, 740 + "%s: mod(%d), fec(%d), pilot(%d)\n", 741 + __func__, 742 + c->modulation, c->fec_inner, c->pilot); 743 + 744 + return 0; 745 + } 746 + 747 + 748 + /* Clock ratios lookup table 749 + * 750 + * Values obtained from much larger table in old driver 751 + * which had numerous entries which would never match. 752 + * 753 + * There's probably some way of calculating these but I 754 + * can't determine the pattern 755 + */ 756 + static struct cx24120_clock_ratios_table { 757 + fe_delivery_system_t delsys; 758 + fe_pilot_t pilot; 759 + fe_modulation_t mod; 760 + fe_code_rate_t fec; 761 + u32 m_rat; 762 + u32 n_rat; 763 + u32 rate; 764 + } clock_ratios_table[] = { 765 + /*delsys pilot mod fec m_rat n_rat rate */ 766 + { SYS_DVBS2, PILOT_OFF, QPSK, FEC_1_2, 273088, 254505, 274 }, 767 + { SYS_DVBS2, PILOT_OFF, QPSK, FEC_3_5, 17272, 13395, 330 }, 768 + { SYS_DVBS2, PILOT_OFF, QPSK, FEC_2_3, 24344, 16967, 367 }, 769 + { SYS_DVBS2, PILOT_OFF, QPSK, FEC_3_4, 410788, 254505, 413 }, 770 + { SYS_DVBS2, PILOT_OFF, QPSK, FEC_4_5, 438328, 254505, 440 }, 771 + { SYS_DVBS2, PILOT_OFF, QPSK, FEC_5_6, 30464, 16967, 459 }, 772 + { SYS_DVBS2, PILOT_OFF, QPSK, FEC_8_9, 487832, 254505, 490 }, 773 + { SYS_DVBS2, PILOT_OFF, QPSK, FEC_9_10, 493952, 254505, 496 }, 774 + { SYS_DVBS2, PILOT_OFF, PSK_8, FEC_3_5, 328168, 169905, 494 }, 775 + { SYS_DVBS2, PILOT_OFF, PSK_8, FEC_2_3, 24344, 11327, 550 }, 776 + { SYS_DVBS2, PILOT_OFF, PSK_8, FEC_3_4, 410788, 169905, 618 }, 777 + { SYS_DVBS2, PILOT_OFF, PSK_8, FEC_5_6, 30464, 11327, 688 }, 778 + { SYS_DVBS2, PILOT_OFF, PSK_8, FEC_8_9, 487832, 169905, 735 }, 779 + { SYS_DVBS2, PILOT_OFF, PSK_8, FEC_9_10, 493952, 169905, 744 }, 780 + { SYS_DVBS2, PILOT_ON, QPSK, FEC_1_2, 273088, 260709, 268 }, 781 + { SYS_DVBS2, PILOT_ON, QPSK, FEC_3_5, 328168, 260709, 322 }, 782 + { SYS_DVBS2, PILOT_ON, QPSK, FEC_2_3, 121720, 86903, 358 }, 783 + { SYS_DVBS2, PILOT_ON, QPSK, FEC_3_4, 410788, 260709, 403 }, 784 + { SYS_DVBS2, PILOT_ON, QPSK, FEC_4_5, 438328, 260709, 430 }, 785 + { SYS_DVBS2, PILOT_ON, QPSK, FEC_5_6, 152320, 86903, 448 }, 786 + { SYS_DVBS2, PILOT_ON, QPSK, FEC_8_9, 487832, 260709, 479 }, 787 + { SYS_DVBS2, PILOT_ON, QPSK, FEC_9_10, 493952, 260709, 485 }, 788 + { SYS_DVBS2, PILOT_ON, PSK_8, FEC_3_5, 328168, 173853, 483 }, 789 + { SYS_DVBS2, PILOT_ON, PSK_8, FEC_2_3, 121720, 57951, 537 }, 790 + { SYS_DVBS2, PILOT_ON, PSK_8, FEC_3_4, 410788, 173853, 604 }, 791 + { SYS_DVBS2, PILOT_ON, PSK_8, FEC_5_6, 152320, 57951, 672 }, 792 + { SYS_DVBS2, PILOT_ON, PSK_8, FEC_8_9, 487832, 173853, 718 }, 793 + { SYS_DVBS2, PILOT_ON, PSK_8, FEC_9_10, 493952, 173853, 727 }, 794 + { SYS_DVBS, PILOT_OFF, QPSK, FEC_1_2, 152592, 152592, 256 }, 795 + { SYS_DVBS, PILOT_OFF, QPSK, FEC_2_3, 305184, 228888, 341 }, 796 + { SYS_DVBS, PILOT_OFF, QPSK, FEC_3_4, 457776, 305184, 384 }, 797 + { SYS_DVBS, PILOT_OFF, QPSK, FEC_5_6, 762960, 457776, 427 }, 798 + { SYS_DVBS, PILOT_OFF, QPSK, FEC_7_8, 1068144, 610368, 448 }, 799 + }; 800 + 801 + 802 + /* Set clock ratio from lookup table */ 803 + static void cx24120_set_clock_ratios(struct dvb_frontend *fe) 804 + { 805 + struct dtv_frontend_properties *c = &fe->dtv_property_cache; 806 + struct cx24120_state *state = fe->demodulator_priv; 807 + struct cx24120_cmd cmd; 808 + int ret, idx; 809 + 810 + /* Find fec, modulation, pilot */ 811 + ret = cx24120_get_fec(fe); 812 + if (ret != 0) 813 + return; 814 + 815 + /* Find the clock ratios in the lookup table */ 816 + for (idx = 0; idx < ARRAY_SIZE(clock_ratios_table); idx++) { 817 + if (clock_ratios_table[idx].delsys != state->dcur.delsys) 818 + continue; 819 + if (clock_ratios_table[idx].mod != c->modulation) 820 + continue; 821 + if (clock_ratios_table[idx].fec != c->fec_inner) 822 + continue; 823 + if (clock_ratios_table[idx].pilot != c->pilot) 824 + continue; 825 + 826 + break; /* found */ 827 + } 828 + 829 + if (idx >= ARRAY_SIZE(clock_ratios_table)) { 830 + info("Clock ratio not found - data reception in danger\n"); 831 + return; 832 + } 833 + 834 + 835 + /* Read current values? */ 836 + cmd.id = CMD_CLOCK_READ; 837 + cmd.len = 1; 838 + cmd.arg[0] = 0x00; 839 + ret = cx24120_message_sendrcv(state, &cmd, 6); 840 + if (ret != 0) 841 + return; 842 + /* in cmd[0]-[5] - result */ 843 + 844 + dev_dbg(&state->i2c->dev, 845 + "%s: m=%d, n=%d; idx: %d m=%d, n=%d, rate=%d\n", 846 + __func__, 847 + cmd.arg[2] | (cmd.arg[1] << 8) | (cmd.arg[0] << 16), 848 + cmd.arg[5] | (cmd.arg[4] << 8) | (cmd.arg[3] << 16), 849 + idx, 850 + clock_ratios_table[idx].m_rat, 851 + clock_ratios_table[idx].n_rat, 852 + clock_ratios_table[idx].rate); 853 + 854 + 855 + 856 + /* Set the clock */ 857 + cmd.id = CMD_CLOCK_SET; 858 + cmd.len = 10; 859 + cmd.arg[0] = 0; 860 + cmd.arg[1] = 0x10; 861 + cmd.arg[2] = (clock_ratios_table[idx].m_rat >> 16) & 0xff; 862 + cmd.arg[3] = (clock_ratios_table[idx].m_rat >> 8) & 0xff; 863 + cmd.arg[4] = (clock_ratios_table[idx].m_rat >> 0) & 0xff; 864 + cmd.arg[5] = (clock_ratios_table[idx].n_rat >> 16) & 0xff; 865 + cmd.arg[6] = (clock_ratios_table[idx].n_rat >> 8) & 0xff; 866 + cmd.arg[7] = (clock_ratios_table[idx].n_rat >> 0) & 0xff; 867 + cmd.arg[8] = (clock_ratios_table[idx].rate >> 8) & 0xff; 868 + cmd.arg[9] = (clock_ratios_table[idx].rate >> 0) & 0xff; 869 + 870 + cx24120_message_send(state, &cmd); 871 + 872 + } 873 + 874 + 875 + /* Set inversion value */ 876 + static int cx24120_set_inversion(struct cx24120_state *state, 877 + fe_spectral_inversion_t inversion) 878 + { 879 + dev_dbg(&state->i2c->dev, "%s(%d)\n", 880 + __func__, inversion); 881 + 882 + switch (inversion) { 883 + case INVERSION_OFF: 884 + state->dnxt.inversion_val = 0x00; 885 + break; 886 + case INVERSION_ON: 887 + state->dnxt.inversion_val = 0x04; 888 + break; 889 + case INVERSION_AUTO: 890 + state->dnxt.inversion_val = 0x0c; 891 + break; 892 + default: 893 + return -EINVAL; 894 + } 895 + 896 + state->dnxt.inversion = inversion; 897 + 898 + return 0; 899 + } 900 + 901 + /* FEC lookup table for tuning 902 + * Some DVB-S2 val's have been found by trial 903 + * and error. Sofar it seems to match up with 904 + * the contents of the REG_FECMODE after tuning 905 + * The rest will probably be the same but would 906 + * need testing. 907 + * Anything not in the table will run with 908 + * FEC_AUTO and take a while longer to tune in 909 + * ( c.500ms instead of 30ms ) 910 + */ 911 + static struct cx24120_modfec_table { 912 + fe_delivery_system_t delsys; 913 + fe_modulation_t mod; 914 + fe_code_rate_t fec; 915 + u8 val; 916 + } modfec_table[] = { 917 + /*delsys mod fec val */ 918 + { SYS_DVBS, QPSK, FEC_1_2, 0x2e }, 919 + { SYS_DVBS, QPSK, FEC_2_3, 0x2f }, 920 + { SYS_DVBS, QPSK, FEC_3_4, 0x30 }, 921 + { SYS_DVBS, QPSK, FEC_5_6, 0x31 }, 922 + { SYS_DVBS, QPSK, FEC_6_7, 0x32 }, 923 + { SYS_DVBS, QPSK, FEC_7_8, 0x33 }, 924 + 925 + { SYS_DVBS2, QPSK, FEC_3_4, 0x07 }, 926 + 927 + { SYS_DVBS2, PSK_8, FEC_2_3, 0x0d }, 928 + { SYS_DVBS2, PSK_8, FEC_3_4, 0x0e }, 929 + }; 930 + 931 + /* Set fec_val & fec_mask values from delsys, modulation & fec */ 932 + static int cx24120_set_fec(struct cx24120_state *state, 933 + fe_modulation_t mod, fe_code_rate_t fec) 934 + { 935 + int idx; 936 + 937 + dev_dbg(&state->i2c->dev, 938 + "%s(0x%02x,0x%02x)\n", __func__, mod, fec); 939 + 940 + state->dnxt.fec = fec; 941 + 942 + /* Lookup fec_val from modfec table */ 943 + for (idx = 0; idx < ARRAY_SIZE(modfec_table); idx++) { 944 + if (modfec_table[idx].delsys != state->dnxt.delsys) 945 + continue; 946 + if (modfec_table[idx].mod != mod) 947 + continue; 948 + if (modfec_table[idx].fec != fec) 949 + continue; 950 + 951 + /* found */ 952 + state->dnxt.fec_mask = 0x00; 953 + state->dnxt.fec_val = modfec_table[idx].val; 954 + return 0; 955 + } 956 + 957 + 958 + if (state->dnxt.delsys == SYS_DVBS2) { 959 + /* DVBS2 auto is 0x00/0x00 */ 960 + state->dnxt.fec_mask = 0x00; 961 + state->dnxt.fec_val = 0x00; 962 + } else { 963 + /* Set DVB-S to auto */ 964 + state->dnxt.fec_val = 0x2e; 965 + state->dnxt.fec_mask = 0xac; 966 + } 967 + 968 + return 0; 969 + } 970 + 971 + 972 + /* Set pilot */ 973 + static int cx24120_set_pilot(struct cx24120_state *state, 974 + fe_pilot_t pilot) { 975 + 976 + dev_dbg(&state->i2c->dev, 977 + "%s(%d)\n", __func__, pilot); 978 + 979 + /* Pilot only valid in DVBS2 */ 980 + if (state->dnxt.delsys != SYS_DVBS2) { 981 + state->dnxt.pilot_val = CX24120_PILOT_OFF; 982 + return 0; 983 + } 984 + 985 + 986 + switch (pilot) { 987 + case PILOT_OFF: 988 + state->dnxt.pilot_val = CX24120_PILOT_OFF; 989 + break; 990 + case PILOT_ON: 991 + state->dnxt.pilot_val = CX24120_PILOT_ON; 992 + break; 993 + case PILOT_AUTO: 994 + default: 995 + state->dnxt.pilot_val = CX24120_PILOT_AUTO; 996 + } 997 + 998 + return 0; 999 + } 1000 + 1001 + /* Set symbol rate */ 1002 + static int cx24120_set_symbolrate(struct cx24120_state *state, u32 rate) 1003 + { 1004 + dev_dbg(&state->i2c->dev, "%s(%d)\n", 1005 + __func__, rate); 1006 + 1007 + state->dnxt.symbol_rate = rate; 1008 + 1009 + /* Check symbol rate */ 1010 + if (rate > 31000000) { 1011 + state->dnxt.clkdiv = (-(rate < 31000001) & 3) + 2; 1012 + state->dnxt.ratediv = (-(rate < 31000001) & 6) + 4; 1013 + } else { 1014 + state->dnxt.clkdiv = 3; 1015 + state->dnxt.ratediv = 6; 1016 + } 1017 + 1018 + return 0; 1019 + } 1020 + 1021 + 1022 + /* Overwrite the current tuning params, we are about to tune */ 1023 + static void cx24120_clone_params(struct dvb_frontend *fe) 1024 + { 1025 + struct cx24120_state *state = fe->demodulator_priv; 1026 + 1027 + state->dcur = state->dnxt; 1028 + } 1029 + 1030 + 1031 + /* Table of time to tune for different symrates */ 1032 + static struct cx24120_symrate_delay { 1033 + fe_delivery_system_t delsys; 1034 + u32 symrate; /* Check for >= this symrate */ 1035 + u32 delay; /* Timeout in ms */ 1036 + } symrates_delay_table[] = { 1037 + { SYS_DVBS, 10000000, 400 }, 1038 + { SYS_DVBS, 8000000, 2000 }, 1039 + { SYS_DVBS, 6000000, 5000 }, 1040 + { SYS_DVBS, 3000000, 10000 }, 1041 + { SYS_DVBS, 0, 15000 }, 1042 + { SYS_DVBS2, 10000000, 600 }, /* DVBS2 needs a little longer */ 1043 + { SYS_DVBS2, 8000000, 2000 }, /* (so these might need bumping too) */ 1044 + { SYS_DVBS2, 6000000, 5000 }, 1045 + { SYS_DVBS2, 3000000, 10000 }, 1046 + { SYS_DVBS2, 0, 15000 }, 1047 + }; 1048 + 1049 + 1050 + static int cx24120_set_frontend(struct dvb_frontend *fe) 1051 + { 1052 + struct dtv_frontend_properties *c = &fe->dtv_property_cache; 1053 + struct cx24120_state *state = fe->demodulator_priv; 1054 + struct cx24120_cmd cmd; 1055 + int ret; 1056 + int delay_cnt, sd_idx = 0; 1057 + fe_status_t status; 1058 + 1059 + switch (c->delivery_system) { 1060 + case SYS_DVBS2: 1061 + dev_dbg(&state->i2c->dev, "%s() DVB-S2\n", 1062 + __func__); 1063 + break; 1064 + case SYS_DVBS: 1065 + dev_dbg(&state->i2c->dev, "%s() DVB-S\n", 1066 + __func__); 1067 + break; 1068 + default: 1069 + dev_dbg(&state->i2c->dev, 1070 + "%s() Delivery system(%d) not supported\n", 1071 + __func__, c->delivery_system); 1072 + ret = -EINVAL; 1073 + break; 1074 + } 1075 + 1076 + 1077 + state->dnxt.delsys = c->delivery_system; 1078 + state->dnxt.modulation = c->modulation; 1079 + state->dnxt.frequency = c->frequency; 1080 + state->dnxt.pilot = c->pilot; 1081 + 1082 + ret = cx24120_set_inversion(state, c->inversion); 1083 + if (ret != 0) 1084 + return ret; 1085 + 1086 + ret = cx24120_set_fec(state, c->modulation, c->fec_inner); 1087 + if (ret != 0) 1088 + return ret; 1089 + 1090 + ret = cx24120_set_pilot(state, c->pilot); 1091 + if (ret != 0) 1092 + return ret; 1093 + 1094 + ret = cx24120_set_symbolrate(state, c->symbol_rate); 1095 + if (ret != 0) 1096 + return ret; 1097 + 1098 + 1099 + /* discard the 'current' tuning parameters and prepare to tune */ 1100 + cx24120_clone_params(fe); 1101 + 1102 + dev_dbg(&state->i2c->dev, 1103 + "%s: delsys = %d\n", __func__, state->dcur.delsys); 1104 + dev_dbg(&state->i2c->dev, 1105 + "%s: modulation = %d\n", __func__, state->dcur.modulation); 1106 + dev_dbg(&state->i2c->dev, 1107 + "%s: frequency = %d\n", __func__, state->dcur.frequency); 1108 + dev_dbg(&state->i2c->dev, 1109 + "%s: pilot = %d (val = 0x%02x)\n", __func__, 1110 + state->dcur.pilot, state->dcur.pilot_val); 1111 + dev_dbg(&state->i2c->dev, 1112 + "%s: symbol_rate = %d (clkdiv/ratediv = 0x%02x/0x%02x)\n", 1113 + __func__, state->dcur.symbol_rate, 1114 + state->dcur.clkdiv, state->dcur.ratediv); 1115 + dev_dbg(&state->i2c->dev, 1116 + "%s: FEC = %d (mask/val = 0x%02x/0x%02x)\n", __func__, 1117 + state->dcur.fec, state->dcur.fec_mask, state->dcur.fec_val); 1118 + dev_dbg(&state->i2c->dev, 1119 + "%s: Inversion = %d (val = 0x%02x)\n", __func__, 1120 + state->dcur.inversion, state->dcur.inversion_val); 1121 + 1122 + 1123 + 1124 + /* Tune in */ 1125 + cmd.id = CMD_TUNEREQUEST; 1126 + cmd.len = 15; 1127 + cmd.arg[0] = 0; 1128 + cmd.arg[1] = (state->dcur.frequency & 0xff0000) >> 16; 1129 + cmd.arg[2] = (state->dcur.frequency & 0x00ff00) >> 8; 1130 + cmd.arg[3] = (state->dcur.frequency & 0x0000ff); 1131 + cmd.arg[4] = ((state->dcur.symbol_rate/1000) & 0xff00) >> 8; 1132 + cmd.arg[5] = ((state->dcur.symbol_rate/1000) & 0x00ff); 1133 + cmd.arg[6] = state->dcur.inversion; 1134 + cmd.arg[7] = state->dcur.fec_val | state->dcur.pilot_val; 1135 + cmd.arg[8] = CX24120_SEARCH_RANGE_KHZ >> 8; 1136 + cmd.arg[9] = CX24120_SEARCH_RANGE_KHZ & 0xff; 1137 + cmd.arg[10] = 0; /* maybe rolloff? */ 1138 + cmd.arg[11] = state->dcur.fec_mask; 1139 + cmd.arg[12] = state->dcur.ratediv; 1140 + cmd.arg[13] = state->dcur.clkdiv; 1141 + cmd.arg[14] = 0; 1142 + 1143 + 1144 + /* Send tune command */ 1145 + ret = cx24120_message_send(state, &cmd); 1146 + if (ret != 0) 1147 + return ret; 1148 + 1149 + /* Write symbol rate values */ 1150 + ret = cx24120_writereg(state, CX24120_REG_CLKDIV, state->dcur.clkdiv); 1151 + ret = cx24120_readreg(state, CX24120_REG_RATEDIV); 1152 + ret &= 0xfffffff0; 1153 + ret |= state->dcur.ratediv; 1154 + ret = cx24120_writereg(state, CX24120_REG_RATEDIV, ret); 1155 + 1156 + /* Default time to tune */ 1157 + delay_cnt = 500; 1158 + 1159 + /* Establish time to tune from symrates_delay_table */ 1160 + for (sd_idx = 0; sd_idx < ARRAY_SIZE(symrates_delay_table); sd_idx++) { 1161 + if (state->dcur.delsys != symrates_delay_table[sd_idx].delsys) 1162 + continue; 1163 + if (c->symbol_rate < symrates_delay_table[sd_idx].symrate) 1164 + continue; 1165 + 1166 + /* found */ 1167 + delay_cnt = symrates_delay_table[sd_idx].delay; 1168 + dev_dbg(&state->i2c->dev, "%s: Found symrate delay = %d\n", 1169 + __func__, delay_cnt); 1170 + break; 1171 + } 1172 + 1173 + /* Wait for tuning */ 1174 + while (delay_cnt >= 0) { 1175 + cx24120_read_status(fe, &status); 1176 + if (status & FE_HAS_LOCK) 1177 + goto tuned; 1178 + msleep(20); 1179 + delay_cnt -= 20; 1180 + } 1181 + 1182 + 1183 + /* Fail to tune */ 1184 + dev_dbg(&state->i2c->dev, "%s: Tuning failed\n", 1185 + __func__); 1186 + 1187 + return -EINVAL; 1188 + 1189 + 1190 + tuned: 1191 + dev_dbg(&state->i2c->dev, "%s: Tuning successful\n", 1192 + __func__); 1193 + 1194 + /* Set clock ratios */ 1195 + cx24120_set_clock_ratios(fe); 1196 + 1197 + /* Old driver would do a msleep(200) here */ 1198 + 1199 + /* Renable mpeg output */ 1200 + if (!state->mpeg_enabled) 1201 + cx24120_msg_mpeg_output_global_config(state, 1); 1202 + 1203 + return 0; 1204 + } 1205 + 1206 + 1207 + /* Calculate vco from config */ 1208 + static u64 cx24120_calculate_vco(struct cx24120_state *state) 1209 + { 1210 + u32 vco; 1211 + u64 inv_vco, res, xxyyzz; 1212 + u32 xtal_khz = state->config->xtal_khz; 1213 + 1214 + xxyyzz = 0x400000000ULL; 1215 + vco = xtal_khz * 10 * 4; 1216 + inv_vco = xxyyzz / vco; 1217 + res = xxyyzz % vco; 1218 + 1219 + if (inv_vco > xtal_khz * 10 * 2) 1220 + ++inv_vco; 1221 + 1222 + dev_dbg(&state->i2c->dev, 1223 + "%s: xtal=%d, vco=%d, inv_vco=%lld, res=%lld\n", 1224 + __func__, xtal_khz, vco, inv_vco, res); 1225 + 1226 + return inv_vco; 1227 + } 1228 + 1229 + 1230 + int cx24120_init(struct dvb_frontend *fe) 1231 + { 1232 + const struct firmware *fw; 1233 + struct cx24120_state *state = fe->demodulator_priv; 1234 + struct cx24120_cmd cmd; 1235 + u8 ret, ret_EA, reg1; 1236 + u64 inv_vco; 1237 + int reset_result; 1238 + 1239 + int i; 1240 + unsigned char vers[4]; 1241 + 1242 + if (state->cold_init) 1243 + return 0; 1244 + 1245 + /* ???? */ 1246 + ret = cx24120_writereg(state, 0xea, 0x00); 1247 + ret = cx24120_test_rom(state); 1248 + ret = cx24120_readreg(state, 0xfb) & 0xfe; 1249 + ret = cx24120_writereg(state, 0xfb, ret); 1250 + ret = cx24120_readreg(state, 0xfc) & 0xfe; 1251 + ret = cx24120_writereg(state, 0xfc, ret); 1252 + ret = cx24120_writereg(state, 0xc3, 0x04); 1253 + ret = cx24120_writereg(state, 0xc4, 0x04); 1254 + ret = cx24120_writereg(state, 0xce, 0x00); 1255 + ret = cx24120_writereg(state, 0xcf, 0x00); 1256 + ret_EA = cx24120_readreg(state, 0xea) & 0xfe; 1257 + ret = cx24120_writereg(state, 0xea, ret_EA); 1258 + ret = cx24120_writereg(state, 0xeb, 0x0c); 1259 + ret = cx24120_writereg(state, 0xec, 0x06); 1260 + ret = cx24120_writereg(state, 0xed, 0x05); 1261 + ret = cx24120_writereg(state, 0xee, 0x03); 1262 + ret = cx24120_writereg(state, 0xef, 0x05); 1263 + ret = cx24120_writereg(state, 0xf3, 0x03); 1264 + ret = cx24120_writereg(state, 0xf4, 0x44); 1265 + 1266 + for (reg1 = 0xf0; reg1 < 0xf3; reg1++) { 1267 + cx24120_writereg(state, reg1, 0x04); 1268 + cx24120_writereg(state, reg1 - 10, 0x02); 1269 + } 1270 + 1271 + ret = cx24120_writereg(state, 0xea, (ret_EA | 0x01)); 1272 + for (reg1 = 0xc5; reg1 < 0xcb; reg1 += 2) { 1273 + ret = cx24120_writereg(state, reg1, 0x00); 1274 + ret = cx24120_writereg(state, reg1 + 1, 0x00); 1275 + } 1276 + 1277 + ret = cx24120_writereg(state, 0xe4, 0x03); 1278 + ret = cx24120_writereg(state, 0xeb, 0x0a); 1279 + 1280 + dev_dbg(&state->i2c->dev, 1281 + "%s: Requesting firmware (%s) to download...\n", 1282 + __func__, CX24120_FIRMWARE); 1283 + 1284 + ret = state->config->request_firmware(fe, &fw, CX24120_FIRMWARE); 1285 + if (ret) { 1286 + err("Could not load firmware (%s): %d\n", 1287 + CX24120_FIRMWARE, ret); 1288 + return ret; 1289 + } 1290 + 1291 + dev_dbg(&state->i2c->dev, 1292 + "%s: Firmware found, size %d bytes (%02x %02x .. %02x %02x)\n", 1293 + __func__, 1294 + (int)fw->size, /* firmware_size in bytes */ 1295 + fw->data[0], /* fw 1st byte */ 1296 + fw->data[1], /* fw 2d byte */ 1297 + fw->data[fw->size - 2], /* fw before last byte */ 1298 + fw->data[fw->size - 1]); /* fw last byte */ 1299 + 1300 + ret = cx24120_test_rom(state); 1301 + ret = cx24120_readreg(state, 0xfb) & 0xfe; 1302 + ret = cx24120_writereg(state, 0xfb, ret); 1303 + ret = cx24120_writereg(state, 0xe0, 0x76); 1304 + ret = cx24120_writereg(state, 0xf7, 0x81); 1305 + ret = cx24120_writereg(state, 0xf8, 0x00); 1306 + ret = cx24120_writereg(state, 0xf9, 0x00); 1307 + ret = cx24120_writeregN(state, 0xfa, fw->data, (fw->size - 1), 0x00); 1308 + ret = cx24120_writereg(state, 0xf7, 0xc0); 1309 + ret = cx24120_writereg(state, 0xe0, 0x00); 1310 + ret = (fw->size - 2) & 0x00ff; 1311 + ret = cx24120_writereg(state, 0xf8, ret); 1312 + ret = ((fw->size - 2) >> 8) & 0x00ff; 1313 + ret = cx24120_writereg(state, 0xf9, ret); 1314 + ret = cx24120_writereg(state, 0xf7, 0x00); 1315 + ret = cx24120_writereg(state, 0xdc, 0x00); 1316 + ret = cx24120_writereg(state, 0xdc, 0x07); 1317 + msleep(500); 1318 + 1319 + /* Check final byte matches final byte of firmware */ 1320 + ret = cx24120_readreg(state, 0xe1); 1321 + if (ret == fw->data[fw->size - 1]) { 1322 + dev_dbg(&state->i2c->dev, 1323 + "%s: Firmware uploaded successfully\n", 1324 + __func__); 1325 + reset_result = 0; 1326 + } else { 1327 + err("Firmware upload failed. Last byte returned=0x%x\n", ret); 1328 + reset_result = -EREMOTEIO; 1329 + } 1330 + ret = cx24120_writereg(state, 0xdc, 0x00); 1331 + release_firmware(fw); 1332 + if (reset_result != 0) 1333 + return reset_result; 1334 + 1335 + 1336 + /* Start tuner */ 1337 + cmd.id = CMD_START_TUNER; 1338 + cmd.len = 3; 1339 + cmd.arg[0] = 0x00; 1340 + cmd.arg[1] = 0x00; 1341 + cmd.arg[2] = 0x00; 1342 + 1343 + if (cx24120_message_send(state, &cmd) != 0) { 1344 + err("Error tuner start! :(\n"); 1345 + return -EREMOTEIO; 1346 + } 1347 + 1348 + /* Set VCO */ 1349 + inv_vco = cx24120_calculate_vco(state); 1350 + 1351 + cmd.id = CMD_VCO_SET; 1352 + cmd.len = 12; 1353 + cmd.arg[0] = 0x06; 1354 + cmd.arg[1] = 0x2b; 1355 + cmd.arg[2] = 0xd8; 1356 + cmd.arg[3] = (inv_vco >> 8) & 0xff; 1357 + cmd.arg[4] = (inv_vco) & 0xff; 1358 + cmd.arg[5] = 0x03; 1359 + cmd.arg[6] = 0x9d; 1360 + cmd.arg[7] = 0xfc; 1361 + cmd.arg[8] = 0x06; 1362 + cmd.arg[9] = 0x03; 1363 + cmd.arg[10] = 0x27; 1364 + cmd.arg[11] = 0x7f; 1365 + 1366 + if (cx24120_message_send(state, &cmd)) { 1367 + err("Error set VCO! :(\n"); 1368 + return -EREMOTEIO; 1369 + } 1370 + 1371 + 1372 + /* set bandwidth */ 1373 + cmd.id = CMD_BANDWIDTH; 1374 + cmd.len = 12; 1375 + cmd.arg[0] = 0x00; 1376 + cmd.arg[1] = 0x00; 1377 + cmd.arg[2] = 0x00; 1378 + cmd.arg[3] = 0x00; 1379 + cmd.arg[4] = 0x05; 1380 + cmd.arg[5] = 0x02; 1381 + cmd.arg[6] = 0x02; 1382 + cmd.arg[7] = 0x00; 1383 + cmd.arg[8] = 0x05; 1384 + cmd.arg[9] = 0x02; 1385 + cmd.arg[10] = 0x02; 1386 + cmd.arg[11] = 0x00; 1387 + 1388 + if (cx24120_message_send(state, &cmd)) { 1389 + err("Error set bandwidth!\n"); 1390 + return -EREMOTEIO; 1391 + } 1392 + 1393 + ret = cx24120_readreg(state, 0xba); 1394 + if (ret > 3) { 1395 + dev_dbg(&state->i2c->dev, "%s: Reset-readreg 0xba: %x\n", 1396 + __func__, ret); 1397 + err("Error initialising tuner!\n"); 1398 + return -EREMOTEIO; 1399 + } 1400 + 1401 + dev_dbg(&state->i2c->dev, "%s: Tuner initialised correctly.\n", 1402 + __func__); 1403 + 1404 + 1405 + /* Initialise mpeg outputs */ 1406 + ret = cx24120_writereg(state, 0xeb, 0x0a); 1407 + if (cx24120_msg_mpeg_output_global_config(state, 0) || 1408 + cx24120_msg_mpeg_output_config(state, 0) || 1409 + cx24120_msg_mpeg_output_config(state, 1) || 1410 + cx24120_msg_mpeg_output_config(state, 2)) { 1411 + err("Error initialising mpeg output. :(\n"); 1412 + return -EREMOTEIO; 1413 + } 1414 + 1415 + 1416 + /* ???? */ 1417 + cmd.id = CMD_TUNER_INIT; 1418 + cmd.len = 3; 1419 + cmd.arg[0] = 0x00; 1420 + cmd.arg[1] = 0x10; 1421 + cmd.arg[2] = 0x10; 1422 + if (cx24120_message_send(state, &cmd)) { 1423 + err("Error sending final init message. :(\n"); 1424 + return -EREMOTEIO; 1425 + } 1426 + 1427 + 1428 + /* Firmware CMD 35: Get firmware version */ 1429 + cmd.id = CMD_FWVERSION; 1430 + cmd.len = 1; 1431 + for (i = 0; i < 4; i++) { 1432 + cmd.arg[0] = i; 1433 + ret = cx24120_message_send(state, &cmd); 1434 + if (ret != 0) 1435 + return ret; 1436 + vers[i] = cx24120_readreg(state, CX24120_REG_MAILBOX); 1437 + } 1438 + info("FW version %i.%i.%i.%i\n", vers[0], vers[1], vers[2], vers[3]); 1439 + 1440 + 1441 + state->cold_init = 1; 1442 + return 0; 1443 + } 1444 + 1445 + 1446 + static int cx24120_tune(struct dvb_frontend *fe, bool re_tune, 1447 + unsigned int mode_flags, unsigned int *delay, fe_status_t *status) 1448 + { 1449 + struct cx24120_state *state = fe->demodulator_priv; 1450 + int ret; 1451 + 1452 + dev_dbg(&state->i2c->dev, "%s(%d)\n", __func__, re_tune); 1453 + 1454 + /* TODO: Do we need to set delay? */ 1455 + 1456 + if (re_tune) { 1457 + ret = cx24120_set_frontend(fe); 1458 + if (ret) 1459 + return ret; 1460 + } 1461 + 1462 + return cx24120_read_status(fe, status); 1463 + } 1464 + 1465 + 1466 + 1467 + static int cx24120_get_algo(struct dvb_frontend *fe) 1468 + { 1469 + return DVBFE_ALGO_HW; 1470 + } 1471 + 1472 + 1473 + static int cx24120_sleep(struct dvb_frontend *fe) 1474 + { 1475 + return 0; 1476 + } 1477 + 1478 + 1479 + /*static int cx24120_wakeup(struct dvb_frontend *fe) 1480 + * { 1481 + * return 0; 1482 + * } 1483 + */ 1484 + 1485 + 1486 + static int cx24120_get_frontend(struct dvb_frontend *fe) 1487 + { 1488 + struct dtv_frontend_properties *c = &fe->dtv_property_cache; 1489 + struct cx24120_state *state = fe->demodulator_priv; 1490 + u8 freq1, freq2, freq3; 1491 + 1492 + dev_dbg(&state->i2c->dev, "%s()", __func__); 1493 + 1494 + /* don't return empty data if we're not tuned in */ 1495 + if (state->mpeg_enabled) 1496 + return 0; 1497 + 1498 + /* Get frequency */ 1499 + freq1 = cx24120_readreg(state, CX24120_REG_FREQ1); 1500 + freq2 = cx24120_readreg(state, CX24120_REG_FREQ2); 1501 + freq3 = cx24120_readreg(state, CX24120_REG_FREQ3); 1502 + c->frequency = (freq3 << 16) | (freq2 << 8) | freq1; 1503 + dev_dbg(&state->i2c->dev, "%s frequency = %d\n", __func__, 1504 + c->frequency); 1505 + 1506 + /* Get modulation, fec, pilot */ 1507 + cx24120_get_fec(fe); 1508 + 1509 + return 0; 1510 + } 1511 + 1512 + 1513 + static void cx24120_release(struct dvb_frontend *fe) 1514 + { 1515 + struct cx24120_state *state = fe->demodulator_priv; 1516 + 1517 + dev_dbg(&state->i2c->dev, "%s: Clear state structure\n", __func__); 1518 + kfree(state); 1519 + } 1520 + 1521 + 1522 + static int cx24120_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) 1523 + { 1524 + struct cx24120_state *state = fe->demodulator_priv; 1525 + 1526 + *ucblocks = (cx24120_readreg(state, CX24120_REG_UCB_H) << 8) | 1527 + cx24120_readreg(state, CX24120_REG_UCB_L); 1528 + 1529 + dev_dbg(&state->i2c->dev, "%s: Blocks = %d\n", 1530 + __func__, *ucblocks); 1531 + return 0; 1532 + } 1533 + 1534 + 1535 + static struct dvb_frontend_ops cx24120_ops = { 1536 + .delsys = { SYS_DVBS, SYS_DVBS2 }, 1537 + .info = { 1538 + .name = "Conexant CX24120/CX24118", 1539 + .frequency_min = 950000, 1540 + .frequency_max = 2150000, 1541 + .frequency_stepsize = 1011, /* kHz for QPSK frontends */ 1542 + .frequency_tolerance = 5000, 1543 + .symbol_rate_min = 1000000, 1544 + .symbol_rate_max = 45000000, 1545 + .caps = FE_CAN_INVERSION_AUTO | 1546 + FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | 1547 + FE_CAN_FEC_4_5 | FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 | 1548 + FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO | 1549 + FE_CAN_2G_MODULATION | 1550 + FE_CAN_QPSK | FE_CAN_RECOVER 1551 + }, 1552 + .release = cx24120_release, 1553 + 1554 + .init = cx24120_init, 1555 + .sleep = cx24120_sleep, 1556 + 1557 + .tune = cx24120_tune, 1558 + .get_frontend_algo = cx24120_get_algo, 1559 + .set_frontend = cx24120_set_frontend, 1560 + 1561 + .get_frontend = cx24120_get_frontend, 1562 + .read_status = cx24120_read_status, 1563 + .read_ber = cx24120_read_ber, 1564 + .read_signal_strength = cx24120_read_signal_strength, 1565 + .read_snr = cx24120_read_snr, 1566 + .read_ucblocks = cx24120_read_ucblocks, 1567 + 1568 + .diseqc_send_master_cmd = cx24120_send_diseqc_msg, 1569 + 1570 + .diseqc_send_burst = cx24120_diseqc_send_burst, 1571 + .set_tone = cx24120_set_tone, 1572 + .set_voltage = cx24120_set_voltage, 1573 + }; 1574 + 1575 + MODULE_DESCRIPTION("DVB Frontend module for Conexant CX24120/CX24118 hardware"); 1576 + MODULE_AUTHOR("Jemma Denson"); 1577 + MODULE_LICENSE("GPL");
+56
drivers/media/dvb-frontends/cx24120.h
··· 1 + /* 2 + * Conexant CX24120/CX24118 - DVB-S/S2 demod/tuner driver 3 + * 4 + * Copyright (C) 2008 Patrick Boettcher <pb@linuxtv.org> 5 + * Copyright (C) 2009 Sergey Tyurin <forum.free-x.de> 6 + * Updated 2012 by Jannis Achstetter <jannis_achstetter@web.de> 7 + * Copyright (C) 2015 Jemma Denson <jdenson@gmail.com> 8 + * 9 + * This program is free software; you can redistribute it and/or modify 10 + * it under the terms of the GNU General Public License as published by 11 + * the Free Software Foundation; either version 2 of the License, or 12 + * (at your option) any later version. 13 + * 14 + * This program is distributed in the hope that it will be useful, 15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 + * GNU General Public License for more details. 18 + */ 19 + 20 + #ifndef CX24120_H 21 + #define CX24120_H 22 + 23 + #include <linux/kconfig.h> 24 + #include <linux/dvb/frontend.h> 25 + #include <linux/firmware.h> 26 + 27 + struct cx24120_initial_mpeg_config { 28 + u8 x1; 29 + u8 x2; 30 + u8 x3; 31 + }; 32 + 33 + struct cx24120_config { 34 + u8 i2c_addr; 35 + u32 xtal_khz; 36 + struct cx24120_initial_mpeg_config initial_mpeg_config; 37 + 38 + int (*request_firmware)(struct dvb_frontend *fe, 39 + const struct firmware **fw, char *name); 40 + }; 41 + 42 + #if IS_REACHABLE(CONFIG_DVB_CX24120) 43 + extern struct dvb_frontend *cx24120_attach( 44 + const struct cx24120_config *config, 45 + struct i2c_adapter *i2c); 46 + #else 47 + static inline struct dvb_frontend *cx24120_attach( 48 + const struct cx24120_config *config, 49 + struct i2c_adapter *i2c) 50 + { 51 + printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 52 + return NULL; 53 + } 54 + #endif 55 + 56 + #endif /* CX24120_H */