1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * Copyright (C) 2022 ROHM Semiconductors 4 * 5 * ROHM/KIONIX KX022A accelerometer driver 6 */ 7 8 #ifndef _KX022A_H_ 9 #define _KX022A_H_ 10 11 #include <linux/bits.h> 12 #include <linux/regmap.h> 13 14 #define KX022A_REG_WHO 0x0f 15 #define KX022A_ID 0xc8 16 #define KX132ACR_LBZ_ID 0xd8 17 #define KX134ACR_LBZ_ID 0xcc 18 19 #define KX022A_REG_CNTL2 0x19 20 #define KX022A_MASK_SRST BIT(7) 21 #define KX022A_REG_CNTL 0x18 22 #define KX022A_MASK_PC1 BIT(7) 23 #define KX022A_MASK_RES BIT(6) 24 #define KX022A_MASK_DRDY BIT(5) 25 #define KX022A_MASK_GSEL GENMASK(4, 3) 26 #define KX022A_GSEL_SHIFT 3 27 #define KX022A_GSEL_2 0x0 28 #define KX022A_GSEL_4 BIT(3) 29 #define KX022A_GSEL_8 BIT(4) 30 #define KX022A_GSEL_16 GENMASK(4, 3) 31 32 #define KX022A_REG_INS2 0x13 33 #define KX022A_MASK_INS2_DRDY BIT(4) 34 #define KX122_MASK_INS2_WMI BIT(5) 35 36 #define KX022A_REG_XHP_L 0x0 37 #define KX022A_REG_XOUT_L 0x06 38 #define KX022A_REG_YOUT_L 0x08 39 #define KX022A_REG_ZOUT_L 0x0a 40 #define KX022A_REG_COTR 0x0c 41 #define KX022A_REG_TSCP 0x10 42 #define KX022A_REG_INT_REL 0x17 43 44 #define KX022A_REG_ODCNTL 0x1b 45 46 #define KX022A_REG_BTS_WUF_TH 0x31 47 #define KX022A_REG_MAN_WAKE 0x2c 48 49 #define KX022A_REG_BUF_CNTL1 0x3a 50 #define KX022A_MASK_WM_TH GENMASK(6, 0) 51 #define KX022A_REG_BUF_CNTL2 0x3b 52 #define KX022A_MASK_BUF_EN BIT(7) 53 #define KX022A_MASK_BRES16 BIT(6) 54 #define KX022A_REG_BUF_STATUS_1 0x3c 55 #define KX022A_REG_BUF_STATUS_2 0x3d 56 #define KX022A_REG_BUF_CLEAR 0x3e 57 #define KX022A_REG_BUF_READ 0x3f 58 #define KX022A_MASK_ODR GENMASK(3, 0) 59 #define KX022A_ODR_SHIFT 3 60 #define KX022A_FIFO_MAX_WMI_TH 41 61 62 #define KX022A_REG_INC1 0x1c 63 #define KX022A_REG_INC5 0x20 64 #define KX022A_REG_INC6 0x21 65 #define KX022A_MASK_IEN BIT(5) 66 #define KX022A_MASK_IPOL BIT(4) 67 #define KX022A_IPOL_LOW 0 68 #define KX022A_IPOL_HIGH KX022A_MASK_IPOL1 69 #define KX022A_MASK_ITYP BIT(3) 70 #define KX022A_ITYP_PULSE KX022A_MASK_ITYP 71 #define KX022A_ITYP_LEVEL 0 72 73 #define KX022A_REG_INC4 0x1f 74 #define KX022A_MASK_WMI BIT(5) 75 76 #define KX022A_REG_SELF_TEST 0x60 77 #define KX022A_MAX_REGISTER 0x60 78 79 #define KX132_REG_WHO 0x13 80 #define KX132_ID 0x3d 81 #define KX134_1211_ID 0x46 82 83 #define KX132_FIFO_LENGTH 86 84 85 #define KX132_REG_CNTL 0x1b 86 #define KX132_REG_CNTL2 0x1c 87 #define KX132_REG_CNTL5 0x1f 88 #define KX132_MASK_RES BIT(6) 89 #define KX132_GSEL_2 0x0 90 #define KX132_GSEL_4 BIT(3) 91 #define KX132_GSEL_8 BIT(4) 92 #define KX132_GSEL_16 GENMASK(4, 3) 93 94 #define KX132_REG_INS2 0x17 95 #define KX132_MASK_INS2_WMI BIT(5) 96 97 #define KX132_REG_XADP_L 0x02 98 #define KX132_REG_XOUT_L 0x08 99 #define KX132_REG_YOUT_L 0x0a 100 #define KX132_REG_ZOUT_L 0x0c 101 #define KX132_REG_COTR 0x12 102 #define KX132_REG_TSCP 0x14 103 #define KX132_REG_INT_REL 0x1a 104 105 #define KX132_REG_ODCNTL 0x21 106 107 #define KX132_REG_BTS_WUF_TH 0x4a 108 109 #define KX132_REG_BUF_CNTL1 0x5e 110 #define KX132_REG_BUF_CNTL2 0x5f 111 #define KX132_REG_BUF_STATUS_1 0x60 112 #define KX132_REG_BUF_STATUS_2 0x61 113 #define KX132_MASK_BUF_SMP_LVL GENMASK(9, 0) 114 #define KX132_REG_BUF_CLEAR 0x62 115 #define KX132_REG_BUF_READ 0x63 116 #define KX132_ODR_SHIFT 3 117 #define KX132_FIFO_MAX_WMI_TH 86 118 119 #define KX132_REG_INC1 0x22 120 #define KX132_REG_INC5 0x26 121 #define KX132_REG_INC6 0x27 122 #define KX132_IPOL_LOW 0 123 #define KX132_IPOL_HIGH KX022A_MASK_IPOL 124 #define KX132_ITYP_PULSE KX022A_MASK_ITYP 125 126 #define KX132_REG_INC4 0x25 127 128 #define KX132_REG_SELF_TEST 0x5d 129 #define KX132_MAX_REGISTER 0x76 130 131 struct device; 132 133 struct kx022a_data; 134 135 /** 136 * struct kx022a_chip_info - Kionix accelerometer chip specific information 137 * 138 * @name: name of the device 139 * @regmap_config: pointer to register map configuration 140 * @scale_table: An array of tables of scaling factors for 141 * a supported acceleration measurement range. 142 * Each table containing a single scaling 143 * factor consisting of two integers. The first 144 * value in a table is the integer part, and 145 * the second value is the fractional part as 146 * parts per billion. 147 * @scale_table_size: Amount of values in tables. 148 * @channels: pointer to iio_chan_spec array 149 * @num_channels: number of iio_chan_spec channels 150 * @fifo_length: number of 16-bit samples in a full buffer 151 * @buf_smp_lvl_mask: buffer sample level mask 152 * @who: WHO_AM_I register 153 * @id: WHO_AM_I register value 154 * @cntl: control register 1 155 * @cntl2: control register 2 156 * @odcntl: output data control register 157 * @buf_cntl1: buffer control register 1 158 * @buf_cntl2: buffer control register 2 159 * @buf_clear: buffer clear register 160 * @buf_status1: buffer status register 1 161 * @buf_read: buffer read register 162 * @inc1: interrupt control register 1 163 * @inc4: interrupt control register 4 164 * @inc5: interrupt control register 5 165 * @inc6: interrupt control register 6 166 * @xout_l: x-axis output least significant byte 167 * @get_fifo_bytes_available: function pointer to get amount of acceleration 168 * data bytes currently stored in the sensor's FIFO 169 * buffer 170 */ 171 struct kx022a_chip_info { 172 const char *name; 173 const struct regmap_config *regmap_config; 174 const int (*scale_table)[2]; 175 const int scale_table_size; 176 const struct iio_chan_spec *channels; 177 unsigned int num_channels; 178 unsigned int fifo_length; 179 u16 buf_smp_lvl_mask; 180 u8 who; 181 u8 id; 182 u8 cntl; 183 u8 cntl2; 184 u8 odcntl; 185 u8 buf_cntl1; 186 u8 buf_cntl2; 187 u8 buf_clear; 188 u8 buf_status1; 189 u8 buf_read; 190 u8 inc1; 191 u8 inc4; 192 u8 inc5; 193 u8 inc6; 194 u8 xout_l; 195 int (*get_fifo_bytes_available)(struct kx022a_data *); 196 }; 197 198 int kx022a_probe_internal(struct device *dev, const struct kx022a_chip_info *chip_info); 199 200 extern const struct kx022a_chip_info kx022a_chip_info; 201 extern const struct kx022a_chip_info kx132_chip_info; 202 extern const struct kx022a_chip_info kx134_chip_info; 203 extern const struct kx022a_chip_info kx132acr_chip_info; 204 extern const struct kx022a_chip_info kx134acr_chip_info; 205 206 #endif 207