ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

高通平台读取USB ID

2021-02-06 11:31:47  阅读:397  来源: 互联网

标签:USB motg msm ID 高通 phy state id usb


参考文件:
kernel/drivers/usb/phy/phy-msm-usb.c
kernel/msm-3.18/drivers/usb/phy/phy-msm-usb.c

+//begin:stone modify for usb id
+static bool usb_id_flag = 1;
+bool get_usb_id(void)
+{
+	return usb_id_flag;
+}
+EXPORT_SYMBOL(get_usb_id);
+//end:stone modify for usb id

在msm_id_status_w函数中添加即可:

static void msm_id_status_w(struct work_struct *w)
{
	struct msm_otg *motg = container_of(w, struct msm_otg,
						id_status_work.work);
	int work = 0;
	int id_state = 0;

	dev_dbg(motg->phy.dev, "ID status_w\n");

	if (motg->pdata->pmic_id_irq)
		id_state = msm_otg_read_pmic_id_state(motg);
	else if (motg->ext_id_irq)
		id_state = gpio_get_value(motg->pdata->usb_id_gpio);
	else if (motg->phy_irq)
		id_state = msm_otg_read_phy_id_state(motg);
		//usb_otg: usb@78d9000 {中定义了:
		//interrupt-names = "core_irq", "async_irq","phy_irq";
		//motg->phy_irq = platform_get_irq_byname(pdev, "phy_irq");
		//所以phy_irq不为空,走到这里
		
	if (id_state) {
		if (!test_and_set_bit(ID, &motg->inputs)) {
			pr_debug("ID set\n");
			msm_otg_dbg_log_event(&motg->phy, "ID SET",
					motg->inputs, motg->phy.state);
			work = 1;
		}
	} else {
		if (test_and_clear_bit(ID, &motg->inputs)) {
			pr_debug("ID clear\n");
			msm_otg_dbg_log_event(&motg->phy, "ID CLEAR",
					motg->inputs, motg->phy.state);
			set_bit(A_BUS_REQ, &motg->inputs);
			work = 1;
		}
	}

	+//begin:stone modify for usb id
	+usb_id_flag = !!id_state;
	+printk(KERN_ERR "usb_id_flag=%d\n",usb_id_flag);
	+//end:stone modify for usb id

	if (work && (motg->phy.state != OTG_STATE_UNDEFINED)) {
		msm_otg_dbg_log_event(&motg->phy,
				"CHECK ID EVENT DURING SUSPEND",
				atomic_read(&motg->pm_suspended),
				motg->sm_work_pending);
		if (atomic_read(&motg->pm_suspended)) {
			motg->sm_work_pending = true;
		} else if (!motg->sm_work_pending) {
			/* process event only if previous one is not pending */
			queue_work(motg->otg_wq, &motg->sm_work);
		}
	}

}

真正读取ID的函数是msm_otg_read_phy_id_state:

static bool msm_otg_read_phy_id_state(struct msm_otg *motg)
{
	u8 val;

	/*
	 * clear the pending/outstanding interrupts and
	 * read the ID status from the SRC_STATUS register.
	 */
	writeb_relaxed(USB_PHY_ID_MASK, USB2_PHY_USB_PHY_INTERRUPT_CLEAR1);

	writeb_relaxed(0x1, USB2_PHY_USB_PHY_IRQ_CMD);
	/*
	 * Databook says 200 usec delay is required for
	 * clearing the interrupts.
	 */
	udelay(200);
	writeb_relaxed(0x0, USB2_PHY_USB_PHY_IRQ_CMD);

	val = readb_relaxed(USB2_PHY_USB_PHY_INTERRUPT_SRC_STATUS);
	if (val & USB_PHY_IDDIG_1_0)
		return false; /* ID is grounded */
	else
		return true;
}

标签:USB,motg,msm,ID,高通,phy,state,id,usb
来源: https://blog.csdn.net/cornerstone1/article/details/113715982

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有