.. | .. |
---|
| 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> |
---|
.. | .. |
---|
18 | 17 | #include <linux/iio/common/st_sensors_spi.h> |
---|
19 | 18 | #include "st_gyro.h" |
---|
20 | 19 | |
---|
21 | | -#ifdef CONFIG_OF |
---|
22 | 20 | /* |
---|
23 | 21 | * For new single-chip sensors use <device_name> as compatible string. |
---|
24 | 22 | * For old single-chip devices keep <device_name>-gyro to maintain |
---|
.. | .. |
---|
64 | 62 | {}, |
---|
65 | 63 | }; |
---|
66 | 64 | MODULE_DEVICE_TABLE(of, st_gyro_of_match); |
---|
67 | | -#else |
---|
68 | | -#define st_gyro_of_match NULL |
---|
69 | | -#endif |
---|
70 | 65 | |
---|
71 | 66 | static int st_gyro_spi_probe(struct spi_device *spi) |
---|
72 | 67 | { |
---|
73 | | - struct iio_dev *indio_dev; |
---|
| 68 | + const struct st_sensor_settings *settings; |
---|
74 | 69 | struct st_sensor_data *gdata; |
---|
| 70 | + struct iio_dev *indio_dev; |
---|
75 | 71 | int err; |
---|
| 72 | + |
---|
| 73 | + st_sensors_dev_name_probe(&spi->dev, spi->modalias, sizeof(spi->modalias)); |
---|
| 74 | + |
---|
| 75 | + settings = st_gyro_get_settings(spi->modalias); |
---|
| 76 | + if (!settings) { |
---|
| 77 | + dev_err(&spi->dev, "device name %s not recognized.\n", |
---|
| 78 | + spi->modalias); |
---|
| 79 | + return -ENODEV; |
---|
| 80 | + } |
---|
76 | 81 | |
---|
77 | 82 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*gdata)); |
---|
78 | 83 | if (!indio_dev) |
---|
79 | 84 | return -ENOMEM; |
---|
80 | 85 | |
---|
81 | 86 | gdata = iio_priv(indio_dev); |
---|
| 87 | + gdata->sensor_settings = (struct st_sensor_settings *)settings; |
---|
82 | 88 | |
---|
83 | | - st_sensors_of_name_probe(&spi->dev, st_gyro_of_match, |
---|
84 | | - spi->modalias, sizeof(spi->modalias)); |
---|
85 | | - st_sensors_spi_configure(indio_dev, spi, gdata); |
---|
86 | | - |
---|
87 | | - err = st_gyro_common_probe(indio_dev); |
---|
| 89 | + err = st_sensors_spi_configure(indio_dev, spi); |
---|
88 | 90 | if (err < 0) |
---|
89 | 91 | return err; |
---|
90 | 92 | |
---|
| 93 | + err = st_sensors_power_enable(indio_dev); |
---|
| 94 | + if (err) |
---|
| 95 | + return err; |
---|
| 96 | + |
---|
| 97 | + err = st_gyro_common_probe(indio_dev); |
---|
| 98 | + if (err < 0) |
---|
| 99 | + goto st_gyro_power_off; |
---|
| 100 | + |
---|
91 | 101 | return 0; |
---|
| 102 | + |
---|
| 103 | +st_gyro_power_off: |
---|
| 104 | + st_sensors_power_disable(indio_dev); |
---|
| 105 | + |
---|
| 106 | + return err; |
---|
92 | 107 | } |
---|
93 | 108 | |
---|
94 | 109 | static int st_gyro_spi_remove(struct spi_device *spi) |
---|
95 | 110 | { |
---|
96 | | - st_gyro_common_remove(spi_get_drvdata(spi)); |
---|
| 111 | + struct iio_dev *indio_dev = spi_get_drvdata(spi); |
---|
| 112 | + |
---|
| 113 | + st_gyro_common_remove(indio_dev); |
---|
| 114 | + |
---|
| 115 | + st_sensors_power_disable(indio_dev); |
---|
97 | 116 | |
---|
98 | 117 | return 0; |
---|
99 | 118 | } |
---|
.. | .. |
---|
115 | 134 | static struct spi_driver st_gyro_driver = { |
---|
116 | 135 | .driver = { |
---|
117 | 136 | .name = "st-gyro-spi", |
---|
118 | | - .of_match_table = of_match_ptr(st_gyro_of_match), |
---|
| 137 | + .of_match_table = st_gyro_of_match, |
---|
119 | 138 | }, |
---|
120 | 139 | .probe = st_gyro_spi_probe, |
---|
121 | 140 | .remove = st_gyro_spi_remove, |
---|