Skip to content

Commit dcbf8f0

Browse files
committed
driver: flash: Add Set/ Get write protect function
Add Set_WP function to set SPI flash WP line to low Add Get_WP function to obtain status of the SPI flash WP line Signed-off-by: Benson Huang <[email protected]>
1 parent 6e34acc commit dcbf8f0

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

drivers/flash/flash_realtek_rts5912.c

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,34 @@ static int flash_read_sr2(const struct device *dev, uint8_t *val)
427427
}
428428
#endif
429429

430+
#ifdef CONFIG_FLASH_EX_OP_ENABLED
431+
#define SPIC_BASE 0x40010200ul
432+
static int flash_set_wp(const struct device *dev, uint8_t *val, uint8_t cnt)
433+
{
434+
volatile uint32_t *reg = (volatile uint32_t *)(SPIC_BASE + 0x110u);
435+
436+
if (!val) {
437+
return -EINVAL;
438+
}
439+
440+
if (*val) {
441+
*reg |= (1u << 1);
442+
}
443+
444+
return 0;
445+
}
446+
447+
static int flash_get_wp(const struct device *dev, uint8_t *val)
448+
{
449+
volatile uint32_t *reg = (volatile uint32_t *)(SPIC_BASE + 0x110u);
450+
uint32_t tmp = *reg;
451+
452+
*val = (uint8_t)(tmp & 0x02u);
453+
454+
return 0;
455+
}
456+
#endif
457+
430458
static int flash_wait_till_ready(const struct device *dev)
431459
{
432460
int ret;
@@ -438,9 +466,6 @@ static int flash_wait_till_ready(const struct device *dev)
438466
*/
439467
do {
440468
ret = flash_read_sr(dev, &sr);
441-
if (ret < 0) {
442-
return ret;
443-
}
444469
if (!(sr & SPI_NOR_WIP_BIT)) {
445470
return 0;
446471
}
@@ -751,6 +776,12 @@ static int flash_rts5912_ex_op(const struct device *dev, uint16_t opcode, const
751776
case FLASH_RTS5912_EX_OP_RD_SR2:
752777
ret = flash_read_sr2(dev, (uint8_t *)in);
753778
break;
779+
case FLASH_RTS5912_EX_OP_SET_WP:
780+
ret = flash_set_wp(dev, (uint8_t *)out, 1);
781+
break;
782+
case FLASH_RTS5912_EX_OP_GET_WP:
783+
ret = flash_get_wp(dev, (uint8_t *)in);
784+
break;
754785
}
755786

756787
k_sem_give(&dev_data->sem);

include/zephyr/drivers/flash/rts5912_flash_api_ex.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ enum flash_rts5912_ex_ops {
1313
FLASH_RTS5912_EX_OP_WR_SR2,
1414
FLASH_RTS5912_EX_OP_RD_SR,
1515
FLASH_RTS5912_EX_OP_RD_SR2,
16+
FLASH_RTS5912_EX_OP_SET_WP,
17+
FLASH_RTS5912_EX_OP_GET_WP,
1618
};
1719

1820
#endif /* __ZEPHYR_INCLUDE_DRIVERS_RTS5912_FLASH_API_EX_H__ */

0 commit comments

Comments
 (0)