From 7ff97417010946a571dae391f9489429ff07dfa1 Mon Sep 17 00:00:00 2001 From: Shuide Chen Date: Thu, 21 Jun 2018 09:56:02 +0800 Subject: [PATCH] power: battery add dummy battery driver [1/1] PD#169027: add dummy battery and charger for CTS/VTS some CTS and VTS testcases use the battery information, here implement a dummy battery for it. for P, it requires a dummy charger to set the online property to 1. Change-Id: I7cf516f7050b3930cfdd933dc65b811289f89c4f Signed-off-by: Shuide Chen --- MAINTAINERS | 6 + arch/arm64/boot/dts/amlogic/gxl_p212_1g.dts | 10 ++ arch/arm64/boot/dts/amlogic/gxl_p212_2g.dts | 10 ++ arch/arm64/boot/dts/amlogic/txlx_t962e_r321.dts | 9 ++ arch/arm64/configs/meson64_defconfig | 2 + drivers/amlogic/Kconfig | 1 + drivers/amlogic/Makefile | 3 + drivers/amlogic/battery/Kconfig | 15 +++ drivers/amlogic/battery/Makefile | 3 + drivers/amlogic/battery/amlogic_battery.c | 153 ++++++++++++++++++++++++ drivers/amlogic/battery/amlogic_charger.c | 120 +++++++++++++++++++ 11 files changed, 332 insertions(+) create mode 100644 drivers/amlogic/battery/Kconfig create mode 100644 drivers/amlogic/battery/Makefile create mode 100644 drivers/amlogic/battery/amlogic_battery.c create mode 100644 drivers/amlogic/battery/amlogic_charger.c diff --git a/MAINTAINERS b/MAINTAINERS index 13b7bd2..a12e940 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13437,6 +13437,12 @@ AMLOGIC MAILBOX DRIVER M: Yun Cai F: drivers/amlogic/mailbox/ +AMLOGIC DUMMY BATTERY DRIVER +M: Shuide +F: drivers/amlogic/battery/ +F: drivers/amlogic/battery/amlogic_battery.c +F: drivers/amlogic/battery/amlogic_charger.c + AMLOGIC REGISTER DEBUG DRIVER M: Yun Cai F: drivers/amlogic/reg_access/ diff --git a/arch/arm64/boot/dts/amlogic/gxl_p212_1g.dts b/arch/arm64/boot/dts/amlogic/gxl_p212_1g.dts index 3b46504..36939bb 100644 --- a/arch/arm64/boot/dts/amlogic/gxl_p212_1g.dts +++ b/arch/arm64/boot/dts/amlogic/gxl_p212_1g.dts @@ -139,6 +139,16 @@ }; }; + dummy-battery { + compatible = "amlogic, dummy-battery"; + status = "okay"; + }; + + dummy-charger { + compatible = "amlogic, dummy-charger"; + status = "okay"; + }; + bt-dev{ compatible = "amlogic, bt-dev"; dev_name = "bt-dev"; diff --git a/arch/arm64/boot/dts/amlogic/gxl_p212_2g.dts b/arch/arm64/boot/dts/amlogic/gxl_p212_2g.dts index 8f13082..98d49d7 100644 --- a/arch/arm64/boot/dts/amlogic/gxl_p212_2g.dts +++ b/arch/arm64/boot/dts/amlogic/gxl_p212_2g.dts @@ -148,6 +148,16 @@ }; }; + dummy-battery { + compatible = "amlogic, dummy-battery"; + status = "okay"; + }; + + dummy-charger { + compatible = "amlogic, dummy-charger"; + status = "okay"; + }; + bt-dev{ compatible = "amlogic, bt-dev"; dev_name = "bt-dev"; diff --git a/arch/arm64/boot/dts/amlogic/txlx_t962e_r321.dts b/arch/arm64/boot/dts/amlogic/txlx_t962e_r321.dts index 9365027..d1d8f02 100644 --- a/arch/arm64/boot/dts/amlogic/txlx_t962e_r321.dts +++ b/arch/arm64/boot/dts/amlogic/txlx_t962e_r321.dts @@ -212,6 +212,15 @@ }; }; + dummy-battery { + compatible = "amlogic, dummy-battery"; + status = "okay"; + }; + dummy-charger { + compatible = "amlogic, dummy-charger"; + status = "okay"; + }; + ethmac: ethernet@0xff3f0000 { compatible = "amlogic, gxbb-eth-dwmac"; status = "okay"; diff --git a/arch/arm64/configs/meson64_defconfig b/arch/arm64/configs/meson64_defconfig index 4ea0942..389af7d 100644 --- a/arch/arm64/configs/meson64_defconfig +++ b/arch/arm64/configs/meson64_defconfig @@ -361,6 +361,8 @@ CONFIG_AMLOGIC_ATV_DEMOD=y CONFIG_AMLOGIC_DEBUG=y CONFIG_AMLOGIC_DEBUG_LOCKUP=y CONFIG_AMLOGIC_DEFENDKEY=y +CONFIG_AMLOGIC_BATTERY_DUMMY=y +CONFIG_AMLOGIC_CHARGER_DUMMY=y CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug" CONFIG_DEVTMPFS=y CONFIG_DEVTMPFS_MOUNT=y diff --git a/drivers/amlogic/Kconfig b/drivers/amlogic/Kconfig index bbae04d..ea7a11b 100644 --- a/drivers/amlogic/Kconfig +++ b/drivers/amlogic/Kconfig @@ -132,5 +132,6 @@ source "drivers/amlogic/debug/Kconfig" source "drivers/amlogic/defendkey/Kconfig" +source "drivers/amlogic/battery/Kconfig" endmenu endif diff --git a/drivers/amlogic/Makefile b/drivers/amlogic/Makefile index fb12f96..e28869c 100644 --- a/drivers/amlogic/Makefile +++ b/drivers/amlogic/Makefile @@ -49,6 +49,9 @@ obj-$(CONFIG_AMLOGIC_EFUSE) += efuse/ obj-$(CONFIG_AMLOGIC_REBOOT) += reboot/ +obj-$(CONFIG_AMLOGIC_BATTERY_DUMMY) += battery/ +obj-$(CONFIG_AMLOGIC_CHARGER_DUMMY) += battery/ + obj-$(CONFIG_AMLOGIC_INTERNAL_PHY) += ethernet/phy/ obj-$(CONFIG_AMLOGIC_CPU_HOTPLUG) += cpu_hotplug/ diff --git a/drivers/amlogic/battery/Kconfig b/drivers/amlogic/battery/Kconfig new file mode 100644 index 0000000..d5229c4 --- /dev/null +++ b/drivers/amlogic/battery/Kconfig @@ -0,0 +1,15 @@ +config AMLOGIC_BATTERY_DUMMY + tristate "Dummy battery driver for Amlogic" + help + Say Y to enable generic support for battery charging according + to common Android policies. + This driver adds periodic battery level and health monitoring, + kernel log reporting and other debugging features, common board + battery file glue logic for battery/case temperature sensors, + etc. + +config AMLOGIC_CHARGER_DUMMY + tristate "Dummy charger driver for Amlogic" + help + Say Y to enable dummy support for battery charging according + to common Android policies diff --git a/drivers/amlogic/battery/Makefile b/drivers/amlogic/battery/Makefile new file mode 100644 index 0000000..4cbe530 --- /dev/null +++ b/drivers/amlogic/battery/Makefile @@ -0,0 +1,3 @@ + +obj-$(CONFIG_AMLOGIC_BATTERY_DUMMY) += amlogic_battery.o +obj-$(CONFIG_AMLOGIC_CHARGER_DUMMY) += amlogic_charger.o \ No newline at end of file diff --git a/drivers/amlogic/battery/amlogic_battery.c b/drivers/amlogic/battery/amlogic_battery.c new file mode 100644 index 0000000..cf6c52b --- /dev/null +++ b/drivers/amlogic/battery/amlogic_battery.c @@ -0,0 +1,153 @@ +/* + * drivers/amlogic/battery/amlogic_battery.c + * + * Copyright (C) 2017 Amlogic, Inc. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +struct dummy_battery_info { + struct device *dev; + struct power_supply *battery; + struct mutex lock; + unsigned int present; +}; + +static int dummy_batt_get_prop(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) +{ + static int counter = 1; + + switch (psp) { + case POWER_SUPPLY_PROP_PRESENT: + val->intval = 1; + break; + case POWER_SUPPLY_PROP_HEALTH: + val->intval = POWER_SUPPLY_HEALTH_GOOD; + break; + case POWER_SUPPLY_PROP_CAPACITY: + val->intval = 100; + break; + case POWER_SUPPLY_PROP_TECHNOLOGY: + val->intval = POWER_SUPPLY_TECHNOLOGY_LION; + break; + case POWER_SUPPLY_PROP_VOLTAGE_NOW: + val->intval = 4200; + break; + case POWER_SUPPLY_PROP_VOLTAGE_AVG: + val->intval = 4100; + break; + case POWER_SUPPLY_PROP_CURRENT_NOW: + val->intval = 1100; + break; + case POWER_SUPPLY_PROP_CHARGE_COUNTER: + val->intval = counter++; + break; + case POWER_SUPPLY_PROP_CHARGE_FULL: + val->intval = 10000000; + break; + case POWER_SUPPLY_PROP_STATUS: + val->intval = POWER_SUPPLY_STATUS_CHARGING; + break; + default: + return -ENODEV; + } + return 0; +} + +static int dummy_batt_set_prop(struct power_supply *psy, + enum power_supply_property psp, + const union power_supply_propval *val) +{ + return -EPERM; +} + +static enum power_supply_property dummy_batt_props[] = { + POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_HEALTH, + POWER_SUPPLY_PROP_CHARGE_COUNTER, + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_CAPACITY, + POWER_SUPPLY_PROP_TECHNOLOGY, + POWER_SUPPLY_PROP_VOLTAGE_NOW, + POWER_SUPPLY_PROP_VOLTAGE_AVG, + POWER_SUPPLY_PROP_CURRENT_NOW, + POWER_SUPPLY_PROP_CHARGE_FULL, +}; + +static const struct power_supply_desc dummy_battery_desc = { + .name = "Battery", + .type = POWER_SUPPLY_TYPE_BATTERY, + .properties = dummy_batt_props, + .num_properties = ARRAY_SIZE(dummy_batt_props), + .get_property = dummy_batt_get_prop, + .set_property = dummy_batt_set_prop, +}; + +static int dummy_battery_probe(struct platform_device *pdev) +{ + struct dummy_battery_info *info; + struct device *dev = &pdev->dev; + + info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + if (!info) + return -ENOMEM; + + info->dev = dev; + + mutex_init(&info->lock); + platform_set_drvdata(pdev, info); + + info->battery = devm_power_supply_register(dev, + &dummy_battery_desc, + NULL); + if (IS_ERR(info->battery)) { + pr_err("\n%ld\n", PTR_ERR(info->battery)); + return PTR_ERR(info->battery); + } + + info->battery->dev.parent = dev; + + return 0; +} + +static const struct of_device_id meson_dummybattery_dt_match[] = { + { + .compatible = "amlogic, dummy-battery", + }, + {}, +}; + +static struct platform_driver dummy_battery_driver = { + .driver = { + .name = "dummy-battery", + .owner = THIS_MODULE, + .of_match_table = meson_dummybattery_dt_match, + }, + .probe = dummy_battery_probe, +}; + +module_platform_driver(dummy_battery_driver); + +MODULE_DESCRIPTION("Amlogic Dummy Battery driver"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Shuide Chen"); diff --git a/drivers/amlogic/battery/amlogic_charger.c b/drivers/amlogic/battery/amlogic_charger.c new file mode 100644 index 0000000..5ea9c53 --- /dev/null +++ b/drivers/amlogic/battery/amlogic_charger.c @@ -0,0 +1,120 @@ +/* + * drivers/amlogic/battery/amlogic_charger.c + * + * Copyright (C) 2017 Amlogic, Inc. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +struct dummy_charger_info { + struct device *dev; + struct power_supply *usb; + unsigned int online; +}; + +static int dummy_usb_get_prop(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) +{ + switch (psp) { + case POWER_SUPPLY_PROP_STATUS: + val->intval = POWER_SUPPLY_STATUS_CHARGING; + break; + case POWER_SUPPLY_PROP_ONLINE: + val->intval = 1; + break; + default: + return -ENODEV; + } + return 0; +} + + +static enum power_supply_property dummy_usb_props[] = { + POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_ONLINE, +}; + +static const struct power_supply_desc dummy_charger_desc = { + .name = "usb", + .type = POWER_SUPPLY_TYPE_USB, + .properties = dummy_usb_props, + .num_properties = ARRAY_SIZE(dummy_usb_props), + .get_property = dummy_usb_get_prop, +}; + +static int dummy_charger_probe(struct platform_device *pdev) +{ + struct dummy_charger_info *info; + struct device *dev = &pdev->dev; + + info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + if (!info) + return -ENOMEM; + + info->dev = dev; + platform_set_drvdata(pdev, info); + + info->usb = power_supply_register(dev, &dummy_charger_desc, + NULL); + + if (IS_ERR(info->usb)) { + pr_err("\n%ld\n", PTR_ERR(info->usb)); + return PTR_ERR(info->usb); + } + + info->usb->dev.parent = dev; + + return 0; +} + +static int dummy_charger_remove(struct platform_device *pdev) +{ + struct dummy_charger_info *info = platform_get_drvdata(pdev); + + power_supply_unregister(info->usb); + return 0; +} + + +static const struct of_device_id meson_dummycharger_dt_match[] = { + { + .compatible = "amlogic, dummy-charger", + }, + {}, +}; + +static struct platform_driver dummy_charger_driver = { + .driver = { + .name = "dummy-charger", + .owner = THIS_MODULE, + .of_match_table = meson_dummycharger_dt_match, + }, + .probe = dummy_charger_probe, + .remove = dummy_charger_remove, + +}; + +module_platform_driver(dummy_charger_driver); + +MODULE_DESCRIPTION("Amlogic Dummy Charger driver"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Shuide Chen"); -- 2.7.4