xref: /freebsd/sys/arm/mv/clk/periph_clk_gate.c (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
1f21c469dSHubert Mazur /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3f21c469dSHubert Mazur  *
4f21c469dSHubert Mazur  * Copyright (c) 2021 Semihalf.
5f21c469dSHubert Mazur  *
6f21c469dSHubert Mazur  * Redistribution and use in source and binary forms, with or without
7f21c469dSHubert Mazur  * modification, are permitted provided that the following conditions
8f21c469dSHubert Mazur  * are met:
9f21c469dSHubert Mazur  * 1. Redistributions of source code must retain the above copyright
10f21c469dSHubert Mazur  *    notice, this list of conditions and the following disclaimer.
11f21c469dSHubert Mazur  * 2. Redistributions in binary form must reproduce the above copyright
12f21c469dSHubert Mazur  *    notice, this list of conditions and the following disclaimer in the
13f21c469dSHubert Mazur  *    documentation and/or other materials provided with the distribution.
14f21c469dSHubert Mazur  *
15f21c469dSHubert Mazur  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16f21c469dSHubert Mazur  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17f21c469dSHubert Mazur  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18f21c469dSHubert Mazur  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19f21c469dSHubert Mazur  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20f21c469dSHubert Mazur  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21f21c469dSHubert Mazur  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22f21c469dSHubert Mazur  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23f21c469dSHubert Mazur  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24f21c469dSHubert Mazur  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25f21c469dSHubert Mazur  * SUCH DAMAGE.
26f21c469dSHubert Mazur  */
27f21c469dSHubert Mazur 
28f21c469dSHubert Mazur #include <sys/cdefs.h>
29f21c469dSHubert Mazur __FBSDID("$FreeBSD$");
30f21c469dSHubert Mazur 
31f21c469dSHubert Mazur #include <sys/param.h>
32f21c469dSHubert Mazur #include <sys/bus.h>
33f21c469dSHubert Mazur #include <sys/kernel.h>
34f21c469dSHubert Mazur #include <sys/module.h>
35f21c469dSHubert Mazur #include <sys/mutex.h>
36f21c469dSHubert Mazur #include <sys/rman.h>
37f21c469dSHubert Mazur #include <machine/bus.h>
38f21c469dSHubert Mazur 
39f21c469dSHubert Mazur #include <dev/fdt/simplebus.h>
40f21c469dSHubert Mazur 
41f21c469dSHubert Mazur #include <dev/extres/clk/clk.h>
42f21c469dSHubert Mazur #include <dev/extres/clk/clk_div.h>
43f21c469dSHubert Mazur #include <dev/extres/clk/clk_fixed.h>
44f21c469dSHubert Mazur #include <dev/extres/clk/clk_gate.h>
45f21c469dSHubert Mazur #include <dev/extres/clk/clk_mux.h>
46f21c469dSHubert Mazur 
47f21c469dSHubert Mazur #include <dev/ofw/ofw_bus.h>
48f21c469dSHubert Mazur #include <dev/ofw/ofw_bus_subr.h>
49f21c469dSHubert Mazur 
50f21c469dSHubert Mazur #include "clkdev_if.h"
51f21c469dSHubert Mazur #include "periph.h"
52f21c469dSHubert Mazur 
53f21c469dSHubert Mazur /*
54f21c469dSHubert Mazur  * Regsiter gate clock (disable or enable clock).
55f21c469dSHubert Mazur  */
56f21c469dSHubert Mazur 
57f21c469dSHubert Mazur int
58f21c469dSHubert Mazur a37x0_periph_gate_register_gate(struct clkdom *clkdom,
59f21c469dSHubert Mazur     struct a37x0_periph_clknode_def *device_def)
60f21c469dSHubert Mazur {
61f21c469dSHubert Mazur 	struct clk_gate_def *gate;
62f21c469dSHubert Mazur 	const char *parent_name;
63f21c469dSHubert Mazur 	int error, dev_id;
64f21c469dSHubert Mazur 
65f21c469dSHubert Mazur 	dev_id = device_def->common_def.device_id;
66f21c469dSHubert Mazur 	gate = &device_def->clk_def.gate.gate;
67f21c469dSHubert Mazur 
68f21c469dSHubert Mazur 	if (device_def->common_def.pname == NULL)
69f21c469dSHubert Mazur 		parent_name = device_def->common_def.xtal;
70f21c469dSHubert Mazur 	else
71f21c469dSHubert Mazur 		parent_name = device_def->common_def.pname;
72f21c469dSHubert Mazur 
73f21c469dSHubert Mazur 	a37x0_periph_set_props(&gate->clkdef, &parent_name, 1);
74f21c469dSHubert Mazur 	error = a37x0_periph_create_gate(clkdom, gate,
75f21c469dSHubert Mazur 	    dev_id);
76f21c469dSHubert Mazur 	if (error) goto fail;
77f21c469dSHubert Mazur 
78f21c469dSHubert Mazur 	fail:
79f21c469dSHubert Mazur 		return (error);
80f21c469dSHubert Mazur 
81f21c469dSHubert Mazur 	return (0);
82f21c469dSHubert Mazur }
83