xref: /freebsd-14.2/sys/dev/extres/clk/clk_link.c (revision 685dc743)
1 /*-
2  * Copyright 2016 Michal Meloun <[email protected]>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #include <sys/cdefs.h>
28 #include <sys/param.h>
29 #include <sys/conf.h>
30 #include <sys/bus.h>
31 #include <sys/kernel.h>
32 #include <sys/kobj.h>
33 #include <sys/malloc.h>
34 #include <sys/mutex.h>
35 #include <sys/module.h>
36 #include <sys/rman.h>
37 #include <sys/systm.h>
38 
39 #include <machine/bus.h>
40 
41 #include <dev/extres/clk/clk_link.h>
42 
43 static int clknode_link_init(struct clknode *clk, device_t dev);
44 static int clknode_link_recalc(struct clknode *clk, uint64_t *freq);
45 static int clknode_link_set_freq(struct clknode *clk, uint64_t fin,
46     uint64_t *fout, int flags, int *stop);
47 static int clknode_link_set_mux(struct clknode *clk, int idx);
48 static int clknode_link_set_gate(struct clknode *clk, bool enable);
49 
50 static clknode_method_t clknode_link_methods[] = {
51 	/* Device interface */
52 	CLKNODEMETHOD(clknode_init,	   clknode_link_init),
53 	CLKNODEMETHOD(clknode_recalc_freq, clknode_link_recalc),
54 	CLKNODEMETHOD(clknode_set_freq,	   clknode_link_set_freq),
55 	CLKNODEMETHOD(clknode_set_gate,	   clknode_link_set_gate),
56 	CLKNODEMETHOD(clknode_set_mux,	   clknode_link_set_mux),
57 	CLKNODEMETHOD_END
58 };
59 DEFINE_CLASS_1(clknode_link, clknode_link_class, clknode_link_methods,
60    0, clknode_class);
61 
62 static int
clknode_link_init(struct clknode * clk,device_t dev)63 clknode_link_init(struct clknode *clk, device_t dev)
64 {
65 	return(0);
66 }
67 
68 static int
clknode_link_recalc(struct clknode * clk,uint64_t * freq)69 clknode_link_recalc(struct clknode *clk, uint64_t *freq)
70 {
71 
72 	printf("%s: Attempt to use unresolved linked clock: %s\n", __func__,
73 	    clknode_get_name(clk));
74 	return (EBADF);
75 }
76 
77 static int
clknode_link_set_freq(struct clknode * clk,uint64_t fin,uint64_t * fout,int flags,int * stop)78 clknode_link_set_freq(struct clknode *clk, uint64_t fin, uint64_t *fout,
79     int flags, int *stop)
80 {
81 
82 	printf("%s: Attempt to use unresolved linked clock: %s\n", __func__,
83 	    clknode_get_name(clk));
84 	return (EBADF);
85 }
86 
87 static int
clknode_link_set_mux(struct clknode * clk,int idx)88 clknode_link_set_mux(struct clknode *clk, int idx)
89 {
90 
91 	printf("%s: Attempt to use unresolved linked clock: %s\n", __func__,
92 	    clknode_get_name(clk));
93 	return (EBADF);
94 }
95 
96 static int
clknode_link_set_gate(struct clknode * clk,bool enable)97 clknode_link_set_gate(struct clknode *clk, bool enable)
98 {
99 
100 	printf("%s: Attempt to use unresolved linked clock: %s\n", __func__,
101 	    clknode_get_name(clk));
102 	return (EBADF);
103 }
104 
105 int
clknode_link_register(struct clkdom * clkdom,struct clk_link_def * clkdef)106 clknode_link_register(struct clkdom *clkdom, struct clk_link_def *clkdef)
107 {
108 	struct clknode *clk;
109 	struct clknode_init_def tmp;
110 
111 	tmp = clkdef->clkdef;
112 	tmp.flags |= CLK_NODE_LINKED;
113 	clk = clknode_create(clkdom, &clknode_link_class, &tmp);
114 	if (clk == NULL)
115 		return (1);
116 	clknode_register(clkdom, clk);
117 	return (0);
118 }
119