linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Cvek <petr.cvek@tul.cz>
To: robert.jarzmik@free.fr, philipp.zabel@gmail.com,
	daniel@zonque.org, haojian.zhuang@gmail.com, cooloney@gmail.com,
	rpurdie@rpsys.net, j.anaszewski@samsung.com,
	linux@arm.linux.org.uk, sre@kernel.org, dbaryshkov@gmail.com,
	lee.jones@linaro.org, sameo@linux.intel.com, dwmw2@infradead.org,
	arnd@arndb.de, g.liakhovetski@gmx.de
Cc: linux-leds@vger.kernel.org, linux-pm@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 13/26] ARM: pxa: magician: Fix and add charging detection functions
Date: Thu, 17 Sep 2015 06:59:12 +0200	[thread overview]
Message-ID: <55FA48A0.9090709@tul.cz> (raw)
In-Reply-To: <cover.1442462898.git.petr.cvek@tul.cz>

This patch fixes the charging detection functions for pda_power driver
(according to newly discovered EGPIOs) and add NiCd backup accumulator
charging support.

Signed-off-by: Petr Cvek <petr.cvek@tul.cz>
---
 arch/arm/mach-pxa/magician.c | 57 ++++++++++++++++++++++++++++++++++++++------
 1 file changed, 50 insertions(+), 7 deletions(-)

diff --git a/arch/arm/mach-pxa/magician.c b/arch/arm/mach-pxa/magician.c
index b645288..906df6d 100644
--- a/arch/arm/mach-pxa/magician.c
+++ b/arch/arm/mach-pxa/magician.c
@@ -596,18 +596,59 @@ static struct platform_device gpio_vbus = {
  * External power
  */
 
-static int power_supply_init(struct device *dev)
+static int magician_supply_init(struct device *dev)
 {
-	return gpio_request(EGPIO_MAGICIAN_CABLE_TYPE, "Cable USB/AC type");
+	int ret = -1;
+
+	ret = gpio_request(EGPIO_MAGICIAN_CABLE_TYPE, "Cable is AC charger");
+	if (ret) {
+		pr_err("Cannot request AC/USB charger GPIO (%i)\n", ret);
+		goto err_ac;
+	}
+
+	ret = gpio_request(EGPIO_MAGICIAN_CABLE_INSERTED, "Cable inserted");
+	if (ret) {
+		pr_err("Cannot request cable detection GPIO (%i)\n", ret);
+		goto err_usb;
+	}
+
+	return 0;
+
+err_usb:
+	gpio_free(EGPIO_MAGICIAN_CABLE_TYPE);
+err_ac:
+	return ret;
+}
+
+static void magician_set_charge(int flags)
+{
+	if (flags & PDA_POWER_CHARGE_AC) {
+		pr_debug("Charging from AC\n");
+		gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 1);
+	} else if (flags & PDA_POWER_CHARGE_USB) {
+		pr_debug("Charging from USB\n");
+		gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 1);
+	} else {
+		pr_debug("Charging disabled\n");
+		gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 0);
+	}
 }
 
 static int magician_is_ac_online(void)
 {
-	return gpio_get_value(EGPIO_MAGICIAN_CABLE_TYPE);
+	return gpio_get_value(EGPIO_MAGICIAN_CABLE_INSERTED) &&
+		gpio_get_value(EGPIO_MAGICIAN_CABLE_TYPE); /* AC=1 */
+}
+
+static int magician_is_usb_online(void)
+{
+	return gpio_get_value(EGPIO_MAGICIAN_CABLE_INSERTED) &&
+		(!gpio_get_value(EGPIO_MAGICIAN_CABLE_TYPE)); /* USB=0 */
 }
 
-static void power_supply_exit(struct device *dev)
+static void magician_supply_exit(struct device *dev)
 {
+	gpio_free(EGPIO_MAGICIAN_CABLE_INSERTED);
 	gpio_free(EGPIO_MAGICIAN_CABLE_TYPE);
 }
 
@@ -616,9 +657,11 @@ static char *magician_supplicants[] = {
 };
 
 static struct pda_power_pdata power_supply_info = {
-	.init			= power_supply_init,
+	.init			= magician_supply_init,
+	.exit			= magician_supply_exit,
 	.is_ac_online		= magician_is_ac_online,
-	.exit			= power_supply_exit,
+	.is_usb_online		= magician_is_usb_online,
+	.set_charge		= magician_set_charge,
 	.supplied_to		= magician_supplicants,
 	.num_supplicants	= ARRAY_SIZE(magician_supplicants),
 };
@@ -683,7 +726,7 @@ static struct gpio_regulator_config bq24022_info = {
 
 	.enable_gpio		= GPIO30_MAGICIAN_BQ24022_nCHARGE_EN,
 	.enable_high		= 0,
-	.enabled_at_boot	= 0,
+	.enabled_at_boot	= 1,
 
 	.gpios			= bq24022_gpios,
 	.nr_gpios		= ARRAY_SIZE(bq24022_gpios),
-- 
1.7.12.1

  parent reply	other threads:[~2015-09-17  4:59 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1442462898.git.petr.cvek@tul.cz>
2015-09-17  4:54 ` [PATCH v3 01/26] ARM: pxa: magician: Fix indentation in machine files Petr Cvek
2015-09-17  4:55 ` [PATCH v3 02/26] ARM: pxa: magician: Change comments to be more informative Petr Cvek
2015-09-17  4:55 ` [PATCH v3 03/26] ARM: pxa: magician: Print more specific error message for global GPIOs Petr Cvek
2015-09-17  4:55 ` [PATCH v3 04/26] ARM: pxa: magician: Optimize debug messages for LCD power Petr Cvek
2015-09-26 11:55   ` Robert Jarzmik
2015-09-17  4:55 ` [PATCH v3 05/26] ARM: pxa: magician: Change description of LCD power GPIO Petr Cvek
2015-09-26 11:55   ` Robert Jarzmik
2015-09-17  4:56 ` [PATCH v3 06/26] ARM: pxa: magician: Add new discovered EGPIO pins Petr Cvek
2015-09-17  4:56 ` [PATCH v3 07/26] ARM: pxa: magician: Fix HTC Magician pin mux definitions Petr Cvek
2015-09-17  4:57 ` [PATCH v3 08/26] ARM: pxa: magician: Rename abstract LCD GPIOs Petr Cvek
2015-09-17  4:57 ` [PATCH v3 09/26] ARM: pxa: magician: Optimize powerup delays for Samsung LCD Petr Cvek
2015-09-17  4:57 ` [PATCH v3 10/26] ARM: pxa: magician: Optimize Samsung LCD refresh to 50Hz Petr Cvek
2015-09-17  4:58 ` [PATCH v3 11/26] ARM: pxa: magician: Optimize EGPIO initial values Petr Cvek
2015-09-17  4:58 ` [PATCH v3 12/26] ARM: pxa: magician: Rename charger cable detection EGPIOs Petr Cvek
2015-09-17  4:59 ` Petr Cvek [this message]
2015-09-26 14:45   ` [PATCH v3 13/26] ARM: pxa: magician: Fix and add charging detection functions Robert Jarzmik
2015-09-17  4:59 ` [PATCH v3 14/26] ARM: pxa: magician: Fix platform data for both PXA27x I2C controllers Petr Cvek
2015-09-17  4:59 ` [PATCH v3 15/26] ARM: pxa: magician: Fix redundant GPIO request for pxaficp_ir Petr Cvek

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=55FA48A0.9090709@tul.cz \
    --to=petr.cvek@tul.cz \
    --cc=arnd@arndb.de \
    --cc=cooloney@gmail.com \
    --cc=daniel@zonque.org \
    --cc=dbaryshkov@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=g.liakhovetski@gmx.de \
    --cc=haojian.zhuang@gmail.com \
    --cc=j.anaszewski@samsung.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=philipp.zabel@gmail.com \
    --cc=robert.jarzmik@free.fr \
    --cc=rpurdie@rpsys.net \
    --cc=sameo@linux.intel.com \
    --cc=sre@kernel.org \
    /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).