summaryrefslogtreecommitdiff
path: root/drivers/sensorhub/stm/ssp_input.c
blob: 072f573a019c2e0d3e92ccce57ed32ab147cd6b7 (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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*
 *  Copyright (C) 2012, Samsung Electronics Co. Ltd. All Rights Reserved.
 *
 *  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.
 *
 */
#include "ssp.h"

/*************************************************************************/
/* SSP Kernel -> HAL input evnet function                                */
/*************************************************************************/
void convert_acc_data(s16 *iValue)
{
	if (*iValue > MAX_ACCEL_2G)
		*iValue = ((MAX_ACCEL_4G - *iValue)) * (-1);
}

void report_acc_data(struct ssp_data *data, struct sensor_value *accdata)
{
	data->buf[ACCELEROMETER_SENSOR].x = accdata->x;
	data->buf[ACCELEROMETER_SENSOR].y = accdata->y;
	data->buf[ACCELEROMETER_SENSOR].z = accdata->z;

	input_report_rel(data->acc_input_dev, REL_X,
		data->buf[ACCELEROMETER_SENSOR].x);
	input_report_rel(data->acc_input_dev, REL_Y,
		data->buf[ACCELEROMETER_SENSOR].y);
	input_report_rel(data->acc_input_dev, REL_Z,
		data->buf[ACCELEROMETER_SENSOR].z);
	input_sync(data->acc_input_dev);
}

void report_gyro_data(struct ssp_data *data, struct sensor_value *gyrodata)
{
	long lTemp[3] = {0,};
	data->buf[GYROSCOPE_SENSOR].x = gyrodata->x;
	data->buf[GYROSCOPE_SENSOR].y = gyrodata->y;
	data->buf[GYROSCOPE_SENSOR].z = gyrodata->z;

	if (data->uGyroDps == GYROSCOPE_DPS500) {
		lTemp[0] = (long)data->buf[GYROSCOPE_SENSOR].x;
		lTemp[1] = (long)data->buf[GYROSCOPE_SENSOR].y;
		lTemp[2] = (long)data->buf[GYROSCOPE_SENSOR].z;
	} else if (data->uGyroDps == GYROSCOPE_DPS250)	{
		lTemp[0] = (long)data->buf[GYROSCOPE_SENSOR].x >> 1;
		lTemp[1] = (long)data->buf[GYROSCOPE_SENSOR].y >> 1;
		lTemp[2] = (long)data->buf[GYROSCOPE_SENSOR].z >> 1;
	} else if (data->uGyroDps == GYROSCOPE_DPS2000)	{
		lTemp[0] = (long)data->buf[GYROSCOPE_SENSOR].x << 2;
		lTemp[1] = (long)data->buf[GYROSCOPE_SENSOR].y << 2;
		lTemp[2] = (long)data->buf[GYROSCOPE_SENSOR].z << 2;
	} else {
		lTemp[0] = (long)data->buf[GYROSCOPE_SENSOR].x;
		lTemp[1] = (long)data->buf[GYROSCOPE_SENSOR].y;
		lTemp[2] = (long)data->buf[GYROSCOPE_SENSOR].z;
	}

	input_report_rel(data->gyro_input_dev, REL_RX, lTemp[0]);
	input_report_rel(data->gyro_input_dev, REL_RY, lTemp[1]);
	input_report_rel(data->gyro_input_dev, REL_RZ, lTemp[2]);
	input_sync(data->gyro_input_dev);
}

#ifdef CONFIG_SENSORS_SSP_ADPD142
void report_hrm_raw_data(struct ssp_data *data, struct sensor_value *hrmdata)
{
	data->buf[BIO_HRM_RAW].ch_a = hrmdata->ch_a;
	data->buf[BIO_HRM_RAW].ch_b = hrmdata->ch_b;
	input_report_rel(data->hrm_raw_input_dev, REL_X, data->buf[BIO_HRM_RAW].ch_a + 1);
	input_report_rel(data->hrm_raw_input_dev, REL_Y, data->buf[BIO_HRM_RAW].ch_b + 1);
	input_report_rel(data->hrm_raw_input_dev, REL_Z, 1);	// Dummy code
	input_sync(data->hrm_raw_input_dev);
}

void report_hrm_raw_fac_data(struct ssp_data *data, struct sensor_value *hrmdata)
{
	data->buf[BIO_HRM_RAW_FAC].ch_a = hrmdata->ch_a;
	data->buf[BIO_HRM_RAW_FAC].ch_b = hrmdata->ch_b;
	data->buf[BIO_HRM_RAW_FAC].frequency = hrmdata->frequency;
	data->buf[BIO_HRM_RAW_FAC].noise_value = hrmdata->noise_value;
	data->buf[BIO_HRM_RAW_FAC].dc_value = hrmdata->dc_value;
	data->buf[BIO_HRM_RAW_FAC].ac_value = hrmdata->ac_value;
	data->buf[BIO_HRM_RAW_FAC].perfusion_rate = hrmdata->perfusion_rate;
	data->buf[BIO_HRM_RAW_FAC].snrac = hrmdata->snrac;
	data->buf[BIO_HRM_RAW_FAC].snrdc = hrmdata->snrdc;
	input_report_rel(data->hrm_raw_input_dev, REL_X, data->buf[BIO_HRM_RAW_FAC].ch_a + 1);
	input_report_rel(data->hrm_raw_input_dev, REL_Y, data->buf[BIO_HRM_RAW_FAC].ch_b + 1);
	input_report_rel(data->hrm_raw_input_dev, REL_Z, 1);	// Dummy code
	input_sync(data->hrm_raw_input_dev);
}

void report_hrm_lib_data(struct ssp_data *data, struct sensor_value *hrmdata)
{
	data->buf[BIO_HRM_LIB].hr = hrmdata->hr;
	data->buf[BIO_HRM_LIB].rri = hrmdata->rri;
	data->buf[BIO_HRM_LIB].snr = hrmdata->snr;

	input_report_rel(data->hrm_lib_input_dev, REL_X, data->buf[BIO_HRM_LIB].hr + 1);
	input_report_rel(data->hrm_lib_input_dev, REL_Y, data->buf[BIO_HRM_LIB].rri + 1);
	input_report_rel(data->hrm_lib_input_dev, REL_Z, data->buf[BIO_HRM_LIB].snr + 1);
	input_sync(data->hrm_lib_input_dev);
}
#endif

int initialize_event_symlink(struct ssp_data *data)
{
	int iRet = 0;

	iRet = sensors_create_symlink(data->acc_input_dev);
	if (iRet < 0)
		goto iRet_acc_sysfs_create_link;

	iRet = sensors_create_symlink(data->gyro_input_dev);
	if (iRet < 0)
		goto iRet_gyro_sysfs_create_link;

#ifdef CONFIG_SENSORS_SSP_ADPD142
	iRet = sensors_create_symlink(data->hrm_raw_input_dev);
	if (iRet < 0)
		goto iRet_hrm_raw_sysfs_create_link;

	iRet = sensors_create_symlink(data->hrm_lib_input_dev);
	if (iRet < 0)
		goto iRet_hrm_lib_sysfs_create_link;
#endif

	return SUCCESS;

#ifdef CONFIG_SENSORS_SSP_ADPD142
iRet_hrm_lib_sysfs_create_link:
	sensors_remove_symlink(data->hrm_raw_input_dev);
iRet_hrm_raw_sysfs_create_link:
	sensors_remove_symlink(data->gyro_input_dev);
#endif
iRet_gyro_sysfs_create_link:
	sensors_remove_symlink(data->acc_input_dev);
iRet_acc_sysfs_create_link:
	ssp_err("could not create event symlink\n");
	return FAIL;
}

void remove_event_symlink(struct ssp_data *data)
{
	sensors_remove_symlink(data->acc_input_dev);
	sensors_remove_symlink(data->gyro_input_dev);
#ifdef CONFIG_SENSORS_SSP_ADPD142
	sensors_remove_symlink(data->hrm_raw_input_dev);
	sensors_remove_symlink(data->hrm_lib_input_dev);
#endif
}

int initialize_input_dev(struct ssp_data *data)
{
	int iRet = 0;

	data->acc_input_dev = input_allocate_device();
	if (data->acc_input_dev == NULL)
		goto err_initialize_acc_input_dev;

	data->acc_input_dev->name = "accelerometer_sensor";
	input_set_capability(data->acc_input_dev, EV_REL, REL_X);
	input_set_capability(data->acc_input_dev, EV_REL, REL_Y);
	input_set_capability(data->acc_input_dev, EV_REL, REL_Z);

	iRet = input_register_device(data->acc_input_dev);
	if (iRet < 0) {
		input_free_device(data->acc_input_dev);
		goto err_initialize_acc_input_dev;
	}
	input_set_drvdata(data->acc_input_dev, data);

	data->gyro_input_dev = input_allocate_device();
	if (data->gyro_input_dev == NULL)
		goto err_initialize_gyro_input_dev;

	data->gyro_input_dev->name = "gyro_sensor";
	input_set_capability(data->gyro_input_dev, EV_REL, REL_RX);
	input_set_capability(data->gyro_input_dev, EV_REL, REL_RY);
	input_set_capability(data->gyro_input_dev, EV_REL, REL_RZ);

	iRet = input_register_device(data->gyro_input_dev);
	if (iRet < 0) {
		input_free_device(data->gyro_input_dev);
		goto err_initialize_gyro_input_dev;
	}
	input_set_drvdata(data->gyro_input_dev, data);

	data->key_input_dev = input_allocate_device();
	if (data->key_input_dev == NULL)
		goto err_initialize_key_input_dev;

	data->key_input_dev->name = "LPM_MOTION";
	input_set_capability(data->key_input_dev, EV_KEY, KEY_HOMEPAGE);

	iRet = input_register_device(data->key_input_dev);
	if (iRet < 0) {
		input_free_device(data->key_input_dev);
		goto err_initialize_key_input_dev;
	}
	input_set_drvdata(data->key_input_dev, data);

#ifdef CONFIG_SENSORS_SSP_ADPD142
	data->hrm_raw_input_dev = input_allocate_device();
	if (data->hrm_raw_input_dev == NULL)
		goto err_initialize_hrm_raw_input_dev;

	data->hrm_raw_input_dev->name = "hrm_raw_sensor";
	input_set_capability(data->hrm_raw_input_dev, EV_REL, REL_X);
	input_set_capability(data->hrm_raw_input_dev, EV_REL, REL_Y);
	input_set_capability(data->hrm_raw_input_dev, EV_REL, REL_Z);

	iRet = input_register_device(data->hrm_raw_input_dev);
	if (iRet < 0) {
		input_free_device(data->hrm_raw_input_dev);
		goto err_initialize_hrm_raw_input_dev;
	}
	input_set_drvdata(data->hrm_raw_input_dev, data);

	data->hrm_lib_input_dev = input_allocate_device();
	if (data->hrm_lib_input_dev == NULL)
		goto err_initialize_hrm_lib_input_dev;

	data->hrm_lib_input_dev->name = "hrm_lib_sensor";
	input_set_capability(data->hrm_lib_input_dev, EV_REL, REL_X);
	input_set_capability(data->hrm_lib_input_dev, EV_REL, REL_Y);
	input_set_capability(data->hrm_lib_input_dev, EV_REL, REL_Z);

	iRet = input_register_device(data->hrm_lib_input_dev);
	if (iRet < 0) {
		input_free_device(data->hrm_lib_input_dev);
		goto err_initialize_hrm_lib_input_dev;
	}
	input_set_drvdata(data->hrm_lib_input_dev, data);
#endif

	return SUCCESS;

#ifdef CONFIG_SENSORS_SSP_ADPD142
err_initialize_hrm_lib_input_dev:
	ssp_err("could not allocate hrm lib input device\n");
	input_unregister_device(data->hrm_raw_input_dev);
err_initialize_hrm_raw_input_dev:
	ssp_err("could not allocate hrm raw input device\n");
	input_unregister_device(data->key_input_dev);
#endif
err_initialize_key_input_dev:
	ssp_err("could not allocate key input device\n");
	input_unregister_device(data->gyro_input_dev);
err_initialize_gyro_input_dev:
	ssp_err("could not allocate gyro input device\n");
	input_unregister_device(data->acc_input_dev);
err_initialize_acc_input_dev:
	ssp_err("could not allocate acc input device\n");
	return ERROR;
}

void remove_input_dev(struct ssp_data *data)
{
	input_unregister_device(data->acc_input_dev);
	input_unregister_device(data->gyro_input_dev);
}