^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Panasonic MN88473 DVB-T/T2/C demodulator driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2014 Antti Palosaari <crope@iki.fi>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "mn88473_priv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) static int mn88473_get_tune_settings(struct dvb_frontend *fe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) struct dvb_frontend_tune_settings *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) s->min_delay_ms = 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) static int mn88473_set_frontend(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct i2c_client *client = fe->demodulator_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct mn88473_dev *dev = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct dtv_frontend_properties *c = &fe->dtv_property_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) unsigned int uitmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) u32 if_frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) u8 delivery_system_val, if_val[3], *conf_val_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) u8 reg_bank2_2d_val, reg_bank0_d2_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) dev_dbg(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) "delivery_system=%u modulation=%u frequency=%u bandwidth_hz=%u symbol_rate=%u inversion=%d stream_id=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) c->delivery_system, c->modulation, c->frequency,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) c->bandwidth_hz, c->symbol_rate, c->inversion, c->stream_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) if (!dev->active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) ret = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) switch (c->delivery_system) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) case SYS_DVBT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) delivery_system_val = 0x02;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) reg_bank2_2d_val = 0x23;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) reg_bank0_d2_val = 0x2a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) case SYS_DVBT2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) delivery_system_val = 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) reg_bank2_2d_val = 0x3b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) reg_bank0_d2_val = 0x29;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) case SYS_DVBC_ANNEX_A:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) delivery_system_val = 0x04;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) reg_bank2_2d_val = 0x3b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) reg_bank0_d2_val = 0x29;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) switch (c->delivery_system) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) case SYS_DVBT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) case SYS_DVBT2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) switch (c->bandwidth_hz) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) case 6000000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) conf_val_ptr = "\xe9\x55\x55\x1c\x29\x1c\x29";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) case 7000000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) conf_val_ptr = "\xc8\x00\x00\x17\x0a\x17\x0a";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) case 8000000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) conf_val_ptr = "\xaf\x00\x00\x11\xec\x11\xec";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) case SYS_DVBC_ANNEX_A:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) conf_val_ptr = "\x10\xab\x0d\xae\x1d\x9d";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /* Program tuner */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (fe->ops.tuner_ops.set_params) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) ret = fe->ops.tuner_ops.set_params(fe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (fe->ops.tuner_ops.get_if_frequency) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ret = fe->ops.tuner_ops.get_if_frequency(fe, &if_frequency);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) dev_dbg(&client->dev, "get_if_frequency=%u\n", if_frequency);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /* Calculate IF registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) uitmp = DIV_ROUND_CLOSEST_ULL((u64) if_frequency * 0x1000000, dev->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if_val[0] = (uitmp >> 16) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if_val[1] = (uitmp >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if_val[2] = (uitmp >> 0) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ret = regmap_write(dev->regmap[2], 0x05, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) ret = regmap_write(dev->regmap[2], 0xfb, 0x13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) ret = regmap_write(dev->regmap[2], 0xef, 0x13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) ret = regmap_write(dev->regmap[2], 0xf9, 0x13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ret = regmap_write(dev->regmap[2], 0x00, 0x18);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) ret = regmap_write(dev->regmap[2], 0x01, 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) ret = regmap_write(dev->regmap[2], 0x02, 0x21);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) ret = regmap_write(dev->regmap[2], 0x03, delivery_system_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) ret = regmap_write(dev->regmap[2], 0x0b, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) for (i = 0; i < sizeof(if_val); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) ret = regmap_write(dev->regmap[2], 0x10 + i, if_val[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) switch (c->delivery_system) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) case SYS_DVBT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) case SYS_DVBT2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) for (i = 0; i < 7; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) ret = regmap_write(dev->regmap[2], 0x13 + i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) conf_val_ptr[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) case SYS_DVBC_ANNEX_A:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) ret = regmap_bulk_write(dev->regmap[1], 0x10, conf_val_ptr, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) ret = regmap_write(dev->regmap[2], 0x2d, reg_bank2_2d_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) ret = regmap_write(dev->regmap[2], 0x2e, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) ret = regmap_write(dev->regmap[2], 0x56, 0x0d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) ret = regmap_bulk_write(dev->regmap[0], 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) "\xba\x13\x80\xba\x91\xdd\xe7\x28", 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) ret = regmap_write(dev->regmap[0], 0x0a, 0x1a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) ret = regmap_write(dev->regmap[0], 0x13, 0x1f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) ret = regmap_write(dev->regmap[0], 0x19, 0x03);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) ret = regmap_write(dev->regmap[0], 0x1d, 0xb0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) ret = regmap_write(dev->regmap[0], 0x2a, 0x72);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) ret = regmap_write(dev->regmap[0], 0x2d, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) ret = regmap_write(dev->regmap[0], 0x3c, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) ret = regmap_write(dev->regmap[0], 0x3f, 0xf8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) ret = regmap_bulk_write(dev->regmap[0], 0x40, "\xf4\x08", 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) ret = regmap_write(dev->regmap[0], 0xd2, reg_bank0_d2_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) ret = regmap_write(dev->regmap[0], 0xd4, 0x55);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) ret = regmap_write(dev->regmap[1], 0xbe, 0x08);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) ret = regmap_write(dev->regmap[0], 0xb2, 0x37);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) ret = regmap_write(dev->regmap[0], 0xd7, 0x04);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /* PLP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (c->delivery_system == SYS_DVBT2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) ret = regmap_write(dev->regmap[2], 0x36,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) (c->stream_id == NO_STREAM_ID_FILTER) ? 0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) c->stream_id );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /* Reset FSM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) ret = regmap_write(dev->regmap[2], 0xf8, 0x9f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) dev_dbg(&client->dev, "failed=%d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static int mn88473_read_status(struct dvb_frontend *fe, enum fe_status *status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct i2c_client *client = fe->demodulator_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct mn88473_dev *dev = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct dtv_frontend_properties *c = &fe->dtv_property_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) int ret, i, stmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) unsigned int utmp, utmp1, utmp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) u8 buf[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (!dev->active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) ret = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) /* Lock detection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) switch (c->delivery_system) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) case SYS_DVBT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) ret = regmap_read(dev->regmap[0], 0x62, &utmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (!(utmp & 0xa0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if ((utmp & 0x0f) >= 0x09)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) *status = FE_HAS_SIGNAL | FE_HAS_CARRIER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) FE_HAS_VITERBI | FE_HAS_SYNC |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) FE_HAS_LOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) else if ((utmp & 0x0f) >= 0x03)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) *status = FE_HAS_SIGNAL | FE_HAS_CARRIER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) *status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) case SYS_DVBT2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) ret = regmap_read(dev->regmap[2], 0x8b, &utmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (!(utmp & 0x40)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) if ((utmp & 0x0f) >= 0x0d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) *status = FE_HAS_SIGNAL | FE_HAS_CARRIER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) FE_HAS_VITERBI | FE_HAS_SYNC |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) FE_HAS_LOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) else if ((utmp & 0x0f) >= 0x0a)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) *status = FE_HAS_SIGNAL | FE_HAS_CARRIER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) FE_HAS_VITERBI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) else if ((utmp & 0x0f) >= 0x07)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) *status = FE_HAS_SIGNAL | FE_HAS_CARRIER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) *status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) case SYS_DVBC_ANNEX_A:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) ret = regmap_read(dev->regmap[1], 0x85, &utmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) if (!(utmp & 0x40)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) ret = regmap_read(dev->regmap[1], 0x89, &utmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (utmp & 0x01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) *status = FE_HAS_SIGNAL | FE_HAS_CARRIER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) FE_HAS_VITERBI | FE_HAS_SYNC |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) FE_HAS_LOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) *status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) /* Signal strength */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) if (*status & FE_HAS_SIGNAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) ret = regmap_bulk_read(dev->regmap[2], 0x86 + i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) &buf[i], 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) /* AGCRD[15:6] gives us a 10bit value ([5:0] are always 0) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) utmp1 = buf[0] << 8 | buf[1] << 0 | buf[0] >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) dev_dbg(&client->dev, "strength=%u\n", utmp1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) c->strength.stat[0].scale = FE_SCALE_RELATIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) c->strength.stat[0].uvalue = utmp1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /* CNR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (*status & FE_HAS_VITERBI && c->delivery_system == SYS_DVBT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) /* DVB-T CNR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) ret = regmap_bulk_read(dev->regmap[0], 0x8f, buf, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) utmp = buf[0] << 8 | buf[1] << 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (utmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) /* CNR[dB]: 10 * (log10(65536 / value) + 0.2) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) /* log10(65536) = 80807124, 0.2 = 3355443 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) stmp = div_u64(((u64)80807124 - intlog10(utmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) + 3355443) * 10000, 1 << 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) dev_dbg(&client->dev, "cnr=%d value=%u\n", stmp, utmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) stmp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) c->cnr.stat[0].svalue = stmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) } else if (*status & FE_HAS_VITERBI &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) c->delivery_system == SYS_DVBT2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) /* DVB-T2 CNR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) for (i = 0; i < 3; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) ret = regmap_bulk_read(dev->regmap[2], 0xb7 + i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) &buf[i], 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) utmp = buf[1] << 8 | buf[2] << 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) utmp1 = (buf[0] >> 2) & 0x01; /* 0=SISO, 1=MISO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (utmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (utmp1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) /* CNR[dB]: 10 * (log10(16384 / value) - 0.6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) /* log10(16384) = 70706234, 0.6 = 10066330 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) stmp = div_u64(((u64)70706234 - intlog10(utmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) - 10066330) * 10000, 1 << 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) dev_dbg(&client->dev, "cnr=%d value=%u MISO\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) stmp, utmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) /* CNR[dB]: 10 * (log10(65536 / value) + 0.2) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) /* log10(65536) = 80807124, 0.2 = 3355443 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) stmp = div_u64(((u64)80807124 - intlog10(utmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) + 3355443) * 10000, 1 << 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) dev_dbg(&client->dev, "cnr=%d value=%u SISO\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) stmp, utmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) stmp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) c->cnr.stat[0].svalue = stmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) } else if (*status & FE_HAS_VITERBI &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) c->delivery_system == SYS_DVBC_ANNEX_A) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) /* DVB-C CNR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) ret = regmap_bulk_read(dev->regmap[1], 0xa1, buf, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) utmp1 = buf[0] << 8 | buf[1] << 0; /* signal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) utmp2 = buf[2] << 8 | buf[3] << 0; /* noise */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (utmp1 && utmp2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /* CNR[dB]: 10 * log10(8 * (signal / noise)) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) /* log10(8) = 15151336 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) stmp = div_u64(((u64)15151336 + intlog10(utmp1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) - intlog10(utmp2)) * 10000, 1 << 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) dev_dbg(&client->dev, "cnr=%d signal=%u noise=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) stmp, utmp1, utmp2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) stmp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) c->cnr.stat[0].svalue = stmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) /* BER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (*status & FE_HAS_LOCK && (c->delivery_system == SYS_DVBT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) c->delivery_system == SYS_DVBC_ANNEX_A)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) /* DVB-T & DVB-C BER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) ret = regmap_bulk_read(dev->regmap[0], 0x92, buf, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) utmp1 = buf[0] << 16 | buf[1] << 8 | buf[2] << 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) utmp2 = buf[3] << 8 | buf[4] << 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) utmp2 = utmp2 * 8 * 204;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) dev_dbg(&client->dev, "post_bit_error=%u post_bit_count=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) utmp1, utmp2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) c->post_bit_error.stat[0].uvalue += utmp1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) c->post_bit_count.stat[0].uvalue += utmp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) /* PER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) if (*status & FE_HAS_LOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) ret = regmap_bulk_read(dev->regmap[0], 0xdd, buf, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) utmp1 = buf[0] << 8 | buf[1] << 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) utmp2 = buf[2] << 8 | buf[3] << 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) dev_dbg(&client->dev, "block_error=%u block_count=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) utmp1, utmp2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) c->block_error.stat[0].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) c->block_error.stat[0].uvalue += utmp1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) c->block_count.stat[0].scale = FE_SCALE_COUNTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) c->block_count.stat[0].uvalue += utmp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) c->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) dev_dbg(&client->dev, "failed=%d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) static int mn88473_init(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) struct i2c_client *client = fe->demodulator_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) struct mn88473_dev *dev = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) struct dtv_frontend_properties *c = &fe->dtv_property_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) int ret, len, remain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) unsigned int uitmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) const struct firmware *fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) const char *name = MN88473_FIRMWARE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) dev_dbg(&client->dev, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) /* Check if firmware is already running */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) ret = regmap_read(dev->regmap[0], 0xf5, &uitmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) if (!(uitmp & 0x01))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) goto warm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) /* Request the firmware, this will block and timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) ret = request_firmware(&fw, name, &client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) dev_err(&client->dev, "firmware file '%s' not found\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) dev_info(&client->dev, "downloading firmware from file '%s'\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) ret = regmap_write(dev->regmap[0], 0xf5, 0x03);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) goto err_release_firmware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) for (remain = fw->size; remain > 0; remain -= (dev->i2c_wr_max - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) len = min(dev->i2c_wr_max - 1, remain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) ret = regmap_bulk_write(dev->regmap[0], 0xf6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) &fw->data[fw->size - remain], len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) dev_err(&client->dev, "firmware download failed %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) goto err_release_firmware;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) release_firmware(fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) /* Parity check of firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) ret = regmap_read(dev->regmap[0], 0xf8, &uitmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) if (uitmp & 0x10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) dev_err(&client->dev, "firmware parity check failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) ret = regmap_write(dev->regmap[0], 0xf5, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) warm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) /* TS config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) ret = regmap_write(dev->regmap[2], 0x09, 0x08);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) ret = regmap_write(dev->regmap[2], 0x08, 0x1d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) dev->active = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) /* init stats here to indicate which stats are supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) c->strength.len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) c->cnr.len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) c->post_bit_error.len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) c->post_bit_count.len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) c->block_error.len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) c->block_count.len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) c->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) err_release_firmware:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) release_firmware(fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) dev_dbg(&client->dev, "failed=%d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) static int mn88473_sleep(struct dvb_frontend *fe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) struct i2c_client *client = fe->demodulator_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) struct mn88473_dev *dev = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) dev_dbg(&client->dev, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) dev->active = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) ret = regmap_write(dev->regmap[2], 0x05, 0x3e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) dev_dbg(&client->dev, "failed=%d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) static const struct dvb_frontend_ops mn88473_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) .delsys = {SYS_DVBT, SYS_DVBT2, SYS_DVBC_ANNEX_A},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) .info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) .name = "Panasonic MN88473",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) .symbol_rate_min = 1000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) .symbol_rate_max = 7200000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) .caps = FE_CAN_FEC_1_2 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) FE_CAN_FEC_2_3 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) FE_CAN_FEC_3_4 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) FE_CAN_FEC_5_6 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) FE_CAN_FEC_7_8 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) FE_CAN_FEC_AUTO |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) FE_CAN_QPSK |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) FE_CAN_QAM_16 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) FE_CAN_QAM_32 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) FE_CAN_QAM_64 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) FE_CAN_QAM_128 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) FE_CAN_QAM_256 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) FE_CAN_QAM_AUTO |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) FE_CAN_TRANSMISSION_MODE_AUTO |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) FE_CAN_GUARD_INTERVAL_AUTO |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) FE_CAN_HIERARCHY_AUTO |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) FE_CAN_MUTE_TS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) FE_CAN_2G_MODULATION |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) FE_CAN_MULTISTREAM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) .get_tune_settings = mn88473_get_tune_settings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) .init = mn88473_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) .sleep = mn88473_sleep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) .set_frontend = mn88473_set_frontend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) .read_status = mn88473_read_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) static int mn88473_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) struct mn88473_config *config = client->dev.platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) struct mn88473_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) unsigned int uitmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) static const struct regmap_config regmap_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) .reg_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) .val_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) dev_dbg(&client->dev, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) /* Caller really need to provide pointer for frontend we create */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) if (config->fe == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) dev_err(&client->dev, "frontend pointer not defined\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) dev = kzalloc(sizeof(*dev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) if (dev == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) if (config->i2c_wr_max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) dev->i2c_wr_max = config->i2c_wr_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) dev->i2c_wr_max = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) if (config->xtal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) dev->clk = config->xtal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) dev->clk = 25000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) dev->client[0] = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) dev->regmap[0] = regmap_init_i2c(dev->client[0], ®map_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) if (IS_ERR(dev->regmap[0])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) ret = PTR_ERR(dev->regmap[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) goto err_kfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) * Chip has three I2C addresses for different register banks. Used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) * addresses are 0x18, 0x1a and 0x1c. We register two dummy clients,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) * 0x1a and 0x1c, in order to get own I2C client for each register bank.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) * Also, register bank 2 do not support sequential I/O. Only single
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) * register write or read is allowed to that bank.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) dev->client[1] = i2c_new_dummy_device(client->adapter, 0x1a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) if (IS_ERR(dev->client[1])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) ret = PTR_ERR(dev->client[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) dev_err(&client->dev, "I2C registration failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) goto err_regmap_0_regmap_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) dev->regmap[1] = regmap_init_i2c(dev->client[1], ®map_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) if (IS_ERR(dev->regmap[1])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) ret = PTR_ERR(dev->regmap[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) goto err_client_1_i2c_unregister_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) i2c_set_clientdata(dev->client[1], dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) dev->client[2] = i2c_new_dummy_device(client->adapter, 0x1c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) if (IS_ERR(dev->client[2])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) ret = PTR_ERR(dev->client[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) dev_err(&client->dev, "2nd I2C registration failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) goto err_regmap_1_regmap_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) dev->regmap[2] = regmap_init_i2c(dev->client[2], ®map_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) if (IS_ERR(dev->regmap[2])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) ret = PTR_ERR(dev->regmap[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) goto err_client_2_i2c_unregister_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) i2c_set_clientdata(dev->client[2], dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) /* Check demod answers with correct chip id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) ret = regmap_read(dev->regmap[2], 0xff, &uitmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) goto err_regmap_2_regmap_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) dev_dbg(&client->dev, "chip id=%02x\n", uitmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) if (uitmp != 0x03) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) goto err_regmap_2_regmap_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) /* Sleep because chip is active by default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) ret = regmap_write(dev->regmap[2], 0x05, 0x3e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) goto err_regmap_2_regmap_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) /* Create dvb frontend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) memcpy(&dev->frontend.ops, &mn88473_ops, sizeof(dev->frontend.ops));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) dev->frontend.demodulator_priv = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) *config->fe = &dev->frontend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) i2c_set_clientdata(client, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) dev_info(&client->dev, "Panasonic MN88473 successfully identified\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) err_regmap_2_regmap_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) regmap_exit(dev->regmap[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) err_client_2_i2c_unregister_device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) i2c_unregister_device(dev->client[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) err_regmap_1_regmap_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) regmap_exit(dev->regmap[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) err_client_1_i2c_unregister_device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) i2c_unregister_device(dev->client[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) err_regmap_0_regmap_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) regmap_exit(dev->regmap[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) err_kfree:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) kfree(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) dev_dbg(&client->dev, "failed=%d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) static int mn88473_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) struct mn88473_dev *dev = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) dev_dbg(&client->dev, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) regmap_exit(dev->regmap[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) i2c_unregister_device(dev->client[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) regmap_exit(dev->regmap[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) i2c_unregister_device(dev->client[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) regmap_exit(dev->regmap[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) kfree(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) static const struct i2c_device_id mn88473_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) {"mn88473", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) MODULE_DEVICE_TABLE(i2c, mn88473_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) static struct i2c_driver mn88473_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) .name = "mn88473",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) .suppress_bind_attrs = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) .probe = mn88473_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) .remove = mn88473_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) .id_table = mn88473_id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) module_i2c_driver(mn88473_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) MODULE_DESCRIPTION("Panasonic MN88473 DVB-T/T2/C demodulator driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) MODULE_FIRMWARE(MN88473_FIRMWARE);