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.
Showing the changes to include/linux (1 of 2 files). Show all
Unified · Split
| @@ -243,6 +243,7 @@ enum spi_nor_option_flags { · 242 unmodified lines | ||
| 243 | 243 | SNOR_F_BROKEN_RESET = BIT(6), |
| 244 | 244 | SNOR_F_4B_OPCODES = BIT(7), |
| 245 | 245 | SNOR_F_HAS_4BAIT = BIT(8), |
| 246 | + SNOR_F_HAS_LOCK = BIT(9), | |
| 246 | 247 | }; |
| 247 | 248 | |
| 248 | 249 | /** |
| @@ -465,6 +466,18 @@ enum spi_nor_pp_command_index { · 216 unmodified lines | ||
| 465 | 466 | /* Forward declaration that will be used in 'struct spi_nor_flash_parameter' */ |
| 466 | 467 | struct spi_nor; |
| 467 | 468 | |
| 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 | + | |
| 468 | 481 | /** |
| 469 | 482 | * struct spi_nor_flash_parameter - SPI NOR flash parameters and settings. |
| 470 | 483 | * Includes legacy flash parameters and settings that can be overwritten |
| @@ -483,6 +496,7 @@ struct spi_nor; · 12 unmodified lines | ||
| 483 | 496 | * Table. |
| 484 | 497 | * @quad_enable: enables SPI NOR quad mode. |
| 485 | 498 | * @set_4byte: puts the SPI NOR in 4 byte addressing mode. |
| 499 | + * @locking_ops: SPI NOR locking methods. | |
| 486 | 500 | */ |
| 487 | 501 | struct spi_nor_flash_parameter { |
| 488 | 502 | u64 size; |
| @@ -496,6 +510,8 @@ struct spi_nor_flash_parameter { · 7 unmodified lines | ||
| 496 | 510 | |
| 497 | 511 | int (*quad_enable)(struct spi_nor *nor); |
| 498 | 512 | int (*set_4byte)(struct spi_nor *nor, bool enable); |
| 513 | + | |
| 514 | + const struct spi_nor_locking_ops *locking_ops; | |
| 499 | 515 | }; |
| 500 | 516 | |
| 501 | 517 | /** |
| @@ -536,10 +552,6 @@ struct flash_info; · 34 unmodified lines | ||
| 536 | 552 | * @erase: [DRIVER-SPECIFIC] erase a sector of the SPI NOR |
| 537 | 553 | * at the offset @offs; if not provided by the driver, |
| 538 | 554 | * 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 | |
| 543 | 555 | * @clear_sr_bp: [FLASH-SPECIFIC] clears the Block Protection Bits from |
| 544 | 556 | * the SPI NOR Status Register. |
| 545 | 557 | * @params: [FLASH-SPECIFIC] SPI-NOR flash parameters and settings. |
| @@ -579,9 +591,6 @@ struct spi_nor { · 33 unmodified lines | ||
| 579 | 591 | size_t len, const u_char *write_buf); |
| 580 | 592 | int (*erase)(struct spi_nor *nor, loff_t offs); |
| 581 | 593 | |
| 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); | |
| 585 | 594 | int (*clear_sr_bp)(struct spi_nor *nor); |
| 586 | 595 | struct spi_nor_flash_parameter params; |
| 587 | 596 | |