]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mfd: rk8xx-core: Allow to customize RK806 reset mode
authorQuentin Schulz <quentin.schulz@cherry.de>
Fri, 27 Jun 2025 10:53:54 +0000 (12:53 +0200)
committerLee Jones <lee@kernel.org>
Thu, 24 Jul 2025 10:27:17 +0000 (11:27 +0100)
The RK806 PMIC has a bitfield for configuring the restart/reset behavior
(which I assume Rockchip calls "function") whenever the PMIC is reset
either programmatically (c.f. DEV_RST in the datasheet) or via PWRCTRL
or RESETB pins.

For RK806, the following values are possible for RST_FUN:

0b00 means "Restart PMU"
0b01 means "Reset all the power off reset registers, forcing
the state to switch to ACTIVE mode"
0b10 means "Reset all the power off reset registers, forcing
the state to switch to ACTIVE mode, and simultaneously
pull down the RESETB PIN for 5mS before releasing"
0b11 means the same as for 0b10 just above.

This adds the appropriate logic in the driver to parse the new
rockchip,reset-mode DT property to pass this information. It just
happens that the values in the binding match the values to write in the
bitfield so no mapping is necessary.

If it is missing, the register is left untouched and relies either on
the silicon default or on whatever was set earlier in the boot stages
(e.g. the bootloader).

Signed-off-by: Quentin Schulz <quentin.schulz@cherry.de>
Link: https://lore.kernel.org/r/20250627-rk8xx-rst-fun-v4-2-ce05d041b45f@cherry.de
Signed-off-by: Lee Jones <lee@kernel.org>
drivers/mfd/rk8xx-core.c
include/linux/mfd/rk808.h

index 71c2b80a4678d627e86cfbec8135f08e262559d3..def4587fdfb8b82e5548e70310d3e16e6d07d7af 100644 (file)
@@ -10,6 +10,7 @@
  * Author: Wadim Egorov <w.egorov@phytec.de>
  */
 
+#include <linux/bitfield.h>
 #include <linux/interrupt.h>
 #include <linux/mfd/rk808.h>
 #include <linux/mfd/core.h>
@@ -699,6 +700,7 @@ int rk8xx_probe(struct device *dev, int variant, unsigned int irq, struct regmap
        const struct mfd_cell *cells;
        int dual_support = 0;
        int nr_pre_init_regs;
+       u32 rst_fun = 0;
        int nr_cells;
        int ret;
        int i;
@@ -726,6 +728,16 @@ int rk8xx_probe(struct device *dev, int variant, unsigned int irq, struct regmap
                cells = rk806s;
                nr_cells = ARRAY_SIZE(rk806s);
                dual_support = IRQF_SHARED;
+
+               ret = device_property_read_u32(dev, "rockchip,reset-mode", &rst_fun);
+               if (ret)
+                       break;
+
+               ret = regmap_update_bits(rk808->regmap, RK806_SYS_CFG3, RK806_RST_FUN_MSK,
+                                        FIELD_PREP(RK806_RST_FUN_MSK, rst_fun));
+               if (ret)
+                       return dev_err_probe(dev, ret,
+                                            "Failed to configure requested restart/reset behavior\n");
                break;
        case RK808_ID:
                rk808->regmap_irq_chip = &rk808_irq_chip;
index 69cbea78b430b562a23d995263369d475daa6287..28170ee08898ca59c76a741a1d42763a42b72380 100644 (file)
@@ -812,6 +812,8 @@ enum rk806_pin_dr_sel {
 #define RK806_INT_POL_H                        BIT(1)
 #define RK806_INT_POL_L                        0
 
+/* SYS_CFG3 */
+#define RK806_RST_FUN_MSK              GENMASK(7, 6)
 #define RK806_SLAVE_RESTART_FUN_MSK    BIT(1)
 #define RK806_SLAVE_RESTART_FUN_EN     BIT(1)
 #define RK806_SLAVE_RESTART_FUN_OFF    0