Merge tag 'counter-fixes-for-6.1a' of git://git.kernel.org/pub/scm/linux/kernel/git/wbg/counter into char-misc-linus

William writes:
"First set of Counter fixes for 6.1 cycle

Typical driver fixes for races and bugs. This also includes a sparse
warning fix for the recently introduced counter_array API: the macro
DEFINE_COUNTER_ARRAY_POLARITY() is reduced to a simple structure
definition rather than multiple data structure definitions.
- 104-quad-8
* Fix race getting function mode and direction
- microchip-tcb-capture
* Handle Signal1 read and Synapse
- ti-ecap-capture
* fix IS_ERR() vs NULL check
- counter
* Reduce DEFINE_COUNTER_ARRAY_POLARITY() to defining counter_array"

* tag 'counter-fixes-for-6.1a' of git://git.kernel.org/pub/scm/linux/kernel/git/wbg/counter:
counter: 104-quad-8: Fix race getting function mode and direction
counter: microchip-tcb-capture: Handle Signal1 read and Synapse
counter: ti-ecap-capture: fix IS_ERR() vs NULL check
counter: Reduce DEFINE_COUNTER_ARRAY_POLARITY() to defining counter_array

Changed files
+62 -32
drivers
include
linux
+42 -22
drivers/counter/104-quad-8.c
··· 232 232 COUNTER_FUNCTION_QUADRATURE_X4, 233 233 }; 234 234 235 + static int quad8_function_get(const struct quad8 *const priv, const size_t id, 236 + enum counter_function *const function) 237 + { 238 + if (!priv->quadrature_mode[id]) { 239 + *function = COUNTER_FUNCTION_PULSE_DIRECTION; 240 + return 0; 241 + } 242 + 243 + switch (priv->quadrature_scale[id]) { 244 + case 0: 245 + *function = COUNTER_FUNCTION_QUADRATURE_X1_A; 246 + return 0; 247 + case 1: 248 + *function = COUNTER_FUNCTION_QUADRATURE_X2_A; 249 + return 0; 250 + case 2: 251 + *function = COUNTER_FUNCTION_QUADRATURE_X4; 252 + return 0; 253 + default: 254 + /* should never reach this path */ 255 + return -EINVAL; 256 + } 257 + } 258 + 235 259 static int quad8_function_read(struct counter_device *counter, 236 260 struct counter_count *count, 237 261 enum counter_function *function) 238 262 { 239 263 struct quad8 *const priv = counter_priv(counter); 240 - const int id = count->id; 241 264 unsigned long irqflags; 265 + int retval; 242 266 243 267 spin_lock_irqsave(&priv->lock, irqflags); 244 268 245 - if (priv->quadrature_mode[id]) 246 - switch (priv->quadrature_scale[id]) { 247 - case 0: 248 - *function = COUNTER_FUNCTION_QUADRATURE_X1_A; 249 - break; 250 - case 1: 251 - *function = COUNTER_FUNCTION_QUADRATURE_X2_A; 252 - break; 253 - case 2: 254 - *function = COUNTER_FUNCTION_QUADRATURE_X4; 255 - break; 256 - } 257 - else 258 - *function = COUNTER_FUNCTION_PULSE_DIRECTION; 269 + retval = quad8_function_get(priv, count->id, function); 259 270 260 271 spin_unlock_irqrestore(&priv->lock, irqflags); 261 272 262 - return 0; 273 + return retval; 263 274 } 264 275 265 276 static int quad8_function_write(struct counter_device *counter, ··· 370 359 enum counter_synapse_action *action) 371 360 { 372 361 struct quad8 *const priv = counter_priv(counter); 362 + unsigned long irqflags; 373 363 int err; 374 364 enum counter_function function; 375 365 const size_t signal_a_id = count->synapses[0].signal->id; ··· 386 374 return 0; 387 375 } 388 376 389 - err = quad8_function_read(counter, count, &function); 390 - if (err) 377 + spin_lock_irqsave(&priv->lock, irqflags); 378 + 379 + /* Get Count function and direction atomically */ 380 + err = quad8_function_get(priv, count->id, &function); 381 + if (err) { 382 + spin_unlock_irqrestore(&priv->lock, irqflags); 391 383 return err; 384 + } 385 + err = quad8_direction_read(counter, count, &direction); 386 + if (err) { 387 + spin_unlock_irqrestore(&priv->lock, irqflags); 388 + return err; 389 + } 390 + 391 + spin_unlock_irqrestore(&priv->lock, irqflags); 392 392 393 393 /* Default action mode */ 394 394 *action = COUNTER_SYNAPSE_ACTION_NONE; ··· 413 389 return 0; 414 390 case COUNTER_FUNCTION_QUADRATURE_X1_A: 415 391 if (synapse->signal->id == signal_a_id) { 416 - err = quad8_direction_read(counter, count, &direction); 417 - if (err) 418 - return err; 419 - 420 392 if (direction == COUNTER_COUNT_DIRECTION_FORWARD) 421 393 *action = COUNTER_SYNAPSE_ACTION_RISING_EDGE; 422 394 else
+14 -4
drivers/counter/microchip-tcb-capture.c
··· 28 28 int qdec_mode; 29 29 int num_channels; 30 30 int channel[2]; 31 - bool trig_inverted; 32 31 }; 33 32 34 33 static const enum counter_function mchp_tc_count_functions[] = { ··· 152 153 153 154 regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], SR), &sr); 154 155 155 - if (priv->trig_inverted) 156 + if (signal->id == 1) 156 157 sigstatus = (sr & ATMEL_TC_MTIOB); 157 158 else 158 159 sigstatus = (sr & ATMEL_TC_MTIOA); ··· 169 170 { 170 171 struct mchp_tc_data *const priv = counter_priv(counter); 171 172 u32 cmr; 173 + 174 + if (priv->qdec_mode) { 175 + *action = COUNTER_SYNAPSE_ACTION_BOTH_EDGES; 176 + return 0; 177 + } 178 + 179 + /* Only TIOA signal is evaluated in non-QDEC mode */ 180 + if (synapse->signal->id != 0) { 181 + *action = COUNTER_SYNAPSE_ACTION_NONE; 182 + return 0; 183 + } 172 184 173 185 regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr); 174 186 ··· 209 199 struct mchp_tc_data *const priv = counter_priv(counter); 210 200 u32 edge = ATMEL_TC_ETRGEDG_NONE; 211 201 212 - /* QDEC mode is rising edge only */ 213 - if (priv->qdec_mode) 202 + /* QDEC mode is rising edge only; only TIOA handled in non-QDEC mode */ 203 + if (priv->qdec_mode || synapse->signal->id != 0) 214 204 return -EINVAL; 215 205 216 206 switch (action) {
+4 -3
drivers/counter/ti-ecap-capture.c
··· 377 377 COUNTER_SIGNAL_POLARITY_NEGATIVE, 378 378 }; 379 379 380 - static DEFINE_COUNTER_ARRAY_POLARITY(ecap_cnt_pol_array, ecap_cnt_pol_avail, ECAP_NB_CEVT); 380 + static DEFINE_COUNTER_AVAILABLE(ecap_cnt_pol_available, ecap_cnt_pol_avail); 381 + static DEFINE_COUNTER_ARRAY_POLARITY(ecap_cnt_pol_array, ecap_cnt_pol_available, ECAP_NB_CEVT); 381 382 382 383 static struct counter_comp ecap_cnt_signal_ext[] = { 383 384 COUNTER_COMP_ARRAY_POLARITY(ecap_cnt_pol_read, ecap_cnt_pol_write, ecap_cnt_pol_array), ··· 480 479 int ret; 481 480 482 481 counter_dev = devm_counter_alloc(dev, sizeof(*ecap_dev)); 483 - if (IS_ERR(counter_dev)) 484 - return PTR_ERR(counter_dev); 482 + if (!counter_dev) 483 + return -ENOMEM; 485 484 486 485 counter_dev->name = ECAP_DRV_NAME; 487 486 counter_dev->parent = dev;
+2 -3
include/linux/counter.h
··· 542 542 #define DEFINE_COUNTER_ARRAY_CAPTURE(_name, _length) \ 543 543 DEFINE_COUNTER_ARRAY_U64(_name, _length) 544 544 545 - #define DEFINE_COUNTER_ARRAY_POLARITY(_name, _enums, _length) \ 546 - DEFINE_COUNTER_AVAILABLE(_name##_available, _enums); \ 545 + #define DEFINE_COUNTER_ARRAY_POLARITY(_name, _available, _length) \ 547 546 struct counter_array _name = { \ 548 547 .type = COUNTER_COMP_SIGNAL_POLARITY, \ 549 - .avail = &(_name##_available), \ 548 + .avail = &(_available), \ 550 549 .length = (_length), \ 551 550 } 552 551