From patchwork Tue Apr 19 16:38:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 563371 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp3462984map; Tue, 19 Apr 2022 10:25:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHEw8gwnADiLuLLdzDhEYGYu3zB2jHEb2rbtq6m0bxMbyruUr6OLcc8tD9ng4oObeqxIys X-Received: by 2002:a63:b20a:0:b0:398:9e3e:d581 with SMTP id x10-20020a63b20a000000b003989e3ed581mr16097757pge.236.1650389133846; Tue, 19 Apr 2022 10:25:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650389133; cv=none; d=google.com; s=arc-20160816; b=t3WsM2IUiozUlCm/IGc4L5FpxAuTqDzWT1g6/IS6p+siLvdFDt/a+DXeY7iyF3Q734 18TJESoIULHf40smtBr6jsO/VI5h/xuhxqG5rJ/9iWtWBGsMk36aZIia2ka7zQwr12af 30eOSLlpPmA/28jxRgvfWIEFtxvTPRHMhW9q/ibBrFFciuzJF3cfsHc/q8inddmv4M/B 1oBd7FGZ4JMpbQerKack2zOByujjEzp/geTvimhyZc5eC7wKcna2WFmcmyNUqUACjiVv oJywRda1hdbUHxbqtIjZw3xzs4YQMM8xUOKObTVVCTE6RImlI7U9/eEFfl//qOX5iUq+ d5jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dkim-signature:dkim-signature; bh=ryz8qy/JUWssbrspZgEujSCjV9QCU922iccJQkxmvLo=; b=fqsI8via/8V3PjM+Jc7HaddUAzdQKIiipiR+2fw1sC3BS7gT2evCorlpg4IXBn2hbd 6kr5HU+dMmPlTR40Oxa0kzhuRsmyrF8emkefyK+7tAclZj1jif2/75o6M0MA4s0f+lkE N/N86BAbOpD2zs6PMq+4YH9pbHKwXr6TkH90CxktUjWssNGR3UuX6THjODc2C3dBcuSO s7KETOFA4Vf+vqMrChzm4zv5euJH9qvK932RgfOue9QYF311n0cjXdYde1HpQAGbQsG3 W69vljfxiA6bN8OCg68XdCl8sKa2gohuSwZoXEQi2H4yt+QdJYTmLj7vdTErNV2f4g8u pDRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20210309 header.b=K0e7Z4oy; dkim=neutral (body hash did not verify) header.i=@infradead.org header.s=desiato.20200630 header.b=JqLcppW3; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=SgAVx6hk; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id k14-20020a170902ba8e00b00158d6dbbfc2si11440583pls.145.2022.04.19.10.25.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Apr 2022 10:25:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20210309 header.b=K0e7Z4oy; dkim=neutral (body hash did not verify) header.i=@infradead.org header.s=desiato.20200630 header.b=JqLcppW3; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=SgAVx6hk; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ryz8qy/JUWssbrspZgEujSCjV9QCU922iccJQkxmvLo=; b=K0e7Z4oyHJFsW5 fltB68DY5NNGzAjhpyJPajG9gtnEDG1J8XQcuLXHKIeq+ur1KkTruiA0MwKQ+2wYVgmNiR2eZwEAw 4N7lguD0g5THsf+R2apr20dI+W+bo9MWHyVskdZjYDEHNpRV+xgi4Ys+sw7dJs9plWFjtAIh34gMq OF51J2cMaNJtYGAK7m+jmg0nKptx+hkeUgGQBnEW97ZhBo6GgTDFFscT6uPXSEVvJDM6W7d8sDIKn AjUMw8eYu8ihLp1AUHFbbDFUY/vyV4rE2bKyXad+Eh5eOuD4Z6xQo5d/IC7bOL/Rml9pecaHvG34n ZzV6sk+jHYnpRjGp6JOg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngrbP-005Hvw-U0; Tue, 19 Apr 2022 17:25:24 +0000 Received: from desiato.infradead.org ([90.155.92.199]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngqxc-004yew-Hu; Tue, 19 Apr 2022 16:44:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=40eu/ynCJ8jPApvj6Gcuxw/FIIs/cfzuygj5gmLBN7w=; b=JqLcppW3n+qEg9Od1EXcRiunFa dOcLcc9fJWr20MEVJmSNjSv95uKtsjUIFC308PB7sre6HxIwPIBfjiihSOAltw+20Ct9AW9qWNP1w JtWHXi4E3NppoDUvECrpumzcIJ2OPdJTh7nOPCJGq8fUA8i9razgD1eTCyLhpR1GmHWuxyhdnUKxE 3wo5+8dOP1AFWG0dbBr4v2fusiosPHOwLsI/0BXy0MA0FzK6yFqIqnOQmZvrG1NdqjsFY399FpTkM v/Yq2c5dnFjAinrpH6eulZ5iyubAwyf6MUpI61WrswkXGzRuH/88QKE9pgSRroeBJlXlknTu/rEse JXdMA7GQ==; Received: from dfw.source.kernel.org ([139.178.84.217]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngqxW-006s0y-TR; Tue, 19 Apr 2022 16:44:14 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D3D9E61899; Tue, 19 Apr 2022 16:44:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73DF2C385AB; Tue, 19 Apr 2022 16:43:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650386644; bh=dqIJ/cXf0VPjwidEepmxEeZMiI7iN357W1VgCgckmDE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SgAVx6hkZdaHv3CD8CN9Q7eFkd1WUAxX4YYUeFf05mJNMCnPu3lsKbjbIJb+nrCSH MbRo2uS1vlrWa6T8ShtJWreZbTLJrb3dXDPHBc25PMNa0XNB4hScmCRsBeQkEkqSCv +D1EK+XAc5braLuQb46aOEU3+7YIhdjNAW0N5PZNZrplKGnsuxTJ6x799OQOgfgMbW sbEfJMfJtKirlg5dW3FA+g0LbZALwv1CD2pNQ8XdFMVqsxpox+u5NY6tYIKKBroYh4 rdb9urn3q2CZRyIE88jk1iLQ4cIwwCb8rIZ4FbWkBX8VTcNRrzaU+7vSzuv+G4IMMQ 4B9UEXBmi+xuw== From: Arnd Bergmann To: robert.jarzmik@free.fr, linux-arm-kernel@lists.infradead.org Cc: Arnd Bergmann , Daniel Mack , Haojian Zhuang , Marek Vasut , Philipp Zabel , Lubomir Rintel , Paul Parsons , Tomas Cech , Sergey Lapin , Thomas Bogendoerfer , Michael Turquette , Stephen Boyd , "Rafael J. Wysocki" , Viresh Kumar , Dmitry Torokhov , Ulf Hansson , Dominik Brodowski , Helge Deller , Mark Brown , Linus Walleij , linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-ide@vger.kernel.org, linux-clk@vger.kernel.org, linux-pm@vger.kernel.org, linux-input@vger.kernel.org, patches@opensource.cirrus.com, linux-leds@vger.kernel.org, linux-mmc@vger.kernel.org, linux-mtd@lists.infradead.org, linux-rtc@vger.kernel.org, linux-usb@vger.kernel.org, linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, alsa-devel@alsa-project.org, Sebastian Reichel Subject: [PATCH 40/48] ARM: pxa: tosa: use gpio lookup for battery Date: Tue, 19 Apr 2022 18:38:02 +0200 Message-Id: <20220419163810.2118169-41-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20220419163810.2118169-1-arnd@kernel.org> References: <20220419163810.2118169-1-arnd@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220419_174411_957395_BFCBAAB7 X-CRM114-Status: GOOD ( 25.93 ) X-Spam-Score: -5.2 (-----) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Arnd Bergmann The battery driver uses a lot of GPIO lines, hardcoded from a machine header file. Change it to use a gpiod lookup table instead. Content analysis details: (-5.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at https://www.dnswl.org/, high trust [139.178.84.217 listed in list.dnswl.org] -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 T_SCC_BODY_TEXT_LINE No description available. -0.0 DKIMWL_WL_HIGH DKIMwl.org - High trust sender X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org From: Arnd Bergmann The battery driver uses a lot of GPIO lines, hardcoded from a machine header file. Change it to use a gpiod lookup table instead. Reviewed-by: Sebastian Reichel Acked-by: Sebastian Reichel Cc: linux-pm@vger.kernel.org Signed-off-by: Arnd Bergmann --- arch/arm/mach-pxa/tosa.c | 23 +++++ drivers/power/supply/tosa_battery.c | 147 ++++++++++++++++------------ 2 files changed, 109 insertions(+), 61 deletions(-) diff --git a/arch/arm/mach-pxa/tosa.c b/arch/arm/mach-pxa/tosa.c index 5a16a025192c..19fe79518aaf 100644 --- a/arch/arm/mach-pxa/tosa.c +++ b/arch/arm/mach-pxa/tosa.c @@ -366,6 +366,28 @@ static struct pxaficp_platform_data tosa_ficp_platform_data = { .shutdown = tosa_irda_shutdown, }; +static struct gpiod_lookup_table tosa_battery_gpio_table = { + .dev_id = "wm97xx-battery", + .table = { + GPIO_LOOKUP("tc6393xb", TOSA_GPIO_CHARGE_OFF - TOSA_TC6393XB_GPIO_BASE, "main charge off", GPIO_ACTIVE_HIGH ), + GPIO_LOOKUP("tc6393xb", TOSA_GPIO_CHARGE_OFF_JC - TOSA_TC6393XB_GPIO_BASE, "jacket charge off", GPIO_ACTIVE_HIGH ), + GPIO_LOOKUP("tc6393xb", TOSA_GPIO_BAT_SW_ON - TOSA_TC6393XB_GPIO_BASE, "battery switch", GPIO_ACTIVE_HIGH ), + GPIO_LOOKUP("tc6393xb", TOSA_GPIO_BAT0_V_ON - TOSA_TC6393XB_GPIO_BASE, "main battery", GPIO_ACTIVE_HIGH ), + GPIO_LOOKUP("tc6393xb", TOSA_GPIO_BAT1_V_ON - TOSA_TC6393XB_GPIO_BASE, "jacket battery", GPIO_ACTIVE_HIGH ), + GPIO_LOOKUP("tc6393xb", TOSA_GPIO_BAT1_TH_ON - TOSA_TC6393XB_GPIO_BASE, "main battery temp", GPIO_ACTIVE_HIGH ), + GPIO_LOOKUP("tc6393xb", TOSA_GPIO_BAT0_TH_ON - TOSA_TC6393XB_GPIO_BASE, "jacket battery temp", GPIO_ACTIVE_HIGH ), + GPIO_LOOKUP("tc6393xb", TOSA_GPIO_BU_CHRG_ON - TOSA_TC6393XB_GPIO_BASE, "backup battery", GPIO_ACTIVE_HIGH ), + + GPIO_LOOKUP("gpio-pxa", TOSA_GPIO_BAT0_CRG, "main battery full", GPIO_ACTIVE_HIGH ), + GPIO_LOOKUP("gpio-pxa", TOSA_GPIO_BAT1_CRG, "jacket battery full", GPIO_ACTIVE_HIGH ), + GPIO_LOOKUP("gpio-pxa", TOSA_GPIO_BAT0_LOW, "main battery low", GPIO_ACTIVE_HIGH ), + GPIO_LOOKUP("gpio-pxa", TOSA_GPIO_BAT1_LOW, "jacket battery low", GPIO_ACTIVE_HIGH ), + GPIO_LOOKUP("gpio-pxa", TOSA_GPIO_JACKET_DETECT, "jacket detect", GPIO_ACTIVE_HIGH ), + { }, + }, +}; + + /* * Tosa AC IN */ @@ -954,6 +976,7 @@ static void __init tosa_init(void) /* enable batt_fault */ PMCR = 0x01; + gpiod_add_lookup_table(&tosa_battery_gpio_table); gpiod_add_lookup_table(&tosa_mci_gpio_table); gpiod_add_lookup_table(&tosa_audio_gpio_table); pxa_set_mci_info(&tosa_mci_platform_data); diff --git a/drivers/power/supply/tosa_battery.c b/drivers/power/supply/tosa_battery.c index b26b0eca33e1..d10320f348d0 100644 --- a/drivers/power/supply/tosa_battery.c +++ b/drivers/power/supply/tosa_battery.c @@ -15,11 +15,16 @@ #include #include -#include static DEFINE_MUTEX(bat_lock); /* protects gpio pins */ static struct work_struct bat_work; +struct tosa_gpio { + const char *con; + enum gpiod_flags flags; + struct gpio_desc *desc; +}; + struct tosa_bat { int status; struct power_supply *psy; @@ -28,38 +33,42 @@ struct tosa_bat { struct mutex work_lock; /* protects data */ bool (*is_present)(struct tosa_bat *bat); - int gpio_full; - int gpio_charge_off; + struct tosa_gpio gpio_full; + struct tosa_gpio gpio_charge_off; int technology; - int gpio_bat; + struct tosa_gpio gpio_bat; int adc_bat; int adc_bat_divider; int bat_max; int bat_min; - int gpio_temp; + struct tosa_gpio gpio_temp; int adc_temp; int adc_temp_divider; }; static struct tosa_bat tosa_bat_main; static struct tosa_bat tosa_bat_jacket; +static struct tosa_gpio gpiod_jacket_det = { "jacket detect", GPIOD_IN }; +static struct tosa_gpio gpiod_battery_switch = { "battery switch", GPIOD_OUT_LOW }; +static struct tosa_gpio gpiod_main_battery_low = { "main battery low", GPIOD_IN }; +static struct tosa_gpio gpiod_jacket_battery_low = { "jacket battery low", GPIOD_IN }; static unsigned long tosa_read_bat(struct tosa_bat *bat) { unsigned long value = 0; - if (bat->gpio_bat < 0 || bat->adc_bat < 0) + if (!bat->gpio_bat.desc || bat->adc_bat < 0) return 0; mutex_lock(&bat_lock); - gpio_set_value(bat->gpio_bat, 1); + gpiod_set_value(bat->gpio_bat.desc, 1); msleep(5); value = wm97xx_read_aux_adc(dev_get_drvdata(bat->psy->dev.parent), bat->adc_bat); - gpio_set_value(bat->gpio_bat, 0); + gpiod_set_value(bat->gpio_bat.desc, 0); mutex_unlock(&bat_lock); value = value * 1000000 / bat->adc_bat_divider; @@ -71,15 +80,15 @@ static unsigned long tosa_read_temp(struct tosa_bat *bat) { unsigned long value = 0; - if (bat->gpio_temp < 0 || bat->adc_temp < 0) + if (!bat->gpio_temp.desc || bat->adc_temp < 0) return 0; mutex_lock(&bat_lock); - gpio_set_value(bat->gpio_temp, 1); + gpiod_set_value(bat->gpio_temp.desc, 1); msleep(5); value = wm97xx_read_aux_adc(dev_get_drvdata(bat->psy->dev.parent), bat->adc_temp); - gpio_set_value(bat->gpio_temp, 0); + gpiod_set_value(bat->gpio_temp.desc, 0); mutex_unlock(&bat_lock); value = value * 10000 / bat->adc_temp_divider; @@ -136,7 +145,7 @@ static int tosa_bat_get_property(struct power_supply *psy, static bool tosa_jacket_bat_is_present(struct tosa_bat *bat) { - return gpio_get_value(TOSA_GPIO_JACKET_DETECT) == 0; + return gpiod_get_value(gpiod_jacket_det.desc) == 0; } static void tosa_bat_external_power_changed(struct power_supply *psy) @@ -166,23 +175,23 @@ static void tosa_bat_update(struct tosa_bat *bat) bat->full_chrg = -1; } else if (power_supply_am_i_supplied(psy)) { if (bat->status == POWER_SUPPLY_STATUS_DISCHARGING) { - gpio_set_value(bat->gpio_charge_off, 0); + gpiod_set_value(bat->gpio_charge_off.desc, 0); mdelay(15); } - if (gpio_get_value(bat->gpio_full)) { + if (gpiod_get_value(bat->gpio_full.desc)) { if (old == POWER_SUPPLY_STATUS_CHARGING || bat->full_chrg == -1) bat->full_chrg = tosa_read_bat(bat); - gpio_set_value(bat->gpio_charge_off, 1); + gpiod_set_value(bat->gpio_charge_off.desc, 1); bat->status = POWER_SUPPLY_STATUS_FULL; } else { - gpio_set_value(bat->gpio_charge_off, 0); + gpiod_set_value(bat->gpio_charge_off.desc, 0); bat->status = POWER_SUPPLY_STATUS_CHARGING; } } else { - gpio_set_value(bat->gpio_charge_off, 1); + gpiod_set_value(bat->gpio_charge_off.desc, 1); bat->status = POWER_SUPPLY_STATUS_DISCHARGING; } @@ -251,18 +260,18 @@ static struct tosa_bat tosa_bat_main = { .full_chrg = -1, .psy = NULL, - .gpio_full = TOSA_GPIO_BAT0_CRG, - .gpio_charge_off = TOSA_GPIO_CHARGE_OFF, + .gpio_full = { "main battery full", GPIOD_IN }, + .gpio_charge_off = { "main charge off" , GPIOD_OUT_HIGH }, .technology = POWER_SUPPLY_TECHNOLOGY_LIPO, - .gpio_bat = TOSA_GPIO_BAT0_V_ON, + .gpio_bat = { "main battery", GPIOD_OUT_LOW }, .adc_bat = WM97XX_AUX_ID3, .adc_bat_divider = 414, .bat_max = 4310000, .bat_min = 1551 * 1000000 / 414, - .gpio_temp = TOSA_GPIO_BAT1_TH_ON, + .gpio_temp = { "main battery temp", GPIOD_OUT_LOW }, .adc_temp = WM97XX_AUX_ID2, .adc_temp_divider = 10000, }; @@ -273,18 +282,18 @@ static struct tosa_bat tosa_bat_jacket = { .psy = NULL, .is_present = tosa_jacket_bat_is_present, - .gpio_full = TOSA_GPIO_BAT1_CRG, - .gpio_charge_off = TOSA_GPIO_CHARGE_OFF_JC, + .gpio_full = { "jacket battery full", GPIOD_IN }, + .gpio_charge_off = { "jacket charge off", GPIOD_OUT_HIGH }, .technology = POWER_SUPPLY_TECHNOLOGY_LIPO, - .gpio_bat = TOSA_GPIO_BAT1_V_ON, + .gpio_bat = { "jacket battery", GPIOD_OUT_LOW }, .adc_bat = WM97XX_AUX_ID3, .adc_bat_divider = 414, .bat_max = 4310000, .bat_min = 1551 * 1000000 / 414, - .gpio_temp = TOSA_GPIO_BAT0_TH_ON, + .gpio_temp = { "jacket battery temp", GPIOD_OUT_LOW }, .adc_temp = WM97XX_AUX_ID2, .adc_temp_divider = 10000, }; @@ -294,36 +303,16 @@ static struct tosa_bat tosa_bat_bu = { .full_chrg = -1, .psy = NULL, - .gpio_full = -1, - .gpio_charge_off = -1, - .technology = POWER_SUPPLY_TECHNOLOGY_LiMn, - .gpio_bat = TOSA_GPIO_BU_CHRG_ON, + .gpio_bat = { "backup battery", GPIOD_OUT_LOW }, .adc_bat = WM97XX_AUX_ID4, .adc_bat_divider = 1266, - .gpio_temp = -1, .adc_temp = -1, .adc_temp_divider = -1, }; -static struct gpio tosa_bat_gpios[] = { - { TOSA_GPIO_CHARGE_OFF, GPIOF_OUT_INIT_HIGH, "main charge off" }, - { TOSA_GPIO_CHARGE_OFF_JC, GPIOF_OUT_INIT_HIGH, "jacket charge off" }, - { TOSA_GPIO_BAT_SW_ON, GPIOF_OUT_INIT_LOW, "battery switch" }, - { TOSA_GPIO_BAT0_V_ON, GPIOF_OUT_INIT_LOW, "main battery" }, - { TOSA_GPIO_BAT1_V_ON, GPIOF_OUT_INIT_LOW, "jacket battery" }, - { TOSA_GPIO_BAT1_TH_ON, GPIOF_OUT_INIT_LOW, "main battery temp" }, - { TOSA_GPIO_BAT0_TH_ON, GPIOF_OUT_INIT_LOW, "jacket battery temp" }, - { TOSA_GPIO_BU_CHRG_ON, GPIOF_OUT_INIT_LOW, "backup battery" }, - { TOSA_GPIO_BAT0_CRG, GPIOF_IN, "main battery full" }, - { TOSA_GPIO_BAT1_CRG, GPIOF_IN, "jacket battery full" }, - { TOSA_GPIO_BAT0_LOW, GPIOF_IN, "main battery low" }, - { TOSA_GPIO_BAT1_LOW, GPIOF_IN, "jacket battery low" }, - { TOSA_GPIO_JACKET_DETECT, GPIOF_IN, "jacket detect" }, -}; - #ifdef CONFIG_PM static int tosa_bat_suspend(struct platform_device *dev, pm_message_t state) { @@ -343,6 +332,21 @@ static int tosa_bat_resume(struct platform_device *dev) #define tosa_bat_resume NULL #endif +static int tosa_bat_gpio_get(struct device *dev, struct tosa_gpio *gpio) +{ + int ret; + + if (!gpio->con) + return 0; + + gpio->desc = devm_gpiod_get(dev, gpio->con, gpio->flags); + ret = PTR_ERR_OR_ZERO(gpio->desc); + if (ret) + dev_warn(dev, "failed to get gpio \"%s\"\n", gpio->con); + + return ret; +} + static int tosa_power_supply_register(struct device *dev, struct tosa_bat *bat, const struct power_supply_desc *desc) @@ -350,6 +354,23 @@ static int tosa_power_supply_register(struct device *dev, struct power_supply_config cfg = { .drv_data = bat, }; + int ret; + + ret = tosa_bat_gpio_get(dev, &bat->gpio_full); + if (ret) + return ret; + + ret = tosa_bat_gpio_get(dev, &bat->gpio_charge_off); + if (ret) + return ret; + + ret = tosa_bat_gpio_get(dev, &bat->gpio_bat); + if (ret) + return ret; + + ret = tosa_bat_gpio_get(dev, &bat->gpio_temp); + if (ret) + return ret; mutex_init(&bat->work_lock); bat->psy = power_supply_register(dev, desc, &cfg); @@ -358,49 +379,55 @@ static int tosa_power_supply_register(struct device *dev, } -static int tosa_bat_probe(struct platform_device *dev) +static int tosa_bat_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; int ret; if (!machine_is_tosa()) return -ENODEV; - ret = gpio_request_array(tosa_bat_gpios, ARRAY_SIZE(tosa_bat_gpios)); + ret = tosa_bat_gpio_get(dev, &gpiod_jacket_det); if (ret) return ret; + /* these are not used anywhere, continue on failure */ + tosa_bat_gpio_get(dev, &gpiod_battery_switch); + tosa_bat_gpio_get(dev, &gpiod_main_battery_low); + tosa_bat_gpio_get(dev, &gpiod_jacket_battery_low); + INIT_WORK(&bat_work, tosa_bat_work); - ret = tosa_power_supply_register(&dev->dev, &tosa_bat_main, + ret = tosa_power_supply_register(dev, &tosa_bat_main, &tosa_bat_main_desc); if (ret) goto err_psy_reg_main; - ret = tosa_power_supply_register(&dev->dev, &tosa_bat_jacket, + ret = tosa_power_supply_register(dev, &tosa_bat_jacket, &tosa_bat_jacket_desc); if (ret) goto err_psy_reg_jacket; - ret = tosa_power_supply_register(&dev->dev, &tosa_bat_bu, + ret = tosa_power_supply_register(dev, &tosa_bat_bu, &tosa_bat_bu_desc); if (ret) goto err_psy_reg_bu; - ret = request_irq(gpio_to_irq(TOSA_GPIO_BAT0_CRG), + ret = request_irq(gpiod_to_irq(tosa_bat_main.gpio_full.desc), tosa_bat_gpio_isr, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "main full", &tosa_bat_main); if (ret) goto err_req_main; - ret = request_irq(gpio_to_irq(TOSA_GPIO_BAT1_CRG), + ret = request_irq(gpiod_to_irq(tosa_bat_jacket.gpio_full.desc), tosa_bat_gpio_isr, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "jacket full", &tosa_bat_jacket); if (ret) goto err_req_jacket; - ret = request_irq(gpio_to_irq(TOSA_GPIO_JACKET_DETECT), + ret = request_irq(gpiod_to_irq(gpiod_jacket_det.desc), tosa_bat_gpio_isr, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "jacket detect", &tosa_bat_jacket); @@ -409,9 +436,9 @@ static int tosa_bat_probe(struct platform_device *dev) return 0; } - free_irq(gpio_to_irq(TOSA_GPIO_BAT1_CRG), &tosa_bat_jacket); + free_irq(gpiod_to_irq(tosa_bat_jacket.gpio_full.desc), &tosa_bat_jacket); err_req_jacket: - free_irq(gpio_to_irq(TOSA_GPIO_BAT0_CRG), &tosa_bat_main); + free_irq(gpiod_to_irq(tosa_bat_main.gpio_full.desc), &tosa_bat_main); err_req_main: power_supply_unregister(tosa_bat_bu.psy); err_psy_reg_bu: @@ -423,15 +450,14 @@ static int tosa_bat_probe(struct platform_device *dev) /* see comment in tosa_bat_remove */ cancel_work_sync(&bat_work); - gpio_free_array(tosa_bat_gpios, ARRAY_SIZE(tosa_bat_gpios)); return ret; } static int tosa_bat_remove(struct platform_device *dev) { - free_irq(gpio_to_irq(TOSA_GPIO_JACKET_DETECT), &tosa_bat_jacket); - free_irq(gpio_to_irq(TOSA_GPIO_BAT1_CRG), &tosa_bat_jacket); - free_irq(gpio_to_irq(TOSA_GPIO_BAT0_CRG), &tosa_bat_main); + free_irq(gpiod_to_irq(gpiod_jacket_det.desc), &tosa_bat_jacket); + free_irq(gpiod_to_irq(tosa_bat_jacket.gpio_full.desc), &tosa_bat_jacket); + free_irq(gpiod_to_irq(tosa_bat_main.gpio_full.desc), &tosa_bat_main); power_supply_unregister(tosa_bat_bu.psy); power_supply_unregister(tosa_bat_jacket.psy); @@ -443,7 +469,6 @@ static int tosa_bat_remove(struct platform_device *dev) * unregistered now. */ cancel_work_sync(&bat_work); - gpio_free_array(tosa_bat_gpios, ARRAY_SIZE(tosa_bat_gpios)); return 0; }