QSPI Flash驱动代码分析(等待QSPI空闲)

本文详细解析了如何在Linux驱动中实现QSPIFlash的等待空闲功能,包括cqspi_is_idle函数利用配置寄存器判断接口状态,cqspi_wait_idle函数的超时处理和cpu_relax暂停策略。
摘要由CSDN通过智能技术生成

QSPI Flash驱动代码分析(等待QSPI空闲)

        等待QSPI空闲的含义是,在一个时间间隔内连续N次判断出QSPI处于空闲状态。

1. 函数cqspi_is_idle()

通过QSPI配置寄存器(偏移量0x00)的状态只读bit[31]位,该位为1表示串行接口和QSPI流水管道处于空闲状态。

2. 函数cqspi_wait_idle()

该函数是为了等待QSPI空闲,要求在CQSPI_TIMEOUT_MS(500ms)时间内有连续poll_idle_retry(3)次判断出QSPI空闲;否则就退出超时。

注意:每次判断后需要暂时放弃当前CPU执行,即调用cpu_relax()。

static bool cqspi_is_idle(struct cqspi_st *cqspi)
{
	u32 reg = readl(cqspi->iobase + CQSPI_REG_CONFIG);

	return reg & (1UL << CQSPI_REG_CONFIG_IDLE_LSB);
}

static int cqspi_wait_idle(struct cqspi_st *cqspi)
{
	const unsigned int poll_idle_retry = 3;
	unsigned int count = 0;
	unsigned long timeout;

	timeout = jiffies + msecs_to_jiffies(CQSPI_TIMEOUT_MS);
	while (1) {
		/*
		 * Read few times in succession to ensure the controller
		 * is indeed idle, that is, the bit does not transition
		 * low again.
		 */
		if (cqspi_is_idle(cqspi))
			count++;
		else
			count = 0;

		if (count >= poll_idle_retry)
			return 0;

		if (time_after(jiffies, timeout)) {
			/* Timeout, in busy mode. */
			dev_err(&cqspi->pdev->dev,
				"QSPI is still busy after %dms timeout.\n",
				CQSPI_TIMEOUT_MS);
			return -ETIMEDOUT;
		}

		cpu_relax();
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值