一、dts配置
ps_tmd26353: tmd26353@39 {
compatible = "ps_tmd26353";
reg = <0x39>;
type = <SENSOR_TYPE_PROXIMITY>;
pinctrl-names = "default";
//pinctrl-0 = <&gpio2_c3>;
irq-gpio = <&gpio3 RK_PC3 IRQ_TYPE_LEVEL_LOW>;
irq_enable = <0>;
ps_threshold_high = <0x200>;
ps_threshold_low = <0x100>;
//ps_ctrl_gain = <3>; /* 0:x1 1:x4 2:x16 3:x64 */
//ps_led_current = <3>; /* 0:12.5mA 1:25mA 2:50mA 3:100mA */
poll_delay_ms = <100>;
status = "okay";
};
二、驱动代码
#include <linux/interrupt.h>
#include <linux/i2c.h>
#include <linux/slab.h>
#include <linux/irq.h>
#include <linux/miscdevice.h>
#include <linux/gpio.h>
#include <linux/uaccess.h>
#include <linux/atomic.h>
#include <linux/delay.h>
#include <linux/input.h>
#include <linux/workqueue.h>
#include <linux/freezer.h>
#include <linux/of_gpio.h>
#ifdef CONFIG_HAS_EARLYSUSPEND
#include <linux/earlysuspend.h>
#endif
#include <linux/sensor-dev.h>
/*********************************************
Register
**********************************************/
#define TMD26353_ENABLE_PROXIMITY 0x80
#define TMD26353_PRATE 0x82 //采样时间PRATE
#define TMD26353_PCFG0 0x8E //增益
#define TMD26353_PCFG1 0x8F
#define TMD26353_DEVICE_ID 0x92
#define TMD26353_PDATAL 0x9C //ADC
#define TMD26353_PDATAH 0x9D
#define TMD26353_CFG6_APC 0xAE //使能APC
#define TMD26353_POFFSETL 0xC0 自动校准
#define TMD26353_POFFSETH 0xC1
#define TMD26353_CALIBCFG 0xD9 //样本数量CALIBCFG
#define TMD26353_INT_ENABLE 0xDD
#define TMD26353_INT_STATUS 0x9B //中断状态
#define PS_ENABLE (1 << 2)
static int ps_threshold_low;
static int ps_threshold_high;
enum tmd26353_register_name {
REG_PDATA = 0,
REG_DEVICE_ID = 1,
REG_ENABLE = 2,
REG_POFFSET = 3,
REG_PRATE = 4,
REG_CALIBCFG = 5,
REG_CFG6_APC = 6,
REG_PCFG0 = 7,
REG_PCFG1 = 8,
REG_INT_ENABLE,
};
struct tmd26353_register_desc {
u8 msb;
u8 lsb;
};
static const struct tmd26353_register_desc tmd26353_registers[] = {
[REG_PDATA] = {
.msb =