0001
0002
0003
0004
0005
0006
0007
0008 #ifndef IIO_SX_COMMON_H
0009 #define IIO_SX_COMMON_H
0010
0011 #include <linux/iio/iio.h>
0012 #include <linux/iio/types.h>
0013 #include <linux/regulator/consumer.h>
0014 #include <linux/types.h>
0015
0016 struct device;
0017 struct i2c_client;
0018 struct regmap_config;
0019 struct sx_common_data;
0020
0021 #define SX_COMMON_REG_IRQ_SRC 0x00
0022
0023 #define SX_COMMON_MAX_NUM_CHANNELS 4
0024 static_assert(SX_COMMON_MAX_NUM_CHANNELS < BITS_PER_LONG);
0025
0026 struct sx_common_reg_default {
0027 u8 reg;
0028 u8 def;
0029 };
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 struct sx_common_ops {
0045 int (*read_prox_data)(struct sx_common_data *data,
0046 const struct iio_chan_spec *chan, __be16 *val);
0047 int (*check_whoami)(struct device *dev, struct iio_dev *indio_dev);
0048 int (*init_compensation)(struct iio_dev *indio_dev);
0049 int (*wait_for_sample)(struct sx_common_data *data);
0050 const struct sx_common_reg_default *
0051 (*get_default_reg)(struct device *dev, int idx,
0052 struct sx_common_reg_default *reg_def);
0053 };
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 struct sx_common_chip_info {
0077 unsigned int reg_stat;
0078 unsigned int reg_irq_msk;
0079 unsigned int reg_enable_chan;
0080 unsigned int reg_reset;
0081
0082 unsigned int mask_enable_chan;
0083 unsigned int stat_offset;
0084 unsigned int irq_msk_offset;
0085 unsigned int num_channels;
0086 int num_default_regs;
0087
0088 struct sx_common_ops ops;
0089
0090 const struct iio_chan_spec *iio_channels;
0091 int num_iio_channels;
0092 struct iio_info iio_info;
0093 };
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114 struct sx_common_data {
0115 const struct sx_common_chip_info *chip_info;
0116
0117 struct mutex mutex;
0118 struct completion completion;
0119 struct i2c_client *client;
0120 struct iio_trigger *trig;
0121 struct regmap *regmap;
0122
0123 struct regulator_bulk_data supplies[2];
0124 unsigned long chan_prox_stat;
0125 bool trigger_enabled;
0126
0127
0128 struct {
0129 __be16 channels[SX_COMMON_MAX_NUM_CHANNELS];
0130 s64 ts __aligned(8);
0131 } buffer;
0132
0133 unsigned int suspend_ctrl;
0134 unsigned long chan_read;
0135 unsigned long chan_event;
0136 };
0137
0138 int sx_common_read_proximity(struct sx_common_data *data,
0139 const struct iio_chan_spec *chan, int *val);
0140
0141 int sx_common_read_event_config(struct iio_dev *indio_dev,
0142 const struct iio_chan_spec *chan,
0143 enum iio_event_type type,
0144 enum iio_event_direction dir);
0145 int sx_common_write_event_config(struct iio_dev *indio_dev,
0146 const struct iio_chan_spec *chan,
0147 enum iio_event_type type,
0148 enum iio_event_direction dir, int state);
0149
0150 int sx_common_probe(struct i2c_client *client,
0151 const struct sx_common_chip_info *chip_info,
0152 const struct regmap_config *regmap_config);
0153
0154
0155 extern const struct iio_event_spec sx_common_events[3];
0156
0157 #endif