32 .addr = priv->
cfg.i2c_addr,
48 "%s: i2c wr failed=%d reg=%02x len=%d\n",
49 KBUILD_MODNAME, ret, reg, len);
57 static int hd29l2_rd_regs(
struct hd29l2_priv *priv,
u8 reg,
u8 *val,
int len)
60 u8 buf[2] = { 0x00, reg };
68 .addr = priv->
cfg.i2c_addr,
80 "%s: i2c rd failed=%d reg=%02x len=%d\n",
81 KBUILD_MODNAME, ret, reg, len);
91 return hd29l2_wr_regs(priv, reg, &val, 1);
97 return hd29l2_rd_regs(priv, reg, val, 1);
108 ret = hd29l2_rd_regs(priv, reg, &tmp, 1);
117 return hd29l2_wr_regs(priv, reg, &val, 1);
126 ret = hd29l2_rd_regs(priv, reg, &tmp, 1);
133 for (i = 0; i < 8; i++) {
134 if ((mask >> i) & 0x01)
142 static int hd29l2_soft_reset(
struct hd29l2_priv *priv)
147 ret = hd29l2_rd_reg(priv, 0x26, &tmp);
151 ret = hd29l2_wr_reg(priv, 0x26, 0x0d);
157 ret = hd29l2_wr_reg(priv, 0x26, tmp);
163 dev_dbg(&priv->
i2c->dev,
"%s: failed=%d\n", __func__, ret);
173 dev_dbg(&priv->
i2c->dev,
"%s: enable=%d\n", __func__, enable);
178 ret = hd29l2_wr_reg(priv, 0x9d, priv->
cfg.tuner_i2c_addr << 1);
186 ret = hd29l2_wr_reg(priv, 0x9f, enable);
191 for (i = 10;
i; i--) {
192 ret = hd29l2_rd_reg(priv, 0x9e, &tmp);
202 dev_dbg(&priv->
i2c->dev,
"%s: loop=%d\n", __func__, i);
206 dev_dbg(&priv->
i2c->dev,
"%s: failed=%d\n", __func__, ret);
218 ret = hd29l2_rd_reg(priv, 0x05, &buf[0]);
227 ret = hd29l2_rd_reg(priv, 0x0d, &buf[1]);
231 if ((buf[1] & 0xfe) == 0x78)
241 dev_dbg(&priv->
i2c->dev,
"%s: failed=%d\n", __func__, ret);
258 ret = hd29l2_rd_regs(priv, 0x0b, buf, 2);
262 tmp = (buf[0] << 8) | buf[1];
265 #define LOG10_20736_24 72422627
273 dev_dbg(&priv->
i2c->dev,
"%s: failed=%d\n", __func__, ret);
277 static int hd29l2_read_signal_strength(
struct dvb_frontend *fe,
u16 *strength)
286 ret = hd29l2_rd_regs(priv, 0xd5, buf, 2);
290 tmp = buf[0] << 8 | buf[1];
294 *strength = tmp * 0xffff / 0x0fff;
298 dev_dbg(&priv->
i2c->dev,
"%s: failed=%d\n", __func__, ret);
314 ret = hd29l2_rd_regs(priv, 0xd9, buf, 2);
321 *ber = ((buf[0] & 0x0f) << 8) | buf[1];
325 dev_dbg(&priv->
i2c->dev,
"%s: failed=%d\n", __func__, ret);
329 static int hd29l2_read_ucblocks(
struct dvb_frontend *fe,
u32 *ucblocks)
347 dev_dbg(&priv->
i2c->dev,
"%s: delivery_system=%d frequency=%d " \
348 "bandwidth_hz=%d modulation=%d inversion=%d " \
349 "fec_inner=%d guard_interval=%d\n", __func__,
358 if (fe->
ops.tuner_ops.set_params)
359 fe->
ops.tuner_ops.set_params(fe);
362 if (fe->
ops.tuner_ops.get_if_frequency)
363 fe->
ops.tuner_ops.get_if_frequency(fe, &if_freq);
384 buf[0] = ((if_ctl >> 0) & 0xff);
385 buf[1] = ((if_ctl >> 8) & 0xff);
386 buf[2] = ((if_ctl >> 16) & 0xff);
389 ret = hd29l2_wr_regs(priv, 0x14, buf, 3);
394 ret = hd29l2_wr_reg(priv, 0xab, tmp);
398 dev_dbg(&priv->
i2c->dev,
"%s: if_freq=%d if_ctl=%x\n",
399 __func__, if_freq, if_ctl);
407 ret = hd29l2_wr_reg_mask(priv, 0xac, 0 << 7, 0x80);
411 ret = hd29l2_wr_reg_mask(priv, 0x82, 1 << 1, 0x02);
416 ret = hd29l2_wr_reg_mask(priv, 0x7d, 1 << 6, 0x40);
420 ret = hd29l2_wr_reg_mask(priv, 0x81, 1 << 3, 0x08);
425 ret = hd29l2_soft_reset(priv);
430 for (i = 30;
i; i--) {
433 ret = hd29l2_rd_reg(priv, 0x0d, &tmp);
437 if ((((tmp & 0xf0) >= 0x10) &&
438 ((tmp & 0x0f) == 0x08)) || (tmp >= 0x2c))
442 dev_dbg(&priv->
i2c->dev,
"%s: loop=%d\n", __func__, i);
463 tmp = (code_rate << 3) | modulation;
464 ret = hd29l2_wr_reg_mask(priv, 0x7d, tmp, 0x5f);
468 tmp = (carrier << 2) | guard_interval;
469 ret = hd29l2_wr_reg_mask(priv, 0x81, tmp, 0x0f);
474 ret = hd29l2_wr_reg_mask(priv, 0x82, tmp, 0x03);
481 if (modulation > (
ARRAY_SIZE(reg_mod_vals_tab[0].val) - 1)) {
482 dev_dbg(&priv->
i2c->dev,
"%s: modulation=%d not valid\n",
483 __func__, modulation);
488 for (i = 0; i <
ARRAY_SIZE(reg_mod_vals_tab); i++) {
489 ret = hd29l2_wr_reg(priv, reg_mod_vals_tab[i].reg,
490 reg_mod_vals_tab[i].val[modulation]);
506 "%s: modulation=%d guard_interval=%d carrier=%d\n",
507 __func__, modulation, guard_interval, carrier);
511 dev_dbg(&priv->
i2c->dev,
"%s: C=3780 && QAM64 && PN945\n",
514 ret = hd29l2_wr_reg(priv, 0x42, 0x33);
518 ret = hd29l2_wr_reg(priv, 0xdd, 0x01);
526 ret = hd29l2_soft_reset(priv);
531 for (i = 30;
i; i--) {
543 dev_dbg(&priv->
i2c->dev,
"%s: loop=%d\n", __func__, i);
550 dev_dbg(&priv->
i2c->dev,
"%s: failed=%d\n", __func__, ret);
554 static int hd29l2_get_frontend_algo(
struct dvb_frontend *fe)
566 char *str_constellation, *str_code_rate, *str_constellation_code_rate,
567 *str_guard_interval, *str_carrier, *str_guard_interval_carrier,
568 *str_interleave, *str_interleave_;
570 ret = hd29l2_rd_reg(priv, 0x7d, &buf[0]);
574 ret = hd29l2_rd_regs(priv, 0x81, &buf[1], 2);
579 switch ((buf[0] >> 0) & 0x07) {
581 str_constellation =
"QAM4NR";
585 str_constellation =
"QAM4";
589 str_constellation =
"QAM16";
593 str_constellation =
"QAM32";
597 str_constellation =
"QAM64";
601 str_constellation =
"?";
605 switch ((buf[0] >> 3) & 0x03) {
607 str_code_rate =
"0.4";
611 str_code_rate =
"0.6";
615 str_code_rate =
"0.8";
623 switch ((buf[0] >> 6) & 0x01) {
625 str_constellation_code_rate =
"manual";
628 str_constellation_code_rate =
"auto";
631 str_constellation_code_rate =
"?";
635 switch ((buf[1] >> 0) & 0x03) {
637 str_guard_interval =
"PN945";
641 str_guard_interval =
"PN595";
645 str_guard_interval =
"PN420";
649 str_guard_interval =
"?";
653 switch ((buf[1] >> 2) & 0x01) {
658 str_carrier =
"C=3780";
665 switch ((buf[1] >> 3) & 0x01) {
667 str_guard_interval_carrier =
"manual";
670 str_guard_interval_carrier =
"auto";
673 str_guard_interval_carrier =
"?";
677 switch ((buf[2] >> 0) & 0x01) {
679 str_interleave =
"M=720";
682 str_interleave =
"M=240";
685 str_interleave =
"?";
689 switch ((buf[2] >> 1) & 0x01) {
691 str_interleave_ =
"manual";
694 str_interleave_ =
"auto";
697 str_interleave_ =
"?";
706 ret = hd29l2_rd_regs(priv, 0xb1, &buf[0], 3);
710 if_ctl = (buf[0] << 16) | ((buf[1] - 7) << 8) | buf[2];
712 dev_dbg(&priv->
i2c->dev,
"%s: %s %s %s | %s %s %s | %s %s | NCO=%06x\n",
713 __func__, str_constellation, str_code_rate,
714 str_constellation_code_rate, str_guard_interval,
715 str_carrier, str_guard_interval_carrier, str_interleave,
716 str_interleave_, if_ctl);
719 dev_dbg(&priv->
i2c->dev,
"%s: failed=%d\n", __func__, ret);
728 static const struct reg_val tab[] = {
753 ret = hd29l2_wr_reg(priv, tab[i].reg, tab[i].val);
759 ret = hd29l2_rd_reg(priv, 0x36, &tmp);
764 tmp |= priv->
cfg.ts_mode;
765 ret = hd29l2_wr_reg(priv, 0x36, tmp);
769 ret = hd29l2_rd_reg(priv, 0x31, &tmp);
772 if (!(priv->
cfg.ts_mode >> 7))
776 ret = hd29l2_wr_reg(priv, 0x31, tmp);
782 dev_dbg(&priv->
i2c->dev,
"%s: failed=%d\n", __func__, ret);
812 ret = hd29l2_rd_reg(priv, 0x00, &tmp);
818 priv->
fe.demodulator_priv =
priv;
830 .name =
"HDIC HD29L2 DMB-TH",
831 .frequency_min = 474000000,
832 .frequency_max = 858000000,
833 .frequency_stepsize = 10000,
847 .release = hd29l2_release,
851 .get_frontend_algo = hd29l2_get_frontend_algo,
852 .search = hd29l2_search,
853 .get_frontend = hd29l2_get_frontend,
855 .read_status = hd29l2_read_status,
856 .read_snr = hd29l2_read_snr,
857 .read_signal_strength = hd29l2_read_signal_strength,
858 .read_ber = hd29l2_read_ber,
859 .read_ucblocks = hd29l2_read_ucblocks,
861 .i2c_gate_ctrl = hd29l2_i2c_gate_ctrl,