hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/iio/gyro/st_gyro_core.c
....@@ -1,11 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * STMicroelectronics gyroscopes driver
34 *
45 * Copyright 2012-2013 STMicroelectronics Inc.
56 *
67 * Denis Ciocca <denis.ciocca@st.com>
7
- *
8
- * Licensed under the GPL-2.
98 */
109
1110 #include <linux/kernel.h>
....@@ -13,10 +12,8 @@
1312 #include <linux/slab.h>
1413 #include <linux/errno.h>
1514 #include <linux/types.h>
16
-#include <linux/mutex.h>
1715 #include <linux/interrupt.h>
1816 #include <linux/i2c.h>
19
-#include <linux/gpio.h>
2017 #include <linux/irq.h>
2118 #include <linux/delay.h>
2219 #include <linux/iio/iio.h>
....@@ -442,45 +439,55 @@
442439 #define ST_GYRO_TRIGGER_OPS NULL
443440 #endif
444441
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
+
445460 int st_gyro_common_probe(struct iio_dev *indio_dev)
446461 {
447462 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;
449464 int err;
450465
451466 indio_dev->modes = INDIO_DIRECT_MODE;
452467 indio_dev->info = &gyro_info;
453
- mutex_init(&gdata->tb.buf_lock);
454468
455
- err = st_sensors_power_enable(indio_dev);
456
- if (err)
469
+ err = st_sensors_verify_id(indio_dev);
470
+ if (err < 0)
457471 return err;
458472
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
-
465473 gdata->num_data_channels = ST_GYRO_NUMBER_DATA_CHANNELS;
466
- gdata->multiread_bit = gdata->sensor_settings->multi_read_bit;
467474 indio_dev->channels = gdata->sensor_settings->ch;
468475 indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
469476
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];
472478 gdata->odr = gdata->sensor_settings->odr.odr_avl[0].hz;
473479
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);
476483 if (err < 0)
477
- goto st_gyro_power_off;
484
+ return err;
478485
479486 err = st_gyro_allocate_ring(indio_dev);
480487 if (err < 0)
481
- goto st_gyro_power_off;
488
+ return err;
482489
483
- if (irq > 0) {
490
+ if (gdata->irq > 0) {
484491 err = st_sensors_allocate_trigger(indio_dev,
485492 ST_GYRO_TRIGGER_OPS);
486493 if (err < 0)
....@@ -497,13 +504,10 @@
497504 return 0;
498505
499506 st_gyro_device_register_error:
500
- if (irq > 0)
507
+ if (gdata->irq > 0)
501508 st_sensors_deallocate_trigger(indio_dev);
502509 st_gyro_probe_trigger_error:
503510 st_gyro_deallocate_ring(indio_dev);
504
-st_gyro_power_off:
505
- st_sensors_power_disable(indio_dev);
506
-
507511 return err;
508512 }
509513 EXPORT_SYMBOL(st_gyro_common_probe);
....@@ -512,10 +516,8 @@
512516 {
513517 struct st_sensor_data *gdata = iio_priv(indio_dev);
514518
515
- st_sensors_power_disable(indio_dev);
516
-
517519 iio_device_unregister(indio_dev);
518
- if (gdata->get_irq_data_ready(indio_dev) > 0)
520
+ if (gdata->irq > 0)
519521 st_sensors_deallocate_trigger(indio_dev);
520522
521523 st_gyro_deallocate_ring(indio_dev);