summaryrefslogtreecommitdiff
authorShuide Chen <shuide.chen@amlogic.com>2018-06-21 01:56:02 (GMT)
committer Jianxin Pan <jianxin.pan@amlogic.com>2018-08-01 08:04:15 (GMT)
commit7ff97417010946a571dae391f9489429ff07dfa1 (patch)
tree0cd88da8973d5bddbe306640dd53489a7650cc7a
parent5d415782ab008163654377d99c18a49a06a2abb5 (diff)
downloadcommon-7ff97417010946a571dae391f9489429ff07dfa1.zip
common-7ff97417010946a571dae391f9489429ff07dfa1.tar.gz
common-7ff97417010946a571dae391f9489429ff07dfa1.tar.bz2
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 <shuide.chen@amlogic.com>
Diffstat
-rw-r--r--MAINTAINERS6
-rw-r--r--arch/arm64/boot/dts/amlogic/gxl_p212_1g.dts10
-rw-r--r--arch/arm64/boot/dts/amlogic/gxl_p212_2g.dts10
-rw-r--r--arch/arm64/boot/dts/amlogic/txlx_t962e_r321.dts9
-rw-r--r--arch/arm64/configs/meson64_defconfig2
-rw-r--r--drivers/amlogic/Kconfig1
-rw-r--r--drivers/amlogic/Makefile3
-rw-r--r--drivers/amlogic/battery/Kconfig15
-rw-r--r--drivers/amlogic/battery/Makefile3
-rw-r--r--drivers/amlogic/battery/amlogic_battery.c153
-rw-r--r--drivers/amlogic/battery/amlogic_charger.c120
11 files changed, 332 insertions, 0 deletions
diff --git a/MAINTAINERS b/MAINTAINERS
index 13b7bd2..a12e940 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13437,6 +13437,12 @@ AMLOGIC MAILBOX DRIVER
M: Yun Cai <yun.cai@amlogic.com>
F: drivers/amlogic/mailbox/
+AMLOGIC DUMMY BATTERY DRIVER
+M: Shuide <shuide.chen@amlogic.com>
+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 <yun.cai@amlogic.com>
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
--- a/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
--- a/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
--- a/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 <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/mutex.h>
+#include <linux/string.h>
+#include <linux/power_supply.h>
+
+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<shuide.chen@amlogic.com>");
diff --git a/drivers/amlogic/battery/amlogic_charger.c b/drivers/amlogic/battery/amlogic_charger.c
new file mode 100644
index 0000000..5ea9c53
--- a/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 <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/of.h>
+#include <linux/mutex.h>
+#include <linux/string.h>
+#include <linux/power_supply.h>
+
+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<shuide.chen@amlogic.com>");