1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2023 Beckhoff Automation GmbH & Co. KG 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28 #include <sys/cdefs.h> 29 30 #include <sys/param.h> 31 #include <sys/systm.h> 32 #include <sys/bus.h> 33 34 #include <dev/clk/clk.h> 35 36 #include <dev/clk/xilinx/zynqmp_clk_mux.h> 37 38 #include "clkdev_if.h" 39 #include "zynqmp_firmware_if.h" 40 41 struct zynqmp_clk_mux_softc { 42 device_t firmware; 43 uint32_t id; 44 }; 45 46 static int 47 zynqmp_clk_mux_init(struct clknode *clk, device_t dev) 48 { 49 50 clknode_init_parent_idx(clk, 0); 51 return (0); 52 } 53 54 static int 55 zynqmp_clk_mux_set_mux(struct clknode *clk, int idx) 56 { 57 58 printf("%s: called for %s\n", __func__, clknode_get_name(clk)); 59 return (0); 60 } 61 62 static clknode_method_t zynqmp_clk_mux_clknode_methods[] = { 63 /* Device interface */ 64 CLKNODEMETHOD(clknode_init, zynqmp_clk_mux_init), 65 CLKNODEMETHOD(clknode_set_mux, zynqmp_clk_mux_set_mux), 66 CLKNODEMETHOD_END 67 }; 68 69 DEFINE_CLASS_1(zynqmp_clk_mux_clknode, zynqmp_clk_mux_clknode_class, 70 zynqmp_clk_mux_clknode_methods, sizeof(struct zynqmp_clk_mux_softc), clknode_class); 71 72 int 73 zynqmp_clk_mux_register(struct clkdom *clkdom, device_t fw, struct clknode_init_def *clkdef) 74 { 75 struct clknode *clk; 76 struct zynqmp_clk_mux_softc *sc; 77 uint32_t fw_clk_id; 78 79 fw_clk_id = clkdef->id - 1; 80 clkdef->id = 0; 81 clk = clknode_create(clkdom, &zynqmp_clk_mux_clknode_class, clkdef); 82 if (clk == NULL) 83 return (1); 84 sc = clknode_get_softc(clk); 85 sc->id = fw_clk_id; 86 sc->firmware = fw; 87 clknode_register(clkdom, clk); 88 return (0); 89 } 90