.pm = &usb_extcon_pm_ops,
.of_match_table = usb_extcon_dt_match, // 用于匹配dts文件里的设备,如果有compatible 相同的设备后才会调用probe 函数
},
.id_table = usb_extcon_platform_ids,
};
module_platform_driver(usb_extcon_driver); // 该驱动的入口函数
接着查看probe 函数,里面有两个中断,分别是id-gpio和 vbus-gpio
bsp/kernel/kernel4.14/drivers/extcon/extcon-usb-gpio.c
static int usb_extcon_probe(struct platform_device *pdev)
{
…
info->id_gpiod = devm_gpiod_get_optional(&pdev->dev, “id”, GPIOD_IN);
info->vbus_gpiod = devm_gpiod_get_optional(&pdev->dev, “vbus”, GPIOD_IN);
…
if (info->id_gpiod)
// 用于防抖的
ret = gpiod_set_debounce(info->id_gpiod, USB_GPIO_DEBOUNCE_MS * 1000);
if (!ret && info->vbus_gpiod)
ret = gpiod_set_debounce(info->vbus_gpiod, USB_GPIO_DEBOUNCE_MS * 1000);
…
if (info->id_gpiod) {
info->id_irq = gpiod_to_irq(info->id_gpiod); // 将id-gpio 口设置为中断模式
…
// 设置中断条件,发生中断是调用usb_irq_handler() 方法,当GPIO 上拉或者下拉时触发中断
ret = devm_request_threaded_irq(dev, info->id_irq, NULL,
usb_irq_handler,
IRQF_TRIGGER_RISING |
IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
pdev->name, info);
…
}
if (info->vbus_gpiod) {
info->vbus_irq = gpiod_to_irq(info->vbus_gpiod); // 将vbus-gpio 口设置为中断模式
...
// 设置中断条件,发生中断是调用usb_irq_handler() 方法,当GPIO 上拉或者下拉时触发中断
ret = devm_request_threaded_irq(dev, info->vbus_irq, NULL,
usb_irq_handler,
IRQF_TRIGGER_RISING |
IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
pdev->name, info);
...
}
...
}
当id-gpio 和 vbus-gpio 口上拉或者下拉时触发中断,调用usb\_irq\_handler() 中断,上拉或者下拉代表USB 的插入和拔出。
bsp/kernel/kernel4.14/drivers/extcon/extcon-usb-gpio.c
static irqreturn_t usb_irq_handler(int irq, void *dev_id)
{
struct usb_extcon_info *info = dev_id;
queue_delayed_work(system_power_efficient_wq, &info->wq_detcable,
info->debounce_jiffies);
return IRQ_HANDLED;
}
static int usb_extcon_probe(struct platform_device *pdev)
{
…
INIT_DELAYED_WORK(&info->wq_detcable, usb_extcon_detect_cable); // 初始化工作队列wq_detcable 为usb_extcon_detect_cable() 方法
…
}