Lines Matching +full:xspi +full:- +full:nor

1 // SPDX-License-Identifier: GPL-2.0
8 #include <linux/mtd/spi-nor.h>
14 #define SFDP_PARAM_HEADER_ID(p) (((p)->id_msb << 8) | (p)->id_lsb)
16 (((p)->parameter_table_pointer[2] << 16) | \
17 ((p)->parameter_table_pointer[1] << 8) | \
18 ((p)->parameter_table_pointer[0] << 0))
19 #define SFDP_PARAM_HEADER_PARAM_LEN(p) ((p)->length * 4)
23 #define SFDP_4BAIT_ID 0xff84 /* 4-byte Address Instruction Table */
24 #define SFDP_PROFILE1_ID 0xff05 /* xSPI Profile 1.0 table. */
31 * Register Map Offsets for Multi-Chip
41 u8 nph; /* 0-base number of parameter headers */
50 /* The Fast Read x-y-z hardware capability in params->hwcaps.mask. */
55 * whether the Fast Read x-y-z command is supported.
61 * The half-word at offset <setting_shift> in <setting_dword> BFPT DWORD
63 * states to be used by Fast Read x-y-z command.
68 /* The SPI protocol for this Fast Read x-y-z command. */
74 * The half-word at offset <shift> in DWORD <dword> encodes the
135 * the associated 4-byte address op code is supported.
141 * spi_nor_read_raw() - raw read of serial flash memory. read_opcode,
144 * @nor: pointer to a 'struct spi_nor'
147 * @buf: buffer where the data is copied into (dma-safe memory)
149 * Return: 0 on success, -errno otherwise.
151 static int spi_nor_read_raw(struct spi_nor *nor, u32 addr, size_t len, u8 *buf) in spi_nor_read_raw() argument
156 ret = spi_nor_read_data(nor, addr, len, buf); in spi_nor_read_raw()
160 return -EIO; in spi_nor_read_raw()
164 len -= ret; in spi_nor_read_raw()
170 * spi_nor_read_sfdp() - read Serial Flash Discoverable Parameters.
171 * @nor: pointer to a 'struct spi_nor'
174 * @buf: buffer where the SFDP data are copied into (dma-safe memory)
178 * followed by a 3-byte address and 8 dummy clock cycles.
180 * Return: 0 on success, -errno otherwise.
182 static int spi_nor_read_sfdp(struct spi_nor *nor, u32 addr, in spi_nor_read_sfdp() argument
188 read_opcode = nor->read_opcode; in spi_nor_read_sfdp()
189 addr_nbytes = nor->addr_nbytes; in spi_nor_read_sfdp()
190 read_dummy = nor->read_dummy; in spi_nor_read_sfdp()
192 nor->read_opcode = SPINOR_OP_RDSFDP; in spi_nor_read_sfdp()
193 nor->addr_nbytes = 3; in spi_nor_read_sfdp()
194 nor->read_dummy = 8; in spi_nor_read_sfdp()
196 ret = spi_nor_read_raw(nor, addr, len, buf); in spi_nor_read_sfdp()
198 nor->read_opcode = read_opcode; in spi_nor_read_sfdp()
199 nor->addr_nbytes = addr_nbytes; in spi_nor_read_sfdp()
200 nor->read_dummy = read_dummy; in spi_nor_read_sfdp()
206 * spi_nor_read_sfdp_dma_unsafe() - read Serial Flash Discoverable Parameters.
207 * @nor: pointer to a 'struct spi_nor'
213 * guaranteed to be dma-safe.
215 * Return: -ENOMEM if kmalloc() fails, the return code of spi_nor_read_sfdp()
218 static int spi_nor_read_sfdp_dma_unsafe(struct spi_nor *nor, u32 addr, in spi_nor_read_sfdp_dma_unsafe() argument
226 return -ENOMEM; in spi_nor_read_sfdp_dma_unsafe()
228 ret = spi_nor_read_sfdp(nor, addr, len, dma_safe_buf); in spi_nor_read_sfdp_dma_unsafe()
240 read->num_mode_clocks = (half >> 5) & 0x07; in spi_nor_set_read_settings_from_bfpt()
241 read->num_wait_states = (half >> 0) & 0x1f; in spi_nor_set_read_settings_from_bfpt()
242 read->opcode = (half >> 8) & 0xff; in spi_nor_set_read_settings_from_bfpt()
243 read->proto = proto; in spi_nor_set_read_settings_from_bfpt()
247 /* Fast Read 1-1-2 */
255 /* Fast Read 1-2-2 */
263 /* Fast Read 2-2-2 */
271 /* Fast Read 1-1-4 */
279 /* Fast Read 1-4-4 */
287 /* Fast Read 4-4-4 */
311 * spi_nor_set_erase_settings_from_bfpt() - set erase type settings from BFPT
312 * @erase: pointer to a structure that describes a SPI NOR erase type
327 erase->idx = i; in spi_nor_set_erase_settings_from_bfpt()
332 * spi_nor_map_cmp_erase_type() - compare the map's erase types by size
340 * Return: the result of @l->size - @r->size
346 return left->size - right->size; in spi_nor_map_cmp_erase_type()
350 * spi_nor_sort_erase_mask() - sort erase mask
351 * @map: the erase map of the SPI NOR
362 struct spi_nor_erase_type *erase_type = map->erase_type; in spi_nor_sort_erase_mask()
378 * spi_nor_regions_sort_erase_types() - sort erase types in each region
379 * @map: the erase map of the SPI NOR
391 struct spi_nor_erase_region *region = map->regions; in spi_nor_regions_sort_erase_types()
395 for (i = 0; i < map->n_regions; i++) { in spi_nor_regions_sort_erase_types()
405 * spi_nor_parse_bfpt() - read and parse the Basic Flash Parameter Table.
406 * @nor: pointer to a 'struct spi_nor'
430 * Return: 0 on success, -errno otherwise.
432 static int spi_nor_parse_bfpt(struct spi_nor *nor, in spi_nor_parse_bfpt() argument
435 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_parse_bfpt()
436 struct spi_nor_erase_map *map = &params->erase_map; in spi_nor_parse_bfpt()
437 struct spi_nor_erase_type *erase_type = map->erase_type; in spi_nor_parse_bfpt()
448 if (bfpt_header->length < BFPT_DWORD_MAX_JESD216) in spi_nor_parse_bfpt()
449 return -EINVAL; in spi_nor_parse_bfpt()
453 bfpt_header->length * sizeof(u32)); in spi_nor_parse_bfpt()
456 err = spi_nor_read_sfdp_dma_unsafe(nor, addr, len, &bfpt); in spi_nor_parse_bfpt()
467 params->addr_nbytes = 3; in spi_nor_parse_bfpt()
468 params->addr_mode_nbytes = 3; in spi_nor_parse_bfpt()
472 params->addr_nbytes = 4; in spi_nor_parse_bfpt()
473 params->addr_mode_nbytes = 4; in spi_nor_parse_bfpt()
486 * Prevent overflows on params->size. Anyway, a NOR of 2^64 in spi_nor_parse_bfpt()
491 return -EINVAL; in spi_nor_parse_bfpt()
493 params->size = 1ULL << val; in spi_nor_parse_bfpt()
495 params->size = val + 1; in spi_nor_parse_bfpt()
497 params->size >>= 3; /* Convert to bytes. */ in spi_nor_parse_bfpt()
504 if (!(bfpt.dwords[rd->supported_dword] & rd->supported_bit)) { in spi_nor_parse_bfpt()
505 params->hwcaps.mask &= ~rd->hwcaps; in spi_nor_parse_bfpt()
509 params->hwcaps.mask |= rd->hwcaps; in spi_nor_parse_bfpt()
510 cmd = spi_nor_hwcaps_read2cmd(rd->hwcaps); in spi_nor_parse_bfpt()
511 read = &params->reads[cmd]; in spi_nor_parse_bfpt()
512 half = bfpt.dwords[rd->settings_dword] >> rd->settings_shift; in spi_nor_parse_bfpt()
513 spi_nor_set_read_settings_from_bfpt(read, half, rd->proto); in spi_nor_parse_bfpt()
521 memset(&params->erase_map, 0, sizeof(params->erase_map)); in spi_nor_parse_bfpt()
527 half = bfpt.dwords[er->dword] >> er->shift; in spi_nor_parse_bfpt()
540 spi_nor_init_uniform_erase_map(map, erase_mask, params->size); in spi_nor_parse_bfpt()
555 if (bfpt_header->length == BFPT_DWORD_MAX_JESD216) in spi_nor_parse_bfpt()
556 return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt); in spi_nor_parse_bfpt()
562 params->page_size = 1U << val; in spi_nor_parse_bfpt()
567 params->quad_enable = NULL; in spi_nor_parse_bfpt()
573 * side-effect of clearing Status Register 2. in spi_nor_parse_bfpt()
580 nor->flags |= SNOR_F_HAS_16BIT_SR | SNOR_F_NO_READ_CR; in spi_nor_parse_bfpt()
581 params->quad_enable = spi_nor_sr2_bit1_quad_enable; in spi_nor_parse_bfpt()
585 nor->flags &= ~SNOR_F_HAS_16BIT_SR; in spi_nor_parse_bfpt()
586 params->quad_enable = spi_nor_sr1_bit6_quad_enable; in spi_nor_parse_bfpt()
590 nor->flags &= ~SNOR_F_HAS_16BIT_SR; in spi_nor_parse_bfpt()
591 params->quad_enable = spi_nor_sr2_bit7_quad_enable; in spi_nor_parse_bfpt()
599 * assumption of a 16-bit Write Status (01h) command. in spi_nor_parse_bfpt()
601 nor->flags |= SNOR_F_HAS_16BIT_SR; in spi_nor_parse_bfpt()
603 params->quad_enable = spi_nor_sr2_bit1_quad_enable; in spi_nor_parse_bfpt()
607 dev_dbg(nor->dev, "BFPT QER reserved value used\n"); in spi_nor_parse_bfpt()
613 params->set_4byte_addr_mode = spi_nor_set_4byte_addr_mode_brwr; in spi_nor_parse_bfpt()
615 params->set_4byte_addr_mode = spi_nor_set_4byte_addr_mode_wren_en4b_ex4b; in spi_nor_parse_bfpt()
617 params->set_4byte_addr_mode = spi_nor_set_4byte_addr_mode_en4b_ex4b; in spi_nor_parse_bfpt()
619 dev_dbg(nor->dev, "BFPT: 4-Byte Address Mode method is not recognized or not implemented\n"); in spi_nor_parse_bfpt()
623 nor->flags |= SNOR_F_SOFT_RESET; in spi_nor_parse_bfpt()
626 if (bfpt_header->length == BFPT_DWORD_MAX_JESD216B) in spi_nor_parse_bfpt()
627 return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt); in spi_nor_parse_bfpt()
629 /* Parse 1-1-8 read instruction */ in spi_nor_parse_bfpt()
636 params->hwcaps.mask |= SNOR_HWCAPS_READ_1_1_8; in spi_nor_parse_bfpt()
637 spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ_1_1_8], in spi_nor_parse_bfpt()
642 /* Parse 1-8-8 read instruction */ in spi_nor_parse_bfpt()
649 params->hwcaps.mask |= SNOR_HWCAPS_READ_1_8_8; in spi_nor_parse_bfpt()
650 spi_nor_set_read_settings(&params->reads[SNOR_CMD_READ_1_8_8], in spi_nor_parse_bfpt()
655 /* 8D-8D-8D command extension. */ in spi_nor_parse_bfpt()
658 nor->cmd_ext_type = SPI_NOR_EXT_REPEAT; in spi_nor_parse_bfpt()
662 nor->cmd_ext_type = SPI_NOR_EXT_INVERT; in spi_nor_parse_bfpt()
666 dev_dbg(nor->dev, "Reserved command extension used\n"); in spi_nor_parse_bfpt()
670 dev_dbg(nor->dev, "16-bit opcodes not supported\n"); in spi_nor_parse_bfpt()
671 return -EOPNOTSUPP; in spi_nor_parse_bfpt()
674 return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt); in spi_nor_parse_bfpt()
678 * spi_nor_smpt_addr_nbytes() - return the number of address bytes used in the
680 * @nor: pointer to a 'struct spi_nor'
683 static u8 spi_nor_smpt_addr_nbytes(const struct spi_nor *nor, const u32 settings) in spi_nor_smpt_addr_nbytes() argument
694 return nor->params->addr_mode_nbytes; in spi_nor_smpt_addr_nbytes()
699 * spi_nor_smpt_read_dummy() - return the configuration detection command read
701 * @nor: pointer to a 'struct spi_nor'
706 static u8 spi_nor_smpt_read_dummy(const struct spi_nor *nor, const u32 settings) in spi_nor_smpt_read_dummy() argument
711 return nor->read_dummy; in spi_nor_smpt_read_dummy()
716 * spi_nor_get_map_in_use() - get the configuration map in use
717 * @nor: pointer to a 'struct spi_nor'
721 * Return: pointer to the map in use, ERR_PTR(-errno) otherwise.
723 static const u32 *spi_nor_get_map_in_use(struct spi_nor *nor, const u32 *smpt, in spi_nor_get_map_in_use() argument
734 /* Use a kmalloc'ed bounce buffer to guarantee it is DMA-able. */ in spi_nor_get_map_in_use()
737 return ERR_PTR(-ENOMEM); in spi_nor_get_map_in_use()
739 addr_nbytes = nor->addr_nbytes; in spi_nor_get_map_in_use()
740 read_dummy = nor->read_dummy; in spi_nor_get_map_in_use()
741 read_opcode = nor->read_opcode; in spi_nor_get_map_in_use()
750 nor->addr_nbytes = spi_nor_smpt_addr_nbytes(nor, smpt[i]); in spi_nor_get_map_in_use()
751 nor->read_dummy = spi_nor_smpt_read_dummy(nor, smpt[i]); in spi_nor_get_map_in_use()
752 nor->read_opcode = SMPT_CMD_OPCODE(smpt[i]); in spi_nor_get_map_in_use()
755 err = spi_nor_read_raw(nor, addr, 1, buf); in spi_nor_get_map_in_use()
775 ret = ERR_PTR(-EINVAL); in spi_nor_get_map_in_use()
797 nor->addr_nbytes = addr_nbytes; in spi_nor_get_map_in_use()
798 nor->read_dummy = read_dummy; in spi_nor_get_map_in_use()
799 nor->read_opcode = read_opcode; in spi_nor_get_map_in_use()
804 * spi_nor_region_check_overlay() - set overlay bit when the region is overlaid
805 * @region: pointer to a structure that describes a SPI NOR erase region
806 * @erase: pointer to a structure that describes a SPI NOR erase type
819 if (region->size & erase[i].size_mask) { in spi_nor_region_check_overlay()
820 region->overlaid = true; in spi_nor_region_check_overlay()
827 * spi_nor_init_non_uniform_erase_map() - initialize the non-uniform erase map
828 * @nor: pointer to a 'struct spi_nor'
831 * Return: 0 on success, -errno otherwise.
833 static int spi_nor_init_non_uniform_erase_map(struct spi_nor *nor, in spi_nor_init_non_uniform_erase_map() argument
836 struct spi_nor_erase_map *map = &nor->params->erase_map; in spi_nor_init_non_uniform_erase_map()
837 struct spi_nor_erase_type *erase = map->erase_type; in spi_nor_init_non_uniform_erase_map()
850 region = devm_kcalloc(nor->dev, region_count, sizeof(*region), in spi_nor_init_non_uniform_erase_map()
853 return -ENOMEM; in spi_nor_init_non_uniform_erase_map()
854 map->regions = region; in spi_nor_init_non_uniform_erase_map()
855 map->n_regions = region_count; in spi_nor_init_non_uniform_erase_map()
885 save_uniform_erase_type = map->uniform_region.erase_mask; in spi_nor_init_non_uniform_erase_map()
886 map->uniform_region.erase_mask = in spi_nor_init_non_uniform_erase_map()
895 map->uniform_region.erase_mask = save_uniform_erase_type; in spi_nor_init_non_uniform_erase_map()
896 return -EINVAL; in spi_nor_init_non_uniform_erase_map()
912 * spi_nor_parse_smpt() - parse Sector Map Parameter Table
913 * @nor: pointer to a 'struct spi_nor'
920 * Return: 0 on success, -errno otherwise.
922 static int spi_nor_parse_smpt(struct spi_nor *nor, in spi_nor_parse_smpt() argument
932 len = smpt_header->length * sizeof(*smpt); in spi_nor_parse_smpt()
935 return -ENOMEM; in spi_nor_parse_smpt()
938 ret = spi_nor_read_sfdp(nor, addr, len, smpt); in spi_nor_parse_smpt()
943 le32_to_cpu_array(smpt, smpt_header->length); in spi_nor_parse_smpt()
945 sector_map = spi_nor_get_map_in_use(nor, smpt, smpt_header->length); in spi_nor_parse_smpt()
951 ret = spi_nor_init_non_uniform_erase_map(nor, sector_map); in spi_nor_parse_smpt()
955 spi_nor_regions_sort_erase_types(&nor->params->erase_map); in spi_nor_parse_smpt()
963 * spi_nor_parse_4bait() - parse the 4-Byte Address Instruction Table
964 * @nor: pointer to a 'struct spi_nor'.
966 * the 4-Byte Address Instruction Table length and version.
968 * Return: 0 on success, -errno otherwise.
970 static int spi_nor_parse_4bait(struct spi_nor *nor, in spi_nor_parse_4bait() argument
997 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_parse_4bait()
998 struct spi_nor_pp_command *params_pp = params->page_programs; in spi_nor_parse_4bait()
999 struct spi_nor_erase_map *map = &params->erase_map; in spi_nor_parse_4bait()
1000 struct spi_nor_erase_type *erase_type = map->erase_type; in spi_nor_parse_4bait()
1006 if (param_header->major != SFDP_JESD216_MAJOR || in spi_nor_parse_4bait()
1007 param_header->length < SFDP_4BAIT_DWORD_MAX) in spi_nor_parse_4bait()
1008 return -EINVAL; in spi_nor_parse_4bait()
1010 /* Read the 4-byte Address Instruction Table. */ in spi_nor_parse_4bait()
1013 /* Use a kmalloc'ed bounce buffer to guarantee it is DMA-able. */ in spi_nor_parse_4bait()
1016 return -ENOMEM; in spi_nor_parse_4bait()
1019 ret = spi_nor_read_sfdp(nor, addr, len, dwords); in spi_nor_parse_4bait()
1027 * Compute the subset of (Fast) Read commands for which the 4-byte in spi_nor_parse_4bait()
1035 discard_hwcaps |= read->hwcaps; in spi_nor_parse_4bait()
1036 if ((params->hwcaps.mask & read->hwcaps) && in spi_nor_parse_4bait()
1037 (dwords[SFDP_DWORD(1)] & read->supported_bit)) in spi_nor_parse_4bait()
1038 read_hwcaps |= read->hwcaps; in spi_nor_parse_4bait()
1042 * Compute the subset of Page Program commands for which the 4-byte in spi_nor_parse_4bait()
1052 * Bypass the params->hwcaps.mask and consider 4BAIT the biggest in spi_nor_parse_4bait()
1055 discard_hwcaps |= program->hwcaps; in spi_nor_parse_4bait()
1056 if (dwords[SFDP_DWORD(1)] & program->supported_bit) in spi_nor_parse_4bait()
1057 pp_hwcaps |= program->hwcaps; in spi_nor_parse_4bait()
1061 * Compute the subset of Sector Erase commands for which the 4-byte in spi_nor_parse_4bait()
1068 if (dwords[SFDP_DWORD(1)] & erase->supported_bit) in spi_nor_parse_4bait()
1076 * We need at least one 4-byte op code per read, program and erase in spi_nor_parse_4bait()
1078 * nor->addr_nbytes value. in spi_nor_parse_4bait()
1084 * Discard all operations from the 4-byte instruction set which are in spi_nor_parse_4bait()
1087 params->hwcaps.mask &= ~discard_hwcaps; in spi_nor_parse_4bait()
1088 params->hwcaps.mask |= (read_hwcaps | pp_hwcaps); in spi_nor_parse_4bait()
1090 /* Use the 4-byte address instruction set. */ in spi_nor_parse_4bait()
1092 struct spi_nor_read_command *read_cmd = &params->reads[i]; in spi_nor_parse_4bait()
1094 read_cmd->opcode = spi_nor_convert_3to4_read(read_cmd->opcode); in spi_nor_parse_4bait()
1102 * Since xSPI Page Program opcode is backward compatible with in spi_nor_parse_4bait()
1132 params->addr_nbytes = 4; in spi_nor_parse_4bait()
1133 nor->flags |= SNOR_F_4B_OPCODES | SNOR_F_HAS_4BAIT; in spi_nor_parse_4bait()
1150 * spi_nor_parse_profile1() - parse the xSPI Profile 1.0 table
1151 * @nor: pointer to a 'struct spi_nor'
1155 * Return: 0 on success, -errno otherwise.
1157 static int spi_nor_parse_profile1(struct spi_nor *nor, in spi_nor_parse_profile1() argument
1165 len = profile1_header->length * sizeof(*dwords); in spi_nor_parse_profile1()
1168 return -ENOMEM; in spi_nor_parse_profile1()
1171 ret = spi_nor_read_sfdp(nor, addr, len, dwords); in spi_nor_parse_profile1()
1175 le32_to_cpu_array(dwords, profile1_header->length); in spi_nor_parse_profile1()
1177 /* Get 8D-8D-8D fast read opcode and dummy cycles. */ in spi_nor_parse_profile1()
1182 nor->params->rdsr_dummy = 8; in spi_nor_parse_profile1()
1184 nor->params->rdsr_dummy = 4; in spi_nor_parse_profile1()
1187 nor->params->rdsr_addr_nbytes = 4; in spi_nor_parse_profile1()
1189 nor->params->rdsr_addr_nbytes = 0; in spi_nor_parse_profile1()
1211 dev_dbg(nor->dev, in spi_nor_parse_profile1()
1218 nor->params->hwcaps.mask |= SNOR_HWCAPS_READ_8_8_8_DTR; in spi_nor_parse_profile1()
1219 spi_nor_set_read_settings(&nor->params->reads[SNOR_CMD_READ_8_8_8_DTR], in spi_nor_parse_profile1()
1224 * Page Program is "Required Command" in the xSPI Profile 1.0. Update in spi_nor_parse_profile1()
1225 * the params->hwcaps.mask here. in spi_nor_parse_profile1()
1227 nor->params->hwcaps.mask |= SNOR_HWCAPS_PP_8_8_8_DTR; in spi_nor_parse_profile1()
1237 * spi_nor_parse_sccr() - Parse the Status, Control and Configuration Register
1239 * @nor: pointer to a 'struct spi_nor'
1243 * Return: 0 on success, -errno otherwise.
1245 static int spi_nor_parse_sccr(struct spi_nor *nor, in spi_nor_parse_sccr() argument
1248 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_parse_sccr()
1253 len = sccr_header->length * sizeof(*dwords); in spi_nor_parse_sccr()
1256 return -ENOMEM; in spi_nor_parse_sccr()
1259 ret = spi_nor_read_sfdp(nor, addr, len, dwords); in spi_nor_parse_sccr()
1263 le32_to_cpu_array(dwords, sccr_header->length); in spi_nor_parse_sccr()
1266 if (!params->vreg_offset) { in spi_nor_parse_sccr()
1267 params->vreg_offset = devm_kmalloc(nor->dev, sizeof(*dwords), in spi_nor_parse_sccr()
1269 if (!params->vreg_offset) { in spi_nor_parse_sccr()
1270 ret = -ENOMEM; in spi_nor_parse_sccr()
1274 params->vreg_offset[0] = dwords[SFDP_DWORD(1)]; in spi_nor_parse_sccr()
1275 params->n_dice = 1; in spi_nor_parse_sccr()
1279 nor->flags |= SNOR_F_IO_MODE_EN_VOLATILE; in spi_nor_parse_sccr()
1287 * spi_nor_parse_sccr_mc() - Parse the Status, Control and Configuration
1288 * Register Map Offsets for Multi-Chip SPI Memory
1290 * @nor: pointer to a 'struct spi_nor'
1294 * Return: 0 on success, -errno otherwise.
1296 static int spi_nor_parse_sccr_mc(struct spi_nor *nor, in spi_nor_parse_sccr_mc() argument
1299 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_parse_sccr_mc()
1305 len = sccr_mc_header->length * sizeof(*dwords); in spi_nor_parse_sccr_mc()
1308 return -ENOMEM; in spi_nor_parse_sccr_mc()
1311 ret = spi_nor_read_sfdp(nor, addr, len, dwords); in spi_nor_parse_sccr_mc()
1315 le32_to_cpu_array(dwords, sccr_mc_header->length); in spi_nor_parse_sccr_mc()
1318 * Pair of DOWRDs (volatile and non-volatile register offsets) per in spi_nor_parse_sccr_mc()
1321 n_dice = 1 + sccr_mc_header->length / 2; in spi_nor_parse_sccr_mc()
1324 params->vreg_offset = in spi_nor_parse_sccr_mc()
1325 devm_krealloc(nor->dev, params->vreg_offset, in spi_nor_parse_sccr_mc()
1328 if (!params->vreg_offset) { in spi_nor_parse_sccr_mc()
1329 ret = -ENOMEM; in spi_nor_parse_sccr_mc()
1334 params->vreg_offset[i] = dwords[SFDP_DWORD(i) * 2]; in spi_nor_parse_sccr_mc()
1336 params->n_dice = n_dice; in spi_nor_parse_sccr_mc()
1344 * spi_nor_post_sfdp_fixups() - Updates the flash's parameters and settings
1347 * @nor: pointer to a 'struct spi_nor'
1352 static int spi_nor_post_sfdp_fixups(struct spi_nor *nor) in spi_nor_post_sfdp_fixups() argument
1356 if (nor->manufacturer && nor->manufacturer->fixups && in spi_nor_post_sfdp_fixups()
1357 nor->manufacturer->fixups->post_sfdp) { in spi_nor_post_sfdp_fixups()
1358 ret = nor->manufacturer->fixups->post_sfdp(nor); in spi_nor_post_sfdp_fixups()
1363 if (nor->info->fixups && nor->info->fixups->post_sfdp) in spi_nor_post_sfdp_fixups()
1364 return nor->info->fixups->post_sfdp(nor); in spi_nor_post_sfdp_fixups()
1370 * spi_nor_check_sfdp_signature() - check for a valid SFDP signature
1371 * @nor: pointer to a 'struct spi_nor'
1376 * Return: 0 on success, -errno otherwise.
1378 int spi_nor_check_sfdp_signature(struct spi_nor *nor) in spi_nor_check_sfdp_signature() argument
1384 err = spi_nor_read_sfdp_dma_unsafe(nor, 0, sizeof(signature), in spi_nor_check_sfdp_signature()
1391 return -EINVAL; in spi_nor_check_sfdp_signature()
1397 * spi_nor_parse_sfdp() - parse the Serial Flash Discoverable Parameters.
1398 * @nor: pointer to a 'struct spi_nor'
1402 * (Q)SPI memory manufacturers. Those hard-coded tables allow us to learn at
1406 * Return: 0 on success, -errno otherwise.
1408 int spi_nor_parse_sfdp(struct spi_nor *nor) in spi_nor_parse_sfdp() argument
1413 struct device *dev = nor->dev; in spi_nor_parse_sfdp()
1420 err = spi_nor_read_sfdp_dma_unsafe(nor, 0, sizeof(header), &header); in spi_nor_parse_sfdp()
1427 return -EINVAL; in spi_nor_parse_sfdp()
1435 bfpt_header->major != SFDP_JESD216_MAJOR) in spi_nor_parse_sfdp()
1436 return -EINVAL; in spi_nor_parse_sfdp()
1457 return -ENOMEM; in spi_nor_parse_sfdp()
1459 err = spi_nor_read_sfdp(nor, sizeof(header), in spi_nor_parse_sfdp()
1490 err = -ENOMEM; in spi_nor_parse_sfdp()
1500 sfdp->num_dwords = DIV_ROUND_UP(sfdp_size, sizeof(*sfdp->dwords)); in spi_nor_parse_sfdp()
1501 sfdp->dwords = devm_kcalloc(dev, sfdp->num_dwords, in spi_nor_parse_sfdp()
1502 sizeof(*sfdp->dwords), GFP_KERNEL); in spi_nor_parse_sfdp()
1503 if (!sfdp->dwords) { in spi_nor_parse_sfdp()
1504 err = -ENOMEM; in spi_nor_parse_sfdp()
1509 err = spi_nor_read_sfdp(nor, 0, sfdp_size, sfdp->dwords); in spi_nor_parse_sfdp()
1512 devm_kfree(dev, sfdp->dwords); in spi_nor_parse_sfdp()
1517 nor->sfdp = sfdp; in spi_nor_parse_sfdp()
1527 param_header->major == SFDP_JESD216_MAJOR && in spi_nor_parse_sfdp()
1528 (param_header->minor > bfpt_header->minor || in spi_nor_parse_sfdp()
1529 (param_header->minor == bfpt_header->minor && in spi_nor_parse_sfdp()
1530 param_header->length > bfpt_header->length))) in spi_nor_parse_sfdp()
1534 err = spi_nor_parse_bfpt(nor, bfpt_header); in spi_nor_parse_sfdp()
1544 err = spi_nor_parse_smpt(nor, param_header); in spi_nor_parse_sfdp()
1548 err = spi_nor_parse_4bait(nor, param_header); in spi_nor_parse_sfdp()
1552 err = spi_nor_parse_profile1(nor, param_header); in spi_nor_parse_sfdp()
1556 err = spi_nor_parse_sccr(nor, param_header); in spi_nor_parse_sfdp()
1560 err = spi_nor_parse_sccr_mc(nor, param_header); in spi_nor_parse_sfdp()
1580 err = spi_nor_post_sfdp_fixups(nor); in spi_nor_parse_sfdp()