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
|
/*
* 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 <linux/init.h>
#include <linux/module.h>
#include <linux/dirent.h>
#include "adsp.h"
#define VENDOR "CAPELLA"
#define CHIP_ID "VEML3328"
/*************************************************************************/
/* factory Sysfs */
/*************************************************************************/
static ssize_t light_vendor_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return snprintf(buf, PAGE_SIZE, "%s\n", VENDOR);
}
static ssize_t light_name_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return snprintf(buf, PAGE_SIZE, "%s\n", CHIP_ID);
}
int get_light_sidx(struct adsp_data *data)
{
int ret = MSG_LIGHT;
#ifdef CONFIG_SUPPORT_DUAL_OPTIC
switch (data->fac_fstate) {
case FSTATE_INACTIVE:
case FSTATE_FAC_INACTIVE:
ret = MSG_LIGHT;
break;
case FSTATE_ACTIVE:
case FSTATE_FAC_ACTIVE:
ret = MSG_LIGHT_SUB;
break;
default:
break;
}
#endif
return ret;
}
static ssize_t light_raw_data_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct adsp_data *data = dev_get_drvdata(dev);
uint16_t light_idx = get_light_sidx(data);
uint8_t cnt = 0;
mutex_lock(&data->light_factory_mutex);
adsp_unicast(NULL, 0, light_idx, 0, MSG_TYPE_GET_RAW_DATA);
while (!(data->ready_flag[MSG_TYPE_GET_RAW_DATA] & 1 << light_idx) &&
cnt++ < TIMEOUT_CNT)
usleep_range(500, 550);
data->ready_flag[MSG_TYPE_GET_RAW_DATA] &= ~(1 << light_idx);
if (cnt >= TIMEOUT_CNT) {
pr_err("[FACTORY] %s: Timeout!!!\n", __func__);
mutex_unlock(&data->light_factory_mutex);
return snprintf(buf, PAGE_SIZE, "0,0,0,0,0,0\n");
}
mutex_unlock(&data->light_factory_mutex);
return snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d,%d,%d\n",
data->msg_buf[light_idx][0], data->msg_buf[light_idx][1],
data->msg_buf[light_idx][2], data->msg_buf[light_idx][3],
data->msg_buf[light_idx][4], data->msg_buf[light_idx][5]);
}
static ssize_t light_get_dhr_sensor_info_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct adsp_data *data = dev_get_drvdata(dev);
uint16_t light_idx = get_light_sidx(data);
uint8_t cnt = 0;
pr_info("[FACTORY] %s: start\n", __func__);
mutex_lock(&data->light_factory_mutex);
adsp_unicast(NULL, 0, light_idx, 0, MSG_TYPE_GET_DHR_INFO);
while (!(data->ready_flag[MSG_TYPE_GET_DHR_INFO] & 1 << light_idx) &&
cnt++ < TIMEOUT_CNT)
usleep_range(500, 550);
data->ready_flag[MSG_TYPE_GET_DHR_INFO] &= ~(1 << light_idx);
if (cnt >= TIMEOUT_CNT)
pr_err("[FACTORY] %s: Timeout!!!\n", __func__);
mutex_unlock(&data->light_factory_mutex);
return data->msg_buf[light_idx][0];
}
static DEVICE_ATTR(vendor, 0444, light_vendor_show, NULL);
static DEVICE_ATTR(name, 0444, light_name_show, NULL);
static DEVICE_ATTR(lux, 0444, light_raw_data_show, NULL);
static DEVICE_ATTR(raw_data, 0444, light_raw_data_show, NULL);
static DEVICE_ATTR(dhr_sensor_info, 0444, light_get_dhr_sensor_info_show, NULL);
static struct device_attribute *light_attrs[] = {
&dev_attr_vendor,
&dev_attr_name,
&dev_attr_lux,
&dev_attr_raw_data,
&dev_attr_dhr_sensor_info,
NULL,
};
static int __init veml3328_light_factory_init(void)
{
adsp_factory_register(MSG_LIGHT, light_attrs);
pr_info("[FACTORY] %s\n", __func__);
return 0;
}
static void __exit veml3328_light_factory_exit(void)
{
adsp_factory_unregister(MSG_LIGHT);
pr_info("[FACTORY] %s\n", __func__);
}
module_init(veml3328_light_factory_init);
module_exit(veml3328_light_factory_exit);
|