Skip to contentSkip to conversation

Trickle charging for rtc-bq32k

PATCH Pavel Machek 2 participants 4 messages Aug 22, 2014 – Sep 2, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi!

Here's a patch to enable trickle charging; without it the clock stops when power is removed -> not very useful.

_But_ this should probably be enabled using device tree entry, right? Unfortunately, the driver is i2c driver, not platform one, so I don't see how to do that easily...

Or would module parameter be acceptable?

Thanks,
Pavel

commit 00abeaa1197a5ad6400497558891793b6cd880d5

Author: Pavel <[email protected]>
Date:   Fri Aug 22 14:58:00 2014 +0200

Enable trickle charging for bq32k.

drivers/rtc/rtc-bq32k.c +27 -0
index c74bf0d..b6a4dd0 100644
@@ -2,10 +2,14 @@
  * Driver for TI BQ32000 RTC.
  *
  * Copyright (C) 2009 Semihalf.
+ * Copyright (C) 2014 Pavel Machek <[email protected]>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
+ *
+ * You can get hardware description at
+ * http://www.ti.com/lit/ds/symlink/bq32000.pdf
  */
 
 #include <linux/module.h>
@@ -27,6 +31,10 @@
 #define BQ32K_CENT		0x40	/* Century flag */
 #define BQ32K_CENT_EN		0x80	/* Century flag enable bit */
 
+#define BQ32K_CALIBRATION	0x07	/* CAL_CFG1, calibration and control */
+#define BQ32K_TCH2		0x08	/* Trickle charge enable */
+#define BQ32K_CFG2		0x09	/* Trickle charger control */
+
 struct bq32k_regs {
 	uint8_t		seconds;
 	uint8_t		minutes;
@@ -153,6 +161,25 @@ static int bq32k_probe(struct i2c_client *client,
 	if (error)
 		return error;
 
+	if (0) {
+		/*
+		 * TCHE[3:0] == 0x05, TCH2 == 1, TCFE == 0 (charging
+		 * over diode and 940ohm resistor)
+		 */
+
+		reg = 0x05;
+		error = bq32k_write(dev, &reg, BQ32K_CFG2, 1);
+		if (error)
+			return error;
+
+		reg = 0x20;
+		error = bq32k_write(dev, &reg, BQ32K_TCH2, 1);
+		if (error)
+			return error;
+
+		dev_info(dev, "Enabled trickle RTC battery charge.\n");
+	}
+
 	rtc = devm_rtc_device_register(&client->dev, bq32k_driver.driver.name,
 						&bq32k_rtc_ops, THIS_MODULE);
 	if (IS_ERR(rtc))
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#1 lore raw
Quoted 4 lines

_But_ this should probably be enabled using device tree entry, right? Unfortunately, the driver is i2c driver, not platform one, so I don't see how to do that easily...

Trickle charging is usually depending on the hardware setup, so devicetree is actually a good place to put it. We'd just need generic bindings so that they could be applied to various RTC. Just guessing, resistor value would probably be one such property? We would not need putting plain register values into DT.

There should be no difference regarding DT between i2c and platform drivers.

You should add the devicetree ML for discussing such things.

Quoted 1 line

Or would module parameter be acceptable?

No, this is device dependent, not module dependent.

Quoted 2 lines

* Copyright (C) 2009 Semihalf.
+ * Copyright (C) 2014 Pavel Machek <[email protected]>

IMO, such a small improvement does not justify claiming copyright on the driver.

#2 lore raw
Quoted 10 lines · Wolfram Sang
Quoted 4 lines

_But_ this should probably be enabled using device tree entry, right? Unfortunately, the driver is i2c driver, not platform one, so I don't see how to do that easily...

Trickle charging is usually depending on the hardware setup, so devicetree is actually a good place to put it. We'd just need generic bindings so that they could be applied to various RTC. Just guessing, resistor value would probably be one such property? We would not need putting plain register values into DT.

Well, for bq32000 there's selection between "no charging", "diode + resistor", "different resistor".

Quoted 2 lines

There should be no difference regarding DT between i2c and platform drivers.

Do you have example how to acces of_ from i2c driver?

Platform drivers do:

static int palmas_rtc_probe(struct platform_device *pdev)

{
        struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
        struct palmas_rtc *palmas_rtc = NULL;
	int ret;
        bool enable_bb_charging = false;
        bool high_bb_charging;

        if (pdev->dev.of_node) {
	   enable_bb_charging =
	   of_property_read_bool(pdev->dev.of_node,
                                        "ti,backup-battery-chargeable");
					        high_bb_charging =
	   of_property_read_bool(pdev->dev.of_node,
                                        "ti,backup-battery-charge-high-current");

Thanks,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#3 lore raw
Quoted 6 lines

Do you have example how to acces of_ from i2c driver?

Platform drivers do:

        if (pdev->dev.of_node) {

As I said, this is basically the same. Just use the node from the client's device. Nothing special here.