| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Holt Integrated Circuits HI-8435 threshold detector driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2015 Zodiac Inflight Innovations |
|---|
| 5 | 6 | * Copyright (C) 2015 Cogent Embedded, Inc. |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 8 | | - * under the terms of the GNU General Public License as published by the |
|---|
| 9 | | - * Free Software Foundation; either version 2 of the License, or (at your |
|---|
| 10 | | - * option) any later version. |
|---|
| 11 | 7 | */ |
|---|
| 12 | 8 | |
|---|
| 13 | 9 | #include <linux/delay.h> |
|---|
| .. | .. |
|---|
| 19 | 15 | #include <linux/iio/triggered_event.h> |
|---|
| 20 | 16 | #include <linux/interrupt.h> |
|---|
| 21 | 17 | #include <linux/module.h> |
|---|
| 22 | | -#include <linux/of.h> |
|---|
| 23 | | -#include <linux/of_device.h> |
|---|
| 24 | | -#include <linux/of_gpio.h> |
|---|
| 18 | +#include <linux/mod_devicetable.h> |
|---|
| 25 | 19 | #include <linux/spi/spi.h> |
|---|
| 26 | 20 | #include <linux/gpio/consumer.h> |
|---|
| 27 | 21 | |
|---|
| .. | .. |
|---|
| 460 | 454 | return IRQ_HANDLED; |
|---|
| 461 | 455 | } |
|---|
| 462 | 456 | |
|---|
| 457 | +static void hi8435_triggered_event_cleanup(void *data) |
|---|
| 458 | +{ |
|---|
| 459 | + iio_triggered_event_cleanup(data); |
|---|
| 460 | +} |
|---|
| 461 | + |
|---|
| 463 | 462 | static int hi8435_probe(struct spi_device *spi) |
|---|
| 464 | 463 | { |
|---|
| 465 | 464 | struct iio_dev *idev; |
|---|
| .. | .. |
|---|
| 481 | 480 | hi8435_writeb(priv, HI8435_CTRL_REG, 0); |
|---|
| 482 | 481 | } else { |
|---|
| 483 | 482 | udelay(5); |
|---|
| 484 | | - gpiod_set_value(reset_gpio, 1); |
|---|
| 483 | + gpiod_set_value_cansleep(reset_gpio, 1); |
|---|
| 485 | 484 | } |
|---|
| 486 | 485 | |
|---|
| 487 | 486 | spi_set_drvdata(spi, idev); |
|---|
| 488 | 487 | mutex_init(&priv->lock); |
|---|
| 489 | 488 | |
|---|
| 490 | | - idev->dev.parent = &spi->dev; |
|---|
| 491 | | - idev->dev.of_node = spi->dev.of_node; |
|---|
| 492 | 489 | idev->name = spi_get_device_id(spi)->name; |
|---|
| 493 | 490 | idev->modes = INDIO_DIRECT_MODE; |
|---|
| 494 | 491 | idev->info = &hi8435_info; |
|---|
| .. | .. |
|---|
| 517 | 514 | if (ret) |
|---|
| 518 | 515 | return ret; |
|---|
| 519 | 516 | |
|---|
| 520 | | - ret = iio_device_register(idev); |
|---|
| 521 | | - if (ret < 0) { |
|---|
| 522 | | - dev_err(&spi->dev, "unable to register device\n"); |
|---|
| 523 | | - goto unregister_triggered_event; |
|---|
| 524 | | - } |
|---|
| 517 | + ret = devm_add_action_or_reset(&spi->dev, |
|---|
| 518 | + hi8435_triggered_event_cleanup, |
|---|
| 519 | + idev); |
|---|
| 520 | + if (ret) |
|---|
| 521 | + return ret; |
|---|
| 525 | 522 | |
|---|
| 526 | | - return 0; |
|---|
| 527 | | - |
|---|
| 528 | | -unregister_triggered_event: |
|---|
| 529 | | - iio_triggered_event_cleanup(idev); |
|---|
| 530 | | - return ret; |
|---|
| 531 | | -} |
|---|
| 532 | | - |
|---|
| 533 | | -static int hi8435_remove(struct spi_device *spi) |
|---|
| 534 | | -{ |
|---|
| 535 | | - struct iio_dev *idev = spi_get_drvdata(spi); |
|---|
| 536 | | - |
|---|
| 537 | | - iio_device_unregister(idev); |
|---|
| 538 | | - iio_triggered_event_cleanup(idev); |
|---|
| 539 | | - |
|---|
| 540 | | - return 0; |
|---|
| 523 | + return devm_iio_device_register(&spi->dev, idev); |
|---|
| 541 | 524 | } |
|---|
| 542 | 525 | |
|---|
| 543 | 526 | static const struct of_device_id hi8435_dt_ids[] = { |
|---|
| .. | .. |
|---|
| 555 | 538 | static struct spi_driver hi8435_driver = { |
|---|
| 556 | 539 | .driver = { |
|---|
| 557 | 540 | .name = DRV_NAME, |
|---|
| 558 | | - .of_match_table = of_match_ptr(hi8435_dt_ids), |
|---|
| 541 | + .of_match_table = hi8435_dt_ids, |
|---|
| 559 | 542 | }, |
|---|
| 560 | 543 | .probe = hi8435_probe, |
|---|
| 561 | | - .remove = hi8435_remove, |
|---|
| 562 | 544 | .id_table = hi8435_id, |
|---|
| 563 | 545 | }; |
|---|
| 564 | 546 | module_spi_driver(hi8435_driver); |
|---|