Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 1 | diff --git a/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt b/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt |
Jan Kundrát | 2bfe9ee | 2019-12-04 13:42:07 +0100 | [diff] [blame] | 2 | index 8b94aa8f5971..2723e6143aa9 100644 |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 3 | --- a/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt |
| 4 | +++ b/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt |
| 5 | @@ -144,3 +144,38 @@ gpio21: gpio@21 { |
| 6 | bias-pull-up; |
| 7 | }; |
| 8 | }; |
| 9 | + |
| 10 | +Line naming |
| 11 | +=========== |
| 12 | + |
| 13 | +Because several gpio_chip instances are hidden below a single device tree |
| 14 | +node, it is necessary to split the names into several child nodes. Ensure |
| 15 | +that the configured addresses match those in the microchip,spi-present-mask: |
| 16 | + |
| 17 | +gpio@0 { |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 18 | + compatible = "microchip,mcp23s17"; |
| 19 | + gpio-controller; |
| 20 | + #gpio-cells = <2>; |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 21 | + /* this bitmask has bits #0 (0x01) and #2 (0x04) set */ |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 22 | + spi-present-mask = <0x05>; |
| 23 | + reg = <0>; |
| 24 | + spi-max-frequency = <1000000>; |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 25 | + |
| 26 | + gpio-bank@1 { |
| 27 | + address = <0>; |
| 28 | + gpio-line-names = |
| 29 | + "GPA0", |
| 30 | + "GPA1", |
| 31 | + ... |
| 32 | + "GPA7", |
| 33 | + "GPB0", |
| 34 | + "GPB1", |
| 35 | + ... |
| 36 | + "GPB7"; |
| 37 | + }; |
| 38 | + |
| 39 | + gpio-bank@2 { |
| 40 | + address = <2>; |
| 41 | + gpio-line-names = ... |
| 42 | + }; |
| 43 | +}; |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 44 | diff --git a/Documentation/hwmon/max31790.rst b/Documentation/hwmon/max31790.rst |
| 45 | index f301385d8cef..05ee1a3e5a01 100644 |
| 46 | --- a/Documentation/hwmon/max31790.rst |
| 47 | +++ b/Documentation/hwmon/max31790.rst |
| 48 | @@ -30,14 +30,62 @@ monitoring and control of fan RPM as well as detection of fan failure. |
| 49 | Six pins are dedicated tachometer inputs. Any of the six PWM outputs can |
| 50 | also be configured to serve as tachometer inputs. |
| 51 | |
| 52 | +About pwm[1-6]_enable |
| 53 | +--------------------- |
| 54 | +0 - full-speed |
| 55 | + The chip doesn't have a specific way to set "full speed", so setting |
| 56 | + pwm[1-6]_enable to 0 is just "set PWM mode with 255 duty cycle". |
| 57 | +1 - PWM mode |
| 58 | + Fan speed is controlled by writing a value to pwm[1-6]. |
| 59 | +2 - RPM mode |
| 60 | + Fan speed is controlled by writing a value to fan[1-6]_target. |
| 61 | + |
| 62 | +About fan[1-6]_fault |
| 63 | +-------------------- |
| 64 | +In PWM (or full-speed) mode, if the input RPM goes below what is set |
| 65 | +in fan[1-6]_target, fan[1-6]_fault gets set to 1. In other words, |
| 66 | +fan[1-6]_target works as the minimum input RPM before a fan fault goes off. |
| 67 | + |
| 68 | +In RPM mode, fan fault is set when the fan spins "too slowly" (exact |
| 69 | +conditions are in the datasheet). RPM mode depends on four variables: |
| 70 | + target_speed: This is set by fan[1-6]_target. |
| 71 | + speed_range: This is set automatically when setting target_speed |
| 72 | + or manually by fan[1-12]_div. |
| 73 | + pwm_rate_of_change: NOT set by the driver. |
| 74 | + fan_window: NOT set by the driver. |
| 75 | + |
| 76 | +The last two values are not set by the driver, because there's no generic way to |
| 77 | +compute them. You should set them manually through i2c (in the bootloader for |
| 78 | +example). Check the datasheet for details. |
| 79 | + |
| 80 | +The fan fault value latches, to reset it, set a value to pwm[1-6] |
| 81 | +or fan[1-6]_target. |
| 82 | + |
| 83 | +About fan[1-12]_pulses |
| 84 | +---------------------- |
| 85 | +You should set this depending on the fan you use. It affects what values |
| 86 | +are in fan[1-12]_input and also what gets written to fan[1-6]_target. |
| 87 | + |
| 88 | +About fan[1-12]_div |
| 89 | +------------------- |
| 90 | +This value affects the measurable range of the chip. The driver sets this value |
| 91 | +automatically in RPM based on fan[1-6]_target. In PWM mode, you should set this |
| 92 | +value manually based on the details from the datasheet. Setting the speed range |
| 93 | +is disabled while in RPM mode to prevent overwriting the automatically |
| 94 | +calculated value. |
| 95 | |
| 96 | Sysfs entries |
| 97 | ------------- |
| 98 | |
| 99 | -================== === ======================================================= |
| 100 | +================== === ============================================================= |
| 101 | +fan[1-12]_enable RW enable fan speed monitoring |
| 102 | +fan[1-12]_pulses RW pulses per fan revolution (default: 2) |
| 103 | fan[1-12]_input RO fan tachometer speed in RPM |
| 104 | fan[1-12]_fault RO fan experienced fault |
| 105 | -fan[1-6]_target RW desired fan speed in RPM |
| 106 | -pwm[1-6]_enable RW regulator mode, 0=disabled, 1=manual mode, 2=rpm mode |
| 107 | +fan[1-12]_div RW set the measurable speed range, not available in RPM mode |
| 108 | +fan[1-6]_target RW RPM mode = desired fan speed |
| 109 | + PWM mode = minimum fan speed until fault |
| 110 | +pwm[1-6]_enable RW regulator mode, 0=full speed, 1=manual (pwm) mode, 2=rpm mode |
| 111 | + setting rpm mode sets fan*_enable to 1 |
| 112 | pwm[1-6] RW fan target duty cycle (0-255) |
| 113 | -================== === ======================================================= |
| 114 | +================== === ============================================================= |
| 115 | diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig |
| 116 | index 1ecf697d8d99..9f11d036c316 100644 |
| 117 | --- a/drivers/hwmon/Kconfig |
| 118 | +++ b/drivers/hwmon/Kconfig |
| 119 | @@ -1095,6 +1095,7 @@ config SENSORS_MAX6697 |
| 120 | config SENSORS_MAX31790 |
| 121 | tristate "Maxim MAX31790 sensor chip" |
| 122 | depends on I2C |
| 123 | + select REGMAP_I2C |
| 124 | help |
| 125 | If you say yes here you get support for 6-Channel PWM-Output |
| 126 | Fan RPM Controller. |
Jan Kundrát | 6406d51 | 2020-11-18 18:24:36 +0100 | [diff] [blame] | 127 | diff --git a/drivers/hwmon/max31790.c b/drivers/hwmon/max31790.c |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 128 | index 86e6c71db685..3ef205e45dc1 100644 |
Jan Kundrát | 6406d51 | 2020-11-18 18:24:36 +0100 | [diff] [blame] | 129 | --- a/drivers/hwmon/max31790.c |
| 130 | +++ b/drivers/hwmon/max31790.c |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 131 | @@ -12,6 +12,7 @@ |
| 132 | #include <linux/init.h> |
| 133 | #include <linux/jiffies.h> |
| 134 | #include <linux/module.h> |
| 135 | +#include <linux/regmap.h> |
| 136 | #include <linux/slab.h> |
| 137 | |
| 138 | /* MAX31790 registers */ |
| 139 | @@ -38,22 +39,65 @@ |
| 140 | |
| 141 | #define FAN_RPM_MIN 120 |
| 142 | #define FAN_RPM_MAX 7864320 |
| 143 | +#define MAX_PWM 0XFF80 |
| 144 | |
| 145 | -#define RPM_FROM_REG(reg, sr) (((reg) >> 4) ? \ |
| 146 | - ((60 * (sr) * 8192) / ((reg) >> 4)) : \ |
| 147 | - FAN_RPM_MAX) |
| 148 | -#define RPM_TO_REG(rpm, sr) ((60 * (sr) * 8192) / ((rpm) * 2)) |
| 149 | +#define RPM_FROM_REG(reg, sr, pulses) \ |
| 150 | + (((reg) >> 5) ? \ |
| 151 | + ((60 * (sr) * 8192) / ((reg) >> 5) / (pulses)) : \ |
| 152 | + FAN_RPM_MAX) |
| 153 | +#define RPM_TO_REG(rpm, sr, pulses) \ |
| 154 | + ((60 * (sr) * 8192) / ((rpm) * (pulses))) |
| 155 | |
| 156 | #define NR_CHANNEL 6 |
| 157 | |
| 158 | +#define MAX31790_REG_USER_BYTE_67 0x67 |
| 159 | + |
| 160 | +#define BULK_TO_U16(msb, lsb) (((msb) << 8) + (lsb)) |
| 161 | +#define U16_MSB(num) (((num) & 0xFF00) >> 8) |
| 162 | +#define U16_LSB(num) ((num) & 0x00FF) |
| 163 | + |
| 164 | +#define FAN_INFO_1_TO_6 \ |
| 165 | + (HWMON_F_DIV | \ |
| 166 | + HWMON_F_PULSES | \ |
| 167 | + HWMON_F_ENABLE | \ |
| 168 | + HWMON_F_INPUT | \ |
| 169 | + HWMON_F_TARGET | \ |
| 170 | + HWMON_F_FAULT) |
| 171 | + |
| 172 | +#define FAN_INFO_7_TO_12 \ |
| 173 | + (HWMON_F_PULSES | \ |
| 174 | + HWMON_F_ENABLE | \ |
| 175 | + HWMON_F_INPUT | \ |
| 176 | + HWMON_F_FAULT) |
| 177 | + |
| 178 | +static const struct regmap_range max31790_ro_range = { |
| 179 | + .range_min = MAX31790_REG_TACH_COUNT(0), |
| 180 | + .range_max = MAX31790_REG_PWMOUT(0) - 1, |
| 181 | +}; |
| 182 | + |
| 183 | +static const struct regmap_access_table max31790_wr_table = { |
| 184 | + .no_ranges = &max31790_ro_range, |
| 185 | + .n_no_ranges = 1, |
| 186 | +}; |
| 187 | + |
| 188 | +static const struct regmap_config max31790_regmap_config = { |
| 189 | + .reg_bits = 8, |
| 190 | + .val_bits = 8, |
| 191 | + .reg_stride = 1, |
| 192 | + .max_register = MAX31790_REG_USER_BYTE_67, |
| 193 | + .wr_table = &max31790_wr_table, |
| 194 | +}; |
| 195 | + |
| 196 | /* |
| 197 | * Client data (each client gets its own) |
| 198 | */ |
| 199 | struct max31790_data { |
| 200 | - struct i2c_client *client; |
| 201 | + struct regmap *regmap; |
| 202 | struct mutex update_lock; |
| 203 | bool valid; /* zero until following fields are valid */ |
| 204 | unsigned long last_updated; /* in jiffies */ |
| 205 | + bool full_speed[NR_CHANNEL]; |
| 206 | + u8 pulses[NR_CHANNEL]; |
| 207 | |
| 208 | /* register values */ |
| 209 | u8 fan_config[NR_CHANNEL]; |
| 210 | @@ -67,53 +111,72 @@ struct max31790_data { |
| 211 | static struct max31790_data *max31790_update_device(struct device *dev) |
| 212 | { |
| 213 | struct max31790_data *data = dev_get_drvdata(dev); |
| 214 | - struct i2c_client *client = data->client; |
| 215 | + struct regmap *regmap = data->regmap; |
| 216 | struct max31790_data *ret = data; |
| 217 | int i; |
| 218 | int rv; |
| 219 | + int val; |
| 220 | + u8 val_bulk[2]; |
| 221 | |
| 222 | mutex_lock(&data->update_lock); |
| 223 | |
| 224 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { |
| 225 | - rv = i2c_smbus_read_byte_data(client, |
| 226 | - MAX31790_REG_FAN_FAULT_STATUS1); |
| 227 | + rv = regmap_read(regmap, |
| 228 | + MAX31790_REG_FAN_FAULT_STATUS1, |
| 229 | + &val); |
| 230 | if (rv < 0) |
| 231 | goto abort; |
| 232 | - data->fault_status = rv & 0x3F; |
| 233 | + data->fault_status = val & 0x3F; |
| 234 | |
| 235 | - rv = i2c_smbus_read_byte_data(client, |
| 236 | - MAX31790_REG_FAN_FAULT_STATUS2); |
| 237 | + rv = regmap_read(regmap, |
| 238 | + MAX31790_REG_FAN_FAULT_STATUS2, |
| 239 | + &val); |
| 240 | if (rv < 0) |
| 241 | goto abort; |
| 242 | - data->fault_status |= (rv & 0x3F) << 6; |
| 243 | + data->fault_status |= (val & 0x3F) << 6; |
| 244 | |
| 245 | for (i = 0; i < NR_CHANNEL; i++) { |
| 246 | - rv = i2c_smbus_read_word_swapped(client, |
| 247 | - MAX31790_REG_TACH_COUNT(i)); |
| 248 | + rv = regmap_bulk_read(regmap, |
| 249 | + MAX31790_REG_TACH_COUNT(i), |
| 250 | + val_bulk, |
| 251 | + 2); |
| 252 | if (rv < 0) |
| 253 | goto abort; |
| 254 | - data->tach[i] = rv; |
| 255 | + data->tach[i] = BULK_TO_U16(val_bulk[0], |
| 256 | + val_bulk[1]); |
| 257 | |
| 258 | if (data->fan_config[i] |
| 259 | & MAX31790_FAN_CFG_TACH_INPUT) { |
| 260 | - rv = i2c_smbus_read_word_swapped(client, |
| 261 | - MAX31790_REG_TACH_COUNT(NR_CHANNEL |
| 262 | - + i)); |
| 263 | + rv = regmap_bulk_read(regmap, |
| 264 | + MAX31790_REG_TACH_COUNT(NR_CHANNEL |
| 265 | + + i), |
| 266 | + val_bulk, |
| 267 | + 2); |
| 268 | if (rv < 0) |
| 269 | goto abort; |
| 270 | - data->tach[NR_CHANNEL + i] = rv; |
| 271 | + |
| 272 | + data->tach[NR_CHANNEL + i] = |
| 273 | + BULK_TO_U16(val_bulk[0], |
| 274 | + val_bulk[1]); |
| 275 | } else { |
| 276 | - rv = i2c_smbus_read_word_swapped(client, |
| 277 | - MAX31790_REG_PWMOUT(i)); |
| 278 | + rv = regmap_bulk_read(regmap, |
| 279 | + MAX31790_REG_PWMOUT(i), |
| 280 | + val_bulk, |
| 281 | + 2); |
| 282 | if (rv < 0) |
| 283 | goto abort; |
| 284 | - data->pwm[i] = rv; |
| 285 | + data->pwm[i] = BULK_TO_U16(val_bulk[0], |
| 286 | + val_bulk[1]); |
| 287 | |
| 288 | - rv = i2c_smbus_read_word_swapped(client, |
| 289 | - MAX31790_REG_TARGET_COUNT(i)); |
| 290 | + rv = regmap_bulk_read(regmap, |
| 291 | + MAX31790_REG_TARGET_COUNT(i), |
| 292 | + val_bulk, |
| 293 | + 2); |
| 294 | if (rv < 0) |
| 295 | goto abort; |
| 296 | - data->target_count[i] = rv; |
| 297 | + data->target_count[i] = |
| 298 | + BULK_TO_U16(val_bulk[0], |
| 299 | + val_bulk[1]); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | @@ -159,6 +222,26 @@ static u8 bits_for_tach_period(int rpm) |
| 304 | return bits; |
| 305 | } |
| 306 | |
| 307 | +static int bits_for_speed_range(int speed_range) |
| 308 | +{ |
| 309 | + switch (speed_range) { |
| 310 | + case 1: |
| 311 | + return 0x0; |
| 312 | + case 2: |
| 313 | + return 0x1; |
| 314 | + case 4: |
| 315 | + return 0x2; |
| 316 | + case 8: |
| 317 | + return 0x3; |
| 318 | + case 16: |
| 319 | + return 0x4; |
| 320 | + case 32: |
| 321 | + return 0x5; |
| 322 | + default: |
| 323 | + return -1; |
| 324 | + } |
| 325 | +} |
| 326 | + |
| 327 | static int max31790_read_fan(struct device *dev, u32 attr, int channel, |
| 328 | long *val) |
| 329 | { |
| 330 | @@ -170,18 +253,41 @@ static int max31790_read_fan(struct device *dev, u32 attr, int channel, |
| 331 | |
| 332 | switch (attr) { |
| 333 | case hwmon_fan_input: |
| 334 | + if (!(data->fan_config[channel] & |
| 335 | + MAX31790_FAN_CFG_TACH_INPUT_EN)) { |
| 336 | + *val = 0; |
| 337 | + return 0; |
| 338 | + } |
| 339 | sr = get_tach_period(data->fan_dynamics[channel]); |
| 340 | - rpm = RPM_FROM_REG(data->tach[channel], sr); |
| 341 | + rpm = RPM_FROM_REG(data->tach[channel], |
| 342 | + sr, |
| 343 | + data->pulses[channel]); |
| 344 | *val = rpm; |
| 345 | return 0; |
| 346 | case hwmon_fan_target: |
| 347 | sr = get_tach_period(data->fan_dynamics[channel]); |
| 348 | - rpm = RPM_FROM_REG(data->target_count[channel], sr); |
| 349 | + rpm = RPM_FROM_REG(data->target_count[channel], |
| 350 | + sr, |
| 351 | + data->pulses[channel]); |
| 352 | *val = rpm; |
| 353 | return 0; |
| 354 | case hwmon_fan_fault: |
| 355 | + if (!(data->fan_config[channel] & |
| 356 | + MAX31790_FAN_CFG_TACH_INPUT_EN)) { |
| 357 | + *val = 0; |
| 358 | + return 0; |
| 359 | + } |
| 360 | *val = !!(data->fault_status & (1 << channel)); |
| 361 | return 0; |
| 362 | + case hwmon_fan_enable: |
| 363 | + *val = !!(data->fan_config[channel] & MAX31790_FAN_CFG_TACH_INPUT_EN); |
| 364 | + return 0; |
| 365 | + case hwmon_fan_pulses: |
| 366 | + *val = data->pulses[channel]; |
| 367 | + return 0; |
| 368 | + case hwmon_fan_div: |
| 369 | + *val = get_tach_period(data->fan_config[channel]); |
| 370 | + return 0; |
| 371 | default: |
| 372 | return -EOPNOTSUPP; |
| 373 | } |
| 374 | @@ -191,11 +297,12 @@ static int max31790_write_fan(struct device *dev, u32 attr, int channel, |
| 375 | long val) |
| 376 | { |
| 377 | struct max31790_data *data = dev_get_drvdata(dev); |
| 378 | - struct i2c_client *client = data->client; |
| 379 | + struct regmap *regmap = data->regmap; |
| 380 | int target_count; |
| 381 | int err = 0; |
| 382 | u8 bits; |
| 383 | int sr; |
| 384 | + u8 bulk_val[2]; |
| 385 | |
| 386 | mutex_lock(&data->update_lock); |
| 387 | |
| 388 | @@ -207,21 +314,55 @@ static int max31790_write_fan(struct device *dev, u32 attr, int channel, |
| 389 | ((data->fan_dynamics[channel] & |
| 390 | ~MAX31790_FAN_DYN_SR_MASK) | |
| 391 | (bits << MAX31790_FAN_DYN_SR_SHIFT)); |
| 392 | - err = i2c_smbus_write_byte_data(client, |
| 393 | - MAX31790_REG_FAN_DYNAMICS(channel), |
| 394 | - data->fan_dynamics[channel]); |
| 395 | + err = regmap_write(regmap, |
| 396 | + MAX31790_REG_FAN_DYNAMICS(channel), |
| 397 | + data->fan_dynamics[channel]); |
| 398 | if (err < 0) |
| 399 | break; |
| 400 | |
| 401 | sr = get_tach_period(data->fan_dynamics[channel]); |
| 402 | - target_count = RPM_TO_REG(val, sr); |
| 403 | + target_count = RPM_TO_REG(val, sr, data->pulses[channel]); |
| 404 | target_count = clamp_val(target_count, 0x1, 0x7FF); |
| 405 | |
| 406 | data->target_count[channel] = target_count << 5; |
| 407 | + bulk_val[0] = U16_MSB(data->target_count[channel]); |
| 408 | + bulk_val[1] = U16_LSB(data->target_count[channel]); |
| 409 | |
| 410 | - err = i2c_smbus_write_word_swapped(client, |
| 411 | + err = regmap_bulk_write(regmap, |
| 412 | MAX31790_REG_TARGET_COUNT(channel), |
| 413 | - data->target_count[channel]); |
| 414 | + bulk_val, |
| 415 | + 2); |
| 416 | + break; |
| 417 | + case hwmon_fan_enable: |
| 418 | + if (val == 0) |
| 419 | + data->fan_config[channel] &= ~MAX31790_FAN_CFG_TACH_INPUT_EN; |
| 420 | + else |
| 421 | + data->fan_config[channel] |= MAX31790_FAN_CFG_TACH_INPUT_EN; |
| 422 | + err = regmap_write(regmap, |
| 423 | + MAX31790_REG_FAN_CONFIG(channel), |
| 424 | + data->fan_config[channel]); |
| 425 | + break; |
| 426 | + case hwmon_fan_pulses: |
| 427 | + data->pulses[channel] = val; |
| 428 | + break; |
| 429 | + case hwmon_fan_div: |
| 430 | + if (data->fan_config[channel] & MAX31790_FAN_CFG_RPM_MODE) { |
| 431 | + err = -EINVAL; |
| 432 | + break; |
| 433 | + } |
| 434 | + sr = bits_for_speed_range(val); |
| 435 | + if (sr < 0) { |
| 436 | + err = -EINVAL; |
| 437 | + break; |
| 438 | + } |
| 439 | + |
| 440 | + data->fan_dynamics[channel] = |
| 441 | + ((data->fan_dynamics[channel] & |
| 442 | + ~MAX31790_FAN_DYN_SR_MASK) | |
| 443 | + (sr << MAX31790_FAN_DYN_SR_SHIFT)); |
| 444 | + err = regmap_write(regmap, |
| 445 | + MAX31790_REG_FAN_DYNAMICS(channel), |
| 446 | + data->fan_dynamics[channel]); |
| 447 | break; |
| 448 | default: |
| 449 | err = -EOPNOTSUPP; |
| 450 | @@ -250,6 +391,16 @@ static umode_t max31790_fan_is_visible(const void *_data, u32 attr, int channel) |
| 451 | !(fan_config & MAX31790_FAN_CFG_TACH_INPUT)) |
| 452 | return 0644; |
| 453 | return 0; |
| 454 | + case hwmon_fan_enable: |
| 455 | + if (channel < NR_CHANNEL || |
| 456 | + (fan_config & MAX31790_FAN_CFG_TACH_INPUT)) |
| 457 | + return 0644; |
| 458 | + return 0; |
| 459 | + case hwmon_fan_div: |
| 460 | + case hwmon_fan_pulses: |
| 461 | + if (channel < NR_CHANNEL) |
| 462 | + return 0644; |
| 463 | + return 0; |
| 464 | default: |
| 465 | return 0; |
| 466 | } |
| 467 | @@ -271,12 +422,12 @@ static int max31790_read_pwm(struct device *dev, u32 attr, int channel, |
| 468 | *val = data->pwm[channel] >> 8; |
| 469 | return 0; |
| 470 | case hwmon_pwm_enable: |
| 471 | - if (fan_config & MAX31790_FAN_CFG_RPM_MODE) |
| 472 | + if (data->full_speed[channel]) |
| 473 | + *val = 0; |
| 474 | + else if (fan_config & MAX31790_FAN_CFG_RPM_MODE) |
| 475 | *val = 2; |
| 476 | - else if (fan_config & MAX31790_FAN_CFG_TACH_INPUT_EN) |
| 477 | - *val = 1; |
| 478 | else |
| 479 | - *val = 0; |
| 480 | + *val = 1; |
| 481 | return 0; |
| 482 | default: |
| 483 | return -EOPNOTSUPP; |
| 484 | @@ -287,43 +438,69 @@ static int max31790_write_pwm(struct device *dev, u32 attr, int channel, |
| 485 | long val) |
| 486 | { |
| 487 | struct max31790_data *data = dev_get_drvdata(dev); |
| 488 | - struct i2c_client *client = data->client; |
| 489 | + struct regmap *regmap = data->regmap; |
| 490 | u8 fan_config; |
| 491 | int err = 0; |
| 492 | + u8 bulk_val[2]; |
| 493 | |
| 494 | mutex_lock(&data->update_lock); |
| 495 | |
| 496 | switch (attr) { |
| 497 | case hwmon_pwm_input: |
| 498 | - if (val < 0 || val > 255) { |
| 499 | + if (data->full_speed[channel] || val < 0 || val > 255) { |
| 500 | err = -EINVAL; |
| 501 | break; |
| 502 | } |
| 503 | data->pwm[channel] = val << 8; |
| 504 | - err = i2c_smbus_write_word_swapped(client, |
| 505 | - MAX31790_REG_PWMOUT(channel), |
| 506 | - data->pwm[channel]); |
| 507 | + bulk_val[0] = U16_MSB(data->pwm[channel]); |
| 508 | + bulk_val[1] = U16_LSB(data->pwm[channel]); |
| 509 | + err = regmap_bulk_write(regmap, |
| 510 | + MAX31790_REG_PWMOUT(channel), |
| 511 | + bulk_val, |
| 512 | + 2); |
| 513 | break; |
| 514 | case hwmon_pwm_enable: |
| 515 | fan_config = data->fan_config[channel]; |
| 516 | - if (val == 0) { |
| 517 | - fan_config &= ~(MAX31790_FAN_CFG_TACH_INPUT_EN | |
| 518 | - MAX31790_FAN_CFG_RPM_MODE); |
| 519 | - } else if (val == 1) { |
| 520 | - fan_config = (fan_config | |
| 521 | - MAX31790_FAN_CFG_TACH_INPUT_EN) & |
| 522 | - ~MAX31790_FAN_CFG_RPM_MODE; |
| 523 | + if (val == 0 || val == 1) { |
| 524 | + fan_config &= ~MAX31790_FAN_CFG_RPM_MODE; |
| 525 | } else if (val == 2) { |
| 526 | - fan_config |= MAX31790_FAN_CFG_TACH_INPUT_EN | |
| 527 | - MAX31790_FAN_CFG_RPM_MODE; |
| 528 | + fan_config |= MAX31790_FAN_CFG_RPM_MODE; |
| 529 | } else { |
| 530 | err = -EINVAL; |
| 531 | break; |
| 532 | } |
| 533 | data->fan_config[channel] = fan_config; |
| 534 | - err = i2c_smbus_write_byte_data(client, |
| 535 | - MAX31790_REG_FAN_CONFIG(channel), |
| 536 | - fan_config); |
| 537 | + err = regmap_write(regmap, |
| 538 | + MAX31790_REG_FAN_CONFIG(channel), |
| 539 | + fan_config); |
| 540 | + |
| 541 | + /* |
| 542 | + * The chip sets PWM to zero when using its "monitor only" mode |
| 543 | + * and 0 means full speed. |
| 544 | + */ |
| 545 | + if (val == 0) { |
| 546 | + data->full_speed[channel] = true; |
| 547 | + data->pwm[channel] = MAX_PWM; |
| 548 | + bulk_val[0] = U16_MSB(data->pwm[channel]); |
| 549 | + bulk_val[1] = U16_LSB(data->pwm[channel]); |
| 550 | + err = regmap_bulk_write(regmap, |
| 551 | + MAX31790_REG_PWMOUT(channel), |
| 552 | + bulk_val, |
| 553 | + 2); |
| 554 | + } else { |
| 555 | + data->full_speed[channel] = false; |
| 556 | + } |
| 557 | + |
| 558 | + /* |
| 559 | + * RPM mode implies enabled TACH input, so enable it in RPM |
| 560 | + * mode. |
| 561 | + */ |
| 562 | + if (val == 2) { |
| 563 | + data->fan_config[channel] |= MAX31790_FAN_CFG_TACH_INPUT_EN; |
| 564 | + err = regmap_write(regmap, |
| 565 | + MAX31790_REG_FAN_CONFIG(channel), |
| 566 | + data->fan_config[channel]); |
| 567 | + } |
| 568 | break; |
| 569 | default: |
| 570 | err = -EOPNOTSUPP; |
| 571 | @@ -393,25 +570,25 @@ static umode_t max31790_is_visible(const void *data, |
| 572 | |
| 573 | static const struct hwmon_channel_info *max31790_info[] = { |
| 574 | HWMON_CHANNEL_INFO(fan, |
| 575 | - HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, |
| 576 | - HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, |
| 577 | - HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, |
| 578 | - HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, |
| 579 | - HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, |
| 580 | - HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT, |
| 581 | - HWMON_F_INPUT | HWMON_F_FAULT, |
| 582 | - HWMON_F_INPUT | HWMON_F_FAULT, |
| 583 | - HWMON_F_INPUT | HWMON_F_FAULT, |
| 584 | - HWMON_F_INPUT | HWMON_F_FAULT, |
| 585 | - HWMON_F_INPUT | HWMON_F_FAULT, |
| 586 | - HWMON_F_INPUT | HWMON_F_FAULT), |
| 587 | + FAN_INFO_1_TO_6, |
| 588 | + FAN_INFO_1_TO_6, |
| 589 | + FAN_INFO_1_TO_6, |
| 590 | + FAN_INFO_1_TO_6, |
| 591 | + FAN_INFO_1_TO_6, |
| 592 | + FAN_INFO_1_TO_6, |
| 593 | + FAN_INFO_7_TO_12, |
| 594 | + FAN_INFO_7_TO_12, |
| 595 | + FAN_INFO_7_TO_12, |
| 596 | + FAN_INFO_7_TO_12, |
| 597 | + FAN_INFO_7_TO_12, |
| 598 | + FAN_INFO_7_TO_12), |
| 599 | HWMON_CHANNEL_INFO(pwm, |
| 600 | - HWMON_PWM_INPUT | HWMON_PWM_ENABLE, |
| 601 | - HWMON_PWM_INPUT | HWMON_PWM_ENABLE, |
| 602 | - HWMON_PWM_INPUT | HWMON_PWM_ENABLE, |
| 603 | - HWMON_PWM_INPUT | HWMON_PWM_ENABLE, |
| 604 | - HWMON_PWM_INPUT | HWMON_PWM_ENABLE, |
| 605 | - HWMON_PWM_INPUT | HWMON_PWM_ENABLE), |
| 606 | + HWMON_PWM_INPUT | HWMON_PWM_ENABLE, |
| 607 | + HWMON_PWM_INPUT | HWMON_PWM_ENABLE, |
| 608 | + HWMON_PWM_INPUT | HWMON_PWM_ENABLE, |
| 609 | + HWMON_PWM_INPUT | HWMON_PWM_ENABLE, |
| 610 | + HWMON_PWM_INPUT | HWMON_PWM_ENABLE, |
| 611 | + HWMON_PWM_INPUT | HWMON_PWM_ENABLE), |
| 612 | NULL |
| 613 | }; |
| 614 | |
| 615 | @@ -426,23 +603,29 @@ static const struct hwmon_chip_info max31790_chip_info = { |
| 616 | .info = max31790_info, |
| 617 | }; |
| 618 | |
| 619 | -static int max31790_init_client(struct i2c_client *client, |
| 620 | +static int max31790_init_client(struct regmap *regmap, |
| 621 | struct max31790_data *data) |
| 622 | { |
| 623 | - int i, rv; |
| 624 | + int i, rv, val; |
| 625 | |
| 626 | for (i = 0; i < NR_CHANNEL; i++) { |
| 627 | - rv = i2c_smbus_read_byte_data(client, |
| 628 | - MAX31790_REG_FAN_CONFIG(i)); |
| 629 | + rv = regmap_read(regmap, |
| 630 | + MAX31790_REG_FAN_CONFIG(i), |
| 631 | + &val); |
| 632 | if (rv < 0) |
| 633 | return rv; |
| 634 | - data->fan_config[i] = rv; |
| 635 | + data->fan_config[i] = val; |
| 636 | + |
| 637 | + data->full_speed[i] = false; |
| 638 | |
| 639 | - rv = i2c_smbus_read_byte_data(client, |
| 640 | - MAX31790_REG_FAN_DYNAMICS(i)); |
| 641 | + data->pulses[i] = 2; |
| 642 | + |
| 643 | + rv = regmap_read(regmap, |
| 644 | + MAX31790_REG_FAN_DYNAMICS(i), |
| 645 | + &val); |
| 646 | if (rv < 0) |
| 647 | return rv; |
| 648 | - data->fan_dynamics[i] = rv; |
| 649 | + data->fan_dynamics[i] = val; |
| 650 | } |
| 651 | |
| 652 | return 0; |
| 653 | @@ -464,13 +647,19 @@ static int max31790_probe(struct i2c_client *client) |
| 654 | if (!data) |
| 655 | return -ENOMEM; |
| 656 | |
| 657 | - data->client = client; |
| 658 | mutex_init(&data->update_lock); |
| 659 | |
| 660 | + data->regmap = devm_regmap_init_i2c(client, &max31790_regmap_config); |
| 661 | + |
| 662 | + if (IS_ERR(data->regmap)) { |
| 663 | + dev_err(dev, "failed to allocate register map\n"); |
| 664 | + return PTR_ERR(data->regmap); |
| 665 | + } |
| 666 | + |
| 667 | /* |
| 668 | * Initialize the max31790 chip |
| 669 | */ |
| 670 | - err = max31790_init_client(client, data); |
| 671 | + err = max31790_init_client(data->regmap, data); |
| 672 | if (err) |
| 673 | return err; |
| 674 | |
| 675 | @@ -488,11 +677,18 @@ static const struct i2c_device_id max31790_id[] = { |
Jan Kundrát | 6406d51 | 2020-11-18 18:24:36 +0100 | [diff] [blame] | 676 | }; |
| 677 | MODULE_DEVICE_TABLE(i2c, max31790_id); |
| 678 | |
| 679 | +static const struct of_device_id __maybe_unused max31790_of_match[] = { |
| 680 | + { .compatible = "maxim,max31790" }, |
| 681 | + { } |
| 682 | +}; |
| 683 | +MODULE_DEVICE_TABLE(of, max31790_of_match); |
| 684 | + |
| 685 | static struct i2c_driver max31790_driver = { |
| 686 | .class = I2C_CLASS_HWMON, |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 687 | .probe_new = max31790_probe, |
Jan Kundrát | 6406d51 | 2020-11-18 18:24:36 +0100 | [diff] [blame] | 688 | .driver = { |
| 689 | .name = "max31790", |
| 690 | + .of_match_table = of_match_ptr(max31790_of_match), |
| 691 | }, |
| 692 | .id_table = max31790_id, |
| 693 | }; |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 694 | diff --git a/drivers/leds/leds-tlc591xx.c b/drivers/leds/leds-tlc591xx.c |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 695 | index 5b9dfdf743ec..26ea1164cb49 100644 |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 696 | --- a/drivers/leds/leds-tlc591xx.c |
| 697 | +++ b/drivers/leds/leds-tlc591xx.c |
Jan Kundrát | f97c81d | 2020-02-06 00:33:19 +0100 | [diff] [blame] | 698 | @@ -40,6 +40,9 @@ |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 699 | |
| 700 | #define ldev_to_led(c) container_of(c, struct tlc591xx_led, ldev) |
| 701 | |
| 702 | +#define TLC591XX_RESET_BYTE_0 0xa5 |
| 703 | +#define TLC591XX_RESET_BYTE_1 0x5a |
| 704 | + |
| 705 | struct tlc591xx_led { |
| 706 | bool active; |
| 707 | unsigned int led_no; |
Jan Kundrát | f97c81d | 2020-02-06 00:33:19 +0100 | [diff] [blame] | 708 | @@ -51,21 +54,25 @@ struct tlc591xx_priv { |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 709 | struct tlc591xx_led leds[TLC591XX_MAX_LEDS]; |
| 710 | struct regmap *regmap; |
| 711 | unsigned int reg_ledout_offset; |
| 712 | + struct i2c_client *swrst_client; |
| 713 | }; |
| 714 | |
| 715 | struct tlc591xx { |
| 716 | unsigned int max_leds; |
| 717 | unsigned int reg_ledout_offset; |
| 718 | + u8 swrst_addr; |
| 719 | }; |
| 720 | |
| 721 | static const struct tlc591xx tlc59116 = { |
| 722 | .max_leds = 16, |
| 723 | .reg_ledout_offset = 0x14, |
| 724 | + .swrst_addr = 0x6b, |
| 725 | }; |
| 726 | |
| 727 | static const struct tlc591xx tlc59108 = { |
| 728 | .max_leds = 8, |
| 729 | .reg_ledout_offset = 0x0c, |
| 730 | + .swrst_addr = 0x4b, |
| 731 | }; |
| 732 | |
| 733 | static int |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 734 | @@ -176,6 +183,18 @@ tlc591xx_probe(struct i2c_client *client, |
Jan Kundrát | 31bf7ae | 2020-02-14 17:03:53 +0100 | [diff] [blame] | 735 | |
| 736 | i2c_set_clientdata(client, priv); |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 737 | |
Jan Kundrát | f97c81d | 2020-02-06 00:33:19 +0100 | [diff] [blame] | 738 | + priv->swrst_client = devm_i2c_new_dummy_device(dev, client->adapter, tlc591xx->swrst_addr); |
Jan Kundrát | 89b682a | 2020-03-08 13:03:33 -0700 | [diff] [blame] | 739 | + if (IS_ERR(priv->swrst_client)) { |
| 740 | + dev_info(dev, "Skipping reset: address %02x already used\n", |
| 741 | + tlc591xx->swrst_addr); |
| 742 | + } else { |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 743 | + err = i2c_smbus_write_byte_data(priv->swrst_client, |
| 744 | + TLC591XX_RESET_BYTE_0, TLC591XX_RESET_BYTE_1); |
| 745 | + if (err) { |
| 746 | + dev_warn(dev, "SW reset failed\n"); |
| 747 | + } |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 748 | + } |
| 749 | + |
Jan Kundrát | 31bf7ae | 2020-02-14 17:03:53 +0100 | [diff] [blame] | 750 | err = tlc591xx_set_mode(priv->regmap, MODE2_DIM); |
| 751 | if (err < 0) |
| 752 | return err; |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 753 | diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c |
| 754 | index 03f78fdb0dcd..7e2e12f70d70 100644 |
| 755 | --- a/drivers/net/ethernet/intel/igb/igb_main.c |
| 756 | +++ b/drivers/net/ethernet/intel/igb/igb_main.c |
| 757 | @@ -577,16 +577,15 @@ static void igb_set_i2c_data(void *data, int state) |
| 758 | struct e1000_hw *hw = &adapter->hw; |
| 759 | s32 i2cctl = rd32(E1000_I2CPARAMS); |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 760 | |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 761 | - if (state) |
| 762 | - i2cctl |= E1000_I2C_DATA_OUT; |
| 763 | - else |
| 764 | + if (state) { |
| 765 | + i2cctl |= E1000_I2C_DATA_OUT | E1000_I2C_DATA_OE_N; |
| 766 | + } else { |
| 767 | + i2cctl &= ~E1000_I2C_DATA_OE_N; |
| 768 | i2cctl &= ~E1000_I2C_DATA_OUT; |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 769 | + } |
| 770 | |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 771 | - i2cctl &= ~E1000_I2C_DATA_OE_N; |
| 772 | - i2cctl |= E1000_I2C_CLK_OE_N; |
| 773 | wr32(E1000_I2CPARAMS, i2cctl); |
| 774 | wrfl(); |
| 775 | - |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 776 | } |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 777 | |
| 778 | /** |
| 779 | @@ -603,8 +602,7 @@ static void igb_set_i2c_clk(void *data, int state) |
| 780 | s32 i2cctl = rd32(E1000_I2CPARAMS); |
| 781 | |
| 782 | if (state) { |
| 783 | - i2cctl |= E1000_I2C_CLK_OUT; |
| 784 | - i2cctl &= ~E1000_I2C_CLK_OE_N; |
| 785 | + i2cctl |= E1000_I2C_CLK_OUT | E1000_I2C_CLK_OE_N; |
| 786 | } else { |
| 787 | i2cctl &= ~E1000_I2C_CLK_OUT; |
| 788 | i2cctl &= ~E1000_I2C_CLK_OE_N; |
| 789 | @@ -3109,11 +3107,20 @@ static void igb_init_mas(struct igb_adapter *adapter) |
| 790 | static s32 igb_init_i2c(struct igb_adapter *adapter) |
| 791 | { |
| 792 | s32 status = 0; |
| 793 | + s32 i2cctl; |
| 794 | + struct e1000_hw *hw = &adapter->hw; |
| 795 | |
| 796 | /* I2C interface supported on i350 devices */ |
| 797 | if (adapter->hw.mac.type != e1000_i350) |
| 798 | return 0; |
| 799 | |
| 800 | + i2cctl = rd32(E1000_I2CPARAMS); |
| 801 | + i2cctl |= E1000_I2CBB_EN |
| 802 | + | E1000_I2C_CLK_OUT | E1000_I2C_CLK_OE_N |
| 803 | + | E1000_I2C_DATA_OUT | E1000_I2C_DATA_OE_N; |
| 804 | + wr32(E1000_I2CPARAMS, i2cctl); |
| 805 | + wrfl(); |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 806 | + |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 807 | /* Initialize the i2c bus which is controlled by the registers. |
| 808 | * This bus will use the i2c_algo_bit structue that implements |
| 809 | * the protocol through toggling of the 4 bits in the register. |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 810 | diff --git a/drivers/pinctrl/pinctrl-mcp23s08_spi.c b/drivers/pinctrl/pinctrl-mcp23s08_spi.c |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 811 | index 9ae10318f6f3..d378369bbeca 100644 |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 812 | --- a/drivers/pinctrl/pinctrl-mcp23s08_spi.c |
| 813 | +++ b/drivers/pinctrl/pinctrl-mcp23s08_spi.c |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 814 | @@ -8,6 +8,7 @@ |
| 815 | #include <linux/spi/spi.h> |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 816 | |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 817 | #include "pinctrl-mcp23s08.h" |
| 818 | +#include "../gpio/gpiolib.h" |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 819 | |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 820 | #define MCP_MAX_DEV_PER_CS 8 |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 821 | |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 822 | @@ -143,6 +144,10 @@ static int mcp23s08_probe(struct spi_device *spi) |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 823 | int type; |
| 824 | int ret; |
| 825 | u32 v; |
| 826 | + struct device_node *np; |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 827 | + int line_name_count; |
| 828 | + const char **names; |
| 829 | + int i; |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 830 | |
| 831 | match = device_get_match_data(dev); |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 832 | if (match) |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 833 | @@ -192,6 +197,43 @@ static int mcp23s08_probe(struct spi_device *spi) |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 834 | return ret; |
| 835 | |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 836 | ngpio += data->mcp[addr]->chip.ngpio; |
| 837 | + |
| 838 | + for_each_available_child_of_node(spi->dev.of_node, np) { |
| 839 | + u32 chip_addr; |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 840 | + ret = of_property_read_u32(np, "address", &chip_addr); |
| 841 | + if (ret) |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 842 | + continue; |
| 843 | + if (chip_addr != addr) |
| 844 | + continue; |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 845 | + |
| 846 | + line_name_count = fwnode_property_read_string_array(of_fwnode_handle(np), "gpio-line-names", NULL, 0); |
| 847 | + if (line_name_count < 0) |
| 848 | + continue; |
| 849 | + |
| 850 | + if (line_name_count > data->mcp[addr]->chip.ngpio) { |
| 851 | + dev_warn(&spi->dev, "gpio-line-names is length %d but should be at most length %d", |
| 852 | + line_name_count, data->mcp[addr]->chip.ngpio); |
| 853 | + line_name_count = data->mcp[addr]->chip.ngpio; |
| 854 | + } |
| 855 | + |
| 856 | + names = kcalloc(line_name_count, sizeof(*names), GFP_KERNEL); |
| 857 | + if (!names) { |
| 858 | + dev_warn(&spi->dev, "cannot allocate gpio-line-names"); |
| 859 | + continue; |
| 860 | + } |
| 861 | + |
| 862 | + ret = fwnode_property_read_string_array(of_fwnode_handle(np), "gpio-line-names", names, line_name_count); |
| 863 | + if (ret < 0) { |
| 864 | + dev_warn(&spi->dev, "failed to read GPIO line names"); |
| 865 | + kfree(names); |
| 866 | + continue; |
| 867 | + } |
| 868 | + |
| 869 | + for (i = 0; i < line_name_count; i++) |
| 870 | + data->mcp[addr]->chip.gpiodev->descs[i].name = names[i]; |
| 871 | + |
| 872 | + kfree(names); |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 873 | + } |
| 874 | } |
| 875 | data->ngpio = ngpio; |
| 876 | |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 877 | diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 878 | index b57b8b3cc26e..056d107d8f32 100644 |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 879 | --- a/drivers/spi/spi-orion.c |
| 880 | +++ b/drivers/spi/spi-orion.c |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 881 | @@ -86,10 +86,6 @@ struct orion_direct_acc { |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 882 | u32 size; |
| 883 | }; |
| 884 | |
| 885 | -struct orion_child_options { |
| 886 | - struct orion_direct_acc direct_access; |
| 887 | -}; |
| 888 | - |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 889 | struct orion_spi { |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 890 | struct spi_master *master; |
| 891 | void __iomem *base; |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 892 | @@ -97,7 +93,7 @@ struct orion_spi { |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 893 | struct clk *axi_clk; |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 894 | const struct orion_spi_dev *devdata; |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 895 | |
| 896 | - struct orion_child_options child[ORION_NUM_CHIPSELECTS]; |
| 897 | + struct orion_direct_acc direct_access[ORION_NUM_CHIPSELECTS]; |
| 898 | }; |
| 899 | |
| 900 | static inline void __iomem *spi_reg(struct orion_spi *orion_spi, u32 reg) |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 901 | @@ -434,7 +430,7 @@ orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer) |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 902 | int cs = spi->chip_select; |
Jan Kundrát | 549db87 | 2019-03-05 12:23:25 +0100 | [diff] [blame] | 903 | void __iomem *vaddr; |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 904 | |
| 905 | - word_len = spi->bits_per_word; |
| 906 | + word_len = xfer->bits_per_word; |
| 907 | count = xfer->len; |
| 908 | |
| 909 | orion_spi = spi_master_get_devdata(spi->master); |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 910 | @@ -443,7 +439,7 @@ orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer) |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 911 | * Use SPI direct write mode if base address is available. Otherwise |
| 912 | * fall back to PIO mode for this transfer. |
| 913 | */ |
| 914 | - vaddr = orion_spi->child[cs].direct_access.vaddr; |
| 915 | + vaddr = orion_spi->direct_access[cs].vaddr; |
| 916 | |
| 917 | if (vaddr && xfer->tx_buf && word_len == 8) { |
| 918 | unsigned int cnt = count / 4; |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 919 | @@ -682,7 +678,6 @@ static int orion_spi_probe(struct platform_device *pdev) |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | for_each_available_child_of_node(pdev->dev.of_node, np) { |
| 923 | - struct orion_direct_acc *dir_acc; |
| 924 | u32 cs; |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 925 | |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 926 | /* Get chip-select number from the "reg" property */ |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 927 | @@ -711,13 +706,14 @@ static int orion_spi_probe(struct platform_device *pdev) |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 928 | * This needs to get extended for the direct SPI NOR / SPI NAND |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 929 | * support, once this gets implemented. |
| 930 | */ |
| 931 | - dir_acc = &spi->child[cs].direct_access; |
| 932 | - dir_acc->vaddr = devm_ioremap(&pdev->dev, r->start, PAGE_SIZE); |
| 933 | - if (!dir_acc->vaddr) { |
| 934 | + spi->direct_access[cs].vaddr = devm_ioremap(&pdev->dev, |
| 935 | + r->start, |
| 936 | + PAGE_SIZE); |
| 937 | + if (!spi->direct_access[cs].vaddr) { |
| 938 | status = -ENOMEM; |
| 939 | goto out_rel_axi_clk; |
| 940 | } |
| 941 | - dir_acc->size = PAGE_SIZE; |
| 942 | + spi->direct_access[cs].size = PAGE_SIZE; |
| 943 | |
| 944 | dev_info(&pdev->dev, "CS%d configured for direct access\n", cs); |
| 945 | } |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 946 | diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 947 | index 9795b2e8b0b2..67e7c310a7dc 100644 |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 948 | --- a/drivers/tty/serial/max310x.c |
| 949 | +++ b/drivers/tty/serial/max310x.c |
Jan Kundrát | 2bfe9ee | 2019-12-04 13:42:07 +0100 | [diff] [blame] | 950 | @@ -235,6 +235,10 @@ |
| 951 | #define MAX310x_REV_MASK (0xf8) |
| 952 | #define MAX310X_WRITE_BIT 0x80 |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 953 | |
Jan Kundrát | 2bfe9ee | 2019-12-04 13:42:07 +0100 | [diff] [blame] | 954 | +/* Timeout for external crystal stability */ |
| 955 | +#define MAX310X_XTAL_WAIT_RETRIES 20 |
| 956 | +#define MAX310X_XTAL_WAIT_DELAY_MS 10 |
| 957 | + |
| 958 | /* MAX3107 specific */ |
| 959 | #define MAX3107_REV_ID (0xa0) |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 960 | |
Jan Kundrát | 2bfe9ee | 2019-12-04 13:42:07 +0100 | [diff] [blame] | 961 | @@ -610,11 +614,14 @@ static int max310x_set_ref_clk(struct device *dev, struct max310x_port *s, |
| 962 | |
| 963 | /* Wait for crystal */ |
| 964 | if (xtal) { |
| 965 | - unsigned int val; |
| 966 | - msleep(10); |
| 967 | - regmap_read(s->regmap, MAX310X_STS_IRQSTS_REG, &val); |
| 968 | + unsigned int val = 0, i; |
| 969 | + for (i = 0; i < MAX310X_XTAL_WAIT_RETRIES && !(val & MAX310X_STS_CLKREADY_BIT); ++i) { |
| 970 | + msleep(MAX310X_XTAL_WAIT_DELAY_MS); |
| 971 | + regmap_read(s->regmap, MAX310X_STS_IRQSTS_REG, &val); |
| 972 | + } |
| 973 | if (!(val & MAX310X_STS_CLKREADY_BIT)) { |
| 974 | - dev_warn(dev, "clock is not stable yet\n"); |
| 975 | + dev_err(dev, "clock is not stable\n"); |
| 976 | + return -EAGAIN; |
| 977 | } |
| 978 | } |
| 979 | |
Jan Kundrát | bf1e091 | 2021-03-05 12:45:23 +0100 | [diff] [blame] | 980 | @@ -1346,6 +1353,10 @@ static int max310x_probe(struct device *dev, const struct max310x_devtype *devty |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | uartclk = max310x_set_ref_clk(dev, s, freq, xtal); |
Jan Kundrát | 2bfe9ee | 2019-12-04 13:42:07 +0100 | [diff] [blame] | 984 | + if (uartclk < 0) { |
| 985 | + ret = uartclk; |
| 986 | + goto out_uart; |
| 987 | + } |
| 988 | dev_dbg(dev, "Reference clock set to %i Hz\n", uartclk); |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 989 | |
Jan Kundrát | 2bfe9ee | 2019-12-04 13:42:07 +0100 | [diff] [blame] | 990 | for (i = 0; i < devtype->nr; i++) { |