1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
/* $OpenBSD: hireset.c,v 1.1 2018/08/27 14:12:59 kettenis Exp $ */
/*
* Copyright (c) 2018 Mark Kettenis <kettenis@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <machine/intr.h>
#include <machine/bus.h>
#include <machine/fdt.h>
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_clock.h>
#include <dev/ofw/ofw_misc.h>
#include <dev/ofw/fdt.h>
struct hireset_softc {
struct device sc_dev;
uint32_t sc_rst_syscon;
struct reset_device sc_rd;
};
int hireset_match(struct device *, void *, void *);
void hireset_attach(struct device *, struct device *, void *);
struct cfattach hireset_ca = {
sizeof (struct hireset_softc), hireset_match, hireset_attach
};
struct cfdriver hireset_cd = {
NULL, "hireset", DV_DULL
};
void hireset_reset(void *, uint32_t *, int);
int
hireset_match(struct device *parent, void *match, void *aux)
{
struct fdt_attach_args *faa = aux;
return OF_is_compatible(faa->fa_node, "hisilicon,hi3660-reset");
}
void
hireset_attach(struct device *parent, struct device *self, void *aux)
{
struct hireset_softc *sc = (struct hireset_softc *)self;
struct fdt_attach_args *faa = aux;
sc->sc_rst_syscon = OF_getpropint(faa->fa_node, "hisi,rst-syscon", 0);
printf("\n");
sc->sc_rd.rd_node = faa->fa_node;
sc->sc_rd.rd_cookie = sc;
sc->sc_rd.rd_reset = hireset_reset;
reset_register(&sc->sc_rd);
}
void
hireset_reset(void *cookie, uint32_t *cells, int on)
{
struct hireset_softc *sc = cookie;
struct regmap *rm;
uint32_t offset = cells[0];
uint32_t bit = cells[1];
rm = regmap_byphandle(sc->sc_rst_syscon);
if (rm == NULL) {
printf("%s: can't find regmap\n", sc->sc_dev.dv_xname);
return;
}
if (on)
regmap_write_4(rm, offset + 0, (1 << bit));
else
regmap_write_4(rm, offset + 4, (1 << bit));
}
|