1 // SPDX-License-Identifier: GPL-2.0
3 * (C) Copyright 2017 Rockchip Electronics Co., Ltd
10 #include <reset-uclass.h>
11 #include <linux/bitops.h>
13 #include <asm/arch-rockchip/hardware.h>
14 #include <dm/device-internal.h>
17 * Each reg has 16 bits reset signal for devices
18 * Note: Not including rk2818 and older SoCs
20 #define ROCKCHIP_RESET_NUM_IN_REG 16
22 struct rockchip_reset_priv {
24 /* Rockchip reset reg locate at cru controller */
26 /* Rockchip reset reg number */
30 static int rockchip_reset_request(struct reset_ctl *reset_ctl)
32 struct rockchip_reset_priv *priv = dev_get_priv(reset_ctl->dev);
34 debug("%s(reset_ctl=%p) (dev=%p, id=%lu) (reg_num=%d)\n", __func__,
35 reset_ctl, reset_ctl->dev, reset_ctl->id, priv->reset_reg_num);
37 if (reset_ctl->id / ROCKCHIP_RESET_NUM_IN_REG >= priv->reset_reg_num)
43 static int rockchip_reset_assert(struct reset_ctl *reset_ctl)
45 struct rockchip_reset_priv *priv = dev_get_priv(reset_ctl->dev);
46 int bank = reset_ctl->id / ROCKCHIP_RESET_NUM_IN_REG;
47 int offset = reset_ctl->id % ROCKCHIP_RESET_NUM_IN_REG;
49 debug("%s(reset_ctl=%p) (dev=%p, id=%lu) (reg_addr=%p)\n", __func__,
50 reset_ctl, reset_ctl->dev, reset_ctl->id,
51 priv->base + (bank * 4));
53 rk_setreg(priv->base + (bank * 4), BIT(offset));
58 static int rockchip_reset_deassert(struct reset_ctl *reset_ctl)
60 struct rockchip_reset_priv *priv = dev_get_priv(reset_ctl->dev);
61 int bank = reset_ctl->id / ROCKCHIP_RESET_NUM_IN_REG;
62 int offset = reset_ctl->id % ROCKCHIP_RESET_NUM_IN_REG;
64 debug("%s(reset_ctl=%p) (dev=%p, id=%lu) (reg_addr=%p)\n", __func__,
65 reset_ctl, reset_ctl->dev, reset_ctl->id,
66 priv->base + (bank * 4));
68 rk_clrreg(priv->base + (bank * 4), BIT(offset));
73 struct reset_ops rockchip_reset_ops = {
74 .request = rockchip_reset_request,
75 .rst_assert = rockchip_reset_assert,
76 .rst_deassert = rockchip_reset_deassert,
79 static int rockchip_reset_probe(struct udevice *dev)
81 struct rockchip_reset_priv *priv = dev_get_priv(dev);
85 addr = dev_read_addr_size(dev, "reg", &size);
86 if (addr == FDT_ADDR_T_NONE)
89 if ((priv->reset_reg_offset == 0) && (priv->reset_reg_num == 0))
92 addr += priv->reset_reg_offset;
93 priv->base = ioremap(addr, size);
95 debug("%s(base=%p) (reg_offset=%x, reg_num=%d)\n", __func__,
96 priv->base, priv->reset_reg_offset, priv->reset_reg_num);
101 int rockchip_reset_bind(struct udevice *pdev, u32 reg_offset, u32 reg_number)
103 struct udevice *rst_dev;
104 struct rockchip_reset_priv *priv;
107 ret = device_bind_driver_to_node(pdev, "rockchip_reset", "reset",
108 dev_ofnode(pdev), &rst_dev);
110 debug("Warning: No rockchip reset driver: ret=%d\n", ret);
113 priv = malloc(sizeof(struct rockchip_reset_priv));
114 priv->reset_reg_offset = reg_offset;
115 priv->reset_reg_num = reg_number;
116 dev_set_priv(rst_dev, priv);
121 U_BOOT_DRIVER(rockchip_reset) = {
122 .name = "rockchip_reset",
124 .probe = rockchip_reset_probe,
125 .ops = &rockchip_reset_ops,
126 .priv_auto = sizeof(struct rockchip_reset_priv),