日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

從這篇文章你能學到如何使用MMC框架里的輪詢機制做探卡檢測,十分簡單。

1 前言

最近遇到客戶提的一個問題,大概意思是他們的SDIO Wi-Fi在卸載Wi-Fi驅動后再加載就檢測不到Wi-Fi設備了。從他的問題看大概是熱插拔有問題。

想要支持Wi-Fi復位后能重新掃描到Wi-Fi設備,需要host設置MMC_CAP_NEEDS_POLL。

#define MMC_CAP_NEEDS_POLL	(1 << 5)	/* Needs polling for card-detection */

2 如何使用MMC里的輪詢機制做探卡檢測?

先說方法,后面再分析。

方法一:修改dts,在對應的節點增加字段broken-cd,同時,如果有non-removable字段,必須去掉該字段。

 

方法二:通過其他手段設置host->caps |= MMC_CAP_NEEDS_POLL

3 MMC里的輪詢機制剖析

3.1 在dts設置broken-cd字段,代碼在哪里解析?

在mmc_of_parse函數,路徑是driversmmccorecore.c,of_property_read_bool函數讀broken-cd字段,如果讀到,就給host設置MMC_CAP_NEEDS_POLL能力。

int mmc_of_parse(struct mmc_host *host)
{
    /* 省略 */
	/*
	 * Configure CD and WP pins. They are both by default active low to
	 * match the SDHCI spec. If GPIOS are provided for CD and / or WP, the
	 * mmc-gpio helpers are used to attach, configure and use them. If
	 * polarity inversion is specified in DT, one of MMC_CAP2_CD_ACTIVE_HIGH
	 * and MMC_CAP2_RO_ACTIVE_HIGH capability-2 flags is set. If the
	 * "broken-cd" property is provided, the MMC_CAP_NEEDS_POLL capability
	 * is set. If the "non-removable" property is found, the
	 * MMC_CAP_NONREMOVABLE capability is set and no card-detection
	 * configuration is performed.
	 */
	/* Parse Card Detection */
	if (of_property_read_bool(np, "non-removable")) {
		host->caps |= MMC_CAP_NONREMOVABLE;
		if (of_property_read_bool(np, "cd-post"))
			host->caps2 |= MMC_CAP2_CD_POST;
	} else {
		cd_cap_invert = of_property_read_bool(np, "cd-inverted");
		if (of_property_read_bool(np, "broken-cd"))
			host->caps |= MMC_CAP_NEEDS_POLL;
		ret = mmc_gpiod_request_cd(host, "cd", 0, true,
					   0, &cd_gpio_invert);
		if (!ret)
			dev_info(host->parent, "Got CD GPIOn");
		else if (ret != -ENOENT && ret != -ENOSYS)
			return ret;
		/*
		 * There are two ways to flag that the CD line is inverted:
		 * through the cd-inverted flag and by the GPIO line itself
		 * being inverted from the GPIO subsystem. This is a leftover
		 * from the times when the GPIO subsystem did not make it
		 * possible to flag a line as inverted.
		 *
		 * If the capability on the host AND the GPIO line are
		 * both inverted, the end result is that the CD line is
		 * not inverted.
		 */
		if (cd_cap_invert ^ cd_gpio_invert)
			host->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
	}
    /* 省略 */
}

3.2 探卡檢測流程

mmc_alloc_host函數會創建一個工作隊列,mmc_rescan與host->detect綁定。

INIT_DELAYED_WORK(&host->detect, mmc_rescan);

mmc_rescan就是掃描卡的函數

void mmc_rescan(struct work_struct *work)
{
	struct mmc_host *host =
		container_of(work, struct mmc_host, detect.work);
	int i;
	if (host->trigger_card_event && host->ops->card_event) {
		host->ops->card_event(host);
		host->trigger_card_event = false;
	}
	if (host->rescan_disable)
		return;
	/* If there is a non-removable card registered, only scan once */
	if ((host->caps & MMC_CAP_NONREMOVABLE) && host->rescan_entered)
		return;
	host->rescan_entered = 1;
	mmc_bus_get(host);
	/*
	 * if there is a _removable_ card registered, check whether it is
	 * still present
	 */
	if (host->bus_ops && !host->bus_dead
	    && !(host->caps & MMC_CAP_NONREMOVABLE))
		host->bus_ops->detect(host);
	host->detect_change = 0;
	/*
	 * Let mmc_bus_put() free the bus/bus_ops if we've found that
	 * the card is no longer present.
	 */
	mmc_bus_put(host);
	mmc_bus_get(host);
	/* if there still is a card present, stop here */
	if (host->bus_ops != NULL) {
		mmc_bus_put(host);
		goto out;
	}
	/*
	 * Only we can add a new handler, so it's safe to
	 * release the lock here.
	 */
	mmc_bus_put(host);
	if (!(host->caps & MMC_CAP_NONREMOVABLE) && host->ops->get_cd &&
			host->ops->get_cd(host) == 0) {
		mmc_claim_host(host);
		mmc_power_off(host);
		mmc_release_host(host);
		goto out;
	}
	mmc_claim_host(host);
	for (i = 0; i < ARRAY_SIZE(freqs); i++) {
		if (!mmc_rescan_try_freq(host, max(freqs[i], host->f_min)))
			break;
		if (freqs[i] <= host->f_min)
			break;
	}
	mmc_release_host(host);
 out:
	if (host->caps & MMC_CAP_NEEDS_POLL)
		mmc_schedule_delayed_work(&host->detect, HZ);
}

看到最后兩行,判斷host的能力,如果設置了MMC_CAP_NEEDS_POLL,也就是輪詢機制,就會每隔HZ(這是個宏)時間執行一次host->detect,也就是mmc_rescan。

總結

對于探卡檢測,通過在dts里面配置broken-cd就可以實現輪詢探卡檢測。

分享到:
標簽:Linux
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定