forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 748e4f3d702def1a4bff191e0cf93b6a05340f01
kernel/drivers/clk/sunxi-ng/ccu_nkmp.c
....@@ -1,14 +1,11 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 2016 Maxime Ripard
34 * Maxime Ripard <maxime.ripard@free-electrons.com>
4
- *
5
- * This program is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU General Public License as
7
- * published by the Free Software Foundation; either version 2 of
8
- * the License, or (at your option) any later version.
95 */
106
117 #include <linux/clk-provider.h>
8
+#include <linux/io.h>
129
1310 #include "ccu_gate.h"
1411 #include "ccu_nkmp.h"
....@@ -137,6 +134,13 @@
137134 if (nkmp->common.features & CCU_FEATURE_FIXED_POSTDIV)
138135 rate *= nkmp->fixed_post_div;
139136
137
+ if (nkmp->max_rate && rate > nkmp->max_rate) {
138
+ rate = nkmp->max_rate;
139
+ if (nkmp->common.features & CCU_FEATURE_FIXED_POSTDIV)
140
+ rate /= nkmp->fixed_post_div;
141
+ return rate;
142
+ }
143
+
140144 _nkmp.min_n = nkmp->n.min ?: 1;
141145 _nkmp.max_n = nkmp->n.max ?: 1 << nkmp->n.width;
142146 _nkmp.min_k = nkmp->k.min ?: 1;
....@@ -179,6 +183,12 @@
179183
180184 ccu_nkmp_find_best(parent_rate, rate, &_nkmp);
181185
186
+ /*
187
+ * If width is 0, GENMASK() macro may not generate expected mask (0)
188
+ * as it falls under undefined behaviour by C standard due to shifts
189
+ * which are equal or greater than width of left operand. This can
190
+ * be easily avoided by explicitly checking if width is 0.
191
+ */
182192 if (nkmp->n.width)
183193 n_mask = GENMASK(nkmp->n.width + nkmp->n.shift - 1,
184194 nkmp->n.shift);