Martin Roth | 3a54318 | 2015-09-28 15:27:24 -0600 | [diff] [blame^] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2015 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc. |
| 18 | */ |
| 19 | |
| 20 | #include <spi-generic.h> |
| 21 | #include <spi_flash.h> |
| 22 | #include <console/spi.h> |
| 23 | |
| 24 | void spiconsole_init(void) { |
| 25 | spi_init(); |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | /* |
| 30 | * The EM100 'hyper terminal' specification defines a header of 9 characters. |
| 31 | * Because of this, devices with a spi_crop_chunk of less than 10 characters |
| 32 | * can't be supported by this standard. |
| 33 | * |
| 34 | * To add support in romstage, the static struct here and the ones used by |
| 35 | * spi_xfer will need to be modified - removed, or mapped into cbmem. |
| 36 | * |
| 37 | * Because the Dediprog software expects strings, not single characters, and |
| 38 | * because of the header overhead, this builds up a buffer to send. |
| 39 | */ |
| 40 | void spiconsole_tx_byte(unsigned char c) { |
| 41 | static struct em100_msg msg = { |
| 42 | .header.spi_command = EM100_DEDICATED_CMD, |
| 43 | .header.em100_command = EM100_UFIFO_CMD, |
| 44 | .header.msg_signature = EM100_MSG_SIGNATURE, |
| 45 | .header.msg_type = EM100_MSG_ASCII, |
| 46 | .header.msg_length = 0 |
| 47 | }; |
| 48 | |
| 49 | /* Verify the spi buffer is big enough to send even a single byte */ |
| 50 | if (spi_crop_chunk(0,MAX_MSG_LENGTH) < |
| 51 | sizeof(struct em100_msg_header) + 1) |
| 52 | return; |
| 53 | |
| 54 | msg.data[msg.header.msg_length] = c; |
| 55 | msg.header.msg_length++; |
| 56 | |
| 57 | /* Send the data on newline or when the max spi length is reached */ |
| 58 | if (c == '\n' || (sizeof(struct em100_msg_header) + |
| 59 | msg.header.msg_length == spi_crop_chunk(0, |
| 60 | MAX_MSG_LENGTH))) { |
| 61 | struct spi_slave spi = {.rw = SPI_READ_FLAG}; |
| 62 | |
| 63 | spi_xfer(&spi, &msg, sizeof(struct em100_msg_header) + |
| 64 | msg.header.msg_length, NULL, 0); |
| 65 | |
| 66 | msg.header.msg_length = 0; |
| 67 | } |
| 68 | |
| 69 | return; |
| 70 | } |
| 71 | |