blob: a678b8f745696719df6566fa249791accdfd89a6 [file] [log] [blame]
Shawn Guo8aa8f302019-03-20 15:32:39 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2019, Linaro Limited
4 */
5
Simon Glass9bc15642020-02-03 07:36:16 -07006#include <malloc.h>
Shawn Guo8aa8f302019-03-20 15:32:39 +08007#include <asm/io.h>
8#include <common.h>
9#include <dm.h>
10#include <dt-bindings/reset/ti-syscon.h>
11#include <reset-uclass.h>
12
13struct hisi_reset_priv {
14 void __iomem *base;
15};
16
17static int hisi_reset_deassert(struct reset_ctl *rst)
18{
19 struct hisi_reset_priv *priv = dev_get_priv(rst->dev);
20 u32 val;
21
22 val = readl(priv->base + rst->data);
23 if (rst->polarity & DEASSERT_SET)
24 val |= BIT(rst->id);
25 else
26 val &= ~BIT(rst->id);
27 writel(val, priv->base + rst->data);
28
29 return 0;
30}
31
32static int hisi_reset_assert(struct reset_ctl *rst)
33{
34 struct hisi_reset_priv *priv = dev_get_priv(rst->dev);
35 u32 val;
36
37 val = readl(priv->base + rst->data);
38 if (rst->polarity & ASSERT_SET)
39 val |= BIT(rst->id);
40 else
41 val &= ~BIT(rst->id);
42 writel(val, priv->base + rst->data);
43
44 return 0;
45}
46
47static int hisi_reset_free(struct reset_ctl *rst)
48{
49 return 0;
50}
51
52static int hisi_reset_request(struct reset_ctl *rst)
53{
54 return 0;
55}
56
57static int hisi_reset_of_xlate(struct reset_ctl *rst,
58 struct ofnode_phandle_args *args)
59{
60 if (args->args_count != 3) {
61 debug("Invalid args_count: %d\n", args->args_count);
62 return -EINVAL;
63 }
64
65 /* Use .data field as register offset and .id field as bit shift */
66 rst->data = args->args[0];
67 rst->id = args->args[1];
68 rst->polarity = args->args[2];
69
70 return 0;
71}
72
73static const struct reset_ops hisi_reset_reset_ops = {
74 .of_xlate = hisi_reset_of_xlate,
75 .request = hisi_reset_request,
Simon Glass1928cd42020-02-03 07:35:52 -070076 .rfree = hisi_reset_free,
Shawn Guo8aa8f302019-03-20 15:32:39 +080077 .rst_assert = hisi_reset_assert,
78 .rst_deassert = hisi_reset_deassert,
79};
80
81static const struct udevice_id hisi_reset_ids[] = {
82 { .compatible = "hisilicon,hi3798cv200-reset" },
83 { }
84};
85
86static int hisi_reset_probe(struct udevice *dev)
87{
88 struct hisi_reset_priv *priv = dev_get_priv(dev);
89
90 priv->base = dev_remap_addr(dev);
91 if (!priv->base)
92 return -ENOMEM;
93
94 return 0;
95}
96
97U_BOOT_DRIVER(hisi_reset) = {
98 .name = "hisilicon_reset",
99 .id = UCLASS_RESET,
100 .of_match = hisi_reset_ids,
101 .ops = &hisi_reset_reset_ops,
102 .probe = hisi_reset_probe,
103 .priv_auto_alloc_size = sizeof(struct hisi_reset_priv),
104};