Re: [PATCH 2/3] power_supply: Add support for tps65217-charger.

2015-09-22 Thread Sebastian Reichel
Hi,

On Tue, Sep 08, 2015 at 10:09:38AM +0200, Enric Balletbo i Serra wrote:
> This patch adds support for the tps65217 charger driver. This driver is
> responsible for controlling the charger aspect of the tps65217 mfd.
> Currently, this mainly consists of turning on and off the charger, but
> some other features of the charger can be supported through this driver.

Driver looks mostly fine. I have two comments though:

> [...]
>
> +static int tps65217_ac_get_property(struct power_supply *psy,
> + enum power_supply_property psp,
> + union power_supply_propval *val)
> +{
> + struct tps65217_charger *charger = power_supply_get_drvdata(psy);
> +
> + if (psp == POWER_SUPPLY_PROP_ONLINE) {
> + val->intval = charger->ac_online;
> + charger->prev_ac_online = charger->ac_online;

I think prev_ac_online should be set at the beginning of
tps65217_charger_irq().

> [...]
>
> +static int tps65217_charger_probe(struct platform_device *pdev)
> +{
>
> [...]
>
> + charger->ac = power_supply_register(>dev,
> + _charger_desc, NULL);
> + if (IS_ERR(charger->ac)) {
> + dev_err(>dev, "failed: power supply register\n");
> + return PTR_ERR(charger->ac);
> + }

You can use devm_power_supply_register(...) to simplify the driver
a bit more.

-- Sebastian


signature.asc
Description: Digital signature


[PATCH 2/3] power_supply: Add support for tps65217-charger.

2015-09-08 Thread Enric Balletbo i Serra
This patch adds support for the tps65217 charger driver. This driver is
responsible for controlling the charger aspect of the tps65217 mfd.
Currently, this mainly consists of turning on and off the charger, but
some other features of the charger can be supported through this driver.

Signed-off-by: Enric Balletbo i Serra 
---
 drivers/power/Kconfig|   7 +
 drivers/power/Makefile   |   1 +
 drivers/power/tps65217_charger.c | 269 +++
 3 files changed, 277 insertions(+)
 create mode 100644 drivers/power/tps65217_charger.c

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index f8758d6..57fdc80 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -434,6 +434,13 @@ config CHARGER_TPS65090
 Say Y here to enable support for battery charging with TPS65090
 PMIC chips.
 
+config CHARGER_TPS65217
+   tristate "TPS65217 battery charger driver"
+   depends on MFD_TPS65217
+   help
+Say Y here to enable support for battery charging with TPS65217
+PMIC chips.
+
 config BATTERY_GAUGE_LTC2941
tristate "LTC2941/LTC2943 Battery Gauge Driver"
depends on I2C
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 5752ce8..c1409b3 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -65,6 +65,7 @@ obj-$(CONFIG_CHARGER_BQ25890) += bq25890_charger.o
 obj-$(CONFIG_POWER_AVS)+= avs/
 obj-$(CONFIG_CHARGER_SMB347)   += smb347-charger.o
 obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o
+obj-$(CONFIG_CHARGER_TPS65217) += tps65217_charger.o
 obj-$(CONFIG_POWER_RESET)  += reset/
 obj-$(CONFIG_AXP288_FUEL_GAUGE) += axp288_fuel_gauge.o
 obj-$(CONFIG_AXP288_CHARGER)   += axp288_charger.o
diff --git a/drivers/power/tps65217_charger.c b/drivers/power/tps65217_charger.c
new file mode 100644
index 000..0b6a30d
--- /dev/null
+++ b/drivers/power/tps65217_charger.c
@@ -0,0 +1,269 @@
+/*
+ * Battery charger driver for TI's tps65217
+ *
+ * Copyright (c) 2015, Collabora Ltd.
+
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+
+ * This program is distributed in the hope 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.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+/*
+ * Battery charger driver for TI's tps65217
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#define POLL_INTERVAL  (HZ * 2)
+
+struct tps65217_charger {
+   struct tps65217 *tps;
+   struct device *dev;
+   struct power_supply *ac;
+
+   int ac_online;
+   int prev_ac_online;
+
+   struct task_struct  *poll_task;
+};
+
+static enum power_supply_property tps65217_ac_props[] = {
+   POWER_SUPPLY_PROP_ONLINE,
+};
+
+static int tps65217_config_charger(struct tps65217_charger *charger)
+{
+   int ret;
+
+   dev_dbg(charger->dev, "%s\n", __func__);
+
+   /*
+* tps65217 rev. G, p. 31 (see p. 32 for NTC schematic)
+*
+* The device can be configured to support a 100k NTC (B = 3960) by
+* setting the the NTC_TYPE bit in register CHGCONFIG1 to 1. However it
+* is not recommended to do so. In sleep mode, the charger continues
+* charging the battery, but all register values are reset to default
+* values. Therefore, the charger would get the wrong temperature
+* information. If 100k NTC setting is required, please contact the
+* factory.
+*
+* ATTENTION, conflicting information, from p. 46
+*
+* NTC TYPE (for battery temperature measurement)
+*   0 – 100k (curve 1, B = 3960)
+*   1 – 10k  (curve 2, B = 3480) (default on reset)
+*
+*/
+   ret = tps65217_clear_bits(charger->tps, TPS65217_REG_CHGCONFIG1,
+   TPS65217_CHGCONFIG1_NTC_TYPE,
+   TPS65217_PROTECT_NONE);
+   if (ret) {
+   dev_err(charger->dev,
+   "failed to set 100k NTC setting: %d\n", ret);
+   return ret;
+   }
+
+   return 0;
+}
+
+static int tps65217_enable_charging(struct tps65217_charger *charger)
+{
+   int ret;
+
+   /* charger already enabled */
+   if (charger->ac_online)
+   return 0;
+
+   dev_dbg(charger->dev, "%s: enable charging\n", __func__);
+   ret = tps65217_set_bits(charger->tps, TPS65217_REG_CHGCONFIG1,
+