input: misc: fxls8471: add motion sensor fxls8471_i2c

Add Freescale fxls8471 motion sensor support files.

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
This commit is contained in:
Clark Wang 2019-08-14 19:43:02 +08:00 committed by Dong Aisheng
parent 24a8460504
commit d047f4467e
4 changed files with 211 additions and 0 deletions

View File

@ -904,4 +904,9 @@ config INPUT_MPL3115
This driver can also be built as a module. If so, the module
will be called mpl3115
config SENSOR_FXLS8471
tristate "FXLS8471 motion sensor device driver"
depends on I2C
default n
endif

View File

@ -86,3 +86,4 @@ obj-$(CONFIG_INPUT_XEN_KBDDEV_FRONTEND) += xen-kbdfront.o
obj-$(CONFIG_INPUT_YEALINK) += yealink.o
obj-$(CONFIG_INPUT_IDEAPAD_SLIDEBAR) += ideapad_slidebar.o
obj-$(CONFIG_INPUT_MPL3115) += mpl3115.o
obj-$(CONFIG_SENSOR_FXLS8471) += fxls8471.o fxls8471_i2c.o

View File

@ -0,0 +1,94 @@
/*
* fxls8471.h - Linux kernel modules for 3-Axis Accel sensor
* Copyright (C) 2014-2015 Freescale Semiconductor, Inc. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifndef _FXSL8471_H
#define _FXSL8471_H
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/mutex.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/hwmon-sysfs.h>
#include <linux/err.h>
#include <linux/input.h>
#define FXSL8471_ID 0x6a
/* register enum for fxls8471 registers */
enum { FXLS8471_STATUS = 0x00, FXLS8471_OUT_X_MSB, FXLS8471_OUT_X_LSB,
FXLS8471_OUT_Y_MSB, FXLS8471_OUT_Y_LSB, FXLS8471_OUT_Z_MSB,
FXLS8471_OUT_Z_LSB, FXLS8471_F_SETUP =
0x09, FXLS8471_TRIG_CFG, FXLS8471_SYSMOD,
FXLS8471_INT_SOURCE, FXLS8471_WHO_AM_I,
FXLS8471_XYZ_DATA_CFG, FXLS8471_HP_FILTER_CUTOFF,
FXLS8471_PL_STATUS, FXLS8471_PL_CFG, FXLS8471_PL_COUNT,
FXLS8471_PL_BF_ZCOMP, FXLS8471_P_L_THS_REG,
FXLS8471_FF_MT_CFG, FXLS8471_FF_MT_SRC, FXLS8471_FF_MT_THS,
FXLS8471_FF_MT_COUNT, FXLS8471_TRANSIENT_CFG =
0x1D, FXLS8471_TRANSIENT_SRC, FXLS8471_TRANSIENT_THS,
FXLS8471_TRANSIENT_COUNT, FXLS8471_PULSE_CFG,
FXLS8471_PULSE_SRC, FXLS8471_PULSE_THSX, FXLS8471_PULSE_THSY,
FXLS8471_PULSE_THSZ, FXLS8471_PULSE_TMLT,
FXLS8471_PULSE_LTCY, FXLS8471_PULSE_WIND,
FXLS8471_ASLP_COUNT, FXLS8471_CTRL_REG1, FXLS8471_CTRL_REG2,
FXLS8471_CTRL_REG3, FXLS8471_CTRL_REG4, FXLS8471_CTRL_REG5,
FXLS8471_OFF_X, FXLS8471_OFF_Y, FXLS8471_OFF_Z,
FXLS8471_REG_END,
};
enum { STANDBY = 0, ACTIVED,
};
enum { MODE_2G = 0, MODE_4G, MODE_8G,
};
struct fxls8471_data_axis {
short x;
short y;
short z;
};
struct fxls8471_data {
void *bus_priv;
u16 bus_type;
int irq;
s32 (*write)(struct fxls8471_data *pdata, u8 reg, u8 val);
s32 (*read)(struct fxls8471_data *pdata, u8 reg);
s32 (*read_block)(struct fxls8471_data *pdata, u8 reg, u8 len,
u8 *val);
struct input_dev *idev;
atomic_t active;
atomic_t delay;
atomic_t position;
atomic_t range;
u8 chip_id;
};
extern struct fxls8471_data fxls8471_dev;
int fxls8471_driver_init(struct fxls8471_data *pdata);
int fxls8471_driver_remove(struct fxls8471_data *pdata);
int fxls8471_driver_suspend(struct fxls8471_data *pdata);
int fxls8471_driver_resume(struct fxls8471_data *pdata);
#endif /* */

View File

@ -0,0 +1,111 @@
/*
* fxls8471-i2c.c - Linux kernel modules for 3-Axis Smart Orientation
* /Motion Sensor
* Version : 01.00
* Time : Dec.26, 2012
* Author : rick zhang <rick.zhang@freescale.com>
*
* Copyright (C) 2010-2011 Freescale Semiconductor.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/err.h>
#include <linux/i2c.h>
#include "fxls8471.h"
static s32 fxls8471_i2c_write(struct fxls8471_data *pdata, u8 reg, u8 val)
{
struct i2c_client *client = (struct i2c_client *)pdata->bus_priv;
return i2c_smbus_write_byte_data(client, reg, val);
}
static int fxls8471_i2c_read(struct fxls8471_data *pdata, u8 reg)
{
struct i2c_client *client = (struct i2c_client *)pdata->bus_priv;
return i2c_smbus_read_byte_data(client, reg);
}
static int fxls8471_i2c_read_block(struct fxls8471_data *pdata, u8 reg, u8 len,
u8 *val)
{
struct i2c_client *client = (struct i2c_client *)pdata->bus_priv;
return i2c_smbus_read_i2c_block_data(client, reg, len, val);
}
static int fxls8471_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
fxls8471_dev.bus_priv = client;
fxls8471_dev.bus_type = BUS_I2C;
fxls8471_dev.irq = client->irq;
fxls8471_dev.read = fxls8471_i2c_read;
fxls8471_dev.write = fxls8471_i2c_write;
fxls8471_dev.read_block = fxls8471_i2c_read_block;
i2c_set_clientdata(client, &fxls8471_dev);
return fxls8471_driver_init(&fxls8471_dev);
}
static int fxls8471_i2c_remove(struct i2c_client *client)
{
return fxls8471_driver_remove(&fxls8471_dev);
}
#ifdef CONFIG_PM_SLEEP
static int fxls8471_i2c_suspend(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
return fxls8471_driver_suspend(i2c_get_clientdata(client));
}
static int fxls8471_i2c_resume(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
return fxls8471_driver_resume(i2c_get_clientdata(client));
}
#else /* */
#define fxls8471_i2c_suspend NULL
#define fxls8471_i2c_resume NULL
#endif /* */
static const struct i2c_device_id fxls8471_i2c_id[] = {
{"fxls8471", 0},
{}
};
MODULE_DEVICE_TABLE(i2c, fxls8471_i2c_id);
static SIMPLE_DEV_PM_OPS(fxls8471_pm_ops, fxls8471_i2c_suspend,
fxls8471_i2c_resume);
static struct i2c_driver fxls8471_i2c_driver = {
.driver = {
.name = "fxls8471",
.owner = THIS_MODULE,
.pm = &fxls8471_pm_ops,
},
.probe = fxls8471_i2c_probe,
.remove = fxls8471_i2c_remove,
.id_table = fxls8471_i2c_id,
};
module_i2c_driver(fxls8471_i2c_driver);
MODULE_AUTHOR("Freescale Semiconductor, Inc.");
MODULE_DESCRIPTION("FXLS8471 3-Axis Acc Sensor driver");
MODULE_LICENSE("GPL");