if (ptr != pd->usb_psy || evt != PSY_EVENT_PROP_CHANGED) return 0; ret = power_supply_get_property(pd->usb_psy, POWER_SUPPLY_PROP_TYPEC_MODE, &val); if (ret) { usbpd_err(&pd->dev, "Unable to read USB TYPEC_MODE: %d\n", ret); return ret; } typec_mode = val.intval; ret = power_supply_get_property(pd->usb_psy, POWER_SUPPLY_PROP_PE_START, &val); if (ret) { usbpd_err(&pd->dev, "Unable to read USB PROP_PE_START: %d\n", ret); return ret; } /* Don't proceed if PE_START=0; start USB directly if needed */ if (!val.intval && !pd->pd_connected && typec_mode >= POWER_SUPPLY_TYPEC_SOURCE_DEFAULT) { ret = power_supply_get_property(pd->usb_psy, POWER_SUPPLY_PROP_REAL_TYPE, &val); if (ret) { usbpd_err(&pd->dev, "Unable to read USB TYPE: %d\n", ret); return ret; } if (val.intval == POWER_SUPPLY_TYPE_USB || val.intval == POWER_SUPPLY_TYPE_USB_CDP || val.intval == POWER_SUPPLY_TYPE_USB_FLOAT) { usbpd_dbg(&pd->dev, "typec mode:%d type:%d\n", typec_mode, val.intval); pd->typec_mode = typec_mode; queue_work(pd->wq, &pd->start_periph_work); printk("psy_change:start_periph_work\n");/////////////////////////////////////////////////////////////// } return 0; } ret = power_supply_get_property(pd->usb_psy, POWER_SUPPLY_PROP_PRESENT, &val); if (ret) { usbpd_err(&pd->dev, "Unable to read USB PRESENT: %d\n", ret); return ret; } pd->vbus_present = val.intval; /* * For sink hard reset, state machine needs to know when VBUS changes * - when in PE_SNK_TRANSITION_TO_DEFAULT, notify when VBUS falls * - when in PE_SNK_DISCOVERY, notify when VBUS rises */ if (typec_mode && ((!pd->vbus_present && pd->current_state == PE_SNK_TRANSITION_TO_DEFAULT) || (pd->vbus_present && pd->current_state == PE_SNK_DISCOVERY))) { usbpd_dbg(&pd->dev, "hard reset: typec mode:%d present:%d\n", typec_mode, pd->vbus_present); pd->typec_mode = typec_mode; if (!work_busy(&pd->sm_work)) kick_sm(pd, 0); else usbpd_dbg(&pd->dev, "usbpd_sm already running\n"); return 0; } if (pd->typec_mode == typec_mode) return 0; pd->typec_mode = typec_mode; usbpd_dbg(&pd->dev, "typec mode:%d present:%d orientation:%d\n", typec_mode, pd->vbus_present, usbpd_get_plug_orientation(pd));代码分析
时间: 2024-04-21 17:26:30 浏览: 130
PTR2000.rar_PTR 2000_PTR20_PTR2000_ptr2000 pdf_单片机 无线
这段代码是一个 USB Power Delivery 设备的驱动程序,主要是对 USB Type-C 模式和电源状态的监测和控制。具体来说,这段代码的作用是:当 USB 电源的属性发生变化时,首先获取 USB Type-C 模式和 PE_START 属性的值,如果 PE_START=0,说明 USB 设备已经连接,直接启动设备;否则,获取 USB 的类型,如果是 USB 或 USB_CDP 或 USB_FLOAT,则将 Type-C 模式和 USB 设备类型保存在设备上下文中,并在工作队列中启动一个工作项 start_periph_work;如果 VBUS 发生变化,需要进行硬复位操作,通知状态机进行相关处理。代码中有一些调试信息打印,用于调试程序。
阅读全文