| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * ADIS16260/ADIS16265 Programmable Digital Gyroscope Sensor Driver |
|---|
| 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/interrupt.h> |
|---|
| .. | .. |
|---|
| 294 | 293 | addr = adis16260_addresses[chan->scan_index][1]; |
|---|
| 295 | 294 | return adis_write_reg_16(adis, addr, val); |
|---|
| 296 | 295 | case IIO_CHAN_INFO_SAMP_FREQ: |
|---|
| 297 | | - mutex_lock(&indio_dev->mlock); |
|---|
| 296 | + mutex_lock(&adis->state_lock); |
|---|
| 298 | 297 | if (spi_get_device_id(adis->spi)->driver_data) |
|---|
| 299 | 298 | t = 256 / val; |
|---|
| 300 | 299 | else |
|---|
| .. | .. |
|---|
| 309 | 308 | adis->spi->max_speed_hz = ADIS16260_SPI_SLOW; |
|---|
| 310 | 309 | else |
|---|
| 311 | 310 | adis->spi->max_speed_hz = ADIS16260_SPI_FAST; |
|---|
| 312 | | - ret = adis_write_reg_8(adis, ADIS16260_SMPL_PRD, t); |
|---|
| 311 | + ret = __adis_write_reg_8(adis, ADIS16260_SMPL_PRD, t); |
|---|
| 313 | 312 | |
|---|
| 314 | | - mutex_unlock(&indio_dev->mlock); |
|---|
| 313 | + mutex_unlock(&adis->state_lock); |
|---|
| 315 | 314 | return ret; |
|---|
| 316 | 315 | } |
|---|
| 317 | 316 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 333 | 332 | [ADIS16260_DIAG_STAT_POWER_LOW_BIT] = "Power supply below 4.75", |
|---|
| 334 | 333 | }; |
|---|
| 335 | 334 | |
|---|
| 335 | +static const struct adis_timeout adis16260_timeouts = { |
|---|
| 336 | + .reset_ms = ADIS16260_STARTUP_DELAY, |
|---|
| 337 | + .sw_reset_ms = ADIS16260_STARTUP_DELAY, |
|---|
| 338 | + .self_test_ms = ADIS16260_STARTUP_DELAY, |
|---|
| 339 | +}; |
|---|
| 340 | + |
|---|
| 336 | 341 | static const struct adis_data adis16260_data = { |
|---|
| 337 | 342 | .write_delay = 30, |
|---|
| 338 | 343 | .read_delay = 30, |
|---|
| .. | .. |
|---|
| 341 | 346 | .diag_stat_reg = ADIS16260_DIAG_STAT, |
|---|
| 342 | 347 | |
|---|
| 343 | 348 | .self_test_mask = ADIS16260_MSC_CTRL_MEM_TEST, |
|---|
| 344 | | - .startup_delay = ADIS16260_STARTUP_DELAY, |
|---|
| 349 | + .self_test_reg = ADIS16260_MSC_CTRL, |
|---|
| 350 | + .timeouts = &adis16260_timeouts, |
|---|
| 345 | 351 | |
|---|
| 346 | 352 | .status_error_msgs = adis1620_status_error_msgs, |
|---|
| 347 | 353 | .status_error_mask = BIT(ADIS16260_DIAG_STAT_FLASH_CHK_BIT) | |
|---|
| .. | .. |
|---|
| 352 | 358 | BIT(ADIS16260_DIAG_STAT_POWER_HIGH_BIT) | |
|---|
| 353 | 359 | BIT(ADIS16260_DIAG_STAT_POWER_LOW_BIT), |
|---|
| 354 | 360 | }; |
|---|
| 361 | + |
|---|
| 362 | +static void adis16260_stop(void *data) |
|---|
| 363 | +{ |
|---|
| 364 | + adis16260_stop_device(data); |
|---|
| 365 | +} |
|---|
| 355 | 366 | |
|---|
| 356 | 367 | static int adis16260_probe(struct spi_device *spi) |
|---|
| 357 | 368 | { |
|---|
| .. | .. |
|---|
| 375 | 386 | adis16260->info = &adis16260_chip_info_table[id->driver_data]; |
|---|
| 376 | 387 | |
|---|
| 377 | 388 | indio_dev->name = id->name; |
|---|
| 378 | | - indio_dev->dev.parent = &spi->dev; |
|---|
| 379 | 389 | indio_dev->info = &adis16260_info; |
|---|
| 380 | 390 | indio_dev->channels = adis16260->info->channels; |
|---|
| 381 | 391 | indio_dev->num_channels = adis16260->info->num_channels; |
|---|
| .. | .. |
|---|
| 385 | 395 | if (ret) |
|---|
| 386 | 396 | return ret; |
|---|
| 387 | 397 | |
|---|
| 388 | | - ret = adis_setup_buffer_and_trigger(&adis16260->adis, indio_dev, NULL); |
|---|
| 398 | + ret = devm_adis_setup_buffer_and_trigger(&adis16260->adis, indio_dev, NULL); |
|---|
| 389 | 399 | if (ret) |
|---|
| 390 | 400 | return ret; |
|---|
| 391 | 401 | |
|---|
| 392 | 402 | /* Get the device into a sane initial state */ |
|---|
| 393 | 403 | ret = adis_initial_startup(&adis16260->adis); |
|---|
| 394 | 404 | if (ret) |
|---|
| 395 | | - goto error_cleanup_buffer_trigger; |
|---|
| 396 | | - ret = iio_device_register(indio_dev); |
|---|
| 405 | + return ret; |
|---|
| 406 | + |
|---|
| 407 | + ret = devm_add_action_or_reset(&spi->dev, adis16260_stop, indio_dev); |
|---|
| 397 | 408 | if (ret) |
|---|
| 398 | | - goto error_cleanup_buffer_trigger; |
|---|
| 409 | + return ret; |
|---|
| 399 | 410 | |
|---|
| 400 | | - return 0; |
|---|
| 401 | | - |
|---|
| 402 | | -error_cleanup_buffer_trigger: |
|---|
| 403 | | - adis_cleanup_buffer_and_trigger(&adis16260->adis, indio_dev); |
|---|
| 404 | | - return ret; |
|---|
| 405 | | -} |
|---|
| 406 | | - |
|---|
| 407 | | -static int adis16260_remove(struct spi_device *spi) |
|---|
| 408 | | -{ |
|---|
| 409 | | - struct iio_dev *indio_dev = spi_get_drvdata(spi); |
|---|
| 410 | | - struct adis16260 *adis16260 = iio_priv(indio_dev); |
|---|
| 411 | | - |
|---|
| 412 | | - iio_device_unregister(indio_dev); |
|---|
| 413 | | - adis16260_stop_device(indio_dev); |
|---|
| 414 | | - adis_cleanup_buffer_and_trigger(&adis16260->adis, indio_dev); |
|---|
| 415 | | - |
|---|
| 416 | | - return 0; |
|---|
| 411 | + return devm_iio_device_register(&spi->dev, indio_dev); |
|---|
| 417 | 412 | } |
|---|
| 418 | 413 | |
|---|
| 419 | 414 | /* |
|---|
| .. | .. |
|---|
| 436 | 431 | .name = "adis16260", |
|---|
| 437 | 432 | }, |
|---|
| 438 | 433 | .probe = adis16260_probe, |
|---|
| 439 | | - .remove = adis16260_remove, |
|---|
| 440 | 434 | .id_table = adis16260_id, |
|---|
| 441 | 435 | }; |
|---|
| 442 | 436 | module_spi_driver(adis16260_driver); |
|---|
| .. | .. |
|---|
| 444 | 438 | MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); |
|---|
| 445 | 439 | MODULE_DESCRIPTION("Analog Devices ADIS16260/5 Digital Gyroscope Sensor"); |
|---|
| 446 | 440 | MODULE_LICENSE("GPL v2"); |
|---|
| 441 | +MODULE_IMPORT_NS(IIO_ADISLIB); |
|---|