summaryrefstree
path: root/kernel/drivers/adsp_factory/adsp.h
blob: 6ddcccc12aeafb4e4519c7dd1c67e4da14613000 (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
/*
 *  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.
 *
 */
#ifndef __ADSP_SENSOR_H__
#define __ADSP_SENSOR_H__

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/delay.h>
#include <linux/fs.h>
#include <linux/file.h>
#include <linux/fcntl.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
//#include <linux/sensors.h>
#include <linux/adsp/adsp_ft_common.h>

#define TIMEOUT_CNT 200
#define TIMEOUT_DHR_CNT 50

#define PATH_LEN                 50
#define FILE_BUF_LEN             110
#define ID_INDEX_NUMS            2
#define RETRY_MAX                3
#define VERSION_FILE_NAME_LEN    20
#ifdef CONFIG_SUPPORT_LIGHT_CALIBRATION
#define LIGHT_UB_CELL_ID_INFO_STRING_LENGTH 23
#define UB_CELL_ID_PATH "/sys/class/lcd/panel/SVC_OCTA"
#endif
#ifdef CONFIG_SUPPORT_AK0997X
#define AUTO_CAL_DATA_NUM 19
#define AUTO_CAL_FILE_BUF_LEN 140
#define DIGITAL_HALL_AUTO_CAL_X_PATH "/efs/FactoryApp/digital_hall_auto_cal_x"
#define DIGITAL_HALL_AUTO_CAL_Y_PATH "/efs/FactoryApp/digital_hall_auto_cal_y"
#define DIGITAL_HALL_AUTO_CAL_Z_PATH "/efs/FactoryApp/digital_hall_auto_cal_z"
#endif

enum {
	D_FACTOR,
	R_COEF,
	G_COEF,
	B_COEF,
	C_COEF,
	CT_COEF,
	CT_OFFSET,
	THD_HIGH,
	THD_LOW,
	IRIS_PROX_THD,
	SUM_CRC,
	EFS_SAVE_NUMS,
};

enum {
	ID_UTYPE,
	ID_BLACK,
	ID_WHITE,
	ID_GOLD,
	ID_SILVER,
	ID_GREEN,
	ID_BLUE,
	ID_PINKGOLD,
	ID_MAX,
};

/* Main struct containing all the data */
struct adsp_data {
	struct device *adsp;
	struct device *sensor_device[MSG_SENSOR_MAX];
	struct device_attribute **sensor_attr[MSG_SENSOR_MAX];
#ifdef CONFIG_SUPPORT_MOBEAM
	struct device *mobeam_device;
#ifdef CONFIG_SUPPORT_SUB_MOBEAM
	struct device *sub_mobeam_device;
#endif
#endif
	struct sock *adsp_skt;
	int32_t *msg_buf[MSG_SENSOR_MAX];
	unsigned int ready_flag[MSG_TYPE_MAX];
	bool sysfs_created[MSG_SENSOR_MAX];
	struct mutex prox_factory_mutex;
	struct mutex light_factory_mutex;
	struct mutex accel_factory_mutex;
	struct mutex remove_sysfs_mutex;
#ifdef CONFIG_SUPPORT_AK0997X
	struct mutex digital_hall_mutex;
#endif
	struct notifier_block adsp_nb;
#ifdef CONFIG_VBUS_NOTIFIER
	struct notifier_block vbus_nb;
#endif
	int32_t fac_fstate;
	int32_t temp_reg;
#ifdef CONFIG_SUPPORT_LIGHT_CALIBRATION
	struct delayed_work light_cal_work;
	int32_t light_cal_result;
	int32_t light_cal1;
	int32_t light_cal2;
	int32_t copr_w;
	char light_ub_id[LIGHT_UB_CELL_ID_INFO_STRING_LENGTH];
#endif
	struct delayed_work light_copr_debug_work;
	int light_copr_debug_count;
#ifdef CONFIG_SUPPORT_BRIGHTNESS_NOTIFY_FOR_LIGHT_SENSOR
	struct work_struct light_br_work;
	int32_t brightness_info[2];
#endif
	int32_t pre_bl_level;
#ifdef CONFIG_SUPPORT_PROX_CALIBRATION
	int32_t prox_cal;
#endif
	struct delayed_work accel_cal_work;
	struct delayed_work sub_accel_cal_work;
#ifdef CONFIG_SUPPORT_LIGHT_SEAMLESS
	struct delayed_work light_seamless_work;
#endif
	uint32_t support_algo;
	bool restrict_mode;
	int turn_over_crash;
};

#ifdef CONFIG_SUPPORT_MOBEAM
void adsp_mobeam_register(struct device_attribute *attributes[]);
void adsp_mobeam_unregister(struct device_attribute *attributes[]);
#ifdef CONFIG_SUPPORT_SUB_MOBEAM
void adsp_sub_mobeam_register(struct device_attribute *attributes[]);
void adsp_sub_mobeam_unregister(struct device_attribute *attributes[]);
#endif
#endif
#ifdef CONFIG_SEC_FACTORY
int get_mag_raw_data(int32_t *raw_data);
#endif
int get_accel_raw_data(int32_t *raw_data);
#ifdef CONFIG_SUPPORT_DUAL_6AXIS
int get_sub_accel_raw_data(int32_t *raw_data);
#endif
int get_prox_raw_data(int *raw_data, int *offset);
#ifdef CONFIG_SUPPORT_DUAL_OPTIC
int get_sub_prox_raw_data(int *raw_data, int *offset);
#endif
int adsp_get_sensor_data(int sensor_type);
int adsp_factory_register(unsigned int type,
	struct device_attribute *attributes[]);
int adsp_factory_unregister(unsigned int type);
#if defined(CONFIG_SUPPORT_DEVICE_MODE) || defined(CONFIG_VBUS_NOTIFIER)
struct adsp_data* adsp_ssc_core_register(unsigned int type,
	struct device_attribute *attributes[]);
struct adsp_data* adsp_ssc_core_unregister(unsigned int type);
#endif
int adsp_unicast(void *param, int param_size, u16 sensor_type,
	u32 portid, u16 msg_type);
int sensors_register(struct device **dev, void *drvdata,
	struct device_attribute *attributes[], char *name);
void sensors_unregister(struct device *dev,
	struct device_attribute *attributes[]);
#ifdef CONFIG_SUPPORT_HIDDEN_HOLE
void hidden_hole_init_work(void);
#endif
#ifdef CONFIG_SUPPORT_HIDDEN_HOLE_SUB
void hidden_hole_sub_init_work(void);
#endif
void accel_factory_init_work(struct adsp_data *data);
void accel_cal_work_func(struct work_struct *work);
#ifdef CONFIG_SUPPORT_DUAL_6AXIS
void sub_accel_factory_init_work(struct adsp_data *data);
void sub_accel_cal_work_func(struct work_struct *work);
#endif
#ifdef CONFIG_SUPPORT_DEVICE_MODE
void sns_device_mode_init_work(void);
#endif
#ifdef CONFIG_SUPPORT_DUAL_OPTIC
void sns_flip_init_work(void);
#endif
#ifdef CONFIG_VBUS_NOTIFIER
void sns_vbus_init_work(void);
#endif
#ifdef CONFIG_SUPPORT_LIGHT_CALIBRATION
void light_cal_init_work(struct adsp_data *data);
void light_cal_read_work_func(struct work_struct *work);
int light_load_ub_cell_id_from_file(char *path, char *data_str);
int light_save_ub_cell_id_to_efs(char *data_str, bool first_booting);
#endif
void light_copr_debug_work_func(struct work_struct *work);
#ifdef CONFIG_SUPPORT_PROX_CALIBRATION
void prox_cal_init_work(struct adsp_data *data);
void prox_send_cal_data(struct adsp_data *data, bool fac_cal);
#endif
#ifdef CONFIG_SUPPORT_PROX_POWER_ON_CAL
void prox_factory_init_work(void);
#endif
#ifdef CONFIG_SUPPORT_AK0997X
void digital_hall_factory_auto_cal_init_work(void);
int get_hall_angle_data(int32_t *raw_data);
#endif
#ifdef CONFIG_SUPPORT_LIGHT_SEAMLESS
void light_seamless_work_func(struct work_struct *work);
void light_seamless_init_work(struct adsp_data *data);
#endif
#if defined(CONFIG_SUPPORT_BHL_COMPENSATION_FOR_LIGHT_SENSOR) || \
	defined(CONFIG_SUPPORT_BRIGHT_SYSFS_COMPENSATION_LUX)
int get_light_sidx(struct adsp_data *data);
#endif
#ifdef CONFIG_SUPPORT_BRIGHTNESS_NOTIFY_FOR_LIGHT_SENSOR
struct adsp_data* adsp_get_struct_data(void);
void light_brightness_work_func(struct work_struct *work);
#endif
#endif /* __ADSP_SENSOR_H__ */