| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * STMicroelectronics gyroscopes driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright 2012-2013 STMicroelectronics Inc. |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * Denis Ciocca <denis.ciocca@st.com> |
|---|
| 7 | | - * |
|---|
| 8 | | - * Licensed under the GPL-2. |
|---|
| 9 | 8 | */ |
|---|
| 10 | 9 | |
|---|
| 11 | 10 | #include <linux/kernel.h> |
|---|
| .. | .. |
|---|
| 13 | 12 | #include <linux/slab.h> |
|---|
| 14 | 13 | #include <linux/errno.h> |
|---|
| 15 | 14 | #include <linux/types.h> |
|---|
| 16 | | -#include <linux/mutex.h> |
|---|
| 17 | 15 | #include <linux/interrupt.h> |
|---|
| 18 | 16 | #include <linux/i2c.h> |
|---|
| 19 | | -#include <linux/gpio.h> |
|---|
| 20 | 17 | #include <linux/irq.h> |
|---|
| 21 | 18 | #include <linux/delay.h> |
|---|
| 22 | 19 | #include <linux/iio/iio.h> |
|---|
| .. | .. |
|---|
| 442 | 439 | #define ST_GYRO_TRIGGER_OPS NULL |
|---|
| 443 | 440 | #endif |
|---|
| 444 | 441 | |
|---|
| 442 | +/* |
|---|
| 443 | + * st_gyro_get_settings() - get sensor settings from device name |
|---|
| 444 | + * @name: device name buffer reference. |
|---|
| 445 | + * |
|---|
| 446 | + * Return: valid reference on success, NULL otherwise. |
|---|
| 447 | + */ |
|---|
| 448 | +const struct st_sensor_settings *st_gyro_get_settings(const char *name) |
|---|
| 449 | +{ |
|---|
| 450 | + int index = st_sensors_get_settings_index(name, |
|---|
| 451 | + st_gyro_sensors_settings, |
|---|
| 452 | + ARRAY_SIZE(st_gyro_sensors_settings)); |
|---|
| 453 | + if (index < 0) |
|---|
| 454 | + return NULL; |
|---|
| 455 | + |
|---|
| 456 | + return &st_gyro_sensors_settings[index]; |
|---|
| 457 | +} |
|---|
| 458 | +EXPORT_SYMBOL(st_gyro_get_settings); |
|---|
| 459 | + |
|---|
| 445 | 460 | int st_gyro_common_probe(struct iio_dev *indio_dev) |
|---|
| 446 | 461 | { |
|---|
| 447 | 462 | struct st_sensor_data *gdata = iio_priv(indio_dev); |
|---|
| 448 | | - int irq = gdata->get_irq_data_ready(indio_dev); |
|---|
| 463 | + struct st_sensors_platform_data *pdata; |
|---|
| 449 | 464 | int err; |
|---|
| 450 | 465 | |
|---|
| 451 | 466 | indio_dev->modes = INDIO_DIRECT_MODE; |
|---|
| 452 | 467 | indio_dev->info = &gyro_info; |
|---|
| 453 | | - mutex_init(&gdata->tb.buf_lock); |
|---|
| 454 | 468 | |
|---|
| 455 | | - err = st_sensors_power_enable(indio_dev); |
|---|
| 456 | | - if (err) |
|---|
| 469 | + err = st_sensors_verify_id(indio_dev); |
|---|
| 470 | + if (err < 0) |
|---|
| 457 | 471 | return err; |
|---|
| 458 | 472 | |
|---|
| 459 | | - err = st_sensors_check_device_support(indio_dev, |
|---|
| 460 | | - ARRAY_SIZE(st_gyro_sensors_settings), |
|---|
| 461 | | - st_gyro_sensors_settings); |
|---|
| 462 | | - if (err < 0) |
|---|
| 463 | | - goto st_gyro_power_off; |
|---|
| 464 | | - |
|---|
| 465 | 473 | gdata->num_data_channels = ST_GYRO_NUMBER_DATA_CHANNELS; |
|---|
| 466 | | - gdata->multiread_bit = gdata->sensor_settings->multi_read_bit; |
|---|
| 467 | 474 | indio_dev->channels = gdata->sensor_settings->ch; |
|---|
| 468 | 475 | indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; |
|---|
| 469 | 476 | |
|---|
| 470 | | - gdata->current_fullscale = (struct st_sensor_fullscale_avl *) |
|---|
| 471 | | - &gdata->sensor_settings->fs.fs_avl[0]; |
|---|
| 477 | + gdata->current_fullscale = &gdata->sensor_settings->fs.fs_avl[0]; |
|---|
| 472 | 478 | gdata->odr = gdata->sensor_settings->odr.odr_avl[0].hz; |
|---|
| 473 | 479 | |
|---|
| 474 | | - err = st_sensors_init_sensor(indio_dev, |
|---|
| 475 | | - (struct st_sensors_platform_data *)&gyro_pdata); |
|---|
| 480 | + pdata = (struct st_sensors_platform_data *)&gyro_pdata; |
|---|
| 481 | + |
|---|
| 482 | + err = st_sensors_init_sensor(indio_dev, pdata); |
|---|
| 476 | 483 | if (err < 0) |
|---|
| 477 | | - goto st_gyro_power_off; |
|---|
| 484 | + return err; |
|---|
| 478 | 485 | |
|---|
| 479 | 486 | err = st_gyro_allocate_ring(indio_dev); |
|---|
| 480 | 487 | if (err < 0) |
|---|
| 481 | | - goto st_gyro_power_off; |
|---|
| 488 | + return err; |
|---|
| 482 | 489 | |
|---|
| 483 | | - if (irq > 0) { |
|---|
| 490 | + if (gdata->irq > 0) { |
|---|
| 484 | 491 | err = st_sensors_allocate_trigger(indio_dev, |
|---|
| 485 | 492 | ST_GYRO_TRIGGER_OPS); |
|---|
| 486 | 493 | if (err < 0) |
|---|
| .. | .. |
|---|
| 497 | 504 | return 0; |
|---|
| 498 | 505 | |
|---|
| 499 | 506 | st_gyro_device_register_error: |
|---|
| 500 | | - if (irq > 0) |
|---|
| 507 | + if (gdata->irq > 0) |
|---|
| 501 | 508 | st_sensors_deallocate_trigger(indio_dev); |
|---|
| 502 | 509 | st_gyro_probe_trigger_error: |
|---|
| 503 | 510 | st_gyro_deallocate_ring(indio_dev); |
|---|
| 504 | | -st_gyro_power_off: |
|---|
| 505 | | - st_sensors_power_disable(indio_dev); |
|---|
| 506 | | - |
|---|
| 507 | 511 | return err; |
|---|
| 508 | 512 | } |
|---|
| 509 | 513 | EXPORT_SYMBOL(st_gyro_common_probe); |
|---|
| .. | .. |
|---|
| 512 | 516 | { |
|---|
| 513 | 517 | struct st_sensor_data *gdata = iio_priv(indio_dev); |
|---|
| 514 | 518 | |
|---|
| 515 | | - st_sensors_power_disable(indio_dev); |
|---|
| 516 | | - |
|---|
| 517 | 519 | iio_device_unregister(indio_dev); |
|---|
| 518 | | - if (gdata->get_irq_data_ready(indio_dev) > 0) |
|---|
| 520 | + if (gdata->irq > 0) |
|---|
| 519 | 521 | st_sensors_deallocate_trigger(indio_dev); |
|---|
| 520 | 522 | |
|---|
| 521 | 523 | st_gyro_deallocate_ring(indio_dev); |
|---|