Lines Matching refs:max3191x

121 static unsigned int max3191x_wordlen(struct max3191x_chip *max3191x)  in max3191x_wordlen()  argument
123 return max3191x->mode == STATUS_BYTE_ENABLED ? 2 : 1; in max3191x_wordlen()
126 static int max3191x_readout_locked(struct max3191x_chip *max3191x) in max3191x_readout_locked() argument
128 struct device *dev = max3191x->gpio.parent; in max3191x_readout_locked()
132 val = spi_sync(spi, &max3191x->mesg); in max3191x_readout_locked()
138 for (i = 0; i < max3191x->nchips; i++) { in max3191x_readout_locked()
139 if (max3191x->mode == STATUS_BYTE_ENABLED) { in max3191x_readout_locked()
140 u8 in = ((u8 *)max3191x->xfer.rx_buf)[i * 2]; in max3191x_readout_locked()
141 u8 status = ((u8 *)max3191x->xfer.rx_buf)[i * 2 + 1]; in max3191x_readout_locked()
144 __assign_bit(i, max3191x->crc_error, val); in max3191x_readout_locked()
150 __assign_bit(i, max3191x->overtemp, ot); in max3191x_readout_locked()
155 if (!max3191x->ignore_uv) { in max3191x_readout_locked()
157 __assign_bit(i, max3191x->undervolt1, uv1); in max3191x_readout_locked()
163 __assign_bit(i, max3191x->undervolt2, val); in max3191x_readout_locked()
170 if (max3191x->fault_pins && !max3191x->ignore_uv) { in max3191x_readout_locked()
173 (max3191x->fault_pins->ndescs == 1) in max3191x_readout_locked()
174 ? max3191x->fault_pins->desc[0] in max3191x_readout_locked()
175 : max3191x->fault_pins->desc[i]; in max3191x_readout_locked()
183 __assign_bit(i, max3191x->fault, val); in max3191x_readout_locked()
193 static bool max3191x_chip_is_faulting(struct max3191x_chip *max3191x, in max3191x_chip_is_faulting() argument
197 if (!max3191x->ignore_uv && test_bit(chipnum, max3191x->fault)) in max3191x_chip_is_faulting()
200 if (max3191x->mode == STATUS_BYTE_DISABLED) in max3191x_chip_is_faulting()
203 return test_bit(chipnum, max3191x->crc_error) || in max3191x_chip_is_faulting()
204 test_bit(chipnum, max3191x->overtemp) || in max3191x_chip_is_faulting()
205 (!max3191x->ignore_uv && in max3191x_chip_is_faulting()
206 test_bit(chipnum, max3191x->undervolt1)); in max3191x_chip_is_faulting()
211 struct max3191x_chip *max3191x = gpiochip_get_data(gpio); in max3191x_get() local
212 int ret, chipnum, wordlen = max3191x_wordlen(max3191x); in max3191x_get()
215 mutex_lock(&max3191x->lock); in max3191x_get()
216 ret = max3191x_readout_locked(max3191x); in max3191x_get()
221 if (max3191x_chip_is_faulting(max3191x, chipnum)) { in max3191x_get()
226 in = ((u8 *)max3191x->xfer.rx_buf)[chipnum * wordlen]; in max3191x_get()
230 mutex_unlock(&max3191x->lock); in max3191x_get()
237 struct max3191x_chip *max3191x = gpiochip_get_data(gpio); in max3191x_get_multiple() local
238 int ret, bit = 0, wordlen = max3191x_wordlen(max3191x); in max3191x_get_multiple()
240 mutex_lock(&max3191x->lock); in max3191x_get_multiple()
241 ret = max3191x_readout_locked(max3191x); in max3191x_get_multiple()
249 if (max3191x_chip_is_faulting(max3191x, chipnum)) { in max3191x_get_multiple()
254 in = ((u8 *)max3191x->xfer.rx_buf)[chipnum * wordlen]; in max3191x_get_multiple()
264 mutex_unlock(&max3191x->lock); in max3191x_get_multiple()
271 struct max3191x_chip *max3191x = gpiochip_get_data(gpio); in max3191x_set_config() local
277 if (!max3191x->db0_pins || !max3191x->db1_pins) in max3191x_set_config()
302 if (max3191x->db0_pins->ndescs == 1) in max3191x_set_config()
307 mutex_lock(&max3191x->lock); in max3191x_set_config()
308 gpiod_set_value_cansleep(max3191x->db0_pins->desc[chipnum], db0_val); in max3191x_set_config()
309 gpiod_set_value_cansleep(max3191x->db1_pins->desc[chipnum], db1_val); in max3191x_set_config()
310 mutex_unlock(&max3191x->lock); in max3191x_set_config()
361 struct max3191x_chip *max3191x; in max3191x_probe() local
364 max3191x = devm_kzalloc(dev, sizeof(*max3191x), GFP_KERNEL); in max3191x_probe()
365 if (!max3191x) in max3191x_probe()
367 spi_set_drvdata(spi, max3191x); in max3191x_probe()
369 max3191x->nchips = 1; in max3191x_probe()
371 &max3191x->nchips); in max3191x_probe()
373 n = BITS_TO_LONGS(max3191x->nchips); in max3191x_probe()
374 max3191x->crc_error = devm_kcalloc(dev, n, sizeof(long), GFP_KERNEL); in max3191x_probe()
375 max3191x->undervolt1 = devm_kcalloc(dev, n, sizeof(long), GFP_KERNEL); in max3191x_probe()
376 max3191x->undervolt2 = devm_kcalloc(dev, n, sizeof(long), GFP_KERNEL); in max3191x_probe()
377 max3191x->overtemp = devm_kcalloc(dev, n, sizeof(long), GFP_KERNEL); in max3191x_probe()
378 max3191x->fault = devm_kcalloc(dev, n, sizeof(long), GFP_KERNEL); in max3191x_probe()
379 max3191x->xfer.rx_buf = devm_kcalloc(dev, max3191x->nchips, in max3191x_probe()
381 if (!max3191x->crc_error || !max3191x->undervolt1 || in max3191x_probe()
382 !max3191x->overtemp || !max3191x->undervolt2 || in max3191x_probe()
383 !max3191x->fault || !max3191x->xfer.rx_buf) in max3191x_probe()
386 max3191x->modesel_pins = devm_gpiod_get_array_optional_count(dev, in max3191x_probe()
387 "maxim,modesel", GPIOD_ASIS, max3191x->nchips); in max3191x_probe()
388 max3191x->fault_pins = devm_gpiod_get_array_optional_count(dev, in max3191x_probe()
389 "maxim,fault", GPIOD_IN, max3191x->nchips); in max3191x_probe()
390 max3191x->db0_pins = devm_gpiod_get_array_optional_count(dev, in max3191x_probe()
391 "maxim,db0", GPIOD_OUT_LOW, max3191x->nchips); in max3191x_probe()
392 max3191x->db1_pins = devm_gpiod_get_array_optional_count(dev, in max3191x_probe()
393 "maxim,db1", GPIOD_OUT_LOW, max3191x->nchips); in max3191x_probe()
395 max3191x->mode = device_property_read_bool(dev, "maxim,modesel-8bit") in max3191x_probe()
397 if (max3191x->modesel_pins) in max3191x_probe()
399 max3191x->modesel_pins->ndescs, in max3191x_probe()
400 max3191x->modesel_pins->desc, max3191x->mode); in max3191x_probe()
402 max3191x->ignore_uv = device_property_read_bool(dev, in max3191x_probe()
405 if (max3191x->db0_pins && max3191x->db1_pins && in max3191x_probe()
406 max3191x->db0_pins->ndescs != max3191x->db1_pins->ndescs) { in max3191x_probe()
408 devm_gpiod_put_array(dev, max3191x->db0_pins); in max3191x_probe()
409 devm_gpiod_put_array(dev, max3191x->db1_pins); in max3191x_probe()
410 max3191x->db0_pins = NULL; in max3191x_probe()
411 max3191x->db1_pins = NULL; in max3191x_probe()
414 max3191x->xfer.len = max3191x->nchips * max3191x_wordlen(max3191x); in max3191x_probe()
415 spi_message_init_with_transfers(&max3191x->mesg, &max3191x->xfer, 1); in max3191x_probe()
417 max3191x->gpio.label = spi->modalias; in max3191x_probe()
418 max3191x->gpio.owner = THIS_MODULE; in max3191x_probe()
419 max3191x->gpio.parent = dev; in max3191x_probe()
420 max3191x->gpio.base = -1; in max3191x_probe()
421 max3191x->gpio.ngpio = max3191x->nchips * MAX3191X_NGPIO; in max3191x_probe()
422 max3191x->gpio.can_sleep = true; in max3191x_probe()
424 max3191x->gpio.get_direction = max3191x_get_direction; in max3191x_probe()
425 max3191x->gpio.direction_input = max3191x_direction_input; in max3191x_probe()
426 max3191x->gpio.direction_output = max3191x_direction_output; in max3191x_probe()
427 max3191x->gpio.set = max3191x_set; in max3191x_probe()
428 max3191x->gpio.set_multiple = max3191x_set_multiple; in max3191x_probe()
429 max3191x->gpio.get = max3191x_get; in max3191x_probe()
430 max3191x->gpio.get_multiple = max3191x_get_multiple; in max3191x_probe()
431 max3191x->gpio.set_config = max3191x_set_config; in max3191x_probe()
433 mutex_init(&max3191x->lock); in max3191x_probe()
435 ret = gpiochip_add_data(&max3191x->gpio, max3191x); in max3191x_probe()
437 mutex_destroy(&max3191x->lock); in max3191x_probe()
446 struct max3191x_chip *max3191x = spi_get_drvdata(spi); in max3191x_remove() local
448 gpiochip_remove(&max3191x->gpio); in max3191x_remove()
449 mutex_destroy(&max3191x->lock); in max3191x_remove()