| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Intel IXP4xx HSS (synchronous serial port) driver for Linux |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * 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. |
|---|
| 9 | 6 | */ |
|---|
| 10 | 7 | |
|---|
| 11 | 8 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
|---|
| .. | .. |
|---|
| 20 | 17 | #include <linux/io.h> |
|---|
| 21 | 18 | #include <linux/kernel.h> |
|---|
| 22 | 19 | #include <linux/platform_device.h> |
|---|
| 20 | +#include <linux/platform_data/wan_ixp4xx_hss.h> |
|---|
| 23 | 21 | #include <linux/poll.h> |
|---|
| 24 | 22 | #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> |
|---|
| 27 | 25 | |
|---|
| 28 | 26 | #define DEBUG_DESC 0 |
|---|
| 29 | 27 | #define DEBUG_RX 0 |
|---|
| .. | .. |
|---|
| 246 | 244 | #ifdef __ARMEB__ |
|---|
| 247 | 245 | typedef struct sk_buff buffer_t; |
|---|
| 248 | 246 | #define free_buffer dev_kfree_skb |
|---|
| 249 | | -#define free_buffer_irq dev_kfree_skb_irq |
|---|
| 247 | +#define free_buffer_irq dev_consume_skb_irq |
|---|
| 250 | 248 | #else |
|---|
| 251 | 249 | typedef void buffer_t; |
|---|
| 252 | 250 | #define free_buffer kfree |
|---|
| .. | .. |
|---|
| 1185 | 1183 | } |
|---|
| 1186 | 1184 | } |
|---|
| 1187 | 1185 | |
|---|
| 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, |
|---|
| 1189 | 1187 | u32 *best, u32 *best_diff, u32 *reg) |
|---|
| 1190 | 1188 | { |
|---|
| 1191 | 1189 | /* a is 10-bit, b is 10-bit, c is 12-bit */ |
|---|
| 1192 | 1190 | u64 new_rate; |
|---|
| 1193 | 1191 | u32 new_diff; |
|---|
| 1194 | 1192 | |
|---|
| 1195 | | - new_rate = ixp4xx_timer_freq * (u64)(c + 1); |
|---|
| 1193 | + new_rate = timer_freq * (u64)(c + 1); |
|---|
| 1196 | 1194 | do_div(new_rate, a * (c + 1) + b + 1); |
|---|
| 1197 | 1195 | new_diff = abs((u32)new_rate - rate); |
|---|
| 1198 | 1196 | |
|---|
| .. | .. |
|---|
| 1204 | 1202 | return new_diff; |
|---|
| 1205 | 1203 | } |
|---|
| 1206 | 1204 | |
|---|
| 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) |
|---|
| 1208 | 1206 | { |
|---|
| 1209 | 1207 | u32 a, b, diff = 0xFFFFFFFF; |
|---|
| 1210 | 1208 | |
|---|
| 1211 | | - a = ixp4xx_timer_freq / rate; |
|---|
| 1209 | + a = timer_freq / rate; |
|---|
| 1212 | 1210 | |
|---|
| 1213 | 1211 | 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); |
|---|
| 1215 | 1213 | return; |
|---|
| 1216 | 1214 | } |
|---|
| 1217 | 1215 | if (a == 0) { /* > 66.666 MHz */ |
|---|
| 1218 | 1216 | a = 1; /* minimum divider is 1 (a = 0, b = 1, c = 1) */ |
|---|
| 1219 | | - rate = ixp4xx_timer_freq; |
|---|
| 1217 | + rate = timer_freq; |
|---|
| 1220 | 1218 | } |
|---|
| 1221 | 1219 | |
|---|
| 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); |
|---|
| 1224 | 1222 | return; |
|---|
| 1225 | 1223 | } |
|---|
| 1226 | 1224 | |
|---|
| 1227 | 1225 | for (b = 0; b < 0x400; b++) { |
|---|
| 1228 | 1226 | u64 c = (b + 1) * (u64)rate; |
|---|
| 1229 | | - do_div(c, ixp4xx_timer_freq - rate * a); |
|---|
| 1227 | + do_div(c, timer_freq - rate * a); |
|---|
| 1230 | 1228 | c--; |
|---|
| 1231 | 1229 | if (c >= 0xFFF) { /* 12-bit - no need to check more 'b's */ |
|---|
| 1232 | 1230 | 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)) |
|---|
| 1234 | 1233 | return; |
|---|
| 1235 | | - check_clock(rate, a, b, 0xFFF, best, &diff, reg); |
|---|
| 1234 | + check_clock(timer_freq, rate, a, b, 0xFFF, best, |
|---|
| 1235 | + &diff, reg); |
|---|
| 1236 | 1236 | return; |
|---|
| 1237 | 1237 | } |
|---|
| 1238 | | - if (!check_clock(rate, a, b, c, best, &diff, reg)) |
|---|
| 1238 | + if (!check_clock(timer_freq, rate, a, b, c, best, &diff, reg)) |
|---|
| 1239 | 1239 | 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)) |
|---|
| 1241 | 1242 | return; |
|---|
| 1242 | 1243 | } |
|---|
| 1243 | 1244 | } |
|---|
| .. | .. |
|---|
| 1288 | 1289 | |
|---|
| 1289 | 1290 | port->clock_type = clk; /* Update settings */ |
|---|
| 1290 | 1291 | 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); |
|---|
| 1293 | 1295 | else { |
|---|
| 1294 | 1296 | port->clock_rate = 0; |
|---|
| 1295 | 1297 | port->clock_reg = CLK42X_SPEED_2048KHZ; |
|---|