#include <linux/delay.h>
#include <linux/device.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/mutex.h>
#include <linux/property.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include <linux/slab.h>
#include <linux/string_choices.h>
#include <linux/units.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include <linux/iio/trigger.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h>
#include "kionix-kx022a.h"
#define KX022A_FIFO_LENGTH …
#define KX022A_FIFO_FULL_VALUE …
#define KX022A_SOFT_RESET_WAIT_TIME_US …
#define KX022A_SOFT_RESET_TOTAL_WAIT_TIME_US …
#define KX022A_FIFO_SAMPLES_SIZE_BYTES …
#define KX022A_FIFO_MAX_BYTES …
enum { … };
static const struct regmap_range kx022a_volatile_ranges[] = …;
static const struct regmap_access_table kx022a_volatile_regs = …;
static const struct regmap_range kx022a_precious_ranges[] = …;
static const struct regmap_access_table kx022a_precious_regs = …;
static const struct regmap_range kx022a_read_only_ranges[] = …;
static const struct regmap_access_table kx022a_ro_regs = …;
static const struct regmap_range kx022a_write_only_ranges[] = …;
static const struct regmap_access_table kx022a_wo_regs = …;
static const struct regmap_range kx022a_noinc_read_ranges[] = …;
static const struct regmap_access_table kx022a_nir_regs = …;
static const struct regmap_config kx022a_regmap_config = …;
static const struct regmap_range kx132_volatile_ranges[] = …;
static const struct regmap_access_table kx132_volatile_regs = …;
static const struct regmap_range kx132_precious_ranges[] = …;
static const struct regmap_access_table kx132_precious_regs = …;
static const struct regmap_range kx132_read_only_ranges[] = …;
static const struct regmap_access_table kx132_ro_regs = …;
static const struct regmap_range kx132_write_only_ranges[] = …;
static const struct regmap_access_table kx132_wo_regs = …;
static const struct regmap_range kx132_noinc_read_ranges[] = …;
static const struct regmap_access_table kx132_nir_regs = …;
static const struct regmap_config kx132_regmap_config = …;
struct kx022a_data { … };
static const struct iio_mount_matrix *
kx022a_get_mount_matrix(const struct iio_dev *idev,
const struct iio_chan_spec *chan)
{ … }
enum { … };
static const unsigned long kx022a_scan_masks[] = …;
static const struct iio_chan_spec_ext_info kx022a_ext_info[] = …;
#define KX022A_ACCEL_CHAN(axis, reg, index) …
static const struct iio_chan_spec kx022a_channels[] = …;
static const struct iio_chan_spec kx132_channels[] = …;
static const int kx022a_accel_samp_freq_table[][2] = …;
static const unsigned int kx022a_odrs[] = …;
static const int kx022a_scale_table[][2] = …;
static int kx022a_read_avail(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
const int **vals, int *type, int *length,
long mask)
{ … }
#define KX022A_DEFAULT_PERIOD_NS …
static void kx022a_reg2freq(unsigned int val, int *val1, int *val2)
{ … }
static void kx022a_reg2scale(unsigned int val, unsigned int *val1,
unsigned int *val2)
{ … }
static int kx022a_turn_on_off_unlocked(struct kx022a_data *data, bool on)
{ … }
static int kx022a_turn_off_lock(struct kx022a_data *data)
{ … }
static int kx022a_turn_on_unlock(struct kx022a_data *data)
{ … }
static int kx022a_write_raw_get_fmt(struct iio_dev *idev,
struct iio_chan_spec const *chan,
long mask)
{ … }
static int kx022a_write_raw(struct iio_dev *idev,
struct iio_chan_spec const *chan,
int val, int val2, long mask)
{ … }
static int kx022a_fifo_set_wmi(struct kx022a_data *data)
{ … }
static int kx022a_get_axis(struct kx022a_data *data,
struct iio_chan_spec const *chan,
int *val)
{ … }
static int kx022a_read_raw(struct iio_dev *idev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
{
struct kx022a_data *data = iio_priv(idev);
unsigned int regval;
int ret;
switch (mask) {
case IIO_CHAN_INFO_RAW:
ret = iio_device_claim_direct_mode(idev);
if (ret)
return ret;
mutex_lock(&data->mutex);
ret = kx022a_get_axis(data, chan, val);
mutex_unlock(&data->mutex);
iio_device_release_direct_mode(idev);
return ret;
case IIO_CHAN_INFO_SAMP_FREQ:
ret = regmap_read(data->regmap, data->chip_info->odcntl, ®val);
if (ret)
return ret;
if ((regval & KX022A_MASK_ODR) >
ARRAY_SIZE(kx022a_accel_samp_freq_table)) {
dev_err(data->dev, "Invalid ODR\n");
return -EINVAL;
}
kx022a_reg2freq(regval, val, val2);
return IIO_VAL_INT_PLUS_MICRO;
case IIO_CHAN_INFO_SCALE:
ret = regmap_read(data->regmap, data->chip_info->cntl, ®val);
if (ret < 0)
return ret;
kx022a_reg2scale(regval, val, val2);
return IIO_VAL_INT_PLUS_NANO;
}
return -EINVAL;
};
static int kx022a_set_watermark(struct iio_dev *idev, unsigned int val)
{ … }
static ssize_t hwfifo_enabled_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{ … }
static ssize_t hwfifo_watermark_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{ … }
static IIO_DEVICE_ATTR_RO(hwfifo_enabled, 0);
static IIO_DEVICE_ATTR_RO(hwfifo_watermark, 0);
static const struct iio_dev_attr *kx022a_fifo_attributes[] = …;
static int kx022a_drop_fifo_contents(struct kx022a_data *data)
{ … }
static int kx022a_get_fifo_bytes_available(struct kx022a_data *data)
{ … }
static int kx132_get_fifo_bytes_available(struct kx022a_data *data)
{ … }
static int __kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples,
bool irq)
{ … }
static int kx022a_fifo_flush(struct iio_dev *idev, unsigned int samples)
{ … }
static const struct iio_info kx022a_info = …;
static int kx022a_set_drdy_irq(struct kx022a_data *data, bool en)
{ … }
static int kx022a_prepare_irq_pin(struct kx022a_data *data)
{ … }
static int kx022a_fifo_disable(struct kx022a_data *data)
{ … }
static int kx022a_buffer_predisable(struct iio_dev *idev)
{ … }
static int kx022a_fifo_enable(struct kx022a_data *data)
{ … }
static int kx022a_buffer_postenable(struct iio_dev *idev)
{ … }
static const struct iio_buffer_setup_ops kx022a_buffer_ops = …;
static irqreturn_t kx022a_trigger_handler(int irq, void *p)
{ … }
static irqreturn_t kx022a_irq_handler(int irq, void *private)
{ … }
static irqreturn_t kx022a_irq_thread_handler(int irq, void *private)
{ … }
static int kx022a_trigger_set_state(struct iio_trigger *trig,
bool state)
{ … }
static const struct iio_trigger_ops kx022a_trigger_ops = …;
static int kx022a_chip_init(struct kx022a_data *data)
{ … }
const struct kx022a_chip_info kx022a_chip_info = …;
EXPORT_SYMBOL_NS_GPL(…);
const struct kx022a_chip_info kx132_chip_info = …;
EXPORT_SYMBOL_NS_GPL(…);
const struct kx022a_chip_info kx132acr_chip_info = …;
EXPORT_SYMBOL_NS_GPL(…);
int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chip_info)
{ … }
EXPORT_SYMBOL_NS_GPL(…);
MODULE_DESCRIPTION(…) …;
MODULE_AUTHOR(…) …;
MODULE_LICENSE(…) …;