aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLee Jones <lee.jones@linaro.org>2014-03-20 05:21:06 -0400
committerBrian Norris <computersforpeace@gmail.com>2014-03-20 07:17:21 -0400
commite6b1bb4e18919b969cd876d48b40733993c2a7c7 (patch)
treebfcc085db628299cb66ceb38cdeabe18494c4aac
parentcd7cac9ec3b691e6e0aca92f7c97e5cbb390d17c (diff)
mtd: st_spi_fsm: Move runtime configurable msg sequences into device's struct
Until now the dynamically configurable message sequences for read, write and enable 32bit addressing have been global. Brian makes a good point why this should not be the case. If there are ever two FSM's located on the same platform, we could be potentially introducing a race condition on "needlessly shared data". Suggested-by: Brian Norris <computersforpeace@gmail.com> 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>
-rw-r--r--drivers/mtd/devices/st_spi_fsm.c64
1 files changed, 32 insertions, 32 deletions
diff --git a/drivers/mtd/devices/st_spi_fsm.c b/drivers/mtd/devices/st_spi_fsm.c
index dc9412a93abd..dccbac013340 100644
--- a/drivers/mtd/devices/st_spi_fsm.c
+++ b/drivers/mtd/devices/st_spi_fsm.c
@@ -273,6 +273,19 @@
273#define CFG_ERASESEC_TOGGLE_32BIT_ADDR 0x00000008 273#define CFG_ERASESEC_TOGGLE_32BIT_ADDR 0x00000008
274#define CFG_S25FL_CHECK_ERROR_FLAGS 0x00000010 274#define CFG_S25FL_CHECK_ERROR_FLAGS 0x00000010
275 275
276struct stfsm_seq {
277 uint32_t data_size;
278 uint32_t addr1;
279 uint32_t addr2;
280 uint32_t addr_cfg;
281 uint32_t seq_opc[5];
282 uint32_t mode;
283 uint32_t dummy;
284 uint32_t status;
285 uint8_t seq[16];
286 uint32_t seq_cfg;
287} __packed __aligned(4);
288
276struct stfsm { 289struct stfsm {
277 struct device *dev; 290 struct device *dev;
278 void __iomem *base; 291 void __iomem *base;
@@ -286,20 +299,11 @@ struct stfsm {
286 bool booted_from_spi; 299 bool booted_from_spi;
287 bool reset_signal; 300 bool reset_signal;
288 bool reset_por; 301 bool reset_por;
289};
290 302
291struct stfsm_seq { 303 struct stfsm_seq stfsm_seq_read;
292 uint32_t data_size; 304 struct stfsm_seq stfsm_seq_write;
293 uint32_t addr1; 305 struct stfsm_seq stfsm_seq_en_32bit_addr;
294 uint32_t addr2; 306};
295 uint32_t addr_cfg;
296 uint32_t seq_opc[5];
297 uint32_t mode;
298 uint32_t dummy;
299 uint32_t status;
300 uint8_t seq[16];
301 uint32_t seq_cfg;
302} __packed __aligned(4);
303 307
304/* Parameters to configure a READ or WRITE FSM sequence */ 308/* Parameters to configure a READ or WRITE FSM sequence */
305struct seq_rw_config { 309struct seq_rw_config {
@@ -587,10 +591,6 @@ static struct seq_rw_config stfsm_s25fl_write4_configs[] = {
587 */ 591 */
588#define W25Q_STATUS_QE (0x1 << 9) 592#define W25Q_STATUS_QE (0x1 << 9)
589 593
590static struct stfsm_seq stfsm_seq_read; /* Dynamically populated */
591static struct stfsm_seq stfsm_seq_write; /* Dynamically populated */
592static struct stfsm_seq stfsm_seq_en_32bit_addr;/* Dynamically populated */
593
594static struct stfsm_seq stfsm_seq_read_jedec = { 594static struct stfsm_seq stfsm_seq_read_jedec = {
595 .data_size = TRANSFER_SIZE(8), 595 .data_size = TRANSFER_SIZE(8),
596 .seq_opc[0] = (SEQ_OPC_PADS_1 | 596 .seq_opc[0] = (SEQ_OPC_PADS_1 |
@@ -826,7 +826,7 @@ static int stfsm_write_fifo(struct stfsm *fsm,
826 826
827static int stfsm_enter_32bit_addr(struct stfsm *fsm, int enter) 827static int stfsm_enter_32bit_addr(struct stfsm *fsm, int enter)
828{ 828{
829 struct stfsm_seq *seq = &stfsm_seq_en_32bit_addr; 829 struct stfsm_seq *seq = &fsm->stfsm_seq_en_32bit_addr;
830 uint32_t cmd = enter ? FLASH_CMD_EN4B_ADDR : FLASH_CMD_EX4B_ADDR; 830 uint32_t cmd = enter ? FLASH_CMD_EN4B_ADDR : FLASH_CMD_EX4B_ADDR;
831 831
832 seq->seq_opc[0] = (SEQ_OPC_PADS_1 | 832 seq->seq_opc[0] = (SEQ_OPC_PADS_1 |
@@ -1101,7 +1101,7 @@ static int stfsm_prepare_rwe_seqs_default(struct stfsm *fsm)
1101 int ret; 1101 int ret;
1102 1102
1103 /* Configure 'READ' sequence */ 1103 /* Configure 'READ' sequence */
1104 ret = stfsm_search_prepare_rw_seq(fsm, &stfsm_seq_read, 1104 ret = stfsm_search_prepare_rw_seq(fsm, &fsm->stfsm_seq_read,
1105 default_read_configs); 1105 default_read_configs);
1106 if (ret) { 1106 if (ret) {
1107 dev_err(fsm->dev, 1107 dev_err(fsm->dev,
@@ -1111,7 +1111,7 @@ static int stfsm_prepare_rwe_seqs_default(struct stfsm *fsm)
1111 } 1111 }
1112 1112
1113 /* Configure 'WRITE' sequence */ 1113 /* Configure 'WRITE' sequence */
1114 ret = stfsm_search_prepare_rw_seq(fsm, &stfsm_seq_write, 1114 ret = stfsm_search_prepare_rw_seq(fsm, &fsm->stfsm_seq_write,
1115 default_write_configs); 1115 default_write_configs);
1116 if (ret) { 1116 if (ret) {
1117 dev_err(fsm->dev, 1117 dev_err(fsm->dev,
@@ -1146,7 +1146,7 @@ static int stfsm_mx25_config(struct stfsm *fsm)
1146 */ 1146 */
1147 if (flags & FLASH_FLAG_32BIT_ADDR) { 1147 if (flags & FLASH_FLAG_32BIT_ADDR) {
1148 /* Configure 'enter_32bitaddr' FSM sequence */ 1148 /* Configure 'enter_32bitaddr' FSM sequence */
1149 stfsm_mx25_en_32bit_addr_seq(&stfsm_seq_en_32bit_addr); 1149 stfsm_mx25_en_32bit_addr_seq(&fsm->stfsm_seq_en_32bit_addr);
1150 1150
1151 soc_reset = stfsm_can_handle_soc_reset(fsm); 1151 soc_reset = stfsm_can_handle_soc_reset(fsm);
1152 if (soc_reset || !fsm->booted_from_spi) { 1152 if (soc_reset || !fsm->booted_from_spi) {
@@ -1169,7 +1169,7 @@ static int stfsm_mx25_config(struct stfsm *fsm)
1169 } 1169 }
1170 1170
1171 /* For QUAD mode, set 'QE' STATUS bit */ 1171 /* For QUAD mode, set 'QE' STATUS bit */
1172 data_pads = ((stfsm_seq_read.seq_cfg >> 16) & 0x3) + 1; 1172 data_pads = ((fsm->stfsm_seq_read.seq_cfg >> 16) & 0x3) + 1;
1173 if (data_pads == 4) { 1173 if (data_pads == 4) {
1174 stfsm_read_status(fsm, FLASH_CMD_RDSR, &sta); 1174 stfsm_read_status(fsm, FLASH_CMD_RDSR, &sta);
1175 sta |= MX25_STATUS_QE; 1175 sta |= MX25_STATUS_QE;
@@ -1188,10 +1188,10 @@ static int stfsm_n25q_config(struct stfsm *fsm)
1188 1188
1189 /* Configure 'READ' sequence */ 1189 /* Configure 'READ' sequence */
1190 if (flags & FLASH_FLAG_32BIT_ADDR) 1190 if (flags & FLASH_FLAG_32BIT_ADDR)
1191 ret = stfsm_search_prepare_rw_seq(fsm, &stfsm_seq_read, 1191 ret = stfsm_search_prepare_rw_seq(fsm, &fsm->stfsm_seq_read,
1192 n25q_read4_configs); 1192 n25q_read4_configs);
1193 else 1193 else
1194 ret = stfsm_search_prepare_rw_seq(fsm, &stfsm_seq_read, 1194 ret = stfsm_search_prepare_rw_seq(fsm, &fsm->stfsm_seq_read,
1195 n25q_read3_configs); 1195 n25q_read3_configs);
1196 if (ret) { 1196 if (ret) {
1197 dev_err(fsm->dev, 1197 dev_err(fsm->dev,
@@ -1201,7 +1201,7 @@ static int stfsm_n25q_config(struct stfsm *fsm)
1201 } 1201 }
1202 1202
1203 /* Configure 'WRITE' sequence (default configs) */ 1203 /* Configure 'WRITE' sequence (default configs) */
1204 ret = stfsm_search_prepare_rw_seq(fsm, &stfsm_seq_write, 1204 ret = stfsm_search_prepare_rw_seq(fsm, &fsm->stfsm_seq_write,
1205 default_write_configs); 1205 default_write_configs);
1206 if (ret) { 1206 if (ret) {
1207 dev_err(fsm->dev, 1207 dev_err(fsm->dev,
@@ -1215,7 +1215,7 @@ static int stfsm_n25q_config(struct stfsm *fsm)
1215 1215
1216 /* Configure 32-bit address support */ 1216 /* Configure 32-bit address support */
1217 if (flags & FLASH_FLAG_32BIT_ADDR) { 1217 if (flags & FLASH_FLAG_32BIT_ADDR) {
1218 stfsm_n25q_en_32bit_addr_seq(&stfsm_seq_en_32bit_addr); 1218 stfsm_n25q_en_32bit_addr_seq(&fsm->stfsm_seq_en_32bit_addr);
1219 1219
1220 soc_reset = stfsm_can_handle_soc_reset(fsm); 1220 soc_reset = stfsm_can_handle_soc_reset(fsm);
1221 if (soc_reset || !fsm->booted_from_spi) { 1221 if (soc_reset || !fsm->booted_from_spi) {
@@ -1374,12 +1374,12 @@ static int stfsm_s25fl_config(struct stfsm *fsm)
1374 * Prepare Read/Write/Erase sequences according to S25FLxxx 1374 * Prepare Read/Write/Erase sequences according to S25FLxxx
1375 * 32-bit address command set 1375 * 32-bit address command set
1376 */ 1376 */
1377 ret = stfsm_search_prepare_rw_seq(fsm, &stfsm_seq_read, 1377 ret = stfsm_search_prepare_rw_seq(fsm, &fsm->stfsm_seq_read,
1378 stfsm_s25fl_read4_configs); 1378 stfsm_s25fl_read4_configs);
1379 if (ret) 1379 if (ret)
1380 return ret; 1380 return ret;
1381 1381
1382 ret = stfsm_search_prepare_rw_seq(fsm, &stfsm_seq_write, 1382 ret = stfsm_search_prepare_rw_seq(fsm, &fsm->stfsm_seq_write,
1383 stfsm_s25fl_write4_configs); 1383 stfsm_s25fl_write4_configs);
1384 if (ret) 1384 if (ret)
1385 return ret; 1385 return ret;
@@ -1415,7 +1415,7 @@ static int stfsm_s25fl_config(struct stfsm *fsm)
1415 } 1415 }
1416 1416
1417 /* Check status of 'QE' bit */ 1417 /* Check status of 'QE' bit */
1418 data_pads = ((stfsm_seq_read.seq_cfg >> 16) & 0x3) + 1; 1418 data_pads = ((fsm->stfsm_seq_read.seq_cfg >> 16) & 0x3) + 1;
1419 stfsm_read_status(fsm, FLASH_CMD_RDSR2, &cr1); 1419 stfsm_read_status(fsm, FLASH_CMD_RDSR2, &cr1);
1420 if (data_pads == 4) { 1420 if (data_pads == 4) {
1421 if (!(cr1 & STFSM_S25FL_CONFIG_QE)) { 1421 if (!(cr1 & STFSM_S25FL_CONFIG_QE)) {
@@ -1465,7 +1465,7 @@ static int stfsm_w25q_config(struct stfsm *fsm)
1465 return ret; 1465 return ret;
1466 1466
1467 /* If using QUAD mode, set QE STATUS bit */ 1467 /* If using QUAD mode, set QE STATUS bit */
1468 data_pads = ((stfsm_seq_read.seq_cfg >> 16) & 0x3) + 1; 1468 data_pads = ((fsm->stfsm_seq_read.seq_cfg >> 16) & 0x3) + 1;
1469 if (data_pads == 4) { 1469 if (data_pads == 4) {
1470 stfsm_read_status(fsm, FLASH_CMD_RDSR, &sta1); 1470 stfsm_read_status(fsm, FLASH_CMD_RDSR, &sta1);
1471 stfsm_read_status(fsm, FLASH_CMD_RDSR2, &sta2); 1471 stfsm_read_status(fsm, FLASH_CMD_RDSR2, &sta2);
@@ -1485,7 +1485,7 @@ static int stfsm_w25q_config(struct stfsm *fsm)
1485static int stfsm_read(struct stfsm *fsm, uint8_t *buf, uint32_t size, 1485static int stfsm_read(struct stfsm *fsm, uint8_t *buf, uint32_t size,
1486 uint32_t offset) 1486 uint32_t offset)
1487{ 1487{
1488 struct stfsm_seq *seq = &stfsm_seq_read; 1488 struct stfsm_seq *seq = &fsm->stfsm_seq_read;
1489 uint32_t data_pads; 1489 uint32_t data_pads;
1490 uint32_t read_mask; 1490 uint32_t read_mask;
1491 uint32_t size_ub; 1491 uint32_t size_ub;
@@ -1546,7 +1546,7 @@ static int stfsm_read(struct stfsm *fsm, uint8_t *buf, uint32_t size,
1546static int stfsm_write(struct stfsm *fsm, const uint8_t *const buf, 1546static int stfsm_write(struct stfsm *fsm, const uint8_t *const buf,
1547 const uint32_t size, const uint32_t offset) 1547 const uint32_t size, const uint32_t offset)
1548{ 1548{
1549 struct stfsm_seq *seq = &stfsm_seq_write; 1549 struct stfsm_seq *seq = &fsm->stfsm_seq_write;
1550 uint32_t data_pads; 1550 uint32_t data_pads;
1551 uint32_t write_mask; 1551 uint32_t write_mask;
1552 uint32_t size_ub; 1552 uint32_t size_ub;