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. |
Martin Roth | 3a54318 | 2015-09-28 15:27:24 -0600 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <spi-generic.h> |
| 17 | #include <spi_flash.h> |
| 18 | #include <console/spi.h> |
| 19 | |
| 20 | void spiconsole_init(void) { |
| 21 | spi_init(); |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | /* |
| 26 | * The EM100 'hyper terminal' specification defines a header of 9 characters. |
| 27 | * Because of this, devices with a spi_crop_chunk of less than 10 characters |
| 28 | * can't be supported by this standard. |
| 29 | * |
| 30 | * To add support in romstage, the static struct here and the ones used by |
| 31 | * spi_xfer will need to be modified - removed, or mapped into cbmem. |
| 32 | * |
| 33 | * Because the Dediprog software expects strings, not single characters, and |
| 34 | * because of the header overhead, this builds up a buffer to send. |
| 35 | */ |
| 36 | void spiconsole_tx_byte(unsigned char c) { |
| 37 | static struct em100_msg msg = { |
| 38 | .header.spi_command = EM100_DEDICATED_CMD, |
| 39 | .header.em100_command = EM100_UFIFO_CMD, |
| 40 | .header.msg_signature = EM100_MSG_SIGNATURE, |
| 41 | .header.msg_type = EM100_MSG_ASCII, |
| 42 | .header.msg_length = 0 |
| 43 | }; |
| 44 | |
| 45 | /* Verify the spi buffer is big enough to send even a single byte */ |
| 46 | if (spi_crop_chunk(0,MAX_MSG_LENGTH) < |
| 47 | sizeof(struct em100_msg_header) + 1) |
| 48 | return; |
| 49 | |
| 50 | msg.data[msg.header.msg_length] = c; |
| 51 | msg.header.msg_length++; |
| 52 | |
| 53 | /* Send the data on newline or when the max spi length is reached */ |
| 54 | if (c == '\n' || (sizeof(struct em100_msg_header) + |
| 55 | msg.header.msg_length == spi_crop_chunk(0, |
| 56 | MAX_MSG_LENGTH))) { |
Furquan Shaikh | c28984d | 2016-11-20 21:04:00 -0800 | [diff] [blame] | 57 | struct spi_slave spi = { }; |
Martin Roth | 3a54318 | 2015-09-28 15:27:24 -0600 | [diff] [blame] | 58 | |
| 59 | spi_xfer(&spi, &msg, sizeof(struct em100_msg_header) + |
| 60 | msg.header.msg_length, NULL, 0); |
| 61 | |
| 62 | msg.header.msg_length = 0; |
| 63 | } |
| 64 | |
| 65 | return; |
| 66 | } |