Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright (C) 2012 ST Microelectronics
0004  * Viresh Kumar <vireshk@kernel.org>
0005  *
0006  * SPEAr clk - Common routines
0007  */
0008 
0009 #include <linux/clk-provider.h>
0010 #include <linux/types.h>
0011 #include "clk.h"
0012 
0013 long clk_round_rate_index(struct clk_hw *hw, unsigned long drate,
0014         unsigned long parent_rate, clk_calc_rate calc_rate, u8 rtbl_cnt,
0015         int *index)
0016 {
0017     unsigned long prev_rate, rate = 0;
0018 
0019     for (*index = 0; *index < rtbl_cnt; (*index)++) {
0020         prev_rate = rate;
0021         rate = calc_rate(hw, parent_rate, *index);
0022         if (drate < rate) {
0023             /* previous clock was best */
0024             if (*index) {
0025                 rate = prev_rate;
0026                 (*index)--;
0027             }
0028             break;
0029         }
0030     }
0031 
0032     if ((*index) == rtbl_cnt)
0033         (*index)--;
0034 
0035     return rate;
0036 }