Commit | Line | Data |
---|---|---|
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 | ******************************************************************************/ | |
39 | struct 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 | /*----------------------------------------------------------------------------*/ | |
49 | struct hwmsen_reg_test_multi { | |
50 | u8 addr; | |
51 | u8 len; | |
52 | u8 mode; | |
53 | u8 _align; | |
54 | }; | |
55 | /*----------------------------------------------------------------------------*/ | |
56 | enum { | |
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 | */ | |
79 | struct hwmsen_convert { | |
80 | s8 sign[C_MAX_HWMSEN_EVENT_NUM]; | |
81 | u8 map[C_MAX_HWMSEN_EVENT_NUM]; | |
82 | }; | |
83 | /*----------------------------------------------------------------------------*/ | |
84 | struct hwmsen_conf { | |
85 | s32 sensitivity[C_MAX_HWMSEN_EVENT_NUM]; /*output sensitivity of sensor data */ | |
86 | int num; | |
87 | }; | |
88 | /*----------------------------------------------------------------------------*/ | |
89 | typedef struct hwmsen_reg *(*find_reg_t) (int reg_idx); | |
90 | /*----------------------------------------------------------------------------*/ | |
91 | extern int hwmsen_set_bits(struct i2c_client *client, u8 addr, u8 bits); | |
92 | extern int hwmsen_clr_bits(struct i2c_client *client, u8 addr, u8 bits); | |
93 | extern int hwmsen_read_byte(struct i2c_client *client, u8 addr, u8 *data); | |
94 | extern int hwmsen_write_byte(struct i2c_client *client, u8 addr, u8 data); | |
95 | extern int hwmsen_read_block(struct i2c_client *client, u8 addr, u8 *data, u8 len); | |
96 | extern int hwmsen_write_block(struct i2c_client *client, u8 addr, u8 *data, u8 len); | |
97 | extern void hwmsen_single_rw(struct i2c_client *client, struct hwmsen_reg *regs, int num); | |
98 | extern void hwmsen_multi_rw(struct i2c_client *client, find_reg_t findreg, | |
99 | struct hwmsen_reg_test_multi *items, int inum); | |
100 | extern ssize_t hwmsen_show_dump(struct i2c_client *client, u8 startAddr, u8 *regtbl, u32 regnum, | |
101 | find_reg_t findreg, char *buf, u32 buflen); | |
102 | extern ssize_t hwmsen_read_all_regs(struct i2c_client *client, struct hwmsen_reg *regs, u32 num, | |
103 | char *buf, u32 buflen); | |
104 | extern ssize_t hwmsen_show_reg(struct i2c_client *client, u8 addr, char *buf, u32 buflen); | |
105 | extern ssize_t hwmsen_store_reg(struct i2c_client *client, u8 addr, const char *buf, size_t count); | |
106 | extern ssize_t hwmsen_show_byte(struct device *dev, struct device_attribute *attr, char *buf, | |
107 | u32 buflen); | |
108 | extern ssize_t hwmsen_store_byte(struct device *dev, struct device_attribute *attr, const char *buf, | |
109 | size_t count); | |
110 | extern ssize_t hwmsen_show_word(struct device *dev, struct device_attribute *attr, char *buf, | |
111 | u32 buflen); | |
112 | extern ssize_t hwmsen_store_word(struct device *dev, struct device_attribute *attr, const char *buf, | |
113 | size_t count); | |
114 | extern int hwmsen_get_convert(int direction, struct hwmsen_convert *cvt); | |
115 | /*----------------------------------------------------------------------------*/ | |
116 | #endif |