xref: /openbsd-src/sys/arch/armv7/omap/omsysc.c (revision 94673892b7b28179327a9d4cb100f53993b0bd92)
1 /* $OpenBSD: omsysc.c,v 1.4 2023/09/22 01:10:43 jsg 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/device.h>
20 
21 #include <machine/fdt.h>
22 
23 #include <dev/ofw/openfirm.h>
24 #include <dev/ofw/ofw_clock.h>
25 #include <dev/ofw/fdt.h>
26 
27 #include <machine/simplebusvar.h>
28 
29 struct omsysc_softc {
30 	struct simplebus_softc	sc_bus;
31 };
32 
33 int	omsysc_match(struct device *, void *, void *);
34 void	omsysc_attach(struct device *, struct device *, void *);
35 
36 const struct cfattach omsysc_ca = {
37 	sizeof(struct omsysc_softc), omsysc_match, omsysc_attach
38 };
39 
40 struct cfdriver omsysc_cd = {
41 	NULL, "omsysc", DV_DULL
42 };
43 
44 int
omsysc_match(struct device * parent,void * cfdata,void * aux)45 omsysc_match(struct device *parent, void *cfdata, void *aux)
46 {
47 	struct fdt_attach_args *faa = aux;
48 	struct cfdata *cf = cfdata;
49 	int node;
50 
51 	/*
52 	 * On AM33xx we need to make sure we attach the PRCM and SCM
53 	 * modules since they provide clock and pinctrl for other
54 	 * hardware modules.  Therefore we attach those during the
55 	 * "early" phase.
56 	 */
57 	node = OF_child(faa->fa_node);
58 	if (node && cf->cf_loc[0]) {
59 		return (OF_is_compatible(node, "ti,am3-prcm") ||
60 		    OF_is_compatible(node, "ti,am3-scm"));
61 	}
62 
63 	return OF_is_compatible(faa->fa_node, "ti,sysc");
64 }
65 
66 void
omsysc_attach(struct device * parent,struct device * self,void * aux)67 omsysc_attach(struct device *parent, struct device *self, void *aux)
68 {
69 	struct omsysc_softc *sc = (struct omsysc_softc *)self;
70 	struct fdt_attach_args *faa = aux;
71 
72 	if (OF_getproplen(faa->fa_node, "ti,hwmods") < 0 &&
73 	    OF_is_compatible(faa->fa_node, "ti,sysc-omap2"))
74 		clock_enable(faa->fa_node, "fck");
75 
76 	simplebus_attach(parent, &sc->sc_bus.sc_dev, faa);
77 }
78