From: Sebastian Reichel <sebastian.reichel@collabora.com>
To: Virendra Kakade <virendra.kakade@ni.com>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-pm@vger.kernel.org, lee.jones@linaro.org,
robh+dt@kernel.org, mark.rutland@arm.com,
moritz.fischer@ettus.com
Subject: Re: [RFC 4/6] power: supply: Ettus Research E31x charger driver
Date: Tue, 12 Feb 2019 22:46:48 +0100 [thread overview]
Message-ID: <20190212214648.77lzvexfs2v46ejn@earth.universe> (raw)
In-Reply-To: <20190212010143.3729-5-virendra.kakade@ni.com>
[-- Attachment #1: Type: text/plain, Size: 7973 bytes --]
Hi,
On Mon, Feb 11, 2019 at 07:01:41PM -0600, Virendra Kakade wrote:
> Add support for E31x devices charger which is a sub-device of E31X-PMU.
> Enables query of charger properties from device tree.
>
> Signed-off-by: Virendra Kakade <virendra.kakade@ni.com>
> ---
> drivers/power/supply/Kconfig | 6 +
> drivers/power/supply/Makefile | 1 +
> drivers/power/supply/e31x-charger.c | 190 ++++++++++++++++++++++++++++
> include/linux/mfd/e31x-pmu.h | 4 +
> 4 files changed, 201 insertions(+)
> create mode 100644 drivers/power/supply/e31x-charger.c
>
> diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig
> index e901b9879e7e..3d043b8fd49c 100644
> --- a/drivers/power/supply/Kconfig
> +++ b/drivers/power/supply/Kconfig
> @@ -660,4 +660,10 @@ config FUEL_GAUGE_SC27XX
> Say Y here to enable support for fuel gauge with SC27XX
> PMIC chips.
>
> +config E31X_CHARGER
> + tristate "Ettus Research E31x charger support"
> + depends on MFD_E31X_PMU
> + help
> + This adds support for the battery charger in Ettus Research E31x PMU.
> +
> endif # POWER_SUPPLY
> diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile
> index b731c2a9b695..6f4f8ca5484e 100644
> --- a/drivers/power/supply/Makefile
> +++ b/drivers/power/supply/Makefile
> @@ -87,3 +87,4 @@ obj-$(CONFIG_AXP288_CHARGER) += axp288_charger.o
> obj-$(CONFIG_CHARGER_CROS_USBPD) += cros_usbpd-charger.o
> obj-$(CONFIG_CHARGER_SC2731) += sc2731_charger.o
> obj-$(CONFIG_FUEL_GAUGE_SC27XX) += sc27xx_fuel_gauge.o
> +obj-$(CONFIG_E31X_CHARGER) += e31x-charger.o
> diff --git a/drivers/power/supply/e31x-charger.c b/drivers/power/supply/e31x-charger.c
> new file mode 100644
> index 000000000000..f154482bf95e
> --- /dev/null
> +++ b/drivers/power/supply/e31x-charger.c
> @@ -0,0 +1,190 @@
> +// SPDX-License-Identifier: GPL-2.0
This specifies GPLv2 only, but MODULE_LICENSE("GPL") specifies GPL2
or later. Please fix one of them.
> +/*
> + * Copyright (c) 2018 National Instruments Corp
> + * Author: Virendra Kakade <virendra.kakade@ni.com>
> + *
> + * Ettus Research E31x charger driver
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/of_device.h>
> +#include <linux/platform_device.h>
> +#include <linux/mfd/syscon.h>
> +#include <linux/mutex.h>
> +#include <linux/regmap.h>
> +#include <linux/string.h>
> +#include <linux/slab.h>
> +#include <linux/power_supply.h>
> +#include <linux/delay.h>
> +#include <linux/mfd/e31x-pmu.h>
Please check the includes. Quite a few seem to be unused.
> +
> +#define E31X_PMU_CHARGER_HEALTH_MASK GENMASK(1, 0)
> +#define E31X_PMU_CHARGER_HEALTH_SHIFT 0
> +#define E31X_PMU_CHARGER_CHARGE_TYPE_MASK GENMASK(4, 3)
> +#define E31X_PMU_CHARGER_CHARGE_TYPE_SHIFT 3
> +
> +struct e31x_charger_dev {
> + struct regmap *regmap;
> + struct power_supply *supply;
> +};
> +
> +static int e31x_charger_get_health(struct e31x_charger_dev *charger,
> + union power_supply_propval *val)
> +{
> + u32 value;
> + int err;
> +
> + err = regmap_read(charger->regmap, E31X_PMU_REG_CHARGER, &value);
> + if (err)
> + return err;
> +
> + value = E31X_PMU_GET_FIELD(CHARGER_HEALTH, value);
> + switch (value) {
> + case 0x0:
> + val->intval = POWER_SUPPLY_HEALTH_GOOD;
> + break;
> + case 0x1:
> + val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
> + break;
> + case 0x2:
> + val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
> + break;
> + case 0x3:
> + val->intval = POWER_SUPPLY_HEALTH_OVERHEAT;
> + break;
> + default:
> + val->intval = POWER_SUPPLY_HEALTH_UNKNOWN;
> + break;
> + };
> +
> + return 0;
> +}
> +
> +static int e31x_charger_get_type(struct e31x_charger_dev *charger,
> + union power_supply_propval *val)
> +{
> + u32 value;
> + int err;
> +
> + err = regmap_read(charger->regmap, E31X_PMU_REG_CHARGER, &value);
> + if (err)
> + return err;
> +
> + value = E31X_PMU_GET_FIELD(CHARGER_CHARGE_TYPE, value);
> + switch (value) {
> + case 0x0:
> + val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE;
> + break;
> + case 0x1:
> + val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
> + break;
> + case 0x2:
> + val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST;
> + break;
> + default:
> + val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE;
> + break;
> + };
> + return 0;
> +}
> +
> +static int e31x_charger_get_online(struct e31x_charger_dev *charger,
> + union power_supply_propval *val)
> +{
> + u32 value;
> + int err;
> +
> + err = regmap_read(charger->regmap, E31X_PMU_REG_CHARGER, &value);
> + if (err)
> + return err;
> +
> + value = E31X_PMU_GET_FIELD(CHARGER_ONLINE, value);
> + val->intval = !!value;
> +
> + return 0;
> +}
> +
> +static int e31x_charger_get_property(struct power_supply *psy,
> + enum power_supply_property psp,
> + union power_supply_propval *val)
> +{
> + struct e31x_charger_dev *charger = power_supply_get_drvdata(psy);
> + int err = -EINVAL;
> +
> + switch (psp) {
> + case POWER_SUPPLY_PROP_HEALTH:
> + return e31x_charger_get_health(charger, val);
> + case POWER_SUPPLY_PROP_CHARGE_TYPE:
> + return e31x_charger_get_type(charger, val);
> + case POWER_SUPPLY_PROP_ONLINE:
> + return e31x_charger_get_online(charger, val);
> + case POWER_SUPPLY_PROP_SCOPE:
> + val->intval = POWER_SUPPLY_SCOPE_SYSTEM;
> + return 0;
> + default:
> + break;
> + }
> +
> + return err;
> +}
> +
> +static enum power_supply_property e31x_charger_properties[] = {
> + POWER_SUPPLY_PROP_HEALTH,
> + POWER_SUPPLY_PROP_CHARGE_TYPE,
> + POWER_SUPPLY_PROP_ONLINE,
> + POWER_SUPPLY_PROP_SCOPE,
> +};
> +
> +static const struct power_supply_desc e31x_charger_desc = {
> + .name = "e31x-charger",
> + .type = POWER_SUPPLY_TYPE_MAINS,
> + .properties = e31x_charger_properties,
> + .num_properties = ARRAY_SIZE(e31x_charger_properties),
> + .get_property = e31x_charger_get_property,
> +};
> +
> +static const struct of_device_id e31x_charger_id[] = {
> + { .compatible = "ni,e31x-charger" },
> + { },
> +};
> +
> +static int e31x_charger_probe(struct platform_device *pdev)
> +{
> + struct power_supply_config psy_cfg = {};
> + struct e31x_charger_dev *charger;
> +
> + if (!of_device_is_available(pdev->dev.of_node))
> + return -ENODEV;
> +
> + charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL);
> + if (!charger)
> + return -ENOMEM;
> +
> + charger->regmap = syscon_regmap_lookup_by_phandle(\
useless \
> + pdev->dev.parent->of_node, "regmap");
> +
> + psy_cfg.of_node = pdev->dev.of_node;
> + psy_cfg.drv_data = charger;
> +
> + charger->supply = devm_power_supply_register(&pdev->dev,
> + &e31x_charger_desc,
> + &psy_cfg);
> +
> + if (IS_ERR(charger->supply))
> + return PTR_ERR(charger->supply);
> + return 0;
> +}
> +
> +static struct platform_driver e31x_charger_driver = {
> + .driver = {
> + .name = "e31x-charger",
> + .of_match_table = e31x_charger_id,
> + },
> + .probe = e31x_charger_probe,
> +};
> +module_platform_driver(e31x_charger_driver);
> +
> +MODULE_AUTHOR("Virendra Kakade <virendra.kakade@ni.com>");
> +MODULE_DESCRIPTION("E31x charger driver");
> +MODULE_LICENSE("GPL");
> diff --git a/include/linux/mfd/e31x-pmu.h b/include/linux/mfd/e31x-pmu.h
> index c57d5a8c1aad..e0649845fe4d 100644
> --- a/include/linux/mfd/e31x-pmu.h
> +++ b/include/linux/mfd/e31x-pmu.h
> @@ -12,9 +12,13 @@
> #include <linux/bitops.h>
>
> #define E31X_PMU_REG_MISC 0x04
> +#define E31X_PMU_REG_CHARGER 0x0c
>
> #define E31X_PMU_GET_FIELD(name, reg) \
> (((reg) & E31X_PMU_## name ##_MASK) >> \
> E31X_PMU_## name ##_SHIFT)
>
> +#define E31X_PMU_CHARGER_ONLINE_MASK BIT(2)
> +#define E31X_PMU_CHARGER_ONLINE_SHIFT 2
> +
> #endif /* MFD_E31X_PMU_H */
Otherwise this looks good.
-- Sebastian
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2019-02-12 21:46 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-12 1:01 [RFC 0/6] Add support for Ettus Research E31x devices PMU Virendra Kakade
2019-02-12 1:01 ` [RFC 1/6] mfd: Support " Virendra Kakade
2019-02-12 10:51 ` Moritz Fischer
2019-02-14 9:23 ` Lee Jones
2019-02-12 1:01 ` [RFC 2/6] " Virendra Kakade
2019-02-14 9:34 ` Lee Jones
2019-02-17 16:37 ` Moritz Fischer
2019-02-18 8:56 ` Lee Jones
2019-02-12 1:01 ` [RFC 3/6] power: supply: Ettus Research E31x charger driver Virendra Kakade
2019-02-14 9:38 ` Lee Jones
2019-02-25 23:38 ` Rob Herring
2019-02-12 1:01 ` [RFC 4/6] " Virendra Kakade
2019-02-12 21:46 ` Sebastian Reichel [this message]
2019-02-12 1:01 ` [RFC 5/6] power: supply: Ettus Research E31x battery driver Virendra Kakade
2019-02-14 9:39 ` Lee Jones
2019-02-12 1:01 ` [RFC 6/6] " Virendra Kakade
2019-02-12 22:26 ` Sebastian Reichel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190212214648.77lzvexfs2v46ejn@earth.universe \
--to=sebastian.reichel@collabora.com \
--cc=devicetree@vger.kernel.org \
--cc=lee.jones@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=moritz.fischer@ettus.com \
--cc=robh+dt@kernel.org \
--cc=virendra.kakade@ni.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).