xref: /openbsd/sys/arch/armv7/omap/omsysc.c (revision 09467b48)
1 /* $OpenBSD: omsysc.c,v 1.1 2020/04/10 22:02:45 kettenis Exp $ */
2 /*
3  * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #include <sys/param.h>
19 #include <sys/systm.h>
20 #include <sys/device.h>
21 
22 #include <machine/fdt.h>
23 
24 #include <dev/ofw/openfirm.h>
25 #include <dev/ofw/ofw_clock.h>
26 #include <dev/ofw/fdt.h>
27 
28 #include <arm/simplebus/simplebusvar.h>
29 
30 struct omsysc_softc {
31 	struct simplebus_softc	sc_bus;
32 };
33 
34 int	omsysc_match(struct device *, void *, void *);
35 void	omsysc_attach(struct device *, struct device *, void *);
36 
37 struct cfattach omsysc_ca = {
38 	sizeof(struct omsysc_softc), omsysc_match, omsysc_attach
39 };
40 
41 struct cfdriver omsysc_cd = {
42 	NULL, "omsysc", DV_DULL
43 };
44 
45 int
46 omsysc_match(struct device *parent, void *cfdata, void *aux)
47 {
48 	struct fdt_attach_args *faa = aux;
49 	struct cfdata *cf = cfdata;
50 	int node;
51 
52 	/*
53 	 * On AM33xx we need to make sure we attach the PRCM and SCM
54 	 * modules since they provide clock and pinctrl for other
55 	 * hardware modules.  Therefore we attach those during the
56 	 * "early" phase.
57 	 */
58 	node = OF_child(faa->fa_node);
59 	if (node && cf->cf_loc[0]) {
60 		return (OF_is_compatible(node, "ti,am3-prcm") ||
61 		    OF_is_compatible(node, "ti,am3-scm"));
62 	}
63 
64 	return OF_is_compatible(faa->fa_node, "ti,sysc");
65 }
66 
67 void
68 omsysc_attach(struct device *parent, struct device *self, void *aux)
69 {
70 	struct omsysc_softc *sc = (struct omsysc_softc *)self;
71 	struct fdt_attach_args *faa = aux;
72 
73 	if (OF_getproplen(faa->fa_node, "ti,hwmods") < 0 &&
74 	    OF_is_compatible(faa->fa_node, "ti,sysc-omap2"))
75 		clock_enable(faa->fa_node, "fck");
76 
77 	simplebus_attach(parent, &sc->sc_bus.sc_dev, faa);
78 }
79