diff options
author | Lee Jones <lee.jones@linaro.org> | 2014-03-20 05:20:44 -0400 |
---|---|---|
committer | Brian Norris <computersforpeace@gmail.com> | 2014-03-20 07:17:16 -0400 |
commit | 97ccf2d253cd211d3922a30bde5d4adf9080fb8a (patch) | |
tree | 7f8434929934377f348bdb92a1bd72088f1fe221 /drivers/mtd/devices | |
parent | 3b5d1981933b25973b02684dccb17d4282fd4d6d (diff) |
mtd: st_spi_fsm: Prepare the read/write FSM message sequence(s)
The FSM Serial Flash Controller is driven by issuing a standard set of
register writes we call a message sequence. This patch supplies a method
to prepare read/write FSM message sequence(s) based on chip capability
and configuration.
Acked-by Angus Clark <angus.clark@st.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Diffstat (limited to 'drivers/mtd/devices')
-rw-r--r-- | drivers/mtd/devices/st_spi_fsm.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/drivers/mtd/devices/st_spi_fsm.c b/drivers/mtd/devices/st_spi_fsm.c index 5a1b470ce908..83cf9dfd02e7 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c | |||
@@ -489,6 +489,75 @@ stfsm_search_seq_rw_configs(struct stfsm *fsm, | |||
489 | return NULL; | 489 | return NULL; |
490 | } | 490 | } |
491 | 491 | ||
492 | /* Prepare a READ/WRITE sequence according to configuration parameters */ | ||
493 | static void stfsm_prepare_rw_seq(struct stfsm *fsm, | ||
494 | struct stfsm_seq *seq, | ||
495 | struct seq_rw_config *cfg) | ||
496 | { | ||
497 | int addr1_cycles, addr2_cycles; | ||
498 | int i = 0; | ||
499 | |||
500 | memset(seq, 0, sizeof(*seq)); | ||
501 | |||
502 | /* Add READ/WRITE OPC */ | ||
503 | seq->seq_opc[i++] = (SEQ_OPC_PADS_1 | | ||
504 | SEQ_OPC_CYCLES(8) | | ||
505 | SEQ_OPC_OPCODE(cfg->cmd)); | ||
506 | |||
507 | /* Add WREN OPC for a WRITE sequence */ | ||
508 | if (cfg->write) | ||
509 | seq->seq_opc[i++] = (SEQ_OPC_PADS_1 | | ||
510 | SEQ_OPC_CYCLES(8) | | ||
511 | SEQ_OPC_OPCODE(FLASH_CMD_WREN) | | ||
512 | SEQ_OPC_CSDEASSERT); | ||
513 | |||
514 | /* Address configuration (24 or 32-bit addresses) */ | ||
515 | addr1_cycles = (fsm->info->flags & FLASH_FLAG_32BIT_ADDR) ? 16 : 8; | ||
516 | addr1_cycles /= cfg->addr_pads; | ||
517 | addr2_cycles = 16 / cfg->addr_pads; | ||
518 | seq->addr_cfg = ((addr1_cycles & 0x3f) << 0 | /* ADD1 cycles */ | ||
519 | (cfg->addr_pads - 1) << 6 | /* ADD1 pads */ | ||
520 | (addr2_cycles & 0x3f) << 16 | /* ADD2 cycles */ | ||
521 | ((cfg->addr_pads - 1) << 22)); /* ADD2 pads */ | ||
522 | |||
523 | /* Data/Sequence configuration */ | ||
524 | seq->seq_cfg = ((cfg->data_pads - 1) << 16 | | ||
525 | SEQ_CFG_STARTSEQ | | ||
526 | SEQ_CFG_CSDEASSERT); | ||
527 | if (!cfg->write) | ||
528 | seq->seq_cfg |= SEQ_CFG_READNOTWRITE; | ||
529 | |||
530 | /* Mode configuration (no. of pads taken from addr cfg) */ | ||
531 | seq->mode = ((cfg->mode_data & 0xff) << 0 | /* data */ | ||
532 | (cfg->mode_cycles & 0x3f) << 16 | /* cycles */ | ||
533 | (cfg->addr_pads - 1) << 22); /* pads */ | ||
534 | |||
535 | /* Dummy configuration (no. of pads taken from addr cfg) */ | ||
536 | seq->dummy = ((cfg->dummy_cycles & 0x3f) << 16 | /* cycles */ | ||
537 | (cfg->addr_pads - 1) << 22); /* pads */ | ||
538 | |||
539 | |||
540 | /* Instruction sequence */ | ||
541 | i = 0; | ||
542 | if (cfg->write) | ||
543 | seq->seq[i++] = STFSM_INST_CMD2; | ||
544 | |||
545 | seq->seq[i++] = STFSM_INST_CMD1; | ||
546 | |||
547 | seq->seq[i++] = STFSM_INST_ADD1; | ||
548 | seq->seq[i++] = STFSM_INST_ADD2; | ||
549 | |||
550 | if (cfg->mode_cycles) | ||
551 | seq->seq[i++] = STFSM_INST_MODE; | ||
552 | |||
553 | if (cfg->dummy_cycles) | ||
554 | seq->seq[i++] = STFSM_INST_DUMMY; | ||
555 | |||
556 | seq->seq[i++] = | ||
557 | cfg->write ? STFSM_INST_DATA_WRITE : STFSM_INST_DATA_READ; | ||
558 | seq->seq[i++] = STFSM_INST_STOP; | ||
559 | } | ||
560 | |||
492 | static void stfsm_read_jedec(struct stfsm *fsm, uint8_t *const jedec) | 561 | static void stfsm_read_jedec(struct stfsm *fsm, uint8_t *const jedec) |
493 | { | 562 | { |
494 | const struct stfsm_seq *seq = &stfsm_seq_read_jedec; | 563 | const struct stfsm_seq *seq = &stfsm_seq_read_jedec; |