From patchwork Mon Aug 17 22:03:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Cvek X-Patchwork-Id: 7027581 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 87A66C05AC for ; Mon, 17 Aug 2015 22:02:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A42B2205E5 for ; Mon, 17 Aug 2015 22:02:25 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BDE3720712 for ; Mon, 17 Aug 2015 22:02:24 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZRSSQ-0002Yn-MO; Mon, 17 Aug 2015 22:00:42 +0000 Received: from bubo.tul.cz ([2001:718:1c01:16::aa]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZRSSM-00027a-RN for linux-arm-kernel@lists.infradead.org; Mon, 17 Aug 2015 22:00:39 +0000 Received: from [78.80.185.17] (78-80-185-17.tmcz.cz [78.80.185.17]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by bubo.tul.cz (Postfix) with ESMTPSA id 123C01F0006; Mon, 17 Aug 2015 23:59:52 +0200 (CEST) From: Petr Cvek Subject: [PATCH v2 13/21] ARM: pxa: magician: Fix charging source and add NiCd backup charging To: robert.jarzmik@free.fr, philipp.zabel@gmail.com, daniel@zonque.org, haojian.zhuang@gmail.com, sameo@linux.intel.com, lee.jones@linaro.org, cooloney@gmail.com, rpurdie@rpsys.net, j.anaszewski@samsung.com, linux@arm.linux.org.uk, sre@kernel.org, dbaryshkov@gmail.com, dwmw2@infradead.org References: Message-ID: <55D25A1B.50106@tul.cz> Date: Tue, 18 Aug 2015 00:03:07 +0200 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150817_150039_275333_042BB6B4 X-CRM114-Status: GOOD ( 12.95 ) X-Spam-Score: -2.5 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, linux-leds@vger.kernel.org, linux-pm@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix charging (cable insert functionality shared with UDC). Add charging control for RTC NiCd accu. Signed-off-by: Petr Cvek --- arch/arm/mach-pxa/magician.c | 83 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 10 deletions(-) diff --git a/arch/arm/mach-pxa/magician.c b/arch/arm/mach-pxa/magician.c index 23b59a0..50c5325 100644 --- a/arch/arm/mach-pxa/magician.c +++ b/arch/arm/mach-pxa/magician.c @@ -756,18 +756,79 @@ static struct platform_device gpio_vbus = { * Charging functions */ -static int power_supply_init(struct device *dev) +static int magician_supply_init(struct device *dev) { - return gpio_request(EGPIO_MAGICIAN_CABLE_TYPE, "CABLE_STATE_AC"); + int ret = -1; + + ret = gpio_request(EGPIO_MAGICIAN_CABLE_TYPE, "AC charger in USB"); + if (ret) { + pr_err("Cannot request AC/USB charger GPIO (%i)\n", ret); + goto err_ac; + } + + ret = gpio_request(EGPIO_MAGICIAN_CABLE_INSERT1, "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) +{ + /* EGPIO_MAGICIAN_BQ24022_ISET2: =1 500mA, =0 100mA + * + * RTC NiCd voltage can be read from ADS7846 + * in0_input=1930, when =0 (after =1 its going up) + * in0_input=1367, when =1 + * in0_input=2499, always (without NiCd) + * + * FIXME Will disabled NiCd slow accu discharge? + * + * Charging from USB can be 500mA too + * NOTICE: IrDA=on, Vcore=1V, Fcore=104MHz, everything other=off + * -> power consumption still over 100mA + */ + + 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); + } + + gpio_set_value(EGPIO_MAGICIAN_NICD_CHARGE, 1); } static int magician_is_ac_online(void) { - return gpio_get_value(EGPIO_MAGICIAN_CABLE_INSERT1); + return gpio_get_value(EGPIO_MAGICIAN_CABLE_INSERT1) && + gpio_get_value(EGPIO_MAGICIAN_CABLE_TYPE); /* AC=1 */ +} + +static int magician_is_usb_online(void) +{ + my_usb_online = gpio_get_value(EGPIO_MAGICIAN_CABLE_INSERT1) && + (!gpio_get_value(EGPIO_MAGICIAN_CABLE_TYPE)); /* USB=0 */ + return my_usb_online; } -static void power_supply_exit(struct device *dev) +static void magician_supply_exit(struct device *dev) { + /* HACK FIXME EGPIO pin is used with two drivers */ + my_usb_online = 1; + + gpio_free(EGPIO_MAGICIAN_CABLE_INSERT1); gpio_free(EGPIO_MAGICIAN_CABLE_TYPE); } @@ -780,11 +841,13 @@ static char *magician_supplicants[] = { */ static struct pda_power_pdata power_supply_info = { - .init = power_supply_init, - .is_ac_online = magician_is_ac_online, - .exit = power_supply_exit, - .supplied_to = magician_supplicants, - .num_supplicants = ARRAY_SIZE(magician_supplicants), + .init = magician_supply_init, + .exit = magician_supply_exit, + .is_ac_online = magician_is_ac_online, + .is_usb_online = magician_is_usb_online, + .set_charge = magician_set_charge, + .supplied_to = magician_supplicants, + .num_supplicants = ARRAY_SIZE(magician_supplicants), }; static struct resource power_supply_resources[] = { @@ -847,7 +910,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),