/* SPDX-License-Identifier: GPL-2.0-only */ /* * STMicroelectronics st_lsm6dsx sensor driver * * Copyright 2016 STMicroelectronics Inc. * * Lorenzo Bianconi <[email protected]> * Denis Ciocca <[email protected]> */ #ifndef ST_LSM6DSX_H #define ST_LSM6DSX_H #include <linux/device.h> #include <linux/iio/iio.h> #include <linux/regulator/consumer.h> #define ST_LSM6DS3_DEV_NAME … #define ST_LSM6DS3H_DEV_NAME … #define ST_LSM6DSL_DEV_NAME … #define ST_LSM6DSM_DEV_NAME … #define ST_ISM330DLC_DEV_NAME … #define ST_LSM6DSO_DEV_NAME … #define ST_ASM330LHH_DEV_NAME … #define ST_LSM6DSOX_DEV_NAME … #define ST_LSM6DSR_DEV_NAME … #define ST_LSM6DS3TRC_DEV_NAME … #define ST_ISM330DHCX_DEV_NAME … #define ST_LSM9DS1_DEV_NAME … #define ST_LSM6DS0_DEV_NAME … #define ST_LSM6DSRX_DEV_NAME … #define ST_LSM6DST_DEV_NAME … #define ST_LSM6DSOP_DEV_NAME … #define ST_ASM330LHHX_DEV_NAME … #define ST_LSM6DSTX_DEV_NAME … #define ST_LSM6DSV_DEV_NAME … #define ST_LSM6DSV16X_DEV_NAME … #define ST_LSM6DSO16IS_DEV_NAME … #define ST_ISM330IS_DEV_NAME … #define ST_ASM330LHB_DEV_NAME … #define ST_ASM330LHHXG1_DEV_NAME … enum st_lsm6dsx_hw_id { … }; #define ST_LSM6DSX_BUFF_SIZE … #define ST_LSM6DSX_CHAN_SIZE … #define ST_LSM6DSX_SAMPLE_SIZE … #define ST_LSM6DSX_TAG_SIZE … #define ST_LSM6DSX_TAGGED_SAMPLE_SIZE … #define ST_LSM6DSX_MAX_WORD_LEN … #define ST_LSM6DSX_MAX_TAGGED_WORD_LEN … #define ST_LSM6DSX_SHIFT_VAL(val, mask) … #define ST_LSM6DSX_CHANNEL_ACC(chan_type, addr, mod, scan_idx) … #define ST_LSM6DSX_CHANNEL(chan_type, addr, mod, scan_idx) … struct st_lsm6dsx_reg { … }; struct st_lsm6dsx_sensor; struct st_lsm6dsx_hw; struct st_lsm6dsx_odr { … }; #define ST_LSM6DSX_ODR_LIST_SIZE … struct st_lsm6dsx_odr_table_entry { … }; struct st_lsm6dsx_samples_to_discard { … }; struct st_lsm6dsx_fs { … }; #define ST_LSM6DSX_FS_LIST_SIZE … struct st_lsm6dsx_fs_table_entry { … }; /** * struct st_lsm6dsx_fifo_ops - ST IMU FIFO settings * @update_fifo: Update FIFO configuration callback. * @read_fifo: Read FIFO callback. * @fifo_th: FIFO threshold register info (addr + mask). * @fifo_diff: FIFO diff status register info (addr + mask). * @max_size: Sensor max fifo length in FIFO words. * @th_wl: FIFO threshold word length. */ struct st_lsm6dsx_fifo_ops { … }; /** * struct st_lsm6dsx_hw_ts_settings - ST IMU hw timer settings * @timer_en: Hw timer enable register info (addr + mask). * @hr_timer: Hw timer resolution register info (addr + mask). * @fifo_en: Hw timer FIFO enable register info (addr + mask). * @decimator: Hw timer FIFO decimator register info (addr + mask). * @freq_fine: Difference in % of ODR with respect to the typical. */ struct st_lsm6dsx_hw_ts_settings { … }; /** * struct st_lsm6dsx_shub_settings - ST IMU hw i2c controller settings * @page_mux: register page mux info (addr + mask). * @master_en: master config register info (addr + mask). * @pullup_en: i2c controller pull-up register info (addr + mask). * @aux_sens: aux sensor register info (addr + mask). * @wr_once: write_once register info (addr + mask). * @emb_func: embedded function register info (addr + mask). * @num_ext_dev: max number of slave devices. * @shub_out: sensor hub first output register info. * @slv0_addr: slave0 address in secondary page. * @dw_slv0_addr: slave0 write register address in secondary page. * @batch_en: Enable/disable FIFO batching. * @pause: controller pause value. */ struct st_lsm6dsx_shub_settings { … }; struct st_lsm6dsx_event_settings { … }; enum st_lsm6dsx_ext_sensor_id { … }; /** * struct st_lsm6dsx_ext_dev_settings - i2c controller slave settings * @i2c_addr: I2c slave address list. * @wai: Wai address info. * @id: external sensor id. * @odr_table: Output data rate of the sensor [Hz]. * @fs_table: Configured sensor sensitivity table depending on full scale. * @temp_comp: Temperature compensation register info (addr + mask). * @pwr_table: Power on register info (addr + mask). * @off_canc: Offset cancellation register info (addr + mask). * @bdu: Block data update register info (addr + mask). * @out: Output register info. */ struct st_lsm6dsx_ext_dev_settings { … }; /** * struct st_lsm6dsx_settings - ST IMU sensor settings * @reset: register address for reset. * @boot: register address for boot. * @bdu: register address for Block Data Update. * @id: List of hw id/device name supported by the driver configuration. * @channels: IIO channels supported by the device. * @irq_config: interrupts related registers. * @drdy_mask: register info for data-ready mask (addr + mask). * @odr_table: Hw sensors odr table (Hz + val). * @samples_to_discard: Number of samples to discard for filters settling time. * @fs_table: Hw sensors gain table (gain + val). * @decimator: List of decimator register info (addr + mask). * @batch: List of FIFO batching register info (addr + mask). * @fifo_ops: Sensor hw FIFO parameters. * @ts_settings: Hw timer related settings. * @shub_settings: i2c controller related settings. */ struct st_lsm6dsx_settings { … }; enum st_lsm6dsx_sensor_id { … }; enum st_lsm6dsx_fifo_mode { … }; /** * struct st_lsm6dsx_sensor - ST IMU sensor instance * @name: Sensor name. * @id: Sensor identifier. * @hw: Pointer to instance of struct st_lsm6dsx_hw. * @gain: Configured sensor sensitivity. * @odr: Output data rate of the sensor [Hz]. * @samples_to_discard: Number of samples to discard for filters settling time. * @watermark: Sensor watermark level. * @decimator: Sensor decimation factor. * @sip: Number of samples in a given pattern. * @ts_ref: Sensor timestamp reference for hw one. * @ext_info: Sensor settings if it is connected to i2c controller */ struct st_lsm6dsx_sensor { … }; /** * struct st_lsm6dsx_hw - ST IMU MEMS hw instance * @dev: Pointer to instance of struct device (I2C or SPI). * @regmap: Register map of the device. * @irq: Device interrupt line (I2C or SPI). * @fifo_lock: Mutex to prevent concurrent access to the hw FIFO. * @conf_lock: Mutex to prevent concurrent FIFO configuration update. * @page_lock: Mutex to prevent concurrent memory page configuration. * @suspend_mask: Suspended sensor bitmask. * @enable_mask: Enabled sensor bitmask. * @fifo_mask: Enabled hw FIFO bitmask. * @ts_gain: Hw timestamp rate after internal calibration. * @ts_sip: Total number of timestamp samples in a given pattern. * @sip: Total number of samples (acc/gyro/ts) in a given pattern. * @buff: Device read buffer. * @irq_routing: pointer to interrupt routing configuration. * @event_threshold: wakeup event threshold. * @enable_event: enabled event bitmask. * @iio_devs: Pointers to acc/gyro iio_dev instances. * @settings: Pointer to the specific sensor settings in use. * @orientation: sensor chip orientation relative to main hardware. * @scan: Temporary buffers used to align data before iio_push_to_buffers() */ struct st_lsm6dsx_hw { … }; static __maybe_unused const struct iio_event_spec st_lsm6dsx_event = …; static __maybe_unused const unsigned long st_lsm6dsx_available_scan_masks[] = …; extern const struct dev_pm_ops st_lsm6dsx_pm_ops; int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id, struct regmap *regmap); int st_lsm6dsx_sensor_set_enable(struct st_lsm6dsx_sensor *sensor, bool enable); int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw); int st_lsm6dsx_set_watermark(struct iio_dev *iio_dev, unsigned int val); int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark); int st_lsm6dsx_update_fifo(struct st_lsm6dsx_sensor *sensor, bool enable); int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw); int st_lsm6dsx_resume_fifo(struct st_lsm6dsx_hw *hw); int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw); int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw); int st_lsm6dsx_check_odr(struct st_lsm6dsx_sensor *sensor, u32 odr, u8 *val); int st_lsm6dsx_shub_probe(struct st_lsm6dsx_hw *hw, const char *name); int st_lsm6dsx_shub_set_enable(struct st_lsm6dsx_sensor *sensor, bool enable); int st_lsm6dsx_shub_read_output(struct st_lsm6dsx_hw *hw, u8 *data, int len); int st_lsm6dsx_set_page(struct st_lsm6dsx_hw *hw, bool enable); static inline int st_lsm6dsx_update_bits_locked(struct st_lsm6dsx_hw *hw, unsigned int addr, unsigned int mask, unsigned int val) { … } static inline int st_lsm6dsx_read_locked(struct st_lsm6dsx_hw *hw, unsigned int addr, void *val, unsigned int len) { … } static inline int st_lsm6dsx_write_locked(struct st_lsm6dsx_hw *hw, unsigned int addr, unsigned int val) { … } static inline const struct iio_mount_matrix * st_lsm6dsx_get_mount_matrix(const struct iio_dev *iio_dev, const struct iio_chan_spec *chan) { … } static inline int st_lsm6dsx_device_set_enable(struct st_lsm6dsx_sensor *sensor, bool enable) { … } static const struct iio_chan_spec_ext_info __maybe_unused st_lsm6dsx_ext_info[] = …; #endif /* ST_LSM6DSX_H */