18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/** 38c2ecf20Sopenharmony_ci * Sensortek STK8312 3-Axis Accelerometer 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2015, Intel Corporation. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * IIO driver for STK8312; 7-bit I2C address: 0x3D. 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/acpi.h> 118c2ecf20Sopenharmony_ci#include <linux/i2c.h> 128c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 138c2ecf20Sopenharmony_ci#include <linux/kernel.h> 148c2ecf20Sopenharmony_ci#include <linux/module.h> 158c2ecf20Sopenharmony_ci#include <linux/delay.h> 168c2ecf20Sopenharmony_ci#include <linux/iio/buffer.h> 178c2ecf20Sopenharmony_ci#include <linux/iio/iio.h> 188c2ecf20Sopenharmony_ci#include <linux/iio/sysfs.h> 198c2ecf20Sopenharmony_ci#include <linux/iio/trigger.h> 208c2ecf20Sopenharmony_ci#include <linux/iio/triggered_buffer.h> 218c2ecf20Sopenharmony_ci#include <linux/iio/trigger_consumer.h> 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define STK8312_REG_XOUT 0x00 248c2ecf20Sopenharmony_ci#define STK8312_REG_YOUT 0x01 258c2ecf20Sopenharmony_ci#define STK8312_REG_ZOUT 0x02 268c2ecf20Sopenharmony_ci#define STK8312_REG_INTSU 0x06 278c2ecf20Sopenharmony_ci#define STK8312_REG_MODE 0x07 288c2ecf20Sopenharmony_ci#define STK8312_REG_SR 0x08 298c2ecf20Sopenharmony_ci#define STK8312_REG_STH 0x13 308c2ecf20Sopenharmony_ci#define STK8312_REG_RESET 0x20 318c2ecf20Sopenharmony_ci#define STK8312_REG_AFECTRL 0x24 328c2ecf20Sopenharmony_ci#define STK8312_REG_OTPADDR 0x3D 338c2ecf20Sopenharmony_ci#define STK8312_REG_OTPDATA 0x3E 348c2ecf20Sopenharmony_ci#define STK8312_REG_OTPCTRL 0x3F 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define STK8312_MODE_ACTIVE BIT(0) 378c2ecf20Sopenharmony_ci#define STK8312_MODE_STANDBY 0x00 388c2ecf20Sopenharmony_ci#define STK8312_MODE_INT_AH_PP 0xC0 /* active-high, push-pull */ 398c2ecf20Sopenharmony_ci#define STK8312_DREADY_BIT BIT(4) 408c2ecf20Sopenharmony_ci#define STK8312_RNG_6G 1 418c2ecf20Sopenharmony_ci#define STK8312_RNG_SHIFT 6 428c2ecf20Sopenharmony_ci#define STK8312_RNG_MASK GENMASK(7, 6) 438c2ecf20Sopenharmony_ci#define STK8312_SR_MASK GENMASK(2, 0) 448c2ecf20Sopenharmony_ci#define STK8312_SR_400HZ_IDX 0 458c2ecf20Sopenharmony_ci#define STK8312_ALL_CHANNEL_MASK GENMASK(2, 0) 468c2ecf20Sopenharmony_ci#define STK8312_ALL_CHANNEL_SIZE 3 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define STK8312_DRIVER_NAME "stk8312" 498c2ecf20Sopenharmony_ci#define STK8312_IRQ_NAME "stk8312_event" 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci/* 528c2ecf20Sopenharmony_ci * The accelerometer has two measurement ranges: 538c2ecf20Sopenharmony_ci * 548c2ecf20Sopenharmony_ci * -6g - +6g (8-bit, signed) 558c2ecf20Sopenharmony_ci * -16g - +16g (8-bit, signed) 568c2ecf20Sopenharmony_ci * 578c2ecf20Sopenharmony_ci * scale1 = (6 + 6) * 9.81 / (2^8 - 1) = 0.4616 588c2ecf20Sopenharmony_ci * scale2 = (16 + 16) * 9.81 / (2^8 - 1) = 1.2311 598c2ecf20Sopenharmony_ci */ 608c2ecf20Sopenharmony_ci#define STK8312_SCALE_AVAIL "0.4616 1.2311" 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_cistatic const int stk8312_scale_table[][2] = { 638c2ecf20Sopenharmony_ci {0, 461600}, {1, 231100} 648c2ecf20Sopenharmony_ci}; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistatic const struct { 678c2ecf20Sopenharmony_ci int val; 688c2ecf20Sopenharmony_ci int val2; 698c2ecf20Sopenharmony_ci} stk8312_samp_freq_table[] = { 708c2ecf20Sopenharmony_ci {400, 0}, {200, 0}, {100, 0}, {50, 0}, {25, 0}, 718c2ecf20Sopenharmony_ci {12, 500000}, {6, 250000}, {3, 125000} 728c2ecf20Sopenharmony_ci}; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci#define STK8312_ACCEL_CHANNEL(index, reg, axis) { \ 758c2ecf20Sopenharmony_ci .type = IIO_ACCEL, \ 768c2ecf20Sopenharmony_ci .address = reg, \ 778c2ecf20Sopenharmony_ci .modified = 1, \ 788c2ecf20Sopenharmony_ci .channel2 = IIO_MOD_##axis, \ 798c2ecf20Sopenharmony_ci .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 808c2ecf20Sopenharmony_ci .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 818c2ecf20Sopenharmony_ci BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 828c2ecf20Sopenharmony_ci .scan_index = index, \ 838c2ecf20Sopenharmony_ci .scan_type = { \ 848c2ecf20Sopenharmony_ci .sign = 's', \ 858c2ecf20Sopenharmony_ci .realbits = 8, \ 868c2ecf20Sopenharmony_ci .storagebits = 8, \ 878c2ecf20Sopenharmony_ci .endianness = IIO_CPU, \ 888c2ecf20Sopenharmony_ci }, \ 898c2ecf20Sopenharmony_ci} 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cistatic const struct iio_chan_spec stk8312_channels[] = { 928c2ecf20Sopenharmony_ci STK8312_ACCEL_CHANNEL(0, STK8312_REG_XOUT, X), 938c2ecf20Sopenharmony_ci STK8312_ACCEL_CHANNEL(1, STK8312_REG_YOUT, Y), 948c2ecf20Sopenharmony_ci STK8312_ACCEL_CHANNEL(2, STK8312_REG_ZOUT, Z), 958c2ecf20Sopenharmony_ci IIO_CHAN_SOFT_TIMESTAMP(3), 968c2ecf20Sopenharmony_ci}; 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_cistruct stk8312_data { 998c2ecf20Sopenharmony_ci struct i2c_client *client; 1008c2ecf20Sopenharmony_ci struct mutex lock; 1018c2ecf20Sopenharmony_ci u8 range; 1028c2ecf20Sopenharmony_ci u8 sample_rate_idx; 1038c2ecf20Sopenharmony_ci u8 mode; 1048c2ecf20Sopenharmony_ci struct iio_trigger *dready_trig; 1058c2ecf20Sopenharmony_ci bool dready_trigger_on; 1068c2ecf20Sopenharmony_ci /* Ensure timestamp is naturally aligned */ 1078c2ecf20Sopenharmony_ci struct { 1088c2ecf20Sopenharmony_ci s8 chans[3]; 1098c2ecf20Sopenharmony_ci s64 timestamp __aligned(8); 1108c2ecf20Sopenharmony_ci } scan; 1118c2ecf20Sopenharmony_ci}; 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_cistatic IIO_CONST_ATTR(in_accel_scale_available, STK8312_SCALE_AVAIL); 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cistatic IIO_CONST_ATTR_SAMP_FREQ_AVAIL("3.125 6.25 12.5 25 50 100 200 400"); 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_cistatic struct attribute *stk8312_attributes[] = { 1188c2ecf20Sopenharmony_ci &iio_const_attr_in_accel_scale_available.dev_attr.attr, 1198c2ecf20Sopenharmony_ci &iio_const_attr_sampling_frequency_available.dev_attr.attr, 1208c2ecf20Sopenharmony_ci NULL, 1218c2ecf20Sopenharmony_ci}; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_cistatic const struct attribute_group stk8312_attribute_group = { 1248c2ecf20Sopenharmony_ci .attrs = stk8312_attributes 1258c2ecf20Sopenharmony_ci}; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_cistatic int stk8312_otp_init(struct stk8312_data *data) 1288c2ecf20Sopenharmony_ci{ 1298c2ecf20Sopenharmony_ci int ret; 1308c2ecf20Sopenharmony_ci int count = 10; 1318c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci ret = i2c_smbus_write_byte_data(client, STK8312_REG_OTPADDR, 0x70); 1348c2ecf20Sopenharmony_ci if (ret < 0) 1358c2ecf20Sopenharmony_ci goto exit_err; 1368c2ecf20Sopenharmony_ci ret = i2c_smbus_write_byte_data(client, STK8312_REG_OTPCTRL, 0x02); 1378c2ecf20Sopenharmony_ci if (ret < 0) 1388c2ecf20Sopenharmony_ci goto exit_err; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci do { 1418c2ecf20Sopenharmony_ci usleep_range(1000, 5000); 1428c2ecf20Sopenharmony_ci ret = i2c_smbus_read_byte_data(client, STK8312_REG_OTPCTRL); 1438c2ecf20Sopenharmony_ci if (ret < 0) 1448c2ecf20Sopenharmony_ci goto exit_err; 1458c2ecf20Sopenharmony_ci count--; 1468c2ecf20Sopenharmony_ci } while (!(ret & BIT(7)) && count > 0); 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci if (count == 0) { 1498c2ecf20Sopenharmony_ci ret = -ETIMEDOUT; 1508c2ecf20Sopenharmony_ci goto exit_err; 1518c2ecf20Sopenharmony_ci } 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci ret = i2c_smbus_read_byte_data(client, STK8312_REG_OTPDATA); 1548c2ecf20Sopenharmony_ci if (ret == 0) 1558c2ecf20Sopenharmony_ci ret = -EINVAL; 1568c2ecf20Sopenharmony_ci if (ret < 0) 1578c2ecf20Sopenharmony_ci goto exit_err; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci ret = i2c_smbus_write_byte_data(data->client, STK8312_REG_AFECTRL, ret); 1608c2ecf20Sopenharmony_ci if (ret < 0) 1618c2ecf20Sopenharmony_ci goto exit_err; 1628c2ecf20Sopenharmony_ci msleep(150); 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci return 0; 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ciexit_err: 1678c2ecf20Sopenharmony_ci dev_err(&client->dev, "failed to initialize sensor\n"); 1688c2ecf20Sopenharmony_ci return ret; 1698c2ecf20Sopenharmony_ci} 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_cistatic int stk8312_set_mode(struct stk8312_data *data, u8 mode) 1728c2ecf20Sopenharmony_ci{ 1738c2ecf20Sopenharmony_ci int ret; 1748c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci if (mode == data->mode) 1778c2ecf20Sopenharmony_ci return 0; 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci ret = i2c_smbus_write_byte_data(client, STK8312_REG_MODE, mode); 1808c2ecf20Sopenharmony_ci if (ret < 0) { 1818c2ecf20Sopenharmony_ci dev_err(&client->dev, "failed to change sensor mode\n"); 1828c2ecf20Sopenharmony_ci return ret; 1838c2ecf20Sopenharmony_ci } 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci data->mode = mode; 1868c2ecf20Sopenharmony_ci if (mode & STK8312_MODE_ACTIVE) { 1878c2ecf20Sopenharmony_ci /* Need to run OTP sequence before entering active mode */ 1888c2ecf20Sopenharmony_ci usleep_range(1000, 5000); 1898c2ecf20Sopenharmony_ci ret = stk8312_otp_init(data); 1908c2ecf20Sopenharmony_ci } 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci return ret; 1938c2ecf20Sopenharmony_ci} 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_cistatic int stk8312_set_interrupts(struct stk8312_data *data, u8 int_mask) 1968c2ecf20Sopenharmony_ci{ 1978c2ecf20Sopenharmony_ci int ret; 1988c2ecf20Sopenharmony_ci u8 mode; 1998c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci mode = data->mode; 2028c2ecf20Sopenharmony_ci /* We need to go in standby mode to modify registers */ 2038c2ecf20Sopenharmony_ci ret = stk8312_set_mode(data, STK8312_MODE_STANDBY); 2048c2ecf20Sopenharmony_ci if (ret < 0) 2058c2ecf20Sopenharmony_ci return ret; 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci ret = i2c_smbus_write_byte_data(client, STK8312_REG_INTSU, int_mask); 2088c2ecf20Sopenharmony_ci if (ret < 0) { 2098c2ecf20Sopenharmony_ci dev_err(&client->dev, "failed to set interrupts\n"); 2108c2ecf20Sopenharmony_ci stk8312_set_mode(data, mode); 2118c2ecf20Sopenharmony_ci return ret; 2128c2ecf20Sopenharmony_ci } 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci return stk8312_set_mode(data, mode); 2158c2ecf20Sopenharmony_ci} 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_cistatic int stk8312_data_rdy_trigger_set_state(struct iio_trigger *trig, 2188c2ecf20Sopenharmony_ci bool state) 2198c2ecf20Sopenharmony_ci{ 2208c2ecf20Sopenharmony_ci struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); 2218c2ecf20Sopenharmony_ci struct stk8312_data *data = iio_priv(indio_dev); 2228c2ecf20Sopenharmony_ci int ret; 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci if (state) 2258c2ecf20Sopenharmony_ci ret = stk8312_set_interrupts(data, STK8312_DREADY_BIT); 2268c2ecf20Sopenharmony_ci else 2278c2ecf20Sopenharmony_ci ret = stk8312_set_interrupts(data, 0x00); 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci if (ret < 0) { 2308c2ecf20Sopenharmony_ci dev_err(&data->client->dev, "failed to set trigger state\n"); 2318c2ecf20Sopenharmony_ci return ret; 2328c2ecf20Sopenharmony_ci } 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci data->dready_trigger_on = state; 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci return 0; 2378c2ecf20Sopenharmony_ci} 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_cistatic const struct iio_trigger_ops stk8312_trigger_ops = { 2408c2ecf20Sopenharmony_ci .set_trigger_state = stk8312_data_rdy_trigger_set_state, 2418c2ecf20Sopenharmony_ci}; 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_cistatic int stk8312_set_sample_rate(struct stk8312_data *data, u8 rate) 2448c2ecf20Sopenharmony_ci{ 2458c2ecf20Sopenharmony_ci int ret; 2468c2ecf20Sopenharmony_ci u8 masked_reg; 2478c2ecf20Sopenharmony_ci u8 mode; 2488c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci if (rate == data->sample_rate_idx) 2518c2ecf20Sopenharmony_ci return 0; 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci mode = data->mode; 2548c2ecf20Sopenharmony_ci /* We need to go in standby mode to modify registers */ 2558c2ecf20Sopenharmony_ci ret = stk8312_set_mode(data, STK8312_MODE_STANDBY); 2568c2ecf20Sopenharmony_ci if (ret < 0) 2578c2ecf20Sopenharmony_ci return ret; 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci ret = i2c_smbus_read_byte_data(client, STK8312_REG_SR); 2608c2ecf20Sopenharmony_ci if (ret < 0) 2618c2ecf20Sopenharmony_ci goto err_activate; 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci masked_reg = (ret & (~STK8312_SR_MASK)) | rate; 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_ci ret = i2c_smbus_write_byte_data(client, STK8312_REG_SR, masked_reg); 2668c2ecf20Sopenharmony_ci if (ret < 0) 2678c2ecf20Sopenharmony_ci goto err_activate; 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci data->sample_rate_idx = rate; 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci return stk8312_set_mode(data, mode); 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_cierr_activate: 2748c2ecf20Sopenharmony_ci dev_err(&client->dev, "failed to set sampling rate\n"); 2758c2ecf20Sopenharmony_ci stk8312_set_mode(data, mode); 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci return ret; 2788c2ecf20Sopenharmony_ci} 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_cistatic int stk8312_set_range(struct stk8312_data *data, u8 range) 2818c2ecf20Sopenharmony_ci{ 2828c2ecf20Sopenharmony_ci int ret; 2838c2ecf20Sopenharmony_ci u8 masked_reg; 2848c2ecf20Sopenharmony_ci u8 mode; 2858c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci if (range != 1 && range != 2) 2888c2ecf20Sopenharmony_ci return -EINVAL; 2898c2ecf20Sopenharmony_ci else if (range == data->range) 2908c2ecf20Sopenharmony_ci return 0; 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci mode = data->mode; 2938c2ecf20Sopenharmony_ci /* We need to go in standby mode to modify registers */ 2948c2ecf20Sopenharmony_ci ret = stk8312_set_mode(data, STK8312_MODE_STANDBY); 2958c2ecf20Sopenharmony_ci if (ret < 0) 2968c2ecf20Sopenharmony_ci return ret; 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci ret = i2c_smbus_read_byte_data(client, STK8312_REG_STH); 2998c2ecf20Sopenharmony_ci if (ret < 0) 3008c2ecf20Sopenharmony_ci goto err_activate; 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ci masked_reg = ret & (~STK8312_RNG_MASK); 3038c2ecf20Sopenharmony_ci masked_reg |= range << STK8312_RNG_SHIFT; 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_ci ret = i2c_smbus_write_byte_data(client, STK8312_REG_STH, masked_reg); 3068c2ecf20Sopenharmony_ci if (ret < 0) 3078c2ecf20Sopenharmony_ci goto err_activate; 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci data->range = range; 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci return stk8312_set_mode(data, mode); 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_cierr_activate: 3148c2ecf20Sopenharmony_ci dev_err(&client->dev, "failed to change sensor range\n"); 3158c2ecf20Sopenharmony_ci stk8312_set_mode(data, mode); 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_ci return ret; 3188c2ecf20Sopenharmony_ci} 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_cistatic int stk8312_read_accel(struct stk8312_data *data, u8 address) 3218c2ecf20Sopenharmony_ci{ 3228c2ecf20Sopenharmony_ci int ret; 3238c2ecf20Sopenharmony_ci struct i2c_client *client = data->client; 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci if (address > 2) 3268c2ecf20Sopenharmony_ci return -EINVAL; 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci ret = i2c_smbus_read_byte_data(client, address); 3298c2ecf20Sopenharmony_ci if (ret < 0) 3308c2ecf20Sopenharmony_ci dev_err(&client->dev, "register read failed\n"); 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci return ret; 3338c2ecf20Sopenharmony_ci} 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_cistatic int stk8312_read_raw(struct iio_dev *indio_dev, 3368c2ecf20Sopenharmony_ci struct iio_chan_spec const *chan, 3378c2ecf20Sopenharmony_ci int *val, int *val2, long mask) 3388c2ecf20Sopenharmony_ci{ 3398c2ecf20Sopenharmony_ci struct stk8312_data *data = iio_priv(indio_dev); 3408c2ecf20Sopenharmony_ci int ret; 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci switch (mask) { 3438c2ecf20Sopenharmony_ci case IIO_CHAN_INFO_RAW: 3448c2ecf20Sopenharmony_ci if (iio_buffer_enabled(indio_dev)) 3458c2ecf20Sopenharmony_ci return -EBUSY; 3468c2ecf20Sopenharmony_ci mutex_lock(&data->lock); 3478c2ecf20Sopenharmony_ci ret = stk8312_set_mode(data, data->mode | STK8312_MODE_ACTIVE); 3488c2ecf20Sopenharmony_ci if (ret < 0) { 3498c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 3508c2ecf20Sopenharmony_ci return ret; 3518c2ecf20Sopenharmony_ci } 3528c2ecf20Sopenharmony_ci ret = stk8312_read_accel(data, chan->address); 3538c2ecf20Sopenharmony_ci if (ret < 0) { 3548c2ecf20Sopenharmony_ci stk8312_set_mode(data, 3558c2ecf20Sopenharmony_ci data->mode & (~STK8312_MODE_ACTIVE)); 3568c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 3578c2ecf20Sopenharmony_ci return ret; 3588c2ecf20Sopenharmony_ci } 3598c2ecf20Sopenharmony_ci *val = sign_extend32(ret, 7); 3608c2ecf20Sopenharmony_ci ret = stk8312_set_mode(data, 3618c2ecf20Sopenharmony_ci data->mode & (~STK8312_MODE_ACTIVE)); 3628c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 3638c2ecf20Sopenharmony_ci if (ret < 0) 3648c2ecf20Sopenharmony_ci return ret; 3658c2ecf20Sopenharmony_ci return IIO_VAL_INT; 3668c2ecf20Sopenharmony_ci case IIO_CHAN_INFO_SCALE: 3678c2ecf20Sopenharmony_ci *val = stk8312_scale_table[data->range - 1][0]; 3688c2ecf20Sopenharmony_ci *val2 = stk8312_scale_table[data->range - 1][1]; 3698c2ecf20Sopenharmony_ci return IIO_VAL_INT_PLUS_MICRO; 3708c2ecf20Sopenharmony_ci case IIO_CHAN_INFO_SAMP_FREQ: 3718c2ecf20Sopenharmony_ci *val = stk8312_samp_freq_table[data->sample_rate_idx].val; 3728c2ecf20Sopenharmony_ci *val2 = stk8312_samp_freq_table[data->sample_rate_idx].val2; 3738c2ecf20Sopenharmony_ci return IIO_VAL_INT_PLUS_MICRO; 3748c2ecf20Sopenharmony_ci } 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci return -EINVAL; 3778c2ecf20Sopenharmony_ci} 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_cistatic int stk8312_write_raw(struct iio_dev *indio_dev, 3808c2ecf20Sopenharmony_ci struct iio_chan_spec const *chan, 3818c2ecf20Sopenharmony_ci int val, int val2, long mask) 3828c2ecf20Sopenharmony_ci{ 3838c2ecf20Sopenharmony_ci int i; 3848c2ecf20Sopenharmony_ci int index = -1; 3858c2ecf20Sopenharmony_ci int ret; 3868c2ecf20Sopenharmony_ci struct stk8312_data *data = iio_priv(indio_dev); 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci switch (mask) { 3898c2ecf20Sopenharmony_ci case IIO_CHAN_INFO_SCALE: 3908c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(stk8312_scale_table); i++) 3918c2ecf20Sopenharmony_ci if (val == stk8312_scale_table[i][0] && 3928c2ecf20Sopenharmony_ci val2 == stk8312_scale_table[i][1]) { 3938c2ecf20Sopenharmony_ci index = i + 1; 3948c2ecf20Sopenharmony_ci break; 3958c2ecf20Sopenharmony_ci } 3968c2ecf20Sopenharmony_ci if (index < 0) 3978c2ecf20Sopenharmony_ci return -EINVAL; 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci mutex_lock(&data->lock); 4008c2ecf20Sopenharmony_ci ret = stk8312_set_range(data, index); 4018c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ci return ret; 4048c2ecf20Sopenharmony_ci case IIO_CHAN_INFO_SAMP_FREQ: 4058c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(stk8312_samp_freq_table); i++) 4068c2ecf20Sopenharmony_ci if (val == stk8312_samp_freq_table[i].val && 4078c2ecf20Sopenharmony_ci val2 == stk8312_samp_freq_table[i].val2) { 4088c2ecf20Sopenharmony_ci index = i; 4098c2ecf20Sopenharmony_ci break; 4108c2ecf20Sopenharmony_ci } 4118c2ecf20Sopenharmony_ci if (index < 0) 4128c2ecf20Sopenharmony_ci return -EINVAL; 4138c2ecf20Sopenharmony_ci mutex_lock(&data->lock); 4148c2ecf20Sopenharmony_ci ret = stk8312_set_sample_rate(data, index); 4158c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_ci return ret; 4188c2ecf20Sopenharmony_ci } 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_ci return -EINVAL; 4218c2ecf20Sopenharmony_ci} 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_cistatic const struct iio_info stk8312_info = { 4248c2ecf20Sopenharmony_ci .read_raw = stk8312_read_raw, 4258c2ecf20Sopenharmony_ci .write_raw = stk8312_write_raw, 4268c2ecf20Sopenharmony_ci .attrs = &stk8312_attribute_group, 4278c2ecf20Sopenharmony_ci}; 4288c2ecf20Sopenharmony_ci 4298c2ecf20Sopenharmony_cistatic irqreturn_t stk8312_trigger_handler(int irq, void *p) 4308c2ecf20Sopenharmony_ci{ 4318c2ecf20Sopenharmony_ci struct iio_poll_func *pf = p; 4328c2ecf20Sopenharmony_ci struct iio_dev *indio_dev = pf->indio_dev; 4338c2ecf20Sopenharmony_ci struct stk8312_data *data = iio_priv(indio_dev); 4348c2ecf20Sopenharmony_ci int bit, ret, i = 0; 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci mutex_lock(&data->lock); 4378c2ecf20Sopenharmony_ci /* 4388c2ecf20Sopenharmony_ci * Do a bulk read if all channels are requested, 4398c2ecf20Sopenharmony_ci * from 0x00 (XOUT) to 0x02 (ZOUT) 4408c2ecf20Sopenharmony_ci */ 4418c2ecf20Sopenharmony_ci if (*(indio_dev->active_scan_mask) == STK8312_ALL_CHANNEL_MASK) { 4428c2ecf20Sopenharmony_ci ret = i2c_smbus_read_i2c_block_data(data->client, 4438c2ecf20Sopenharmony_ci STK8312_REG_XOUT, 4448c2ecf20Sopenharmony_ci STK8312_ALL_CHANNEL_SIZE, 4458c2ecf20Sopenharmony_ci data->scan.chans); 4468c2ecf20Sopenharmony_ci if (ret < STK8312_ALL_CHANNEL_SIZE) { 4478c2ecf20Sopenharmony_ci dev_err(&data->client->dev, "register read failed\n"); 4488c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 4498c2ecf20Sopenharmony_ci goto err; 4508c2ecf20Sopenharmony_ci } 4518c2ecf20Sopenharmony_ci } else { 4528c2ecf20Sopenharmony_ci for_each_set_bit(bit, indio_dev->active_scan_mask, 4538c2ecf20Sopenharmony_ci indio_dev->masklength) { 4548c2ecf20Sopenharmony_ci ret = stk8312_read_accel(data, bit); 4558c2ecf20Sopenharmony_ci if (ret < 0) { 4568c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 4578c2ecf20Sopenharmony_ci goto err; 4588c2ecf20Sopenharmony_ci } 4598c2ecf20Sopenharmony_ci data->scan.chans[i++] = ret; 4608c2ecf20Sopenharmony_ci } 4618c2ecf20Sopenharmony_ci } 4628c2ecf20Sopenharmony_ci mutex_unlock(&data->lock); 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_ci iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, 4658c2ecf20Sopenharmony_ci pf->timestamp); 4668c2ecf20Sopenharmony_cierr: 4678c2ecf20Sopenharmony_ci iio_trigger_notify_done(indio_dev->trig); 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_ci return IRQ_HANDLED; 4708c2ecf20Sopenharmony_ci} 4718c2ecf20Sopenharmony_ci 4728c2ecf20Sopenharmony_cistatic irqreturn_t stk8312_data_rdy_trig_poll(int irq, void *private) 4738c2ecf20Sopenharmony_ci{ 4748c2ecf20Sopenharmony_ci struct iio_dev *indio_dev = private; 4758c2ecf20Sopenharmony_ci struct stk8312_data *data = iio_priv(indio_dev); 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_ci if (data->dready_trigger_on) 4788c2ecf20Sopenharmony_ci iio_trigger_poll(data->dready_trig); 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci return IRQ_HANDLED; 4818c2ecf20Sopenharmony_ci} 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_cistatic int stk8312_buffer_preenable(struct iio_dev *indio_dev) 4848c2ecf20Sopenharmony_ci{ 4858c2ecf20Sopenharmony_ci struct stk8312_data *data = iio_priv(indio_dev); 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ci return stk8312_set_mode(data, data->mode | STK8312_MODE_ACTIVE); 4888c2ecf20Sopenharmony_ci} 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_cistatic int stk8312_buffer_postdisable(struct iio_dev *indio_dev) 4918c2ecf20Sopenharmony_ci{ 4928c2ecf20Sopenharmony_ci struct stk8312_data *data = iio_priv(indio_dev); 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci return stk8312_set_mode(data, data->mode & (~STK8312_MODE_ACTIVE)); 4958c2ecf20Sopenharmony_ci} 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_cistatic const struct iio_buffer_setup_ops stk8312_buffer_setup_ops = { 4988c2ecf20Sopenharmony_ci .preenable = stk8312_buffer_preenable, 4998c2ecf20Sopenharmony_ci .postdisable = stk8312_buffer_postdisable, 5008c2ecf20Sopenharmony_ci}; 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_cistatic int stk8312_probe(struct i2c_client *client, 5038c2ecf20Sopenharmony_ci const struct i2c_device_id *id) 5048c2ecf20Sopenharmony_ci{ 5058c2ecf20Sopenharmony_ci int ret; 5068c2ecf20Sopenharmony_ci struct iio_dev *indio_dev; 5078c2ecf20Sopenharmony_ci struct stk8312_data *data; 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 5108c2ecf20Sopenharmony_ci if (!indio_dev) { 5118c2ecf20Sopenharmony_ci dev_err(&client->dev, "iio allocation failed!\n"); 5128c2ecf20Sopenharmony_ci return -ENOMEM; 5138c2ecf20Sopenharmony_ci } 5148c2ecf20Sopenharmony_ci 5158c2ecf20Sopenharmony_ci data = iio_priv(indio_dev); 5168c2ecf20Sopenharmony_ci data->client = client; 5178c2ecf20Sopenharmony_ci i2c_set_clientdata(client, indio_dev); 5188c2ecf20Sopenharmony_ci mutex_init(&data->lock); 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ci indio_dev->info = &stk8312_info; 5218c2ecf20Sopenharmony_ci indio_dev->name = STK8312_DRIVER_NAME; 5228c2ecf20Sopenharmony_ci indio_dev->modes = INDIO_DIRECT_MODE; 5238c2ecf20Sopenharmony_ci indio_dev->channels = stk8312_channels; 5248c2ecf20Sopenharmony_ci indio_dev->num_channels = ARRAY_SIZE(stk8312_channels); 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_ci /* A software reset is recommended at power-on */ 5278c2ecf20Sopenharmony_ci ret = i2c_smbus_write_byte_data(data->client, STK8312_REG_RESET, 0x00); 5288c2ecf20Sopenharmony_ci if (ret < 0) { 5298c2ecf20Sopenharmony_ci dev_err(&client->dev, "failed to reset sensor\n"); 5308c2ecf20Sopenharmony_ci return ret; 5318c2ecf20Sopenharmony_ci } 5328c2ecf20Sopenharmony_ci data->sample_rate_idx = STK8312_SR_400HZ_IDX; 5338c2ecf20Sopenharmony_ci ret = stk8312_set_range(data, STK8312_RNG_6G); 5348c2ecf20Sopenharmony_ci if (ret < 0) 5358c2ecf20Sopenharmony_ci return ret; 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_ci ret = stk8312_set_mode(data, 5388c2ecf20Sopenharmony_ci STK8312_MODE_INT_AH_PP | STK8312_MODE_ACTIVE); 5398c2ecf20Sopenharmony_ci if (ret < 0) 5408c2ecf20Sopenharmony_ci return ret; 5418c2ecf20Sopenharmony_ci 5428c2ecf20Sopenharmony_ci if (client->irq > 0) { 5438c2ecf20Sopenharmony_ci ret = devm_request_threaded_irq(&client->dev, client->irq, 5448c2ecf20Sopenharmony_ci stk8312_data_rdy_trig_poll, 5458c2ecf20Sopenharmony_ci NULL, 5468c2ecf20Sopenharmony_ci IRQF_TRIGGER_RISING | 5478c2ecf20Sopenharmony_ci IRQF_ONESHOT, 5488c2ecf20Sopenharmony_ci STK8312_IRQ_NAME, 5498c2ecf20Sopenharmony_ci indio_dev); 5508c2ecf20Sopenharmony_ci if (ret < 0) { 5518c2ecf20Sopenharmony_ci dev_err(&client->dev, "request irq %d failed\n", 5528c2ecf20Sopenharmony_ci client->irq); 5538c2ecf20Sopenharmony_ci goto err_power_off; 5548c2ecf20Sopenharmony_ci } 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_ci data->dready_trig = devm_iio_trigger_alloc(&client->dev, 5578c2ecf20Sopenharmony_ci "%s-dev%d", 5588c2ecf20Sopenharmony_ci indio_dev->name, 5598c2ecf20Sopenharmony_ci indio_dev->id); 5608c2ecf20Sopenharmony_ci if (!data->dready_trig) { 5618c2ecf20Sopenharmony_ci ret = -ENOMEM; 5628c2ecf20Sopenharmony_ci goto err_power_off; 5638c2ecf20Sopenharmony_ci } 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ci data->dready_trig->dev.parent = &client->dev; 5668c2ecf20Sopenharmony_ci data->dready_trig->ops = &stk8312_trigger_ops; 5678c2ecf20Sopenharmony_ci iio_trigger_set_drvdata(data->dready_trig, indio_dev); 5688c2ecf20Sopenharmony_ci ret = iio_trigger_register(data->dready_trig); 5698c2ecf20Sopenharmony_ci if (ret) { 5708c2ecf20Sopenharmony_ci dev_err(&client->dev, "iio trigger register failed\n"); 5718c2ecf20Sopenharmony_ci goto err_power_off; 5728c2ecf20Sopenharmony_ci } 5738c2ecf20Sopenharmony_ci } 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_ci ret = iio_triggered_buffer_setup(indio_dev, 5768c2ecf20Sopenharmony_ci iio_pollfunc_store_time, 5778c2ecf20Sopenharmony_ci stk8312_trigger_handler, 5788c2ecf20Sopenharmony_ci &stk8312_buffer_setup_ops); 5798c2ecf20Sopenharmony_ci if (ret < 0) { 5808c2ecf20Sopenharmony_ci dev_err(&client->dev, "iio triggered buffer setup failed\n"); 5818c2ecf20Sopenharmony_ci goto err_trigger_unregister; 5828c2ecf20Sopenharmony_ci } 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci ret = iio_device_register(indio_dev); 5858c2ecf20Sopenharmony_ci if (ret < 0) { 5868c2ecf20Sopenharmony_ci dev_err(&client->dev, "device_register failed\n"); 5878c2ecf20Sopenharmony_ci goto err_buffer_cleanup; 5888c2ecf20Sopenharmony_ci } 5898c2ecf20Sopenharmony_ci 5908c2ecf20Sopenharmony_ci return 0; 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_cierr_buffer_cleanup: 5938c2ecf20Sopenharmony_ci iio_triggered_buffer_cleanup(indio_dev); 5948c2ecf20Sopenharmony_cierr_trigger_unregister: 5958c2ecf20Sopenharmony_ci if (data->dready_trig) 5968c2ecf20Sopenharmony_ci iio_trigger_unregister(data->dready_trig); 5978c2ecf20Sopenharmony_cierr_power_off: 5988c2ecf20Sopenharmony_ci stk8312_set_mode(data, STK8312_MODE_STANDBY); 5998c2ecf20Sopenharmony_ci return ret; 6008c2ecf20Sopenharmony_ci} 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_cistatic int stk8312_remove(struct i2c_client *client) 6038c2ecf20Sopenharmony_ci{ 6048c2ecf20Sopenharmony_ci struct iio_dev *indio_dev = i2c_get_clientdata(client); 6058c2ecf20Sopenharmony_ci struct stk8312_data *data = iio_priv(indio_dev); 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci iio_device_unregister(indio_dev); 6088c2ecf20Sopenharmony_ci iio_triggered_buffer_cleanup(indio_dev); 6098c2ecf20Sopenharmony_ci 6108c2ecf20Sopenharmony_ci if (data->dready_trig) 6118c2ecf20Sopenharmony_ci iio_trigger_unregister(data->dready_trig); 6128c2ecf20Sopenharmony_ci 6138c2ecf20Sopenharmony_ci return stk8312_set_mode(data, STK8312_MODE_STANDBY); 6148c2ecf20Sopenharmony_ci} 6158c2ecf20Sopenharmony_ci 6168c2ecf20Sopenharmony_ci#ifdef CONFIG_PM_SLEEP 6178c2ecf20Sopenharmony_cistatic int stk8312_suspend(struct device *dev) 6188c2ecf20Sopenharmony_ci{ 6198c2ecf20Sopenharmony_ci struct stk8312_data *data; 6208c2ecf20Sopenharmony_ci 6218c2ecf20Sopenharmony_ci data = iio_priv(i2c_get_clientdata(to_i2c_client(dev))); 6228c2ecf20Sopenharmony_ci 6238c2ecf20Sopenharmony_ci return stk8312_set_mode(data, data->mode & (~STK8312_MODE_ACTIVE)); 6248c2ecf20Sopenharmony_ci} 6258c2ecf20Sopenharmony_ci 6268c2ecf20Sopenharmony_cistatic int stk8312_resume(struct device *dev) 6278c2ecf20Sopenharmony_ci{ 6288c2ecf20Sopenharmony_ci struct stk8312_data *data; 6298c2ecf20Sopenharmony_ci 6308c2ecf20Sopenharmony_ci data = iio_priv(i2c_get_clientdata(to_i2c_client(dev))); 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci return stk8312_set_mode(data, data->mode | STK8312_MODE_ACTIVE); 6338c2ecf20Sopenharmony_ci} 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_cistatic SIMPLE_DEV_PM_OPS(stk8312_pm_ops, stk8312_suspend, stk8312_resume); 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci#define STK8312_PM_OPS (&stk8312_pm_ops) 6388c2ecf20Sopenharmony_ci#else 6398c2ecf20Sopenharmony_ci#define STK8312_PM_OPS NULL 6408c2ecf20Sopenharmony_ci#endif 6418c2ecf20Sopenharmony_ci 6428c2ecf20Sopenharmony_cistatic const struct i2c_device_id stk8312_i2c_id[] = { 6438c2ecf20Sopenharmony_ci {"STK8312", 0}, 6448c2ecf20Sopenharmony_ci {} 6458c2ecf20Sopenharmony_ci}; 6468c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, stk8312_i2c_id); 6478c2ecf20Sopenharmony_ci 6488c2ecf20Sopenharmony_cistatic const struct acpi_device_id stk8312_acpi_id[] = { 6498c2ecf20Sopenharmony_ci {"STK8312", 0}, 6508c2ecf20Sopenharmony_ci {} 6518c2ecf20Sopenharmony_ci}; 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(acpi, stk8312_acpi_id); 6548c2ecf20Sopenharmony_ci 6558c2ecf20Sopenharmony_cistatic struct i2c_driver stk8312_driver = { 6568c2ecf20Sopenharmony_ci .driver = { 6578c2ecf20Sopenharmony_ci .name = STK8312_DRIVER_NAME, 6588c2ecf20Sopenharmony_ci .pm = STK8312_PM_OPS, 6598c2ecf20Sopenharmony_ci .acpi_match_table = ACPI_PTR(stk8312_acpi_id), 6608c2ecf20Sopenharmony_ci }, 6618c2ecf20Sopenharmony_ci .probe = stk8312_probe, 6628c2ecf20Sopenharmony_ci .remove = stk8312_remove, 6638c2ecf20Sopenharmony_ci .id_table = stk8312_i2c_id, 6648c2ecf20Sopenharmony_ci}; 6658c2ecf20Sopenharmony_ci 6668c2ecf20Sopenharmony_cimodule_i2c_driver(stk8312_driver); 6678c2ecf20Sopenharmony_ci 6688c2ecf20Sopenharmony_ciMODULE_AUTHOR("Tiberiu Breana <tiberiu.a.breana@intel.com>"); 6698c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("STK8312 3-Axis Accelerometer driver"); 6708c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 671