blob: 68d3219aa094dec36c8a24c3ed990af08390f751 (
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
|
/* Copyright (c) 2011 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.
*/
/* Port 80 module for Chrome EC */
#include "console.h"
#include "port80.h"
#include "uart.h"
#include "util.h"
#define HISTORY_LEN 16
static uint8_t history[HISTORY_LEN];
static int head = 0; /* Next index to use / oldest previous entry */
static int last_data = -1; /* Last data written to port 80 */
void port_80_write(int data)
{
/* Ignore duplicate writes, since the linux kernel writes to port 80
* as a delay mechanism during boot. */
if (data == last_data)
return;
/* TODO: post to SWI and print from there? This currently
* prints from inside the LPC interrupt itself. */
uart_printf("[Port 80: 0x%02x]\n", data);
last_data = data;
history[head] = data;
head = (head + 1) & (HISTORY_LEN - 1);
}
/*****************************************************************************/
/* Console commands */
static int command_port80(int argc, char **argv)
{
int h = head;
int i;
/* Technically, if a port 80 write comes in while we're
* printing this, we could print an incorrect history.
* Probably not worth the complexity to work around that. */
uart_puts("Last port 80 writes:");
for (i = 0; i < HISTORY_LEN; i++)
uart_printf(" %02x", history[(h + i) & (HISTORY_LEN - 1)]);
uart_puts(" <--newest\n");
return EC_SUCCESS;
}
static const struct console_command console_commands[] = {
{"port80", command_port80},
};
static const struct console_group command_group = {
"Port 80", console_commands, ARRAY_SIZE(console_commands)
};
/*****************************************************************************/
/* Initialization */
int port_80_init(void)
{
console_register_commands(&command_group);
memset(history, 0, sizeof(history));
return EC_SUCCESS;
}
|