1f21c469dSHubert Mazur /*-
24d846d26SWarner 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/param.h>
29f21c469dSHubert Mazur #include <sys/bus.h>
30f21c469dSHubert Mazur #include <sys/kernel.h>
31f21c469dSHubert Mazur #include <sys/module.h>
32f21c469dSHubert Mazur #include <sys/mutex.h>
33f21c469dSHubert Mazur #include <sys/rman.h>
34f21c469dSHubert Mazur #include <machine/bus.h>
35f21c469dSHubert Mazur
36f21c469dSHubert Mazur #include <dev/fdt/simplebus.h>
37f21c469dSHubert Mazur
38*be82b3a0SEmmanuel Vadot #include <dev/clk/clk.h>
39*be82b3a0SEmmanuel Vadot #include <dev/clk/clk_div.h>
40*be82b3a0SEmmanuel Vadot #include <dev/clk/clk_fixed.h>
41*be82b3a0SEmmanuel Vadot #include <dev/clk/clk_gate.h>
42*be82b3a0SEmmanuel Vadot #include <dev/clk/clk_mux.h>
43f21c469dSHubert Mazur
44f21c469dSHubert Mazur #include <dev/ofw/ofw_bus.h>
45f21c469dSHubert Mazur #include <dev/ofw/ofw_bus_subr.h>
46f21c469dSHubert Mazur
47f21c469dSHubert Mazur #include "clkdev_if.h"
48f21c469dSHubert Mazur #include "periph.h"
49f21c469dSHubert Mazur
50f21c469dSHubert Mazur /*
51f21c469dSHubert Mazur * Regsiter gate clock (disable or enable clock).
52f21c469dSHubert Mazur */
53f21c469dSHubert Mazur
54f21c469dSHubert Mazur int
a37x0_periph_gate_register_gate(struct clkdom * clkdom,struct a37x0_periph_clknode_def * device_def)55f21c469dSHubert Mazur a37x0_periph_gate_register_gate(struct clkdom *clkdom,
56f21c469dSHubert Mazur struct a37x0_periph_clknode_def *device_def)
57f21c469dSHubert Mazur {
58f21c469dSHubert Mazur struct clk_gate_def *gate;
59f21c469dSHubert Mazur const char *parent_name;
60f21c469dSHubert Mazur int error, dev_id;
61f21c469dSHubert Mazur
62f21c469dSHubert Mazur dev_id = device_def->common_def.device_id;
63f21c469dSHubert Mazur gate = &device_def->clk_def.gate.gate;
64f21c469dSHubert Mazur
65f21c469dSHubert Mazur if (device_def->common_def.pname == NULL)
66f21c469dSHubert Mazur parent_name = device_def->common_def.xtal;
67f21c469dSHubert Mazur else
68f21c469dSHubert Mazur parent_name = device_def->common_def.pname;
69f21c469dSHubert Mazur
70f21c469dSHubert Mazur a37x0_periph_set_props(&gate->clkdef, &parent_name, 1);
71f21c469dSHubert Mazur error = a37x0_periph_create_gate(clkdom, gate,
72f21c469dSHubert Mazur dev_id);
73f21c469dSHubert Mazur if (error) goto fail;
74f21c469dSHubert Mazur
75f21c469dSHubert Mazur fail:
76f21c469dSHubert Mazur return (error);
77f21c469dSHubert Mazur
78f21c469dSHubert Mazur return (0);
79f21c469dSHubert Mazur }
80