History

mtd: spi-nor: Trim what is exposed in spi-nor.h

The SPI NOR controllers drivers must not be able to use structures that are meant just for the SPI NOR core. struct spi_nor_flash_parameter is filled at run-time with info gathered from flash_info, manufacturer and sfdp data. struct spi_nor_flash_parameter should be opaque to the SPI NOR controller drivers, make sure it is. spi_nor_option_flags, spi_nor_read_command, spi_nor_pp_command, spi_nor_read_command_index and spi_nor_pp_command_index are defined for the core use, make sure they are opaque to the SPI NOR controller drivers.

Tudor Ambarus committed 6 years ago

Commit 829ec641 parent d3c4bb311 files · +294 −296Browse files

Showing the changes to include/linux (1 of 11 files). Show all

Unified · Split

include/linux/mtd/spi-nor.h+6−254
@@ -210,110 +210,6 @@ static inline u8 spi_nor_get_protocol_width(enum spi_nor_protocol proto) · 209 unmodified lines
210 return spi_nor_get_protocol_data_nbits(proto);210 return spi_nor_get_protocol_data_nbits(proto);
211}211}
212 212
213enum spi_nor_option_flags {
214 SNOR_F_USE_FSR = BIT(0),
215 SNOR_F_HAS_SR_TB = BIT(1),
216 SNOR_F_NO_OP_CHIP_ERASE = BIT(2),
217 SNOR_F_READY_XSR_RDY = BIT(3),
218 SNOR_F_USE_CLSR = BIT(4),
219 SNOR_F_BROKEN_RESET = BIT(5),
220 SNOR_F_4B_OPCODES = BIT(6),
221 SNOR_F_HAS_4BAIT = BIT(7),
222 SNOR_F_HAS_LOCK = BIT(8),
223 SNOR_F_HAS_16BIT_SR = BIT(9),
224 SNOR_F_NO_READ_CR = BIT(10),
225 SNOR_F_HAS_SR_TB_BIT6 = BIT(11),
226
227};
228
229/**
230 * struct spi_nor_erase_type - Structure to describe a SPI NOR erase type
231 * @size: the size of the sector/block erased by the erase type.
232 * JEDEC JESD216B imposes erase sizes to be a power of 2.
233 * @size_shift: @size is a power of 2, the shift is stored in
234 * @size_shift.
235 * @size_mask: the size mask based on @size_shift.
236 * @opcode: the SPI command op code to erase the sector/block.
237 * @idx: Erase Type index as sorted in the Basic Flash Parameter
238 * Table. It will be used to synchronize the supported
239 * Erase Types with the ones identified in the SFDP
240 * optional tables.
241 */
242struct spi_nor_erase_type {
243 u32 size;
244 u32 size_shift;
245 u32 size_mask;
246 u8 opcode;
247 u8 idx;
248};
249
250/**
251 * struct spi_nor_erase_command - Used for non-uniform erases
252 * The structure is used to describe a list of erase commands to be executed
253 * once we validate that the erase can be performed. The elements in the list
254 * are run-length encoded.
255 * @list: for inclusion into the list of erase commands.
256 * @count: how many times the same erase command should be
257 * consecutively used.
258 * @size: the size of the sector/block erased by the command.
259 * @opcode: the SPI command op code to erase the sector/block.
260 */
261struct spi_nor_erase_command {
262 struct list_head list;
263 u32 count;
264 u32 size;
265 u8 opcode;
266};
267
268/**
269 * struct spi_nor_erase_region - Structure to describe a SPI NOR erase region
270 * @offset: the offset in the data array of erase region start.
271 * LSB bits are used as a bitmask encoding flags to
272 * determine if this region is overlaid, if this region is
273 * the last in the SPI NOR flash memory and to indicate
274 * all the supported erase commands inside this region.
275 * The erase types are sorted in ascending order with the
276 * smallest Erase Type size being at BIT(0).
277 * @size: the size of the region in bytes.
278 */
279struct spi_nor_erase_region {
280 u64 offset;
281 u64 size;
282};
283
284#define SNOR_ERASE_TYPE_MAX 4
285#define SNOR_ERASE_TYPE_MASK GENMASK_ULL(SNOR_ERASE_TYPE_MAX - 1, 0)
286
287#define SNOR_LAST_REGION BIT(4)
288#define SNOR_OVERLAID_REGION BIT(5)
289
290#define SNOR_ERASE_FLAGS_MAX 6
291#define SNOR_ERASE_FLAGS_MASK GENMASK_ULL(SNOR_ERASE_FLAGS_MAX - 1, 0)
292
293/**
294 * struct spi_nor_erase_map - Structure to describe the SPI NOR erase map
295 * @regions: array of erase regions. The regions are consecutive in
296 * address space. Walking through the regions is done
297 * incrementally.
298 * @uniform_region: a pre-allocated erase region for SPI NOR with a uniform
299 * sector size (legacy implementation).
300 * @erase_type: an array of erase types shared by all the regions.
301 * The erase types are sorted in ascending order, with the
302 * smallest Erase Type size being the first member in the
303 * erase_type array.
304 * @uniform_erase_type: bitmask encoding erase types that can erase the
305 * entire memory. This member is completed at init by
306 * uniform and non-uniform SPI NOR flash memories if they
307 * support at least one erase type that can erase the
308 * entire memory.
309 */
310struct spi_nor_erase_map {
311 struct spi_nor_erase_region *regions;
312 struct spi_nor_erase_region uniform_region;
313 struct spi_nor_erase_type erase_type[SNOR_ERASE_TYPE_MAX];
314 u8 uniform_erase_type;
315};
316
317/**213/**
318 * struct spi_nor_hwcaps - Structure for describing the hardware capabilies214 * struct spi_nor_hwcaps - Structure for describing the hardware capabilies
319 * supported by the SPI controller (bus master).215 * supported by the SPI controller (bus master).
@@ -389,61 +285,7 @@ struct spi_nor_hwcaps { · 69 unmodified lines
389#define SNOR_HWCAPS_ALL (SNOR_HWCAPS_READ_MASK | \285#define SNOR_HWCAPS_ALL (SNOR_HWCAPS_READ_MASK | \
390 SNOR_HWCAPS_PP_MASK)286 SNOR_HWCAPS_PP_MASK)
391 287
392struct spi_nor_read_command {288/* Forward declaration that is used in 'struct spi_nor_controller_ops' */
393 u8 num_mode_clocks;
394 u8 num_wait_states;
395 u8 opcode;
396 enum spi_nor_protocol proto;
397};
398
399struct spi_nor_pp_command {
400 u8 opcode;
401 enum spi_nor_protocol proto;
402};
403
404enum spi_nor_read_command_index {
405 SNOR_CMD_READ,
406 SNOR_CMD_READ_FAST,
407 SNOR_CMD_READ_1_1_1_DTR,
408
409 /* Dual SPI */
410 SNOR_CMD_READ_1_1_2,
411 SNOR_CMD_READ_1_2_2,
412 SNOR_CMD_READ_2_2_2,
413 SNOR_CMD_READ_1_2_2_DTR,
414
415 /* Quad SPI */
416 SNOR_CMD_READ_1_1_4,
417 SNOR_CMD_READ_1_4_4,
418 SNOR_CMD_READ_4_4_4,
419 SNOR_CMD_READ_1_4_4_DTR,
420
421 /* Octal SPI */
422 SNOR_CMD_READ_1_1_8,
423 SNOR_CMD_READ_1_8_8,
424 SNOR_CMD_READ_8_8_8,
425 SNOR_CMD_READ_1_8_8_DTR,
426
427 SNOR_CMD_READ_MAX
428};
429
430enum spi_nor_pp_command_index {
431 SNOR_CMD_PP,
432
433 /* Quad SPI */
434 SNOR_CMD_PP_1_1_4,
435 SNOR_CMD_PP_1_4_4,
436 SNOR_CMD_PP_4_4_4,
437
438 /* Octal SPI */
439 SNOR_CMD_PP_1_1_8,
440 SNOR_CMD_PP_1_8_8,
441 SNOR_CMD_PP_8_8_8,
442
443 SNOR_CMD_PP_MAX
444};
445
446/* Forward declaration that will be used in 'struct spi_nor_flash_parameter' */
447struct spi_nor;289struct spi_nor;
448 290
449/**291/**
@@ -474,74 +316,13 @@ struct spi_nor_controller_ops { · 24 unmodified lines
474 int (*erase)(struct spi_nor *nor, loff_t offs);316 int (*erase)(struct spi_nor *nor, loff_t offs);
475};317};
476 318
477/**319/*
478 * struct spi_nor_locking_ops - SPI NOR locking methods320 * Forward declarations that are used internally by the core and manufacturer
479 * @lock: lock a region of the SPI NOR.321 * drivers.
480 * @unlock: unlock a region of the SPI NOR.
481 * @is_locked: check if a region of the SPI NOR is completely locked
482 */
483struct spi_nor_locking_ops {
484 int (*lock)(struct spi_nor *nor, loff_t ofs, uint64_t len);
485 int (*unlock)(struct spi_nor *nor, loff_t ofs, uint64_t len);
486 int (*is_locked)(struct spi_nor *nor, loff_t ofs, uint64_t len);
487};
488
489/**
490 * struct spi_nor_flash_parameter - SPI NOR flash parameters and settings.
491 * Includes legacy flash parameters and settings that can be overwritten
492 * by the spi_nor_fixups hooks, or dynamically when parsing the JESD216
493 * Serial Flash Discoverable Parameters (SFDP) tables.
494 *
495 * @size: the flash memory density in bytes.
496 * @page_size: the page size of the SPI NOR flash memory.
497 * @hwcaps: describes the read and page program hardware
498 * capabilities.
499 * @reads: read capabilities ordered by priority: the higher index
500 * in the array, the higher priority.
501 * @page_programs: page program capabilities ordered by priority: the
502 * higher index in the array, the higher priority.
503 * @erase_map: the erase map parsed from the SFDP Sector Map Parameter
504 * Table.
505 * @quad_enable: enables SPI NOR quad mode.
506 * @set_4byte_addr_mode: puts the SPI NOR in 4 byte addressing mode.
507 * @convert_addr: converts an absolute address into something the flash
508 * will understand. Particularly useful when pagesize is
509 * not a power-of-2.
510 * @setup: configures the SPI NOR memory. Useful for SPI NOR
511 * flashes that have peculiarities to the SPI NOR standard
512 * e.g. different opcodes, specific address calculation,
513 * page size, etc.
514 * @locking_ops: SPI NOR locking methods.
515 */
516struct spi_nor_flash_parameter {
517 u64 size;
518 u32 page_size;
519
520 struct spi_nor_hwcaps hwcaps;
521 struct spi_nor_read_command reads[SNOR_CMD_READ_MAX];
522 struct spi_nor_pp_command page_programs[SNOR_CMD_PP_MAX];
523
524 struct spi_nor_erase_map erase_map;
525
526 int (*quad_enable)(struct spi_nor *nor);
527 int (*set_4byte_addr_mode)(struct spi_nor *nor, bool enable);
528 u32 (*convert_addr)(struct spi_nor *nor, u32 addr);
529 int (*setup)(struct spi_nor *nor, const struct spi_nor_hwcaps *hwcaps);
530
531 const struct spi_nor_locking_ops *locking_ops;
532};
533
534/**
535 * struct flash_info - Forward declaration of a structure used internally by
536 * spi_nor_scan()
537 */322 */
538struct flash_info;323struct flash_info;
539
540/**
541 * struct spi_nor_manufacturer - Forward declaration of a structure used
542 * internally by the core and manufacturer drivers.
543 */
544struct spi_nor_manufacturer;324struct spi_nor_manufacturer;
325struct spi_nor_flash_parameter;
545 326
546/**327/**
547 * struct spi_nor - Structure for defining a the SPI NOR layer328 * struct spi_nor - Structure for defining a the SPI NOR layer
@@ -596,7 +377,7 @@ struct spi_nor { · 48 unmodified lines
596 377
597 const struct spi_nor_controller_ops *controller_ops;378 const struct spi_nor_controller_ops *controller_ops;
598 379
599 struct spi_nor_flash_parameter params;380 struct spi_nor_flash_parameter *params;
600 381
601 struct {382 struct {
602 struct spi_mem_dirmap_desc *rdesc;383 struct spi_mem_dirmap_desc *rdesc;
@@ -606,35 +387,6 @@ struct spi_nor { · 3 unmodified lines
606 void *priv;387 void *priv;
607};388};
608 389
609static u64 __maybe_unused
610spi_nor_region_is_last(const struct spi_nor_erase_region *region)
611{
612 return region->offset & SNOR_LAST_REGION;
613}
614
615static u64 __maybe_unused
616spi_nor_region_end(const struct spi_nor_erase_region *region)
617{
618 return (region->offset & ~SNOR_ERASE_FLAGS_MASK) + region->size;
619}
620
621static void __maybe_unused
622spi_nor_region_mark_end(struct spi_nor_erase_region *region)
623{
624 region->offset |= SNOR_LAST_REGION;
625}
626
627static void __maybe_unused
628spi_nor_region_mark_overlay(struct spi_nor_erase_region *region)
629{
630 region->offset |= SNOR_OVERLAID_REGION;
631}
632
633static bool __maybe_unused spi_nor_has_uniform_erase(const struct spi_nor *nor)
634{
635 return !!nor->params.erase_map.uniform_erase_type;
636}
637
638static inline void spi_nor_set_flash_node(struct spi_nor *nor,390static inline void spi_nor_set_flash_node(struct spi_nor *nor,
639 struct device_node *np)391 struct device_node *np)
640{392{