zl3073x_flash_mode_leave() resets the device CPU back to normal firmware processing via an open-coded HW register write sequence in flash.c. The same core reset is needed for a full device reset that reboots the firmware and reloads the configuration from flash, introduced later in this series. Factor it into a reusable helper, zl3073x_dev_hw_reset(), in core.c. Drop the 'wait' field from struct zl3073x_hwreg_seq_item and the HWREG_SEQ_ITEM() macro. zl3073x_write_hwreg_seq() tested seq->wait instead of seq[i].wait, so only the first item of a sequence was considered and, as that is zero in all the sequences, the 1000 ms waits requested by the flash mode enter sequences never took place. The flash update has worked without them, so drop them instead of fixing the test. zl3073x_flash_mode_leave() waits after the core reset with msleep() on its own, and that wait moves into the helper. Reviewed-by: Min Li Tested-by: Min Li Signed-off-by: Ivan Vecera --- Changes in v2: - Comment that the 500 ms wait after the core reset follows the datasheet RST_B timing (Sashiko) --- drivers/dpll/zl3073x/core.c | 61 ++++++++++++++++++++++++++-- drivers/dpll/zl3073x/core.h | 6 +-- drivers/dpll/zl3073x/flash.c | 79 ++++++++---------------------------- 3 files changed, 77 insertions(+), 69 deletions(-) diff --git a/drivers/dpll/zl3073x/core.c b/drivers/dpll/zl3073x/core.c index 230df08e27cd19..e833c62d064842 100644 --- a/drivers/dpll/zl3073x/core.c +++ b/drivers/dpll/zl3073x/core.c @@ -497,14 +497,69 @@ int zl3073x_write_hwreg_seq(struct zl3073x_dev *zldev, seq[i].value, seq[i].mask); if (rc) return rc; - - if (seq->wait) - msleep(seq->wait); } return rc; } +/** + * zl3073x_dev_hw_reset - Reset the device CPU and reload firmware and config + * @zldev: zl3073x device pointer + * + * Triggers a core reset that reboots the firmware and reloads the whole + * configuration from flash. The device is inaccessible on the control bus + * while the reset is in progress. + * + * Context: Process context. The caller must stop normal operation with + * zl3073x_dev_stop() first. + * + * Return: 0 on success, <0 on error + */ +int zl3073x_dev_hw_reset(struct zl3073x_dev *zldev) +{ + static const struct zl3073x_hwreg_seq_item hw_seq[] = { + HWREG_SEQ_ITEM(0x80000404, 1, BIT(0)), + HWREG_SEQ_ITEM(0x80000410, 1, BIT(0)), + }; + u8 reset_status; + int rc; + + /* Read reset status register */ + rc = zl3073x_read_u8(zldev, ZL_REG_RESET_STATUS, &reset_status); + if (rc) + return rc; + + /* Arm the reset detection flag */ + reset_status |= ZL_REG_RESET_STATUS_RESET; + rc = zl3073x_write_u8(zldev, ZL_REG_RESET_STATUS, reset_status); + if (rc) + return rc; + + /* Trigger the core reset. The last write typically errors out as + * the device CPU resets mid-transaction, so its return value is + * not checked. + */ + zl3073x_write_hwreg_seq(zldev, hw_seq, ARRAY_SIZE(hw_seq)); + + /* The core reset acts like a reset via the RST_B pin, device + * registers can be accessed 500 ms after it. + */ + msleep(500); + + /* Read again the reset status register */ + rc = zl3073x_read_u8(zldev, ZL_REG_RESET_STATUS, &reset_status); + if (rc) + return rc; + + /* Check the reset flag was cleared by the firmware */ + if (reset_status & ZL_REG_RESET_STATUS_RESET) { + dev_err(zldev->dev, "Device reset not confirmed\n"); + return -EINVAL; + } + + return 0; +} + static int zl3073x_dev_state_fetch(struct zl3073x_dev *zldev) { diff --git a/drivers/dpll/zl3073x/core.h b/drivers/dpll/zl3073x/core.h index 67c10e2595118c..4d979543500c4e 100644 --- a/drivers/dpll/zl3073x/core.h +++ b/drivers/dpll/zl3073x/core.h @@ -125,21 +125,18 @@ int zl3073x_dev_phase_avg_factor_set(struct zl3073x_dev *zldev, u8 factor); * @addr: HW register to be written * @value: value to be written to HW register * @mask: bitmask indicating bits to be updated - * @wait: number of ms to wait after register write */ struct zl3073x_hwreg_seq_item { u32 addr; u32 value; u32 mask; - u32 wait; }; -#define HWREG_SEQ_ITEM(_addr, _value, _mask, _wait) \ +#define HWREG_SEQ_ITEM(_addr, _value, _mask) \ { \ .addr = _addr, \ .value = FIELD_PREP_CONST(_mask, _value), \ .mask = _mask, \ - .wait = _wait, \ } int zl3073x_mb_op(struct zl3073x_dev *zldev, unsigned int op_reg, u8 op_val, @@ -161,6 +158,7 @@ int zl3073x_update_hwreg(struct zl3073x_dev *zldev, u32 addr, u32 value, int zl3073x_write_hwreg_seq(struct zl3073x_dev *zldev, const struct zl3073x_hwreg_seq_item *seq, size_t num_items); +int zl3073x_dev_hw_reset(struct zl3073x_dev *zldev); /***************** * Misc operations diff --git a/drivers/dpll/zl3073x/flash.c b/drivers/dpll/zl3073x/flash.c index f85535c8ad2469..306e7c857b2313 100644 --- a/drivers/dpll/zl3073x/flash.c +++ b/drivers/dpll/zl3073x/flash.c @@ -529,22 +529,22 @@ int zl3073x_flash_mode_enter(struct zl3073x_dev *zldev, const void *util_ptr, { /* Sequence to be written prior utility download */ static const struct zl3073x_hwreg_seq_item pre_seq[] = { - HWREG_SEQ_ITEM(0x80000400, 1, BIT(0), 0), - HWREG_SEQ_ITEM(0x80206340, 1, BIT(4), 0), - HWREG_SEQ_ITEM(0x10000000, 1, BIT(2), 0), - HWREG_SEQ_ITEM(0x10000024, 0x00000001, U32_MAX, 0), - HWREG_SEQ_ITEM(0x10000020, 0x00000001, U32_MAX, 0), - HWREG_SEQ_ITEM(0x10000000, 1, BIT(10), 1000), + HWREG_SEQ_ITEM(0x80000400, 1, BIT(0)), + HWREG_SEQ_ITEM(0x80206340, 1, BIT(4)), + HWREG_SEQ_ITEM(0x10000000, 1, BIT(2)), + HWREG_SEQ_ITEM(0x10000024, 0x00000001, U32_MAX), + HWREG_SEQ_ITEM(0x10000020, 0x00000001, U32_MAX), + HWREG_SEQ_ITEM(0x10000000, 1, BIT(10)), }; /* Sequence to be written after utility download */ static const struct zl3073x_hwreg_seq_item post_seq[] = { - HWREG_SEQ_ITEM(0x10400004, 0x000000C0, U32_MAX, 0), - HWREG_SEQ_ITEM(0x10400008, 0x00000000, U32_MAX, 0), - HWREG_SEQ_ITEM(0x10400010, 0x20000000, U32_MAX, 0), - HWREG_SEQ_ITEM(0x10400014, 0x20000004, U32_MAX, 0), - HWREG_SEQ_ITEM(0x10000000, 1, GENMASK(10, 9), 0), - HWREG_SEQ_ITEM(0x10000020, 0x00000000, U32_MAX, 0), - HWREG_SEQ_ITEM(0x10000000, 0, BIT(0), 1000), + HWREG_SEQ_ITEM(0x10400004, 0x000000C0, U32_MAX), + HWREG_SEQ_ITEM(0x10400008, 0x00000000, U32_MAX), + HWREG_SEQ_ITEM(0x10400010, 0x20000000, U32_MAX), + HWREG_SEQ_ITEM(0x10400014, 0x20000004, U32_MAX), + HWREG_SEQ_ITEM(0x10000000, 1, GENMASK(10, 9)), + HWREG_SEQ_ITEM(0x10000020, 0x00000000, U32_MAX), + HWREG_SEQ_ITEM(0x10000000, 0, BIT(0)), }; int rc; @@ -604,62 +604,17 @@ int zl3073x_flash_mode_enter(struct zl3073x_dev *zldev, const void *util_ptr, * @extack: netlink extack pointer to report errors * * The function instructs the device to leave the flash mode and - * to return back to normal operation. - * - * The procedure: - * 1) Set reset flag - * 2) Reset the device CPU by specific HW register sequence - * 3) Wait for the device to be ready - * 4) Check the reset flag was cleared + * to return back to normal operation by resetting the device CPU + * with zl3073x_dev_hw_reset(). * * Return: 0 on success, <0 on error */ int zl3073x_flash_mode_leave(struct zl3073x_dev *zldev, struct netlink_ext_ack *extack) { - /* Sequence to be written after flash */ - static const struct zl3073x_hwreg_seq_item fw_reset_seq[] = { - HWREG_SEQ_ITEM(0x80000404, 1, BIT(0), 0), - HWREG_SEQ_ITEM(0x80000410, 1, BIT(0), 0), - }; - u8 reset_status; - int rc; - zl3073x_devlink_flash_notify(zldev, "Leaving flash mode", "utility", 0, 0); - /* Read reset status register */ - rc = zl3073x_read_u8(zldev, ZL_REG_RESET_STATUS, &reset_status); - if (rc) - return rc; - - /* Set reset bit */ - reset_status |= ZL_REG_RESET_STATUS_RESET; - - /* Update reset status register */ - rc = zl3073x_write_u8(zldev, ZL_REG_RESET_STATUS, reset_status); - if (rc) - return rc; - - /* We do not check the return value here as the sequence resets - * the device CPU and the last write always return an error. - */ - zl3073x_write_hwreg_seq(zldev, fw_reset_seq, ARRAY_SIZE(fw_reset_seq)); - - /* Wait for the device to be ready */ - msleep(500); - - /* Read again the reset status register */ - rc = zl3073x_read_u8(zldev, ZL_REG_RESET_STATUS, &reset_status); - if (rc) - return rc; - - /* Check the reset bit was cleared */ - if (reset_status & ZL_REG_RESET_STATUS_RESET) { - dev_err(zldev->dev, - "Reset not confirmed after switch to normal mode\n"); - return -EINVAL; - } - - return 0; + /* Reset the device CPU to resume normal firmware processing */ + return zl3073x_dev_hw_reset(zldev); } -- 2.56.1