Skip to content

Commit febbc08

Browse files
committed
Added support for manual CS control
This serprog spec addition added support for selecting the CS mode for SPI_OP commands: https://review.coreboot.org/c/flashrom/+/81428 This commit adds support for the 0x18 S_CS_MODE command.
1 parent 4fe28ad commit febbc08

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

main.c

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
(1 << S_CMD_S_SPI_FREQ) | \
4242
(1 << S_CMD_S_PIN_STATE) | \
4343
(1 << S_CMD_S_SPI_CS) | \
44-
(1 << S_CMD_S_SPI_MODE) \
44+
(1 << S_CMD_S_SPI_MODE) | \
45+
(1 << S_CMD_S_CS_MODE) \
4546
)
4647

4748
enum spi_mode {
@@ -52,6 +53,15 @@ enum spi_mode {
5253

5354
enum spi_mode current_spi_mode = SPI_MODE_HALF_DUPLEX;
5455

56+
enum cs_mode {
57+
CS_MODE_AUTO = 0,
58+
CS_MODE_SELECTED = 1,
59+
CS_MODE_DESELECTED = 2,
60+
CS_MODE_MAX = CS_MODE_DESELECTED,
61+
};
62+
63+
enum cs_mode current_cs_mode = CS_MODE_AUTO;
64+
5565
uint active_cs_pin = 0;
5666
#define NUM_CS_AVAILABLE 4 // Number of usable chip selects
5767
uint8_t cs_pins[NUM_CS_AVAILABLE] = { PIN_CS_0, PIN_CS_1, PIN_CS_2, PIN_CS_3 };
@@ -200,7 +210,9 @@ void process(const pio_spi_inst_t *spi, int command) {
200210
uint32_t wlen = getu24();
201211
uint32_t rlen = getu24();
202212

203-
cs_select(active_cs_pin);
213+
if (current_cs_mode == CS_MODE_AUTO) {
214+
cs_select(active_cs_pin);
215+
}
204216
switch (current_spi_mode) {
205217
case SPI_MODE_HALF_DUPLEX:
206218
spi_half_duplex(spi, wlen, rlen);
@@ -211,7 +223,9 @@ void process(const pio_spi_inst_t *spi, int command) {
211223
default:
212224
break;
213225
}
214-
cs_deselect(active_cs_pin);
226+
if (current_spi_mode == CS_MODE_AUTO) {
227+
cs_deselect(active_cs_pin);
228+
}
215229
}
216230
break;
217231
case S_CMD_S_SPI_FREQ:
@@ -253,6 +267,27 @@ void process(const pio_spi_inst_t *spi, int command) {
253267
}
254268
break;
255269
}
270+
case S_CMD_S_CS_MODE:
271+
{
272+
uint8_t cs_mode = getchar();
273+
switch (cs_mode) {
274+
case CS_MODE_AUTO:
275+
case CS_MODE_DESELECTED:
276+
cs_deselect(active_cs_pin);
277+
current_cs_mode = cs_mode;
278+
putchar(S_ACK);
279+
break;
280+
case CS_MODE_SELECTED:
281+
cs_select(active_cs_pin);
282+
current_cs_mode = cs_mode;
283+
putchar(S_ACK);
284+
break;
285+
default:
286+
putchar(S_NAK);
287+
break;
288+
}
289+
break;
290+
}
256291
default:
257292
putchar(S_NAK);
258293
}

spi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@
2525
#define S_CMD_S_PIN_STATE 0x15 /* Enable/disable output drivers */
2626
#define S_CMD_S_SPI_CS 0x16 /* Set SPI chip select to use */
2727
#define S_CMD_S_SPI_MODE 0x17 /* Sets the spi mode used by S_CMD_O_SPIOP */
28+
#define S_CMD_S_CS_MODE 0x18 /* Sets the way the CS is controlled */

0 commit comments

Comments
 (0)