linux/drivers/iio/accel/kxcjk-1013.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * KXCJK-1013 3-axis accelerometer driver
 * Copyright (c) 2014, Intel Corporation.
 */

#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/bitops.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/acpi.h>
#include <linux/pm.h>
#include <linux/pm_runtime.h>
#include <linux/regulator/consumer.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
#include <linux/iio/buffer.h>
#include <linux/iio/trigger.h>
#include <linux/iio/events.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h>
#include <linux/iio/accel/kxcjk_1013.h>

#define KXCJK1013_DRV_NAME
#define KXCJK1013_IRQ_NAME

#define KXTF9_REG_HP_XOUT_L
#define KXTF9_REG_HP_XOUT_H
#define KXTF9_REG_HP_YOUT_L
#define KXTF9_REG_HP_YOUT_H
#define KXTF9_REG_HP_ZOUT_L
#define KXTF9_REG_HP_ZOUT_H

#define KXCJK1013_REG_XOUT_L
/*
 * From low byte X axis register, all the other addresses of Y and Z can be
 * obtained by just applying axis offset. The following axis defines are just
 * provide clarity, but not used.
 */
#define KXCJK1013_REG_XOUT_H
#define KXCJK1013_REG_YOUT_L
#define KXCJK1013_REG_YOUT_H
#define KXCJK1013_REG_ZOUT_L
#define KXCJK1013_REG_ZOUT_H

#define KXCJK1013_REG_DCST_RESP
#define KXCJK1013_REG_WHO_AM_I
#define KXTF9_REG_TILT_POS_CUR
#define KXTF9_REG_TILT_POS_PREV
#define KXTF9_REG_INT_SRC1
#define KXTF9_REG_INT_SRC2
#define KXCJK1013_REG_INT_SRC1
#define KXCJK1013_REG_INT_SRC2
#define KXCJK1013_REG_STATUS_REG
#define KXCJK1013_REG_INT_REL
#define KXCJK1013_REG_CTRL1
#define KXTF9_REG_CTRL2
#define KXTF9_REG_CTRL3
#define KXCJK1013_REG_CTRL2
#define KXCJK1013_REG_INT_CTRL1
#define KXCJK1013_REG_INT_CTRL2
#define KXTF9_REG_INT_CTRL3
#define KXCJK1013_REG_DATA_CTRL
#define KXTF9_REG_TILT_TIMER
#define KXCJK1013_REG_WAKE_TIMER
#define KXTF9_REG_TDT_TIMER
#define KXTF9_REG_TDT_THRESH_H
#define KXTF9_REG_TDT_THRESH_L
#define KXTF9_REG_TDT_TAP_TIMER
#define KXTF9_REG_TDT_TOTAL_TIMER
#define KXTF9_REG_TDT_LATENCY_TIMER
#define KXTF9_REG_TDT_WINDOW_TIMER
#define KXCJK1013_REG_SELF_TEST
#define KXTF9_REG_WAKE_THRESH
#define KXTF9_REG_TILT_ANGLE
#define KXTF9_REG_HYST_SET
#define KXCJK1013_REG_WAKE_THRES

/* Everything up to 0x11 is equal to KXCJK1013/KXTF9 above */
#define KX023_REG_INS1
#define KX023_REG_INS2
#define KX023_REG_INS3
#define KX023_REG_STAT
#define KX023_REG_INT_REL
#define KX023_REG_CNTL1
#define KX023_REG_CNTL2
#define KX023_REG_CNTL3
#define KX023_REG_ODCNTL
#define KX023_REG_INC1
#define KX023_REG_INC2
#define KX023_REG_INC3
#define KX023_REG_INC4
#define KX023_REG_INC5
#define KX023_REG_INC6
#define KX023_REG_TILT_TIMER
#define KX023_REG_WUFC
#define KX023_REG_TDTRC
#define KX023_REG_TDTC
#define KX023_REG_TTH
#define KX023_REG_TTL
#define KX023_REG_FTD
#define KX023_REG_STD
#define KX023_REG_TLT
#define KX023_REG_TWS
#define KX023_REG_ATH
#define KX023_REG_TILT_ANGLE_LL
#define KX023_REG_TILT_ANGLE_HL
#define KX023_REG_HYST_SET
#define KX023_REG_LP_CNTL
#define KX023_REG_BUF_CNTL1
#define KX023_REG_BUF_CNTL2
#define KX023_REG_BUF_STATUS_1
#define KX023_REG_BUF_STATUS_2
#define KX023_REG_BUF_CLEAR
#define KX023_REG_BUF_READ
#define KX023_REG_SELF_TEST

#define KXCJK1013_REG_CTRL1_BIT_PC1
#define KXCJK1013_REG_CTRL1_BIT_RES
#define KXCJK1013_REG_CTRL1_BIT_DRDY
#define KXCJK1013_REG_CTRL1_BIT_GSEL1
#define KXCJK1013_REG_CTRL1_BIT_GSEL0
#define KXCJK1013_REG_CTRL1_BIT_WUFE

#define KXCJK1013_REG_INT_CTRL1_BIT_IEU
#define KXCJK1013_REG_INT_CTRL1_BIT_IEL
#define KXCJK1013_REG_INT_CTRL1_BIT_IEA
#define KXCJK1013_REG_INT_CTRL1_BIT_IEN

#define KXTF9_REG_TILT_BIT_LEFT_EDGE
#define KXTF9_REG_TILT_BIT_RIGHT_EDGE
#define KXTF9_REG_TILT_BIT_LOWER_EDGE
#define KXTF9_REG_TILT_BIT_UPPER_EDGE
#define KXTF9_REG_TILT_BIT_FACE_DOWN
#define KXTF9_REG_TILT_BIT_FACE_UP

#define KXCJK1013_DATA_MASK_12_BIT
#define KXCJK1013_MAX_STARTUP_TIME_US

#define KXCJK1013_SLEEP_DELAY_MS

#define KXCJK1013_REG_INT_SRC1_BIT_TPS
#define KXCJK1013_REG_INT_SRC1_BIT_WUFS
#define KXCJK1013_REG_INT_SRC1_MASK_TDTS
#define KXCJK1013_REG_INT_SRC1_TAP_NONE
#define KXCJK1013_REG_INT_SRC1_TAP_SINGLE
#define KXCJK1013_REG_INT_SRC1_TAP_DOUBLE
#define KXCJK1013_REG_INT_SRC1_BIT_DRDY

/* KXCJK: INT_SOURCE2: motion detect, KXTF9: INT_SRC_REG1: tap detect */
#define KXCJK1013_REG_INT_SRC2_BIT_ZP
#define KXCJK1013_REG_INT_SRC2_BIT_ZN
#define KXCJK1013_REG_INT_SRC2_BIT_YP
#define KXCJK1013_REG_INT_SRC2_BIT_YN
#define KXCJK1013_REG_INT_SRC2_BIT_XP
#define KXCJK1013_REG_INT_SRC2_BIT_XN

/* KX023 interrupt routing to INT1. INT2 can be configured with INC6 */
#define KX023_REG_INC4_BFI1
#define KX023_REG_INC4_WMI1
#define KX023_REG_INC4_DRDY1
#define KX023_REG_INC4_TDTI1
#define KX023_REG_INC4_WUFI1
#define KX023_REG_INC4_TPI1

#define KXCJK1013_DEFAULT_WAKE_THRES

enum kx_chipset {};

enum kx_acpi_type {};

struct kx_chipset_regs {};

static const struct kx_chipset_regs kxcjk1013_regs =;

static const struct kx_chipset_regs kxtf9_regs =;

/* The registers have totally different names but the bits are compatible */
static const struct kx_chipset_regs kx0231025_regs =;

enum kxcjk1013_axis {};

struct kxcjk1013_data {};

enum kxcjk1013_mode {};

enum kxcjk1013_range {};

struct kx_odr_map {};

static const struct kx_odr_map samp_freq_table[] =;

static const char *const kxcjk1013_samp_freq_avail =;

static const struct kx_odr_map kxtf9_samp_freq_table[] =;

static const char *const kxtf9_samp_freq_avail =;

/* Refer to section 4 of the specification */
static __maybe_unused const struct {} odr_start_up_times[KX_MAX_CHIPS][12] =;

static const struct {} KXCJK1013_scale_table[] =;

#ifdef CONFIG_ACPI
enum kiox010a_fn_index {};

static int kiox010a_dsm(struct device *dev, int fn_index)
{}

static const struct acpi_device_id kx_acpi_match[] =;
MODULE_DEVICE_TABLE(acpi, kx_acpi_match);

#endif

static int kxcjk1013_set_mode(struct kxcjk1013_data *data,
			      enum kxcjk1013_mode mode)
{}

static int kxcjk1013_get_mode(struct kxcjk1013_data *data,
			      enum kxcjk1013_mode *mode)
{}

static int kxcjk1013_set_range(struct kxcjk1013_data *data, int range_index)
{}

static int kxcjk1013_chip_init(struct kxcjk1013_data *data)
{}

#ifdef CONFIG_PM
static int kxcjk1013_get_startup_times(struct kxcjk1013_data *data)
{}
#endif

static int kxcjk1013_set_power_state(struct kxcjk1013_data *data, bool on)
{}

static int kxcjk1013_chip_update_thresholds(struct kxcjk1013_data *data)
{}

static int kxcjk1013_setup_any_motion_interrupt(struct kxcjk1013_data *data,
						bool status)
{}

static int kxcjk1013_setup_new_data_interrupt(struct kxcjk1013_data *data,
					      bool status)
{}

static const struct kx_odr_map *kxcjk1013_find_odr_value(
	const struct kx_odr_map *map, size_t map_size, int val, int val2)
{}

static int kxcjk1013_convert_odr_value(const struct kx_odr_map *map,
				       size_t map_size, int odr_bits,
				       int *val, int *val2)
{}

static int kxcjk1013_set_odr(struct kxcjk1013_data *data, int val, int val2)
{}

static int kxcjk1013_get_odr(struct kxcjk1013_data *data, int *val, int *val2)
{}

static int kxcjk1013_get_acc_reg(struct kxcjk1013_data *data, int axis)
{}

static int kxcjk1013_set_scale(struct kxcjk1013_data *data, int val)
{}

static int kxcjk1013_read_raw(struct iio_dev *indio_dev,
			      struct iio_chan_spec const *chan, int *val,
			      int *val2, long mask)
{}

static int kxcjk1013_write_raw(struct iio_dev *indio_dev,
			       struct iio_chan_spec const *chan, int val,
			       int val2, long mask)
{}

static int kxcjk1013_read_event(struct iio_dev *indio_dev,
				   const struct iio_chan_spec *chan,
				   enum iio_event_type type,
				   enum iio_event_direction dir,
				   enum iio_event_info info,
				   int *val, int *val2)
{}

static int kxcjk1013_write_event(struct iio_dev *indio_dev,
				    const struct iio_chan_spec *chan,
				    enum iio_event_type type,
				    enum iio_event_direction dir,
				    enum iio_event_info info,
				    int val, int val2)
{}

static int kxcjk1013_read_event_config(struct iio_dev *indio_dev,
					  const struct iio_chan_spec *chan,
					  enum iio_event_type type,
					  enum iio_event_direction dir)
{}

static int kxcjk1013_write_event_config(struct iio_dev *indio_dev,
					   const struct iio_chan_spec *chan,
					   enum iio_event_type type,
					   enum iio_event_direction dir,
					   int state)
{}

static int kxcjk1013_buffer_preenable(struct iio_dev *indio_dev)
{}

static int kxcjk1013_buffer_postdisable(struct iio_dev *indio_dev)
{}

static ssize_t kxcjk1013_get_samp_freq_avail(struct device *dev,
					     struct device_attribute *attr,
					     char *buf)
{}

static IIO_DEVICE_ATTR(in_accel_sampling_frequency_available, S_IRUGO,
		       kxcjk1013_get_samp_freq_avail, NULL, 0);

static IIO_CONST_ATTR(in_accel_scale_available, "0.009582 0.019163 0.038326");

static struct attribute *kxcjk1013_attributes[] =;

static const struct attribute_group kxcjk1013_attrs_group =;

static const struct iio_event_spec kxcjk1013_event =;

static const struct iio_mount_matrix *
kxcjk1013_get_mount_matrix(const struct iio_dev *indio_dev,
			   const struct iio_chan_spec *chan)
{}

static const struct iio_chan_spec_ext_info kxcjk1013_ext_info[] =;

#define KXCJK1013_CHANNEL(_axis)

static const struct iio_chan_spec kxcjk1013_channels[] =;

static const struct iio_buffer_setup_ops kxcjk1013_buffer_setup_ops =;

static const struct iio_info kxcjk1013_info =;

static const unsigned long kxcjk1013_scan_masks[] =;

static irqreturn_t kxcjk1013_trigger_handler(int irq, void *p)
{}

static void kxcjk1013_trig_reen(struct iio_trigger *trig)
{}

static int kxcjk1013_data_rdy_trigger_set_state(struct iio_trigger *trig,
						bool state)
{}

static const struct iio_trigger_ops kxcjk1013_trigger_ops =;

static void kxcjk1013_report_motion_event(struct iio_dev *indio_dev)
{}

static irqreturn_t kxcjk1013_event_handler(int irq, void *private)
{}

static irqreturn_t kxcjk1013_data_rdy_trig_poll(int irq, void *private)
{}

static const char *kxcjk1013_match_acpi_device(struct device *dev,
					       enum kx_chipset *chipset,
					       enum kx_acpi_type *acpi_type,
					       const char **label)
{}

static int kxcjk1013_probe(struct i2c_client *client)
{}

static void kxcjk1013_remove(struct i2c_client *client)
{}

#ifdef CONFIG_PM_SLEEP
static int kxcjk1013_suspend(struct device *dev)
{}

static int kxcjk1013_resume(struct device *dev)
{}
#endif

#ifdef CONFIG_PM
static int kxcjk1013_runtime_suspend(struct device *dev)
{}

static int kxcjk1013_runtime_resume(struct device *dev)
{}
#endif

static const struct dev_pm_ops kxcjk1013_pm_ops =;

static const struct i2c_device_id kxcjk1013_id[] =;

MODULE_DEVICE_TABLE(i2c, kxcjk1013_id);

static const struct of_device_id kxcjk1013_of_match[] =;
MODULE_DEVICE_TABLE(of, kxcjk1013_of_match);

static struct i2c_driver kxcjk1013_driver =;
module_i2c_driver();

MODULE_AUTHOR();
MODULE_LICENSE();
MODULE_DESCRIPTION();