Lines Matching +full:de +full:- +full:assertion

1 // SPDX-License-Identifier: GPL-2.0-only
3 * gpio-max3191x.c - GPIO driver for Maxim MAX3191x industrial serializer
8 * Multiple chips can be daisy-chained, the spec does not impose
11 * Either of two modes is selectable: In 8-bit mode, only the state
13 * In 16-bit mode, an additional status byte is clocked out with
17 * readout of non-faulting chips in the same daisy-chain.
21 * daisy-chain.
23 * If the chips are hardwired to 8-bit mode ("modesel" pulled high),
24 * gpio-pisosr.c can be used alternatively to this driver.
30 * https://datasheets.maximintegrated.com/en/ds/MAX31953-MAX31963.pdf
47 * struct max3191x_chip - max3191x daisy-chain
50 * @nchips: number of chips in the daisy-chain
51 * @mode: current mode, 0 for 16-bit, 1 for 8-bit;
52 * for simplicity, all chips in the daisy-chain are assumed
64 * @fault: bitmap signaling assertion of @fault_pins for each chip
69 * for simplicity, all chips in the daisy-chain are assumed
109 return -EINVAL; in max3191x_direction_output()
121 return max3191x->mode == STATUS_BYTE_ENABLED ? 2 : 1; in max3191x_wordlen()
126 struct device *dev = max3191x->gpio.parent; in max3191x_readout_locked()
130 val = spi_sync(spi, &max3191x->mesg); in max3191x_readout_locked()
136 for (i = 0; i < max3191x->nchips; i++) { in max3191x_readout_locked()
137 if (max3191x->mode == STATUS_BYTE_ENABLED) { in max3191x_readout_locked()
138 u8 in = ((u8 *)max3191x->xfer.rx_buf)[i * 2]; in max3191x_readout_locked()
139 u8 status = ((u8 *)max3191x->xfer.rx_buf)[i * 2 + 1]; in max3191x_readout_locked()
142 __assign_bit(i, max3191x->crc_error, val); in max3191x_readout_locked()
148 __assign_bit(i, max3191x->overtemp, ot); in max3191x_readout_locked()
153 if (!max3191x->ignore_uv) { in max3191x_readout_locked()
155 __assign_bit(i, max3191x->undervolt1, uv1); in max3191x_readout_locked()
161 __assign_bit(i, max3191x->undervolt2, val); in max3191x_readout_locked()
168 if (max3191x->fault_pins && !max3191x->ignore_uv) { in max3191x_readout_locked()
171 (max3191x->fault_pins->ndescs == 1) in max3191x_readout_locked()
172 ? max3191x->fault_pins->desc[0] in max3191x_readout_locked()
173 : max3191x->fault_pins->desc[i]; in max3191x_readout_locked()
181 __assign_bit(i, max3191x->fault, val); in max3191x_readout_locked()
195 if (!max3191x->ignore_uv && test_bit(chipnum, max3191x->fault)) in max3191x_chip_is_faulting()
198 if (max3191x->mode == STATUS_BYTE_DISABLED) in max3191x_chip_is_faulting()
201 return test_bit(chipnum, max3191x->crc_error) || in max3191x_chip_is_faulting()
202 test_bit(chipnum, max3191x->overtemp) || in max3191x_chip_is_faulting()
203 (!max3191x->ignore_uv && in max3191x_chip_is_faulting()
204 test_bit(chipnum, max3191x->undervolt1)); in max3191x_chip_is_faulting()
213 mutex_lock(&max3191x->lock); in max3191x_get()
220 ret = -EIO; in max3191x_get()
224 in = ((u8 *)max3191x->xfer.rx_buf)[chipnum * wordlen]; in max3191x_get()
228 mutex_unlock(&max3191x->lock); in max3191x_get()
242 mutex_lock(&max3191x->lock); in max3191x_get_multiple()
247 bitmap_zero(bits, gpio->ngpio); in max3191x_get_multiple()
248 for_each_set_clump8(bit, gpio_mask, mask, gpio->ngpio) { in max3191x_get_multiple()
252 ret = -EIO; in max3191x_get_multiple()
256 in = ((u8 *)max3191x->xfer.rx_buf)[chipnum * wordlen]; in max3191x_get_multiple()
262 mutex_unlock(&max3191x->lock); in max3191x_get_multiple()
273 return -ENOTSUPP; in max3191x_set_config()
275 if (!max3191x->db0_pins || !max3191x->db1_pins) in max3191x_set_config()
276 return -EINVAL; in max3191x_set_config()
297 return -EINVAL; in max3191x_set_config()
300 if (max3191x->db0_pins->ndescs == 1) in max3191x_set_config()
305 mutex_lock(&max3191x->lock); in max3191x_set_config()
306 gpiod_set_value_cansleep(max3191x->db0_pins->desc[chipnum], db0_val); in max3191x_set_config()
307 gpiod_set_value_cansleep(max3191x->db1_pins->desc[chipnum], db1_val); in max3191x_set_config()
308 mutex_unlock(&max3191x->lock); in max3191x_set_config()
339 if (found == -ENOENT) in devm_gpiod_get_array_optional_count()
343 dev_err(dev, "ignoring %s-gpios: found %d, expected %u or 1\n", in devm_gpiod_get_array_optional_count()
351 dev_err(dev, "failed to get %s-gpios: %ld\n", in devm_gpiod_get_array_optional_count()
361 struct device *dev = &spi->dev; in max3191x_probe()
367 return -ENOMEM; in max3191x_probe()
370 max3191x->nchips = 1; in max3191x_probe()
371 device_property_read_u32(dev, "#daisy-chained-devices", in max3191x_probe()
372 &max3191x->nchips); in max3191x_probe()
374 n = BITS_TO_LONGS(max3191x->nchips); in max3191x_probe()
375 max3191x->crc_error = devm_kcalloc(dev, n, sizeof(long), GFP_KERNEL); in max3191x_probe()
376 max3191x->undervolt1 = devm_kcalloc(dev, n, sizeof(long), GFP_KERNEL); in max3191x_probe()
377 max3191x->undervolt2 = devm_kcalloc(dev, n, sizeof(long), GFP_KERNEL); in max3191x_probe()
378 max3191x->overtemp = devm_kcalloc(dev, n, sizeof(long), GFP_KERNEL); in max3191x_probe()
379 max3191x->fault = devm_kcalloc(dev, n, sizeof(long), GFP_KERNEL); in max3191x_probe()
380 max3191x->xfer.rx_buf = devm_kcalloc(dev, max3191x->nchips, in max3191x_probe()
382 if (!max3191x->crc_error || !max3191x->undervolt1 || in max3191x_probe()
383 !max3191x->overtemp || !max3191x->undervolt2 || in max3191x_probe()
384 !max3191x->fault || !max3191x->xfer.rx_buf) in max3191x_probe()
385 return -ENOMEM; in max3191x_probe()
387 max3191x->modesel_pins = devm_gpiod_get_array_optional_count(dev, in max3191x_probe()
388 "maxim,modesel", GPIOD_ASIS, max3191x->nchips); in max3191x_probe()
389 max3191x->fault_pins = devm_gpiod_get_array_optional_count(dev, in max3191x_probe()
390 "maxim,fault", GPIOD_IN, max3191x->nchips); in max3191x_probe()
391 max3191x->db0_pins = devm_gpiod_get_array_optional_count(dev, in max3191x_probe()
392 "maxim,db0", GPIOD_OUT_LOW, max3191x->nchips); in max3191x_probe()
393 max3191x->db1_pins = devm_gpiod_get_array_optional_count(dev, in max3191x_probe()
394 "maxim,db1", GPIOD_OUT_LOW, max3191x->nchips); in max3191x_probe()
396 max3191x->mode = device_property_read_bool(dev, "maxim,modesel-8bit") in max3191x_probe()
398 if (max3191x->modesel_pins) in max3191x_probe()
400 max3191x->modesel_pins->ndescs, in max3191x_probe()
401 max3191x->modesel_pins->desc, in max3191x_probe()
402 max3191x->modesel_pins->info, max3191x->mode); in max3191x_probe()
404 max3191x->ignore_uv = device_property_read_bool(dev, in max3191x_probe()
405 "maxim,ignore-undervoltage"); in max3191x_probe()
407 if (max3191x->db0_pins && max3191x->db1_pins && in max3191x_probe()
408 max3191x->db0_pins->ndescs != max3191x->db1_pins->ndescs) { in max3191x_probe()
409 dev_err(dev, "ignoring maxim,db*-gpios: array len mismatch\n"); in max3191x_probe()
410 devm_gpiod_put_array(dev, max3191x->db0_pins); in max3191x_probe()
411 devm_gpiod_put_array(dev, max3191x->db1_pins); in max3191x_probe()
412 max3191x->db0_pins = NULL; in max3191x_probe()
413 max3191x->db1_pins = NULL; in max3191x_probe()
416 max3191x->xfer.len = max3191x->nchips * max3191x_wordlen(max3191x); in max3191x_probe()
417 spi_message_init_with_transfers(&max3191x->mesg, &max3191x->xfer, 1); in max3191x_probe()
419 max3191x->gpio.label = spi->modalias; in max3191x_probe()
420 max3191x->gpio.owner = THIS_MODULE; in max3191x_probe()
421 max3191x->gpio.parent = dev; in max3191x_probe()
422 max3191x->gpio.base = -1; in max3191x_probe()
423 max3191x->gpio.ngpio = max3191x->nchips * MAX3191X_NGPIO; in max3191x_probe()
424 max3191x->gpio.can_sleep = true; in max3191x_probe()
426 max3191x->gpio.get_direction = max3191x_get_direction; in max3191x_probe()
427 max3191x->gpio.direction_input = max3191x_direction_input; in max3191x_probe()
428 max3191x->gpio.direction_output = max3191x_direction_output; in max3191x_probe()
429 max3191x->gpio.set = max3191x_set; in max3191x_probe()
430 max3191x->gpio.set_multiple = max3191x_set_multiple; in max3191x_probe()
431 max3191x->gpio.get = max3191x_get; in max3191x_probe()
432 max3191x->gpio.get_multiple = max3191x_get_multiple; in max3191x_probe()
433 max3191x->gpio.set_config = max3191x_set_config; in max3191x_probe()
435 mutex_init(&max3191x->lock); in max3191x_probe()
437 ret = gpiochip_add_data(&max3191x->gpio, max3191x); in max3191x_probe()
439 mutex_destroy(&max3191x->lock); in max3191x_probe()
450 gpiochip_remove(&max3191x->gpio); in max3191x_remove()
451 mutex_destroy(&max3191x->lock); in max3191x_remove()
493 MODULE_AUTHOR("Lukas Wunner <lukas@wunner.de>");