blob: 24b87ee987dbe7d0477632d049c796655eeed8e3 [file] [log] [blame]
Sergiu Moga71d43932022-04-01 12:27:24 +03001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2022 Microchip Technology, Inc. and its subsidiaries
4 */
5
6#include <asm/arch/hardware.h>
7#include <asm/io.h>
8#include <asm/arch/at91_rstc.h>
9#include <clk.h>
10#include <common.h>
11#include <cpu_func.h>
12#include <dm.h>
13#include <dm/device_compat.h>
14#include <dm/device-internal.h>
15#include <sysreset.h>
16
17static int at91_sysreset_request(struct udevice *dev, enum sysreset_t type)
18{
19 at91_rstc_t *rstc = (at91_rstc_t *)dev_get_priv(dev);
20
21 writel(AT91_RSTC_KEY
22 | AT91_RSTC_CR_PROCRST /* Processor Reset */
23 | AT91_RSTC_CR_PERRST /* Peripheral Reset */
24#ifdef CONFIG_AT91RESET_EXTRST
25 | AT91_RSTC_CR_EXTRST /* External Reset (assert nRST pin) */
26#endif
27 , &rstc->cr);
28
29 return -EINPROGRESS;
30}
31
32static int at91_sysreset_probe(struct udevice *dev)
33{
34 struct clk slck;
35 void *priv;
36 int ret;
37
38 priv = dev_remap_addr(dev);
39 if (!priv)
40 return -EINVAL;
41
42 dev_set_priv(dev, priv);
43
44 ret = clk_get_by_index(dev, 0, &slck);
45 if (ret)
46 return ret;
47
48 ret = clk_prepare_enable(&slck);
49 if (ret)
50 return ret;
51
52 return 0;
53}
54
55static struct sysreset_ops at91_sysreset = {
56 .request = at91_sysreset_request,
57};
58
59static const struct udevice_id a91_sysreset_ids[] = {
60 { .compatible = "atmel,sama5d3-rstc" },
61 { .compatible = "microchip,sam9x60-rstc" },
62 { }
63};
64
65U_BOOT_DRIVER(sysreset_at91) = {
66 .id = UCLASS_SYSRESET,
67 .name = "at91_reset",
68 .ops = &at91_sysreset,
69 .probe = at91_sysreset_probe,
70 .of_match = a91_sysreset_ids,
71};