Lines Matching refs:max3191x

119 static unsigned int max3191x_wordlen(struct max3191x_chip *max3191x)  in max3191x_wordlen()  argument
121 return max3191x->mode == STATUS_BYTE_ENABLED ? 2 : 1; in max3191x_wordlen()
124 static int max3191x_readout_locked(struct max3191x_chip *max3191x) in max3191x_readout_locked() argument
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()
191 static bool max3191x_chip_is_faulting(struct max3191x_chip *max3191x, in max3191x_chip_is_faulting() argument
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()
209 struct max3191x_chip *max3191x = gpiochip_get_data(gpio); in max3191x_get() local
210 int ret, chipnum, wordlen = max3191x_wordlen(max3191x); in max3191x_get()
213 mutex_lock(&max3191x->lock); in max3191x_get()
214 ret = max3191x_readout_locked(max3191x); in max3191x_get()
219 if (max3191x_chip_is_faulting(max3191x, chipnum)) { in max3191x_get()
224 in = ((u8 *)max3191x->xfer.rx_buf)[chipnum * wordlen]; in max3191x_get()
228 mutex_unlock(&max3191x->lock); in max3191x_get()
235 struct max3191x_chip *max3191x = gpiochip_get_data(gpio); in max3191x_get_multiple() local
236 const unsigned int wordlen = max3191x_wordlen(max3191x); in max3191x_get_multiple()
242 mutex_lock(&max3191x->lock); in max3191x_get_multiple()
243 ret = max3191x_readout_locked(max3191x); in max3191x_get_multiple()
251 if (max3191x_chip_is_faulting(max3191x, chipnum)) { 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()
269 struct max3191x_chip *max3191x = gpiochip_get_data(gpio); in max3191x_set_config() local
275 if (!max3191x->db0_pins || !max3191x->db1_pins) 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()
362 struct max3191x_chip *max3191x; in max3191x_probe() local
365 max3191x = devm_kzalloc(dev, sizeof(*max3191x), GFP_KERNEL); in max3191x_probe()
366 if (!max3191x) in max3191x_probe()
368 spi_set_drvdata(spi, max3191x); in max3191x_probe()
370 max3191x->nchips = 1; 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()
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()
407 if (max3191x->db0_pins && max3191x->db1_pins && in max3191x_probe()
408 max3191x->db0_pins->ndescs != max3191x->db1_pins->ndescs) { 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()
448 struct max3191x_chip *max3191x = spi_get_drvdata(spi); in max3191x_remove() local
450 gpiochip_remove(&max3191x->gpio); in max3191x_remove()
451 mutex_destroy(&max3191x->lock); in max3191x_remove()