Lines Matching +full:firmware +full:- +full:initialized

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Silicon Labs Si2168 DVB-T/T2/C demodulator driver
16 memcpy(cmd->args, buf, wlen); in cmd_init()
17 cmd->wlen = wlen; in cmd_init()
18 cmd->rlen = rlen; in cmd_init()
21 /* execute firmware command */
28 mutex_lock(&dev->i2c_mutex); in si2168_cmd_execute()
30 if (cmd->wlen) { in si2168_cmd_execute()
31 /* write cmd and args for firmware */ in si2168_cmd_execute()
32 ret = i2c_master_send(client, cmd->args, cmd->wlen); in si2168_cmd_execute()
35 } else if (ret != cmd->wlen) { in si2168_cmd_execute()
36 ret = -EREMOTEIO; in si2168_cmd_execute()
41 if (cmd->rlen) { in si2168_cmd_execute()
46 ret = i2c_master_recv(client, cmd->args, cmd->rlen); in si2168_cmd_execute()
49 } else if (ret != cmd->rlen) { in si2168_cmd_execute()
50 ret = -EREMOTEIO; in si2168_cmd_execute()
54 /* firmware ready? */ in si2168_cmd_execute()
55 if ((cmd->args[0] >> 7) & 0x01) in si2168_cmd_execute()
59 dev_dbg(&client->dev, "cmd execution took %d ms\n", in si2168_cmd_execute()
60 jiffies_to_msecs(jiffies) - in si2168_cmd_execute()
61 (jiffies_to_msecs(timeout) - TIMEOUT)); in si2168_cmd_execute()
64 if ((cmd->args[0] >> 6) & 0x01) { in si2168_cmd_execute()
65 ret = -EREMOTEIO; in si2168_cmd_execute()
69 if (!((cmd->args[0] >> 7) & 0x01)) { in si2168_cmd_execute()
70 ret = -ETIMEDOUT; in si2168_cmd_execute()
75 mutex_unlock(&dev->i2c_mutex); in si2168_cmd_execute()
78 mutex_unlock(&dev->i2c_mutex); in si2168_cmd_execute()
79 dev_dbg(&client->dev, "failed=%d\n", ret); in si2168_cmd_execute()
85 struct i2c_client *client = fe->demodulator_priv; in si2168_ts_bus_ctrl()
90 dev_dbg(&client->dev, "%s acquire: %d\n", __func__, acquire); in si2168_ts_bus_ctrl()
93 if (dev->ts_mode & SI2168_TS_CLK_MANUAL) { in si2168_ts_bus_ctrl()
101 if (dev->ts_mode & SI2168_TS_CLK_MANUAL) in si2168_ts_bus_ctrl()
104 cmd.args[4] |= dev->ts_mode; in si2168_ts_bus_ctrl()
107 if (dev->ts_clock_gapped) in si2168_ts_bus_ctrl()
116 struct i2c_client *client = fe->demodulator_priv; in si2168_read_status()
118 struct dtv_frontend_properties *c = &fe->dtv_property_cache; in si2168_read_status()
125 if (!dev->active) { in si2168_read_status()
126 ret = -EAGAIN; in si2168_read_status()
130 switch (c->delivery_system) { in si2168_read_status()
141 ret = -EINVAL; in si2168_read_status()
159 dev->fe_status = *status; in si2168_read_status()
162 c->cnr.len = 1; in si2168_read_status()
163 c->cnr.stat[0].scale = FE_SCALE_DECIBEL; in si2168_read_status()
164 c->cnr.stat[0].svalue = cmd.args[3] * 1000 / 4; in si2168_read_status()
166 c->cnr.len = 1; in si2168_read_status()
167 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; in si2168_read_status()
170 dev_dbg(&client->dev, "status=%02x args=%*ph\n", in si2168_read_status()
181 * Firmware returns [0, 255] mantissa and [0, 8] exponent. in si2168_read_status()
182 * Convert to DVB API: mantissa * 10^(8 - exponent) / 10^8 in si2168_read_status()
184 utmp = clamp(8 - cmd.args[1], 0, 8); in si2168_read_status()
191 dev_dbg(&client->dev, in si2168_read_status()
192 "post_bit_error=%u post_bit_count=%u ber=%u*10^-%u\n", in si2168_read_status()
195 c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER; in si2168_read_status()
196 c->post_bit_error.stat[0].uvalue += utmp1; in si2168_read_status()
197 c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER; in si2168_read_status()
198 c->post_bit_count.stat[0].uvalue += utmp2; in si2168_read_status()
200 c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; in si2168_read_status()
201 c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; in si2168_read_status()
212 dev_dbg(&client->dev, "block_error=%u\n", utmp1); in si2168_read_status()
214 /* Sometimes firmware returns bogus value */ in si2168_read_status()
218 c->block_error.stat[0].scale = FE_SCALE_COUNTER; in si2168_read_status()
219 c->block_error.stat[0].uvalue += utmp1; in si2168_read_status()
221 c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; in si2168_read_status()
226 dev_dbg(&client->dev, "failed=%d\n", ret); in si2168_read_status()
232 struct i2c_client *client = fe->demodulator_priv; in si2168_set_frontend()
234 struct dtv_frontend_properties *c = &fe->dtv_property_cache; in si2168_set_frontend()
239 dev_dbg(&client->dev, in si2168_set_frontend()
241 c->delivery_system, c->modulation, c->frequency, in si2168_set_frontend()
242 c->bandwidth_hz, c->symbol_rate, c->inversion, in si2168_set_frontend()
243 c->stream_id); in si2168_set_frontend()
245 if (!dev->active) { in si2168_set_frontend()
246 ret = -EAGAIN; in si2168_set_frontend()
250 switch (c->delivery_system) { in si2168_set_frontend()
261 ret = -EINVAL; in si2168_set_frontend()
265 if (c->bandwidth_hz == 0) { in si2168_set_frontend()
266 ret = -EINVAL; in si2168_set_frontend()
268 } else if (c->bandwidth_hz <= 2000000) in si2168_set_frontend()
270 else if (c->bandwidth_hz <= 5000000) in si2168_set_frontend()
272 else if (c->bandwidth_hz <= 6000000) in si2168_set_frontend()
274 else if (c->bandwidth_hz <= 7000000) in si2168_set_frontend()
276 else if (c->bandwidth_hz <= 8000000) in si2168_set_frontend()
278 else if (c->bandwidth_hz <= 9000000) in si2168_set_frontend()
280 else if (c->bandwidth_hz <= 10000000) in si2168_set_frontend()
286 if (fe->ops.tuner_ops.set_params) { in si2168_set_frontend()
287 ret = fe->ops.tuner_ops.set_params(fe); in si2168_set_frontend()
298 if (c->delivery_system == SYS_DVBT) in si2168_set_frontend()
300 else if (c->delivery_system == SYS_DVBC_ANNEX_A) in si2168_set_frontend()
302 else if (c->delivery_system == SYS_DVBT2) in si2168_set_frontend()
308 if (c->delivery_system == SYS_DVBT2) { in si2168_set_frontend()
311 cmd.args[1] = c->stream_id & 0xff; in si2168_set_frontend()
312 cmd.args[2] = c->stream_id == NO_STREAM_ID_FILTER ? 0 : 1; in si2168_set_frontend()
347 if (dev->spectral_inversion) in si2168_set_frontend()
353 /* set DVB-C symbol rate */ in si2168_set_frontend()
354 if (c->delivery_system == SYS_DVBC_ANNEX_A) { in si2168_set_frontend()
356 cmd.args[4] = ((c->symbol_rate / 1000) >> 0) & 0xff; in si2168_set_frontend()
357 cmd.args[5] = ((c->symbol_rate / 1000) >> 8) & 0xff; in si2168_set_frontend()
369 cmd.args[5] |= dev->ts_clock_inv ? 0x00 : 0x10; in si2168_set_frontend()
375 cmd.args[5] |= dev->ts_clock_inv ? 0x00 : 0x10; in si2168_set_frontend()
395 dev->delivery_system = c->delivery_system; in si2168_set_frontend()
404 dev_dbg(&client->dev, "failed=%d\n", ret); in si2168_set_frontend()
410 struct i2c_client *client = fe->demodulator_priv; in si2168_init()
412 struct dtv_frontend_properties *c = &fe->dtv_property_cache; in si2168_init()
414 const struct firmware *fw; in si2168_init()
417 dev_dbg(&client->dev, "\n"); in si2168_init()
426 if (dev->warm) { in si2168_init()
448 /* request the firmware, this will block and timeout */ in si2168_init()
449 ret = request_firmware(&fw, dev->firmware_name, &client->dev); in si2168_init()
451 dev_err(&client->dev, in si2168_init()
452 "firmware file '%s' not found\n", in si2168_init()
453 dev->firmware_name); in si2168_init()
457 dev_info(&client->dev, "downloading firmware from file '%s'\n", in si2168_init()
458 dev->firmware_name); in si2168_init()
460 if ((fw->size % 17 == 0) && (fw->data[0] > 5)) { in si2168_init()
461 /* firmware is in the new format */ in si2168_init()
462 for (remaining = fw->size; remaining > 0; remaining -= 17) { in si2168_init()
463 len = fw->data[fw->size - remaining]; in si2168_init()
465 ret = -EINVAL; in si2168_init()
468 cmd_init(&cmd, &fw->data[(fw->size - remaining) + 1], in si2168_init()
474 } else if (fw->size % 8 == 0) { in si2168_init()
475 /* firmware is in the old format */ in si2168_init()
476 for (remaining = fw->size; remaining > 0; remaining -= 8) { in si2168_init()
477 cmd_init(&cmd, &fw->data[fw->size - remaining], 8, 1); in si2168_init()
483 /* bad or unknown firmware format */ in si2168_init()
484 ret = -EINVAL; in si2168_init()
488 dev_err(&client->dev, "firmware download failed %d\n", ret); in si2168_init()
499 /* query firmware version */ in si2168_init()
505 dev->version = (cmd.args[9] + '@') << 24 | (cmd.args[6] - '0') << 16 | in si2168_init()
506 (cmd.args[7] - '0') << 8 | (cmd.args[8]) << 0; in si2168_init()
507 dev_info(&client->dev, "firmware version: %c %d.%d.%d\n", in si2168_init()
508 dev->version >> 24 & 0xff, dev->version >> 16 & 0xff, in si2168_init()
509 dev->version >> 8 & 0xff, dev->version >> 0 & 0xff); in si2168_init()
516 dev->warm = true; in si2168_init()
517 dev->initialized = true; in si2168_init()
520 c->cnr.len = 1; in si2168_init()
521 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; in si2168_init()
522 c->post_bit_error.len = 1; in si2168_init()
523 c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; in si2168_init()
524 c->post_bit_count.len = 1; in si2168_init()
525 c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; in si2168_init()
526 c->block_error.len = 1; in si2168_init()
527 c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; in si2168_init()
529 dev->active = true; in si2168_init()
535 dev_dbg(&client->dev, "failed=%d\n", ret); in si2168_init()
541 struct i2c_client *client = fe->demodulator_priv; in si2168_resume()
546 * outside of a resume cycle. Only call it (and load firmware) in si2168_resume()
551 if (dev->initialized) { in si2168_resume()
552 dev_dbg(&client->dev, "previously initialized, call si2168_init()\n"); in si2168_resume()
555 dev_dbg(&client->dev, "not initialized yet, skipping init on resume\n"); in si2168_resume()
561 struct i2c_client *client = fe->demodulator_priv; in si2168_sleep()
566 dev_dbg(&client->dev, "\n"); in si2168_sleep()
568 dev->active = false; in si2168_sleep()
570 /* tri-state data bus */ in si2168_sleep()
575 /* Firmware later than B 4.0-11 loses warm state during sleep */ in si2168_sleep()
576 if (dev->version > ('B' << 24 | 4 << 16 | 0 << 8 | 11 << 0)) in si2168_sleep()
577 dev->warm = false; in si2168_sleep()
586 dev_dbg(&client->dev, "failed=%d\n", ret); in si2168_sleep()
593 s->min_delay_ms = 900; in si2168_get_tune_settings()
612 dev_dbg(&client->dev, "failed=%d\n", ret); in si2168_select()
630 dev_dbg(&client->dev, "failed=%d\n", ret); in si2168_deselect()
677 struct si2168_config *config = client->dev.platform_data; in si2168_probe()
682 dev_dbg(&client->dev, "\n"); in si2168_probe()
686 ret = -ENOMEM; in si2168_probe()
691 mutex_init(&dev->i2c_mutex); in si2168_probe()
712 dev->chip_id = cmd.args[1] << 24 | cmd.args[2] << 16 | in si2168_probe()
715 switch (dev->chip_id) { in si2168_probe()
717 dev->firmware_name = SI2168_A20_FIRMWARE; in si2168_probe()
720 dev->firmware_name = SI2168_A30_FIRMWARE; in si2168_probe()
723 dev->firmware_name = SI2168_B40_FIRMWARE; in si2168_probe()
726 dev->firmware_name = SI2168_D60_FIRMWARE; in si2168_probe()
729 dev_dbg(&client->dev, "unknown chip version Si21%d-%c%c%c\n", in si2168_probe()
731 ret = -ENODEV; in si2168_probe()
735 dev->version = (cmd.args[1]) << 24 | (cmd.args[3] - '0') << 16 | in si2168_probe()
736 (cmd.args[4] - '0') << 8 | (cmd.args[5]) << 0; in si2168_probe()
739 dev->muxc = i2c_mux_alloc(client->adapter, &client->dev, in si2168_probe()
742 if (!dev->muxc) { in si2168_probe()
743 ret = -ENOMEM; in si2168_probe()
746 dev->muxc->priv = client; in si2168_probe()
747 ret = i2c_mux_add_adapter(dev->muxc, 0, 0, 0); in si2168_probe()
752 memcpy(&dev->fe.ops, &si2168_ops, sizeof(struct dvb_frontend_ops)); in si2168_probe()
753 dev->fe.demodulator_priv = client; in si2168_probe()
754 *config->i2c_adapter = dev->muxc->adapter[0]; in si2168_probe()
755 *config->fe = &dev->fe; in si2168_probe()
756 dev->ts_mode = config->ts_mode; in si2168_probe()
757 dev->ts_clock_inv = config->ts_clock_inv; in si2168_probe()
758 dev->ts_clock_gapped = config->ts_clock_gapped; in si2168_probe()
759 dev->spectral_inversion = config->spectral_inversion; in si2168_probe()
761 dev_info(&client->dev, "Silicon Labs Si2168-%c%d%d successfully identified\n", in si2168_probe()
762 dev->version >> 24 & 0xff, dev->version >> 16 & 0xff, in si2168_probe()
763 dev->version >> 8 & 0xff); in si2168_probe()
764 dev_info(&client->dev, "firmware version: %c %d.%d.%d\n", in si2168_probe()
765 dev->version >> 24 & 0xff, dev->version >> 16 & 0xff, in si2168_probe()
766 dev->version >> 8 & 0xff, dev->version >> 0 & 0xff); in si2168_probe()
772 dev_warn(&client->dev, "probe failed = %d\n", ret); in si2168_probe()
780 dev_dbg(&client->dev, "\n"); in si2168_remove()
782 i2c_mux_del_adapters(dev->muxc); in si2168_remove()
784 dev->fe.ops.release = NULL; in si2168_remove()
785 dev->fe.demodulator_priv = NULL; in si2168_remove()
809 MODULE_DESCRIPTION("Silicon Labs Si2168 DVB-T/T2/C demodulator driver");