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