加速度传感器 芯片kxtj9 linux 驱动程序

发布于:2024-12-18 ⋅ 阅读:(52) ⋅ 点赞:(0)

/*

  • Copyright © 2011 Kionix, Inc.
  • This program is free software; you can redistribute it and/or modify
  • it under the terms of the GNU General Public License version 2 as
  • published by the Free Software Foundation.
  • This program is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the implied warranty of
  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • GNU General Public License for more details.
  • You should have received a copy of the GNU General Public License
  • along with this program; if not, write to the Free Software
  • Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  • 02111-1307, USA
    */

#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/input.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/input/kxtj9.h>
#include <linux/input-polldev.h>

#define NAME “kxtj9”
#define G_MAX 8000
/* OUTPUT REGISTERS /
#define XOUT_L 0x06
#define WHO_AM_I 0x0F
/
CONTROL REGISTERS /
#define INT_REL 0x1A
#define CTRL_REG1 0x1B
#define INT_CTRL1 0x1E
#define DATA_CTRL 0x21
/
CONTROL REGISTER 1 BITS /
#define PC1_OFF 0x7F
#define PC1_ON (1 << 7)
/
Data ready funtion enable bit: set during probe if using irq mode /
#define DRDYE (1 << 5)
/
DATA CONTROL REGISTER BITS /
#define ODR12_5F 0
#define ODR25F 1
#define ODR50F 2
#define ODR100F 3
#define ODR200F 4
#define ODR400F 5
#define ODR800F 6
/
INTERRUPT CONTROL REGISTER 1 BITS /
/
Set these during probe if using irq mode /
#define KXTJ9_IEL (1 << 3)
#define KXTJ9_IEA (1 << 4)
#define KXTJ9_IEN (1 << 5)
/
INPUT_ABS CONSTANTS /
#define FUZZ 3
#define FLAT 3
/
RESUME STATE INDICES */
#define RES_DATA_CTRL 0
#define RES_CTRL_REG1 1
#define RES_INT_CTRL1 2
#define RESUME_ENTRIES 3

/*

  • The following table lists the maximum appropriate poll interval for each
  • available output data rate.
    */
    static const struct {
    unsigned int cutoff;
    u8 mask;
    } kxtj9_odr_table[] = {
    { 3, ODR800F },
    { 5, ODR400F },
    { 10, ODR200F },
    { 20, ODR100F },
    { 40, ODR50F },
    { 80, ODR25F },
    { 0, ODR12_5F},
    };

struct kxtj9_data {
struct i2c_client *client;
struct kxtj9_platform_data pdata;
struct input_dev *input_dev;
#ifdef CONFIG_INPUT_KXTJ9_POLLED_MODE
struct input_polled_dev *poll_dev;
#endif
unsigned int last_poll_interval;
u8 shift;
u8 ctrl_reg1;
u8 data_ctrl;
u8 int_ctrl;
};

static int kxtj9_i2c_read(struct kxtj9_data *tj9, u8 addr, u8 *data, int len)
{
struct i2c_msg msgs[] = {
{
.addr = tj9->client->addr,
.flags = tj9->client->flags,
.len = 1,
.buf = &addr,
},
{
.addr = tj9->client->addr,
.flags = tj9->client->flags | I2C_M_RD,
.len = len,
.buf = data,
},
};

return i2c_transfer(tj9->client->adapter, msgs, 2);

}

static void kxtj9_report_acceleration_data(struct kxtj9_data tj9)
{
s16 acc_data[3]; /
Data bytes from hardware xL, xH, yL, yH, zL, zH */
s16 x, y, z


网站公告

今日签到

点亮在社区的每一天
去签到