安卓linux uevent核心上報機制例項
阿新 • • 發佈:2019-02-14
以拔出T卡為例,核心通知上層。這裡的T卡是一種sdio裝置,普通TF卡是塊裝置,安卓通過塊裝置可以知道T卡的移除。
kernel:
Index: kernel/drivers/mmc/host/msm_sdcc.c
===================================================================
--- kernel/drivers/mmc/host/msm_sdcc.c (revision 10898)
+++ kernel/drivers/mmc/host/msm_sdcc.c (working copy)
@@ -77,6 +77,8 @@
#define MSM_MMC_BUS_VOTING_DELAY 200 /* msecs */
#define INVALID_TUNING_PHASE -1
+struct device *mmc1_dev;
+static int obj_enable =0;
+static int set_kobject_env(const char *val, struct kernel_param *kp)
+{
+ printk("%s called 00 \n",__func__);
+ kobject_uevent_env(&mmc1_dev->kobj, KOBJ_CHANGE, NULL);
+ return 0;
+}
+module_param_call(obj, set_kobject_env, param_get_uint,
+ &obj_enable, 0644);
+
static irqreturn_t
msmsdcc_platform_status_irq(int irq, void *dev_id)
{
@@ -6186,6 +6205,11 @@
ret = device_create_file(&pdev->dev, &host->idle_timeout);
if (ret)
goto remove_polling_file;
+
+ if(mmc->index ==1)
+ mmc1_dev = &pdev->dev;
+
+
return 0;
java:
if (new File("/sys/devices/platform/msm_sdcc.3/uevent").exists()) {
mInvalidChargerObserver.startObserving(
"DEVPATH=/devices/platform/msm_sdcc.3");
}
private final UEventObserver mInvalidChargerObserver = new UEventObserver() {
@Override
public void onUEvent(UEventObserver.UEvent event) {
Slog.v(TAG, "Uevent changed ");
final int invalidCharger = "1".equals(event.get("SWITCH_STATE")) ? 1 : 0;
synchronized (mLock) {
if (mInvalidCharger != invalidCharger) {
mInvalidCharger = invalidCharger;
updateLocked();
}
}
}
};
kernel:
Index: kernel/drivers/mmc/host/msm_sdcc.c
===================================================================
--- kernel/drivers/mmc/host/msm_sdcc.c (revision 10898)
+++ kernel/drivers/mmc/host/msm_sdcc.c (working copy)
@@ -77,6 +77,8 @@
#define MSM_MMC_BUS_VOTING_DELAY 200 /* msecs */
#define INVALID_TUNING_PHASE -1
+struct device *mmc1_dev;
+static int obj_enable =0;
+static int set_kobject_env(const char *val, struct kernel_param *kp)
+{
+ printk("%s called 00 \n",__func__);
+ kobject_uevent_env(&mmc1_dev->kobj, KOBJ_CHANGE, NULL);
+ return 0;
+}
+module_param_call(obj, set_kobject_env, param_get_uint,
+ &obj_enable, 0644);
+
static irqreturn_t
msmsdcc_platform_status_irq(int irq, void *dev_id)
{
@@ -6186,6 +6205,11 @@
ret = device_create_file(&pdev->dev, &host->idle_timeout);
if (ret)
goto remove_polling_file;
+
+ if(mmc->index ==1)
+ mmc1_dev = &pdev->dev;
+
+
return 0;
java:
if (new File("/sys/devices/platform/msm_sdcc.3/uevent").exists()) {
mInvalidChargerObserver.startObserving(
"DEVPATH=/devices/platform/msm_sdcc.3");
}
private final UEventObserver mInvalidChargerObserver = new UEventObserver() {
@Override
public void onUEvent(UEventObserver.UEvent event) {
Slog.v(TAG, "Uevent changed ");
final int invalidCharger = "1".equals(event.get("SWITCH_STATE")) ? 1 : 0;
synchronized (mLock) {
if (mInvalidCharger != invalidCharger) {
mInvalidCharger = invalidCharger;
updateLocked();
}
}
}
};