Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: spinand: Add spinand_init_flash() helper

Add spinand_init_flash() helper which implement
all needed init for future SPI-NAND resume ops.

Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20210602094913.26472-3-patrice.chotard@foss.st.com

authored by

Patrice Chotard and committed by
Miquel Raynal
41e005c2 ff0cd841

+45 -29
+45 -29
drivers/mtd/nand/spi/core.c
··· 1086 1086 return 0; 1087 1087 } 1088 1088 1089 + static int spinand_init_flash(struct spinand_device *spinand) 1090 + { 1091 + struct device *dev = &spinand->spimem->spi->dev; 1092 + struct nand_device *nand = spinand_to_nand(spinand); 1093 + int ret, i; 1094 + 1095 + ret = spinand_read_cfg(spinand); 1096 + if (ret) 1097 + return ret; 1098 + 1099 + ret = spinand_init_quad_enable(spinand); 1100 + if (ret) 1101 + return ret; 1102 + 1103 + ret = spinand_upd_cfg(spinand, CFG_OTP_ENABLE, 0); 1104 + if (ret) 1105 + return ret; 1106 + 1107 + ret = spinand_manufacturer_init(spinand); 1108 + if (ret) { 1109 + dev_err(dev, 1110 + "Failed to initialize the SPI NAND chip (err = %d)\n", 1111 + ret); 1112 + return ret; 1113 + } 1114 + 1115 + /* After power up, all blocks are locked, so unlock them here. */ 1116 + for (i = 0; i < nand->memorg.ntargets; i++) { 1117 + ret = spinand_select_target(spinand, i); 1118 + if (ret) 1119 + break; 1120 + 1121 + ret = spinand_lock_block(spinand, BL_ALL_UNLOCKED); 1122 + if (ret) 1123 + break; 1124 + } 1125 + 1126 + if (ret) 1127 + spinand_manufacturer_cleanup(spinand); 1128 + 1129 + return ret; 1130 + } 1131 + 1089 1132 static int spinand_init(struct spinand_device *spinand) 1090 1133 { 1091 1134 struct device *dev = &spinand->spimem->spi->dev; 1092 1135 struct mtd_info *mtd = spinand_to_mtd(spinand); 1093 1136 struct nand_device *nand = mtd_to_nanddev(mtd); 1094 - int ret, i; 1137 + int ret; 1095 1138 1096 1139 /* 1097 1140 * We need a scratch buffer because the spi_mem interface requires that ··· 1167 1124 if (ret) 1168 1125 goto err_free_bufs; 1169 1126 1170 - ret = spinand_read_cfg(spinand); 1127 + ret = spinand_init_flash(spinand); 1171 1128 if (ret) 1172 1129 goto err_free_bufs; 1173 - 1174 - ret = spinand_init_quad_enable(spinand); 1175 - if (ret) 1176 - goto err_free_bufs; 1177 - 1178 - ret = spinand_upd_cfg(spinand, CFG_OTP_ENABLE, 0); 1179 - if (ret) 1180 - goto err_free_bufs; 1181 - 1182 - ret = spinand_manufacturer_init(spinand); 1183 - if (ret) { 1184 - dev_err(dev, 1185 - "Failed to initialize the SPI NAND chip (err = %d)\n", 1186 - ret); 1187 - goto err_free_bufs; 1188 - } 1189 1130 1190 1131 ret = spinand_create_dirmaps(spinand); 1191 1132 if (ret) { ··· 1177 1150 "Failed to create direct mappings for read/write operations (err = %d)\n", 1178 1151 ret); 1179 1152 goto err_manuf_cleanup; 1180 - } 1181 - 1182 - /* After power up, all blocks are locked, so unlock them here. */ 1183 - for (i = 0; i < nand->memorg.ntargets; i++) { 1184 - ret = spinand_select_target(spinand, i); 1185 - if (ret) 1186 - goto err_manuf_cleanup; 1187 - 1188 - ret = spinand_lock_block(spinand, BL_ALL_UNLOCKED); 1189 - if (ret) 1190 - goto err_manuf_cleanup; 1191 1153 } 1192 1154 1193 1155 ret = nanddev_init(nand, &spinand_ops, THIS_MODULE);