blob: 3e9a343f2c0e7c0f2bed7e06feed8a8240eacd56 (
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
|
/* 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.
*
* EC-CR50 communication
*/
#include "common.h"
#include "console.h"
#include "gpio.h"
#include "hooks.h"
#include "system.h"
#include "task.h"
#include "uartn.h"
#define CPRINTS(format, args...) cprints(CC_TASK, "EC-COMM: " format, ## args)
/*
* Context of EC-CR50 communication
*/
static struct ec_comm_context_ {
uint8_t uart; /* Current UART ID in packet mode. */
/* UART_NULL if no UART is in packet mode */
} ec_comm_ctx;
/*
* Initialize EC-CR50 communication context.
*/
static void ec_comm_init_(void)
{
ec_comm_ctx.uart = UART_NULL;
if (!board_has_ec_cr50_comm_support())
return;
CPRINTS("Initializtion");
gpio_enable_interrupt(GPIO_EC_PACKET_MODE_EN);
gpio_enable_interrupt(GPIO_EC_PACKET_MODE_DIS);
/* If DIOB3 is already high, then enable the packet mode. */
if (gpio_get_level(GPIO_EC_PACKET_MODE_EN))
ec_comm_packet_mode_en(GPIO_EC_PACKET_MODE_EN);
}
DECLARE_HOOK(HOOK_INIT, ec_comm_init_, HOOK_PRIO_DEFAULT + 1);
void ec_comm_packet_mode_en(enum gpio_signal unsed)
{
disable_sleep(SLEEP_MASK_EC_CR50_COMM);
/* TODO: Initialize packet context */
ec_comm_ctx.uart = UART_EC; /* Enable Packet Mode */
ccd_update_state();
}
void ec_comm_packet_mode_dis(enum gpio_signal unsed)
{
ec_comm_ctx.uart = UART_NULL; /* Disable Packet Mode. */
ccd_update_state();
enable_sleep(SLEEP_MASK_EC_CR50_COMM);
}
int ec_comm_is_uart_in_packet_mode(int uart)
{
return uart == ec_comm_ctx.uart;
}
|