Path: blob/master/drivers/misc/lis3lv02d/lis3lv02d.h
15111 views
/*1* lis3lv02d.h - ST LIS3LV02DL accelerometer driver2*3* Copyright (C) 2007-2008 Yan Burman4* Copyright (C) 2008-2009 Eric Piel5*6* This program is free software; you can redistribute it and/or modify7* it under the terms of the GNU General Public License as published by8* the Free Software Foundation; either version 2 of the License, or9* (at your option) any later version.10*11* This program is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14* GNU General Public License for more details.15*16* You should have received a copy of the GNU General Public License17* along with this program; if not, write to the Free Software18* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA19*/20#include <linux/platform_device.h>21#include <linux/input-polldev.h>22#include <linux/regulator/consumer.h>2324/*25* This driver tries to support the "digital" accelerometer chips from26* STMicroelectronics such as LIS3LV02DL, LIS302DL, LIS3L02DQ, LIS331DL,27* LIS35DE, or LIS202DL. They are very similar in terms of programming, with28* almost the same registers. In addition to differing on physical properties,29* they differ on the number of axes (2/3), precision (8/12 bits), and special30* features (freefall detection, click...). Unfortunately, not all the31* differences can be probed via a register.32* They can be connected either via I²C or SPI.33*/3435#include <linux/lis3lv02d.h>3637enum lis3_reg {38WHO_AM_I = 0x0F,39OFFSET_X = 0x16,40OFFSET_Y = 0x17,41OFFSET_Z = 0x18,42GAIN_X = 0x19,43GAIN_Y = 0x1A,44GAIN_Z = 0x1B,45CTRL_REG1 = 0x20,46CTRL_REG2 = 0x21,47CTRL_REG3 = 0x22,48CTRL_REG4 = 0x23,49HP_FILTER_RESET = 0x23,50STATUS_REG = 0x27,51OUTX_L = 0x28,52OUTX_H = 0x29,53OUTX = 0x29,54OUTY_L = 0x2A,55OUTY_H = 0x2B,56OUTY = 0x2B,57OUTZ_L = 0x2C,58OUTZ_H = 0x2D,59OUTZ = 0x2D,60};6162enum lis302d_reg {63FF_WU_CFG_1 = 0x30,64FF_WU_SRC_1 = 0x31,65FF_WU_THS_1 = 0x32,66FF_WU_DURATION_1 = 0x33,67FF_WU_CFG_2 = 0x34,68FF_WU_SRC_2 = 0x35,69FF_WU_THS_2 = 0x36,70FF_WU_DURATION_2 = 0x37,71CLICK_CFG = 0x38,72CLICK_SRC = 0x39,73CLICK_THSY_X = 0x3B,74CLICK_THSZ = 0x3C,75CLICK_TIMELIMIT = 0x3D,76CLICK_LATENCY = 0x3E,77CLICK_WINDOW = 0x3F,78};7980enum lis3lv02d_reg {81FF_WU_CFG = 0x30,82FF_WU_SRC = 0x31,83FF_WU_ACK = 0x32,84FF_WU_THS_L = 0x34,85FF_WU_THS_H = 0x35,86FF_WU_DURATION = 0x36,87DD_CFG = 0x38,88DD_SRC = 0x39,89DD_ACK = 0x3A,90DD_THSI_L = 0x3C,91DD_THSI_H = 0x3D,92DD_THSE_L = 0x3E,93DD_THSE_H = 0x3F,94};9596enum lis3_who_am_i {97WAI_3DC = 0x33, /* 8 bits: LIS3DC, HP3DC */98WAI_12B = 0x3A, /* 12 bits: LIS3LV02D[LQ]... */99WAI_8B = 0x3B, /* 8 bits: LIS[23]02D[LQ]... */100WAI_6B = 0x52, /* 6 bits: LIS331DLF - not supported */101};102103enum lis3lv02d_ctrl1_12b {104CTRL1_Xen = 0x01,105CTRL1_Yen = 0x02,106CTRL1_Zen = 0x04,107CTRL1_ST = 0x08,108CTRL1_DF0 = 0x10,109CTRL1_DF1 = 0x20,110CTRL1_PD0 = 0x40,111CTRL1_PD1 = 0x80,112};113114/* Delta to ctrl1_12b version */115enum lis3lv02d_ctrl1_8b {116CTRL1_STM = 0x08,117CTRL1_STP = 0x10,118CTRL1_FS = 0x20,119CTRL1_PD = 0x40,120CTRL1_DR = 0x80,121};122123enum lis3lv02d_ctrl1_3dc {124CTRL1_ODR0 = 0x10,125CTRL1_ODR1 = 0x20,126CTRL1_ODR2 = 0x40,127CTRL1_ODR3 = 0x80,128};129130enum lis3lv02d_ctrl2 {131CTRL2_DAS = 0x01,132CTRL2_SIM = 0x02,133CTRL2_DRDY = 0x04,134CTRL2_IEN = 0x08,135CTRL2_BOOT = 0x10,136CTRL2_BLE = 0x20,137CTRL2_BDU = 0x40, /* Block Data Update */138CTRL2_FS = 0x80, /* Full Scale selection */139};140141enum lis3lv02d_ctrl4_3dc {142CTRL4_SIM = 0x01,143CTRL4_ST0 = 0x02,144CTRL4_ST1 = 0x04,145CTRL4_FS0 = 0x10,146CTRL4_FS1 = 0x20,147};148149enum lis302d_ctrl2 {150HP_FF_WU2 = 0x08,151HP_FF_WU1 = 0x04,152CTRL2_BOOT_8B = 0x40,153};154155enum lis3lv02d_ctrl3 {156CTRL3_CFS0 = 0x01,157CTRL3_CFS1 = 0x02,158CTRL3_FDS = 0x10,159CTRL3_HPFF = 0x20,160CTRL3_HPDD = 0x40,161CTRL3_ECK = 0x80,162};163164enum lis3lv02d_status_reg {165STATUS_XDA = 0x01,166STATUS_YDA = 0x02,167STATUS_ZDA = 0x04,168STATUS_XYZDA = 0x08,169STATUS_XOR = 0x10,170STATUS_YOR = 0x20,171STATUS_ZOR = 0x40,172STATUS_XYZOR = 0x80,173};174175enum lis3lv02d_ff_wu_cfg {176FF_WU_CFG_XLIE = 0x01,177FF_WU_CFG_XHIE = 0x02,178FF_WU_CFG_YLIE = 0x04,179FF_WU_CFG_YHIE = 0x08,180FF_WU_CFG_ZLIE = 0x10,181FF_WU_CFG_ZHIE = 0x20,182FF_WU_CFG_LIR = 0x40,183FF_WU_CFG_AOI = 0x80,184};185186enum lis3lv02d_ff_wu_src {187FF_WU_SRC_XL = 0x01,188FF_WU_SRC_XH = 0x02,189FF_WU_SRC_YL = 0x04,190FF_WU_SRC_YH = 0x08,191FF_WU_SRC_ZL = 0x10,192FF_WU_SRC_ZH = 0x20,193FF_WU_SRC_IA = 0x40,194};195196enum lis3lv02d_dd_cfg {197DD_CFG_XLIE = 0x01,198DD_CFG_XHIE = 0x02,199DD_CFG_YLIE = 0x04,200DD_CFG_YHIE = 0x08,201DD_CFG_ZLIE = 0x10,202DD_CFG_ZHIE = 0x20,203DD_CFG_LIR = 0x40,204DD_CFG_IEND = 0x80,205};206207enum lis3lv02d_dd_src {208DD_SRC_XL = 0x01,209DD_SRC_XH = 0x02,210DD_SRC_YL = 0x04,211DD_SRC_YH = 0x08,212DD_SRC_ZL = 0x10,213DD_SRC_ZH = 0x20,214DD_SRC_IA = 0x40,215};216217enum lis3lv02d_click_src_8b {218CLICK_SINGLE_X = 0x01,219CLICK_DOUBLE_X = 0x02,220CLICK_SINGLE_Y = 0x04,221CLICK_DOUBLE_Y = 0x08,222CLICK_SINGLE_Z = 0x10,223CLICK_DOUBLE_Z = 0x20,224CLICK_IA = 0x40,225};226227enum lis3lv02d_reg_state {228LIS3_REG_OFF = 0x00,229LIS3_REG_ON = 0x01,230};231232union axis_conversion {233struct {234int x, y, z;235};236int as_array[3];237238};239240struct lis3lv02d {241void *bus_priv; /* used by the bus layer only */242struct device *pm_dev; /* for pm_runtime purposes */243int (*init) (struct lis3lv02d *lis3);244int (*write) (struct lis3lv02d *lis3, int reg, u8 val);245int (*read) (struct lis3lv02d *lis3, int reg, u8 *ret);246int (*blkread) (struct lis3lv02d *lis3, int reg, int len, u8 *ret);247int (*reg_ctrl) (struct lis3lv02d *lis3, bool state);248249int *odrs; /* Supported output data rates */250u8 *regs; /* Regs to store / restore */251int regs_size;252u8 *reg_cache;253bool regs_stored;254u8 odr_mask; /* ODR bit mask */255u8 whoami; /* indicates measurement precision */256s16 (*read_data) (struct lis3lv02d *lis3, int reg);257int mdps_max_val;258int pwron_delay;259int scale; /*260* relationship between 1 LBS and mG261* (1/1000th of earth gravity)262*/263264struct input_polled_dev *idev; /* input device */265struct platform_device *pdev; /* platform device */266struct regulator_bulk_data regulators[2];267atomic_t count; /* interrupt count after last read */268union axis_conversion ac; /* hw -> logical axis */269int mapped_btns[3];270271u32 irq; /* IRQ number */272struct fasync_struct *async_queue; /* queue for the misc device */273wait_queue_head_t misc_wait; /* Wait queue for the misc device */274unsigned long misc_opened; /* bit0: whether the device is open */275int data_ready_count[2];276atomic_t wake_thread;277unsigned char irq_cfg;278279struct lis3lv02d_platform_data *pdata; /* for passing board config */280struct mutex mutex; /* Serialize poll and selftest */281};282283int lis3lv02d_init_device(struct lis3lv02d *lis3);284int lis3lv02d_joystick_enable(void);285void lis3lv02d_joystick_disable(void);286void lis3lv02d_poweroff(struct lis3lv02d *lis3);287void lis3lv02d_poweron(struct lis3lv02d *lis3);288int lis3lv02d_remove_fs(struct lis3lv02d *lis3);289290extern struct lis3lv02d lis3_dev;291292293