forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-09 244b2c5ca8b14627e4a17755e5922221e121c771
kernel/drivers/net/wan/ixp4xx_hss.c
....@@ -1,11 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Intel IXP4xx HSS (synchronous serial port) driver for Linux
34 *
45 * Copyright (C) 2007-2008 Krzysztof HaƂasa <khc@pm.waw.pl>
5
- *
6
- * This program is free software; you can redistribute it and/or modify it
7
- * under the terms of version 2 of the GNU General Public License
8
- * as published by the Free Software Foundation.
96 */
107
118 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -20,10 +17,11 @@
2017 #include <linux/io.h>
2118 #include <linux/kernel.h>
2219 #include <linux/platform_device.h>
20
+#include <linux/platform_data/wan_ixp4xx_hss.h>
2321 #include <linux/poll.h>
2422 #include <linux/slab.h>
25
-#include <mach/npe.h>
26
-#include <mach/qmgr.h>
23
+#include <linux/soc/ixp4xx/npe.h>
24
+#include <linux/soc/ixp4xx/qmgr.h>
2725
2826 #define DEBUG_DESC 0
2927 #define DEBUG_RX 0
....@@ -246,7 +244,7 @@
246244 #ifdef __ARMEB__
247245 typedef struct sk_buff buffer_t;
248246 #define free_buffer dev_kfree_skb
249
-#define free_buffer_irq dev_kfree_skb_irq
247
+#define free_buffer_irq dev_consume_skb_irq
250248 #else
251249 typedef void buffer_t;
252250 #define free_buffer kfree
....@@ -1185,14 +1183,14 @@
11851183 }
11861184 }
11871185
1188
-static u32 check_clock(u32 rate, u32 a, u32 b, u32 c,
1186
+static u32 check_clock(u32 timer_freq, u32 rate, u32 a, u32 b, u32 c,
11891187 u32 *best, u32 *best_diff, u32 *reg)
11901188 {
11911189 /* a is 10-bit, b is 10-bit, c is 12-bit */
11921190 u64 new_rate;
11931191 u32 new_diff;
11941192
1195
- new_rate = ixp4xx_timer_freq * (u64)(c + 1);
1193
+ new_rate = timer_freq * (u64)(c + 1);
11961194 do_div(new_rate, a * (c + 1) + b + 1);
11971195 new_diff = abs((u32)new_rate - rate);
11981196
....@@ -1204,40 +1202,43 @@
12041202 return new_diff;
12051203 }
12061204
1207
-static void find_best_clock(u32 rate, u32 *best, u32 *reg)
1205
+static void find_best_clock(u32 timer_freq, u32 rate, u32 *best, u32 *reg)
12081206 {
12091207 u32 a, b, diff = 0xFFFFFFFF;
12101208
1211
- a = ixp4xx_timer_freq / rate;
1209
+ a = timer_freq / rate;
12121210
12131211 if (a > 0x3FF) { /* 10-bit value - we can go as slow as ca. 65 kb/s */
1214
- check_clock(rate, 0x3FF, 1, 1, best, &diff, reg);
1212
+ check_clock(timer_freq, rate, 0x3FF, 1, 1, best, &diff, reg);
12151213 return;
12161214 }
12171215 if (a == 0) { /* > 66.666 MHz */
12181216 a = 1; /* minimum divider is 1 (a = 0, b = 1, c = 1) */
1219
- rate = ixp4xx_timer_freq;
1217
+ rate = timer_freq;
12201218 }
12211219
1222
- if (rate * a == ixp4xx_timer_freq) { /* don't divide by 0 later */
1223
- check_clock(rate, a - 1, 1, 1, best, &diff, reg);
1220
+ if (rate * a == timer_freq) { /* don't divide by 0 later */
1221
+ check_clock(timer_freq, rate, a - 1, 1, 1, best, &diff, reg);
12241222 return;
12251223 }
12261224
12271225 for (b = 0; b < 0x400; b++) {
12281226 u64 c = (b + 1) * (u64)rate;
1229
- do_div(c, ixp4xx_timer_freq - rate * a);
1227
+ do_div(c, timer_freq - rate * a);
12301228 c--;
12311229 if (c >= 0xFFF) { /* 12-bit - no need to check more 'b's */
12321230 if (b == 0 && /* also try a bit higher rate */
1233
- !check_clock(rate, a - 1, 1, 1, best, &diff, reg))
1231
+ !check_clock(timer_freq, rate, a - 1, 1, 1, best,
1232
+ &diff, reg))
12341233 return;
1235
- check_clock(rate, a, b, 0xFFF, best, &diff, reg);
1234
+ check_clock(timer_freq, rate, a, b, 0xFFF, best,
1235
+ &diff, reg);
12361236 return;
12371237 }
1238
- if (!check_clock(rate, a, b, c, best, &diff, reg))
1238
+ if (!check_clock(timer_freq, rate, a, b, c, best, &diff, reg))
12391239 return;
1240
- if (!check_clock(rate, a, b, c + 1, best, &diff, reg))
1240
+ if (!check_clock(timer_freq, rate, a, b, c + 1, best, &diff,
1241
+ reg))
12411242 return;
12421243 }
12431244 }
....@@ -1288,8 +1289,9 @@
12881289
12891290 port->clock_type = clk; /* Update settings */
12901291 if (clk == CLOCK_INT)
1291
- find_best_clock(new_line.clock_rate, &port->clock_rate,
1292
- &port->clock_reg);
1292
+ find_best_clock(port->plat->timer_freq,
1293
+ new_line.clock_rate,
1294
+ &port->clock_rate, &port->clock_reg);
12931295 else {
12941296 port->clock_rate = 0;
12951297 port->clock_reg = CLK42X_SPEED_2048KHZ;