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