1 // SPDX-License-Identifier: GPL-2.0
3 * (C) Copyright 2017 Rockchip Electronics Co., Ltd
8 #include <reset-uclass.h>
10 #include <asm/arch/hardware.h>
13 * Each reg has 16 bits reset signal for devices
14 * Note: Not including rk2818 and older SoCs
16 #define ROCKCHIP_RESET_NUM_IN_REG 16
18 struct rockchip_reset_priv {
20 /* Rockchip reset reg locate at cru controller */
22 /* Rockchip reset reg number */
26 static int rockchip_reset_request(struct reset_ctl *reset_ctl)
28 struct rockchip_reset_priv *priv = dev_get_priv(reset_ctl->dev);
30 debug("%s(reset_ctl=%p) (dev=%p, id=%lu) (reg_num=%d)\n", __func__,
31 reset_ctl, reset_ctl->dev, reset_ctl->id, priv->reset_reg_num);
33 if (reset_ctl->id / ROCKCHIP_RESET_NUM_IN_REG >= priv->reset_reg_num)
39 static int rockchip_reset_free(struct reset_ctl *reset_ctl)
41 debug("%s(reset_ctl=%p) (dev=%p, id=%lu)\n", __func__, reset_ctl,
42 reset_ctl->dev, reset_ctl->id);
47 static int rockchip_reset_assert(struct reset_ctl *reset_ctl)
49 struct rockchip_reset_priv *priv = dev_get_priv(reset_ctl->dev);
50 int bank = reset_ctl->id / ROCKCHIP_RESET_NUM_IN_REG;
51 int offset = reset_ctl->id % ROCKCHIP_RESET_NUM_IN_REG;
53 debug("%s(reset_ctl=%p) (dev=%p, id=%lu) (reg_addr=%p)\n", __func__,
54 reset_ctl, reset_ctl->dev, reset_ctl->id,
55 priv->base + (bank * 4));
57 rk_setreg(priv->base + (bank * 4), BIT(offset));
62 static int rockchip_reset_deassert(struct reset_ctl *reset_ctl)
64 struct rockchip_reset_priv *priv = dev_get_priv(reset_ctl->dev);
65 int bank = reset_ctl->id / ROCKCHIP_RESET_NUM_IN_REG;
66 int offset = reset_ctl->id % ROCKCHIP_RESET_NUM_IN_REG;
68 debug("%s(reset_ctl=%p) (dev=%p, id=%lu) (reg_addr=%p)\n", __func__,
69 reset_ctl, reset_ctl->dev, reset_ctl->id,
70 priv->base + (bank * 4));
72 rk_clrreg(priv->base + (bank * 4), BIT(offset));
77 struct reset_ops rockchip_reset_ops = {
78 .request = rockchip_reset_request,
79 .free = rockchip_reset_free,
80 .rst_assert = rockchip_reset_assert,
81 .rst_deassert = rockchip_reset_deassert,
84 static int rockchip_reset_probe(struct udevice *dev)
86 struct rockchip_reset_priv *priv = dev_get_priv(dev);
90 addr = dev_read_addr_size(dev, "reg", &size);
91 if (addr == FDT_ADDR_T_NONE)
94 if ((priv->reset_reg_offset == 0) && (priv->reset_reg_num == 0))
97 addr += priv->reset_reg_offset;
98 priv->base = ioremap(addr, size);
100 debug("%s(base=%p) (reg_offset=%x, reg_num=%d)\n", __func__,
101 priv->base, priv->reset_reg_offset, priv->reset_reg_num);
106 int rockchip_reset_bind(struct udevice *pdev, u32 reg_offset, u32 reg_number)
108 struct udevice *rst_dev;
109 struct rockchip_reset_priv *priv;
112 ret = device_bind_driver_to_node(pdev, "rockchip_reset", "reset",
113 dev_ofnode(pdev), &rst_dev);
115 debug("Warning: No rockchip reset driver: ret=%d\n", ret);
118 priv = malloc(sizeof(struct rockchip_reset_priv));
119 priv->reset_reg_offset = reg_offset;
120 priv->reset_reg_num = reg_number;
121 rst_dev->priv = priv;
126 U_BOOT_DRIVER(rockchip_reset) = {
127 .name = "rockchip_reset",
129 .probe = rockchip_reset_probe,
130 .ops = &rockchip_reset_ops,
131 .priv_auto_alloc_size = sizeof(struct rockchip_reset_priv),