Lines Matching +full:firmware +full:- +full:reset
1 // SPDX-License-Identifier: GPL-2.0-or-later
15 #include <linux/firmware.h>
60 /* Firmware commands */
92 "Watchdog reset pulse duration in milliseconds");
108 rev->major = ret; in ziirave_wdt_revision()
114 rev->minor = ret; in ziirave_wdt_revision()
121 struct i2c_client *client = to_i2c_client(wdd->parent); in ziirave_wdt_set_state()
138 struct i2c_client *client = to_i2c_client(wdd->parent); in ziirave_wdt_ping()
147 struct i2c_client *client = to_i2c_client(wdd->parent); in ziirave_wdt_set_timeout()
152 wdd->timeout = timeout; in ziirave_wdt_set_timeout()
159 struct i2c_client *client = to_i2c_client(wdd->parent); in ziirave_wdt_get_timeleft()
171 struct i2c_client *client = to_i2c_client(wdd->parent); in ziirave_firm_read_ack()
176 dev_err(&client->dev, "Failed to read status byte\n"); in ziirave_firm_read_ack()
180 return ret == ZIIRAVE_FIRM_DOWNLOAD_ACK ? 0 : -EIO; in ziirave_firm_read_ack()
185 struct i2c_client *client = to_i2c_client(wdd->parent); in ziirave_firm_set_read_addr()
203 * ziirave_firm_write_pkt() - Build and write a firmware packet
205 * A packet to send to the firmware is composed by following bytes:
218 struct i2c_client *client = to_i2c_client(wdd->parent); in __ziirave_firm_write_pkt()
224 dev_err(&client->dev, "Firmware packet too long (%d)\n", in __ziirave_firm_write_pkt()
226 return -EMSGSIZE; in __ziirave_firm_write_pkt()
234 * of firmware update in __ziirave_firm_write_pkt()
245 memset(packet + 3 + len, 0, ZIIRAVE_FIRM_PKT_DATA_SIZE - len); in __ziirave_firm_write_pkt()
250 packet[ZIIRAVE_FIRM_PKT_TOTAL_SIZE - 1] = checksum; in __ziirave_firm_write_pkt()
255 dev_err(&client->dev, in __ziirave_firm_write_pkt()
262 dev_err(&client->dev, in __ziirave_firm_write_pkt()
263 "Failed to write firmware packet at address 0x%04x: %d\n", in __ziirave_firm_write_pkt()
272 const u8 max_write_len = ZIIRAVE_FIRM_PAGE_SIZE - in ziirave_firm_write_pkt()
273 (addr - ALIGN_DOWN(addr, ZIIRAVE_FIRM_PAGE_SIZE)); in ziirave_firm_write_pkt()
287 len -= max_write_len; in ziirave_firm_write_pkt()
294 const struct firmware *fw) in ziirave_firm_verify()
296 struct i2c_client *client = to_i2c_client(wdd->parent); in ziirave_firm_verify()
301 for (rec = (void *)fw->data; rec; rec = ihex_next_binrec(rec)) { in ziirave_firm_verify()
302 const u16 len = be16_to_cpu(rec->len); in ziirave_firm_verify()
303 const u32 addr = be32_to_cpu(rec->addr); in ziirave_firm_verify()
310 dev_err(&client->dev, in ziirave_firm_verify()
320 dev_err(&client->dev, in ziirave_firm_verify()
327 if (memcmp(data, rec->data, len)) { in ziirave_firm_verify()
328 dev_err(&client->dev, in ziirave_firm_verify()
329 "Firmware mismatch at address 0x%04x\n", addr); in ziirave_firm_verify()
330 return -EINVAL; in ziirave_firm_verify()
338 const struct firmware *fw) in ziirave_firm_upload()
340 struct i2c_client *client = to_i2c_client(wdd->parent); in ziirave_firm_upload()
348 dev_err(&client->dev, "Failed to jump to bootloader\n"); in ziirave_firm_upload()
356 dev_err(&client->dev, "Failed to start download\n"); in ziirave_firm_upload()
362 dev_err(&client->dev, "No ACK for start download\n"); in ziirave_firm_upload()
368 for (rec = (void *)fw->data; rec; rec = ihex_next_binrec(rec)) { in ziirave_firm_upload()
369 ret = ziirave_firm_write_pkt(wdd, be32_to_cpu(rec->addr), in ziirave_firm_upload()
370 rec->data, be16_to_cpu(rec->len)); in ziirave_firm_upload()
376 * Finish firmware download process by sending a zero length in ziirave_firm_upload()
381 dev_err(&client->dev, "Failed to send EMPTY packet: %d\n", ret); in ziirave_firm_upload()
388 /* Start firmware verification */ in ziirave_firm_upload()
391 dev_err(&client->dev, in ziirave_firm_upload()
392 "Failed to verify firmware: %d\n", ret); in ziirave_firm_upload()
399 dev_err(&client->dev, in ziirave_firm_upload()
400 "Failed to end firmware download: %d\n", ret); in ziirave_firm_upload()
404 /* Reset the processor */ in ziirave_firm_upload()
409 dev_err(&client->dev, in ziirave_firm_upload()
410 "Failed to reset the watchdog: %d\n", ret); in ziirave_firm_upload()
437 struct i2c_client *client = to_i2c_client(dev->parent); in ziirave_wdt_sysfs_show_firm()
441 ret = mutex_lock_interruptible(&w_priv->sysfs_mutex); in ziirave_wdt_sysfs_show_firm()
446 w_priv->firmware_rev.major, in ziirave_wdt_sysfs_show_firm()
447 w_priv->firmware_rev.minor); in ziirave_wdt_sysfs_show_firm()
449 mutex_unlock(&w_priv->sysfs_mutex); in ziirave_wdt_sysfs_show_firm()
461 struct i2c_client *client = to_i2c_client(dev->parent); in ziirave_wdt_sysfs_show_boot()
465 ret = mutex_lock_interruptible(&w_priv->sysfs_mutex); in ziirave_wdt_sysfs_show_boot()
470 w_priv->bootloader_rev.major, in ziirave_wdt_sysfs_show_boot()
471 w_priv->bootloader_rev.minor); in ziirave_wdt_sysfs_show_boot()
473 mutex_unlock(&w_priv->sysfs_mutex); in ziirave_wdt_sysfs_show_boot()
485 struct i2c_client *client = to_i2c_client(dev->parent); in ziirave_wdt_sysfs_show_reason()
489 ret = mutex_lock_interruptible(&w_priv->sysfs_mutex); in ziirave_wdt_sysfs_show_reason()
493 ret = sysfs_emit(buf, "%s\n", ziirave_reasons[w_priv->reset_reason]); in ziirave_wdt_sysfs_show_reason()
495 mutex_unlock(&w_priv->sysfs_mutex); in ziirave_wdt_sysfs_show_reason()
507 struct i2c_client *client = to_i2c_client(dev->parent); in ziirave_wdt_sysfs_store_firm()
509 const struct firmware *fw; in ziirave_wdt_sysfs_store_firm()
514 dev_err(&client->dev, "Failed to request ihex firmware\n"); in ziirave_wdt_sysfs_store_firm()
518 err = mutex_lock_interruptible(&w_priv->sysfs_mutex); in ziirave_wdt_sysfs_store_firm()
522 err = ziirave_firm_upload(&w_priv->wdd, fw); in ziirave_wdt_sysfs_store_firm()
524 dev_err(&client->dev, "The firmware update failed: %d\n", err); in ziirave_wdt_sysfs_store_firm()
528 /* Update firmware version */ in ziirave_wdt_sysfs_store_firm()
529 err = ziirave_wdt_revision(client, &w_priv->firmware_rev, in ziirave_wdt_sysfs_store_firm()
532 dev_err(&client->dev, "Failed to read firmware version: %d\n", in ziirave_wdt_sysfs_store_firm()
537 dev_info(&client->dev, in ziirave_wdt_sysfs_store_firm()
538 "Firmware updated to version 02.%02u.%02u\n", in ziirave_wdt_sysfs_store_firm()
539 w_priv->firmware_rev.major, w_priv->firmware_rev.minor); in ziirave_wdt_sysfs_store_firm()
542 err = ziirave_wdt_set_timeout(&w_priv->wdd, w_priv->wdd.timeout); in ziirave_wdt_sysfs_store_firm()
544 dev_err(&client->dev, "Failed to set timeout: %d\n", err); in ziirave_wdt_sysfs_store_firm()
547 mutex_unlock(&w_priv->sysfs_mutex); in ziirave_wdt_sysfs_store_firm()
572 /* See if the reset pulse duration is provided in an of_node */ in ziirave_wdt_init_duration()
573 if (!client->dev.of_node) in ziirave_wdt_init_duration()
574 ret = -ENODEV; in ziirave_wdt_init_duration()
576 ret = of_property_read_u32(client->dev.of_node, in ziirave_wdt_init_duration()
577 "reset-duration-ms", in ziirave_wdt_init_duration()
580 dev_info(&client->dev, in ziirave_wdt_init_duration()
581 "No reset pulse duration specified, using default\n"); in ziirave_wdt_init_duration()
587 return -EINVAL; in ziirave_wdt_init_duration()
589 dev_info(&client->dev, "Setting reset duration to %dms", in ziirave_wdt_init_duration()
602 if (!i2c_check_functionality(client->adapter, in ziirave_wdt_probe()
606 return -ENODEV; in ziirave_wdt_probe()
608 w_priv = devm_kzalloc(&client->dev, sizeof(*w_priv), GFP_KERNEL); in ziirave_wdt_probe()
610 return -ENOMEM; in ziirave_wdt_probe()
612 mutex_init(&w_priv->sysfs_mutex); in ziirave_wdt_probe()
614 w_priv->wdd.info = &ziirave_wdt_info; in ziirave_wdt_probe()
615 w_priv->wdd.ops = &ziirave_wdt_ops; in ziirave_wdt_probe()
616 w_priv->wdd.min_timeout = ZIIRAVE_TIMEOUT_MIN; in ziirave_wdt_probe()
617 w_priv->wdd.max_timeout = ZIIRAVE_TIMEOUT_MAX; in ziirave_wdt_probe()
618 w_priv->wdd.parent = &client->dev; in ziirave_wdt_probe()
619 w_priv->wdd.groups = ziirave_wdt_groups; in ziirave_wdt_probe()
621 watchdog_init_timeout(&w_priv->wdd, wdt_timeout, &client->dev); in ziirave_wdt_probe()
628 if (w_priv->wdd.timeout == 0) { in ziirave_wdt_probe()
631 dev_err(&client->dev, "Failed to read timeout\n"); in ziirave_wdt_probe()
639 w_priv->wdd.timeout = val; in ziirave_wdt_probe()
642 ret = ziirave_wdt_set_timeout(&w_priv->wdd, w_priv->wdd.timeout); in ziirave_wdt_probe()
644 dev_err(&client->dev, "Failed to set timeout\n"); in ziirave_wdt_probe()
648 dev_info(&client->dev, "Timeout set to %ds\n", w_priv->wdd.timeout); in ziirave_wdt_probe()
650 watchdog_set_nowayout(&w_priv->wdd, nowayout); in ziirave_wdt_probe()
657 dev_err(&client->dev, "Failed to read state\n"); in ziirave_wdt_probe()
662 ziirave_wdt_stop(&w_priv->wdd); in ziirave_wdt_probe()
666 dev_err(&client->dev, "Failed to init duration\n"); in ziirave_wdt_probe()
670 ret = ziirave_wdt_revision(client, &w_priv->firmware_rev, in ziirave_wdt_probe()
673 dev_err(&client->dev, "Failed to read firmware version\n"); in ziirave_wdt_probe()
677 dev_info(&client->dev, in ziirave_wdt_probe()
678 "Firmware version: 02.%02u.%02u\n", in ziirave_wdt_probe()
679 w_priv->firmware_rev.major, w_priv->firmware_rev.minor); in ziirave_wdt_probe()
681 ret = ziirave_wdt_revision(client, &w_priv->bootloader_rev, in ziirave_wdt_probe()
684 dev_err(&client->dev, "Failed to read bootloader version\n"); in ziirave_wdt_probe()
688 dev_info(&client->dev, in ziirave_wdt_probe()
690 w_priv->bootloader_rev.major, w_priv->bootloader_rev.minor); in ziirave_wdt_probe()
692 w_priv->reset_reason = i2c_smbus_read_byte_data(client, in ziirave_wdt_probe()
694 if (w_priv->reset_reason < 0) { in ziirave_wdt_probe()
695 dev_err(&client->dev, "Failed to read reset reason\n"); in ziirave_wdt_probe()
696 return w_priv->reset_reason; in ziirave_wdt_probe()
699 if (w_priv->reset_reason >= ARRAY_SIZE(ziirave_reasons) || in ziirave_wdt_probe()
700 !ziirave_reasons[w_priv->reset_reason]) { in ziirave_wdt_probe()
701 dev_err(&client->dev, "Invalid reset reason\n"); in ziirave_wdt_probe()
702 return -ENODEV; in ziirave_wdt_probe()
705 ret = watchdog_register_device(&w_priv->wdd); in ziirave_wdt_probe()
714 watchdog_unregister_device(&w_priv->wdd); in ziirave_wdt_remove()
718 { "rave-wdt", 0 },
724 { .compatible = "zii,rave-wdt", },