Lines Matching +full:0 +full:- +full:dev

1 // SPDX-License-Identifier: GPL-2.0-or-later
13 static int m88ds3103_update_bits(struct m88ds3103_dev *dev, in m88ds3103_update_bits() argument
20 if (mask != 0xff) { in m88ds3103_update_bits()
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()
34 static int m88ds3103_wr_reg_val_tab(struct m88ds3103_dev *dev, in m88ds3103_wr_reg_val_tab() argument
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()
48 for (i = 0, j = 0; i < tab_len; i++, j++) { 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()
61 return 0; in m88ds3103_wr_reg_val_tab()
63 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_wr_reg_val_tab()
71 static int m88ds3103b_dt_write(struct m88ds3103_dev *dev, int reg, int data) in m88ds3103b_dt_write() argument
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()
81 m88ds3103_update_bits(dev, 0x11, 0x01, 0x00); in m88ds3103b_dt_write()
83 val = 0x11; 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()
93 m88ds3103_update_bits(dev, 0x11, 0x01, 0x01); in m88ds3103b_dt_write()
94 return -EREMOTEIO; in m88ds3103b_dt_write()
96 m88ds3103_update_bits(dev, 0x11, 0x01, 0x01); 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()
101 return 0; in m88ds3103b_dt_write()
108 static int m88ds3103b_dt_read(struct m88ds3103_dev *dev, u8 reg) in m88ds3103b_dt_read() argument
110 struct i2c_client *client = dev->client; in m88ds3103b_dt_read()
114 u8 b1[] = { 0 }; in m88ds3103b_dt_read()
117 .addr = dev->dt_addr, in m88ds3103b_dt_read()
118 .flags = 0, in m88ds3103b_dt_read()
123 .addr = dev->dt_addr, in m88ds3103b_dt_read()
130 m88ds3103_update_bits(dev, 0x11, 0x01, 0x00); in m88ds3103b_dt_read()
132 val = 0x12; 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()
142 m88ds3103_update_bits(dev, 0x11, 0x01, 0x01); in m88ds3103b_dt_read()
143 return -EREMOTEIO; in m88ds3103b_dt_read()
145 m88ds3103_update_bits(dev, 0x11, 0x01, 0x01); 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()
150 return b1[0]; in m88ds3103b_dt_read()
158 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_get_agc_pwm() local
162 ret = regmap_read(dev->regmap, 0x3f, &tmp); in m88ds3103_get_agc_pwm()
163 if (ret == 0) in m88ds3103_get_agc_pwm()
172 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_read_status() local
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()
179 *status = 0; 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()
192 if ((utmp & 0x07) == 0x07) in m88ds3103_read_status()
198 ret = regmap_read(dev->regmap, 0x0d, &utmp); in m88ds3103_read_status()
202 if ((utmp & 0x8f) == 0x8f) 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()
220 cnr = 0; in m88ds3103_read_status()
224 switch (c->delivery_system) { in m88ds3103_read_status()
226 itmp = 0; in m88ds3103_read_status()
228 for (i = 0; i < M88DS3103_SNR_ITERATIONS; i++) { in m88ds3103_read_status()
229 ret = regmap_read(dev->regmap, 0xff, &utmp); in m88ds3103_read_status()
243 noise_tot = 0; in m88ds3103_read_status()
244 signal_tot = 0; in m88ds3103_read_status()
246 for (i = 0; i < M88DS3103_SNR_ITERATIONS; i++) { in m88ds3103_read_status()
247 ret = regmap_bulk_read(dev->regmap, 0x8c, buf, 3); in m88ds3103_read_status()
252 noise |= buf[0] & 0x3f; /* [5:0] */ 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()
301 if (!(utmp & 0x10)) { in m88ds3103_read_status()
302 ret = regmap_bulk_read(dev->regmap, 0xf6, buf, 2); in m88ds3103_read_status()
306 post_bit_error = buf[1] << 8 | buf[0] << 0; in m88ds3103_read_status()
307 post_bit_count = 0x800000; 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()
313 utmp |= 0x10; 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()
324 utmp = buf[2] << 16 | buf[1] << 8 | buf[0] << 0; in m88ds3103_read_status()
328 ret = regmap_bulk_read(dev->regmap, 0xf7, buf, 2); in m88ds3103_read_status()
332 post_bit_error = buf[1] << 8 | buf[0] << 0; 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()
371 return 0; in m88ds3103_read_status()
373 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_read_status()
377 static int m88ds3103b_select_mclk(struct m88ds3103_dev *dev) in m88ds3103b_select_mclk() argument
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()
384 u32 max_offset = 0; 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()
388 char big_symbol = 0; in m88ds3103b_select_mclk()
390 big_symbol = (c->symbol_rate > 45010000) ? 1 : 0; in m88ds3103b_select_mclk()
398 for (i = 0; i < 3; i++) { 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()
429 reg15 = m88ds3103b_dt_read(dev, 0x15); in m88ds3103b_select_mclk()
431 m88ds3103b_dt_write(dev, 0x05, 0x40); in m88ds3103b_select_mclk()
432 m88ds3103b_dt_write(dev, 0x11, 0x08); in m88ds3103b_select_mclk()
435 reg15 |= 0x02; in m88ds3103b_select_mclk()
437 reg15 &= ~0x02; in m88ds3103b_select_mclk()
439 m88ds3103b_dt_write(dev, 0x15, reg15); in m88ds3103b_select_mclk()
440 m88ds3103b_dt_write(dev, 0x16, reg16); in m88ds3103b_select_mclk()
444 m88ds3103b_dt_write(dev, 0x05, 0x00); in m88ds3103b_select_mclk()
445 m88ds3103b_dt_write(dev, 0x11, (u8)(big_symbol ? 0x0E : 0x0A)); in m88ds3103b_select_mclk()
449 return 0; in m88ds3103b_select_mclk()
452 static int m88ds3103b_set_mclk(struct m88ds3103_dev *dev, u32 mclk_khz) in m88ds3103b_set_mclk() argument
455 u8 sm, f0 = 0, f1 = 0, f2 = 0, f3 = 0; in m88ds3103b_set_mclk()
459 reg15 = m88ds3103b_dt_read(dev, 0x15); in m88ds3103b_set_mclk()
460 reg16 = m88ds3103b_dt_read(dev, 0x16); in m88ds3103b_set_mclk()
461 reg1D = m88ds3103b_dt_read(dev, 0x1D); in m88ds3103b_set_mclk()
463 if (dev->cfg->ts_mode != M88DS3103_TS_SERIAL) { in m88ds3103b_set_mclk()
475 pll_div_fb = (reg15 & 0x01) << 8; 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()
489 f3 = 0; in m88ds3103b_set_mclk()
494 f1 = (div - f0) / (N - 1); in m88ds3103b_set_mclk()
495 f2 = div - f0 - f1; in m88ds3103b_set_mclk()
496 f3 = 0; 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()
514 f0 = 0; in m88ds3103b_set_mclk()
515 else if ((f0 < 8) && (f0 != 0)) in m88ds3103b_set_mclk()
519 f1 = 0; in m88ds3103b_set_mclk()
520 else if ((f1 < 8) && (f1 != 0)) in m88ds3103b_set_mclk()
524 f2 = 0; in m88ds3103b_set_mclk()
525 else if ((f2 < 8) && (f2 != 0)) in m88ds3103b_set_mclk()
529 f3 = 0; in m88ds3103b_set_mclk()
530 else if ((f3 < 8) && (f3 != 0)) in m88ds3103b_set_mclk()
536 f0 = 0; in m88ds3103b_set_mclk()
538 f2 = div - f1; in m88ds3103b_set_mclk()
539 f3 = 0; in m88ds3103b_set_mclk()
544 f1 = (div - f0) / (N - 1); in m88ds3103b_set_mclk()
545 f2 = div - f0 - f1; in m88ds3103b_set_mclk()
546 f3 = 0; 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()
564 f0 = 0; in m88ds3103b_set_mclk()
565 else if ((f0 < 9) && (f0 != 0)) in m88ds3103b_set_mclk()
569 f1 = 0; in m88ds3103b_set_mclk()
570 else if ((f1 < 9) && (f1 != 0)) in m88ds3103b_set_mclk()
574 f2 = 0; in m88ds3103b_set_mclk()
575 else if ((f2 < 9) && (f2 != 0)) in m88ds3103b_set_mclk()
579 f3 = 0; in m88ds3103b_set_mclk()
580 else if ((f3 < 9) && (f3 != 0)) in m88ds3103b_set_mclk()
584 sm = N - 1; in m88ds3103b_set_mclk()
587 //reg15 &= 0x01; in m88ds3103b_set_mclk()
588 //reg15 |= (pll_div_fb >> 8) & 0x01; in m88ds3103b_set_mclk()
590 //reg16 = pll_div_fb & 0xFF; in m88ds3103b_set_mclk()
592 reg1D &= ~0x03; in m88ds3103b_set_mclk()
594 reg1D |= 0x80; in m88ds3103b_set_mclk()
596 reg1E = ((f3 << 4) + f2) & 0xFF; in m88ds3103b_set_mclk()
597 reg1F = ((f1 << 4) + f0) & 0xFF; in m88ds3103b_set_mclk()
599 m88ds3103b_dt_write(dev, 0x05, 0x40); in m88ds3103b_set_mclk()
600 m88ds3103b_dt_write(dev, 0x11, 0x08); in m88ds3103b_set_mclk()
601 m88ds3103b_dt_write(dev, 0x1D, reg1D); in m88ds3103b_set_mclk()
602 m88ds3103b_dt_write(dev, 0x1E, reg1E); in m88ds3103b_set_mclk()
603 m88ds3103b_dt_write(dev, 0x1F, reg1F); in m88ds3103b_set_mclk()
605 m88ds3103b_dt_write(dev, 0x17, 0xc1); in m88ds3103b_set_mclk()
606 m88ds3103b_dt_write(dev, 0x17, 0x81); in m88ds3103b_set_mclk()
610 m88ds3103b_dt_write(dev, 0x05, 0x00); in m88ds3103b_set_mclk()
611 m88ds3103b_dt_write(dev, 0x11, 0x0A); in m88ds3103b_set_mclk()
615 return 0; in m88ds3103b_set_mclk()
620 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_set_frontend() local
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()
625 u8 u8tmp, u8tmp1 = 0, u8tmp2 = 0; /* silence compiler warning */ in m88ds3103_set_frontend()
631 {0x07, 0x80}, {0x07, 0x00} 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()
655 if (u32tmp == 0x01) { 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()
703 m88ds3103b_select_mclk(dev); in m88ds3103_set_frontend()
704 m88ds3103b_set_mclk(dev, target_mclk / 1000); 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()
742 u8tmp1 = 0x02; /* 0b10 */ in m88ds3103_set_frontend()
743 u8tmp2 = 0x01; /* 0b01 */ in m88ds3103_set_frontend()
746 u8tmp1 = 0x00; /* 0b00 */ in m88ds3103_set_frontend()
747 u8tmp2 = 0x01; /* 0b01 */ in m88ds3103_set_frontend()
750 u8tmp1 = 0x03; /* 0b11 */ in m88ds3103_set_frontend()
751 u8tmp2 = 0x00; /* 0b00 */ in m88ds3103_set_frontend()
754 ret = m88ds3103_update_bits(dev, 0x22, 0xc0, u8tmp1 << 6); in m88ds3103_set_frontend()
757 ret = m88ds3103_update_bits(dev, 0x24, 0xc0, u8tmp2 << 6); 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()
797 ret = m88ds3103_wr_reg_val_tab(dev, init, len); 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()
808 buf[0] = 0x09; in m88ds3103_set_frontend()
809 buf[1] = 0x22; in m88ds3103_set_frontend()
810 buf[2] = 0x88; in m88ds3103_set_frontend()
811 ret = regmap_bulk_write(dev->regmap, 0x8a, buf, 3); in m88ds3103_set_frontend()
815 ret = m88ds3103_update_bits(dev, 0x9d, 0x08, 0x08); in m88ds3103_set_frontend()
819 if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { in m88ds3103_set_frontend()
820 buf[0] = m88ds3103b_dt_read(dev, 0x15); in m88ds3103_set_frontend()
821 buf[1] = m88ds3103b_dt_read(dev, 0x16); in m88ds3103_set_frontend()
823 if (c->symbol_rate > 45010000) { in m88ds3103_set_frontend()
824 buf[0] &= ~0x03; in m88ds3103_set_frontend()
825 buf[0] |= 0x02; 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()
831 buf[0] &= ~0x03; 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()
837 m88ds3103b_dt_write(dev, 0x15, buf[0]); in m88ds3103_set_frontend()
838 m88ds3103b_dt_write(dev, 0x16, buf[1]); in m88ds3103_set_frontend()
840 regmap_read(dev->regmap, 0x30, &u32tmp); in m88ds3103_set_frontend()
841 u32tmp &= ~0x80; 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()
850 ret = m88ds3103_update_bits(dev, 0x30, 0x80, 0x80); in m88ds3103_set_frontend()
856 switch (dev->cfg->ts_mode) { in m88ds3103_set_frontend()
858 u8tmp1 = 0x00; in m88ds3103_set_frontend()
859 u8tmp = 0x06; in m88ds3103_set_frontend()
862 u8tmp1 = 0x20; in m88ds3103_set_frontend()
863 u8tmp = 0x06; in m88ds3103_set_frontend()
866 u8tmp = 0x02; in m88ds3103_set_frontend()
867 if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { in m88ds3103_set_frontend()
868 u8tmp = 0x01; in m88ds3103_set_frontend()
869 u8tmp1 = 0x01; in m88ds3103_set_frontend()
873 u8tmp = 0x03; 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()
882 u8tmp |= 0x40; 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()
892 ret = m88ds3103_update_bits(dev, 0x29, 0x20, u8tmp1); in m88ds3103_set_frontend()
895 u16tmp = 0; in m88ds3103_set_frontend()
896 u8tmp1 = 0x3f; in m88ds3103_set_frontend()
897 u8tmp2 = 0x3f; in m88ds3103_set_frontend()
900 if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { in m88ds3103_set_frontend()
901 ret = m88ds3103_update_bits(dev, 0x29, 0x01, u8tmp1); 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()
915 /* u8tmp1[5:2] => fe[3:0], u8tmp1[1:0] => ea[7:6] */ in m88ds3103_set_frontend()
916 /* u8tmp2[5:0] => ea[5:0] */ in m88ds3103_set_frontend()
917 u8tmp = (u8tmp1 >> 2) & 0x0f; in m88ds3103_set_frontend()
918 ret = regmap_update_bits(dev->regmap, 0xfe, 0x0f, u8tmp); in m88ds3103_set_frontend()
921 u8tmp = ((u8tmp1 & 0x03) << 6) | u8tmp2 >> 0; 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()
927 u8tmp = 0x20; in m88ds3103_set_frontend()
928 else if (c->symbol_rate <= 10000000) in m88ds3103_set_frontend()
929 u8tmp = 0x10; in m88ds3103_set_frontend()
931 u8tmp = 0x06; in m88ds3103_set_frontend()
933 if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) in m88ds3103_set_frontend()
934 m88ds3103b_set_mclk(dev, target_mclk / 1000); 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()
953 buf[0] = (u16tmp >> 0) & 0xff; in m88ds3103_set_frontend()
954 buf[1] = (u16tmp >> 8) & 0xff; 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()
973 ret = m88ds3103_update_bits(dev, 0x29, 0x10, in m88ds3103_set_frontend()
974 (c->delivery_system == SYS_DVBS) ? 0x10 : 0x0); in m88ds3103_set_frontend()
978 ret = m88ds3103_update_bits(dev, 0xc9, 0x08, 0x08); 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()
989 buf[0] = (s32tmp >> 0) & 0xff; in m88ds3103_set_frontend()
990 buf[1] = (s32tmp >> 8) & 0xff; 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 dev->delivery_system = c->delivery_system; in m88ds3103_set_frontend()
1005 return 0; in m88ds3103_set_frontend()
1007 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_set_frontend()
1013 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_init() local
1014 struct i2c_client *client = dev->client; in m88ds3103_init()
1015 struct dtv_frontend_properties *c = &fe->dtv_property_cache; in m88ds3103_init()
1021 dev_dbg(&client->dev, "\n"); in m88ds3103_init()
1024 dev->warm = false; in m88ds3103_init()
1027 ret = m88ds3103_update_bits(dev, 0x08, 0x01, 0x01); in m88ds3103_init()
1030 ret = m88ds3103_update_bits(dev, 0x04, 0x01, 0x00); in m88ds3103_init()
1033 ret = m88ds3103_update_bits(dev, 0x23, 0x10, 0x00); in m88ds3103_init()
1038 ret = regmap_read(dev->regmap, 0xb9, &utmp); in m88ds3103_init()
1042 dev_dbg(&client->dev, "firmware=%02x\n", utmp); in m88ds3103_init()
1048 ret = regmap_write(dev->regmap, 0x07, 0xe0); in m88ds3103_init()
1051 ret = regmap_write(dev->regmap, 0x07, 0x00); in m88ds3103_init()
1055 /* cold state - try to download firmware */ in m88ds3103_init()
1056 dev_info(&client->dev, "found a '%s' in cold state\n", in m88ds3103_init()
1057 dev->fe.ops.info.name); in m88ds3103_init()
1059 if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) in m88ds3103_init()
1061 else if (dev->chip_id == M88RS6000_CHIP_ID) in m88ds3103_init()
1067 ret = request_firmware(&firmware, name, &client->dev); in m88ds3103_init()
1069 dev_err(&client->dev, "firmware file '%s' not found\n", name); in m88ds3103_init()
1073 dev_info(&client->dev, "downloading firmware from file '%s'\n", name); in m88ds3103_init()
1075 ret = regmap_write(dev->regmap, 0xb2, 0x01); in m88ds3103_init()
1079 for (rem = firmware->size; rem > 0; rem -= (dev->cfg->i2c_wr_max - 1)) { in m88ds3103_init()
1080 len = min(dev->cfg->i2c_wr_max - 1, rem); in m88ds3103_init()
1081 ret = regmap_bulk_write(dev->regmap, 0xb0, in m88ds3103_init()
1082 &firmware->data[firmware->size - rem], in m88ds3103_init()
1085 dev_err(&client->dev, "firmware download failed %d\n", in m88ds3103_init()
1091 ret = regmap_write(dev->regmap, 0xb2, 0x00); in m88ds3103_init()
1097 ret = regmap_read(dev->regmap, 0xb9, &utmp); in m88ds3103_init()
1102 ret = -EINVAL; in m88ds3103_init()
1103 dev_info(&client->dev, "firmware did not run\n"); in m88ds3103_init()
1107 dev_info(&client->dev, "found a '%s' in warm state\n", in m88ds3103_init()
1108 dev->fe.ops.info.name); in m88ds3103_init()
1109 dev_info(&client->dev, "firmware version: %X.%X\n", in m88ds3103_init()
1110 (utmp >> 4) & 0xf, (utmp >> 0 & 0xf)); in m88ds3103_init()
1112 if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { in m88ds3103_init()
1113 m88ds3103b_dt_write(dev, 0x21, 0x92); in m88ds3103_init()
1114 m88ds3103b_dt_write(dev, 0x15, 0x6C); in m88ds3103_init()
1115 m88ds3103b_dt_write(dev, 0x17, 0xC1); in m88ds3103_init()
1116 m88ds3103b_dt_write(dev, 0x17, 0x81); in m88ds3103_init()
1120 dev->warm = true; in m88ds3103_init()
1123 c->cnr.len = 1; in m88ds3103_init()
1124 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; in m88ds3103_init()
1125 c->post_bit_error.len = 1; in m88ds3103_init()
1126 c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; in m88ds3103_init()
1127 c->post_bit_count.len = 1; in m88ds3103_init()
1128 c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; in m88ds3103_init()
1130 return 0; in m88ds3103_init()
1134 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_init()
1140 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_sleep() local
1141 struct i2c_client *client = dev->client; in m88ds3103_sleep()
1145 dev_dbg(&client->dev, "\n"); in m88ds3103_sleep()
1147 dev->fe_status = 0; in m88ds3103_sleep()
1148 dev->delivery_system = SYS_UNDEFINED; in m88ds3103_sleep()
1150 /* TS Hi-Z */ in m88ds3103_sleep()
1151 if (dev->chip_id == M88RS6000_CHIP_ID) in m88ds3103_sleep()
1152 utmp = 0x29; in m88ds3103_sleep()
1154 utmp = 0x27; in m88ds3103_sleep()
1155 ret = m88ds3103_update_bits(dev, utmp, 0x01, 0x00); in m88ds3103_sleep()
1160 ret = m88ds3103_update_bits(dev, 0x08, 0x01, 0x00); in m88ds3103_sleep()
1163 ret = m88ds3103_update_bits(dev, 0x04, 0x01, 0x01); in m88ds3103_sleep()
1166 ret = m88ds3103_update_bits(dev, 0x23, 0x10, 0x10); in m88ds3103_sleep()
1170 return 0; in m88ds3103_sleep()
1172 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_sleep()
1179 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_get_frontend() local
1180 struct i2c_client *client = dev->client; in m88ds3103_get_frontend()
1184 dev_dbg(&client->dev, "\n"); in m88ds3103_get_frontend()
1186 if (!dev->warm || !(dev->fe_status & FE_HAS_LOCK)) { in m88ds3103_get_frontend()
1187 ret = 0; in m88ds3103_get_frontend()
1191 switch (c->delivery_system) { in m88ds3103_get_frontend()
1193 ret = regmap_bulk_read(dev->regmap, 0xe0, &buf[0], 1); in m88ds3103_get_frontend()
1197 ret = regmap_bulk_read(dev->regmap, 0xe6, &buf[1], 1); in m88ds3103_get_frontend()
1201 switch ((buf[0] >> 2) & 0x01) { in m88ds3103_get_frontend()
1202 case 0: in m88ds3103_get_frontend()
1203 c->inversion = INVERSION_OFF; in m88ds3103_get_frontend()
1206 c->inversion = INVERSION_ON; in m88ds3103_get_frontend()
1210 switch ((buf[1] >> 5) & 0x07) { in m88ds3103_get_frontend()
1211 case 0: in m88ds3103_get_frontend()
1212 c->fec_inner = FEC_7_8; in m88ds3103_get_frontend()
1215 c->fec_inner = FEC_5_6; in m88ds3103_get_frontend()
1218 c->fec_inner = FEC_3_4; in m88ds3103_get_frontend()
1221 c->fec_inner = FEC_2_3; in m88ds3103_get_frontend()
1224 c->fec_inner = FEC_1_2; in m88ds3103_get_frontend()
1227 dev_dbg(&client->dev, "invalid fec_inner\n"); in m88ds3103_get_frontend()
1230 c->modulation = QPSK; in m88ds3103_get_frontend()
1234 ret = regmap_bulk_read(dev->regmap, 0x7e, &buf[0], 1); in m88ds3103_get_frontend()
1238 ret = regmap_bulk_read(dev->regmap, 0x89, &buf[1], 1); in m88ds3103_get_frontend()
1242 ret = regmap_bulk_read(dev->regmap, 0xf2, &buf[2], 1); in m88ds3103_get_frontend()
1246 switch ((buf[0] >> 0) & 0x0f) { in m88ds3103_get_frontend()
1248 c->fec_inner = FEC_2_5; in m88ds3103_get_frontend()
1251 c->fec_inner = FEC_1_2; in m88ds3103_get_frontend()
1254 c->fec_inner = FEC_3_5; in m88ds3103_get_frontend()
1257 c->fec_inner = FEC_2_3; in m88ds3103_get_frontend()
1260 c->fec_inner = FEC_3_4; in m88ds3103_get_frontend()
1263 c->fec_inner = FEC_4_5; in m88ds3103_get_frontend()
1266 c->fec_inner = FEC_5_6; in m88ds3103_get_frontend()
1269 c->fec_inner = FEC_8_9; in m88ds3103_get_frontend()
1272 c->fec_inner = FEC_9_10; in m88ds3103_get_frontend()
1275 dev_dbg(&client->dev, "invalid fec_inner\n"); in m88ds3103_get_frontend()
1278 switch ((buf[0] >> 5) & 0x01) { in m88ds3103_get_frontend()
1279 case 0: in m88ds3103_get_frontend()
1280 c->pilot = PILOT_OFF; in m88ds3103_get_frontend()
1283 c->pilot = PILOT_ON; in m88ds3103_get_frontend()
1287 switch ((buf[0] >> 6) & 0x07) { in m88ds3103_get_frontend()
1288 case 0: in m88ds3103_get_frontend()
1289 c->modulation = QPSK; in m88ds3103_get_frontend()
1292 c->modulation = PSK_8; in m88ds3103_get_frontend()
1295 c->modulation = APSK_16; in m88ds3103_get_frontend()
1298 c->modulation = APSK_32; in m88ds3103_get_frontend()
1301 dev_dbg(&client->dev, "invalid modulation\n"); in m88ds3103_get_frontend()
1304 switch ((buf[1] >> 7) & 0x01) { in m88ds3103_get_frontend()
1305 case 0: in m88ds3103_get_frontend()
1306 c->inversion = INVERSION_OFF; in m88ds3103_get_frontend()
1309 c->inversion = INVERSION_ON; in m88ds3103_get_frontend()
1313 switch ((buf[2] >> 0) & 0x03) { in m88ds3103_get_frontend()
1314 case 0: in m88ds3103_get_frontend()
1315 c->rolloff = ROLLOFF_35; in m88ds3103_get_frontend()
1318 c->rolloff = ROLLOFF_25; in m88ds3103_get_frontend()
1321 c->rolloff = ROLLOFF_20; in m88ds3103_get_frontend()
1324 dev_dbg(&client->dev, "invalid rolloff\n"); in m88ds3103_get_frontend()
1328 dev_dbg(&client->dev, "invalid delivery_system\n"); in m88ds3103_get_frontend()
1329 ret = -EINVAL; in m88ds3103_get_frontend()
1333 ret = regmap_bulk_read(dev->regmap, 0x6d, buf, 2); in m88ds3103_get_frontend()
1337 c->symbol_rate = DIV_ROUND_CLOSEST_ULL((u64)(buf[1] << 8 | buf[0] << 0) * dev->mclk, 0x10000); in m88ds3103_get_frontend()
1339 return 0; in m88ds3103_get_frontend()
1341 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_get_frontend()
1347 struct dtv_frontend_properties *c = &fe->dtv_property_cache; in m88ds3103_read_snr()
1349 if (c->cnr.stat[0].scale == FE_SCALE_DECIBEL) in m88ds3103_read_snr()
1350 *snr = div_s64(c->cnr.stat[0].svalue, 100); in m88ds3103_read_snr()
1352 *snr = 0; in m88ds3103_read_snr()
1354 return 0; in m88ds3103_read_snr()
1359 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_read_ber() local
1361 *ber = dev->dvbv3_ber; in m88ds3103_read_ber()
1363 return 0; in m88ds3103_read_ber()
1369 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_set_tone() local
1370 struct i2c_client *client = dev->client; in m88ds3103_set_tone()
1374 dev_dbg(&client->dev, "fe_sec_tone_mode=%d\n", fe_sec_tone_mode); in m88ds3103_set_tone()
1376 if (!dev->warm) { in m88ds3103_set_tone()
1377 ret = -EAGAIN; in m88ds3103_set_tone()
1383 tone = 0; in m88ds3103_set_tone()
1384 reg_a1_mask = 0x47; in m88ds3103_set_tone()
1388 reg_a1_mask = 0x00; in m88ds3103_set_tone()
1391 dev_dbg(&client->dev, "invalid fe_sec_tone_mode\n"); in m88ds3103_set_tone()
1392 ret = -EINVAL; in m88ds3103_set_tone()
1396 utmp = tone << 7 | dev->cfg->envelope_mode << 5; in m88ds3103_set_tone()
1397 ret = m88ds3103_update_bits(dev, 0xa2, 0xe0, utmp); in m88ds3103_set_tone()
1402 ret = m88ds3103_update_bits(dev, 0xa1, reg_a1_mask, utmp); in m88ds3103_set_tone()
1406 return 0; in m88ds3103_set_tone()
1408 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_set_tone()
1415 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_set_voltage() local
1416 struct i2c_client *client = dev->client; in m88ds3103_set_voltage()
1421 dev_dbg(&client->dev, "fe_sec_voltage=%d\n", fe_sec_voltage); in m88ds3103_set_voltage()
1423 if (!dev->warm) { in m88ds3103_set_voltage()
1424 ret = -EAGAIN; in m88ds3103_set_voltage()
1442 dev_dbg(&client->dev, "invalid fe_sec_voltage\n"); in m88ds3103_set_voltage()
1443 ret = -EINVAL; in m88ds3103_set_voltage()
1448 voltage_sel ^= dev->cfg->lnb_hv_pol; in m88ds3103_set_voltage()
1449 voltage_dis ^= dev->cfg->lnb_en_pol; in m88ds3103_set_voltage()
1451 utmp = voltage_dis << 1 | voltage_sel << 0; in m88ds3103_set_voltage()
1452 ret = m88ds3103_update_bits(dev, 0xa2, 0x03, utmp); in m88ds3103_set_voltage()
1456 return 0; in m88ds3103_set_voltage()
1458 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_set_voltage()
1465 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_diseqc_send_master_cmd() local
1466 struct i2c_client *client = dev->client; in m88ds3103_diseqc_send_master_cmd()
1471 dev_dbg(&client->dev, "msg=%*ph\n", in m88ds3103_diseqc_send_master_cmd()
1472 diseqc_cmd->msg_len, diseqc_cmd->msg); in m88ds3103_diseqc_send_master_cmd()
1474 if (!dev->warm) { in m88ds3103_diseqc_send_master_cmd()
1475 ret = -EAGAIN; in m88ds3103_diseqc_send_master_cmd()
1479 if (diseqc_cmd->msg_len < 3 || diseqc_cmd->msg_len > 6) { in m88ds3103_diseqc_send_master_cmd()
1480 ret = -EINVAL; in m88ds3103_diseqc_send_master_cmd()
1484 utmp = dev->cfg->envelope_mode << 5; in m88ds3103_diseqc_send_master_cmd()
1485 ret = m88ds3103_update_bits(dev, 0xa2, 0xe0, utmp); in m88ds3103_diseqc_send_master_cmd()
1489 ret = regmap_bulk_write(dev->regmap, 0xa3, diseqc_cmd->msg, in m88ds3103_diseqc_send_master_cmd()
1490 diseqc_cmd->msg_len); in m88ds3103_diseqc_send_master_cmd()
1494 ret = regmap_write(dev->regmap, 0xa1, in m88ds3103_diseqc_send_master_cmd()
1495 (diseqc_cmd->msg_len - 1) << 3 | 0x07); in m88ds3103_diseqc_send_master_cmd()
1504 utmp = diseqc_cmd->msg_len * 13500; in m88ds3103_diseqc_send_master_cmd()
1505 usleep_range(utmp - 4000, utmp); in m88ds3103_diseqc_send_master_cmd()
1508 ret = regmap_read(dev->regmap, 0xa1, &utmp); in m88ds3103_diseqc_send_master_cmd()
1511 utmp = (utmp >> 6) & 0x1; in m88ds3103_diseqc_send_master_cmd()
1514 if (utmp == 0) { in m88ds3103_diseqc_send_master_cmd()
1515 dev_dbg(&client->dev, "diseqc tx took %u ms\n", in m88ds3103_diseqc_send_master_cmd()
1516 jiffies_to_msecs(jiffies) - in m88ds3103_diseqc_send_master_cmd()
1517 (jiffies_to_msecs(timeout) - SEND_MASTER_CMD_TIMEOUT)); in m88ds3103_diseqc_send_master_cmd()
1519 dev_dbg(&client->dev, "diseqc tx timeout\n"); in m88ds3103_diseqc_send_master_cmd()
1521 ret = m88ds3103_update_bits(dev, 0xa1, 0xc0, 0x40); in m88ds3103_diseqc_send_master_cmd()
1526 ret = m88ds3103_update_bits(dev, 0xa2, 0xc0, 0x80); in m88ds3103_diseqc_send_master_cmd()
1531 ret = -ETIMEDOUT; in m88ds3103_diseqc_send_master_cmd()
1535 return 0; in m88ds3103_diseqc_send_master_cmd()
1537 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_diseqc_send_master_cmd()
1544 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_diseqc_send_burst() local
1545 struct i2c_client *client = dev->client; in m88ds3103_diseqc_send_burst()
1550 dev_dbg(&client->dev, "fe_sec_mini_cmd=%d\n", fe_sec_mini_cmd); in m88ds3103_diseqc_send_burst()
1552 if (!dev->warm) { in m88ds3103_diseqc_send_burst()
1553 ret = -EAGAIN; in m88ds3103_diseqc_send_burst()
1557 utmp = dev->cfg->envelope_mode << 5; in m88ds3103_diseqc_send_burst()
1558 ret = m88ds3103_update_bits(dev, 0xa2, 0xe0, utmp); in m88ds3103_diseqc_send_burst()
1564 burst = 0x02; in m88ds3103_diseqc_send_burst()
1567 burst = 0x01; in m88ds3103_diseqc_send_burst()
1570 dev_dbg(&client->dev, "invalid fe_sec_mini_cmd\n"); in m88ds3103_diseqc_send_burst()
1571 ret = -EINVAL; in m88ds3103_diseqc_send_burst()
1575 ret = regmap_write(dev->regmap, 0xa1, burst); in m88ds3103_diseqc_send_burst()
1587 ret = regmap_read(dev->regmap, 0xa1, &utmp); in m88ds3103_diseqc_send_burst()
1590 utmp = (utmp >> 6) & 0x1; in m88ds3103_diseqc_send_burst()
1593 if (utmp == 0) { in m88ds3103_diseqc_send_burst()
1594 dev_dbg(&client->dev, "diseqc tx took %u ms\n", in m88ds3103_diseqc_send_burst()
1595 jiffies_to_msecs(jiffies) - in m88ds3103_diseqc_send_burst()
1596 (jiffies_to_msecs(timeout) - SEND_BURST_TIMEOUT)); in m88ds3103_diseqc_send_burst()
1598 dev_dbg(&client->dev, "diseqc tx timeout\n"); in m88ds3103_diseqc_send_burst()
1600 ret = m88ds3103_update_bits(dev, 0xa1, 0xc0, 0x40); in m88ds3103_diseqc_send_burst()
1605 ret = m88ds3103_update_bits(dev, 0xa2, 0xc0, 0x80); in m88ds3103_diseqc_send_burst()
1610 ret = -ETIMEDOUT; in m88ds3103_diseqc_send_burst()
1614 return 0; in m88ds3103_diseqc_send_burst()
1616 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_diseqc_send_burst()
1623 s->min_delay_ms = 3000; in m88ds3103_get_tune_settings()
1625 return 0; in m88ds3103_get_tune_settings()
1630 struct m88ds3103_dev *dev = fe->demodulator_priv; in m88ds3103_release() local
1631 struct i2c_client *client = dev->client; in m88ds3103_release()
1638 struct m88ds3103_dev *dev = i2c_mux_priv(muxc); in m88ds3103_select() local
1639 struct i2c_client *client = dev->client; in m88ds3103_select()
1642 .addr = client->addr, in m88ds3103_select()
1643 .flags = 0, in m88ds3103_select()
1649 ret = __i2c_transfer(client->adapter, &msg, 1); in m88ds3103_select()
1651 dev_warn(&client->dev, "i2c wr failed=%d\n", ret); in m88ds3103_select()
1652 if (ret >= 0) in m88ds3103_select()
1653 ret = -EREMOTEIO; in m88ds3103_select()
1657 return 0; in m88ds3103_select()
1673 pdata.clk = cfg->clock; in m88ds3103_attach()
1674 pdata.i2c_wr_max = cfg->i2c_wr_max; in m88ds3103_attach()
1675 pdata.ts_mode = cfg->ts_mode; in m88ds3103_attach()
1676 pdata.ts_clk = cfg->ts_clk; in m88ds3103_attach()
1677 pdata.ts_clk_pol = cfg->ts_clk_pol; in m88ds3103_attach()
1678 pdata.spec_inv = cfg->spec_inv; in m88ds3103_attach()
1679 pdata.agc = cfg->agc; in m88ds3103_attach()
1680 pdata.agc_inv = cfg->agc_inv; in m88ds3103_attach()
1681 pdata.clk_out = cfg->clock_out; in m88ds3103_attach()
1682 pdata.envelope_mode = cfg->envelope_mode; in m88ds3103_attach()
1683 pdata.lnb_hv_pol = cfg->lnb_hv_pol; in m88ds3103_attach()
1684 pdata.lnb_en_pol = cfg->lnb_en_pol; in m88ds3103_attach()
1687 memset(&board_info, 0, sizeof(board_info)); in m88ds3103_attach()
1689 board_info.addr = cfg->i2c_addr; in m88ds3103_attach()
1747 struct m88ds3103_dev *dev = i2c_get_clientdata(client); in m88ds3103_get_dvb_frontend() local
1749 dev_dbg(&client->dev, "\n"); in m88ds3103_get_dvb_frontend()
1751 return &dev->fe; in m88ds3103_get_dvb_frontend()
1756 struct m88ds3103_dev *dev = i2c_get_clientdata(client); in m88ds3103_get_i2c_adapter() local
1758 dev_dbg(&client->dev, "\n"); in m88ds3103_get_i2c_adapter()
1760 return dev->muxc->adapter[0]; in m88ds3103_get_i2c_adapter()
1766 struct m88ds3103_dev *dev; in m88ds3103_probe() local
1767 struct m88ds3103_platform_data *pdata = client->dev.platform_data; in m88ds3103_probe()
1771 dev = kzalloc(sizeof(*dev), GFP_KERNEL); in m88ds3103_probe()
1772 if (!dev) { in m88ds3103_probe()
1773 ret = -ENOMEM; in m88ds3103_probe()
1777 dev->client = client; in m88ds3103_probe()
1778 dev->config.clock = pdata->clk; in m88ds3103_probe()
1779 dev->config.i2c_wr_max = pdata->i2c_wr_max; in m88ds3103_probe()
1780 dev->config.ts_mode = pdata->ts_mode; in m88ds3103_probe()
1781 dev->config.ts_clk = pdata->ts_clk * 1000; in m88ds3103_probe()
1782 dev->config.ts_clk_pol = pdata->ts_clk_pol; in m88ds3103_probe()
1783 dev->config.spec_inv = pdata->spec_inv; in m88ds3103_probe()
1784 dev->config.agc_inv = pdata->agc_inv; in m88ds3103_probe()
1785 dev->config.clock_out = pdata->clk_out; in m88ds3103_probe()
1786 dev->config.envelope_mode = pdata->envelope_mode; in m88ds3103_probe()
1787 dev->config.agc = pdata->agc; in m88ds3103_probe()
1788 dev->config.lnb_hv_pol = pdata->lnb_hv_pol; in m88ds3103_probe()
1789 dev->config.lnb_en_pol = pdata->lnb_en_pol; in m88ds3103_probe()
1790 dev->cfg = &dev->config; in m88ds3103_probe()
1792 dev->regmap_config.reg_bits = 8; in m88ds3103_probe()
1793 dev->regmap_config.val_bits = 8; in m88ds3103_probe()
1794 dev->regmap_config.lock_arg = dev; in m88ds3103_probe()
1795 dev->regmap = devm_regmap_init_i2c(client, &dev->regmap_config); in m88ds3103_probe()
1796 if (IS_ERR(dev->regmap)) { in m88ds3103_probe()
1797 ret = PTR_ERR(dev->regmap); in m88ds3103_probe()
1801 /* 0x00: chip id[6:0], 0x01: chip ver[7:0], 0x02: chip ver[15:8] */ in m88ds3103_probe()
1802 ret = regmap_read(dev->regmap, 0x00, &utmp); in m88ds3103_probe()
1806 dev->chip_id = utmp >> 1; in m88ds3103_probe()
1807 dev->chiptype = (u8)id->driver_data; in m88ds3103_probe()
1809 dev_dbg(&client->dev, "chip_id=%02x\n", dev->chip_id); in m88ds3103_probe()
1811 switch (dev->chip_id) { in m88ds3103_probe()
1816 ret = -ENODEV; in m88ds3103_probe()
1817 dev_err(&client->dev, "Unknown device. Chip_id=%02x\n", dev->chip_id); in m88ds3103_probe()
1821 switch (dev->cfg->clock_out) { in m88ds3103_probe()
1823 utmp = 0x80; in m88ds3103_probe()
1826 utmp = 0x00; in m88ds3103_probe()
1829 utmp = 0x10; in m88ds3103_probe()
1832 ret = -EINVAL; in m88ds3103_probe()
1836 if (!pdata->ts_clk) { in m88ds3103_probe()
1837 ret = -EINVAL; in m88ds3103_probe()
1841 /* 0x29 register is defined differently for m88rs6000. */ in m88ds3103_probe()
1842 /* set internal tuner address to 0x21 */ in m88ds3103_probe()
1843 if (dev->chip_id == M88RS6000_CHIP_ID) in m88ds3103_probe()
1844 utmp = 0x00; in m88ds3103_probe()
1846 ret = regmap_write(dev->regmap, 0x29, utmp); in m88ds3103_probe()
1851 ret = m88ds3103_update_bits(dev, 0x08, 0x01, 0x00); in m88ds3103_probe()
1854 ret = m88ds3103_update_bits(dev, 0x04, 0x01, 0x01); in m88ds3103_probe()
1857 ret = m88ds3103_update_bits(dev, 0x23, 0x10, 0x10); in m88ds3103_probe()
1862 dev->muxc = i2c_mux_alloc(client->adapter, &client->dev, 1, 0, 0, in m88ds3103_probe()
1864 if (!dev->muxc) { in m88ds3103_probe()
1865 ret = -ENOMEM; in m88ds3103_probe()
1868 dev->muxc->priv = dev; in m88ds3103_probe()
1869 ret = i2c_mux_add_adapter(dev->muxc, 0, 0, 0); in m88ds3103_probe()
1874 memcpy(&dev->fe.ops, &m88ds3103_ops, sizeof(struct dvb_frontend_ops)); in m88ds3103_probe()
1875 if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) in m88ds3103_probe()
1876 strscpy(dev->fe.ops.info.name, "Montage Technology M88DS3103B", in m88ds3103_probe()
1877 sizeof(dev->fe.ops.info.name)); in m88ds3103_probe()
1878 else if (dev->chip_id == M88RS6000_CHIP_ID) in m88ds3103_probe()
1879 strscpy(dev->fe.ops.info.name, "Montage Technology M88RS6000", in m88ds3103_probe()
1880 sizeof(dev->fe.ops.info.name)); in m88ds3103_probe()
1881 if (!pdata->attach_in_use) in m88ds3103_probe()
1882 dev->fe.ops.release = NULL; in m88ds3103_probe()
1883 dev->fe.demodulator_priv = dev; in m88ds3103_probe()
1884 i2c_set_clientdata(client, dev); in m88ds3103_probe()
1887 pdata->get_dvb_frontend = m88ds3103_get_dvb_frontend; in m88ds3103_probe()
1888 pdata->get_i2c_adapter = m88ds3103_get_i2c_adapter; in m88ds3103_probe()
1890 if (dev->chiptype == M88DS3103_CHIPTYPE_3103B) { in m88ds3103_probe()
1892 m88ds3103_update_bits(dev, 0x11, 0x01, 0x01); in m88ds3103_probe()
1895 ret = regmap_read(dev->regmap, 0x29, &utmp); in m88ds3103_probe()
1898 dev->dt_addr = ((utmp & 0x80) == 0) ? 0x42 >> 1 : 0x40 >> 1; in m88ds3103_probe()
1899 dev_dbg(&client->dev, "dt addr is 0x%02x\n", dev->dt_addr); in m88ds3103_probe()
1901 dev->dt_client = i2c_new_dummy_device(client->adapter, in m88ds3103_probe()
1902 dev->dt_addr); in m88ds3103_probe()
1903 if (IS_ERR(dev->dt_client)) { in m88ds3103_probe()
1904 ret = PTR_ERR(dev->dt_client); in m88ds3103_probe()
1909 return 0; in m88ds3103_probe()
1912 i2c_mux_del_adapters(dev->muxc); in m88ds3103_probe()
1914 kfree(dev); in m88ds3103_probe()
1916 dev_dbg(&client->dev, "failed=%d\n", ret); in m88ds3103_probe()
1922 struct m88ds3103_dev *dev = i2c_get_clientdata(client); in m88ds3103_remove() local
1924 dev_dbg(&client->dev, "\n"); in m88ds3103_remove()
1926 if (dev->dt_client) in m88ds3103_remove()
1927 i2c_unregister_device(dev->dt_client); in m88ds3103_remove()
1929 i2c_mux_del_adapters(dev->muxc); in m88ds3103_remove()
1931 kfree(dev); in m88ds3103_remove()
1955 MODULE_DESCRIPTION("Montage Technology M88DS3103 DVB-S/S2 demodulator driver");