.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Driver for the Diolan u2c-12 USB-I2C adapter |
---|
3 | 4 | * |
---|
.. | .. |
---|
6 | 7 | * Derived from: |
---|
7 | 8 | * i2c-tiny-usb.c |
---|
8 | 9 | * Copyright (C) 2006-2007 Till Harbaum (Till@Harbaum.org) |
---|
9 | | - * |
---|
10 | | - * This program is free software; you can redistribute it and/or |
---|
11 | | - * modify it under the terms of the GNU General Public License as |
---|
12 | | - * published by the Free Software Foundation, version 2. |
---|
13 | 10 | */ |
---|
14 | 11 | |
---|
15 | 12 | #include <linux/kernel.h> |
---|
.. | .. |
---|
67 | 64 | #define U2C_I2C_SPEED_2KHZ 242 /* 2 kHz, minimum speed */ |
---|
68 | 65 | #define U2C_I2C_SPEED(f) ((DIV_ROUND_UP(1000000, (f)) - 10) / 2 + 1) |
---|
69 | 66 | |
---|
70 | | -#define U2C_I2C_FREQ_FAST 400000 |
---|
71 | | -#define U2C_I2C_FREQ_STD 100000 |
---|
72 | 67 | #define U2C_I2C_FREQ(s) (1000000 / (2 * (s - 1) + 10)) |
---|
73 | 68 | |
---|
74 | 69 | #define DIOLAN_USB_TIMEOUT 100 /* in ms */ |
---|
.. | .. |
---|
90 | 85 | int ocount; /* Number of enqueued messages */ |
---|
91 | 86 | }; |
---|
92 | 87 | |
---|
93 | | -static uint frequency = U2C_I2C_FREQ_STD; /* I2C clock frequency in Hz */ |
---|
| 88 | +static uint frequency = I2C_MAX_STANDARD_MODE_FREQ; /* I2C clock frequency in Hz */ |
---|
94 | 89 | |
---|
95 | 90 | module_param(frequency, uint, S_IRUGO | S_IWUSR); |
---|
96 | 91 | MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz"); |
---|
.. | .. |
---|
302 | 297 | { |
---|
303 | 298 | int speed, ret; |
---|
304 | 299 | |
---|
305 | | - if (frequency >= 200000) { |
---|
| 300 | + if (frequency >= 2 * I2C_MAX_STANDARD_MODE_FREQ) { |
---|
306 | 301 | speed = U2C_I2C_SPEED_FAST; |
---|
307 | | - frequency = U2C_I2C_FREQ_FAST; |
---|
308 | | - } else if (frequency >= 100000 || frequency == 0) { |
---|
| 302 | + frequency = I2C_MAX_FAST_MODE_FREQ; |
---|
| 303 | + } else if (frequency >= I2C_MAX_STANDARD_MODE_FREQ || frequency == 0) { |
---|
309 | 304 | speed = U2C_I2C_SPEED_STD; |
---|
310 | | - frequency = U2C_I2C_FREQ_STD; |
---|
| 305 | + frequency = I2C_MAX_STANDARD_MODE_FREQ; |
---|
311 | 306 | } else { |
---|
312 | 307 | speed = U2C_I2C_SPEED(frequency); |
---|
313 | 308 | if (speed > U2C_I2C_SPEED_2KHZ) |
---|