| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright 2010 Analog Devices Inc. |
|---|
| 5 | | - * |
|---|
| 6 | | - * Licensed under the GPL-2 or later. |
|---|
| 7 | 6 | */ |
|---|
| 8 | 7 | |
|---|
| 9 | 8 | #include <linux/device.h> |
|---|
| .. | .. |
|---|
| 73 | 72 | #define ADIS16209_STAT_FLASH_UPT_FAIL_BIT 2 |
|---|
| 74 | 73 | /* Power supply above 3.625 V */ |
|---|
| 75 | 74 | #define ADIS16209_STAT_POWER_HIGH_BIT 1 |
|---|
| 76 | | -/* Power supply below 3.15 V */ |
|---|
| 75 | +/* Power supply below 2.975 V */ |
|---|
| 77 | 76 | #define ADIS16209_STAT_POWER_LOW_BIT 0 |
|---|
| 78 | 77 | |
|---|
| 79 | 78 | #define ADIS16209_CMD_REG 0x3E |
|---|
| .. | .. |
|---|
| 241 | 240 | [ADIS16209_STAT_SPI_FAIL_BIT] = "SPI failure", |
|---|
| 242 | 241 | [ADIS16209_STAT_FLASH_UPT_FAIL_BIT] = "Flash update failed", |
|---|
| 243 | 242 | [ADIS16209_STAT_POWER_HIGH_BIT] = "Power supply above 3.625V", |
|---|
| 244 | | - [ADIS16209_STAT_POWER_LOW_BIT] = "Power supply below 3.15V", |
|---|
| 243 | + [ADIS16209_STAT_POWER_LOW_BIT] = "Power supply below 2.975V", |
|---|
| 244 | +}; |
|---|
| 245 | + |
|---|
| 246 | +static const struct adis_timeout adis16209_timeouts = { |
|---|
| 247 | + .reset_ms = ADIS16209_STARTUP_DELAY_MS, |
|---|
| 248 | + .self_test_ms = ADIS16209_STARTUP_DELAY_MS, |
|---|
| 249 | + .sw_reset_ms = ADIS16209_STARTUP_DELAY_MS, |
|---|
| 245 | 250 | }; |
|---|
| 246 | 251 | |
|---|
| 247 | 252 | static const struct adis_data adis16209_data = { |
|---|
| .. | .. |
|---|
| 251 | 256 | .diag_stat_reg = ADIS16209_STAT_REG, |
|---|
| 252 | 257 | |
|---|
| 253 | 258 | .self_test_mask = ADIS16209_MSC_CTRL_SELF_TEST_EN, |
|---|
| 259 | + .self_test_reg = ADIS16209_MSC_CTRL_REG, |
|---|
| 254 | 260 | .self_test_no_autoclear = true, |
|---|
| 255 | | - .startup_delay = ADIS16209_STARTUP_DELAY_MS, |
|---|
| 261 | + .timeouts = &adis16209_timeouts, |
|---|
| 256 | 262 | |
|---|
| 257 | 263 | .status_error_msgs = adis16209_status_error_msgs, |
|---|
| 258 | 264 | .status_error_mask = BIT(ADIS16209_STAT_SELFTEST_FAIL_BIT) | |
|---|
| .. | .. |
|---|
| 276 | 282 | spi_set_drvdata(spi, indio_dev); |
|---|
| 277 | 283 | |
|---|
| 278 | 284 | indio_dev->name = spi->dev.driver->name; |
|---|
| 279 | | - indio_dev->dev.parent = &spi->dev; |
|---|
| 280 | 285 | indio_dev->info = &adis16209_info; |
|---|
| 281 | 286 | indio_dev->channels = adis16209_channels; |
|---|
| 282 | 287 | indio_dev->num_channels = ARRAY_SIZE(adis16209_channels); |
|---|
| .. | .. |
|---|
| 286 | 291 | if (ret) |
|---|
| 287 | 292 | return ret; |
|---|
| 288 | 293 | |
|---|
| 289 | | - ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL); |
|---|
| 294 | + ret = devm_adis_setup_buffer_and_trigger(st, indio_dev, NULL); |
|---|
| 290 | 295 | if (ret) |
|---|
| 291 | 296 | return ret; |
|---|
| 292 | 297 | |
|---|
| 293 | 298 | ret = adis_initial_startup(st); |
|---|
| 294 | 299 | if (ret) |
|---|
| 295 | | - goto error_cleanup_buffer_trigger; |
|---|
| 296 | | - ret = iio_device_register(indio_dev); |
|---|
| 297 | | - if (ret) |
|---|
| 298 | | - goto error_cleanup_buffer_trigger; |
|---|
| 300 | + return ret; |
|---|
| 299 | 301 | |
|---|
| 300 | | - return 0; |
|---|
| 301 | | - |
|---|
| 302 | | -error_cleanup_buffer_trigger: |
|---|
| 303 | | - adis_cleanup_buffer_and_trigger(st, indio_dev); |
|---|
| 304 | | - return ret; |
|---|
| 305 | | -} |
|---|
| 306 | | - |
|---|
| 307 | | -static int adis16209_remove(struct spi_device *spi) |
|---|
| 308 | | -{ |
|---|
| 309 | | - struct iio_dev *indio_dev = spi_get_drvdata(spi); |
|---|
| 310 | | - struct adis *st = iio_priv(indio_dev); |
|---|
| 311 | | - |
|---|
| 312 | | - iio_device_unregister(indio_dev); |
|---|
| 313 | | - adis_cleanup_buffer_and_trigger(st, indio_dev); |
|---|
| 314 | | - |
|---|
| 315 | | - return 0; |
|---|
| 302 | + return devm_iio_device_register(&spi->dev, indio_dev); |
|---|
| 316 | 303 | } |
|---|
| 317 | 304 | |
|---|
| 318 | 305 | static struct spi_driver adis16209_driver = { |
|---|
| .. | .. |
|---|
| 320 | 307 | .name = "adis16209", |
|---|
| 321 | 308 | }, |
|---|
| 322 | 309 | .probe = adis16209_probe, |
|---|
| 323 | | - .remove = adis16209_remove, |
|---|
| 324 | 310 | }; |
|---|
| 325 | 311 | module_spi_driver(adis16209_driver); |
|---|
| 326 | 312 | |
|---|
| .. | .. |
|---|
| 328 | 314 | MODULE_DESCRIPTION("Analog Devices ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer"); |
|---|
| 329 | 315 | MODULE_LICENSE("GPL v2"); |
|---|
| 330 | 316 | MODULE_ALIAS("spi:adis16209"); |
|---|
| 317 | +MODULE_IMPORT_NS(IIO_ADISLIB); |
|---|