mtd: st_spi_fsm: Search for preferred FSM message sequence configurations
[firefly-linux-kernel-4.4.55.git] / drivers / mtd / devices / st_spi_fsm.c
index 9467585fcfda13c054b391583e5d3208aa9c5773..2740ae195ef5e03ec7f5e5c0b5c979dc07bfd86c 100644 (file)
@@ -222,6 +222,18 @@ struct stfsm_seq {
        uint32_t seq_cfg;
 } __packed __aligned(4);
 
+/* Parameters to configure a READ or WRITE FSM sequence */
+struct seq_rw_config {
+       uint32_t        flags;          /* flags to support config */
+       uint8_t         cmd;            /* FLASH command */
+       int             write;          /* Write Sequence */
+       uint8_t         addr_pads;      /* No. of addr pads (MODE & DUMMY) */
+       uint8_t         data_pads;      /* No. of data pads */
+       uint8_t         mode_data;      /* MODE data */
+       uint8_t         mode_cycles;    /* No. of MODE cycles */
+       uint8_t         dummy_cycles;   /* No. of DUMMY cycles */
+};
+
 /* SPI Flash Device Table */
 struct flash_info {
        char            *name;
@@ -462,6 +474,21 @@ static void stfsm_read_fifo(struct stfsm *fsm, uint32_t *buf,
        }
 }
 
+/* Search for preferred configuration based on available flags */
+static struct seq_rw_config *
+stfsm_search_seq_rw_configs(struct stfsm *fsm,
+                           struct seq_rw_config cfgs[])
+{
+       struct seq_rw_config *config;
+       int flags = fsm->info->flags;
+
+       for (config = cfgs; config->cmd != 0; config++)
+               if ((config->flags & flags) == config->flags)
+                       return config;
+
+       return NULL;
+}
+
 static void stfsm_read_jedec(struct stfsm *fsm, uint8_t *const jedec)
 {
        const struct stfsm_seq *seq = &stfsm_seq_read_jedec;