coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
spiconsole.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <spi-generic.h>
4 #include <spi_flash.h>
5 #include <console/spi.h>
6 
7 static struct spi_slave slave;
8 
9 void spiconsole_init(void) {
10  spi_init();
11  spi_setup_slave(0, 0, &slave);
12 }
13 
14 /*
15  * The EM100 'hyper terminal' specification defines a header of 9 characters.
16  * Because of this, devices with a spi_crop_chunk of less than 10 characters
17  * can't be supported by this standard.
18  *
19  * To add support in romstage, the static struct here and the ones used by
20  * spi_xfer will need to be modified - removed, or mapped into cbmem.
21  *
22  * Because the Dediprog software expects strings, not single characters, and
23  * because of the header overhead, this builds up a buffer to send.
24  */
25 void spiconsole_tx_byte(unsigned char c) {
26  static struct em100_msg msg = {
28  .header.em100_command = EM100_UFIFO_CMD,
29  .header.msg_signature = EM100_MSG_SIGNATURE,
30  .header.msg_type = EM100_MSG_ASCII,
31  .header.msg_length = 0
32  };
33 
34  /* Verify the spi buffer is big enough to send even a single byte */
36  sizeof(struct em100_msg_header) + 1)
37  return;
38 
39  msg.data[msg.header.msg_length] = c;
40  msg.header.msg_length++;
41 
42  /* Send the data on newline or when the max spi length is reached */
43  if (c == '\n' || (sizeof(struct em100_msg_header) +
45  MAX_MSG_LENGTH))) {
46  spi_xfer(&slave, &msg, sizeof(struct em100_msg_header) +
47  msg.header.msg_length, NULL, 0);
48 
49  msg.header.msg_length = 0;
50  }
51 }
@ EM100_MSG_ASCII
Definition: spi.h:36
#define EM100_UFIFO_CMD
Definition: spi.h:28
#define EM100_MSG_SIGNATURE
Definition: spi.h:29
#define MAX_MSG_LENGTH
Definition: spi.h:25
#define EM100_DEDICATED_CMD
Definition: spi.h:27
unsigned int spi_crop_chunk(const struct spi_slave *slave, unsigned int cmd_len, unsigned int buf_len)
Definition: spi-generic.c:79
int spi_xfer(const struct spi_slave *slave, const void *dout, size_t bytesout, void *din, size_t bytesin)
Definition: spi-generic.c:68
void __weak spi_init(void)
Definition: spi-generic.c:117
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
Definition: spi-generic.c:122
void spiconsole_tx_byte(unsigned char c)
Definition: spiconsole.c:25
void spiconsole_init(void)
Definition: spiconsole.c:9
static struct spi_slave slave
Definition: spiconsole.c:7
#define NULL
Definition: stddef.h:19
uint8_t msg_length
Definition: spi.h:47
uint8_t spi_command
Definition: spi.h:42
Definition: spi.h:50
char data[MAX_MSG_LENGTH]
Definition: spi.h:52
struct em100_msg_header header
Definition: spi.h:51
#define c(value, pmcreg, dst_bits)