Merge tag 'v3.10.83' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / linux / hwmsen_helper.h
CommitLineData
6fa3eb70
S
1/* alps
2 *
3 * (C) Copyright 2009
4 * MediaTek <www.MediaTek.com>
5 *
6 * Sensor helper
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22#include <linux/types.h>
23#include <linux/i2c.h>
24#include <linux/hwmsensor.h>
25#ifndef __HWMSEN_HELPER_H__
26#define __HWMSEN_HELPER_H__
27/******************************************************************************
28 * MACRO & DEFINITION
29******************************************************************************/
30#define C_I2C_FIFO_SIZE 8 /*according i2c_mt6516.c */
31#define HWM_TAG "<HWMSEN> "
32#define HWM_FUN(f) printk(HWM_TAG"%s\n", __func__)
33#define HWM_ERR(fmt, args...) printk(HWM_TAG"%s %d : "fmt, __func__, __LINE__, ##args)
34#define HWM_LOG(fmt, args...) printk(HWM_TAG fmt, ##args)
35#define HWM_VER(fmt, args...) printk(HWM_TAG"%s: "fmt, __func__, ##args) /* ((void)0) */
36/******************************************************************************
37 * STRUCTURE & ENUMERATION
38******************************************************************************/
39struct hwmsen_reg {
40 const char *name;
41 u16 addr;
42 u16 mode;
43 u16 mask;
44 u16 len;
45};
46/*----------------------------------------------------------------------------*/
47#define HWMSEN_DUMMY_REG(X) {NULL, X, REG_NA, 0x00, 0}
48/*----------------------------------------------------------------------------*/
49struct hwmsen_reg_test_multi {
50 u8 addr;
51 u8 len;
52 u8 mode;
53 u8 _align;
54};
55/*----------------------------------------------------------------------------*/
56enum {
57 REG_NA = 0x0000,
58 REG_RO = 0x0001,
59 REG_WO = 0x0002,
60 REG_LK = 0x0004, /*lcoked, register test will by-pass this register */
61 REG_RW = REG_RO | REG_WO,
62};
63/*----------------------------------------------------------------------------*/
64/*
65 * @sign, map: only used in accelerometer/magnetic field
66 * sometimes, the sensor output need to be remapped before reporting to framework.
67 * the 'sign' is only -1 or +1 to align the sign for framework's coordinate system
68 * the 'map' align the value for framework's coordinate system. Take accelerometer
69 * as an exmaple:
70 * assume HAL receives original acceleration: acc[] = {100, 0, 100}
71 * sign[] = {1, -1, 1, 0};
72 * map[] = {HWM_CODE_ACC_Y, HWM_CODE_ACC_X, HWM_CODE_ACC_Z, 0};
73 * according to the above 'sign' & 'map', the sensor output need to remap as {y, -x, z}:
74 * float resolution = unit_numerator*GRAVITY_EARTH/unit_denominator;
75 * acc_x = sign[0]*acc[map[0]]*resolution;
76 * acc_y = sign[1]*acc[map[1]]*resolution;
77 * acc_z = sign[2]*acc[map[2]]*resolution;
78 */
79struct hwmsen_convert {
80 s8 sign[C_MAX_HWMSEN_EVENT_NUM];
81 u8 map[C_MAX_HWMSEN_EVENT_NUM];
82};
83/*----------------------------------------------------------------------------*/
84struct hwmsen_conf {
85 s32 sensitivity[C_MAX_HWMSEN_EVENT_NUM]; /*output sensitivity of sensor data */
86 int num;
87};
88/*----------------------------------------------------------------------------*/
89typedef struct hwmsen_reg *(*find_reg_t) (int reg_idx);
90/*----------------------------------------------------------------------------*/
91extern int hwmsen_set_bits(struct i2c_client *client, u8 addr, u8 bits);
92extern int hwmsen_clr_bits(struct i2c_client *client, u8 addr, u8 bits);
93extern int hwmsen_read_byte(struct i2c_client *client, u8 addr, u8 *data);
94extern int hwmsen_write_byte(struct i2c_client *client, u8 addr, u8 data);
95extern int hwmsen_read_block(struct i2c_client *client, u8 addr, u8 *data, u8 len);
96extern int hwmsen_write_block(struct i2c_client *client, u8 addr, u8 *data, u8 len);
97extern void hwmsen_single_rw(struct i2c_client *client, struct hwmsen_reg *regs, int num);
98extern void hwmsen_multi_rw(struct i2c_client *client, find_reg_t findreg,
99 struct hwmsen_reg_test_multi *items, int inum);
100extern ssize_t hwmsen_show_dump(struct i2c_client *client, u8 startAddr, u8 *regtbl, u32 regnum,
101 find_reg_t findreg, char *buf, u32 buflen);
102extern ssize_t hwmsen_read_all_regs(struct i2c_client *client, struct hwmsen_reg *regs, u32 num,
103 char *buf, u32 buflen);
104extern ssize_t hwmsen_show_reg(struct i2c_client *client, u8 addr, char *buf, u32 buflen);
105extern ssize_t hwmsen_store_reg(struct i2c_client *client, u8 addr, const char *buf, size_t count);
106extern ssize_t hwmsen_show_byte(struct device *dev, struct device_attribute *attr, char *buf,
107 u32 buflen);
108extern ssize_t hwmsen_store_byte(struct device *dev, struct device_attribute *attr, const char *buf,
109 size_t count);
110extern ssize_t hwmsen_show_word(struct device *dev, struct device_attribute *attr, char *buf,
111 u32 buflen);
112extern ssize_t hwmsen_store_word(struct device *dev, struct device_attribute *attr, const char *buf,
113 size_t count);
114extern int hwmsen_get_convert(int direction, struct hwmsen_convert *cvt);
115/*----------------------------------------------------------------------------*/
116#endif