• DA9034驱动程序阅读笔记(6)


    转载时请注明出处和作者联系方式
    文章出处:http://www.limodev.cn/blog
    作者联系方式:李先静 <xianjimli at hotmail dot com>

    DA9034是一个集成了电源管理、音频设备、触摸屏控制器和能用A/D|D/A转换的多功能芯片。最近读了一下相关驱动程序,这里记些笔记,不成体系,作为备忘而已。有兴趣的朋友可以一起讨论。

    电源驱动主要是为用户空间提供一些接口,让用户空间可以查询相应的状态,比如是否在充电,以及电池的电量等。

    电源设备是一个platform device,在littleton.c中定义:

    static struct platform_device micco_power_device = {
        .name       = "micco-power",
        .id     = -1,
        .dev        = {
            .platform_data = &power_pdata,
        },
    };

    电源驱动程序在drivers/power/micco_power.c里:

    static struct platform_driver micco_power_pdrv = {
        .driver = {
            .name = "micco-power",
        },
        .probe = micco_power_probe,
        .remove = micco_power_remove,
        .suspend = micco_power_suspend,
        .resume = micco_power_resume,
    };

    在micco_power_probe函数里:

    创建了两个timer:

        setup_timer(&charger_timer, charger_timer_func, 0);
        setup_timer(&supply_timer, supply_timer_func, 0);

    charger_timer_func主要功能是更新充电状态,由于power_pdata里的回调函数都是空的,所以其实什么也没有做。

    struct pda_power_pdata {
        int (*init)(struct device *dev);
        int (*is_ac_online)(void);
        int (*is_usb_online)(void);
        void (*set_charge)(int flags);
        void (*exit)(struct device *dev);
     
        char **supplied_to;
        size_t num_supplicants;
     
        unsigned int wait_for_status; /* msecs, default is 500 */
        unsigned int wait_for_charger; /* msecs, default is 500 */
        unsigned int polling_interval; /* msecs, default is 2000 */
    };
     
    static struct pda_power_pdata power_pdata = {
        .polling_interval = 1000,
    };

    supply_timer_func主要功能是更新供电状态,最终会调用函数power_supply_changed_work:
    由于external_power_changed是空的,所以power_supply_changed_work只做了两件事,一是更新充电指示灯,二是上报uevent通知用户空间。

    static void power_supply_changed_work(struct work_struct *work)
    {
        struct power_supply *psy = container_of(work, struct power_supply,
                            changed_work);
     
        dev_dbg(psy->dev, "%s/n", __func__);
     
        class_for_each_device(power_supply_class, NULL, psy,
                      __power_supply_changed_work);
     
        power_supply_update_leds(psy);
     
        kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE);
    }

    接下来注册了几个power supply:充电器、USB和电池:

        /* register ac power supply */
        ret = power_supply_register(power_dev, &micco_psy_ac);
        if (ret) {
            dev_err(power_dev, "failed to register %s power supply/n",
                micco_psy_ac.name);
            goto ac_supply_failed;
        }
     
        /* register usb power supply */
        ret = power_supply_register(power_dev, &micco_psy_usb);
        if (ret) {
            dev_err(power_dev, "failed to register %s power supply/n",
                micco_psy_usb.name);
            goto usb_supply_failed;
        }
     
        /* register battery power supply */
        ret = power_supply_register(power_dev, &micco_bat);
        if (ret) {
            dev_err(power_dev, "failed to register %s power supply/n",
                micco_bat.name);
            goto battery_supply_failed;
        }

    最后打开充设备:

    ret = micco_charger_open();

    现在看下充电器的supply:

    只有一个“是否插上”的属性:

    static enum power_supply_property micco_power_props[] = {
        POWER_SUPPLY_PROP_ONLINE,
    };

    可以用来给主电池和备用电池充电:

    static char *micco_power_supplied_to[] = {
        "main-battery",
        "backup-battery",
    };

    配置信息。

    static struct power_supply micco_psy_ac = {
        .name = "ac",
        .type = POWER_SUPPLY_TYPE_MAINS,
        .supplied_to = micco_power_supplied_to,
        .num_supplicants = ARRAY_SIZE(micco_power_supplied_to),
        .properties = micco_power_props,
        .num_properties = ARRAY_SIZE(micco_power_props),
        .get_property = micco_power_get_property,
    };

    USB的supply:其配置和充电器基本一样:
    只有一个“是否插上”的属性:

    static enum power_supply_property micco_power_props[] = {
        POWER_SUPPLY_PROP_ONLINE,
    };

    可以用来给主电池和备用电池充电:

    static char *micco_power_supplied_to[] = {
        "main-battery",
        "backup-battery",
    };
     
    static struct power_supply micco_psy_usb = {
        .name = "usb",
        .type = POWER_SUPPLY_TYPE_USB,
        .supplied_to = micco_power_supplied_to,
        .num_supplicants = ARRAY_SIZE(micco_power_supplied_to),
        .properties = micco_power_props,
        .num_properties = ARRAY_SIZE(micco_power_props),
        .get_property = micco_power_get_property,
    };

    电池supply:
    属性很多:

    static enum power_supply_property micco_bat_props[] = {
        POWER_SUPPLY_PROP_STATUS,
        POWER_SUPPLY_PROP_PRESENT,
        POWER_SUPPLY_PROP_HEALTH,
        POWER_SUPPLY_PROP_TECHNOLOGY,
        POWER_SUPPLY_PROP_VOLTAGE_NOW,
        POWER_SUPPLY_PROP_VOLTAGE_AVG,
        POWER_SUPPLY_PROP_CURRENT_AVG,
        POWER_SUPPLY_PROP_CAPACITY,
        POWER_SUPPLY_PROP_TEMP,
        POWER_SUPPLY_PROP_TEMP_AMBIENT,
        POWER_SUPPLY_PROP_MANUFACTURER,
        POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
        POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
    };
     
    static struct power_supply micco_bat = {
        .name = "battery",
        .type = POWER_SUPPLY_TYPE_BATTERY,
        .properties = micco_bat_props,
        .num_properties = ARRAY_SIZE(micco_bat_props),
        .get_property = micco_bat_get_property,
        .use_for_apm = 1,
    };

  • 相关阅读:
    Tensorflow的对二次函数的神经网络训练
    ubuntu16.04的Anaconda下的tensorflow安装py3.5
    数字信号处理C语言(3) ------FFT
    数字信号处理C语言(2) ------带高斯噪声的sin函数和组合sin函数
    数字信号处理C语言(1) ------均匀分布和高斯分布随机数
    CCIE学习笔记 ----TSHOOT
    CCIE学习笔记 ----BGP
    CCIE学习笔记 ----GRE over IPsec
    调试
    Java protobuf框架使用向导
  • 原文地址:https://www.cnblogs.com/zhangyunlin/p/6167457.html
Copyright © 2020-2023  润新知