aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/misc/yas529.h
blob: 1e5a7a5ac589f0f04aabe59c258cff57dcc22646 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
 * Copyright (c) 2010 Yamaha Corporation
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston,
 * MA  02110-1301, USA.
 */

#ifndef _YAS529_H_
#define _YAS529_H_

#define YAS529_DEFAULT_THRESHOLD	(1)
#define YAS529_DEFAULT_DISTORTION	(15)
#define YAS529_DEFAULT_SHAPE		(0)

#define __LINUX_KERNEL_DRIVER__

#ifndef STATIC
#define STATIC static
#endif

#ifndef NULL
#define NULL ((void *)0)
#endif

#ifndef FALSE
#define FALSE (0)
#endif

#ifndef TRUE
#define TRUE (!(0))
#endif

#ifndef NELEMS
#define NELEMS(a) ((int)(sizeof(a)/sizeof(a[0])))
#endif

#ifdef __LINUX_KERNEL_DRIVER__
#include <linux/types.h>
#include <asm/uaccess.h>
#include <linux/kernel.h>
#define YLOGD(...) /* printk(KERN_ERR __VA_ARGS__) */
#define YLOGI(...) /* printk(KERN_ERR __VA_ARGS__) */
#define YLOGW(...) /* printk(KERN_WARNING __VA_ARGS__) */
#define YLOGE(...) /* printk(KERN_ERR __VA_ARGS__) */
#else
#include <stdint.h>
#define YLOGD(...)
#define YLOGI(...)
#define YLOGW(...)
#define YLOGE(...)
#endif

#ifndef __UTIMER_H__
#define __UTIMER_H__

struct utimeval {
	int32_t tv_sec;
	int32_t tv_msec;
};

struct utimer {
	struct utimeval prev_time;
	struct utimeval total_time;
	struct utimeval delay_ms;
};

STATIC int utimeval_init(struct utimeval *val);
STATIC int utimeval_is_initial(struct utimeval *val);
STATIC int utimeval_is_overflow(struct utimeval *val);
STATIC struct utimeval utimeval_plus(struct utimeval *first, struct utimeval *second);
STATIC struct utimeval utimeval_minus(struct utimeval *first, struct utimeval *second);
STATIC int utimeval_greater_than(struct utimeval *first, struct utimeval *second);
STATIC int utimeval_greater_or_equal(struct utimeval *first, struct utimeval *second);
STATIC int utimeval_greater_than_zero(struct utimeval *val);
STATIC int utimeval_less_than_zero(struct utimeval *val);
STATIC struct utimeval *msec_to_utimeval(struct utimeval *result, uint32_t msec);
STATIC uint32_t utimeval_to_msec(struct utimeval *val);

STATIC struct utimeval utimer_calc_next_time(struct utimer *ut,
						struct utimeval *cur);
STATIC struct utimeval utimer_current_time(void);
STATIC int utimer_is_timeout(struct utimer *ut);
STATIC int utimer_clear_timeout(struct utimer *ut);
STATIC uint32_t utimer_get_delay(struct utimer *ut);
STATIC int utimer_set_delay(struct utimer *ut, uint32_t delay_ms);
STATIC int utimer_update(struct utimer *ut);
STATIC int utimer_update_with_curtime(struct utimer *ut, struct utimeval *cur);
STATIC uint32_t utimer_sleep_time_with_curtime(struct utimer *ut,
					struct utimeval *cur);
STATIC int utimer_init(struct utimer *ut, uint32_t delay_ms);
STATIC int utimer_clear(struct utimer *ut);
STATIC void utimer_lib_init(void (*func)(int *sec, int *msec));

#endif

#ifndef __YAS529_CDRIVER_H__
#define __YAS529_CDRIVER_H__

# define YAS529_CDRV_CENTER_X  512
# define YAS529_CDRV_CENTER_Y1 512
# define YAS529_CDRV_CENTER_Y2 512
# define YAS529_CDRV_CENTER_T  256
# define YAS529_CDRV_CENTER_I1 512
# define YAS529_CDRV_CENTER_I2 512
# define YAS529_CDRV_CENTER_I3 512

#define YAS529_CDRV_ROUGHOFFSET_MEASURE_OF_VALUE 	33
#define YAS529_CDRV_ROUGHOFFSET_MEASURE_UF_VALUE	0
#define YAS529_CDRV_NORMAL_MEASURE_OF_VALUE		1024
#define YAS529_CDRV_NORMAL_MEASURE_UF_VALUE		1

#define MS3CDRV_CMD_MEASURE_ROUGHOFFSET	0x1
#define MS3CDRV_CMD_MEASURE_XY1Y2T	0x2

#define MS3CDRV_RDSEL_MEASURE		0xc0
#define MS3CDRV_RDSEL_CALREGISTER	0xc8

#define MS3CDRV_WAIT_MEASURE_ROUGHOFFSET	2 /*  1.5[ms] */
#define MS3CDRV_WAIT_MEASURE_XY1Y2T		13 /* 12.3[ms] */

#define MS3CDRV_I2C_SLAVE_ADDRESS	0x2e
#define MS3CDRV_GSENSOR_INITIALIZED	0x01
#define MS3CDRV_MSENSOR_INITIALIZED	0x02

#define YAS529_CDRV_NO_ERROR 		0
#define YAS529_CDRV_ERR_ARG 		-1
#define YAS529_CDRV_ERR_NOT_INITIALIZED	-3
#define YAS529_CDRV_ERR_BUSY		-4
#define YAS529_CDRV_ERR_I2CCTRL		-5
#define YAS529_CDRV_ERR_ROUGHOFFSET_NOT_WRITTEN -126
#define YAS529_CDRV_ERROR			-127

#define YAS529_CDRV_MEASURE_X_OFUF  0x1
#define YAS529_CDRV_MEASURE_Y1_OFUF 0x2
#define YAS529_CDRV_MEASURE_Y2_OFUF 0x4

STATIC int yas529_cdrv_actuate_initcoil(void);
STATIC int yas529_cdrv_set_rough_offset(const uint8_t *rough_offset);
STATIC int yas529_cdrv_recalc_fine_offset(int32_t *prev_fine_offset,
					int32_t *new_fine_offset,
					uint8_t *prev_rough_offset,
					uint8_t *new_rough_offset);
STATIC int yas529_cdrv_set_transformatiom_matrix(const int8_t *transform);
STATIC int yas529_cdrv_measure_rough_offset(uint8_t *rough_offset);
STATIC int yas529_cdrv_measure(int32_t *msens, int32_t *raw, int16_t *t);
STATIC int yas529_cdrv_init(const int8_t *transform);
STATIC int yas529_cdrv_term(void);

#endif

#ifndef __YAS529_DRIVER_H__
#define __YAS529_DRIVER_H__

#define YAS529_NO_ERROR			0
#define YAS529_ERROR_ARG		YAS529_CDRV_ERR_ARG
#define YAS529_ERROR_NOT_INITIALIZED	YAS529_CDRV_ERR_NOT_INITIALIZED
#define YAS529_ERROR_BUSY		YAS529_CDRV_ERR_BUSY
#define YAS529_ERROR_I2C		YAS529_CDRV_ERR_I2CCTRL
#define YAS529_ERROR_NOT_ACTIVE		-124
#define YAS529_ERROR_ROUGHOFFSET_NOT_WRITTEN	YAS529_CDRV_ERR_ROUGHOFFSET_NOT_WRITTEN
#define YAS529_ERROR_ERROR 			YAS529_CDRV_ERROR
#define YAS529_ERROR_RESTARTSYS		-512

#define YAS529_IOC_GET_DRIVER_STATE	1
#define YAS529_IOC_SET_DRIVER_STATE	2

#define YAS529_REPORT_DATA			0x01
#define YAS529_REPORT_CALIB			0x02
#define YAS529_REPORT_OVERFLOW_OCCURED		0x04
#define YAS529_REPORT_ROUGH_OFFSET_CHANGED	0x08
#define YAS529_REPORT_FINE_OFFSET_CHANGED	0x10

struct yas529_driver_state {
	int32_t fine_offset[3];
	uint8_t rough_offset[3];
	int accuracy;
};

struct geomagnetic_hwdep_driver {
	int (*init)(void);
	int (*term)(void);
	int (*get_enable)(void);
	int (*set_enable)(int enable);
	int (*get_filter_enable)(void);
	int (*set_filter_enable)(int enable);
	int (*get_filter_len)(void);
	int (*set_filter_len)(int len);
	int (*get_delay)(void);
	int (*set_delay)(int delay);
	int (*get_position)(void);
	int (*set_position)(int accuracy);
	int (*measure)(int32_t *magnetic, int32_t *raw, int32_t *accuracy,
			uint32_t *time_delay_ms);
	int (*ioctl)(unsigned int cmd, unsigned long args);

	struct geomagnetic_hwdep_callback {
	int (*lock)(void);
	int (*unlock)(void);
	void (*current_time)(int32_t *sec, int32_t *msec);
	} callback;
};

STATIC int geomagnetic_driver_init(struct geomagnetic_hwdep_driver *hwdep_driver);

#endif

/*
 * Copyright (c) 2010 Yamaha Corporation
 *
 * This software is provided 'as-is', without any express or implied
 * warranty.  In no event will the authors be held liable for any damages
 * arising from the use of this software.
 *
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it
 * freely, subject to the following restrictions:
 *
 * 1. The origin of this software must not be misrepresented; you must not
 *    claim that you wrote the original software. If you use this software
 *    in a product, an acknowledgment in the product documentation would be
 *    appreciated but is not required.
 * 2. Altered source versions must be plainly marked as such, and must not be
 *    misrepresented as being the original software.
 * 3. This notice may not be removed or altered from any source distribution.
 */

#ifndef _YAS529_LINUX_H_
#define _YAS529_LINUX_H_

#define GEOMAGNETIC_I2C_DEVICE_NAME	"yas529"
#define GEOMAGNETIC_DEVICE_NAME		"yas529"
#define GEOMAGNETIC_INPUT_NAME		"magnetic_sensor"
#define GEOMAGNETIC_INPUT_RAW_NAME	"raw_magnetic_sensor"

#endif /* _YAS529_LINUX_H_ */

#endif /* _YAS529_H_ */