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
|
/* Copyright 2020 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.
*/
/* Malefor board-specific configuration */
#include "button.h"
#include "cbi_ec_fw_config.h"
#include "common.h"
#include "driver/ppc/sn5s330.h"
#include "driver/ppc/syv682x.h"
#include "driver/sync.h"
#include "driver/tcpm/ps8xxx.h"
#include "driver/tcpm/tcpci.h"
#include "extpower.h"
#include "fan.h"
#include "fan_chip.h"
#include "gpio.h"
#include "hooks.h"
#include "keyboard_scan.h"
#include "lid_switch.h"
#include "power.h"
#include "power_button.h"
#include "pwm.h"
#include "pwm_chip.h"
#include "switch.h"
#include "system.h"
#include "task.h"
#include "tablet_mode.h"
#include "uart.h"
#include "usbc_ppc.h"
#include "util.h"
#include "gpio_list.h" /* Must come after other header files. */
#define CPRINTS(format, args...) cprints(CC_CHIPSET, format, ## args)
#define CPRINTF(format, args...) cprintf(CC_CHIPSET, format, ## args)
/*
* FW_CONFIG defaults for Malefor if the CBI data is not initialized.
*/
union volteer_cbi_fw_config fw_config_defaults = {
.usb_db = DB_USB3_NO_A,
};
static void board_init(void)
{
/*
* TODO: b/154447182 - Malefor will control power LED and battery LED
* independently, and keep the max brightness of power LED and battery
* LED as 50%.
*/
pwm_enable(PWM_CH_LED4_SIDESEL, 1);
pwm_set_duty(PWM_CH_LED4_SIDESEL, 50);
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
/******************************************************************************/
/* Physical fans. These are logically separate from pwm_channels. */
const struct fan_conf fan_conf_0 = {
.flags = FAN_USE_RPM_MODE,
.ch = MFT_CH_0, /* Use MFT id to control fan */
.pgood_gpio = -1,
.enable_gpio = GPIO_EN_PP5000_FAN,
};
/*
* Fan specs from datasheet:
* Max speed 5900 rpm (+/- 7%), minimum duty cycle 30%.
* Minimum speed not specified by RPM. Set minimum RPM to max speed (with
* margin) x 30%.
* 5900 x 1.07 x 0.30 = 1894, round up to 1900
*/
const struct fan_rpm fan_rpm_0 = {
.rpm_min = 1900,
.rpm_start = 1900,
.rpm_max = 5900,
};
const struct fan_t fans[FAN_CH_COUNT] = {
[FAN_CH_0] = {
.conf = &fan_conf_0,
.rpm = &fan_rpm_0,
},
};
/******************************************************************************/
/* MFT channels. These are logically separate from pwm_channels. */
const struct mft_t mft_channels[] = {
[MFT_CH_0] = {
.module = NPCX_MFT_MODULE_1,
.clk_src = TCKC_LFCLK,
.pwm_id = PWM_CH_FAN,
},
};
BUILD_ASSERT(ARRAY_SIZE(mft_channels) == MFT_CH_COUNT);
/******************************************************************************/
/* I2C port map configuration */
const struct i2c_port_t i2c_ports[] = {
{
.name = "usb_c0",
.port = I2C_PORT_USB_C0,
.kbps = 1000,
.scl = GPIO_EC_I2C1_USB_C0_SCL,
.sda = GPIO_EC_I2C1_USB_C0_SDA,
},
{
.name = "usb_c1",
.port = I2C_PORT_USB_C1,
.kbps = 1000,
.scl = GPIO_EC_I2C2_USB_C1_SCL,
.sda = GPIO_EC_I2C2_USB_C1_SDA,
},
{
.name = "lightbar",
.port = I2C_PORT_LIGHTBAR,
.kbps = 400,
.scl = GPIO_EC_I2C3_LEDBAR_SCL,
.sda = GPIO_EC_I2C3_LEDBAR_SDA,
},
{
.name = "power",
.port = I2C_PORT_POWER,
.kbps = 100,
.scl = GPIO_EC_I2C5_POWER_SCL,
.sda = GPIO_EC_I2C5_POWER_SDA,
},
{
.name = "eeprom",
.port = I2C_PORT_EEPROM,
.kbps = 400,
.scl = GPIO_EC_I2C7_EEPROM_SCL,
.sda = GPIO_EC_I2C7_EEPROM_SDA,
},
};
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
/******************************************************************************/
/* PWM configuration */
const struct pwm_t pwm_channels[] = {
[PWM_CH_LED4_SIDESEL] = {
.channel = 7,
.flags = PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP,
/* Run at a higher frequency than the color PWM signals to avoid
* timing-based color shifts.
*/
.freq = 4800,
},
[PWM_CH_FAN] = {
.channel = 5,
.flags = PWM_CONFIG_OPEN_DRAIN,
.freq = 25000
},
[PWM_CH_KBLIGHT] = {
.channel = 3,
.flags = 0,
/*
* Set PWM frequency to multiple of 50 Hz and 60 Hz to prevent
* flicker. Higher frequencies consume similar average power to
* lower PWM frequencies, but higher frequencies record a much
* lower maximum power.
*/
.freq = 2400,
},
};
BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT);
/* USBC TCPC configuration for port 1 on USB3 board */
static const struct tcpc_config_t tcpc_config_p1_usb3 = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_USB_C1,
.addr_flags = PS8751_I2C_ADDR1_FLAGS,
},
.flags = TCPC_FLAGS_TCPCI_REV2_0 | TCPC_FLAGS_TCPCI_REV2_0_NO_VSAFE0V,
.drv = &ps8xxx_tcpm_drv,
.usb23 = USBC_PORT_1_USB2_NUM | (USBC_PORT_1_USB3_NUM << 4),
};
static const struct usb_mux usbc1_usb3_db_retimer = {
.usb_port = USBC_PORT_C1,
.driver = &tcpci_tcpm_usb_mux_driver,
.hpd_update = &ps8xxx_tcpc_update_hpd_status,
.next_mux = NULL,
};
static const struct usb_mux mux_config_p1_usb3 = {
.usb_port = USBC_PORT_C1,
.driver = &virtual_usb_mux_driver,
.hpd_update = &virtual_hpd_update,
.next_mux = &usbc1_usb3_db_retimer,
};
void board_reset_pd_mcu(void)
{
/* TODO(b/159024035): Malefor: check USB PD reset operation */
}
__override void board_cbi_init(void)
{
/* Config DB USB3 */
tcpc_config[USBC_PORT_C1] = tcpc_config_p1_usb3;
usb_muxes[USBC_PORT_C1] = mux_config_p1_usb3;
}
/******************************************************************************/
/* USBC PPC configuration */
struct ppc_config_t ppc_chips[] = {
[USBC_PORT_C0] = {
.i2c_port = I2C_PORT_USB_C0,
.i2c_addr_flags = SN5S330_ADDR0_FLAGS,
.drv = &sn5s330_drv,
},
[USBC_PORT_C1] = {
.i2c_port = I2C_PORT_USB_C1,
.i2c_addr_flags = SYV682X_ADDR0_FLAGS,
.drv = &syv682x_drv,
},
};
BUILD_ASSERT(ARRAY_SIZE(ppc_chips) == USBC_PORT_COUNT);
unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips);
/******************************************************************************/
/* PPC support routines */
void ppc_interrupt(enum gpio_signal signal)
{
switch (signal) {
case GPIO_USB_C0_PPC_INT_ODL:
sn5s330_interrupt(USBC_PORT_C0);
break;
case GPIO_USB_C1_PPC_INT_ODL:
syv682x_interrupt(USBC_PORT_C1);
default:
break;
}
}
|