1*e34a491bSAdrian Chadd /*-
2*e34a491bSAdrian Chadd * Copyright (c) 2021 Adrian Chadd <adrian@FreeBSD.org>.
3*e34a491bSAdrian Chadd *
4*e34a491bSAdrian Chadd * Redistribution and use in source and binary forms, with or without
5*e34a491bSAdrian Chadd * modification, are permitted provided that the following conditions
6*e34a491bSAdrian Chadd * are met:
7*e34a491bSAdrian Chadd * 1. Redistributions of source code must retain the above copyright
8*e34a491bSAdrian Chadd * notice, this list of conditions and the following disclaimer.
9*e34a491bSAdrian Chadd * 2. Redistributions in binary form must reproduce the above copyright
10*e34a491bSAdrian Chadd * notice, this list of conditions and the following disclaimer in the
11*e34a491bSAdrian Chadd * documentation and/or other materials provided with the distribution.
12*e34a491bSAdrian Chadd *
13*e34a491bSAdrian Chadd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14*e34a491bSAdrian Chadd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15*e34a491bSAdrian Chadd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16*e34a491bSAdrian Chadd * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17*e34a491bSAdrian Chadd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18*e34a491bSAdrian Chadd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19*e34a491bSAdrian Chadd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20*e34a491bSAdrian Chadd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21*e34a491bSAdrian Chadd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22*e34a491bSAdrian Chadd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23*e34a491bSAdrian Chadd * SUCH DAMAGE.
24*e34a491bSAdrian Chadd */
25*e34a491bSAdrian Chadd
26*e34a491bSAdrian Chadd #include <sys/param.h>
27*e34a491bSAdrian Chadd #include <sys/systm.h>
28*e34a491bSAdrian Chadd #include <sys/bus.h>
29*e34a491bSAdrian Chadd #include <sys/lock.h>
30*e34a491bSAdrian Chadd #include <sys/mutex.h>
31*e34a491bSAdrian Chadd #include <sys/rman.h>
32*e34a491bSAdrian Chadd #include <machine/bus.h>
33*e34a491bSAdrian Chadd
34*e34a491bSAdrian Chadd #include "qcom_clk_freqtbl.h"
35*e34a491bSAdrian Chadd
36*e34a491bSAdrian Chadd /*
37*e34a491bSAdrian Chadd * Walk the list of frequencies and return the highest frequency supported.
38*e34a491bSAdrian Chadd */
39*e34a491bSAdrian Chadd const struct qcom_clk_freq_tbl *
qcom_clk_freq_tbl_lookup(const struct qcom_clk_freq_tbl * tbl,uint64_t freq)40*e34a491bSAdrian Chadd qcom_clk_freq_tbl_lookup(const struct qcom_clk_freq_tbl *tbl, uint64_t freq)
41*e34a491bSAdrian Chadd {
42*e34a491bSAdrian Chadd const struct qcom_clk_freq_tbl *t;
43*e34a491bSAdrian Chadd
44*e34a491bSAdrian Chadd if (tbl == NULL)
45*e34a491bSAdrian Chadd return (NULL);
46*e34a491bSAdrian Chadd
47*e34a491bSAdrian Chadd for (t = tbl; t->freq !=0; t++) {
48*e34a491bSAdrian Chadd if (freq <= t->freq)
49*e34a491bSAdrian Chadd return (t);
50*e34a491bSAdrian Chadd }
51*e34a491bSAdrian Chadd
52*e34a491bSAdrian Chadd return (NULL);
53*e34a491bSAdrian Chadd }
54