aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/dvb-usb/af9015.c
diff options
context:
space:
mode:
authorAntti Palosaari <crope@iki.fi>2011-11-28 18:58:11 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-12-30 12:31:33 -0500
commitf571e004c396c2ed8c2ba6bfc8a229b6bd5ab724 (patch)
tree7c5559319e97d66212ac1cf0ac5281bed75a8cdc /drivers/media/dvb/dvb-usb/af9015.c
parente90ab840fb826621c8c01cc9e70ca3f0889fa416 (diff)
[media] af9013: rewrite whole driver
Rewrite whole af9013 demod driver in order to decrease I2C I/O. We need to decrease I2C load since AF9015 (I2C adapter / USB-bridge used) seems to have some problems under heavy I2C traffic. Signed-off-by: Antti Palosaari <crope@iki.fi> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/dvb/dvb-usb/af9015.c')
-rw-r--r--drivers/media/dvb/dvb-usb/af9015.c82
1 files changed, 42 insertions, 40 deletions
diff --git a/drivers/media/dvb/dvb-usb/af9015.c b/drivers/media/dvb/dvb-usb/af9015.c
index 033aa8affd8e..7b606b7834b3 100644
--- a/drivers/media/dvb/dvb-usb/af9015.c
+++ b/drivers/media/dvb/dvb-usb/af9015.c
@@ -50,14 +50,14 @@ static int af9015_properties_count = ARRAY_SIZE(af9015_properties);
50 50
51static struct af9013_config af9015_af9013_config[] = { 51static struct af9013_config af9015_af9013_config[] = {
52 { 52 {
53 .demod_address = AF9015_I2C_DEMOD, 53 .i2c_addr = AF9015_I2C_DEMOD,
54 .output_mode = AF9013_OUTPUT_MODE_USB, 54 .ts_mode = AF9013_TS_USB,
55 .api_version = { 0, 1, 9, 0 }, 55 .api_version = { 0, 1, 9, 0 },
56 .gpio[0] = AF9013_GPIO_HI, 56 .gpio[0] = AF9013_GPIO_HI,
57 .gpio[3] = AF9013_GPIO_TUNER_ON, 57 .gpio[3] = AF9013_GPIO_TUNER_ON,
58 58
59 }, { 59 }, {
60 .output_mode = AF9013_OUTPUT_MODE_SERIAL, 60 .ts_mode = AF9013_TS_SERIAL,
61 .api_version = { 0, 1, 9, 0 }, 61 .api_version = { 0, 1, 9, 0 },
62 .gpio[0] = AF9013_GPIO_TUNER_ON, 62 .gpio[0] = AF9013_GPIO_TUNER_ON,
63 .gpio[1] = AF9013_GPIO_LO, 63 .gpio[1] = AF9013_GPIO_LO,
@@ -216,8 +216,8 @@ static int af9015_write_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg,
216{ 216{
217 struct req_t req = {WRITE_I2C, addr, reg, 1, 1, 1, &val}; 217 struct req_t req = {WRITE_I2C, addr, reg, 1, 1, 1, &val};
218 218
219 if (addr == af9015_af9013_config[0].demod_address || 219 if (addr == af9015_af9013_config[0].i2c_addr ||
220 addr == af9015_af9013_config[1].demod_address) 220 addr == af9015_af9013_config[1].i2c_addr)
221 req.addr_len = 3; 221 req.addr_len = 3;
222 222
223 return af9015_ctrl_msg(d, &req); 223 return af9015_ctrl_msg(d, &req);
@@ -228,8 +228,8 @@ static int af9015_read_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg,
228{ 228{
229 struct req_t req = {READ_I2C, addr, reg, 0, 1, 1, val}; 229 struct req_t req = {READ_I2C, addr, reg, 0, 1, 1, val};
230 230
231 if (addr == af9015_af9013_config[0].demod_address || 231 if (addr == af9015_af9013_config[0].i2c_addr ||
232 addr == af9015_af9013_config[1].demod_address) 232 addr == af9015_af9013_config[1].i2c_addr)
233 req.addr_len = 3; 233 req.addr_len = 3;
234 234
235 return af9015_ctrl_msg(d, &req); 235 return af9015_ctrl_msg(d, &req);
@@ -271,8 +271,8 @@ Due to that the only way to select correct tuner is use demodulator I2C-gate.
271 return -EAGAIN; 271 return -EAGAIN;
272 272
273 while (i < num) { 273 while (i < num) {
274 if (msg[i].addr == af9015_af9013_config[0].demod_address || 274 if (msg[i].addr == af9015_af9013_config[0].i2c_addr ||
275 msg[i].addr == af9015_af9013_config[1].demod_address) { 275 msg[i].addr == af9015_af9013_config[1].i2c_addr) {
276 addr = msg[i].buf[0] << 8; 276 addr = msg[i].buf[0] << 8;
277 addr += msg[i].buf[1]; 277 addr += msg[i].buf[1];
278 mbox = msg[i].buf[2]; 278 mbox = msg[i].buf[2];
@@ -288,8 +288,7 @@ Due to that the only way to select correct tuner is use demodulator I2C-gate.
288 ret = -EOPNOTSUPP; 288 ret = -EOPNOTSUPP;
289 goto error; 289 goto error;
290 } 290 }
291 if (msg[i].addr == 291 if (msg[i].addr == af9015_af9013_config[0].i2c_addr)
292 af9015_af9013_config[0].demod_address)
293 req.cmd = READ_MEMORY; 292 req.cmd = READ_MEMORY;
294 else 293 else
295 req.cmd = READ_I2C; 294 req.cmd = READ_I2C;
@@ -307,7 +306,7 @@ Due to that the only way to select correct tuner is use demodulator I2C-gate.
307 goto error; 306 goto error;
308 } 307 }
309 if (msg[i].addr == 308 if (msg[i].addr ==
310 af9015_af9013_config[0].demod_address) { 309 af9015_af9013_config[0].i2c_addr) {
311 ret = -EINVAL; 310 ret = -EINVAL;
312 goto error; 311 goto error;
313 } 312 }
@@ -325,8 +324,7 @@ Due to that the only way to select correct tuner is use demodulator I2C-gate.
325 ret = -EOPNOTSUPP; 324 ret = -EOPNOTSUPP;
326 goto error; 325 goto error;
327 } 326 }
328 if (msg[i].addr == 327 if (msg[i].addr == af9015_af9013_config[0].i2c_addr)
329 af9015_af9013_config[0].demod_address)
330 req.cmd = WRITE_MEMORY; 328 req.cmd = WRITE_MEMORY;
331 else 329 else
332 req.cmd = WRITE_I2C; 330 req.cmd = WRITE_I2C;
@@ -508,7 +506,7 @@ static int af9015_copy_firmware(struct dvb_usb_device *d)
508 msleep(100); 506 msleep(100);
509 507
510 ret = af9015_read_reg_i2c(d, 508 ret = af9015_read_reg_i2c(d,
511 af9015_af9013_config[1].demod_address, 0x98be, &val); 509 af9015_af9013_config[1].i2c_addr, 0x98be, &val);
512 if (ret) 510 if (ret)
513 goto error; 511 goto error;
514 else 512 else
@@ -536,7 +534,7 @@ static int af9015_copy_firmware(struct dvb_usb_device *d)
536 goto error; 534 goto error;
537 535
538 /* request boot firmware */ 536 /* request boot firmware */
539 ret = af9015_write_reg_i2c(d, af9015_af9013_config[1].demod_address, 537 ret = af9015_write_reg_i2c(d, af9015_af9013_config[1].i2c_addr,
540 0xe205, 1); 538 0xe205, 1);
541 deb_info("%s: firmware boot cmd status:%d\n", __func__, ret); 539 deb_info("%s: firmware boot cmd status:%d\n", __func__, ret);
542 if (ret) 540 if (ret)
@@ -547,7 +545,7 @@ static int af9015_copy_firmware(struct dvb_usb_device *d)
547 545
548 /* check firmware status */ 546 /* check firmware status */
549 ret = af9015_read_reg_i2c(d, 547 ret = af9015_read_reg_i2c(d,
550 af9015_af9013_config[1].demod_address, 0x98be, &val); 548 af9015_af9013_config[1].i2c_addr, 0x98be, &val);
551 deb_info("%s: firmware status cmd status:%d fw status:%02x\n", 549 deb_info("%s: firmware status cmd status:%d fw status:%02x\n",
552 __func__, ret, val); 550 __func__, ret, val);
553 if (ret) 551 if (ret)
@@ -840,7 +838,7 @@ static int af9015_read_config(struct usb_device *udev)
840 if (ret) 838 if (ret)
841 goto error; 839 goto error;
842 840
843 deb_info("%s: IR mode:%d\n", __func__, val); 841 deb_info("%s: IR mode=%d\n", __func__, val);
844 for (i = 0; i < af9015_properties_count; i++) { 842 for (i = 0; i < af9015_properties_count; i++) {
845 if (val == AF9015_IR_MODE_DISABLED) 843 if (val == AF9015_IR_MODE_DISABLED)
846 af9015_properties[i].rc.core.rc_codes = NULL; 844 af9015_properties[i].rc.core.rc_codes = NULL;
@@ -854,7 +852,7 @@ static int af9015_read_config(struct usb_device *udev)
854 if (ret) 852 if (ret)
855 goto error; 853 goto error;
856 af9015_config.dual_mode = val; 854 af9015_config.dual_mode = val;
857 deb_info("%s: TS mode:%d\n", __func__, af9015_config.dual_mode); 855 deb_info("%s: TS mode=%d\n", __func__, af9015_config.dual_mode);
858 856
859 /* Set adapter0 buffer size according to USB port speed, adapter1 buffer 857 /* Set adapter0 buffer size according to USB port speed, adapter1 buffer
860 size can be static because it is enabled only USB2.0 */ 858 size can be static because it is enabled only USB2.0 */
@@ -878,7 +876,7 @@ static int af9015_read_config(struct usb_device *udev)
878 ret = af9015_rw_udev(udev, &req); 876 ret = af9015_rw_udev(udev, &req);
879 if (ret) 877 if (ret)
880 goto error; 878 goto error;
881 af9015_af9013_config[1].demod_address = val; 879 af9015_af9013_config[1].i2c_addr = val;
882 880
883 /* enable 2nd adapter */ 881 /* enable 2nd adapter */
884 for (i = 0; i < af9015_properties_count; i++) 882 for (i = 0; i < af9015_properties_count; i++)
@@ -900,34 +898,38 @@ static int af9015_read_config(struct usb_device *udev)
900 goto error; 898 goto error;
901 switch (val) { 899 switch (val) {
902 case 0: 900 case 0:
903 af9015_af9013_config[i].adc_clock = 28800; 901 af9015_af9013_config[i].clock = 28800000;
904 break; 902 break;
905 case 1: 903 case 1:
906 af9015_af9013_config[i].adc_clock = 20480; 904 af9015_af9013_config[i].clock = 20480000;
907 break; 905 break;
908 case 2: 906 case 2:
909 af9015_af9013_config[i].adc_clock = 28000; 907 af9015_af9013_config[i].clock = 28000000;
910 break; 908 break;
911 case 3: 909 case 3:
912 af9015_af9013_config[i].adc_clock = 25000; 910 af9015_af9013_config[i].clock = 25000000;
913 break; 911 break;
914 }; 912 };
915 deb_info("%s: [%d] xtal:%d set adc_clock:%d\n", __func__, i, 913 deb_info("%s: [%d] xtal=%d set clock=%d\n", __func__, i,
916 val, af9015_af9013_config[i].adc_clock); 914 val, af9015_af9013_config[i].clock);
917 915
918 /* tuner IF */ 916 /* IF frequency */
919 req.addr = AF9015_EEPROM_IF1H + offset; 917 req.addr = AF9015_EEPROM_IF1H + offset;
920 ret = af9015_rw_udev(udev, &req); 918 ret = af9015_rw_udev(udev, &req);
921 if (ret) 919 if (ret)
922 goto error; 920 goto error;
923 af9015_af9013_config[i].tuner_if = val << 8; 921
922 af9015_af9013_config[i].if_frequency = val << 8;
923
924 req.addr = AF9015_EEPROM_IF1L + offset; 924 req.addr = AF9015_EEPROM_IF1L + offset;
925 ret = af9015_rw_udev(udev, &req); 925 ret = af9015_rw_udev(udev, &req);
926 if (ret) 926 if (ret)
927 goto error; 927 goto error;
928 af9015_af9013_config[i].tuner_if += val; 928
929 deb_info("%s: [%d] IF1:%d\n", __func__, i, 929 af9015_af9013_config[i].if_frequency += val;
930 af9015_af9013_config[0].tuner_if); 930 af9015_af9013_config[i].if_frequency *= 1000;
931 deb_info("%s: [%d] IF frequency=%d\n", __func__, i,
932 af9015_af9013_config[0].if_frequency);
931 933
932 /* MT2060 IF1 */ 934 /* MT2060 IF1 */
933 req.addr = AF9015_EEPROM_MT2060_IF1H + offset; 935 req.addr = AF9015_EEPROM_MT2060_IF1H + offset;
@@ -940,7 +942,7 @@ static int af9015_read_config(struct usb_device *udev)
940 if (ret) 942 if (ret)
941 goto error; 943 goto error;
942 af9015_config.mt2060_if1[i] += val; 944 af9015_config.mt2060_if1[i] += val;
943 deb_info("%s: [%d] MT2060 IF1:%d\n", __func__, i, 945 deb_info("%s: [%d] MT2060 IF1=%d\n", __func__, i,
944 af9015_config.mt2060_if1[i]); 946 af9015_config.mt2060_if1[i]);
945 947
946 /* tuner */ 948 /* tuner */
@@ -957,30 +959,30 @@ static int af9015_read_config(struct usb_device *udev)
957 case AF9013_TUNER_TDA18271: 959 case AF9013_TUNER_TDA18271:
958 case AF9013_TUNER_QT1010A: 960 case AF9013_TUNER_QT1010A:
959 case AF9013_TUNER_TDA18218: 961 case AF9013_TUNER_TDA18218:
960 af9015_af9013_config[i].rf_spec_inv = 1; 962 af9015_af9013_config[i].spec_inv = 1;
961 break; 963 break;
962 case AF9013_TUNER_MXL5003D: 964 case AF9013_TUNER_MXL5003D:
963 case AF9013_TUNER_MXL5005D: 965 case AF9013_TUNER_MXL5005D:
964 case AF9013_TUNER_MXL5005R: 966 case AF9013_TUNER_MXL5005R:
965 case AF9013_TUNER_MXL5007T: 967 case AF9013_TUNER_MXL5007T:
966 af9015_af9013_config[i].rf_spec_inv = 0; 968 af9015_af9013_config[i].spec_inv = 0;
967 break; 969 break;
968 case AF9013_TUNER_MC44S803: 970 case AF9013_TUNER_MC44S803:
969 af9015_af9013_config[i].gpio[1] = AF9013_GPIO_LO; 971 af9015_af9013_config[i].gpio[1] = AF9013_GPIO_LO;
970 af9015_af9013_config[i].rf_spec_inv = 1; 972 af9015_af9013_config[i].spec_inv = 1;
971 break; 973 break;
972 default: 974 default:
973 warn("tuner id:%d not supported, please report!", val); 975 warn("tuner id=%d not supported, please report!", val);
974 return -ENODEV; 976 return -ENODEV;
975 }; 977 };
976 978
977 af9015_af9013_config[i].tuner = val; 979 af9015_af9013_config[i].tuner = val;
978 deb_info("%s: [%d] tuner id:%d\n", __func__, i, val); 980 deb_info("%s: [%d] tuner id=%d\n", __func__, i, val);
979 } 981 }
980 982
981error: 983error:
982 if (ret) 984 if (ret)
983 err("eeprom read failed:%d", ret); 985 err("eeprom read failed=%d", ret);
984 986
985 /* AverMedia AVerTV Volar Black HD (A850) device have bad EEPROM 987 /* AverMedia AVerTV Volar Black HD (A850) device have bad EEPROM
986 content :-( Override some wrong values here. Ditto for the 988 content :-( Override some wrong values here. Ditto for the
@@ -998,7 +1000,7 @@ error:
998 af9015_properties[i].num_adapters = 1; 1000 af9015_properties[i].num_adapters = 1;
999 1001
1000 /* set correct IF */ 1002 /* set correct IF */
1001 af9015_af9013_config[0].tuner_if = 4570; 1003 af9015_af9013_config[0].if_frequency = 4570000;
1002 } 1004 }
1003 1005
1004 return ret; 1006 return ret;
@@ -1156,7 +1158,7 @@ static int af9015_af9013_sleep(struct dvb_frontend *fe)
1156 if (mutex_lock_interruptible(&adap->dev->usb_mutex)) 1158 if (mutex_lock_interruptible(&adap->dev->usb_mutex))
1157 return -EAGAIN; 1159 return -EAGAIN;
1158 1160
1159 ret = priv->init[adap->id](fe); 1161 ret = priv->sleep[adap->id](fe);
1160 1162
1161 mutex_unlock(&adap->dev->usb_mutex); 1163 mutex_unlock(&adap->dev->usb_mutex);
1162 1164