| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * STMicroelectronics sensors library 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 | #ifndef ST_SENSORS_H |
|---|
| .. | .. |
|---|
| 17 | 16 | #include <linux/iio/trigger.h> |
|---|
| 18 | 17 | #include <linux/bitops.h> |
|---|
| 19 | 18 | #include <linux/regulator/consumer.h> |
|---|
| 19 | +#include <linux/regmap.h> |
|---|
| 20 | 20 | |
|---|
| 21 | 21 | #include <linux/platform_data/st_sensors_pdata.h> |
|---|
| 22 | 22 | |
|---|
| 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)) |
|---|
| 25 | 29 | |
|---|
| 26 | 30 | #define ST_SENSORS_ODR_LIST_MAX 10 |
|---|
| 27 | 31 | #define ST_SENSORS_FULLSCALE_AVL_MAX 10 |
|---|
| .. | .. |
|---|
| 40 | 44 | #define ST_SENSORS_DEFAULT_STAT_ADDR 0x27 |
|---|
| 41 | 45 | |
|---|
| 42 | 46 | #define ST_SENSORS_MAX_NAME 17 |
|---|
| 43 | | -#define ST_SENSORS_MAX_4WAI 7 |
|---|
| 47 | +#define ST_SENSORS_MAX_4WAI 8 |
|---|
| 44 | 48 | |
|---|
| 45 | 49 | #define ST_SENSORS_LSM_CHANNELS(device_type, mask, index, mod, \ |
|---|
| 46 | 50 | ch2, s, endian, rbits, sbits, addr) \ |
|---|
| .. | .. |
|---|
| 171 | 175 | }; |
|---|
| 172 | 176 | |
|---|
| 173 | 177 | /** |
|---|
| 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 | | -/** |
|---|
| 204 | 178 | * struct st_sensor_settings - ST specific sensor settings |
|---|
| 205 | 179 | * @wai: Contents of WhoAmI register. |
|---|
| 206 | 180 | * @wai_addr: The address of WhoAmI register. |
|---|
| .. | .. |
|---|
| 243 | 217 | * @current_fullscale: Maximum range of measure by the sensor. |
|---|
| 244 | 218 | * @vdd: Pointer to sensor's Vdd power supply |
|---|
| 245 | 219 | * @vdd_io: Pointer to sensor's Vdd-IO power supply |
|---|
| 220 | + * @regmap: Pointer to specific sensor regmap configuration. |
|---|
| 246 | 221 | * @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. |
|---|
| 249 | 222 | * @odr: Output data rate of the sensor [Hz]. |
|---|
| 250 | 223 | * num_data_channels: Number of data channels used in buffer. |
|---|
| 251 | 224 | * @drdy_int_pin: Redirect DRDY on pin 1 (1) or pin 2 (2). |
|---|
| 252 | 225 | * @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. |
|---|
| 256 | 227 | * @edge_irq: the IRQ triggers on edges and need special handling. |
|---|
| 257 | 228 | * @hw_irq_trigger: if we're using the hardware interrupt on the sensor. |
|---|
| 258 | 229 | * @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 |
|---|
| 259 | 232 | */ |
|---|
| 260 | 233 | struct st_sensor_data { |
|---|
| 261 | 234 | struct device *dev; |
|---|
| 262 | 235 | struct iio_trigger *trig; |
|---|
| 236 | + struct iio_mount_matrix *mount_matrix; |
|---|
| 263 | 237 | struct st_sensor_settings *sensor_settings; |
|---|
| 264 | 238 | struct st_sensor_fullscale_avl *current_fullscale; |
|---|
| 265 | 239 | struct regulator *vdd; |
|---|
| 266 | 240 | struct regulator *vdd_io; |
|---|
| 241 | + struct regmap *regmap; |
|---|
| 267 | 242 | |
|---|
| 268 | 243 | bool enabled; |
|---|
| 269 | | - bool multiread_bit; |
|---|
| 270 | | - |
|---|
| 271 | | - char *buffer_data; |
|---|
| 272 | 244 | |
|---|
| 273 | 245 | unsigned int odr; |
|---|
| 274 | 246 | unsigned int num_data_channels; |
|---|
| 275 | 247 | |
|---|
| 276 | 248 | u8 drdy_int_pin; |
|---|
| 277 | 249 | 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; |
|---|
| 283 | 251 | |
|---|
| 284 | 252 | bool edge_irq; |
|---|
| 285 | 253 | bool hw_irq_trigger; |
|---|
| 286 | 254 | s64 hw_timestamp; |
|---|
| 255 | + |
|---|
| 256 | + char buffer_data[ST_SENSORS_MAX_BUFFER_SIZE] ____cacheline_aligned; |
|---|
| 257 | + |
|---|
| 258 | + struct mutex odr_lock; |
|---|
| 287 | 259 | }; |
|---|
| 288 | 260 | |
|---|
| 289 | 261 | #ifdef CONFIG_IIO_BUFFER |
|---|
| .. | .. |
|---|
| 334 | 306 | int st_sensors_read_info_raw(struct iio_dev *indio_dev, |
|---|
| 335 | 307 | struct iio_chan_spec const *ch, int *val); |
|---|
| 336 | 308 | |
|---|
| 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); |
|---|
| 339 | 314 | |
|---|
| 340 | 315 | ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev, |
|---|
| 341 | 316 | struct device_attribute *attr, char *buf); |
|---|
| .. | .. |
|---|
| 343 | 318 | ssize_t st_sensors_sysfs_scale_avail(struct device *dev, |
|---|
| 344 | 319 | struct device_attribute *attr, char *buf); |
|---|
| 345 | 320 | |
|---|
| 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); |
|---|
| 357 | 322 | |
|---|
| 358 | 323 | #endif /* ST_SENSORS_H */ |
|---|