hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/include/linux/iio/common/st_sensors.h
....@@ -1,11 +1,10 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * STMicroelectronics sensors library 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 #ifndef ST_SENSORS_H
....@@ -17,11 +16,16 @@
1716 #include <linux/iio/trigger.h>
1817 #include <linux/bitops.h>
1918 #include <linux/regulator/consumer.h>
19
+#include <linux/regmap.h>
2020
2121 #include <linux/platform_data/st_sensors_pdata.h>
2222
23
-#define ST_SENSORS_TX_MAX_LENGTH 2
24
-#define ST_SENSORS_RX_MAX_LENGTH 6
23
+/*
24
+ * Buffer size max case: 2bytes per channel, 3 channels in total +
25
+ * 8bytes timestamp channel (s64)
26
+ */
27
+#define ST_SENSORS_MAX_BUFFER_SIZE (ALIGN(2 * 3, sizeof(s64)) + \
28
+ sizeof(s64))
2529
2630 #define ST_SENSORS_ODR_LIST_MAX 10
2731 #define ST_SENSORS_FULLSCALE_AVL_MAX 10
....@@ -40,7 +44,7 @@
4044 #define ST_SENSORS_DEFAULT_STAT_ADDR 0x27
4145
4246 #define ST_SENSORS_MAX_NAME 17
43
-#define ST_SENSORS_MAX_4WAI 7
47
+#define ST_SENSORS_MAX_4WAI 8
4448
4549 #define ST_SENSORS_LSM_CHANNELS(device_type, mask, index, mod, \
4650 ch2, s, endian, rbits, sbits, addr) \
....@@ -171,36 +175,6 @@
171175 };
172176
173177 /**
174
- * struct st_sensor_transfer_buffer - ST sensor device I/O buffer
175
- * @buf_lock: Mutex to protect rx and tx buffers.
176
- * @tx_buf: Buffer used by SPI transfer function to send data to the sensors.
177
- * This buffer is used to avoid DMA not-aligned issue.
178
- * @rx_buf: Buffer used by SPI transfer to receive data from sensors.
179
- * This buffer is used to avoid DMA not-aligned issue.
180
- */
181
-struct st_sensor_transfer_buffer {
182
- struct mutex buf_lock;
183
- u8 rx_buf[ST_SENSORS_RX_MAX_LENGTH];
184
- u8 tx_buf[ST_SENSORS_TX_MAX_LENGTH] ____cacheline_aligned;
185
-};
186
-
187
-/**
188
- * struct st_sensor_transfer_function - ST sensor device I/O function
189
- * @read_byte: Function used to read one byte.
190
- * @write_byte: Function used to write one byte.
191
- * @read_multiple_byte: Function used to read multiple byte.
192
- */
193
-struct st_sensor_transfer_function {
194
- int (*read_byte) (struct st_sensor_transfer_buffer *tb,
195
- struct device *dev, u8 reg_addr, u8 *res_byte);
196
- int (*write_byte) (struct st_sensor_transfer_buffer *tb,
197
- struct device *dev, u8 reg_addr, u8 data);
198
- int (*read_multiple_byte) (struct st_sensor_transfer_buffer *tb,
199
- struct device *dev, u8 reg_addr, int len, u8 *data,
200
- bool multiread_bit);
201
-};
202
-
203
-/**
204178 * struct st_sensor_settings - ST specific sensor settings
205179 * @wai: Contents of WhoAmI register.
206180 * @wai_addr: The address of WhoAmI register.
....@@ -243,47 +217,45 @@
243217 * @current_fullscale: Maximum range of measure by the sensor.
244218 * @vdd: Pointer to sensor's Vdd power supply
245219 * @vdd_io: Pointer to sensor's Vdd-IO power supply
220
+ * @regmap: Pointer to specific sensor regmap configuration.
246221 * @enabled: Status of the sensor (false->off, true->on).
247
- * @multiread_bit: Use or not particular bit for [I2C/SPI] multiread.
248
- * @buffer_data: Data used by buffer part.
249222 * @odr: Output data rate of the sensor [Hz].
250223 * num_data_channels: Number of data channels used in buffer.
251224 * @drdy_int_pin: Redirect DRDY on pin 1 (1) or pin 2 (2).
252225 * @int_pin_open_drain: Set the interrupt/DRDY to open drain.
253
- * @get_irq_data_ready: Function to get the IRQ used for data ready signal.
254
- * @tf: Transfer function structure used by I/O operations.
255
- * @tb: Transfer buffers and mutex used by I/O operations.
226
+ * @irq: the IRQ number.
256227 * @edge_irq: the IRQ triggers on edges and need special handling.
257228 * @hw_irq_trigger: if we're using the hardware interrupt on the sensor.
258229 * @hw_timestamp: Latest timestamp from the interrupt handler, when in use.
230
+ * @buffer_data: Data used by buffer part.
231
+ * @odr_lock: Local lock for preventing concurrent ODR accesses/changes
259232 */
260233 struct st_sensor_data {
261234 struct device *dev;
262235 struct iio_trigger *trig;
236
+ struct iio_mount_matrix *mount_matrix;
263237 struct st_sensor_settings *sensor_settings;
264238 struct st_sensor_fullscale_avl *current_fullscale;
265239 struct regulator *vdd;
266240 struct regulator *vdd_io;
241
+ struct regmap *regmap;
267242
268243 bool enabled;
269
- bool multiread_bit;
270
-
271
- char *buffer_data;
272244
273245 unsigned int odr;
274246 unsigned int num_data_channels;
275247
276248 u8 drdy_int_pin;
277249 bool int_pin_open_drain;
278
-
279
- unsigned int (*get_irq_data_ready) (struct iio_dev *indio_dev);
280
-
281
- const struct st_sensor_transfer_function *tf;
282
- struct st_sensor_transfer_buffer tb;
250
+ int irq;
283251
284252 bool edge_irq;
285253 bool hw_irq_trigger;
286254 s64 hw_timestamp;
255
+
256
+ char buffer_data[ST_SENSORS_MAX_BUFFER_SIZE] ____cacheline_aligned;
257
+
258
+ struct mutex odr_lock;
287259 };
288260
289261 #ifdef CONFIG_IIO_BUFFER
....@@ -334,8 +306,11 @@
334306 int st_sensors_read_info_raw(struct iio_dev *indio_dev,
335307 struct iio_chan_spec const *ch, int *val);
336308
337
-int st_sensors_check_device_support(struct iio_dev *indio_dev,
338
- int num_sensors_list, const struct st_sensor_settings *sensor_settings);
309
+int st_sensors_get_settings_index(const char *name,
310
+ const struct st_sensor_settings *list,
311
+ const int list_length);
312
+
313
+int st_sensors_verify_id(struct iio_dev *indio_dev);
339314
340315 ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev,
341316 struct device_attribute *attr, char *buf);
....@@ -343,16 +318,6 @@
343318 ssize_t st_sensors_sysfs_scale_avail(struct device *dev,
344319 struct device_attribute *attr, char *buf);
345320
346
-#ifdef CONFIG_OF
347
-void st_sensors_of_name_probe(struct device *dev,
348
- const struct of_device_id *match,
349
- char *name, int len);
350
-#else
351
-static inline void st_sensors_of_name_probe(struct device *dev,
352
- const struct of_device_id *match,
353
- char *name, int len)
354
-{
355
-}
356
-#endif
321
+void st_sensors_dev_name_probe(struct device *dev, char *name, int len);
357322
358323 #endif /* ST_SENSORS_H */