History

mtd: spi-nor: Rework the SPI NOR lock/unlock logic

Add the SNOR_F_HAS_LOCK flag and set it when SPI_NOR_HAS_LOCK is set in the flash_info entry or when it's a Micron or ST flash. Move the locking hooks in a separate struct so that we have just one field to update when we change the locking implementation.

Boris Brezillon committed 7 years ago

Commit dff97241 parent 64c160f2 files · +53 −20Browse files

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

Unified · Split

include/linux/mtd/spi-nor.h+16−7
@@ -243,6 +243,7 @@ enum spi_nor_option_flags { · 242 unmodified lines
243243 SNOR_F_BROKEN_RESET = BIT(6),
244244 SNOR_F_4B_OPCODES = BIT(7),
245245 SNOR_F_HAS_4BAIT = BIT(8),
246+ SNOR_F_HAS_LOCK = BIT(9),
246247 };
247248
248249 /**
@@ -465,6 +466,18 @@ enum spi_nor_pp_command_index { · 216 unmodified lines
465466 /* Forward declaration that will be used in 'struct spi_nor_flash_parameter' */
466467 struct spi_nor;
467468
469+/**
470+ * struct spi_nor_locking_ops - SPI NOR locking methods
471+ * @lock: lock a region of the SPI NOR.
472+ * @unlock: unlock a region of the SPI NOR.
473+ * @is_locked: check if a region of the SPI NOR is completely locked
474+ */
475+struct spi_nor_locking_ops {
476+ int (*lock)(struct spi_nor *nor, loff_t ofs, uint64_t len);
477+ int (*unlock)(struct spi_nor *nor, loff_t ofs, uint64_t len);
478+ int (*is_locked)(struct spi_nor *nor, loff_t ofs, uint64_t len);
479+};
480+
468481 /**
469482 * struct spi_nor_flash_parameter - SPI NOR flash parameters and settings.
470483 * Includes legacy flash parameters and settings that can be overwritten
@@ -483,6 +496,7 @@ struct spi_nor; · 12 unmodified lines
483496 * Table.
484497 * @quad_enable: enables SPI NOR quad mode.
485498 * @set_4byte: puts the SPI NOR in 4 byte addressing mode.
499+ * @locking_ops: SPI NOR locking methods.
486500 */
487501 struct spi_nor_flash_parameter {
488502 u64 size;
@@ -496,6 +510,8 @@ struct spi_nor_flash_parameter { · 7 unmodified lines
496510
497511 int (*quad_enable)(struct spi_nor *nor);
498512 int (*set_4byte)(struct spi_nor *nor, bool enable);
513+
514+ const struct spi_nor_locking_ops *locking_ops;
499515 };
500516
501517 /**
@@ -536,10 +552,6 @@ struct flash_info; · 34 unmodified lines
536552 * @erase: [DRIVER-SPECIFIC] erase a sector of the SPI NOR
537553 * at the offset @offs; if not provided by the driver,
538554 * spi-nor will send the erase opcode via write_reg()
539− * @flash_lock: [FLASH-SPECIFIC] lock a region of the SPI NOR
540− * @flash_unlock: [FLASH-SPECIFIC] unlock a region of the SPI NOR
541− * @flash_is_locked: [FLASH-SPECIFIC] check if a region of the SPI NOR is
542− * completely locked
543555 * @clear_sr_bp: [FLASH-SPECIFIC] clears the Block Protection Bits from
544556 * the SPI NOR Status Register.
545557 * @params: [FLASH-SPECIFIC] SPI-NOR flash parameters and settings.
@@ -579,9 +591,6 @@ struct spi_nor { · 33 unmodified lines
579591 size_t len, const u_char *write_buf);
580592 int (*erase)(struct spi_nor *nor, loff_t offs);
581593
582− int (*flash_lock)(struct spi_nor *nor, loff_t ofs, uint64_t len);
583− int (*flash_unlock)(struct spi_nor *nor, loff_t ofs, uint64_t len);
584− int (*flash_is_locked)(struct spi_nor *nor, loff_t ofs, uint64_t len);
585594 int (*clear_sr_bp)(struct spi_nor *nor);
586595 struct spi_nor_flash_parameter params;
587596

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t