Lines Matching +full:a +full:- +full:f0 +full:- +full:9 +full:-

1 // SPDX-License-Identifier: GPL-2.0-or-later
21 ret = regmap_bulk_read(dev->regmap, reg, &tmp, 1); in m88ds3103_update_bits()
30 return regmap_bulk_write(dev->regmap, reg, &val, 1); in m88ds3103_update_bits()
37 struct i2c_client *client = dev->client; in m88ds3103_wr_reg_val_tab()
41 dev_dbg(&client->dev, "tab_len=%d\n", tab_len); in m88ds3103_wr_reg_val_tab()
44 ret = -EINVAL; in m88ds3103_wr_reg_val_tab()
51 if (i == tab_len - 1 || tab[i].reg != tab[i + 1].reg - 1 || in m88ds3103_wr_reg_val_tab()
52 !((j + 1) % (dev->cfg->i2c_wr_max - 1))) { in m88ds3103_wr_reg_val_tab()
53 ret = regmap_bulk_write(dev->regmap, tab[i].reg - j, buf, j + 1); in m88ds3103_wr_reg_val_tab()
57 j = -1; in m88ds3103_wr_reg_val_tab()
63 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_wr_reg_val_tab()
73 struct i2c_client *client = dev->client; in m88ds3103b_dt_write()
78 .addr = dev->dt_addr, .flags = 0, .buf = buf, .len = 2 in m88ds3103b_dt_write()
84 ret = regmap_write(dev->regmap, 0x03, val); in m88ds3103b_dt_write()
86 dev_dbg(&client->dev, "fail=%d\n", ret); in m88ds3103b_dt_write()
88 ret = i2c_transfer(dev->dt_client->adapter, &msg, 1); in m88ds3103b_dt_write()
90 dev_err(&client->dev, "0x%02x (ret=%i, reg=0x%02x, value=0x%02x)\n", in m88ds3103b_dt_write()
91 dev->dt_addr, ret, reg, data); in m88ds3103b_dt_write()
94 return -EREMOTEIO; in m88ds3103b_dt_write()
98 dev_dbg(&client->dev, "0x%02x reg 0x%02x, value 0x%02x\n", in m88ds3103b_dt_write()
99 dev->dt_addr, reg, data); in m88ds3103b_dt_write()
110 struct i2c_client *client = dev->client; in m88ds3103b_dt_read()
117 .addr = dev->dt_addr, in m88ds3103b_dt_read()
123 .addr = dev->dt_addr, in m88ds3103b_dt_read()
133 ret = regmap_write(dev->regmap, 0x03, val); in m88ds3103b_dt_read()
135 dev_dbg(&client->dev, "fail=%d\n", ret); in m88ds3103b_dt_read()
137 ret = i2c_transfer(dev->dt_client->adapter, msg, 2); in m88ds3103b_dt_read()
139 dev_err(&client->dev, "0x%02x (ret=%d, reg=0x%02x)\n", in m88ds3103b_dt_read()
140 dev->dt_addr, ret, reg); in m88ds3103b_dt_read()
143 return -EREMOTEIO; in m88ds3103b_dt_read()
147 dev_dbg(&client->dev, "0x%02x reg 0x%02x, value 0x%02x\n", in m88ds3103b_dt_read()
148 dev->dt_addr, reg, b1[0]); in m88ds3103b_dt_read()
158 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_get_agc_pwm()
162 ret = regmap_read(dev->regmap, 0x3f, &tmp); in m88ds3103_get_agc_pwm()
172 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_read_status()
173 struct i2c_client *client = dev->client; in m88ds3103_read_status()
174 struct dtv_frontend_properties *c = &fe->dtv_property_cache; in m88ds3103_read_status()
181 if (!dev->warm) { in m88ds3103_read_status()
182 ret = -EAGAIN; in m88ds3103_read_status()
186 switch (c->delivery_system) { in m88ds3103_read_status()
188 ret = regmap_read(dev->regmap, 0xd1, &utmp); in m88ds3103_read_status()
198 ret = regmap_read(dev->regmap, 0x0d, &utmp); in m88ds3103_read_status()
208 dev_dbg(&client->dev, "invalid delivery_system\n"); in m88ds3103_read_status()
209 ret = -EINVAL; in m88ds3103_read_status()
213 dev->fe_status = *status; in m88ds3103_read_status()
214 dev_dbg(&client->dev, "lock=%02x status=%02x\n", utmp, *status); in m88ds3103_read_status()
217 if (dev->fe_status & FE_HAS_VITERBI) { in m88ds3103_read_status()
224 switch (c->delivery_system) { in m88ds3103_read_status()
229 ret = regmap_read(dev->regmap, 0xff, &utmp); in m88ds3103_read_status()
247 ret = regmap_bulk_read(dev->regmap, 0x8c, buf, 3); in m88ds3103_read_status()
271 dev_dbg(&client->dev, "invalid delivery_system\n"); in m88ds3103_read_status()
272 ret = -EINVAL; in m88ds3103_read_status()
277 c->cnr.stat[0].scale = FE_SCALE_DECIBEL; in m88ds3103_read_status()
278 c->cnr.stat[0].svalue = cnr; in m88ds3103_read_status()
280 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; in m88ds3103_read_status()
283 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; in m88ds3103_read_status()
287 if (dev->fe_status & FE_HAS_LOCK) { in m88ds3103_read_status()
290 switch (c->delivery_system) { in m88ds3103_read_status()
292 ret = regmap_write(dev->regmap, 0xf9, 0x04); in m88ds3103_read_status()
296 ret = regmap_read(dev->regmap, 0xf8, &utmp); in m88ds3103_read_status()
302 ret = regmap_bulk_read(dev->regmap, 0xf6, buf, 2); in m88ds3103_read_status()
308 dev->post_bit_error += post_bit_error; in m88ds3103_read_status()
309 dev->post_bit_count += post_bit_count; in m88ds3103_read_status()
310 dev->dvbv3_ber = post_bit_error; in m88ds3103_read_status()
314 ret = regmap_write(dev->regmap, 0xf8, utmp); in m88ds3103_read_status()
320 ret = regmap_bulk_read(dev->regmap, 0xd5, buf, 3); in m88ds3103_read_status()
328 ret = regmap_bulk_read(dev->regmap, 0xf7, buf, 2); in m88ds3103_read_status()
334 dev->post_bit_error += post_bit_error; in m88ds3103_read_status()
335 dev->post_bit_count += post_bit_count; in m88ds3103_read_status()
336 dev->dvbv3_ber = post_bit_error; in m88ds3103_read_status()
339 ret = regmap_write(dev->regmap, 0xd1, 0x01); in m88ds3103_read_status()
343 ret = regmap_write(dev->regmap, 0xf9, 0x01); in m88ds3103_read_status()
347 ret = regmap_write(dev->regmap, 0xf9, 0x00); in m88ds3103_read_status()
351 ret = regmap_write(dev->regmap, 0xd1, 0x00); in m88ds3103_read_status()
357 dev_dbg(&client->dev, "invalid delivery_system\n"); in m88ds3103_read_status()
358 ret = -EINVAL; in m88ds3103_read_status()
362 c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER; in m88ds3103_read_status()
363 c->post_bit_error.stat[0].uvalue = dev->post_bit_error; in m88ds3103_read_status()
364 c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER; in m88ds3103_read_status()
365 c->post_bit_count.stat[0].uvalue = dev->post_bit_count; in m88ds3103_read_status()
367 c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; in m88ds3103_read_status()
368 c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; in m88ds3103_read_status()
373 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_read_status()
379 struct i2c_client *client = dev->client; in m88ds3103b_select_mclk()
380 struct dtv_frontend_properties *c = &dev->fe.dtv_property_cache; in m88ds3103b_select_mclk()
385 u32 old_setting = dev->mclk; in m88ds3103b_select_mclk()
386 u32 tuner_freq_MHz = c->frequency / 1000; in m88ds3103b_select_mclk()
390 big_symbol = (c->symbol_rate > 45010000) ? 1 : 0; in m88ds3103b_select_mclk()
402 offset_MHz[i] = adc_Freq_MHz[i] - offset_MHz[i]; in m88ds3103b_select_mclk()
407 dev->mclk = adc_Freq_MHz[i] * 1000 * 1000; in m88ds3103b_select_mclk()
410 dev->mclk /= 2; in m88ds3103b_select_mclk()
412 dev_dbg(&client->dev, "modifying mclk %u -> %u\n", in m88ds3103b_select_mclk()
413 old_setting, dev->mclk); in m88ds3103b_select_mclk()
418 if (dev->mclk == 93000000) in m88ds3103b_select_mclk()
419 regmap_write(dev->regmap, 0xA0, 0x42); in m88ds3103b_select_mclk()
420 else if (dev->mclk == 96000000) in m88ds3103b_select_mclk()
421 regmap_write(dev->regmap, 0xA0, 0x44); in m88ds3103b_select_mclk()
422 else if (dev->mclk == 99000000) in m88ds3103b_select_mclk()
423 regmap_write(dev->regmap, 0xA0, 0x46); in m88ds3103b_select_mclk()
424 else if (dev->mclk == 110250000) in m88ds3103b_select_mclk()
425 regmap_write(dev->regmap, 0xA0, 0x4E); in m88ds3103b_select_mclk()
427 regmap_write(dev->regmap, 0xA0, 0x44); in m88ds3103b_select_mclk()
455 u8 sm, f0 = 0, f1 = 0, f2 = 0, f3 = 0; in m88ds3103b_set_mclk() local
463 if (dev->cfg->ts_mode != M88DS3103_TS_SERIAL) { in m88ds3103b_set_mclk()
482 if (dev->cfg->ts_mode == M88DS3103_TS_SERIAL) { in m88ds3103b_set_mclk()
486 f0 = 0; in m88ds3103b_set_mclk()
488 f2 = div - f1; in m88ds3103b_set_mclk()
493 f0 = div / N; in m88ds3103b_set_mclk()
494 f1 = (div - f0) / (N - 1); in m88ds3103b_set_mclk()
495 f2 = div - f0 - f1; in m88ds3103b_set_mclk()
500 f0 = div / N; in m88ds3103b_set_mclk()
501 f1 = (div - f0) / (N - 1); in m88ds3103b_set_mclk()
502 f2 = (div - f0 - f1) / (N - 2); in m88ds3103b_set_mclk()
503 f3 = div - f0 - f1 - f2; in m88ds3103b_set_mclk()
507 f0 = 16; in m88ds3103b_set_mclk()
513 if (f0 == 16) in m88ds3103b_set_mclk()
514 f0 = 0; in m88ds3103b_set_mclk()
515 else if ((f0 < 8) && (f0 != 0)) in m88ds3103b_set_mclk()
516 f0 = 8; in m88ds3103b_set_mclk()
536 f0 = 0; in m88ds3103b_set_mclk()
538 f2 = div - f1; in m88ds3103b_set_mclk()
543 f0 = div / N; in m88ds3103b_set_mclk()
544 f1 = (div - f0) / (N - 1); in m88ds3103b_set_mclk()
545 f2 = div - f0 - f1; in m88ds3103b_set_mclk()
550 f0 = div / N; in m88ds3103b_set_mclk()
551 f1 = (div - f0) / (N - 1); in m88ds3103b_set_mclk()
552 f2 = (div - f0 - f1) / (N - 2); in m88ds3103b_set_mclk()
553 f3 = div - f0 - f1 - f2; in m88ds3103b_set_mclk()
557 f0 = 16; in m88ds3103b_set_mclk()
563 if (f0 == 16) in m88ds3103b_set_mclk()
564 f0 = 0; in m88ds3103b_set_mclk()
565 else if ((f0 < 9) && (f0 != 0)) in m88ds3103b_set_mclk()
566 f0 = 9; in m88ds3103b_set_mclk()
570 else if ((f1 < 9) && (f1 != 0)) in m88ds3103b_set_mclk()
571 f1 = 9; in m88ds3103b_set_mclk()
575 else if ((f2 < 9) && (f2 != 0)) in m88ds3103b_set_mclk()
576 f2 = 9; in m88ds3103b_set_mclk()
580 else if ((f3 < 9) && (f3 != 0)) in m88ds3103b_set_mclk()
581 f3 = 9; in m88ds3103b_set_mclk()
584 sm = N - 1; in m88ds3103b_set_mclk()
597 reg1F = ((f1 << 4) + f0) & 0xFF; in m88ds3103b_set_mclk()
620 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_set_frontend()
621 struct i2c_client *client = dev->client; in m88ds3103_set_frontend()
622 struct dtv_frontend_properties *c = &fe->dtv_property_cache; in m88ds3103_set_frontend()
634 dev_dbg(&client->dev, in m88ds3103_set_frontend()
636 c->delivery_system, c->modulation, c->frequency, c->symbol_rate, in m88ds3103_set_frontend()
637 c->inversion, c->pilot, c->rolloff); in m88ds3103_set_frontend()
639 if (!dev->warm) { in m88ds3103_set_frontend()
640 ret = -EAGAIN; in m88ds3103_set_frontend()
645 ret = regmap_multi_reg_write(dev->regmap, reset_buf, 2); in m88ds3103_set_frontend()
650 if (dev->chip_id == M88RS6000_CHIP_ID) { in m88ds3103_set_frontend()
651 if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { in m88ds3103_set_frontend()
652 ret = regmap_read(dev->regmap, 0xb2, &u32tmp); in m88ds3103_set_frontend()
656 ret = regmap_write(dev->regmap, 0x00, 0x00); in m88ds3103_set_frontend()
659 ret = regmap_write(dev->regmap, 0xb2, 0x00); in m88ds3103_set_frontend()
665 ret = regmap_write(dev->regmap, 0x06, 0xe0); in m88ds3103_set_frontend()
671 if (fe->ops.tuner_ops.set_params) { in m88ds3103_set_frontend()
672 ret = fe->ops.tuner_ops.set_params(fe); in m88ds3103_set_frontend()
677 if (fe->ops.tuner_ops.get_frequency) { in m88ds3103_set_frontend()
678 ret = fe->ops.tuner_ops.get_frequency(fe, &tuner_frequency_khz); in m88ds3103_set_frontend()
687 tuner_frequency_khz = c->frequency; in m88ds3103_set_frontend()
691 if (dev->chip_id == M88RS6000_CHIP_ID) { in m88ds3103_set_frontend()
692 if (c->symbol_rate > 45010000) in m88ds3103_set_frontend()
693 dev->mclk = 110250000; in m88ds3103_set_frontend()
695 dev->mclk = 96000000; in m88ds3103_set_frontend()
697 if (c->delivery_system == SYS_DVBS) in m88ds3103_set_frontend()
702 if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { in m88ds3103_set_frontend()
708 ret = regmap_write(dev->regmap, 0x06, 0x00); in m88ds3103_set_frontend()
714 dev->mclk = 96000000; in m88ds3103_set_frontend()
716 switch (dev->cfg->ts_mode) { in m88ds3103_set_frontend()
719 target_mclk = dev->cfg->ts_clk; in m88ds3103_set_frontend()
723 if (c->delivery_system == SYS_DVBS) in m88ds3103_set_frontend()
726 if (c->symbol_rate < 18000000) in m88ds3103_set_frontend()
728 else if (c->symbol_rate < 28000000) in m88ds3103_set_frontend()
735 dev_dbg(&client->dev, "invalid ts_mode\n"); in m88ds3103_set_frontend()
736 ret = -EINVAL; in m88ds3103_set_frontend()
762 ret = regmap_write(dev->regmap, 0xb2, 0x01); in m88ds3103_set_frontend()
766 ret = regmap_write(dev->regmap, 0x00, 0x01); in m88ds3103_set_frontend()
770 switch (c->delivery_system) { in m88ds3103_set_frontend()
772 if (dev->chip_id == M88RS6000_CHIP_ID) { in m88ds3103_set_frontend()
781 if (dev->chip_id == M88RS6000_CHIP_ID) { in m88ds3103_set_frontend()
790 dev_dbg(&client->dev, "invalid delivery_system\n"); in m88ds3103_set_frontend()
791 ret = -EINVAL; in m88ds3103_set_frontend()
796 if (c->delivery_system != dev->delivery_system) { in m88ds3103_set_frontend()
802 if (dev->chip_id == M88RS6000_CHIP_ID) { in m88ds3103_set_frontend()
803 if (c->delivery_system == SYS_DVBS2 && in m88ds3103_set_frontend()
804 c->symbol_rate <= 5000000) { in m88ds3103_set_frontend()
805 ret = regmap_write(dev->regmap, 0xc0, 0x04); in m88ds3103_set_frontend()
811 ret = regmap_bulk_write(dev->regmap, 0x8a, buf, 3); in m88ds3103_set_frontend()
819 if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { in m88ds3103_set_frontend()
823 if (c->symbol_rate > 45010000) { in m88ds3103_set_frontend()
826 buf[0] |= ((147 - 32) >> 8) & 0x01; in m88ds3103_set_frontend()
827 buf[1] = (147 - 32) & 0xFF; in m88ds3103_set_frontend()
829 dev->mclk = 110250 * 1000; in m88ds3103_set_frontend()
832 buf[0] |= ((128 - 32) >> 8) & 0x01; in m88ds3103_set_frontend()
833 buf[1] = (128 - 32) & 0xFF; in m88ds3103_set_frontend()
835 dev->mclk = 96000 * 1000; in m88ds3103_set_frontend()
840 regmap_read(dev->regmap, 0x30, &u32tmp); in m88ds3103_set_frontend()
842 regmap_write(dev->regmap, 0x30, u32tmp & 0xff); in m88ds3103_set_frontend()
845 ret = regmap_write(dev->regmap, 0xf1, 0x01); in m88ds3103_set_frontend()
849 if (dev->chiptype != M88DS3103_CHIPTYPE_3103B) { in m88ds3103_set_frontend()
856 switch (dev->cfg->ts_mode) { in m88ds3103_set_frontend()
867 if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { in m88ds3103_set_frontend()
876 dev_dbg(&client->dev, "invalid ts_mode\n"); in m88ds3103_set_frontend()
877 ret = -EINVAL; in m88ds3103_set_frontend()
881 if (dev->cfg->ts_clk_pol) in m88ds3103_set_frontend()
885 ret = regmap_write(dev->regmap, 0xfd, u8tmp); in m88ds3103_set_frontend()
889 switch (dev->cfg->ts_mode) { in m88ds3103_set_frontend()
900 if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { in m88ds3103_set_frontend()
907 u16tmp = DIV_ROUND_UP(target_mclk, dev->cfg->ts_clk); in m88ds3103_set_frontend()
908 u8tmp1 = u16tmp / 2 - 1; in m88ds3103_set_frontend()
909 u8tmp2 = DIV_ROUND_UP(u16tmp, 2) - 1; in m88ds3103_set_frontend()
912 dev_dbg(&client->dev, "target_mclk=%u ts_clk=%u ts_clk_divide_ratio=%u\n", in m88ds3103_set_frontend()
913 target_mclk, dev->cfg->ts_clk, u16tmp); in m88ds3103_set_frontend()
918 ret = regmap_update_bits(dev->regmap, 0xfe, 0x0f, u8tmp); in m88ds3103_set_frontend()
922 ret = regmap_write(dev->regmap, 0xea, u8tmp); in m88ds3103_set_frontend()
926 if (c->symbol_rate <= 3000000) in m88ds3103_set_frontend()
928 else if (c->symbol_rate <= 10000000) in m88ds3103_set_frontend()
933 if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) in m88ds3103_set_frontend()
936 ret = regmap_write(dev->regmap, 0xc3, 0x08); in m88ds3103_set_frontend()
940 ret = regmap_write(dev->regmap, 0xc8, u8tmp); in m88ds3103_set_frontend()
944 ret = regmap_write(dev->regmap, 0xc4, 0x08); in m88ds3103_set_frontend()
948 ret = regmap_write(dev->regmap, 0xc7, 0x00); in m88ds3103_set_frontend()
952 u16tmp = DIV_ROUND_CLOSEST_ULL((u64)c->symbol_rate * 0x10000, dev->mclk); in m88ds3103_set_frontend()
955 ret = regmap_bulk_write(dev->regmap, 0x61, buf, 2); in m88ds3103_set_frontend()
959 ret = m88ds3103_update_bits(dev, 0x4d, 0x02, dev->cfg->spec_inv << 1); in m88ds3103_set_frontend()
963 ret = m88ds3103_update_bits(dev, 0x30, 0x10, dev->cfg->agc_inv << 4); in m88ds3103_set_frontend()
967 ret = regmap_write(dev->regmap, 0x33, dev->cfg->agc); in m88ds3103_set_frontend()
971 if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { in m88ds3103_set_frontend()
974 (c->delivery_system == SYS_DVBS) ? 0x10 : 0x0); in m88ds3103_set_frontend()
983 dev_dbg(&client->dev, "carrier offset=%d\n", in m88ds3103_set_frontend()
984 (tuner_frequency_khz - c->frequency)); in m88ds3103_set_frontend()
986 /* Use 32-bit calc as there is no s64 version of DIV_ROUND_CLOSEST() */ in m88ds3103_set_frontend()
987 s32tmp = 0x10000 * (tuner_frequency_khz - c->frequency); in m88ds3103_set_frontend()
988 s32tmp = DIV_ROUND_CLOSEST(s32tmp, dev->mclk / 1000); in m88ds3103_set_frontend()
991 ret = regmap_bulk_write(dev->regmap, 0x5e, buf, 2); in m88ds3103_set_frontend()
995 ret = regmap_write(dev->regmap, 0x00, 0x00); in m88ds3103_set_frontend()
999 ret = regmap_write(dev->regmap, 0xb2, 0x00); in m88ds3103_set_frontend()
1003 if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { in m88ds3103_set_frontend()
1010 dev->delivery_system = c->delivery_system; in m88ds3103_set_frontend()
1014 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_set_frontend()
1020 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_init()
1021 struct i2c_client *client = dev->client; in m88ds3103_init()
1022 struct dtv_frontend_properties *c = &fe->dtv_property_cache; in m88ds3103_init()
1028 dev_dbg(&client->dev, "\n"); in m88ds3103_init()
1031 dev->warm = false; in m88ds3103_init()
1045 ret = regmap_read(dev->regmap, 0xb9, &utmp); in m88ds3103_init()
1049 dev_dbg(&client->dev, "firmware=%02x\n", utmp); in m88ds3103_init()
1055 ret = regmap_write(dev->regmap, 0x07, 0xe0); in m88ds3103_init()
1058 ret = regmap_write(dev->regmap, 0x07, 0x00); in m88ds3103_init()
1062 /* cold state - try to download firmware */ in m88ds3103_init()
1063 dev_info(&client->dev, "found a '%s' in cold state\n", in m88ds3103_init()
1064 dev->fe.ops.info.name); in m88ds3103_init()
1066 if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) in m88ds3103_init()
1068 else if (dev->chip_id == M88RS6000_CHIP_ID) in m88ds3103_init()
1074 ret = request_firmware(&firmware, name, &client->dev); in m88ds3103_init()
1076 dev_err(&client->dev, "firmware file '%s' not found\n", name); in m88ds3103_init()
1080 dev_info(&client->dev, "downloading firmware from file '%s'\n", name); in m88ds3103_init()
1082 ret = regmap_write(dev->regmap, 0xb2, 0x01); in m88ds3103_init()
1086 for (rem = firmware->size; rem > 0; rem -= (dev->cfg->i2c_wr_max - 1)) { in m88ds3103_init()
1087 len = min(dev->cfg->i2c_wr_max - 1, rem); in m88ds3103_init()
1088 ret = regmap_bulk_write(dev->regmap, 0xb0, in m88ds3103_init()
1089 &firmware->data[firmware->size - rem], in m88ds3103_init()
1092 dev_err(&client->dev, "firmware download failed %d\n", in m88ds3103_init()
1098 ret = regmap_write(dev->regmap, 0xb2, 0x00); in m88ds3103_init()
1104 ret = regmap_read(dev->regmap, 0xb9, &utmp); in m88ds3103_init()
1109 ret = -EINVAL; in m88ds3103_init()
1110 dev_info(&client->dev, "firmware did not run\n"); in m88ds3103_init()
1114 dev_info(&client->dev, "found a '%s' in warm state\n", in m88ds3103_init()
1115 dev->fe.ops.info.name); in m88ds3103_init()
1116 dev_info(&client->dev, "firmware version: %X.%X\n", in m88ds3103_init()
1119 if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { in m88ds3103_init()
1127 dev->warm = true; in m88ds3103_init()
1130 c->cnr.len = 1; in m88ds3103_init()
1131 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; in m88ds3103_init()
1132 c->post_bit_error.len = 1; in m88ds3103_init()
1133 c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; in m88ds3103_init()
1134 c->post_bit_count.len = 1; in m88ds3103_init()
1135 c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; in m88ds3103_init()
1141 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_init()
1147 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_sleep()
1148 struct i2c_client *client = dev->client; in m88ds3103_sleep()
1152 dev_dbg(&client->dev, "\n"); in m88ds3103_sleep()
1154 dev->fe_status = 0; in m88ds3103_sleep()
1155 dev->delivery_system = SYS_UNDEFINED; in m88ds3103_sleep()
1157 /* TS Hi-Z */ in m88ds3103_sleep()
1158 if (dev->chip_id == M88RS6000_CHIP_ID) in m88ds3103_sleep()
1179 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_sleep()
1186 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_get_frontend()
1187 struct i2c_client *client = dev->client; in m88ds3103_get_frontend()
1191 dev_dbg(&client->dev, "\n"); in m88ds3103_get_frontend()
1193 if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) { in m88ds3103_get_frontend()
1198 switch (c->delivery_system) { in m88ds3103_get_frontend()
1200 ret = regmap_bulk_read(dev->regmap, 0xe0, &buf[0], 1); in m88ds3103_get_frontend()
1204 ret = regmap_bulk_read(dev->regmap, 0xe6, &buf[1], 1); in m88ds3103_get_frontend()
1210 c->inversion = INVERSION_OFF; in m88ds3103_get_frontend()
1213 c->inversion = INVERSION_ON; in m88ds3103_get_frontend()
1219 c->fec_inner = FEC_7_8; in m88ds3103_get_frontend()
1222 c->fec_inner = FEC_5_6; in m88ds3103_get_frontend()
1225 c->fec_inner = FEC_3_4; in m88ds3103_get_frontend()
1228 c->fec_inner = FEC_2_3; in m88ds3103_get_frontend()
1231 c->fec_inner = FEC_1_2; in m88ds3103_get_frontend()
1234 dev_dbg(&client->dev, "invalid fec_inner\n"); in m88ds3103_get_frontend()
1237 c->modulation = QPSK; in m88ds3103_get_frontend()
1241 ret = regmap_bulk_read(dev->regmap, 0x7e, &buf[0], 1); in m88ds3103_get_frontend()
1245 ret = regmap_bulk_read(dev->regmap, 0x89, &buf[1], 1); in m88ds3103_get_frontend()
1249 ret = regmap_bulk_read(dev->regmap, 0xf2, &buf[2], 1); in m88ds3103_get_frontend()
1255 c->fec_inner = FEC_2_5; in m88ds3103_get_frontend()
1258 c->fec_inner = FEC_1_2; in m88ds3103_get_frontend()
1261 c->fec_inner = FEC_3_5; in m88ds3103_get_frontend()
1264 c->fec_inner = FEC_2_3; in m88ds3103_get_frontend()
1267 c->fec_inner = FEC_3_4; in m88ds3103_get_frontend()
1270 c->fec_inner = FEC_4_5; in m88ds3103_get_frontend()
1273 c->fec_inner = FEC_5_6; in m88ds3103_get_frontend()
1275 case 9: in m88ds3103_get_frontend()
1276 c->fec_inner = FEC_8_9; in m88ds3103_get_frontend()
1279 c->fec_inner = FEC_9_10; in m88ds3103_get_frontend()
1282 dev_dbg(&client->dev, "invalid fec_inner\n"); in m88ds3103_get_frontend()
1287 c->pilot = PILOT_OFF; in m88ds3103_get_frontend()
1290 c->pilot = PILOT_ON; in m88ds3103_get_frontend()
1296 c->modulation = QPSK; in m88ds3103_get_frontend()
1299 c->modulation = PSK_8; in m88ds3103_get_frontend()
1302 c->modulation = APSK_16; in m88ds3103_get_frontend()
1305 c->modulation = APSK_32; in m88ds3103_get_frontend()
1308 dev_dbg(&client->dev, "invalid modulation\n"); in m88ds3103_get_frontend()
1313 c->inversion = INVERSION_OFF; in m88ds3103_get_frontend()
1316 c->inversion = INVERSION_ON; in m88ds3103_get_frontend()
1322 c->rolloff = ROLLOFF_35; in m88ds3103_get_frontend()
1325 c->rolloff = ROLLOFF_25; in m88ds3103_get_frontend()
1328 c->rolloff = ROLLOFF_20; in m88ds3103_get_frontend()
1331 dev_dbg(&client->dev, "invalid rolloff\n"); in m88ds3103_get_frontend()
1335 dev_dbg(&client->dev, "invalid delivery_system\n"); in m88ds3103_get_frontend()
1336 ret = -EINVAL; in m88ds3103_get_frontend()
1340 ret = regmap_bulk_read(dev->regmap, 0x6d, buf, 2); in m88ds3103_get_frontend()
1344 c->symbol_rate = DIV_ROUND_CLOSEST_ULL((u64)(buf[1] << 8 | buf[0] << 0) * dev->mclk, 0x10000); in m88ds3103_get_frontend()
1348 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_get_frontend()
1354 struct dtv_frontend_properties *c = &fe->dtv_property_cache; in m88ds3103_read_snr()
1356 if (c->cnr.stat[0].scale == FE_SCALE_DECIBEL) in m88ds3103_read_snr()
1357 *snr = div_s64(c->cnr.stat[0].svalue, 100); in m88ds3103_read_snr()
1366 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_read_ber()
1368 *ber = dev->dvbv3_ber; in m88ds3103_read_ber()
1376 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_set_tone()
1377 struct i2c_client *client = dev->client; in m88ds3103_set_tone()
1381 dev_dbg(&client->dev, "fe_sec_tone_mode=%d\n", fe_sec_tone_mode); in m88ds3103_set_tone()
1383 if (!dev->warm) { in m88ds3103_set_tone()
1384 ret = -EAGAIN; in m88ds3103_set_tone()
1398 dev_dbg(&client->dev, "invalid fe_sec_tone_mode\n"); in m88ds3103_set_tone()
1399 ret = -EINVAL; in m88ds3103_set_tone()
1403 utmp = tone << 7 | dev->cfg->envelope_mode << 5; in m88ds3103_set_tone()
1415 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_set_tone()
1422 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_set_voltage()
1423 struct i2c_client *client = dev->client; in m88ds3103_set_voltage()
1428 dev_dbg(&client->dev, "fe_sec_voltage=%d\n", fe_sec_voltage); in m88ds3103_set_voltage()
1430 if (!dev->warm) { in m88ds3103_set_voltage()
1431 ret = -EAGAIN; in m88ds3103_set_voltage()
1449 dev_dbg(&client->dev, "invalid fe_sec_voltage\n"); in m88ds3103_set_voltage()
1450 ret = -EINVAL; in m88ds3103_set_voltage()
1455 voltage_sel ^= dev->cfg->lnb_hv_pol; in m88ds3103_set_voltage()
1456 voltage_dis ^= dev->cfg->lnb_en_pol; in m88ds3103_set_voltage()
1465 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_set_voltage()
1472 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_diseqc_send_master_cmd()
1473 struct i2c_client *client = dev->client; in m88ds3103_diseqc_send_master_cmd()
1478 dev_dbg(&client->dev, "msg=%*ph\n", in m88ds3103_diseqc_send_master_cmd()
1479 diseqc_cmd->msg_len, diseqc_cmd->msg); in m88ds3103_diseqc_send_master_cmd()
1481 if (!dev->warm) { in m88ds3103_diseqc_send_master_cmd()
1482 ret = -EAGAIN; in m88ds3103_diseqc_send_master_cmd()
1486 if (diseqc_cmd->msg_len < 3 || diseqc_cmd->msg_len > 6) { in m88ds3103_diseqc_send_master_cmd()
1487 ret = -EINVAL; in m88ds3103_diseqc_send_master_cmd()
1491 utmp = dev->cfg->envelope_mode << 5; in m88ds3103_diseqc_send_master_cmd()
1496 ret = regmap_bulk_write(dev->regmap, 0xa3, diseqc_cmd->msg, in m88ds3103_diseqc_send_master_cmd()
1497 diseqc_cmd->msg_len); in m88ds3103_diseqc_send_master_cmd()
1501 ret = regmap_write(dev->regmap, 0xa1, in m88ds3103_diseqc_send_master_cmd()
1502 (diseqc_cmd->msg_len - 1) << 3 | 0x07); in m88ds3103_diseqc_send_master_cmd()
1511 utmp = diseqc_cmd->msg_len * 13500; in m88ds3103_diseqc_send_master_cmd()
1512 usleep_range(utmp - 4000, utmp); in m88ds3103_diseqc_send_master_cmd()
1515 ret = regmap_read(dev->regmap, 0xa1, &utmp); in m88ds3103_diseqc_send_master_cmd()
1522 dev_dbg(&client->dev, "diseqc tx took %u ms\n", in m88ds3103_diseqc_send_master_cmd()
1523 jiffies_to_msecs(jiffies) - in m88ds3103_diseqc_send_master_cmd()
1524 (jiffies_to_msecs(timeout) - SEND_MASTER_CMD_TIMEOUT)); in m88ds3103_diseqc_send_master_cmd()
1526 dev_dbg(&client->dev, "diseqc tx timeout\n"); in m88ds3103_diseqc_send_master_cmd()
1538 ret = -ETIMEDOUT; in m88ds3103_diseqc_send_master_cmd()
1544 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_diseqc_send_master_cmd()
1551 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_diseqc_send_burst()
1552 struct i2c_client *client = dev->client; in m88ds3103_diseqc_send_burst()
1557 dev_dbg(&client->dev, "fe_sec_mini_cmd=%d\n", fe_sec_mini_cmd); in m88ds3103_diseqc_send_burst()
1559 if (!dev->warm) { in m88ds3103_diseqc_send_burst()
1560 ret = -EAGAIN; in m88ds3103_diseqc_send_burst()
1564 utmp = dev->cfg->envelope_mode << 5; in m88ds3103_diseqc_send_burst()
1577 dev_dbg(&client->dev, "invalid fe_sec_mini_cmd\n"); in m88ds3103_diseqc_send_burst()
1578 ret = -EINVAL; in m88ds3103_diseqc_send_burst()
1582 ret = regmap_write(dev->regmap, 0xa1, burst); in m88ds3103_diseqc_send_burst()
1594 ret = regmap_read(dev->regmap, 0xa1, &utmp); in m88ds3103_diseqc_send_burst()
1601 dev_dbg(&client->dev, "diseqc tx took %u ms\n", in m88ds3103_diseqc_send_burst()
1602 jiffies_to_msecs(jiffies) - in m88ds3103_diseqc_send_burst()
1603 (jiffies_to_msecs(timeout) - SEND_BURST_TIMEOUT)); in m88ds3103_diseqc_send_burst()
1605 dev_dbg(&client->dev, "diseqc tx timeout\n"); in m88ds3103_diseqc_send_burst()
1617 ret = -ETIMEDOUT; in m88ds3103_diseqc_send_burst()
1623 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_diseqc_send_burst()
1630 s->min_delay_ms = 3000; in m88ds3103_get_tune_settings()
1637 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_release()
1638 struct i2c_client *client = dev->client; in m88ds3103_release()
1646 struct i2c_client *client = dev->client; in m88ds3103_select()
1649 .addr = client->addr, in m88ds3103_select()
1656 ret = __i2c_transfer(client->adapter, &msg, 1); in m88ds3103_select()
1658 dev_warn(&client->dev, "i2c wr failed=%d\n", ret); in m88ds3103_select()
1660 ret = -EREMOTEIO; in m88ds3103_select()
1680 pdata.clk = cfg->clock; in m88ds3103_attach()
1681 pdata.i2c_wr_max = cfg->i2c_wr_max; in m88ds3103_attach()
1682 pdata.ts_mode = cfg->ts_mode; in m88ds3103_attach()
1683 pdata.ts_clk = cfg->ts_clk; in m88ds3103_attach()
1684 pdata.ts_clk_pol = cfg->ts_clk_pol; in m88ds3103_attach()
1685 pdata.spec_inv = cfg->spec_inv; in m88ds3103_attach()
1686 pdata.agc = cfg->agc; in m88ds3103_attach()
1687 pdata.agc_inv = cfg->agc_inv; in m88ds3103_attach()
1688 pdata.clk_out = cfg->clock_out; in m88ds3103_attach()
1689 pdata.envelope_mode = cfg->envelope_mode; in m88ds3103_attach()
1690 pdata.lnb_hv_pol = cfg->lnb_hv_pol; in m88ds3103_attach()
1691 pdata.lnb_en_pol = cfg->lnb_en_pol; in m88ds3103_attach()
1696 board_info.addr = cfg->i2c_addr; in m88ds3103_attach()
1756 dev_dbg(&client->dev, "\n"); in m88ds3103_get_dvb_frontend()
1758 return &dev->fe; in m88ds3103_get_dvb_frontend()
1765 dev_dbg(&client->dev, "\n"); in m88ds3103_get_i2c_adapter()
1767 return dev->muxc->adapter[0]; in m88ds3103_get_i2c_adapter()
1774 struct m88ds3103_platform_data *pdata = client->dev.platform_data; in m88ds3103_probe()
1780 ret = -ENOMEM; in m88ds3103_probe()
1784 dev->client = client; in m88ds3103_probe()
1785 dev->config.clock = pdata->clk; in m88ds3103_probe()
1786 dev->config.i2c_wr_max = pdata->i2c_wr_max; in m88ds3103_probe()
1787 dev->config.ts_mode = pdata->ts_mode; in m88ds3103_probe()
1788 dev->config.ts_clk = pdata->ts_clk * 1000; in m88ds3103_probe()
1789 dev->config.ts_clk_pol = pdata->ts_clk_pol; in m88ds3103_probe()
1790 dev->config.spec_inv = pdata->spec_inv; in m88ds3103_probe()
1791 dev->config.agc_inv = pdata->agc_inv; in m88ds3103_probe()
1792 dev->config.clock_out = pdata->clk_out; in m88ds3103_probe()
1793 dev->config.envelope_mode = pdata->envelope_mode; in m88ds3103_probe()
1794 dev->config.agc = pdata->agc; in m88ds3103_probe()
1795 dev->config.lnb_hv_pol = pdata->lnb_hv_pol; in m88ds3103_probe()
1796 dev->config.lnb_en_pol = pdata->lnb_en_pol; in m88ds3103_probe()
1797 dev->cfg = &dev->config; in m88ds3103_probe()
1799 dev->regmap_config.reg_bits = 8; in m88ds3103_probe()
1800 dev->regmap_config.val_bits = 8; in m88ds3103_probe()
1801 dev->regmap_config.lock_arg = dev; in m88ds3103_probe()
1802 dev->regmap = devm_regmap_init_i2c(client, &dev->regmap_config); in m88ds3103_probe()
1803 if (IS_ERR(dev->regmap)) { in m88ds3103_probe()
1804 ret = PTR_ERR(dev->regmap); in m88ds3103_probe()
1809 ret = regmap_read(dev->regmap, 0x00, &utmp); in m88ds3103_probe()
1813 dev->chip_id = utmp >> 1; in m88ds3103_probe()
1814 dev->chiptype = (u8)id->driver_data; in m88ds3103_probe()
1816 dev_dbg(&client->dev, "chip_id=%02x\n", dev->chip_id); in m88ds3103_probe()
1818 switch (dev->chip_id) { in m88ds3103_probe()
1823 ret = -ENODEV; in m88ds3103_probe()
1824 dev_err(&client->dev, "Unknown device. Chip_id=%02x\n", dev->chip_id); in m88ds3103_probe()
1828 switch (dev->cfg->clock_out) { in m88ds3103_probe()
1839 ret = -EINVAL; in m88ds3103_probe()
1843 if (!pdata->ts_clk) { in m88ds3103_probe()
1844 ret = -EINVAL; in m88ds3103_probe()
1850 if (dev->chip_id == M88RS6000_CHIP_ID) in m88ds3103_probe()
1853 ret = regmap_write(dev->regmap, 0x29, utmp); in m88ds3103_probe()
1869 dev->muxc = i2c_mux_alloc(client->adapter, &client->dev, 1, 0, 0, in m88ds3103_probe()
1871 if (!dev->muxc) { in m88ds3103_probe()
1872 ret = -ENOMEM; in m88ds3103_probe()
1875 dev->muxc->priv = dev; in m88ds3103_probe()
1876 ret = i2c_mux_add_adapter(dev->muxc, 0, 0); in m88ds3103_probe()
1881 memcpy(&dev->fe.ops, &m88ds3103_ops, sizeof(struct dvb_frontend_ops)); in m88ds3103_probe()
1882 if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) in m88ds3103_probe()
1883 strscpy(dev->fe.ops.info.name, "Montage Technology M88DS3103B", in m88ds3103_probe()
1884 sizeof(dev->fe.ops.info.name)); in m88ds3103_probe()
1885 else if (dev->chip_id == M88RS6000_CHIP_ID) in m88ds3103_probe()
1886 strscpy(dev->fe.ops.info.name, "Montage Technology M88RS6000", in m88ds3103_probe()
1887 sizeof(dev->fe.ops.info.name)); in m88ds3103_probe()
1888 if (!pdata->attach_in_use) in m88ds3103_probe()
1889 dev->fe.ops.release = NULL; in m88ds3103_probe()
1890 dev->fe.demodulator_priv = dev; in m88ds3103_probe()
1894 pdata->get_dvb_frontend = m88ds3103_get_dvb_frontend; in m88ds3103_probe()
1895 pdata->get_i2c_adapter = m88ds3103_get_i2c_adapter; in m88ds3103_probe()
1897 if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { in m88ds3103_probe()
1902 ret = regmap_read(dev->regmap, 0x29, &utmp); in m88ds3103_probe()
1905 dev->dt_addr = ((utmp & 0x80) == 0) ? 0x42 >> 1 : 0x40 >> 1; in m88ds3103_probe()
1906 dev_dbg(&client->dev, "dt addr is 0x%02x\n", dev->dt_addr); in m88ds3103_probe()
1908 dev->dt_client = i2c_new_dummy_device(client->adapter, in m88ds3103_probe()
1909 dev->dt_addr); in m88ds3103_probe()
1910 if (IS_ERR(dev->dt_client)) { in m88ds3103_probe()
1911 ret = PTR_ERR(dev->dt_client); in m88ds3103_probe()
1919 i2c_mux_del_adapters(dev->muxc); in m88ds3103_probe()
1923 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_probe()
1931 dev_dbg(&client->dev, "\n"); in m88ds3103_remove()
1933 i2c_unregister_device(dev->dt_client); in m88ds3103_remove()
1935 i2c_mux_del_adapters(dev->muxc); in m88ds3103_remove()
1961 MODULE_DESCRIPTION("Montage Technology M88DS3103 DVB-S/S2 demodulator driver");