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

[media] af9035: move device configuration to the state

Fixes most problems when having more than one device connected
as demod and tuner configurations are not shared.

Signed-off-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Antti Palosaari and committed by
Mauro Carvalho Chehab
2a79eefa 47eafa54

+40 -31
+32 -30
drivers/media/dvb/dvb-usb/af9035.c
··· 20 20 */ 21 21 22 22 #include "af9035.h" 23 - #include "af9033.h" 24 - #include "tua9001.h" 25 - #include "fc0011.h" 26 - #include "mxl5007t.h" 27 - #include "tda18218.h" 28 23 29 24 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 30 25 static DEFINE_MUTEX(af9035_usb_mutex); 31 - static struct config af9035_config; 32 26 static struct dvb_usb_device_properties af9035_properties[2]; 33 27 static int af9035_properties_count = ARRAY_SIZE(af9035_properties); 34 - static struct af9033_config af9035_af9033_config[] = { 35 - { 36 - .ts_mode = AF9033_TS_MODE_USB, 37 - }, { 38 - .ts_mode = AF9033_TS_MODE_SERIAL, 39 - } 40 - }; 41 28 42 29 static u16 af9035_checksum(const u8 *buf, size_t len) 43 30 { ··· 205 218 struct i2c_msg msg[], int num) 206 219 { 207 220 struct dvb_usb_device *d = i2c_get_adapdata(adap); 221 + struct state *state = d->priv; 208 222 int ret; 209 223 210 224 if (mutex_lock_interruptible(&d->i2c_mutex) < 0) ··· 232 244 if (msg[0].len > 40 || msg[1].len > 40) { 233 245 /* TODO: correct limits > 40 */ 234 246 ret = -EOPNOTSUPP; 235 - } else if (msg[0].addr == af9035_af9033_config[0].i2c_addr) { 247 + } else if (msg[0].addr == state->af9033_config[0].i2c_addr) { 236 248 /* integrated demod */ 237 249 u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 | 238 250 msg[0].buf[2]; ··· 255 267 if (msg[0].len > 40) { 256 268 /* TODO: correct limits > 40 */ 257 269 ret = -EOPNOTSUPP; 258 - } else if (msg[0].addr == af9035_af9033_config[0].i2c_addr) { 270 + } else if (msg[0].addr == state->af9033_config[0].i2c_addr) { 259 271 /* integrated demod */ 260 272 u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 | 261 273 msg[0].buf[2]; ··· 334 346 335 347 static int af9035_init(struct dvb_usb_device *d) 336 348 { 349 + struct state *state = d->priv; 337 350 int ret, i; 338 351 u16 frame_size = 87 * 188 / 4; 339 352 u8 packet_size = 512 / 4; ··· 349 360 { 0x00dd88, (frame_size >> 0) & 0xff, 0xff}, 350 361 { 0x00dd89, (frame_size >> 8) & 0xff, 0xff}, 351 362 { 0x00dd0c, packet_size, 0xff}, 352 - { 0x00dd11, af9035_config.dual_mode << 6, 0x40 }, 363 + { 0x00dd11, state->dual_mode << 6, 0x40 }, 353 364 { 0x00dd8a, (frame_size >> 0) & 0xff, 0xff}, 354 365 { 0x00dd8b, (frame_size >> 8) & 0xff, 0xff}, 355 366 { 0x00dd0d, packet_size, 0xff }, ··· 585 596 /* abuse that callback as there is no better one for reading eeprom */ 586 597 static int af9035_read_mac_address(struct dvb_usb_device *d, u8 mac[6]) 587 598 { 599 + struct state *state = d->priv; 588 600 int ret, i, eeprom_shift = 0; 589 601 u8 tmp; 590 602 u16 tmp16; ··· 595 605 if (ret < 0) 596 606 goto err; 597 607 598 - af9035_config.dual_mode = tmp; 599 - pr_debug("%s: dual mode=%d\n", __func__, af9035_config.dual_mode); 608 + state->dual_mode = tmp; 609 + pr_debug("%s: dual mode=%d\n", __func__, state->dual_mode); 600 610 601 611 for (i = 0; i < af9035_properties[0].num_adapters; i++) { 602 612 /* tuner */ ··· 604 614 if (ret < 0) 605 615 goto err; 606 616 607 - af9035_af9033_config[i].tuner = tmp; 617 + state->af9033_config[i].tuner = tmp; 608 618 pr_debug("%s: [%d]tuner=%02x\n", __func__, i, tmp); 609 619 610 620 switch (tmp) { ··· 612 622 case AF9033_TUNER_FC0011: 613 623 case AF9033_TUNER_MXL5007T: 614 624 case AF9033_TUNER_TDA18218: 615 - af9035_af9033_config[i].spec_inv = 1; 625 + state->af9033_config[i].spec_inv = 1; 616 626 break; 617 627 default: 618 - af9035_config.hw_not_supported = true; 628 + state->hw_not_supported = true; 619 629 warn("tuner ID=%02x not supported, please report!", 620 630 tmp); 621 631 }; ··· 646 656 tmp = (tmp >> 0) & 0x0f; 647 657 648 658 for (i = 0; i < af9035_properties[0].num_adapters; i++) 649 - af9035_af9033_config[i].clock = clock_lut[tmp]; 659 + state->af9033_config[i].clock = clock_lut[tmp]; 650 660 651 661 ret = af9035_rd_reg(d, EEPROM_IR_MODE, &tmp); 652 662 if (ret < 0) ··· 685 695 /* abuse that callback as there is no better one for reading eeprom */ 686 696 static int af9035_read_mac_address_it9135(struct dvb_usb_device *d, u8 mac[6]) 687 697 { 698 + struct state *state = d->priv; 688 699 int ret, i; 689 700 u8 tmp; 690 701 691 - af9035_config.dual_mode = 0; 702 + state->dual_mode = false; 692 703 693 704 /* get demod clock */ 694 705 ret = af9035_rd_reg(d, 0x00d800, &tmp); ··· 699 708 tmp = (tmp >> 0) & 0x0f; 700 709 701 710 for (i = 0; i < af9035_properties[0].num_adapters; i++) 702 - af9035_af9033_config[i].clock = clock_lut_it9135[tmp]; 711 + state->af9033_config[i].clock = clock_lut_it9135[tmp]; 703 712 704 713 return 0; 705 714 ··· 776 785 777 786 static int af9035_tuner_callback(struct dvb_usb_device *d, int cmd, int arg) 778 787 { 779 - switch (af9035_af9033_config[0].tuner) { 788 + struct state *state = d->priv; 789 + 790 + switch (state->af9033_config[0].tuner) { 780 791 case AF9033_TUNER_FC0011: 781 792 return af9035_fc0011_tuner_callback(d, cmd, arg); 782 793 default: ··· 806 813 807 814 static int af9035_frontend_attach(struct dvb_usb_adapter *adap) 808 815 { 816 + struct state *state = adap->dev->priv; 809 817 int ret; 810 818 811 - if (af9035_config.hw_not_supported) { 819 + if (state->hw_not_supported) { 812 820 ret = -ENODEV; 813 821 goto err; 814 822 } 815 823 816 824 if (adap->id == 0) { 825 + state->af9033_config[0].ts_mode = AF9033_TS_MODE_USB; 826 + state->af9033_config[1].ts_mode = AF9033_TS_MODE_SERIAL; 827 + 817 828 ret = af9035_wr_reg(adap->dev, 0x00417f, 818 - af9035_af9033_config[1].i2c_addr); 829 + state->af9033_config[1].i2c_addr); 819 830 if (ret < 0) 820 831 goto err; 821 832 822 833 ret = af9035_wr_reg(adap->dev, 0x00d81a, 823 - af9035_config.dual_mode); 834 + state->dual_mode); 824 835 if (ret < 0) 825 836 goto err; 826 837 } 827 838 828 839 /* attach demodulator */ 829 840 adap->fe_adap[0].fe = dvb_attach(af9033_attach, 830 - &af9035_af9033_config[adap->id], &adap->dev->i2c_adap); 841 + &state->af9033_config[adap->id], &adap->dev->i2c_adap); 831 842 if (adap->fe_adap[0].fe == NULL) { 832 843 ret = -ENODEV; 833 844 goto err; ··· 873 876 874 877 static int af9035_tuner_attach(struct dvb_usb_adapter *adap) 875 878 { 879 + struct state *state = adap->dev->priv; 876 880 int ret; 877 881 struct dvb_frontend *fe; 878 882 879 - switch (af9035_af9033_config[adap->id].tuner) { 883 + switch (state->af9033_config[adap->id].tuner) { 880 884 case AF9033_TUNER_TUA9001: 881 885 /* AF9035 gpiot3 = TUA9001 RESETN 882 886 AF9035 gpiot2 = TUA9001 RXEN */ ··· 1030 1032 .firmware = "dvb-usb-af9035-02.fw", 1031 1033 .no_reconnect = 1, 1032 1034 1035 + .size_of_priv = sizeof(struct state), 1036 + 1033 1037 .num_adapters = 1, 1034 1038 .adapter = { 1035 1039 { ··· 1108 1108 .download_firmware = af9035_download_firmware_it9135, 1109 1109 .firmware = "dvb-usb-it9135-01.fw", 1110 1110 .no_reconnect = 1, 1111 + 1112 + .size_of_priv = sizeof(struct state), 1111 1113 1112 1114 .num_adapters = 1, 1113 1115 .adapter = {
+8 -1
drivers/media/dvb/dvb-usb/af9035.h
··· 26 26 #define DVB_USB_LOG_PREFIX "af9035" 27 27 28 28 #include "dvb-usb.h" 29 + #include "af9033.h" 30 + #include "tua9001.h" 31 + #include "fc0011.h" 32 + #include "mxl5007t.h" 33 + #include "tda18218.h" 29 34 30 35 struct reg_val { 31 36 u32 reg; ··· 52 47 u8 *rbuf; 53 48 }; 54 49 55 - struct config { 50 + struct state { 56 51 bool dual_mode; 57 52 bool hw_not_supported; 53 + 54 + struct af9033_config af9033_config[2]; 58 55 }; 59 56 60 57 u32 clock_lut[] = {