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
|
/* Copyright 2018 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* Arcada ISH board-specific configuration */
#include "console.h"
#include "driver/accel_lis2dh.h"
#include "driver/accelgyro_lsm6dsm.h"
#include "driver/mag_lis2mdl.h"
#include "gpio.h"
#include "hooks.h"
#include "host_command.h"
#include "i2c.h"
#include "lid_switch.h"
#include "motion_sense.h"
#include "power.h"
#include "tablet_mode.h"
#include "task.h"
#include "gpio_list.h" /* has to be included last */
/* I2C port map */
const struct i2c_port_t i2c_ports[] = {
{
.name = "sensor",
.port = I2C_PORT_SENSOR,
.kbps = 1000
},
};
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
/* Sensor config */
static struct mutex g_lid_mutex;
static struct mutex g_lid_mag_mutex;
static struct mutex g_base_mutex;
/* sensor private data */
static struct lsm6dsm_data lsm6dsm_a_data;
static struct stprivate_data g_lis2dh_data;
static struct lis2mdl_private_data lis2mdl_a_data;
/* Matrix to rotate lid sensor into standard reference frame */
const mat33_fp_t lid_rot_ref = {
{ FLOAT_TO_FP(-1), 0, 0},
{ 0, FLOAT_TO_FP(-1), 0},
{ 0, 0, FLOAT_TO_FP(1)}
};
/* Drivers */
struct motion_sensor_t motion_sensors[] = {
[LID_ACCEL] = {
.name = "Lid Accel",
.active_mask = SENSOR_ACTIVE_S0,
.chip = MOTIONSENSE_CHIP_LSM6DS3,
.type = MOTIONSENSE_TYPE_ACCEL,
.location = MOTIONSENSE_LOC_LID,
.drv = &lsm6dsm_drv,
.mutex = &g_lid_mutex,
.drv_data = LSM6DSM_ST_DATA(lsm6dsm_a_data,
MOTIONSENSE_TYPE_ACCEL),
.port = I2C_PORT_SENSOR,
.addr = LSM6DSM_ADDR1,
.rot_standard_ref = &lid_rot_ref,
.default_range = 4, /* g */
.min_frequency = LSM6DSM_ODR_MIN_VAL,
.max_frequency = LSM6DSM_ODR_MAX_VAL,
.config = {
/* EC use accel for angle detection */
[SENSOR_CONFIG_EC_S0] = {
.odr = 13000 | ROUND_UP_FLAG,
},
/* Sensor on for lid angle detection */
[SENSOR_CONFIG_EC_S3] = {
.odr = 13000 | ROUND_UP_FLAG,
},
},
},
[LID_GYRO] = {
.name = "Lid Gyro",
.active_mask = SENSOR_ACTIVE_S0,
.chip = MOTIONSENSE_CHIP_LSM6DS3,
.type = MOTIONSENSE_TYPE_GYRO,
.location = MOTIONSENSE_LOC_LID,
.drv = &lsm6dsm_drv,
.mutex = &g_lid_mutex,
.drv_data = LSM6DSM_ST_DATA(lsm6dsm_a_data,
MOTIONSENSE_TYPE_GYRO),
.port = I2C_PORT_SENSOR,
.addr = LSM6DSM_ADDR1,
.default_range = 1000 | ROUND_UP_FLAG, /* dps */
.rot_standard_ref = &lid_rot_ref,
.min_frequency = LSM6DSM_ODR_MIN_VAL,
.max_frequency = LSM6DSM_ODR_MAX_VAL,
},
[BASE_ACCEL] = {
.name = "Base Accel",
.active_mask = SENSOR_ACTIVE_S0,
.chip = MOTIONSENSE_CHIP_LNG2DM,
.type = MOTIONSENSE_TYPE_ACCEL,
.location = MOTIONSENSE_LOC_BASE,
.drv = &lis2dh_drv,
.mutex = &g_base_mutex,
.drv_data = &g_lis2dh_data,
.port = I2C_PORT_SENSOR,
.addr = LNG2DM_ADDR0,
.rot_standard_ref = NULL, /* Identity matrix */
/* We only use 2g because its resolution is only 8-bits */
.default_range = 2, /* g */
.min_frequency = LIS2DH_ODR_MIN_VAL,
.max_frequency = LIS2DH_ODR_MAX_VAL,
.config = {
/* EC use accel for angle detection */
[SENSOR_CONFIG_EC_S0] = {
.odr = 10000 | ROUND_UP_FLAG,
},
/* Sensor on for lid angle detection */
[SENSOR_CONFIG_EC_S3] = {
.odr = 10000 | ROUND_UP_FLAG,
},
},
},
[LID_MAG] = {
.name = "Lid Mag",
.active_mask = SENSOR_ACTIVE_S0,
.chip = MOTIONSENSE_CHIP_LIS2MDL,
.type = MOTIONSENSE_TYPE_MAG,
.location = MOTIONSENSE_LOC_LID,
.drv = &lis2mdl_drv,
.mutex = &g_lid_mag_mutex,
.drv_data = &lis2mdl_a_data,
.port = I2C_PORT_SENSOR,
.addr = LIS2MDL_ADDR,
.default_range = 1 << 11, /* 16LSB / uT, fixed */
.rot_standard_ref = NULL, /* TODO rotate correctly */
.min_frequency = LIS2MDL_ODR_MIN_VAL,
.max_frequency = LIS2MDL_ODR_MAX_VAL,
},
};
const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
/* Initialize board. */
static void board_init(void)
{
/* Enable interrupt for LSM6DS3 sensor */
gpio_enable_interrupt(GPIO_ACCEL_GYRO_INT_L);
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
#ifdef HAS_TASK_CHIPSET
/* TODO(b/122364080): replace when implement real chipset/power task */
int chipset_in_state(int state_mask)
{
/* Until we know better, ISH assumes AP is always ON */
return state_mask & CHIPSET_STATE_ON;
}
/* TODO(b/122364080): replace when implement real chipset/power task */
int chipset_in_or_transitioning_to_state(int state_mask)
{
/* Until we know better, ISH assumes AP is always ON */
return state_mask & CHIPSET_STATE_ON;
}
/* TODO(b/122364080): replace when implement real chipset/power task */
void chipset_force_shutdown(enum chipset_shutdown_reason reason)
{
}
#endif /* HAS_TASK_CHIPSET */
/* TODO(b/122364080): remove when implement real chipset/power task */
int board_idle_task(void *unused)
{
while (1)
task_wait_event(-1);
}
static void board_tablet_mode_change(void)
{
/* Update GPIO to EC letting it know that we entered tablet mode */
gpio_set_level(GPIO_NB_MODE_L, tablet_get_mode());
}
DECLARE_HOOK(HOOK_TABLET_MODE_CHANGE, board_tablet_mode_change,
HOOK_PRIO_DEFAULT);
|